public function hasAlarm() { //caching is required. We don't use the session because we need to close //session writing when checking email accounts. Otherwise it can block the //session to long. if (\GO::cache() instanceof \GO\Base\Cache\None) { return false; } $cached = \GO::cache()->get($this->_getCacheKey()); return $cached != $this->unseen && $this->unseen > 0; }
/** * * @return Filehandler\FilehandlerInterface */ public static function getAllFileHandlers() { if (!isset(self::$fileHandlers)) { self::$fileHandlers = \GO::cache()->get('files-file-handlers'); if (!self::$fileHandlers) { $modules = \GO::modules()->getAllModules(); self::$fileHandlers = array(); foreach ($modules as $module) { self::$fileHandlers = array_merge(self::$fileHandlers, $module->moduleManager->findClasses('filehandler')); } \GO::cache()->set('files-file-handlers', self::$fileHandlers); } } return self::$fileHandlers; }
/** * Returns all custom fields for this link type * * @param int $linkType * @return PDOStatement */ private function _getAllFields() { //cache is cleared when a field is saved or deleted in Field::AfterSave and afterdelete if (!isset(self::$cacheColumns[$this->extendsModel()])) { $cacheKey = $this->getCacheKey(); if ($cached = \GO::cache()->get($cacheKey)) { self::$attributeLabels[$this->extendsModel()] = $cached['attributeLabels']; self::$cacheColumns[$this->extendsModel()] = $cached['columns']; } else { $findParams = \GO\Base\Db\FindParams::newInstance()->select('t.*')->ignoreAcl()->joinRelation('category'); $findParams->getCriteria()->addCondition('extends_model', $this->extendsModel(), '=', 'category'); $stmt = \GO\Customfields\Model\Field::model()->find($findParams); self::$cacheColumns[$this->extendsModel()] = \GO\Base\Db\Columns::getColumns($this); self::$attributeLabels[$this->extendsModel()] = array(); while ($field = $stmt->fetch()) { self::$attributeLabels[$this->extendsModel()][$field->columnName()] = $field->category->name . ':' . $field->name; self::$cacheColumns[$this->extendsModel()][$field->columnName()]['customfield'] = $field; self::$cacheColumns[$this->extendsModel()][$field->columnName()]['regex'] = $field->validation_regex; self::$cacheColumns[$this->extendsModel()][$field->columnName()]['gotype'] = 'customfield'; self::$cacheColumns[$this->extendsModel()][$field->columnName()]['unique'] = $field->unique_values; //Don't validate required on the server side because customfields tabs can be disabled. //self::$cacheColumns[$this->extendsModel()][$field->columnName()]['required']=$field->required; } \GO::cache()->set($cacheKey, array('attributeLabels' => self::$attributeLabels[$this->extendsModel()], 'columns' => self::$cacheColumns[$this->extendsModel()])); } } $this->columns = self::$cacheColumns[$this->extendsModel()]; }
public function render() { require_once \GO::modules()->site->path . 'widget/twitter/codebird.php'; $cacheKey = $this->consumerKey . ':' . $this->accessToken . ':' . $this->userTimeLine . ':' . $this->retweets; if (!$this->cacheLifeTime || !($tweets = \GO::cache()->get($cacheKey))) { //Get authenticated \Codebird\Codebird::setConsumerKey($this->consumerKey, $this->consumerSecret); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($this->accessToken, $this->accessTokenSecret); //These are our params passed in $params = array('screen_name' => $this->screenName, 'count' => $this->limit, 'include_rts' => $this->retweets, 'exclude_replies' => $this->exclude_replies); //tweets returned by Twitter $tweets = $this->userTimeLine ? (array) $cb->statuses_userTimeline($params) : (array) $cb->statuses_homeTimeline($params); \GO::cache()->set($cacheKey, $tweets, $this->cacheLifeTime); } $html = ''; foreach ($tweets as $tweet) { if (is_object($tweet)) { $str = $this->template; foreach ($tweet as $key => $value) { if (!is_object($value)) { if ($key == 'text') { $value = \GO\Base\Util\String::text_to_html($value); } if ($key == 'created_at') { $value = strtotime($value); if ($value) { $value = date('Y-m-d G:i', $value); } } $str = str_replace('{' . $key . '}', $value, $str); } else { $value = (array) $value; foreach ($value as $subKey => $subValue) { if (is_string($subValue)) { $str = str_replace('{' . $key . ':' . $subKey . '}', $subValue, $str); } } } } $html .= $str; } } return $html; }
/** * GO caches the table schema for performance. We need to clear it */ private function _clearColumnCache() { //deleted cached column schema. See AbstractCustomFieldsRecord \GO\Base\Db\Columns::clearCache(\GO::getModel(\GO::getModel($this->category->extends_model)->customfieldsModel())); \GO::cache()->delete('customfields_' . $this->category->extends_model); }
/** * Get all columns of a model * * @param ActiveRecord $model * @return array */ public static function getColumns(ActiveRecord $model) { $tableName = $model->tableName(); $cacheKey = self::getCacheKey($model); if (self::$forceLoad) { unset(self::$_columns[$tableName]); \GO::cache()->delete($cacheKey); } if (isset(self::$_columns[$tableName]) && !self::$forceLoad) { return self::$_columns[$tableName]; } elseif ($columns = \GO::cache()->get($cacheKey)) { // \GO::debug("Got columns from cache for $tableName"); self::$_columns[$tableName] = $columns; return self::$_columns[$tableName]; } else { // \GO::debug("Loading columns for $tableName"); self::$_columns[$tableName] = array(); $sql = "SHOW COLUMNS FROM `" . $tableName . "`;"; $stmt = $model->getDbConnection()->query($sql); while ($field = $stmt->fetch()) { preg_match('/([a-zA-Z].*)\\(([1-9].*)\\)/', $field['Type'], $matches); if ($matches) { $length = $matches[2]; $type = $matches[1]; } else { $type = $field['Type']; $length = 0; } $required = false; $gotype = 'textfield'; $default = $field['Default']; $ai = strpos($field['Extra'], 'auto_increment') !== false; $pdoType = PDO::PARAM_STR; switch ($type) { case 'int': case 'tinyint': case 'bigint': $pdoType = PDO::PARAM_INT; if ($length == 1 && $type == 'tinyint') { $gotype = 'boolean'; } else { $gotype = ''; } $length = 0; $default = $ai || !isset($field['Default']) ? null : intval($default); break; case 'float': case 'double': case 'decimal': $pdoType = PDO::PARAM_STR; $length = 0; $gotype = 'number'; $default = $default == null ? null : floatval($default); break; case 'mediumtext': case 'longtext': case 'text': $gotype = 'textarea'; break; case 'mediumblob': case 'longblob': case 'blob': $gotype = 'blob'; break; case 'date': $gotype = 'date'; break; case 'time': $gotype = 'time'; break; } switch ($field['Field']) { case 'ctime': case 'mtime': $gotype = 'unixtimestamp'; break; case 'name': $required = true; break; case 'user_id': $gotype = 'user'; break; } //HACK: When a database may not be null and has no default value value is empty string if (!GO::config()->debug) { if ($field['Null'] == 'NO' && is_null($default) && !$ai) { $default = ''; } } //workaround for old boolean fields as enums. Should be using bool now. if ($type == "enum('0','1')") { $gotype = 'boolean'; $default = '0'; } //$required = is_null($default) && $field['Null']=='NO' && strpos($field['Extra'],'auto_increment')===false; self::$_columns[$tableName][$field['Field']] = array('type' => $pdoType, 'required' => $required, 'length' => $length, 'gotype' => $gotype, 'default' => $default, 'dbtype' => $type, 'null' => $field['Null'] == 'YES'); } \GO::cache()->set($cacheKey, self::$_columns[$tableName]); return self::$_columns[$tableName]; } }
/** * Clears the: * * 1. \GO::config()->cachedir folder. This folder contains mainly cached javascripts. * 2. \GO\Base\Model objects cached in memory for a single script run * 3. The permanent cache stored in \GO::cache() * */ public static function clearCache() { \GO::config()->getCacheFolder(false)->delete(); \GO::cache()->flush(); \GO\Base\Model::clearCache(); }