public function load_from_post() { global $theme; global $user; $ws_theme = $theme; if ($this->theme != $theme->name) { $ws_theme = new theme(); $ws_theme->load($this->theme); } $this->name = $_REQUEST['title']; $this->protocol = $_REQUEST['protocol']; $this->subdomain = $_REQUEST['subdomain']; $this->domain = $_REQUEST['domain']; $this->folder = $_REQUEST['folder']; $this->word_separator = $_REQUEST['word_separator']; $this->redirect_to = $_REQUEST['redirect_to']; $this->wrong_path_action = $_REQUEST['wrong_path_action']; $this->wrong_path_redirect = $_REQUEST['wrong_path_redirect']; $this->empty_path_action = $_REQUEST['empty_path_action']; $this->date_format = $_REQUEST['date_format']; $this->tinymce_css = $_REQUEST['tinymce_css']; $this->resize_uploaded_images = intval($_REQUEST['resize_uploaded_images']); $this->comments_enabled_for = intval($_REQUEST['comments_enabled_for']); $this->comments_default_moderator = $_REQUEST['comments_default_moderator']; $this->share_files_media_browser = intval($_REQUEST['share_files_media_browser']); $this->additional_scripts = $_REQUEST['additional_scripts']; if (empty($_REQUEST['homepage_from_structure'])) { $this->homepage = $_REQUEST['homepage']; } $this->permission = intval($_REQUEST['permission']); $this->default_timezone = $_REQUEST['default_timezone']; $this->mail_mailer = $_REQUEST['mail_mailer'][0]; $this->mail_server = $_REQUEST['mail_server']; $this->mail_port = intval($_REQUEST['mail_port']); $this->mail_security = intval($_REQUEST['mail_security']); $this->mail_user = $_REQUEST['mail_user']; $this->mail_address = $_REQUEST['mail_address']; if (!empty($_REQUEST['mail_password'])) { $this->mail_password = $_REQUEST['mail_password']; } $ce = explode("\n", $_REQUEST['contact_emails']); $this->contact_emails = array(); foreach ($ce as $cemail) { $cemail = trim($cemail); if (empty($cemail)) { continue; } $this->contact_emails[] = $cemail; } $this->favicon = intval($_REQUEST['website-favicon']); // languages and locales $this->languages = array(); $this->languages_published = array(); for ($li = 0; $li < count($_REQUEST['language-id']); $li++) { $variant = trim($_REQUEST['language-variant-code'][$li]); $code = $_REQUEST['language-id'][$li]; if (!empty($variant)) { $code .= '_' . $variant; } $this->languages[$code] = array('language' => $_REQUEST['language-id'][$li], 'variant' => $variant, 'code' => $code, 'system_locale' => $_REQUEST['language-locale'][$li]); $this->languages_published[] = $_REQUEST['language-published'][$li] == '1' ? $code : ''; } // Website metatags $this->metatag_description = array(); $this->metatag_keywords = array(); $this->metatags = array(); foreach ($this->languages as $language) { $lcode = $language['code']; $this->metatag_description[$lcode] = $_REQUEST['metatag_description-' . $lcode]; $this->metatag_keywords[$lcode] = $_REQUEST['metatag_keywords-' . $lcode]; $this->metatags[$lcode] = $_REQUEST['metatags-' . $lcode]; } // website aliases $this->aliases = array(); if (empty($_POST['website-aliases-alias'])) { $_POST['website-aliases-alias'] = array(); } foreach ($_POST['website-aliases-alias'] as $key => $value) { $value = trim($value); if (!empty($value)) { $value_real = trim($_POST['website-aliases-real'][$key]); if (!empty($value_real)) { $this->aliases[$value] = $value_real; } } } $this->theme_options = array(); // Theme style (common property) $this->theme_options['style'] = $_REQUEST['property-style']; if (!empty($ws_theme->options)) { foreach ($ws_theme->options as $theme_option) { // get property info $property = new property(); $property->load_from_theme($theme_option, NULL, NULL, NULL, $this->id); $value = ''; switch ($property->type) { case 'text': case 'textarea': case 'rich_textarea': // multilang $value = array(); if (!is_array($this->languages_list)) { $this->languages_list = array(); } foreach ($this->languages_list as $lang) { $value[$lang] = $_REQUEST['property-' . $theme_option->id . '-' . $lang]; } break; case 'link': // multilang and title+link $value = array(); foreach ($this->languages_list as $lang) { $value[$lang] = $_REQUEST['property-' . $theme_option->id . '-' . $lang . '-link'] . '##' . $_REQUEST['property-' . $theme_option->id . '-' . $lang . '-title']; } break; case 'date': case 'datetime': $value = core_date2ts($_REQUEST['property-' . $theme_option->id]); break; case 'moption': $value = implode(',', $_REQUEST['property-' . $theme_option->id]); break; case 'coordinates': $value = $_REQUEST['property-' . $theme_option->id . '-latitude'] . '#' . $_REQUEST['property-' . $theme_option->id . '-longitude']; break; case 'decimal': $value = $_REQUEST['property-' . $theme_option->id]; $value = core_string2decimal($value); break; default: // direct value $value = $_REQUEST['property-' . $theme_option->id]; } $this->theme_options[$theme_option->id] = $value; } } }
public static function save_properties_from_post($object_type, $object_id, $template = null, $element = null, $object_uid = null) { global $DB; global $website; global $theme; $dictionary = array(); // load properties associated with the element type if ($object_type == 'block_group_block') { $block = block::block_group_block($template, $element); $properties = $block->properties; if (!is_numeric($object_id)) { $block_group_id = $DB->query_single('MAX(id)', 'nv_block_groups', ' code = ' . protect($template) . ' AND website = ' . $website->id); $object_id = $block_group_id; if (empty($block_group_id)) { $object_id = 0; } } } else { if ($object_type == 'extension_block') { // in this case, the parameters must match the following: // $element => (not used) // $template => type of the block in the extension definition // $object_type => "extension_block" // $object_id => type of the block_group (f.e. "sidebar" or the one defined in the theme definition) // $object_uid => the unique id assigned to the block in the block_group // find the extension block definition, to get the list of properties $extensions_blocks = extension::blocks(); for ($eb = 0; $eb < count($extensions_blocks); $eb++) { if ($extensions_blocks[$eb]->id == $template) { $properties = $extensions_blocks[$eb]->properties; break; } } // we must find the REAL numeric block group ID (based on its code) to get the assigned property values // $object_id MUST BE the numeric ID of the block group (we have only its codename, not the numeric ID) if (!empty($template)) { $block_group_id = $DB->query_single('MAX(id)', 'nv_block_groups', ' code = ' . protect($object_id) . ' AND website = ' . $website->id); $object_id = $block_group_id; if (empty($block_group_id)) { $object_id = 0; } } $object_type = "block_group-extension-block"; } else { if ($object_type == 'webuser') { // the properties set in the theme definition $properties = $theme->webusers['properties']; } else { if (empty($template)) { $template = $_REQUEST['property-template']; } if (empty($element)) { $element = $_REQUEST['property-element']; } $properties = property::elements($template, $element); } } } if (!is_array($properties)) { $properties = array(); } foreach ($properties as $property) { // ALWAYS SAVE the property value, even if it is empty $property_value = $_REQUEST['property-' . $property->id]; // multilanguage property? if (in_array($property->type, array('text', 'textarea', 'link', 'rich_textarea')) || @$property->multilanguage == 'true' || @$property->multilanguage === true) { $property_value = '[dictionary]'; } // date/datetime property? if ($property->type == 'date' || $property->type == 'datetime') { $property_value = core_date2ts($_REQUEST['property-' . $property->id]); } if ($property->type == 'moption' && !empty($_REQUEST['property-' . $property->id])) { $property_value = implode(',', $_REQUEST['property-' . $property->id]); } if ($property->type == 'coordinates') { $property_value = $_REQUEST['property-' . $property->id . '-latitude'] . '#' . $_REQUEST['property-' . $property->id . '-longitude']; } if ($property->type == 'decimal') { $property_value = core_string2decimal($_REQUEST['property-' . $property->id]); } if ($property->type == 'webuser_groups' && !empty($_REQUEST['property-' . $property->id])) { $property_value = 'g' . implode(',g', $_REQUEST['property-' . $property->id]); } // boolean (checkbox): if not checked, form does not send the value if ($property->type == 'boolean' && !isset($_REQUEST['property-' . $property->id])) { $property_value = 0; } // item (select2): if no selection, the form does not send a value (HTML); // if we don't set an empty value, Navigate would take that as non-existant field and would set the default value, // which is different as the user may really want to set "empty" as the value if (($property->type == 'element' || $property->type == 'item') && !isset($_REQUEST['property-' . $property->id])) { $property_value = ""; } // remove the old property row $DB->execute(' DELETE FROM nv_properties_items WHERE property_id = ' . protect($property->id) . ' AND element = ' . protect($object_type) . ' AND node_id = ' . protect($object_id) . (empty($object_uid) ? '' : ' AND node_uid = ' . protect($object_uid)) . ' AND website = ' . $website->id); // now insert the new row $DB->execute(' INSERT INTO nv_properties_items (id, website, property_id, element, node_id, node_uid, name, value) VALUES ( 0, :website, :property_id, :type, :object_id, :object_uid, :name, :value )', array(':website' => $website->id, ':property_id' => $property->id, ':type' => $object_type, ':object_id' => value_or_default($object_id, 0), ':object_uid' => value_or_default($object_uid, ""), ':name' => value_or_default($property->name, $property->id), ':value' => value_or_default($property_value, ""))); // save in the dictionary the multilanguage properties $default_language = ''; if ($property->multilanguage === 'false' || $property->multilanguage === false) { $default_language = $website->languages_list[0]; } if (in_array($property->type, array('text', 'textarea', 'rich_textarea')) || @$property->multilanguage == 'true' || @$property->multilanguage === true) { foreach ($website->languages_list as $lang) { if (!empty($default_language)) { // property is NOT multilanguage, use the first value for all languages $_REQUEST['property-' . $property->id . '-' . $lang] = $_REQUEST['property-' . $property->id . '-' . $default_language]; } $dictionary[$lang]['property-' . $property->id . '-' . $lang] = $_REQUEST['property-' . $property->id . '-' . $lang]; } } else { if ($property->type == 'link') { foreach ($website->languages_list as $lang) { $link = $_REQUEST['property-' . $property->id . '-' . $lang . '-link'] . '##' . $_REQUEST['property-' . $property->id . '-' . $lang . '-title'] . '##' . $_REQUEST['property-' . $property->id . '-' . $lang . '-target']; $dictionary[$lang]['property-' . $property->id . '-' . $lang] = $link; if (!empty($default_language)) { // property is NOT multilanguage, use the first value for all languages $dictionary[$lang]['property-' . $property->id . '-' . $lang] = $dictionary[$lang]['property-' . $property->id . '-' . $default_language]; } } } } } if (!empty($dictionary)) { $property_element = $_REQUEST['property-element']; if ($object_type == 'block_group_block') { $property_element = 'block_group_block'; } else { if ($object_type == 'block_group-extension-block') { $property_element = 'block_group-extension-block'; } } webdictionary::save_element_strings('property-' . $property_element, $object_id, $dictionary, $website->id, $object_uid); } return true; }