Example #1
0
 /**
  * Display system messages
  *
  * @param   string	$what Dictionary what
  * @param   string	$personal_msg Alternative message
  * @return  void
  */
 public function message($what = '', $personal_msg = '')
 {
     // load dictionary
     $this->dict->get_words();
     // get page
     $page = $this->get_page('msg');
     $view = new X4View_core(X4Utils_helper::set_tpl($page->tpl));
     $view->page = $page;
     // get menus
     $view->navbar = array($this->site->get_bredcrumb($page));
     $view->menus = $this->site->get_menus($page->id_area);
     // content
     $view->args = X4Route_core::$args;
     $qs = !empty(X4Route_core::$query_string) ? X4Route_core::get_query_string() : array();
     // set title
     if (isset($qs['ok'])) {
         switch ($qs['ok']) {
             case 1:
                 $title = _CONGRATULATIONS;
                 break;
             case 2:
                 $title = _MSG_OK;
                 break;
         }
     } else {
         $title = _WARNING;
     }
     // get message
     $msg = empty($personal_msg) ? $this->dict->get_message($title, strtoupper($what), 'msg') : $this->dict->build_message($title, $personal_msg, 'msg');
     $sections = $this->site->get_sections($page->id);
     $sections[1] = array($msg);
     $view->sections = $sections;
     $view->render(TRUE);
 }
Example #2
0
 /**
  * Default call
  *
  * @param string	method name
  * @param array		array of arguments
  * @return string
  */
 public function __call($method, $arguments)
 {
     // Disable auto-rendering
     $this->auto_render = FALSE;
     // By defining a __call method, all pages routed to this controller
     // that result in 404 errors will be handled by this method, instead of
     // being displayed as "Page Not Found" errors.
     echo 'This text is generated by __call.<br />You ask this page: ' . X4Route_core::getRoute();
 }
Example #3
0
 /**
  * Constructor
  * Initialize site model
  * 
  *
  * @return void
  */
 public function __construct()
 {
     parent::__construct('sites');
     // get area
     $this->area = $this->set_data();
     // if no language is set by route set area predefined language
     $this->lang = empty(X4Route_core::$lang) ? $this->area->lang : X4Route_core::$lang;
     // set language
     X4Route_core::set_lang($this->lang);
     // get site
     $this->site = $this->get_site($this->area->id);
     if (!$this->area || !$this->site) {
         header('Location: ' . ROOT . 'public/msg/message/_page_not_found');
         die;
     }
     // set now
     $this->now = time();
     // Load site parameters
     $this->to_define();
 }
 /**
  * Change status
  *
  * @param   string  $what field to change
  * @param   integer $id ID of the item to change
  * @param   integer $value value to set (0 = off, 1 = on)
  * @return  void
  */
 public function set($what, $id, $value = 0)
 {
     $msg = null;
     // check permission
     $val = $what == 'xlock' ? 4 : 3;
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'languages', $id, $val);
     if (is_null($msg)) {
         $qs = X4Route_core::get_query_string();
         // do action
         $lang = new Language_model();
         $result = $lang->update($id, array($what => $value));
         // set message
         $this->dict->get_words();
         $msg = AdmUtils_helper::set_msg($result);
         // set update
         if ($result[1]) {
             $msg->update[] = array('element' => $qs['div'], 'url' => urldecode($qs['url']), 'title' => null);
         }
     }
     $this->response($msg);
 }
Example #5
0
 /**
  * Set the contest
  *
  * @static
  * @return  void
  */
 public static function setCore($default, $db = NULL, $cli = '')
 {
     // set the route
     if (defined('X3CLI') && !empty($cli)) {
         X4Route_core::set_route($cli, $default);
     } else {
         X4Route_core::set_route($_SERVER['REQUEST_URI'], $default);
     }
     // check if controller exists
     self::$controller = X4Route_core::controller_path();
     // set db data
     if (!is_null($db)) {
         self::$db = $db;
     }
     // Start output buffering
     ob_start(array('X4Core_core', 'output_buffer'));
     // Set autoloader
     spl_autoload_register(array('X4Core_core', 'auto_load'));
     // Run the controller
     self::instance();
     // Enable output handling
     self::shutdown();
 }
Example #6
0
 /**
  * Change status
  *
  * @param   string  $what field to change
  * @param   integer $id ID of the item to change
  * @param   integer $value value to set (0 = off, 1 = on)
  * @return  void
  */
 public function set($what, $id, $value = 0)
 {
     $msg = null;
     $mod = new Widget_model();
     $id_user = $mod->get_var($id, 'widgets', 'id_user');
     if ($id_user != $_SESSION['xuid']) {
         $msg = AdminUtils::set_msg(false, '', $this->dict->get_word('_NOT_PERMITTED', 'msg'));
     }
     if (is_null($msg)) {
         $qs = X4Route_core::get_query_string();
         // do action
         $mod = new Widget_model();
         $result = $mod->update($id, array($what => $value));
         // set message
         $this->dict->get_words();
         $msg = AdmUtils_helper::set_msg($result);
         // set update
         if ($result[1]) {
             $msg->update[] = array('element' => $qs['div'], 'url' => urldecode($qs['url']), 'title' => null);
         }
     }
     $this->response($msg);
 }
Example #7
0
 /**
  * Register Edit / New Area form data
  *
  * @access	private
  * @param   integer $id item ID (if 0 then is a new item)
  * @param   array 	$_post _POST array
  * @return  void
  */
 private function editing($id, $_post)
 {
     $msg = null;
     // check permissions
     $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'areas', $id, 2) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_area_creation', 0, 4);
     if (is_null($msg)) {
         // handle _post
         $post = array('lang' => $_post['lang'], 'name' => X4Utils_helper::unspace($_post['name']), 'title' => $_post['title'], 'description' => $_post['description'], 'id_theme' => $_post['id_theme'], 'private' => intval(isset($_post['private'])) && $_post['private'], 'folder' => $_post['folder']);
         $mod = new Area_model();
         // check if area name already exists
         $check = (bool) $mod->exists($post['name'], $id);
         if ($check) {
             $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_AREA_ALREADY_EXISTS', 'msg'));
         } else {
             // Redirect checker
             $redirect = false;
             // enable logs
             if (LOGS && DEVEL) {
                 $mod->set_log(true);
             }
             // update or insert
             if ($id) {
                 $result = $mod->update($id, $post);
                 if ($id == 1 && X4Route_core::$lang != $post['lang']) {
                     $redirect = true;
                 }
             } else {
                 $result = $mod->insert($post);
                 // create permissions
                 if ($result[1]) {
                     $id = $result[0];
                     $perm = new Permission_model();
                     // aprivs permissions
                     $domain = X4Utils_helper::obj2array($perm->get_aprivs($_SESSION['xuid']), null, 'id_area');
                     $domain[] = $result[0];
                     $res = $perm->set_aprivs($_SESSION['xuid'], $domain);
                     // privs permissions
                     $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4);
                     $res = $perm->pexec('areas', $array, $id);
                 }
             }
             if ($result[1]) {
                 // refresh languages related to area
                 $lang = new Language_model();
                 $lang->set_alang($id, $_post['languages'], $_post['lang']);
                 // update theme settings
                 if ($_post['id'] && $_post['id_theme'] != $_post['old_id_theme']) {
                     $menu = new Menu_model();
                     // reset tpl, css, id_menu, ordinal
                     $result = $menu->reset($_post['id']);
                     $langs = $lang->get_languages();
                     // restore ordinal
                     foreach ($langs as $i) {
                         $menu->ordinal($_post['id'], $i->code, 'home', 'A');
                     }
                 }
                 if (APC) {
                     apc_clear_cache();
                     apc_clear_cache('user');
                     apc_clear_cache('opcode');
                 }
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // set what update
             if ($result[1]) {
                 if ($redirect) {
                     X4Route_core::redirect($this->site->site->domain . '/admin');
                 } else {
                     $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'areas', 'title' => null);
                 }
             }
         }
     }
     $this->response($msg);
 }
Example #8
0
 /**
  * Minimize css files
  *
  * @return void
  */
 public function minimize($id_theme, $name)
 {
     $msg = null;
     // check permission
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'themes', $id_theme, 4);
     if (is_null($msg)) {
         $qs = X4Route_core::get_query_string();
         // do action
         $res = 1;
         // get the templates in the theme
         $mod = new Theme_model();
         // CSS section
         $path = PATH . 'themes/' . $name . '/css/';
         $items = $mod->get_css($id_theme);
         foreach ($items as $i) {
             if (file_exists($path . $i->css . '.css')) {
                 $txt = file_get_contents($path . $i->css . '.css');
                 $txt = $mod->compress_css($txt);
                 $chk = file_put_contents($path . $i->css . '.min.css', $txt);
                 if (!$chk) {
                     $res = 0;
                 }
             }
         }
         // JS section
         X4Core_core::auto_load('jshrink_library');
         $path = PATH . 'themes/' . $name . '/js/';
         $items = $mod->get_js($id_theme);
         foreach ($items as $i) {
             if (file_exists($path . $i->js . '.js')) {
                 $txt = file_get_contents($path . $i->js . '.js');
                 $txt = Minifier::minify($txt, array('flaggedComments' => false));
                 $chk = file_put_contents($path . $i->js . '.min.js', $txt);
                 if (!$chk) {
                     $res = 0;
                 }
             }
         }
         $result = array(0, $res);
         // set message
         $this->dict->get_words();
         $msg = AdmUtils_helper::set_msg($result);
         // set update
         if ($result[1]) {
             $msg->update[] = array('element' => $qs['div'], 'url' => urldecode($qs['url']), 'title' => null);
         }
     }
     $this->response($msg);
 }
Example #9
0
 /**
  * Generic page override __call
  *
  * @param string	url/controller name
  * @param array		array of arguments
  * @return void
  */
 public function __call($url, $args)
 {
     // dict
     $this->dict->get_words();
     // get page data
     $page = $this->site->get_page($url);
     if ($page) {
         // check login if area is private
         if ($this->site->area->private && !in_array($url, $this->admitted)) {
             if (file_exists(APATH . 'controllers/' . X4Route_core::$area . '/login.php')) {
                 X4Utils_helper::logged($page->id_area, X4Route_core::$area . '/login');
             } else {
                 X4Utils_helper::logged($page->id_area, 'public/home');
             }
         }
         // set view
         $view = new X4View_core(X4Utils_helper::set_tpl($page->tpl));
         $view->page = $page;
         $view->args = $args;
         // get menus
         $view->menus = $this->site->get_menus($page->id_area);
         $view->navbar = array($this->site->get_bredcrumb($page));
         // get sections
         $view->sections = $this->site->get_sections($page->id);
         $view->render(true);
     } else {
         // check for redirects
         $url = X4Route_core::get_uri();
         $mod = new X4Plugin_model();
         $redirect = $mod->check_redirect(array('Page_model'), $url);
         if (!$redirect) {
             header('HTTP/1.0 404 Not Found');
             header('Location: ' . BASE_URL . 'msg/message/_page_not_found');
         } else {
             // redirect to
             header('Location: ' . $this->site->site->domain . '/' . $redirect->url, true, $redirect->redirect_code);
         }
     }
 }
Example #10
0
 /**
  * Display search results
  *
  * @return  void
  */
 public function _default()
 {
     // load dictionary
     $this->dict->get_wordarray(array('search'));
     // get page data
     $page = $this->get_page('search');
     $view = new X4View_core(X4Utils_helper::set_tpl($page->tpl));
     $view->page = $page;
     // build the message
     $tmp = '';
     // check post
     $is_post = X4Route_core::$post && trim($_POST['search']) != '';
     // check query string
     $is_get = false;
     if (X4Route_core::$query_string) {
         $qs = X4Route_core::get_query_string();
         $is_get = isset($qs['search']) && !empty($qs['search']);
     }
     // search
     // if submitted
     if ($is_post || $is_get) {
         // found counter
         $tot = 0;
         // sanitize
         if ($is_post) {
             $searched = X4Validation_helper::sanitize(strtolower($_POST['search']), 'string');
         } else {
             $searched = $qs['search'];
         }
         // handle _POST
         $str = explode(' ', addslashes($searched));
         // search in area's articles
         $found = $this->site->search($page->id_area, $str);
         // build links to items found
         if ($found) {
             // update counter
             $tot += sizeof($found);
             // set message
             $tmp .= '<h3>' . _SEARCH_PAGES . '</h3><ul class="search_result">';
             // build links to items found
             foreach ($found as $i) {
                 $tmp .= '<li><a href="' . $i->url . '" title="' . stripslashes($i->description) . '">' . stripslashes($i->name) . '</a>' . _TRAIT_ . nl2br(stripslashes($i->description)) . '</li>';
             }
             $tmp .= '</ul>';
         }
         // modules
         $plug = new X4Plugin_model();
         // get searchable plugins
         $searchable = $plug->get_searchable($page->id_area);
         if ($searchable) {
             foreach ($searchable as $i) {
                 // model to load
                 $model = ucfirst($i->name) . '_model';
                 $mod = new $model();
                 // get page URL to use as link
                 if (isset($mod->search_param)) {
                     $to_page = $this->site->get_page_to($page->id_area, $page->lang, $i->name, $mod->search_param);
                 } else {
                     $to_page = $this->site->get_page_to($page->id_area, $page->lang, $i->name, '*');
                 }
                 // perform plugin search
                 $found = $mod->search($page->id_area, $page->lang, $str);
                 // build links to items found
                 if ($found) {
                     // plugin name
                     $plugin = strtoupper($i->name);
                     // update counter
                     $tot += sizeof($found);
                     // set message
                     if (defined('_SEARCH_' . $plugin)) {
                         $tmp .= '<h3>' . constant('_SEARCH_' . $plugin) . '</h3>';
                     }
                     // build links to items found
                     $tmp .= '<ul class="search_result">';
                     foreach ($found as $ii) {
                         // create url
                         $url = isset($mod->personalized_url) && $mod->personalized_url ? $mod->get_url($ii, $to_page) : $to_page . '/' . $ii->id . '/detail';
                         // item name
                         $item = stripslashes($ii->name);
                         $descr = empty($ii->description) ? '' : _TRAIT_ . nl2br(stripslashes($ii->description));
                         // link to item
                         $tmp .= '<li><a href="' . $url . '" title="' . $item . '">' . $item . '</a>' . $descr . '</li>';
                     }
                     $tmp .= '</ul>';
                 }
             }
         }
         // if found
         if ($tot) {
             $tmp = '<p>' . _SEARCH_FOUND . ' ' . $tot . ' ' . _SEARCH_ITEMS . '</p>' . $tmp;
         } else {
             $tmp .= '<p>' . _SEARCH_ZERO_RESULT . '</p>';
         }
         $msg = new Obj_msg(_SEARCH_RESULT, _SEARCH_OF . ' <strong>' . addslashes($searched) . '</strong>' . $tmp, false);
     } else {
         // empty request
         $msg = new Obj_msg(_SEARCH_RESULT, '<p>' . _SEARCH_MSG_SEARCH_EMPTY . '</p>');
     }
     // get menus
     $view->menus = $this->site->get_menus($page->id_area);
     $view->navbar = array($this->site->get_bredcrumb($page));
     // popolate section
     $sections = $this->site->get_sections($page->id);
     $sections[1] = array($msg);
     $view->sections = $sections;
     $view->render(TRUE);
 }
Example #11
0
</title>
<meta name="description" content="<?php 
echo $description;
?>
">
<meta name="robots" content="<?php 
echo $robots;
?>
">
<meta name="keywords" content="<?php 
echo $xkeys;
?>
">

<link rel="canonical" href="<?php 
echo X4Route_core::get_uri();
?>
">
<link rel="sitemap" type="application/xml" title="Sitemap" href="/sitemap.xml">

<link rel="shortcut icon" href="<?php 
echo THEME_URL;
?>
favicon.ico" type="images/x-icon">
<link rel="stylesheet" href="<?php 
echo THEME_URL;
?>
css/bootstrap.min.css">
<?php 
echo !DEVEL && file_exists(PATH . 'themes/' . $this->site->area->theme . '/css/' . $css . '.min.css') ? '<link rel="stylesheet" href="' . THEME_URL . 'css/' . $css . '.min.css">' : '<link rel="stylesheet" href="' . THEME_URL . 'css/' . $css . '.css">';
// if you have to display right-to-left languages
Example #12
0
 /**
  * Change site status
  *
  * @param   integer  $id Site ID
  * @param   integer  $value value to set (0 = off, 1 = on)
  * @return  void
  */
 public function offline($id, $value = 0)
 {
     $this->dict->get_words();
     $msg = null;
     // check permissions
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'sites', $id, 4);
     if (is_null($msg)) {
         $qs = X4Route_core::get_query_string();
         // do action
         $result = $this->site->update($id, array('xon' => $value));
         if (APC) {
             apc_clear_cache();
             apc_clear_cache('user');
             apc_clear_cache('opcode');
         }
         // set message
         $msg = AdmUtils_helper::set_msg($result);
         // set update
         if ($result[1]) {
             $msg->update[] = array('element' => $qs['div'], 'url' => urldecode($qs['url']), 'title' => null);
         }
     }
     $this->response($msg);
 }
Example #13
0
    /**
     * New / Edit article form
     * The form is simplified if site use simple editing
     *
     * @param   integer $id_area Area ID
     * @param   string	$lang Language code
     * @param   integer	$code_context Context code
     * @param   string	$bid, the unique ID of articles
     * @param   integer	$id_page Page ID (for simple editing)
     * @param   boolean	$duplicate Duplicate article resetting bid
     * @return  void
     */
    public function edit($id_area = 2, $lang = '', $code_context = 0, $bid = 0, $id_page = 0, $duplicate = 0)
    {
        // set language
        $lang = empty($lang) ? X4Route_core::$lang : $lang;
        // load dictionaries
        $this->dict->get_wordarray(array('form', 'articles'));
        // referer
        $qs = X4Route_core::get_query_string();
        $referer = isset($qs['ref']) ? $qs['ref'] : '';
        $mod = new Article_model();
        // simple editing
        if ($id_page && $bid != 'x3') {
            $bid = $mod->get_bid_by_id_page($id_page);
        }
        // get object
        $item = $bid && $bid != 'x3' ? $mod->get_by_bid($bid) : new Article_obj($id_area, $lang, $code_context);
        // dedicated page when called from composer
        if ($bid == 'x3') {
            $item->id_page = $id_page;
        }
        // if duplicate reset bid
        if ($duplicate) {
            $item->name = _COPY_OF . ' ' . $item->name;
            $item->bid = $mod->get_new_bid();
        }
        // build the form
        $fields = array();
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band double-inner-pad clearfix"><div id="left-box" class="four-fifth md-three-fourth sm-two-third xs-one-whole">');
        $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $referer, 'name' => 'from');
        $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->bid, 'name' => 'bid');
        $lmod = new Language_model();
        if ($id_page == 0 || $bid == 'x3') {
            // advanced editing
            // area
            $amod = new Area_model();
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band clearfix"><div class="one-fourth sm-one-half pad-right xs-one-whole xs-pad-none">');
            $fields[] = array('label' => _AREA, 'type' => 'select', 'value' => $item->id_area, 'options' => array($amod->get_areas(), 'id', 'name'), 'name' => 'id_area', 'extra' => 'class="large spinner spin2"');
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => 'module|' . BASE_URL . 'articles/refresh_module|id_area', 'name' => 'spinner1_data');
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-fourth sm-one-half pad-right xs-one-whole sm-pad-none">');
            // language
            $fields[] = array('label' => _LANGUAGE, 'type' => 'select', 'value' => $item->lang, 'options' => array($lmod->get_languages(), 'code', 'language'), 'name' => 'lang', 'extra' => 'class="large spinner spin2"');
            // value = id_to_update|url|ids_to_get
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => 'code_context|' . BASE_URL . 'articles/refresh_context|id_area|lang', 'name' => 'spinner2_data');
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-fourth sm-one-half pad-right xs-one-whole xs-pad-none">');
            // contexts
            $cmod = new Context_model();
            $fields[] = array('label' => _CONTEXT, 'type' => 'select', 'value' => $item->code_context, 'options' => array($cmod->get_contexts($item->id_area, $item->lang), 'code', 'name'), 'name' => 'code_context', 'extra' => 'class="large spin2"');
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->code_context, 'name' => 'old_context');
            // value = id_to_update|url|ids_to_get
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => 'id_page|' . BASE_URL . 'articles/refresh_pages|id_area|lang|code_context', 'name' => 'spinner3_data');
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-fourth sm-one-half xs-one-whole">');
            $fields[] = array('label' => _PAGE, 'type' => 'select', 'value' => $item->id_page, 'options' => $item->id_page ? array($cmod->get_pages($item->id_area, $item->lang, 1), 'id', 'name') : array(), 'name' => 'id_page', 'extra' => 'class="large"');
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
        } else {
            // simple editing
            // hidden fields
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->id_area, 'name' => 'id_area');
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->lang, 'name' => 'lang');
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->code_context, 'name' => 'code_context');
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->code_context, 'name' => 'old_context');
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->id_page, 'name' => 'id_page');
        }
        // classification section
        $fields[] = array('label' => _NAME, 'type' => 'text', 'value' => stripslashes($item->name), 'name' => 'name', 'rule' => 'required', 'extra' => 'class="large"');
        // content
        $fields[] = array('label' => _CONTENT, 'type' => 'textarea', 'value' => $item->content, 'name' => 'content');
        if (EDITOR_SCRIPTS) {
            // content
            $fields[] = array('label' => _SCRIPT, 'type' => 'textarea', 'value' => htmlentities($item->js), 'name' => 'js', 'extra' => 'class="NoEditor"', 'suggestion' => _SCRIPT_MSG);
        } else {
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->js, 'name' => 'js');
        }
        // plugin section
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h3>' . _PLUGIN . '</h3>
						<div class="band clearfix"><div class="one-half pad-right">');
        $plugin = new X4Plugin_model();
        // for APC
        $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->module, 'name' => 'old_module');
        $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->param, 'name' => 'old_param');
        $fields[] = array('label' => _MODULE, 'type' => 'select', 'value' => $item->module, 'options' => array($plugin->get_modules($id_area, 0), 'name', 'description', ''), 'name' => 'module', 'extra' => 'class="large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half pad-left">');
        $fields[] = array('label' => _PARAM, 'type' => 'text', 'value' => $item->param, 'name' => 'param', 'extra' => 'class="large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div></div>
				<div id="right-box" class="one-fifth md-one-fourth sm-one-third xs-one-whole xs-hidden">');
        // time window section
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h2>' . _TIME_WINDOW . '</h2><div class="band clearfix inner-pad"><div class="one-half sm-one-whole">');
        $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->date_in, 'name' => 'old_date_in');
        $fields[] = array('label' => _START_DATE, 'type' => 'text', 'value' => date('Y-m-d', $item->date_in), 'name' => 'date_in', 'rule' => 'required|date', 'extra' => 'class="date date_toggled large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half sm-one-whole">');
        $fields[] = array('label' => _END_DATE, 'type' => 'text', 'value' => $item->date_out == 0 ? '' : date('Y-m-d', $item->date_out), 'name' => 'date_out', 'rule' => 'date', 'extra' => 'class="date date_toggled large"', 'suggestion' => _NO_END_MSG);
        // classification section
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div><h2>' . _ORGANIZATION . '</h2>');
        // categories
        $camod = new Category_model();
        $fields[] = array('label' => _CATEGORY, 'type' => 'select', 'value' => $item->category, 'options' => array($camod->get_categories($item->id_area, $item->lang), 'name', 'description', 0), 'name' => 'category', 'extra' => 'class="large"');
        // xkeys
        $fields[] = array('label' => _KEYS, 'type' => 'text', 'value' => $item->xkeys, 'name' => 'xkeys', 'extra' => 'class="large"');
        // tags
        $fields[] = array('label' => _TAGS, 'type' => 'text', 'value' => $item->tags, 'name' => 'tags', 'extra' => 'class="large"');
        // author
        $fields[] = array('label' => _AUTHOR, 'type' => 'text', 'value' => empty($item->author) ? $_SESSION['mail'] : $item->author, 'name' => 'author', 'rule' => 'required', 'extra' => 'class="large"');
        if (EDITOR_OPTIONS) {
            // options section
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h2>' . _OPTIONS . '</h2>
                            <div class="band clearfix">
                                <div class="one-half sm-one-whole">');
            $fields[] = array('label' => _SHOW_AUTHOR, 'type' => 'checkbox', 'value' => $item->show_author, 'name' => 'show_author', 'checked' => $item->show_author);
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half sm-one-whole">');
            $fields[] = array('label' => _SHOW_DATE, 'type' => 'checkbox', 'value' => $item->show_date, 'name' => 'show_date', 'checked' => $item->show_date);
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half sm-one-whole">');
            $fields[] = array('label' => _SHOW_TAGS, 'type' => 'checkbox', 'value' => $item->show_tags, 'name' => 'show_tags', 'checked' => $item->show_tags);
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half sm-one-whole">');
            $fields[] = array('label' => _SHOW_ACTIONS, 'type' => 'checkbox', 'value' => $item->show_actions, 'name' => 'show_actions', 'checked' => $item->show_actions);
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
        }
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
        /*
        // TODO: maybe in the future
        		$fields[] = array(
        			'label' => _SCHEMA,
        			'type' => 'textarea', 
        			'value' => $item->xschema,
        			'name' => 'xschema',
        			'extra' => 'class="mceNoEditor"'
        		);
        */
        // if submitted
        if (X4Route_core::$post) {
            $e = X4Validation_helper::form($fields, 'editor');
            if ($e) {
                $this->editing($item, $_POST);
            } else {
                $this->notice($fields);
            }
            die;
        }
        // content
        $view = new X4View_core('tabber');
        $view->tabs = array();
        $view->down = new X4View_core('editor');
        $view->down->close = false;
        // Set the navbar
        $page = $this->get_page('articles/edit');
        $ref = isset($_SESSION['referer']) ? $_SESSION['referer'] : 'index/' . $id_area . '/' . $lang;
        $navbar = array($this->site->get_bredcrumb($page), array('articles' => $ref));
        $pmod = new Page_model();
        if ($id_page && $bid != 'x3') {
            // simple editing
            $page = $pmod->get_by_id($id_page);
            $view->title = _CONTENT_EDITOR . ' <a class="bta" href="' . BASE_URL . 'pages/index/' . $page->id_area . '/' . $page->lang . '/' . $page->xfrom . '/1" title="' . _GO_BACK . '">' . stripslashes($page->name) . '</a>' . _TRAIT_ . $lang;
            $view->down->js = '';
        } else {
            // generic back
            $back = '<a class="bta" href="' . BASE_URL . 'pages/index/' . $id_area . '/' . $lang . '/home/1" title="' . _GO_BACK . '">' . _PAGES . '</a>';
            if ($bid) {
                if ($item->id_page) {
                    // back to the right page
                    $page = $pmod->get_by_id($item->id_page);
                    $back = ADVANCED_EDITING ? '<a class="bta" href="' . BASE_URL . 'sections/compose/' . $page->id . '" title="' . _GO_BACK . '">' . stripslashes($page->name) . '</a>' : '<a class="bta" href="' . BASE_URL . 'pages/index/' . $page->id_area . '/' . $page->lang . '/' . $page->xfrom . '/1" title="' . _GO_BACK . '">' . stripslashes($page->name) . '</a>';
                }
                $view->title = $back . _TRAIT_ . _EDIT_ARTICLE . _TRAIT_ . $lang;
            } else {
                $view->title = $back . _TRAIT_ . _ADD_ARTICLE . _TRAIT_ . $lang;
            }
            $view->down->js = '
<script>
window.addEvent("domready", function()
{
	if ($chk($("spinner1_data"))) {
		var sdata = $("spinner1_data").get("value").split("|");
		spinnerize(sdata, ".spinner");
	}
	
	if ($chk($("spinner2_data"))) {
		var sdata = $("spinner2_data").get("value").split("|");
		spinnerize(sdata, ".spinner");
	}
	
	if ($chk($("spinner3_data"))) {
		var sdata = $("spinner3_data").get("value").split("|");
		spinnerize(sdata, ".spin2");
	}
});
</script>
			';
        }
        $view->down->js .= '
<script>
window.addEvent("domready", function()
{
	X3.content("filters","articles/filter/' . $id_area . '/' . $lang . '", "' . addslashes(X4Utils_helper::navbar($navbar, ' . ')) . '");
	buttonize("tabber", "bta", "topic");
	pickerize(1);
	
	$("module").addEvent("change", function(event, target){
    	event.preventDefault();
    	v = this.get("value");
    	if (v.length == 0) {
    	   $("param").set("value", "");
    	} else {
    	   X3.modal("", "' . _ARTICLE_PARAM_SETTING . '", "' . BASE_URL . 'articles/param/' . $id_area . '/' . $lang . '/"+v);
    	}
    });
    
    $("param").addEvent("focus", function(event, target){
    	event.preventDefault();
    	m = $("module").get("value");
    	if (m != "") {
            v = this.get("value");
            X3.modal("", "' . _ARTICLE_PARAM_SETTING . '", "' . BASE_URL . 'articles/param/' . $id_area . '/' . $lang . '/"+m+"/"+v);
        }
    });
});
</script>';
        // form builder
        $view->down->form = X4Form_helper::doform('editor', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\', \'content\');"');
        $view->down->tinymce = new X4View_core('tinymce');
        $view->down->tinymce->id_area = $id_area;
        // rtl
        if ($lmod->rtl($lang)) {
            $view->down->tinymce->rtl = 1;
        }
        $view->render(TRUE);
    }
Example #14
0
 /**
  * Initialize area: create default pages
  *
  * @param   integer	$id_area Area ID
  * @param   string	$lang Language code
  * @return  void
  */
 public function init($id_area, $lang)
 {
     $msg = null;
     // check permissions
     $msg = AdmUtils_helper::chklevel($_SESSION['xuid'], '_page_creation', 0, 4);
     if (is_null($msg)) {
         $qs = X4Route_core::get_query_string();
         // get object: the area
         $area = new Area_model();
         $a = $area->get_by_id($id_area);
         $mod = new Page_model($id_area, $lang);
         // build the post array
         $post = array();
         if ($id_area == 1) {
             // admin area
             // uses admin area with language = SESSION['lang'] as base and duplicates all pages
             $pmod = new Page_model($id_area, $_SESSION['lang']);
             $pages = $pmod->get_pages();
             foreach ($pages as $i) {
                 $post[] = array($i->url, array('lang' => $lang, 'id_area' => $id_area, 'xid' => $i->xid, 'url' => $i->url, 'name' => $i->name, 'title' => $i->title, 'description' => $i->description, 'xfrom' => $i->xfrom, 'tpl' => $i->tpl, 'css' => $i->css, 'id_menu' => $i->id_menu, 'xpos' => $i->xpos, 'deep' => $i->deep, 'ordinal' => $i->ordinal, 'xon' => $i->xon));
             }
         } else {
             // other areas
             // home
             $post[] = array('home', array('lang' => $lang, 'id_area' => $id_area, 'xid' => 'pages', 'url' => 'home', 'name' => 'Home page', 'title' => 'Home page', 'description' => 'Home page', 'xfrom' => 'home', 'tpl' => 'base', 'css' => 'base', 'id_menu' => 0, 'xpos' => 0, 'deep' => 0, 'ordinal' => 'A', 'xon' => 1));
             // x3admin
             $post[] = array('x3admin', array('lang' => $lang, 'id_area' => $id_area, 'xid' => 'pages', 'url' => 'x3admin', 'name' => 'Editor', 'title' => 'Editor', 'description' => 'Editor', 'xfrom' => 'home', 'tpl' => 'base', 'css' => 'base', 'id_menu' => 0, 'xpos' => 1, 'deep' => 1, 'ordinal' => 'A0000001', 'hidden' => 1, 'xlock' => 1, 'xon' => 1));
             // msg
             $post[] = array('comunication', array('lang' => $lang, 'id_area' => $id_area, 'xid' => 'pages', 'url' => 'msg', 'name' => 'Communication', 'title' => 'Communication', 'description' => 'Communication', 'xfrom' => 'home', 'tpl' => 'base', 'css' => 'base', 'id_menu' => 0, 'xpos' => 2, 'deep' => 1, 'ordinal' => 'A0000002', 'hidden' => 1, 'xlock' => 1, 'xon' => 1));
             // search
             $post[] = array('search', array('lang' => $lang, 'id_area' => $id_area, 'xid' => 'pages', 'url' => 'search', 'name' => 'Search result', 'title' => 'Search result', 'description' => 'Search result', 'xfrom' => 'home', 'tpl' => 'base', 'css' => 'base', 'id_menu' => 0, 'xpos' => 3, 'deep' => 1, 'ordinal' => 'A0000003', 'hidden' => 1, 'xlock' => 1, 'xon' => 1));
             // if is a private area
             if ($a->private) {
                 // exit
                 $post[] = array('logout', array('lang' => $lang, 'id_area' => $id_area, 'xid' => 'pages', 'url' => 'logout', 'name' => 'Logout', 'title' => 'Logout', 'description' => 'Logout', 'xfrom' => 'home', 'tpl' => 'base', 'css' => 'base', 'id_menu' => 0, 'xpos' => 4, 'deep' => 1, 'ordinal' => 'A0000004', 'hidden' => 0, 'xlock' => 1, 'xon' => 1));
             }
         }
         // action
         $result = $mod->initialize_area($id_area, $lang, $post);
         // set message
         $this->dict->get_words();
         $msg = AdmUtils_helper::set_msg($result);
         if ($result[1]) {
             // create default contexts
             $mod->initialize_context($id_area, $lang);
             // refresh permissions
             $perm = new Permission_model();
             $perm->refactory($_SESSION['xuid']);
             // set update
             $msg->update[] = array('element' => $qs['div'], 'url' => urldecode($qs['url']), 'title' => null);
         }
     }
     $this->response($msg);
 }
Example #15
0
 /**
  * Refresh User permission with group's settings
  * User will keep all customizations
  *
  * @param   integer	$id_user User ID
  * @return  void
  */
 public function refactory($id_user)
 {
     $msg = null;
     // check permission
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'users', $id_user, 3);
     if (is_null($msg)) {
         $qs = X4Route_core::get_query_string();
         // do action
         $mod = new Permission_model();
         $result = $mod->refactory($id_user, null);
         // set message
         $this->dict->get_words();
         $msg = AdmUtils_helper::set_msg($result);
         // set update
         if ($result[1]) {
             $msg->update[] = array('element' => $qs['div'], 'url' => urldecode($qs['url']), 'title' => null);
         }
     }
     $this->response($msg);
 }
Example #16
0
 /**
  * Reset password
  * send an email with new credentials
  *
  * @param   integer	$id User ID
  * @param   string	$md5 Encrypted verification code
  * @return  void
  */
 public function reset($id, $md5)
 {
     $mod = new X4Auth_model('users');
     $user = $mod->get_by_id($id, 'users', 'last_in, password, mail, username');
     $id_area = X4Route_core::get_id_area();
     if ($user) {
         // user exists
         if (md5($user->last_in . SITE . $user->password) == $md5 && time() - strtotime($user->last_in) < 604800) {
             $new_pwd = X4Text_helper::random_string(6);
             $result = $mod->reset($user->mail, $new_pwd);
             if ($result) {
                 // load dictionary
                 $this->dict->get_wordarray(array('login', 'pwd_recovery'));
                 $src = array('XXXUSERNAMEXXX', 'XXXPASSWORDXXX');
                 $rpl = array($user->username, $new_pwd);
                 $view = new X4View_core(X4Utils_helper::set_tpl('mail'));
                 $view->subject = SERVICE . ' - ' . _RECOVERY_SUBJECT;
                 $view->message = str_replace($src, $rpl, _RECOVERY_BODY_RESET);
                 // build msg
                 $body = $view->__toString();
                 $msg = mb_convert_encoding($body, 'ISO-8859-1', 'auto');
                 // recipients
                 $to = array(array('mail' => $user->mail, 'name' => $user->username));
                 $check = X4Mailer_helper::mailto(MAIL, true, $view->subject, $msg, $to, array());
                 X4Utils_helper::set_msg($check, _RECOVERY_PWD_OK, _MSG_ERROR);
                 header('Location: ' . BASE_URL . 'login/recovery');
                 die;
             }
             // log
             if (LOGS) {
                 $mod->logger($user->id, $id_area, 'users', 'recovery password completed for ' . $user->mail);
             }
         } else {
             if (LOGS) {
                 $mod->logger($user->id, $id_area, 'users', 'recovery password failed for ' . $user->mail);
             }
         }
     } else {
         if (LOGS) {
             $mod->logger($user->id, $id_area, 'users', 'recovery password attempt from unknown id ' . $id);
         }
     }
     X4Utils_helper::set_msg(false, '', _RECOVERY_PWD_ERROR);
     header('Location: ' . BASE_URL . 'login/recovery');
     die;
 }
Example #17
0
 /**
  * Install a plugin
  *
  * @param integer	$id_area Area ID
  * @param string	$plugin_name Plugin name
  * @return  void
  */
 public function install($id_area, $plugin_name)
 {
     $msg = null;
     // check permission
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_module_install', 0, 4);
     if (is_null($msg)) {
         $qs = X4Route_core::get_query_string();
         // load global dictionary
         $this->dict->get_words();
         // install the plugin
         $mod = new X4Plugin_model();
         $result = $mod->install($id_area, $plugin_name);
         // the result is an array only if an error occurred
         if (is_array($result) && !empty($result)) {
             // build msg
             $str = array();
             foreach ($result as $i) {
                 $str[] = $i['label'] . _TRAIT_ . $this->dict->get_word(strtoupper($i['error'][0]), 'msg');
             }
             $msg = AdmUtils_helper::set_msg(false, '', implode('<br />', $str));
         } else {
             // set message
             $msg = AdmUtils_helper::set_msg(true);
             // installed
             if ($result) {
                 $area = $mod->get_by_id($id_area, 'areas', 'name');
                 // add permission
                 $mod = new Permission_model();
                 $array[] = array('action' => 'insert', 'id_what' => $result, 'id_user' => $_SESSION['xuid'], 'level' => 4);
                 $result = $mod->pexec('modules', $array, $id_area);
                 // refresh deep, xpos and ordinal
                 $mod = new Menu_model();
                 $mod->ordinal(1, X4Route_core::$lang, 'modules', 'A0021005');
                 $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'modules/index/' . $id_area . '/' . $area->name, 'title' => null);
             }
         }
     }
     $this->response($msg);
 }
Example #18
0
 /**
  * Change status
  *
  * @param   string  $what field to change
  * @param   integer $id ID of the item to change
  * @param   integer $value value to set (0 = off, 1 = on)
  * @return  void
  */
 public function set($what, $id, $value = 0)
 {
     $msg = null;
     // check permission
     $val = $what == 'xlock' ? 4 : 3;
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'contexts', $id, $val);
     if (is_null($msg)) {
         $qs = X4Route_core::get_query_string();
         // do action
         $mod = new Context_model();
         $obj = $mod->get_by_id($id);
         // default contexts cannot change status
         $result = $obj->code > 100 ? $mod->update($id, array($what => $value)) : false;
         // set message
         $this->dict->get_words();
         $msg = AdmUtils_helper::set_msg($result);
         // set update
         if ($result[1]) {
             $msg->update[] = array('element' => $qs['div'], 'url' => urldecode($qs['url']), 'title' => null);
         }
     }
     $this->response($msg);
 }
Example #19
0
 /**
  * get controller path
  *
  * @static
  * @return  string
  */
 public static function controller_path()
 {
     $folder = str_replace('-', '_', self::$folder);
     $control = str_replace('-', '_', self::$control);
     if (file_exists(APATH . 'controllers/' . $folder . '/' . $control . '_controller' . EXT)) {
         // app controller
         return APATH . 'controllers/' . $folder . '/' . $control . '_controller' . EXT;
     } elseif (file_exists(PATH . 'plugins/' . $control . '/controllers/' . $control . '_controller' . EXT)) {
         // plugin controller
         return PATH . 'plugins/' . $control . '/controllers/' . $control . '_controller' . EXT;
     } else {
         // x4page generic controller
         array_unshift(self::$args, self::$method);
         self::$method = self::$control;
         return SPATH . 'controllers/X4Page_controller' . EXT;
     }
 }