function displayView($view, $id = 0) { $tpl_vars = array(); switch ($view) { case 'about': break; case 'config': $dev_infos = $this->_getPocheVersion('dev'); $dev = trim($dev_infos[0]); $check_time_dev = date('d-M-Y H:i', $dev_infos[1]); $prod_infos = $this->_getPocheVersion('prod'); $prod = trim($prod_infos[0]); $check_time_prod = date('d-M-Y H:i', $prod_infos[1]); $compare_dev = version_compare(POCHE, $dev); $compare_prod = version_compare(POCHE, $prod); $themes = $this->tpl->getInstalledThemes(); $languages = $this->language->getInstalledLanguages(); $token = $this->user->getConfigValue('token'); $http_auth = isset($_SERVER['PHP_AUTH_USER']) || isset($_SERVER['REMOTE_USER']) ? true : false; $only_user = $this->store->listUsers() > 1 ? false : true; $tpl_vars = array('themes' => $themes, 'languages' => $languages, 'dev' => $dev, 'prod' => $prod, 'check_time_dev' => $check_time_dev, 'check_time_prod' => $check_time_prod, 'compare_dev' => $compare_dev, 'compare_prod' => $compare_prod, 'token' => $token, 'user_id' => $this->user->getId(), 'http_auth' => $http_auth, 'only_user' => $only_user); Tools::logm('config view'); break; case 'edit-tags': # tags $entry = $this->store->retrieveOneById($id, $this->user->getId()); if (!$entry) { $this->messages->add('e', _('Article not found!')); Tools::logm('error : article not found'); Tools::redirect(); } $tags = $this->store->retrieveTagsByEntry($id); $tpl_vars = array('entry_id' => $id, 'tags' => $tags, 'entry' => $entry); break; case 'tags': $token = $this->user->getConfigValue('token'); //if term is set - search tags for this term $term = Tools::checkVar('term'); $tags = $this->store->retrieveAllTags($this->user->getId(), $term); if (Tools::isAjaxRequest()) { $result = array(); foreach ($tags as $tag) { $result[] = $tag['value']; } echo json_encode($result); exit; } $tpl_vars = array('token' => $token, 'user_id' => $this->user->getId(), 'tags' => $tags); break; case 'search': if (isset($_GET['search'])) { $search = filter_var($_GET['search'], FILTER_SANITIZE_STRING); $tpl_vars['entries'] = $this->store->search($search, $this->user->getId()); $count = count($tpl_vars['entries']); $this->pagination->set_total($count); $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), $this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&')); $tpl_vars['page_links'] = $page_links; $tpl_vars['nb_results'] = $count; $tpl_vars['searchterm'] = $search; } break; case 'view': $entry = $this->store->retrieveOneById($id, $this->user->getId()); if ($entry != NULL) { Tools::logm('view link #' . $id); $content = $entry['content']; if (function_exists('tidy_parse_string')) { $tidy = tidy_parse_string($content, array('indent' => true, 'show-body-only' => true), 'UTF8'); $tidy->cleanRepair(); $content = $tidy->value; } # flattr checking $flattr = NULL; if (FLATTR) { $flattr = new FlattrItem(); $flattr->checkItem($entry['url'], $entry['id']); } # tags $tags = $this->store->retrieveTagsByEntry($entry['id']); $tpl_vars = array('entry' => $entry, 'content' => $content, 'flattr' => $flattr, 'tags' => $tags); } else { Tools::logm('error in view call : entry is null'); } break; default: # home, favorites, archive and tag views $tpl_vars = array('entries' => '', 'page_links' => '', 'nb_results' => '', 'listmode' => isset($_COOKIE['listmode']) ? true : false); //if id is given - we retrieve entries by tag: id is tag id if ($id) { $tpl_vars['tag'] = $this->store->retrieveTag($id, $this->user->getId()); $tpl_vars['id'] = intval($id); } $count = $this->store->getEntriesByViewCount($view, $this->user->getId(), $id); if ($count > 0) { $this->pagination->set_total($count); $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . ($id ? '&id=' . $id : '') . '&')); $tpl_vars['entries'] = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit(), $id); $tpl_vars['page_links'] = $page_links; $tpl_vars['nb_results'] = $count; } Tools::logm('display ' . $view . ' view'); break; } return $tpl_vars; }
function displayView($view, $id = 0) { $tpl_vars = array(); switch ($view) { case 'about': break; case 'config': $dev_infos = $this->_getPocheVersion('dev'); $dev = trim($dev_infos[0]); $check_time_dev = date('d-M-Y H:i', $dev_infos[1]); $prod_infos = $this->_getPocheVersion('prod'); $prod = trim($prod_infos[0]); $check_time_prod = date('d-M-Y H:i', $prod_infos[1]); $compare_dev = version_compare(POCHE, $dev); $compare_prod = version_compare(POCHE, $prod); $themes = $this->tpl->getInstalledThemes(); $languages = $this->language->getInstalledLanguages(); $token = $this->user->getConfigValue('token'); $http_auth = isset($_SERVER['REMOTE_USER']); $only_user = $this->store->listUsers() > 1 ? false : true; $https = substr(Tools::getPocheUrl(), 0, 5) == 'https'; $tpl_vars = array('themes' => $themes, 'languages' => $languages, 'dev' => $dev, 'prod' => $prod, 'check_time_dev' => $check_time_dev, 'check_time_prod' => $check_time_prod, 'compare_dev' => $compare_dev, 'compare_prod' => $compare_prod, 'token' => $token, 'user_id' => $this->user->getId(), 'http_auth' => $http_auth, 'only_user' => $only_user, 'https' => $https); Tools::logm('config view'); break; case 'edit-tags': # tags $entry = $this->store->retrieveOneById($id, $this->user->getId()); if (!$entry) { $this->messages->add('e', _('Article not found!')); Tools::logm('error : article not found'); Tools::redirect(); } $tags = $this->store->retrieveTagsByEntry($id); $all_tags = $this->store->retrieveAllTags($this->user->getId()); $maximus = 0; foreach ($all_tags as $eachtag) { // search for the most times a tag is present if ($eachtag["entriescount"] > $maximus) { $maximus = $eachtag["entriescount"]; } } foreach ($all_tags as $key => $eachtag) { // get the percentage of presence of each tag $percent = floor($eachtag["entriescount"] / $maximus * 100); if ($percent < 20) { // assign a css class, depending on the number of entries count $cssclass = 'smallesttag'; } elseif ($percent >= 20 and $percent < 40) { $cssclass = 'smalltag'; } elseif ($percent >= 40 and $percent < 60) { $cssclass = 'mediumtag'; } elseif ($percent >= 60 and $percent < 80) { $cssclass = 'largetag'; } else { $cssclass = 'largesttag'; } $all_tags[$key]['cssclass'] = $cssclass; } $tpl_vars = array('entry_id' => $id, 'tags' => $tags, 'alltags' => $all_tags, 'entry' => $entry); break; case 'tags': $token = $this->user->getConfigValue('token'); //if term is set - search tags for this term $term = Tools::checkVar('term'); $tags = $this->store->retrieveAllTags($this->user->getId(), $term); if (Tools::isAjaxRequest()) { $result = array(); foreach ($tags as $tag) { $result[] = $tag['value']; } echo json_encode($result); exit; } $tpl_vars = array('token' => $token, 'user_id' => $this->user->getId(), 'tags' => $tags); break; case 'search': if (isset($_GET['search'])) { $search = filter_var($_GET['search'], FILTER_SANITIZE_STRING); $tpl_vars['entries'] = $this->store->search($search, $this->user->getId()); $count = count($tpl_vars['entries']); $this->pagination->set_total($count); $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), $this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&')); $tpl_vars['page_links'] = $page_links; $tpl_vars['nb_results'] = $count; $tpl_vars['searchterm'] = $search; } break; case 'view': $entry = $this->store->retrieveOneById($id, $this->user->getId()); if ($entry != NULL) { Tools::logm('view link #' . $id); $content = $entry['content']; if (function_exists('tidy_parse_string')) { $tidy = tidy_parse_string($content, array('indent' => true, 'show-body-only' => true), 'UTF8'); $tidy->cleanRepair(); $content = $tidy->value; } # flattr checking $flattr = NULL; if (FLATTR) { $flattr = new FlattrItem(); $flattr->checkItem($entry['url'], $entry['id']); } # previous and next $previous = FALSE; $previous_id = $this->store->getPreviousArticle($id, $this->user->getId()); $next = FALSE; $next_id = $this->store->getNextArticle($id, $this->user->getId()); if ($this->store->retrieveOneById($previous_id, $this->user->getId())) { $previous = TRUE; } if ($this->store->retrieveOneById($next_id, $this->user->getId())) { $next = TRUE; } $navigate = array('previous' => $previous, 'previousid' => $previous_id, 'next' => $next, 'nextid' => $next_id); # tags $tags = $this->store->retrieveTagsByEntry($entry['id']); $tpl_vars = array('entry' => $entry, 'content' => $content, 'flattr' => $flattr, 'tags' => $tags, 'navigate' => $navigate); } else { Tools::logm('error in view call : entry is null'); } break; default: # home, favorites, archive and tag views $tpl_vars = array('entries' => '', 'page_links' => '', 'nb_results' => '', 'listmode' => isset($_COOKIE['listmode']) ? true : false, 'view' => $view); //if id is given - we retrieve entries by tag: id is tag id if ($id) { $tpl_vars['tag'] = $this->store->retrieveTag($id, $this->user->getId()); $tpl_vars['id'] = intval($id); } $count = $this->store->getEntriesByViewCount($view, $this->user->getId(), $id); if ($count && $count > 0) { $this->pagination->set_total($count); $page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')), $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . ($id ? '&id=' . $id : '') . '&')); $tpl_vars['entries'] = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit(), $id); $tpl_vars['page_links'] = $page_links; $tpl_vars['nb_results'] = $count; } Tools::logm('display ' . $view . ' view'); break; } return $tpl_vars; }