Exemple #1
0
 /**
  * Get areas data as an array
  * Join with privs table
  *
  * @param   integer $id_area Area ID
  * @return  array	array
  */
 public function get_my_areas($id_area = 0)
 {
     $items = X4Array_helper::indicize($this->get_areas(), 'id');
     // check user group
     $id_group = $this->get_var($_SESSION['xuid'], 'users', 'id_group');
     if ($id_group > 1) {
         unset($items[1]);
     }
     if ($id_area && !isset($items[$id_area])) {
         reset($items);
         $id_area = key($items);
     }
     return array($id_area, $items);
 }
Exemple #2
0
    /**
     * Duplicate area for another language
     *
     * @return  array(array_of_installed_modules, res)
     */
    public function duplicate_area_lang($id_area, $old_lang, $new_lang)
    {
        // sync contexts
        $old = X4Array_helper::indicize($this->db->query('SELECT *
			FROM contexts
			WHERE id_area = ' . intval($id_area) . ' AND lang = ' . $this->db->escape($old_lang) . '
			ORDER BY code ASC'), 'code');
        $new = X4Array_helper::indicize($this->db->query('SELECT *
			FROM contexts
			WHERE id_area = ' . intval($id_area) . ' AND lang = ' . $this->db->escape($new_lang) . '
			ORDER BY code ASC'), 'code');
        // insert contexts
        foreach ($old as $k => $v) {
            if (!in_array($k, $new)) {
                // create the new context
                $post = (array) $v;
                unset($post['id'], $post['updated']);
                $post['lang'] = $new_lang;
                $res = $this->insert($post, 'contexts');
            }
        }
        // sync pages
        // get pages in the old
        $old = X4Array_helper::indicize($this->db->query('SELECT *
			FROM pages
			WHERE id_area = ' . intval($id_area) . ' AND lang = ' . $this->db->escape($old_lang) . '
			ORDER BY ordinal ASC'), 'url');
        // get pages already in new to avoid duplicates
        $new = X4Array_helper::indicize($this->db->query('SELECT *
			FROM pages
			WHERE id_area = ' . intval($id_area) . ' AND lang = ' . $this->db->escape($new_lang) . '
			ORDER BY ordinal ASC'), 'url');
        // memo for modules
        $modules = array();
        $res = 0;
        // insert pages
        foreach ($old as $k => $v) {
            $old_id_page = $v->id;
            $id_page = 0;
            if (!in_array($k, $new)) {
                // create the new page
                $post = (array) $v;
                unset($post['id'], $post['updated']);
                $post['lang'] = $new_lang;
                $res = $this->insert($post, 'pages');
                if ($res[1]) {
                    $id_page = $res[0];
                }
            } else {
                // check for contents
                $id_page = $new[$k]->id;
            }
            if ($id_page) {
                // get sections
                $sections = $this->db->query('SELECT *
                    FROM sections
                    WHERE id_area = ' . intval($id_area) . ' AND id_page = ' . intval($old_id_page) . '
                    ORDER BY progressive ASC');
                if ($sections) {
                    foreach ($sections as $i) {
                        $articles = explode('|', $i->articles);
                        $bids = array();
                        if (!empty($articles)) {
                            foreach ($articles as $ii) {
                                if (!empty($ii)) {
                                    // get the article
                                    $art = $this->db->query_row('SELECT *
                                        FROM articles
                                        WHERE 
                                            id_area = ' . intval($id_area) . ' AND 
                                            lang = ' . $this->db->escape($old_lang) . ' AND 
                                            bid = ' . $this->db->escape($ii) . ' AND 
                                            xon = 1
                                        ORDER BY id DESC');
                                    if ($art) {
                                        $bid = md5($art->id . time() . '-' . $_SESSION['xuid']);
                                        // insert the article
                                        $post = (array) $art;
                                        unset($post['id'], $post['updated']);
                                        $post['bid'] = $bid;
                                        $post['lang'] = $new_lang;
                                        $post['id_page'] = $id_page;
                                        $post['id_editor'] = $_SESSION['xuid'];
                                        $res = $this->insert($post, 'articles');
                                        if ($res[1]) {
                                            // memo for bid
                                            $bids[] = $bid;
                                            // modules
                                            if (!empty($i->module) && !in_array($i->module, $modules)) {
                                                $modules[] = $i->module;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // create section
                        $post = array('id_area' => $id_area, 'id_page' => $id_page, 'progressive' => $i->progressive, 'articles' => implode('|', $bids), 'xon' => 1);
                        $res = $this->insert($post, 'sections');
                    }
                }
            }
        }
        return array($modules, $res);
    }
    /**
     * Get dictionary sections 
     * A section consists of the triad of values language_code-area_name-key_value
     *
     * @return  array	array of objects
     */
    public function get_section_options()
    {
        // sections
        $sections = $this->db->query('SELECT DISTINCT CONCAT(lang, \'-\', area, \'-\', what) AS lang_what 
			FROM dictionary 
			WHERE xon = 1 
			ORDER BY lang_what ASC');
        // to add ALL option
        // areas
        $areas = $this->db->query('SELECT DISTINCT CONCAT(lang, \'-\', area, \'-ALL\') AS lang_what 
			FROM dictionary 
			WHERE xon = 1 
			ORDER BY lang_what ASC');
        // merge
        $res = array_merge($sections, $areas);
        // to array
        $res = X4Array_helper::obj2array($res, null, 'lang_what');
        sort($res);
        // to obj
        return X4Array_helper::array2obj($res);
    }
    /**
     * Edit SEO data of a page (use Ajax)
     *
     * @param   integer  $id Page ID
     * @return  void
     */
    public function seo($id)
    {
        // load dictionaries
        $this->dict->get_wordarray(array('form', 'pages'));
        // get object
        $mod = new Page_model('', '', $id);
        $page = $mod->get_page_by_id($id);
        // build the form
        $fields = array();
        $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $id, 'name' => 'id');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
        $fields[] = array('label' => _FROM_PAGE, 'type' => 'select', 'value' => $page->xfrom, 'options' => array($mod->get_pages('', 0, $page->url), 'url', 'title'), 'name' => 'xfrom', 'rule' => 'required', 'extra' => 'class="large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
        $fields[] = array('label' => _NOT_IN_MAP, 'type' => 'checkbox', 'value' => $page->hidden, 'name' => 'hidden', 'checked' => $page->hidden);
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div id="accordion" class="gap-top">');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h4 class="context">' . _TEMPLATE . '</h4><div class="section">');
        $fields[] = array('label' => _TEMPLATE, 'type' => 'select', 'value' => $page->tpl, 'options' => array($mod->get_templates(), 'name', 'description'), 'name' => 'tpl', 'extra' => 'class="large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><h4 class="context">' . _SEO_TOOLS . '</h4><div class="section">');
        $fields[] = array('label' => _URL, 'type' => 'text', 'value' => $page->url, 'name' => 'url', 'rule' => 'required', 'extra' => 'class="large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
        $fields[] = array('label' => _NAME, 'type' => 'text', 'value' => $page->name, 'name' => 'name', 'rule' => 'required', 'extra' => 'class="large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
        $fields[] = array('label' => _TITLE, 'type' => 'text', 'value' => $page->title, 'name' => 'title', 'rule' => 'required', 'extra' => 'class="large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
        $fields[] = array('label' => _DESCRIPTION, 'type' => 'textarea', 'value' => $page->description, 'name' => 'description');
        $fields[] = array('label' => _KEYS, 'type' => 'textarea', 'value' => $page->xkeys, 'name' => 'xkeys');
        $fields[] = array('label' => _ROBOT, 'type' => 'text', 'value' => $page->robot, 'name' => 'robot', 'suggestion' => _ROBOT_MSG, 'extra' => 'class="large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-fifth xs-one-whole">');
        $codes = array(301, 302);
        $fields[] = array('label' => _REDIRECT_CODE, 'type' => 'select', 'value' => $page->redirect_code, 'name' => 'redirect_code', 'options' => array(X4Array_helper::simplearray2obj($codes, 'value', 'option'), 'value', 'option', 0), 'extra' => 'class="large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="four-fifth xs-one-whole">');
        $fields[] = array('label' => _REDIRECT, 'type' => 'text', 'value' => $page->redirect, 'name' => 'redirect', 'rule' => 'requiredif§redirect_code§!0|url', 'suggestion' => _REDIRECT_MSG, 'extra' => 'class="large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
        // if submitted
        if (X4Route_core::$post) {
            $e = X4Validation_helper::form($fields, 'editor');
            if ($e) {
                $this->reg_seo($_POST);
            } else {
                $this->notice($fields);
            }
            die;
        }
        // contents
        $view = new X4View_core('editor');
        $view->title = _SEO_TOOLS;
        // form builder
        $view->form = '<div id="scrolled">' . X4Form_helper::doform('editor', BASE_URL . 'pages/seo/' . $id, $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\');"') . '</div>';
        $view->js = '
<script>
window.addEvent("domready", function()
{
    var myScroll = new Scrollable($("scrolled"));
	saccordion("accordion", "#accordion h4", "#accordion .section");
});
</script>';
        $view->render(TRUE);
    }