コード例 #1
0
ファイル: twitter.php プロジェクト: atikahmed/joomla-probid
 static function fetchXML($params, $force = 0)
 {
     $rssurl = $params->get('rss_url', '');
     $items_limit = intval($params->get('items_limit', 10));
     $doCache = intval($params->get('scr_cache', 1));
     $CacheTime = intval($params->get('cache_time', 3600));
     $twitter_timeline = $params->get('twitter_timeline', 'user');
     $username = $params->get('twitter_username', '');
     $password = $params->get('twitter_password', '');
     $list = $params->get('twitter_list', '');
     if ($twitter_timeline == 'friends') {
         $rssurl = 'http://api.twitter.com/1/statuses/friends_timeline.xml';
     } else {
         if ($twitter_timeline == 'mentions') {
             $rssurl = 'http://api.twitter.com/1/statuses/mentions.xml';
         } else {
             if ($twitter_timeline == 'list') {
                 $rssurl = 'http://api.twitter.com/1/' . urlencode($username) . '/lists/' . urlencode($list) . '/statuses.xml';
             } else {
                 if ($twitter_timeline == 'user_rt' && $username != '') {
                     $rssurl = 'http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=' . urlencode($username) . '&include_rts=true';
                 } else {
                     if ($username != '') {
                         $rssurl = 'http://api.twitter.com/1/statuses/user_timeline/' . urlencode($username) . '.xml';
                     } else {
                         $rssurl = str_replace('.rss', '.xml', $rssurl);
                     }
                 }
             }
         }
     }
     $feed_desc = 1;
     $item_desc = 1;
     $feed_array = array();
     $xmlDoc =& JFactory::getXMLParser('Simple');
     if ($doCache) {
         if (!class_exists('JCache')) {
             require_once JPATH_SITE . DS . 'libraries' . DS . 'joomla' . DS . 'cache' . DS . 'cache.php';
         }
         $options = array('defaultgroup' => 'mod_ajaxscroller', 'lifetime' => $CacheTime, 'checkTime' => true, 'caching' => true);
         $cache = new JCache($options);
         $cache->setLifeTime($CacheTime);
         if ($force) {
             // delete the cache, force the new fetch
             $cache->remove(md5($rssurl), 'mod_ajaxscroller');
         }
         if ($string = $cache->get(md5($rssurl), 'mod_ajaxscroller')) {
             $xmlDoc->loadString($string);
         } else {
             $xml = simplexml_load_file($rssurl);
             $string = $xml->asXML();
             $string = str_replace('georss:', 'georss_', $string);
             // simplexml doesn't like ':'
             $xmlDoc->loadString($string);
             $cache->store($xmlDoc->document->toString(), md5($rssurl));
         }
     } else {
         $xml = simplexml_load_file($rssurl);
         $string = $xml->asXML();
         $string = str_replace('georss:', 'georss_', $string);
         // simplexml doesn't like ':'
         $xmlDoc->loadString($string);
     }
     $root =& $xmlDoc->document;
     $statuses =& $root->children();
     $length = count($statuses);
     $total = $items_limit && $items_limit < $length ? $items_limit : $length;
     if ($total == 0) {
         $feed_array = $xmlDoc->loadString($string);
     }
     for ($i = 0; $i < $total; $i++) {
         $status =& $statuses[$i];
         $id =& $status->getElementByPath('id')->data();
         $created_at =& $status->getElementByPath('created_at')->data();
         $text =& $status->getElementByPath('text')->data();
         $source =& $status->getElementByPath('source')->data();
         $in_reply_to_status_id =& $status->getElementByPath('in_reply_to_status_id')->data();
         $in_reply_to_user_id =& $status->getElementByPath('in_reply_to_user_id')->data();
         $in_reply_to_screen_name =& $status->getElementByPath('in_reply_to_screen_name')->data();
         $user_id =& $status->getElementByPath('user')->getElementByPath('id')->data();
         $user_screen_name =& $status->getElementByPath('user')->getElementByPath('screen_name')->data();
         $user_profile_image_url =& $status->getElementByPath('user')->getElementByPath('profile_image_url')->data();
         $feed_array[$i]['item_href'] = 'http://twitter.com/' . $user_screen_name . '/statuses/' . $id;
         $feed_array[$i]['item_date'] = $created_at;
         $feed_array[$i]['item_title'] = $user_screen_name;
         //$text = htmlentities($text);
         $feed_array[$i]['item_desc'] = modAjaxScrollerCommonHelper::ajax_scroller_format_twitter($text, $params, $user_profile_image_url, $user_screen_name, $created_at, $source, $in_reply_to_user_id, $in_reply_to_screen_name, $in_reply_to_status_id);
     }
     return $feed_array;
 }
コード例 #2
0
ファイル: rss.php プロジェクト: atikahmed/joomla-probid
 static function fetchRSS($params, $force = 0)
 {
     $type = $params->get('type', '');
     $rssurl = $params->get('rss_url', '');
     $twitter_timeline = $params->get('twitter_timeline', 'user');
     $twitter_keyword = $params->get('twitter_keyword', '');
     if ($type == 'twitter' && $twitter_timeline == 'search') {
         $rssurl = 'http://search.twitter.com/search.atom?q=' . urlencode($twitter_keyword);
     }
     $items_limit = intval($params->get('items_limit', 10));
     $rss_image_only = intval($params->get('rss_image_only', 0));
     $doCache = intval($params->get('scr_cache', 1));
     $CacheTime = intval($params->get('cache_time', 3600));
     $feed_desc = 1;
     $item_desc = 1;
     $cacheDir = JPATH_BASE . DS . 'cache' . DS;
     $feed_array = array();
     $feed_array[0] = '';
     jimport('simplepie.simplepie');
     $simplepie = new SimplePie();
     // check if cache directory is writeable
     if (!is_writable($cacheDir) || !$doCache) {
         $simplepie->enable_cache(false);
     } else {
         // delete the cache file if fetch forced
         $cache_file = $cacheDir . md5($rssurl) . '.spc';
         if ($force && file_exists($cache_file)) {
             // delete the cache, force the new fetch
             @unlink($cache_file);
         }
         $simplepie->set_cache_name_function('md5');
         $simplepie->set_cache_location($cacheDir);
         $simplepie->set_cache_duration($CacheTime);
     }
     $simplepie->set_feed_url($rssurl);
     $simplepie->init();
     $simplepie->handle_content_type();
     if ($simplepie->data) {
         $rssDoc = $simplepie;
     } else {
         return 'Error: Feed not retrieved';
     }
     //$feed_array[0]['feed_title'] = @$rssDoc->get_title();
     //$feed_array[0]['feed_link'] = @$rssDoc->get_link();
     //$feed_array[0]['feed_desc'] = @$rssDoc->get_description();
     // items
     $feed_items = @$rssDoc->get_items();
     if (empty($feed_items)) {
         return 'Error: No items fetched';
     }
     if ($rss_image_only) {
         // filter only feeds that contain image
         $temp_array = array();
         foreach ($feed_items as $item) {
             $description = @$item->get_description();
             if ($description && stristr($description, 'img src')) {
                 $temp_array[] = $item;
             }
         }
         $feed_items = $temp_array;
     }
     if ($items_limit > 0) {
         $feed_items = array_slice($feed_items, 0, $items_limit);
     }
     foreach ($feed_items as $j => $item) {
         if (!is_null(@$item->get_link())) {
             $feed_array[0][$j]['item_href'] = $item->get_link();
         }
         if (!is_null(@$item->get_title())) {
             $feed_array[0][$j]['item_title'] = @$item->get_title();
         }
         if (!is_null(@$item->get_date())) {
             $feed_array[0][$j]['item_date'] = @$item->get_date();
         }
         if (@$item->get_description()) {
             $feed_array[0][$j]['item_desc'] = @$item->get_description();
             $feed_array[0][$j]['item_desc'] = str_replace('&apos;', "'", $feed_array[0][$j]['item_desc']);
         }
         // Twitter search
         if (preg_match('/^tag:search.twitter.com/', @$item->get_id())) {
             $user_profile_image_url = @$item->get_link(0, 'image');
             $user_screen_name = '';
             if (@$item->get_author()) {
                 $author = @$item->get_author();
                 if (isset($author->name)) {
                     $author = $author->name;
                     if (!empty($author) && stristr($author, ' ')) {
                         $author = explode(' ', $author);
                         $author = $author[0];
                         $user_screen_name = $author;
                     }
                 }
             }
             // Replace title
             $feed_array[0][$j]['item_title'] = $user_screen_name;
             // Replace text
             $text = $feed_array[0][$j]['item_desc'];
             $created_at = $feed_array[0][$j]['item_date'];
             $source = @$item->get_item_tags('http://api.twitter.com/', 'source');
             $source = @$item->sanitize($source[0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
             $feed_array[0][$j]['item_desc'] = modAjaxScrollerCommonHelper::ajax_scroller_format_twitter($text, $params, $user_profile_image_url, $user_screen_name, $created_at, $source);
         }
     }
     //echo '<pre>'; print_r($feed_array[0]); die;
     return $feed_array[0];
 }
コード例 #3
0
ファイル: banners.php プロジェクト: atikahmed/joomla-probid
    static function get($moduleid, $params, $start = 0)
    {
        require_once JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'html' . DS . 'parameter.php';
        $db =& JFactory::getDBO();
        $ordering = $params->get('banner_ordering', 'ordering ASC');
        if ($ordering == 'random') {
            $order = 'ordering ASC';
        } else {
            $order = $ordering;
        }
        $items_count = intval($params->get('items_count', 1));
        $items_limit = intval($params->get('items_limit', 0));
        $target_blank = $params->get('target_blank', 0);
        $categories = (array) $params->get('banner_categories', array());
        $clients = (array) $params->get('banner_clients', array());
        $params->set('read_more', 0);
        $params->set('date', 0);
        $current_id = JRequest::getInt('c', $start);
        $direction = JRequest::getString('d');
        $date =& JFactory::getDate();
        $now = $date->toFormat();
        $nullDate = $db->getNullDate();
        $wheres1 = array();
        foreach ($categories as $catid) {
            if (!empty($catid)) {
                $wheres1[] = "b.catid = {$catid}";
            }
        }
        if (empty($wheres1)) {
            $wheres1[] = '1';
        }
        $wheres2 = array();
        foreach ($clients as $cid) {
            if (!empty($cid)) {
                $wheres2[] = "b.cid = {$cid}";
            }
        }
        if (empty($wheres2)) {
            $wheres2[] = '1';
        }
        $query = "SELECT * FROM #__banners AS b" . "\n WHERE b.state = 1" . "\n AND (" . implode(' OR ', $wheres1) . ")" . "\n AND (" . implode(' OR ', $wheres2) . ")" . "\n AND ( b.publish_up = '{$nullDate}' OR b.publish_up <= '{$now}' )" . "\n AND ( b.publish_down = '{$nullDate}' OR b.publish_down >= '{$now}' )" . "\n ORDER BY {$order} LIMIT 1000";
        $db->setQuery($query);
        $rows = $db->loadObjectList();
        if ($items_limit) {
            $rows = array_slice($rows, 0, $items_limit);
        }
        if ($ordering == 'random') {
            uksort($rows, create_function('$a,$b', '
				$rand = sha1($_SERVER["REMOTE_ADDR"].date("Ymd"));
				$value = $a + $b;
				$value = substr($value,-1);

				if (intval(hexdec($rand{$value})) % 2) {
					return -1;
				} else {
					return 1;
				}
				
			'));
            // update keys
            $i = 0;
            foreach ($rows as $value) {
                $rows[$i] = $value;
                $i++;
            }
            ksort($rows);
        }
        /*
        $i=1;
        foreach($rows as $row) {
        	echo $i.'. '.$row->id.' '.$row->name.'<br />';
        	$i++;
        }
        die;
        */
        $content = '';
        for ($index = 0; $index < $items_count; $index++) {
            $key = $current_id + $index;
            if ($direction == 'prev') {
                $key = $key - $items_count;
                if ($key < 0) {
                    $remainder = count($rows) % $items_count;
                    if ($remainder == 0) {
                        $key = count($rows) - $items_count;
                    } else {
                        $key = count($rows) - $remainder;
                    }
                    $current_id = $key - $items_count;
                    $direction = 'next';
                }
            } else {
                if ($direction == 'next') {
                    $key = $key + $items_count;
                    if ($key >= count($rows) && $index == 0) {
                        $key = 0;
                        $current_id = $key - $items_count;
                    }
                }
            }
            if (empty($rows[$key])) {
                $empty = new stdClass();
                $empty->id = null;
                $empty->name = '';
                $empty->imageurl = '';
                $empty->clickurl = '';
                $empty->type = 0;
                $empty->custombannercode = '';
                $row = $empty;
            } else {
                $row = $rows[$key];
                $params1 = new JParameter($row->params);
                $row->imageurl = $params1->get('imageurl', '');
            }
            //echo "<pre>"; print_r($row); echo "</pre>"; die;
            // Output
            $link = "index.php?option=com_banners&amp;task=click&amp;id={$row->id}";
            $link = JRoute::_($link);
            $image = JURI::base() . $row->imageurl;
            if ($row->type == 1 && !empty($row->custombannercode)) {
                $text = $row->custombannercode;
                $text = str_replace('{NAME}', $row->name, $text);
                $text = str_replace('{CLICKURL}', $link, $text);
            } else {
                $text = '<a href="' . $link . '"';
                $text .= $target_blank ? ' target="_blank"' : '';
                $text .= '><img src="' . $image . '" alt="' . $row->name . '" border="0" /></a>';
            }
            $content .= modAjaxScrollerCommonHelper::get_scroller_item($row->name, $link, $text, '', $key, $index, $params, $moduleid);
        }
        return $content;
    }
コード例 #4
0
ファイル: content.php プロジェクト: atikahmed/joomla-probid
    static function fetch_content($moduleid, $params, $current_id, $direction)
    {
        $ordering = $params->get('ordering', 'created DESC');
        if ($ordering == 'random') {
            $order = 'a.ordering ASC';
        } else {
            if ($ordering == 'frontpage') {
                $order = 'f.ordering ASC';
            } else {
                $order = 'a.' . $ordering;
            }
        }
        list($orderby, $drctn) = explode(' ', $order);
        $items_count = intval($params->get('items_count', 1));
        $items_limit = intval($params->get('items_limit', 0));
        $categories = (array) $params->get('categories', array(0 => ''));
        $text_type = $params->get('text_type', 'both');
        $display_image = intval($params->get('display_image', 0));
        $image_max_width = intval($params->get('image_max_width', 40));
        $date_format = $params->get('date_format', 'Y-m-d');
        require_once JPATH_BASE . DS . 'components' . DS . 'com_content' . DS . 'models' . DS . 'articles.php';
        $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
        $model->setState('params', JFactory::getApplication()->getParams());
        $categories = (array) $params->get('categories', array(0 => ''));
        $model->setState('filter.category_id', $categories);
        $model->setState('list.ordering', $orderby);
        $model->setState('list.direction', $drctn);
        $model->setState('list.select', 'a.id, a.title, a.alias, a.title_alias, a.introtext, a.fulltext, ' . 'a.checked_out, a.checked_out_time, ' . 'a.catid, a.created, a.created_by, a.created_by_alias, ' . 'CASE WHEN a.modified = 0 THEN a.created ELSE a.modified END as modified, ' . 'a.modified_by, uam.name as modified_by_name,' . 'CASE WHEN a.publish_up = 0 THEN a.created ELSE a.publish_up END as publish_up, ' . 'a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, ' . 'a.hits, a.xreference, a.featured,' . ' LENGTH(a.fulltext) AS readmore ');
        //echo '<pre>'; print_r($model); die;
        $rows = $model->getItems();
        if ($items_limit) {
            $rows = array_slice($rows, 0, $items_limit);
        }
        // Compute the article slugs and prepare introtext (runs content plugins).
        for ($i = 0, $n = count($rows); $i < $n; $i++) {
            $item =& $rows[$i];
            $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id;
            $rows[$i] = $item;
        }
        if ($ordering == 'random') {
            uksort($rows, create_function('$a,$b', '
				$rand = sha1($_SERVER["REMOTE_ADDR"].date("Ymd"));
				$value = $a + $b;
				$value = substr($value,-1);

				if (intval(hexdec($rand{$value})) % 2) {
					return -1;
				} else {
					return 1;
				}
				
			'));
            // update keys
            $i = 0;
            foreach ($rows as $value) {
                $rows[$i] = $value;
                $i++;
            }
            ksort($rows);
        }
        /*
        $i=1;
        foreach($rows as $row) {
        	echo $i.'. '.$row->id.' '.$row->title.'<br />';
        	$i++;
        }
        die;
        */
        $content = '';
        for ($index = 0; $index < $items_count; $index++) {
            $key = $current_id + $index;
            if ($direction == 'prev') {
                $key = $key - $items_count;
                if ($key < 0) {
                    $remainder = count($rows) % $items_count;
                    if ($remainder == 0) {
                        $key = count($rows) - $items_count;
                    } else {
                        $key = count($rows) - $remainder;
                    }
                    $current_id = $key - $items_count;
                    $direction = 'next';
                }
            } else {
                if ($direction == 'next') {
                    $key = $key + $items_count;
                    if ($key >= count($rows) && $index == 0) {
                        $key = 0;
                        $current_id = $key - $items_count;
                    }
                }
            }
            if (empty($rows[$key])) {
                $empty = new stdClass();
                $empty->sectionid = null;
                $empty->id = null;
                $empty->slug = '';
                $empty->catslug = '';
                $empty->created = '';
                $empty->title = '';
                $empty->introtext = '';
                $empty->fulltext = '';
                $row = $empty;
            } else {
                $row = $rows[$key];
            }
            //echo "<pre>"; print_r($row); echo "</pre>"; die;
            //$link = "index.php?option=com_content&amp;view=article&amp;id=$row->slug&amp;catid=$row->catslug" . $Itemid;
            //$link = JRoute::_( $link );
            require_once JPATH_BASE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php';
            $link = ContentHelperRoute::getArticleRoute($row->slug, $row->catid);
            $link = JRoute::_($link);
            $date = JHTML::_('date', $row->created, $date_format);
            if ($text_type == 'introtext') {
                $text = $row->introtext;
            } else {
                if ($text_type == 'fulltext') {
                    $text = $row->fulltext;
                } else {
                    $text = $row->introtext . $row->fulltext;
                }
            }
            $text = modAjaxScrollerCommonHelper::ajax_scroller_fix_text($text, $params);
            if ($display_image) {
                $row->text = $text;
                $params->get('image', 1);
                $params->get('intro_only', 1);
                /*
                JPluginHelper::importPlugin('content', null, false);			
                $dispatcher =& JDispatcher::getInstance();
                $result = $dispatcher->trigger('onPrepareContent', array($row, $params, 0));
                */
                $text = $row->text;
                if ($image_max_width) {
                    $text = preg_replace('/height="[0-9]+"/i', '', $text);
                    $text = preg_replace('/width="[0-9]+"/i', '', $text);
                    $text = preg_replace('/<img /i', '<img width="' . $image_max_width . '" ', $text);
                }
                $text = preg_replace('/hspace="[0-9]+"/i', 'hspace="2"', $text);
                $text = preg_replace('/src="images\\/stories\\//i', 'src="' . JUri::base() . 'images/stories/', $text);
            } else {
                $text = preg_replace('/{.*}/', '', $text);
            }
            $content .= modAjaxScrollerCommonHelper::get_scroller_item($row->title, $link, $text, $date, $key, $index, $params, $moduleid);
        }
        return $content;
    }