protected function showTags()
 {
     $this->loadLanguageFile('tl_module');
     $strUrl = ampersand(\Environment::get('request'), ENCODE_AMPERSANDS);
     // Get target page
     $objPageObject = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")->limit(1)->execute($this->tag_jumpTo);
     global $objPage;
     $default = $objPage != null ? $objPage->row() : array();
     $pageArr = $objPageObject->numRows ? $objPageObject->fetchAssoc() : $default;
     $strParams = '';
     if ($this->keep_url_params) {
         $strParams = \TagHelper::getSavedURLParams($this->Input);
     }
     foreach ($this->arrTags as $idx => $tag) {
         if (count($pageArr)) {
             if ($tag['tag_name'] != \Input::get('tag') && $tag['tag_name'] != str_replace('|slash|', '/', \Input::get('tag'))) {
                 $strUrl = ampersand($this->generateFrontendUrl($pageArr, '/tag/' . str_replace('/', '|slash|', \System::urlencode($tag['tag_name']))));
             } else {
                 $strUrl = ampersand($this->generateFrontendUrl($pageArr));
             }
             if (strlen($strParams)) {
                 if (strpos($strUrl, '?') !== false) {
                     $strUrl .= '&' . $strParams;
                 } else {
                     $strUrl .= '?' . $strParams;
                 }
             }
         }
         $this->arrTags[$idx]['tag_url'] = $strUrl;
         if ($tag['tag_name'] == \Input::get('tag') || $tag['tag_name'] == str_replace('|slash|', '/', \Input::get('tag'))) {
             $this->arrTags[$idx]['tag_class'] .= ' active';
         }
         if ($this->checkForArticleOnPage) {
             global $objPage;
             // get articles on page
             $arrArticles = $this->Database->prepare("SELECT id FROM tl_article WHERE pid = ?")->execute($objPage->id)->fetchEach('id');
             $arrTagIds = $this->Database->prepare("SELECT tid FROM " . $this->tag_tagtable . " WHERE from_table = ? AND tag = ?")->execute('tl_article', $tag['tag_name'])->fetchEach('tid');
             if (count(array_intersect($arrArticles, $arrTagIds))) {
                 $this->arrTags[$idx]['tag_class'] .= ' here';
             }
         }
         if ($this->checkForContentElementOnPage) {
             global $objPage;
             // get articles on page
             $arrArticles = $this->Database->prepare("SELECT id FROM tl_article WHERE pid = ?")->execute($objPage->id)->fetchEach('id');
             if (count($arrArticles)) {
                 $arrCE = $this->Database->prepare("SELECT id FROM tl_content WHERE pid IN (" . implode(",", $arrArticles) . ")")->execute()->fetchEach('id');
                 $arrTagIds = $this->Database->prepare("SELECT tid FROM " . $this->tag_tagtable . " WHERE from_table = ? AND tag = ?")->execute('tl_content', $tag['tag_name'])->fetchEach('tid');
                 if (count(array_intersect($arrCE, $arrTagIds))) {
                     $this->arrTags[$idx]['tag_class'] .= ' here';
                 }
             }
         }
     }
     $relatedlist = strlen(\Input::get('related')) ? preg_split("/,/", \Input::get('related')) : array();
     foreach ($this->arrRelated as $idx => $tag) {
         if (count($pageArr)) {
             if ($tag['tag_name'] != \Input::get('tag')) {
                 $strUrl = ampersand($this->generateFrontendUrl($pageArr, '/tag/' . str_replace('/', '|slash|', \System::urlencode(\Input::get('tag'))) . '/related/' . str_replace('/', '|slash|', \System::urlencode(join(array_merge($relatedlist, array($tag['tag_name'])), ',')))));
             } else {
                 $strUrl = ampersand($this->generateFrontendUrl($pageArr));
             }
         }
         $this->arrRelated[$idx]['tag_url'] = $strUrl;
     }
     $this->Template->pageID = $this->id;
     $this->Template->tags = $this->arrTags;
     $this->Template->jumpTo = $this->jumpTo;
     $this->Template->relatedtags = $this->arrRelated;
     $this->Template->strRelatedTags = $GLOBALS['TL_LANG']['tl_module']['tag_relatedtags'];
     $this->Template->strAllTags = $GLOBALS['TL_LANG']['tl_module']['tag_alltags'];
     $this->Template->strTopTenTags = sprintf($GLOBALS['TL_LANG']['tl_module']['top_tags'], $this->tag_topten_number);
     $this->Template->tagcount = count($this->arrTags);
     $this->Template->selectedtags = strlen(\Input::get('tag')) ? count($this->arrRelated) + 1 : 0;
     if ($this->tag_show_reset) {
         $strEmptyUrl = ampersand($this->generateFrontendUrl($pageArr, ''));
         if (strlen($strParams)) {
             if (strpos($strUrl, '?') !== false) {
                 $strEmptyUrl .= '&' . $strParams;
             } else {
                 $strEmptyUrl .= '?' . $strParams;
             }
         }
         $this->Template->empty_url = $strEmptyUrl;
         $this->Template->lngEmpty = $GLOBALS['TL_LANG']['tl_module']['tag_clear_tags'];
     }
     $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/tags/assets/tagcloud.js';
     if (count($pageArr)) {
         $this->Template->topten = $this->tag_topten;
         if ($this->tag_topten) {
             foreach ($this->arrTopTenTags as $idx => $tag) {
                 if (count($pageArr)) {
                     if ($tag['tag_name'] != \Input::get('tag')) {
                         $strUrl = ampersand($this->generateFrontendUrl($pageArr, '/tag/' . str_replace('/', '|slash|', \System::urlencode($tag['tag_name']))));
                     } else {
                         $strUrl = ampersand($this->generateFrontendUrl($pageArr));
                     }
                     if (strlen($strParams)) {
                         if (strpos($strUrl, '?') !== false) {
                             $strUrl .= '&' . $strParams;
                         } else {
                             $strUrl .= '?' . $strParams;
                         }
                     }
                 }
                 if ($this->arrTopTenTags[$idx]['tag_name'] == str_replace('|slash|', '/', \Input::get('tag'))) {
                     $this->arrTopTenTags[$idx]['tag_class'] .= ' active';
                 }
                 $this->arrTopTenTags[$idx]['tag_url'] = $strUrl;
             }
             $ts = deserialize(\Input::cookie('tagcloud_states'), true);
             //				$ts = $this->Session->get('tagcloud_states');
             $this->Template->expandedTopTen = strlen($ts[$this->id]['topten']) ? strcmp($ts[$this->id]['topten'], 'none') == 0 ? 0 : 1 : $this->tag_topten_expanded;
             $this->Template->expandedAll = strlen($ts[$this->id]['alltags']) ? strcmp($ts[$this->id]['alltags'], 'none') == 0 ? 0 : 1 : $this->tag_all_expanded;
             $this->Template->expandedRelated = strlen($ts[$this->id]['related']) ? strcmp($ts[$this->id]['related'], 'none') == 0 ? 0 : 1 : 1;
             $this->Template->toptentags = $this->arrTopTenTags;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Generate module
  */
 protected function compile()
 {
     $this->loadLanguageFile('tl_module');
     $this->Template->lngTags = strlen($this->clear_text) ? $this->clear_text : $GLOBALS['TL_LANG']['tl_module']['tags'];
     $this->Template->jumpTo = $this->jumpTo;
     $this->Template->arrTags = $this->arrTags;
     $objPageObject = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")->limit(1)->execute($this->tag_jumpTo);
     $pageArr = $objPageObject->numRows ? $objPageObject->fetchAssoc() : array();
     $strParams = '';
     if ($this->keep_url_params) {
         $strParams = \TagHelper::getSavedURLParams($this->Input);
     }
     $tagurls = array();
     foreach ($this->arrTags as $idx => $tag) {
         if (count($pageArr)) {
             $strUrl = ampersand($this->generateFrontendUrl($pageArr, '/tag/' . \System::urlencode($tag)));
             if (strlen($strParams)) {
                 if (strpos($strUrl, '?') !== false) {
                     $strUrl .= '&' . $strParams;
                 } else {
                     $strUrl .= '?' . $strParams;
                 }
             }
             $tagurls[$tag] = $strUrl;
         }
     }
     $this->Template->tag_urls = $tagurls;
     $strEmptyUrl = ampersand($this->generateFrontendUrl($pageArr, ''));
     if (strlen($strParams)) {
         if (strpos($strEmptyUrl, '?') !== false) {
             $strEmptyUrl .= '&' . $strParams;
         } else {
             $strEmptyUrl .= '?' . $strParams;
         }
     }
     $this->Template->empty_url = $strEmptyUrl;
     $deleteUrls = array();
     if (count($this->arrTags) > 0) {
         if (count($this->arrTags) == 1) {
             $deleteUrls[$this->arrTags[0]] = $strEmptyUrl;
         } else {
             foreach ($this->arrTags as $idx => $tag) {
                 $newarr = array();
                 foreach ($this->arrTags as $idxnew => $tagnew) {
                     if ($idxnew != $idx) {
                         array_push($newarr, $tagnew);
                     }
                 }
                 $tagpath = '/tag/' . \System::urlencode($newarr[0]);
                 if (count($newarr) > 1) {
                     $related = array_slice($newarr, 1);
                     $tagpath .= '/related/' . \System::urlencode(join($related, ','));
                 }
                 $strUrl = ampersand($this->generateFrontendUrl($pageArr, $tagpath));
                 if (strlen($strParams)) {
                     if (strpos($strUrl, '?') !== false) {
                         $strUrl .= '&' . $strParams;
                     } else {
                         $strUrl .= '?' . $strParams;
                     }
                 }
                 $deleteUrls[$tag] = $strUrl;
             }
         }
     }
     $this->Template->delete_urls = $deleteUrls;
 }