/** * Renders the Articles tab * * @param Table[] $rows Articles to render * @param cbPageNav $pageNav Pagination * @param boolean $searching Currently searching * @param string[] $input HTML of input elements * @param UserTable $viewer Viewing user * @param UserTable $user Viewed user * @param stdClass $model The model reference * @param TabTable $tab Current Tab * @param PluginTable $plugin Current Plugin * @return string HTML */ public static function showArticleTab($rows, $pageNav, $searching, $input, $viewer, $user, $model, $tab, $plugin) { global $_CB_framework; $tabPaging = $tab->params->get('tab_paging', 1); $canSearch = $tab->params->get('tab_search', 1) && ($searching || $pageNav->total); $return = '<div class="articlesTab">' . '<form action="' . $_CB_framework->userProfileUrl($user->id, true, $tab->tabid) . '" method="post" name="articleForm" id="articleForm" class="articleForm">'; if ($canSearch) { $return .= '<div class="articlesHeader row" style="margin-bottom: 10px;">' . '<div class="col-sm-offset-8 col-sm-4 text-right">' . '<div class="input-group">' . '<span class="input-group-addon"><span class="fa fa-search"></span></span>' . $input['search'] . '</div>' . '</div>' . '</div>'; } $return .= '<table class="articlesContainer table table-hover table-responsive">' . '<thead>' . '<tr>' . '<th style="width: 50%;" class="text-left">' . CBTxt::T('Article') . '</th>' . '<th style="width: 25%;" class="text-left hidden-xs">' . CBTxt::T('Category') . '</th>' . '<th style="width: 25%;" class="text-left hidden-xs">' . CBTxt::T('Created') . '</th>' . '</tr>' . '</thead>' . '<tbody>'; if ($rows) { foreach ($rows as $row) { $return .= '<tr>' . '<td style="width: 50%;" class="text-left"><a href="' . cbarticlesModel::getUrl($row, true, 'article') . '">' . $row->get('title') . '</a></td>' . '<td style="width: 25%;" class="text-left hidden-xs">' . ($row->get('category') ? '<a href="' . cbarticlesModel::getUrl($row, true, 'category') . '">' . $row->get('category_title') . '</a>' : CBTxt::T('None')) . '</td>' . '<td style="width: 25%;" class="text-left hidden-xs">' . cbFormatDate($row->get('created')) . '</td>' . '</tr>'; } } else { $return .= '<tr>' . '<td colspan="3" class="text-left">'; if ($searching) { $return .= CBTxt::T('No article search results found.'); } else { if ($viewer->id == $user->id) { $return .= CBTxt::T('You have no articles.'); } else { $return .= CBTxt::T('This user has no articles.'); } } $return .= '</td>' . '</tr>'; } $return .= '</tbody>'; if ($tabPaging && $pageNav->total > $pageNav->limit) { $return .= '<tfoot>' . '<tr>' . '<td colspan="3" class="text-center">' . $pageNav->getListLinks() . '</td>' . '</tr>' . '</tfoot>'; } $return .= '</table>' . $pageNav->getLimitBox(false) . '</form>' . '</div>'; return $return; }
/** * Generates the HTML to display the user profile tab * * @param \CB\Database\Table\TabTable $tab the tab database entry * @param \CB\Database\Table\UserTable $user the user being displayed * @param int $ui 1 for front-end, 2 for back-end * @return string|boolean Either string HTML for tab content, or false if ErrorMSG generated */ public function getDisplayTab($tab, $user, $ui) { global $_CB_framework, $_CB_database; outputCbJs(1); outputCbTemplate(1); cbimport('cb.pagination'); $plugin = cbarticlesClass::getPlugin(); $model = cbarticlesClass::getModel(); $viewer = CBuser::getMyUserDataInstance(); cbarticlesClass::getTemplate('tab'); $limit = (int) $this->params->get('tab_limit', 15); $limitstart = $_CB_framework->getUserStateFromRequest('tab_articles_limitstart{com_comprofiler}', 'tab_articles_limitstart'); $filterSearch = $_CB_framework->getUserStateFromRequest('tab_articles_search{com_comprofiler}', 'tab_articles_search'); $where = null; if (isset($filterSearch) && $filterSearch != '') { $where .= "\n AND ( a." . $_CB_database->NameQuote('title') . " LIKE " . $_CB_database->Quote('%' . $_CB_database->getEscaped($filterSearch, true) . '%', false) . " OR a." . $_CB_database->NameQuote('introtext') . " LIKE " . $_CB_database->Quote('%' . $_CB_database->getEscaped($filterSearch, true) . '%', false) . " OR a." . $_CB_database->NameQuote('fulltext') . " LIKE " . $_CB_database->Quote('%' . $_CB_database->getEscaped($filterSearch, true) . '%', false) . " )"; } $searching = $where ? true : false; $total = cbarticlesModel::getArticlesTotal($where, $viewer, $user, $plugin); if ($total <= $limitstart) { $limitstart = 0; } $pageNav = new cbPageNav($total, $limitstart, $limit); $pageNav->setInputNamePrefix('tab_articles_'); $rows = cbarticlesModel::getArticles($this->params->get('tab_paging', 1) ? array($pageNav->limitstart, $pageNav->limit) : null, $where, $viewer, $user, $plugin); $input = array(); $input['search'] = '<input type="text" name="tab_articles_search" value="' . htmlspecialchars($filterSearch) . '" onchange="document.articleForm.submit();" placeholder="' . htmlspecialchars(CBTxt::T('Search Articles...')) . '" class="form-control" />'; $tab->params = $this->params; $class = $plugin->params->get('general_class', null); $return = '<div id="cbArticles" class="cbArticles' . ($class ? ' ' . htmlspecialchars($class) : null) . '">' . '<div id="cbArticlesInner" class="cbArticlesInner">' . HTML_cbarticlesTab::showArticleTab($rows, $pageNav, $searching, $input, $viewer, $user, $model, $tab, $plugin) . '</div>' . '</div>'; return $return; }