joomla_test/modules/mod_yahoostylenewsslider/yahoostylenewsslider/components/content.php
2020-01-02 22:20:31 +07:00

206 lines
10 KiB
PHP

<?php
/**
* helper.php Social Crowd Module for Joomla
*
* @version 1.2
* @package mod_socialcrowd
* @author Sabuj kundu ( http://codeboxr.com )
* @copyright Copyright (C) 2011-2013 http://codeboxr.com. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @ help: http://codeboxr.com/product/social-crowd-for-joomla
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
//var_dump(JPATH_COMPONENT);
/*require_once (JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'article.php');*/
/**
* Social Crowd Module
*
* @package Joomla
* @subpackage Module
* @since 1.0
*/
class modYahooStyleNewsSliderContent{
static function getItemContent($params, $module){
require_once JPATH_SITE.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_content'. DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'article.php';
require_once JPATH_SITE.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_content'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'route.php';
$articles = array();
$articleids = array();
$article = new ContentModelArticle();
$articleselopt = intval($params->get('articleselopt', 2));
$categories = $params->get('contentcat', array());
$contenttype = $params->get('contenttype',0);
$nothumb = JURI::root().'modules/mod_yahoostylenewsslider/yahoostylenewsslider/images/no_thumb.jpg';
//var_dump($categories);
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$k = 0;
if($articleselopt == 2):
for($i = 1;$i <= 20; $i++){
$singlarticletemp = new stdClass();
$id = $params->get('id'.$i);
// var_dump($id);
if(!$id) continue;
$query->clear();
$query->select('a.state');
$query->from('#__content AS a');
$query->where('a.id = ' . (int) $id);
//$query->where('a.state = 1');
$db->setQuery($query);
$state = trim($db->loadResult());
if(intval($state) != 1) continue;
$articletemp = $article->getItem($id);
$singlarticletemp->id = $articletemp->id;
$singlarticletemp->title = $articletemp->title;
$singlarticletemp->introtext = $articletemp->introtext;
$singlarticletemp->fulltext = $articletemp->fulltext;
$singlarticletemp->articletext = $contenttype ? $articletemp->fulltext:$articletemp->introtext;
$singlarticletemp->created = $articletemp->created;
//$singlarticletemp->images = $articletemp->images;
//echo '<pre>';var_dump($articletemp );echo '</pre>';
$query->clear();
$query->select('a.catid');
$query->from('#__content AS a');
$query->where('a.id = ' . (int) $id);
$query->where('a.state = 1');
$db->setQuery($query);
$catid = trim($db->loadResult());
$singlarticletemp->permalink = JRoute::_(ContentHelperRoute::getArticleRoute($articletemp->id.($articletemp->alias?':'.$articletemp->alias:''), $catid.($articletemp->category_alias?':'.$articletemp->category_alias:'')));
// var_dump($catid);
$img_temp = preg_match_all('/.*"image_intro":"([^"]+)"/',stripslashes($articletemp->images),$matches);
$imgpath = ($img_temp? $matches[1][0]:'');
if(!$img_temp){
$img_temp = preg_match_all('/.*"image_fulltext":"([^"]+)"/',stripslashes($articletemp->images),$matches);
$imgpath = ($img_temp? $matches[1][0]:'');
}
if(!$img_temp){
$img_temp = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $articletemp->introtext,$matches)?true
:preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $articletemp->fulltext,$matches);
$imgpath = ($img_temp? $matches[1][0]:'');
}
$singlarticletemp->image = $imgpath ? $imgpath:'';
if($singlarticletemp->image && strpos($singlarticletemp->image,'http') === false){
$singlarticletemp->image = JURI::base().$singlarticletemp->image;
}
if($singlarticletemp->image == '' ){$singlarticletemp->image = $nothumb;}
//var_dump($imgpath);
//var_dump(JURI::base());
$articles[] = $singlarticletemp;
}
else:
$catids = $categories ? '('.implode(',',$categories).')':'';
//var_dump($catids);
$ordering = $params->get('content_ordering' ,'a.id');
$numofartcils = intval($params->get('numofartcils' ,20));
$db = JFactory::getDbo();
$user = JFactory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
$date = JFactory::getDate();
$nullDate = $db->getNullDate();
//$now = $date->toMySQL();
$now = $date->toSql() ;//date('Y-m-d h:i:s');
$query = $db->getQuery(true);
$query->select('a.id,a.title,a.introtext,a.catid,a.state,a.created_by_alias ,a.fulltext,c.title AS cattitle,u.name AS author');
$query->select('a.created_by = '.$user->id.' AS canedit, a.created_by_alias AS author_alias'); //find edit permission for showing edit icon
$query->select('a.images AS image');
$query->select('a.created as created');
$query->select('a.modified as modified');
$query->select('a.publish_up as publish_up');
$query->select('CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug');
$query->select('CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as catslug');
$query->from('#__content AS a');
$query->leftJoin('#__categories AS c ON c.id = a.catid');
$query->leftJoin('#__users AS u ON u.id = a.created_by');
$query->where('a.state = 1');
$query->where('c.published = 1'); //if category is unpublished no article of that category will be fetched
$query->where('a.access IN (' . $groups . ')');
$query->where('(a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).')');
$query->where('(a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).')');
if($catids){
$query->where('a.catid IN '.$catids);
}
$query->order( $ordering );
//$query->order( $grpbycattitle.$ordering ); // group by category if option is set then order according to the ordering field
// $query->group('a.catid');
$db->setQuery($query,0,$numofartcils);//$numberofarticle
$output = $db->loadObjectList();
if($output != '' && count($output)){
foreach($output as $key => $item){
$singlarticletemp = new stdClass();
$singlarticletemp->id = $item->id;
$singlarticletemp->title = $item->title;
$singlarticletemp->introtext = $item->introtext;
$singlarticletemp->fulltext = $item->fulltext;
$singlarticletemp->articletext = $contenttype ? $item->fulltext:$item->introtext;
$singlarticletemp->created = $item->created;
//$singlarticletemp->images = $articletemp->images;
//echo '<pre>';var_dump($articletemp );echo '</pre>';
$singlarticletemp->permalink = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
// var_dump($catid);
$img_temp = preg_match_all('/.*"image_intro":"([^"]+)"/',stripslashes($item->image),$matches);
$imgpath = ($img_temp? $matches[1][0]:'');
if(!$img_temp){
$img_temp = preg_match_all('/.*"image_fulltext":"([^"]+)"/',stripslashes($item->image),$matches);
$imgpath = ($img_temp? $matches[1][0]:'');
}
if(!$img_temp){
$img_temp = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $item->introtext,$matches)?true
:preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $item->fulltext,$matches);
$imgpath = ($img_temp? $matches[1][0]:'');
}
$singlarticletemp->image = $imgpath ? $imgpath:'';
if($singlarticletemp->image && strpos($singlarticletemp->image,'http') === false){
$singlarticletemp->image = JURI::base().$singlarticletemp->image;
}
if($singlarticletemp->image == '' ){$singlarticletemp->image = $nothumb;}
//var_dump($imgpath);
//var_dump(JURI::base());
$articles[] = $singlarticletemp;
}
}
// var_dump($catids);
endif;
//echo '<pre>';var_dump($article->getItem($articleids[0]));echo '</pre>';
return $articles;
}
}
?>