Пример #1
0
 public static function getSourceInfo($table, $rowId, $forApi = false, $moduleName = "weibo")
 {
     static $_forApi = "0";
     $_forApi == "0" && ($_forApi = intval($forApi));
     $key = $_forApi ? $table . $rowId . "_api" : $table . $rowId;
     $info = CacheUtil::get("source_info_" . $key);
     if ($info) {
         return $info;
     }
     switch ($table) {
         case "feed":
             $info = self::getInfoFromFeed($table, $rowId, $_forApi);
             break;
         case "comment":
             $info = self::getInfoFromComment($table, $rowId, $_forApi);
             break;
         default:
             $table = ucfirst($table);
             $model = $table::model();
             if (method_exists($model, "getSourceInfo")) {
                 $info = $model->getSourceInfo($rowId, $_forApi);
             }
             unset($model);
             break;
     }
     $info["source_table"] = $table;
     $info["source_id"] = $rowId;
     CacheUtil::set("source_info_" . $key, $info);
     return $info;
 }
Пример #2
0
 public function fetchAllCache($cacheNames)
 {
     $cacheNames = is_array($cacheNames) ? $cacheNames : array($cacheNames);
     $data = CacheUtil::get($cacheNames);
     if (is_array($data) && in_array(false, $data, true) || !$data) {
         $data = false;
     }
     $newArray = $data !== false ? array_diff($cacheNames, array_keys($data)) : $cacheNames;
     if (empty($newArray)) {
         foreach ($data as &$cache) {
             $isSerialized = $cache == serialize(false) || @unserialize($cache) !== false;
             $cache = $isSerialized ? unserialize($cache) : $cache;
         }
         return $data;
     } else {
         $cacheNames = $newArray;
     }
     $caches = $this->fetchAll(sprintf("FIND_IN_SET(name,'%s')", implode(",", $cacheNames)));
     if ($caches) {
         foreach ($caches as $sysCache) {
             $data[$sysCache["name"]] = $sysCache["type"] ? unserialize($sysCache["value"]) : $sysCache["value"];
             CacheUtil::set($sysCache["name"], $data[$sysCache["name"]]);
         }
         foreach ($cacheNames as $name) {
             if ($data[$name] === null) {
                 $data[$name] = null;
                 CacheUtil::rm($name);
             }
         }
     }
     return $data;
 }
Пример #3
0
 public function __construct(ICFlowForm $form)
 {
     $cache = CacheUtil::get("form_" . $form->getID());
     if (is_array($cache)) {
         $this->_cache = $cache;
     }
     parent::__construct($form);
 }
Пример #4
0
 public function getNodeList()
 {
     $list = CacheUtil::get("notifyNode");
     if (!$list) {
         $list = $this->fetchAllSortByPk("node", array("order" => "`module` DESC"));
         CacheUtil::set("notifyNode", $list);
     }
     return $list;
 }
Пример #5
0
 public static function getPurv($posId)
 {
     $access = CacheUtil::get("purv_" . $posId);
     if (!$access) {
         $access = Ibos::app()->getAuthManager()->getItemChildren($posId);
         CacheUtil::set("purv_" . $posId, array_flip(array_map("strtolower", array_keys($access))));
     }
     return $access;
 }
Пример #6
0
 public static function getLogTableId()
 {
     $tableId = CacheUtil::get("logtableid");
     if ($tableId === false) {
         $tableId = Ibos::app()->db->createCommand()->select("svalue")->from("{{setting}}")->where("skey = 'logtableid'")->queryScalar();
         CacheUtil::set("logtableid", intval($tableId));
     }
     return $tableId;
 }
Пример #7
0
 public function fetchAllEnabledModule()
 {
     $module = CacheUtil::get("module");
     if ($module == false) {
         $criteria = array("condition" => "`disabled` = 0", "order" => "`sort` ASC");
         $module = $this->fetchAllSortByPk("module", $criteria);
         CacheUtil::set("module", $module);
     }
     return $module;
 }
Пример #8
0
 private function processCmdCache($cmd, $name, $ttl = 0)
 {
     $ret = "";
     switch ($cmd) {
         case "set":
             $ret = CacheUtil::set("process_lock_" . $name, TIMESTAMP, $ttl);
             break;
         case "get":
             $ret = CacheUtil::get("process_lock_" . $name);
             break;
         case "rm":
             $ret = CacheUtil::rm("process_lock_" . $name);
     }
     return $ret;
 }
Пример #9
0
 public function getUserData($uid = "")
 {
     if (empty($uid)) {
         $uid = Ibos::app()->user->uid;
     }
     if (($data = CacheUtil::get("userData_" . $uid)) === false || count($data) == 1) {
         $data = array();
         $list = $this->fetchAll("`uid` = :uid", array(":uid" => $uid));
         if (!empty($list)) {
             foreach ($list as $v) {
                 $data[$v["key"]] = (int) $v["value"];
             }
         }
         CacheUtil::set("userData_" . $uid, $data, 60);
     }
     return $data;
 }
Пример #10
0
 public function fetchAllEnabledModule()
 {
     $module = CacheUtil::get("module");
     if ($module == false) {
         $criteria = array("condition" => "`disabled` = 0", "order" => "`sort` ASC");
         $module = $this->fetchAllSortByPk("module", $criteria);
         if (defined("LICENCE_DISABLE")) {
             $disabledModules = explode(",", LICENCE_DISABLE);
         } else {
             $disabledModules = false;
         }
         if ($disabledModules) {
             foreach ($module as $index => $mod) {
                 if (in_array($mod["module"], $disabledModules)) {
                     unset($module[$index]);
                 }
             }
         }
         CacheUtil::set("module", $module);
     }
     return $module;
 }
Пример #11
0
 public static function getAllExpression($flush = false)
 {
     $cacheId = "expression";
     if (($res = CacheUtil::get($cacheId)) === false || $flush === true) {
         $filepath = "static/image/expression/";
         $expression = new Dir($filepath);
         $expression_pkg = $expression->toArray();
         $res = array();
         $typeMap = array("df" => "默认", "bm" => "暴漫");
         foreach ($expression_pkg as $index => $value) {
             list($file) = explode(".", $value["filename"]);
             list($type) = explode("_", $file);
             $temp["value"] = $file;
             $temp["phrase"] = "[" . $file . "]";
             $temp["icon"] = $value["filename"];
             $temp["type"] = $type;
             $temp["category"] = $typeMap[$type];
             $res[$temp["phrase"]] = $temp;
         }
         CacheUtil::set($cacheId, $res);
     }
     return $res;
 }
Пример #12
0
 protected function fetchCaches($pks)
 {
     $return = array();
     if ($this->getIsAllowCache()) {
         foreach ($pks as $pk) {
             $data = CacheUtil::get($this->getCacheKey($pk));
             if ($data !== false) {
                 $return[$pk] = $data;
             }
         }
     }
     return !empty($return) ? $return : false;
 }
Пример #13
0
 public static function loadProcessCache($flowId)
 {
     $cacheName = "flowprocess_" . intval($flowId);
     $cache = CacheUtil::get($cacheName);
     if ($cache === false) {
         $cache = array();
         $data = Ibos::app()->db->createCommand()->select("ft.name,ft.type,fp.*")->from("{{flow_type}} ft")->leftJoin("{{flow_process}} fp", "ft.flowid = fp.flowid")->where(sprintf("ft.flowid = %d", $flowId))->order("ft.flowid,fp.processid")->queryAll();
         foreach ($data as $process) {
             $cache[$process["processid"]] = $process;
         }
         CacheUtil::set($cacheName, $cache);
     }
     return $cache;
 }
Пример #14
0
 public function getCommentInfo($id, $source = true)
 {
     $id = intval($id);
     if (empty($id)) {
         $this->addError("get", Ibos::lang("Parameters error", "error"));
         return false;
     }
     $info = CacheUtil::get("comment_info_" . $id);
     if ($info) {
         return $info;
     } else {
         $info = $this->fetchByPk($id);
         $info["user_info"] = User::model()->fetchByUid($info["uid"]);
         $info["content"] = $info["content"];
         $source && ($info["sourceInfo"] = Source::getCommentSource($info));
         $source && CacheUtil::set("comment_info_" . $id, $info);
         return $info;
     }
 }
Пример #15
0
 private static function parseAtByUserName($name)
 {
     $info = CacheUtil::get("userInfoRealName_" . md5($name[1]));
     if (!$info) {
         $info = User::model()->fetchByRealname($name[1]);
         CacheUtil::set("userInfoRealName_" . md5($name[1]), $info);
     }
     if ($info) {
         return "<a class=\"anchor\" data-toggle=\"usercard\" data-param=\"uid=" . $info["uid"] . "\" href=\"" . $info["space_url"] . "\" target=\"_blank\">" . $name[0] . "</a>";
     } else {
         return $name[0];
     }
 }
Пример #16
0
 public function getFeedInfo($id, $forApi = false)
 {
     $data = CacheUtil::get("feed_info_" . $id);
     if ($data !== false && $forApi === false) {
         return $data;
     }
     $data = Ibos::app()->db->createCommand()->from("{{feed}} a")->leftJoin("{{feed_data}} b", "a.feedid = b.feedid")->where("a.feedid = " . $id)->queryRow();
     $fd = unserialize($data["feeddata"]);
     $userInfo = User::model()->fetchByUid($data["uid"]);
     $data["ctime"] = ConvertUtil::formatDate($data["ctime"], "n月d日H:i");
     $data["content"] = $forApi ? StringUtil::parseForApi($fd["body"]) : $fd["body"];
     $data["realname"] = $userInfo["realname"];
     $data["avatar_big"] = $userInfo["avatar_big"];
     $data["avatar_middle"] = $userInfo["avatar_middle"];
     $data["avatar_small"] = $userInfo["avatar_small"];
     unset($data["feeddata"]);
     if ($data["type"] == "repost") {
         $data["transpond_id"] = $data["rowid"];
         $data["transpond_data"] = $this->getFeedInfo($data["transpond_id"], $forApi);
     }
     if (!empty($fd["attach_id"])) {
         $data["has_attach"] = 1;
         $attach = AttachUtil::getAttachData($fd["attach_id"]);
         $attachUrl = FileUtil::getAttachUrl();
         foreach ($attach as $ak => $av) {
             $_attach = array("attach_id" => $av["aid"], "attach_name" => $av["filename"], "attach_url" => FileUtil::fileName($attachUrl . "/" . $av["attachment"]), "extension" => StringUtil::getFileExt($av["filename"]), "size" => $av["filesize"]);
             if ($data["type"] == "postimage") {
                 $_attach["attach_small"] = WbCommonUtil::getThumbImageUrl($av, WbConst::ALBUM_DISPLAY_WIDTH, WbConst::ALBUM_DISPLAY_HEIGHT);
                 $_attach["attach_middle"] = WbCommonUtil::getThumbImageUrl($av, WbConst::WEIBO_DISPLAY_WIDTH, WbConst::WEIBO_DISPLAY_HEIGHT);
             }
             $data["attach"][] = $_attach;
         }
     } else {
         $data["has_attach"] = 0;
     }
     $data["feedType"] = $data["type"];
     $feedInfo = $this->get($id);
     $data["source_body"] = $feedInfo["body"];
     $data["api_source"] = $feedInfo["api_source"];
     CacheUtil::set("feed_info_" . $id, $data, 60);
     if ($forApi) {
         $data["content"] = StringUtil::realStripTags($data["content"]);
         unset($data["isdel"]);
         unset($data["fromdata"]);
         unset($data["table"]);
         unset($data["rowid"]);
         unset($data["source_body"]);
     }
     return $data;
 }