Пример #1
0
 public function actionImagelist($attr)
 {
     $attribute = strtolower($attr);
     $uploadPath = Yii::app()->basePath . '/../images';
     $uploadUrl = bu('images');
     if ($uploadPath === null) {
         $path = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'uploads';
         $uploadPath = realpath($path);
         if ($uploadPath === false) {
             exit;
         }
     }
     if ($uploadUrl === null) {
         $uploadUrl = Yii::app()->request->baseUrl . '/uploads';
     }
     $attributePath = $uploadPath . DIRECTORY_SEPARATOR . $attribute;
     $attributeUrl = $uploadUrl . '/' . $attribute . '/';
     $files = CFileHelper::findFiles($attributePath, array('fileTypes' => array('gif', 'png', 'jpg', 'jpeg'), 'level' => 0));
     $data = array();
     if ($files) {
         foreach ($files as $file) {
             $data[] = array('thumb' => $attributeUrl . basename($file), 'image' => $attributeUrl . basename($file));
         }
     }
     echo CJSON::encode($data);
     exit;
 }
Пример #2
0
 public function run($attr)
 {
     $name = strtolower($this->getController()->getId());
     $attribute = strtolower((string) $attr);
     if ($this->uploadPath === null) {
         $path = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'uploads';
         $this->uploadPath = realpath($path);
         if ($this->uploadPath === false) {
             exit;
         }
     }
     if ($this->uploadUrl === null) {
         $this->uploadUrl = Yii::app()->request->baseUrl . '/uploads';
     }
     $attributePath = $this->uploadPath . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . $attribute;
     $attributeUrl = $this->uploadUrl . '/' . $name . '/' . $attribute . '/';
     $files = CFileHelper::findFiles($attributePath, array('fileTypes' => array('gif', 'png', 'jpg', 'jpeg')));
     $data = array();
     if ($files) {
         foreach ($files as $file) {
             $data[] = array('thumb' => $attributeUrl . basename($file), 'image' => $attributeUrl . basename($file));
         }
     }
     echo CJSON::encode($data);
     exit;
 }
Пример #3
0
 /**
  * Execute the action.
  * @param array command line parameters specific for this command
  */
 public function run($args)
 {
     if (!isset($args[0])) {
         $this->usageError('the CLDR data directory is not specified.');
     }
     if (!is_dir($path = $args[0])) {
         $this->usageError("directory '{$path}' does not exist.");
     }
     // collect XML files to be processed
     $options = array('exclude' => array('.svn'), 'fileTypes' => array('xml'), 'level' => 0);
     $files = CFileHelper::findFiles(realpath($path), $options);
     $sourceFiles = array();
     foreach ($files as $file) {
         $sourceFiles[basename($file)] = $file;
     }
     // sort by file name so that inheritances can be processed properly
     ksort($sourceFiles);
     // process root first because it is inherited by all
     if (isset($sourceFiles['root.xml'])) {
         $this->process($sourceFiles['root.xml']);
         unset($sourceFiles['root.xml']);
         foreach ($sourceFiles as $sourceFile) {
             $this->process($sourceFile);
         }
     } else {
         die('Unable to find the required root.xml under CLDR data directory.');
     }
 }
Пример #4
0
 public function prepare()
 {
     $this->files = array();
     $templatePath = $this->templatePath;
     $modulePath = $this->modulePath;
     $moduleTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'module.php';
     $this->files[] = new CCodeFile($modulePath . '/' . $this->moduleClass . '.php', $this->render($moduleTemplateFile));
     $files = CFileHelper::findFiles($templatePath, array('exclude' => array('.svn')));
     foreach ($files as $file) {
         if ($file !== $moduleTemplateFile) {
             if (CFileHelper::getExtension($file) === 'php') {
                 $content = $this->render($file);
             } else {
                 if (basename($file) === '.yii') {
                     // an empty directory
                     $file = dirname($file);
                     $content = null;
                 } else {
                     $content = file_get_contents($file);
                 }
             }
             $this->files[] = new CCodeFile($modulePath . substr($file, strlen($templatePath)), $content);
         }
     }
 }
Пример #5
0
 public function actionGet()
 {
     $dir = Yii::getPathOfAlias(Yii::app()->params['sharedMemory']['flushDirectory']);
     $files = CFileHelper::findFiles($dir, array('fileTypes' => array(Yii::app()->params['sharedMemory']['flushExtension'])));
     if (isset($files[0])) {
         $size = filesize($files[0]);
         $file = fopen($files[0], 'r');
         $descriptor = $files[0] . ".descr";
         if (is_file($descriptor)) {
             $descr = fopen($descriptor, "r");
             $pos = fread($descr, filesize($descriptor));
             fclose($descr);
         } else {
             $pos = 0;
         }
         fseek($file, $pos);
         $content = fread($file, self::CHUNK_SIZE);
         $position = strrpos($content, '##') + 2;
         $pos += $position;
         echo substr($content, 0, $position);
         fclose($file);
         $descr = fopen($descriptor, "w");
         fwrite($descr, $pos);
         fclose($descr);
         if ($pos >= $size) {
             unlink($files[0]);
             unlink($descriptor);
         }
         Yii::app()->end();
     }
 }
Пример #6
0
 /**
  * Execute the action.
  * @param array command line parameters specific for this command
  */
 public function run($args)
 {
     $options = array('fileTypes' => array('php'), 'exclude' => array('.gitignore', '/messages', '/views', '/cli', '/yii.php', '/yiit.php', '/yiilite.php', '/web/js', '/vendors', '/i18n/data', '/utils/mimeTypes.php', '/test', '/zii', '/gii'));
     $files = CFileHelper::findFiles(YII_PATH, $options);
     $map = array();
     foreach ($files as $file) {
         if (($pos = strpos($file, YII_PATH)) !== 0) {
             die("Invalid file '{$file}' found.");
         }
         $path = str_replace('\\', '/', substr($file, strlen(YII_PATH)));
         $className = substr(basename($path), 0, -4);
         if ($className[0] === 'C') {
             $map[$path] = "\t\t'{$className}' => '{$path}',\n";
         }
     }
     ksort($map);
     $map = implode($map);
     $yiiBase = file_get_contents(YII_PATH . '/YiiBase.php');
     $newYiiBase = preg_replace('/private\\s+static\\s+\\$_coreClasses\\s*=\\s*array\\s*\\([^\\)]*\\)\\s*;/', "private static \$_coreClasses=array(\n{$map}\t);", $yiiBase);
     if ($yiiBase !== $newYiiBase) {
         file_put_contents(YII_PATH . '/YiiBase.php', $newYiiBase);
         echo "YiiBase.php is updated successfully.\n";
     } else {
         echo "Nothing changed.\n";
     }
 }
Пример #7
0
 public function actionIndex($path = null, $fix = null)
 {
     if ($path === null) {
         $path = YII_PATH;
     }
     echo "Checking {$path} for files with BOM.\n";
     $checkFiles = CFileHelper::findFiles($path, array('exclude' => array('.gitignore')));
     $detected = false;
     foreach ($checkFiles as $file) {
         $fileObj = new SplFileObject($file);
         if (!$fileObj->eof() && false !== strpos($fileObj->fgets(), self::BOM)) {
             if (!$detected) {
                 echo "Detected BOM in:\n";
                 $detected = true;
             }
             echo $file . "\n";
             if ($fix) {
                 file_put_contents($file, substr(file_get_contents($file), 3));
             }
         }
     }
     if (!$detected) {
         echo "No files with BOM were detected.\n";
     } else {
         if ($fix) {
             echo "All files were fixed.\n";
         }
     }
 }
Пример #8
0
 public function prepare()
 {
     $this->files = array();
     $templatePath = $this->templatePath;
     $modulePath = $this->modulePath;
     $moduleTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'module.php';
     $this->files[] = new CCodeFile($modulePath . '/' . $this->moduleClass . '.php', $this->render($moduleTemplateFile));
     $files = CFileHelper::findFiles($templatePath, array('exclude' => array('.svn', '.gitignore')));
     foreach ($files as $file) {
         if ($file !== $moduleTemplateFile && !$this->isIgnireFile($file)) {
             if (CFileHelper::getExtension($file) === 'php') {
                 $content = $this->render($file);
             } elseif (basename($file) === '.gitkeep') {
                 $file = dirname($file);
                 $content = null;
             } else {
                 $content = file_get_contents($file);
             }
             $modifiedFile = $this->getModifiedFile($file);
             if ($modifiedFile !== false) {
                 $file = $modifiedFile;
             }
             $this->files[] = new CCodeFile($modulePath . substr($file, strlen($templatePath)), $content);
         }
     }
 }
Пример #9
0
 /**
  * Lists all log files.
  */
 public function actionIndex()
 {
     //$this->setLogPath();
     $a_files = CFileHelper::findFiles($this->logPath, array('exclude' => array('zip')));
     $arr = array();
     foreach ($a_files as $k => $f) {
         $arr[] = array('id' => $k, 'name' => basename($f), 'size' => filesize($f));
     }
     //print_r($arr);
     $dataProvider = new CArrayDataProvider($arr, array('sort' => array('attributes' => array('name', 'size')), 'pagination' => array('pageSize' => 50)));
     $this->render('index', array('dataProvider' => $dataProvider));
 }
 public function initialise($properties = false)
 {
     if ($properties) {
         foreach ($properties as $key => $value) {
             $this->{$key} = $value;
         }
     }
     parent::prepare();
     $this->files = array();
     $this->moduleTemplateFile = $this->templatePath . DIRECTORY_SEPARATOR . 'module.php';
     $this->files[] = new CCodeFile($this->modulePath . '/' . $this->moduleClass . '.php', $this->render($this->moduleTemplateFile));
     $this->files_to_process = CFileHelper::findFiles($this->templatePath, array('exclude' => array('.svn')));
 }
Пример #11
0
 public static function getFlagImagesList()
 {
     Yii::import('system.utils.CFileHelper');
     $adminAssetsUrl = Yii::app()->getModule('admin')->assetsUrl;
     $flagsPath = 'application.modules.admin.assets.images.flags.png';
     $result = array();
     $flags = CFileHelper::findFiles(Yii::getPathOfAlias($flagsPath));
     foreach ($flags as $f) {
         $fileName = end(explode(DIRECTORY_SEPARATOR, $f));
         $result[$fileName] = $fileName;
     }
     return $result;
 }
Пример #12
0
 public function actionIndex()
 {
     $files = CFileHelper::findFiles(Yii::getPathOfAlias('application.messages.zh_cn'));
     include Yii::getPathOfAlias('application.data') . '/ZhConversion.php';
     $path = Yii::getPathOfAlias('application.messages.zh_tw');
     foreach ($files as $file) {
         if (basename($file) === 'event.php') {
             continue;
         }
         $content = file_get_contents($file);
         $content = strtr($content, $zh2Hant);
         file_put_contents($path . '/' . basename($file), $content);
     }
 }
Пример #13
0
 /**
  * Execute the action.
  * @param array command line parameters specific for this command
  */
 public function run($args)
 {
     // Url template
     $template = 'http://code.google.com/p/yii/source/diff?format=side&path=/trunk/docs/{type}/{name}&old={old}&r={new}';
     if (!isset($args[0])) {
         $this->usageError('the language ID is not specified.');
     }
     $path = Yii::getPathOfAlias('application') . '/../' . $this->type . '/' . $args[0];
     if (!is_dir($path)) {
         $this->usageError("no translation available for language '{$args[0]}'.");
     }
     $srcPath = Yii::getPathOfAlias('application') . '/../' . $this->type . '/source';
     $files = CFileHelper::findFiles($srcPath, array('fileTypes' => array('txt'), 'level' => 0));
     $results = array();
     $urls = array();
     foreach ($files as $file) {
         $name = basename($file);
         $srcContent = file_get_contents($file);
         if (!preg_match('/\\$Id:\\s*([\\w\\.\\-]+)\\s*(\\d+)/iu', $srcContent, $matches) || $name !== $matches[1]) {
             $results[$name] = "revision token not found in source file.";
             continue;
         }
         $srcRevision = $matches[2];
         if (!is_file($path . '/' . $name) || ($content = file_get_contents($path . '/' . $name)) === $srcContent) {
             $results[$name] = "not translated yet.";
         } else {
             if (!preg_match('/\\$Id:\\s*([\\w\\.\\-]+)\\s*(\\d+)/iu', $content, $matches) || $name !== $matches[1]) {
                 $results[$name] = "revision token not found in translation.";
             } else {
                 if ($matches[2] >= $srcRevision) {
                     $results[$name] = "up-to-date.";
                 } else {
                     $results[$name] = "outdated (source: r{$srcRevision}, translation: r{$matches[2]}).";
                     $tr = array('{name}' => $name, '{old}' => $matches[2], '{new}' => $srcRevision, '{type}' => $this->type);
                     $urls[$name] = strtr($template, $tr);
                 }
             }
         }
     }
     asort($results);
     foreach ($results as $name => $result) {
         echo str_pad($name, 30, ' ', STR_PAD_LEFT) . ': ' . $result . "\n";
     }
     echo "\n****************** diff URL's ******************\n";
     asort($urls);
     foreach ($urls as $name => $result) {
         echo $name . ":\n" . $result . "\n\n";
     }
 }
Пример #14
0
    public function generateMessagesModules($locale)
    {
        $modules = ModulesModel::getModules();
        $t = new yandexTranslate();
        $result = array();
        $num = -1;
        $params = array();
        foreach ($modules as $key => $mod) {
            $pathDefault = Yii::getPathOfAlias(self::PATH_MOD . '.' . $key . '.messages.ru');
            $listfile = CFileHelper::findFiles($pathDefault, array('fileTypes' => array('php'), 'absolutePaths' => false));
            $path = Yii::getPathOfAlias(self::PATH_MOD . '.' . $key . '.messages' . DS . $locale);
            //CFileHelper::createDirectory($path, 0777);
            CFileHelper::copyDirectory($pathDefault, $path, array('fileTypes' => array('php'), 'level' => 1));
            foreach ($listfile as $file) {
                //   $file = str_replace('.php', '', $file);
                $openFileContent = self::PATH_MOD . ".{$key}.messages.{$locale}";
                $contentList = (include Yii::getPathOfAlias($openFileContent) . DS . $file);
                // foreach($contentList as $pkey=>$value){
                foreach ($contentList as $pkey => $val) {
                    $params[] = $val;
                    $num++;
                    $spec[$num] = $pkey;
                }
                $response = $t->translate(array('ru', $locale), $contentList);
                foreach ($response['text'] as $k => $v) {
                    $result[$spec[$k]] = $v;
                }
                if (!@file_put_contents($path . DS . $file, '<?php

/**
 * Message translations. (auto translate)
 * 
 * Each array element represents the translation (value) of a message (key).
 * If the value is empty, the message is considered as not translated.
 * Messages that no longer need translation will have their translations
 * enclosed between a pair of \'@@\' marks.
 * 
 * @author Andrew (Panix) Semenov <*****@*****.**>
 * @package modules.messages.' . $locale . '
 */
return ' . var_export($result, true) . ';')) {
                    throw new CException(Yii::t('admin', 'Error write modules setting in {file}...', array('{file}' => $file)));
                }
            }
            die('finish ' . $key);
        }
        die('Complate');
        // $locale
    }
Пример #15
0
 /**
  * is a clone of initModuleData the differnece is this import files can contain 
  * multiple destination dataset in one single file, the key being the destignation collection 
  * http://127.0.0.1/ph/communecter/person/initDataPeopleAll
  * http://127.0.0.1/ph/communecter/person/clearInitDataPeopleAll
  * tool mongo query :: db.citoyens.find({email:/oceat/},{email:1,events:1,links:1,projects:1})
  * @param type $moduleId 
  * @param type $type , is the file type when wanting to load only one file at a time
  * @param type $isDummy , if is true, often associated with the type , on each dummy data inserted will be added dummyData:$type
  * @return type
  */
 public static function initMultipleModuleData($moduleId, $type = null, $isDummy = false, $linkAllToActiveUser = false, $reverse = false)
 {
     $res = array("module" => $moduleId, "userId" => Yii::app()->session['userId'], "imported" => array(), "errors" => 0, "linkAllToActiveUser" => $linkAllToActiveUser);
     if (file_exists(Yii::getPathOfAlias(Yii::app()->params["modulePath"] . $moduleId . ".data"))) {
         $file = null;
         foreach (CFileHelper::findFiles(Yii::getPathOfAlias(Yii::app()->params["modulePath"] . $moduleId . ".data")) as $f) {
             //echo pathinfo($f, PATHINFO_FILENAME)."<br/>";
             if (pathinfo($f, PATHINFO_FILENAME) == $type) {
                 $file = $f;
                 break;
             }
         }
         $jsonAll = json_decode(file_get_contents($file), true);
         $importRes = array("file" => $type, "isDummy" => $isDummy ? $type : false, "imports" => array(), "count" => 0, "errors" => 0);
         foreach ($jsonAll as $col => $data) {
             if (!$reverse) {
                 if ($col != "linkAllToActiveUser") {
                     $importRes['imports'][$col] = array();
                     $importRes['imports'][$col]["count"] = count($data);
                     $importRes["count"] += count($data);
                     $importRes['imports'][$col]["collection"] = $col;
                     $errors = array();
                     $infos = array();
                     foreach ($data as $row) {
                         //TODO SBAR - Faire un test sur le type pour utiliser les méthodes du modèle ?
                         $infosRes = self::insertData($row, $col, $type, $isDummy, $linkAllToActiveUser);
                         if ($infosRes["error"]) {
                             array_push($errors, $infosRes["error"]);
                         }
                         array_push($infos, $infosRes["info"]);
                     }
                     $importRes['imports'][$col]["infos"] = $infos;
                     $importRes['imports'][$col]["errors"] = $errors;
                 } else {
                     $linkAllToActiveUser = true;
                     $res["linkAllToActiveUser"] = true;
                 }
             } else {
                 $infosRes = self::removeData($col, $type, $isDummy, $linkAllToActiveUser);
                 $importRes["count"] += $infosRes["count"];
             }
         }
         array_push($res["imported"], $importRes);
     } else {
         $res["msg"] = "Nothing to import";
     }
     return $res;
 }
Пример #16
0
 /**
  * Redactor image list.
  *
  * @param string $name Model name
  * @param string $attr Model attribute
  */
 public function actionRedactorImageList($name, $attr)
 {
     $name = (string) $name;
     $attribute = (string) $attr;
     $attributePath = $this->module->getAttributePath($name, $attribute);
     $files = CFileHelper::findFiles($attributePath, array('fileTypes' => array('gif', 'png', 'jpg', 'jpeg')));
     $data = array();
     if ($files) {
         foreach ($files as $file) {
             $fileUrl = $this->module->getAttributeUrl($name, $attribute, basename($file));
             $data[] = array('thumb' => $fileUrl, 'image' => $fileUrl);
         }
     }
     echo CJSON::encode($data);
     exit;
 }
Пример #17
0
 public function prepare()
 {
     //$this->encodedLayoutName = $this->encode($this->layoutName);
     $this->encodedLayoutName = GxcHelpers::encode($this->layoutName, '_', false);
     //The directory where the new code will be generated to
     $layoutPath = COMMON_FOLDER . DIRECTORY_SEPARATOR . 'front_layouts' . DIRECTORY_SEPARATOR . $this->encodedLayoutName;
     //Get all the paths of template files
     $files = CFileHelper::findFiles($this->templatePath);
     foreach ($files as $file) {
         //Get the path of new code to be generated
         $generatedFilePath = $layoutPath . str_replace($this->templatePath, '', $file);
         //Get the path of template files (in the folder templates)
         $templateFile = $this->render($file);
         //code to be generated
         $this->files[] = new CCodeFile($generatedFilePath, $templateFile);
     }
 }
Пример #18
0
 /**
  * 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('desktop' => array(), 'mobile' => array(), 'tablet' => array());
         $fileHelper = new CFileHelper();
         $files = $fileHelper->findFiles(Yii::getPathOfAlias('webroot.themes'), array('fileTypes' => array('json'), 'level' => 1));
         foreach ($files as $file) {
             if (strpos($file, 'theme.json') === false) {
                 continue;
             }
             $theme = json_decode(file_get_contents($file), true);
             $themes[$theme['type']][] = $theme;
         }
         Yii::app()->cache->set('settings_themes', $themes);
     }
     return $themes;
 }
Пример #19
0
 public function getuppload_files()
 {
     $session = new CHttpSession();
     $session->open();
     $folder = $_SERVER['DOCUMENT_ROOT'] . '/upload/tmp/' . $session->SessionID;
     $files = array();
     if (is_dir($folder)) {
         $files = CFileHelper::findFiles($folder, array('level' => 0));
     }
     if (!$this->isimport) {
         if (!$files) {
             return CUploadedFile::getInstancesByName('');
         } else {
             return $files;
         }
     } else {
         return array(123, 321);
     }
 }
Пример #20
0
 protected function generateRoutes($moduleId)
 {
     $module = app()->getModule($moduleId);
     $controllerPath = Yii::getPathOfAlias($moduleId . '.controllers');
     $files = CFileHelper::findFiles($controllerPath, array('fileType' => array('php'), 'exclude' => array('.svn', '/widgets')));
     $controllers = array();
     foreach ($files as $file) {
         $name = str_replace('.php', '', basename($file));
         $path = $this->resolveControllerPath($moduleId, $controllerPath, $file);
         if (!in_array($name, get_declared_classes())) {
             try {
                 require_once $file;
             } catch (Exception $ex) {
                 echo $ex->getMessage(), "\n";
             }
         }
         $controllers[$path] = new ReflectionClass($name);
     }
     /** process classes */
     // master route of the module (mask all controllers)
     $this->addRoute($moduleId, '', 'module');
     foreach ($controllers as $path => $c) {
         // master route of controller (mask all actions)
         $this->addRoute($moduleId, $path, 'controller');
         // route for each action
         /** @var ReflectionClass $c */
         $methods = $c->getMethods(ReflectionMethod::IS_PUBLIC);
         $actions = array();
         foreach ($methods as $method) {
             if (strpos($method->name, 'action') === 0) {
                 if ($method->name != 'actions') {
                     $actions[] = str_replace('action', '', $method->name);
                 }
             }
         }
         foreach ($actions as $action) {
             $route = "{$path}.{$action}";
             $this->addRoute($moduleId, $route);
         }
         /** TODO: delete all actions removed in code */
     }
     return true;
 }
Пример #21
0
 public static function getMap($exclude = array())
 {
     if (self::$_map !== null) {
         return self::$_map;
     }
     $modules = array_merge(array('application' => array()), Yii::app()->getModules());
     $map = array();
     foreach ($modules as $module => $config) {
         if (isset($exclude[$module]) && $exclude[$module] == '*') {
             continue;
         }
         if (!file_exists(Yii::getPathOfAlias("{$module}.models"))) {
             continue;
         }
         Yii::import("{$module}.models.*");
         $filenames = CFileHelper::findFiles(Yii::getPathOfAlias("{$module}.models"), array('fileTypes' => array('php'), 'level' => 0));
         foreach ($filenames as $filename) {
             //remove off the path
             $file = substr($filename, strrpos($filename, '/') + 1);
             // remove the extension, strlen('.php') = 4
             $model = substr($file, 0, strlen($file) - 4);
             $class = new ReflectionClass($model);
             if ($class->isAbstract()) {
                 continue;
             }
             try {
                 $obj = CActiveRecord::model($model);
             } catch (Exception $e) {
                 continue;
             }
             if (!$obj instanceof NetActiveRecord) {
                 continue;
             }
             if (isset($exclude[$module]) && in_array($model, $exclude[$module])) {
                 continue;
             }
             $map[$model] = $module;
         }
     }
     self::$_map = $map;
     return self::$_map;
 }
Пример #22
0
 public static function getListOfControllers($flag = TRUE)
 {
     $appControllerPath = Yii::getPathOfAlias('application.controllers');
     //checking existence of controllers directory
     if (is_dir($appControllerPath)) {
         $fileLists = CFileHelper::findFiles($appControllerPath);
     }
     $controllerName = array();
     foreach ($fileLists as $controllerPath) {
         //getting controller name like e.g. 'siteController.php'
         $name = substr($controllerPath, strrpos($controllerPath, DIRECTORY_SEPARATOR) + 1, -4);
         $name = str_replace('Controller', '', $name);
         if (in_array($name, array("Auth", "App"))) {
             if ($flag != TRUE) {
                 $controllerName[$name] = $name;
             }
         } else {
             $controllerName[$name] = $name;
         }
     }
     return $controllerName;
 }
 private function checkModelsRelations()
 {
     $cFileHelper = new CFileHelper();
     $models = $cFileHelper->findFiles(Yii::getPathOfAlias('application.models'), array('fileTypes' => array('php')));
     foreach ($models as $model) {
         $modelName = substr($model, strrpos($model, DIRECTORY_SEPARATOR) + 1);
         $modelName = substr($modelName, 0, strpos($modelName, '.php'));
         if (strpos($modelName, 'Base') === 0 || !method_exists($modelName, 'model')) {
             //echo "\nSkipping $modelName as not Contains base or has not model method";
             continue;
         }
         try {
             $thisModel = $modelName::model();
             if (!$thisModel instanceof CActiveRecord) {
                 //echo "\nSkipping $modelName as not CactiveRecord";
                 continue;
             }
         } catch (CdbException $e) {
             echo "\n skipping : " . $modelName;
             continue;
         } catch (Exception $e) {
             echo "\nSomething wrong happened: " . $modelName . " Code: " . $e->getCode() . " Message: " . $e->getMessage() . " Trace: " . $e->getTraceAsString();
         }
         $rels = $thisModel->relations();
         echo "\nChecking Model name : " . $modelName . " rels: " . var_export($rels, true);
         foreach ($rels as $rel => $relProps) {
             if ($relProps[0] == 'CBelongsToRelation') {
                 foreach ($thisModel->findAll() as $thisRecords) {
                     $findBelongs = $thisModel->with($rel)->findByPk($thisRecords->id);
                     if (count($findBelongs) > 0) {
                         //echo "\n$modelName Relation $rel found, tot:" . count($findBelongs);
                     } else {
                         echo "\n{$modelName} belong Relation {$rel}  missing \n\n";
                     }
                 }
             }
         }
     }
 }
Пример #24
0
 public function prepare()
 {
     $this->files = array();
     $templatePath = $this->templatePath;
     $widgetPath = Yii::getPathOfAlias($this->widgetPath);
     $widgetTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'widget.php';
     $this->files[] = new CCodeFile($widgetPath . '/' . $this->widgetClass . '.php', $this->render($widgetTemplateFile));
     $files = CFileHelper::findFiles($templatePath, array('exclude' => array('.svn', '.gitignore')));
     foreach ($files as $file) {
         if ($file !== $widgetTemplateFile) {
             if (CFileHelper::getExtension($file) === 'php') {
                 $content = $this->render($file);
             } elseif (basename($file) === '.yii') {
                 $file = dirname($file);
                 $content = null;
             } else {
                 $content = file_get_contents($file);
             }
             $this->files[] = new CCodeFile($widgetPath . substr($file, strlen($templatePath)), $content);
         }
     }
 }
Пример #25
0
 /**
  * Publishes all messages to JavaScript files to use on client side.
  */
 public function publishJavaScriptMessages()
 {
     $language = Yii::app()->getLanguage();
     // Load date of last change
     $maxFiletime = null;
     $packages = array();
     $files = CFileHelper::findFiles($this->basePath . DIRECTORY_SEPARATOR . 'en');
     foreach ($files as $file) {
         $basename = basename($file);
         $packages[] = substr($basename, 0, strpos($basename, '.'));
         $maxFiletime = max($maxFiletime, filemtime($file));
     }
     // Get asset manager
     $assetManager = Yii::app()->getAssetManager();
     $assetPath = $assetManager->getBasePath() . DIRECTORY_SEPARATOR . 'lang_js';
     // Check for changes
     $publish = false;
     if (!is_dir($assetPath)) {
         mkdir($assetPath);
         $publish = true;
     } elseif (!is_file($assetPath . DIRECTORY_SEPARATOR . $language . '.js')) {
         $publish = true;
     } elseif (filemtime($assetPath . DIRECTORY_SEPARATOR . $language . '.js') < $maxFiletime) {
         $publish = true;
     }
     // Publish if needed
     if ($publish || YII_DEBUG) {
         $code = '';
         foreach ($packages as $package) {
             $code .= 'lang.' . $package . ' = [];' . "\n";
             $data = $this->loadMessages($package, $language);
             foreach ($data as $key => $value) {
                 $code .= 'lang.' . $package . '["' . $key . '"] = ' . CJSON::encode($value) . ';' . "\n";
             }
         }
         file_put_contents($assetPath . DIRECTORY_SEPARATOR . $language . '.js', $code);
     }
 }
Пример #26
0
 /**
  * Get a list of all models.
  *
  * @return array Model names
  */
 public function getModelsList()
 {
     $models = $this->registerModels;
     if (!empty($models)) {
         foreach ($models as $model) {
             Yii::import($model);
             if (substr($model, -1) == '*') {
                 // Get a list of all models inside a directory. Example: 'application.models.*'
                 $files = CFileHelper::findFiles(Yii::getPathOfAlias($model), array('fileTypes' => array('php')));
                 if ($files) {
                     foreach ($files as $file) {
                         $modelName = str_replace('.php', '', substr(strrchr($file, DIRECTORY_SEPARATOR), 1));
                         $this->addModel($modelName);
                     }
                 }
             } else {
                 $modelName = substr(strrchr($model, "."), 1);
                 $this->addModel($modelName);
             }
         }
     }
     return array_unique($this->_modelsList);
 }
Пример #27
0
 public function actionIndex()
 {
     //		try {
     $options = [];
     if (isset($fileTypes)) {
         $options['fileTypes'] = $fileTypes;
     }
     if (isset($exclude)) {
         $options['exclude'] = $exclude;
     }
     $files = CFileHelper::findFiles(realpath($this->sourcePath), $options);
     $messages = [];
     foreach ($files as $file) {
         $messages = array_merge_recursive($messages, $this->extractMessages($file, $this->translator));
     }
     foreach ($messages as $category => $msgs) {
         $msgs = array_values(array_unique($msgs));
         $this->saveMessageSources($category, $msgs);
         //			$this->generateMessageFile($msgs, $dir . DIRECTORY_SEPARATOR . $category . '.php', $overwrite, $removeOld, $sort, $fileHeader);
     }
     //		} catch (Exception $e) {
     //			echo $e->getMessage() . PHP_EOL;
     //		}
 }
Пример #28
0
 /**
  * Системные виджеты
  * @return array
  */
 private function getWidgetsSystem()
 {
     $result = array();
     $extFiles = CFileHelper::findFiles(Yii::getPathOfAlias('ext.blocks'), array('level' => 1, 'fileTypes' => array('php'), 'absolutePaths' => false));
     foreach ($extFiles as $file) {
         $rep = str_replace('.php', '', $file);
         $expFile = explode(DS, $rep);
         $dir = $expFile[0];
         $name = $expFile[1];
         $alias = "ext.blocks.{$dir}.{$name}";
         Yii::import($alias);
         $class = new $name();
         if ($class instanceof BlockWidget) {
             $data = array('name' => $class->getTitle(), 'alias_wgt' => $alias);
             $result[$alias] = $class->getTitle();
             $this->set('system', $data);
         } else {
             $data = array('name' => $name, 'alias_wgt' => $alias);
             $result[$alias] = $name;
             $this->set('system', $data);
         }
     }
     return $result;
 }
Пример #29
0
 public function prepare()
 {
     $this->files = array();
     $templatePath = $this->templatePath;
     $modulePath = $this->modulePath;
     $moduleTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'module.php';
     // Файл описывающий модуль
     $moduleFile = $modulePath . '/' . $this->moduleClass . '.php';
     $this->isNewModule = file_exists($moduleFile) ? false : true;
     if ($this->isNewModule) {
         $this->files[] = new CCodeFile($moduleFile, $this->render($moduleTemplateFile));
     }
     $files = CFileHelper::findFiles($templatePath, array('exclude' => array('.svn', '.gitignore')));
     foreach ($files as $file) {
         if ($file !== $moduleTemplateFile) {
             if (CFileHelper::getExtension($file) === 'php') {
                 $content = $this->render($file);
             } else {
                 if (basename($file) === '.yii') {
                     $file = dirname($file);
                     $content = null;
                 } else {
                     $content = file_get_contents($file);
                 }
             }
             // Controller custom filename
             if (basename($file) == 'controller.php') {
                 $filePath = $modulePath . substr(dirname($file) . '/' . ucfirst($this->controllerID) . 'Controller.php', strlen($templatePath));
             } else {
                 //$filePath = $modulePath . substr($file, strlen($templatePath));
                 $filePath = $modulePath . '/views/' . $this->controllerID . '/' . basename($file);
             }
             $this->files[] = new CCodeFile($filePath, $content);
         }
     }
 }
Пример #30
0
 /**
  * Execute the action.
  * @param array command line parameters specific for this command
  */
 public function run($args)
 {
     if (!isset($args[0])) {
         $this->usageError('the configuration file is not specified.');
     }
     if (!is_file($args[0])) {
         $this->usageError("the configuration file {$args[0]} does not exist.");
     }
     $config = (require_once $args[0]);
     $translator = 'Yii::t';
     extract($config);
     if (!isset($sourcePath, $messagePath, $languages)) {
         $this->usageError('The configuration file must specify "sourcePath", "messagePath" and "languages".');
     }
     if (!is_dir($sourcePath)) {
         $this->usageError("The source path {$sourcePath} is not a valid directory.");
     }
     if (!is_dir($messagePath)) {
         $this->usageError("The message path {$messagePath} is not a valid directory.");
     }
     if (empty($languages)) {
         $this->usageError("Languages cannot be empty.");
     }
     if (!isset($overwrite)) {
         $overwrite = false;
     }
     if (!isset($removeOld)) {
         $removeOld = false;
     }
     $options = array();
     if (isset($fileTypes)) {
         $options['fileTypes'] = $fileTypes;
     }
     if (isset($exclude)) {
         $options['exclude'] = $exclude;
     }
     $files = CFileHelper::findFiles(realpath($sourcePath), $options);
     $messages = array();
     foreach ($files as $file) {
         $messages = array_merge_recursive($messages, $this->extractMessages($file, $translator));
     }
     foreach ($languages as $language) {
         $dir = $messagePath . DIRECTORY_SEPARATOR . $language;
         if (!is_dir($dir)) {
             @mkdir($dir);
         }
         foreach ($messages as $category => $msgs) {
             $msgs = array_values(array_unique($msgs));
             $this->generateMessageFile($msgs, $dir . DIRECTORY_SEPARATOR . $category . '.php', $overwrite, $removeOld);
         }
     }
 }