示例#1
0
 /**
  * Export a pdf
  *
  * @static
  * @param	string	$title		Document title
  * @param	string	$css		CSS Contents
  * @param	string	$html		HTML Contents
  * @param	string	$page_format 	Default A4
  * @param	string	$orientation	Can be P|L
  * @return boolean
  */
 public static function pdf_export($title, $css, $html, $page_format = 'A4', $orientation = 'P')
 {
     // language set
     $l = array();
     $l['a_meta_charset'] = 'UTF-8';
     $l['a_meta_dir'] = 'rtl';
     $l['a_meta_language'] = X4Route_core::$lang;
     $l['w_page'] = _PAGE;
     X4Core_core::auto_load('mpdf_library');
     // create the PDF object
     $mpdf = new mPDF(X4Route_core::$lang, $page_format, 0, 0, 0, 0, 0, 0, $orientation);
     $title = SERVICE . ' - ' . $title . ' - ' . date('Y-m-d H:i:s');
     $mpdf->SetAuthor($_SESSION['nickname']);
     $mpdf->SetCreator(SERVICE);
     $mpdf->SetTitle($title);
     $mpdf->SetDisplayMode('fullwidth');
     $mpdf->WriteHTML($css, 1);
     $mpdf->WriteHTML($html, 2);
     $filename = X4Utils_helper::unspace(str_replace(' - ', '-', $title), true);
     $mpdf->Output($filename . '.pdf', 'D');
     exit;
 }
示例#2
0
 /**
  * Register Edit / New language 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 permission
     if ($id) {
         $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'languages', $_post['id'], 3);
     } else {
         $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_language_creation', 0, 4);
     }
     if (is_null($msg)) {
         // handle _post
         $post = array('code' => X4Utils_helper::unspace($_post['code']), 'language' => $_post['language'], 'rtl' => intval(isset($_post['rtl'])));
         $lang = new Language_model();
         // check if language already exists
         $check = $lang->exists($post, $id);
         if ($check) {
             $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_LANGUAGE_ALREADY_EXISTS', 'msg'));
         } else {
             // update or insert
             if ($id) {
                 $result = $lang->update($_post['id'], $post);
             } else {
                 $result = $lang->insert($post);
                 // create permissions
                 if ($result[1]) {
                     $perm = new Permission_model();
                     $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4);
                     $res = $perm->pexec('languages', $array, 1);
                 }
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // set what update
             if ($result[1]) {
                 $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'languages', 'title' => null);
             }
         }
     }
     $this->response($msg);
 }
示例#3
0
 /**
  * Create a basic dictionary
  *
  * @param string    $area
  * @param string    $name
  * @return void
  */
 public function dictionary($area, $name)
 {
     if ($area == 'admin') {
         // get the final name
         $name = X4Utils_helper::unspace($name, true, true);
         // create the dictionary section
         $mod = new X3cli_model();
         $res = $mod->create_dictionary($area, $name);
         if (!is_null($res)) {
             echo NL . 'The dictionary section "' . $name . '" was created successfully!' . NL;
         } else {
             echo NL . 'WARNING: an error occurred' . NL;
         }
     } else {
         // dictionary is available only for admin area
         echo NL . 'WARNING: you can create dictionary section only for the "admin" area' . NL;
     }
 }
示例#4
0
 /**
  * Register site data
  *
  * @access	private
  * @param   array 	$_post _POST array
  * @return  void
  */
 private function editing($_post)
 {
     $msg = null;
     // check permission
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'sites', $_post['id'], 4);
     if (is_null($msg)) {
         // handle _post
         $post = array('xcode' => X4Utils_helper::unspace($_post['xcode']), 'domain' => $_post['domain']);
         // do update
         $result = $this->site->update($_post['id'], $post);
         // set message
         $msg = AdmUtils_helper::set_msg($result);
         // set what update
         if ($result[1]) {
             $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'sites/show/1', 'title' => null);
         }
     }
     $this->response($msg);
 }
示例#5
0
 /**
  * Register SEO data
  *
  * @access	private
  * @param   array 	$_post _POST array
  * @return  void
  */
 private function reg_seo($_post)
 {
     $msg = null;
     // check permissions
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'pages', $_post['id'], 2);
     if (is_null($msg)) {
         // get object
         $mod = new Page_model('', '', $_post['id']);
         $page = $mod->get_by_id($_post['id'], 'pages', 'id_area, lang, url, xfrom');
         // this pages cannot be changed
         $no_change = array('home', 'msg', 'search');
         // remove slash from url
         if ($page->id_area > 1) {
             $_post['url'] = str_replace('/', '-', $_post['url']);
         }
         // handle _post
         $post = array('url' => !in_array($page->url, $no_change) ? X4Utils_helper::unspace($_post['url']) : $page->url, 'name' => $_post['name'], 'title' => $_post['title'], 'description' => $_post['description'], 'xfrom' => !in_array($page->url, $no_change) ? $_post['xfrom'] : $page->xfrom, 'hidden' => intval(isset($_post['hidden'])), 'xkeys' => $_post['xkeys'], 'robot' => $_post['robot'], 'redirect_code' => $_post['redirect_code'], 'redirect' => $_post['redirect'], 'tpl' => $_post['tpl']);
         // check if a page with the same URL already exists
         $check = (bool) $mod->exists($post['url'], $_post['id']);
         if ($check) {
             $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_PAGE_ALREADY_EXISTS', 'msg'));
         } else {
             // set css for the page
             $tmod = new Template_model();
             $css = $tmod->get_css($page->id_area, $_post['tpl']);
             $post['css'] = $css;
             // update page data
             $result = $mod->update_page($_post['id'], $post, $this->site->site->domain);
             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]) {
                 $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'pages/index/' . $page->id_area . '/' . $page->lang . '/' . str_replace('/', '-', $page->xfrom) . '/0/', 'title' => null);
             }
         }
     }
     $this->response($msg);
 }
示例#6
0
 /**
  * Register Edit file form data
  *
  * @access	private
  * @param   array 	$_post _POST array
  * @return  void
  */
 private function editing($_post)
 {
     $msg = null;
     // check permission
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'files', $_post['id'], 2);
     if (is_null($msg)) {
         // handle _post
         $post = array('category' => X4Utils_helper::unspace($_post['category']), 'subcategory' => X4Utils_helper::unspace($_post['subcategory']), 'alt' => $_post['alt']);
         // do action
         $mod = new File_model();
         $result = $mod->update($_post['id'], $post);
         // set message
         $msg = AdmUtils_helper::set_msg($result);
         // set what update
         if ($result[1]) {
             $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'files/index/' . $_post['id_area'] . '/' . $post['category'] . '/' . $post['subcategory'], 'title' => null);
         }
     }
     $this->response($msg);
 }
 /**
  * Register Edit / New Category 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 permission
     $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'categories', $_post['id'], 3) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_category_creation', 0, 4);
     if (is_null($msg)) {
         // handle _post
         $post = array('id_area' => $_post['id_area'], 'lang' => $_post['lang'], 'title' => $_post['title'], 'name' => X4Utils_helper::unspace($_post['title']), 'tag' => X4Utils_helper::unspace($_post['tag']));
         $mod = new Category_model();
         // check if category already exists
         $check = $mod->exists($post, $id);
         if ($check) {
             $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_CATEGORY_ALREADY_EXISTS', 'msg'));
         } else {
             // update or insert
             if ($id) {
                 $result = $mod->update($_post['id'], $post);
             } else {
                 $result = $mod->insert($post);
                 // create permissions
                 if ($result[1]) {
                     $perm = new Permission_model();
                     $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4);
                     $res = $perm->pexec('categories', $array, $_post['id_area']);
                 }
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // set what update
             if ($result[1]) {
                 $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'categories/index/' . $post['id_area'] . '/' . $post['lang'] . '/' . $post['tag'], 'title' => null);
             }
         }
     }
     $this->response($msg);
 }
示例#8
0
 /**
  * Get a file
  * the path of the file will remain anonymous
  *
  * @param string	$file file with path
  * @param string	$filename file dname for the download
  * @param boolean	$download force the download
  * @return file
  */
 public static function get_file($file, $filename = '', $download = true)
 {
     if (file_exists($file)) {
         $download_name = empty($filename) ? basename($file) : X4Utils_helper::unspace($filename);
         $mime = self::get_mime($file);
         if ($download) {
             header('Content-Description: File Transfer');
             header('Cache-Control: private');
             header('Content-type: ' . $mime);
             header('Content-Disposition: attachment; filename=' . $download_name);
             header('Content-Transfer-Encoding: Binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate');
             header('Pragma: public');
             header('Content-Length:' . filesize($file));
         } else {
             header('Content-Description: File Transfer');
             header('Cache-Control: private');
             header('Content-type: ' . $mime);
             header('Content-Disposition: inline; filename=' . $download_name);
             header('Content-Transfer-Encoding: Binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate');
             header('Pragma: public');
             // for adobe reader
             if ($mime == 'application/pdf') {
                 header("Content-Range: bytes");
             }
             header('Content-Length:' . filesize($file));
         }
         ob_clean();
         flush();
         readfile($file);
         exit;
     }
 }
 /**
  * Register New dictionary word form data
  *
  * @access	private
  * @param   array 	$_post _POST array
  * @return  void
  */
 private function adding($_post)
 {
     $msg = null;
     // check permission
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_word_creation', 0, 4);
     if (is_null($msg)) {
         // handle _post
         $post = array('lang' => $_post['lang'], 'area' => $_post['area'], 'what' => X4Utils_helper::unspace($_post['what']), 'xkey' => strtoupper(trim($_post['xkey'])), 'xval' => nl2br(trim($_post['xval'])));
         $dict = new Dictionary_model();
         // check if words already exists
         $check = $dict->exists($post);
         if ($check) {
             $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_XKEY_ALREADY_EXISTS', 'msg'));
         } else {
             // insert
             $result = $dict->insert($post);
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // add permission
             if ($result[1]) {
                 $amod = new Area_model();
                 $id_area = $amod->get_area_id($_post['area']);
                 $perm = new Permission_model();
                 $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4);
                 $result = $perm->pexec('dictionary', $array, $id_area);
                 $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'dictionary/keys/' . $post['lang'] . '/' . $post['area'] . '/' . $post['what'], 'title' => null);
             }
         }
     }
     $this->response($msg);
 }
示例#10
0
 /**
  * Register Edit / New Context 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 permission
     $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'contexts', $id, 3) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_context_creation', 0, 4);
     if (is_null($msg)) {
         // handle _post
         $post = array('id_area' => $_post['id_area'], 'lang' => $_post['lang'], 'name' => strtolower($_post['name']), 'xkey' => X4Utils_helper::unspace($_post['name']));
         $mod = new Context_model();
         // check if context already exists
         $check = $mod->exists($post, $id);
         if ($check) {
             $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_CONTEXT_ALREADY_EXISTS', 'msg'));
         } else {
             // update or insert
             if ($id) {
                 $result = $mod->update($id, $post);
                 // check if dictionary name for the context already exists
                 if ($result[1]) {
                     $mod->check_dictionary($post);
                 }
             } else {
                 // get the code of the new context
                 $code = $mod->get_max_code($post['id_area'], $post['lang']);
                 // this implies that the site can't have more than 33 languages
                 // you have 3 default contexts (draft, page, multipages) for each language and for each area
                 $post['code'] = $code > 100 ? $code + 1 : 101;
                 $result = $mod->insert($post);
                 if ($result[1]) {
                     // add item into dictionary
                     $mod->check_dictionary($post, 1);
                     // create permission
                     $perm = new Permission_model();
                     $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4);
                     $res = $perm->pexec('contexts', $array, $post['id_area']);
                 }
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // set what update
             if ($result[1]) {
                 $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'contexts/index/' . $post['id_area'] . '/' . $post['lang'], 'title' => null);
             }
         }
     }
     $this->response($msg);
 }
示例#11
0
    /**
     * Rename area (secret method)
     * If for whatever reason you need to rename an area you can call this script
     * /admin/areas/reaname_area/ID_AREA/NEW_NAME
     *
     * @param   integer $id_area Area ID to rename
     * @param   string  $new_name New name to set
     * @return  string
     */
    public function rename_area($id_area, $new_name)
    {
        // Comment the next row to enable the method
        die('Operation disabled!');
        $mod = new Area_model();
        // clean the new name
        $new = X4Utils_helper::unspace(urldecode($new_name), true);
        // check if already exists
        $chk = $mod->exists($new, $id_area);
        // get the old area name
        $old = $mod->get_var($id_area, 'areas', 'name');
        if (!$chk && $old && $old != $new && strlen($new) > 2) {
            // replace name
            $res = $mod->rename_area($id_area, $old, $new);
            if ($res[1]) {
                echo '<h1>CONGRATULATIONS!</h1>';
                echo '<p>The changes on the database are applied.</p>';
                // print instructions for manual changes
                echo '<p>Follow this instructions to perform manual changes.</p>
				<ul>
					<li>Rename the folder /cms/controllers/' . $old . ' to /cms/controllers/' . $new . '</li>
					<li>Rename the folder /cms/views/' . $old . ' to /cms/views/' . $new . '</li>
					<li>In the file system/core/X4Route_core.php replace the old area name "' . $old . '" with the new "' . $new . '" in the static vars</li>
					<li>In the file cms/config/config.php replace the old area name "' . $old . '" with the new "' . $new . '" in the $default array</li>
				</ul>
				<p>Done!</p>
				
				<p>NOTE: this operation acts on the core system of the CMS, if you use plugins you have to check if they need to be changed.</p>';
            } else {
                echo '<h1>WARNING!</h1>';
                echo '<p>Something went wrong, changes are not applied.</p>';
            }
        } else {
            echo '<h1>WARNING!</h1>';
            if (!$old) {
                echo '<p>Not exists an area with ID ' . $id_area . '.</p>';
            } else {
                if (strlen($new) < 3) {
                    echo '<p>The new name "' . $new . '" is too short (the minimum is 3 chars).</p>';
                }
                if (!$chk) {
                    echo '<p>An area with the same name "' . $new . '" already exists.</p>';
                }
                if ($old == $new) {
                    echo '<p>The old name "' . $old . '" and the new name "' . $new . '" are equal.</p>';
                }
            }
        }
        die;
    }