Exemplo n.º 1
0
 /**
  * @return	JDatabaseQuery
  */
 function getListQuery()
 {
     // Set the archive ordering
     $params = $this->state->params;
     $articleOrderby = $params->get('orderby_sec', 'rdate');
     $articleOrderDate = $params->get('order_date');
     // No category ordering
     $categoryOrderby = '';
     $secondary = TZ_PortfolioHelperQuery::orderbySecondary($articleOrderby, $articleOrderDate) . ', ';
     $primary = TZ_PortfolioHelperQuery::orderbyPrimary($categoryOrderby);
     $orderby = $primary . ' ' . $secondary . ' a.created DESC ';
     $this->setState('list.ordering', $orderby);
     $this->setState('list.direction', '');
     // Create a new query object.
     $query = parent::getListQuery();
     // Add routing for archive
     //sqlsrv changes
     $case_when = ' CASE WHEN ';
     $case_when .= $query->charLength('a.alias');
     $case_when .= ' THEN ';
     $a_id = $query->castAsChar('a.id');
     $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
     $case_when .= ' ELSE ';
     $case_when .= $a_id . ' END as slug';
     $query->select($case_when);
     $case_when = ' CASE WHEN ';
     $case_when .= $query->charLength('c.alias');
     $case_when .= ' THEN ';
     $c_id = $query->castAsChar('c.id');
     $case_when .= $query->concatenate(array($c_id, 'c.alias'), ':');
     $case_when .= ' ELSE ';
     $case_when .= $c_id . ' END as catslug';
     $query->select($case_when);
     // Filter on month, year
     // First, get the date field
     $queryDate = TZ_PortfolioHelperQuery::getQueryDate($articleOrderDate);
     if ($month = $this->getState('filter.month')) {
         $query->where('MONTH(' . $queryDate . ') = ' . $month);
     }
     if ($year = $this->getState('filter.year')) {
         $query->where('YEAR(' . $queryDate . ') = ' . $year);
     }
     //echo nl2br(str_replace('#__','jos_',$query));
     return $query;
 }
Exemplo n.º 2
0
    public function display($tpl = null)
    {
        $app = JFactory::getApplication();
        $user = JFactory::getUser();
        $doc = JFactory::getDocument();
        // Get some data from the models
        $state = $this->get('State');
        $params = $state->params;
        if ($params->get('fields_option_order')) {
            switch ($params->get('fields_option_order')) {
                case 'alpha':
                    $fieldsOptionOrder = 't.value ASC';
                    break;
                case 'ralpha':
                    $fieldsOptionOrder = 't.value DESC';
                    break;
                case 'ordering':
                    $fieldsOptionOrder = 't.ordering ASC';
                    break;
            }
            if (isset($fieldsOptionOrder)) {
                $this->extraFields->setState('filter.option.order', $fieldsOptionOrder);
            }
        }
        // Set value again for option tz_portfolio_redirect
        if ($params->get('tz_portfolio_redirect') == 'default') {
            $params->set('tz_portfolio_redirect', 'article');
        }
        $csscompress = null;
        if ($params->get('css_compression', 0)) {
            $csscompress = '.min';
        }
        $jscompress = new stdClass();
        $jscompress->extfile = null;
        $jscompress->folder = null;
        if ($params->get('js_compression', 1)) {
            $jscompress->extfile = '.min';
            $jscompress->folder = '/packed';
        }
        $items = $this->get('Items');
        $parent = $this->get('Parent');
        $pagination = $this->get('Pagination');
        if (!COM_TZ_PORTFOLIO_JVERSION_COMPARE) {
            $pagination->pagesTotal = $pagination->getPagesCounter();
        }
        // Check for errors.
        if (count($errors = $this->get('Errors'))) {
            JError::raiseError(500, implode("\n", $errors));
            return false;
        }
        // Check whether category access level allows access.
        $user = JFactory::getUser();
        $groups = $user->getAuthorisedViewLevels();
        // PREPARE THE DATA
        // Get the metrics for the structural page layout.
        $numLeading = $params->def('num_leading_articles', 1);
        $numIntro = $params->def('num_intro_articles', 4);
        $numLinks = $params->def('num_links', 4);
        //Get Plugins Model
        $pmodel = JModelLegacy::getInstance('Plugins', 'TZ_PortfolioModel', array('ignore_request' => true));
        $categories = JCategories::getInstance('Content');
        if ($params->get('comment_function_type', 'default') != 'js') {
            // Compute the article slugs and prepare introtext (runs content plugins).
            if ($params->get('tz_show_count_comment', 1) == 1) {
                require_once JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'HTTPFetcher.php';
                require_once JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'readfile.php';
                $fetch = new Services_Yadis_PlainHTTPFetcher();
            }
            $threadLink = null;
            $comments = null;
            if ($items) {
                foreach ($items as $key => &$item) {
                    $slug = $item->alias ? $item->id . ':' . $item->alias : $item->id;
                    /*** New source ***/
                    //Check redirect to view article
                    if ($item->params->get('tz_portfolio_redirect') == 'p_article') {
                        $contentUrl = JRoute::_(TZ_PortfolioHelperRoute::getPortfolioArticleRoute($slug, $item->catid), true, -1);
                    } else {
                        $contentUrl = JRoute::_(TZ_PortfolioHelperRoute::getArticleRoute($slug, $item->catid), true, -1);
                    }
                    /*** End New Source ***/
                    if ($params->get('tz_show_count_comment', 1) == 1) {
                        if ($params->get('tz_comment_type', 'disqus') == 'disqus') {
                            $threadLink .= '&thread[]=link:' . $contentUrl;
                        } elseif ($params->get('tz_comment_type', 'disqus') == 'facebook') {
                            $threadLink .= '&urls[]=' . $contentUrl;
                        }
                    }
                }
            }
            // Get comment counts for all items(articles)
            if ($params->get('tz_show_count_comment', 1) == 1) {
                // From Disqus
                if ($params->get('tz_comment_type', 'disqus') == 'disqus') {
                    if ($threadLink) {
                        $url = 'https://disqus.com/api/3.0/threads/list.json?api_secret=' . $params->get('disqusApiSecretKey', '4sLbLjSq7ZCYtlMkfsG7SS5muVp7DsGgwedJL5gRsfUuXIt6AX5h6Ae6PnNREMiB') . '&forum=' . $params->get('disqusSubDomain', 'templazatoturials') . $threadLink . '&include=open';
                        $content = $fetch->get($url);
                        if ($content) {
                            if ($body = json_decode($content->body)) {
                                if ($responses = $body->response) {
                                    if (!is_array($responses)) {
                                        JError::raiseNotice('300', JText::_('COM_TZ_PORTFOLIO_DISQUS_INVALID_SECRET_KEY'));
                                    }
                                    if (is_array($responses) && count($responses)) {
                                        foreach ($responses as $response) {
                                            $comments[$response->link] = $response->posts;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                // From Facebook
                if ($params->get('tz_comment_type', 'disqus') == 'facebook') {
                    if ($threadLink) {
                        $url = 'http://api.facebook.com/restserver.php?method=links.getStats' . $threadLink;
                        $content = $fetch->get($url);
                        if ($content) {
                            if ($bodies = $content->body) {
                                if (preg_match_all('/\\<link_stat\\>(.*?)\\<\\/link_stat\\>/ims', $bodies, $matches)) {
                                    if (isset($matches[1]) && !empty($matches[1])) {
                                        foreach ($matches[1] as $val) {
                                            $match = null;
                                            if (preg_match('/\\<url\\>(.*?)\\<\\/url\\>.*?\\<comment_count\\>(.*?)\\<\\/comment_count\\>/msi', $val, $match)) {
                                                if (isset($match[1]) && isset($match[2])) {
                                                    $comments[$match[1]] = $match[2];
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // End Get comment counts for all items(articles)
        } else {
            // Add facebook script api
            if ($params->get('tz_show_count_comment', 1) == 1) {
                if ($params->get('tz_comment_type', 'disqus') == 'facebook') {
                    $doc->addScriptDeclaration('
                        (function(d, s, id) {
                          var js, fjs = d.getElementsByTagName(s)[0];
                          if (d.getElementById(id)) return;
                          js = d.createElement(s); js.id = id;
                          js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";
                          fjs.parentNode.insertBefore(js, fjs);
                        }(document, \'script\', \'facebook-jssdk\'));
                   ');
                }
                // Add disqus script api
                if ($params->get('tz_comment_type', 'disqus') == 'disqus') {
                    $doc->addScriptDeclaration('
                        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
                        var disqus_shortname = \'templazatoturials\'; // required: replace example with your forum shortname

                        /* * * DON\'T EDIT BELOW THIS LINE * * */
                        (function () {
                        var s = document.createElement(\'script\'); s.async = true;
                        s.type = \'text/javascript\';
                        s.src = \'http://\' + disqus_shortname + \'.disqus.com/count.js\';
                        (document.getElementsByTagName(\'HEAD\')[0] || document.getElementsByTagName(\'BODY\')[0]).appendChild(s);
                        }());
                   ');
                    $doc->addCustomTag('
                    <script type="text/javascript">
                        window.addEvent("load",function(){
                            var a=document.getElementsByTagName("A");

                            for(var h=0;h<a.length;h++){
                                if(a[h].href.indexOf("#disqus_thread")>=0){
                                var span = document.createElement("span");
                                span.innerHTML  = a[h].innerHTML;
                                a[h].parentNode.appendChild(span);
                                a[h].remove();
                                }
                            }
                        });
                    </script>
                   ');
                }
            }
        }
        $content_ids = array();
        if ($items) {
            for ($i = 0, $n = count($items); $i < $n; $i++) {
                $content_ids[] = $items[$i]->id;
            }
        }
        $tags = null;
        if (count($content_ids) && $params->get('show_tags', 1)) {
            $m_tag = JModelLegacy::getInstance('Tag', 'TZ_PortfolioModel', array('ignore_request' => true));
            $m_tag->setState('params', $params);
            $m_tag->setState('article.id', $content_ids);
            $m_tag->setState('list.ordering', 'x.contentid');
            $tags = $m_tag->getArticleTags();
        }
        $_params = null;
        for ($i = 0, $n = count($items); $i < $n; $i++) {
            $item =& $items[$i];
            if ($tags && count($tags) && isset($tags[$item->id])) {
                $item->tags = $tags[$item->id];
            }
            $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id;
            /*** New source ***/
            $tmpl = null;
            if ($item->params->get('tz_use_lightbox', 1) == 1) {
                $tmpl = '&tmpl=component';
            }
            //Check redirect to view article
            if ($item->params->get('tz_portfolio_redirect') == 'p_article') {
                $item->link = JRoute::_(TZ_PortfolioHelperRoute::getPortfolioArticleRoute($item->slug, $item->catid) . $tmpl);
                $item->fullLink = JRoute::_(TZ_PortfolioHelperRoute::getPortfolioArticleRoute($item->slug, $item->catid), true, -1);
            } else {
                $item->link = JRoute::_(TZ_PortfolioHelperRoute::getArticleRoute($item->slug, $item->catid) . $tmpl);
                $item->fullLink = JRoute::_(TZ_PortfolioHelperRoute::getArticleRoute($item->slug, $item->catid), true, -1);
            }
            /*** End New Source ***/
            if ($params->get('comment_function_type', 'default') != 'js') {
                if ($params->get('tz_show_count_comment', 1) == 1) {
                    if ($params->get('tz_comment_type', 'disqus') == 'disqus' || $params->get('tz_comment_type', 'disqus') == 'facebook') {
                        if ($comments) {
                            if (array_key_exists($item->fullLink, $comments)) {
                                $item->commentCount = $comments[$item->fullLink];
                            } else {
                                $item->commentCount = 0;
                            }
                        } else {
                            $item->commentCount = 0;
                        }
                    }
                }
            } else {
                $item->commentCount = 0;
            }
            // No link for ROOT category
            if ($item->parent_alias == 'root') {
                $item->parent_slug = null;
            }
            $item->event = new stdClass();
            $dispatcher = JDispatcher::getInstance();
            //Get plugin Params for this article
            $pmodel->setState('filter.contentid', $item->id);
            $pluginItems = $pmodel->getItems();
            $pluginParams = $pmodel->getParams();
            $item->pluginparams = clone $pluginParams;
            // Ignore content plugins on links.
            if ($i < $numLeading + $numIntro) {
                // Old plugins: Ensure that text property is available
                if (!isset($item->text)) {
                    $item->text = $item->introtext;
                }
                //Call trigger in group content
                JPluginHelper::importPlugin('content');
                $results = $dispatcher->trigger('onContentPrepare', array('com_tz_portfolio.date', &$item, &$params, 0));
                $item->introtext = $item->text;
                $results = $dispatcher->trigger('onContentAfterTitle', array('com_tz_portfolio.date', &$item, &$item->params, 0));
                $item->event->afterDisplayTitle = trim(implode("\n", $results));
                $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_tz_portfolio.date', &$item, &$item->params, 0));
                $item->event->beforeDisplayContent = trim(implode("\n", $results));
                $results = $dispatcher->trigger('onContentAfterDisplay', array('com_tz_portfolio.date', &$item, &$item->params, 0));
                $item->event->afterDisplayContent = trim(implode("\n", $results));
                $results = $dispatcher->trigger('onContentTZPortfolioVote', array('com_tz_portfolio.date', &$item, &$item->params, 0));
                $item->event->TZPortfolioVote = trim(implode("\n", $results));
                //Call trigger in group tz_portfolio
                JPluginHelper::importPlugin('tz_portfolio');
                $item->introtext = JHtml::_('article.tzprepare', $item->introtext, '', $pluginParams, 'com_tz_portfolio.category');
                $results = $dispatcher->trigger('onTZPluginAfterTitle', array('com_tz_portfolio.article', &$item, &$params, &$pluginParams, 0));
                $item->event->TZafterDisplayTitle = trim(implode("\n", $results));
                $results = $dispatcher->trigger('onTZPluginBeforeDisplay', array('com_tz_portfolio.article', &$item, &$params, &$pluginParams, 0));
                $item->event->TZbeforeDisplayContent = trim(implode("\n", $results));
                $results = $dispatcher->trigger('onTZPluginAfterDisplay', array('com_tz_portfolio.article', &$item, &$params, &$pluginParams, 0));
                $item->event->TZafterDisplayContent = trim(implode("\n", $results));
            }
        }
        // For blog layouts, preprocess the breakdown of leading, intro and linked articles.
        // This makes it much easier for the designer to just interrogate the arrays.
        $max = count($items);
        // The first group is the leading articles.
        $limit = $numLeading;
        for ($i = 0; $i < $limit && $i < $max; $i++) {
            $this->lead_items[$i] =& $items[$i];
            if ($items[$i]->params->get('article_leading_image_size')) {
                $items[$i]->params->set('article_leading_image_resize', $items[$i]->params->get('article_leading_image_size', 'L'));
            }
            if ($items[$i]->params->get('article_leading_image_gallery_size')) {
                $items[$i]->params->set('article_leading_image_gallery_resize', $items[$i]->params->get('article_leading_image_gallery_size', 'L'));
            }
        }
        // The second group is the intro articles.
        $limit = $numLeading + $numIntro;
        // Order articles across, then down (or single column mode)
        for ($i = $numLeading; $i < $limit && $i < $max; $i++) {
            $this->intro_items[$i] =& $items[$i];
            if ($items[$i]->params->get('article_secondary_image_size')) {
                $items[$i]->params->set('article_secondary_image_resize', $items[$i]->params->get('article_secondary_image_size', 'M'));
            }
            if ($items[$i]->params->get('article_secondary_image_gallery_size')) {
                $items[$i]->params->set('article_secondary_image_gallery_resize', $items[$i]->params->get('article_secondary_image_gallery_size', 'M'));
            }
        }
        $this->columns = max(1, $params->def('num_columns', 1));
        $order = $params->def('multi_column_order', 1);
        if ($order == 0 && $this->columns > 1) {
            // call order down helper
            $this->intro_items = TZ_PortfolioHelperQuery::orderDownColumns($this->intro_items, $this->columns);
        }
        $limit = $numLeading + $numIntro + $numLinks;
        // The remainder are the links.
        for ($i = $numLeading + $numIntro; $i < $limit && $i < $max; $i++) {
            $this->link_items[$i] =& $items[$i];
        }
        //Escape strings for HTML output
        $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
        $this->assign('state', $state);
        $this->assign('items', $items);
        //        $this->assign('category', $category);
        //        $this->assignRef('children', $children);
        $this->assignRef('params', $params);
        //        $this->assignRef('parent', $parent);
        $this->assignRef('pagination', $pagination);
        $this->assignRef('user', $user);
        $this->assign('listImage', $this->get('CatImages'));
        $model = JModelLegacy::getInstance('Portfolio', 'TZ_PortfolioModel', array('ignore_request' => true));
        $pParams = clone $params;
        $pParams->set('tz_catid', $params->get('tz_catid', array()));
        $model->setState('params', $pParams);
        $model->setState('filter.year', $state->get('filter.year'));
        $model->setState('filter.month', $state->get('filter.month'));
        $this->assign('char', $state->get('char'));
        $this->assign('availLetter', $model->getAvailableLetter());
        //        $catParams  = $category -> params;
        //        $params -> merge($catParams);
        $this->assign('mediaParams', $params);
        if ($params->get('tz_use_image_hover', 1) == 1) {
            $doc->addStyleDeclaration('
                .tz_image_hover{
                    opacity: 0;
                    position: absolute;
                    top:0;
                    left: 0;
                    transition: opacity ' . $params->get('tz_image_timeout', 0.35) . 's ease-in-out;
                   -moz-transition: opacity ' . $params->get('tz_image_timeout', 0.35) . 's ease-in-out;
                   -webkit-transition: opacity ' . $params->get('tz_image_timeout', 0.35) . 's ease-in-out;
                }
                .tz_image_hover:hover{
                    opacity: 1;
                    margin: 0;
                }
            ');
        }
        if ($params->get('tz_use_lightbox', 1) == 1) {
            $doc->addCustomTag('<script type="text/javascript" src="components/com_tz_portfolio/js' . $jscompress->folder . '/jquery.fancybox.pack.js"></script>');
            $doc->addStyleSheet('components/com_tz_portfolio/css/fancybox.min.css');
            $width = null;
            $height = null;
            $autosize = null;
            if ($params->get('tz_lightbox_width')) {
                if (preg_match('/%|px/', $params->get('tz_lightbox_width'))) {
                    $width = 'width:\'' . $params->get('tz_lightbox_width') . '\',';
                } else {
                    $width = 'width:' . $params->get('tz_lightbox_width') . ',';
                }
            }
            if ($params->get('tz_lightbox_height')) {
                if (preg_match('/%|px/', $params->get('tz_lightbox_height'))) {
                    $height = 'height:\'' . $params->get('tz_lightbox_height') . '\',';
                } else {
                    $height = 'height:' . $params->get('tz_lightbox_height') . ',';
                }
            }
            if ($width || $height) {
                $autosize = 'fitToView: false,autoSize: false,';
            }
            $scrollHidden = null;
            if ($params->get('use_custom_scrollbar', 1)) {
                $scrollHidden = ',scrolling: "no"
                                    ,iframe: {
                                        scrolling : "no",
                                    }';
            }
            $doc->addCustomTag('<script type="text/javascript">
                jQuery(\'.fancybox\').fancybox({
                    type:\'iframe\',
                    openSpeed:' . $params->get('tz_lightbox_speed', 350) . ',
                    openEffect: "' . $params->get('tz_lightbox_transition', 'elastic') . '",
                    ' . $width . $height . $autosize . '
                    helpers:  {
                        title : {
                            type : "inside"
                        },
                        overlay : {
                            css : {background: "rgba(0,0,0,' . $params->get('tz_lightbox_opacity', 0.75) . ')"}
                        }
                    }' . $scrollHidden . '
                });
                </script>
            ');
        }
        $doc->addStyleSheet('components/com_tz_portfolio/css/tzportfolio.min.css');
        //        $this->_prepareDocument();
        // Add feed links
        if ($this->params->get('show_feed_link', 1)) {
            $link = '&format=feed&limitstart=';
            $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
            $this->document->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
            $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
            $this->document->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
        }
        parent::display($tpl);
    }
Exemplo n.º 3
0
 protected function _buildContentOrderBy()
 {
     $app = JFactory::getApplication('site');
     $db = $this->getDbo();
     $params = $this->state->params;
     $itemid = JRequest::getInt('id', 0) . ':' . JRequest::getInt('Itemid', 0);
     $orderCol = $app->getUserStateFromRequest('com_tz_portfolio.category.list.' . $itemid . '.filter_order', 'filter_order', '', 'string');
     $orderDirn = $app->getUserStateFromRequest('com_tz_portfolio.category.list.' . $itemid . '.filter_order_Dir', 'filter_order_Dir', '', 'cmd');
     $orderby = ' ';
     if (!in_array($orderCol, $this->filter_fields)) {
         $orderCol = null;
     }
     if (!in_array(strtoupper($orderDirn), array('ASC', 'DESC', ''))) {
         $orderDirn = 'ASC';
     }
     if ($orderCol && $orderDirn) {
         $orderby .= $db->escape($orderCol) . ' ' . $db->escape($orderDirn) . ', ';
     }
     $articleOrderby = $params->get('orderby_sec', 'rdate');
     $articleOrderDate = $params->get('order_date');
     $categoryOrderby = $params->def('orderby_pri', '');
     $secondary = TZ_PortfolioHelperQuery::orderbySecondary($articleOrderby, $articleOrderDate) . ', ';
     $primary = TZ_PortfolioHelperQuery::orderbyPrimary($categoryOrderby);
     $orderby .= $db->escape($primary) . ' ' . $db->escape($secondary) . ' a.created ';
     return $orderby;
 }
Exemplo n.º 4
0
 /**
  * @return	JDatabaseQuery
  */
 function getListQuery()
 {
     // Set the blog ordering
     $params = $this->state->params;
     $articleOrderby = $params->get('orderby_sec', 'rdate');
     $articleOrderDate = $params->get('order_date');
     $categoryOrderby = $params->def('orderby_pri', '');
     $secondary = TZ_PortfolioHelperQuery::orderbySecondary($articleOrderby, $articleOrderDate) . ', ';
     $primary = TZ_PortfolioHelperQuery::orderbyPrimary($categoryOrderby);
     $orderby = $primary . ' ' . $secondary . ' a.created DESC ';
     $this->setState('list.ordering', $orderby);
     $this->setState('list.direction', '');
     // Create a new query object.
     $query = parent::getListQuery();
     // Filter by frontpage.
     if ($this->getState('filter.frontpage')) {
         $query->join('INNER', '#__content_frontpage AS fp ON fp.content_id = a.id');
     }
     // Filter by categories
     if (is_array($featuredCategories = $this->getState('filter.frontpage.categories'))) {
         $featuredCategories = array_filter($featuredCategories);
         $query->where(' a.catid IN (' . implode(',', $featuredCategories) . ')');
     }
     return $query;
 }