コード例 #1
0
ファイル: helper.php プロジェクト: ranrolls/ras-full-portal
 public static function getList(&$params)
 {
     $input = JFactory::getApplication()->input;
     $start = $input->getInt('fc_start', 0);
     $count = (int) $params->get('count', 3);
     $subcount = (int) $params->get('subcount', 0);
     $colcount = (int) $params->get('colcount', 3);
     $ajaxed = (int) $params->get('ajaxed', '');
     $pag = $params->get('pag_show', 0);
     $cat_image = $params->get('cat_image', 0);
     $groups = array();
     $col_class = 'featcat';
     $categories = JCategories::getInstance('Content');
     if ($pag) {
         $limit = (int) $params->get('limit', '');
         $col_class .= ' pag';
     } else {
         $limit = $count + $subcount;
     }
     if (!$ajaxed) {
         $catids = $params->get('catid');
     } else {
         $catids = array();
         if ($input->getVar('catid')) {
             $catids[] = $input->getInt('catid');
         } else {
             $catids[] = '';
         }
     }
     $col = 0;
     if ($catids) {
         foreach ($catids as $catid) {
             $col++;
             $groups[$catid] = new stdClass();
             $groups[$catid]->col_class = $col_class . ' col' . $col;
             if ($col == 1) {
                 $groups[$catid]->col_class .= ' firstcol featcat_clr';
             } elseif ($col == $colcount) {
                 $groups[$catid]->col_class .= ' lastcol';
                 $col = 0;
             }
             $category = $categories->get($catid);
             $groups[$catid]->category_title = $category->title;
             $groups[$catid]->category_link = JRoute::_(ContentHelperRoute::getCategoryRoute($catid));
             if ($cat_image) {
                 $catParams = $category->params;
                 $registry = new JRegistry();
                 $registry->loadString($category->params);
                 $groups[$catid]->category_image = $registry->get('image');
             }
             $groups[$catid]->articles = array();
             $articles = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
             $articles->setState('list.select', 'a.id, a.title, a.alias, a.introtext, a.fulltext, a.images, ' . 'a.catid, a.created, a.created_by, a.created_by_alias, ' . 'a.modified, a.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 ');
             $app = JFactory::getApplication();
             $appParams = $app->getParams('com_content');
             $articles->setState('params', $appParams);
             $articles->setState('list.start', 0);
             $articles->setState('list.limit', $limit);
             $articles->setState('filter.published', 1);
             $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
             $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
             $articles->setState('filter.access', $access);
             $articles->setState('filter.category_id.include', 1);
             if ($params->get('show_child_category_articles', 0) && (int) $params->get('levels', 0) > 0) {
                 $subcategories = JModelLegacy::getInstance('Categories', 'ContentModel', array('ignore_request' => true));
                 $subcategories->setState('params', $appParams);
                 $levels = $params->get('levels', 1) ? $params->get('levels', 1) : 9999;
                 $subcategories->setState('filter.get_children', $levels);
                 $subcategories->setState('filter.published', 1);
                 $subcategories->setState('filter.access', $access);
                 $include_subcategories = array();
                 $include_subcategories[] = $catid;
                 $subcategories->setState('filter.parentId', $catid);
                 $recursive = true;
                 $items = $subcategories->getItems($recursive);
                 if ($items) {
                     foreach ($items as $subcategory) {
                         $condition = $subcategory->level - $subcategory->getParent()->level <= $levels;
                         if ($condition) {
                             $include_subcategories[] = $subcategory->id;
                         }
                     }
                 }
                 $articles->setState('filter.category_id', $include_subcategories);
             } else {
                 $articles->setState('filter.category_id', $catid);
             }
             $articles->setState('list.ordering', $params->get('article_ordering', 'a.ordering'));
             $articles->setState('list.direction', $params->get('article_ordering_direction', 'ASC'));
             $articles->setState('filter.featured', $params->get('show_front', 'show'));
             $articles->setState('filter.author_id', $params->get('created_by', ""));
             $articles->setState('filter.author_id.include', $params->get('author_filtering_type', 1));
             $articles->setState('filter.author_alias', $params->get('created_by_alias', ""));
             $articles->setState('filter.author_alias.include', $params->get('author_alias_filtering_type', 1));
             $excluded_articles = $params->get('excluded_articles', '');
             if ($excluded_articles) {
                 $excluded_articles = explode("\r\n", $excluded_articles);
                 $articles->setState('filter.article_id', $excluded_articles);
                 $articles->setState('filter.article_id.include', false);
                 // Exclude
             }
             $date_filtering = $params->get('date_filtering', 'off');
             if ($date_filtering !== 'off') {
                 $articles->setState('filter.date_filtering', $date_filtering);
                 $articles->setState('filter.date_field', $params->get('date_field', 'a.created'));
                 $articles->setState('filter.start_date_range', $params->get('start_date_range', '1000-01-01 00:00:00'));
                 $articles->setState('filter.end_date_range', $params->get('end_date_range', '9999-12-31 23:59:59'));
                 $articles->setState('filter.relative_date', $params->get('relative_date', 30));
             }
             $articles->setState('filter.language', $app->getLanguageFilter());
             $items = $articles->getItems();
             $show_date = $params->get('show_date', 0);
             $show_date2 = $params->get('show_date2', 0);
             $show_date_field = $params->get('show_date_field', 'created');
             $show_date_format = $params->get('show_date_format', 'Y-m-d H:i:s');
             $show_hits = $params->get('show_hits', 0);
             $show_author = $params->get('show_author', 0);
             $show_author2 = $params->get('show_author2', 0);
             $show_introtext = $params->get('show_introtext', 1);
             $show_introtext2 = $params->get('show_introtext2', 0);
             $show_image = $params->get('show_image', 0);
             $yt_image = $params->get('yt_image', 0);
             $introtext_limit = $params->get('introtext_limit', 100);
             $introtext_limit2 = $params->get('introtext_limit2', 100);
             $title_limit = $params->get('title_limit', '');
             $title_limit2 = $params->get('title_limit2', '');
             $option = $input->getCmd('option');
             $view = $input->getCmd('view');
             if ($option === 'com_content' && $view === 'article') {
                 $active_article_id = $input->getInt('id');
             } else {
                 $active_article_id = 0;
             }
             $groups[$catid]->pages = array('items' => $count + $subcount, 'total' => $count + $subcount ? ceil(count($items) / ($count + $subcount)) : 0, 'current' => $count + $subcount ? $start / ($count + $subcount) : 0);
             $groups[$catid]->articles = array();
             $groups[$catid]->subarticles = array();
             for ($j = $start; $j < $start + $count + $subcount; $j++) {
                 if (isset($items[$j])) {
                     $items[$j]->slug = $items[$j]->id . ':' . $items[$j]->alias;
                     $items[$j]->catslug = $items[$j]->catid ? $items[$j]->catid . ':' . $items[$j]->category_alias : $items[$j]->catid;
                     if ($access || in_array($items[$j]->access, $authorised)) {
                         $items[$j]->link = JRoute::_(ContentHelperRoute::getArticleRoute($items[$j]->slug, $items[$j]->catslug));
                     } else {
                         $app = JFactory::getApplication();
                         $menu = $app->getMenu();
                         $menuitems = $menu->getItems('link', 'index.php?option=com_users&view=login');
                         if (isset($menuitems[0])) {
                             $Itemid = $menuitems[0]->id;
                         } else {
                             if ($input->getInt('Itemid') > 0) {
                                 $Itemid = $input->getInt('Itemid');
                             }
                         }
                         $items[$j]->link = JRoute::_('index.php?option=com_users&view=login&Itemid=' . $Itemid);
                     }
                     $items[$j]->active = $items[$j]->id == $active_article_id ? ' active' : '';
                     $items[$j]->displayHits = $show_hits ? $items[$j]->hits : '';
                     $items[$j]->displayDate = '';
                     $items[$j]->displayAuthorName = '';
                     if ($j < $count + $start) {
                         if ($title_limit && strlen($items[$j]->title) > $title_limit) {
                             $items[$j]->title = mb_substr($items[$j]->title, 0, $title_limit) . '...';
                         }
                         if ($show_date) {
                             $items[$j]->displayDate = JHTML::_('date', $items[$j]->{$show_date_field}, $show_date_format);
                         }
                         if ($show_author) {
                             $items[$j]->displayAuthorName = $items[$j]->author;
                         }
                         $items[$j]->image = "";
                         $content = $items[$j]->introtext . $items[$j]->fulltext;
                         if ($show_image) {
                             $img = "";
                             $alt = $items[$j]->title;
                             $def_image = $params->get('def_image', '');
                             if ($yt_image != 0) {
                                 $regex = '/\\/\\/www.youtube.com\\/embed\\/([A-Za-z0-9_-]+)["\']/';
                                 if ($video_id = modFeatcatsHelper::srch_first_occ($regex, $content)) {
                                     $img = 'http://i1.ytimg.com/vi/' . $video_id . '/0.jpg';
                                     $url = "http://gdata.youtube.com/feeds/api/videos/" . $video_id;
                                     $doc = new DOMDocument();
                                     $doc->load($url);
                                     $alt = htmlspecialchars($doc->getElementsByTagName("title")->item(0)->nodeValue);
                                 }
                             }
                             if (!$img && $yt_image != 2) {
                                 $images = json_decode($items[$j]->images);
                                 if (isset($images->image_intro) and !empty($images->image_intro)) {
                                     $img = $images->image_intro;
                                     $alt = htmlspecialchars($images->image_intro_alt);
                                 } elseif (isset($images->image_fulltext) and !empty($images->image_fulltext)) {
                                     $img = $images->image_fulltext;
                                     $alt = htmlspecialchars($images->image_fulltext_alt);
                                 } else {
                                     $regex = "/<img[^>]+src\\s*=\\s*[\"']\\/?([^\"']+)[\"'][^>]*\\>/";
                                     $img = modFeatcatsHelper::srch_first_occ($regex, $content);
                                 }
                             }
                             if ($img or $def_image) {
                                 if ($params->get('thumb_image', 1)) {
                                     $img = str_replace(JURI::base(false), '', $img);
                                     $items[$j]->image = modFeatcatsHelper::getThumbnail($img, $params, $items[$j]->id, $alt);
                                 } else {
                                     $img_base = !modFeatcatsHelper::is_absolute($img) ? JURI::base(false) : '';
                                     $width = $params->get('thumb_width', 90);
                                     $height = $params->get('thumb_height', 90);
                                     if ($width) {
                                         $attribs['width'] = $width;
                                     }
                                     if ($height) {
                                         $attribs['height'] = $height;
                                     }
                                     $items[$j]->image = JHTML::_('image', $img_base . $img, $alt, $attribs);
                                 }
                             }
                         }
                         if ($show_introtext) {
                             $items[$j]->introtext = JHtml::_('content.prepare', $items[$j]->introtext);
                         }
                         switch ($show_introtext) {
                             case 1:
                                 $items[$j]->introtext = self::_cleanIntrotext($items[$j]->introtext);
                                 $items[$j]->displayIntrotext = self::truncate($items[$j]->introtext, $introtext_limit);
                                 break;
                             case 2:
                                 $items[$j]->displayIntrotext = $items[$j]->introtext;
                                 break;
                             default:
                                 $items[$j]->displayIntrotext = '';
                                 break;
                         }
                         $items[$j]->displayReadmore = $items[$j]->alternative_readmore;
                         $groups[$catid]->articles[] = $items[$j];
                     } else {
                         if ($title_limit2 && strlen($items[$j]->title) > $title_limit2) {
                             $items[$j]->title = mb_substr($items[$j]->title, 0, $title_limit2) . '...';
                         }
                         if ($show_date2) {
                             $items[$j]->displayDate = JHTML::_('date', $items[$j]->{$show_date_field}, $show_date_format);
                         }
                         if ($show_author2) {
                             $items[$j]->displayAuthorName = $items[$j]->author;
                         }
                         if ($show_introtext2) {
                             $items[$j]->introtext = JHtml::_('content.prepare', $items[$j]->introtext);
                         }
                         switch ($show_introtext2) {
                             case 1:
                                 $items[$j]->introtext = self::_cleanIntrotext($items[$j]->introtext);
                                 $items[$j]->displayIntrotext = self::truncate($items[$j]->introtext, $introtext_limit);
                                 break;
                             case 2:
                                 $items[$j]->displayIntrotext = $items[$j]->introtext;
                                 break;
                             default:
                                 $items[$j]->displayIntrotext = '';
                                 break;
                         }
                         $groups[$catid]->subarticles[] = $items[$j];
                     }
                 }
             }
         }
     }
     return $groups;
 }
コード例 #2
0
ファイル: helper.php プロジェクト: fur81/zofaxiopeu
 public static function getList(&$params)
 {
     $start = (int) JRequest::getVar('start', 0);
     $count = (int) $params->get('count', 3);
     $subcount = (int) $params->get('subcount', 0);
     $colcount = (int) $params->get('colcount', 3);
     $ajaxed = (int) $params->get('ajaxed', '');
     $pag = $params->get('pag_show', 0);
     $groups = array();
     $col_class = 'featcat';
     $categories = JCategories::getInstance('Content');
     if ($pag) {
         $limit = (int) $params->get('limit', '');
         $col_class .= ' pag';
     } else {
         $limit = $count + $subcount;
     }
     if (!$ajaxed) {
         $catids = $params->get('catid');
     } else {
         $catids = array();
         if (JRequest::getVar('catid')) {
             $catids[] = (int) JRequest::getVar('catid');
         } else {
             $catids[] = '';
         }
     }
     $col = 0;
     if ($catids) {
         foreach ($catids as $catid) {
             $col++;
             $groups[$catid] = new stdClass();
             $groups[$catid]->col_class = $col_class . ' col' . $col;
             if ($col == 1) {
                 $groups[$catid]->col_class .= ' firstcol';
             } elseif ($col == $colcount) {
                 $groups[$catid]->col_class .= ' lastcol';
             } elseif ($col == $colcount + 1) {
                 $groups[$catid]->col_class .= ' featcat_clr';
                 $col = 0;
             }
             $category = $categories->get($catid);
             $groups[$catid]->category_title = $category->title;
             $groups[$catid]->category_link = JRoute::_(ContentHelperRoute::getCategoryRoute($catid));
             $groups[$catid]->articles = array();
             $articles = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
             $articles->setState('list.select', 'a.id, a.title, a.alias, a.introtext, a.fulltext, a.images, ' . 'a.catid, a.created, a.created_by, a.created_by_alias, ' . 'a.modified, a.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 ');
             $app = JFactory::getApplication();
             $appParams = $app->getParams('com_content');
             $articles->setState('params', $appParams);
             $articles->setState('list.start', 0);
             $articles->setState('list.limit', $limit);
             $articles->setState('filter.published', 1);
             $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
             $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
             $articles->setState('filter.access', $access);
             $articles->setState('filter.category_id.include', 1);
             if ($params->get('show_child_category_articles', 0) && (int) $params->get('levels', 0) > 0) {
                 $subcategories = JModelLegacy::getInstance('Categories', 'ContentModel', array('ignore_request' => true));
                 $subcategories->setState('params', $appParams);
                 $levels = $params->get('levels', 1) ? $params->get('levels', 1) : 9999;
                 $subcategories->setState('filter.get_children', $levels);
                 $subcategories->setState('filter.published', 1);
                 $subcategories->setState('filter.access', $access);
                 $include_subcategories = array();
                 $include_subcategories[] = $catid;
                 $subcategories->setState('filter.parentId', $catid);
                 $recursive = true;
                 $items = $subcategories->getItems($recursive);
                 if ($items) {
                     foreach ($items as $subcategory) {
                         $condition = $subcategory->level - $subcategory->getParent()->level <= $levels;
                         if ($condition) {
                             $include_subcategories[] = $subcategory->id;
                         }
                     }
                 }
                 $articles->setState('filter.category_id', $include_subcategories);
             } else {
                 $articles->setState('filter.category_id', $catid);
             }
             $articles->setState('list.ordering', $params->get('article_ordering', 'a.ordering'));
             $articles->setState('list.direction', $params->get('article_ordering_direction', 'ASC'));
             $articles->setState('filter.featured', $params->get('show_front', 'show'));
             $articles->setState('filter.author_id', $params->get('created_by', ""));
             $articles->setState('filter.author_id.include', $params->get('author_filtering_type', 1));
             $articles->setState('filter.author_alias', $params->get('created_by_alias', ""));
             $articles->setState('filter.author_alias.include', $params->get('author_alias_filtering_type', 1));
             $excluded_articles = $params->get('excluded_articles', '');
             if ($excluded_articles) {
                 $excluded_articles = explode("\r\n", $excluded_articles);
                 $articles->setState('filter.article_id', $excluded_articles);
                 $articles->setState('filter.article_id.include', false);
                 // Exclude
             }
             $date_filtering = $params->get('date_filtering', 'off');
             if ($date_filtering !== 'off') {
                 $articles->setState('filter.date_filtering', $date_filtering);
                 $articles->setState('filter.date_field', $params->get('date_field', 'a.created'));
                 $articles->setState('filter.start_date_range', $params->get('start_date_range', '1000-01-01 00:00:00'));
                 $articles->setState('filter.end_date_range', $params->get('end_date_range', '9999-12-31 23:59:59'));
                 $articles->setState('filter.relative_date', $params->get('relative_date', 30));
             }
             $articles->setState('filter.language', $app->getLanguageFilter());
             $items = $articles->getItems();
             $show_date = $params->get('show_date', 0);
             $show_date2 = $params->get('show_date2', 0);
             $show_date_field = $params->get('show_date_field', 'created');
             $show_date_format = $params->get('show_date_format', 'Y-m-d H:i:s');
             $show_hits = $params->get('show_hits', 0);
             $show_author = $params->get('show_author', 0);
             $show_author2 = $params->get('show_author2', 0);
             $show_introtext = $params->get('show_introtext', 0);
             $show_introtext2 = $params->get('show_introtext2', 0);
             $show_image = $params->get('show_image', 0);
             $def_image = $params->get('def_image', '');
             $introtext_limit = $params->get('introtext_limit', 100);
             $introtext_limit2 = $params->get('introtext_limit2', 100);
             $title_limit = $params->get('title_limit', '');
             $title_limit2 = $params->get('title_limit2', '');
             $option = JRequest::getCmd('option');
             $view = JRequest::getCmd('view');
             if ($option === 'com_content' && $view === 'article') {
                 $active_article_id = JRequest::getInt('id');
             } else {
                 $active_article_id = 0;
             }
             $groups[$catid]->pages = array('items' => $count + $subcount, 'total' => ceil(count($items) / ($count + $subcount)), 'current' => $start / ($count + $subcount));
             $groups[$catid]->articles = array();
             $groups[$catid]->subarticles = array();
             for ($j = $start; $j < $start + $count + $subcount; $j++) {
                 if (isset($items[$j])) {
                     $items[$j]->slug = $items[$j]->id . ':' . $items[$j]->alias;
                     $items[$j]->catslug = $items[$j]->catid ? $items[$j]->catid . ':' . $items[$j]->category_alias : $items[$j]->catid;
                     if ($access || in_array($items[$j]->access, $authorised)) {
                         $items[$j]->link = JRoute::_(ContentHelperRoute::getArticleRoute($items[$j]->slug, $items[$j]->catslug));
                     } else {
                         $app = JFactory::getApplication();
                         $menu = $app->getMenu();
                         $menuitems = $menu->getItems('link', 'index.php?option=com_users&view=login');
                         if (isset($menuitems[0])) {
                             $Itemid = $menuitems[0]->id;
                         } else {
                             if (JRequest::getInt('Itemid') > 0) {
                                 $Itemid = JRequest::getInt('Itemid');
                             }
                         }
                         $items[$j]->link = JRoute::_('index.php?option=com_users&view=login&Itemid=' . $Itemid);
                     }
                     $items[$j]->active = $items[$j]->id == $active_article_id ? ' active' : '';
                     $items[$j]->displayHits = $show_hits ? $items[$j]->hits : '';
                     $items[$j]->displayDate = '';
                     $items[$j]->displayAuthorName = '';
                     if ($j < $count + $start) {
                         if ($title_limit && strlen($items[$j]->title) > $title_limit) {
                             $items[$j]->title = mb_substr($items[$j]->title, 0, $title_limit) . '...';
                         }
                         if ($show_date) {
                             $items[$j]->displayDate = JHTML::_('date', $items[$j]->{$show_date_field}, $show_date_format);
                         }
                         if ($show_author) {
                             $items[$j]->displayAuthorName = $items[$j]->author;
                         }
                         $items[$j]->image = "";
                         if ($show_image) {
                             $img = "";
                             $images = json_decode($items[$j]->images);
                             if (isset($images->image_intro) and !empty($images->image_intro)) {
                                 $img = $images->image_intro;
                             } elseif (isset($images->image_fulltext) and !empty($images->image_fulltext)) {
                                 $img = $images->image_fulltext;
                             } else {
                                 $regex = "/<img[^>]+src\\s*=\\s*[\"']\\/?([^\"']+)[\"'][^>]*\\>/";
                                 $search = $items[$j]->introtext . $items[$j]->fulltext;
                                 preg_match($regex, $search, $matches);
                                 $images = count($matches) ? $matches : array();
                                 if (count($images)) {
                                     $img = $images[1];
                                 }
                             }
                             $img_base = str_replace('modules/mod_featcats/assets/', '', JURI::base(false));
                             if ($img) {
                                 $attribs = array();
                                 if ($params->get('thumb_image', 1)) {
                                     $img = str_replace(JURI::base(false), '', $img);
                                     $items[$j]->image = modFeatcatsHelper::getThumbnail($img, $params, $items[$j]->id);
                                 } else {
                                     $width = $params->get('thumb_width', 90);
                                     $height = $params->get('thumb_height', 90);
                                     if ($width) {
                                         $attribs['width'] = $width;
                                     }
                                     if ($height) {
                                         $attribs['height'] = $height;
                                     }
                                     $items[$j]->image = JHTML::_('image', $img_base . '/' . $img, '', $attribs);
                                 }
                             } elseif ($def_image && ($size = @getimagesize(JPATH_BASE . '/' . $def_image))) {
                                 $items[$j]->image = JHTML::_('image', $img_base . '/' . $def_image, '', array('width' => $size[0], 'height' => $size[1]));
                             }
                         }
                         if ($show_introtext) {
                             $items[$j]->introtext = JHtml::_('content.prepare', $items[$j]->introtext);
                             $items[$j]->introtext = self::_cleanIntrotext($items[$j]->introtext);
                         }
                         $items[$j]->displayIntrotext = $show_introtext ? self::truncate($items[$j]->introtext, $introtext_limit) : '';
                         $items[$j]->displayReadmore = $items[$j]->alternative_readmore;
                         $groups[$catid]->articles[] = $items[$j];
                     } else {
                         if ($title_limit2 && strlen($items[$j]->title) > $title_limit2) {
                             $items[$j]->title = mb_substr($items[$j]->title, 0, $title_limit2) . '...';
                         }
                         if ($show_date2) {
                             $items[$j]->displayDate = JHTML::_('date', $items[$j]->{$show_date_field}, $show_date_format);
                         }
                         if ($show_author2) {
                             $items[$j]->displayAuthorName = $items[$j]->author;
                         }
                         if ($show_introtext2) {
                             $items[$j]->introtext = JHtml::_('content.prepare', $items[$j]->introtext);
                             $items[$j]->introtext = self::_cleanIntrotext($items[$j]->introtext);
                         }
                         $items[$j]->displayIntrotext = $show_introtext2 ? self::truncate($items[$j]->introtext, $introtext_limit2) : '';
                         $groups[$catid]->subarticles[] = $items[$j];
                     }
                 }
             }
         }
     }
     return $groups;
 }