/** * Display website list for (dis)approval * * @return null */ public function display_websites() { global $phpbb_admin_path; // Sort keys $sort_days = $this->request->variable('st', 0); $sort_key = $this->request->variable('sk', 't'); $sort_dir = $this->request->variable('sd', 'd'); // Number of entries to display $per_page = $this->request->variable('links_per_page', (int) $this->config['dir_show']); $start = $this->request->variable('start', 0); // Categorie ordering options $limit_days = array(0 => $this->user->lang['SEE_ALL'], 1 => $this->user->lang['1_DAY'], 7 => $this->user->lang['7_DAYS'], 14 => $this->user->lang['2_WEEKS'], 30 => $this->user->lang['1_MONTH'], 90 => $this->user->lang['3_MONTHS'], 180 => $this->user->lang['6_MONTHS'], 365 => $this->user->lang['1_YEAR']); $sort_by_text = array('a' => $this->user->lang['AUTHOR'], 't' => $this->user->lang['POST_TIME']); $sort_by_sql = array('a' => 'u.username_clean', 't' => array('l.link_time', 'l.link_id')); $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); // Define where and sort sql for use in displaying logs $sql_where = $sort_days ? time() - $sort_days * 86400 : 0; $direction = $sort_dir == 'd' ? 'DESC' : 'ASC'; if (is_array($sort_by_sql[$sort_key])) { $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction; } else { $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction; } $sql = 'SELECT COUNT(1) AS total_links FROM ' . DIR_LINK_TABLE . ' WHERE link_active = 0' . ($sql_where ? " AND link_time >= {$sql_where}" : ''); $result = $this->db->sql_query($sql); $total_links = (int) $this->db->sql_fetchfield('total_links'); $this->db->sql_freeresult($result); // Make sure $start is set to the last page if it exceeds the amount $start = $this->pagination->validate_start($start, $per_page, $total_links); $sql_array = array('SELECT' => 'l.link_id, l.link_name, l.link_url, l.link_description, l.link_cat, l.link_user_id, l.link_guest_email, l.link_uid, l.link_bitfield, l.link_flags, l.link_banner, l.link_time, c.cat_name, u.user_id, u.username, u.user_colour', 'FROM' => array(DIR_LINK_TABLE => 'l'), 'LEFT_JOIN' => array(array('FROM' => array(DIR_CAT_TABLE => 'c'), 'ON' => 'c.cat_id = l.link_cat'), array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = l.link_user_id')), 'WHERE' => 'l.link_active = 0' . ($sql_where ? " AND l.link_time >= {$sql_where}" : ''), 'ORDER_BY' => $sql_sort_order); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query_limit($sql, $per_page, $start); while ($row = $this->db->sql_fetchrow($result)) { $s_banner = $this->link->display_bann($row); $username = $row['link_user_id'] == ANONYMOUS ? $row['link_guest_email'] : $row['username']; $link_row = array('LINK_URL' => $row['link_url'], 'LINK_NAME' => $row['link_name'], 'LINK_DESC' => generate_text_for_display($row['link_description'], $row['link_uid'], $row['link_bitfield'], $row['link_flags']), 'L_DIR_USER_PROP' => $this->user->lang('DIR_USER_PROP', get_username_string('full', $row['link_user_id'], $username, $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.{$this->php_ext}", 'i=users&mode=overview')), '<select name=c' . $row['link_id'] . '>' . $this->categorie->make_cat_select((int) $row['link_cat']) . '</select>', $this->user->format_date($row['link_time'])), 'BANNER' => $s_banner, 'LINK_ID' => $row['link_id']); $this->template->assign_block_vars('linkrow', $link_row); } $this->db->sql_freeresult($result); $option_ary = array('approved' => 'DIR_LINK_ACTIVATE', 'disapproved' => 'DIR_LINK_DELETE'); $base_url = $this->u_action . "&{$u_sort_param}&links_per_page={$per_page}"; $this->pagination->generate_template_pagination($base_url, 'pagination', 'start', $total_links, $per_page, $start); $this->template->assign_vars(array('S_LINKS_OPTIONS' => build_select($option_ary), 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'LINKS_PER_PAGE' => $per_page, 'U_ACTION' => $this->u_action . "&{$u_sort_param}&links_per_page={$per_page}&start={$start}")); }
/** * Populate form when an error occurred * * @param int $cat_id The category ID * @param string $mode add|edit * @param string $title Page title (depends of $mode) * @return null */ private function _populate_form($cat_id, $mode, $title) { global $phpbb_extension_manager; if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'] && $mode == 'new') { $this->s_hidden_fields = array_merge($this->s_hidden_fields, $this->captcha->get_hidden_fields()); $this->user->add_lang('ucp'); $this->template->assign_vars(array('CAPTCHA_TEMPLATE' => $this->captcha->get_template())); } $this->user->add_lang('posting'); if (!function_exists('display_custom_bbcodes')) { include $this->root_path . 'includes/functions_display.' . $this->php_ext; } display_custom_bbcodes(); add_form_key('dir_form'); $ext_path = $phpbb_extension_manager->get_extension_path('ernadoo/phpbbdirectory', false); $flag_path = $ext_path . 'images/flags/'; $s_guest = !$this->user->data['is_registered'] || !empty($this->guest_email); $s_rss = $this->config['dir_activ_rss']; $s_banner = $this->config['dir_activ_banner']; $s_back = $this->categorie->data['cat_link_back']; $s_flag = $this->config['dir_activ_flag']; $this->template->assign_vars(array('BBCODE_STATUS' => $this->config['allow_bbcode'] ? $this->user->lang('BBCODE_IS_ON', '<a href="' . append_sid($this->root_path . "faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>') : $this->user->lang('BBCODE_IS_OFF', '<a href="' . append_sid($this->root_path . "faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>'), 'IMG_STATUS' => $this->config['allow_bbcode'] ? $this->user->lang['IMAGES_ARE_ON'] : $this->user->lang['IMAGES_ARE_OFF'], 'SMILIES_STATUS' => $this->config['allow_smilies'] ? $this->user->lang['SMILIES_ARE_ON'] : $this->user->lang['SMILIES_ARE_OFF'], 'URL_STATUS' => $this->config['allow_post_links'] ? $this->user->lang['URL_IS_ON'] : $this->user->lang['URL_IS_OFF'], 'FLASH_STATUS' => $this->config['allow_bbcode'] && $this->config['allow_post_flash'] ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'], 'L_TITLE' => $title, 'L_DIR_DESCRIPTION_EXP' => $this->user->lang('DIR_DESCRIPTION_EXP', $this->config['dir_length_describe']), 'L_DIR_SUBMIT_TYPE' => $this->categorie->dir_submit_type($this->categorie->need_approval()), 'L_DIR_SITE_BANN_EXP' => $this->user->lang('DIR_SITE_BANN_EXP', $this->config['dir_banner_width'], $this->config['dir_banner_height']), 'S_GUEST' => $s_guest ? true : false, 'S_RSS' => $s_rss ? true : false, 'S_BANNER' => $s_banner ? true : false, 'S_BACK' => $s_back ? true : false, 'S_FLAG' => $s_flag ? true : false, 'S_BBCODE_ALLOWED' => (bool) $this->config['allow_bbcode'], 'S_BBCODE_IMG' => (bool) $this->config['allow_bbcode'], 'S_BBCODE_FLASH' => $this->config['allow_bbcode'] && $this->config['allow_post_flash'] ? true : false, 'S_BBCODE_QUOTE' => true, 'S_LINKS_ALLOWED' => (bool) $this->config['allow_post_links'], 'DIR_FLAG_PATH' => $flag_path, 'DIR_FLAG_IMAGE' => $this->flag ? $this->dir_helper->get_img_path('flags', $this->flag) : '', 'EDIT_MODE' => $mode == 'edit' ? true : false, 'SITE_NAME' => isset($this->site_name) ? $this->site_name : '', 'SITE_URL' => isset($this->url) ? $this->url : '', 'DESCRIPTION' => isset($this->description) ? $this->description : '', 'GUEST_EMAIL' => isset($this->guest_email) ? $this->guest_email : '', 'RSS' => isset($this->rss) ? $this->rss : '', 'BANNER' => isset($this->banner) ? $this->banner : '', 'BACK' => isset($this->back) ? $this->back : '', 'S_POST_ACTION' => '', 'S_CATLIST' => $this->categorie->make_cat_select($cat_id), 'S_LIST_FLAG' => $this->link->get_dir_flag_list($flag_path, $this->flag), 'S_DESC_STAR' => @$this->categorie->data['cat_must_describe'] ? '*' : '', 'S_ROOT' => $cat_id, 'S_HIDDEN_FIELDS' => build_hidden_fields($this->s_hidden_fields))); }
/** * View controller for display a category * * @param int $cat_id The category ID * @param int $page Page number taken from the URL * @param int $sort_days Specifies the maximum amount of days a link may be old * @param string $sort_key is the key of $sort_by_sql for the selected sorting: a|t|r|s|v|p * @param string $sort_dir is either a or d representing ASC and DESC (ascending|descending) * @param string $mode watch|unwatch * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object * @throws \phpbb\exception\http_exception */ public function view($cat_id, $page, $sort_days, $sort_key, $sort_dir, $mode = '') { if (false === $this->categorie->get($cat_id)) { throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_CATS'); } $start = ($page - 1) * $this->config['dir_show']; $default_sort_days = 0; $default_sort_key = (string) substr($this->config['dir_default_order'], 0, 1); $default_sort_dir = (string) substr($this->config['dir_default_order'], 2); $sort_days = !$sort_days ? $this->request->variable('st', $default_sort_days) : $sort_days; $sort_key = !$sort_key ? $this->request->variable('sk', $default_sort_key) : $sort_key; $sort_dir = !$sort_dir ? $this->request->variable('sd', $default_sort_dir) : $sort_dir; $link_list = $rowset = array(); // Categorie ordering options $limit_days = array(0 => $this->user->lang['SEE_ALL'], 1 => $this->user->lang['1_DAY'], 7 => $this->user->lang['7_DAYS'], 14 => $this->user->lang['2_WEEKS'], 30 => $this->user->lang['1_MONTH'], 90 => $this->user->lang['3_MONTHS'], 180 => $this->user->lang['6_MONTHS'], 365 => $this->user->lang['1_YEAR']); $sort_by_text = array('a' => $this->user->lang['AUTHOR'], 't' => $this->user->lang['POST_TIME'], 'r' => $this->user->lang['DIR_COMMENTS_ORDER'], 's' => $this->user->lang['DIR_NAME_ORDER'], 'v' => $this->user->lang['DIR_NB_CLICKS_ORDER']); $sort_by_sql = array('a' => 'u.username_clean', 't' => array('l.link_time', 'l.link_id'), 'r' => 'l.link_comment', 's' => 'LOWER(l.link_name)', 'v' => 'l.link_view'); if ($this->config['dir_activ_pagerank']) { $sort_by_text['p'] = $this->user->lang['DIR_PR_ORDER']; $sort_by_sql['p'] = 'l.link_pagerank'; } $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir); $u_sort_param = $sort_days === $default_sort_days && $sort_key == $default_sort_key && $sort_dir == $default_sort_dir ? array() : array('sort_days' => $sort_days, 'sort_key' => $sort_key, 'sort_dir' => $sort_dir); // Are we watching this categorie? $s_watching_categorie = array('link' => '', 'link_toggle' => '', 'title' => '', 'title_toggle' => '', 'is_watching' => false); if ($this->config['email_enable'] && $this->user->data['is_registered']) { $notify_status = isset($this->categorie->data['notify_status']) ? $this->categorie->data['notify_status'] : null; if ($message = $this->categorie->watch_categorie($mode, $s_watching_categorie, $this->user->data['user_id'], $cat_id, $notify_status)) { return $this->helper->message($message); } } // A deadline has been selected if ($sort_days) { $min_post_time = time() - $sort_days * 86400; $sql = 'SELECT COUNT(link_id) AS nb_links FROM ' . DIR_LINK_TABLE . ' WHERE link_cat = ' . (int) $cat_id . ' AND link_time >= ' . $min_post_time; $result = $this->db->sql_query($sql); $nb_links = (int) $this->db->sql_fetchfield('nb_links'); $this->db->sql_freeresult($result); if ($this->request->is_set_post('sort')) { $start = 0; } $sql_limit_time = " AND l.link_time >= {$min_post_time}"; } else { $sql_limit_time = ''; $nb_links = (int) $this->categorie->data['cat_links']; } // Make sure $start is set to the last page if it exceeds the amount $start = $this->pagination->validate_start($start, $this->config['dir_show'], $nb_links); // Build navigation links $this->categorie->generate_dir_nav($this->categorie->data); // Jumpbox $this->categorie->make_cat_jumpbox(); $base_url = array('routes' => 'ernadoo_phpbbdirectory_page_controller', 'params' => array_merge(array('cat_id' => $cat_id), $u_sort_param)); $this->pagination->generate_template_pagination($base_url, 'pagination', 'page', $nb_links, $this->config['dir_show'], $start); $this->template->assign_vars(array('S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, 'S_CATLIST' => $this->categorie->make_cat_select($cat_id), 'S_PAGE_ACTION' => $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => $cat_id, 'page' => $page)), 'S_CAT_ID' => $cat_id, 'TOTAL_LINKS' => $this->user->lang('DIR_NB_LINKS', (int) $nb_links), 'U_NEW_SITE' => $this->helper->route('ernadoo_phpbbdirectory_new_controller', array('cat_id' => $cat_id)), 'U_WATCH_CAT' => $s_watching_categorie['link'], 'U_WATCH_CAT_TOGGLE' => $s_watching_categorie['link_toggle'], 'S_WATCH_CAT_TITLE' => $s_watching_categorie['title'], 'S_WATCH_CAT_TOGGLE' => $s_watching_categorie['title_toggle'], 'S_WATCHING_CAT' => $s_watching_categorie['is_watching'])); // If the user is trying to reach late pages, start searching from the end $store_reverse = false; $sql_limit = $this->config['dir_show']; if ($start > $nb_links / 2) { $store_reverse = true; // Select the sort order $direction = $sort_dir == 'd' ? 'ASC' : 'DESC'; $sql_limit = $this->pagination->reverse_limit($start, $sql_limit, $nb_links); $sql_start = $this->pagination->reverse_start($start, $sql_limit, $nb_links); } else { // Select the sort order $direction = $sort_dir == 'd' ? 'DESC' : 'ASC'; $sql_start = $start; } if (is_array($sort_by_sql[$sort_key])) { $sql_sort_order = implode(' ' . $direction . ', ', $sort_by_sql[$sort_key]) . ' ' . $direction; } else { $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . $direction; } // Grab just the sorted link ids $sql_array = array('SELECT' => 'l.link_id', 'FROM' => array(DIR_LINK_TABLE => 'l'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'l.link_user_id = u.user_id')), 'WHERE' => "l.link_cat = {$cat_id}\n\t\t\t\tAND l.link_active = 1\n\t\t\t\t\t{$sql_limit_time}", 'ORDER_BY' => $sql_sort_order); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query_limit($sql, $sql_limit, $sql_start); while ($row = $this->db->sql_fetchrow($result)) { $link_list[] = (int) $row['link_id']; } $this->db->sql_freeresult($result); if (sizeof($link_list)) { // We get links, informations about poster, votes and number of comments $sql_array = array('SELECT' => 'l.link_id, l.link_cat, l.link_url, l.link_user_id, l.link_comment, l. link_description, l.link_banner, l.link_rss, l. link_uid, l.link_bitfield, l.link_flags, l.link_vote, l.link_note, l.link_view, l.link_time, l.link_name, l.link_flag, l.link_pagerank, l.link_thumb, u.user_id, u.username, u.user_colour, v.vote_user_id', 'FROM' => array(DIR_LINK_TABLE => 'l'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'l.link_user_id = u.user_id'), array('FROM' => array(DIR_VOTE_TABLE => 'v'), 'ON' => 'l.link_id = v.vote_link_id AND v.vote_user_id = ' . $this->user->data['user_id'])), 'WHERE' => $this->db->sql_in_set('l.link_id', $link_list)); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); while ($site = $this->db->sql_fetchrow($result)) { $rowset[$site['link_id']] = $site; } $this->db->sql_freeresult($result); $link_list = $store_reverse ? array_reverse($link_list) : $link_list; $votes_status = $this->categorie->data['cat_allow_votes'] ? true : false; $comments_status = $this->categorie->data['cat_allow_comments'] ? true : false; foreach ($link_list as $link_id) { $site =& $rowset[$link_id]; $s_flag = $this->link->display_flag($site); $s_note = $this->link->display_note($site['link_note'], $site['link_vote'], $votes_status); $s_thumb = $this->link->display_thumb($site); $s_vote = $this->link->display_vote($site); $s_banner = $this->link->display_bann($site); $s_pr = $this->link->display_pagerank($site); $s_rss = $this->link->display_rss($site); $edit_allowed = $this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_dir') || $this->user->data['user_id'] == $site['link_user_id'] && $this->auth->acl_get('u_edit_dir')); $delete_allowed = $this->user->data['is_registered'] && ($this->auth->acl_get('m_delete_dir') || $this->user->data['user_id'] == $site['link_user_id'] && $this->auth->acl_get('u_delete_dir')); $this->template->assign_block_vars('site', array('BANNER' => $s_banner, 'COUNT' => $this->user->lang('DIR_NB_CLICKS', (int) $site['link_view']), 'DESCRIPTION' => generate_text_for_display($site['link_description'], $site['link_uid'], $site['link_bitfield'], $site['link_flags']), 'LINK_ID' => $site['link_id'], 'NAME' => $site['link_name'], 'NB_COMMENT' => $comments_status ? $this->user->lang('DIR_NB_COMMS', (int) $site['link_comment']) : '', 'NB_VOTE' => $this->user->lang('DIR_NB_VOTES', (int) $site['link_vote']), 'NOTE' => $s_note, 'PAGERANK' => $s_pr, 'RSS' => $s_rss, 'TIME' => $site['link_time'] ? $this->user->format_date($site['link_time']) : '', 'USER' => get_username_string('full', $site['link_user_id'], $site['username'], $site['user_colour']), 'VOTE_LIST' => $votes_status ? $s_vote : '', 'IMG_FLAG' => $s_flag, 'ON_CLICK' => "onclick=\"window.open('" . $this->helper->route('ernadoo_phpbbdirectory_view_controller', array('link_id' => (int) $site['link_id'])) . "'); return false;\"", 'S_NEW_LINK' => (time() - $site['link_time']) / 86400 <= $this->config['dir_new_time'] ? true : false, 'U_COMMENT' => $comments_status ? $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller', array('link_id' => (int) $site['link_id'])) : '', 'U_DELETE' => $delete_allowed ? $this->helper->route('ernadoo_phpbbdirectory_delete_controller', array('cat_id' => (int) $cat_id, 'link_id' => (int) $site['link_id'], '_referer' => $this->helper->get_current_url())) : '', 'U_EDIT' => $edit_allowed ? $this->helper->route('ernadoo_phpbbdirectory_edit_controller', array('cat_id' => (int) $cat_id, 'link_id' => (int) $site['link_id'])) : '', 'U_FORM_VOTE' => $votes_status ? $this->helper->route('ernadoo_phpbbdirectory_vote_controller', array('cat_id' => (int) $site['link_cat'], 'link_id' => (int) $site['link_id'])) : '', 'U_LINK' => $site['link_url'], 'U_THUMB' => $s_thumb)); } } else { $this->template->assign_block_vars('no_draw_link', array()); } $page_title = $this->user->lang['DIRECTORY'] . ' - ' . $this->categorie->data['cat_name']; $this->categorie->display(); return $this->helper->render('view_cat.html', $page_title); }