public function update() { global $DB; $ok = $DB->execute(' UPDATE nv_webuser_groups SET website = :website, name = :name, code = :code, description = :description WHERE id = :id', array('id' => $this->id, 'website' => $this->website, 'name' => value_or_default($this->name, ""), 'code' => value_or_default($this->code, ""), 'description' => value_or_default($this->description, ""))); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
public function update() { global $DB; $ok = $DB->execute(' UPDATE nv_profiles SET name = :name, description = :description, menus = :menus WHERE id = :id', array('name' => value_or_default($this->name, ""), 'description' => value_or_default($this->description, ""), 'menus' => json_encode($this->menus), 'id' => $this->id)); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
public function update() { global $DB; $ok = $DB->execute(' UPDATE nv_functions SET category = :category, codename = :codename, icon = :icon, lid = :lid, enabled = :enabled WHERE id = :id', array('id' => $this->id, 'category' => value_or_default($this->category, ""), 'codename' => value_or_default($this->codename, ""), 'icon' => value_or_default($this->icon, ""), 'lid' => value_or_default($this->lid, 0), 'enabled' => value_or_default($this->enabled, 0))); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
public function update() { global $DB; $ok = $DB->execute(' UPDATE nv_paths SET type = :type, object_id = :object_id, lang = :lang, path = :path, cache_file = :cache_file, cache_expires = :cache_expires, views = :views, id = :id, website = :website', array("type" => $this->type, "object_id" => $this->object_id, "lang" => $this->lang, "path" => $this->path, "cache_file" => $this->cache_file, "cache_expires" => $this->cache_expires, "views" => value_or_default($this->views, 0), "id" => $this->id, "website" => $this->website)); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
public function update() { global $DB; global $website; $this->date = core_time(); $ok = $DB->execute(' UPDATE nv_webuser_votes SET webuser = :webuser, object = :object, object_id = :object_id, value = :value, date = :date WHERE id = :id AND website = :website', array('id' => $this->id, 'website' => value_or_default($this->website, $website->id), 'webuser' => value_or_default($this->webuser, 0), 'object' => $this->object, 'object_id' => $this->object_id, 'value' => $this->value, 'date' => value_or_default($this->date, 0))); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
public static function save_properties_from_array($object_type, $object_id, $template, $properties_assoc = array(), $ws = null, $node_uid = "") { global $DB; global $website; global $theme; if (empty($ws)) { $ws = $website; } $dictionary = array(); $property_object_type = $object_type; // object_type: item, structure, block, block_group_block if ($object_type == 'block_group_block') { // we have to identify the block subtype: block, block_type, block_group_block or extension_block // so we can get its properties definition if (!is_numeric($object_id)) { // assume there can only be one block group of the same type $block_group_id = $DB->query_single('MAX(id)', 'nv_block_groups', ' code = ' . protect($template) . ' AND website = ' . $ws->id); $object_id = $block_group_id; if (empty($block_group_id)) { $object_id = 0; } } if (!empty($node_uid)) { $bg = new block_group(); $bg->load($object_id); for ($b = 0; $b < count($bg->blocks); $b++) { if ($bg->blocks[$b]['uid'] == $node_uid) { $block_id = $bg->blocks[$b]['id']; if ($bg->blocks[$b]['type'] == 'extension') { // an extension block $property_object_type = 'block_group-extension-block'; // load the extension, if installed in this instance $extension = new extension(); $extension->load($bg->blocks[$b]['extension']); // find the property declaration in the extension definition if (isset($extension->definition->blocks)) { for ($eb = 0; $eb < count($extension->definition->blocks); $eb++) { if ($extension->definition->blocks[$eb]->id == $block_id) { $block = $extension->definition->blocks[$eb]; break; } } } else { // ignore this property, extension is not installed or it does not have the requested block definition continue; } } else { // a block group block $property_object_type = 'block_group_block'; $block = block::block_group_block($template, $block_id); } // note: standard blocks don't "embed" their properties in a block group, // they have their own separate values break; } } } else { // compatibility with < Navigate 2.1 themes (to be removed) $properties_names = array_keys($properties_assoc); $block = block::block_group_block_by_property($properties_names[0]); } if (!isset($block->properties) || empty($block->properties)) { return false; } $properties = $block->properties; } else { $properties = property::elements($template, $object_type); } if (!is_array($properties)) { $properties = array(); } foreach ($properties as $property) { if (!isset($properties_assoc[$property->name]) && !isset($properties_assoc[$property->id])) { continue; } $values_dict = array(); $value = ''; // we try to find the property value by "property name", if empty then we try to find it via "property id" if (isset($properties_assoc[$property->name])) { $value = $properties_assoc[$property->name]; } if (empty($value)) { $value = $properties_assoc[$property->id]; } // multilanguage property? if (in_array($property->type, array('text', 'textarea', 'link', 'rich_textarea')) || @$property->multilanguage == 'true' || @$property->multilanguage === true) { if (isset($properties_assoc[$property->name])) { $values_dict = $properties_assoc[$property->name]; } if (empty($values_dict)) { $values_dict = $properties_assoc[$property->id]; } $value = '[dictionary]'; } if ($property->type == 'coordinates') { if (is_array($value)) { $value = $value['latitude'] . '#' . $value['longitude']; } // if it isn't an array, then we suppose it already has the right format } // property->type "decimal"; we don't need to reconvert, it should already be in the right format if ($property->type == 'webuser_groups' && !empty($value)) { $value = 'g' . implode(',g', $value); } // boolean (checkbox): if not checked, form does not send the value if ($property->type == 'boolean' && empty($value)) { $value = 0; } if (is_null($value)) { $value = ""; } // should not be needed because of value_or_default, but doing this here fixes some warnings // remove the old property value row $DB->execute(' DELETE FROM nv_properties_items WHERE property_id = ' . protect($property->id) . ' AND element = ' . protect($property_object_type) . ' AND node_id = ' . protect($object_id) . (empty($node_uid) ? '' : ' AND node_uid = ' . protect($node_uid)) . ' AND website = ' . $ws->id); // now we insert a 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, :node_uid, :name, :value )', array(':website' => $ws->id, ':property_id' => $property->id, ':type' => $property_object_type, ':object_id' => value_or_default($object_id, 0), ':node_uid' => value_or_default($node_uid, ""), ':name' => $property->name, ':value' => value_or_default($value, ""))); // $error = $DB->get_last_error(); // set the dictionary for the multilanguage properties $default_language = ''; if (isset($property->multilanguage) && ($property->multilanguage === 'false' || $property->multilanguage === false)) { $default_language = $ws->languages_list[0]; } if (in_array($property->type, array('text', 'textarea', 'rich_textarea', 'link')) || @$property->multilanguage == 'true' || @$property->multilanguage === true) { foreach ($ws->languages_list as $lang) { if (!empty($default_language)) { // property is NOT multilanguage, use the first value for all languages $dictionary[$lang]['property-' . $property->id . '-' . $lang] = $values_dict[$default_language]; } else { $dictionary[$lang]['property-' . $property->id . '-' . $lang] = $values_dict[$lang]; } } } } if (!empty($dictionary)) { webdictionary::save_element_strings('property-' . $property_object_type, $object_id, $dictionary, $ws->id, $node_uid); } return true; }
public function update() { global $DB; $groups = ''; if (is_array($this->groups)) { $this->groups = array_unique($this->groups); // remove duplicates $this->groups = array_filter($this->groups); // remove empty if (!empty($this->groups)) { $groups = 'g' . implode(',g', $this->groups); } } if ($groups == 'g') { $groups = ''; } $ok = $DB->execute(' UPDATE nv_files SET type = :type, parent = :parent, name = :fname, size = :size, mime = :mime, width = :width, height = :height, focalpoint = :focalpoint, title = :title, description = :description, date_added = :date_added, uploaded_by = :uploaded_by, permission = :permission, access = :access, groups = :groups, system = :system, enabled = :enabled WHERE id = :id AND website = :website_id ', array(":id" => $this->id, ":website_id" => $this->website, ":type" => $this->type, ":parent" => $this->parent, ":fname" => $this->name, ":size" => $this->size, ":mime" => $this->mime, ":width" => $this->width, ":height" => $this->height, ":focalpoint" => value_or_default($this->focalpoint, ''), ":title" => json_encode($this->title), ":description" => json_encode($this->description), ":date_added" => $this->date_added, ":uploaded_by" => $this->uploaded_by, ":permission" => $this->permission, ":access" => value_or_default($this->access, 0), ":groups" => $groups, ":system" => value_or_default($this->system, 0), ":enabled" => $this->enabled)); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
function run() { global $user; switch (@$_REQUEST['act']) { case 'json': switch ($_REQUEST['oper']) { case 'settings_panels': // save dashboard panels state $dashboard_panels = $_REQUEST['dashboard_panels']; $user->setting('dashboard-panels', json_encode($dashboard_panels)); echo json_encode(true); core_terminate(); break; case 'feed': $feed = new feed_parser(); $feed->set_cache(4 * 3600); // once update each 4 hours $feed->load($_REQUEST['url']); list($channel, $articles, $count) = $feed->parse(0, $_REQUEST['limit'], 'newest'); $items = item::convert_from_rss($articles); $display_language = $_REQUEST['language']; if (!empty($items)) { $feed_html = ''; for ($c = 0; $c < count($items); $c++) { if (empty($items[$c])) { break; } if (!isset($items[$c]->dictionary[$display_language])) { // requested language not available, get the first available in the feed $feed_languages = array_keys($items[$c]->dictionary); $display_language = $feed_languages[0]; } $tmp = array('<div class="navigate-panel-body-title ui-corner-all">' . '<a href="' . $items[$c]->paths[$display_language] . '" target="_blank">' . core_ts2date($items[$c]->date_to_display, true) . ' ' . '<strong>' . $items[$c]->dictionary[$display_language]['title'] . '</strong>' . '</a>' . '</div>', '<div id="navigatecms-feed-item-' . $items[$c]->id . '" class="navigate-panel-recent-feed-element">' . $items[$c]->dictionary[$display_language]['section-main'] . '</div>'); $feed_html .= implode("\n", $tmp); } } echo $feed_html; core_terminate(); break; default: // list or search } break; case 'recent_items': $ri = users_log::recent_items(value_or_default($_REQUEST['limit']), 10); if (!is_array($ri)) { $ri = array(); } for ($i = 0; $i < count($ri); $i++) { $action = $ri[$i]; $ri[$i]->_url = '?fid=' . $action->function . '&wid=' . $action->website . '&act=load&id=' . $action->item; $ri[$i]->_link = '<a href="' . $ri[$i]->_url . '" title="' . htmlspecialchars($action->item_title) . ' | ' . htmlspecialchars(t($action->function_title, $action->function_title)) . '"><img src="' . $action->function_icon . '" align="absmiddle" /> ' . core_string_cut($action->item_title, 33) . '</a>'; } echo json_encode($ri); core_terminate(); break; default: $out = dashboard_create(); } return $out; }
/** * An alias of {@link value_or_default()} * * * @param mixed $value * @param mixed $default * @return mixed */ function v($value, $default) { return value_or_default($value, $default); }
public function update() { global $DB; global $website; global $events; global $user; if (!is_null($user)) { if ($user->permission("items.edit") == 'false' && $this->author != $user->id) { throw new Exception(t(610, "Sorry, you are not allowed to execute this function.")); } if (!structure::category_allowed($this->category)) { throw new Exception(t(610, "Sorry, you are not allowed to execute this function.")); } } $this->date_modified = core_time(); $groups = ''; if (is_array($this->groups)) { $this->groups = array_unique($this->groups); // remove duplicates $this->groups = array_filter($this->groups); // remove empty if (!empty($this->groups)) { $groups = 'g' . implode(',g', $this->groups); } } if ($groups == 'g') { $groups = ''; } $ok = $DB->execute(' UPDATE nv_items SET association = :association, category = :category, embedding = :embedding, template = :template, date_to_display = :date_to_display, date_published = :date_published, date_unpublish = :date_unpublish, date_modified = :date_modified, author = :author, galleries = :galleries, comments_enabled_to = :comments_enabled_to, comments_moderator = :comments_moderator, access = :access, groups = :groups, permission = :permission, views = :views, votes = :votes, score = :score, position = :position WHERE id = :id AND website = :website', array(":association" => $this->association, ":category" => $this->category, ":embedding" => $this->embedding, ":template" => $this->template, ":date_to_display" => value_or_default($this->date_to_display, 0), ":date_published" => value_or_default($this->date_published, 0), ":date_unpublish" => value_or_default($this->date_unpublish, 0), ":date_modified" => $this->date_modified, ":author" => $this->author, ":galleries" => serialize($this->galleries), ":comments_enabled_to" => value_or_default($this->comments_enabled_to, 0), ":comments_moderator" => value_or_default($this->comments_moderator, 0), ":access" => $this->access, ":groups" => $groups, ":permission" => $this->permission, ":views" => $this->views, ":votes" => $this->votes, ":score" => $this->score, ":position" => value_or_default($this->position, 0), ":id" => $this->id, ":website" => $this->website)); if (!$ok) { throw new Exception($DB->get_last_error()); } webdictionary::save_element_strings('item', $this->id, $this->dictionary, $this->website); webdictionary_history::save_element_strings('item', $this->id, $this->dictionary, false, $this->website); path::saveElementPaths('item', $this->id, $this->paths, $this->website); $events->trigger('item', 'save', array('item' => $this)); return true; }
function all_error_texts() { return implode('<br>', array_map('retry_error_text', array_keys(value_or_default($_GET, ERROR_GET_VARIABLE, array())))); }
/** * Sets a template variable with a value or a default value if value is empty * * @param string $name * @param string $value * @param string $default * @return mixed setted value */ function set_or_default($name, $value, $default) { return set($name, value_or_default($value, $default)); }
public function update() { global $DB; global $website; $groups = ''; if (is_array($this->groups)) { $this->groups = array_unique($this->groups); // remove duplicates $this->groups = array_filter($this->groups); // remove empty if (!empty($this->groups)) { $groups = 'g' . implode(',g', $this->groups); } } if ($groups == 'g') { $groups = ''; } $ok = $DB->execute(' UPDATE nv_structure SET parent = :parent, position = :position, access = :access, groups = :groups, permission = :permission, icon = :icon, metatags = :metatags, date_published = :date_published, date_unpublish = :date_unpublish, template = :template, visible = :visible, views = :views, votes = :votes, score = :score WHERE id = :id AND website = :website ', array(":id" => $this->id, ":website" => $this->website, ":parent" => value_or_default($this->parent, 0), ":position" => $this->position, ":access" => $this->access, ":groups" => $groups, ":permission" => $this->permission, ":icon" => value_or_default($this->icon, ''), ":metatags" => value_or_default($this->metatags, ''), ":template" => $this->template, ":date_published" => value_or_default($this->date_published, 0), ":date_unpublish" => value_or_default($this->date_unpublish, 0), ":visible" => $this->visible, ":views" => $this->views, ":votes" => $this->votes, ":score" => $this->score)); if (!$ok) { throw new Exception($DB->get_last_error()); } webdictionary::save_element_strings('structure', $this->id, $this->dictionary, $this->website); path::saveElementPaths('structure', $this->id, $this->paths, $this->website); return true; }
public function update() { global $DB; if (!is_array($this->categories)) { $this->categories = array(); } $ok = $DB->execute(' UPDATE nv_feeds SET categories = :categories, format = :format, image = :image, entries = :entries, content = :content, views = :views, permission = :permission, enabled = :enabled WHERE id = :id AND website = :website', array('id' => $this->id, 'website' => $this->website, 'categories' => implode(',', $this->categories), 'format' => $this->format, 'image' => value_or_default($this->image, 0), 'entries' => value_or_default($this->entries, 10), 'content' => $this->content, 'views' => value_or_default($this->views, 0), 'permission' => value_or_default($this->permission, 0), 'enabled' => value_or_default($this->enabled, 0))); if (!$ok) { throw new Exception($DB->get_last_error()); } webdictionary::save_element_strings('feed', $this->id, $this->dictionary); path::saveElementPaths('feed', $this->id, $this->paths); return true; }
public function update() { global $DB; global $website; $ok = $DB->execute('UPDATE nv_block_groups SET `code` = :code, title = :title, notes = :notes, blocks = :blocks WHERE id = :id AND website = :website ', array(':id' => $this->id, ':website' => $this->website, ':code' => value_or_default($this->code, ''), ':title' => value_or_default($this->title, ''), ':notes' => value_or_default($this->notes, ''), ':blocks' => json_encode($this->blocks))); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
public function update() { global $DB; global $website; $ok = $DB->execute(' UPDATE nv_templates SET title = :title, file = :file, sections = :sections, gallery = :gallery, comments = :comments, tags = :tags, statistics = :statistics, permission = :permission, enabled = :enabled WHERE id = :id AND website = :website', array(':id' => $this->id, ':website' => value_or_default($this->website, $website->id), ':title' => value_or_default($this->title, ""), ':file' => value_or_default($this->file, ""), ':sections' => serialize($this->sections), ':gallery' => value_or_default($this->gallery, 0), ':comments' => value_or_default($this->comments, 0), ':tags' => value_or_default($this->tags, 0), ':statistics' => value_or_default($this->statistics, 0), ':permission' => value_or_default($this->permission, 0), ':enabled' => value_or_default($this->enabled, 0))); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
function nvweb_comments_list($offset = 0, $limit = NULL, $permission = NULL, $order = 'oldest') { global $DB; global $website; global $current; $limit = value_or_default($limit, 2147483647); if ($order == 'newest' || $order == 'hierarchy_newest') { $orderby = "nvc.date_created DESC"; } else { $orderby = "nvc.date_created ASC"; } $element = $current['object']; if ($current['type'] == 'structure') { if (empty($current['structure_elements'])) { $current['structure_elements'] = $element->elements(); } $element = $current['structure_elements'][0]; } else { if ($current['type'] == 'item') { $element = new item(); $element->load($current['id']); } } if (strpos($order, 'hierarchy') !== false) { // list comments keeping hierarchy // MySQL (still) does not have recursive queries, meanwhile we apply the following procedure: // find all comments of 0-depth (root level) and calculate if they have any reply // then, in PHP, parse the results and load (recursively) all replies and subreplies // in the result array, INSERT the additional results in the position where they must be respecting the order requested (oldest/newest) // note 1: this procedure allows optimization, for now we've made it work // note 2: the only drawback is that offset/limit it's only taken into account for the root level comments, so the // number of results is variable on each request; we found that an acceptable drawback $DB->query(' SELECT SQL_CALC_FOUND_ROWS nvc.*, nvwu.username, nvwu.avatar, (SELECT COUNT(nvcr.id) FROM nv_comments nvcr WHERE nvcr.reply_to = nvc.id AND nvcr.status = 0 ) AS replies FROM nv_comments nvc LEFT OUTER JOIN nv_webusers nvwu ON nvwu.id = nvc.user WHERE nvc.website = ' . protect($website->id) . ' AND nvc.item = ' . protect($element->id) . ' AND nvc.status = 0 AND nvc.reply_to = 0 ORDER BY ' . $orderby . ' LIMIT ' . $limit . ' OFFSET ' . $offset); $rs = $DB->result(); $out = array(); for ($r = 0; $r < count($rs); $r++) { $rows_to_add = array(); if ($rs[$r]->replies > 0) { $c = new comment(); $c->load_from_resultset(array($rs[$r])); $rows_to_add = $c->get_replies(); } $out[] = $rs[$r]; if (!empty($rows_to_add)) { foreach ($rows_to_add as $rta) { $out[] = $rta; } } } $rs = $out; $total = count($rs); } else { $DB->query(' SELECT SQL_CALC_FOUND_ROWS nvc.*, nvwu.username, nvwu.avatar FROM nv_comments nvc LEFT OUTER JOIN nv_webusers nvwu ON nvwu.id = nvc.user WHERE nvc.website = ' . protect($website->id) . ' AND nvc.item = ' . protect($element->id) . ' AND nvc.status = 0 ORDER BY ' . $orderby . ' LIMIT ' . $limit . ' OFFSET ' . $offset); $rs = $DB->result(); $total = $DB->foundRows(); } return array($rs, $total); }
public function save() { global $DB; $ok = false; $settings = $this->settings; $settings = json_encode($settings); if (empty($this->id)) { $ok = $DB->execute(' INSERT INTO nv_extensions (id, website, extension, enabled, settings) VALUES(0, :website, :code, :enabled, :settings)', array(':website' => $this->website, ':code' => $this->code, ':enabled' => value_or_default($this->enabled, 0), ':settings' => $settings)); } else { $ok = $DB->execute(' UPDATE nv_extensions SET enabled = :enabled, settings = :settings WHERE id = :id', array(':enabled' => value_or_default($this->enabled, 0), ':settings' => $settings, ':id' => $this->id)); } return $ok; }
public static function action($function, $item = '', $action = '', $item_title = '', $data = '') { global $DB; global $website; global $user; $encoded_data = ''; if ($action == 'save' && function_exists('gzencode')) { $encoded_data = gzencode($data); } // a blank (new) form requested if ($action == 'load' && empty($item)) { return true; } $wid = $website->id; if (empty($wid)) { $wid = 0; } $uid = $user->id; if (empty($uid)) { $uid = 0; } if (!is_numeric($function)) { $func = core_load_function($function); $function = $func->id; } // prepared statement $ok = $DB->execute(' INSERT INTO nv_users_log (id, `date`, user, website, `function`, item, action, item_title, data) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? )', array(0, core_time(), $uid, $wid, $function, value_or_default($item, ""), value_or_default($action, ""), value_or_default((string) $item_title, ""), value_or_default($encoded_data, ""))); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
public function update($trigger_webuser_modified = true) { global $DB; global $events; $groups = ''; if (is_array($this->groups)) { $this->groups = array_unique($this->groups); // remove duplicates $this->groups = array_filter($this->groups); // remove empty if (!empty($this->groups)) { $groups = 'g' . implode(',g', $this->groups); } } if ($groups == 'g') { $groups = ''; } $ok = $DB->execute(' UPDATE nv_webusers SET website = :website, username = :username, password = :password, email = :email, groups = :groups, fullname = :fullname, gender = :gender, avatar = :avatar, birthdate = :birthdate, language = :language, lastseen = :lastseen, country = :country, timezone = :timezone, address = :address, zipcode = :zipcode, location = :location, phone = :phone, social_website = :social_website, newsletter = :newsletter, private_comment = :private_comment, activation_key = :activation_key, cookie_hash = :cookie_hash, access = :access, access_begin = :access_begin, access_end = :access_end, email_verification_date = :email_verification_date WHERE id = :id ', array(':website' => $this->website, ':username' => $this->username, ':password' => $this->password, ':email' => $this->email, ':groups' => $groups, ':fullname' => $this->fullname, ':gender' => value_or_default($this->gender, ""), ':avatar' => $this->avatar, ':birthdate' => value_or_default($this->birthdate, 0), ':language' => value_or_default($this->language, ""), ':lastseen' => $this->lastseen, ':country' => $this->country, ':timezone' => $this->timezone, ':address' => $this->address, ':zipcode' => $this->zipcode, ':location' => $this->location, ':phone' => $this->phone, ':social_website' => value_or_default($this->social_website, ""), ':newsletter' => value_or_default($this->newsletter, 0), ':private_comment' => value_or_default($this->private_comment, ""), ':activation_key' => value_or_default($this->activation_key, ""), ':cookie_hash' => value_or_default($this->cookie_hash, ""), ":access" => value_or_default($this->access, 0), ":access_begin" => value_or_default($this->access_begin, 0), ":access_end" => value_or_default($this->access_end, 0), ':id' => $this->id, ':email_verification_date' => value_or_default($this->email_verification_date, 0))); if (!$ok) { throw new Exception($DB->get_last_error()); } if ($trigger_webuser_modified) { $events->trigger('webuser', 'save', array('webuser' => $this)); } return true; }
/** * Update the properties of an existing permission in Database * * * @return boolean True if success, Exception otherwise */ public function update() { global $DB; if (empty($this->id)) { return false; } $value = @$this->value; if (!isset($this->value)) { $value = ""; } else { $value = json_encode($this->value); } $ok = $DB->execute(' UPDATE nv_permissions SET website = :website, name = :name, scope = :scope, type = :type, function = :function, profile = :profile, user = :user, value = :value WHERE id = :id', array(':id' => $this->id, ':website' => $this->website, ':name' => value_or_default($this->name, ""), ':scope' => value_or_default($this->scope, ""), ':type' => value_or_default($this->type, ""), ':function' => value_or_default($this->function, 0), ':profile' => value_or_default($this->profile, 0), ':user' => value_or_default($this->user, 0), ':value' => $value)); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
/** * Update the properties of an existing user in Database * * * @return boolean True if success, Exception otherwise */ public function update() { global $DB; if (empty($this->id)) { return false; } $ok = $DB->execute(' UPDATE nv_users SET email = :email, username = :username, password = :password, language = :language, timezone = :timezone, websites = :websites, profile = :profile, date_format = :date_format, decimal_separator = :decimal_separator, thousands_separator = :thousands_separator, skin = :skin, blocked = :blocked, attempts = :attempts, cookie_hash = :cookie_hash, activation_key = :activation_key WHERE id = :id', array(':language' => $this->language, ':id' => $this->id, ':email' => $this->email, ':username' => $this->username, ':password' => $this->password, ':timezone' => $this->timezone, ':websites' => empty($this->websites) ? '' : json_encode($this->websites), ':profile' => $this->profile, ':date_format' => $this->date_format, ':decimal_separator' => value_or_default($this->decimal_separator, "."), ':thousands_separator' => value_or_default($this->thousands_separator, ""), ':skin' => value_or_default($this->skin, "cupertino"), ':blocked' => value_or_default($this->blocked, 0), ':attempts' => value_or_default($this->attempts, 0), ':cookie_hash' => value_or_default($this->cookie_hash, ""), ':activation_key' => value_or_default($this->activation_key, ""))); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
public function update() { global $DB; $ok = $DB->execute(' UPDATE nv_menus SET codename = :codename, icon = :icon, lid = :lid, notes = :notes, functions = :functions, enabled = :enabled WHERE id = :id', array('id' => $this->id, 'codename' => value_or_default($this->codename, ""), 'icon' => value_or_default($this->icon, ""), 'lid' => value_or_default($this->lid, 0), 'notes' => value_or_default($this->notes, ""), 'functions' => json_encode($this->functions), 'enabled' => value_or_default($this->enabled, 0))); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
public function update() { global $DB; global $user; $message = htmlentities($this->message, ENT_COMPAT, 'UTF-8', true); $ok = $DB->execute(' UPDATE nv_comments SET item = :item, user = :user, name = :name, email = :email, url = :url, date_created = :date_created, date_modified = :date_modified, last_modified_by = :last_modified_by, reply_to = :reply_to, status = :status, message = :message WHERE id = :id ', array(":item" => value_or_default($this->item, 0), ":user" => value_or_default($this->user, 0), ":name" => empty($this->name) ? "" : $this->name, ":email" => empty($this->email) ? "" : $this->email, ":url" => empty($this->url) ? "" : $this->url, ":date_created" => $this->date_created, ":date_modified" => core_time(), ":last_modified_by" => value_or_default($user->id, 0), ":reply_to" => value_or_default($this->reply_to, 0), ":status" => value_or_default($this->status, 0), ":message" => $message, ":id" => $this->id)); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
public static function add_comment($type, $id, $comment, $background = '') { global $DB; global $website; global $user; if (empty($comment)) { return 'comment_empty'; } $DB->execute(' INSERT INTO nv_notes (id, website, user, item_type, item_id, background, note, date_created) VALUES ( 0, :website, :user, :item_type, :item_id, :background, :note, :date_created )', array(':website' => $website->id, ':user' => value_or_default($user->id, 0), ':item_type' => value_or_default($type, ''), ':item_id' => value_or_default($id, 0), ':background' => value_or_default($background, ""), ':note' => value_or_default($comment, ""), ':date_created' => time())); return 'true'; }
public function update() { global $DB; $ok = $DB->execute(' UPDATE nv_backups SET size = :size, status = :status, title = :title, notes = :notes, file = :file, runtime = :runtime WHERE id = :id AND website = :website', array('id' => $this->id, 'website' => $this->website, 'size' => value_or_default($this->size, 0), 'status' => value_or_default($this->status, ''), 'title' => value_or_default($this->title, ''), 'notes' => value_or_default($this->notes, ''), 'file' => value_or_default($this->file, ''), 'runtime' => value_or_default($this->runtime, 0))); if (!$ok) { throw new Exception($DB->get_last_error()); } return true; }
function nvweb_languages($vars = array()) { global $website; global $current; $out = array(); $class = value_or_default($vars['class'], ""); switch ($vars['mode']) { case 'code': foreach ($website->languages_published as $lang) { if ($current['lang'] == $lang) { $out[] = '<a href="?lang=' . $lang . '" class="language-selected ' . $class . ' active">' . $lang . '</a>'; } else { $out[] = '<a href="?lang=' . $lang . '" class="' . $class . '">' . $lang . '</a>'; } } $out = implode('<span class="nv-language-separator">' . $vars['separator'] . '</span>', $out); break; case 'name': foreach ($website->languages_published as $lang) { $lang_name = language::name_by_code($lang); if ($current['lang'] == $lang) { $out[] = '<a href="?lang=' . $lang . '" class="language-selected ' . $class . ' active">' . $lang_name . '</a>'; } else { $out[] = '<a href="?lang=' . $lang . '" class="' . $class . '">' . $lang_name . '</a>'; } } $out = implode('<span class="nv-language-separator">' . $vars['separator'] . '</span>', $out); break; case 'flag': foreach ($website->languages_published as $lang) { $flag = $lang; if (strpos($lang, '_') > 0) { $code = explode('_', $lang); $flag = $code[0]; $extra = ' ' . $code[1]; } if ($current['lang'] == $lang) { $out[] = '<a href="?lang=' . $lang . '" class="language-selected ' . $class . ' active"><img src="' . NVWEB_ABSOLUTE . '/object?type=flag&code=' . $flag . '" />' . $extra . '</a>'; } else { $out[] = '<a href="?lang=' . $lang . '" class="' . $class . '"><img src="' . NVWEB_ABSOLUTE . '/object?type=flag&code=' . $flag . '" alt="' . $flag . '" />' . $extra . '</a>'; } } $out = implode('<span class="nv-language-separator">' . $vars['separator'] . '</span>', $out); break; case 'li': foreach ($website->languages_published as $lang) { if (empty($lang)) { continue; } $lang_name = language::name_by_code($lang); if ($current['lang'] == $lang) { $out[] = '<li><a href="?lang=' . $lang . '" class="language-selected ' . $class . ' active">' . $lang_name . '</a></li>'; } else { $out[] = '<li><a href="?lang=' . $lang . '" class="' . $class . '">' . $lang_name . '</a></li>'; } } $out = implode('<span class="nv-language-separator">' . $vars['separator'] . '</span>', $out); break; case 'select': default: $out[] = '<select class="' . $class . '" onchange="if(this.value!=\'' . $current['lang'] . '\') window.location.href = \'?lang=\'+this.value;">'; foreach ($website->languages_published as $lang) { if (empty($lang)) { continue; } $lang_name = language::name_by_code($lang); if ($current['lang'] == $lang) { $out[] = '<option value="' . $lang . '" selected="selected">' . $lang_name . '</option>'; } else { $out[] = '<option value="' . $lang . '">' . $lang_name . '</option>'; } } $out[] = '</select>'; $out = implode("\n", $out); break; } return $out; }
public function update() { global $DB; global $user; if (!is_array($this->categories)) { $this->categories = array(); } if (!is_array($this->exclusions)) { $this->exclusions = array(); } if (!empty($user->id)) { if ($user->permission("blocks.edit") == 'false') { throw new Exception(t(610, "Sorry, you are not allowed to execute this function.")); } } $groups = ''; if (is_array($this->groups)) { $this->groups = array_unique($this->groups); // remove duplicates $this->groups = array_filter($this->groups); // remove empty if (!empty($this->groups)) { $groups = 'g' . implode(',g', $this->groups); } } if ($groups == 'g') { $groups = ''; } $ok = $DB->execute('UPDATE nv_blocks SET `type` = :type, date_published = :date_published, date_unpublish = :date_unpublish, `position` = :position, fixed = :fixed, categories = :categories, exclusions = :exclusions, elements = :elements, `trigger` = :trigger, `action` = :action, access = :access, groups = :groups, enabled = :enabled, notes = :notes, date_modified = :date_modified WHERE id = :id AND website = :website ', array(':id' => $this->id, ':website' => $this->website, ':type' => $this->type, ':date_published' => value_or_default($this->date_published, 0), ':date_unpublish' => value_or_default($this->date_unpublish, 0), ':position' => value_or_default($this->position, 0), ':fixed' => value_or_default($this->fixed, 0), ':categories' => implode(',', $this->categories), ':exclusions' => implode(',', $this->exclusions), ':elements' => json_encode($this->elements), ':access' => value_or_default($this->access, 0), ':groups' => $groups, ':enabled' => value_or_default($this->enabled, 0), ':trigger' => serialize($this->trigger), ':action' => serialize($this->action), ':notes' => value_or_default($this->notes, ""), ':date_modified' => time())); if (!$ok) { throw new Exception($DB->get_last_error()); } webdictionary::save_element_strings('block', $this->id, $this->dictionary, $this->website); return true; }
public function update() { global $DB; $ok = $DB->execute(' UPDATE nv_websites SET name = ?, protocol = ?, subdomain = ?, domain = ?, folder = ?, redirect_to = ?, wrong_path_action = ?, wrong_path_redirect = ?, empty_path_action = ?, languages = ?, languages_published = ?, aliases = ?, word_separator = ?, date_format = ?, tinymce_css = ?, resize_uploaded_images = ?, comments_enabled_for = ?, comments_default_moderator = ?, share_files_media_browser = ?, additional_scripts = ?, permission = ?, mail_mailer = ?, mail_server = ?, mail_port = ?, mail_security = ?, mail_user = ?, mail_address = ?, mail_password = ?, contact_emails = ?, homepage = ?, default_timezone = ?, metatag_description = ?, metatag_keywords = ?, metatags = ?, favicon = ?, theme = ?, theme_options = ? WHERE id = ' . $this->id, array(value_or_default($this->name, ""), value_or_default($this->protocol, "http://"), value_or_default($this->subdomain, ""), value_or_default($this->domain, ""), value_or_default($this->folder, ""), value_or_default($this->redirect_to, ""), value_or_default($this->wrong_path_action, "blank"), value_or_default($this->wrong_path_redirect, ""), value_or_default($this->empty_path_action, "homepage_redirect"), is_array($this->languages) ? serialize($this->languages) : $this->languages, is_array($this->languages_published) ? serialize($this->languages_published) : $this->languages_published, json_encode($this->aliases), value_or_default($this->word_separator, "-"), $this->date_format, value_or_default($this->tinymce_css, ""), $this->resize_uploaded_images, $this->comments_enabled_for, $this->comments_default_moderator, $this->share_files_media_browser, $this->additional_scripts, $this->permission, value_or_default($this->mail_mailer, ""), value_or_default($this->mail_server, ""), value_or_default($this->mail_port, 25), value_or_default($this->mail_security, 0), value_or_default($this->mail_user, ""), value_or_default($this->mail_address, ""), value_or_default($this->mail_password, ""), serialize($this->contact_emails), $this->homepage, $this->default_timezone, json_encode($this->metatag_description), json_encode($this->metatag_keywords), json_encode($this->metatags), value_or_default($this->favicon, 0), value_or_default($this->theme, ""), json_encode($this->theme_options))); if (!$ok) { throw new Exception($DB->get_last_error()); } if (!file_exists(NAVIGATE_PRIVATE . '/' . $this->id)) { @mkdir(NAVIGATE_PRIVATE . '/' . $this->id, 0755, true); @mkdir(NAVIGATE_PRIVATE . '/' . $this->id . '/files', 0755, true); @mkdir(NAVIGATE_PRIVATE . '/' . $this->id . '/templates', 0755, true); @mkdir(NAVIGATE_PRIVATE . '/' . $this->id . '/thumbnails', 0755, true); @mkdir(NAVIGATE_PRIVATE . '/' . $this->id . '/webgets', 0755, true); @mkdir(NAVIGATE_PRIVATE . '/' . $this->id . '/backups', 0755, true); @mkdir(NAVIGATE_PRIVATE . '/' . $this->id . '/cache', 0755, true); } // if allowed, send statistics to navigatecms.com if (NAVIGATECMS_STATS) { global $user; @core_curl_post('http://statistics.navigatecms.com/website/update', array('ip' => $_SERVER['SERVER_ADDR'], 'website_id' => $this->id, 'name' => $this->name, 'url' => $this->absolute_path(), 'folder' => $this->folder, 'word_separator' => $this->word_separator, 'homepage' => $this->homepage, 'theme' => $this->theme, 'emails' => serialize($this->contact_emails), 'languages' => serialize($this->languages_published), 'permission' => $this->permission, 'author_name' => $user->username, 'author_email' => $user->email, 'author_language' => $user->language), NULL, 10, 'post'); } return true; }
function test_main_value_or_default() { assert_equal(value_or_default(10, 20), 10); assert_equal(value_or_default(0, 20), 20); assert_equal(value_or_default(null, 20), 20); assert_equal(value_or_default('hello', 'world'), 'hello'); assert_equal(value_or_default('', 'world'), 'world'); assert_equal(value_or_default(10, 20), v(10, 20)); assert_equal(value_or_default(0, 20), v(0, 20)); }