We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24473
    • 5 Posts
    So after a bit of research it seems that SMF integration with ModX is thus far, hit or miss. I’m currently putting together a site, and even after juggling back and forth between ModX and Joomla I finally settled on ModX after screaming in fury more then a few times at how absolutely infuriating Joomla is to use but thats another story.

    A full integration for me with SMF isn’t really necessary, I don’t need the ModX web users to match up to the SMF users they’ll never be touching the website itself anyways. But what I do want to do is:
    • Add a login for SMF on the top of the website, this should check to see if the user is logged in and if not display the login fields, if they are logged in them display a simple welcome message, their username and maybe status on their PMs (How many unread, etc).
    • Provide a listing of most recent posts titles and who posted it with the date on the index page.

    I’ve done some research on SMF and it seems like this should be possible to do a lite sort of integration. But before I dive directly into doing the work I wanted to see if anyone else has done this, any hurdles they faced, and any advice from ModX users. While I really love ModX, and I have CMS experience on enterprise level systems, I’m very much a noob to ModX itself so any advice or pointers are greatly appreciated.
      • 16183
      • 1,390 Posts
      Hi Ransim,

      Welcome to MODx! Incidentally, there’s been discussions about a MODx/SMF bridge for a long time...see this link for the latest discussion:

      http://modxcms.com/forums/index.php/topic,34181.0.html

      cheers/k
        • 7231
        • 4,205 Posts
        If you do not need them fully integrated (sharing user base), all you need is to have the MODx template match the SMF theme.
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don't know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 24473
          • 5 Posts
          Quote from: dev_cw at Mar 26, 2009, 04:58 PM

          If you do not need them fully integrated (sharing user base), all you need is to have the MODx template match the SMF theme.

          No I don’t need a integrated userbase. Basically I was looking at incorporating the SSI items from SMF onto my ModX template.

          http://www.simplemachines.org/community/ssi_examples.php

          I was curious if anyone had done this yet and what level of success they’d had. I’m planning to use a guide someone put together for WordPress to create the pieces to include this myself. I guess once I finish it i’ll have to look at making it available to others.

          To kondongo, I’ve read through that thread and as much as I’d life to offer up some coding time I’m actually fairly swamped so I couldn’t dedicate the time to helping develop a true bridge if I wanted to. undecided
          • This is how we used to have MODx "integrated" on the old site. Here was our code that checked for a session then allowed you to comment on the blogs:
            include_once("forums/SSI.php");
            
            $loggedin = false;
            
            // redirect to host document if an attempt was 
            // made to display the document containing the comments
            if(isset($hostid)) {
            	$url = $modx->makeUrl($hostid);
            	$modx->sendRedirect($url);
            	exit;
            }
            
            // set to true to echo out variables before the comment block for troubleshooting
            $debug = false;
            
            // get user groups that can post & view comments
            $postgrp = isset($canpost) ? explode(",",$canpost):array();
            $viewgrp = isset($canview) ? explode(",",$canview):array();
            $allowAnyPost = count($postgrp)==0 ? true : false;
            $allowAnyView = count($viewgrp)==0 ? true : false;
            
            // get current document id (if set, show-only mode)
            $docid = isset($docid) ? intval($docid):$modx->documentIdentifier;
            
            // get folder id where we should store comments 
            // else store in current document
            $folder = isset($folder) ? intval($folder):$docid;
            
            // get free form option
            $freeform = isset($freeform) && $freeform==1 ? 1:0;
            
            // get tagid
            $tagid = isset($tagid) ? preg_replace("/[^A-z0-9_\-]/",'',$tagid):'';
            
            // set alias name of document used to store comments
            $alias = 'usrcmt-'.$docid.($tagid ? '-'.$tagid:'');
            
            // get sort order
            $sortorder = isset($sortorder) ? $sortorder : 1;
            
            // get comment block style/class
            $postcss = isset($postcss) ? ' class="'.$postcss.'[+altrowclass+][+authorclass+]"' : ' style="font-size:11px;line-height: 17px;white-space:normal;width:100%;background-color:#eee;color: #111;padding:5px;margin-bottom:10px;" class="[+altrowclass+][+authorclass+]"';
            
            // get post title class
            $titlecss = isset($titlecss) ? ' class="'.$titlecss.'"' : ' style="width:100%;background-color:#c0c0c0;padding:2px;margin-bottom:5px;"';
            
            // get post number class
            $numbercss = isset($numbercss) ? ' class="'.$numbercss.'"' : ' style="float:right; padding: 0 0 20px 20px;font-size:24px;color:#ccc;font-weight:bold;"';
            
            // get code style/class
            $codecss = isset($codecss) ? ' class="'.$codecss.'"' : ' style="background-color:#eee;border-top:2px solid #e0e0e0;margin:0;"';
            
            // get author class
            $authorcss = isset($authorcss) ? ' '.$authorcss : '';
            
            // get owner's class
            $ownercss = isset($ownercss) ? ' '.$ownercss : '';
            
            // get alt row style/class
            $altrowcss = isset($altrowcss) ? ' '.$altrowcss : '';
            
            // get date format
            $dateformat = isset($dateformat) ? $dateformat : '%e%b%Y %I:%M%p';
            
            // set recent post value
            $recentposts = isset($recentposts) ? $recentposts : 0;
            
            // get badwords
            if(isset($badwords)) {
            	$badwords = str_replace(' ','', $badwords);
            	$badwords = "/".str_replace(',','|', $badwords)."/i";
            }
            
            // set splitter
            $splitter = '<!--Comment-Spliter:'.$docid.'-->';
            
            // get postback status
            $isPostBack = isset($_POST['UserCommentForm'.$tagid]) ? true:false;
            
            // get display template
            if(isset($displaytpl)) $displayTpl = $modx->getChunk($displaytpl);
            if(empty($displaytpl)) $displayTpl = '
            [+UID:[+uid+]+]<div[+postclass+]>
               <div[+numberclass+]>
                 [+postnumber+]
               </div>
            	<div[+titleclass+]>
            		<strong>[+subject+]</strong><span>[+user+] [+createdon+]</span>
            	</div>
            	<div class="content">
            		[+comment+]
            	</div>
            
            </div>
            ';
            
            // get form template
            if(isset($formtpl)) $formTpl = $modx->getChunk($formtpl);
            if(empty($formTpl)) $formTpl = '
            <form method="post" action="[~[*id*]~]">
            	<input name="[+tagname+]" type="hidden" value="on" />
            	Subject:<br /><input name="subject" type="text" size="40" value="" /><br />
            	Comment:<br /><textarea name="comment" cols="50" rows="8"></textarea><br />
            	<input name="send" type="submit" value="Submit" />
            </form>
            ';
            
            
            // switch block
            switch ($isPostBack) {
            	case true:	// process post backs
            		if($_POST['comment']!='') {
            			
            			// get user's id and name
            			$uid = $modx->getLoginUserID();
            			$user = $modx->getLoginUserName();
            			if(!$user && $allowAnyPost) $user = 'anonymous';
            
            			// check if user has rights
            			if(!$allowAnyPost && !$modx->isMemberOfWebGroup($postgrp) && !$context['user']['is_logged']) {
            				return 'You must be logged into the forums to comment. Please <a href="/forums/index.php?action=login">login</a>';
            			}
            
            			$createdon = time();
            
            // format comment title, classes and/or styles
            			$comment = str_replace('[+user+]',$user,$displayTpl);
            			$comment = str_replace('[+uid+]',$uid,$comment);
            			$comment = str_replace('[+postclass+]',$postcss,$comment);
            			$comment = str_replace('[+titleclass+]',$titlecss,$comment);
            			$comment = str_replace('[+numberclass+]',$numbercss,$comment);
            			$comment = str_replace('[+createdon+]',strftime($dateformat,$createdon),$comment);			
            			// check for author's comments
            			if($uid && ($uid*-1)==$modx->documentObject['createdby']) {
            				$comment = str_replace('[+authorclass+]',$authorcss,$comment);
            			}
                        
                        // deal with code tags and bad words
            			foreach($_POST as $n=>$v) {
            				if(!empty($badwords)) $v = preg_replace($badwords,'[Filtered]',$v); // remove badwords
            				$v = $modx->stripTags(htmlspecialchars($v));
            				if($n=='comment' && strpos($v,'')!==false){
            // preserve code
            preg_match_all("|\[code\](.*)\[/code\]|Uis",$v,$matches);
            for ($i=0;$i<count($matches[0]);$i++) {
            $tag = $matches[0][$i];
            $text = $matches[1][$i];
            $v = str_replace($tag,'<pre'.$codecss.'>'.$text.'</pre>',$v);
            }
            }
            $v = str_replace("\r",'',$v);
            $v = str_replace("\n",'
            ',$v);
            $comment = str_replace('[+'.$n.'+]',$v,$comment);
            $name = $context['user']['name'];
            $avatar = $context['user']['avatar']['image'];
            $fid = $context['user']['id'];
            $fprofile = "http://modxcms.com/forums/index.php?action=profile;u=".$fid;
            $comment = str_replace('[+forumuser+]',$name,$comment);
            $comment = str_replace('[+avatar+]',$avatar,$comment);
            $comment = str_replace('[+forumprofile+]',$fprofile,$comment);
            }

            $comment = str_replace($splitter,'',$comment); // remove splitter from comment

            // save comment
            $sql = 'SELECT pagetitle FROM '.$modx->getFullTableName('site_content').' WHERE parent=\''.$folder.'\' AND alias=\''.$alias.'\' LIMIT 1';
            if($modx->db->getValue($sql)) {
            // update comments
            $sql = ' UPDATE '.$modx->getFullTableName('site_content').
            ' SET content = CONCAT(\''.$comment.$splitter.'\',content)'.
            ' WHERE parent=\''.$folder.'\' AND alias=\''.$alias.'\'';
            $modx->db->query($sql);
            }
            else {
            // create new comment page
            $doc = $modx->getDocument($docid);
            $title = mysql_escape_string($doc['pagetitle']).' - User comments';
            $flds = array(
            'pagetitle' => $title,
            'alias' => $alias,
            'parent' => $folder,
            'createdon' => $createdon,
            'createdby' => '0',
            'editedon' => '0',
            'editedby' => '0',
            'published' => '1',
            'deleted' => '0',
            'hidemenu' => '1',
            'template' => '0',
            'content' => $comment.$splitter.'[['.$modx->getSnippetName().'? &hostid=`'.$docid.'`]]'
            );
            $modx->db->insert($flds,$modx->getFullTableName('site_content'));
            if(!empty($makefolder)) {
            // convert parent into folder
            $modx->db->update(array('isfolder'=>'1'),$modx->getFullTableName('site_content'),'id=\''.$folder.'\'');
            }
            }
            }

            default: // display comments
            // check if user has rights to view comments
            if(!$allowAnyView && !$modx->isMemberOfWebGroup($viewgrp)) {
            $comment = '';
            }
            else {

            $uid = $modx->getLoginUserID();

            // get comments
            $ds = $modx->db->select('content',$modx->getFullTableName('site_content'),' parent=\''.$folder.'\' AND alias=\''.$alias.'\'');
            $content = $modx->db->getValue($ds);

            // split content into separate comments
            $parts = explode($splitter,$content);
            array_pop($parts);

            // count comments
            $count = count($parts);
            $modx->setPlaceholder("UserComments.Count",$count);

            // handle recent post
            $offset = 0;
            if($recentposts>0) {
            $parts = array_slice($parts,0,$recentposts);
            $offset = $count-$recentposts;
            $count = $recentposts;
            }

            // prepare comments
            if($sortorder==0) $parts = array_reverse($parts);
            for($i=0;$i<$count;$i++) {
            $part = $parts[$i];
            $num = ($sortorder==1) ? $count-$i:$i+1;
            $part = str_replace('[+postnumber+]',$num+$offset,$part);
            if($altrowcss && ($i % 2)==0) $part = str_replace('[+altrowclass+]',$altrowcss,$part);
            // check for owner's comments
            if($uid && strpos($part,'[+UID:'.$uid.'+]')!==false) $part = str_replace('[+authorclass+]',$ownercss,$part);
            $parts[$i] = $part;
            }

            $comments = implode("",$parts);

            }
            // check if user has rights to post comments


            if(!$allowAnyPost && !$modx->isMemberOfWebGroup($postgrp)) {
            $formTpl = '';
            }
            else if ($context['user']['is_logged']){
            $formTpl = str_replace('[+tagname+]','UserCommentForm'.$tagid,$formTpl);
            }
            if (!$context['user']['is_logged']){$formTpl = 'You must be logged into the forums to comment. Please <a href="/forums/index.php?action=login">login</a>';}
            $troubleshooting = ($debug)? "alias: $alias - folder: $folder - docid: $docid - tag: $tagid":'';
            if ($comments == "") {
            $comments = "No-one has commented on this article yet.";
            }

            // return comments along with form
            return $troubleshooting.$comments.($freeform ? $modx->setPlaceholder('UserComments.Form',$formTpl):$formTpl);
            break;
            }
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 24473
              • 5 Posts
              Quote from: rthrash at Mar 26, 2009, 08:21 PM

              This is how we used to have MODx "integrated" on the old site. Here was our code that checked for a session then allowed you to comment on the blogs:
              include_once("forums/SSI.php");
              
              $loggedin = false;
              
              // redirect to host document if an attempt was 
              // made to display the document containing the comments
              if(isset($hostid)) {
              	$url = $modx->makeUrl($hostid);
              	$modx->sendRedirect($url);
              	exit;
              }
              
              // set to true to echo out variables before the comment block for troubleshooting
              $debug = false;
              
              // get user groups that can post & view comments
              $postgrp = isset($canpost) ? explode(",",$canpost):array();
              $viewgrp = isset($canview) ? explode(",",$canview):array();
              $allowAnyPost = count($postgrp)==0 ? true : false;
              $allowAnyView = count($viewgrp)==0 ? true : false;
              
              // get current document id (if set, show-only mode)
              $docid = isset($docid) ? intval($docid):$modx->documentIdentifier;
              
              // get folder id where we should store comments 
              // else store in current document
              $folder = isset($folder) ? intval($folder):$docid;
              
              // get free form option
              $freeform = isset($freeform) && $freeform==1 ? 1:0;
              
              // get tagid
              $tagid = isset($tagid) ? preg_replace("/[^A-z0-9_\-]/",'',$tagid):'';
              
              // set alias name of document used to store comments
              $alias = 'usrcmt-'.$docid.($tagid ? '-'.$tagid:'');
              
              // get sort order
              $sortorder = isset($sortorder) ? $sortorder : 1;
              
              // get comment block style/class
              $postcss = isset($postcss) ? ' class="'.$postcss.'[+altrowclass+][+authorclass+]"' : ' style="font-size:11px;line-height: 17px;white-space:normal;width:100%;background-color:#eee;color: #111;padding:5px;margin-bottom:10px;" class="[+altrowclass+][+authorclass+]"';
              
              // get post title class
              $titlecss = isset($titlecss) ? ' class="'.$titlecss.'"' : ' style="width:100%;background-color:#c0c0c0;padding:2px;margin-bottom:5px;"';
              
              // get post number class
              $numbercss = isset($numbercss) ? ' class="'.$numbercss.'"' : ' style="float:right; padding: 0 0 20px 20px;font-size:24px;color:#ccc;font-weight:bold;"';
              
              // get code style/class
              $codecss = isset($codecss) ? ' class="'.$codecss.'"' : ' style="background-color:#eee;border-top:2px solid #e0e0e0;margin:0;"';
              
              // get author class
              $authorcss = isset($authorcss) ? ' '.$authorcss : '';
              
              // get owner's class
              $ownercss = isset($ownercss) ? ' '.$ownercss : '';
              
              // get alt row style/class
              $altrowcss = isset($altrowcss) ? ' '.$altrowcss : '';
              
              // get date format
              $dateformat = isset($dateformat) ? $dateformat : '%e%b%Y %I:%M%p';
              
              // set recent post value
              $recentposts = isset($recentposts) ? $recentposts : 0;
              
              // get badwords
              if(isset($badwords)) {
              	$badwords = str_replace(' ','', $badwords);
              	$badwords = "/".str_replace(',','|', $badwords)."/i";
              }
              
              // set splitter
              $splitter = '<!--Comment-Spliter:'.$docid.'-->';
              
              // get postback status
              $isPostBack = isset($_POST['UserCommentForm'.$tagid]) ? true:false;
              
              // get display template
              if(isset($displaytpl)) $displayTpl = $modx->getChunk($displaytpl);
              if(empty($displaytpl)) $displayTpl = '
              [+UID:[+uid+]+]<div[+postclass+]>
                 <div[+numberclass+]>
                   [+postnumber+]
                 </div>
              	<div[+titleclass+]>
              		<strong>[+subject+]</strong><span>[+user+] [+createdon+]</span>
              	</div>
              	<div class="content">
              		[+comment+]
              	</div>
              
              </div>
              ';
              
              // get form template
              if(isset($formtpl)) $formTpl = $modx->getChunk($formtpl);
              if(empty($formTpl)) $formTpl = '
              <form method="post" action="[~[*id*]~]">
              	<input name="[+tagname+]" type="hidden" value="on" />
              	Subject:<br /><input name="subject" type="text" size="40" value="" /><br />
              	Comment:<br /><textarea name="comment" cols="50" rows="8"></textarea><br />
              	<input name="send" type="submit" value="Submit" />
              </form>
              ';
              
              
              // switch block
              switch ($isPostBack) {
              	case true:	// process post backs
              		if($_POST['comment']!='') {
              			
              			// get user's id and name
              			$uid = $modx->getLoginUserID();
              			$user = $modx->getLoginUserName();
              			if(!$user && $allowAnyPost) $user = 'anonymous';
              
              			// check if user has rights
              			if(!$allowAnyPost && !$modx->isMemberOfWebGroup($postgrp) && !$context['user']['is_logged']) {
              				return 'You must be logged into the forums to comment. Please <a href="/forums/index.php?action=login">login</a>';
              			}
              
              			$createdon = time();
              
              // format comment title, classes and/or styles
              			$comment = str_replace('[+user+]',$user,$displayTpl);
              			$comment = str_replace('[+uid+]',$uid,$comment);
              			$comment = str_replace('[+postclass+]',$postcss,$comment);
              			$comment = str_replace('[+titleclass+]',$titlecss,$comment);
              			$comment = str_replace('[+numberclass+]',$numbercss,$comment);
              			$comment = str_replace('[+createdon+]',strftime($dateformat,$createdon),$comment);			
              			// check for author's comments
              			if($uid && ($uid*-1)==$modx->documentObject['createdby']) {
              				$comment = str_replace('[+authorclass+]',$authorcss,$comment);
              			}
                          
                          // deal with code tags and bad words
              			foreach($_POST as $n=>$v) {
              				if(!empty($badwords)) $v = preg_replace($badwords,'[Filtered]',$v); // remove badwords
              				$v = $modx->stripTags(htmlspecialchars($v));
              				if($n=='comment' && strpos($v,'')!==false){
              // preserve code
              preg_match_all("|\[code\](.*)\[/code\]|Uis",$v,$matches);
              for ($i=0;$i<count($matches[0]);$i++) {
              $tag = $matches[0][$i];
              $text = $matches[1][$i];
              $v = str_replace($tag,'<pre'.$codecss.'>'.$text.'</pre>',$v);
              }
              }
              $v = str_replace("\r",'',$v);
              $v = str_replace("\n",'
              ',$v);
              $comment = str_replace('[+'.$n.'+]',$v,$comment);
              $name = $context['user']['name'];
              $avatar = $context['user']['avatar']['image'];
              $fid = $context['user']['id'];
              $fprofile = "http://modxcms.com/forums/index.php?action=profile;u=".$fid;
              $comment = str_replace('[+forumuser+]',$name,$comment);
              $comment = str_replace('[+avatar+]',$avatar,$comment);
              $comment = str_replace('[+forumprofile+]',$fprofile,$comment);
              }

              $comment = str_replace($splitter,'',$comment); // remove splitter from comment

              // save comment
              $sql = 'SELECT pagetitle FROM '.$modx->getFullTableName('site_content').' WHERE parent=\''.$folder.'\' AND alias=\''.$alias.'\' LIMIT 1';
              if($modx->db->getValue($sql)) {
              // update comments
              $sql = ' UPDATE '.$modx->getFullTableName('site_content').
              ' SET content = CONCAT(\''.$comment.$splitter.'\',content)'.
              ' WHERE parent=\''.$folder.'\' AND alias=\''.$alias.'\'';
              $modx->db->query($sql);
              }
              else {
              // create new comment page
              $doc = $modx->getDocument($docid);
              $title = mysql_escape_string($doc['pagetitle']).' - User comments';
              $flds = array(
              'pagetitle' => $title,
              'alias' => $alias,
              'parent' => $folder,
              'createdon' => $createdon,
              'createdby' => '0',
              'editedon' => '0',
              'editedby' => '0',
              'published' => '1',
              'deleted' => '0',
              'hidemenu' => '1',
              'template' => '0',
              'content' => $comment.$splitter.'[['.$modx->getSnippetName().'? &hostid=`'.$docid.'`]]'
              );
              $modx->db->insert($flds,$modx->getFullTableName('site_content'));
              if(!empty($makefolder)) {
              // convert parent into folder
              $modx->db->update(array('isfolder'=>'1'),$modx->getFullTableName('site_content'),'id=\''.$folder.'\'');
              }
              }
              }

              default: // display comments
              // check if user has rights to view comments
              if(!$allowAnyView && !$modx->isMemberOfWebGroup($viewgrp)) {
              $comment = '';
              }
              else {

              $uid = $modx->getLoginUserID();

              // get comments
              $ds = $modx->db->select('content',$modx->getFullTableName('site_content'),' parent=\''.$folder.'\' AND alias=\''.$alias.'\'');
              $content = $modx->db->getValue($ds);

              // split content into separate comments
              $parts = explode($splitter,$content);
              array_pop($parts);

              // count comments
              $count = count($parts);
              $modx->setPlaceholder("UserComments.Count",$count);

              // handle recent post
              $offset = 0;
              if($recentposts>0) {
              $parts = array_slice($parts,0,$recentposts);
              $offset = $count-$recentposts;
              $count = $recentposts;
              }

              // prepare comments
              if($sortorder==0) $parts = array_reverse($parts);
              for($i=0;$i<$count;$i++) {
              $part = $parts[$i];
              $num = ($sortorder==1) ? $count-$i:$i+1;
              $part = str_replace('[+postnumber+]',$num+$offset,$part);
              if($altrowcss && ($i % 2)==0) $part = str_replace('[+altrowclass+]',$altrowcss,$part);
              // check for owner's comments
              if($uid && strpos($part,'[+UID:'.$uid.'+]')!==false) $part = str_replace('[+authorclass+]',$ownercss,$part);
              $parts[$i] = $part;
              }

              $comments = implode("",$parts);

              }
              // check if user has rights to post comments


              if(!$allowAnyPost && !$modx->isMemberOfWebGroup($postgrp)) {
              $formTpl = '';
              }
              else if ($context['user']['is_logged']){
              $formTpl = str_replace('[+tagname+]','UserCommentForm'.$tagid,$formTpl);
              }
              if (!$context['user']['is_logged']){$formTpl = 'You must be logged into the forums to comment. Please <a href="/forums/index.php?action=login">login</a>';}
              $troubleshooting = ($debug)? "alias: $alias - folder: $folder - docid: $docid - tag: $tagid":'';
              if ($comments == "") {
              $comments = "No-one has commented on this article yet.";
              }

              // return comments along with form
              return $troubleshooting.$comments.($freeform ? $modx->setPlaceholder('UserComments.Form',$formTpl):$formTpl);
              break;
              }


              Thanks! That helped me along in the right direction.
              • Please make sure to share your solution back here if you don’t mind!
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me