/** * 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); }
/** * Admin area dashboard * This page displays Notices and Bookmarks * * @return void */ public function dashboard() { // load dictionaries $this->dict->get_wordarray(array('widgets', 'home')); // get page $page = $this->get_page('home'); $view = new X4View_core(X4Utils_helper::set_tpl($page->tpl)); $view->page = $page; // content $view->content = new X4View_core('home'); // notices $view->content->notices = NOTICES ? $this->get_notices($page->lang) : ''; // widgets $mod = new Widget_model(); $view->content->widgets = $mod->widgets(); $view->render(TRUE); }
/** * Display system messages * * @param string $what Dictionary what * @return void */ public function message($what = '') { // load global 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->menus = $this->site->get_menus($page->id_area); $view->navbar = array($this->site->get_bredcrumb($page)); // content $view->args = X4Route_core::$args; $view->content = new X4View_core('msg'); $view->content->title = _WARNING; // load the message $view->content->msg = $this->dict->get_word($what, 'msg'); $view->render(TRUE); }
/** * 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 = ''; // search // if submitted if (X4Route_core::$post && trim($_POST['search']) != '') { // found counter $tot = 0; // sanitize $str = X4Validation_helper::sanitize(strtolower($_POST['search']), 'string'); // handle _POST $str = explode(' ', addslashes($str)); // 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 .= '<strong>' . _SEARCH_PAGES . '</strong></p><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 .= '<strong>' . constant('_SEARCH_' . $plugin) . '</strong></p>'; } // 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); $description = empty($ii->description) ? '' : _TRAIT_ . stripslashes($ii->description); // link to item $tmp .= '<li><a href="' . $url . '" title="' . $item . '">' . $item . '</a>' . $description . '</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($_POST['search']) . '</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); }
/** * Edit article by ID * * @param integer $id Article ID * @return void */ public function edit($id = 0) { if ($id == 0) { $this->_default(); } else { // load dictionaries $this->dict->get_wordarray(array('form', 'articles')); // get object $mod = new Article_model(); $i = $mod->get_by_id($id); // cannot edit locked items if ($i->xlock == 1) { $this->_default(); } // switch editor // default use Tiny MCE if (empty($i->xschema)) { // tinymce $fields = array(); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => 0, 'name' => 'schema'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $_SERVER["HTTP_REFERER"], 'name' => 'from'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $i->bid, 'name' => 'bid'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $i->id_area, 'name' => 'id_area'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $i->lang, 'name' => 'lang'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $i->code_context, 'name' => 'code_context'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $i->id_page, 'name' => 'id_page'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $i->xkeys, 'name' => 'xkeys'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => stripslashes($i->name), 'name' => 'name'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $i->module, 'name' => 'module'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $i->param, 'name' => 'param'); // the only field not hidden $fields[] = array('label' => '', 'type' => 'textarea', 'value' => $i->content, 'name' => 'content'); } else { // TODO: schema editor } } // if submitted if (X4Route_core::$post) { $e = X4Validation_helper::form($fields, 'editor'); if ($e) { $this->editing($id, $_POST); die; } else { X4Utils_helper::set_error($fields); } } // get page $page = $this->get_page('x3admin'); $view = new X4View_core(X4Utils_helper::set_tpl($page->tpl)); $view->page = $page; // get menus $view->menus = $this->site->get_menus($page->id_area); $view->navbar = array($this->site->get_bredcrumb($page)); // sections $view->args = array(); $view->sections = array('', ''); // content $view->content = new X4View_core('editor'); $view->content->title = _EDIT_ARTICLE; // form builder $view->content->form = X4Form_helper::doform('editor', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons')); if (empty($i->xschema)) { $view->content->tinymce = new X4View_core('tinymce'); $view->content->tinymce->id_area = $page->id_area; $view->content->tinymce->tinybrowser = true; } $view->render(TRUE); }
/** * 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'); 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, 1, 'users', 'recovery password completed for ' . $user->mail); } } else { if (LOGS) { $mod->logger($user->id, 1, 'users', 'recovery password failed for ' . $user->mail); } } } else { if (LOGS) { $mod->logger($user->id, 1, 'users', 'recovery password attempt from unknown id ' . $id); } } X4Utils_helper::set_msg(false, '', _RECOVERY_PWD_ERROR); header('Location: ' . BASE_URL . 'login/recovery'); die; }
/** * 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); } } }