We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34017
    • 898 Posts
    So I was working on this idea, threw this together, and now Im stuck.

    The idea:
    - Have a non-RTE content box where I can post many RSS Feeds.
    - Create a snippet to parse those via FeedX and show them

    The problem:
    - I can’t call it multiple times on a page (I can but I have to create duplicated-but-renamed snippets).

    So here’s the code (it’s a quick start/hack):
    <?php
    
    	global $modx;
    	
    $xtended_document = isset($document) ? $document : '-99';
    
    $params['preset'] = isset($preset) ? $preset : 'rss';
    	// Define a preset template to use...
    	// Presets are folders inside the /tpl/ directory, the snippet expects
    	// the outer filename to be: $feedxPath/tpl/$tplPreset/outer.tpl
    	// (If outerChunk is defined, it will automatically take precedence over this value)
    
    $params['outerChunk'] = isset($outerChunk) ? $outerChunk : '';
    	// Chunk to use for outer elements (default: use default rss template)
    	// Inner elements are called via chunk calls (in the template) formated like:
    	// 	{{entityName->chunkName}}
    	// In addition, setting the maximum number of elements displayed can be done via:
    	// 	{{entityName(max)->chunkName}}
    	// A start offset can also be added:
    	// 	{{entityName(max,start)->chunkName}}
    	// XML values can be displayed within a chunk via placeholder calls:
    	//	[+fieldName+]
    	// XML attributes can be displayed using:
    	//	[+fieldName.attrName+]
    
    $params['maxElements'] = isset($maxElements) ? $maxElements : '';
    	// Maximum number of times to display a repeating element
    	// This setting will be overridden by any limit values in the template
    	// Use the colon replacement value for element names which include colons
    	// Syntax: ELEMENT_NAME(x) where x is the maximum number of times to display
    	//         Multiple elements can be defined and must be separated by a colon
    	// Example: `CHANNEL(5):ITEM(10)`
    
    $params['startElements'] = isset($startElements) ? $startElements : '';
    	// Define the start (offset) for the displaying of elements
    	// This setting will be overridden by any offset values in the template
    	// Syntax: ELEMENT_NAME(x) where x is the offset integer
    	//         Multiple elements can be defined and must be separated by a colon
    	// Example: `CHANNEL(1):ITEM(5)`
    
    $params['filterElements'] = isset($filterElements) ? $filterElements : '';
    	// Specify a field to perform a match on, where the matching value is a Perl-style regular expression
    	// Matching elements can either be excluded using EQ (equals) or included NE (not equals) operators
    	// Syntax: ELEMENT_NAME(FIELDNAME NE /value/)
    	//         Multiple elements can be defined and must be separated by a colon
    	// Example: `ITEM(TITLE EQ /advertisement|sponsor|partner/)`
    
    $params['sortElements'] = isset($sortElements) ? $sortElements : '';
    	// Specify a field to perform a natural sort on, if %rand% is specified the elements will be randomized
    	// ASC and DESC can be optionally be added to modify the order in which the elements are sorted
    	// Syntax: ELEMENT_NAME(FIELDNAME)
    	//         Multiple elements can be defined and must be separated by a colon
    	// Example: `ITEM(PUB_DATE DESC)`
    
    $params['userPh'] = isset($userPh) ? html_entity_decode($userPh) : '';
    	// Set placeholder names and values which will be used globally
    	// Syntax: PLACEHOLDER_NAME->string value
    	//         Multiple elements can be defined and must be separated by a colon
    	//         Any string value with a colon should use the colon replacement
    	// Example: `JSID->test` ([+JSID+] contains the value test and can be used within all called templates)
    
    $params['oddElements'] = isset($oddElements) ? html_entity_decode($oddElements) : '';
    	// If $outerChunk is defined the snippet will call a chunk, if not,
    	// the snippet will attempt to use a file of the given name within the preset directory
    	// Syntax: ELEMENT_NAME->calledChunk
    	//         Multiple elements can be defiend and must be separated by a colon
    	// Example: `ITEM->oddChunk`
    
    $params['evenElements'] = isset($evenElements) ? html_entity_decode($evenElements) : '';
    	// Syntax: ELEMENT_NAME->calledChunk
    	//         Multiple elements can be defined and must be separated by a colon
    	// Example: `ITEM->evenChunk`
    
    $params['firstElement'] = isset($firstElement) ? html_entity_decode($firstElement) : '';
    	// Syntax: ELEMENT_NAME->calledChunk
    	//         Multiple elements can be defined and must be separated by a colon
    	// Example: `ITEM->firstChunk`
    
    $params['lastElement'] = isset($lastElement) ? html_entity_decode($lastElement) : '';
    	// Syntax: ELEMENT_NAME->calledChunk
    	//         Multiple elements can be defined and must be separated by a colon
    	// Example: `ITEM->lastChunk`
    
    $params['usePhx'] = isset($usePhx) ? intval($usePhx) : 1;
    	// Set to 1 to use the PHx parser (will fall back to standalone PHx mode if not installed globally)
    	// Set to 0 to disable PHx parsing
    
    $params['convEntities'] = isset($convEntities) ? $convEntities : 1;
    	// Set to 1 to convert HTML entities to characters (default)
    	// Set to 0 to convert characters to HTML entities
    
    $params['replaceColon'] = isset($replaceColon) ? $replaceColon : '|';
    	// Replace colons with the specified character(s) (defualt: |)
    	// (Resolves conflicts with PHx parsing)
    
    $params['cacheType'] = isset($cacheType) ? intval($cacheType) : 0;
    	// Sets the level of caching
    	// 0 stores the the parsed data and re-renders on each page load
    	// 1 stores the parsed data as well as the finalized output for a small efficiency gain
    
    $params['cacheTime'] = isset($cacheTime) ? intval($cacheTime) : 900;
    	// Time in seconds before re-retrieving a cached feed (default: 15 minutes)
    
    $params['cachePath'] = isset($cachePath) ? $cachePath : $modx->config['base_path'] . 'assets/cache/feedx/';
    	// Path to the cache directory (default: modx_base/assets/cache/feedx/)
    
    $params['timeout'] = isset($timeout) ? intval($timeout) : 20;
    	// Number of seconds to wait before giving up on feed retrieval
    
    $params['feedxPath'] = isset($feedxPath) ? $feedxPath : $modx->config['base_path'] . 'assets/snippets/FeedX/';
    	// Path to the feedX snippet directory (default: modx_base/assets/snippets/FeedX/)
    
    $params['language'] = isset($language) ? $language : 'english';
    	// Language for debug and error messages
    	// Language name must have a corresponding file in the feedxPath/lang/ folder
    
    $params['debug'] = isset($debug) ? intval($debug) : 0;
    	// Set to 1 to turn on debug/template builder mode
    	// Helps users create custom chunks by showing all potential placeholder names in a hierarchal fashion
    	// Also shows information about loaded templates
    	
    	//$modx->documentObject['content'];
    	 $url_page = $modx->getPageInfo($xtended_document,1,'content');
    
    	 
    	 $urls = explode("\n",$url_page[content]);
    	 
    	 foreach ($urls as $url)
    	 {
    	 		
    			$rss_feeds .= $modx->runSnippet(
    				"FeedX",
    					array(
    						"url"							=> $url,		//only thing different
    						"preset"					=> $params['preset'],
    						"outerChunk"			=> $params['outerChunk'],
    						"maxElements"			=> $params['maxElements'],
    						"startElements"		=> $params['startElements'],
    						"filterElements"	=> $params['filterElements'],
    						"sortElements"		=> $params['sortElements'],
    						"userPh"					=> $params['userPh'],
    						"oddElements"			=> $params['oddElements'],
    						"evenElements"		=> $params['evenElements'],
    						"firstElement"		=> $params['firstElement'],
    						"lastElement"			=> $params['lastElement'],
    						"usePhx"					=> $params['usePhx'],
    						"convEntities"		=> $params['convEntities'],
    						"replaceColon"		=> $params['replaceColon'],
    						"cacheType"				=> $params['cacheType'],
    						"cacheTime"				=> $params['cacheTime'],
    						"cachePath"				=> $params['cachePath'],
    						"timeout"					=> $params['timeout'],
    						"feedxPath"				=> $params['feedxPath'],
    						"language"				=> $params['language'],
    						"debug"						=> $params['debug']
    					)
    			);
    			
    	 }
    
    	 echo $rss_feeds;
    
    
    ?>
    


    I pulled the parameters from FeedX so they could be used dynamically here. It works great with only one on a page.

    Chuck
      Chuck the Trukk
      ProWebscape.com :: Nashville-WebDesign.com
      - - - - - - - -
      What are TV's? Here's some info below.
      http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
      http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008