/** * Usergroups::delete() * Function responsible to delete a user group. * @return void */ public function add() { $clang = Yii::app()->lang; $aData = array(); $aViewUrls = array(); if (Permission::model()->hasGlobalPermission('CMS', 'create')) { //echo $test = getBasePath(); $controllername = $this->getId(); $newPath = "application.views."; $newPath = YiiBase::getPathOfAlias($newPath); //$filepath = $newPath . '\admin\cms\template\default.tpl.php'; $filepath = $newPath . '/admin/cms/template/default.tpl.php'; $page_content = $_POST['template_editor']; // $page_content = html_entity_decode($page_content, ENT_QUOTES, "UTF-8"); // $page_content = fixCKeditorText($page_content); if (file_put_contents($filepath, $page_content, LOCK_EX)) { Yii::app()->setFlashMessage($clang->gT("Template updated successfully")); $this->getController()->redirect(array("admin/template/index")); } } else { Yii::app()->setFlashMessage($clang->gT("You do not have sufficient rights to access page."), 'error'); $this->getController()->redirect(array("admin/index")); } $this->_renderWrappedTemplate('cms/cms', $aViewUrls, $aData); }
public static function GetSize($intImageTypeId) { list($intDefWidth, $intDefHeight) = ImagesType::$SizeArray[$intImageTypeId]; $strCfg = ImagesType::GetConfigKey($intImageTypeId); $strCfgWidth = $strCfg . '_WIDTH'; $strCfgHeight = $strCfg . '_HEIGHT'; $intWidth = Yii::app()->theme->info->{$strCfgWidth}; $intHeight = Yii::app()->theme->info->{$strCfgHeight}; //If our theme doesn't have the config there, see if we have a 3.0 style config.xml if (empty($intWidth) || empty($intHeight)) { $fnOptions = YiiBase::getPathOfAlias('webroot') . "/themes/" . Yii::app()->theme->name . "/config.xml"; if (file_exists($fnOptions)) { $strXml = file_get_contents($fnOptions); // Parse xml for response values $oXML = new SimpleXMLElement($strXml); if (isset($oXML->defaults->configuration)) { foreach ($oXML->defaults->configuration as $item) { if ((string) $item->key_name == $strCfgWidth) { $intWidth = (string) $item->key_value; } if ((string) $item->key_name == $strCfgHeight) { $intHeight = (string) $item->key_value; } } } } } //if all else STILL fails, go old school and get them from the config (And even more so, use defaults) if (empty($intWidth) || empty($intHeight)) { $intWidth = _xls_get_conf($strCfgWidth, $intDefWidth); $intHeight = _xls_get_conf($strCfgHeight, $intDefHeight); } return array($intWidth, $intHeight); }
/** * 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 cards in a particular category * @param string $id The category id */ public function actionGetCardsByCategory($id = NULL) { if ($id === NULL) { throw new CHttpException(400, Yii::t('Dashboard.main', 'Missing category id')); } $categories = Yii::app()->cache->get('cards_in_category'); if ($categories === false) { $this->getCards(); $categories = Yii::app()->cache->get('cards_in_category'); } $cards = $categories[$id]; $elements = $elementOptions = array(); // TODO: Fix multiple select //$elementOptions['multiple'] = 'multiple'; foreach ($cards as $k => $card) { $asset = Yii::app()->assetManager->publish(YiiBase::getPathOfAlias($card['path']), true, -1, YII_DEBUG); $elements[] = $k; $elementOptions['options'][] = array('value' => $k, 'data-img-src' => Yii::app()->getBaseUrl(true) . $asset . '/default.png'); } $form = $this->beginWidget('ext.cii.widgets.CiiActiveForm', array('htmlOptions' => array('class' => 'pure-form pure-form-aligned item-selection-form'))); echo CHtml::openTag('div', array('class' => 'pure-form-group', 'style' => 'padding-bottom: 20px')); echo CHtml::link(Yii::t('Dashboard.main', 'Add to Dashboard'), '#', array('id' => 'add-cards-button', 'class' => 'pure-button pure-button-link pure-button-primary pull-right pure-button-small', 'style' => 'position: absolute; top: 15px; right: 3%;')); echo CHtml::tag('legend', array(), $id); echo CHtml::dropDownList('card', NULL, $elements, $elementOptions); echo CHtml::closeTag('div'); $this->endWidget(); }
/** * Registers Analytics.js and initializes the tracking code */ public function init() { if (php_sapi_name() === 'cli') { return; } // Set the alias path if (Yii::getPathOfAlias('analytics') === false) { Yii::setPathOfAlias('analytics', realpath(dirname(__FILE__) . '/..')); } parent::init(); // Don't load up the analytics.js if we don't have any data $providers = $this->getProviders(); if (empty($providers)) { return; } // Conver options into json $json = CJSON::encode($this->getProviders()); // Load up the asset manager $asset = Yii::app()->assetManager->publish(YiiBase::getPathOfAlias('ext.EAnalytics.assets.js'), true, -1, YII_DEBUG); $cs = Yii::app()->getClientScript(); // Register the appropriate script file $cs->registerScriptFile($asset . (YII_DEBUG ? '/analytics.js' : '/analytics.min.js')); // Initialize $cs->registerScript('analytics.js', "analytics.initialize({$json});"); if ($this->lowerBounceRate) { $cs->registerScript('analytics.js-bounce-rate-15', 'setTimeout(function() { analytics.track("_trackEvent", "15 Seconds"); }, 15000 );'); $cs->registerScript('analytics.js-bounce-rate-30', 'setTimeout(function() { analytics.track("_trackEvent", "30 Seconds"); }, 30000 );'); $cs->registerScript('analytics.js-bounce-rate-60', 'setTimeout(function() { analytics.track("_trackEvent", "60 Seconds"); }, 60000 );'); } }
*/ class ImageHelper { /** * Directory to store thumbnails * @var string */ const THUMB_DIR = '.tmb'; /** * Create a thumbnail of an image and returns relative path in webroot * the options array is an associative array which can take the values * quality (jpg quality) and method (the method for resizing) * * @param int $width * @param int $height * @param string $img * @param array $options * @return string $path */ public static function thumb($width, $height, $img, $options = null) { if (!file_exists($img)) { $img = str_replace('\\', '/', YiiBase::getPathOfAlias('webroot') . $img); if (!file_exists($img)) { throw new ExceptionClass('Image not found'); } } // Jpeg quality $quality = 80; // Method for resizing $method = 'adaptiveResize'; if ($options) { extract($options, EXTR_IF_EXISTS); }
/** * @static send a email * @param array $data * array('subject'=>?, 'params'=>array(), 'view'=>?, 'to'=>?, 'from'=>?) * @param bool $requireView if true, it will only send email if view is existed */ public static function mail($data, $requireView = false) { // self::_setTestEmail($data, '*****@*****.**'); $message = new YiiMailMessage($data['subject']); if (isset($data['view'])) { if ($requireView) { $path = YiiBase::getPathOfAlias(Yii::app()->mail->viewPath) . '/' . $data['view'] . '.php'; if (!file_exists($path)) { return; } } $message->view = $data['view']; } elseif ($requireView) { return; } $message->setBody($data['params'], 'text/html'); if (is_array($data['to'])) { foreach ($data['to'] as $t) { $message->addTo($t); } } else { $message->addTo($data['to']); } $message->from = $data['from']; $message->setFrom(array($data['from'] => Yii::app()->setting->getItem('title_all_mail'))); // test email using local mail server if ($_SERVER['HTTP_HOST'] == 'localhost') { Yii::app()->mail->transportType = 'smtp'; Yii::app()->mail->transportOptions = array('host' => 'localhost', 'username' => null, 'password' => null); } return Yii::app()->mail->send($message); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'update' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); // set attributes from get if (isset($_GET['SaleGroup'])) { $model->attributes = $_GET['SaleGroup']; } if (isset($_POST['SaleGroup'])) { $model->attributes = $_POST['SaleGroup']; $model->imagefile = CUploadedFile::getInstance($model, 'imagefile'); if (isset($model->imagefile)) { $ext = pathinfo($model->imagefile); $model->image = $ext['extension']; } if ($model->save()) { if (isset($model->imagefile) && ($modelSettings = SiteModuleSettings::model()->find('site_module_id = 9'))) { $filename = $model->id . '.' . $model->image; $filepatch = '/../uploads/filestorage/sale/rubrics/'; $model->imagefile->saveAs(YiiBase::getPathOfAlias('webroot') . $filepatch . $filename); //Обработка изображения SiteModuleSettings::model()->chgImgModel($modelSettings, 'GD', 1, $model->id); } $url = isset($_POST['go_to_list']) ? $this->listUrl('index') : $this->itemUrl('update', $model->id); $this->redirect($url); } } $this->render('update', array('model' => $model)); }
public static function tempPath() { static $tempPath; if (empty($tempPath)) { $tempPath = YiiBase::getPathOfAlias('webroot.temp'); } return $tempPath; }
public function post_image($id, $image, $width = '150', $class = 'post_img') { if (isset($image) && file_exists(YiiBase::getPathOfAlias('webroot') . '/images/' . $image)) { return CHtml::image(Yii::app()->getBaseUrl(true) . '/images/' . $image); } else { return CHtml::image(Yii::app()->getBaseUrl(true) . '/images/noimage.png', 'no image', array('width' => $width, 'class' => $class)); } }
public function actionIndex() { $users_dp = new CActiveDataProvider(User::model()->cache(60 * 15, null, 2), array("criteria" => array(), "pagination" => array("pageSize" => 50), "sort" => array("attributes" => array("login", "rate_u", "rate_t", "n_trs"), "defaultOrder" => array("rate_t" => true)))); $this->side_view = "list_side"; $global_stats = unserialize(file_get_contents(YiiBase::getPathOfAlias("application.runtime") . "/global_stat.ser")); $this->side_params = $global_stats; $this->render("list", array("users_dp" => $users_dp)); }
function __construct() { foreach (Yii::app()->modules as $module => $value) { $path = 'application.modules.' . $module . '.components.' . ucwords($module) . 'AdminmenuWidget'; if (file_exists(YiiBase::getPathOfAlias($path) . '.php')) { $this->modulesMenus[$module] = $path; } } }
public function menuWidgets() { if (file_exists(YiiBase::getPathOfAlias("application.widgets.AdminmenuWidget") . '.php')) { $this->widget("application.widgets.AdminmenuWidget"); } foreach (Yii::app()->modulesMenus as $path) { $this->widget($path); } }
public function init() { Yii::app()->clientScript->coreScriptUrl = Yii::app()->baseUrl . "/js"; //设置css路径 YiiBase::setPathOfAlias('webcss', YiiBase::getPathOfAlias('webroot') . '/css'); $this->layout = 'application.views.layouts.adminRight'; parent::init(); $_GET['r'] = isset($_GET['r']) ? $_GET['r'] : Yii::app()->homeUrl; }
/** * Initializes initializer. */ public function __construct($frameworkScript, $configScript, $webApplicationFactory) { defined('YII_DEBUG') or define('YII_DEBUG', true); require_once $frameworkScript; // tells Yii to not just include files, but to let other // autoloaders or the include path try \YiiBase::$enableIncludePath = false; // create the application and remember it $this->yii = $webApplicationFactory::createWebApplication($configScript); }
public function init() { // this method is called when the module is being created // you may place code here to customize the module or the application $this->layoutPath = Yii::getPathOfAlias('dashboard.views.layouts'); // import the module-level models and components $this->setImport(array('dashboard.models.*', 'dashboard.components.*')); $asset = Yii::app()->assetManager->publish(YiiBase::getPathOfAlias('application.modules.dashboard.assets.js'), true, -1, YII_DEBUG); Yii::app()->setComponents(array('errorHandler' => array('errorAction' => 'dashboard/default/error'), 'messages' => array('class' => 'ext.cii.components.CiiPHPMessageSource', 'basePath' => Yii::getPathOfAlias('application.modules.dashboard')), 'clientScript' => array('class' => 'ext.minify.EClientScript', 'combineScriptFiles' => !YII_DEBUG, 'combineCssFiles' => !YII_DEBUG, 'optimizeCssFiles' => !YII_DEBUG, 'optimizeScriptFiles' => !YII_DEBUG, 'compressHTML' => !YII_DEBUG, 'packages' => array('jquery' => array('baseUrl' => $asset, 'js' => array('jquery-2.0.0.min.js')))))); }
public function actionDailyFixes() { // Укорачиваем search_history $this->execSQL("truncate search_history", "DELETE FROM search_history WHERE cdate < now() - interval '7 days'"); // Считаем глобальные показатели статистики $this->profileStart("global counters"); $global_stat = array("n_users" => Yii::app()->db->createCommand("SELECT reltuples::int FROM pg_class WHERE relname = 'users'")->queryScalar(), "n_books" => Yii::app()->db->createCommand("SELECT reltuples::int FROM pg_class WHERE relname = 'books'")->queryScalar(), "n_orig" => Yii::app()->db->createCommand("SELECT reltuples::int FROM pg_class WHERE relname = 'orig'")->queryScalar(), "n_tr" => Yii::app()->db->createCommand("SELECT reltuples::int FROM pg_class WHERE relname = 'translate'")->queryScalar()); file_put_contents(YiiBase::getPathOfAlias("application.runtime") . "/global_stat.ser", serialize($global_stat)); $this->profileStop(); $this->execSQL("groups & invites clean", "\n\t\t\tDELETE FROM groups WHERE status = 0 AND n_trs = 0;\n\t\t\tDELETE FROM invites WHERE cdate + interval '100 day' <= now();\n\t\t"); }
public function wrapContent($_scenario_, $data) { foreach ($data as $k => $v) { ${$k} = $v; } ob_start(); include YiiBase::getPathOfAlias('aiajaya.components.email_template.' . $_scenario_) . '.php'; $html = ob_get_contents(); ob_end_clean(); return $html; }
public function generate($html) { $this->pdfPath = YiiBase::getPathOfAlias('webroot') . '/uploads/filestorage/pdf/'; /** @var HTML2PDF $html2pdf */ $html2pdf = Yii::app()->ePdf->HTML2PDF($this->orientation, $this->format); $html2pdf->setDefaultFont('freesans'); $html2pdf->WriteHTML($html); $fileName = md5(uniqid('pdf')) . '.pdf'; $html2pdf->Output($this->pdfPath . $fileName, 'F'); return $fileName; }
/** * Returns the aws service builder * @return Guzzle\Service\Builder\ServiceBuilder * @throws CException */ public function getAws() { if (null === $this->_aws) { $config = $this->_config !== null ? $this->_config : YiiBase::getPathOfAlias("webroot") . '/config/aws-config.php'; if (is_scalar($config) && !@file_exists($config)) { throw new CException(Yii::t('zii', '"aws-config.php" configuration file not found')); } $this->_aws = Aws::factory($config); } return $this->_aws; }
/** * Initializes the route. * This method is invoked after the route is created by the route manager. */ public function init() { // required for correct PhpConsoleExtension work YiiBase::app()->getErrorHandler()->discardOutput = false; YiiBase::getLogger()->autoFlush = 1; // init PHP Console require_once dirname(__FILE__) . '/PhpConsole/PhpConsole.php'; PhpConsole::$callOldErrorHandler = false; PhpConsole::$callOldExceptionsHandler = false; PhpConsole::start($this->handleErrors, $this->handleExceptions, $this->basePathToStrip); }
/** * 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(); } }
public function search($query) { require_once YiiBase::getPathOfAlias("webroot") . '/twitteroauth/twitteroauth.php'; define('CONSUMER_KEY', 'Avr29V0jGRAtHaOMpaVypfw10'); define('CONSUMER_SECRET', 'WBItWNYDdHXgthG8elxsrDA16ZcFiPVQupm3UcRUZAOjz9WXcB'); define('ACCESS_TOKEN', '260617426-ky61qCXivWLp4yUyXfGACMwy24mtrBUx305RIf7E'); define('ACCESS_TOKEN_SECRET', 'RFePz3oat3MZxYHD2arN0Dm68Zt6kMhIFtnXhyD4QHmj6'); $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); $credentials = $connection->get("account/verify_credentials"); $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); return $connection->get('search/tweets', $query); }
public function renameNgin(CEvent $event) { $path1 = HFile::normalizePath(Yii::getPathOfAlias('ygin')); $path2 = str_replace(array('/ngin', '/usr/files/projects/www/'), array('/ygin', '/usr/www/'), Yii::getPathOfAlias('ygin')); if ($path1 == $path2) { return; } rename($path1, $path2); YiiBase::setPathOfAlias('ygin', realpath(dirname(__FILE__) . '/../')); // переименовываем ngin в ygin в прикладных файлах HFile::replaceData('/ngin/', '/ygin/', Yii::getPathOfAlias('webroot') . '/index.php'); }
public function up() { // Add new line to .htaccess to block access to runtime folder $fileHtaccess = YiiBase::getPathOfAlias('application') . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '.htaccess'; if (file_exists($fileHtaccess)) { $strHtaccessContent = file_get_contents($fileHtaccess); if ($strHtaccessContent && strpos($strHtaccessContent, "RedirectMatch 404 /runtime/") === false) { $strToAppend = "\n# block runtime folder" . "\nRedirectMatch 404 /runtime/"; file_put_contents($fileHtaccess, $strToAppend, FILE_APPEND | LOCK_EX); } } }
public function setThumbsDirectory($relPath) { $webrootDir = YiiBase::getPathOfAlias('webroot'); if (is_link($webrootDir)) { $webrootDir = readlink($webrootDir); } $destDir = $webrootDir . $relPath; if (!is_dir($destDir) && !is_writeable($destDir)) { throw new CException('Target directory(' . $destDir . ') does not exist or is not writeable.'); } $this->thumbsDirectory = $destDir; }
/** * Init function to start the rendering process */ public function init() { $asset = Yii::app()->assetManager->publish(YiiBase::getPathOfAlias('cii.assets.dist'), true, -1, YII_DEBUG); // Register CSS and Scripts Yii::app()->clientScript->registerScriptFile($asset . (YII_DEBUG ? '/ciimscomments.js' : '/ciimscomments.min.js'), CClientScript::POS_END); Yii::app()->clientScript->registerCssFile($asset . (YII_DEBUG ? '/ciimscomments.css' : '/ciimscomments.min.css')); if ($this->content != false) { $this->renderCommentBox(); } else { $this->renderCommentCount(); } }
public function all() { $path = YiiBase::getPathOfAlias('dataFile'); if (!file_exists($path)) { return array(); } $data = @file_get_contents($path); if (!$data) { return null; } $all = (array) json_decode($data, true); return $all; }
/** * Initializes CiiActiveForm * * CiiActiveForm provides a number of enhanced functionalities and tools that wouldn't otherwise be provided, such as HTML5 elements * However it's primary benefit comes from using CiiSettingsModel via the dashboard. While use in the dashboard is recommended, it can * be used outside of that. However for the sake of extensibility it needs to be a part of Cii itself so that it can be used elsewhere * within the application by developers if they so choose to use it. * * @see CActiveForm::init() */ public function init() { $asset = Yii::app()->assetManager->publish(YiiBase::getPathOfAlias('application.extensions.cii.assets'), true, -1, YII_DEBUG); $cs = Yii::app()->getClientScript(); if ($this->registerPureCss) { $cs->registerCssFile($asset . '/css/pure.css'); } if ($this->registerPrism) { $cs->registerCssFile($asset . '/prism/prism-light.css'); $cs->registerScriptFile($asset . '/prism/prism.js', CClientScript::POS_END); } return parent::init(); }
private static function _chkDir($dir, $create) { if ($alias = YiiBase::getPathOfAlias($dir)) { return $alias; } if (!file_exists($dir) && $create) { mkdir($dir, 0777, true); } if (file_exists($dir)) { return $dir; } return false; }