Beispiel #1
0
 function countCategoryItems($id)
 {
     $mainframe =& JFactory::getApplication();
     $user =& JFactory::getUser();
     $aid = (int) $user->get('aid');
     $id = (int) $id;
     $db =& JFactory::getDBO();
     $jnow =& JFactory::getDate();
     $now = $jnow->toMySQL();
     $nullDate = $db->getNullDate();
     $categories = K2ModelItemlist::getCategoryTree($id);
     $query = "SELECT COUNT(*) FROM #__k2_items WHERE catid IN (" . implode(',', $categories) . ") AND published=1 AND trash=0";
     if (K2_JVERSION == '16') {
         $query .= " AND access IN(" . implode(',', $user->authorisedLevels()) . ") ";
         if ($mainframe->getLanguageFilter()) {
             $query .= " AND language IN(" . $db->Quote(JFactory::getLanguage()->getTag()) . ", " . $db->Quote('*') . ")";
         }
     } else {
         $query .= " AND access<=" . $aid;
     }
     $query .= " AND ( publish_up = " . $db->Quote($nullDate) . " OR publish_up <= " . $db->Quote($now) . " )";
     $query .= " AND ( publish_down = " . $db->Quote($nullDate) . " OR publish_down >= " . $db->Quote($now) . " )";
     $db->setQuery($query);
     $total = $db->loadResult();
     return $total;
 }
Beispiel #2
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);
     $query = "SELECT COUNT(*) FROM #__k2_items WHERE trash={$filter_trash}";
     if ($search) {
         if ($params->get('adminSearch') == 'full') {
             $query .= " AND MATCH(title, introtext, `fulltext`, extra_fields_search, image_caption, image_credits, video_caption, video_credits, metadesc, metakey) AGAINST(" . $db->Quote($search) . ")";
         } else {
             $query .= " AND MATCH( title ) AGAINST(" . $db->Quote($search) . ")";
         }
     }
     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')) {
             require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
             $categories = K2ModelItemlist::getCategoryChilds($filter_category);
             $categories[] = $filter_category;
             $categories = @array_unique($categories);
             $sql = @implode(',', $categories);
             $query .= " AND catid IN ({$sql})";
         } else {
             $query .= " AND catid={$filter_category}";
         }
     }
     if ($filter_author > 0) {
         $query .= " AND created_by={$filter_author}";
     }
     $db->setQuery($query);
     $result = $db->loadResult();
     return $result;
 }
Beispiel #3
0
 /**
  * This function is copied from:
  * /administrator/components/com_k2/models/items.php method getData()
  * The only changes to the function is the select statement, only grabbing the data that is needed
  * also added check for database error.
  */
 function getData()
 {
     $mainframe =& JFactory::getApplication();
     $params =& JComponentHelper::getParams('com_k2');
     $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');
     $filter_order = $mainframe->getUserStateFromRequest($option . $view . 'filter_order', 'filter_order', 'i.id', 'cmd');
     $filter_order_Dir = $mainframe->getUserStateFromRequest($option . $view . 'filter_order_Dir', 'filter_order_Dir', 'DESC', 'word');
     $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 i.id, i.title, i.published, i.created, i.access, g.name AS groupname, c.name AS category, v.name AS author FROM #__k2_items as i";
     $query .= " LEFT JOIN #__k2_categories AS c ON c.id = i.catid" . " LEFT JOIN #__groups AS g ON g.id = i.access" . " LEFT JOIN #__users AS u ON u.id = i.checked_out" . " LEFT JOIN #__users AS v ON v.id = i.created_by" . " LEFT JOIN #__users AS w ON w.id = i.modified_by";
     if ($params->get('showTagFilter') && $tag) {
         $query .= " LEFT JOIN #__k2_tags_xref AS tags_xref ON tags_xref.itemID = i.id";
     }
     $query .= " WHERE i.trash={$filter_trash}";
     if ($search) {
         $search = JString::str_ireplace('*', '', $search);
         $words = explode(' ', $search);
         for ($i = 0; $i < count($words); $i++) {
             $words[$i] = '+' . $words[$i];
             $words[$i] .= '*';
         }
         $search = implode(' ', $words);
         $search = $db->Quote($db->getEscaped($search, true), false);
         if ($params->get('adminSearch') == 'full') {
             $query .= " AND MATCH(i.title, i.introtext, i.`fulltext`, i.extra_fields_search, i.image_caption,i.image_credits,i.video_caption,i.video_credits,i.metadesc,i.metakey)";
         } else {
             $query .= " AND MATCH( i.title )";
         }
         $query .= " AGAINST ({$search} IN BOOLEAN MODE)";
     }
     if ($filter_state > -1) {
         $query .= " AND i.published={$filter_state}";
     }
     if ($filter_featured > -1) {
         $query .= " AND i.featured={$filter_featured}";
     }
     if ($filter_category > 0) {
         if ($params->get('showChildCatItems')) {
             require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
             $categories = K2ModelItemlist::getCategoryTree($filter_category);
             $sql = @implode(',', $categories);
             $query .= " AND i.catid IN ({$sql})";
         } else {
             $query .= " AND i.catid={$filter_category}";
         }
     }
     if ($filter_author > 0) {
         $query .= " AND i.created_by={$filter_author}";
     }
     if ($params->get('showTagFilter') && $tag) {
         $query .= " AND tags_xref.tagID = {$tag}";
     }
     if ($language) {
         $query .= " AND i.language = " . $db->Quote($language);
     }
     if ($filter_order == 'i.ordering') {
         $query .= " ORDER BY i.catid, i.ordering {$filter_order_Dir}";
     } else {
         $query .= " ORDER BY {$filter_order} {$filter_order_Dir} ";
     }
     if (K2_JVERSION == '16') {
         $query = JString::str_ireplace('#__groups', '#__viewlevels', $query);
         $query = JString::str_ireplace('g.name', 'g.title', $query);
     }
     $db->setQuery($query, $limitstart, $limit);
     $rows = $db->loadObjectList();
     if ($db->getErrorNum()) {
         $this->setError($db->getErrorMsg());
         return false;
     }
     return $rows;
 }
Beispiel #4
0
 function countCategoryItems($id)
 {
     $user =& JFactory::getUser();
     $aid = (int) $user->get('aid');
     $id = (int) $id;
     $db =& JFactory::getDBO();
     $jnow =& JFactory::getDate();
     $now = $jnow->toMySQL();
     $nullDate = $db->getNullDate();
     $catIDs = array();
     $catIDs[] = $id;
     $categories = K2ModelItemlist::getCategoryChilds($id, true);
     foreach ($categories as $child) {
         $catIDs[] = $child;
     }
     $total = 0;
     JArrayHelper::toInteger($catIDs);
     foreach ($catIDs as $catid) {
         $query = "SELECT COUNT(*) FROM #__k2_items WHERE catid={$catid} AND published=1 AND trash=0 AND access<=" . $aid;
         $query .= " AND ( publish_up = " . $db->Quote($nullDate) . " OR publish_up <= " . $db->Quote($now) . " )";
         $query .= " AND ( publish_down = " . $db->Quote($nullDate) . " OR publish_down >= " . $db->Quote($now) . " )";
         $db->setQuery($query);
         $total += $db->loadResult();
     }
     return $total;
 }
Beispiel #5
0
 /**
  *
  * Get data K2 item
  * @param object $helper object from JAHelperPro
  * @param object $params
  * @return object $helper object include data of item K2
  */
 function getDatas(&$helper, $params)
 {
     if (!file_exists(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'route.php')) {
         return;
     }
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'route.php';
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'utilities.php';
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
     $getChildren = $params->get('getChildren', 1);
     $catsid = $params->get('k2catsid');
     if (!is_array($catsid)) {
         $arr_cats[] = $catsid;
     } else {
         $arr_cats = $catsid;
     }
     $moduleid = $helper->moduleid;
     if ($helper->get('maxSubCats', -1) == 0) {
         $arr_cats = array(-1);
     }
     foreach ($arr_cats as $catid) {
         $params_cat = new JRegistry('');
         $cooki_name = 'mod' . $moduleid . '_' . $catid;
         if (isset($_COOKIE[$cooki_name]) && $_COOKIE[$cooki_name] != '') {
             $cookie_user_setting = $_COOKIE[$cooki_name];
             $arr_values = explode('&', $cookie_user_setting);
             if ($arr_values) {
                 foreach ($arr_values as $row) {
                     list($k, $value) = explode('=', $row);
                     if ($k != '') {
                         $params_cat->set($k, $value);
                     }
                 }
             }
         }
         if (!$catid) {
             continue;
         }
         $_section = $this->getCategory($catid);
         $_categories = K2ModelItemlist::getCategoryFirstChildren($catid, 'order');
         if (!count($_section) && !count($_categories)) {
             return;
         }
         $_categories_org = $_categories;
         $cookie_catsid = array();
         if ($params_cat->get('cookie_catsid', '') != '') {
             $cookie_catsid = explode(',', $params_cat->get('cookie_catsid', ''));
             if ($_categories) {
                 $temp = array();
                 foreach ($_categories as $k => $cat) {
                     $cat->title = $cat->name;
                     if (in_array($cat->id, $cookie_catsid)) {
                         $temp[] = $_categories[$k];
                     }
                 }
                 $_categories = $temp;
             }
         }
         $cat_link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($_section->id . ':' . urlencode($_section->alias))));
         $cat_title = $_section->name;
         $cat_desc = $_section->description;
         if (count($_section) && count($_categories)) {
             foreach ($_categories as $k => $cat) {
                 $_categories[$k]->title = $_categories[$k]->name;
                 $_categories[$k]->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($cat->id . ':' . urlencode($cat->alias))));
             }
         }
         if ($helper->get('groupbysubcat', 0)) {
             $maxSubCats = $params_cat->get('maxSubCats', $helper->get('maxSubCats', -1));
             if ($maxSubCats == -1) {
                 $maxSubCats = count($_categories);
             }
             $temp = array();
             if ($_categories) {
                 $i = 0;
                 foreach ($_categories as $k => $cat) {
                     $catids = array();
                     $subcatids = array();
                     $catids[] = $cat->id;
                     if ($getChildren) {
                         if (JAK2HelperPro::hasK2Children($cat->id)) {
                             $subcatids = JAK2HelperPro::getK2CategoryChildren($cat->id, true);
                         }
                         $catids = array_merge($catids, $subcatids);
                     }
                     $rows = $this->getArticles(implode(',', $catids), $helper, $params_cat);
                     if ($rows) {
                         $temp[] = $cat;
                         $articles[$cat->id] = $rows;
                         $i++;
                         if ($i == $maxSubCats) {
                             break;
                         }
                     }
                 }
                 $_categories = $temp;
             }
         } else {
             $catids = array();
             $catids[] = $catid;
             if ($getChildren && count($_categories)) {
                 foreach ($_categories as $cat) {
                     $catids[] = $cat->id;
                     $subcatids = array();
                     if (JAK2HelperPro::hasK2Children($cat->id)) {
                         $subcatids = JAK2HelperPro::getK2CategoryChildren($cat->id);
                     }
                     $catids = array_merge($catids, $subcatids);
                 }
             }
             $articles = $this->getArticles(implode(',', $catids), $helper, $params_cat);
         }
         $helper->articles[$catid] = $articles;
         $helper->_section[$catid] = $_section;
         $helper->_categories[$catid] = $_categories;
         $helper->_categories_org[$catid] = $_categories_org;
         $helper->cat_link[$catid] = $cat_link;
         $helper->cat_title[$catid] = $cat_title;
         $helper->cat_desc[$catid] = $cat_desc;
     }
 }
Beispiel #6
0
 function trash()
 {
     $mainframe =& JFactory::getApplication();
     $db =& JFactory::getDBO();
     $cid = JRequest::getVar('cid');
     $row =& JTable::getInstance('K2Category', 'Table');
     JArrayHelper::toInteger($cid);
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
     $model = new K2ModelItemlist();
     $categories = $cid;
     foreach ($cid as $id) {
         $categories = @array_merge($categories, K2ModelItemlist::getCategoryChilds($id));
     }
     $categories = @array_unique($categories);
     JArrayHelper::toInteger($categories);
     $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::_('Categories moved to trash'));
 }
Beispiel #7
0
 function onAfterDispatch()
 {
     $mainframe =& JFactory::getApplication();
     if ($mainframe->isAdmin()) {
         return;
     }
     JPlugin::loadLanguage('com_k2');
     $params =& JComponentHelper::getParams('com_k2');
     if (!$params->get('K2UserProfile')) {
         return;
     }
     $option = JRequest::getCmd('option');
     $view = JRequest::getCmd('view');
     $task = JRequest::getCmd('task');
     $layout = JRequest::getCmd('layout');
     $user =& JFactory::getUser();
     if ($option == 'com_user' && $view == 'register') {
         if (!$user->guest) {
             $mainframe->redirect(JURI::root(), JText::_('You are already registered as a member.'), 'notice');
             $mainframe->close();
         }
         require_once JPATH_SITE . DS . 'components' . DS . 'com_user' . DS . 'controller.php';
         $controller = new UserController();
         $view = $controller->getView('register', 'html');
         $view->_addPath('template', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'templates');
         $view->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
         $view->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
         $view->setLayout('register');
         $K2User = new JObject();
         $K2User->description = '';
         $K2User->gender = 'm';
         $K2User->image = '';
         $K2User->url = '';
         $K2User->plugins = '';
         $wysiwyg =& JFactory::getEditor();
         $editor = $wysiwyg->display('description', $K2User->description, '100%', '250', '40', '5', false);
         $view->assignRef('editor', $editor);
         $lists = array();
         $genderOptions[] = JHTML::_('select.option', 'm', JText::_('Male'));
         $genderOptions[] = JHTML::_('select.option', 'f', JText::_('Female'));
         $lists['gender'] = JHTML::_('select.radiolist', $genderOptions, 'gender', '', 'value', 'text', $K2User->gender);
         $view->assignRef('lists', $lists);
         JPluginHelper::importPlugin('k2');
         $dispatcher =& JDispatcher::getInstance();
         $K2Plugins = $dispatcher->trigger('onRenderAdminForm', array(&$K2User, 'user'));
         $view->assignRef('K2Plugins', $K2Plugins);
         $view->assignRef('K2User', $K2User);
         $pathway =& $mainframe->getPathway();
         $pathway->setPathway(NULL);
         ob_start();
         $view->display();
         $contents = ob_get_clean();
         $document =& JFactory::getDocument();
         $document->setBuffer($contents, 'component');
     }
     if ($option == 'com_user' && $view == 'user' && ($task == 'edit' || $layout == 'form')) {
         require_once JPATH_SITE . DS . 'components' . DS . 'com_user' . DS . 'controller.php';
         $controller = new UserController();
         $view = $controller->getView('user', 'html');
         $view->_addPath('template', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'templates');
         $view->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
         $view->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
         $view->setLayout('profile');
         require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
         $model = new K2ModelItemlist();
         $K2User = $model->getUserProfile($user->id);
         if (!is_object($K2User)) {
             $K2User = new Jobject();
             $K2User->description = '';
             $K2User->gender = 'm';
             $K2User->url = '';
             $K2User->image = NULL;
         }
         $wysiwyg =& JFactory::getEditor();
         $editor = $wysiwyg->display('description', $K2User->description, '100%', '250', '40', '5', false);
         $view->assignRef('editor', $editor);
         $lists = array();
         $genderOptions[] = JHTML::_('select.option', 'm', JText::_('Male'));
         $genderOptions[] = JHTML::_('select.option', 'f', JText::_('Female'));
         $lists['gender'] = JHTML::_('select.radiolist', $genderOptions, 'gender', '', 'value', 'text', $K2User->gender);
         $view->assignRef('lists', $lists);
         JPluginHelper::importPlugin('k2');
         $dispatcher =& JDispatcher::getInstance();
         $K2Plugins = $dispatcher->trigger('onRenderAdminForm', array(&$K2User, 'user'));
         $view->assignRef('K2Plugins', $K2Plugins);
         $view->assignRef('K2User', $K2User);
         ob_start();
         $view->_displayForm();
         $contents = ob_get_clean();
         $document =& JFactory::getDocument();
         $document->setBuffer($contents, 'component');
     }
 }
    function render(&$params)
    {
        $mainframe =& JFactory::getApplication();
        // load the admin language file
        $lang =& JFactory::getLanguage();
        if ($lang->getTag() != 'en-GB') {
            // Loads English language file as fallback (for undefined stuff in other language file)
            $lang->load('plg_editors-xtd_articlesanywhere', JPATH_ADMINISTRATOR, 'en-GB');
        }
        $lang->load('plg_editors-xtd_articlesanywhere', JPATH_ADMINISTRATOR, null, 1);
        // load the content language file
        $lang->load('com_content', JPATH_ADMINISTRATOR);
        require_once JPATH_ADMINISTRATOR . '/components/com_content/helpers/content.php';
        //$k2 = JFile::exists( JPATH_ADMINISTRATOR.'/components/com_k2/admin.k2.php' );
        $k2 = 0;
        $content_type = JRequest::getCmd('content_type', $params->content_type);
        // Initialize variables
        $db =& JFactory::getDBO();
        $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int'));
        $filter = null;
        // Get some variables from the request
        $filter_order = $mainframe->getUserStateFromRequest('articlesanywhere_filter_order', 'filter_order', 'ordering', 'cmd');
        $filter_order_Dir = $mainframe->getUserStateFromRequest('articlesanywhere_filter_order_Dir', 'filter_order_Dir', '', 'word');
        $filter_featured = $mainframe->getUserStateFromRequest('articlesanywhere_filter_featured', 'filter_featured', '', 'int');
        $filter_category = $mainframe->getUserStateFromRequest('articlesanywhere_filter_category', 'filter_category', 0, 'int');
        $filter_author = $mainframe->getUserStateFromRequest('articlesanywhere_filter_author', 'filter_author', 0, 'int');
        $filter_state = $mainframe->getUserStateFromRequest('articlesanywhere_filter_state', 'filter_state', '', 'word');
        $search = $mainframe->getUserStateFromRequest('articlesanywhere_search', 'search', '', 'string');
        $search = JString::strtolower($search);
        $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
        $limitstart = $mainframe->getUserStateFromRequest('articlesanywhere_limitstart', 'limitstart', 0, 'int');
        // In case limit has been changed, adjust limitstart accordingly
        $limitstart = $limit != 0 ? floor($limitstart / $limit) * $limit : 0;
        $lists = array();
        // search filter
        $lists['search'] = $search;
        // table ordering
        if ($k2 && $content_type == 'k2') {
            if ($filter_order == 'section' || $filter_order == 'frontpage') {
                $filter_order = 'ordering';
                $filter_order_Dir = '';
            }
        } else {
            if ($filter_order == 'featured') {
                $filter_order = 'ordering';
                $filter_order_Dir = '';
            }
        }
        $lists['order_Dir'] = $filter_order_Dir;
        $lists['order'] = $filter_order;
        if ($k2 && $content_type == 'k2') {
            // load the k2 language file
            $lang->load('com_k2', JPATH_ADMINISTRATOR);
            define('JPATH_COMPONENT', JPATH_ADMINISTRATOR . '/components/com_k2');
            define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_COMPONENT);
            /* FILTERS */
            // featured filter
            $filter_featured_options[] = JHTML::_('select.option', -1, JText::_('- Select featured state -'));
            $filter_featured_options[] = JHTML::_('select.option', 1, JText::_('Featured'));
            $filter_featured_options[] = JHTML::_('select.option', 0, JText::_('Not featured'));
            $lists['featured'] = JHTML::_('select.genericlist', $filter_featured_options, 'filter_featured', 'onchange="this.form.submit();"', 'value', 'text', $filter_featured);
            // get list of categories for dropdown filter
            require_once JPATH_COMPONENT . '/models/categories.php';
            $categoriesModel = new K2ModelCategories();
            $categories_option[] = JHTML::_('select.option', 0, JText::_('- Select category -'));
            $categories = $categoriesModel->categoriesTree();
            $categories_options = @array_merge($categories_option, $categories);
            $lists['categories'] = JHTML::_('select.genericlist', $categories_options, 'filter_category', 'onchange="this.form.submit();"', 'value', 'text', $filter_category);
            // get list of Authors for dropdown filter
            $query = 'SELECT c.created_by, u.name
				FROM #__k2_items AS c
				LEFT JOIN #__users AS u ON u.id = c.created_by
				WHERE c.published <> -1
				AND c.published <> -2
				AND trash = 0
				GROUP BY u.id
				ORDER BY c.id DESC
				';
            $authors[] = JHTML::_('select.option', '0', '- ' . JText::_('Select Author') . ' -', 'created_by', 'name');
            $db->setQuery($query);
            $authors = array_merge($authors, $db->loadObjectList());
            $lists['authors'] = JHTML::_('select.genericlist', $authors, 'filter_author', 'class="inputbox" size="1" onchange="this.form.submit( );"', 'created_by', 'name', $filter_author);
            // state filter
            $filter_state_options[] = JHTML::_('select.option', -1, JText::_('- Select publishing state -'));
            $filter_state_options[] = JHTML::_('select.option', 1, JText::_('Published'));
            $filter_state_options[] = JHTML::_('select.option', 0, JText::_('Unpublished'));
            $lists['state'] = JHTML::_('select.genericlist', $filter_state_options, 'filter_state', 'onchange="this.form.submit();"', 'value', 'text', $filter_state);
            /* ITEMS */
            $where = array();
            $where[] = 'c.published != -2 AND c.trash = 0';
            if ($search) {
                if ($params->adminSearch == 'full') {
                    $where[] = 'MATCH(c.title, c.introtext, c.`fulltext`, c.extra_fields_search, c.image_caption,c.image_credits,c.video_caption,c.video_credits,c.metadesc,c.metakey) AGAINST(' . $db->quote($search) . ')';
                } else {
                    $where[] = 'MATCH( c.title ) AGAINST(' . $db->quote($search) . ')';
                }
            }
            if ($filter_state && $filter_state > -1) {
                $where[] = 'c.published = ' . (int) $filter_state;
            }
            if ($filter_featured && $filter_featured > -1) {
                $where[] = 'c.featured = ' . (int) $filter_featured;
            }
            if ($filter_category && $filter_category > 0) {
                require_once JPATH_SITE . '/components/com_k2/models/itemlist.php';
                $categories = K2ModelItemlist::getCategoryChilds($filter_category);
                $categories[] = $filter_category;
                $categories = @array_unique($categories);
                $sql = @implode(',', $categories);
                $where[] = 'c.catid IN (' . $sql . ')';
            }
            if ($filter_author && $filter_author > 0) {
                $where[] = 'c.created_by=' . (int) $filter_author;
            }
            // Build the where clause of the content record query
            $where = count($where) ? ' WHERE ' . implode(' AND ', $where) : '';
            // Get the total number of records
            $query = 'SELECT COUNT( * )
				FROM #__k2_items as c
				LEFT JOIN #__k2_categories AS cc ON cc.id = c.catid
				' . $where;
            $db->setQuery($query);
            $total = $db->loadResult();
            // Create the pagination object
            jimport('joomla.html.pagination');
            $page = new JPagination($total, $limitstart, $limit);
            if ($filter_order == 'ordering') {
                $order = ' ORDER BY category, ordering ' . $filter_order_Dir;
            } else {
                $order = ' ORDER BY ' . $filter_order . ' ' . $filter_order_Dir . ', category, ordering';
            }
            $query = 'SELECT c.*, g.name AS accesslevel, cc.name AS category, v.name AS author,
				w.name as moderator, u.name AS editor
				FROM #__k2_items as c
				LEFT JOIN #__k2_categories AS cc ON cc.id = c.catid
				LEFT JOIN #__groups AS g ON g.id = c.access
				LEFT JOIN #__users AS u ON u.id = c.checked_out
				LEFT JOIN #__users AS v ON v.id = c.created_by
				LEFT JOIN #__users AS w ON w.id = c.modified_by
				' . $where . $order;
            $db->setQuery($query, $page->limitstart, $page->limit);
            $rows = $db->loadObjectList();
            // If there is a database query error, throw a HTTP 500 and exit
            if ($db->getErrorNum()) {
                JError::raiseError(500, $db->stderr());
                return false;
            }
        } else {
            $options = JHtml::_('category.options', 'com_content');
            array_unshift($options, JHtml::_('select.option', '0', '- ' . JText::_('Select Category') . ' -'));
            $lists['categories'] = JHTML::_('select.genericlist', $options, 'filter_category', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $filter_category);
            //$lists['categories'] = JHTML::_( 'select.genericlist',  $categories, 'filter_category', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $filter_category );
            // get list of Authors for dropdown filter
            $query = 'SELECT c.created_by, u.name
				FROM #__content AS c
				LEFT JOIN #__users AS u ON u.id = c.created_by
				WHERE c.state <> -1
				AND c.state <> -2
				GROUP BY u.id
				ORDER BY u.id DESC
				';
            $db->setQuery($query);
            $options = $db->loadObjectList();
            array_unshift($options, JHtml::_('select.option', '0', '- ' . JText::_('Select Author') . ' -', 'created_by', 'name'));
            $lists['authors'] = JHTML::_('select.genericlist', $options, 'filter_author', 'class="inputbox" size="1" onchange="this.form.submit( );"', 'created_by', 'name', $filter_author);
            // state filter
            $lists['state'] = JHTML::_('grid.state', $filter_state, 'Published', 'Unpublished', 'Archived');
            /* ITEMS */
            $where = array();
            $where[] = 'c.state != -2';
            /*
             * Add the filter specific information to the where clause
             */
            // Category filter
            if ($filter_category > 0) {
                $where[] = 'c.catid = ' . (int) $filter_category;
            }
            // Author filter
            if ($filter_author > 0) {
                $where[] = 'c.created_by = ' . (int) $filter_author;
            }
            // Content state filter
            if ($filter_state) {
                if ($filter_state == 'P') {
                    $where[] = 'c.state = 1';
                } else {
                    if ($filter_state == 'U') {
                        $where[] = 'c.state = 0';
                    } else {
                        if ($filter_state == 'A') {
                            $where[] = 'c.state = -1';
                        } else {
                            $where[] = 'c.state != -2';
                        }
                    }
                }
            }
            // Keyword filter
            if ($search) {
                $where[] = '(LOWER( c.title ) LIKE ' . $db->quote('%' . $db->getEscaped($search, true) . '%', false) . ' OR c.id = ' . (int) $search . ' )';
            }
            // Build the where clause of the content record query
            $where = count($where) ? ' WHERE ' . implode(' AND ', $where) : '';
            // Get the total number of records
            $query = 'SELECT COUNT( * )
				FROM #__content AS c
				LEFT JOIN #__categories AS cc ON cc.id = c.catid
				' . $where;
            $db->setQuery($query);
            $total = $db->loadResult();
            // Create the pagination object
            jimport('joomla.html.pagination');
            $page = new JPagination($total, $limitstart, $limit);
            if ($filter_order == 'ordering') {
                $order = ' ORDER BY category, ordering ' . $filter_order_Dir;
            } else {
                $order = ' ORDER BY ' . $filter_order . ' ' . $filter_order_Dir . ', category, ordering';
            }
            // Get the articles
            $query = 'SELECT c.*, c.state as published, g.title AS accesslevel, cc.title AS category, u.name AS editor, f.content_id AS frontpage, v.name AS author
				FROM #__content AS c
				LEFT JOIN #__categories AS cc ON cc.id = c.catid
				LEFT JOIN #__viewlevels AS g ON g.id = c.access
				LEFT JOIN #__users AS u ON u.id = c.checked_out
				LEFT JOIN #__users AS v ON v.id = c.created_by
				LEFT JOIN #__content_frontpage AS f ON f.content_id = c.id
				' . $where . $order;
            $db->setQuery($query, $page->limitstart, $page->limit);
            $rows = $db->loadObjectList();
            // If there is a database query error, throw a HTTP 500 and exit
            if ($db->getErrorNum()) {
                JError::raiseError(500, $db->stderr());
                return false;
            }
        }
        $this->outputHTML($params, $rows, $client, $page, $lists, $k2);
    }
Beispiel #9
0
 /**
  * @param $data
  */
 protected function category($data)
 {
     if (file_exists(JPATH_SITE . '/components/com_k2/models/itemlist.php')) {
         require_once JPATH_SITE . '/components/com_k2/models/itemlist.php';
     }
     $wheres = array();
     foreach ($data as $match) {
         $k2model = new K2ModelItemlist();
         $categories = $k2model->getCategoryTree($match);
         $sql = @implode(',', $categories);
         $wheres[] = "a.catid IN ({$sql})";
     }
     $this->filter_where[] = '(' . implode(' OR ', $wheres) . ')';
 }
Beispiel #10
0
 function getItems(&$params, $format = 'html')
 {
     jimport('joomla.filesystem.file');
     $limit = $params->get('itemCount', 5);
     $cid = $params->get('category_id', NULL);
     $ordering = $params->get('itemsOrdering', '');
     $componentParams =& JComponentHelper::getParams('com_k2');
     $limitstart = JRequest::getInt('limitstart');
     $user =& JFactory::getUser();
     $aid = $user->get('aid');
     $db =& JFactory::getDBO();
     $jnow =& JFactory::getDate();
     $now = $jnow->toMySQL();
     $nullDate = $db->getNullDate();
     if ($params->get('source') == 'specific') {
         $value = $params->get('items');
         $current = array();
         if (is_string($value) && !empty($value)) {
             $current[] = $value;
         }
         if (is_array($value)) {
             $current = $value;
         }
         $items = array();
         foreach ($current as $id) {
             $query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams";
             $query .= " FROM #__k2_items as i LEFT JOIN #__k2_categories c ON c.id = i.catid";
             $query .= " WHERE i.published = 1 AND i.access <= {$aid} AND i.trash = 0 AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0";
             $query .= " AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )";
             $query .= " AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )";
             $query .= " AND i.id={$id}";
             $db->setQuery($query);
             $item = $db->loadObject();
             if ($item) {
                 $items[] = $item;
             }
         }
     } else {
         $query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams";
         if ($ordering == 'best') {
             $query .= ", (r.rating_sum/r.rating_count) AS rating";
         }
         if ($ordering == 'comments') {
             $query .= ", COUNT(comments.id) AS numOfComments";
         }
         $query .= " FROM #__k2_items as i LEFT JOIN #__k2_categories c ON c.id = i.catid";
         if ($ordering == 'best') {
             $query .= " LEFT JOIN #__k2_rating r ON r.itemID = i.id";
         }
         if ($ordering == 'comments') {
             $query .= " LEFT JOIN #__k2_comments comments ON comments.itemID = i.id";
         }
         $query .= " WHERE i.published = 1 AND i.access <= {$aid} AND i.trash = 0 AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0";
         $query .= " AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )";
         $query .= " AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )";
         if ($params->get('catfilter')) {
             if (!is_null($cid)) {
                 if (is_array($cid)) {
                     if ($params->get('getChildren')) {
                         require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
                         $allChildren = array();
                         foreach ($cid as $id) {
                             $categories = K2ModelItemlist::getCategoryChilds($id, true);
                             $categories[] = $id;
                             $categories = @array_unique($categories);
                             $allChildren = @array_merge($allChildren, $categories);
                         }
                         $allChildren = @array_unique($allChildren);
                         JArrayHelper::toInteger($allChildren);
                         $sql = @implode(',', $allChildren);
                         $query .= " AND i.catid IN ({$sql})";
                     } else {
                         JArrayHelper::toInteger($cid);
                         $query .= " AND i.catid IN(" . implode(',', $cid) . ")";
                     }
                 } else {
                     if ($params->get('getChildren')) {
                         require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
                         $categories = K2ModelItemlist::getCategoryChilds($cid, true);
                         $categories[] = $cid;
                         $categories = @array_unique($categories);
                         JArrayHelper::toInteger($categories);
                         $sql = @implode(',', $categories);
                         $query .= " AND i.catid IN ({$sql})";
                     } else {
                         $query .= " AND i.catid=" . (int) $cid;
                     }
                 }
             }
         }
         if ($params->get('FeaturedItems') == '0') {
             $query .= " AND i.featured != 1";
         }
         if ($params->get('FeaturedItems') == '2') {
             $query .= " AND i.featured = 1";
         }
         if ($params->get('videosOnly')) {
             $query .= " AND (i.video IS NOT NULL AND i.video!='')";
         }
         if ($ordering == 'comments') {
             $query .= " AND comments.published = 1";
         }
         switch ($ordering) {
             case 'date':
                 $orderby = 'i.created ASC';
                 break;
             case 'rdate':
                 $orderby = 'i.created DESC';
                 break;
             case 'alpha':
                 $orderby = 'i.title';
                 break;
             case 'ralpha':
                 $orderby = 'i.title DESC';
                 break;
             case 'order':
                 if ($params->get('FeaturedItems') == '2') {
                     $orderby = 'i.featured_ordering';
                 } else {
                     $orderby = 'i.ordering';
                 }
                 break;
             case 'rorder':
                 if ($params->get('FeaturedItems') == '2') {
                     $orderby = 'i.featured_ordering DESC';
                 } else {
                     $orderby = 'i.ordering DESC';
                 }
                 break;
             case 'hits':
                 if ($params->get('popularityRange')) {
                     $datenow =& JFactory::getDate();
                     $date = $datenow->toMySQL();
                     $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $params->get('popularityRange') . " DAY) ";
                 }
                 $orderby = 'i.hits DESC';
                 break;
             case 'rand':
                 $orderby = 'RAND()';
                 break;
             case 'best':
                 $orderby = 'rating DESC';
                 break;
             case 'comments':
                 if ($params->get('popularityRange')) {
                     $datenow =& JFactory::getDate();
                     $date = $datenow->toMySQL();
                     $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $params->get('popularityRange') . " DAY) ";
                 }
                 $query .= " GROUP BY i.id ";
                 $orderby = 'numOfComments DESC';
                 break;
             case 'modified':
                 $orderby = 'i.modified DESC';
                 break;
             default:
                 $orderby = 'i.id DESC';
                 break;
         }
         $query .= " ORDER BY " . $orderby;
         $db->setQuery($query, 0, $limit);
         $items = $db->loadObjectList();
     }
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'item.php';
     $model = new K2ModelItem();
     if (count($items)) {
         foreach ($items as $item) {
             //Clean title
             $item->title = JFilterOutput::ampReplace($item->title);
             //Images
             if ($params->get('itemImage')) {
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XS.jpg')) {
                     $item->imageXSmall = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_XS.jpg';
                 }
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) {
                     $item->imageSmall = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg';
                 }
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_M.jpg')) {
                     $item->imageMedium = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_M.jpg';
                 }
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
                     $item->imageLarge = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg';
                 }
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XL.jpg')) {
                     $item->imageXLarge = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_XL.jpg';
                 }
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_Generic.jpg')) {
                     $item->imageGeneric = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_Generic.jpg';
                 }
                 $image = 'image' . $params->get('itemImgSize', 'Small');
                 if (isset($item->{$image})) {
                     $item->image = $item->{$image};
                 }
             }
             //Read more link
             $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias))));
             //Tags
             if ($params->get('itemTags')) {
                 $tags = $model->getItemTags($item->id);
                 for ($i = 0; $i < sizeof($tags); $i++) {
                     $tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name));
                 }
                 $item->tags = $tags;
             }
             //Category link
             if ($params->get('itemCategory')) {
                 $item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
             }
             //Extra fields
             if ($params->get('itemExtraFields')) {
                 $item->extra_fields = $model->getItemExtraFields($item->extra_fields);
             }
             //Comments counter
             if ($params->get('itemCommentsCounter')) {
                 $item->numOfComments = $model->countItemComments($item->id);
             }
             //Attachments
             if ($params->get('itemAttachments')) {
                 $item->attachments = $model->getItemAttachments($item->id);
             }
             //Import plugins
             if ($format != 'feed') {
                 $dispatcher =& JDispatcher::getInstance();
                 JPluginHelper::importPlugin('content');
             }
             //Video
             if ($params->get('itemVideo') && $format != 'feed') {
                 $params->set('vfolder', 'media/k2/videos');
                 $item->text = $item->video;
                 $dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
                 $item->video = $item->text;
             }
             // Introtext
             $item->text = '';
             if ($params->get('itemIntroText')) {
                 // Word limit
                 if ($params->get('itemIntroTextWordLimit')) {
                     $item->text .= K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit'));
                 } else {
                     $item->text .= $item->introtext;
                 }
             }
             if ($format != 'feed') {
                 $params->set('parsedInModule', 1);
                 // for plugins to know when they are parsed inside this module
                 if ($params->get('JPlugins', 1)) {
                     //Plugins
                     $results = $dispatcher->trigger('onBeforeDisplay', array(&$item, &$params, $limitstart));
                     $item->event->BeforeDisplay = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onAfterDisplay', array(&$item, &$params, $limitstart));
                     $item->event->AfterDisplay = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onAfterDisplayTitle', array(&$item, &$params, $limitstart));
                     $item->event->AfterDisplayTitle = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onBeforeDisplayContent', array(&$item, &$params, $limitstart));
                     $item->event->BeforeDisplayContent = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onAfterDisplayContent', array(&$item, &$params, $limitstart));
                     $item->event->AfterDisplayContent = trim(implode("\n", $results));
                     $dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
                     $item->introtext = $item->text;
                 }
                 //Init K2 plugin events
                 $item->event->K2BeforeDisplay = '';
                 $item->event->K2AfterDisplay = '';
                 $item->event->K2AfterDisplayTitle = '';
                 $item->event->K2BeforeDisplayContent = '';
                 $item->event->K2AfterDisplayContent = '';
                 $item->event->K2CommentsCounter = '';
                 if ($params->get('K2Plugins', 1)) {
                     //K2 plugins
                     JPluginHelper::importPlugin('k2');
                     $results = $dispatcher->trigger('onK2BeforeDisplay', array(&$item, &$params, $limitstart));
                     $item->event->K2BeforeDisplay = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onK2AfterDisplay', array(&$item, &$params, $limitstart));
                     $item->event->K2AfterDisplay = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onK2AfterDisplayTitle', array(&$item, &$params, $limitstart));
                     $item->event->K2AfterDisplayTitle = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onK2BeforeDisplayContent', array(&$item, &$params, $limitstart));
                     $item->event->K2BeforeDisplayContent = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onK2AfterDisplayContent', array(&$item, &$params, $limitstart));
                     $item->event->K2AfterDisplayContent = trim(implode("\n", $results));
                     $dispatcher->trigger('onK2PrepareContent', array(&$item, &$params, $limitstart));
                     $item->introtext = $item->text;
                     if ($params->get('itemCommentsCounter')) {
                         $results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart));
                         $item->event->K2CommentsCounter = trim(implode("\n", $results));
                     }
                 }
             }
             //Clean the plugin tags
             $item->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext);
             //Author
             if ($params->get('itemAuthor')) {
                 if (!empty($item->created_by_alias)) {
                     $item->author = $item->created_by_alias;
                     $item->authorGender = NULL;
                     if ($params->get('itemAuthorAvatar')) {
                         $item->authorAvatar = K2HelperUtilities::getAvatar('alias');
                     }
                 } else {
                     $author =& JFactory::getUser($item->created_by);
                     $item->author = $author->name;
                     $query = "SELECT `gender` FROM #__k2_users WHERE userID=" . (int) $author->id;
                     $db->setQuery($query, 0, 1);
                     $item->authorGender = $db->loadResult();
                     if ($params->get('itemAuthorAvatar')) {
                         $item->authorAvatar = K2HelperUtilities::getAvatar($author->id, $author->email, $componentParams->get('userImageWidth'));
                     }
                     //Author Link
                     $item->authorLink = JRoute::_(K2HelperRoute::getUserRoute($item->created_by));
                 }
             }
             $rows[] = $item;
         }
         return $rows;
     }
 }
Beispiel #11
0
    function onAfterDispatch()
    {
        $mainframe =& JFactory::getApplication();
        if ($mainframe->isAdmin()) {
            return;
        }
        $params =& JComponentHelper::getParams('com_k2');
        if (!$params->get('K2UserProfile')) {
            return;
        }
        $option = JRequest::getCmd('option');
        $view = JRequest::getCmd('view');
        $task = JRequest::getCmd('task');
        $layout = JRequest::getCmd('layout');
        $user =& JFactory::getUser();
        if ($option == 'com_user' && $view == 'register' || $option == 'com_users' && $view == 'registration') {
            if ($params->get('recaptchaOnRegistration') && $params->get('recaptcha_public_key')) {
                $document =& JFactory::getDocument();
                $document->addScript('http://api.recaptcha.net/js/recaptcha_ajax.js');
                $js = '
				function showRecaptcha(){
					Recaptcha.create("' . $params->get('recaptcha_public_key') . '", "recaptcha", {
						theme: "' . $params->get('recaptcha_theme', 'clean') . '"
					});
				}
				$K2(document).ready(function() {
					showRecaptcha();
				});
				';
                $document->addScriptDeclaration($js);
            }
            if (!$user->guest) {
                $mainframe->redirect(JURI::root(), JText::_('K2_YOU_ARE_ALREADY_REGISTERED_AS_A_MEMBER'), 'notice');
                $mainframe->close();
            }
            if (K2_JVERSION == '16') {
                require_once JPATH_SITE . DS . 'components' . DS . 'com_users' . DS . 'controller.php';
                $controller = new UsersController();
            } else {
                require_once JPATH_SITE . DS . 'components' . DS . 'com_user' . DS . 'controller.php';
                $controller = new UserController();
            }
            $view = $controller->getView($view, 'html');
            $view->addTemplatePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'templates');
            $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
            $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
            $view->setLayout('register');
            $K2User = new JObject();
            $K2User->description = '';
            $K2User->gender = 'm';
            $K2User->image = '';
            $K2User->url = '';
            $K2User->plugins = '';
            $wysiwyg =& JFactory::getEditor();
            $editor = $wysiwyg->display('description', $K2User->description, '100%', '250px', '', '', false);
            $view->assignRef('editor', $editor);
            $lists = array();
            $genderOptions[] = JHTML::_('select.option', 'm', JText::_('K2_MALE'));
            $genderOptions[] = JHTML::_('select.option', 'f', JText::_('K2_FEMALE'));
            $lists['gender'] = JHTML::_('select.radiolist', $genderOptions, 'gender', '', 'value', 'text', $K2User->gender);
            $view->assignRef('lists', $lists);
            $view->assignRef('K2Params', $params);
            JPluginHelper::importPlugin('k2');
            $dispatcher =& JDispatcher::getInstance();
            $K2Plugins = $dispatcher->trigger('onRenderAdminForm', array(&$K2User, 'user'));
            $view->assignRef('K2Plugins', $K2Plugins);
            $view->assignRef('K2User', $K2User);
            if (K2_JVERSION == '16') {
                $view->assignRef('user', $user);
            }
            $pathway =& $mainframe->getPathway();
            $pathway->setPathway(NULL);
            ob_start();
            $view->display();
            $contents = ob_get_clean();
            $document =& JFactory::getDocument();
            $document->setBuffer($contents, 'component');
        }
        if ($option == 'com_user' && $view == 'user' && ($task == 'edit' || $layout == 'form') || $option == 'com_users' && $view == 'profile' && $layout == 'edit') {
            if ($user->guest) {
                JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
            }
            if (K2_JVERSION == '16') {
                require_once JPATH_SITE . DS . 'components' . DS . 'com_users' . DS . 'controller.php';
                $controller = new UsersController();
            } else {
                require_once JPATH_SITE . DS . 'components' . DS . 'com_user' . DS . 'controller.php';
                $controller = new UserController();
            }
            /*
            // TO DO - We open the profile editing page in a modal, so let's define some CSS
            $document = &JFactory::getDocument();
            $document->addStyleSheet(JURI::root(true).'/media/k2/assets/css/k2.frontend.css');
            $document->addStyleSheet(JURI::root(true).'/templates/system/css/general.css');
            $document->addStyleSheet(JURI::root(true).'/templates/system/css/system.css');
            if(K2_JVERSION == '16') {
            	$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');
            }
            */
            $view = $controller->getView($view, 'html');
            $view->addTemplatePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'templates');
            $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
            $view->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
            $view->setLayout('profile');
            require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
            $model = new K2ModelItemlist();
            $K2User = $model->getUserProfile($user->id);
            if (!is_object($K2User)) {
                $K2User = new Jobject();
                $K2User->description = '';
                $K2User->gender = 'm';
                $K2User->url = '';
                $K2User->image = NULL;
            }
            $wysiwyg =& JFactory::getEditor();
            $editor = $wysiwyg->display('description', $K2User->description, '100%', '250px', '', '', false);
            $view->assignRef('editor', $editor);
            $lists = array();
            $genderOptions[] = JHTML::_('select.option', 'm', JText::_('K2_MALE'));
            $genderOptions[] = JHTML::_('select.option', 'f', JText::_('K2_FEMALE'));
            $lists['gender'] = JHTML::_('select.radiolist', $genderOptions, 'gender', '', 'value', 'text', $K2User->gender);
            $view->assignRef('lists', $lists);
            JPluginHelper::importPlugin('k2');
            $dispatcher =& JDispatcher::getInstance();
            $K2Plugins = $dispatcher->trigger('onRenderAdminForm', array(&$K2User, 'user'));
            $view->assignRef('K2Plugins', $K2Plugins);
            $view->assignRef('K2User', $K2User);
            ob_start();
            if (K2_JVERSION == '16') {
                $view->assignRef('user', $user);
                $view->display();
            } else {
                $view->_displayForm();
            }
            $contents = ob_get_clean();
            $document =& JFactory::getDocument();
            $document->setBuffer($contents, 'component');
        }
    }
Beispiel #12
0
 function getSearchCategoryFilter(&$params)
 {
     $result = '';
     $cid = $params->get('category_id', NULL);
     if ($params->get('catfilter')) {
         if (!is_null($cid)) {
             if (is_array($cid)) {
                 if ($params->get('getChildren')) {
                     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
                     $categories = K2ModelItemlist::getCategoryTree($cid);
                     $result = @implode(',', $categories);
                 } else {
                     JArrayHelper::toInteger($cid);
                     $result = implode(',', $cid);
                 }
             } else {
                 if ($params->get('getChildren')) {
                     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
                     $categories = K2ModelItemlist::getCategoryTree($cid);
                     $result = @implode(',', $categories);
                 } else {
                     $result = (int) $cid;
                 }
             }
         }
     }
     return $result;
 }
Beispiel #13
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) {
         $search = JString::str_ireplace('*', '', $search);
         $words = explode(' ', $search);
         for ($i = 0; $i < count($words); $i++) {
             $words[$i] = '+' . $words[$i];
             $words[$i] .= '*';
         }
         $search = implode(' ', $words);
         $search = $db->Quote($db->getEscaped($search, true), false);
         if ($params->get('adminSearch') == 'full') {
             $query .= " AND MATCH(title, introtext, `fulltext`, extra_fields_search, image_caption, image_credits, video_caption, video_credits, metadesc, metakey)";
         } else {
             $query .= " AND MATCH( title )";
         }
         $query .= " AGAINST ({$search} IN BOOLEAN MODE)";
     }
     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')) {
             require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
             $categories = K2ModelItemlist::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);
     }
     $db->setQuery($query);
     $result = $db->loadResult();
     return $result;
 }
Beispiel #14
0
 function trash()
 {
     $mainframe =& JFactory::getApplication();
     $db =& JFactory::getDBO();
     $cid = JRequest::getVar('cid');
     $row =& JTable::getInstance('K2Category', 'Table');
     JArrayHelper::toInteger($cid);
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
     $model = new K2ModelItemlist();
     $categories = K2ModelItemlist::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'));
 }
Beispiel #15
0
 /**
  * @return JDatabaseQuery
  */
 protected function getListQuery()
 {
     // Create a new query object.
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $user = JFactory::getUser();
     // Select the required fields from the table.
     $query->select($this->getState('list.select', 'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid' . ', a.published, a.trash, a.access, a.created, a.created_by, a.ordering, a.featured, a.language, a.hits' . ', a.publish_up, a.publish_down'));
     $query->from('#__k2_items AS a');
     // Join over the language
     $query->select('l.title AS language_title');
     $query->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language');
     // Join over the users for the checked out user.
     $query->select('uc.userName AS editor');
     $query->join('LEFT', '#__k2_users AS uc ON uc.id=a.checked_out');
     // Join over the asset groups.
     $query->select('ag.title AS access_level');
     $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
     // Join over the categories.
     $query->select('c.name AS category_title');
     $query->join('LEFT', '#__k2_categories AS c ON c.id = a.catid');
     // Join over the users for the author.
     $query->select('ua.userName AS author_name');
     $query->join('LEFT', '#__k2_users AS ua ON ua.userID = a.created_by');
     // Filter by access level.
     if ($access = $this->getState('filter.access')) {
         $query->where('a.access = ' . (int) $access);
     }
     // Implement View Level Access
     if (!$user->authorise('core.admin')) {
         $groups = implode(',', $user->getAuthorisedViewLevels());
         $query->where('a.access IN (' . $groups . ')');
     }
     // Filter by published state
     $published = $this->getState('filter.published');
     if (is_numeric($published) && $published == -2) {
         $query->where('(a.published = 0 OR a.published = 1)');
         $query->where('a.trash = 1');
     } elseif (is_numeric($published)) {
         $query->where('a.published = ' . (int) $published);
         $query->where('a.trash = 0');
     } elseif ($published === '') {
         $query->where('(a.published = 0 OR a.published = 1)');
         $query->where('a.trash = 0');
     }
     $catid = JRequest::getInt('catid');
     if ($catid > 0) {
         require_once JPATH_SITE . '/components/com_k2/models/itemlist.php';
         $categories = K2ModelItemlist::getCategoryTree($catid);
         $sql = @implode(',', $categories);
         $query->where("a.catid IN ({$sql})");
     }
     $categoryId = $this->getState('filter.category_id');
     if ($categoryId > 0) {
         require_once JPATH_SITE . '/components/com_k2/models/itemlist.php';
         $categories = K2ModelItemlist::getCategoryTree($categoryId);
         $sql = @implode(',', $categories);
         $query->where("a.catid IN ({$sql})");
     }
     // Filter by author
     $authorId = $this->getState('filter.author_id');
     if (is_numeric($authorId)) {
         $type = $this->getState('filter.author_id.include', true) ? '= ' : '<>';
         $query->where('a.created_by ' . $type . (int) $authorId);
     }
     // Filter by search in title.
     $search = $this->getState('filter.search');
     if (!empty($search)) {
         if (stripos($search, 'id:') === 0) {
             $query->where('a.id = ' . (int) substr($search, 3));
         } elseif (stripos($search, 'author:') === 0) {
             $search = $db->Quote('%' . $db->escape(substr($search, 7), true) . '%');
             $query->where('(ua.userName LIKE ' . $search . ' OR ua.username LIKE ' . $search . ')');
         } else {
             $search = $db->Quote('%' . $db->escape($search, true) . '%');
             $query->where('(a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search . ')');
         }
     }
     // Filter on the language.
     if ($language = $this->getState('filter.language')) {
         $query->where('a.language = ' . $db->quote($language));
     }
     // Add the list ordering clause.
     $orderCol = $this->state->get('list.ordering', 'a.title');
     $orderDirn = $this->state->get('list.direction', 'asc');
     if ($orderCol == 'a.ordering' || $orderCol == 'category_title') {
         $orderCol = 'c.name ' . $orderDirn . ', a.ordering';
     }
     //sqlsrv change
     if ($orderCol == 'language') {
         $orderCol = 'l.title';
     }
     if ($orderCol == 'access_level') {
         $orderCol = 'ag.title';
     }
     $query->order($db->escape($orderCol . ' ' . $orderDirn));
     // echo nl2br(str_replace('#__','jos_',$query));
     return $query;
 }
Beispiel #16
0
 function setPermissions()
 {
     $params =& K2HelperUtilities::getParams('com_k2');
     $user =& JFactory::getUser();
     if ($user->guest) {
         return;
     }
     $K2User = K2HelperPermissions::getK2User($user->id);
     if (!is_object($K2User)) {
         return;
     }
     $K2UserGroup = K2HelperPermissions::getK2UserGroup($K2User->group);
     if (is_null($K2UserGroup)) {
         return;
     }
     $K2Permissions =& K2Permissions::getInstance();
     $permissions = new JParameter($K2UserGroup->permissions);
     $K2Permissions->permissions = $permissions;
     if ($permissions->get('categories') == 'none') {
         return;
     } else {
         if ($permissions->get('categories') == 'all') {
             if ($permissions->get('add') && $permissions->get('frontEdit') && $params->get('frontendEditing')) {
                 $K2Permissions->actions[] = 'add.category.all';
                 $K2Permissions->actions[] = 'tag';
                 $K2Permissions->actions[] = 'extraFields';
             }
             if ($permissions->get('editOwn') && $permissions->get('frontEdit') && $params->get('frontendEditing')) {
                 $K2Permissions->actions[] = 'editOwn.item.' . $user->id;
                 $K2Permissions->actions[] = 'tag';
                 $K2Permissions->actions[] = 'extraFields';
             }
             if ($permissions->get('editAll') && $permissions->get('frontEdit') && $params->get('frontendEditing')) {
                 $K2Permissions->actions[] = 'editAll.category.all';
                 $K2Permissions->actions[] = 'tag';
                 $K2Permissions->actions[] = 'extraFields';
             }
             if ($permissions->get('publish') && $permissions->get('frontEdit') && $params->get('frontendEditing')) {
                 $K2Permissions->actions[] = 'publish.category.all';
             }
             if ($permissions->get('comment')) {
                 $K2Permissions->actions[] = 'comment.category.all';
             }
         } else {
             $selectedCategories = $permissions->get('categories', NULL);
             if (is_string($selectedCategories)) {
                 $searchIDs[] = $selectedCategories;
             } else {
                 $searchIDs = $selectedCategories;
             }
             if ($permissions->get('inheritance')) {
                 JLoader::register('K2ModelItemlist', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php');
                 $categories = K2ModelItemlist::getCategoryTree($searchIDs);
             } else {
                 $categories = $searchIDs;
             }
             if (is_array($categories) && count($categories)) {
                 foreach ($categories as $category) {
                     if ($permissions->get('add') && $permissions->get('frontEdit') && $params->get('frontendEditing')) {
                         $K2Permissions->actions[] = 'add.category.' . $category;
                         $K2Permissions->actions[] = 'tag';
                         $K2Permissions->actions[] = 'extraFields';
                     }
                     if ($permissions->get('editOwn') && $permissions->get('frontEdit') && $params->get('frontendEditing')) {
                         $K2Permissions->actions[] = 'editOwn.item.' . $user->id . '.' . $category;
                         $K2Permissions->actions[] = 'tag';
                         $K2Permissions->actions[] = 'extraFields';
                     }
                     if ($permissions->get('editAll') && $permissions->get('frontEdit') && $params->get('frontendEditing')) {
                         $K2Permissions->actions[] = 'editAll.category.' . $category;
                         $K2Permissions->actions[] = 'tag';
                         $K2Permissions->actions[] = 'extraFields';
                     }
                     if ($permissions->get('publish') && $permissions->get('frontEdit') && $params->get('frontendEditing')) {
                         $K2Permissions->actions[] = 'publish.category.' . $category;
                     }
                     if ($permissions->get('comment')) {
                         $K2Permissions->actions[] = 'comment.category.' . $category;
                     }
                 }
             }
         }
     }
     return;
 }