public function save() { if (!$this->issetErrors() && (empty($this->values['d_name']) || empty($this->values['d_def_lang']) || empty($this->values['d_email']) || empty($this->values['d_sitename']))) { $this->newError(61, 'Не все обязательные поля были заполнены!'); } if ($this->issetErrors()) { return false; } else { if (!empty($this->id)) { // Изменение домена $sql = $this->getSql(); if (!empty($sql)) { db::q('UPDATE <<domains>> SET ' . $sql . ' WHERE d_id = "' . $this->id . '";'); } system::log('Изменен домен "' . $this->values['d_name'] . '" (id:' . $this->id . ')', warning); // Переименовываем папки с шаблонами if ($this->old_name != $this->values['d_name']) { $lang = languages::getAll(); while (list($key, $val) = each($lang)) { if ($this->id != 1 || $val['l_id'] != 1) { $old_name = '/__' . str_replace('.', '_', $this->old_name) . '_' . $val['l_prefix']; $new_name = '/__' . str_replace('.', '_', $this->values['d_name']) . '_' . $val['l_prefix']; @rename(TEMPL_DIR . $old_name, TEMPL_DIR . $new_name); } } } return true; } else { // Добавление домена $sql = $this->getSql(); if (!empty($sql)) { $this->id = db::q('INSERT INTO <<domains>> SET ' . $sql . ';'); } if (!empty($this->id)) { $lang = languages::getAll(); while (list($key, $val) = each($lang)) { rights::createForStructure($this->id, $val['id']); $templ = new template(); $templ->setName('default'); $templ->setFile('default'); $templ->setLangId($val['id']); $templ->setDomainId($this->id); $templ->save(); reg::setKey('/structure/' . $this->id . '/' . $val['id'] . '/title_prefix', '%text% | ' . $this->values['d_sitename']); reg::setKey('/structure/' . $this->id . '/' . $val['id'] . '/view_as_tree', 1); $dname = '/__' . str_replace('.', '_', $this->values['d_name']) . '_' . $val['l_prefix']; $this->copyDir(TEMPL_DIR, TEMPL_DIR . $dname); } system::log('Создан домен "' . $this->values['d_name'] . '" (id:' . $this->id . ')', warning); return true; } else { $this->newError(62, 'Произошла ошибка при добавлении домена!'); system::log('Произошла ошибка при добавлении домена!', error); return false; } } } }
/** * Speichert Template in Dateisystem * @return boolean */ public function save() { $this->content = strip_tags($this->content); $this->content = $this->events->runEvent('templateSave', array('file' => $this->fullpath, 'content' => $this->content))['content']; return parent::save(); }
public function save() { if (!$this->issetErrors() && (empty($this->values['l_name']) || empty($this->values['l_prefix']))) { $this->newError(52, 'Поля "Название" и "Префикс" обязательны для заполнения!'); } if ($this->issetErrors()) { return false; } else { if (!empty($this->id)) { // Изменение языка $sql = $this->getSql(); if (!empty($sql)) { db::q('UPDATE <<langs>> SET ' . $sql . ' WHERE l_id = "' . $this->id . '";'); } system::log('Изменена языковая версия сайта "' . $this->values['l_name'] . '" (id:' . $this->id . ')', warning); // Переименовываем папки с шаблонами if ($this->old_prefix != $this->values['l_prefix']) { $domain = domains::getAll(); while (list($key, $val) = each($domain)) { if ($this->id != 1 || $val['d_id'] != 1) { $old_name = '/__' . str_replace('.', '_', $val['d_name']) . '_' . $this->old_prefix; $new_name = '/__' . str_replace('.', '_', $val['d_name']) . '_' . $this->values['l_prefix']; @rename(TEMPL_DIR . $old_name, TEMPL_DIR . $new_name); } } } return true; } else { // Добавление языка $sql = $this->getSql(); if (!empty($sql)) { $this->id = db::q('INSERT INTO <<langs>> SET ' . $sql . ';'); } if (is_numeric($this->id)) { // Добавляем для каждого домена право и шаблон $domain = domains::getAll(); while (list($key, $val) = each($domain)) { rights::createForStructure($val['id'], $this->id); $templ = new template(); $templ->setName('default'); $templ->setFile('default'); $templ->setLangId($this->id); $templ->setDomainId($val['id']); $templ->save(); reg::setKey('/structure/' . $val['id'] . '/' . $this->id . '/title_prefix', '%text% | ' . $val['d_sitename']); reg::setKey('/structure/' . $val['id'] . '/' . $this->id . '/view_as_tree', 1); // Создаем папки с шаблонами $dname = '/__' . str_replace('.', '_', $val['d_name']) . '_' . $this->values['l_prefix']; $this->copyDir(TEMPL_DIR, TEMPL_DIR . $dname); } system::log('Создана новая языковая версия сайта "' . $this->values['l_name'] . '" (id:' . $this->id . ')', warning); return true; } else { $this->newError(53, 'Произошла ошибка при добавление языка!'); system::log('Произошла ошибка при добавление языка!', error); return false; } } } }
private function createTemplate($field_name) { $id = 0; $type = $field_name == 'template_id' ? 0 : 1; if (!empty($_POST[$field_name . '_new_val']) && !empty($_POST[$field_name . '_new_val2'])) { $templ = new template($id); $templ->setName($_POST[$field_name . '_new_val']); $templ->setFile($_POST[$field_name . '_new_val2']); $templ->setDestination($type); $templ->setLangId(languages::curId()); $templ->setDomainId(domains::curId()); $id = $templ->save(); } if (!empty($id)) { $_POST[$field_name] = $id; } }
function changeTempl($id, $obj, $form_name) { $type = $form_name == 'page_tpl' ? 0 : 1; $templ = new template($id); $templ->setName($obj['t_name']); $templ->setFile($obj['t_file']); $templ->setDestination($type); $templ->setLangId(languages::curId()); $templ->setDomainId(domains::curId()); $templ->save(); return true; }
function run() { global $user; global $layout; global $DB; global $website; $out = ''; $item = new template(); switch ($_REQUEST['act']) { case 'json': case 1: // json data retrieval & operations switch ($_REQUEST['oper']) { case 'del': // remove rows $ids = $_REQUEST['ids']; foreach ($ids as $id) { $item->load($id); $item->delete(); } echo json_encode(true); break; default: // list or search // we have to merge the theme templates with the custom private templates (which are defined in the DB) // as we don't expect a lot of templates, we will always return the whole dataset // for this reason, paginate is useless $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord']; if (isset($_REQUEST['quicksearch'])) { $dataset = template::search($orderby, array('quicksearch' => $_REQUEST['quicksearch'])); } else { $dataset = template::search($orderby); } $total = count($dataset); $out = array(); $permissions = array(0 => '<img src="img/icons/silk/world.png" align="absmiddle" /> ' . t(69, 'Published'), 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" /> ' . t(70, 'Private'), 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" /> ' . t(81, 'Hidden')); if (empty($dataset)) { $rows = 0; } else { $rows = count($dataset); } for ($i = 0; $i < $rows; $i++) { $out[$i] = array(0 => $dataset[$i]['id'], 1 => $dataset[$i]['title'], 2 => $dataset[$i]['theme'], 3 => $permissions[$dataset[$i]['permission']], 4 => $dataset[$i]['enabled'] == 1 ? '<img src="img/icons/silk/accept.png" />' : '<img src="img/icons/silk/cancel.png" />'); } navitable::jqgridJson($out, 1, 0, PHP_INT_MAX, $total); break; } core_terminate(); break; case 'load': case 2: // edit/new form if (!empty($_REQUEST['id'])) { if (is_numeric($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); } else { $item->load_from_theme($_REQUEST['id']); } } if (isset($_REQUEST['form-sent'])) { $item->load_from_post(); try { $item->save(); if (!empty($_REQUEST['property-enabled'])) { $enableds = array_values($_REQUEST['property-enabled']); } else { $enableds = array(); } property::reorder("template", $item->id, $_REQUEST['template-properties-order'], $enableds); $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check'); } catch (Exception $e) { $layout->navigate_notification($e->getMessage(), true, true); } users_log::action($_REQUEST['fid'], $item->id, 'save', $item->title, json_encode($_REQUEST)); } else { users_log::action($_REQUEST['fid'], $item->id, 'load', $item->title); } $out = templates_form($item); break; case 'save_template_file': // save template html if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); } $data = $_REQUEST['templates-file-edit-area']; $data = str_replace("\r\n", "\r", $data); $x = file_put_contents(NAVIGATE_PRIVATE . '/' . $website->id . '/templates/' . $item->file, $data); echo json_encode($x > 0); session_write_close(); exit; break; case 4: // remove if (!empty($_REQUEST['id'])) { $item->load(intval($_REQUEST['id'])); if ($item->delete() > 0) { $layout->navigate_notification(t(55, 'Item removed successfully.'), false); $out = templates_list(); } else { $layout->navigate_notification(t(56, 'Unexpected error.'), false); $out = webdictionary_list(); } users_log::action($_REQUEST['fid'], $item->id, $item->title, 'remove'); } break; case 'template_property_load': $property = new property(); if (!empty($_REQUEST['id'])) { if (is_numeric($_REQUEST['id'])) { $property->load(intval($_REQUEST['id'])); } else { $property->load_from_theme($_REQUEST['id'], null, 'template', $_REQUEST['template']); } } header('Content-type: text/json'); $types = property::types(); $property->type_text = $types[$property->type]; echo json_encode($property); session_write_close(); exit; break; case 'template_property_save': // save property details $property = new property(); if (!empty($_REQUEST['property-id'])) { $property->load(intval($_REQUEST['property-id'])); } $property->load_from_post(); $property->save(); header('Content-type: text/json'); $types = property::types(); $property->type_text = $types[$property->type]; echo json_encode($property); session_write_close(); exit; break; case 'template_property_remove': // remove property $property = new property(); if (!empty($_REQUEST['property-id'])) { $property->load(intval($_REQUEST['property-id'])); } $property->delete(); session_write_close(); exit; break; case 0: // list / search result // list / search result default: $out = templates_list(); break; } return $out; }