function get_favicon($url) { if (!$url || !is_url($url)) { return false; } if (!isset($_GET['refresh']) && UNIX_TIME <= get_timestamp($url) + FAVICON_CACHE_TTL) { $cache = get_url_filename($url); return file_get_contents($cache); } else { return update_cache($url); } }
function currency_converted($total) { /* $currency_selected = Keywords::find(5); $currency_sel = $currency_selected->keyword; */ $currency_sel = Config::get('app.generic_keywords.Currency'); if ($currency_sel == '$') { $currency_sel = "USD"; } else { $currency_sel = Config::get('app.generic_keywords.Currency'); } if ($currency_sel != 'USD') { $check = check_cache($currency_sel); if (!$check) { $url = "http://currency-api.appspot.com/api/USD/" . $currency_sel . ".json?key=65d69f1a909b37e41272574dcd20c30fb2fbb06e"; $result = file_get_contents($url); $result = json_decode($result); $rate = $result->rate; update_cache($currency_sel, $rate); $total = $total * $rate; } else { $rate = Cash::where('key', 'like', '%' . $currency_sel . '%')->first(); $total = $total * $rate->value; } } else { $total = $total; } return $total; }
function phpquranOnline() { global $SQL, $dbprefix, $config, $session; // get information .. $ip = get_ip(); $agent = $SQL->escape($_SERVER['HTTP_USER_AGENT']); $timeout = 600; //seconds //10 min $time = time(); $timeout2 = $time - $timeout; $username = '******'; //--- if (!empty($ip) && !empty($agent) && !empty($session)) { $rep_query = array('REPLACE' => 'ip, username, agent, time, session', 'INTO' => "{$dbprefix}online", 'VALUES' => "'{$ip}','{$username}','{$agent}','{$time}','{$session}'", 'UNIQUE' => "session='{$session}'"); $SQL->build($rep_query); } $last_online_time_update = get_cache_value('last_online_time_update'); //clean online table if (time() - $last_online_time_update >= 3600) { $query_del = array('DELETE' => "{$dbprefix}online", 'WHERE' => "time < '{$timeout2}'"); $SQL->build($query_del); //update last_online_time_update update_cache('last_online_time_update', time()); } }
// if ID <> 0 then get template info from database $sql = "UPDATE " . DB_PREPEND . "phpwcms_template SET " . "template_name='" . aporeplace($template["name"]) . "', " . "template_default=" . $template["default"] . ", " . "template_var='" . aporeplace(serialize($template)) . "' " . "WHERE template_id=" . $template["id"]; } else { // if ID = 0 then show create new template form $sql = "INSERT INTO " . DB_PREPEND . "phpwcms_template (" . "template_name, template_default, template_var) VALUES ('" . aporeplace($template["name"]) . "', " . $template["default"] . ", '" . aporeplace(serialize($template)) . "')"; } // update or insert data entry @mysql_query($sql, $db) or die("error while updating or inserting template datas"); if (empty($template["id"]) || $createcopy == 1) { $template["id"] = mysql_insert_id($db); } //now proof for default template definition if ($template["default"]) { mysql_query("UPDATE " . DB_PREPEND . "phpwcms_template SET template_default=0 " . "WHERE template_id != " . $template["id"], $db); } update_cache(); headerRedirect(PHPWCMS_URL . 'phpwcms.php?' . get_token_get_string('csrftoken') . '&do=admin&p=11&s=' . $template["id"]); } if ($template["id"]) { // read the given template datas from db $sql = "SELECT * FROM " . DB_PREPEND . "phpwcms_template WHERE template_id=" . $template["id"] . " LIMIT 1"; if ($result = mysql_query($sql, $db)) { if ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { unset($template); $template = unserialize($row["template_var"]); $template["id"] = $row["template_id"]; $template["default"] = $row["template_default"]; // compatibility for older releases where only // 1 css file could be stored per template if (is_string($template['css'])) { $template['css'] = array($template['css']);
/** * 导入插件处理函数 * * @access public * @return void */ public function _import_post() { $plugin = $this->input->post('plugin', TRUE); !class_exists('SimpleXMLElement') and $this->_message('检测到服务器不支持SimpleXMLElement类,请开启后重试!', 'plugin/import/', TRUE); @libxml_use_internal_errors(TRUE); try { $plugin_xml = new SimpleXMLElement($plugin, NULL, TRUE); if ((string) $plugin_xml->attributes() === 'DiliCMS' and $plugin_info = (array) $plugin_xml->plugin[0]) { $_POST = $plugin_info; if ($this->_validate_model_form('', FALSE)) { //新增分类模型 $this->plugin_mdl->add_plugin($_POST); //更新缓存 update_cache('plugin'); $this->_message('插件安装成功!', 'plugin/view', TRUE); } else { $this->_message(validation_errors(), 'plugin/import/', TRUE); } } else { $this->_message('不合法的安装XML文件!', 'plugin/import/', TRUE); } } catch (Exception $e) { $this->_message('XML文件读取失败,请检查地址!', 'plugin/import/', TRUE); } }
/** * 删除处理函数 * * @access public * @return void */ public function _del_post() { $this->_check_permit(); $ids = $this->input->get_post('classid', TRUE); $model = $this->input->get('model', TRUE); $model_data = $this->db->select('id')->where('name', $model)->get($this->db->dbprefix('cate_models'))->row(); $model_id = $model_data->id; if ($ids) { if (!is_array($ids)) { $ids = array($ids); } //搜索子分类 $where_string = 'classid < 0 '; foreach ($ids as $v) { $_category = $this->db->select('path')->where('classid', $v)->get($this->db->dbprefix('u_c_') . $model)->row(); $where_string .= " OR path Like '" . $_category->path . ',{' . $v . "}%'"; } $this->db->select('classid')->from($this->db->dbprefix('u_c_') . $model); $this->db->where($where_string); $result = $this->db->get()->result(); foreach ($result as $v) { array_push($ids, $v->classid); } $this->plugin_manager->trigger('deleting', $ids); $attachments = $this->db->select('name, folder, type')->where('model', $model_id)->where_in('content', $ids)->where('from', 1)->get($this->db->dbprefix('attachments'))->result(); foreach ($attachments as $attachment) { $this->platform->file_delete(DILICMS_SHARE_PATH . '../' . setting('attachment_dir') . '/' . $attachment->folder . '/' . $attachment->name . '.' . $attachment->type); } $this->db->where('model', $model_id)->where_in('content', $ids)->where('from', 1)->delete($this->db->dbprefix('attachments')); $this->db->where_in('classid', $ids)->delete($this->db->dbprefix('u_c_') . $model); $this->plugin_manager->trigger('deleted', $ids); if ($model_data->auto_update) { update_cache('category', $model); } } $this->_message('删除操作成功完成!', '', TRUE); }
/** * 更新缓存处理函数 * * @access public * @return void */ public function _cache_post() { $this->_check_permit(); $cache = $this->input->post('cache'); if ($cache and is_array($cache)) { update_cache($cache); } $this->_message("缓存更新成功!", '', TRUE); }
while (!feof($handle)) { $read_data = fgets($handle); } fclose($handle); return $read_data; } else { return false; } } function update_cache($write_data) { if (is_writable(dirname(CACHE_FILE))) { $handle = fopen(CACHE_FILE, 'w'); $write_data = time() . "\r\n" . $write_data; fwrite($handle, $write_data); fclose($handle); return true; } else { return false; } } if (time() - last_cache() > 60 * CACHE_INTERVAL) { require_once 'twitter-api.php'; $twitter_api = new TwitterAPIExchange(array('consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret, 'oauth_access_token' => $access_token, 'oauth_access_token_secret' => $access_token_secret)); if ($response = $twitter_api->setGetfield('?screen_name=' . $username . '&count=10')->buildOauth('https://api.twitter.com/1.1/statuses/user_timeline.json', 'GET')->performRequest()) { update_cache($response); echo $response; exit; } } echo read_cache();
function refresh(&$row) { global $wgRequest, $wgTemplateName, $wgTermField, $wgDefinitionField; $templatename = $wgTemplateName ? $wgTemplateName : "Lexicon"; $termfield = $wgTermField ? $wgTermField : "term"; $definitionfield = $wgDefinitionField ? $wgDefinitionField : "definition"; $dbr = wfGetDB(DB_MASTER); $res = $dbr->select('templatelinks', array('tl_from'), array('tl_from' => $row->id, 'tl_title' => $templatename), __METHOD__); if ($row1 = $res->fetchObject()) { $term = $definition = ''; $title = Title::newFromID($row1->tl_from); $id = $title->getArticleId(); $article = Article::newFromId($id); $content1 = $article->getRawText(); $content = str_replace("\n", '', $article->getRawText()); $url = $title->getFullUrl(); $termTeplate_reg = "/{{[\\s]*" . $templatename . "(.*)}}/i"; if (preg_match($termTeplate_reg, $content, $matches)) { $paras = $matches[1]; } else { return false; } $fields = preg_split("/\\|/", $paras); foreach ($fields as $field) { $value = preg_split("/=/", $field); if (trim($value[0]) == $termfield) { $term = trim($value[1]); } if (trim($value[0]) == $definitionfield) { $definition = trim($value[1]); } } if (!strlen($definition) || !strlen($term)) { return false; } $row->term = $term; $row->def = $definition; $row->url = $url; update_cache($row1->tl_from, $term, $definition, $url); } else { $dbw = wfGetDB(DB_MASTER); $dbw->delete('Lexicon_cache', array('id' => $row->id), __METHOD__); return false; } return true; }
/** * 分类模型字段删除入口 * * @access public * @param int * @return void */ public function del_field($id = 0) { $field = $this->category_mdl->get_field_by_id($id); !$field and $this->_message('不存在的分类字段!', '', FALSE); $model = $this->category_mdl->get_category_model_by_id($field->model); !$model and $this->_message('不存在的分类模型!', '', FALSE); if ($field and $model) { $this->category_mdl->del_category_field($model, $field); update_cache('category', $model->name); } $this->_message('字段删除成功!', 'category/fields/' . $model->id, TRUE); }
/** * 修改用户组表单生成/处理函数 * * @access public * @param int * @return void */ public function _edit_post($id = 0) { $data = $this->role_mdl->get_form_data(); $data['role'] = $this->role_mdl->get_role_by_id($id); if (!$data['role']) { $this->_message('不存在的用户组', '', FALSE); } if (!$this->_validate_role_form($data['role']->name)) { $this->_template('role_edit', $data); } else { $this->role_mdl->edit_role($id, $this->_get_form_data()); update_cache('role', $id); $this->_message('用户组修改成功!', 'role/edit/' . $id, TRUE); } }
/** * 缩略图尺寸预设删除 * * @access public * @return void */ public function _thumbs_delete($id = '') { $thumbs = json_decode($this->db->get('site_settings')->row()->thumbs_preferences); if (is_null($thumbs)) { $thumbs = array(); } foreach ($thumbs as $key => $thumb) { if ($thumb->size == $id) { unset($thumbs[$key]); break; } } $this->db->set('thumbs_preferences', json_encode($thumbs))->update('site_settings'); update_cache('site'); echo 'ok'; }