/** * Initiates the password reset process on behalf of the user * Generates a unique hash and an expiration time that the hash is valid up until (defaults to 15 minutes) * This key will internally expire (but not be expunged) after that time */ public function initPasswordResetProcess() { if (!$this->validate()) { return false; } $hash = Cii::generateSafeHash(); $expires = strtotime("+15 minutes"); $meta = UserMetadata::model()->findByAttributes(array('user_id' => $this->_user->id, 'key' => 'passwordResetCode')); if ($meta === NULL) { $meta = new UserMetadata(); } $meta->user_id = $this->_user->id; $meta->key = 'passwordResetCode'; $meta->value = $hash; $meta->save(); $meta = UserMetadata::model()->findByAttributes(array('user_id' => $this->_user->id, 'key' => 'passwordResetExpires')); if ($meta === NULL) { $meta = new UserMetadata(); } $meta->user_id = $this->_user->id; $meta->key = 'passwordResetExpires'; $meta->value = $expires; $meta->save(); $emailSettings = new EmailSettings(); $emailSettings->send($this->_user, Yii::t('ciims.email', 'Your Password Reset Information'), 'webroot.themes.' . Cii::getConfig('theme', 'default') . '.views.email.forgot', array('user' => $this->_user, 'hash' => $hash), true, true); // Set success flash Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'An email has been sent to {{email}} with further instructions on how to reset your password', array('{{email}}' => $this->email))); return true; }
/** * Provides functionality for a user to edit their profile */ public function actionEdit() { $model = Users::model()->findByPk(Yii::app()->user->id); if (Cii::get($_POST, 'Users', NULL) !== NULL) { // Load the bcrypt hashing tools if the user is running a version of PHP < 5.5.x if (!function_exists('password_hash')) { require_once YiiBase::getPathOfAlias('ext.bcrypt.bcrypt') . '.php'; } $cost = Cii::getBcryptCost(); if ($_POST['Users']['password'] != '') { $_POST['Users']['password'] = password_hash(Users::model()->encryptHash($_POST['Users']['email'], $_POST['Users']['password'], Yii::app()->params['encryptionKey']), PASSWORD_BCRYPT, array('cost' => $cost)); } else { unset($_POST['Users']['password']); } unset($_POST['Users']['status']); unset($_POST['Users']['user_role']); $model->attributes = Cii::get($_POST, 'Users', array()); $model->about = Cii::get(Cii::get($_POST, 'Users', array()), 'about', NULL); if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Profile', 'Your profile has been updated!')); $this->redirect($this->createUrl('/profile/' . $model->id)); } else { Yii::app()->user->setFlash('warning', Yii::t('ciims.controllers.Profile', 'There were errors saving your profile. Please correct them before trying to save again.')); } } $this->render('edit', array('model' => $model)); }
/** * Retrieves all of the themes from webroot.themes and returns them in an array group by type, each containing * the contents of theme.json. * * The themes are then cached for easy retrieval later. (I really hate unecessary DiskIO if something isn't changing...) * * @return array */ public function getThemes() { $themes = Yii::app()->cache->get('settings_themes'); if ($themes == false) { $themes = array(); $currentTheme = Cii::getConfig('theme'); $themePath = Yii::getPathOfAlias('base.themes') . DS; $directories = glob($themePath . "*", GLOB_ONLYDIR); // Pushes the current theme onto the top of the list foreach ($directories as $k => $dir) { if ($dir == Yii::getPathOfAlias('base.themes') . DS . $currentTheme) { unset($directories[$k]); break; } } array_unshift($directories, $themePath . $currentTheme); foreach ($directories as $dir) { $json = CJSON::decode(file_get_contents($dir . DIRECTORY_SEPARATOR . 'composer.json')); $name = $json['name']; $key = str_replace('ciims-themes/', '', $name); $themes[$key] = array('path' => $dir, 'name' => $name, 'hidden' => isset($json['hidden']) ? $json['hidden'] : false); } Yii::app()->cache->set('settings_themes', $themes); return $themes; } return $themes; }
public function testEncryptDecrypt() { $this->assertEquals(Cii::decrypt(Cii::encrypt(1)), 1); // Integer $this->assertEquals(Cii::decrypt(Cii::encrypt("1")), "1"); // String integer $this->assertEquals(Cii::decrypt(Cii::encrypt(3.14)), 3.14); // Float $this->assertEquals(Cii::decrypt(Cii::encrypt("3.14")), "3.14"); // String float $this->assertEquals(Cii::decrypt(Cii::encrypt("string")), "string"); // String // Test a variety of hashes of various sizes generated by Cii::generateSafeHash() $hash1 = Cii::generateSafeHash(4); $this->assertEquals(Cii::decrypt(Cii::encrypt($hash1)), $hash1); $hash2 = Cii::generateSafeHash(16); $this->assertEquals(Cii::decrypt(Cii::encrypt($hash2)), $hash2); $hash3 = Cii::generateSafeHash(32); $this->assertEquals(Cii::decrypt(Cii::encrypt($hash3)), $hash3); $hash4 = Cii::generateSafeHash(64); $this->assertEquals(Cii::decrypt(Cii::encrypt($hash4)), $hash4); $hash5 = Cii::generateSafeHash(128); $this->assertEquals(Cii::decrypt(Cii::encrypt($hash5)), $hash5); $hash6 = Cii::generateSafeHash(256); $this->assertEquals(Cii::decrypt(Cii::encrypt($hash6)), $hash6); $hash7 = Cii::generateSafeHash(512); $this->assertEquals(Cii::decrypt(Cii::encrypt($hash7)), $hash7); }
public function createPageUrl($id = 1) { $queryParam = NULL; if (Cii::get($this->_options['param'], 'getParam', NULL) != NULL) { $queryParam = '?' . Cii::get($this->_options['param'], 'getParam', NULL) . '=' . Cii::get($this->_options['param'], 'param', NULL); } return '/' . $this->_options['url'] . '/' . ($id + 1) . $queryParam; }
/** * Direct overload of EAnalytics::getProviders() * @return array(), Providors from database merges with providers from config */ public function getProviders() { $providers = array(); try { $providers = Cii::getAnalyticsProviders(); } catch (Exception $e) { } return CMap::mergeArray($this->options, $providers); }
/** * __constructor * @param $config */ public function __construct($config = array()) { $this->_config = CMap::mergeArray($this->_core, $config); $this->checkServerSettings(); if (Cii::get($_FILES, 'file') !== NULL) { $this->file = new CiiFile(); } $this->verifyFile(); }
/** * Displays a listing of all blog posts */ public function actionList() { $this->setPageTitle(Yii::t('ciims.controllers.Categories', '{{app_name}} | {{label}}', array('{{app_name}}' => Cii::getConfig('name', Yii::app()->name), '{{label}}' => Yii::t('ciims.controllers.Categories', 'Categories')))); $this->setLayout('main'); $this->breadcrumbs = array(Yii::t('ciims.controllers.Categories', 'All Categories')); $criteria = new CDbCriteria(); $criteria->addCondition('id != 1'); $categories = Categories::model()->findAll($criteria); $this->render('list', array('categories' => $categories)); }
public function init() { // Register the cii path alias. if (Yii::getPathOfAlias('cii') === false) { Yii::setPathOfAlias('cii', realpath(dirname(__FILE__) . '/..')); } Cii::loadUserInfo(); $this->registerJqueryCore(); parent::init(); }
/** * Creates a new comment * TODO: Figure out how to fix the email issues * @param int $id The Comment id * @return array */ private function createComment() { $model = new Comments(); $model->attributes = $_POST; $model->approved = Cii::getConfig('autoApproveComments', 0); if ($model->save()) { return $model->getApiAttributes(); } return $this->returnError(400, NULL, $model->getErrors()); }
/** * Generic method for sending an email. Instead of having to call a bunch of code all over over the place * This method can be called which should be able to handle almost anything. * * By calling this method, the SMTP details will automatically be setup as well the notify email and user * * @param Users $user The User we are sending the email to * @param string $subject The email Subject * @param string $viewFile The view file we want to render. Generally this should be in the form //email/<file> * And should correspond to a viewfile in /themes/<theme>/views/email/<file> * @param array $content The content to pass to renderPartial() * @param boolean $return Whether the output should be returned. The default is TRUE since this output will be passed to MsgHTML * @param boolean $processOutput Whether the output should be processed. The default is TRUE since this output will be passed to MsgHTML * @return boolean Whether or not the email sent sucessfully */ public function send($user, $subject = "", $viewFile, $content = array(), $return = true, $processOutput = true, $debug = false) { $mail = new PHPMailer($debug); $mail->IsSMTP(); $mail->SMTPAuth = false; $smtpHost = Cii::getConfig('SMTPHost', NULL); $smtpPort = Cii::getConfig('SMTPPort', NULL); $smtpUser = Cii::getConfig('SMTPUser', NULL); $smtpPass = Cii::getConfig('SMTPPass', NULL); $useTLS = Cii::getConfig('useTLS', 0); $useSSL = Cii::getConfig('useSSL', 0); $notifyUser = new stdClass(); if (isset($content['origin_from'])) { $notifyUser->email = $content['origin_from']['email']; $notifyUser->username = $content['origin_from']['name']; } else { $notifyUser->email = Cii::getConfig('notifyEmail', NULL); $notifyUser->username = Cii::getConfig('notifyName', NULL); } if ($smtpHost !== NULL && $smtpHost !== "") { $mail->Host = $smtpHost; } if ($smtpPort !== NULL && $smtpPort !== "") { $mail->Port = $smtpPort; } if ($smtpUser !== NULL && $smtpUser !== "") { $mail->Username = $smtpUser; $mail->SMTPAuth = true; } if ($useTLS == 1) { $mail->SMTPSecure = 'tls'; } if ($useSSL == 1) { $mail->SMTPSecure = 'ssl'; } if (!empty($smtpPass)) { $mail->Password = Cii::decrypt($smtpPass); $mail->SMTPAuth = true; } if ($notifyUser->email == NULL && $notifyUser->username == NULL) { $notifyUser = Users::model()->findByPk(1); } $mail->SetFrom($notifyUser->email, $notifyUser->username); $mail->Subject = $subject; $mail->MsgHTML($this->renderFile(Yii::getPathOfAlias($viewFile) . '.php', $content, $return, $processOutput)); $mail->AddAddress($user->email, $user->username); try { return $mail->Send(); } catch (phpmailerException $e) { return $debug ? $e->errorMessage() : false; } catch (Exception $e) { return $debug ? $e : false; } return false; }
/** * Init function to start the rendering process */ public function init() { $this->_shortname = Cii::getConfig('disqus_shortname'); $asset = Yii::app()->assetManager->publish(YiiBase::getPathOfAlias('cii.assets.dist'), true, -1, YII_DEBUG); Yii::app()->clientScript->registerScriptFile($asset . (YII_DEBUG ? '/ciidisqus.js' : '/ciidisqus.min.js'), CClientScript::POS_END); if ($this->content != false) { $this->renderCommentBox(); } else { $this->renderCommentCount(); } }
function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760) { $allowedExtensions = array_map("strtolower", $allowedExtensions); $this->allowedExtensions = $allowedExtensions; $this->sizeLimit = $sizeLimit; $this->checkServerSettings(); $this->file = false; if (Cii::get($_FILES, 'file') !== NULL) { $this->file = new CiiFile(); } }
/** * Actually creates the users * @return bool If the user was created */ public function acceptInvite() { if (!$this->validate()) { return false; } $user = Users::model()->findByPk($this->id); // Bcrypt the initial password instead of just using the basic hashing mechanism $hash = Users::model()->encryptHash($this->email, $this->password, Yii::app()->params['encryptionKey']); $cost = Cii::getBcryptCost(); $this->password = password_hash($hash, PASSWORD_BCRYPT, array('cost' => $cost)); $user->attributes = array('email' => $this->email, 'password' => $this->password, 'username' => $this->username, 'status' => Users::ACTIVE); return $user->save(); }
/** * Constructor * Sets the default basePath to webroot.themes.{{themename}} */ public function init() { Yii::app()->language = Cii::setApplicationLanguage(); parent::init(); if (isset(Yii::app()->theme) && isset(Yii::app()->theme->name)) { $this->basePath = Yii::getPathOfAlias('base.themes.' . Yii::app()->theme->name . '.messages'); } else { if (isset(Yii::app()->controller->module->id)) { $this->basePath = Yii::getPathOfAlias('application.modules.' . Yii::app()->controller->module->id); } else { $this->basePath = Yii::getPathOfAlias('application.modules.install'); } } }
public function init() { echo CHtml::openTag('div', array('class' => 'comments', 'id' => 'comment')); if (Cii::getConfig('useDisqusComments')) { echo CHtml::tag('div', array('id' => 'disqus_thread'), NULL); } else { if (Cii::getConfig('useDiscourseComments')) { echo CHtml::tag('div', array('id' => 'discourse-comments'), NULL); } else { echo CHtml::tag('div', array('id' => 'ciims_comments'), NULL); } } echo CHtml::closeTag('div'); }
/** * Overrides processRules, allowing us to inject our own ruleset into the URL Manager * Takes no parameters **/ protected function processRules() { $this->addBasicRules(); $this->cacheRules('content', $this->contentUrlRulesId); $this->cacheRules('categories', $this->categoriesUrlRulesId); // Allow Sphinx Search settings to be dynamically via CiiSettings if (Cii::getConfig('sphinx_enabled')) { $this->rules['/search/<page:\\d+>'] = '/site/search'; $this->rules['/search'] = '/site/search'; } // Append our cache rules BEFORE we run the defaults $this->rules['<controller:\\w+>/<action:\\w+>/<id:\\d+>'] = '<controller>/<action>'; $this->rules['<controller:\\w+>/<action:\\w+>'] = '<controller>/<action>'; return parent::processRules(); }
public function actionIndex() { $event = new Events(); $event->attributes = $_GET; if (!isset($_GET['content_id'])) { $content = Content::model()->findByAttributes(array('slug' => Cii::get($_GET, 'uri', NULL))); if ($content !== NULL) { $event->content_id = $content->id; } } if ($event->save()) { Yii::app()->end(); } return $this->returnError(400, NULL, $event->getErrors()); }
/** * Provides functionality for a user to edit their profile */ public function actionEdit() { $model = new ProfileForm(); $model->load(Yii::app()->user->id); if (Cii::get($_POST, 'ProfileForm', NULL) !== NULL) { $model->attributes = $_POST['ProfileForm']; $model->password_repeat = $_POST['ProfileForm']['password_repeat']; if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Profile', 'Your profile has been updated!')); $this->redirect($this->createUrl('profile/index', array('id' => $model->id, 'username' => $model->username))); } else { Yii::app()->user->setFlash('error', Yii::t('ciims.controllers.Profile', 'There were errors saving your profile. Please correct them before trying to save again.')); } } $this->render('edit', array('model' => $model)); }
/** * Actually creates the users * @param int $user_id The id of the user that was created * @return bool If the user was created */ public function save($user_id) { $this->id = $user_id; if (!$this->validate()) { return false; } if (!function_exists('password_hash')) { require_once YiiBase::getPathOfAlias('ext.bcrypt.bcrypt') . '.php'; } $user = Users::model()->findByPk($this->id); // Bcrypt the initial password instead of just using the basic hashing mechanism $hash = Users::model()->encryptHash($this->email, $this->password, Yii::app()->params['encryptionKey']); $cost = Cii::getBcryptCost(); $this->password = password_hash($hash, PASSWORD_BCRYPT, array('cost' => $cost)); $user->attributes = array('email' => $this->email, 'password' => $this->password, 'firstName' => $this->firstName, 'lastName' => $this->lastName, 'displayName' => $this->displayName, 'status' => Users::ACTIVE); return $user->save(); }
/** * Provides functionality to make a comment */ public function actionComment() { if (Yii::app()->request->isAjaxRequest && Cii::get($_POST, 'Comments')) { $comment = new Comments(); $comment->attributes = array('user_id' => Yii::app()->user->id, 'content_id' => $_POST['Comments']['content_id'], 'comment' => $_POST['Comments']['comment'], 'parent_id' => Cii::get($_POST['Comments'], 'parent_id', 0), 'approved' => Cii::getConfig('autoApproveComments', 1) == null ? 1 : Cii::getConfig('autoApproveComments', 1)); if ($comment->save()) { $content = Content::model()->findByPk($comment->content_id); // Pass the values as "now" for the comment view" $comment->created = $comment->updated = Yii::t('Dashboard.main', 'now'); // Set the attributed id to make life easier... header("X-Attribute-Id: {$comment->id}"); $this->renderPartial('/content/comments', array('count' => $content->comment_count, 'comment' => $comment, 'depth' => 0, 'md' => new CMarkdownParser())); } else { throw new CHttpException(400, Yii::t('Dashboard.main', 'There was an error saving your comment.')); } } }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionSave($id = NULL) { if ($id == NULL) { $model = new Categories(); } else { $model = Categories::model()->findByPk($id); } if (Cii::get($_POST, 'Categories') !== NULL) { $model->attributes = Cii::get($_POST, 'Categories', array()); $model->description = Cii::get(Cii::get($_POST, 'Categories', array()), 'description', NULL); if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('Dashboard.main', 'Category has been updated')); $this->redirect(Yii::app()->createUrl('/dashboard/categories')); } Yii::app()->user->setFlash('error', Yii::t('Dashboard.main', 'There was an error in your submission, please verify you data before trying again.')); } $this->render('save', array('model' => $model)); }
/** * Generic method for sending an email. Instead of having to call a bunch of code all over over the place * This method can be called which should be able to handle almost anything. * * By calling this method, the SMTP details will automatically be setup as well the notify email and user * * @param Users $user The User we are sending the email to * @param string $subject The email Subject * @param string $viewFile The view file we want to render. Generally this should be in the form //email/<file> * And should correspond to a viewfile in /themes/<theme>/views/email/<file> * @param array $content The content to pass to renderPartial() * @param boolean $return Whether the output should be returned. The default is TRUE since this output will be passed to MsgHTML * @param boolean $processOutput Whether the output should be processed. The default is TRUE since this output will be passed to MsgHTML * @return boolean Whether or not the email sent sucessfully */ public function send($user, $subject = "", $viewFile, $content = array(), $return = true, $processOutput = true, $debug = false) { $mail = new PHPMailer($debug); $mail->IsSMTP(); $mail->SMTPAuth = false; $notifyUser = $this->getNotifyUser(isset($content['origin_from']) ? $content['origin_from'] : array()); if (empty($this->SMTPHost)) { $mail->Host = $this->SMTPHost; } if (empty($this->SMTPPort)) { $mail->Port = $this->SMTPPort; } if (empty($this->SMTPUser)) { $mail->Username = $this->SMTPUser; $mail->SMTPAuth = true; } if ($this->useTLS == 1) { $mail->SMTPSecure = 'tls'; } else { if ($this->useSSL == 1) { $mail->SMTPSecure = 'ssl'; } } if (empty($this->SMTPPass)) { $mail->Password = Cii::decrypt($this->SMTPPass); $mail->SMTPAuth = true; } $mail->SetFrom($notifyUser->email, $notifyUser->username); $mail->Subject = $subject; $mail->MsgHTML($this->renderFile(Yii::getPathOfAlias($viewFile) . '.php', $content, $return, $processOutput)); $mail->AddAddress($user->email, $user->username); try { return $mail->Send(); } catch (phpmailerException $e) { Yii::log($e->getMessage(), 'info', 'ciims.models.EmailSettings'); return false; } catch (Exception $e) { Yii::log($e->getMessage(), 'info', 'ciims.models.EmailSettings'); return false; } }
/** * Handles all incoming requests for the entire site that are not previous defined in CUrlManager * Requests come in, are verified, and then pulled from the database dynamically * Shows all blog posts for a particular category_id * @param $id - The content ID that we want to pull from the database **/ public function actionIndex($id = NULL) { // Run a pre check of our data $this->beforeCiiAction($id); // Retrieve the data $category = Categories::model()->findByPk($id); // Set the layout $this->setLayout('default'); $this->setPageTitle(Yii::t('ciims.controllers.Categories', '{{app_name}} | {{label}}', array('{{app_name}}' => Cii::getConfig('name', Yii::app()->name), '{{label}}' => $category->name))); $pageSize = Cii::getConfig('categoryPaginationSize', 10); $criteria = Content::model()->getBaseCriteria()->addCondition('type_id >= 2')->addCondition("category_id = " . $id)->addCondition('password = ""'); $criteria->limit = $pageSize; $criteria->order = 'created DESC'; $itemCount = Content::model()->count($criteria); $pages = new CPagination($itemCount); $pages->pageSize = $pageSize; $criteria->offset = $criteria->limit * $pages->getCurrentPage(); $data = Content::model()->findAll($criteria); $pages->applyLimit($criteria); $this->render('index', array('id' => $id, 'category' => $category, 'data' => $data, 'itemCount' => $itemCount, 'pages' => $pages, 'meta' => array('description' => $category->getDescription()))); }
/** * Sends an invite to a new user * @return boolean */ public function invite() { if (!$this->validate()) { return false; } $user = new Users(); $user->attributes = array('email' => $this->email, 'firstName' => null, 'lastName' => null, 'displayName' => null, 'password' => null, 'user_role' => 5, 'status' => Users::PENDING_INVITATION); // Create a new user, but bypass validation if ($user->save(false)) { $meta = new UserMetadata(); $meta->attributes = array('user_id' => $user->id, 'key' => 'invitationKey', 'value' => Cii::generateSafeHash()); // If the key was savedm send the email out if ($meta->save()) { $emailSettings = new EmailSettings(); $emailSettings->send($user, Yii::t('ciims.models.InvitationForm', "You've Been Invited..."), 'webroot.themes.' . Cii::getConfig('theme', 'default') . '.views.email.invite', array('user' => $user, 'hash' => $meta->value), true, true); return true; } $user->delete(); } return false; }
/** * Attempts to import settings from HybridAuth config. */ private function socialSettings(&$connection) { $config = Yii::app()->getModules(false); if (isset($config['hybridauth'])) { foreach (Cii::get(Cii::get($config, 'hybridauth', array()), 'providers', array()) as $k => $v) { $key = 'ha_' . strtolower($k) . '_'; foreach ($v as $j => $l) { if ($j == 'keys') { foreach ($l as $m => $n) { $key = 'ha_' . strtolower($k) . '_' . $m; $value = $n; $connection->createCommand('INSERT IGNORE INTO `configuration` (`key`, value, created, updated) VALUES (:key, :value, NOW(), NOW())')->bindParam(':key', $key)->bindParam(':value', $n)->execute(); } } else { $value = $l; $key = 'ha_' . strtolower($k) . '_' . $j; $connection->createCommand('INSERT IGNORE INTO `configuration` (`key`, value, created, updated) VALUES (:key, :value, NOW(), NOW())')->bindParam(':key', $key)->bindParam(':value', $value)->execute(); } } } } }
/** * Generic function to handle all resource uploads * @param string $value The value that should be assigned to $meta->value * @return string */ private function _handleResourceUpload($value) { if (Cii::get($this->_result, 'success', false) == true) { $meta = ContentMetadata::model()->findbyAttributes(array('content_id' => $this->_id, 'key' => $this->_result['filename'])); if ($meta == NULL) { $meta = new ContentMetadata(); } $meta->content_id = $this->_id; $meta->key = $this->_result['filename']; $meta->value = $value; if ($meta->save()) { if ($this->_promote) { $this->_promote($this->_result['filename']); } $this->_result['filepath'] = $value; return htmlspecialchars(CJSON::encode($this->_result), ENT_NOQUOTES); } else { throw new CHttpException(400, Yii::t('ciims.misc', 'Unable to save uploaded image.')); } } else { throw new CHttpException(400, $this->_result['error']); } }
/** * getTweets callback method * @param $_POST $postData Data supplied over post */ public function getTweets($postData = NULL) { header("Content-Type: application/json"); Yii::import('ext.twitteroauth.*'); try { $connection = new TwitterOAuth(Cii::getConfig('ha_twitter_key', NULL, NULL), Cii::getConfig('ha_twitter_secret', NULL, NULL), Cii::getConfig('ha_twitter_accessToken', NULL, NULL), Cii::getConfig('ha_twitter_accessTokenSecret', NULL, NULL)); $tweets = Yii::app()->cache->get($this->theme . '_settings_tweets'); if ($tweets == false) { $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={$this->twitterHandle}&include_rts=false&exclude_replies=true&count={$this->twitterTweetsToFetch}"); foreach ($tweets as &$tweet) { $tweet->text = preg_replace("/([\\w]+\\:\\/\\/[\\w-?&;#~=\\.\\/\\@]+[\\w\\/])/", "<a target=\"_blank\" href=\"\$1\">\$1</a>", $tweet->text); $tweet->text = preg_replace("/#([A-Za-z0-9\\/\\.]*)/", "<a target=\"_new\" href=\"http://twitter.com/search?q=\$1\">#\$1</a>", $tweet->text); $tweet->text = preg_replace("/@([A-Za-z0-9\\/\\.]*)/", "<a href=\"http://www.twitter.com/\$1\">@\$1</a>", $tweet->text); } // Cache the result for 15 minutes if (!isset($tweets->errors)) { Yii::app()->cache->set($this->theme . '_settings_tweets', $tweets, 900); } } echo CJSON::encode($tweets); } catch (Exception $e) { echo CJSON::encode(array('errors' => array(array('message' => $e->getMessage())))); } }
public function afterSave() { Yii::app()->cache->set('hybridauth_providers', false); Cii::getHybridAuthProviders(); return parent::afterSave(); }
/** * Allow some override values * @return parent::beforeSave(); */ public function beforeSave() { if (($allow_api = Cii::get(Cii::getCiiConfig(), 'allow_api', true)) == false) { $this->attributes['enableAPI'] = $this->enableAPI = (int) $allow_api; } // Encrypt the Openstack API Key if ($this->attributes['openstack_apikey'] != NULL && $this->attributes['openstack_apikey'] != "") { $this->attributes['openstack_apikey'] = $this->openstack_apikey = Cii::encrypt($this->attributes['openstack_apikey']); } return parent::beforeSave(); }