File manager - Edit - /home/jardides/www/Jardi-design/j37/plugins/sliderck/k2/helper/helper_k2.php
Back
<?php /** * @name Slider CK * @copyright Copyright (C) 2017. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @author Cedric Keiflin - http://www.template-creator.com - http://www.joomlack.fr */ // No direct access defined('_JEXEC') or die; jimport('joomla.filesystem.folder'); /** * Helper Class. */ class SliderckHelpersourceK2 { private static $params; /* * Get the items from the source */ public static function getItems($params) { if (!file_exists(JPATH_SITE . '/components/com_k2/helpers/route.php')) { echo '<p style="color:red;font-weight:bold;">SLIDER CK MESSAGE : Component K2 not found !</p>'; return false; } require_once JPATH_SITE . '/components/com_k2/helpers/route.php'; if (empty(self::$params)) { self:$params = $params; } // load the main helper include_once JPATH_ROOT . '/modules/mod_sliderck/helper.php'; // load the com_content language $lang = JFactory::getLanguage(); $lang->load('com_content'); $app = JFactory::getApplication(); $limit = (int) $params->get('numberslides', 0); $cid = $params->get('k2_catid', NULL); $ordering = $params->get('k2_article_ordering', ''); $componentParams = JComponentHelper::getParams('com_k2'); $limitstart = $app->input->get('limitstart', 0, 'int'); $user = JFactory::getUser(); $aid = $user->get('aid'); $db = JFactory::getDBO(); $jnow = JFactory::getDate(); $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql(); $nullDate = $db->getNullDate(); $query = "SELECT i.*,"; if ($ordering == 'modified') { $query .= " CASE WHEN i.modified = 0 THEN i.created ELSE i.modified END as lastChanged,"; } $query .= "c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams"; if ($ordering == 'best') $query .= ", (r.rating_sum/r.rating_count) AS rating"; if ($ordering == 'comments') $query .= ", COUNT(comments.id) AS numOfComments"; $query .= " FROM #__k2_items as i RIGHT JOIN #__k2_categories c ON c.id = i.catid"; if ($ordering == 'best') $query .= " LEFT JOIN #__k2_rating r ON r.itemID = i.id"; if ($ordering == 'comments') $query .= " LEFT JOIN #__k2_comments comments ON comments.itemID = i.id"; $tagsFilter = $params->get('tags'); if($tagsFilter && is_array($tagsFilter) && count($tagsFilter)) { $query .= " INNER JOIN #__k2_tags_xref tags_xref ON tags_xref.itemID = i.id"; } if (K2_JVERSION != '15') { $query .= " WHERE i.published = 1 AND i.access IN(".implode(',', $user->getAuthorisedViewLevels()).") AND i.trash = 0 AND c.published = 1 AND c.access IN(".implode(',', $user->getAuthorisedViewLevels()).") AND c.trash = 0"; } else { $query .= " WHERE i.published = 1 AND i.access <= {$aid} AND i.trash = 0 AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0"; } $query .= " AND ( i.publish_up = ".$db->Quote($nullDate)." OR i.publish_up <= ".$db->Quote($now)." )"; $query .= " AND ( i.publish_down = ".$db->Quote($nullDate)." OR i.publish_down >= ".$db->Quote($now)." )"; // if ($params->get('catfilter', '1')) // { if ($cid != '' && (is_array($cid) && $cid[0] != '')) { if (is_array($cid)) { if ($params->get('k2_show_child_category_articles')) { $itemListModel = K2Model::getInstance('Itemlist', 'K2Model'); $categories = $itemListModel->getCategoryTree($cid); $sql = @implode(',', $categories); $query .= " AND i.catid IN ({$sql})"; } else { JArrayHelper::toInteger($cid); $query .= " AND i.catid IN(".implode(',', $cid).")"; } } else { if ($params->get('k2_show_child_category_articles')) { $itemListModel = K2Model::getInstance('Itemlist', 'K2Model'); $categories = $itemListModel->getCategoryTree($cid); $sql = @implode(',', $categories); $query .= " AND i.catid IN ({$sql})"; } else { $query .= " AND i.catid=".(int)$cid; } } } // } // $tagsFilter = $params->get('tags'); // if($tagsFilter && is_array($tagsFilter) && count($tagsFilter)) // { // $query .= " AND tags_xref.tagID IN(".implode(',', $tagsFilter).")"; // } // $usersFilter = $params->get('users'); // if($usersFilter && is_array($usersFilter) && count($usersFilter)) // { // $query .= " AND i.created_by IN(".implode(',', $usersFilter).") AND i.created_by_alias = ''"; // } if ($params->get('k2_show_front') == 'hide') $query .= " AND i.featured != 1"; if ($params->get('k2_show_front') == 'only') $query .= " AND i.featured = 1"; // if ($params->get('videosOnly')) // $query .= " AND (i.video IS NOT NULL AND i.video!='')"; // if ($ordering == 'comments') // $query .= " AND comments.published = 1"; if (K2_JVERSION != '15') { if ($app->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $query .= " AND c.language IN (".$db->Quote($languageTag).", ".$db->Quote('*').") AND i.language IN (".$db->Quote($languageTag).", ".$db->Quote('*').")"; } } $order_dir = $params->get('k2_article_ordering_direction', 'ASC'); switch ($ordering) { case 'created' : $orderby = 'i.created ' . $order_dir; break; // case 'rdate' : // $orderby = 'i.created DESC'; // break; case 'title' : $orderby = 'i.title ' . $order_dir; break; // case 'ralpha' : // $orderby = 'i.title DESC'; // break; case 'ordering' : $orderby = 'i.ordering ' . $order_dir; break; case 'fp.ordering' : $orderby = 'i.featured_ordering ' . $order_dir; break; case 'hits' : // if ($params->get('popularityRange')) // { // $datenow = JFactory::getDate(); // $date = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql(); // $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL ".$params->get('popularityRange')." DAY) "; // } $orderby = 'i.hits ' . $order_dir; break; // case 'rand' : // $orderby = 'RAND() ' . $order_dir; // break; case 'best' : $orderby = 'rating ' . $order_dir; break; case 'comments' : if ($params->get('popularityRange')) { $datenow = JFactory::getDate(); $date = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql(); $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL ".$params->get('popularityRange')." DAY) "; } $query .= " GROUP BY i.id "; $orderby = 'numOfComments DESC'; break; case 'modified' : $orderby = 'lastChanged ' . $order_dir; break; case 'publish_up' : $orderby = 'i.publish_up ' . $order_dir; break; default : $orderby = 'i.id ' . $order_dir; break; } $query .= " ORDER BY ".$orderby; // $db->setQuery($query, 0, $limit); $db->setQuery($query); $items = $db->loadObjectList(); $model = K2Model::getInstance('Item', 'K2Model'); $slideItems = array(); if (count($items)) { foreach ($items as $item) { $item->event = new stdClass; $item->image = null; //Clean title $item->title = JFilterOutput::ampReplace($item->title); //Images if ($params->get('k2_articleimgsource', 'introimage') == 'introimage') { $date = JFactory::getDate($item->modified); $timestamp = '?t='.$date->toUnix(); if (JFile::exists(JPATH_SITE.'/media/k2/items/cache'.'/'.md5("Image".$item->id).'_XS.jpg')) { $item->image = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg'; if ($componentParams->get('imageTimestamp')) { $item->imageXSmall .= $timestamp; } } if (JFile::exists(JPATH_SITE.'/media/k2/items/cache'.'/'.md5("Image".$item->id).'_S.jpg')) { $item->image = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg'; if ($componentParams->get('imageTimestamp')) { $item->imageSmall .= $timestamp; } } if (JFile::exists(JPATH_SITE.'/media/k2/items/cache'.'/'.md5("Image".$item->id).'_M.jpg')) { $item->image = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg'; if ($componentParams->get('imageTimestamp')) { $item->imageMedium .= $timestamp; } } if (JFile::exists(JPATH_SITE.'/media/k2/items/cache'.'/'.md5("Image".$item->id).'_L.jpg')) { $item->image = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg'; if ($componentParams->get('imageTimestamp')) { $item->imageLarge .= $timestamp; } } if (JFile::exists(JPATH_SITE.'/media/k2/items/cache'.'/'.md5("Image".$item->id).'_XL.jpg')) { $item->image = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg'; if ($componentParams->get('imageTimestamp')) { $item->imageXLarge .= $timestamp; } } if (JFile::exists(JPATH_SITE.'/media/k2/items/cache'.'/'.md5("Image".$item->id).'_Generic.jpg')) { if (! $item->image) $item->image = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg'; if ($componentParams->get('imageTimestamp')) { $item->imageGeneric .= $timestamp; } } // $image = 'image'.$params->get('itemImgSize', 'Small'); // if (isset($item->$image)) // $item->image = $item->$image; } else { $search_images = preg_match('/<img(.*?)src="(.*?)"(.*?)\/>/is', $item->introtext, $imgresult); $item->image = (isset($imgresult[2]) && $imgresult[2] != '') ? (substr($imgresult[2],0,4) == 'http' ? $imgresult[2] : $imgresult[2]) : false; $item->introtext =(isset($imgresult[2])) ? str_replace($imgresult[0], '', $item->introtext) : $item->introtext; } // if no image, then don't include in the slideshow if (! $item->image) continue; //Read more link $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id.':'.urlencode($item->alias), $item->catid.':'.urlencode($item->categoryalias)))); //Tags if ($params->get('itemTags')) { $tags = $model->getItemTags($item->id); for ($i = 0; $i < sizeof($tags); $i++) { $tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name)); } $item->tags = $tags; } //Category link if ($params->get('itemCategory')) $item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid.':'.urlencode($item->categoryalias)))); //Extra fields if ($params->get('itemExtraFields')) { $item->extra_fields = $model->getItemExtraFields($item->extra_fields, $item); } //Comments counter if ($params->get('itemCommentsCounter')) $item->numOfComments = $model->countItemComments($item->id); //Attachments if ($params->get('itemAttachments')) $item->attachments = $model->getItemAttachments($item->id); //Video if ($params->get('itemVideo')) { $params->set('vfolder', 'media/k2/videos'); $params->set('afolder', 'media/k2/audio'); $item->text = $item->video; if (K2_JVERSION == '15') { $dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart)); } else { $dispatcher->trigger('onContentPrepare', array('mod_k2_content.', &$item, &$params, $limitstart)); } $item->video = $item->text; } // Introtext $item->text = ''; if ($params->get('itemIntroText')) { // Word limit if ($params->get('itemIntroTextWordLimit')) { $item->text .= K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit')); } else { $item->text .= $item->introtext; } } // Restore the intotext variable after plugins execution $item->introtext = $item->text ? $item->text : $item->introtext; //Clean the plugin tags $item->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext); //Author if ($params->get('itemAuthor')) { if (!empty($item->created_by_alias)) { $item->author = $item->created_by_alias; $item->authorGender = NULL; $item->authorDescription = NULL; if ($params->get('itemAuthorAvatar')) $item->authorAvatar = K2HelperUtilities::getAvatar('alias'); $item->authorLink = Juri::root(true); } else { $author = JFactory::getUser($item->created_by); $item->author = $author->name; $query = "SELECT `description`, `gender` FROM #__k2_users WHERE userID=".(int)$author->id; $db->setQuery($query, 0, 1); $result = $db->loadObject(); if ($result) { $item->authorGender = $result->gender; $item->authorDescription = $result->description; } else { $item->authorGender = NULL; $item->authorDescription = NULL; } if ($params->get('itemAuthorAvatar')) { $item->authorAvatar = K2HelperUtilities::getAvatar($author->id, $author->email, $componentParams->get('userImageWidth')); } //Author Link $item->authorLink = JRoute::_(K2HelperRoute::getUserRoute($item->created_by)); } } // Author avatar if ($params->get('itemAuthorAvatar') && !isset($item->authorAvatar)) { if (!empty($item->created_by_alias)) { $item->authorAvatar = K2HelperUtilities::getAvatar('alias'); $item->authorLink = Juri::root(true); } else { $jAuthor = JFactory::getUser($item->created_by); $item->authorAvatar = K2HelperUtilities::getAvatar($jAuthor->id, $jAuthor->email, $componentParams->get('userImageWidth')); $item->authorLink = JRoute::_(K2HelperRoute::getUserRoute($item->created_by)); } } // Extra fields plugins if (is_array($item->extra_fields)) { foreach ($item->extra_fields as $key => $extraField) { if ($extraField->type == 'textarea' || $extraField->type == 'textfield') { $tmp = new JObject(); $tmp->text = $extraField->value; if ($params->get('JPlugins', 1)) { if (K2_JVERSION != '15') { $dispatcher->trigger('onContentPrepare', array('mod_k2_content', &$tmp, &$params, $limitstart)); } else { $dispatcher->trigger('onPrepareContent', array(&$tmp, &$params, $limitstart)); } } if ($params->get('K2Plugins', 1)) { $dispatcher->trigger('onK2PrepareContent', array(&$tmp, &$params, $limitstart)); } $extraField->value = $tmp->text; } } } if ( ($item->image || $params->get('articleimgsource', 'introimage') == 'text') && (count($slideItems) < $limit || $limit == 0)) { $slideItem = modSliderckHelper::initItem(); $slideItem->path = $params->get('articleimgsource', 'introimage') != 'text' ? $item->image : null; $slideItem->link = $item->link; $slideItem->title = $item->title; $slideItem->desc = JHTML::_('content.prepare', $item->introtext); $slideItems[] = $slideItem; } // stop if we get the number of slides if ($limit > 0 && count($slideItems) >= $limit) break; } return $slideItems; } } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings