public function RewriteVocabularyFile($all_languages = false) { // Block all operations in demo mode if (strtolower(SITE_MODE) == 'demo') { $this->error = _OPERATION_BLOCKED; return false; } $languages = Languages::GetAllLanguages(' priority_order ASC', '', !$all_languages ? ' abbreviation = \'' . $this->languageId . '\'' : ''); $nl = "\n"; for ($i = 0; $i < $languages[1]; $i++) { $this->GetVocabulary(' AND language_id = \'' . $languages[0][$i]['abbreviation'] . '\''); $string_data = '<?php' . $nl; for ($j = 0; $j < $this->vocabularySize; $j++) { $replace_from = array('"', '\\', '$'); $replace_to = array('"', '\\\\', '$'); $key_text = str_replace($replace_from, $replace_to, $this->keys[$j]['key_text']); // double slashes $string_data .= 'define("' . $this->keys[$j]['key_value'] . '","' . $key_text . '");' . $nl; } $string_data .= $nl . '?>'; // Write data to the file $voc_file = 'include/messages.' . $languages[0][$i]['abbreviation'] . '.inc.php'; @chmod($voc_file, 0755); $fh = @fopen($voc_file, 'w'); if (!$fh) { $this->error = 'Cannot open vocabulary file: ' . $voc_file; } else { @fwrite($fh, $string_data); @fclose($fh); } @chmod($voc_file, 0644); } return true; }
/** * After Insert Record */ public function BeforeDeleteRecord() { $all_languages = Languages::GetAllLanguages('', '', 'is_active = 1'); $this->d_languages_count = $all_languages[1]; if ($this->d_languages_count <= 1) { $this->error = _LANG_DELETE_LAST_ERROR; return false; } // define language's abbreviation $sql = 'SELECT * FROM ' . TABLE_LANGUAGES . ' WHERE id = ' . (int) $this->curRecordId; if ($d_language = database_query($sql, DATA_ONLY, FIRST_ROW_ONLY)) { $this->d_language_abbrev = $d_language['abbreviation']; $this->d_priority_order = $d_language['priority_order']; } return true; }
/** * Creates new page * @param $params - set of fields * @param $copy_to_other_langs */ public function PageCreate($params = array(), $copy_to_other_langs = 'yes') { // Get input parameters if (isset($params['content_type'])) { $this->page['content_type'] = $params['content_type']; } if (isset($params['link_url'])) { $this->page['link_url'] = $params['link_url']; } if (isset($params['link_target'])) { $this->page['link_target'] = $params['link_target']; } if (isset($params['page_title'])) { $this->page['page_title'] = $params['page_title']; } if (isset($params['page_key'])) { $this->page['page_key'] = $params['page_key']; } if (isset($params['page_text'])) { $this->page['page_text'] = $params['page_text']; } if (isset($params['menu_id'])) { $this->page['menu_id'] = $params['menu_id']; } if (isset($params['menu_link'])) { $this->page['menu_link'] = $params['menu_link']; } if (isset($params['is_published'])) { $this->page['is_published'] = $params['is_published']; } if (isset($params['language_id'])) { $this->page['language_id'] = $params['language_id']; } if (isset($params['comments_allowed'])) { $this->page['comments_allowed'] = $params['comments_allowed']; } if (isset($params['show_in_search'])) { $this->page['show_in_search'] = $params['show_in_search']; } if (isset($params['priority_order'])) { $this->page['priority_order'] = $params['priority_order']; } if (isset($params['access_level'])) { $this->page['access_level'] = $params['access_level']; } if (isset($params['finish_publishing'])) { $this->page['finish_publishing'] = $params['finish_publishing']; } if (isset($params['tag_title'])) { $this->page['tag_title'] = $params['tag_title']; } if (isset($params['tag_keywords'])) { $this->page['tag_keywords'] = $params['tag_keywords']; } if (isset($params['tag_description'])) { $this->page['tag_description'] = $params['tag_description']; } // Menu link cannot be more then 40 characters if (strlen($this->page['menu_link']) > 40) { $this->error = _PAGE_LINK_TOO_LONG; return false; } else { if ($this->page['page_title'] == '') { $this->error = _PAGE_HEADER_EMPTY; return false; } else { if ($this->page['content_type'] == 'link' && $this->page['link_url'] == '') { $this->error = str_replace('_FIELD_', '<b>' . _LINK . '</b>', _FIELD_CANNOT_BE_EMPTY); $this->focusOnField = 'link_url'; return false; } else { if (!check_integer($this->page['priority_order']) || $this->page['priority_order'] < 0) { $this->error = str_replace('_FIELD_', '<b>' . _ORDER . '</b>', _FIELD_MUST_BE_NUMERIC_POSITIVE); $this->focusOnField = 'priority_order'; return false; } else { if (strlen($this->page['tag_title']) > 255) { $msg_text = str_replace('_FIELD_', '<b>TITLE</b>', _FIELD_LENGTH_ALERT); $msg_text = str_replace('_LENGTH_', '255', $msg_text); $this->error = $msg_text; $this->focusOnField = 'tag_title'; return false; } else { if (strlen($this->page['tag_keywords']) > 512) { $msg_text = str_replace('_FIELD_', '<b>KEYWORDS</b>', _FIELD_LENGTH_ALERT); $msg_text = str_replace('_LENGTH_', '512', $msg_text); $this->error = $msg_text; $this->focusOnField = 'tag_keywords'; return false; } else { if (strlen($this->page['tag_description']) > 512) { $msg_text = str_replace('_FIELD_', '<b>DESCRIPTION</b>', _FIELD_LENGTH_ALERT); $msg_text = str_replace('_LENGTH_', '512', $msg_text); $this->error = $msg_text; $this->focusOnField = 'tag_description'; return false; } } } } } } } if (strtolower(SITE_MODE) == 'demo') { $this->error = _OPERATION_BLOCKED; return false; } else { if ($copy_to_other_langs == 'yes') { $total_languages = Languages::GetAllActive(); } else { $total_languages = Languages::GetAllLanguages(' priority_order ASC', '', 'abbreviation=\'' . $this->page['language_id'] . '\''); } $page_code = get_random_string(10); for ($i = 0; $i < $total_languages[1]; $i++) { // Create new record $sql = 'INSERT INTO ' . TABLE_PAGES . '( id, page_code, language_id, content_type, link_url, link_target, page_key, page_title, page_text, menu_id, menu_link, tag_title, tag_keywords, tag_description, comments_allowed, show_in_search, date_created, date_updated, finish_publishing, is_published, is_system_page, system_page, status_changed, access_level, priority_order )VALUES( NULL, \'' . $page_code . '\', \'' . $total_languages[0][$i]['abbreviation'] . '\', \'' . $this->page['content_type'] . '\', \'' . encode_text($this->page['link_url']) . '\', \'' . $this->page['link_target'] . '\', \'\', \'' . encode_text($this->page['page_title']) . '\', \'' . encode_text($this->page['page_text']) . '\', ' . (int) $this->GetMenuIdByLang($this->page['menu_id'], $total_languages[0][$i]['abbreviation']) . ', \'' . encode_text($this->page['menu_link']) . '\', \'' . encode_text($this->page['tag_title']) . '\', \'' . encode_text($this->page['tag_keywords']) . '\', \'' . encode_text($this->page['tag_description']) . '\', ' . (int) $this->page['comments_allowed'] . ', ' . (int) $this->page['show_in_search'] . ', \'' . date('Y-m-d H:i:s') . '\', \'0000-00-00 00:00:00\', \'' . $this->page['finish_publishing'] . '\', ' . (int) $this->page['is_published'] . ', 0, \'\', \'0000-00-00 00:00:00\', \'' . $this->page['access_level'] . '\', ' . (int) $this->page['priority_order'] . ' )'; if (database_void_query($sql)) { // Update page_key $last_insert_id = mysql_insert_id(); $sql = 'UPDATE ' . TABLE_PAGES . ' SET page_key=\'' . $this->page['page_key'] . '\' WHERE id=' . (int) $last_insert_id; if (database_void_query($sql)) { // ok $this->page_id = $last_insert_id; } else { $this->error = _TRY_LATER; return false; } } else { $this->error = _TRY_LATER; return false; } } return true; } }