нямам на идея как правилно да бутна strtotime +3 hours
това е целия helper.php файл
$now е накрая на файла
<?php
/**
*
* @version See field version manifest file
* @package See field name manifest file
* @copyright See field copyright manifest file
* @license See field name manifest file
*
*/
// no direct access
defined('_JEXEC') or die;
// define ds variable for joomla 3 compatibility
if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
require_once dirname(__FILE__).DS.'include'.DS.'simple_html_dom.php';
require_once dirname(__FILE__).DS.'include'.DS.'vikresizer.php';
include_once dirname(__FILE__).DS.'administrator'.DS.'elements'.DS.'digigreg_api.php';
class Digi_Showcase_Helper {
private $catId;
private $rows;
private $columns;
private $carousel;
private $carouselDisplayQuantity;
private $timeline;
private $timelineDisplayQuantity;
private $sphere;
private $sphereDisplayQuantity;
private $order_by;
private $order_type;
private $show_image;
private $generate_thumbnail;
private $image_width;
private $image_height;
private $show_title;
private $show_description;
private $characters;
private $show_created_date;
private $articles;
public function __construct($catId=0, $rows=1, $columns=1, $carousel, $carouselDisplayQuantity, $timeline, $timelineDisplayQuantity, $sphere, $sphereDisplayQuantity, $order_by, $order_type, $show_image, $generate_thumbnail, $image_width, $image_height, $show_title, $show_description, $characters, $show_created_date) {
$this->catId = $catId;
$this->rows = $rows;
$this->columns = $columns;
$this->carousel = $carousel;
$this->slides = $carouselDisplayQuantity;
$this->timeline = $timeline;
$this->timeline_items = $timelineDisplayQuantity;
$this->sphere = $sphere;
$this->sphere_items = $sphereDisplayQuantity;
$this->order_by = $order_by;
$this->order_type = $order_type;
$this->show_image = $show_image;
$this->generate_thumbnail = $generate_thumbnail;
$this->image_width = $image_width;
$this->image_height = $image_height;
$this->show_title = $show_title;
$this->show_description = $show_description;
$this->characters = $characters;
$this->show_created_date = $show_created_date;
$this->articles = array();
}
private function _get_resized_article_image($article_id, $image_fullpath, $image_width='120', $image_height='80') {
$pathinfo = pathinfo ( $image_fullpath );
$temp_imagepath = JPATH_BASE.DS.'modules'.DS.'mod_digi_showcase'.DS.'images'.DS.'temp_'.$article_id.'.'.$pathinfo['extension'];
$dest_image = 'article_'.$article_id.'.'.$pathinfo['extension'];
$dest_imagepath = JPATH_BASE.DS.'modules'.DS.'mod_digi_showcase'.DS.'images'.DS.$dest_image;
list ($owid, $ohei) = getimagesize($image_fullpath);
if($owid>$ohei) {
$toheight = $image_height;
$towidth = round(($owid*$image_height)/$ohei);
if($towidth<$image_width) {
$towidth = $image_width;
$toheight = round(($ohei*$image_width)/$owid);
}
} else {
$towidth = $image_width;
$toheight = round(($ohei*$image_width)/$owid);
if($toheight<$image_height) {
$toheight = $image_height;
$towidth = round(($owid*$image_height)/$ohei);
}
}
$vikresizer = new vikResizer();
$vikresizer->scaleImage($image_fullpath, $temp_imagepath, $towidth, $toheight);
$vikresizer->croppedCenterImage($temp_imagepath, $dest_imagepath, $image_width, $image_height);
unlink($temp_imagepath);
return JUri::root().'/modules/mod_digi_showcase/images/'.$dest_image;
}
private function _truncate_sentence($sentence, $characters) {
$sentence_a = explode(' ', $sentence);
$sentence_text = '';
$i=0;
while((strlen($sentence_text)<$characters)&&($i<(count($sentence_a))))
{
$sentence_text .= ($i>0)?' '.$sentence_a[$i]:$sentence_a[$i];
$i++;
}
if(trim($sentence_text)=='')
{
$sentence_text .= $sentence_a[0];
}
if(strlen(trim($sentence_text))<strlen(trim($sentence)))
{
$sentence_text = trim($sentence_text)."…";
}
return $sentence_text;
}
private function _get_article_data($article) {
// get article data
$articleId = $article['id'];
$itemId = '';
$categoryId = $article['catid'];
$title = $article['title'];
$articleAlias = $article['alias'];
$itemAlias = '';
$content = $article['introtext'];
$created = $article['created'];
$articleImages = $article['images'];
$imagesData = json_decode($articleImages);
$introImage = $imagesData->image_intro;
$image = '';
$generate_thumbnail = $this->generate_thumbnail;
// if exist get the associated item id to build the correct link
$dbo = JFactory::getDBO();
$query = $dbo->getQuery(true);
$query->SELECT('menu.id AS id,menu.alias AS alias,menu.link AS link');
$query->FROM('#__menu AS menu');
$query->GROUP('menu.id,menu.alias,menu.link');
$dbo->setQuery($query);
$results = $dbo->loadAssocList();
foreach ($results as &$result) {
// if current article is associated with a single article menu voice
if (strpos($result['link'], 'view=article&id='.$articleId) !== false) {
$itemId = $result['id'];
$itemAlias = $result['alias'];
//echo 'Single article';
break;
}
}
if ($itemId == '') {
foreach ($results as &$result) {
// if current article is associated with a blog category menu voice
if (strpos($result['link'], 'view=category&layout=blog&id='.$categoryId) !== false) {
$itemId = $result['id'];
$itemAlias = $result['alias'];
//echo 'Blog category';
break;
}
}
}
if ($itemId == '') {
foreach ($results as &$result) {
// if current article is associated with a list category menu voice
if (strpos($result['link'], 'view=category&id='.$categoryId) !== false) {
$itemId = $result['id'];
$itemAlias = $result['alias'];
//echo 'List category';
break;
}
}
}
// if exist find the first image inside the article
if(trim($content)!='') {
$html_obj = str_get_html ( $content );
$images = $html_obj->find('img');
// if exist create thumbnail of the first image inside the article
if(!empty($images)) {
if ($generate_thumbnail == 1) {
$image_fullpath = JPATH_BASE.DS.$images[0]->attr['src'];
$image = $this->_get_resized_article_image($articleId, $image_fullpath, $this->image_width, $this->image_height);
} else {
$image = $images[0]->attr['src'];
}
}
}
// if exist create thumbnail of intro image
if ($generate_thumbnail == 1) {
if(!empty($introImage)) {
$image_fullpath = JPATH_BASE.DS.$introImage;
$introImage = $this->_get_resized_article_image($articleId, $image_fullpath, $this->image_width, $this->image_height);
}
}
// build the article array which contain all parsed article data
$data = array(
'id'=>$articleId,
'itemid'=>$itemId,
'categoryid'=>$categoryId,
'title'=>$this->_truncate_sentence($title, $this->characters),
'alias'=>$articleAlias,
'itemalias'=>$itemAlias,
'content'=>$this->_truncate_sentence($content, $this->characters),
'created'=>$created,
'intro-image'=>$introImage,
'image'=>$image,
'link'=>'index.php?option=com_content&view=article'
);
return $data;
}
public function getArticles() {
$carousel = $this->carousel;
$slides = $this->slides;
$timeline = $this->timeline;
$timeline_items = $this->timeline_items;
$sphere = $this->sphere;
$sphere_items = $this->sphere_items;
// define current date and time
$now = (new DateTime())->format('Y-m-d H:i:s');
$dbo = JFactory :: getDBO();
if (($carousel == 0) && ($timeline == 0) && ($sphere == 0)) {
$limit = ((int)$this->rows)*((int)$this->columns);
} else if (($carousel == 1) && ($timeline == 0) && ($sphere == 0)) {
$limit = $slides;
} else if (($carousel == 0) && ($timeline == 1) && ($sphere == 0)) {
$limit = $timeline_items;
} else if (($carousel == 0) && ($timeline == 0) && ($sphere == 1)) {
$limit = $sphere_items;
}
$currentLang = JFactory :: getLanguage();
$lang = $currentLang->getTag();
// split categories array
$catFilter = 'ca.id=%d';
$catIDs = $this->catId;
for ($i = 0; $i < count($catIDs); ++$i) {
$catFilter .= ' OR ca.id='.$catIDs[$i];
}
$query = sprintf("SELECT co.* FROM `#__content` co ");
if($this->catId>0) {
$query .= sprintf(" JOIN `#__categories` ca ON co.catid=ca.id WHERE co.state=1
AND ( co.publish_up < '".$now."')
AND (co.publish_down > '".$now."' OR co.publish_down IS NULL)
AND ( $catFilter )
AND ( co.language='$lang' OR co.language='*' ) ", $this->catId);
}
$query .= sprintf(" ORDER BY co.%s %s LIMIT %d", $this->order_by, $this->order_type, $limit);
$dbo->setQuery($query);
$dbo->Query($query);
$results = $dbo->loadAssocList();
if(!empty($results)) {
foreach($results AS $result) {
$this->articles[] = $this->_get_article_data($result);
}
}
return $this->articles;
}
}
?>