Пример #1
0
 /**
  * Do get data from given feed
  */
 function _get_rss_feed_array($rss_url = '', $feed_ttl = 3600, $num_items = 15)
 {
     require_php_lib('yf_domit');
     // Prepare cache params
     if ($this->USE_ARRAY_CACHE) {
         $_url_hash = md5($rss_url);
         $_obj_cache_path = $this->AGGR_CACHE_PATH . 'array_' . $_url_hash;
     }
     // Check if we can use array cache instead of loading domit library
     if (!empty($_obj_cache_path) && @file_exists($_obj_cache_path) && @filemtime($_obj_cache_path) > time() - $feed_ttl) {
         return @unserialize(file_get_contents($_obj_cache_path));
     } else {
         $rssDoc = new xml_domit_rss_document($rss_url, $this->AGGR_CACHE_PATH);
     }
     $success = (bool) $rssDoc;
     // Stop here if no document parsed
     if (!$success) {
         return false;
     }
     $output = ['channel' => null, 'items' => null];
     $totalChannels = $rssDoc->getChannelCount();
     // special handling for feed encoding
     $this->_decode_func = $this->_feed_encoding($rssDoc);
     // Process only first channel
     $cur_channel =& $rssDoc->getChannel(0);
     if (empty($cur_channel)) {
         return false;
     }
     $cur_ch_image = $cur_channel->getImage();
     $_ch_image = [];
     if (is_object($cur_ch_image)) {
         $_ch_image = ['title' => $this->_decode_text($cur_ch_image->getTitle()), 'link' => $this->_decode_text($cur_ch_image->getLink()), 'url' => $this->_decode_text($cur_ch_image->getUrl()), 'width' => intval($cur_ch_image->getWidth())];
     }
     $output['channel'] = ['url' => $cur_channel->getLink(), 'title' => $this->_decode_text($cur_channel->getTitle()), 'desc' => $this->_decode_text($cur_channel->getDescription()), 'webmaster' => $this->_decode_text($cur_channel->getWebMaster()), 'image' => $_ch_image];
     // Get number of items
     $actual_items = $cur_channel->getItemCount();
     $total_items = $num_items > $actual_items ? $actual_items : $num_items;
     // Process items
     for ($j = 0; $j < $total_items; $j++) {
         $currItem = $cur_channel->getItem($j);
         $cur_enc = $currItem->getEnclosure();
         $_enclosure = [];
         if (is_object($cur_enc)) {
             $_enclosure = ['url' => $this->_decode_text($cur_enc->getUrl()), 'length' => intval($cur_enc->getLength()), 'type' => $this->_decode_text($cur_enc->getType())];
         }
         $output['items'][$j] = ['url' => $currItem->getLink(), 'title' => $this->_decode_text($currItem->getTitle()), 'text' => $this->_decode_text($currItem->getDescription()), 'pub_date' => $currItem->getPubDate(), 'author' => $this->_decode_text($currItem->getAuthor()), 'comments' => $this->_decode_text($currItem->getComments()), 'enclosure' => $_enclosure];
     }
     // Do cache array
     if ($this->USE_ARRAY_CACHE) {
         file_put_contents($_obj_cache_path, serialize($output));
     }
     return $output;
 }
Пример #2
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);
    }
Пример #3
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;
     }
 }