Exemplo n.º 1
0
 public function canEdit()
 {
     JLoader::register('K2HelperPermissions', JPATH_SITE . '/components/com_k2/helpers/permissions.php');
     if ($this->params->option != 'com_k2') {
         K2HelperPermissions::setPermissions();
     }
     return K2HelperPermissions::canEditItem($this->article->created_by, $this->article->catid);
 }
Exemplo n.º 2
0
 function users()
 {
     $itemID = JRequest::getInt('itemID');
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
     $item = JTable::getInstance('K2Item', 'Table');
     $item->load($itemID);
     if (!K2HelperPermissions::canAddItem() && !K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
     }
     $K2Permissions = K2Permissions::getInstance();
     if (!$K2Permissions->permissions->get('editAll')) {
         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
     }
     JRequest::setVar('tmpl', 'component');
     $mainframe = JFactory::getApplication();
     $params = JComponentHelper::getParams('com_k2');
     $language = JFactory::getLanguage();
     $language->load('com_k2', JPATH_ADMINISTRATOR);
     $document = JFactory::getDocument();
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         JHtml::_('behavior.framework');
     } else {
         JHTML::_('behavior.mootools');
     }
     // CSS
     $document->addStyleSheet(JURI::root(true) . '/media/k2/assets/css/k2.css?v=2.6.8');
     // JS
     K2HelperHTML::loadjQuery(true);
     $document->addScript(JURI::root(true) . '/media/k2/assets/js/k2.js?v=2.6.8&sitepath=' . JURI::root(true) . '/');
     $this->addViewPath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'views');
     $this->addModelPath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models');
     $view = $this->getView('users', 'html');
     $view->addTemplatePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'views' . DS . 'users' . DS . 'tmpl');
     $view->setLayout('element');
     $view->display();
 }
Exemplo n.º 3
0
 function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     $params = K2HelperUtilities::getParams('com_k2');
     $document = JFactory::getDocument();
     if (K2_JVERSION == '15') {
         $document->setMimeEncoding('application/json');
         $document->setType('json');
     }
     $model = $this->getModel('itemlist');
     //Set limit for model
     $limit = JRequest::getInt('limit');
     if ($limit > 100 || $limit == 0) {
         $limit = 100;
         JRequest::setVar('limit', $limit);
     }
     $page = JRequest::getInt('page');
     if ($page <= 0) {
         $limitstart = 0;
     } else {
         $page--;
         $limitstart = $page * $limit;
     }
     JRequest::setVar('limitstart', $limitstart);
     $view = JRequest::getWord('view');
     $task = JRequest::getWord('task');
     $response = new JObject();
     unset($response->_errors);
     // Site
     $response->site = new stdClass();
     $uri = JURI::getInstance();
     $response->site->url = $uri->toString(array('scheme', 'host', 'port'));
     $config = JFactory::getConfig();
     $response->site->name = K2_JVERSION == '30' ? $config->get('sitename') : $config->getValue('config.sitename');
     $moduleID = JRequest::getInt('moduleID');
     if ($moduleID) {
         $result = $model->getModuleItems($moduleID);
         $items = $result->items;
         $title = $result->title;
         $prefix = 'cat';
     } else {
         //Get data depending on task
         switch ($task) {
             case 'category':
                 //Get category
                 $id = JRequest::getInt('id');
                 JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
                 $category = JTable::getInstance('K2Category', 'Table');
                 $category->load($id);
                 // State Check
                 if (!$category->published || $category->trash) {
                     JError::raiseError(404, JText::_('K2_CATEGORY_NOT_FOUND'));
                 }
                 //Access check
                 $user = JFactory::getUser();
                 if (K2_JVERSION != '15') {
                     if (!in_array($category->access, $user->getAuthorisedViewLevels())) {
                         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                     }
                     $languageFilter = $mainframe->getLanguageFilter();
                     $languageTag = JFactory::getLanguage()->getTag();
                     if ($languageFilter && $category->language != $languageTag && $category->language != '*') {
                         return;
                     }
                 } else {
                     if ($category->access > $user->get('aid', 0)) {
                         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                     }
                 }
                 //Merge params
                 $cparams = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params);
                 if ($cparams->get('inheritFrom')) {
                     $masterCategory = JTable::getInstance('K2Category', 'Table');
                     $masterCategory->load($cparams->get('inheritFrom'));
                     $cparams = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($masterCategory->params);
                 }
                 $params->merge($cparams);
                 //Category link
                 $category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias))));
                 //Category image
                 $category->image = K2HelperUtilities::getCategoryImage($category->image, $params);
                 //Category plugins
                 $dispatcher = JDispatcher::getInstance();
                 JPluginHelper::importPlugin('content');
                 $category->text = $category->description;
                 if (K2_JVERSION != '15') {
                     $dispatcher->trigger('onContentPrepare', array('com_k2.category', &$category, &$params, $limitstart));
                 } else {
                     $dispatcher->trigger('onPrepareContent', array(&$category, &$params, $limitstart));
                 }
                 $category->description = $category->text;
                 //Category K2 plugins
                 $category->event->K2CategoryDisplay = '';
                 JPluginHelper::importPlugin('k2');
                 $results = $dispatcher->trigger('onK2CategoryDisplay', array(&$category, &$params, $limitstart));
                 $category->event->K2CategoryDisplay = trim(implode("\n", $results));
                 $category->text = $category->description;
                 $dispatcher->trigger('onK2PrepareContent', array(&$category, &$params, $limitstart));
                 $category->description = $category->text;
                 //Category children
                 $ordering = $params->get('subCatOrdering');
                 $children = $model->getCategoryFirstChildren($id, $ordering);
                 $subCategories = array();
                 if (count($children)) {
                     foreach ($children as $child) {
                         if ($params->get('subCatTitleItemCounter')) {
                             $child->numOfItems = $model->countCategoryItems($child->id);
                         }
                         $child->image = K2HelperUtilities::getCategoryImage($child->image, $params);
                         $child->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($child->id . ':' . urlencode($child->alias))));
                         unset($child->params);
                         unset($child->access);
                         unset($child->published);
                         unset($child->trash);
                         unset($child->language);
                         $subCategories[] = $child;
                     }
                 }
                 //Set featured flag
                 JRequest::setVar('featured', $params->get('catFeaturedItems'));
                 //Set title
                 $title = $category->name;
                 // Set ordering
                 if ($params->get('singleCatOrdering')) {
                     $ordering = $params->get('singleCatOrdering');
                 } else {
                     $ordering = $params->get('catOrdering');
                 }
                 // Set parameters prefix
                 $prefix = 'cat';
                 // Prepare the JSON category object;
                 $row = new JObject();
                 unset($row->_errors);
                 $row->id = $category->id;
                 $row->name = $category->name;
                 $row->alias = $category->alias;
                 $row->link = $category->link;
                 $row->parent = $category->parent;
                 $row->extraFieldsGroup = $category->extraFieldsGroup;
                 $row->image = $category->image;
                 $row->ordering = $category->ordering;
                 //$row->plugins = $category->plugins;
                 $row->events = $category->event;
                 $row->chidlren = $subCategories;
                 $response->category = $row;
                 break;
             case 'user':
                 //Get user
                 $id = JRequest::getInt('id');
                 $userObject = JFactory::getUser($id);
                 //Check user status
                 if ($userObject->block) {
                     JError::raiseError(404, JText::_('K2_USER_NOT_FOUND'));
                 }
                 //Get K2 user profile
                 $userObject->profile = $model->getUserProfile();
                 //User image
                 $userObject->avatar = K2HelperUtilities::getAvatar($userObject->id, $userObject->email, $params->get('userImageWidth'));
                 //User K2 plugins
                 $userObject->event->K2UserDisplay = '';
                 if (is_object($userObject->profile) && $userObject->profile->id > 0) {
                     $dispatcher = JDispatcher::getInstance();
                     JPluginHelper::importPlugin('k2');
                     $results = $dispatcher->trigger('onK2UserDisplay', array(&$userObject->profile, &$params, $limitstart));
                     $userObject->event->K2UserDisplay = trim(implode("\n", $results));
                     $userObject->profile->url = htmlspecialchars($userObject->profile->url, ENT_QUOTES, 'UTF-8');
                 }
                 //Set title
                 $title = $userObject->name;
                 // Set ordering
                 $ordering = $params->get('userOrdering');
                 // Set parameters prefix
                 $prefix = 'user';
                 // Prepare the JSON user object;
                 $row = new JObject();
                 unset($row->_errors);
                 //$row->id = $userObject->id;
                 $row->name = $userObject->name;
                 //$row->username = $userObject->username;
                 if (isset($userObject->profile->plugins)) {
                     unset($userObject->profile->plugins);
                 }
                 $row->profile = $userObject->profile;
                 $row->avatar = $userObject->avatar;
                 $row->events = $userObject->event;
                 $response->user = $row;
                 break;
             case 'tag':
                 //Set limit
                 $limit = $params->get('tagItemCount');
                 //set title
                 $title = JText::_('K2_DISPLAYING_ITEMS_BY_TAG') . ' ' . JRequest::getVar('tag');
                 // Set ordering
                 $ordering = $params->get('tagOrdering');
                 // Set parameters prefix
                 $prefix = 'tag';
                 $response->tag = JRequest::getVar('tag');
                 break;
             case 'search':
                 //Set title
                 $title = JText::_('K2_SEARCH_RESULTS_FOR') . ' ' . JRequest::getVar('searchword');
                 // Set parameters prefix
                 $prefix = 'generic';
                 $response->search = JRequest::getVar('searchword');
                 break;
             case 'date':
                 // Set title
                 if (JRequest::getInt('day')) {
                     $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month') . '-' . JRequest::getInt('day'));
                     $dateFormat = K2_JVERSION == '15' ? '%A, %d %B %Y' : 'l, d F Y';
                     $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat);
                 } else {
                     $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month'));
                     $dateFormat = K2_JVERSION == '15' ? '%B %Y' : 'F Y';
                     $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat);
                 }
                 // Set ordering
                 $ordering = 'rdate';
                 // Set parameters prefix
                 $prefix = 'generic';
                 $response->date = JHTML::_('date', $date, $dateFormat);
                 break;
             default:
                 $user = JFactory::getUser();
                 //Set limit
                 $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links');
                 //Set featured flag
                 JRequest::setVar('featured', $params->get('catFeaturedItems'));
                 //Set title
                 $title = $params->get('page_title');
                 // Set ordering
                 $ordering = $params->get('catOrdering');
                 // Set parameters prefix
                 $prefix = 'cat';
                 break;
         }
         if (!isset($ordering)) {
             $items = $model->getData();
         } else {
             $items = $model->getData($ordering);
         }
     }
     //Prepare items
     $user = JFactory::getUser();
     $cache = JFactory::getCache('com_k2_extended');
     $model = JModelLegacy::getInstance('item', 'K2Model');
     $rows = array();
     for ($i = 0; $i < sizeof($items); $i++) {
         //Item group
         if ($task == "category" || $task == "") {
             $items[$i]->itemGroup = 'links';
             if ($i < $params->get('num_links') + $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items')) {
                 $items[$i]->itemGroup = 'links';
             }
             if ($i < $params->get('num_secondary_items') + $params->get('num_leading_items') + $params->get('num_primary_items')) {
                 $items[$i]->itemGroup = 'secondary';
             }
             if ($i < $params->get('num_primary_items') + $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'primary';
             }
             if ($i < $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'leading';
             }
         } else {
             $items[$i]->itemGroup = '';
         }
         $itemParams = class_exists('JParameter') ? new JParameter($items[$i]->params) : new JRegistry($items[$i]->params);
         $itemParams->set($prefix . 'ItemIntroText', true);
         $itemParams->set($prefix . 'ItemFullText', true);
         $itemParams->set($prefix . 'ItemTags', true);
         $itemParams->set($prefix . 'ItemExtraFields', true);
         $itemParams->set($prefix . 'ItemAttachments', true);
         $itemParams->set($prefix . 'ItemRating', true);
         $itemParams->set($prefix . 'ItemAuthor', true);
         $itemParams->set($prefix . 'ItemImageGallery', true);
         $itemParams->set($prefix . 'ItemVideo', true);
         $itemParams->set($prefix . 'ItemImage', true);
         $items[$i]->params = $itemParams->toString();
         //Check if model should use cache for preparing item even if user is logged in
         if ($user->guest || $task == 'tag' || $task == 'search' || $task == 'date') {
             $cacheFlag = true;
         } else {
             $cacheFlag = true;
             if (K2HelperPermissions::canEditItem($items[$i]->created_by, $items[$i]->catid)) {
                 $cacheFlag = false;
             }
         }
         //Prepare item
         if ($cacheFlag) {
             $hits = $items[$i]->hits;
             $items[$i]->hits = 0;
             JTable::getInstance('K2Category', 'Table');
             $items[$i] = $cache->call(array($model, 'prepareItem'), $items[$i], $view, $task);
             $items[$i]->hits = $hits;
         } else {
             $items[$i] = $model->prepareItem($items[$i], $view, $task);
         }
         //Plugins
         $items[$i]->params->set('genericItemIntroText', $params->get('catItemIntroText'));
         $items[$i] = $model->execPlugins($items[$i], $view, $task);
         //Trigger comments counter event
         $dispatcher = JDispatcher::getInstance();
         JPluginHelper::importPlugin('k2');
         $results = $dispatcher->trigger('onK2CommentsCounter', array(&$items[$i], &$params, $limitstart));
         $items[$i]->event->K2CommentsCounter = trim(implode("\n", $results));
         // Set default image
         if ($task == 'user' || $task == 'tag' || $task == 'search' || $task == 'date') {
             $items[$i]->image = isset($items[$i]->imageGeneric) ? $items[$i]->imageGeneric : '';
         } else {
             if (!$moduleID) {
                 K2HelperUtilities::setDefaultImage($items[$i], $view, $params);
             }
         }
         $rows[] = $model->prepareJSONItem($items[$i]);
     }
     $response->items = $rows;
     // Prevent spammers from using the tag view
     if ($task == 'tag' && !count($response->items)) {
         $tag = JRequest::getString('tag');
         $db = JFactory::getDBO();
         $db->setQuery('SELECT id FROM #__k2_tags WHERE name = ' . $db->quote($tag));
         $tagID = $db->loadResult();
         if (!$tagID) {
             JError::raiseError(404, JText::_('K2_NOT_FOUND'));
             return false;
         }
     }
     // Output
     $json = json_encode($response);
     $callback = JRequest::getCmd('callback');
     if ($callback) {
         $document->setMimeEncoding('application/javascript');
         echo $callback . '(' . $json . ')';
     } else {
         echo $json;
     }
 }
Exemplo n.º 4
0
 function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     $params = K2HelperUtilities::getParams('com_k2');
     $model = $this->getModel('itemlist');
     $limitstart = JRequest::getInt('limitstart');
     $view = JRequest::getWord('view');
     $task = JRequest::getWord('task');
     $db = JFactory::getDBO();
     // Add link
     if (K2HelperPermissions::canAddItem()) {
         $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
     }
     $this->assignRef('addLink', $addLink);
     // Get data depending on task
     switch ($task) {
         case 'category':
             // Get category
             $id = JRequest::getInt('id');
             JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
             $category = JTable::getInstance('K2Category', 'Table');
             $category->load($id);
             $category->event = new stdClass();
             // State check
             if (!$category->published || $category->trash) {
                 JError::raiseError(404, JText::_('K2_CATEGORY_NOT_FOUND'));
             }
             // Access check
             $user = JFactory::getUser();
             if (K2_JVERSION != '15') {
                 if (!in_array($category->access, $user->getAuthorisedViewLevels())) {
                     if ($user->guest) {
                         $uri = JFactory::getURI();
                         $url = 'index.php?option=com_users&view=login&return=' . base64_encode($uri->toString());
                         $mainframe->redirect(JRoute::_($url, false), JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'));
                     } else {
                         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                         return;
                     }
                 }
                 $languageFilter = $mainframe->getLanguageFilter();
                 $languageTag = JFactory::getLanguage()->getTag();
                 if ($languageFilter && $category->language != $languageTag && $category->language != '*') {
                     return;
                 }
             } else {
                 if ($category->access > $user->get('aid', 0)) {
                     if ($user->guest) {
                         $uri = JFactory::getURI();
                         $url = 'index.php?option=com_user&view=login&return=' . base64_encode($uri->toString());
                         $mainframe->redirect(JRoute::_($url, false), JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'));
                     } else {
                         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                         return;
                     }
                 }
             }
             // Hide the add new item link if user cannot post in the specific category
             if (!K2HelperPermissions::canAddItem($id)) {
                 unset($this->addLink);
             }
             // Merge params
             $cparams = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params);
             // Get the meta information before merging params since we do not want them to be inherited
             $category->metaDescription = $cparams->get('catMetaDesc');
             $category->metaKeywords = $cparams->get('catMetaKey');
             $category->metaRobots = $cparams->get('catMetaRobots');
             $category->metaAuthor = $cparams->get('catMetaAuthor');
             if ($cparams->get('inheritFrom')) {
                 $masterCategory = JTable::getInstance('K2Category', 'Table');
                 $masterCategory->load($cparams->get('inheritFrom'));
                 $cparams = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($masterCategory->params);
             }
             $params->merge($cparams);
             // Category link
             $category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias))));
             // Category image
             $category->image = K2HelperUtilities::getCategoryImage($category->image, $params);
             // Category plugins
             $dispatcher = JDispatcher::getInstance();
             JPluginHelper::importPlugin('content');
             $category->text = $category->description;
             if (K2_JVERSION != '15') {
                 $dispatcher->trigger('onContentPrepare', array('com_k2.category', &$category, &$params, $limitstart));
             } else {
                 $dispatcher->trigger('onPrepareContent', array(&$category, &$params, $limitstart));
             }
             $category->description = $category->text;
             // Category K2 plugins
             $category->event->K2CategoryDisplay = '';
             JPluginHelper::importPlugin('k2');
             $results = $dispatcher->trigger('onK2CategoryDisplay', array(&$category, &$params, $limitstart));
             $category->event->K2CategoryDisplay = trim(implode("\n", $results));
             $category->text = $category->description;
             $dispatcher->trigger('onK2PrepareContent', array(&$category, &$params, $limitstart));
             $category->description = $category->text;
             $this->assignRef('category', $category);
             $this->assignRef('user', $user);
             // Category children
             $ordering = $params->get('subCatOrdering');
             $children = $model->getCategoryFirstChildren($id, $ordering);
             if (count($children)) {
                 foreach ($children as $child) {
                     if ($params->get('subCatTitleItemCounter')) {
                         $child->numOfItems = $model->countCategoryItems($child->id);
                     }
                     $child->image = K2HelperUtilities::getCategoryImage($child->image, $params);
                     $child->name = htmlspecialchars($child->name, ENT_QUOTES);
                     $child->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($child->id . ':' . urlencode($child->alias))));
                     $subCategories[] = $child;
                 }
                 $this->assignRef('subCategories', $subCategories);
             }
             // Set limit
             $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links');
             // Set featured flag
             JRequest::setVar('featured', $params->get('catFeaturedItems'));
             // Set layout
             $this->setLayout('category');
             // Set title
             $title = $category->name;
             $category->name = htmlspecialchars($category->name, ENT_QUOTES);
             // Set ordering
             if ($params->get('singleCatOrdering')) {
                 $ordering = $params->get('singleCatOrdering');
             } else {
                 $ordering = $params->get('catOrdering');
             }
             $addHeadFeedLink = $params->get('catFeedLink');
             break;
         case 'user':
             // Get user
             $id = JRequest::getInt('id');
             $userObject = JFactory::getUser($id);
             $userObject->event = new stdClass();
             // Check user status
             if ($userObject->block) {
                 JError::raiseError(404, JText::_('K2_USER_NOT_FOUND'));
             }
             // Get K2 user profile
             $userObject->profile = $model->getUserProfile();
             // User image
             $userObject->avatar = K2HelperUtilities::getAvatar($userObject->id, $userObject->email, $params->get('userImageWidth'));
             // User K2 plugins
             $userObject->event->K2UserDisplay = '';
             if (is_object($userObject->profile) && $userObject->profile->id > 0) {
                 $dispatcher = JDispatcher::getInstance();
                 JPluginHelper::importPlugin('k2');
                 $results = $dispatcher->trigger('onK2UserDisplay', array(&$userObject->profile, &$params, $limitstart));
                 $userObject->event->K2UserDisplay = trim(implode("\n", $results));
                 $userObject->profile->url = htmlspecialchars($userObject->profile->url, ENT_QUOTES, 'UTF-8');
             }
             $this->assignRef('user', $userObject);
             $date = JFactory::getDate();
             $now = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql();
             $this->assignRef('now', $now);
             // Set layout
             $this->setLayout('user');
             // Set limit
             $limit = $params->get('userItemCount');
             // Set title
             $title = $userObject->name;
             $userObject->name = htmlspecialchars($userObject->name, ENT_QUOTES);
             // Set ordering
             $ordering = $params->get('userOrdering');
             $addHeadFeedLink = $params->get('userFeedLink', 1);
             break;
         case 'tag':
             // Set layout
             $this->setLayout('tag');
             // Set limit
             $limit = $params->get('tagItemCount');
             // Set title
             $title = JText::_('K2_DISPLAYING_ITEMS_BY_TAG') . ' ' . JRequest::getVar('tag');
             // Set ordering
             $ordering = $params->get('tagOrdering');
             $addHeadFeedLink = $params->get('tagFeedLink', 1);
             break;
         case 'search':
             // Set layout
             $this->setLayout('generic');
             // Set limit
             $limit = $params->get('genericItemCount');
             // Set title
             $title = JText::_('K2_SEARCH_RESULTS_FOR') . ' ' . JRequest::getVar('searchword');
             $addHeadFeedLink = $params->get('genericFeedLink', 1);
             break;
         case 'date':
             // Set layout
             $this->setLayout('generic');
             // Set limit
             $limit = $params->get('genericItemCount');
             // Fix wrong timezone
             if (function_exists('date_default_timezone_get')) {
                 $originalTimezone = date_default_timezone_get();
             }
             if (function_exists('date_default_timezone_set')) {
                 date_default_timezone_set('UTC');
             }
             // Set title
             if (JRequest::getInt('day')) {
                 $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month') . '-' . JRequest::getInt('day'));
                 $dateFormat = K2_JVERSION == '15' ? '%A, %d %B %Y' : 'l, d F Y';
                 $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat);
             } else {
                 $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month'));
                 $dateFormat = K2_JVERSION == '15' ? '%B %Y' : 'F Y';
                 $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat);
             }
             // Restore the original timezone
             if (function_exists('date_default_timezone_set') && isset($originalTimezone)) {
                 date_default_timezone_set($originalTimezone);
             }
             // Set ordering
             $ordering = 'rdate';
             $addHeadFeedLink = $params->get('genericFeedLink', 1);
             break;
         default:
             // Set layout
             $this->setLayout('category');
             $user = JFactory::getUser();
             $this->assignRef('user', $user);
             // Set limit
             $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links');
             // Set featured flag
             JRequest::setVar('featured', $params->get('catFeaturedItems'));
             // Set title
             $title = $params->get('page_title');
             // Set ordering
             $ordering = $params->get('catOrdering');
             $addHeadFeedLink = $params->get('catFeedLink', 1);
             break;
     }
     // Set limit for model
     if (!$limit) {
         $limit = 10;
     }
     JRequest::setVar('limit', $limit);
     // Get items
     if (!isset($ordering)) {
         $items = $model->getData();
     } else {
         $items = $model->getData($ordering);
     }
     // Pagination
     jimport('joomla.html.pagination');
     $total = count($items) ? $model->getTotal() : 0;
     $pagination = new JPagination($total, $limitstart, $limit);
     //Prepare items
     $user = JFactory::getUser();
     $cache = JFactory::getCache('com_k2_extended');
     $model = $this->getModel('item');
     for ($i = 0; $i < sizeof($items); $i++) {
         //Item group
         if ($task == "category" || $task == "") {
             if ($i < $params->get('num_links') + $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items')) {
                 $items[$i]->itemGroup = 'links';
             }
             if ($i < $params->get('num_secondary_items') + $params->get('num_leading_items') + $params->get('num_primary_items')) {
                 $items[$i]->itemGroup = 'secondary';
             }
             if ($i < $params->get('num_primary_items') + $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'primary';
             }
             if ($i < $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'leading';
             }
         }
         // Check if the model should use the cache for preparing the item even if the user is logged in
         if ($user->guest || $task == 'tag' || $task == 'search' || $task == 'date') {
             $cacheFlag = true;
         } else {
             $cacheFlag = true;
             if (K2HelperPermissions::canEditItem($items[$i]->created_by, $items[$i]->catid)) {
                 $cacheFlag = false;
             }
         }
         // Prepare item
         if ($cacheFlag) {
             $hits = $items[$i]->hits;
             $items[$i]->hits = 0;
             JTable::getInstance('K2Category', 'Table');
             $items[$i] = $cache->call(array($model, 'prepareItem'), $items[$i], $view, $task);
             $items[$i]->hits = $hits;
         } else {
             $items[$i] = $model->prepareItem($items[$i], $view, $task);
         }
         // Plugins
         $items[$i] = $model->execPlugins($items[$i], $view, $task);
         // Trigger comments counter event
         $dispatcher = JDispatcher::getInstance();
         JPluginHelper::importPlugin('k2');
         $results = $dispatcher->trigger('onK2CommentsCounter', array(&$items[$i], &$params, $limitstart));
         $items[$i]->event->K2CommentsCounter = trim(implode("\n", $results));
     }
     // Set title
     $document = JFactory::getDocument();
     $application = JFactory::getApplication();
     $menus = $application->getMenu();
     $menu = $menus->getActive();
     if (is_object($menu)) {
         if (is_string($menu->params)) {
             $menu_params = K2_JVERSION == '15' ? new JParameter($menu->params) : new JRegistry($menu->params);
         } else {
             $menu_params = $menu->params;
         }
         if (!$menu_params->get('page_title')) {
             $params->set('page_title', $title);
         }
     } else {
         $params->set('page_title', $title);
     }
     // We're adding a new variable here which won't get the appended/prepended site title,
     // when enabled via Joomla!'s SEO/SEF settings
     $params->set('page_title_clean', $title);
     if (K2_JVERSION != '15') {
         if ($mainframe->getCfg('sitename_pagetitles', 0) == 1) {
             $tmpTitle = JText::sprintf('JPAGETITLE', $mainframe->getCfg('sitename'), $params->get('page_title'));
             $params->set('page_title', $tmpTitle);
         } elseif ($mainframe->getCfg('sitename_pagetitles', 0) == 2) {
             $tmpTitle = JText::sprintf('JPAGETITLE', $params->get('page_title'), $mainframe->getCfg('sitename'));
             $params->set('page_title', $tmpTitle);
         }
     }
     $document->setTitle($params->get('page_title'));
     // Search - Update the Google Search results container (K2 v2.6.6+)
     if ($task == 'search') {
         $googleSearchContainerID = trim($params->get('googleSearchContainer', 'k2GoogleSearchContainer'));
         if ($googleSearchContainerID == 'k2Container') {
             $googleSearchContainerID = 'k2GoogleSearchContainer';
         }
         $params->set('googleSearchContainer', $googleSearchContainerID);
     }
     // Set metadata for category
     if ($task == 'category') {
         if ($category->metaDescription) {
             $document->setDescription($category->metaDescription);
         } else {
             $metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $this->category->description);
             $metaDescItem = strip_tags($metaDescItem);
             $metaDescItem = K2HelperUtilities::characterLimit($metaDescItem, $params->get('metaDescLimit', 150));
             $metaDescItem = htmlspecialchars($metaDescItem, ENT_QUOTES, 'UTF-8');
             $document->setDescription($metaDescItem);
         }
         if ($category->metaKeywords) {
             $document->setMetadata('keywords', $category->metaKeywords);
         }
         if ($category->metaRobots) {
             $document->setMetadata('robots', $category->metaRobots);
         }
         if ($category->metaAuthor) {
             $document->setMetadata('author', $category->metaAuthor);
         }
     }
     if (K2_JVERSION != '15') {
         // Menu metadata options
         if ($params->get('menu-meta_description')) {
             $document->setDescription($params->get('menu-meta_description'));
         }
         if ($params->get('menu-meta_keywords')) {
             $document->setMetadata('keywords', $params->get('menu-meta_keywords'));
         }
         if ($params->get('robots')) {
             $document->setMetadata('robots', $params->get('robots'));
         }
         // Menu page display options
         if ($params->get('page_heading')) {
             $params->set('page_title', $params->get('page_heading'));
         }
         $params->set('show_page_title', $params->get('show_page_heading'));
     }
     // Pathway
     $pathway = $mainframe->getPathWay();
     if (!isset($menu->query['task'])) {
         $menu->query['task'] = '';
     }
     if ($menu) {
         switch ($task) {
             case 'category':
                 if ($menu->query['task'] != 'category' || $menu->query['id'] != JRequest::getInt('id')) {
                     $pathway->addItem($title, '');
                 }
                 break;
             case 'user':
                 if ($menu->query['task'] != 'user' || $menu->query['id'] != JRequest::getInt('id')) {
                     $pathway->addItem($title, '');
                 }
                 break;
             case 'tag':
                 if ($menu->query['task'] != 'tag' || $menu->query['tag'] != JRequest::getVar('tag')) {
                     $pathway->addItem($title, '');
                 }
                 break;
             case 'search':
             case 'date':
                 $pathway->addItem($title, '');
                 break;
         }
     }
     // Feed link
     $config = JFactory::getConfig();
     $menu = $application->getMenu();
     $default = $menu->getDefault();
     $active = $menu->getActive();
     if ($task == 'tag') {
         $link = K2HelperRoute::getTagRoute(JRequest::getVar('tag'));
     } else {
         $link = '';
     }
     $sef = K2_JVERSION == '30' ? $config->get('sef') : $config->getValue('config.sef');
     if (!is_null($active) && $active->id == $default->id && $sef) {
         $link .= '&Itemid=' . $active->id . '&format=feed&limitstart=';
     } else {
         $link .= '&format=feed&limitstart=';
     }
     $feed = JRoute::_($link);
     $this->assignRef('feed', $feed);
     // Add head feed link
     if ($addHeadFeedLink) {
         $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
         $document->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
         $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
         $document->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
     }
     // Assign data
     if ($task == "category" || $task == "") {
         $leading = @array_slice($items, 0, $params->get('num_leading_items'));
         $primary = @array_slice($items, $params->get('num_leading_items'), $params->get('num_primary_items'));
         $secondary = @array_slice($items, $params->get('num_leading_items') + $params->get('num_primary_items'), $params->get('num_secondary_items'));
         $links = @array_slice($items, $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items'), $params->get('num_links'));
         $this->assignRef('leading', $leading);
         $this->assignRef('primary', $primary);
         $this->assignRef('secondary', $secondary);
         $this->assignRef('links', $links);
     } else {
         $this->assignRef('items', $items);
     }
     // Set default values to avoid division by zero
     if ($params->get('num_leading_columns') == 0) {
         $params->set('num_leading_columns', 1);
     }
     if ($params->get('num_primary_columns') == 0) {
         $params->set('num_primary_columns', 1);
     }
     if ($params->get('num_secondary_columns') == 0) {
         $params->set('num_secondary_columns', 1);
     }
     if ($params->get('num_links_columns') == 0) {
         $params->set('num_links_columns', 1);
     }
     $this->assignRef('params', $params);
     $this->assignRef('pagination', $pagination);
     // Set Facebook meta data
     $document = JFactory::getDocument();
     $uri = JURI::getInstance();
     $document->setMetaData('og:url', $uri->toString());
     $document->setMetaData('og:title', htmlspecialchars($document->getTitle(), ENT_QUOTES, 'UTF-8'));
     $document->setMetaData('og:type', 'website');
     if ($task == 'category' && $this->category->image && strpos($this->category->image, 'placeholder/category.png') === false) {
         $image = substr(JURI::root(), 0, -1) . str_replace(JURI::root(true), '', $this->category->image);
         $document->setMetaData('og:image', $image);
         $document->setMetaData('image', $image);
     }
     $document->setMetaData('og:description', htmlspecialchars(strip_tags($document->getDescription()), ENT_QUOTES, 'UTF-8'));
     // Look for template files in component folders
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates');
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default');
     // Look for overrides in template folder (K2 template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default');
     // Look for overrides in template folder (Joomla! template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
     // Look for specific K2 theme files
     if ($params->get('theme')) {
         $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $params->get('theme'));
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $params->get('theme'));
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $params->get('theme'));
     }
     $nullDate = $db->getNullDate();
     $this->assignRef('nullDate', $nullDate);
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('k2');
     $dispatcher->trigger('onK2BeforeViewDisplay');
     // Prevent spammers from using the tag view
     if ($task == 'tag' && !count($this->items)) {
         $tag = JRequest::getString('tag');
         $db = JFactory::getDBO();
         $db->setQuery('SELECT id FROM #__k2_tags WHERE name = ' . $db->quote($tag));
         $tagID = $db->loadResult();
         if (!$tagID) {
             JError::raiseError(404, JText::_('K2_NOT_FOUND'));
             return false;
         }
     }
     parent::display($tpl);
 }
Exemplo n.º 5
0
 function display($tpl = null)
 {
     $mainframe =& JFactory::getApplication();
     $params =& K2HelperUtilities::getParams('com_k2');
     $model =& $this->getModel('itemlist');
     $limitstart = JRequest::getInt('limitstart');
     $view = JRequest::getWord('view');
     $task = JRequest::getWord('task');
     //Add link
     if (K2HelperPermissions::canAddItem()) {
         $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
     }
     $this->assignRef('addLink', $addLink);
     //Get data depending on task
     switch ($task) {
         case 'category':
             //Get category
             $id = JRequest::getInt('id');
             JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
             $category =& JTable::getInstance('K2Category', 'Table');
             $category->load($id);
             // State Check
             if (!$category->published || $category->trash) {
                 JError::raiseError(404, JText::_('K2_CATEGORY_NOT_FOUND'));
             }
             //Access check
             $user =& JFactory::getUser();
             if (K2_JVERSION == '16') {
                 if (!in_array($category->access, $user->authorisedLevels())) {
                     JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                 }
                 $languageFilter = $mainframe->getLanguageFilter();
                 $languageTag = JFactory::getLanguage()->getTag();
                 if ($languageFilter && $category->language != $languageTag && $category->language != '*') {
                     return;
                 }
             } else {
                 if ($category->access > $user->get('aid', 0)) {
                     JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                 }
             }
             // Hide the add new item link if user cannot post in the specific category
             if (!K2HelperPermissions::canAddItem($id)) {
                 unset($this->addLink);
             }
             //Merge params
             $cparams = new JParameter($category->params);
             if ($cparams->get('inheritFrom')) {
                 $masterCategory =& JTable::getInstance('K2Category', 'Table');
                 $masterCategory->load($cparams->get('inheritFrom'));
                 $cparams = new JParameter($masterCategory->params);
             }
             $params->merge($cparams);
             //Category link
             $category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias))));
             //Category image
             $category->image = K2HelperUtilities::getCategoryImage($category->image, $params);
             //Category plugins
             $dispatcher =& JDispatcher::getInstance();
             JPluginHelper::importPlugin('content');
             $category->text = $category->description;
             if (K2_JVERSION == '16') {
                 $dispatcher->trigger('onContentPrepare', array('com_k2.category', &$category, &$params, $limitstart));
             } else {
                 $dispatcher->trigger('onPrepareContent', array(&$category, &$params, $limitstart));
             }
             $category->description = $category->text;
             //Category K2 plugins
             $category->event->K2CategoryDisplay = '';
             JPluginHelper::importPlugin('k2');
             $results = $dispatcher->trigger('onK2CategoryDisplay', array(&$category, &$params, $limitstart));
             $category->event->K2CategoryDisplay = trim(implode("\n", $results));
             $category->text = $category->description;
             $dispatcher->trigger('onK2PrepareContent', array(&$category, &$params, $limitstart));
             $category->description = $category->text;
             $this->assignRef('category', $category);
             $this->assignRef('user', $user);
             //Category children
             $ordering = $params->get('subCatOrdering');
             $children = $model->getCategoryFirstChildren($id, $ordering);
             if (count($children)) {
                 foreach ($children as $child) {
                     if ($params->get('subCatTitleItemCounter')) {
                         $child->numOfItems = $model->countCategoryItems($child->id);
                     }
                     $child->image = K2HelperUtilities::getCategoryImage($child->image, $params);
                     $child->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($child->id . ':' . urlencode($child->alias))));
                     $subCategories[] = $child;
                 }
                 $this->assignRef('subCategories', $subCategories);
             }
             //Set limit
             $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links');
             //Set featured flag
             JRequest::setVar('featured', $params->get('catFeaturedItems'));
             //Set layout
             $this->setLayout('category');
             //Set title
             $title = $category->name;
             // Set ordering
             if ($params->get('singleCatOrdering')) {
                 $ordering = $params->get('singleCatOrdering');
             } else {
                 $ordering = $params->get('catOrdering');
             }
             break;
         case 'user':
             //Get user
             $id = JRequest::getInt('id');
             $userObject =& JFactory::getUser($id);
             //Check user status
             if ($userObject->block) {
                 JError::raiseError(404, JText::_('K2_USER_NOT_FOUND'));
             }
             //Get K2 user profile
             $userObject->profile = $model->getUserProfile();
             //User image
             $userObject->avatar = K2HelperUtilities::getAvatar($userObject->id, $userObject->email, $params->get('userImageWidth'));
             //User K2 plugins
             $userObject->event->K2UserDisplay = '';
             if (is_object($userObject->profile) && $userObject->profile->id > 0) {
                 $dispatcher =& JDispatcher::getInstance();
                 JPluginHelper::importPlugin('k2');
                 $results = $dispatcher->trigger('onK2UserDisplay', array(&$userObject->profile, &$params, $limitstart));
                 $userObject->event->K2UserDisplay = trim(implode("\n", $results));
             }
             $this->assignRef('user', $userObject);
             //Set layout
             $this->setLayout('user');
             //Set limit
             $limit = $params->get('userItemCount');
             //Set title
             $title = $userObject->name;
             // Set ordering
             $ordering = $params->get('userOrdering');
             break;
         case 'tag':
             //Set layout
             $this->setLayout('tag');
             //Set limit
             $limit = $params->get('tagItemCount');
             //set title
             $title = JText::_('K2_DISPLAYING_ITEMS_BY_TAG') . ' ' . JRequest::getVar('tag');
             // Set ordering
             $ordering = $params->get('tagOrdering');
             break;
         case 'search':
             //Set layout
             $this->setLayout('generic');
             $tpl = JRequest::getCmd('tpl', null);
             //Set limit
             $limit = $params->get('genericItemCount');
             //Set title
             $title = JText::_('K2_SEARCH_RESULTS_FOR') . ' ' . JRequest::getVar('searchword');
             break;
         case 'date':
             //Set layout
             $this->setLayout('generic');
             //Set limit
             $limit = $params->get('genericItemCount');
             // Set title
             if (JRequest::getInt('day')) {
                 $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month') . '-' . JRequest::getInt('day'));
                 $dateFormat = K2_JVERSION == '15' ? '%A, %d %B %Y' : 'l, d F Y';
                 $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat);
             } else {
                 $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month'));
                 $dateFormat = K2_JVERSION == '15' ? '%B %Y' : 'F Y';
                 $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat);
             }
             // Set ordering
             $ordering = 'rdate';
             break;
         default:
             //Set layout
             $this->setLayout('category');
             $user =& JFactory::getUser();
             $this->assignRef('user', $user);
             //Set limit
             $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links');
             //Set featured flag
             JRequest::setVar('featured', $params->get('catFeaturedItems'));
             //Set title
             $title = $params->get('page_title');
             // Set ordering
             $ordering = $params->get('catOrdering');
             break;
     }
     //Set limit for model
     JRequest::setVar('limit', $limit);
     if (!isset($ordering)) {
         $items = $model->getData();
     } else {
         $items = $model->getData($ordering);
     }
     //Pagination
     jimport('joomla.html.pagination');
     $total = $model->getTotal();
     $pagination = new JPagination($total, $limitstart, $limit);
     //Prepare items
     $user =& JFactory::getUser();
     $cache =& JFactory::getCache('com_k2_extended');
     $model =& $this->getModel('item');
     for ($i = 0; $i < sizeof($items); $i++) {
         //Item group
         if ($task == "category" || $task == "") {
             if ($i < $params->get('num_links') + $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items')) {
                 $items[$i]->itemGroup = 'links';
             }
             if ($i < $params->get('num_secondary_items') + $params->get('num_leading_items') + $params->get('num_primary_items')) {
                 $items[$i]->itemGroup = 'secondary';
             }
             if ($i < $params->get('num_primary_items') + $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'primary';
             }
             if ($i < $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'leading';
             }
         }
         //Check if model should use cache for preparing item even if user is logged in
         if ($user->guest || $task == 'tag' || $task == 'search' || $task == 'date') {
             $cacheFlag = true;
         } else {
             $cacheFlag = true;
             if (K2HelperPermissions::canEditItem($items[$i]->created_by, $items[$i]->catid)) {
                 $cacheFlag = false;
             }
         }
         //Prepare item
         if ($cacheFlag) {
             $hits = $items[$i]->hits;
             $items[$i]->hits = 0;
             JTable::getInstance('K2Category', 'Table');
             $items[$i] = $cache->call(array('K2ModelItem', 'prepareItem'), $items[$i], $view, $task);
             $items[$i]->hits = $hits;
         } else {
             $items[$i] = $model->prepareItem($items[$i], $view, $task);
         }
         //Plugins
         $items[$i] = $model->execPlugins($items[$i], $view, $task);
         //Trigger comments counter event
         $dispatcher =& JDispatcher::getInstance();
         JPluginHelper::importPlugin('k2');
         $results = $dispatcher->trigger('onK2CommentsCounter', array(&$items[$i], &$params, $limitstart));
         $items[$i]->event->K2CommentsCounter = trim(implode("\n", $results));
     }
     //Pathway
     $pathway =& $mainframe->getPathWay();
     $pathway->addItem($title);
     //Feed link
     $config =& JFactory::getConfig();
     $menu =& JSite::getMenu();
     $default = $menu->getDefault();
     $active = $menu->getActive();
     if ($task == 'tag') {
         $link = K2HelperRoute::getTagRoute(JRequest::getVar('tag'));
     } else {
         $link = '';
     }
     if (!is_null($active) && $active->id == $default->id && $config->getValue('config.sef')) {
         $link .= '&Itemid=' . $active->id . '&format=feed&limitstart=';
     } else {
         $link .= '&format=feed&limitstart=';
     }
     $feed = JRoute::_($link);
     $this->assignRef('feed', $feed);
     //Assign data
     if ($task == "category" || $task == "") {
         $leading = @array_slice($items, 0, $params->get('num_leading_items'));
         $primary = @array_slice($items, $params->get('num_leading_items'), $params->get('num_primary_items'));
         $secondary = @array_slice($items, $params->get('num_leading_items') + $params->get('num_primary_items'), $params->get('num_secondary_items'));
         $links = @array_slice($items, $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items'), $params->get('num_links'));
         $this->assignRef('leading', $leading);
         $this->assignRef('primary', $primary);
         $this->assignRef('secondary', $secondary);
         $this->assignRef('links', $links);
     } else {
         $this->assignRef('items', $items);
     }
     //Set default values to avoid division by zero
     if ($params->get('num_leading_columns') == 0) {
         $params->set('num_leading_columns', 1);
     }
     if ($params->get('num_primary_columns') == 0) {
         $params->set('num_primary_columns', 1);
     }
     if ($params->get('num_secondary_columns') == 0) {
         $params->set('num_secondary_columns', 1);
     }
     if ($params->get('num_links_columns') == 0) {
         $params->set('num_links_columns', 1);
     }
     $this->assignRef('params', $params);
     $this->assignRef('pagination', $pagination);
     //Look for template files in component folders
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates');
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default');
     //Look for overrides in template folder (K2 template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default');
     //Look for overrides in template folder (Joomla! template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
     //Look for specific K2 theme files
     if ($params->get('theme')) {
         $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $params->get('theme'));
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $params->get('theme'));
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $params->get('theme'));
     }
     $db =& JFactory::getDBO();
     $nullDate = $db->getNullDate();
     $this->assignRef('nullDate', $nullDate);
     parent::display($tpl);
 }
Exemplo n.º 6
0
	function prepareItem($item, $view, $task){

		jimport('joomla.filesystem.file');
		JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');
		$limitstart=JRequest::getInt('limitstart');

		//Initialize params
		if ($view!='item'){

			$component = JComponentHelper::getComponent( 'com_k2' );
			$params = new JParameter( $component->params );
			$itemid = JRequest::getInt( 'Itemid' );
			if ($itemid) {
				$menu = JSite::getMenu();
				$menuparams = $menu->getParams( $itemid );
				$params->merge( $menuparams );
			}

		}
		else {
			$params = & JComponentHelper::getParams('com_k2');
		}

		//Category
		$db = & JFactory::getDBO();
		$query = "SELECT * FROM #__k2_categories WHERE id=".(int)$item->catid;
		$db->setQuery($query, 0, 1);
		$category = $db->loadObject();

		$item->category=$category;
		$item->category->link=urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id.':'.urlencode($category->alias))));

		//Read more link
		$link = K2HelperRoute::getItemRoute($item->id.':'.urlencode($item->alias),$item->catid.':'.urlencode($item->category->alias));
		$item->link=urldecode(JRoute::_($link));

		//Print link
		$item->printLink = urldecode(JRoute::_($link.'&tmpl=component&print=1'));

		//Params
		$cparams = new JParameter( $category->params );
		$iparams = new JParameter( $item->params );
		$item->params= $params;
		if ($cparams->get('inheritFrom')){
			$masterCategoryID = $cparams->get('inheritFrom');
			$query = "SELECT * FROM #__k2_categories WHERE id=".(int)$masterCategoryID;
			$db->setQuery($query, 0, 1);
			$masterCategory = $db->loadObject();
			$cparams = new JParameter( $masterCategory->params );
		}
		$item->params->merge($cparams);
		$item->params->merge($iparams);

		//Edit link
		if (K2HelperPermissions::canEditItem($item->created_by,$item->catid))
		$item->editLink = JRoute::_('index.php?option=com_k2&view=item&task=edit&cid='.$item->id.'&tmpl=component');

		//Tags
		if(
		($view=='item' && ($item->params->get('itemTags') || $item->params->get('itemRelated'))) ||
		($view=='itemlist' && ($task=='' || $task=='category') && $item->params->get('catItemTags')) ||
		($view=='itemlist' && $task=='user' && $item->params->get('userItemTags')) ||
		($view=='latest' && $params->get('latestItemTags'))
		)
		{
			$tags = K2ModelItem::getItemTags($item->id);
			for ($i=0; $i<sizeof($tags); $i++) {
				$tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name));
			}
			$item->tags=$tags;
		}


		//Image
		$item->imageXSmall='';
		$item->imageSmall='';
		$item->imageMedium='';
		$item->imageLarge='';
		$item->imageXLarge='';

		if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg'))
		$item->imageXSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';

		if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg'))
		$item->imageSmall = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';

		if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg'))
		$item->imageMedium = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';

		if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))
		$item->imageLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';

		if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg'))
		$item->imageXLarge = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';

		if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg'))
		$item->imageGeneric = JURI::root().'media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';


		//Extra fields
		if(
		($view=='item' && $item->params->get('itemExtraFields')) ||
		($view=='itemlist' && ($task=='' || $task=='category') && $item->params->get('catItemExtraFields')) ||
		($view=='itemlist' && ($task=='search' || $task=='tag' || $task=='date') && $item->params->get('genericItemExtraFields'))
		)
		{
			$item->extra_fields=K2ModelItem::getItemExtraFields($item->extra_fields);
		}

		//Attachments
		if(
		($view=='item' && $item->params->get('itemAttachments')) ||
		($view=='itemlist' && ($task=='' || $task=='category') && $item->params->get('catItemAttachments'))
		)
		{
			$item->attachments=K2ModelItem::getItemAttachments($item->id);
		}


		//Rating
		if(
		($view=='item' && $item->params->get('itemRating')) ||
		($view=='itemlist' && ($task=='' || $task=='category') && $item->params->get('catItemRating'))
		)
		{
			$item->votingPercentage = K2ModelItem::getVotesPercentage($item->id);
			$item->numOfvotes = K2ModelItem::getVotesNum($item->id);

		}

		//Filtering
		if ($params->get('introTextCleanup')){
			$filterTags	= preg_split( '#[,\s]+#', trim( $params->get( 'introTextCleanupExcludeTags' ) ) );
			$filterAttrs = preg_split( '#[,\s]+#', trim( $params->get( 'introTextCleanupTagAttr' ) ) );
			$filter	= new JFilterInput( $filterTags, $filterAttrs, 0, 1 );
			$item->introtext= $filter->clean( $item->introtext );
		}

		if ($params->get('fullTextCleanup')){
			$filterTags	= preg_split( '#[,\s]+#', trim( $params->get( 'fullTextCleanupExcludeTags' ) ) );
			$filterAttrs = preg_split( '#[,\s]+#', trim( $params->get( 'fullTextCleanupTagAttr' ) ) );
			$filter	= new JFilterInput( $filterTags, $filterAttrs, 0, 1 );
			$item->fulltext= $filter->clean( $item->fulltext );
		}

		if ($item->params->get('catItemIntroTextWordLimit') && $task=='category'){
			$item->introtext = K2HelperUtilities::wordLimit($item->introtext, $item->params->get('catItemIntroTextWordLimit'));
		}

		$item->cleanTitle = $item->title;
		$item->title = htmlspecialchars($item->title, ENT_QUOTES);
		$item->image_caption = htmlspecialchars($item->image_caption, ENT_QUOTES);

		//Author
		if(
		($view=='item' && ($item->params->get('itemAuthorBlock') || $item->params->get('itemAuthor'))) ||
		($view=='itemlist' && ($task=='' || $task=='category') && ($item->params->get('catItemAuthorBlock') || $item->params->get('catItemAuthor')) ) ||
		($view=='itemlist' && $task=='user')
		)
		{
			if (!empty($item->created_by_alias)){
				$item->author->name = $item->created_by_alias;
				$item->author->avatar = K2HelperUtilities::getAvatar('alias');
				$item->author->link = JURI::root();
			}
			else {
				$author=&JFactory::getUser($item->created_by);
				$item->author = $author;
				$item->author->link = JRoute::_(K2HelperRoute::getUserRoute($item->created_by));
				$item->author->profile = K2ModelItem::getUserProfile($item->created_by);
				$item->author->avatar = K2HelperUtilities::getAvatar($author->id, $author->email, $params->get('userImageWidth'));
			}

			if (!isset($item->author->profile) || is_null($item->author->profile)){

				$item->author->profile = new JObject;
				$item->author->profile->gender = NULL;

			}


		}

		//Num of comments
		$item->numOfComments = K2ModelItem::countItemComments($item->id);

		return $item;
	}
Exemplo n.º 7
0
 function prepareItem($item, $view, $task)
 {
     jimport('joomla.filesystem.file');
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
     $limitstart = JRequest::getInt('limitstart');
     //Initialize params
     if ($view != 'item') {
         $component = JComponentHelper::getComponent('com_k2');
         $params = new JParameter($component->params);
         $itemid = JRequest::getInt('Itemid');
         if ($itemid) {
             $menu = JSite::getMenu();
             $menuparams = $menu->getParams($itemid);
             $params->merge($menuparams);
         }
     } else {
         $params =& JComponentHelper::getParams('com_k2');
     }
     //Category
     $db =& JFactory::getDBO();
     $query = "SELECT * FROM #__k2_categories WHERE id={$item->catid}";
     $db->setQuery($query, 0, 1);
     $category = $db->loadObject();
     $item->category = $category;
     $item->category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias))));
     //Read more link
     $link = K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->category->alias));
     $item->link = urldecode(JRoute::_($link));
     //Print link
     $item->printLink = urldecode(JRoute::_($link . '&tmpl=component&print=1'));
     //Params
     $cparams = new JParameter($category->params);
     $iparams = new JParameter($item->params);
     $item->params = $params;
     if ($cparams->get('inheritFrom')) {
         $masterCategoryID = $cparams->get('inheritFrom');
         $query = "SELECT * FROM #__k2_categories WHERE id={$masterCategoryID}";
         $db->setQuery($query, 0, 1);
         $masterCategory = $db->loadObject();
         $cparams = new JParameter($masterCategory->params);
     }
     $item->params->merge($cparams);
     $item->params->merge($iparams);
     //Edit link
     if (K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
         $item->editLink = JRoute::_('index.php?option=com_k2&view=item&task=edit&cid=' . $item->id . '&tmpl=component');
     }
     //Tags
     if ($view == 'item' && ($item->params->get('itemTags') || $item->params->get('itemRelated')) || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemTags') || $view == 'itemlist' && $task == 'user' && $item->params->get('userItemTags') || $view == 'latest' && $params->get('latestItemTags')) {
         $tags = K2ModelItem::getItemTags($item->id);
         for ($i = 0; $i < sizeof($tags); $i++) {
             $tags[$i]->link = urldecode(JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name)));
         }
         $item->tags = $tags;
     }
     //Image
     $item->imageXSmall = '';
     $item->imageSmall = '';
     $item->imageMedium = '';
     $item->imageLarge = '';
     $item->imageXLarge = '';
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XS.jpg')) {
         $item->imageXSmall = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_XS.jpg';
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) {
         $item->imageSmall = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg';
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_M.jpg')) {
         $item->imageMedium = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_M.jpg';
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
         $item->imageLarge = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg';
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XL.jpg')) {
         $item->imageXLarge = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_XL.jpg';
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_Generic.jpg')) {
         $item->imageGeneric = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_Generic.jpg';
     }
     //Extra fields
     if ($view == 'item' && $item->params->get('itemExtraFields') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemExtraFields') || $view == 'itemlist' && ($task == 'search' || $task == 'tag' || $task == 'date') && $item->params->get('genericItemExtraFields')) {
         $item->extra_fields = K2ModelItem::getItemExtraFields($item->extra_fields);
     }
     //Attachments
     if ($view == 'item' && $item->params->get('itemAttachments') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemAttachments')) {
         $item->attachments = K2ModelItem::getItemAttachments($item->id);
     }
     //Import plugins
     $dispatcher =& JDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     //Gallery
     if ($view == 'item' && $item->params->get('itemImageGallery') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemImageGallery')) {
         $params->set('galleries_rootfolder', 'media/k2/galleries');
         $params->set('popup_engine', 'mootools_slimbox');
         $params->set('enabledownload', '0');
         $item->text = $item->gallery;
         $dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
         $item->gallery = $item->text;
     }
     //Video
     if ($view == 'item' && $item->params->get('itemVideo') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemVideo') || $view == 'latest' && $item->params->get('latestItemVideo')) {
         if (!empty($item->video) && JString::substr($item->video, 0, 1) !== '{') {
             $item->video = $item->video;
             $item->videoType = 'embedded';
         } else {
             $item->videoType = 'allvideos';
             $params->set('vfolder', 'media/k2/videos');
             if ($view == 'item') {
                 $params->set('vwidth', $item->params->get('itemVideoWidth'));
                 $params->set('vheight', $item->params->get('itemVideoHeight'));
                 $params->set('autoplay', $item->params->get('itemVideoAutoPlay'));
             } else {
                 if ($view == 'latest') {
                     $params->set('vwidth', $item->params->get('latestItemVideoWidth'));
                     $params->set('vheight', $item->params->get('latestItemVideoHeight'));
                     $params->set('autoplay', $item->params->get('latestItemVideoAutoPlay'));
                 } else {
                     $params->set('vwidth', $item->params->get('catItemVideoWidth'));
                     $params->set('vheight', $item->params->get('catItemVideoHeight'));
                     $params->set('autoplay', $item->params->get('catItemVideoAutoPlay'));
                 }
             }
             $item->text = $item->video;
             $dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
             $item->video = $item->text;
         }
     }
     //Rating
     if ($view == 'item' && $item->params->get('itemRating') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemRating')) {
         $item->votingPercentage = K2ModelItem::getVotesPercentage($item->id);
         $item->numOfvotes = K2ModelItem::getVotesNum($item->id);
     }
     //Filtering
     if ($params->get('introTextCleanup')) {
         $filterTags = preg_split('#[,\\s]+#', trim($params->get('introTextCleanupExcludeTags')));
         $filterAttrs = preg_split('#[,\\s]+#', trim($params->get('introTextCleanupTagAttr')));
         $filter = new JFilterInput($filterTags, $filterAttrs, 0, 1);
         $item->introtext = $filter->clean($item->introtext);
     }
     if ($params->get('fullTextCleanup')) {
         $filterTags = preg_split('#[,\\s]+#', trim($params->get('fullTextCleanupExcludeTags')));
         $filterAttrs = preg_split('#[,\\s]+#', trim($params->get('fullTextCleanupTagAttr')));
         $filter = new JFilterInput($filterTags, $filterAttrs, 0, 1);
         $item->fulltext = $filter->clean($item->fulltext);
     }
     if ($item->params->get('catItemIntroTextWordLimit') && $task == 'category') {
         $item->introtext = K2HelperUtilities::wordLimit($item->introtext, $item->params->get('catItemIntroTextWordLimit'));
     }
     //Plugins
     $item->text = '';
     $params->set('vfolder', NULL);
     $params->set('vwidth', NULL);
     $params->set('vheight', NULL);
     $params->set('autoplay', NULL);
     $params->set('galleries_rootfolder', NULL);
     $params->set('popup_engine', NULL);
     $params->set('enabledownload', NULL);
     if ($view == 'item') {
         if ($item->params->get('itemIntroText')) {
             $item->text .= $item->introtext;
         }
         if ($item->params->get('itemFullText')) {
             $item->text .= '{K2Splitter}' . $item->fulltext;
         }
     } else {
         switch ($task) {
             case '':
             case 'category':
                 if ($item->params->get('catItemIntroText')) {
                     $item->text .= $item->introtext;
                 }
                 break;
             case 'user':
                 if ($item->params->get('userItemIntroText')) {
                     $item->text .= $item->introtext;
                 }
                 break;
             default:
                 if ($item->params->get('genericItemIntroText')) {
                     $item->text .= $item->introtext;
                 }
                 break;
         }
     }
     $results = $dispatcher->trigger('onBeforeDisplay', array(&$item, &$params, $limitstart));
     $item->event->BeforeDisplay = trim(implode("\n", $results));
     $results = $dispatcher->trigger('onAfterDisplay', array(&$item, &$params, $limitstart));
     $item->event->AfterDisplay = trim(implode("\n", $results));
     $results = $dispatcher->trigger('onAfterDisplayTitle', array(&$item, &$params, $limitstart));
     $item->event->AfterDisplayTitle = trim(implode("\n", $results));
     $results = $dispatcher->trigger('onBeforeDisplayContent', array(&$item, &$params, $limitstart));
     $item->event->BeforeDisplayContent = trim(implode("\n", $results));
     $results = $dispatcher->trigger('onAfterDisplayContent', array(&$item, &$params, $limitstart));
     $item->event->AfterDisplayContent = trim(implode("\n", $results));
     $dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
     //Author
     if ($view == 'item' && ($item->params->get('itemAuthorBlock') || $item->params->get('itemAuthor')) || $view == 'itemlist' && ($task == '' || $task == 'category') && ($item->params->get('catItemAuthorBlock') || $item->params->get('catItemAuthor')) || $view == 'itemlist' && $task == 'user') {
         if (!empty($item->created_by_alias)) {
             $item->author->name = $item->created_by_alias;
             $item->author->avatar = K2HelperUtilities::getAvatar('alias');
         } else {
             $author =& JFactory::getUser($item->created_by);
             $item->author = $author;
             $item->author->link = JRoute::_(K2HelperRoute::getUserRoute($item->created_by));
             $item->author->profile = K2ModelItem::getUserProfile($item->created_by);
             $item->author->avatar = K2HelperUtilities::getAvatar($author->id, $author->email, $params->get('userImageWidth'));
         }
         if (!is_object($item->author->profile)) {
             $item->author->profile = new JObject();
             $item->author->profile->gender = NULL;
         }
     }
     //Num of comments
     $item->numOfComments = K2ModelItem::countItemComments($item->id);
     //K2 plugins
     $item->event->K2BeforeDisplay = '';
     $item->event->K2AfterDisplay = '';
     $item->event->K2AfterDisplayTitle = '';
     $item->event->K2BeforeDisplayContent = '';
     $item->event->K2AfterDisplayContent = '';
     if ($view == 'item' && $item->params->get('itemK2Plugins') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemK2Plugins') || $view == 'itemlist' && $task == 'user' && $item->params->get('userItemK2Plugins')) {
         JPluginHelper::importPlugin('k2');
         $results = $dispatcher->trigger('onK2BeforeDisplay', array(&$item, &$params, $limitstart));
         $item->event->K2BeforeDisplay = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onK2AfterDisplay', array(&$item, &$params, $limitstart));
         $item->event->K2AfterDisplay = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onK2AfterDisplayTitle', array(&$item, &$params, $limitstart));
         $item->event->K2AfterDisplayTitle = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onK2BeforeDisplayContent', array(&$item, &$params, $limitstart));
         $item->event->K2BeforeDisplayContent = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onK2AfterDisplayContent', array(&$item, &$params, $limitstart));
         $item->event->K2AfterDisplayContent = trim(implode("\n", $results));
         $dispatcher->trigger('onK2PrepareContent', array(&$item, &$params, $limitstart));
     }
     if ($view == 'item') {
         @(list($item->introtext, $item->fulltext) = explode('{K2Splitter}', $item->text));
     } else {
         $item->introtext = $item->text;
     }
     return $item;
 }
Exemplo n.º 8
0
 public static function checkPermissions()
 {
     $view = JRequest::getCmd('view');
     if ($view != 'item') {
         return;
     }
     $task = JRequest::getCmd('task');
     $user = JFactory::getUser();
     if ($user->guest && ($task == 'add' || $task == 'edit')) {
         $mainframe = JFactory::getApplication();
         $uri = JURI::getInstance();
         $return = base64_encode($uri->toString());
         $mainframe->enqueueMessage(JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'), 'notice');
         if (K2_JVERSION == '15') {
             $mainframe->redirect('index.php?option=com_user&view=login&return=' . $return . '&tmpl=component');
         } else {
             $mainframe->redirect('index.php?option=com_users&view=login&return=' . $return . '&tmpl=component');
         }
     }
     switch ($task) {
         case 'add':
             if (!K2HelperPermissions::canAddItem()) {
                 JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
             }
             break;
         case 'edit':
         case 'deleteAttachment':
         case 'checkin':
             $cid = JRequest::getInt('cid');
             if (!$cid) {
                 JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
             }
             JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
             $item = JTable::getInstance('K2Item', 'Table');
             $item->load($cid);
             if (!K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
                 JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
             }
             break;
         case 'save':
             $cid = JRequest::getInt('id');
             if ($cid) {
                 JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
                 $item = JTable::getInstance('K2Item', 'Table');
                 $item->load($cid);
                 if (!K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
                     JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                 }
             } else {
                 if (!K2HelperPermissions::canAddItem()) {
                     JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                 }
             }
             break;
         case 'tag':
             if (!K2HelperPermissions::canAddTag()) {
                 JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
             }
             break;
         case 'extraFields':
             if (!K2HelperPermissions::canRenderExtraFields()) {
                 JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
             }
             break;
     }
 }
Exemplo n.º 9
0
 function prepareItem($item, $view, $task)
 {
     jimport('joomla.filesystem.file');
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
     $limitstart = JRequest::getInt('limitstart');
     $application = JFactory::getApplication();
     //Initialize params
     if ($view != 'item') {
         if (K2_JVERSION == '30') {
             $params = $application->getParams('com_k2');
         } else {
             $component = JComponentHelper::getComponent('com_k2');
             $params = class_exists('JParameter') ? new JParameter($component->params) : new JRegistry($component->params);
             $itemid = JRequest::getInt('Itemid');
             if ($itemid) {
                 $menu = $application->getMenu();
                 $menuparams = $menu->getParams($itemid);
                 $params->merge($menuparams);
             }
         }
     } else {
         $params = K2HelperUtilities::getParams('com_k2');
     }
     //Category
     $db = JFactory::getDBO();
     $category = JTable::getInstance('K2Category', 'Table');
     $category->load($item->catid);
     $item->category = $category;
     $item->category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias))));
     //Read more link
     $link = K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->category->alias));
     $item->link = urldecode(JRoute::_($link));
     //Print link
     $item->printLink = urldecode(JRoute::_($link . '&tmpl=component&print=1'));
     //Params
     $cparams = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params);
     $iparams = class_exists('JParameter') ? new JParameter($item->params) : new JRegistry($item->params);
     $item->params = version_compare(PHP_VERSION, '5.0.0', '>=') ? clone $params : $params;
     if ($cparams->get('inheritFrom')) {
         $masterCategoryID = $cparams->get('inheritFrom');
         $masterCategory = JTable::getInstance('K2Category', 'Table');
         $masterCategory->load((int) $masterCategoryID);
         $cparams = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($masterCategory->params);
     }
     $item->params->merge($cparams);
     $item->params->merge($iparams);
     //Edit link
     if (K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
         $item->editLink = JRoute::_('index.php?option=com_k2&view=item&task=edit&cid=' . $item->id . '&tmpl=component');
     }
     //Tags
     if ($view == 'item' && ($item->params->get('itemTags') || $item->params->get('itemRelated')) || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemTags') || $view == 'itemlist' && $task == 'user' && $item->params->get('userItemTags') || $view == 'latest' && $params->get('latestItemTags')) {
         $tags = $this->getItemTags($item->id);
         for ($i = 0; $i < sizeof($tags); $i++) {
             $tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name));
         }
         $item->tags = $tags;
     }
     //Image
     $item->imageXSmall = '';
     $item->imageSmall = '';
     $item->imageMedium = '';
     $item->imageLarge = '';
     $item->imageXLarge = '';
     $date = JFactory::getDate($item->modified);
     $timestamp = '?t=' . $date->toUnix();
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XS.jpg')) {
         $item->imageXSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_XS.jpg';
         if ($params->get('imageTimestamp')) {
             $item->imageXSmall .= $timestamp;
         }
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) {
         $item->imageSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg';
         if ($params->get('imageTimestamp')) {
             $item->imageSmall .= $timestamp;
         }
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_M.jpg')) {
         $item->imageMedium = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_M.jpg';
         if ($params->get('imageTimestamp')) {
             $item->imageMedium .= $timestamp;
         }
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
         $item->imageLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg';
         if ($params->get('imageTimestamp')) {
             $item->imageLarge .= $timestamp;
         }
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XL.jpg')) {
         $item->imageXLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_XL.jpg';
         if ($params->get('imageTimestamp')) {
             $item->imageXLarge .= $timestamp;
         }
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_Generic.jpg')) {
         $item->imageGeneric = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_Generic.jpg';
         if ($params->get('imageTimestamp')) {
             $item->imageGeneric .= $timestamp;
         }
     }
     //Extra fields
     if ($view == 'item' && $item->params->get('itemExtraFields') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemExtraFields') || $view == 'itemlist' && $task == 'tag' && $item->params->get('tagItemExtraFields') || $view == 'itemlist' && ($task == 'search' || $task == 'date') && $item->params->get('genericItemExtraFields')) {
         $item->extra_fields = $this->getItemExtraFields($item->extra_fields, $item);
     }
     //Attachments
     if ($view == 'item' && $item->params->get('itemAttachments') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemAttachments')) {
         $item->attachments = $this->getItemAttachments($item->id);
     }
     //Rating
     if ($view == 'item' && $item->params->get('itemRating') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemRating')) {
         $item->votingPercentage = $this->getVotesPercentage($item->id);
         $item->numOfvotes = $this->getVotesNum($item->id);
     }
     //Filtering
     if ($params->get('introTextCleanup')) {
         $filterTags = preg_split('#[,\\s]+#', trim($params->get('introTextCleanupExcludeTags')));
         $filterAttrs = preg_split('#[,\\s]+#', trim($params->get('introTextCleanupTagAttr')));
         $filterAttrs = array_filter($filterAttrs);
         $item->introtext = K2HelperUtilities::cleanTags($item->introtext, $filterTags);
         if (count($filterAttrs)) {
             $item->introtext = K2HelperUtilities::cleanAttributes($item->introtext, $filterTags, $filterAttrs);
         }
     }
     if ($params->get('fullTextCleanup')) {
         $filterTags = preg_split('#[,\\s]+#', trim($params->get('fullTextCleanupExcludeTags')));
         $filterAttrs = preg_split('#[,\\s]+#', trim($params->get('fullTextCleanupTagAttr')));
         $filterAttrs = array_filter($filterAttrs);
         $item->fulltext = K2HelperUtilities::cleanTags($item->fulltext, $filterTags);
         if (count($filterAttrs)) {
             $item->fulltext = K2HelperUtilities::cleanAttributes($item->fulltext, $filterTags, $filterAttrs);
         }
     }
     if ($item->params->get('catItemIntroTextWordLimit') && $task == 'category') {
         $item->introtext = K2HelperUtilities::wordLimit($item->introtext, $item->params->get('catItemIntroTextWordLimit'));
     }
     $item->cleanTitle = $item->title;
     $item->title = htmlspecialchars($item->title, ENT_QUOTES);
     $item->image_caption = htmlspecialchars($item->image_caption, ENT_QUOTES);
     //Author
     if ($view == 'item' && ($item->params->get('itemAuthorBlock') || $item->params->get('itemAuthor')) || $view == 'itemlist' && ($task == '' || $task == 'category') && ($item->params->get('catItemAuthorBlock') || $item->params->get('catItemAuthor')) || $view == 'itemlist' && $task == 'user' || $view == 'relatedByTag') {
         if (!empty($item->created_by_alias)) {
             $item->author = new stdClass();
             $item->author->name = $item->created_by_alias;
             $item->author->avatar = K2HelperUtilities::getAvatar('alias');
             $item->author->link = JURI::root();
         } else {
             $author = JFactory::getUser($item->created_by);
             $item->author = $author;
             $item->author->link = JRoute::_(K2HelperRoute::getUserRoute($item->created_by));
             $item->author->profile = $this->getUserProfile($item->created_by);
             $item->author->avatar = K2HelperUtilities::getAvatar($author->id, $author->email, $params->get('userImageWidth'));
         }
         if (!isset($item->author->profile) || is_null($item->author->profile)) {
             $item->author->profile = new JObject();
             $item->author->profile->gender = NULL;
         }
     }
     //Num of comments
     if ($params->get('comments', 0) > 0) {
         $user = JFactory::getUser();
         if (!$user->guest && $user->id == $item->created_by && $params->get('inlineCommentsModeration')) {
             $item->numOfComments = $this->countItemComments($item->id, false);
         } else {
             $item->numOfComments = $this->countItemComments($item->id);
         }
     }
     return $item;
 }
Exemplo n.º 10
0
 function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     $db = JFactory::getDBO();
     $view = JRequest::getCmd('view');
     jimport('joomla.filesystem.file');
     jimport('joomla.html.pane');
     JHTML::_('behavior.keepalive');
     JHTML::_('behavior.modal');
     JRequest::setVar('hidemainmenu', 1);
     $document = JFactory::getDocument();
     $document->addScript(JURI::root(true) . '/media/k2/assets/js/nicEdit.js?v=2.6.8');
     //var K2SitePath = '".JURI::root(true)."/';
     $js = "\n\t\t\t\t\tvar K2BasePath = '" . JURI::base(true) . "/';\n\t\t\t\t\tvar K2Language = [\n\t\t\t\t\t\t'" . JText::_('K2_REMOVE', true) . "',\n\t\t\t\t\t\t'" . JText::_('K2_LINK_TITLE_OPTIONAL', true) . "',\n\t\t\t\t\t\t'" . JText::_('K2_LINK_TITLE_ATTRIBUTE_OPTIONAL', true) . "',\n\t\t\t\t\t\t'" . JText::_('K2_ARE_YOU_SURE', true) . "',\n\t\t\t\t\t\t'" . JText::_('K2_YOU_ARE_NOT_ALLOWED_TO_POST_TO_THIS_CATEGORY', true) . "',\n\t\t\t\t\t\t'" . JText::_('K2_OR_SELECT_A_FILE_ON_THE_SERVER', true) . "'\n\t\t\t\t\t]\n\t\t\t\t";
     $document->addScriptDeclaration($js);
     K2Model::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models');
     $model = K2Model::getInstance('Item', 'K2Model', array('table_path' => JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables'));
     $item = $model->getData();
     JFilterOutput::objectHTMLSafe($item, ENT_QUOTES, array('video', 'params', 'plugins'));
     $user = JFactory::getUser();
     // Permissions check on frontend
     if ($mainframe->isSite()) {
         JLoader::register('K2HelperPermissions', JPATH_COMPONENT . DS . 'helpers' . DS . 'permissions.php');
         $task = JRequest::getCmd('task');
         if ($task == 'edit' && !K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
             JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
         }
         if ($task == 'add' && !K2HelperPermissions::canAddItem()) {
             JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
         }
         // Get permissions
         $K2Permissions = K2Permissions::getInstance();
         $this->assignRef('permissions', $K2Permissions->permissions);
         // Build permissions message
         $permissionsLabels = array();
         if ($this->permissions->get('add')) {
             $permissionsLabels[] = JText::_('K2_ADD_ITEMS');
         }
         if ($this->permissions->get('editOwn')) {
             $permissionsLabels[] = JText::_('K2_EDIT_OWN_ITEMS');
         }
         if ($this->permissions->get('editAll')) {
             $permissionsLabels[] = JText::_('K2_EDIT_ANY_ITEM');
         }
         if ($this->permissions->get('publish')) {
             $permissionsLabels[] = JText::_('K2_PUBLISH_ITEMS');
         }
         if ($this->permissions->get('editPublished')) {
             $permissionsLabels[] = JText::_('K2_ALLOW_EDITING_OF_ALREADY_PUBLISHED_ITEMS');
         }
         $permissionsMessage = JText::_('K2_YOU_ARE_ALLOWED_TO') . ' ' . implode(', ', $permissionsLabels);
         $this->assignRef('permissionsMessage', $permissionsMessage);
     }
     if ($item->isCheckedOut($user->get('id'), $item->checked_out)) {
         $message = JText::_('K2_THE_ITEM') . ': ' . $item->title . ' ' . JText::_('K2_IS_CURRENTLY_BEING_EDITED_BY_ANOTHER_ADMINISTRATOR');
         $url = $mainframe->isSite() ? 'index.php?option=com_k2&view=item&id=' . $item->id . '&tmpl=component' : 'index.php?option=com_k2';
         $mainframe->enqueueMessage($message);
         $mainframe->redirect($url);
     }
     if ($item->id) {
         $item->checkout($user->get('id'));
     } else {
         $item->published = 1;
         $item->publish_down = $db->getNullDate();
         $item->modified = $db->getNullDate();
         $date = JFactory::getDate();
         $now = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql();
         $item->created = $now;
         $item->publish_up = $item->created;
     }
     $lists = array();
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         $dateFormat = 'Y-m-d H:i:s';
     } else {
         $dateFormat = '%Y-%m-%d %H:%M:%S';
     }
     $created = $item->created;
     $publishUp = $item->publish_up;
     $publishDown = $item->publish_down;
     $created = JHTML::_('date', $item->created, $dateFormat);
     $publishUp = JHTML::_('date', $item->publish_up, $dateFormat);
     if ((int) $item->publish_down) {
         $publishDown = JHTML::_('date', $item->publish_down, $dateFormat);
     } else {
         $publishDown = '';
     }
     // Set up calendars
     $lists['createdCalendar'] = JHTML::_('calendar', $created, 'created', 'created');
     $lists['publish_up'] = JHTML::_('calendar', $publishUp, 'publish_up', 'publish_up');
     $lists['publish_down'] = JHTML::_('calendar', $publishDown, 'publish_down', 'publish_down');
     if ($item->id) {
         $lists['created'] = JHTML::_('date', $item->created, JText::_('DATE_FORMAT_LC2'));
     } else {
         $lists['created'] = JText::_('K2_NEW_DOCUMENT');
     }
     if ($item->modified == $db->getNullDate() || !$item->id) {
         $lists['modified'] = JText::_('K2_NEVER');
     } else {
         $lists['modified'] = JHTML::_('date', $item->modified, JText::_('DATE_FORMAT_LC2'));
     }
     $params = JComponentHelper::getParams('com_k2');
     $wysiwyg = JFactory::getEditor();
     $onSave = '';
     if ($params->get("mergeEditors")) {
         if (JString::strlen($item->fulltext) > 1) {
             $textValue = $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext;
         } else {
             $textValue = $item->introtext;
         }
         $text = $wysiwyg->display('text', $textValue, '100%', '400px', '', '');
         $this->assignRef('text', $text);
         if (K2_JVERSION == '30') {
             $onSave = $wysiwyg->save('text');
         }
     } else {
         $introtext = $wysiwyg->display('introtext', $item->introtext, '100%', '400px', '', '', array('readmore'));
         $this->assignRef('introtext', $introtext);
         $fulltext = $wysiwyg->display('fulltext', $item->fulltext, '100%', '400px', '', '', array('readmore'));
         $this->assignRef('fulltext', $fulltext);
         if (K2_JVERSION == '30') {
             $onSave = $wysiwyg->save('introtext');
             $onSave .= $wysiwyg->save('fulltext');
         }
     }
     $document->addScriptDeclaration("function onK2EditorSave(){ " . $onSave . " }");
     $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $item->published);
     $lists['featured'] = JHTML::_('select.booleanlist', 'featured', 'class="inputbox"', $item->featured);
     $lists['access'] = version_compare(JVERSION, '3.0', 'ge') ? JHTML::_('access.level', 'access', $item->access) : JHTML::_('list.accesslevel', $item);
     $query = "SELECT ordering AS value, title AS text FROM #__k2_items WHERE catid={$item->catid}";
     $lists['ordering'] = version_compare(JVERSION, '3.0', 'ge') ? NUll : JHTML::_('list.specificordering', $item, $item->id, $query);
     if (!$item->id) {
         $item->catid = $mainframe->getUserStateFromRequest('com_k2itemsfilter_category', 'catid', 0, 'int');
     }
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/models/categories.php';
     $categoriesModel = K2Model::getInstance('Categories', 'K2Model');
     $categories = $categoriesModel->categoriesTree();
     $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox"', 'value', 'text', $item->catid);
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         $languages = JHTML::_('contentlanguage.existing', true, true);
         $lists['language'] = JHTML::_('select.genericlist', $languages, 'language', '', 'value', 'text', $item->language);
     }
     $lists['checkSIG'] = $model->checkSIG();
     $lists['checkAllVideos'] = $model->checkAllVideos();
     $remoteVideo = false;
     $providerVideo = false;
     $embedVideo = false;
     if (stristr($item->video, 'remote}') !== false) {
         $remoteVideo = true;
         $options['startOffset'] = 1;
     }
     $providers = $model->getVideoProviders();
     if (count($providers)) {
         foreach ($providers as $provider) {
             $providersOptions[] = JHTML::_('select.option', $provider, ucfirst($provider));
             if (stristr($item->video, "{{$provider}}") !== false) {
                 $providerVideo = true;
                 $options['startOffset'] = 2;
             }
         }
     }
     if (JString::substr($item->video, 0, 1) !== '{') {
         $embedVideo = true;
         $options['startOffset'] = 3;
     }
     $lists['uploadedVideo'] = !$remoteVideo && !$providerVideo && !$embedVideo ? true : false;
     if ($lists['uploadedVideo'] || $item->video == '') {
         $options['startOffset'] = 0;
     }
     $document->addScriptDeclaration("var K2ActiveVideoTab = " . $options['startOffset']);
     $lists['remoteVideo'] = $remoteVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['remoteVideoType'] = $remoteVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['providerVideo'] = $providerVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['providerVideoType'] = $providerVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
     $lists['embedVideo'] = $embedVideo ? $item->video : '';
     if (isset($providersOptions)) {
         $lists['providers'] = JHTML::_('select.genericlist', $providersOptions, 'videoProvider', '', 'value', 'text', $lists['providerVideoType']);
     }
     JPluginHelper::importPlugin('content', 'jw_sigpro');
     JPluginHelper::importPlugin('content', 'jw_allvideos');
     $dispatcher = JDispatcher::getInstance();
     // Detect gallery type
     if (JString::strpos($item->gallery, 'http://')) {
         $item->galleryType = 'flickr';
         $item->galleryValue = JString::substr($item->gallery, 9);
         $item->galleryValue = JString::substr($item->galleryValue, 0, -10);
     } else {
         $item->galleryType = 'server';
         $item->galleryValue = '';
     }
     $params->set('galleries_rootfolder', 'media/k2/galleries');
     $item->text = $item->gallery;
     if (K2_JVERSION == '15') {
         $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
     } else {
         $dispatcher->trigger('onContentPrepare', array('com_k2.' . $view, &$item, &$params, null));
     }
     $item->gallery = $item->text;
     if (!$embedVideo) {
         $params->set('vfolder', 'media/k2/videos');
         $params->set('afolder', 'media/k2/audio');
         if (JString::strpos($item->video, 'remote}')) {
             preg_match("#}(.*?){/#s", $item->video, $matches);
             if (JString::substr($matches[1], 0, 7) != 'http://') {
                 $item->video = str_replace($matches[1], JURI::root() . $matches[1], $item->video);
             }
         }
         $item->text = $item->video;
         if (K2_JVERSION == '15') {
             $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
         } else {
             $dispatcher->trigger('onContentPrepare', array('com_k2.' . $view, &$item, &$params, null));
         }
         $item->video = $item->text;
     } else {
         // no nothing
     }
     if (isset($item->created_by)) {
         $author = JUser::getInstance($item->created_by);
         $item->author = $author->name;
     } else {
         $item->author = $user->name;
     }
     if (isset($item->modified_by)) {
         $moderator = JUser::getInstance($item->modified_by);
         $item->moderator = $moderator->name;
     }
     if ($item->id) {
         $active = $item->created_by;
     } else {
         $active = $user->id;
     }
     $lists['authors'] = JHTML::_('list.users', 'created_by', $active, false);
     $categories_option[] = JHTML::_('select.option', 0, JText::_('K2_SELECT_CATEGORY'));
     $categories = $categoriesModel->categoriesTree(NUll, true, false);
     if ($mainframe->isSite()) {
         JLoader::register('K2HelperPermissions', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'permissions.php');
         if (($task == 'add' || $task == 'edit') && !K2HelperPermissions::canAddToAll()) {
             for ($i = 0; $i < sizeof($categories); $i++) {
                 if (!K2HelperPermissions::canAddItem($categories[$i]->value) && $task == 'add') {
                     $categories[$i]->disable = true;
                 }
                 if (!K2HelperPermissions::canEditItem($item->created_by, $categories[$i]->value) && $task == 'edit') {
                     $categories[$i]->disable = true;
                 }
             }
         }
     }
     $categories_options = @array_merge($categories_option, $categories);
     $lists['categories'] = JHTML::_('select.genericlist', $categories_options, 'catid', '', 'value', 'text', $item->catid);
     JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');
     $category = JTable::getInstance('K2Category', 'Table');
     $category->load($item->catid);
     $extraFieldModel = K2Model::getInstance('ExtraField', 'K2Model');
     if ($category->id) {
         $extraFields = $extraFieldModel->getExtraFieldsByGroup($category->extraFieldsGroup);
     } else {
         $extraFields = NULL;
     }
     for ($i = 0; $i < sizeof($extraFields); $i++) {
         $extraFields[$i]->element = $extraFieldModel->renderExtraField($extraFields[$i], $item->id);
     }
     if ($item->id) {
         $item->attachments = $model->getAttachments($item->id);
         $rating = $model->getRating();
         if (is_null($rating)) {
             $item->ratingSum = 0;
             $item->ratingCount = 0;
         } else {
             $item->ratingSum = (int) $rating->rating_sum;
             $item->ratingCount = (int) $rating->rating_count;
         }
     } else {
         $item->attachments = NULL;
         $item->ratingSum = 0;
         $item->ratingCount = 0;
     }
     if ($user->gid < 24 && $params->get('lockTags')) {
         $params->set('taggingSystem', 0);
     }
     $tags = $model->getAvailableTags($item->id);
     $lists['tags'] = JHTML::_('select.genericlist', $tags, 'tags', 'multiple="multiple" size="10" ', 'id', 'name');
     if (isset($item->id)) {
         $item->tags = $model->getCurrentTags($item->id);
         $lists['selectedTags'] = JHTML::_('select.genericlist', $item->tags, 'selectedTags[]', 'multiple="multiple" size="10" ', 'id', 'name');
     } else {
         $lists['selectedTags'] = '<select size="10" multiple="multiple" id="selectedTags" name="selectedTags[]"></select>';
     }
     $lists['metadata'] = class_exists('JParameter') ? new JParameter($item->metadata) : new JRegistry($item->metadata);
     $date = JFactory::getDate($item->modified);
     $timestamp = '?t=' . $date->toUnix();
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
         $item->image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg' . $timestamp;
     }
     if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) {
         $item->thumb = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg' . $timestamp;
     }
     JPluginHelper::importPlugin('k2');
     $dispatcher = JDispatcher::getInstance();
     $K2PluginsItemContent = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'content'));
     $this->assignRef('K2PluginsItemContent', $K2PluginsItemContent);
     $K2PluginsItemImage = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'image'));
     $this->assignRef('K2PluginsItemImage', $K2PluginsItemImage);
     $K2PluginsItemGallery = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'gallery'));
     $this->assignRef('K2PluginsItemGallery', $K2PluginsItemGallery);
     $K2PluginsItemVideo = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'video'));
     $this->assignRef('K2PluginsItemVideo', $K2PluginsItemVideo);
     $K2PluginsItemExtraFields = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'extra-fields'));
     $this->assignRef('K2PluginsItemExtraFields', $K2PluginsItemExtraFields);
     $K2PluginsItemAttachments = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'attachments'));
     $this->assignRef('K2PluginsItemAttachments', $K2PluginsItemAttachments);
     $K2PluginsItemOther = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'other'));
     $this->assignRef('K2PluginsItemOther', $K2PluginsItemOther);
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         jimport('joomla.form.form');
         $form = JForm::getInstance('itemForm', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.xml');
         $values = array('params' => json_decode($item->params));
         $form->bind($values);
     } else {
         $form = new JParameter('', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.xml');
         $form->loadINI($item->params);
     }
     $this->assignRef('form', $form);
     $nullDate = $db->getNullDate();
     $this->assignRef('nullDate', $nullDate);
     $this->assignRef('extraFields', $extraFields);
     $this->assignRef('options', $options);
     $this->assignRef('row', $item);
     $this->assignRef('lists', $lists);
     $this->assignRef('params', $params);
     $this->assignRef('user', $user);
     JRequest::getInt('cid') ? $title = JText::_('K2_EDIT_ITEM') : ($title = JText::_('K2_ADD_ITEM'));
     $this->assignRef('title', $title);
     $this->assignRef('mainframe', $mainframe);
     if ($mainframe->isAdmin()) {
         $this->params->set('showImageTab', true);
         $this->params->set('showImageGalleryTab', true);
         $this->params->set('showVideoTab', true);
         $this->params->set('showExtraFieldsTab', true);
         $this->params->set('showAttachmentsTab', true);
         $this->params->set('showK2Plugins', true);
         JToolBarHelper::title($title, 'k2.png');
         JToolBarHelper::save();
         $saveNewIcon = version_compare(JVERSION, '2.5.0', 'ge') ? 'save-new.png' : 'save.png';
         JToolBarHelper::custom('saveAndNew', $saveNewIcon, 'save_f2.png', 'K2_SAVE_AND_NEW', false);
         JToolBarHelper::apply();
         JToolBarHelper::cancel();
     }
     // ACE ACL integration
     $definedConstants = get_defined_constants();
     if (!empty($definedConstants['ACEACL']) && AceaclApi::authorize('permissions', 'com_aceacl')) {
         $aceAclFlag = true;
     } else {
         $aceAclFlag = false;
     }
     $this->assignRef('aceAclFlag', $aceAclFlag);
     // SIG PRO v3 integration
     if (JPluginHelper::isEnabled('k2', 'jw_sigpro')) {
         $sigPro = true;
         $sigProFolder = $this->row->id ? $this->row->id : uniqid();
         $this->assignRef('sigProFolder', $sigProFolder);
     } else {
         $sigPro = false;
     }
     $this->assignRef('sigPro', $sigPro);
     parent::display($tpl);
 }
Exemplo n.º 11
0
 function checkPermissions()
 {
     $view = JRequest::getCmd('view');
     if ($view != 'item') {
         return;
     }
     $task = JRequest::getCmd('task');
     switch ($task) {
         case 'add':
             if (!K2HelperPermissions::canAddItem()) {
                 JError::raiseError(403, JText::_("ALERTNOTAUTH"));
             }
             break;
         case 'edit':
         case 'deleteAttachment':
         case 'checkin':
             $cid = JRequest::getInt('cid');
             if (!$cid) {
                 JError::raiseError(403, JText::_("ALERTNOTAUTH"));
             }
             JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
             $item =& JTable::getInstance('K2Item', 'Table');
             $item->load($cid);
             if (!K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
                 JError::raiseError(403, JText::_("ALERTNOTAUTH"));
             }
             break;
         case 'save':
             $cid = JRequest::getInt('id');
             if ($cid) {
                 JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
                 $item =& JTable::getInstance('K2Item', 'Table');
                 $item->load($cid);
                 if (!K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
                     JError::raiseError(403, JText::_("ALERTNOTAUTH"));
                 }
             } else {
                 if (!K2HelperPermissions::canAddItem()) {
                     JError::raiseError(403, JText::_("ALERTNOTAUTH"));
                 }
             }
             break;
         case 'tag':
             if (!K2HelperPermissions::canAddTag()) {
                 JError::raiseError(403, JText::_("ALERTNOTAUTH"));
             }
             break;
         case 'extraFields':
             if (!K2HelperPermissions::canRenderExtraFields()) {
                 JError::raiseError(403, JText::_("ALERTNOTAUTH"));
             }
             break;
     }
 }
Exemplo n.º 12
0
 function users()
 {
     $itemID = JRequest::getInt('itemID');
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
     $item =& JTable::getInstance('K2Item', 'Table');
     $item->load($itemID);
     if (!K2HelperPermissions::canAddItem() && !K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
     }
     $K2Permissions =& K2Permissions::getInstance();
     if (!$K2Permissions->permissions->get('editAll')) {
         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
     }
     JRequest::setVar('tmpl', 'component');
     $mainframe =& JFactory::getApplication();
     $params =& JComponentHelper::getParams('com_k2');
     $language =& JFactory::getLanguage();
     $language->load('com_k2', JPATH_ADMINISTRATOR);
     $document =& JFactory::getDocument();
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         JHtml::_('behavior.framework');
     } else {
         JHTML::_('behavior.mootools');
     }
     // CSS
     $document->addStyleSheet(JURI::root(true) . '/media/k2/assets/css/k2.css?v=2.5.7');
     // JS
     $jQueryHandling = $params->get('jQueryHandling', '1.7remote');
     if ($jQueryHandling && strpos($jQueryHandling, 'remote') == true) {
         $document->addScript('http://ajax.googleapis.com/ajax/libs/jquery/' . str_replace('remote', '', $jQueryHandling) . '/jquery.min.js');
         $document->addScript('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js');
     } elseif ($jQueryHandling && strpos($jQueryHandling, 'remote') == false) {
         $document->addScript(JURI::root(true) . '/media/k2/assets/js/jquery-' . $jQueryHandling . '.min.js');
         $document->addScript(JURI::root(true) . '/media/k2/assets/js/jquery-ui-1.8.16.custom.min.js');
     }
     $document->addScript(JURI::root(true) . '/media/k2/assets/js/k2.js?v=2.5.7');
     $this->addViewPath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'views');
     $this->addModelPath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models');
     $view =& $this->getView('users', 'html');
     $view->addTemplatePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'views' . DS . 'users' . DS . 'tmpl');
     $view->setLayout('element');
     $view->display();
 }
Exemplo n.º 13
0
        if ($task == 'create') {
            if ($isNew && !K2HelperPermissions::canAddItem()) {
                $canAccess = false;
            }
            if (!$isNew && !K2HelperPermissions::canEditItem($row->created_by, $row->catid)) {
                $canAccess = false;
            }
        } else {
            $canAccess = false;
        }
    } else {
        if ($view == 'gallery') {
            if ($isNew && !K2HelperPermissions::canAddItem()) {
                $canAccess = false;
            }
            if (!$isNew && !K2HelperPermissions::canEditItem($row->created_by, $row->catid)) {
                $canAccess = false;
            }
        }
    }
    if (!$canAccess) {
        JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
        $application->redirect('index.php');
    }
}
// Bootstrap
if (JFile::exists(JPATH_COMPONENT_ADMINISTRATOR . '/controllers/' . $view . '.php')) {
    JRequest::setVar('view', $view);
    require_once JPATH_COMPONENT_ADMINISTRATOR . '/controllers/' . $view . '.php';
    $class = 'SigProController' . ucfirst($view);
    $controller = new $class();
Exemplo n.º 14
0
    function edit()
    {
        $mainframe =& JFactory::getApplication();
        jimport('joomla.filesystem.file');
        jimport('joomla.html.pane');
        $db =& JFactory::getDBO();
        JHTML::_('behavior.mootools');
        $document =& JFactory::getDocument();
        $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/Autocompleter.js');
        $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/observer.js');
        $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/simpletabs_1.3.js');
        //$document->addScript(JURI::root().'administrator/components/com_k2/js/k2.js'); // Core JS
        $document->addScript(JURI::root() . 'administrator/components/com_k2/js/k2.mootools.js');
        // Mootools based JS
        $document->addCustomTag('
        
<!-- K2 by JoomlaWorks (start) -->
		
	<!-- Load Khepri styling -->
	<link rel="stylesheet" href="' . JURI::root() . 'administrator/templates/system/css/system.css" type="text/css" />
	<link href="' . JURI::root() . 'administrator/templates/khepri/css/template.css" rel="stylesheet" type="text/css" />
	<!--[if IE 7]>
	<link href="' . JURI::root() . 'administrator/templates/khepri/css/ie7.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<!--[if lte IE 6]>
	<link href="' . JURI::root() . 'administrator/templates/khepri/css/ie6.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="' . JURI::root() . 'administrator/templates/khepri/css/rounded.css" />
	
	<!-- Load K2 styling -->
	<link href="' . JURI::root() . 'administrator/components/com_k2/css/k2.css" rel="stylesheet" type="text/css" />
	<!--[if IE 7]>
	<link href="' . JURI::root() . 'administrator/components/com_k2/css/k2_ie7.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<!--[if lte IE 6]>
	<link href="' . JURI::root() . 'administrator/components/com_k2/css/k2_ie6.css" rel="stylesheet" type="text/css" />
	<![endif]-->
		
<!-- K2 by JoomlaWorks (end) -->

		');
        JRequest::setVar('tmpl', 'component');
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.php';
        $model = new K2ModelItem();
        $task = JRequest::getCmd('task');
        $user =& JFactory::getUser();
        if ($task == 'edit') {
            $item = $model->getData();
            JFilterOutput::objectHTMLSafe($item, ENT_QUOTES, 'video');
            if (!K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
                JError::raiseError(403, JText::_("ALERTNOTAUTH"));
            }
            if (JTable::isCheckedOut($user->get('id'), $item->checked_out)) {
                $msg = JText::sprintf('DESCBEINGEDITTED', JText::_('The item'), $item->title);
                $mainframe->redirect('index.php?option=com_k2&view=item&id=' . $item->id . '&tmpl=component', $msg);
            }
        } elseif ($task == 'add') {
            if (!K2HelperPermissions::canAddItem()) {
                JError::raiseError(403, JText::_("ALERTNOTAUTH"));
            }
            JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');
            $item =& JTable::getInstance('K2Item', 'Table');
            $createdate =& JFactory::getDate();
            $item->published = 1;
            $item->publish_up = $createdate->toUnix();
            $item->publish_down = JText::_('Never');
            $item->created = $createdate->toUnix();
            $item->modified = $db->getNullDate();
        }
        if ($item->id) {
            $item->checkout($user->get('id'));
        }
        $item->created = JHTML::_('date', $item->created, '%Y-%m-%d %H:%M:%S');
        $item->publish_up = JHTML::_('date', $item->publish_up, '%Y-%m-%d %H:%M:%S');
        if (JHTML::_('date', $item->publish_down, '%Y') <= 1969 || $item->publish_down == $db->getNullDate()) {
            $item->publish_down = JText::_('Never');
        } else {
            $item->publish_down = JHTML::_('date', $item->publish_down, '%Y-%m-%d %H:%M:%S');
        }
        $params =& JComponentHelper::getParams('com_k2');
        $wysiwyg =& JFactory::getEditor();
        if ($params->get("mergeEditors")) {
            if (JString::strlen($item->fulltext) > 1) {
                $textValue = $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext;
            } else {
                $textValue = $item->introtext;
            }
            $text = $wysiwyg->display('text', $textValue, '100%', '400', '40', '5', array('pagebreak'));
            $this->assignRef('text', $text);
        } else {
            $introtext = $wysiwyg->display('introtext', $item->introtext, '100%', '400', '40', '5', array('pagebreak', 'readmore'));
            $this->assignRef('introtext', $introtext);
            $fulltext = $wysiwyg->display('fulltext', $item->fulltext, '100%', '400', '40', '5', array('pagebreak', 'readmore'));
            $this->assignRef('fulltext', $fulltext);
        }
        $lists = array();
        $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $item->published);
        $lists['access'] = JHTML::_('list.accesslevel', $item);
        $query = "SELECT ordering AS value, title AS text FROM #__k2_items WHERE catid={$item->catid}";
        $lists['ordering'] = JHTML::_('list.specificordering', $item, $item->id, $query);
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'categories.php';
        $categoriesModel = new K2ModelCategories();
        $categories = $categoriesModel->categoriesTree();
        $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox"', 'value', 'text', $item->catid);
        $lists['checkSIG'] = $model->checkSIG();
        $lists['checkAllVideos'] = $model->checkAllVideos();
        $remoteVideo = false;
        $providerVideo = false;
        $embedVideo = false;
        $options['startOffset'] = 0;
        if (stristr($item->video, 'remote}') !== false) {
            $remoteVideo = true;
            $options['startOffset'] = 1;
        }
        $providers = $model->getVideoProviders();
        if (count($providers)) {
            foreach ($providers as $provider) {
                $providersOptions[] = JHTML::_('select.option', $provider, $provider);
                if (stristr($item->video, "{{$provider}}") !== false) {
                    $providerVideo = true;
                    $options['startOffset'] = 2;
                }
            }
        }
        if (JString::substr($item->video, 0, 1) !== '{') {
            $embedVideo = true;
            $options['startOffset'] = 3;
        }
        $lists['uploadedVideo'] = !$remoteVideo && !$providerVideo && !$embedVideo ? true : false;
        if ($lists['uploadedVideo']) {
            $options['startOffset'] = 0;
        }
        $lists['remoteVideo'] = $remoteVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['remoteVideoType'] = $remoteVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['providerVideo'] = $providerVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['providerVideoType'] = $providerVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['embedVideo'] = $embedVideo ? $item->video : '';
        if (count($providers)) {
            $lists['providers'] = JHTML::_('select.genericlist', $providersOptions, 'videoProvider', '', 'value', 'text', $lists['providerVideoType']);
        }
        JPluginHelper::importPlugin('content', 'jw_sigpro');
        JPluginHelper::importPlugin('content', 'jw_sig');
        JPluginHelper::importPlugin('content', 'jw_allvideos');
        $dispatcher =& JDispatcher::getInstance();
        $params->set('galleries_rootfolder', 'media/k2/galleries');
        $params->set('thb_width', '150');
        $params->set('thb_height', '120');
        $params->set('popup_engine', 'mootools_slimbox');
        $params->set('enabledownload', '0');
        $item->text = $item->gallery;
        $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
        $item->gallery = $item->text;
        if (!$embedVideo) {
            $params->set('vfolder', 'media/k2/videos');
            $item->text = $item->video;
            $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
            $item->video = $item->text;
        } else {
            $item->video = '<div>' . $item->video . '</div>';
        }
        if (isset($item->created_by)) {
            $author =& JUser::getInstance($item->created_by);
            $item->author = $author->name;
        }
        if (isset($item->modified_by)) {
            $moderator =& JUser::getInstance($item->modified_by);
            $item->moderator = $moderator->name;
        }
        if ($task == 'edit') {
            $item->editor = $item->author;
        } else {
            $item->editor = $user->name;
        }
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'categories.php';
        $categoriesModel = new K2ModelCategories();
        $categories_option[] = JHTML::_('select.option', 0, JText::_('- Select category -'));
        $categories = $categoriesModel->categoriesTree();
        if (($task == 'add' || $task == 'edit') && !$user->authorize('com_k2', 'add', 'category', 'all')) {
            for ($i = 0; $i < sizeof($categories); $i++) {
                if (!$user->authorize('com_k2', 'add', 'category', $categories[$i]->value)) {
                    $categories[$i]->disable = true;
                }
            }
        }
        $categories_options = @array_merge($categories_option, $categories);
        $lists['categories'] = JHTML::_('select.genericlist', $categories_options, 'catid', '', 'value', 'text', $item->catid);
        JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');
        $category =& JTable::getInstance('K2Category', 'Table');
        $category->load($item->catid);
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'extrafield.php';
        $extraFieldModel = new K2ModelExtraField();
        if ($category->extraFieldsGroup) {
            $extraFields = $extraFieldModel->getExtraFieldsByGroup($category->extraFieldsGroup);
        } else {
            $extraFields = NULL;
        }
        for ($i = 0; $i < sizeof($extraFields); $i++) {
            $extraFields[$i]->element = $extraFieldModel->renderExtraField($extraFields[$i], $item->id);
        }
        if ($item->id) {
            $item->attachments = $model->getAttachments($item->id);
        } else {
            $item->attachments = NULL;
        }
        $tags = $model->getAvailableTags($item->id);
        $lists['tags'] = JHTML::_('select.genericlist', $tags, 'tags', 'multiple="multiple" size="10" ', 'id', 'name');
        if (isset($item->id)) {
            $item->tags = $model->getCurrentTags($item->id);
            $lists['selectedTags'] = JHTML::_('select.genericlist', $item->tags, 'selectedTags[]', 'multiple="multiple" size="10" ', 'id', 'name');
        } else {
            $lists['selectedTags'] = '<select size="10" multiple="multiple" id="selectedTags" name="selectedTags[]"></select>';
        }
        if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
            $item->image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg';
        }
        if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) {
            $item->thumb = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg';
        }
        $lists['metadata'] = new JParameter($item->metadata);
        JPluginHelper::importPlugin('k2');
        $dispatcher =& JDispatcher::getInstance();
        $K2PluginsItemContent = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'content'));
        $this->assignRef('K2PluginsItemContent', $K2PluginsItemContent);
        $K2PluginsItemImage = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'image'));
        $this->assignRef('K2PluginsItemImage', $K2PluginsItemImage);
        $K2PluginsItemGallery = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'gallery'));
        $this->assignRef('K2PluginsItemGallery', $K2PluginsItemGallery);
        $K2PluginsItemVideo = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'video'));
        $this->assignRef('K2PluginsItemVideo', $K2PluginsItemVideo);
        $K2PluginsItemExtraFields = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'extra-fields'));
        $this->assignRef('K2PluginsItemExtraFields', $K2PluginsItemExtraFields);
        $K2PluginsItemAttachments = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'attachments'));
        $this->assignRef('K2PluginsItemAttachments', $K2PluginsItemAttachments);
        $K2PluginsItemOther = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'other'));
        $this->assignRef('K2PluginsItemOther', $K2PluginsItemOther);
        $form = new JParameter('', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.xml');
        $form->loadINI($item->params);
        $this->assignRef('form', $form);
        $this->assignRef('extraFields', $extraFields);
        $this->assignRef('options', $options);
        $this->assignRef('row', $item);
        $this->assignRef('lists', $lists);
        $this->assignRef('params', $params);
        parent::display();
    }