/** * Remove an object from Memcache * @deprecated 3.8.7 Calls to this method should be replaced with deleteMemcacheObject() with the same parameter(s) * @since Version 3.7.5 * @param string|boolean $key * @return mixed */ protected function deleteCache($key = false) { if (!$this->useCache) { return false; } return removeMemcacheObject($key); }
function deleteMemcacheObject($key = false) { return removeMemcacheObject($key); }
/** * Update a PM * @since Version 3.3 * @version 3.3 * @return boolean */ public function commit() { if (!$this->id) { throw new Exception("Cannot commit changes to PM - PM does not exist!"); return false; } $this->validate(); // Theoretically nothing but the type should change. I'll leave the rest in for now... $dataArray = array(); $dataArray['privmsgs_type'] = $this->type; $dataArray['privmsgs_subject'] = $this->subject; $dataArray['privmsgs_from_userid'] = $this->from_user_id; $dataArray['privmsgs_to_userid'] = $this->to_user_id; $dataArray['privmsgs_ip'] = encode_ip($_SERVER['REMOTE_ADDR']); $dataArray['privmsgs_enable_bbcode'] = $this->enable_bbcode; $dataArray['privmsgs_enable_html'] = $this->enable_html; $dataArray['privmsgs_enable_smilies'] = $this->enable_smilies; $dataArray['privmsgs_attach_sig'] = $this->enable_signature; $dataArray['hide_from'] = $this->hide_from; $dataArray['hide_to'] = $this->hide_to; if (filter_var($this->id, FILTER_VALIDATE_INT)) { // Update $where = array("privmsgs_id = ?" => $this->id); $this->db->update("nuke_bbprivmsgs", $dataArray, $where); $data = array('privmsgs_bbcode_uid' => $this->bbcode_uid, 'privmsgs_text' => $this->body); $where = array("privmsgs_text_id = ?" => $this->id); $this->db->update("nuke_bbprivmsgs_text", $data, $where); removeMemcacheObject($this->mckey); return true; } else { // Insert $this->db->insert("nuke_bbprivmsgs", $dataArray); $this->id = $this->db->lastInsertId(); $data = array('privmsgs_bbcode_uid' => $this->bbcode_uid, 'privmsgs_text' => $this->body, 'privmsgs_text_id' => $this->id); $this->db->insert("nuke_bbprivmsgs_text", $data); return true; } }
/** * Commit this news topic * @since Vesion 3.5 * @return boolean */ public function commit() { if (!$this->validate()) { return false; } if ($this->db instanceof \sql_db) { $dataArray = array(); $dataArray['topictext'] = $this->db->real_escape_string($this->title); $dataArray['topicname'] = $this->db->real_escape_string($this->alias); $dataArray['desc'] = $this->db->real_escape_string($this->desc); if ($this->id) { $where = array(); $where['topicid'] = $this->db->real_escape_string($this->id); removeMemcacheObject($this->mckey); $query = $this->db->buildQuery($dataArray, "nuke_topics", $where); } else { $query = $this->db->buildQuery($dataArray, "nuke_topics"); } if ($rs = $this->db->query($query)) { return true; } else { throw new \Exception($this->db->error . "\n\n" . $query); return false; } } else { $data = array("topictext" => $this->title, "topicname" => $this->alias, "desc" => $this->desc); if ($this->id) { $where = array("topicid = ?" => $this->id); removeMemcacheObject($this->mckey); $this->db->update("nuke_topics", $data, $where); return true; } else { $this->db->insert("nuke_topics", $data); $this->id = $this->db->lastInsertId(); return true; } } }
/** * Check if this image has become stale * @since Version 3.8.7 * @return boolean */ public function isStale() { if (!$this->Date instanceof DateTime) { return true; } $Now = new DateTime(); $Diff = $this->Date->diff($Now); if ($Diff->d >= self::MAXAGE) { removeMemcacheObject($this->mckey); return true; } return false; }
/** * Commit changes to the database * @since Version 3.0.1 * @version 3.7.5 * @return boolean */ public function commit() { // Fetch geodata and populate the vars //$url = "http://maps.google.com/maps/geo?q=".$this->lat.",".$this->lon."&output=json&sensor=false"; $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" . $this->lat . "," . $this->lon . "&sensor=false"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $jsondata = json_decode($data, true); curl_close($ch); if (isset($jsondata['results'][0]['address_components'])) { $row = $jsondata['results'][0]['address_components']; } if (empty($this->region) || empty($this->country)) { if (isset($jsondata['Placemark']) && ($area = $jsondata['Placemark'][0]['AddressDetails']['Country'])) { $this->country = $area['CountryNameCode']; $this->region = isset($area['AdministrativeArea']['AdministrativeAreaName']) ? $area['AdministrativeArea']['AdministrativeAreaName'] : NULL; $this->locality = isset($area['AdministrativeArea']['Locality']['LocalityName']) ? $area['AdministrativeArea']['Locality']['LocalityName'] : NULL; $this->neighbourhood = isset($area['CountryNameCode']['someotherarea']) ? $area['CountryNameCode']['someotherarea'] : NULL; } elseif (isset($row)) { // Loop through the results and try to populate the object foreach ($row as $area) { if ($area['types'][0] == "country") { $this->country = $area['short_name']; } if ($area['types'][0] == "administrative_area_level_2") { $this->region = $area['long_name']; } if ($area['types'][0] == "administrative_area_level_3") { $this->neighbourhood = $area['long_name']; } if ($area['types'][0] == "locality") { $this->locality = $area['long_name']; } } } if (empty($this->country) || empty($this->region) || empty($this->locality)) { // Google doesn't give data in a consistent bloody format - go here instead $url = "http://www.geoplugin.net/extras/location.gp?lat=" . $this->lat . "&long=" . $this->lon . "&format=php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $geodata = curl_exec($ch); $geodata = unserialize($geodata); curl_close($ch); $this->country = $geodata['geoplugin_countryCode']; $this->region = $geodata['geoplugin_region']; $this->locality = $geodata['geoplugin_place']; $this->neighbourhood = NULL; } } /** * Fill in the gaps with the new Place object */ if (empty($this->region) || empty($this->country)) { $Place = new Place($this->lat, $this->lon); if (!empty($Place->Country->code)) { $this->country = $Place->Country->code; } if (!empty($Place->Region->name)) { $this->region = $Place->Region->name; } } if (empty($this->slug)) { $this->createSlug(); } if (empty($this->topicid)) { $this->topicid = 0; } $find = array("@Victoria@i", "@New South Wales@i", "@Queensland@i", "@South Australia@i", "@Tasmania@i", "@Northern Territory@i", "@Western Australia@i", "@Australian Capital Territory@i"); $replace = array("VIC", "NSW", "QLD", "SA", "TAS", "NT", "WA", "ACT"); $this->region = preg_replace($find, $replace, $this->region); // Defaults for new locations if (empty($this->id)) { $this->active = 0; $this->date_added = time(); $this->date_modified = time(); } $this->name = trim($this->name); /** * Validate the data */ $this->validate(); if ($this->db instanceof \sql_db) { try { $dataArray = array(); $dataArray['lat'] = $this->db->real_escape_string($this->lat); $dataArray['long'] = $this->db->real_escape_string($this->lon); $dataArray['country'] = $this->db->real_escape_string($this->country); $dataArray['region'] = $this->db->real_escape_string($this->region); $dataArray['locality'] = $this->db->real_escape_string($this->locality); $dataArray['name'] = $this->db->real_escape_string($this->name); $dataArray['desc'] = $this->db->real_escape_string($this->desc); $dataArray['topicid'] = $this->db->real_escape_string($this->topicid); $dataArray['zoom'] = $this->db->real_escape_string($this->zoom); $dataArray['active'] = $this->db->real_escape_string($this->active); $dataArray['date_added'] = $this->db->real_escape_string($this->date_added); $dataArray['date_modified'] = $this->db->real_escape_string($this->date_modified); $dataArray['user_id'] = $this->db->real_escape_string($this->user_id); $dataArray['slug'] = $this->db->real_escape_string($this->slug); $dataArray['traffic'] = $this->db->real_escape_string($this->traffic); $dataArray['environment'] = $this->db->real_escape_string($this->environment); $dataArray['amenities'] = $this->db->real_escape_string($this->amenities); $dataArray['directions_driving'] = $this->db->real_escape_string($this->directions_driving); $dataArray['directions_parking'] = $this->db->real_escape_string($this->directions_parking); $dataArray['directions_pt'] = $this->db->real_escape_string($this->directions_pt); if (!empty($this->id)) { $whereClause = array(); $whereClause['id'] = $this->id; $query = $this->db->buildQuery($dataArray, "location", $whereClause); } else { $query = $this->db->buildQuery($dataArray, "location"); } if ($this->db->query($query)) { if (empty($this->id)) { $this->id = $this->db->insert_id; } return true; } else { throw new Exception($this->db->error); return false; } } catch (Exception $e) { throw new Exception($e->getMessage()); } } else { $data = array("lat" => $this->lat, "long" => $this->lon, "country" => $this->country, "region" => $this->region, "region_slug" => $this->makeRegionSlug(), "locality" => $this->locality, "name" => $this->name, "desc" => $this->desc, "topicid" => $this->topicid, "zoom" => $this->zoom, "active" => $this->active, "date_added" => $this->date_added, "date_modified" => $this->date_modified, "user_id" => $this->user_id, "slug" => $this->slug, "traffic" => $this->traffic, "environment" => $this->environment, "directions_driving" => $this->directions_driving, "directions_parking" => $this->directions_parking, "directions_pt" => $this->directions_pt, "amenities" => $this->amenities); if (filter_var($this->id, FILTER_VALIDATE_INT) && $this->id > 0) { $where = array("id = ?" => $this->id); $this->db->update("location", $data, $where); } else { $this->db->insert("location", $data); $this->id = $this->db->lastInsertId(); removeMemcacheObject("railpage:locations.newest"); } } }
/** * Commit changes to existing user or create new user * @since Version 3.1 * @version 3.9 * @param boolean $force Force an update of this user even if certain values (eg a password) are empty * @return boolean */ public function commit($force = false) { if (!$this->validate($force)) { // Get out early return false; } if (!empty($this->mckey) && getMemcacheObject($this->mckey)) { removeMemcacheObject($this->mckey); } $dataArray = array(); $dataArray['provider'] = $this->provider; $dataArray['meta'] = json_encode($this->meta); $dataArray['user_opts'] = json_encode($this->preferences); $dataArray['username'] = $this->username; $dataArray['user_active'] = $this->active; $dataArray['user_regdate'] = $this->regdate; $dataArray['user_level'] = $this->level; $dataArray['user_posts'] = $this->posts; $dataArray['user_style'] = $this->style; $dataArray['theme'] = $this->theme; $dataArray['user_lang'] = $this->lang; $dataArray['user_dateformat'] = $this->date_format; $dataArray['user_rank'] = $this->rank_id; $dataArray['user_from'] = $this->location; $dataArray['user_occ'] = $this->occupation; $dataArray['user_interests'] = $this->interests; $dataArray['name'] = $this->real_name; $dataArray['timezone'] = $this->timezone; $dataArray['user_website'] = $this->website; $dataArray['user_allow_viewonline'] = $this->hide; $dataArray['uWheat'] = $this->wheat; $dataArray['uChaff'] = $this->chaff; $dataArray['api_key'] = $this->api_key; $dataArray['api_secret'] = $this->api_secret; $dataArray['user_report_optout'] = $this->report_optout; $dataArray['user_warnlevel'] = $this->warning_level; $dataArray['disallow_mod_warn'] = $this->warning_exempt; $dataArray['user_group_cp'] = $this->group_cp; $dataArray['user_group_list_cp'] = $this->group_list_cp; $dataArray['user_active_cp'] = $this->active_cp; $dataArray['user_forum_postsperpage'] = $this->items_per_page; $dataArray['user_avatar'] = $this->avatar; $dataArray['user_avatar_gravatar'] = $this->avatar_gravatar; $dataArray['user_avatar_type'] = $this->avatar_type; $dataArray['user_avatar_width'] = $this->avatar_width; $dataArray['user_avatar_height'] = $this->avatar_height; $dataArray['user_new_privmsg'] = $this->privmsg_new; $dataArray['user_unread_privmsg'] = $this->privmsg_unread; $dataArray['user_last_privmsg'] = $this->privmsg_last_id; $dataArray['user_viewemail'] = $this->email_show; $dataArray['storynum'] = $this->news_submissions; $dataArray['user_notify'] = $this->notify; $dataArray['user_notify_pm'] = $this->notify_privmsg; $dataArray['user_email'] = $this->contact_email; $dataArray['femail'] = $this->contact_email_public; $dataArray['user_icq'] = $this->contact_icq; $dataArray['user_aim'] = $this->contact_aim; $dataArray['user_yim'] = $this->contact_yim; $dataArray['user_msnm'] = $this->contact_msn; $dataArray['user_sig'] = $this->signature; $dataArray['user_attachsig'] = $this->signature_attach; $dataArray['user_showsigs'] = $this->signature_showall; $dataArray['user_sig_bbcode_uid'] = $this->signature_bbcode_uid; $dataArray['user_password'] = $this->password; $dataArray['user_password_bcrypt'] = $this->password_bcrypt; $dataArray['user_lastvisit'] = $this->lastvisit; $dataArray['user_session_time'] = $this->session_time; $dataArray['user_session_page'] = $this->session_page; $dataArray['user_current_visit'] = $this->session_current; $dataArray['user_last_visit'] = $this->session_last; $dataArray['last_session_ip'] = $this->session_ip; $dataArray['last_session_cslh'] = $this->session_cslh; $dataArray['last_session_ignore'] = $this->session_mu_ignore; $dataArray['user_enablerte'] = $this->enable_rte; $dataArray['user_enableglossary'] = $this->enable_glossary; $dataArray['user_allowhtml'] = $this->enable_html; $dataArray['user_allowbbcode'] = $this->enable_bbcode; $dataArray['user_allowsmile'] = $this->enable_emoticons; $dataArray['user_allowavatar'] = $this->enable_avatar; $dataArray['user_allow_pm'] = $this->enable_privmsg; $dataArray['user_popup_pm'] = $this->enable_privmsg_popup; $dataArray['flickr_oauth_token'] = $this->flickr_oauth_token; $dataArray['flickr_oauth_token_secret'] = $this->flickr_oauth_secret; $dataArray['flickr_nsid'] = $this->flickr_nsid; $dataArray['flickr_username'] = $this->flickr_username; $dataArray['user_actkey'] = $this->act_key; $dataArray['oauth_consumer_id'] = $this->oauth_id; $dataArray['sidebar_type'] = $this->sidebar_type; $dataArray['user_enableautologin'] = $this->enable_autologin; $dataArray['user_enablessl'] = $this->ssl; $dataArray['facebook_user_id'] = $this->facebook_user_id; $dataArray['reported_to_sfs'] = $this->reported_to_sfs; if ($this->db instanceof \sql_db) { // Escape values for SQL foreach ($dataArray as $key => $val) { $dataArray[$key] = $this->db->real_escape_string($val); } if ($this->id) { // Update existing user $where = array(); $where['user_id'] = $this->db->real_escape_string($this->id); $query = $this->db->buildQuery($dataArray, "nuke_users", $where); } else { // Create a new user $query = $this->db->buildQuery($dataArray, "nuke_users"); } try { if ($this->db->query($query)) { if (!$this->id) { $this->id = $this->db->insert_id; } $return = true; } else { throw new \Exception($this->db->error); } } catch (Exception $e) { global $Error; $Error->save($e); $return = false; throw new \Exception($e->getMessage()); } return $return; } else { if ($this->id) { $this->db->update("nuke_users", $dataArray, array("user_id = ?" => $this->id)); } else { $this->db->insert("nuke_users", $dataArray); $this->id = $this->db->lastInsertId(); $this->createUrls(); } return true; } }
/** * Flush any cached data from Memcached * @since Version 3.8.7 * @return $this */ public function flushMemcached() { if (!empty($this->mckey)) { removeMemcacheObject("railpage:locos.class_id=" . $this->id); removeMemcacheObject("railpage:locos.class_id=" . $this->slug); } return $this; }