Current Path :
/
home
/
develito
/
httpdocs
/
modules
/
mod_otminitabs
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/develito/httpdocs/modules/mod_otminitabs/helper.php
<?php /** * @package OT Mini Tabs for Joomla! 3.x * @version $Id: helper.php - May 2014 00:00:00Z OmegaTheme * @author OmegaTheme Extensions (services@omegatheme.com) - http://omegatheme.com * @copyright Copyright(C) 2012 - OmegaTheme Extensions * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL **/ // no direct access defined('_JEXEC') or die ('Restricted access'); require_once JPATH_SITE.'/components/com_content/helpers/route.php'; jimport('joomla.application.component.model'); JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_content/models', 'ContentModel'); jimport('joomla.utilities.string'); jimport( 'joomla.application.module.helper' ); abstract class modOtMiniTabsHelper { /** * @return array of tab element object(title, content) which prepared for rendering * @called by root */ public static function getTabsSelection($params) { $tabsarray = array(); $tabs = $params->get('tabs'); if (!is_array($tabs) || empty($tabs)) return array(); foreach ($tabs as $idx => $tab) { $item = new StdClass(); $item->title = $tab->title; $type = $tab->use; $val = $tab->{$type}; switch ($type){ case 'module': $item->content = JModuleHelper::renderModule(modOtMiniTabsHelper::getModule($val)); break; case 'category': $item->content = modOtMiniTabsHelper::getArticleList($val, $params); break; case 'article': $item->content = modOtMiniTabsHelper::getArticle($val,$params); break; default: $item->content = ''; break; } $tabsarray[] = $item; } return $tabsarray; } /** * @return array of modules * @called by template */ public static function getModule($modId) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*'); $query->from('#__modules'); $query->where('id='.$modId); $db->setQuery($query); if (!($module = $db->loadObject())) { JError::raiseWarning(500, JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $db->getErrorMsg())); return false; } $module->user = substr($module->module, 0, 4) == 'mod_' ? 0 : 1; return $module; } /** * @return an article * @called by template */ public static function getArticle($id,$params) { $number_of_article = $params->get('number_of_article', 4); $number_of_character = $params->get('number_of_character', 100); $show_link = $params->get('show_link', 1); $show_readmore = $params->get('show_readmore', 1); $show_date = $params->get('show_date', 0); $date_format = $params->get('date_format', 'd.m.Y'); $show_thumbnail = $params->get('show_thumbnail', 1); $default_image = $params->get('default_image', 'modules/mod_otminitabs/assets/images/sampledefault.jpg'); $thumb_width = $params->get('thumb_width', 70); $thumb_height = $params->get('thumb_height', 50); $show_view_all = $params->get('show_view_all', 1); $db = JFactory::getDbo(); $query = $db->getQuery(true); $db->setQuery( 'SELECT * FROM #__content WHERE `id` = '.(int)$id.';' ); try { $article = $db->loadObject(); } catch (RuntimeException $e) { JError::raiseWarning(500, $e->getMessage()); } $article->slug = $article->id.':'.$article->alias; $article->catslug = $article->catid ? $article->catid .':'.$article->alias : $article->catid; $article->link = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug)); if (!$article->id) return ''; $html=''; $html .='<div class="ottabs-items-wrapper"> <div class="ottabs-item-wrapper">'; if($show_link == 1) { $html .= '<h3 class="ottabs-title"> <a href="'.$article->link.'" class="ottabs-title-link">'; $html .=$article->title; $html .='</a> </h3>'; } else { $html .= '<h3 class="ottabs-title">'. $article->title. '</h3>'; } $html .='<span class="created_date">'; if($show_date == 1) { $html .=JHTML::_('date', $article->created, $params->get( 'date_format' )); } $html .='</span>'; $html .='<div class="ottabs-article-introtext">'; if($article->fulltext !='') { $html .=$article->fulltext; } else { $html .=$article->introtext; } $html .='</div>'; $html .='</div> </div>'; return $html; } /** * @return array of articles specified by category ID * @called by template */ public static function getArticleList($catId, $params) { $number_of_article = $params->get('number_of_article', 4); $number_of_character = $params->get('number_of_character', 100); $show_link = $params->get('show_link', 1); $show_readmore = $params->get('show_readmore', 1); $show_date = $params->get('show_date', 0); $date_format = $params->get('date_format', 'd.m.Y'); $show_thumbnail = $params->get('show_thumbnail', 1); $default_image = $params->get('default_image', 'modules/mod_otminitabs/assets/images/sampledefault.jpg'); $thumb_width = $params->get('thumb_width', 70); $thumb_height = $params->get('thumb_height', 70); $show_view_all = $params->get('show_view_all', 1); // Get the dbo $db = JFactory::getDbo(); // Get an instance of the generic articles model $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true)); // Set application parameters in model $app = JFactory::getApplication(); $appParams = $app->getParams(); $model->setState('params', $appParams); // Set the filters based on the module params $model->setState('list.start', 0); $model->setState('list.limit', (int) $number_of_article); $model->setState('filter.published', 1); // Access filter $access = !JComponentHelper::getParams('com_content')->get('show_noauth'); $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id')); $model->setState('filter.access', $access); // Category filter $model->setState('filter.category_id', $catId); // User filter $userId = JFactory::getUser()->get('id'); switch ($params->get('user_id')) { case 'by_me': $model->setState('filter.author_id', (int) $userId); break; case 'not_me': $model->setState('filter.author_id', $userId); $model->setState('filter.author_id.include', false); break; case '0': break; default: $model->setState('filter.author_id', (int) $params->get('user_id')); break; } // Filter by language $model->setState('filter.language',$app->getLanguageFilter()); // Featured switch switch ($params->get('show_featured')) { case '1': $model->setState('filter.featured', 'only'); break; case '0': $model->setState('filter.featured', 'hide'); break; default: $model->setState('filter.featured', 'show'); break; } // Set ordering $order_map = array( 'm_dsc' => 'a.modified DESC, a.created', 'mc_dsc' => 'CASE WHEN (a.modified = '.$db->quote($db->getNullDate()).') THEN a.created ELSE a.modified END', 'c_dsc' => 'a.created', 'p_dsc' => 'a.publish_up', 'h_dsc' => 'a.hits' ); $ordering = JArrayHelper::getValue($order_map, $params->get('ordering'), 'a.publish_up'); $dir = 'DESC'; $model->setState('list.ordering', $ordering); $model->setState('list.direction', $dir); $items = $model->getItems(); if (!is_array($items) || empty($items)) return JText::_('No articles'); $cateHtml = array(); $itemsHtml = '<div class="ottabs-items-wrapper">'; foreach ($items as &$item) { $item->slug = $item->id.':'.$item->alias; $item->catslug = $item->catid ? $item->catid .':'.$item->category_alias : $item->catid; if ($access || in_array($item->access, $authorised)) { $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug)); } else { $item->link = JRoute::_('index.php?option=com_user&view=login'); } $itemsHtml .= '<div class="ottabs-item-wrapper">'; if ($show_thumbnail == 1) { $itemsHtml .= '<div class="ottabs-thumb-wrapper">'; $images = json_decode($item->images); if (isset($images->image_intro) && !empty($images->image_intro)){ $itemsHtml .= JHTML::_('image', htmlspecialchars($images->image_intro), (trim($images->image_intro_alt) != '' ? htmlspecialchars($images->image_intro_alt) : $item->title), array('class' => 'ottabs-thumbnail img-polaroid', 'width' => $thumb_width, 'height' => $thumb_height)); } else { preg_match_all('/img.*src="([^"]+)"/i', $item->introtext . $item->fulltext , $matches); if(empty($matches[1]) || empty($matches[1][0])){ $itemsHtml .= JHTML::_('image', JURI::root() . $default_image, $item->title, array('class' => 'ottabs-thumbnail img-polaroid', 'width' => $thumb_width, 'height' => $thumb_height)); }else{ $itemsHtml .= JHTML::_('image', $matches[1][0], $item->title, array('class' => 'ottabs-thumbnail img-polaroid', 'width' => $thumb_width, 'height' => $thumb_height)); } } $itemsHtml .='</div>'; } if($show_link == 1) { $itemsHtml .= '<h3 class="ottabs-title">'. '<a href="'.$item->link.'" class="ottabs-title-link">'.$item->title.'</a>'. '</h3>'; } else { $itemsHtml .= '<h3 class="ottabs-title">'. $item->title. '</h3>'; } if($show_date == 1) { $itemsHtml .= '<span class="created_date">'. JHTML::_('date', $item->created, $params->get( 'date_format' )). '</span>'; } $itemsHtml .= '<div class="ottabs-article-introtext">'. JString::substr(strip_tags(preg_replace('/<img([^>]+)>/i',"",JHtml::_('content.prepare', $item->introtext ))), 0, $number_of_character).'...'. '</div>'; if($show_readmore == 1) { $itemsHtml .= '<a href="'.$item->link.'" class="ottabs-readmore-link">'.JText::_('READMORE').'</a>'; } $itemsHtml .= '</div>'; $cate_title = $item->category_title; } if($show_view_all == 1) { $itemsHtml .= '<a class="view-all" href="'.JRoute::_(ContentHelperRoute::getCategoryRoute($catId)).'" title="view all">'.JText::_('VIEW_ALL').'</a>'; } $itemsHtml .= '</div>'; return $itemsHtml; } public static function randomkeys($length) { $pattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; $key = ''; for($i = 0; $i < $length; $i++) { $key .= $pattern{rand(0,strlen($pattern)-1)}; } return $key; } }