/**
  * Display links to Directory
  *
  * @return null
  */
 public function add_page_header_variables()
 {
     $ext_theme_path = $this->dir_helper->get_ext_name() . '/styles/prosilver/theme/';
     $theme_lang_path = $this->user->lang_name;
     // Prevent 'Twig_Error_Loader' if user's lang directory doesn't exist
     if (!file_exists($ext_theme_path . $theme_lang_path . '/directory.css')) {
         // Fallback to English language.
         $theme_lang_path = 'en';
     }
     $this->template->assign_vars(array('T_DIR_THEME_LANG_NAME' => $theme_lang_path, 'U_DIRECTORY' => $this->helper->route('ernadoo_phpbbdirectory_base_controller')));
 }
Example #2
0
    /**
     * Delete category content
     *
     * @return array
     */
    private function _delete_cat_content()
    {
        $this->db->sql_transaction('begin');
        // Before we remove anything we make sure we are able to adjust the post counts later. ;)
        $sql = 'SELECT link_id, link_banner
			FROM ' . DIR_LINK_TABLE . '
			WHERE link_cat = ' . (int) $this->cat_id;
        $result = $this->db->sql_query($sql);
        $link_ids = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $link_ids[] = $row['link_id'];
            if ($row['link_banner'] && !preg_match('/^(http:\\/\\/|https:\\/\\/|ftp:\\/\\/|ftps:\\/\\/|www\\.).+/si', $row['link_banner'])) {
                $banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner']));
                if (file_exists($banner_img)) {
                    @unlink($banner_img);
                }
            }
        }
        $this->db->sql_freeresult($result);
        if (sizeof($link_ids)) {
            // Delete links datas
            $link_datas_ary = array(DIR_COMMENT_TABLE => 'comment_link_id', DIR_VOTE_TABLE => 'vote_link_id');
            foreach ($link_datas_ary as $table => $field) {
                $this->db->sql_query("DELETE FROM {$table} WHERE " . $this->db->sql_in_set($field, $link_ids));
            }
        }
        // Delete cats datas
        $cat_datas_ary = array(DIR_LINK_TABLE => 'link_cat', DIR_WATCH_TABLE => 'cat_id');
        foreach ($cat_datas_ary as $table => $field) {
            $this->db->sql_query("DELETE FROM {$table} WHERE {$field} = " . (int) $this->cat_id);
        }
        $this->db->sql_transaction('commit');
        return array();
    }
Example #3
0
    /**
     * Get orphan banners
     *
     * @param	bool		$delete	True if we want to delete banners, else false
     * @return	null|int	Number of orphan files, else null
     */
    private function _orphan_files($delete = false)
    {
        $banner_path = $this->dir_helper->get_banner_path();
        $imglist = filelist($banner_path);
        $physical_files = $logical_files = $orphan_files = array();
        if (!empty($imglist[''])) {
            $imglist = array_values($imglist);
            $imglist = $imglist[0];
            foreach ($imglist as $img) {
                $physical_files[] = $img;
            }
            $sql = 'SELECT link_banner FROM ' . DIR_LINK_TABLE . '
				WHERE link_banner <> \'\'';
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                if (!preg_match('/^(http:\\/\\/|https:\\/\\/|ftp:\\/\\/|ftps:\\/\\/|www\\.).+/si', $row['link_banner'])) {
                    $logical_files[] = basename($row['link_banner']);
                }
            }
            $this->db->sql_freeresult($result);
            $orphan_files = array_diff($physical_files, $logical_files);
        }
        if (!$delete) {
            return sizeof($orphan_files);
        }
        $dh = @opendir($banner_path);
        while (($file = readdir($dh)) !== false) {
            if (in_array($file, $orphan_files)) {
                @unlink($this->dir_helper->get_banner_path($file));
            }
        }
    }
 /**
  * Disapprove action
  *
  * @return null
  */
 private function _action_disapproved()
 {
     foreach ($this->links_data as $row) {
         if ($row['link_banner'] && !preg_match('/^(http:\\/\\/|https:\\/\\/|ftp:\\/\\/|ftps:\\/\\/|www\\.).+/si', $row['link_banner'])) {
             $banner_img = $this->dir_helper->get_banner_path(basename($row['link_banner']));
             if (file_exists($banner_img)) {
                 @unlink($banner_img);
             }
         }
         $sql = 'DELETE FROM ' . DIR_LINK_TABLE . ' WHERE link_id = ' . (int) $row['link_id'];
         $this->db->sql_query($sql);
     }
 }
Example #5
0
 /**
  * List flags
  *
  * @param	string	$flag_path	The flag directory path
  * @param	string	$value		Selected flag
  * @return	string	$list		Html code
  */
 public function get_dir_flag_list($flag_path, $value)
 {
     $list = '';
     $this->user->add_lang_ext('ernadoo/phpbbdirectory', 'directory_flags');
     $flags = $this->dir_helper->preg_grep_keys('/^DIR_FLAG_CODE_/i', $this->user->lang);
     if (extension_loaded('intl')) {
         $locale = $this->user->lang['USER_LANG'];
         $col = new \Collator($locale);
         $col->asort($flags);
     } else {
         asort($flags);
     }
     foreach ($flags as $file => $name) {
         $img_file = strtolower(substr(strrchr($file, '_'), 1)) . '.png';
         if (file_exists($flag_path . $img_file)) {
             $list .= '<option value="' . $img_file . '" ' . ($img_file == $value ? 'selected="selected"' : '') . '>' . $name . '</option>';
         }
     }
     return $list;
 }
Example #6
0
 /**
  * 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)));
 }
 /**
  * Display cat or subcat
  *
  * @return	null
  */
 public function display()
 {
     $cat_rows = $subcats = array();
     $parent_id = $visible_cats = 0;
     $sql_array = array('SELECT' => 'cat_id, left_id, right_id, parent_id, cat_name, cat_desc, display_subcat_list, cat_desc_uid, cat_desc_bitfield, cat_desc_options, cat_links, cat_icon, cat_count_all', 'FROM' => array(DIR_CAT_TABLE => ''));
     if (empty($this->data)) {
         $root_data = array('cat_id' => 0);
         $sql_where = '';
     } else {
         $root_data = $this->data;
         $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
     }
     $sql = $this->db->sql_build_query('SELECT', array('SELECT' => $sql_array['SELECT'], 'FROM' => $sql_array['FROM'], 'WHERE' => $sql_where, 'ORDER_BY' => 'left_id'));
     $result = $this->db->sql_query($sql);
     $branch_root_id = $root_data['cat_id'];
     while ($row = $this->db->sql_fetchrow($result)) {
         $dir_cat_id = $row['cat_id'];
         if ($row['parent_id'] == $root_data['cat_id'] || $row['parent_id'] == $branch_root_id) {
             // Direct child of current branch
             $parent_id = $dir_cat_id;
             $cat_rows[$dir_cat_id] = $row;
         } else {
             $subcats[$parent_id][$dir_cat_id]['display'] = $row['display_subcat_list'] ? true : false;
             $subcats[$parent_id][$dir_cat_id]['name'] = $row['cat_name'];
             $subcats[$parent_id][$dir_cat_id]['links'] = $row['cat_links'];
             $subcats[$parent_id][$dir_cat_id]['parent_id'] = $row['parent_id'];
         }
     }
     $this->db->sql_freeresult($result);
     foreach ($cat_rows as $row) {
         $visible_cats++;
         $dir_cat_id = $row['cat_id'];
         $subcats_list = array();
         // Generate list of subcats if we need to
         if (isset($subcats[$dir_cat_id])) {
             foreach ($subcats[$dir_cat_id] as $subcat_id => $subcat_row) {
                 $row['cat_links'] = $row['cat_count_all'] ? $row['cat_links'] + $subcat_row['links'] : $row['cat_links'];
                 if ($subcat_row['display'] && $subcat_row['parent_id'] == $dir_cat_id) {
                     $subcats_list[] = array('link' => $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => (int) $subcat_id)), 'name' => $subcat_row['name'], 'links' => $subcat_row['links']);
                 } else {
                     unset($subcats[$dir_cat_id][$subcat_id]);
                 }
             }
         }
         $this->template->assign_block_vars('cat', array('CAT_NAME' => $row['cat_name'], 'CAT_DESC' => generate_text_for_display($row['cat_desc'], $row['cat_desc_uid'], $row['cat_desc_bitfield'], $row['cat_desc_options']), 'CAT_LINKS' => $row['cat_links'], 'CAT_IMG' => $this->dir_helper->get_img_path('icons', $row['cat_icon']), 'U_CAT' => $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => (int) $row['cat_id']))));
         // Assign subcats loop for style authors
         foreach ($subcats_list as $subcat) {
             $this->template->assign_block_vars('cat.subcat', array('U_CAT' => $subcat['link'], 'CAT_NAME' => $subcat['name'], 'CAT_LINKS' => $subcat['links']));
         }
     }
     $this->template->assign_vars(array('S_AUTH_ADD' => $this->auth->acl_get('u_submit_dir'), 'S_AUTH_SEARCH' => $this->auth->acl_get('u_search_dir'), 'S_HAS_SUBCAT' => $visible_cats ? true : false, 'S_ROOT' => empty($this->data), 'U_MAKE_SEARCH' => $this->helper->route('ernadoo_phpbbdirectory_search_controller')));
     // Do the categorie Prune thang - cron type job ...
     if (!$this->config['use_system_cron']) {
         $task = $this->cron->find_task('ernadoo.phpbbdirectory.cron.task.core.prune_categorie');
         $task->set_categorie_data($this->data);
         if ($task->is_ready()) {
             $url = $task->get_url();
             $this->template->assign_var('RUN_CRON_TASK', '<img src="' . $url . '" width="1" height="1" alt="" />');
         }
     }
 }