/** * Install a new template (use Ajax) * * @param integer $id_theme Theme ID * @param string $template_name Template name * @return void */ public function install($id_theme, $template_name) { // load dictionaries $this->dict->get_wordarray(array('form', 'templates', 'sections')); // content $view = new X4View_core('editor'); $view->title = _INSTALL_TEMPLATE; // check the template name if (strstr(urldecode($template_name), ' ') != '') { $view->form = '<h2>' . _WARNING . '</h2><p>' . _INVALID_TEMPLATE . BR . '<strong>>> ' . urldecode($template_name) . ' <<</strong><br /> </p>'; } else { // get theme object $mod = new Theme_model(); $theme = $mod->get_by_id($id_theme); // build the form $fields = array(); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $id_theme, 'name' => 'id_theme'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $template_name, 'name' => 'name', 'extra' => 'class="large"'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h4>' . _TEMPLATE . ': ' . $template_name . '</h4>'); $fields[] = array('label' => _DESCRIPTION, 'type' => 'textarea', 'value' => '', 'name' => 'description', 'extra' => 'class="large"'); // load available CSS style sheets $fields[] = array('label' => _CSS, 'type' => 'select', 'value' => 'base', 'options' => array($this->get_css($theme->name), 'value', 'option'), 'name' => 'css', 'extra' => 'class="large"'); $fields[] = array('label' => _SECTIONS, 'type' => 'text', 'value' => 1, 'name' => 'sections', 'rule' => 'required|numeric', 'extra' => 'class="aright large"'); // if submitted if (X4Route_core::$post) { $e = X4Validation_helper::form($fields, 'editor'); if ($e) { $this->installing($_POST); } else { $this->notice($fields); } die; } // form builder $view->form = X4Form_helper::doform('editor', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\');"'); } $view->render(TRUE); }
/** * 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); }
/** * New / Edit area form (use Ajax) * * @param integer $id item ID (if 0 then is a new item) * @return void */ public function edit($id = 0) { // load dictionaries $this->dict->get_wordarray(array('form', 'areas', 'themes')); // handle id $chk = false; if ($id < 0) { $id = 0; $chk = true; } // get area object $mod = new Area_model(); $item = $id ? $mod->get_area_data($id) : new Area_obj(); // build the form $fields = array(); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $id, 'name' => 'id'); // user can't change names of default areas if ($id == 0 || $id > 3) { $fields[] = array('label' => _NAME, 'type' => 'text', 'value' => $item->name, 'name' => 'name', 'rule' => 'required', 'extra' => 'class="large"'); } else { $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h4>' . _AREA . ': ' . $item->name . '</h4>'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->name, 'name' => 'name'); } $fields[] = array('label' => _TITLE, 'type' => 'text', 'value' => $item->title, 'name' => 'title', 'rule' => 'required', 'extra' => 'class="large"'); $fields[] = array('label' => _DESCRIPTION, 'type' => 'textarea', 'value' => $item->description, 'name' => 'description'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">'); // languages section $lang = new Language_model(); $fields[] = array('label' => _ENABLED_LANGUAGES, 'type' => 'select', 'value' => $lang->get_alang_array($id), 'options' => array($lang->get_languages(), 'code', 'language'), 'name' => 'languages', 'rule' => 'required', 'extra' => 'class="large"', 'multiple' => 4); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">'); $fields[] = array('label' => _DEFAULT_LANG, 'type' => 'select', 'value' => $item->code, 'options' => array($lang->get_languages(), 'code', 'language'), 'name' => 'lang', 'rule' => 'inarray§languages', 'extra' => 'class="large"'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>'); // theme section $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->id_theme, 'name' => 'old_id_theme'); // admin area can't change theme if ($id != 1) { $theme = new Theme_model(); $fields[] = array('label' => _THEME, 'type' => 'select', 'value' => $item->id_theme, 'name' => 'id_theme', 'options' => array($theme->get_installed(), 'id', 'description'), 'extra' => 'class="large"'); } else { $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->id_theme, 'name' => 'id_theme'); } $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">'); // areas subsequent to the default can be set as private if ($id == 0 || $id > 3) { $fields[] = array('label' => _FOLDER, 'type' => 'select', 'value' => $item->folder, 'name' => 'folder', 'options' => array($mod->get_folders(), 'folder', 'folder'), 'extra' => 'class="large"'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">'); $fields[] = array('label' => _PRIVATE, 'type' => 'checkbox', 'value' => 1, 'name' => 'private', 'checked' => $item->private); } else { $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->folder, 'name' => 'folder'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->private, 'name' => 'private'); } $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>'); // if submitted if (X4Route_core::$post) { $e = X4Validation_helper::form($fields, 'editor'); if ($e) { $this->editing($id, $_POST); } else { $this->notice($fields); } die; } // contents $view = new X4View_core('editor'); $view->title = $id ? _EDIT_AREA : _ADD_AREA; // form builder $view->form = X4Form_helper::doform('editor', BASE_URL . 'areas/edit/' . $id, $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\');"'); $view->js = ''; if ($id > 0 || $chk) { $view->render(TRUE); } else { return $view->render(); } }