public function get_search_request($args)
 {
     $search = $args['search'];
     $weight = isset($args['weight']) && is_numeric($args['weight']) ? $args['weight'] : 1;
     require_once PATH_TO_ROOT . '/pages/pages_defines.php';
     $categories = PagesCategoriesCache::load()->get_categories();
     $unauth_cats = '';
     if (!AppContext::get_current_user()->check_auth(PagesConfig::load()->get_authorizations(), READ_PAGE)) {
         $unauth_cats .= '0,';
     }
     foreach ($categories as $id => $cat) {
         if (!AppContext::get_current_user()->check_auth($cat['auth'], READ_PAGE)) {
             $unauth_cats .= $id . ',';
         }
     }
     $unauth_cats = !empty($unauth_cats) ? " AND p.id_cat NOT IN (" . trim($unauth_cats, ',') . ")" : '';
     $results = array();
     $result = PersistenceContext::get_querier()->select("SELECT " . $args['id_search'] . " AS `id_search`,\r\n\t\tp.id AS `id_content`,\r\n\t\tp.title AS `title`,\r\n\t\t( 2 * FT_SEARCH_RELEVANCE(p.title, '" . $args['search'] . "') + FT_SEARCH_RELEVANCE(p.contents, '" . $args['search'] . "') ) / 3 * " . $weight . " AS `relevance`,\r\n\t\tCONCAT('" . PATH_TO_ROOT . "/pages/pages.php?title=',p.encoded_title) AS `link`,\r\n\t\tp.auth AS `auth`\r\n\t\tFROM " . PREFIX . "pages p\r\n\t\tWHERE ( FT_SEARCH(title, '" . $args['search'] . "') OR FT_SEARCH(contents, '" . $args['search'] . "') )" . $unauth_cats . "\r\n\t\tLIMIT 100 OFFSET 0");
     while ($row = $result->fetch()) {
         if (!empty($row['auth'])) {
             $auth = unserialize($row['auth']);
             if (!AppContext::get_current_user()->check_auth($auth, READ_PAGE)) {
                 unset($row['auth']);
                 array_push($results, $row);
             }
         } else {
             unset($row['auth']);
             array_push($results, $row);
         }
     }
     $result->dispose();
     return $results;
 }
 public function get_authorizations()
 {
     require_once PATH_TO_ROOT . '/' . $this->get_module_id() . '/pages_defines.php';
     $page_authorizations = unserialize($this->get_page_authorizations());
     $authorizations = new CommentsAuthorizations();
     if (!empty($page_authorizations)) {
         $authorizations->set_authorized_access_module(AppContext::get_current_user()->check_auth($page_authorizations, READ_PAGE));
     } else {
         $authorizations->set_authorized_access_module(AppContext::get_current_user()->check_auth(PagesConfig::load()->get_authorizations(), READ_PAGE));
     }
     return $authorizations;
 }
 private function get_view()
 {
     global $Bread_crumb, $LANG, $pages;
     $pages_config = PagesConfig::load();
     //Configuration des authorisations
     $config_authorizations = $pages_config->get_authorizations();
     require_once PATH_TO_ROOT . '/pages/pages_begin.php';
     $tpl = new FileTemplate('pages/index.tpl');
     $num_pages = PersistenceContext::get_querier()->count(PREFIX . "pages", 'WHERE redirect = 0');
     $num_coms = CommentsService::get_number_and_lang_comments('pages', $pages['id']);
     $tpl->put_all(array('NUM_PAGES' => sprintf($LANG['pages_num_pages'], $num_pages), 'NUM_COMS' => sprintf($LANG['pages_num_coms'], $num_coms, $num_pages > 0 ? $num_coms / $num_pages : 0), 'L_EXPLAIN_PAGES' => $LANG['pages_explain'], 'L_STATS' => $LANG['pages_stats']));
     //Liste des dossiers de la racine
     $root = '';
     foreach (PagesCategoriesCache::load()->get_categories() as $key => $cat) {
         if ($cat['id_parent'] == 0) {
             //Autorisation particulière ?
             $special_auth = !empty($cat['auth']);
             //Vérification de l'autorisation d'éditer la page
             if ($special_auth && AppContext::get_current_user()->check_auth($cat['auth'], READ_PAGE) || !$special_auth && AppContext::get_current_user()->check_auth($config_authorizations, READ_PAGE)) {
                 $root .= '<li><a href="javascript:open_cat(' . $key . '); show_pages_cat_contents(' . $cat['id_parent'] . ', 0);"><i class="fa fa-folder"></i>' . stripslashes($cat['title']) . '</a></li>';
             }
         }
     }
     //Liste des fichiers de la racine
     $result = PersistenceContext::get_querier()->select("SELECT title, id, encoded_title, auth\r\n\t\t\tFROM " . PREFIX . "pages\r\n\t\t\tWHERE id_cat = 0 AND is_cat = 0\r\n\t\t\tORDER BY is_cat DESC, title ASC");
     while ($row = $result->fetch()) {
         //Autorisation particulière ?
         $special_auth = !empty($row['auth']);
         $array_auth = unserialize($row['auth']);
         //Vérification de l'autorisation d'éditer la page
         if ($special_auth && AppContext::get_current_user()->check_auth($array_auth, READ_PAGE) || !$special_auth && AppContext::get_current_user()->check_auth($config_authorizations, READ_PAGE)) {
             $root .= '<li><a href="' . PagesUrlBuilder::get_link_item($row['encoded_title']) . '"><i class="fa fa-file"></i>' . stripslashes($row['title']) . '</a></li>';
         }
     }
     $result->dispose();
     $tpl->put_all(array('TITLE' => $LANG['pages'], 'L_ROOT' => $LANG['pages_root'], 'ROOT_CONTENTS' => $root, 'L_CATS' => $LANG['pages_cats_tree'], 'L_EXPLORER' => $LANG['pages_explorer'], 'SELECTED_CAT' => 0, 'CAT_0' => 'selected', 'CAT_LIST' => ''));
     $contents = '';
     $result = PersistenceContext::get_querier()->select("SELECT c.id, p.title, p.encoded_title\r\n\t\tFROM " . PREFIX . "pages_cats c\r\n\t\tLEFT JOIN " . PREFIX . "pages p ON p.id = c.id_page\r\n\t\tWHERE c.id_parent = 0\r\n\t\tORDER BY p.title ASC");
     while ($row = $result->fetch()) {
         $sub_cats_number = PersistenceContext::get_querier()->count(PREFIX . "pages_cats", 'WHERE id_parent=:id_parent', array('id_parent' => $row['id']));
         if ($sub_cats_number > 0) {
             $tpl->assign_block_vars('list', array('DIRECTORY' => '<li class="sub"><a class="parent" href="javascript:show_pages_cat_contents(' . $row['id'] . ', 0);"><i class="fa fa-plus-square-o" id="img2_' . $row['id'] . '"></i><i class="fa fa-folder" id ="img_' . $row['id'] . '"></i></a><a id="class_' . $row['id'] . '" href="javascript:open_cat(' . $row['id'] . ');">' . stripslashes($row['title']) . '</a><span id="cat_' . $row['id'] . '"></li>'));
         } else {
             $tpl->assign_block_vars('list', array('DIRECTORY' => '<li class="sub"><a id="class_' . $row['id'] . '" href="javascript:open_cat(' . $row['id'] . ');"><i class="fa fa-folder"></i>' . stripslashes($row['title']) . '</a><span id="cat_' . $row['id'] . '"></span></li>'));
         }
     }
     $result->dispose();
     return $tpl;
 }
 public function get_actions_tree_links()
 {
     global $LANG;
     load_module_lang('pages');
     //Chargement de la langue du module.
     require_once PATH_TO_ROOT . '/pages/pages_defines.php';
     $current_user = AppContext::get_current_user();
     $config = PagesConfig::load();
     $tree = new ModuleTreeLinks();
     $manage_ranks_link = new AdminModuleLink($LANG['pages_manage'], new Url('/pages/pages.php'));
     $manage_ranks_link->add_sub_link(new AdminModuleLink($LANG['pages_manage'], new Url('/pages/pages.php')));
     $manage_ranks_link->add_sub_link(new AdminModuleLink($LANG['pages_create'], new Url('/pages/post.php')));
     $tree->add_link($manage_ranks_link);
     $tree->add_link(new AdminModuleLink(LangLoader::get_message('configuration', 'admin'), new Url('/pages/admin_pages.php')));
     if (!$current_user->check_level(User::ADMIN_LEVEL)) {
         $tree->add_link(new ModuleLink($LANG['pages_create'], new Url('/pages/post.php'), $current_user->check_auth($config->get_authorizations(), EDIT_PAGE)));
     }
     $tree->add_link(new ModuleLink($LANG['pages_redirection_manage'], new Url('/pages/action.php'), $current_user->check_auth($config->get_authorizations(), EDIT_PAGE)));
     $tree->add_link(new ModuleLink($LANG['pages_explorer'], new Url('/pages/explorer.php'), $current_user->check_auth($config->get_authorizations(), EDIT_PAGE)));
     return $tree;
 }
    function get_feed_data_struct($idcat = 0, $name = '')
    {
        global $LANG;
        $querier = PersistenceContext::get_querier();
        $pages_config = PagesConfig::load();
        if (!defined('READ_PAGE')) {
            require_once PATH_TO_ROOT . '/pages/pages_defines.php';
        }
        load_module_lang('pages');
        $data = new FeedData();
        $data->set_title($LANG['pages_rss_desc']);
        $data->set_date(new Date());
        $data->set_link(SyndicationUrlBuilder::rss('pages', $idcat));
        $data->set_host(HOST);
        $data->set_desc($LANG['pages_rss_desc']);
        $data->set_lang($LANG['xml_lang']);
        $data->set_auth_bit(READ_PAGE);
        $where_clause = !empty($idcat) ? ' WHERE p.id_cat = :idcat' : '';
        $results = $querier->select('SELECT p.*
			FROM ' . PREFIX . 'pages p ' . $where_clause . '
			ORDER BY p.timestamp DESC LIMIT :limit OFFSET 0', array('idcat' => $idcat, 'limit' => 10));
        // Generation of the feed's items
        foreach ($results as $row) {
            $item = new FeedItem();
            $link = new Url(PagesUrlBuilder::get_link_item($row['encoded_title']));
            $item->set_title(stripslashes($row['title']));
            $item->set_link($link);
            $item->set_guid($link);
            $item->set_desc(preg_replace('`\\[page\\](.+)\\[/page\\]`U', '<br /><strong>$1</strong><hr />', FormatingHelper::second_parse($row['contents'])));
            $item->set_date(new Date($row['timestamp'], Timezone::SERVER_TIMEZONE));
            $item->set_auth(empty($row['auth']) ? $pages_config->get_authorizations() : unserialize($row['auth']));
            $data->add_item($item);
        }
        $results->dispose();
        return $data;
    }
 private function create_module_map_sections($id_cat, $auth_mode)
 {
     global $LANG;
     $pages_config = PagesConfig::load();
     $categories_cache = PagesCategoriesCache::load();
     $categories = $categories_cache->get_categories();
     //Configuration des authorisations
     $config_authorizations = $pages_config->get_authorizations();
     $this_category = new SitemapLink($categories[$id_cat]['title'], new Url('/pages/' . url('pages.php?title=' . Url::encode_rewrite($categories[$id_cat]['title']), Url::encode_rewrite($categories[$id_cat]['title']))));
     $category = new SitemapSection($this_category);
     $i = 0;
     $keys = array_keys($categories);
     $num_cats = $categories_cache->get_number_categories();
     $properties = array();
     for ($j = 0; $j < $num_cats; $j++) {
         $id = $keys[$j];
         $properties = $categories[$id];
         if ($auth_mode == Sitemap::AUTH_PUBLIC) {
             $this_auth = is_array($properties['auth']) ? Authorizations::check_auth(RANK_TYPE, User::VISITOR_LEVEL, $properties['auth'], READ_PAGE) : Authorizations::check_auth(RANK_TYPE, User::VISITOR_LEVEL, $config_authorizations, READ_PAGE);
         } elseif ($auth_mode == Sitemap::AUTH_USER) {
             if (AppContext::get_current_user()->get_level() == User::ADMIN_LEVEL) {
                 $this_auth = true;
             } else {
                 $this_auth = is_array($properties['auth']) ? Authorizations::check_auth(RANK_TYPE, AppContext::get_current_user()->get_level(), $properties['auth'], READ_PAGE) : Authorizations::check_auth(RANK_TYPE, AppContext::get_current_user()->get_level(), $config_authorizations, READ_PAGE);
             }
         }
         if ($this_auth && $id != 0 && $properties['id_parent'] == $id_cat) {
             $category->add($this->create_module_map_sections($id, $auth_mode));
             $i++;
         }
     }
     if ($i == 0) {
         $category = $this_category;
     }
     return $category;
 }
Example #7
0
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*
 ###################################################*/
require_once '../kernel/begin.php';
require_once 'pages_defines.php';
//Titre de l'article à afficher en version imprimable
$encoded_title = retrieve(GET, 'title', '', TSTRING);
$pages_config = PagesConfig::load();
if (!empty($encoded_title)) {
    try {
        $page_infos = PersistenceContext::get_querier()->select_single_row(PREFIX . 'pages', array('id', 'title', 'auth', 'is_cat', 'id_cat', 'hits', 'count_hits', 'activ_com', 'redirect', 'contents'), 'WHERE encoded_title = :encoded_title', array('encoded_title' => $encoded_title));
    } catch (RowNotFoundException $e) {
        $error_controller = PHPBoostErrors::unexisting_page();
        DispatchManager::redirect($error_controller);
    }
    $num_rows = !empty($page_infos['title']) ? 1 : 0;
    if ($page_infos['redirect'] > 0) {
        $redirect_title = stripslashes($page_infos['title']);
        $redirect_id = $page_infos['id'];
        try {
            $page_infos = PersistenceContext::get_querier()->select_single_row(PREFIX . 'pages', array('id', 'title', 'auth', 'is_cat', 'id_cat', 'hits', 'count_hits', 'activ_com', 'redirect', 'contents'), 'WHERE id = :id', array('id' => $page_infos['redirect']));
        } catch (RowNotFoundException $e) {
            $error_controller = PHPBoostErrors::unexisting_page();