We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32614
    • 65 Posts
    Hello,

    A couple of years ago Mark (of Ditto fame) helped me get my podcast site up and running. He wrote or customized a bunch of snippets and chunks to make my site work. At the time I really didn’t have any idea what all he was doing, but the result was that my site worked perfectly and was easy for me use.

    I believe the stuff he wrote for my site was actually the genesis of Ditto. But it’s not really much like Ditto in it’s current state on my site I don’t think.

    Anyway, recently I decided to update the look of my site, and in the process of updating all of my templates I have discovered just *how* little I know about what Mark did behind the scenes to make my site work the way it did. That is to say: my site is all kinds of broken at this point.

    Mark isn’t really as available to help me this time around, so I was wondering if anyone else might 1) have the know-how; and even more importantly 2) have the kindness in their heart to be willing to help me in his stead?

    You can message me and I can give you the full scoop and all that kind of stuff. I’d be willing to pay someone even to help me. I don’t have loads of cash to drop on it or anything, but I’m pretty desperate and would be open to paying for the help you could maybe offer me.

    Thanks in advance!
      "A great democracy must be progressive, or soon it shall cease to be great, and soon it shall cease to be a democracy." -Theodore Roosevelt
      • 7231
      • 4,205 Posts
      Presentation wise I don’t see much that Ditto could not handle straight up. If you are wanting to wing it I am sure you will receive plenty of help in the forum.
        [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]
        • 32614
        • 65 Posts
        Yeah, I kinda thought that Ditto was probably up to the challenge, but I honestly just don’t have even the faintest idea how to start thinking about using Ditto. Like, I read thru it’s entry on the wiki and on it’s about page, but it’s all basically greek to me. I think I really need someone who can just like, essentially, set it up for me. I know that’s not really what forums are for and no one will likely want to do this. And I know it makes me seem like a loser who isn’t willing to try, but I really don’t have any understanding, fundamentally, of how php coding works. Like at all. I’ve tried to get my head around it several times over the years, but it’s like I have a mental block or something.

        But maybe if someone could tell me where to start, what to do first, etc. the pieces would all fall into place, and the the whole question/answer methodology of the forums would be enough. I’m certainly up for that if I can figure out how to start.

        Thanks for posting even tho I’m probably the most annoying whiny person ever to grace your forums!
          "A great democracy must be progressive, or soon it shall cease to be great, and soon it shall cease to be a democracy." -Theodore Roosevelt
          • 3749
          • 24,544 Posts
          Quote from: wompedy at Jan 26, 2008, 09:21 PM

          Thanks for posting even tho I’m probably the most annoying whiny person ever to grace your forums!

          Not even close laugh

          Can you tell us what version of MODx you have?

          Did you change anything inside the snippet [[ ]] or chunk {{ }} symbols?

          If so, can you find the snippet/chunk calls either in the templates or in the page content that you changed and post them here? They look like this: [[some stuff]] or this: [some stuff!]

          Did you change the actual snippet or chunk content in the Manager?

          If so, can you post the results here?


          Bob

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 32614
            • 65 Posts
            I’m running the latest build of MODx, 0.9.6.1.

            The snippets are almost all customized I believe. And most of them don’t seem to have much in the way of documentation from what I can tell. But I have not changed them much since beginning the upgrade process yesterday.

            A lot of the markup for the site seems to have been commingled into the snippets that make the site work, so I was forced to change some of the snippets just to accommodate the new styling for the site.

            Last night I discovered that I had some double-quotes lurking in the markup I had added to the snippets and when comparing to old version noticed all double-quotes in markup had been switched to single-quotes. This was a bit of a breakthrough and the site works a lot better than it used to now. However there are still issues, and really, I wanted to make the site a little more robust than it’s current framework will allow. So I’m still kinda interested in changing it to run with Ditto.

            Example snippets used on my site:


            <?php
            /*     This one is called with: [[ArchiveLister]]
             *	NewsArchive by Mark Kaplan (October 2005)
             *	Displays an archive of posts with full support for pagination (paging of content in increments)
             *
             *	Version 1.2
             *
             *	Updates:
             *	October 30th 2005 - 1 - FURL detection and support added.
             *	October 30th 2005 - 2 - Increment support added
             *
             *	Based on NewsListing
             *
             *	Always call uncached like so: [!NewsArchive!]
             *
             *	Use the following placeholders for locating the prev/next buttons and other info
             *	[+buttons+] - the previous/next text links
             *	[+start+] - the # of the first item shown
             *	[+limit+] - the # of the last item shown
             *	[+resourcecount+] - the total # of items
             *	
             *	Example:
             *
             *	Showing <strong>[+start+]</strong> - <strong>[+limit+]</strong> of <strong>[+resourcecount+]</strong><br />[+buttons+]
             *
             *  Snippet parameters [default] :
             *      &startID       - the folder containing the posts [the document called from]
             *      &total         - max number of posts to retrieve [100] 
             *
             *		&increment	   - # of items to advance by each time the previous or next links are clicked [10]
             *      &trunc         - truncate to summary posts? if set to false, shows entire post [true]
             *      &truncSplit    - use the special "splitter" format to truncate for summary posts [true]
             *      &truncAt       - the split-point splitter itself [<!-- splitter -->]
             *      &truncText     - text for the summary "show more" link
             *                     
             *                     
             *      &tpl           - name of the chunk to use for the summary view template
             *      &dateformat    - the format for the summary date (see http://php.net/strftime ) [%d-%b-%y %H:%M]
             *      &pubOnly       - only show Published posts [true]
             *      &emptytext     - text to use when no news items are found
             *		&commentschunk - if you're using comments, the name of the chunk used to format them
             *      
             */
             
            $furls = $modx->config['friendly_urls'];
            	// are furls enabled
            	
            $limit = isset($increment)? $limit : 70;
            	// sey # of items to advance by each time the previous or next links are clicked
            	
            $resourceparent = isset($startID) ? $startID : $modx->documentIdentifier;
                // the folder that contains post entries 
                
            $nrtotal = isset($total) ? $total : 100;
                // total number of posts to retrieve 
            
            $trunc = isset($truc) ? $trunc : true;
                // should there be summary/short version of the posts?
            
            $truncsplit = isset($trucSplit) ? $truncSplit : true;
                // should the post be summarized at the "splitter"?
            
            $splitter = isset($trucAt) ? $truncAt : "<!-- splitter -->";
                // where to split the text 
            
            
            $tpl = isset($tpl) ? $modx->getChunk($tpl):'
                <div class="summaryPost">
                    <h3>[+title+]</h3>
                    <div>[+summary+]</div>
                    <p>    [+link+]</p>
                    <div style="text-align:right;">by <strong>[+author+]</strong> on [+date+]</div>
                </div>
            ';
                // optional user defined chunk name to format the summary posts
            	
            $showPublishedOnly = isset($pubOnly) ? $pubOnly : true;
                // allows you to show unpublished docs if needed for some reason...
                
            $linktext = isset($truncText)? $truncText : "More on this story >";
                // text to be displayed in news link
            
            $emptytext = isset($emptytext)? $emptytext : '<p>No entries found.</p>';
                // text to be displayed when there are no results
            
            $comments = isset($comments)? $comments : false;
                // can the posts have comments?
            
            $commText = isset($commText)? $commText : 'Comments';
                // text to be used for the comments link
            	
            $start= $_GET['start']? $_GET['start']: 0;
            
            $commentschunk = isset($commentschunk)? '{{'.$commentschunk.'}}' : '';
                // if you're using comments, the name of the chunk used to format them
            
            $date = isset($dateformat)? $dateformat :"%d-%b-%y %H:%M";
                // format for the summary post date format
            
            $output = '';
                // initialize the blog variable 
            
            $callby = ($showPublishedOnly)? 'getActiveChildren' : 'getAllChildren';
            
            $resource = $modx->$callby($resourceparent, 'createdon', 'DESC', $fields='id, pagetitle, description, introtext, content, createdon, createdby, hidemenu, alias');
            $resourcecount = count($resource);
            
            $output .= ($resourcecount < 1)? $emptytext."\n" : '';  
            
            // function used to clean all the open HTML tags inside summary posts
            // useful so it won't break layouts due to there being open tags like 
            // OL, UL, DIV, H1 or maybe even A tags for example
            function endtags($text) { 
                $openPattern = "/<([^\/].*?)>/";   
                $closePattern = "/<\/(.*?)>/"; 
                $endOpenPattern = "/<([^\/].*?)$/"; 
                $endClosePattern = "/<(\/.*?[^>])$/"; 
                $endTags=''; 
                 
                preg_match_all($openPattern,$text,$openTags); 
                preg_match_all($closePattern,$text,$endtags); 
                
                
                $c=0; 
                $loopCounter = count($endtags[1]);  //used to prevent an infinite loop if the html is malformed 
                while($c<count($endtags[1]) && $loopCounter) { 
                    $i=0; 
                    while($i<count($openTags[1])) { 
                         
                        $tag = trim($openTags[1][$i]); 
                         
                        if(strstr($tag,' ')) { 
                            $tag = substr($tag,0,strpos($tag,' '));    
                        } 
                        //echo $tag.'=='.$endtags[1][$c]."\n"; 
                        if($tag==$endtags[1][$c]) { 
                            $openTags[1][$i]=''; 
                            $c++; 
                            break; 
                        }    
                        $i++; 
                    } 
                    $loopCounter--; 
                } 
                 
                $results = $openTags[1]; 
                 
                if(is_array($results)) {  
                $results = array_reverse($results); 
                     
                    foreach($results as $tag) { 
                
                        $tag = trim($tag); 
                         
                        if(strstr($tag,' ')) { 
                            $tag = substr($tag,0,strpos($tag,' '));    
                        }    
                        if(!stristr($tag,'br') && !stristr($tag,'img') && !empty($tag)) { 
                            $endTags.= '</'.$tag.'>'; 
                        } 
                    }    
                } 
                return $text.$endTags; 
            }
            
            
            if ($resourcecount > 0) { 
            	
            	if ($furls == 0){
            		$char = "&";
            	}else if($furls == 1){
            		$char = "?";
            	}
            	$currentpageid = $modx->documentObject['id'];
            	$next = $start + $limit;
            	$nextlink = "";
            	$previous = $start - $limit;
            	$previouslink = "";
            	$limten = $limit + $start;
            	
            	if ($previous > -1 && $next < $resourcecount){
            			$buttons = $previouslink.$nextlink;
            		}
            		else if ($previous > -1) {
            			$buttons = $previouslink;
            		}		
            
            		else if ($next < $resourcecount) {
            			$buttons = $nextlink;
            		}
            		else if ($start < $resourcecount) {
            			$limit = $limten;
            		}
            	
            	if ($limten > $resourcecount){
            		$limiter = $resourcecount;
            	} else {$limiter = $limten;}
            	
            	$modx->setPlaceholder('buttons',$buttons);
            	$modx->setPlaceholder('start',$start+1);
            	$modx->setPlaceholder('limit',$limiter);
            	$modx->setPlaceholder('resourcecount',$resourcecount);
            	
            	if ($start < $resourcecount) {
            			$limit = $limten;
            		}else if ($limit > $resourcecount){
            			$die = ture;
            		}
            
            	for ($x = $start; $x < $limit; $x++) { 
            		if ($x >= $resourcecount) {
            		$die = ture;		
            		}
            
            		if ($resource[$x]['createdby']<0) {
            			// get web user name
            			$tbl = $modx->getFullTableName("web_users");
            			$sql = "SELECT username FROM $tbl WHERE $tbl.id = '".abs($resource[$x]['createdby'])."'"; 
            		}
            		else {
            			// get manager user name
            			$tbl = $modx->getFullTableName("manager_users");
            			$sql = "SELECT username FROM $tbl WHERE $tbl.id = '".$resource[$x]['createdby']."'";
            		}
            
                    //perform the query
            		$rs2 = $modx->dbQuery($sql);
            		$limit2 = $modx->recordCount($rs2); 
            		if($limit2<1) { 
            			$username = "anonymous"; 
            		}
            		else { 
            			$resourceuser = $modx->fetchRow($rs2); 
            			$username = $resourceuser['username']; 
            		} 
            		// determine and show summary
            		
            		// summary is turned off
            		if (!$trunc) {
            		    $summary = $resource[$x]['content']; 
            		    
            		// contains the splitter and use splitter is on
            		} else if ((strstr($resource[$x]['content'], $splitter)) && $truncsplit) {
                        $summary = array();
                        
                        // HTMLarea/XINHA encloses it in paragraph's
                        $summary = explode('<p>'.$splitter.'</p>',$resource[$x]['content']);
                        
                        // For TinyMCE or if it isn't wrapped inside paragraph tags
                        $summary = explode($splitter,$summary['0']); 
            
                        $summary = $summary['0'];
                        $summary = endtags($summary);
                        
                    // fall back to the summary text    
            		} else if (strlen($resource[$x]['introtext'])>0) {
            			$summary = $resource[$x]['introtext'];
            			
            		// fall back to the summary text count	
            		// skipping this because of ease of breaking in the middle of an A tag... 
            		// so it's not a good idea. If you must have this, then uncomment
            		// } else if(strlen($resource[$x]['content']) > $lentoshow) { 
            		// 	$summary = substr($resource[$x]['content'], 0, $lentoshow).'...'; 
            		//
            		
            		// and back to where we started if all else fails (short post)
            		} else { 
            			$summary = $resource[$x]['content']; 
            		}  
            		
            		$summary = str_replace($commentschunk,'',$summary);
             
                    // add the link to the full post (permalink)
                    $link = '<a href="[~'.$resource[$x]['id'].'~]">'.$linktext.'</a>';
            		
            		$fields = array('[+title+]','[+summary+]','[+link+]','[+author+]','[+date+]','[+id+]','[+alias+]');
            		$values = array($resource[$x]['pagetitle'],$summary,$link,$username,strftime($date, $resource[$x]['createdon']),$resource[$x]['id'],$resource[$x]['alias']);
            		
            		if ($die != true) {$output .= str_replace($fields,$values,$tpl);} 
            		
            	} 
            }
            
            return $output;
            ?>


            Another example:
            <?php
            //
            // **************************
            // Snippet: PrevNext
            // By: Jeroen Bosch
            // Date: februari 2005
            // for: Etomite 0.6
            // version: 0.9
            // **************************
            //
            // Function:
            // Generates a simple previous and next button. very
            // handy on top or bottom of each individual newspost/log item
            // Highly configurable. It can display document titles
            // and add 'first' and 'last' to the options.
            //
            // You can set every option with the snippet call.
            // example:
            
            // [[PrevNext?sortBy=menuindex&sortHow=ASC&displayTitle=true]]
            
            
            # Settings
            
            # Sort items by? 'menuindex' or 'id' or 'createdon'
            if(!isset($sortBy)){
            $sortBy = 'createdon'; // default in NewsListing-snippet
            }
            
            # Sort items How? 'ASC' or 'DESC'
            if(!isset($sortHow)){
            $sortHow = 'ASC'; // default in NewsListing-snippet
            }
            
            # Show 'prev' and 'next' or display document titles?
            if(!isset($displayTitle)){
            $displayTitle = false;
            }
            
            # Show 'first' and 'last'
            if(!isset($displayFixed)){
            $displayFixed = false;
            }
            
            // The code:
            
            // Get the parent ID
            $parentid = $etomite->documentObject['parent']; // maybe this solves it all, but I'm not sure.
            
            // (re)set the $id variable to the one of this document.
            $id = $etomite->documentIdentifier;
            
            // select the other members in this folder -- See: NOTE 1
            $fields='id,pagetitle,isfolder'; // what fields do you want to know
            $children = $etomite->getActiveChildren($parentid, $sortBy, $sortHow, $fields);
            
            // the number of selected documents
            //$limit = $etomite->recordCount($children);
            $limit = count($children);
            
            // set $y to zero
            $y = 1;
            
            // sorting the documents, giving them a sequential and searchable index
            foreach ($children as $child) {
            $my_array[$y] = $child;
            if ($my_array[$y]['id']==$id)
            {
            $current=$y; // The current page has number $y in the array
            }
            $y++;
            }
            
            $prev = $current-1;
            $next = $current+1;
            
            // Here starts the output
            $output = "";
            $output .= "<div class='PrevNextMenu'>";
            
            if($displayFixed==true) {
            $output .= "< <a href='[~".$my_array[1]['id']."~]'>first</a> ‌ ";
            }
            else {
            $output .= "";
            }
            
            if($prev > 0 && $displayTitle==false){
            $output .= " <span class='footerRecent'><a href='[~".$my_array[$prev]['id']."~]'><img src='assets/images/1x1.gif' width='1' height='1' border='0' /></a></span> ";
            }
            elseif($prev > 0 && $displayTitle==true){
            $output .= " <a href='[~".$my_array[$prev]['id']."~]'>".$my_array[$prev]['pagetitle']."</a> ";
            }
            
            if($next <= $limit && $displayTitle==false){
            $output .= " <span class='footerPrevious'><a href='[~".$my_array[$next]['id']."~]'><img src='assets/images/1x1.gif' width='1' height='1' border='0' /></a></span> ";
            }
            elseif($next <= $limit && $displayTitle==true) {
            $output .=" <a href='[~".$my_array[$next]['id']."~]'>".$my_array[$next]['pagetitle']."</a> ";
            }
            
            if($displayFixed==true) {
            $output .= " ‌ <a href='[~".$my_array[$limit]['id']."~]'>last</a> >";
            }
            else {
            $output .= " ";
            }
            
            $output .= "</div>";
            $output .= "";
            
            return $output;
            ?>


            There is also another snippet which is a lot like the "[[ArchiveLister]]" one, but slightly different used on the home page, rather than on sub-pages.

            the site in question here, by the way, is http://www.thesoundsinmyhead.com/

            Thanks to both of you for your help so far!
              "A great democracy must be progressive, or soon it shall cease to be great, and soon it shall cease to be a democracy." -Theodore Roosevelt
              • 3749
              • 24,544 Posts
              This looks like a mistake that might be causing some trouble (trunc is misspelled as truc three times here):

              $trunc = isset($truc) ? $trunc : true;
                  // should there be summary/short version of the posts?
              
              $truncsplit = isset($trucSplit) ? $truncSplit : true;
                  // should the post be summarized at the "splitter"?
              
              $splitter = isset($trucAt) ? $truncAt : "<!-- splitter -->";


              Can you post the actual ArchiveLister snippet call in the template?

              BTW, if you don’t know PHP at all, re-writing actual snippet code is like playing catch with a live rattlesnake wink

              Bob
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 32614
                • 65 Posts
                You know, I don’t think the "ArchiveLister" snippet itself is actually use anywhere. There are a number of modified versions of it, but I don’t think the original is actually called anywhere. Here are some more snippets from the site tho:

                This one is "EpisodeListing"
                <?php
                $resourceparent = isset($newsid) ? $newsid : $modx->documentIdentifier;
                         // the folder that contains blog entries 
                $output = '';
                         // initialise the blog variable 
                $nrblogs = 3;
                         // nr of blogs to show a short portion of 
                $nrblogstotal = 100;
                         // total nr of blogs to retrieve 
                $lentoshow = 150;
                         // how many characters to show of blogs 
                
                $resource = $modx->getActiveChildren($resourceparent, 'createdon', 'DESC', $fields='id, pagetitle, description, introtext, content, createdon, createdby');
                $limit=count($resource);
                if($limit<1) { 
                   $output .= "No entries found.<br />"; 
                } 
                $nrblogs = $nrblogs<$limit ? $nrblogs : $limit; 
                if($limit>0) { 
                	for ($x = 0; $x < $nrblogs; $x++) { 
                		if ($resource[$x]['createdby']<0) {
                			// get web user name
                			$tbl = $modx->getFullTableName("web_users");
                			$sql = "SELECT username FROM $tbl WHERE $tbl.id = '".abs($resource[$x]['createdby'])."'"; 
                		}
                		else {
                			// get manager user name
                			$tbl = $modx->getFullTableName("manager_users");
                			$sql = "SELECT username FROM $tbl WHERE $tbl.id = '".$resource[$x]['createdby']."'"; 
                		}
                		$rs2 = $modx->dbQuery($sql);
                		$limit2 = $modx->recordCount($rs2); 
                		if($limit2<1) { 
                			$username = "anonymous"; 
                		}
                		else { 
                			$resourceuser = $modx->fetchRow($rs2); 
                			$username = $resourceuser['username']; 
                		} 
                		// show summary
                			$rest = $resource[$x]['content']; 
                		$output .= "<div class="episode">
                    	<div class="episodeTopOld"><div class='albums'><img src='http://www.thesoundsinmyhead.com/assets/images/albums/[+alias+]_1.jpg' width='71' height='71' /><img src='http://www.thesoundsinmyhead.com/assets/images/albums/[+alias+]_3.jpg' width='71' height='71' /><img src='http://www.thesoundsinmyhead.com/assets/images/albums/[+alias+]_2.jpg' width='71' height='71' /><img src='http://www.thesoundsinmyhead.com/assets/images/albums/[+alias+]_4.jpg' width='71' height='71' /></div>
                    	".$resource[$x]['pagetitle']."<br />".strftime("%A, %B %d, %Y", $resource[$x]['createdon'])."</a>
                        </div>
                <div class="episodeContent">".$rest."<div class="clear"></div></div>
                        <div class="episodeBottom"><span class="subscribe"><a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=259654789"></a></span><a href="index.php?id=".$resource[$x]['id']."">Permalink</a></div>
                  </div>";
                
                	} 
                } 
                
                if($limit>$nrblogs) { 
                   $output .= "<br /><br /><b>Older news</b><br />"; 
                   for ($x = $nrblogs; $x < $limit; $x++) { 
                      $output .= "> <a href='[~".$resource[$x]['id']."~]'>".$resource[$x]['pagetitle']."</a><br />";          
                   } 
                }
                
                return $output;
                ?>


                This one is "NewsListing" (but note that I don’t think it’s actually used anywhere):
                <?php
                /**
                 * Snippet Name: NewsListing
                 * Short Desc: Displays News Articles and Blog Posts
                 * Created By: The MODx Project
                 * Version: 4.4
                 * 
                 * Displays posts with full support for pagination (paging of content in increments) and Template Variables
                 *
                 * Important Notes
                 *	When in pagination mode (&paginate = 1) always call the snippet uncached in the [!NewsListing!] format
                 *	Also, in pagination mode, make sure to use the placeholders for navigation!
                 *	To display tv's make sure you use the tv prefix! 
                 *	For example, if you have the template variable author you would put [+tvauthor+] in your template.
                 *
                 * Snippet placeholders:
                 *		[+next+] - next button
                 *		[+previous+] - previous button
                 *		[+prevnextsplitter+] - splitter if always show is 0
                 *		[+pages+] - page list
                 *		[+totalpages+] - total number of pages
                 *		[+start+] - the # of the first item shown
                 *		[+stop+] - the # of the last item shown
                 *		[+total+] - the total # of items
                 *
                 * Example of placeholder use:
                 *		Showing <strong>[+start+]</strong> - <strong>[+stop+]</strong> of <strong>[+total+]</strong> Articles<br /><div id="nl_pages">[+previous+] [+pages+] [+next+]</div>
                 *
                 * Example CSS:
                 *		<style type="text/css">
                 *		#nl_pages {margin-top: 10px;}
                 *		#nl_pages #nl_currentpage {border: 1px solid blue;padding: 2px; margin: 2px; background-color: rgb(90, 132, 158); color: white;}
                 *		#nl_pages .nl_off {border: 1px solid #CCCCCC; padding: 2px; margin: 2px}
                 *		#nl_pages a {border: 1px solid rgb(203, 227, 241);; padding: 2px; margin: 2px; text-decoration: none; color: black;}
                 *		#nl_pages a:hover {border: 1px solid #000066; background-color: white; }
                 *		#nl_archivelist ul{list-style-type: none; margin-left: 15px; padding-left: 0px;}
                 *		#nl_archivelist ul ul{list-style-type: square;margin-left: 	35px;}
                 *		.nl_month {font-weight: bold;}
                 *		</style>
                 *
                 *  Snippet parameters [default] :
                 *      &startID       - the folder containing the posts [the document called from]
                 *      &paginate      - paginate [0]
                 *      &prv		   - chunk to be used inside the previous link ["< Previous"]
                 *      &nxt		   - chunk to be used inside the next link ["Next >"]
                 *      &alwaysshow    - always show previous or next links (if enabled, hyperlink will be removed when prev/next page is not available, | delimiter will not be inserted) [0]
                 *      &prevnextsplitter        - character delimiter to use to separate previous next links if alwaysshow is 0  ["|"]
                 *      &summarize     - number of posts to list partially/fully [3]
                 *      &total         - max number of posts to retrieve [all posts] 
                 *      &increment     - # of items to advance by each time the previous or next links are clicked [10] 
                 *      &trunc         - truncate to summary posts? if set to false, shows entire post [true]
                 *      &truncSplit    - use the special "splitter" format to truncate for summary posts [true]
                 *      &truncAt       - the split-point splitter itself [<!-- splitter -->]
                 *      &truncText     - text for the summary "show more" link
                 *      &truncLen      - number of characters to show in the doc summary [300]
                 *      &truncOffset   - negative offset to use to fall back when splitting mid-open tag [30]
                 *                     
                 *      &comments      - whether or not the posts have comments [false]  
                 *      &commText      - comments link text ["Read Comments"]  
                 *                     
                 *      &tpl           - name of the chunk to use for the summary view template  
                 *      &dateformat    - the format for the summary date (see http://php.net/strftime ) [%d-%b-%y %H:%M]
                 *      &datetype      - the date type to display (values can be createdon, pub_date, editedon) [&sortby | "createdon"]
                 *      &pubOnly       - only show Published posts [true]
                 *      &emptytext     - text to use when no news items are found
                 *      &showarch      - show archive listing? [true]
                 *      &archplaceholder -output archive (older posts section) as a placeholder called archive [0]
                 *      &archivetext   - text to use for the Post Archives listing ["Older Items"]
                 *      &commentschunk - if you're using comments, the name of the chunk used to format them
                 *      &sortby        - field to sort by (reccomended values include createdon, pub_date, editedon; reverts to createdon if value is invalid) ["createdon"]
                 *      &sortdir       - direction to sort by ["desc"]
                 *      &debug	       - enables debug output [0]
                 * 
                 *  Modified by Mark Kaplan, Susan Ottwell, Raymond Irving, Greg Matthews and Ryan Thrash:
                 *	10-Dec-2005 restored ability to split after N charcacters without splitting inside an open tag (such as img, a href, etc.)
                 *	06-Dec-2005 added xhtml strict month based archives, added nl_ prefix to all styles, minor fixes and documentation cleanup
                 *	05-Dec-2005 added support for pages and TVs!
                 *	03-Dec-2005 added pagination from NewsArchive (Mark)
                 *	01-Dec-2005 cleaned up code and parameters for 0.9.1 release and improved debug code (Mark)
                 *	25-Nov-2005 added multisort capabilities (Jason/Mark)
                 *	25-Nov-2005 added ability to call useful parts of the document object in a template via [+documentobject+] (Mark)
                 *	24-Nov-2005 added [+longtitle+] by Paul
                 *	11-Nov-2005 showarch added
                 *	04-Nov-2005 various improvements and bugfixes
                 *	21-Oct-2005 footer/header removed from summaries
                 *	12-Oct-2005 malformed tag-closing mojo and more cleanups
                 *	11-Oct-2005 many updates inc. showPublishedOnly, summary splitter, configs and default template format
                 *	22-Sept-2005 add &linktext support
                 *	22-Sept-2005 add template support. Fields - [+title+],[+summary+],[+author+],[+date+],[+link+]
                 *	19-April-2005 add introtext field support
                 *
                 *
                 *  To Do: 
                 *      comment counts where applicable
                 *      evaluate date formats/server offsets
                 *      query optimizations
                 *      show in menu if needed ?
                 *
                 *  Credits:
                 *      Now "goes to eleven" thanks to Mark Kaplan 
                 *      Month archives based on code from the "event-list" snippet by kastor
                 *      Enhancements by Raymond Irving, Ryan Thrash and tag-closing mojo by Greg Matthews 
                 *      Original code by Alex with improvements by LePrince, mrruben5, lloyd_barrett
                 */
                 
                $paginate = isset($paginate)? $paginate : 0;
                	// paginatation enabled or disabled
                
                $furls = $modx->config['friendly_urls'];
                	// are furls enabled
                	
                $resourceparent = isset($startID) ? $startID : $modx->documentIdentifier;
                    // the folder that contains post entries 
                
                $nrposts = isset($summarize) ? $summarize : 3;
                    // number of posts of which to show a summary 
                    // remainder (to nrtotal) go as an arhived/other posts list
                         
                $trunc = isset($trunc) ? $trunc : true;
                    // should there be summary/short version of the posts?
                
                $truncsplit = isset($truncSplit) ? $truncSplit : true;
                    // should the post be summarized at the "splitter"?
                
                $splitter = isset($truncAt) ? $truncAt : "<!-- splitter -->";
                    // where to split the text 
                
                $lentoshow = isset($truncLen) ? $truncLen : 300;
                    // how many characters to show of blogs 
                
                $lenoffset = isset($truncOffest) ? $truncOffset : 30;
                    // how many characters to show of blogs 
                
                $tpl = isset($tpl) ? $modx->getChunk($tpl):'
                    <div class="nl_summaryPost">
                        <h3><a href="[~[+id+]~]">[+title+]</a></h3>
                        <div>[+summary+]</div>
                        <p>[+link+]</p>
                        <div style="text-align:right;">by <strong>[+author+]</strong> on [+date+]</div>
                    </div>
                ';
                    // optional user defined chunk name to format the summary posts
                
                $showPublishedOnly = isset($pubOnly) ? $pubOnly : true;
                    // allows you to show unpublished docs if needed for some reason...
                
                $showInMenuOnly = isset($menuOnly) ? $menuOnly : true;
                    // allows you to show docs marked not to show in the menus 
                    // if needed for some reason...
                    // TO BE IMPLEMENTED
                    
                $linktext = isset($truncText)? $truncText : "More on this story...";
                    // text to be displayed in news link
                
                $emptytext = isset($emptytext)? $emptytext : '<p>No entries found.</p>';
                    // text to be displayed when there are no results
                
                $comments = isset($comments)? $comments : false;
                    // can the posts have comments?
                
                $commText = isset($commText)? $commText : 'Comments';
                    // text to be used for the comments link
                
                $date = isset($dateformat)? $dateformat :"%d-%b-%y %H:%M";
                    // format for the summary post date format
                	
                $showarch = isset($showarch)? $showarch : true;
                  // whether or not to show the Post Archives listing
                
                $archtxt = isset($archivetext)? $archivetext :"Older Items";
                    // text to use for the Post Archives listing
                
                $commentschunk = isset($commentschunk)? '{{'.$commentschunk.'}}' : '';
                    // if you're using comments, the name of the chunk used to format them
                
                $sortdir = isset($sortdir) ? strtoupper($sortdir) : 'DESC';
                    // get sort dir
                
                if (isset($sortby) && ($sortby == "createdon" || $sortby == "editedon" || $sortby == "pub_date" || $sortby == "unpub_date" || $sortby =="deletedon")) {
                	$dt = $sortby;
                } else if (isset($datetype)) {
                	$dt = $datetype;
                } else {
                	$dt = "createdon";
                }
                
                $datetype = $dt;
                	// date type to display (values can be createdon, pub_date, editedon)	
                	
                $start= isset($_GET['start'])? $_GET['start']: 0;
                	// get post # to start at
                
                $debug = isset($debug)? $debug : 0;
                    // for testing only
                
                $output = '';
                    // initialize the output variable 
                	
                $debugtext = '';
                    // initialize the debugtext variable 
                
                $prv = isset($prv)? $modx->getChunk($prv) : "< Previous";
                	// get the chunk code to be used inside the previous <a> tag.
                    
                $nxt = isset($nxt)? $modx->getChunk($nxt) : "Next >";
                	// get the chunk code to be used inside the next <a> tag.
                
                $alwaysshow = isset($alwaysshow)? $alwaysshow : 0;
                	// determine whether or not to always show previous next links
                
                $archplaceholder = isset($archplaceholder)? $archplaceholder : 0;
                	// output archive (older posts section) as a placeholder called [+archive+]
                	
                $prevnextsplitter = isset($prevnextsplitter)? $prevnextsplitter : "|";
                	// splitter to use of always show is disabled
                	
                // Check for valid field to sort by
                	
                $columns = $modx->db->query("show columns from ".$modx->getFullTableName('site_content'));
                while($dbfield = $modx->db->getRow($columns))
                   $dbfields[] = $dbfield['Field'];
                if(isset($sortby) && in_array($sortby,$dbfields)) {
                   $sortby = $sortby;
                } else {
                   $sortby = "createdon";
                }
                
                if ($sortby != 	"pub_date" && $sortby != "unpub_date" && $sortby != "editedon" && $sortby != "deletedon") {
                
                // API Method (allows for everything except pub_date, unpub_date, editedon, deletedon)
                	$debugtext = "Using the API Method (allows for everything except pub_date, unpub_date, editedon, deletedon) <br />";
                	$callby = ($showPublishedOnly)? 'getActiveChildren' : 'getAllChildren';
                	$resource = $modx->$callby($resourceparent, $sortby, $sortdir, $fields='*');
                	
                } else {
                
                // SQL Method (alows for all possibilites but is slower)
                	$debugtext = "Using the SQL Method (alows for all possibilites but is slower) <br />";
                	$tblContent= $modx->db->config['table_prefix'] . 'site_content';
                	$activeClause= $showPublishedOnly? 'AND published = 1': ''; 
                	$query= "SELECT id , type , contentType , pagetitle , longtitle , description , alias , published , IF(pub_date > 0, pub_date, createdon) as pub_date, IF(unpub_date > 0, unpub_date, createdon) as unpub_date , parent , isfolder , introtext , content , richtext , template , menuindex , searchable , cacheable , createdby , createdon, editedby , IF(editedon > 0, editedon, createdon) as editedon, deleted , IF(deletedon > 0, deletedon, createdon) as deletedon, deletedby , menutitle , donthit , haskeywords , hasmetatags , privateweb , privatemgr , content_dispo , hidemenu  FROM $tblContent WHERE parent = $resourceparent $activeClause ORDER BY $sortby $sortdir";
                	
                	if (!$rs= $modx->db->query($query)) {
                		return '';
                	}
                	while ($row= $modx->db->getRow($rs)) {
                		$resource[]= $row;
                	}
                }
                
                $recordcount = count($resource);
                $output .= ($recordcount < 1)? $emptytext."\n" : '';  
                
                $nrtotal = isset($total) ? $total : $recordcount;
                    // total number of posts to retrieve 
                	
                $limit = min( $recordcount, $nrtotal ); 	
                
                if ($recordcount < $nrposts)
                {
                	$stop = $recordcount;
                } else {
                	$stop = $nrposts;
                }
                
                if ($nrtotal > $recordcount) {$nrtotal = $recordcount;}
                
                if ($debug == 1) {
                	// rudimentary debugging output
                	$output .= "Number supposed to be summarized (nrposts/count): $nrposts<br />Total supposed to be returned: $stop<br />Count of total in db (count): $recordcount<br />Sort by (sortby): $sortby <br />Sort direction (sortdir): $sortdir <br/ >$debugtext";
                }
                
                // function used to clean all the open HTML tags inside summary posts
                // useful so it won't break layouts due to there being open tags like 
                // OL, UL, DIV, H1 or maybe even A tags for example
                if(!function_exists('html_substr')) {
                
                	function html_substr($posttext, $minimum_length, $length_offset) {
                	   // The approximate length you want the concatenated text to be
                	   // $minimum_length = 200;
                	   // The variation in how long the text can be
                	   // in this example text length will be between 200-20=180 characters
                	   // and the character where the last tag ends
                	   // $length_offset = 20;
                	   // Reset tag counter & quote checker
                	   $tag_counter = 0;
                	   $quotes_on = FALSE;
                	   // Check if the text is too long
                	   if (strlen($posttext) > $minimum_length) {
                	       // Reset the tag_counter and pass through (part of) the entire text
                	       for ($i = 0; $i < strlen($posttext); $i++) {
                	           // Load the current character and the next one
                	           // if the string has not arrived at the last character
                	           $current_char = substr($posttext,$i,1);
                	           if ($i < strlen($posttext) - 1) {
                	               $next_char = substr($posttext,$i + 1,1);
                	           }
                	           else {
                	               $next_char = "";
                	           }
                	           // First check if quotes are on
                	           if (!$quotes_on) {
                	               // Check if it's a tag
                	               // On a "<" add 3 if it's an opening tag (like <a href...)
                	               // or add only 1 if it's an ending tag (like </a>)
                	               if ($current_char == "<") {
                	                   if ($next_char == "/") {
                	                                       $tag_counter++;
                	                   }
                	                   else {
                	                       $tag_counter = $tag_counter + 3;
                	                   }
                	               }
                	               // Slash signifies an ending (like </a> or ... />)
                	               // substract 2
                	               if ($current_char == "/") $tag_counter = $tag_counter - 2;
                	               // On a ">" substract 1
                	               if ($current_char == ">") $tag_counter--;
                	               // If quotes are encountered, start ignoring the tags
                	               // (for directory slashes)
                	               if ($current_char == "\"") $quotes_on = TRUE;
                	           }
                	           else {
                	               // IF quotes are encountered again, turn it back off
                	               if ($current_char == "\"") $quotes_on = FALSE;
                	           }
                
                	           // Check if the counter has reached the minimum length yet,
                	           // then wait for the tag_counter to become 0, and chop the string there
                	           if ($i > $minimum_length - $length_offset && $tag_counter == 0) {
                	               $posttext = substr($posttext,0,$i + 1) . "...";
                	               return $posttext;
                	           }
                	       }
                	   }
                	             return $posttext;
                	}
                
                
                }
                // function used to clean all the open HTML tags inside summary posts
                // useful so it won't break layouts due to there being open tags like 
                // OL, UL, DIV, H1 or maybe even A tags for example
                if(!function_exists('closeTags')) {
                	function closeTags($text) {
                		global $debug;
                	    $openPattern = "/<([^\/].*?)>/";   
                	    $closePattern = "/<\/(.*?)>/"; 
                	    $endOpenPattern = "/<([^\/].*?)$/"; 
                	    $endClosePattern = "/<(\/.*?[^>])$/"; 
                	    $endTags=''; 
                     
                	    preg_match_all($openPattern,$text,$openTags); 
                	    preg_match_all($closePattern,$text,$closeTags); 
                    
                	    if ($debug == 1) {
                	        print_r($openTags); 
                	        print_r($closeTags); 
                	    }
                    
                	    $c=0; 
                	    $loopCounter = count($closeTags[1]);  //used to prevent an infinite loop if the html is malformed 
                	    while($c<count($closeTags[1]) && $loopCounter) { 
                	        $i=0; 
                	        while($i<count($openTags[1])) { 
                	            $tag = trim($openTags[1][$i]); 
                             
                	            if(strstr($tag,' ')) { 
                	                $tag = substr($tag,0,strpos($tag,' '));    
                	            } 
                	            if ($debug == 1) { echo $tag.'=='.$closeTags[1][$c]."\n"; } 
                	            if($tag==$closeTags[1][$c]) { 
                	                $openTags[1][$i]=''; 
                	                $c++; 
                	                break; 
                	            }    
                	            $i++; 
                	        } 
                	        $loopCounter--; 
                	    } 
                     
                	    $results = $openTags[1]; 
                     
                	    if(is_array($results)) {  
                	    $results = array_reverse($results); 
                         
                	        foreach($results as $tag) { 
                	            $tag = trim($tag); 
                             
                	            if(strstr($tag,' ')) { 
                	                $tag = substr($tag,0,strpos($tag,' '));    
                	            }    
                	            if(!stristr($tag,'br') && !stristr($tag,'img') && !empty($tag)) { 
                	                $endTags.= '</'.$tag.'>'; 
                	            } 
                	        }    
                	    } 
                	    return $text.$endTags; 
                	}
                } // end if function exists
                
                if ($nrposts > 0) { 
                
                	// Start Pagination
                	if ($paginate == 1) {
                		if ($furls == 0) {
                			$char = "&";
                		} else if($furls == 1) {
                			$char = "?";
                		}
                		$currentpageid = $modx->documentObject['id'];
                		$next = $start + $nrposts;
                
                		$nextlink = "<a href='[~$currentpageid~]".$char."start=$next'>".$nxt."</a>";
                		$previous = $start - $nrposts;
                		$previouslink = "<a href='[~$currentpageid~]".$char."start=$previous'>".$prv."</a>";
                		$limten = $nrposts + $start;
                		if ($alwaysshow == 1) {
                			$previousplaceholder = "<span class='nl_off'>".$prv."</span>";
                			$nextplaceholder = "<span class='nl_off'>".$nxt."</span>";
                		} else {
                			$previousplaceholder = "";
                			$nextplaceholder = "";
                		}
                		$split = "";
                		if ($previous > -1 && $next < $nrtotal) $split = $prevnextsplitter;
                		if ($previous > -1) $previousplaceholder = $previouslink;
                		if ($next < $nrtotal) $nextplaceholder = $nextlink;
                		if ($start < $nrtotal) $stop = $limten;
                		if ($limten > $nrtotal){$limiter = $nrtotal;} else {$limiter = $limten;}
                	
                		$totalpages=ceil($nrtotal/$nrposts);
                	
                		for ($x=0; $x<=$totalpages-1; $x++) {
                			$inc = $x * $nrposts;
                			$display = $x+1;
                			if($inc != $start) {
                				$pages .= "<a class=\"nl_page\" href='[~$currentpageid~]".$char."start=$inc'>$display</a>";
                			} else {
                				$pages .= "<span id=\"nl_currentpage\">$display</span>";
                			}	
                		}
                
                		$modx->setPlaceholder('next',$nextplaceholder);
                		$modx->setPlaceholder('previous',$previousplaceholder);
                		$modx->setPlaceholder('prevnextsplitter',$split);
                		$modx->setPlaceholder('start',$start+1);
                		$modx->setPlaceholder('stop',$limiter);
                		$modx->setPlaceholder('total',$nrtotal);
                		$modx->setPlaceholder('pages',$pages);
                		$modx->setPlaceholder('totalpages',$totalpages);	
                
                		if ($start < $nrtotal) $stop = $limten;
                	}
                	// End Pagination
                	
                	if ($debug == 1) $output .= "Start at $start and stop at $stop (stop)/$nrtotal (total)";
                	for ($x = $start; $x < $stop; $x++) { 
                		if ($x <= $nrtotal && $x <= $nrtotal-1) {
                		if ($resource[$x]['createdby']<0) {
                			// get web user name
                			$tbl = $modx->getFullTableName("web_users");
                			$sql = "SELECT username FROM $tbl WHERE $tbl.id = '".abs($resource[$x]['createdby'])."'"; 
                		}
                		else {
                			// get manager user name
                			$tbl = $modx->getFullTableName("manager_users");
                			$sql = "SELECT username FROM $tbl WHERE $tbl.id = '".$resource[$x]['createdby']."'";
                		}
                		$link = '';
                        //perform the query
                		$rs2 = $modx->dbQuery($sql);
                		$limit2 = $modx->recordCount($rs2); 
                		if($limit2<1) { 
                			$username = "anonymous"; 
                		} else { 
                			$resourceuser = $modx->fetchRow($rs2); 
                			$username = $resourceuser['username']; 
                		} 
                		// determine and show summary
                		
                		// summary is turned off
                		if (!$trunc) {
                		    $summary = $resource[$x]['content']; 
                		    
                		// contains the splitter and use splitter is on
                		} else if ((strstr($resource[$x]['content'], $splitter)) && $truncsplit) {
                            $summary = array();
                            
                            // HTMLarea/XINHA encloses it in paragraph's
                            $summary = explode('<p>'.$splitter.'</p>',$resource[$x]['content']);
                            
                            // For TinyMCE or if it isn't wrapped inside paragraph tags
                            $summary = explode($splitter,$summary['0']); 
                
                            $summary = $summary['0'];
                            // $link = '<a href="[~'.$resource[$x]['id'].'~]">'.$linktext.'</a>';
                
                        // fall back to the summary text    
                		} else if (strlen($resource[$x]['introtext'])>0) {
                			$summary = $resource[$x]['introtext'];
                			// $link = '<a href="[~'.$resource[$x]['id'].'~]">'.$linktext.'</a>';
                			
                		// fall back to the summary text count of characters	
                		} else if(strlen($resource[$x]['content']) > $lentoshow) { 
                		 	$summary = substr($resource[$x]['content'], 0, $lentoshow).' ...'; 
                		
                		// and back to where we started if all else fails (short post)
                		} else { 
                			$summary = $resource[$x]['content']; 
                		}  
                		
                		// Post-processing to clean up summaries
                		$summary = html_substr($summary,$lentoshow,$lenoffset);
                		$summary = closeTags($summary);
                		$summary = str_replace($commentschunk,'',$summary); 
                		
                		// Build the "show more" link
                		$link = '<a href="[~'.$resource[$x]['id'].'~]">'.$linktext.'</a>';
                        
                
                    // Output debug info
                	if ($debug == 1) $output .= '<p><strong>Document Data for "'.$resource[$x]['pagetitle'].'"</strong></p><textarea name="Document Data" rows="5" readonly>';
                		// Set placeholders for document object
                		foreach ($resource[$x] as $docVar => $docVarValue) {
                			$modx->setPlaceholder($docVar, $docVarValue); 
                			
                			if ($debug == 1 && $docVar != "content"){			
                			$output .= $docVar." = ".htmlspecialchars($docVarValue)." \n";
                		}
                	}
                			  
                	if ($debug == 1) $output .= '</textarea>';
                	
                	// Set tv placeholders
                	preg_match_all('~\[\+tv(.*?)\+\]~', $tpl, $matches);
                	$cnt = count($matches[1]);
                		for($i=0; $i<$cnt; $i++) {
                			$value = $modx->getTemplateVarOutput($idname=array($matches[1][$i]), $docid=$resource[$x]['id'], $published=$resource[$x]['published']);
                			$v = $value[$matches[1][$i]];
                			$modx->setPlaceholder("tv".$matches[1][$i], $v); 
                		}
                
                	// Set placeholders that can be used in the Chunk
                	
                		// Set placeholders for backwards compadibility and custom fields
                		$modx->setPlaceholder('title', $resource[$x]['pagetitle']);
                		$modx->setPlaceholder('summary', $summary); 
                		$modx->setPlaceholder('link', $link); 
                		$modx->setPlaceholder('author', $username); 
                		$modx->setPlaceholder('date', strftime($date, $resource[$x][$datetype])); 
                		 
                    // Expand the chunk code, and replace Placeholders
                	if ($debug != 1) $output .= $modx->mergePlaceholderContent($modx->mergeChunkContent($tpl));
                
                	} 
                }} 
                $archivehtml = "";
                if ($debug == 1) $output .= "<br />Generate arcive (if true): $stop<$nrtotal and $showarch == true<br />";
                
                if($stop<$nrtotal && $showarch == true) {
                
                $displayeds = 0;
                $lastMonth = -1;
                $archivehtml .= "<h3>$archtxt</h3><div id=\"nl_archivelist\"><ul>";
                for ($i = $stop; $i < $nrtotal; $i++) {
                	$unixdate = $resource[$i][$datetype];
                		$dateArray = getdate($unixdate);
                		$curMonth = $dateArray['mon'];
                		$month = strftime("%B %Y", $resource[$i][$datetype]);
                		if ($curMonth != $lastMonth) {
                			if ($lastMonth != -1) {
                				$archivehtml .= '</ul></li>';
                			}
                			$archivehtml .= '<li><span class="nl_month">'.$month.'</span><ul>';
                		}
                		
                		$archivehtml .= "<li class=\"nl_archpost\"><a href='[~".$resource[$i]['id']."~]'>".$resource[$i]['pagetitle']."</a> (<span class=\"nl_date\">".strftime($date, $resource[$i][$datetype])."</span>)</li>";
                		++$displayeds;
                		$lastMonth  = $curMonth;
                
                }
                $archivehtml .= "</ul></li></ul></div>";
                }
                
                if ($archplaceholder == 1)
                {
                	$modx->setPlaceholder('archive', $archivehtml); 
                }
                else if($showarch == true && $paginate != 1)
                {
                	$output .= $archivehtml;
                }
                else
                {
                	$output .= "";
                }
                
                return $output;
                ?>

                  "A great democracy must be progressive, or soon it shall cease to be great, and soon it shall cease to be a democracy." -Theodore Roosevelt
                  • 32614
                  • 65 Posts
                  My last post was too long to post everything in one post. So here’s the rest:


                  This is a chunk called "EpisodeListingArchive":
                  <div class="episode">
                      	<div class="episodeTopOld"><div class='albums'><img src='http://www.thesoundsinmyhead.com/assets/images/albums/[+alias+]_1.jpg' width='71' height='71' /><img src='http://www.thesoundsinmyhead.com/assets/images/albums/[+alias+]_3.jpg' width='71' height='71' /><img src='http://www.thesoundsinmyhead.com/assets/images/albums/[+alias+]_2.jpg' width='71' height='71' /><img src='http://www.thesoundsinmyhead.com/assets/images/albums/[+alias+]_4.jpg' width='71' height='71' /></div>
                      	<a href="http://www.thesoundsinmyhead.com/episodes/[+alias+].m4a">[+title+]</a>
                          </div>
                  <div class="episodeContent">[+summary+]<div class="clear"></div></div>
                          <div class="episodeBottom"><span class="subscribe"><a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=259654789"></a></span><a href="[~[+id+]~]">Permalink</a></div>
                    </div>


                  And this is a chunk called "2006EpisodeListing":
                       <div class="episode">
                      	<div class="episodeTopOld"><div class='albums'><img src='http://www.thesoundsinmyhead.com/assets/images/albums/[+alias+]_1.jpg' width='71' height='71' /><img src='http://www.thesoundsinmyhead.com/assets/images/albums/[+alias+]_3.jpg' width='71' height='71' /><img src='http://www.thesoundsinmyhead.com/assets/images/albums/[+alias+]_2.jpg' width='71' height='71' /><img src='http://www.thesoundsinmyhead.com/assets/images/albums/[+alias+]_4.jpg' width='71' height='71' /></div>
                      	<a href="http://www.thesoundsinmyhead.com/episodes/[+alias+].m4a">[+title+]</a>
                          </div>
                  <div class="episodeContent">[+content+]<div class="clear"></div></div>
                          <div class="episodeBottom"><span class="subscribe"><a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=259654789"></a></span><a href="[~[+id+]~]">Permalink</a></div>
                    </div>


                  I definitely haven’t tried re-writing any PHP code in the snippets. All I’ve done is change the embedded html that is located in some of these snippets.
                    "A great democracy must be progressive, or soon it shall cease to be great, and soon it shall cease to be a democracy." -Theodore Roosevelt
                    • 32614
                    • 65 Posts
                    Yeah, actually, my site did used to have user comments. They were handled using some primitive snippet which didn’t offer any protection against comment spam, and eventually I had to nuke them just to get things under control. I had actually kinda hoped that in this update I would able to get comments back.

                    Another thing I’d hoped to accomplish was having different looks for different kinds of episodes. Nothing too radical, but basically 3 different looks. 1) the look on the site now, which would be the "old" look. Then 2 new looks which would be basically the same, but with different color themes, which would be used for "new" episodes. You can see what I had in mind here:
                    http://wompedy.com/tsimh/

                    I’m pretty sure that given the way the current custom snippets/chunks that drive the site will not allow for that. But I’m thinking maybe Ditto is powerful enough to handle it? This would be yet another incentive to move things to Ditto.

                    Factors to consider: currently there is a modx-generated RSS feed. I’m not sure how it works. But this is the link to it and the snippet that creates it:
                    http://www.thesoundsinmyhead.com/rss.xml
                    <?php
                    // get folder id where we should look for news else look in current document
                    $folder = isset($newsfolder) ? intval($newsfolder):$modx->documentIdentifier;
                    
                    
                    // get current document id
                    $docid = $modx->documentIdentifier;
                    
                    // set subscribe mode
                    $makerss = isset($makerss) ? $makerss:1;
                    
                    // set link id
                    $linkid = isset($linkid) ? intval($linkid): 0;
                    
                    // set show link mode
                    $showlink = isset($showlink) ? $showlink: 1;
                    
                    // set top items
                    $topitems = isset($topitems) ? $topitems : 10;
                    
                    // set copyright info
                    $copyright = isset($copyright) ? $copyright:"";
                    
                    // set ttl value
                    $ttl = ($ttl) ? intval($ttl):1440;
                    
                    // set lentoshow
                    $lentoshow = isset($truncLen) ? $truncLen : 450;
                    
                    $trunc = isset($truc) ? $trunc : true;
                        // should there be summary/short version of the posts?
                    
                    $truncsplit = isset($trucSplit) ? $truncSplit : true;
                        // should the post be summarized at the "splitter"?
                    
                    $splitter = isset($trucAt) ? $truncAt : "<!-- splitter -->";
                        // where to split the text 
                        
                    $showPublishedOnly = isset($pubOnly) ? $pubOnly : true;
                        // allows you to show unpublished docs if needed for some reason...
                    // functions
                    
                    function closeTags($text) { 
                        $openPattern = "/<([^\/].*?)>/";   
                        $closePattern = "/<\/(.*?)>/"; 
                        $endOpenPattern = "/<([^\/].*?)$/"; 
                        $endClosePattern = "/<(\/.*?[^>])$/"; 
                        $endTags=''; 
                         
                        //$text=preg_replace($endOpenPattern,'',$text); 
                        //$text=preg_replace($endClosePattern,'',$text); 
                        preg_match_all($openPattern,$text,$openTags); 
                        preg_match_all($closePattern,$text,$closeTags); 
                        
                        //print_r($openTags); 
                        //print_r($closeTags); 
                        
                        $c=0; 
                        $loopCounter = count($closeTags[1]);  //used to prevent an infinite loop if the html is malformed 
                        while($c<count($closeTags[1]) && $loopCounter) { 
                            $i=0; 
                            while($i<count($openTags[1])) { 
                                 
                                $tag = trim($openTags[1][$i]); 
                                 
                                if(strstr($tag,' ')) { 
                                    $tag = substr($tag,0,strpos($tag,' '));    
                                } 
                                //echo $tag.'=='.$closeTags[1][$c]."\n"; 
                                if($tag==$closeTags[1][$c]) { 
                                    $openTags[1][$i]=''; 
                                    $c++; 
                                    break; 
                                }    
                                $i++; 
                            } 
                            $loopCounter--; 
                        } 
                         
                        $results = $openTags[1]; 
                         
                        if(is_array($results)) {  
                        $results = array_reverse($results); 
                             
                            foreach($results as $tag) { 
                        
                                $tag = trim($tag); 
                                 
                                if(strstr($tag,' ')) { 
                                    $tag = substr($tag,0,strpos($tag,' '));    
                                }    
                                if(!stristr($tag,'br') && !stristr($tag,'img') && !empty($tag)) { 
                                    $endTags.= '</'.$tag.'>'; 
                                } 
                            }    
                        } 
                        return $text.$endTags; 
                    }
                       
                    // switch block
                    switch ($makerss) {
                    	case true:	// generate rss2xml
                    
                    // Get children of specified document
                    
                    		 
                    			$tblContent= $tbl = $modx->getFullTableName('site_content');
                    		
                    			$query= "SELECT id, pagetitle, description, introtext, content, createdon, createdby, longtitle, alias  FROM $tblContent WHERE parent IN (129, 261) AND published = 1 AND isfolder = 0 ORDER BY createdon DESC";
                    			
                    			if (!$rs= $modx->db->query($query)) {
                    				return '';
                    			}
                    			while ($row= $modx->db->getRow($rs)) {
                    				$children[]= $row;
                    			}
                    			
                    
                    $ds = $children;
                    
                    // Set the Last Build Date
                    if ($children[0]['pub_date'] == 0) { $pubdate = $children[0]['createdon']; }
                    	else { $pubdate = $children[0]['pub_date']; }
                    	$buildate = "<lastBuildDate>".date("r", $children[0]['createdon'])."</lastBuildDate>";
                    
                    		$output .=  '
                    	<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:noNamespaceSchemaLocation="http://www.thearchitect.co.uk/schemas/rss-2_0.xsd" 
                        xmlns:itunes="http://www.itunes.com/DTDs/PodCast-1.0.dtd"
                        version="2.0"><channel>
                    		<title>The Sounds in My Head</title>
                    		<itunes:author>Daniel</itunes:author>
                    		<link>http://www.thesoundsinmyhead.com/</link>
                    		<description>A biweekly music show featuring songs and bands you might have missed. With as much liberal propaganda as I can squeeze in. Every-other Monday.</description>
                    
                    		<itunes:subtitle>A weekly music show featuring songs and bands you might have missed.</itunes:subtitle>
                    		<itunes:summary>A weekly music show hosted by Daniel featuring songs and bands you might have missed. With as much liberal propaganda as he can squeeze in. Every Monday.</itunes:summary>
                    		<language>en-us</language>
                    		<copyright>Daniel, 2005</copyright>
                    		<itunes:owner>
                                <itunes:name>Daniel</itunes:name>
                    
                                <itunes:email>[email protected]</itunes:email>
                            </itunes:owner>				<image>
                                <url>http://www.thesoundsinmyhead.com/images/tsimh_rss.jpg</url>
                                <title>The Sounds in My Head</title>
                                <link>http://www.thesoundsinmyhead.com/</link>
                                <height>320</height>
                    
                                <width>126</width>         </image>
                    		<managingEditor>[email protected]</managingEditor>
                    		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
                    		<category>podcast</category>
                    		<itunes:category text="Music"/>
                    		<itunes:explicit>No</itunes:explicit>
                            <itunes:keywords>Daniel Sounds My Head indiepop indierock tmbg wompedy</itunes:keywords>
                    		'.$buildate.'
                    ';
                    		// Set the Last Build Date
                    	if ($children[0]['pub_date'] == 0) { $pubdate = $children[0]['createdon']; }
                    		else { $pubdate = $children[0]['pub_date']; }
                    		$bd = "<lastBuildDate>".date("r", $children[0]['createdon'])."</lastBuildDate>";
                    		$link = $modx->config['site_url'].$modx->makeUrl($modx->documentIdentifier); // url to current page
                    
                    			
                    
                    
                    	
                    		
                    		$limit=count($ds);
                    		if($limit>0) { 
                    			//$limit = $topitems<$limit ? $topitems : $limit; 
                    			for ($i = 0; $i < $limit; $i++) { 
                    				
                    				if ($ds[$i]['createdby']<0) {
                    					// get web user name
                    					$tbl = $modx->getFullTableName("web_user_attributes");
                    					$sql = "SELECT fullname, email FROM $tbl WHERE $tbl.id = '".abs($ds[$i]['createdby'])."'"; 
                    				}
                    				else {
                    					// get manager user name
                    					$tbl = $modx->getFullTableName("user_attributes");
                    					$sql = "SELECT fullname, email  FROM $tbl WHERE $tbl.id = '".$ds[$i]['createdby']."'"; 
                    				}
                    				
                        				$rs2 = $modx->dbQuery($sql);
                        				$limit2 = $modx->recordCount($rs2); 
                        				if($limit2<1) { 
                    							// get manager user name
                    						$btbl = $modx->getFullTableName("user_attributes");
                    						$bsql = "SELECT fullname, email  FROM $btbl WHERE $btbl.id = '1'"; 
                    						$brs = $modx->dbQuery($bsql);
                    						$blimit = $modx->recordCount($brs);
                    						$bdsuser = $modx->fetchRow($brs); 
                        					$username = "".$bdsuser['fullname']." <".$bdsuser['email'].">";
                    								}
                        				else { 
                        					$dsuser = $modx->fetchRow($rs2); 
                        					$username = "".$dsuser['fullname']." <".$dsuser['email'].">";
                        				} 
                    				
                    		// determine and show summary
                    				    
                    
                    		// contains the splitter and use splitter is on
                    if ((strstr($ds[$i]['content'], $splitter)) && $truncsplit) {
                                $summary = array();
                                
                                // HTMLarea/XINHA encloses it in paragraph's
                                $summary = explode('<p>'.$splitter.'</p>',$ds[$i]['content']);
                                
                                // For TinyMCE or if it isn't wrapped inside paragraph tags
                                $summary = explode($splitter,$summary['0']); 
                    
                                $summary = $summary['0'];
                                $summary = closeTags($summary);
                                
                            // fall back to the summary text    
                    		} else if (strlen($ds[$i]['introtext'])>0) {
                    			$summary = $ds[$i]['introtext'];
                    			
                    		// fall back to the summary text count	
                    		// skipping this because of ease of breaking in the middle of an A tag... 
                    		// so it's not a good idea. If you must have this, then uncomment
                    		// } else if(strlen($ds[$i]['content']) > $lentoshow) { 
                    		// 	$summary = substr($ds[$i]['content'], 0, $lentoshow).'...'; 
                    		//
                    		
                    		// and back to where we started if all else fails (short post)
                    		} else { 
                    			$summary = $ds[$i]['content']; 
                    		}  
                    		
                    		// summary is turned off
                    		if ($trunc == false) {
                    		    $summary = $ds[$i]['content']; 
                    	    }
                    				
                    $alias = $ds[$i]['alias'];
                    $split = explode(".", $alias);
                    $combined = $split[2];
                    $combined .= $split[0];
                    $combined .= $split[1];
                    $combined .= " 0800";
                    $formatted = strtotime($combined );
                    $pubdate = date("r", $formatted);
                    $filename = 'episodes/'.$ds[$i]['alias'].'.m4a';	
                    
                    if (file_exists($filename)) {
                    $fileSize = filesize($filename);
                    } 
                    
                    $tbl = $modx->getFullTableName('site_tmplvar_contentvalues');
                    $id = $ds[$i]['id'];
                    $duration = $modx->db->getValue('SELECT `value` FROM '.$tbl.' WHERE `tmplvarid` = 15 AND `contentid` = '.$id .'');
                    
                    				$allowedTags = '<a><p><br><i><em><b><strong><img><ul><ol><li>';
                    	
                    				// format content
                    				$strippedsummary = $modx->stripTags($summary,$allowedTags);
                    
                    				$link = $modx->config['site_url'].$modx->makeUrl($ds[$i]['id']);
                    				$output .= '<item>'."\n".
                    				'			<title>'.$ds[$i]['longtitle'].'</title>'."\n".
                    				'			<itunes:author>Daniel</itunes:author>'."\n".
                    				'			<description><![CDATA['.$strippedsummary.']]></description>'."\n".
                    				'			<author>[email protected]</author>'."\n".
                    				'			<pubDate>'.$pubdate.'</pubDate>'."\n".
                    				'			<enclosure url="http://www.thesoundsinmyhead.com/episodes/'.$ds[$i]['alias'].'.m4a" length="'.$fileSize.'" type="audio/x-m4a"/>'."\n".
                    				'			<itunes:duration>'.$duration.'</itunes:duration>'."\n".
                    				'			</item>'."\n";
                    			} 
                    		}
                    		$output .= '	</channel>'."\n".
                    		'</rss>';
                    		break;
                    	
                    	default:	// defaul mode
                    		$output = '';
                    		$title = $modx->documentObject['pagetitle'];
                    		$link = $modx->config['site_url'].$modx->makeUrl($linkid);
                    		$modx->regClientCSS('<link rel="alternate" type="application/rss+xml" title="'.$title.'" href="'.$link.'" />');
                            if($showlink) $output = '<a href="'.$link.'">'.$title.'</a>';
                    		break;
                    }
                    
                    return $output;
                    ?>


                    Thanks to you all for all your help!
                      "A great democracy must be progressive, or soon it shall cease to be great, and soon it shall cease to be a democracy." -Theodore Roosevelt
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Sounds like Ditto and Jot will make all your troubles go away. As far as different "looks", you could use TV tags and use phx to change colors depending on the tag... or something like that. I’m sure it can be done, though.
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org