Esempio n. 1
0
    public static function showNewsfeeds(&$newsfeed, $LitePath, $cacheDir, &$params)
    {
        ?>
		<table width="100%" class="contentpane<?php 
        echo $params->get('pageclass_sfx');
        ?>
">
		<?php 
        if ($params->get('header')) {
            ?>
			<tr>
				<td class="componentheading<?php 
            echo $params->get('pageclass_sfx');
            ?>
" colspan="2">
				<?php 
            echo $params->get('header');
            ?>
				</td>
			</tr>
			<?php 
        }
        // full RSS parser used to access image information
        $rssDoc = new xml_domit_rss_document();
        $rssDoc->setRSSTimeout(5);
        $rssDoc->useCacheLite(true, $LitePath, $cacheDir, $newsfeed->cache_time);
        $success = $rssDoc->loadRSS($newsfeed->link);
        if ($success) {
            $totalChannels = $rssDoc->getChannelCount();
            for ($i = 0; $i < $totalChannels; $i++) {
                $currChannel =& $rssDoc->getChannel($i);
                $elements = $currChannel->getElementList();
                $descrip = 0;
                $iUrl = 0;
                foreach ($elements as $element) {
                    //image handling
                    if ($element == 'image') {
                        $image =& $currChannel->getElement(DOMIT_RSS_ELEMENT_IMAGE);
                        $iUrl = $image->getUrl();
                        $iTitle = $image->getTitle();
                    }
                    if ($element == 'description') {
                        $descrip = 1;
                        // hide com_rss descrip in 4.5.0 feeds
                        if ($currChannel->getDescription() == 'com_rss') {
                            $descrip = 0;
                        }
                    }
                }
                $feed_title = $currChannel->getTitle();
                $feed_title = mosCommonHTML::newsfeedEncoding($rssDoc, $feed_title);
                ?>
				<tr>
					<td class="contentheading<?php 
                echo $params->get('pageclass_sfx');
                ?>
">
						<a href="<?php 
                echo ampReplace($currChannel->getLink());
                ?>
" target="_blank">
							<?php 
                echo $feed_title;
                ?>
</a>
					</td>
				</tr>
				<?php 
                // feed description
                if ($descrip && $params->get('feed_descr')) {
                    $feed_descrip = $currChannel->getDescription();
                    $feed_descrip = mosCommonHTML::newsfeedEncoding($rssDoc, $feed_descrip);
                    ?>
					<tr>
						<td>
						<?php 
                    echo $feed_descrip;
                    ?>
						<br />
						<br />
						</td>
					</tr>
					<?php 
                }
                // feed image
                if ($iUrl && $params->get('feed_image')) {
                    ?>
					<tr>
						<td>
						<img src="<?php 
                    echo $iUrl;
                    ?>
" alt="<?php 
                    echo $iTitle;
                    ?>
" />
						</td>
					</tr>
					<?php 
                }
                $actualItems = $currChannel->getItemCount();
                $setItems = $newsfeed->numarticles;
                if ($setItems > $actualItems) {
                    $totalItems = $actualItems;
                } else {
                    $totalItems = $setItems;
                }
                ?>
				<tr>
					<td>
					<ul>
						<?php 
                for ($j = 0; $j < $totalItems; $j++) {
                    $currItem =& $currChannel->getItem($j);
                    $item_title = $currItem->getTitle();
                    $item_title = mosCommonHTML::newsfeedEncoding($rssDoc, $item_title);
                    ?>
							<li>
								<?php 
                    // START fix for RSS enclosure tag url not showing
                    if ($currItem->getLink()) {
                        ?>
									<a href="<?php 
                        echo ampReplace($currItem->getLink());
                        ?>
" target="_blank">
										<?php 
                        echo $item_title;
                        ?>
</a>
									<?php 
                    } else {
                        if ($currItem->getEnclosure()) {
                            $enclosure = $currItem->getEnclosure();
                            $eUrl = $enclosure->getUrl();
                            ?>
									<a href="<?php 
                            echo ampReplace($eUrl);
                            ?>
" target="_blank">
										<?php 
                            echo $item_title;
                            ?>
</a>
									<?php 
                        } else {
                            if ($currItem->getEnclosure() && $currItem->getLink()) {
                                $enclosure = $currItem->getEnclosure();
                                $eUrl = $enclosure->getUrl();
                                ?>
									<a href="<?php 
                                echo ampReplace($currItem->getLink());
                                ?>
" target="_blank">
										<?php 
                                echo $item_title;
                                ?>
</a>
									<br />
									Link:
									<a href="<?php 
                                echo $eUrl;
                                ?>
" target="_blank">
										<?php 
                                echo ampReplace($eUrl);
                                ?>
</a>
									<?php 
                            }
                        }
                    }
                    // END fix for RSS enclosure tag url not showing
                    // item description
                    if ($params->get('item_descr')) {
                        $text = $currItem->getDescription();
                        $text = mosCommonHTML::newsfeedEncoding($rssDoc, $text);
                        $num = $params->get('word_count');
                        // word limit check
                        if ($num) {
                            $texts = explode(' ', $text);
                            $count = count($texts);
                            if ($count > $num) {
                                $text = '';
                                for ($i = 0; $i < $num; $i++) {
                                    $text .= ' ' . $texts[$i];
                                }
                                $text .= '...';
                            }
                        }
                        ?>
									<br />
									<?php 
                        echo $text;
                        ?>
									<br />
									<br />
									<?php 
                    }
                    ?>
							</li>
							<?php 
                }
                ?>
					</ul>
					</td>
				</tr>
				<tr>
					<td>
					<br />
					</td>
				</tr>
				<?php 
            }
        }
        ?>
		</table>
		<?php 
        // displays back button
        mosHTML::BackButton($params);
    }
Esempio n. 2
0
 public static function modoutput_feed(&$module, &$params, $moduleclass_sfx)
 {
     global $mosConfig_absolute_path, $mosConfig_cachepath;
     // check if cache directory is writeable
     $cacheDir = $mosConfig_cachepath . '/';
     if (!is_writable($cacheDir)) {
         $module->content = 'Cache Directory Unwriteable';
         return;
     }
     $rssurl = $params->get('rssurl');
     $rssitems = $params->get('rssitems', 5);
     $rssdesc = $params->get('rssdesc', 1);
     $rssimage = $params->get('rssimage', 1);
     $rssitemdesc = $params->get('rssitemdesc', 1);
     $words = $params->def('word_count', 0);
     $rsstitle = $params->get('rsstitle', 1);
     $rsscache = $params->get('rsscache', 3600);
     $contentBuffer = '';
     $LitePath = $mosConfig_absolute_path . '/includes/Cache/Lite.php';
     require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_rss.php';
     $rssDoc = new xml_domit_rss_document();
     $rssDoc->setRSSTimeout(2);
     $rssDoc->useCacheLite(true, $LitePath, $cacheDir, $rsscache);
     $success = $rssDoc->loadRSS($rssurl);
     if ($success) {
         $content_buffer = '';
         $totalChannels = $rssDoc->getChannelCount();
         for ($i = 0; $i < $totalChannels; $i++) {
             $currChannel =& $rssDoc->getChannel($i);
             $elements = $currChannel->getElementList();
             $iUrl = 0;
             foreach ($elements as $element) {
                 //image handling
                 if ($element == 'image') {
                     $image =& $currChannel->getElement(DOMIT_RSS_ELEMENT_IMAGE);
                     $iUrl = $image->getUrl();
                     $iTitle = $image->getTitle();
                 }
             }
             // feed title
             $content_buffer = '<table cellpadding="0" cellspacing="0" class="moduletable' . $moduleclass_sfx . '">' . "\n";
             if ($currChannel->getTitle() && $rsstitle) {
                 $feed_title = $currChannel->getTitle();
                 $feed_title = mosCommonHTML::newsfeedEncoding($rssDoc, $feed_title);
                 $content_buffer .= "<tr>\n";
                 $content_buffer .= "\t<td>\n";
                 $content_buffer .= "\t\t<strong>\n";
                 $content_buffer .= "\t\t<a href=\"" . ampReplace($currChannel->getLink()) . "\" target=\"_blank\">\n";
                 $content_buffer .= $feed_title . "</a>\n";
                 $content_buffer .= "\t\t</strong>\n";
                 $content_buffer .= "\t</td>\n";
                 $content_buffer .= "</tr>\n";
             }
             // feed description
             if ($rssdesc) {
                 $feed_descrip = $currChannel->getDescription();
                 $feed_descrip = mosCommonHTML::newsfeedEncoding($rssDoc, $feed_descrip);
                 $content_buffer .= "<tr>\n";
                 $content_buffer .= "\t<td>\n";
                 $content_buffer .= $feed_descrip;
                 $content_buffer .= "\t</td>\n";
                 $content_buffer .= "</tr>\n";
             }
             // feed image
             if ($rssimage && $iUrl) {
                 $content_buffer .= "<tr>\n";
                 $content_buffer .= "\t<td align=\"center\">\n";
                 $content_buffer .= "\t\t<image src=\"" . $iUrl . "\" alt=\"" . @$iTitle . "\"/>\n";
                 $content_buffer .= "\t</td>\n";
                 $content_buffer .= "</tr>\n";
             }
             $actualItems = $currChannel->getItemCount();
             $setItems = $rssitems;
             if ($setItems > $actualItems) {
                 $totalItems = $actualItems;
             } else {
                 $totalItems = $setItems;
             }
             $content_buffer .= "<tr>\n";
             $content_buffer .= "\t<td>\n";
             $content_buffer .= "\t\t<ul class=\"newsfeed" . $moduleclass_sfx . "\">\n";
             for ($j = 0; $j < $totalItems; $j++) {
                 $currItem =& $currChannel->getItem($j);
                 // item title
                 $item_title = $currItem->getTitle();
                 $item_title = mosCommonHTML::newsfeedEncoding($rssDoc, $item_title);
                 // START fix for RSS enclosure tag url not showing
                 $content_buffer .= "<li class=\"newsfeed" . $moduleclass_sfx . "\">\n";
                 $content_buffer .= "\t<strong>\n";
                 if ($currItem->getLink()) {
                     $content_buffer .= "        <a href=\"" . ampReplace($currItem->getLink()) . "\" target=\"_blank\">\n";
                     $content_buffer .= "      " . $item_title . "</a>\n";
                 } else {
                     if ($currItem->getEnclosure()) {
                         $enclosure = $currItem->getEnclosure();
                         $eUrl = $enclosure->getUrl();
                         $content_buffer .= "        <a href=\"" . ampReplace($eUrl) . "\" target=\"_blank\">\n";
                         $content_buffer .= "      " . $item_title . "</a>\n";
                     } else {
                         if ($currItem->getEnclosure() && $currItem->getLink()) {
                             $enclosure = $currItem->getEnclosure();
                             $eUrl = $enclosure->getUrl();
                             $content_buffer .= "        <a href=\"" . ampReplace($currItem->getLink()) . "\" target=\"_blank\">\n";
                             $content_buffer .= "      " . $item_title . "</a><br/>\n";
                             $content_buffer .= "        <a href=\"" . ampReplace($eUrl) . "\" target=\"_blank\"><u>Download</u></a>\n";
                         }
                     }
                 }
                 $content_buffer .= "\t</strong>\n";
                 // END fix for RSS enclosure tag url not showing
                 // item description
                 if ($rssitemdesc) {
                     // item description
                     $text = $currItem->getDescription();
                     $text = mosCommonHTML::newsfeedEncoding($rssDoc, $text);
                     // word limit check
                     if ($words) {
                         $texts = explode(' ', $text);
                         $count = count($texts);
                         if ($count > $words) {
                             $text = '';
                             for ($i = 0; $i < $words; $i++) {
                                 $text .= ' ' . $texts[$i];
                             }
                             $text .= '...';
                         }
                     }
                     $content_buffer .= "     <div>\n";
                     $content_buffer .= "        " . $text;
                     $content_buffer .= "\t\t</div>\n";
                 }
                 $content_buffer .= "</li>\n";
             }
             $content_buffer .= "    </ul>\n";
             $content_buffer .= "\t</td>\n";
             $content_buffer .= "</tr>\n";
             $content_buffer .= "</table>\n";
         }
         $module->content = $content_buffer;
     }
 }