Example #1
0
 public function onAfterInitialise()
 {
     // Get application
     $application = JFactory::getApplication();
     // Get user
     $user = JFactory::getUser();
     // Load Joomla! classes
     jimport('joomla.filesystem.file');
     // Load the K2 classes
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/classes/plugin.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/tables/table.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/models/model.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/attachments.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/categories.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/comments.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/extrafields.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/extrafieldsgroups.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/items.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/tags.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/users.php';
     K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models');
     // Load K2 language
     $language = JFactory::getLanguage();
     $language->load('com_k2', JPATH_ADMINISTRATOR);
     // Use K2 to make Joomla! Varnish-friendly. For more checkout: https://snipt.net/fevangelou/the-perfect-varnish-configuration-for-joomla-websites/
     if (!$user->guest) {
         $application->setHeader('X-Logged-In', 'True', true);
     } else {
         $application->setHeader('X-Logged-In', 'False', true);
     }
 }
Example #2
0
 protected function getInput()
 {
     $document = JFactory::getDocument();
     $document->addScriptDeclaration('var K2BasePath = "' . JURI::root(true) . '";');
     $document->addScript(JURI::root(true) . '/plugins/josetta_ext/k2item/fields/k2extrafields.js');
     K2Model::addIncludePath(JPATH_SITE . '/components/com_k2/models');
     JLoader::register('K2HelperUtilities', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'utilities.php');
     $model = K2Model::getInstance('Item', 'K2Model');
     $extraFields = $model->getItemExtraFields($this->value);
     $html = '<div id="extraFieldsContainer">';
     if (count($extraFields)) {
         $html .= '<table class="admintable" id="extraFields">';
         foreach ($extraFields as $extraField) {
             $html .= '<tr>
             <td align="right" class="key">' . $extraField->name . '</td>
             <td>' . $extraField->element . '</td>
             </tr>';
         }
         $html .= '</table>';
     } else {
         $html .= '<span class="k2Note"> ' . JText::_('K2_PLEASE_SELECT_A_CATEGORY_FIRST_TO_RETRIEVE_ITS_RELATED_EXTRA_FIELDS') . ' </span>';
     }
     $html .= '</div>';
     return $html;
 }
Example #3
0
 public function onJosettaLoadItem($context, $id = '')
 {
     if (!empty($context) && $context != $this->_context || empty($id)) {
         return null;
     }
     $item = parent::onJosettaLoadItem($context, $id);
     // Merge introtext and fulltext
     $item->articletext = trim($item->fulltext) != '' ? $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext : $item->introtext;
     // Get tags
     K2Model::addIncludePath(JPATH_SITE . '/components/com_k2/models');
     JLoader::register('K2HelperUtilities', JPATH_SITE . '/components/com_k2/helpers/utilities.php');
     $model = K2Model::getInstance('Item', 'K2Model');
     $tags = $model->getItemTags($item->id);
     $tmp = array();
     foreach ($tags as $tag) {
         $tmp[] = $tag->name;
     }
     $item->tags = implode(', ', $tmp);
     // Get extra fields
     $extraFields = $model->getItemExtraFields($item->extra_fields);
     $html = '';
     if (count($extraFields)) {
         $html .= '<ul>';
         foreach ($extraFields as $key => $extraField) {
             $html .= '<li class="type' . ucfirst($extraField->type) . ' group' . $extraField->group . '">
             <span class="itemExtraFieldsLabel">' . $extraField->name . ':</span>
             <span class="itemExtraFieldsValue">' . $extraField->value . '</span>
         </li>';
         }
         $html .= '</ul>';
     }
     $item->extra_fields = $html;
     // Return the item
     return $item;
 }
Example #4
0
 public static function getAvatar($userID, $email = NULL, $width = 50)
 {
     jimport('joomla.filesystem.folder');
     jimport('joomla.application.component.model');
     $mainframe = JFactory::getApplication();
     $params = K2HelperUtilities::getParams('com_k2');
     if (K2_CB && $userID != 'alias') {
         $cbUser = CBuser::getInstance((int) $userID);
         if (is_object($cbUser)) {
             $avatar = $cbUser->getField('avatar', null, 'csv', 'none', 'profile');
             return $avatar;
         }
     }
     /*
     // JomSocial Avatar integration
     if(JFolder::exists(JPATH_SITE.DS.'components'.DS.'com_community') && $userID>0){
     $userInfo = &CFactory::getUser($userID);
     return $userInfo->getThumbAvatar();
     }
     */
     // Check for placeholder overrides
     if (JFile::exists(JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'images' . DS . 'placeholder' . DS . 'user.png')) {
         $avatarPath = 'templates/' . $mainframe->getTemplate() . '/images/placeholder/user.png';
     } else {
         $avatarPath = 'components/com_k2/images/placeholder/user.png';
     }
     // Continue with default K2 avatar determination
     if ($userID == 'alias') {
         $avatar = JURI::root(true) . '/' . $avatarPath;
     } else {
         if ($userID == 0) {
             if ($params->get('gravatar') && !is_null($email)) {
                 $avatar = 'http://www.gravatar.com/avatar/' . md5($email) . '?s=' . $width . '&amp;default=' . urlencode(JURI::root() . $avatarPath);
             } else {
                 $avatar = JURI::root(true) . '/' . $avatarPath;
             }
         } else {
             if (is_numeric($userID) && $userID > 0) {
                 K2Model::addIncludePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models');
                 $model = K2Model::getInstance('Item', 'K2Model');
                 $profile = $model->getUserProfile($userID);
                 $avatar = is_null($profile) ? '' : $profile->image;
                 if (empty($avatar)) {
                     if ($params->get('gravatar') && !is_null($email)) {
                         $avatar = 'http://www.gravatar.com/avatar/' . md5($email) . '?s=' . $width . '&amp;default=' . urlencode(JURI::root() . $avatarPath);
                     } else {
                         $avatar = JURI::root(true) . '/' . $avatarPath;
                     }
                 } else {
                     $avatar = JURI::root(true) . '/media/k2/users/' . $avatar;
                 }
             }
         }
     }
     if (!$params->get('userImageDefault') && $avatar == JURI::root(true) . '/' . $avatarPath) {
         $avatar = '';
     }
     return $avatar;
 }
Example #5
0
 /**
  * Gets an item instance.
  *
  * @param integer $id	The id of the item to get.
  *
  * @return K2Attachment The attachment object.
  */
 public static function getInstance($id)
 {
     if (empty(self::$instances[$id])) {
         K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models');
         $model = K2Model::getInstance('Attachments', 'K2Model');
         $model->setState('id', $id);
         $item = $model->getRow();
         self::$instances[$id] = $item;
     }
     return self::$instances[$id];
 }
 public function getFields()
 {
     $fields = array();
     if ($this->id) {
         K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models');
         $model = K2Model::getInstance('ExtraFields', 'K2Model');
         $model->setState('group', $this->id);
         $model->setState('sorting', 'ordering');
         $fields = $model->getRows();
     }
     return $fields;
 }
Example #7
0
 public static function _findItem($catid)
 {
     $component = JComponentHelper::getComponent('com_jak2filter');
     $application = JFactory::getApplication();
     $menus = $application->getMenu('site', array());
     if (K2_JVERSION != '15') {
         $items = $menus->getItems('component_id', $component->id);
     } else {
         $items = $menus->getItems('componentid', $component->id);
     }
     $match = null;
     if (count($items)) {
         foreach ($items as $item) {
             if ($catid) {
                 if (@$item->query['view'] == 'itemlist' && @$item->query['category_id'] == $catid) {
                     $match = $item;
                     break;
                 }
             } else {
                 if (@$item->query['view'] == 'itemlist' && !isset($item->query['category_id'])) {
                     $match = $item;
                     break;
                 }
             }
         }
     }
     if (is_null($match)) {
         // Try to detect any parent category menu item....
         if (is_null(self::$tree)) {
             include_once JPATH_ADMINISTRATOR . '/components/com_k2/models/model.php';
             K2Model::addIncludePath(JPATH_SITE . '/components/com_k2/models');
             $model = K2Model::getInstance('Itemlist', 'K2Model');
             self::$model = $model;
             self::$tree = $model->getCategoriesTree();
         }
         $parents = self::$model->getTreePath(self::$tree, $catid);
         if (is_array($parents)) {
             foreach ($parents as $categoryID) {
                 if ($categoryID != $catid) {
                     $match = JAK2FilterHelperRoute::_findItem($categoryID);
                     if (!is_null($match)) {
                         break;
                     }
                 }
             }
         }
         if (is_null($match) && !is_null(self::$anyK2Link)) {
             $match = self::$anyK2Link;
         }
     }
     return $match;
 }
Example #8
0
 public static function getGroups($scope = 'item')
 {
     if (!isset(self::$groups[$scope])) {
         K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models');
         $model = K2Model::getInstance('ExtraFieldsGroups', 'K2Model');
         $model->setState('scope', $scope);
         $model->setState('sorting', 'name');
         $rows = $model->getRows();
         self::$groups[$scope] = array();
         foreach ($rows as $row) {
             self::$groups[$scope][$row->id] = $row;
         }
     }
     return self::$groups[$scope];
 }
Example #9
0
 /**
  * Gets an item instance.
  *
  * @param integer $id	The id of the item to get.
  *
  * @return K2Category The category object.
  */
 public static function getInstance($id)
 {
     if (empty(self::$instances[$id])) {
         K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models');
         $model = K2Model::getInstance('Categories', 'K2Model');
         if (is_numeric($id)) {
             $model->setState('id', $id);
         } else {
             $model->setState('alias', $id);
         }
         $item = $model->getRow();
         self::$instances[$id] = $item;
         self::$instances[$item->alias] = $item;
     }
     return self::$instances[$id];
 }
Example #10
0
 function getRelatedItems($itemID, $tags, $params)
 {
     // var_dump($tags);
     $mainframe = JFactory::getApplication();
     $limit = $params->get('itemRelatedLimit', 10);
     $itemID = (int) $itemID;
     foreach ($tags as $tag) {
         $tagIDs[] = $tag->id;
     }
     JArrayHelper::toInteger($tagIDs);
     $sql = implode(',', $tagIDs);
     $user = JFactory::getUser();
     $aid = (int) $user->get('aid');
     $db = JFactory::getDBO();
     $jnow = JFactory::getDate();
     $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql();
     $nullDate = $db->getNullDate();
     $query = "SELECT DISTINCT itemID FROM #__k2_tags_xref WHERE tagID IN ({$sql}) AND itemID!={$itemID}";
     $db->setQuery($query);
     $itemsIDs = K2_JVERSION == '30' ? $db->loadColumn() : $db->loadResultArray();
     if (!count($itemsIDs)) {
         return array();
     }
     $sql = implode(',', $itemsIDs);
     $query = "SELECT i.*, c.alias as categoryalias FROM #__k2_items as i \n\t\t\t\tLEFT JOIN #__k2_categories c ON c.id = i.catid \n\t\t\t\tWHERE i.published = 1 \n\t\t\t\tAND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " ) \n\t\t\t\tAND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " ) ";
     if (K2_JVERSION != '15') {
         $query .= " AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
         if ($mainframe->getLanguageFilter()) {
             $query .= " AND i.language IN(" . $db->Quote(JFactory::getLanguage()->getTag()) . ", " . $db->Quote('*') . ")";
         }
     } else {
         $query .= " AND i.access <= {$aid} ";
     }
     $query .= " AND i.trash = 0 \n\t\t\t\tAND c.published = 1 ";
     if (K2_JVERSION != '15') {
         $query .= " AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
         if ($mainframe->getLanguageFilter()) {
             $query .= " AND c.language IN(" . $db->Quote(JFactory::getLanguage()->getTag()) . ", " . $db->Quote('*') . ")";
         }
     } else {
         $query .= " AND c.access <= {$aid} ";
     }
     $query .= " AND c.trash = 0 \n\t\t\t\tAND (i.id) IN ({$sql}) \n\t\t\t\tORDER BY i.created DESC";
     $db->setQuery($query, 0, $limit);
     $rows = $db->loadObjectList();
     K2Model::addIncludePath(JPATH_COMPONENT . DS . 'models');
     $model = K2Model::getInstance('Item', 'K2Model');
     for ($key = 0; $key < sizeof($rows); $key++) {
         if (!$params->get('itemRelatedMedia')) {
             $rows[$key]->video = null;
         }
         if (!$params->get('itemRelatedImageGallery')) {
             $rows[$key]->gallery = null;
         }
         $rows[$key] = $model->prepareItem($rows[$key], 'relatedByTag', '');
         $rows[$key] = $model->execPlugins($rows[$key], 'relatedByTag', '');
         K2HelperUtilities::setDefaultImage($rows[$key], 'relatedByTag', $params);
     }
     return $rows;
 }
Example #11
0
 function getTotal()
 {
     $mainframe = JFactory::getApplication();
     $params = JComponentHelper::getParams('com_k2');
     $option = JRequest::getCmd('option');
     $view = JRequest::getCmd('view');
     $db = JFactory::getDBO();
     $filter_trash = $mainframe->getUserStateFromRequest($option . $view . 'filter_trash', 'filter_trash', 0, 'int');
     $filter_featured = $mainframe->getUserStateFromRequest($option . $view . 'filter_featured', 'filter_featured', -1, 'int');
     $filter_category = $mainframe->getUserStateFromRequest($option . $view . 'filter_category', 'filter_category', 0, 'int');
     $filter_author = $mainframe->getUserStateFromRequest($option . $view . 'filter_author', 'filter_author', 0, 'int');
     $filter_state = $mainframe->getUserStateFromRequest($option . $view . 'filter_state', 'filter_state', -1, 'int');
     $search = $mainframe->getUserStateFromRequest($option . $view . 'search', 'search', '', 'string');
     $search = JString::strtolower($search);
     $tag = $mainframe->getUserStateFromRequest($option . $view . 'tag', 'tag', 0, 'int');
     $language = $mainframe->getUserStateFromRequest($option . $view . 'language', 'language', '', 'string');
     $query = "SELECT COUNT(*) FROM #__k2_items AS i ";
     if ($params->get('showTagFilter') && $tag) {
         $query .= " LEFT JOIN #__k2_tags_xref AS tags_xref ON tags_xref.itemID = i.id";
     }
     $query .= " WHERE trash={$filter_trash} ";
     if ($search) {
         $escaped = K2_JVERSION == '15' ? $db->getEscaped($search, true) : $db->escape($search, true);
         $quoted = $db->Quote('%' . $escaped . '%', false);
         if ($params->get('adminSearch') == 'full') {
             $query .= " AND ( LOWER(i.title) LIKE " . $quoted . " OR LOWER(i.introtext) LIKE " . $quoted . " OR LOWER(i.`fulltext`) LIKE " . $quoted . " OR LOWER(i.extra_fields_search) LIKE " . $quoted . " OR LOWER(i.image_caption) LIKE " . $quoted . " OR LOWER(i.image_credits) LIKE " . $quoted . " OR LOWER(i.video_caption) LIKE " . $quoted . " OR LOWER(i.video_credits) LIKE " . $quoted . " OR LOWER(i.metadesc) LIKE " . $quoted . " OR LOWER(i.metakey) LIKE " . $quoted . ") ";
         } else {
             $query .= " AND LOWER(i.title) LIKE " . $quoted;
         }
     }
     if ($filter_state > -1) {
         $query .= " AND published={$filter_state}";
     }
     if ($filter_featured > -1) {
         $query .= " AND featured={$filter_featured}";
     }
     if ($filter_category > 0) {
         if ($params->get('showChildCatItems')) {
             K2Model::addIncludePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models');
             $itemListModel = K2Model::getInstance('Itemlist', 'K2Model');
             $categories = $itemListModel->getCategoryTree($filter_category);
             $sql = @implode(',', $categories);
             $query .= " AND catid IN ({$sql})";
         } else {
             $query .= " AND catid={$filter_category}";
         }
     }
     if ($filter_author > 0) {
         $query .= " AND created_by={$filter_author}";
     }
     if ($params->get('showTagFilter') && $tag) {
         $query .= " AND tags_xref.tagID = {$tag}";
     }
     if ($language) {
         $query .= " AND (language = " . $db->Quote($language) . " OR language = '*')";
     }
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('k2');
     $dispatcher->trigger('onK2BeforeSetQuery', array(&$query));
     $db->setQuery($query);
     $result = $db->loadResult();
     return $result;
 }
Example #12
0
    function reportSpammer()
    {
        $mainframe = JFactory::getApplication();
        $user = JFactory::getUser();
        $format = JRequest::getVar('format');
        $errors = array();
        if (K2_JVERSION != '15')
        {
            if (!$user->authorise('core.admin', 'com_k2'))
            {
                $format == 'raw' ? die(JText::_('K2_ALERTNOTAUTH')) : JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
            }
        }
        else
        {
            if ($user->gid < 25)
            {
                $format == 'raw' ? die(JText::_('K2_ALERTNOTAUTH')) : JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
            }
        }
        K2Model::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'models');
        $model = K2Model::getInstance('User', 'K2Model');
        $model->setState('id', JRequest::getInt('id'));
        $model->reportSpammer();
        if ($format == 'raw')
        {
            $response = '';
            $messages = $mainframe->getMessageQueue();
            foreach ($messages as $message)
            {
                $response .= $message['message']."\n";
            }
            die($response);

        }
        $this->setRedirect('index.php?option=com_k2&view=comments&tmpl=component');
    }
Example #13
0
 function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     $document = JFactory::getDocument();
     $db = JFactory::getDBO();
     $params = JComponentHelper::getParams('com_k2');
     $option = JRequest::getCmd('option');
     $view = JRequest::getCmd('view');
     $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
     $limitstart = $mainframe->getUserStateFromRequest($option . $view . '.limitstart', 'limitstart', 0, 'int');
     $filter_order = $mainframe->getUserStateFromRequest($option . $view . 'filter_order', 'filter_order', 'juser.name', 'cmd');
     $filter_order_Dir = $mainframe->getUserStateFromRequest($option . $view . 'filter_order_Dir', 'filter_order_Dir', '', 'word');
     $filter_status = $mainframe->getUserStateFromRequest($option . $view . 'filter_status', 'filter_status', -1, 'int');
     $filter_group = $mainframe->getUserStateFromRequest($option . $view . 'filter_group', 'filter_group', '', 'string');
     $filter_group_k2 = $mainframe->getUserStateFromRequest($option . $view . 'filter_group_k2', 'filter_group_k2', '', 'string');
     $search = $mainframe->getUserStateFromRequest($option . $view . 'search', 'search', '', 'string');
     $search = JString::strtolower($search);
     K2Model::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models');
     $model = K2Model::getInstance('Users', 'K2Model');
     $total = $model->getTotal();
     if ($limitstart > $total - $limit) {
         $limitstart = max(0, (int) (ceil($total / $limit) - 1) * $limit);
         JRequest::setVar('limitstart', $limitstart);
     }
     $users = $model->getData();
     $task = JRequest::getCmd('task');
     for ($i = 0; $i < sizeof($users); $i++) {
         $users[$i]->loggedin = $model->checkLogin($users[$i]->id);
         $users[$i]->profileID = $model->hasProfile($users[$i]->id);
         if ($users[$i]->profileID) {
             $db->setQuery("SELECT ip FROM #__k2_users WHERE id = " . $users[$i]->profileID);
             $users[$i]->ip = $db->loadResult();
         } else {
             $users[$i]->ip = '';
         }
         if ($users[$i]->lastvisitDate == "0000-00-00 00:00:00") {
             $users[$i]->lvisit = false;
         } else {
             $users[$i]->lvisit = $users[$i]->lastvisitDate;
         }
         $users[$i]->link = JRoute::_('index.php?option=com_k2&view=user&cid=' . $users[$i]->id);
         if (K2_JVERSION == '15') {
             $users[$i]->published = $users[$i]->loggedin;
             $users[$i]->loggedInStatus = strip_tags(JHTML::_('grid.published', $users[$i], $i), '<img>');
             $users[$i]->blockStatus = '';
             if ($users[$i]->block) {
                 $users[$i]->blockStatus .= '<a title="' . JText::_('K2_ENABLE') . '" onclick="return listItemTask(\'cb' . $i . ',\'enable\')" href="#"><img alt="' . JText::_('K2_ENABLED') . '" src="images/publish_x.png"></a>';
             } else {
                 $users[$i]->blockStatus .= '<a title="' . JText::_('K2_DISABLE') . '" onclick="return listItemTask(\'cb' . $i . ',\'disable\')" href="#"><img alt="' . JText::_('K2_DISABLED') . '" src="images/tick.png"></a>';
             }
             if ($task == 'element') {
                 $users[$i]->blockStatus = strip_tags($users[$i]->blockStatus, '<img>');
             }
         } else {
             $states = array(1 => array('', 'K2_LOGGED_IN', 'K2_LOGGED_IN', 'K2_LOGGED_IN', false, 'publish', 'publish'), 0 => array('', 'K2_NOT_LOGGED_IN', 'K2_NOT_LOGGED_IN', 'K2_NOT_LOGGED_IN', false, 'unpublish', 'unpublish'));
             $users[$i]->loggedInStatus = JHtml::_('jgrid.state', $states, $users[$i]->loggedin, $i, '', false);
             $states = array(0 => array('disable', 'K2_ENABLED', 'K2_DISABLE', 'K2_ENABLED', false, 'publish', 'publish'), 1 => array('enable', 'K2_DISABLED', 'K2_ENABLE', 'K2_DISABLED', false, 'unpublish', 'unpublish'));
             $users[$i]->blockStatus = JHtml::_('jgrid.state', $states, $users[$i]->block, $i, '', $task != 'element');
         }
     }
     $this->assignRef('rows', $users);
     jimport('joomla.html.pagination');
     $pageNav = new JPagination($total, $limitstart, $limit);
     $this->assignRef('page', $pageNav);
     $lists = array();
     $lists['search'] = $search;
     $lists['order_Dir'] = $filter_order_Dir;
     $lists['order'] = $filter_order;
     $filter_status_options[] = JHTML::_('select.option', -1, JText::_('K2_SELECT_STATE'));
     $filter_status_options[] = JHTML::_('select.option', 0, JText::_('K2_ENABLED'));
     $filter_status_options[] = JHTML::_('select.option', 1, JText::_('K2_BLOCKED'));
     $lists['status'] = JHTML::_('select.genericlist', $filter_status_options, 'filter_status', '', 'value', 'text', $filter_status);
     $userGroups = $model->getUserGroups();
     $groups[] = JHTML::_('select.option', '0', JText::_('K2_SELECT_JOOMLA_GROUP'));
     foreach ($userGroups as $userGroup) {
         $groups[] = JHTML::_('select.option', $userGroup->value, $userGroup->text);
     }
     $lists['filter_group'] = JHTML::_('select.genericlist', $groups, 'filter_group', '', 'value', 'text', $filter_group);
     $K2userGroups = $model->getUserGroups('k2');
     $K2groups[] = JHTML::_('select.option', '0', JText::_('K2_SELECT_K2_GROUP'));
     foreach ($K2userGroups as $K2userGroup) {
         $K2groups[] = JHTML::_('select.option', $K2userGroup->id, $K2userGroup->name);
     }
     $lists['filter_group_k2'] = JHTML::_('select.genericlist', $K2groups, 'filter_group_k2', '', 'value', 'text', $filter_group_k2);
     $this->assignRef('lists', $lists);
     if (K2_JVERSION != '15') {
         $dateFormat = JText::_('K2_J16_DATE_FORMAT');
     } else {
         $dateFormat = JText::_('K2_DATE_FORMAT');
     }
     $this->assignRef('dateFormat', $dateFormat);
     $template = $mainframe->getTemplate();
     $this->assignRef('template', $template);
     if ($mainframe->isAdmin()) {
         JToolBarHelper::title(JText::_('K2_USERS'), 'k2.png');
         JToolBarHelper::custom('move', 'move.png', 'move_f2.png', 'K2_MOVE', true);
         JToolBarHelper::deleteList('K2_WARNING_YOU_ARE_ABOUT_TO_DELETE_THE_SELECTED_USERS_PERMANENTLY_FROM_THE_SYSTEM', 'delete', 'K2_DELETE');
         JToolBarHelper::publishList('enable', 'K2_ENABLE');
         JToolBarHelper::unpublishList('disable', 'K2_DISABLE');
         JToolBarHelper::editList();
         JToolBarHelper::deleteList('K2_ARE_YOU_SURE_YOU_WANT_TO_RESET_SELECTED_USERS', 'remove', 'K2_RESET_USER_DETAILS');
         $toolbar = JToolBar::getInstance('toolbar');
         if (K2_JVERSION != '15') {
             JToolBarHelper::preferences('com_k2', 550, 875, 'K2_PARAMETERS');
         } else {
             $toolbar->appendButton('Popup', 'config', 'K2_PARAMETERS', 'index.php?option=com_k2&view=settings');
         }
         $this->loadHelper('html');
         K2HelperHTML::subMenu();
         $user = JFactory::getUser();
         $canImport = false;
         if (K2_JVERSION == '15') {
             $canImport = $user->gid > 23;
         } else {
             $canImport = $user->authorise('core.admin', 'com_k2');
         }
         if ($canImport) {
             if (!$params->get('hideImportButton')) {
                 $buttonUrl = JURI::base() . 'index.php?option=com_k2&amp;view=users&amp;task=import';
                 $buttonText = JText::_('K2_IMPORT_JOOMLA_USERS');
                 if (K2_JVERSION == '30') {
                     $button = '<a id="K2ImportUsersButton" class="btn btn-small" href="' . $buttonUrl . '"><i class="icon-archive "></i>' . $buttonText . '</a>';
                 } else {
                     $button = '<a id="K2ImportUsersButton" href="' . $buttonUrl . '"><span class="icon-32-archive" title="' . $buttonText . '"></span>' . $buttonText . '</a>';
                 }
                 $toolbar->appendButton('Custom', $button);
             }
         }
         $document = JFactory::getDocument();
         $document->addScriptDeclaration('var K2Language = ["' . JText::_('K2_REPORT_USER_WARNING', true) . '"];');
     }
     $isAdmin = $mainframe->isAdmin();
     $this->assignRef('isAdmin', $isAdmin);
     if ($mainframe->isSite()) {
         // CSS
         $document->addStyleSheet(JURI::root(true) . '/media/k2/assets/css/k2.frontend.css?v=2.7.0');
         $document->addStyleSheet(JURI::root(true) . '/templates/system/css/general.css');
         $document->addStyleSheet(JURI::root(true) . '/templates/system/css/system.css');
         if (K2_JVERSION != '15') {
             $document->addStyleSheet(JURI::root(true) . '/administrator/templates/bluestork/css/template.css');
             $document->addStyleSheet(JURI::root(true) . '/media/system/css/system.css');
         } else {
             $document->addStyleSheet(JURI::root(true) . '/administrator/templates/khepri/css/general.css');
         }
     }
     parent::display($tpl);
 }
Example #14
0
<?php

/**
 * @version		3.0.0
 * @package		K2
 * @author		JoomlaWorks http://www.joomlaworks.net
 * @copyright	Copyright (c) 2006 - 2014 JoomlaWorks Ltd. All rights reserved.
 * @license		GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
 */
// no direct access
defined('_JEXEC') or die;
require_once JPATH_SITE . '/components/com_k2/helpers/route.php';
require_once JPATH_SITE . '/components/com_k2/helpers/utilities.php';
require_once JPATH_ADMINISTRATOR . '/components/com_k2/models/model.php';
K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models');
class ModK2ToolsHelper
{
    public static function getArchive($params)
    {
        $model = K2Model::getInstance('Items');
        $model->setState('site', true);
        $filter = $params->get('archiveCategory');
        $model->setState('category.filter', $filter);
        $model->setState('sorting', 'created.reverse');
        $rows = $model->getArchive();
        $months = array(JText::_('K2_JANUARY'), JText::_('K2_FEBRUARY'), JText::_('K2_MARCH'), JText::_('K2_APRIL'), JText::_('K2_MAY'), JText::_('K2_JUNE'), JText::_('K2_JULY'), JText::_('K2_AUGUST'), JText::_('K2_SEPTEMBER'), JText::_('K2_OCTOBER'), JText::_('K2_NOVEMBER'), JText::_('K2_DECEMBER'));
        $archives = array();
        $root = isset($filter->categories[0]) ? $filter->categories[0] : 0;
        foreach ($rows as $row) {
            $row->numOfItems = '';
            if ($params->get('archiveItemsCounter')) {
Example #15
0
 function getData()
 {
     $mainframe = JFactory::getApplication();
     $option = JRequest::getCmd('option');
     $view = JRequest::getCmd('view');
     $db = JFactory::getDBO();
     $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
     $limitstart = $mainframe->getUserStateFromRequest($option . $view . '.limitstart', 'limitstart', 0, 'int');
     $search = $mainframe->getUserStateFromRequest($option . $view . 'search', 'search', '', 'string');
     $search = JString::strtolower($search);
     $filter_order = $mainframe->getUserStateFromRequest($option . $view . 'filter_order', 'filter_order', 'c.ordering', 'cmd');
     $filter_order_Dir = $mainframe->getUserStateFromRequest($option . $view . 'filter_order_Dir', 'filter_order_Dir', '', 'word');
     $filter_trash = $mainframe->getUserStateFromRequest($option . $view . 'filter_trash', 'filter_trash', 0, 'int');
     $language = $mainframe->getUserStateFromRequest($option . $view . 'language', 'language', '', 'string');
     $filter_category = $mainframe->getUserStateFromRequest($option . $view . 'filter_category', 'filter_category', 0, 'int');
     // Publish categories only
     $filter_state = $mainframe->getUserStateFromRequest($option . $view . 'filter_state', 'filter_state', 1, 'int');
     $query = "SELECT c.*, g.name AS groupname, exfg.name as extra_fields_group FROM #__k2_categories as c LEFT JOIN #__groups AS g ON g.id = c.access LEFT JOIN #__k2_extra_fields_groups AS exfg ON exfg.id = c.extraFieldsGroup WHERE c.id>0";
     if (!$filter_trash) {
         $query .= " AND c.trash=0";
     }
     if ($search) {
         $escaped = K2_JVERSION == '15' ? $db->getEscaped($search, true) : $db->escape($search, true);
         $query .= " AND LOWER( c.name ) LIKE " . $db->Quote('%' . $escaped . '%', false);
     }
     if ($filter_state > -1) {
         $query .= " AND c.published={$filter_state}";
     }
     if ($language) {
         $query .= " AND (c.language = " . $db->Quote($language) . " OR c.language = '*')";
     }
     if ($filter_category) {
         K2Model::addIncludePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models');
         $ItemlistModel = K2Model::getInstance('Itemlist', 'K2Model');
         $tree = $ItemlistModel->getCategoryTree($filter_category);
         $query .= " AND c.id IN (" . implode(',', $tree) . ")";
     }
     $query .= " ORDER BY {$filter_order} {$filter_order_Dir}";
     if (K2_JVERSION != '15') {
         $query = JString::str_ireplace('#__groups', '#__viewlevels', $query);
         $query = JString::str_ireplace('g.name AS groupname', 'g.title AS groupname', $query);
     }
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     if (K2_JVERSION != '15') {
         foreach ($rows as $row) {
             $row->parent_id = $row->parent;
             $row->title = $row->name;
         }
     }
     $categories = array();
     if ($search) {
         foreach ($rows as $row) {
             $row->treename = $row->name;
             $categories[] = $row;
         }
     } else {
         if ($filter_category) {
             $db->setQuery('SELECT parent FROM #__k2_categories WHERE id = ' . $filter_category);
             $root = $db->loadResult();
         } else {
             $root = 0;
         }
         $categories = $this->indentRows($rows, $root);
     }
     if (isset($categories)) {
         $total = count($categories);
     } else {
         $total = 0;
     }
     jimport('joomla.html.pagination');
     $pageNav = new JPagination($total, $limitstart, $limit);
     $categories = @array_slice($categories, $pageNav->limitstart, $pageNav->limit);
     foreach ($categories as $category) {
         $category->parameters = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params);
         if ($category->parameters->get('inheritFrom')) {
             $db->setQuery("SELECT name FROM #__k2_categories WHERE id = " . (int) $category->parameters->get('inheritFrom'));
             $category->inheritFrom = $db->loadResult();
         } else {
             $category->inheritFrom = '';
         }
     }
     return $categories;
 }
Example #16
0
File: route.php Project: emavro/k2
 public static function _findItem($needles)
 {
     $component = JComponentHelper::getComponent('com_k2');
     $application = JFactory::getApplication();
     $menus = $application->getMenu('site', array());
     if (K2_JVERSION != '15') {
         $items = $menus->getItems('component_id', $component->id);
     } else {
         $items = $menus->getItems('componentid', $component->id);
     }
     $match = null;
     foreach ($needles as $needle => $id) {
         if (count($items)) {
             foreach ($items as $item) {
                 // Detect multiple K2 categories link and set the generic K2 link ( if any )
                 if (@$item->query['view'] == 'itemlist' && @$item->query['task'] == '') {
                     if (!isset(self::$multipleCategoriesMapping[$item->id])) {
                         if (K2_JVERSION == '15') {
                             $menuparams = explode("\n", $item->params);
                             foreach ($menuparams as $param) {
                                 if (strpos($param, 'categories=') === 0) {
                                     $array = explode('categories=', $param);
                                     $item->K2Categories = explode('|', $array[1]);
                                 }
                             }
                             if (!isset($item->K2Categories)) {
                                 $item->K2Categories = array();
                             }
                         } else {
                             $menuparams = json_decode($item->params);
                             $item->K2Categories = isset($menuparams->categories) ? $menuparams->categories : array();
                         }
                         self::$multipleCategoriesMapping[$item->id] = $item->K2Categories;
                         if (count($item->K2Categories) === 0) {
                             self::$anyK2Link = $item;
                         }
                     }
                 }
                 if ($needle == 'user' || $needle == 'category') {
                     if (@$item->query['task'] == $needle && @$item->query['id'] == $id) {
                         $match = $item;
                         break;
                     }
                 } else {
                     if ($needle == 'tag') {
                         if (@$item->query['task'] == $needle && @$item->query['tag'] == $id) {
                             $match = $item;
                             break;
                         }
                     } else {
                         if (@$item->query['view'] == $needle && @$item->query['id'] == $id) {
                             $match = $item;
                             break;
                         }
                     }
                 }
                 if (!is_null($match)) {
                     break;
                 }
             }
             // Second pass [START]
             // Only for multiple categories links. Triggered only if we do not have find any match (link to direct category)
             if (is_null($match) && $needle == 'category') {
                 foreach ($items as $item) {
                     if (@$item->query['view'] == 'itemlist' && @$item->query['task'] == '') {
                         if (isset(self::$multipleCategoriesMapping[$item->id]) && is_array(self::$multipleCategoriesMapping[$item->id])) {
                             foreach (self::$multipleCategoriesMapping[$item->id] as $catid) {
                                 if ((int) $catid == $id) {
                                     $match = $item;
                                     break;
                                 }
                             }
                         }
                         if (!is_null($match)) {
                             break;
                         }
                     }
                 }
             }
             // Second pass [END]
         }
         if (!is_null($match)) {
             break;
         }
     }
     if (is_null($match)) {
         // Try to detect any parent category menu item....
         if ($needle == 'category') {
             if (is_null(self::$tree)) {
                 K2Model::addIncludePath(JPATH_SITE . '/components/com_k2/models');
                 $model = K2Model::getInstance('Itemlist', 'K2Model');
                 self::$model = $model;
                 self::$tree = $model->getCategoriesTree();
             }
             $parents = self::$model->getTreePath(self::$tree, $id);
             if (is_array($parents)) {
                 foreach ($parents as $categoryID) {
                     if ($categoryID != $id) {
                         $match = K2HelperRoute::_findItem(array('category' => $categoryID));
                         if (!is_null($match)) {
                             break;
                         }
                     }
                 }
             }
         }
         if (is_null($match) && !is_null(self::$anyK2Link)) {
             $match = self::$anyK2Link;
         }
     }
     return $match;
 }
Example #17
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);
 }
Example #18
0
 /**
  * K2 Search method
  * The sql must return the following fields that are used in a common display
  * routine: href, title, section, created, text, browsernav
  * @param string Target search string
  * @param string mathcing option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  * @param mixed  An array if the search it to be restricted to areas, null if search all
  */
 public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     // If K2 items are not enabled in this search operation return now
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return array();
         }
     }
     // Trim text. If it is empty return now
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     // Load K2 Model class
     require_once JPATH_ADMINISTRATOR . '/components/com_k2/models/model.php';
     // Add include path
     K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models');
     // Search items
     $model = K2Model::getInstance('Items');
     $model->setState('site', true);
     $model->setState('search', $text);
     $model->setState('search.mode', $phrase);
     switch ($ordering) {
         case 'oldest':
             $model->setState('sorting', 'created');
             break;
         case 'popular':
             $model->setState('sorting', 'hits.reverse');
             break;
         case 'alpha':
             $model->setState('sorting', 'title');
             break;
         case 'category':
             $model->setState('sorting', 'category');
             break;
         case 'newest':
             $model->setState('sorting', 'created.reverse');
             break;
         default:
             $model->setState('sorting', 'id.reverse');
             break;
     }
     $limit = $this->params->def('search_limit', 50);
     $model->setState('limit', $limit);
     $rows = $model->getRows();
     $results = array();
     foreach ($rows as $item) {
         $item->browsernav = '';
         $item->section = $item->category->name;
         $item->href = $item->link;
         $item->text = $item->introtext . ' ' . $item->fulltext;
         $item->extra_fields_search = '';
         foreach ($item->extraFieldsGroups as $extraFieldGroup) {
             foreach ($extraFieldGroup->fields as $field) {
                 $item->extra_fields_search .= $field->output . ' ';
             }
         }
         $item->tags_search = '';
         foreach ($item->tags as $tag) {
             $item->tags_search .= $tag->name . ' ';
         }
         if (SearchHelper::checkNoHTML($item, $text, array('title', 'introtext', 'fulltext', 'extra_fields_search', 'tags_search'))) {
             $results[] = $item;
         }
     }
     return $results;
 }
Example #19
0
File: k2.php Project: emavro/k2
    function onAfterInitialise()
    {
        // Determine Joomla! version
        if (version_compare(JVERSION, '3.0', 'ge')) {
            define('K2_JVERSION', '30');
        } else {
            if (version_compare(JVERSION, '2.5', 'ge')) {
                define('K2_JVERSION', '25');
            } else {
                define('K2_JVERSION', '15');
            }
        }
        // Define the DS constant under Joomla! 3.0
        if (!defined('DS')) {
            define('DS', DIRECTORY_SEPARATOR);
        }
        // Import Joomla! classes
        jimport('joomla.filesystem.file');
        jimport('joomla.filesystem.folder');
        jimport('joomla.application.component.controller');
        jimport('joomla.application.component.model');
        jimport('joomla.application.component.view');
        // Get application
        $mainframe = JFactory::getApplication();
        // Load the K2 classes
        JLoader::register('K2Table', JPATH_ADMINISTRATOR . '/components/com_k2/tables/table.php');
        JLoader::register('K2Controller', JPATH_BASE . '/components/com_k2/controllers/controller.php');
        JLoader::register('K2Model', JPATH_ADMINISTRATOR . '/components/com_k2/models/model.php');
        if ($mainframe->isSite()) {
            K2Model::addIncludePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models');
        } else {
            // Fix warning under Joomla! 1.5 caused by conflict in model names
            if (K2_JVERSION != '15' || K2_JVERSION == '15' && JRequest::getCmd('option') != 'com_users') {
                K2Model::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'models');
            }
        }
        JLoader::register('K2View', JPATH_ADMINISTRATOR . '/components/com_k2/views/view.php');
        JLoader::register('K2HelperHTML', JPATH_ADMINISTRATOR . '/components/com_k2/helpers/html.php');
        // Community Builder integration
        $componentParams = JComponentHelper::getParams('com_k2');
        if ($componentParams->get('cbIntegration') && JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_comprofiler' . DS . 'plugin.foundation.php')) {
            define('K2_CB', true);
            global $_CB_framework;
            require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_comprofiler' . DS . 'plugin.foundation.php';
            cbimport('cb.html');
            cbimport('language.front');
        } else {
            define('K2_CB', false);
        }
        // Define the default Itemid for users and tags. Defined here instead of the K2HelperRoute for performance reasons.
        // UPDATE : Removed. All K2 links without Itemid now use the anyK2Link defined in the router helper.
        // define('K2_USERS_ITEMID', $componentParams->get('defaultUsersItemid'));
        // define('K2_TAGS_ITEMID', $componentParams->get('defaultTagsItemid'));
        // Define JoomFish compatibility version.
        if (JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'joomfish.php')) {
            if (K2_JVERSION == '15') {
                $db = JFactory::getDBO();
                $config = JFactory::getConfig();
                $prefix = $config->getValue('config.dbprefix');
                if (array_key_exists($prefix . '_jf_languages_ext', $db->getTableList())) {
                    define('K2_JF_ID', 'lang_id');
                } else {
                    define('K2_JF_ID', 'id');
                }
            } else {
                define('K2_JF_ID', 'lang_id');
            }
        }
        /*
        if(JRequest::getCmd('option')=='com_k2' && JRequest::getCmd('task')=='save' && !$mainframe->isAdmin()){
        	$dispatcher = JDispatcher::getInstance();
        	foreach($dispatcher->_observers as $observer){
        		if($observer->_name=='jfdatabase' || $observer->_name=='jfrouter' || $observer->_name=='missing_translation'){
        			$dispatcher->detach($observer);
        		}
        	}
        }
        */
        // Use K2 to make Joomla! Varnish-friendly
        // For more checkout: https://snipt.net/fevangelou/the-perfect-varnish-configuration-for-joomla-websites/
        $user = JFactory::getUser();
        if (!$user->guest) {
            JResponse::setHeader('X-Logged-In', 'True', true);
        } else {
            JResponse::setHeader('X-Logged-In', 'False', true);
        }
        if (!$mainframe->isAdmin()) {
            return;
        }
        $option = JRequest::getCmd('option');
        $task = JRequest::getCmd('task');
        $type = JRequest::getCmd('catid');
        if ($option != 'com_joomfish') {
            return;
        }
        if (!JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'JSON.php')) {
            return;
        }
        JPlugin::loadLanguage('com_k2', JPATH_ADMINISTRATOR);
        JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'tables');
        require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'JSON.php';
        // Joom!Fish
        if ($option == 'com_joomfish' && ($task == 'translate.apply' || $task == 'translate.save') && $type == 'k2_items') {
            $language_id = JRequest::getInt('select_language_id');
            $reference_id = JRequest::getInt('reference_id');
            $objects = array();
            $variables = JRequest::get('post');
            foreach ($variables as $key => $value) {
                if ((bool) JString::stristr($key, 'K2ExtraField_')) {
                    $object = new JObject();
                    $object->set('id', JString::substr($key, 13));
                    $object->set('value', $value);
                    unset($object->_errors);
                    $objects[] = $object;
                }
            }
            $json = new Services_JSON();
            $extra_fields = $json->encode($objects);
            $extra_fields_search = '';
            foreach ($objects as $object) {
                $extra_fields_search .= $this->getSearchValue($object->id, $object->value);
                $extra_fields_search .= ' ';
            }
            $user = JFactory::getUser();
            $db = JFactory::getDBO();
            $query = "SELECT COUNT(*) FROM #__jf_content WHERE reference_field = 'extra_fields' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_items'";
            $db->setQuery($query);
            $result = $db->loadResult();
            if ($result > 0) {
                $query = "UPDATE #__jf_content SET value=" . $db->Quote($extra_fields) . " WHERE reference_field = 'extra_fields' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_items'";
                $db->setQuery($query);
                $db->query();
            } else {
                $modified = date("Y-m-d H:i:s");
                $modified_by = $user->id;
                $published = JRequest::getVar('published', 0);
                $query = "INSERT INTO #__jf_content (`id`, `language_id`, `reference_id`, `reference_table`, `reference_field` ,`value`, `original_value`, `original_text`, `modified`, `modified_by`, `published`) VALUES (NULL, {$language_id}, {$reference_id}, 'k2_items', 'extra_fields', " . $db->Quote($extra_fields) . ", '','', " . $db->Quote($modified) . ", {$modified_by}, {$published} )";
                $db->setQuery($query);
                $db->query();
            }
            $query = "SELECT COUNT(*) FROM #__jf_content WHERE reference_field = 'extra_fields_search' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_items'";
            $db->setQuery($query);
            $result = $db->loadResult();
            if ($result > 0) {
                $query = "UPDATE #__jf_content SET value=" . $db->Quote($extra_fields_search) . " WHERE reference_field = 'extra_fields_search' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_items'";
                $db->setQuery($query);
                $db->query();
            } else {
                $modified = date("Y-m-d H:i:s");
                $modified_by = $user->id;
                $published = JRequest::getVar('published', 0);
                $query = "INSERT INTO #__jf_content (`id`, `language_id`, `reference_id`, `reference_table`, `reference_field` ,`value`, `original_value`, `original_text`, `modified`, `modified_by`, `published`) VALUES (NULL, {$language_id}, {$reference_id}, 'k2_items', 'extra_fields_search', " . $db->Quote($extra_fields_search) . ", '','', " . $db->Quote($modified) . ", {$modified_by}, {$published} )";
                $db->setQuery($query);
                $db->query();
            }
        }
        if ($option == 'com_joomfish' && ($task == 'translate.edit' || $task == 'translate.apply') && $type == 'k2_items') {
            if ($task == 'translate.edit') {
                $cid = JRequest::getVar('cid');
                $array = explode('|', $cid[0]);
                $reference_id = $array[1];
            }
            if ($task == 'translate.apply') {
                $reference_id = JRequest::getInt('reference_id');
            }
            $item = JTable::getInstance('K2Item', 'Table');
            $item->load($reference_id);
            $category_id = $item->catid;
            $language_id = JRequest::getInt('select_language_id');
            $category = JTable::getInstance('K2Category', 'Table');
            $category->load($category_id);
            $group = $category->extraFieldsGroup;
            $db = JFactory::getDBO();
            $query = "SELECT * FROM #__k2_extra_fields WHERE `group`=" . $db->Quote($group) . " AND published=1 ORDER BY ordering";
            $db->setQuery($query);
            $extraFields = $db->loadObjectList();
            $json = new Services_JSON();
            $output = '';
            if (count($extraFields)) {
                $output .= '<h1>' . JText::_('K2_EXTRA_FIELDS') . '</h1>';
                $output .= '<h2>' . JText::_('K2_ORIGINAL') . '</h2>';
                foreach ($extraFields as $extrafield) {
                    $extraField = $json->decode($extrafield->value);
                    $output .= trim($this->renderOriginal($extrafield, $reference_id));
                }
            }
            if (count($extraFields)) {
                $output .= '<h2>' . JText::_('K2_TRANSLATION') . '</h2>';
                foreach ($extraFields as $extrafield) {
                    $extraField = $json->decode($extrafield->value);
                    $output .= trim($this->renderTranslated($extrafield, $reference_id));
                }
            }
            $pattern = '/\\r\\n|\\r|\\n/';
            // *** Mootools Snippet ***
            $js = "\n\t\t\twindow.addEvent('domready', function(){\n\t\t\t\tvar target = \$\$('table.adminform');\n\t\t\t\ttarget.setProperty('id', 'adminform');\n\t\t\t\tvar div = new Element('div', {'id': 'K2ExtraFields'}).setHTML('" . preg_replace($pattern, '', $output) . "').injectInside(\$('adminform'));\n\t\t\t});\n\t\t\t";
            if (K2_JVERSION == '15') {
                JHTML::_('behavior.mootools');
            } else {
                JHTML::_('behavior.framework');
            }
            $document = JFactory::getDocument();
            $document->addScriptDeclaration($js);
            // *** Embedded CSS Snippet ***
            $document->addCustomTag('
			<style type="text/css" media="all">
				#K2ExtraFields { color:#000; font-size:11px; padding:6px 2px 4px 4px; text-align:left; }
				#K2ExtraFields h1 { font-size:16px; height:25px; }
				#K2ExtraFields h2 { font-size:14px; }
				#K2ExtraFields strong { font-style:italic; }
			</style>
			');
        }
        if ($option == 'com_joomfish' && ($task == 'translate.apply' || $task == 'translate.save') && $type == 'k2_extra_fields') {
            $language_id = JRequest::getInt('select_language_id');
            $reference_id = JRequest::getInt('reference_id');
            $extraFieldType = JRequest::getVar('extraFieldType');
            $objects = array();
            $values = JRequest::getVar('option_value');
            $names = JRequest::getVar('option_name');
            $target = JRequest::getVar('option_target');
            for ($i = 0; $i < sizeof($values); $i++) {
                $object = new JObject();
                $object->set('name', $names[$i]);
                if ($extraFieldType == 'select' || $extraFieldType == 'multipleSelect' || $extraFieldType == 'radio') {
                    $object->set('value', $i + 1);
                } elseif ($extraFieldType == 'link') {
                    if (substr($values[$i], 0, 7) == 'http://') {
                        $values[$i] = $values[$i];
                    } else {
                        $values[$i] = 'http://' . $values[$i];
                    }
                    $object->set('value', $values[$i]);
                } else {
                    $object->set('value', $values[$i]);
                }
                $object->set('target', $target[$i]);
                unset($object->_errors);
                $objects[] = $object;
            }
            $json = new Services_JSON();
            $value = $json->encode($objects);
            $user = JFactory::getUser();
            $db = JFactory::getDBO();
            $query = "SELECT COUNT(*) FROM #__jf_content WHERE reference_field = 'value' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_extra_fields'";
            $db->setQuery($query);
            $result = $db->loadResult();
            if ($result > 0) {
                $query = "UPDATE #__jf_content SET value=" . $db->Quote($value) . " WHERE reference_field = 'value' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_extra_fields'";
                $db->setQuery($query);
                $db->query();
            } else {
                $modified = date("Y-m-d H:i:s");
                $modified_by = $user->id;
                $published = JRequest::getVar('published', 0);
                $query = "INSERT INTO #__jf_content (`id`, `language_id`, `reference_id`, `reference_table`, `reference_field` ,`value`, `original_value`, `original_text`, `modified`, `modified_by`, `published`) VALUES (NULL, {$language_id}, {$reference_id}, 'k2_extra_fields', 'value', " . $db->Quote($value) . ", '','', " . $db->Quote($modified) . ", {$modified_by}, {$published} )";
                $db->setQuery($query);
                $db->query();
            }
        }
        if ($option == 'com_joomfish' && ($task == 'translate.edit' || $task == 'translate.apply') && $type == 'k2_extra_fields') {
            if ($task == 'translate.edit') {
                $cid = JRequest::getVar('cid');
                $array = explode('|', $cid[0]);
                $reference_id = $array[1];
            }
            if ($task == 'translate.apply') {
                $reference_id = JRequest::getInt('reference_id');
            }
            $extraField = JTable::getInstance('K2ExtraField', 'Table');
            $extraField->load($reference_id);
            $language_id = JRequest::getInt('select_language_id');
            if ($extraField->type == 'multipleSelect' || $extraField->type == 'select' || $extraField->type == 'radio') {
                $subheader = '<strong>' . JText::_('K2_OPTIONS') . '</strong>';
            } else {
                $subheader = '<strong>' . JText::_('K2_DEFAULT_VALUE') . '</strong>';
            }
            $json = new Services_JSON();
            $objects = $json->decode($extraField->value);
            $output = '<input type="hidden" value="' . $extraField->type . '" name="extraFieldType" />';
            if (count($objects)) {
                $output .= '<h1>' . JText::_('K2_EXTRA_FIELDS') . '</h1>';
                $output .= '<h2>' . JText::_('K2_ORIGINAL') . '</h2>';
                $output .= $subheader . '<br />';
                foreach ($objects as $object) {
                    $output .= '<p>' . $object->name . '</p>';
                    if ($extraField->type == 'textfield' || $extraField->type == 'textarea') {
                        $output .= '<p>' . $object->value . '</p>';
                    }
                }
            }
            $db = JFactory::getDBO();
            $query = "SELECT `value` FROM #__jf_content WHERE reference_field = 'value' AND language_id = {$language_id} AND reference_id = {$reference_id} AND reference_table='k2_extra_fields'";
            $db->setQuery($query);
            $result = $db->loadResult();
            $translatedObjects = $json->decode($result);
            if (count($objects)) {
                $output .= '<h2>' . JText::_('K2_TRANSLATION') . '</h2>';
                $output .= $subheader . '<br />';
                foreach ($objects as $key => $value) {
                    if (isset($translatedObjects[$key])) {
                        $value = $translatedObjects[$key];
                    }
                    if ($extraField->type == 'textarea') {
                        $output .= '<p><textarea name="option_name[]" cols="30" rows="15"> ' . $value->name . '</textarea></p>';
                    } else {
                        $output .= '<p><input type="text" name="option_name[]" value="' . $value->name . '" /></p>';
                    }
                    $output .= '<p><input type="hidden" name="option_value[]" value="' . $value->value . '" /></p>';
                    $output .= '<p><input type="hidden" name="option_target[]" value="' . $value->target . '" /></p>';
                }
            }
            $pattern = '/\\r\\n|\\r|\\n/';
            // *** Mootools Snippet ***
            $js = "\n\t\t\twindow.addEvent('domready', function(){\n\t\t\t\tvar target = \$\$('table.adminform');\n\t\t\t\ttarget.setProperty('id', 'adminform');\n\t\t\t\tvar div = new Element('div', {'id': 'K2ExtraFields'}).setHTML('" . preg_replace($pattern, '', $output) . "').injectInside(\$('adminform'));\n\t\t\t});\n\t\t\t";
            JHTML::_('behavior.mootools');
            $document = JFactory::getDocument();
            $document->addScriptDeclaration($js);
        }
        return;
    }
Example #20
0
 public function jsnGetData($attributes)
 {
     $mainframe = JFactory::getApplication();
     $params = JComponentHelper::getParams('com_k2');
     $option = JRequest::getCmd('option');
     $view = JRequest::getCmd('view');
     $db = JFactory::getDBO();
     $filter_trash = $mainframe->getUserStateFromRequest($option . $view . 'filter_trash', 'filter_trash', 0, 'int');
     $filter_featured = $mainframe->getUserStateFromRequest($option . $view . 'filter_featured', 'filter_featured', -1, 'int');
     $search = $mainframe->getUserStateFromRequest($option . $view . 'search', 'search', '', 'string');
     $search = JString::strtolower($search);
     $tag = $mainframe->getUserStateFromRequest($option . $view . 'tag', 'tag', 0, 'int');
     $language = $mainframe->getUserStateFromRequest($option . $view . 'language', 'language', '', 'string');
     // JSNPagebuilder Custom
     // Published items only
     $filter_state = $mainframe->getUserStateFromRequest($option . $view . 'filter_state', 'filter_state', 1, 'int');
     $limit = isset($attributes['articlelist_amount']) ? $attributes['articlelist_amount'] : 5;
     $limitStart = 0;
     $filter_order = $attributes['articlelist_sort_by'] != JSNPbArticleListHelper::PB_ARTICLE_SORT_BY_FP_ORDERING ? $attributes['articlelist_sort_by'] : JSNPbArticleListHelper::PB_ARTICLE_SORT_BY_ID;
     $filter_order_Dir = $attributes['articlelist_sort_order'];
     $filter_category = isset($attributes['articlelist_filter_k2_categories']) ? explode(",", $attributes['articlelist_filter_k2_categories']) : false;
     $filter_author = isset($attributes['articlelist_filter_k2_authors']) ? explode(",", $attributes['articlelist_filter_k2_authors']) : false;
     $dateFiltering = $attributes['articlelist_filter_date'];
     $dateField = $attributes['articlelist_date_field'];
     $startDateRange = isset($attributes['articlelist_range_date_start']) ? JFactory::getDate($attributes['articlelist_range_date_start'])->toSql() : '';
     $endDateRange = isset($attributes['articlelist_range_date_end']) ? JFactory::getDate($attributes['articlelist_range_date_end'])->toSql() : '';
     $relativeDate = isset($attributes['articlelist_relative_date']) ? (int) $attributes['articlelist_relative_date'] : 30;
     $query = "SELECT a.*, g.name AS groupname, c.name AS category, v.name AS author, w.name as moderator, u.name AS editor FROM #__k2_items as a";
     $query .= " LEFT JOIN #__groups AS g ON g.id = a.access" . " LEFT JOIN #__users AS u ON u.id = a.checked_out" . " LEFT JOIN #__users AS v ON v.id = a.created_by" . " LEFT JOIN #__users AS w ON w.id = a.modified_by";
     if ($params->get('showTagFilter') && $tag) {
         $query .= " LEFT JOIN #__k2_tags_xref AS tags_xref ON tags_xref.itemID = a.id";
     }
     $query .= " JOIN #__k2_categories AS c ON c.id = a.catid AND c.published = 1";
     $query .= " WHERE a.trash={$filter_trash}";
     if ($search) {
         $escaped = K2_JVERSION == '15' ? $db->getEscaped($search, true) : $db->escape($search, true);
         $quoted = $db->Quote('%' . $escaped . '%', false);
         if ($params->get('adminSearch') == 'full') {
             $query .= " AND ( LOWER(a.title) LIKE " . $quoted . " OR LOWER(a.introtext) LIKE " . $quoted . " OR LOWER(a.`fulltext`) LIKE " . $quoted . " OR LOWER(a.extra_fields_search) LIKE " . $quoted . " OR LOWER(a.image_caption) LIKE " . $quoted . " OR LOWER(a.image_credits) LIKE " . $quoted . " OR LOWER(a.video_caption) LIKE " . $quoted . " OR LOWER(a.video_credits) LIKE " . $quoted . " OR LOWER(a.metadesc) LIKE " . $quoted . " OR LOWER(a.metakey) LIKE " . $quoted . ") ";
         } else {
             $query .= " AND LOWER(a.title) LIKE " . $quoted;
         }
     }
     if ($filter_state > -1) {
         $query .= " AND a.published={$filter_state}";
     }
     if ($filter_featured > -1) {
         $query .= " AND a.featured={$filter_featured}";
     }
     if ($filter_category) {
         if ($params->get('showChildCatItems')) {
             K2Model::addIncludePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models');
             $itemListModel = K2Model::getInstance('Itemlist', 'K2Model');
             $categories = $itemListModel->getCategoryTree($filter_category);
             $sql = @implode(',', $categories);
             $query .= " AND a.catid IN ({$sql})";
         } else {
             $query .= " AND a.catid={$filter_category}";
         }
     } else {
         $query .= " AND a.catid = '' ";
     }
     if ($filter_author) {
         $query .= " AND a.created_by IN (" . implode(',', $filter_author) . ")";
     }
     if ($params->get('showTagFilter') && $tag) {
         $query .= " AND tags_xref.tagID = {$tag}";
     }
     if ($language) {
         $query .= " AND (a.language = " . $db->Quote($language) . " OR a.language = '*')";
     }
     $nullDate = $db->quote($db->getNullDate());
     $nowDate = $db->quote(JFactory::getDate()->toSql());
     switch ($dateFiltering) {
         case 'range':
             $startDateRange = $startDateRange ? $db->quote($startDateRange) : $nullDate;
             $endDateRange = $endDateRange ? $db->quote($endDateRange) : $nowDate;
             $query .= ' AND (' . $dateField . ' >= DATE(' . $startDateRange . ') AND DATE(' . $dateField . ') <= DATE(' . $endDateRange . '))';
             break;
         case 'relative':
             $query .= ' AND ' . $dateField . ' >= DATE(DATE_SUB(' . $nowDate . ', INTERVAL ' . $relativeDate . ' DAY))';
             break;
         case 'off':
         default:
             break;
     }
     $query .= " ORDER BY {$filter_order} {$filter_order_Dir} ";
     if (K2_JVERSION != '15') {
         $query = JString::str_ireplace('#__groups', '#__viewlevels', $query);
         $query = JString::str_ireplace('g.name', 'g.title', $query);
     }
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('k2');
     $dispatcher->trigger('onK2BeforeSetQuery', array(&$query));
     $db->setQuery($query, $limitStart, $limit);
     return $db->loadAssocList('id');
 }
Example #21
0
 public function getLatest($limit = 10, $exclude = null)
 {
     K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models');
     $model = K2Model::getInstance('Items');
     $model->setState('site', true);
     $model->setState('author', $this->id);
     $model->setState('ordering', 'created');
     if ($exclude) {
         $model->setState('exclude', $exclude);
     }
     $model->setState('limit', $limit);
     $model->setState('limitstart', 0);
     $rows = $model->getRows();
     return $rows;
 }
Example #22
0
 function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     $user = JFactory::getUser();
     $option = JRequest::getCmd('option');
     $view = JRequest::getCmd('view');
     $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
     $limitstart = $mainframe->getUserStateFromRequest($option . $view . '.limitstart', 'limitstart', 0, 'int');
     $filter_order = $mainframe->getUserStateFromRequest($option . $view . 'filter_order', 'filter_order', 'c.id', 'cmd');
     $filter_order_Dir = $mainframe->getUserStateFromRequest($option . $view . 'filter_order_Dir', 'filter_order_Dir', 'DESC', 'word');
     $filter_state = $mainframe->getUserStateFromRequest($option . $view . 'filter_state', 'filter_state', -1, 'int');
     $filter_category = $mainframe->getUserStateFromRequest($option . $view . 'filter_category', 'filter_category', 0, 'int');
     $filter_author = $mainframe->getUserStateFromRequest($option . $view . 'filter_author', 'filter_author', 0, 'int');
     $search = $mainframe->getUserStateFromRequest($option . $view . 'search', 'search', '', 'string');
     $search = JString::strtolower($search);
     if ($mainframe->isSite()) {
         $filter_author = $user->id;
         JRequest::setVar('filter_author', $user->id);
     }
     $this->loadHelper('html');
     K2Model::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models');
     $model = K2Model::getInstance('Comments', 'K2Model');
     $params = JComponentHelper::getParams('com_k2');
     $total = $model->getTotal();
     if ($limitstart > $total - $limit) {
         $limitstart = max(0, (int) (ceil($total / $limit) - 1) * $limit);
         JRequest::setVar('limitstart', $limitstart);
     }
     $comments = $model->getData();
     $reportLink = $mainframe->isAdmin() ? 'index.php?option=com_k2&view=user&task=report&id=' : 'index.php?option=com_k2&view=comments&task=reportSpammer&id=';
     foreach ($comments as $key => $comment) {
         $comment->reportUserLink = false;
         $comment->commenterLastVisitIP = NULL;
         if ($comment->userID) {
             $db = JFactory::getDBO();
             $db->setQuery("SELECT ip FROM #__k2_users WHERE userID = " . $comment->userID);
             $comment->commenterLastVisitIP = $db->loadResult();
             $commenter = JFactory::getUser($comment->userID);
             if ($commenter->name) {
                 $comment->userName = $commenter->name;
             }
             if ($mainframe->isSite()) {
                 if (K2_JVERSION != '15') {
                     if ($user->authorise('core.admin', 'com_k2')) {
                         $comment->reportUserLink = JRoute::_($reportLink . $comment->userID);
                     }
                 } else {
                     if ($user->gid > 24) {
                         $comment->reportUserLink = JRoute::_($reportLink . $comment->userID);
                     }
                 }
             } else {
                 $comment->reportUserLink = JRoute::_($reportLink . $comment->userID);
             }
         }
         if ($mainframe->isSite()) {
             $comment->status = K2HelperHTML::stateToggler($comment, $key);
         } else {
             $comment->status = K2_JVERSION == '15' ? JHTML::_('grid.published', $comment, $key) : JHtml::_('jgrid.published', $comment->published, $key);
         }
     }
     $this->assignRef('rows', $comments);
     jimport('joomla.html.pagination');
     $pageNav = new JPagination($total, $limitstart, $limit);
     $this->assignRef('page', $pageNav);
     $lists = array();
     $lists['search'] = $search;
     $lists['order_Dir'] = $filter_order_Dir;
     $lists['order'] = $filter_order;
     $filter_state_options[] = JHTML::_('select.option', -1, JText::_('K2_SELECT_STATE'));
     $filter_state_options[] = JHTML::_('select.option', 1, JText::_('K2_PUBLISHED'));
     $filter_state_options[] = JHTML::_('select.option', 0, JText::_('K2_UNPUBLISHED'));
     $lists['state'] = JHTML::_('select.genericlist', $filter_state_options, 'filter_state', '', 'value', 'text', $filter_state);
     $categoriesModel = K2Model::getInstance('Categories', 'K2Model');
     $categories_option[] = JHTML::_('select.option', 0, JText::_('K2_SELECT_CATEGORY'));
     $categories = $categoriesModel->categoriesTree(null, true, false);
     $categories_options = @array_merge($categories_option, $categories);
     $lists['categories'] = JHTML::_('select.genericlist', $categories_options, 'filter_category', '', 'value', 'text', $filter_category);
     $lists['authors'] = JHTML::_('list.users', 'filter_author', $filter_author, true, '');
     $this->assignRef('lists', $lists);
     $this->assignRef('mainframe', $mainframe);
     if (K2_JVERSION != '15') {
         $dateFormat = JText::_('K2_J16_DATE_FORMAT');
     } else {
         $dateFormat = JText::_('K2_DATE_FORMAT');
     }
     $this->assignRef('dateFormat', $dateFormat);
     if ($mainframe->isAdmin()) {
         JToolBarHelper::title(JText::_('K2_COMMENTS'), 'k2.png');
         JToolBarHelper::publishList();
         JToolBarHelper::unpublishList();
         JToolBarHelper::deleteList('', 'remove', 'K2_DELETE');
         JToolBarHelper::custom('deleteUnpublished', 'delete', 'delete', 'K2_DELETE_ALL_UNPUBLISHED', false);
         $toolbar = JToolBar::getInstance('toolbar');
         if (K2_JVERSION != '15') {
             JToolBarHelper::preferences('com_k2', 550, 875, 'K2_PARAMETERS');
         } else {
             $toolbar->appendButton('Popup', 'config', 'Parameters', 'index.php?option=com_k2&view=settings');
         }
         K2HelperHTML::subMenu();
         if (K2_JVERSION != '15') {
             $userEditLink = JURI::base() . 'index.php?option=com_k2&view=user&cid=';
         } else {
             $userEditLink = JURI::base() . 'index.php?option=com_k2&view=user&cid=';
         }
         $this->assignRef('userEditLink', $userEditLink);
     }
     $document = JFactory::getDocument();
     $document->addScriptDeclaration('var K2Language = ["' . JText::_('K2_YOU_CANNOT_EDIT_TWO_COMMENTS_AT_THE_SAME_TIME', true) . '", "' . JText::_('K2_THIS_WILL_PERMANENTLY_DELETE_ALL_UNPUBLISHED_COMMENTS_ARE_YOU_SURE', true) . '", "' . JText::_('K2_REPORT_USER_WARNING', true) . '"];');
     if ($mainframe->isSite()) {
         // CSS
         $document->addStyleSheet(JURI::root(true) . '/media/k2/assets/css/k2.frontend.css?v=2.6.2');
         $document->addStyleSheet(JURI::root(true) . '/templates/system/css/general.css');
         $document->addStyleSheet(JURI::root(true) . '/templates/system/css/system.css');
         if (K2_JVERSION != '15') {
             $document->addStyleSheet(JURI::root(true) . '/administrator/templates/bluestork/css/template.css');
             $document->addStyleSheet(JURI::root(true) . '/media/system/css/system.css');
         } else {
             $document->addStyleSheet(JURI::root(true) . '/administrator/templates/khepri/css/general.css');
         }
     }
     parent::display($tpl);
 }
Example #23
0
 function trash()
 {
     $mainframe = JFactory::getApplication();
     $db = JFactory::getDBO();
     $cid = JRequest::getVar('cid');
     $row = JTable::getInstance('K2Category', 'Table');
     JArrayHelper::toInteger($cid);
     K2Model::addIncludePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models');
     $model = K2Model::getInstance('Itemlist', 'K2Model');
     $categories = $model->getCategoryTree($cid);
     $sql = @implode(',', $categories);
     $db = JFactory::getDBO();
     $query = "UPDATE #__k2_categories SET trash=1  WHERE id IN ({$sql})";
     $db->setQuery($query);
     $db->query();
     $query = "UPDATE #__k2_items SET trash=1  WHERE catid IN ({$sql})";
     $db->setQuery($query);
     $db->query();
     $cache = JFactory::getCache('com_k2');
     $cache->clean();
     $mainframe->redirect('index.php?option=com_k2&view=categories', JText::_('K2_CATEGORIES_MOVED_TO_TRASH'));
 }
Example #24
0
 public function display($tpl = null)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get input
     $input = $application->input;
     $id = $input->get('id', 0, 'int');
     $hash = $input->get('hash', '', 'string');
     // Both input fields are required
     if (!$id || empty($hash)) {
         throw new Exception(JText::_('K2_NOT_FOUND'), 404);
     }
     // Check hash
     if (JApplication::getHash($id) != $hash) {
         throw new Exception(JText::_('K2_NOT_FOUND'), 404);
     }
     // Get model
     K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models');
     $model = K2Model::getInstance('Attachments', 'K2Model');
     // Get attachment
     $model->setState('id', $id);
     $attachment = $model->getRow();
     // Get item
     $model = K2Model::getInstance('Items', 'K2Model');
     $model->setState('id', $attachment->itemId);
     $item = $model->getRow();
     // If we are on front-end check access verify that user has the permission to download this attachment
     if ($application->isSite()) {
         $item->checkSiteAccess();
     }
     // Import K2 plugins
     JPluginHelper::importPlugin('k2');
     $dispatcher = JDispatcher::getInstance();
     // Trigger onK2BeforeDownload event
     $dispatcher->trigger('onK2BeforeDownload', array(&$attachment));
     // Params
     $params = JComponentHelper::getParams('com_k2');
     // Custom path flag
     $customPathFlag = $params->get('attachmentsFolder') && $params->get('filesystem') == 'Local' ? true : false;
     // File system
     $filesystem = $customPathFlag ? K2FileSystem::getInstance('Local', $params->get('attachmentsFolder')) : K2FileSystem::getInstance();
     // Path
     $path = $customPathFlag ? '' : 'media/k2/attachments';
     // Determine the key
     if ($attachment->file) {
         $key = $path . '/' . $attachment->itemId . '/' . $attachment->file;
     } else {
         if ($attachment->path) {
             $key = $attachment->path;
             // Since it is a path we need to enforce the local adapter for the file system
             $filesystem = K2FileSystem::getInstance('Local');
         }
     }
     // Check if file exists
     if (!$filesystem->has($key)) {
         throw new Exception(JText::_('K2_NOT_FOUND'), 404);
     }
     // Update downloads counter
     if ($application->isSite()) {
         $attachment->track();
     }
     // Trigger the onK2AfterDownload event
     $dispatcher->trigger('onK2AfterDownload', array(&$attachment));
     // Read the file
     $file = $filesystem->get($key);
     $size = $file->getSize();
     $content = $file->getContent();
     $filename = basename($key);
     $finfo = new finfo(FILEINFO_MIME);
     $mime = $finfo->buffer($content);
     ob_end_clean();
     $application->clearHeaders();
     $application->setHeader('Pragma', 'public', true);
     $application->setHeader('Expires', '0', true);
     $application->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
     $application->setHeader('Content-Type', $mime, true);
     $application->setHeader('Content-Disposition', 'attachment; filename=' . $filename . ';', true);
     $application->setHeader('Content-Transfer-Encoding', 'binary', true);
     $application->setHeader('Content-Length', $size, true);
     $application->sendHeaders();
     echo $content;
     $application->close();
 }