示例#1
0
 function getList($params, $module)
 {
     $content = new YtcContent();
     $content->is_frontpage = $params->get('is_frontpage', 2);
     $content->is_cat_or_sec = $params->get('sec_or_cat', 1);
     if ($content->is_cat_or_sec == 0) {
         $content->cat_or_sec_ids = $params->get('sections', '');
     } else {
         $content->cat_or_sec_ids = $params->get('categories', '');
     }
     $content->featured = $params->get('featured', 2);
     $content->showtype = $params->get('showtype', 1);
     $content->category = $params->get('category', 0);
     $content->listIDs = $params->get('itemIds', '');
     $content->customUrl = $params->get('customUrl', '');
     $content->limit = $params->get('total');
     $content->sort_order_field = $params->get('sort_order_field', "created");
     $content->type_order = $params->get('sort_order', "ASC");
     $content->thumb_height = $params->get('thumb_height', "150px");
     $content->thumb_width = $params->get('thumb_width', "120px");
     $content->small_thumb_height = $params->get('small_thumb_height', "0");
     $content->small_thumb_width = $params->get('small_thumb_width', "0");
     $content->web_url = JURI::base();
     $content->max_title = $params->get('limittitle', 25);
     $content->max_main_description = $params->get('limit_main_description', 25);
     $content->max_normal_description = $params->get('limit_normal_description', 25);
     $content->resize_folder = JPATH_CACHE . DS . $module->module . DS . "images";
     $content->url_to_resize = $content->web_url . "cache/" . $module->module . "/images/";
     $content->cropresizeimage = $params->get('cropresizeimage', 1);
     $items = $content->getList();
     //var_dump($items);die;
     return $items;
 }
 function getList()
 {
     global $mainframe;
     $items = array();
     $arrCustomUrl = YtcContent::getArrURL();
     $db =& JFactory::getDBO();
     $user =& JFactory::getUser();
     $aid = $user->get('aid', 0);
     $contentConfig =& JComponentHelper::getParams('com_content');
     $noauth = !$contentConfig->get('shownoauth');
     jimport('joomla.utilities.date');
     $date = new JDate();
     $now = $date->toMySQL();
     $nullDate = $db->getNullDate();
     if ($this->sort_order_field == 'random') {
         $orderby = ' ORDER BY rand()';
     } elseif ($this->sort_order_field == 'created' || $this->sort_order_field == 'modified') {
         $this->type_order = 'DESC';
         $orderby = ' ORDER BY ' . $this->sort_order_field . ' ' . $this->type_order;
     } elseif ($this->sort_order_field == 'title' || $this->sort_order_field == 'ordering') {
         $this->type_order = 'ASC';
         $orderby = ' ORDER BY ' . $this->sort_order_field . ' ' . $this->type_order;
     } else {
         $orderby = ' ORDER BY ' . $this->sort_order_field . ' ' . $this->type_order;
     }
     $limit = " LIMIT {$this->limit}";
     if ($this->showtype == 0) {
         if (is_array($this->cat_or_sec_ids)) {
             $ary = " in (" . implode(",", $this->cat_or_sec_ids) . ")";
         } else {
             $ary = " = " . (int) $this->cat_or_sec_ids;
         }
     } else {
         $ary = '';
     }
     $this->listIDs = explode(",", $this->listIDs);
     if ($this->showtype == 1) {
         //var_dump($this->listIDs);die;
         if (is_array($this->listIDs)) {
             $id_item = " in (" . implode(",", $this->listIDs) . ")";
         } else {
             $id_item = " = " . (int) $this->listIDs;
         }
     }
     // query to determine article count
     $query = 'SELECT a.*,u.name as creater,cc.description as catdesc, cc.title as cattitle,s.description as secdesc, s.title as sectitle,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,' . ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug,' . ' CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(":", s.id, s.alias) ELSE s.id END as secslug' . ' FROM #__content AS a' . ' INNER JOIN #__categories AS cc ON cc.id = a.catid' . ' INNER JOIN #__sections AS s ON s.id = a.sectionid' . ' left JOIN #__users AS u ON a.created_by = u.id';
     $query .= ' WHERE a.state = 1 ' . ($noauth ? ' AND a.access <= ' . (int) $aid . ' AND cc.access <= ' . (int) $aid . ' AND s.access <= ' . (int) $aid : '') . ' AND (a.publish_up = ' . $db->Quote($nullDate) . ' OR a.publish_up <= ' . $db->Quote($now) . ' ) ' . ' AND (a.publish_down = ' . $db->Quote($nullDate) . ' OR a.publish_down >= ' . $db->Quote($now) . ' )' . ($this->is_cat_or_sec ? "\n AND cc.id" . $ary : ' AND s.id' . $ary) . ' AND a.id' . ($this->showtype ? $id_item : '') . ' AND cc.section = s.id' . ' AND cc.published = 1' . ' AND s.published = 1';
     if ($this->is_frontpage == 0) {
         $query .= ' AND a.id not in (SELECT content_id FROM #__content_frontpage )';
     } else {
         if ($this->is_frontpage == 1) {
             $query .= ' AND a.id in (SELECT content_id FROM #__content_frontpage )';
         }
     }
     $query .= $orderby . $limit;
     //echo $query;die;
     $db->setQuery($query);
     //echo $db->getQuery(); die;
     $rows = $db->loadObjectList();
     //var_dump($rows);die;
     global $mainframe;
     $arrCustomUrl = YtcContent::getArrURL();
     JPluginHelper::importPlugin('content');
     $dispatcher =& JDispatcher::getInstance();
     $params =& $mainframe->getParams('com_content');
     $limitstart = $this->limit;
     for ($i = 0; $i < count($rows); $i++) {
         $rows[$i]->text = $rows[$i]->introtext;
         $results = $dispatcher->trigger('onPrepareContent', array(&$rows[$i], &$params, $limitstart));
         $rows[$i]->introtext = $rows[$i]->text;
         $items[$i]['id'] = $rows[$i]->id;
         $items[$i]['img'] = $this->getImage($rows[$i]->text);
         $items[$i]['title'] = $rows[$i]->title;
         $items[$i]['publish'] = $rows[$i]->publish_up;
         $items[$i]['content'] = $this->removeImage($rows[$i]->text);
         if (array_key_exists($rows[$i]->id, $arrCustomUrl)) {
             $link = $arrCustomUrl[$rows[$i]->id];
             // echo '<pre>'.print_r($link);die;
             //echo($link);die;
         } else {
             $link = JRoute::_(ContentHelperRoute::getArticleRoute($rows[$i]->slug, $rows[$i]->catslug, $rows[$i]->sectionid));
         }
         $items[$i]['link'] = $link;
     }
     $items = $this->update($items);
     //var_dump($items);die;
     /*   Process Images*/
     return $items;
 }