/**
  * Install templates
  *
  * @return void
  */
 private function _installExampleTemplates()
 {
     try {
         $fileHelper = new \CFileHelper();
         @mkdir(craft()->path->getSiteTemplatesPath() . 'sproutemail');
         $fileHelper->copyDirectory(craft()->path->getPluginsPath() . 'sproutemail/templates/_special/examples/emails', craft()->path->getSiteTemplatesPath() . 'sproutemail');
     } catch (\Exception $e) {
         $this->_handleError($e);
     }
 }
Example #2
0
 public function run($args = null)
 {
     $theme = $args[0];
     $themePath = realpath(dirname(__FILE__) . '/../../themes') . DIRECTORY_SEPARATOR . $theme;
     if (!file_exists($themePath)) {
         mkdir($themePath);
         mkdir($themePath . '/views');
     }
     // Find all modules views and copy to theme directory
     $files = glob(realpath(dirname(__FILE__) . '/../') . '/modules/*', GLOB_ONLYDIR);
     foreach ($files as $file) {
         $parts = explode('/', $file);
         $module = end($parts);
         $moduleThemePath = $themePath . '/views/' . $module;
         $moduleViews = glob($file . '/views/*', GLOB_ONLYDIR);
         foreach ($moduleViews as $viewsDirPath) {
             $parts = explode('/', $viewsDirPath);
             if (end($parts) != 'admin') {
                 if (!file_exists($moduleThemePath)) {
                     mkdir($moduleThemePath);
                 }
                 CFileHelper::copyDirectory($viewsDirPath, $moduleThemePath . '/' . end($parts));
             }
         }
     }
 }
Example #3
0
 public function run($args = null)
 {
     $theme = $args[0];
     $themePath = realpath(dirname(__FILE__) . '/../../themes') . '/' . $theme;
     if (!file_exists($themePath)) {
         mkdir($themePath);
         mkdir($themePath . '/views');
     }
     // Find all modules views and copy to theme directory
     $files = glob(realpath(dirname(__FILE__) . '/../') . '/modules/*', GLOB_ONLYDIR);
     foreach ($files as $file) {
         $parts = explode('/', $file);
         $module = end($parts);
         // Don't copy next modules to theme dir.
         if (in_array($module, array('admin', 'install', 'rights'))) {
             continue;
         }
         $moduleThemePath = $themePath . '/views/' . $module;
         $moduleViews = glob($file . '/views/*', GLOB_ONLYDIR);
         foreach ($moduleViews as $viewsDirPath) {
             $parts = explode('/', $viewsDirPath);
             if (end($parts) != 'admin') {
                 if (!file_exists($moduleThemePath)) {
                     mkdir($moduleThemePath, 0777, true);
                 }
                 CFileHelper::copyDirectory($viewsDirPath, $moduleThemePath . '/' . end($parts));
             }
         }
     }
 }
Example #4
0
 protected function getModels()
 {
     $models = array();
     $files = scandir(Yii::getPathOfAlias('application.models'));
     foreach ($files as $file) {
         if ($file[0] !== '.' && CFileHelper::getExtension($file) === 'php') {
             $fileClassName = substr($file, 0, strpos($file, '.'));
             if (class_exists($fileClassName) && is_subclass_of($fileClassName, 'GiiyActiveRecord')) {
                 $fileClass = new ReflectionClass($fileClassName);
                 if (!$fileClass->isAbstract() && !is_array(GiiyActiveRecord::model($fileClassName)->getPrimaryKey())) {
                     $models[] = $fileClassName;
                 }
             }
         }
     }
     foreach (Yii::app()->getModules() as $module => $moduleConf) {
         if (Yii::getPathOfAlias($module . '.models')) {
             $files = scandir(Yii::getPathOfAlias($module . '.models'));
             foreach ($files as $file) {
                 if ($file[0] !== '.' && CFileHelper::getExtension($file) === 'php') {
                     $fileClassName = substr($file, 0, strpos($file, '.'));
                     if (class_exists($fileClassName) && is_subclass_of($fileClassName, 'GiiyActiveRecord')) {
                         $fileClass = new ReflectionClass($fileClassName);
                         if (!$fileClass->isAbstract() && !is_array(GiiyActiveRecord::model($fileClassName)->getPrimaryKey())) {
                             $models[] = $fileClassName;
                         }
                     }
                 }
             }
         }
     }
     return $models;
 }
Example #5
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);
         }
     }
 }
 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);
         }
     }
 }
Example #7
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;
 }
Example #8
0
 public function afterSave($event)
 {
     if (!empty($_FILES)) {
         $model = $this->getOwner();
         $file = new File();
         $file->filename = UploadUtils::createUniquefilename($_FILES[self::NAME]['name'], UploadUtils::getPath(self::$fileDir));
         if (move_uploaded_file($_FILES[self::NAME]['tmp_name'], UploadUtils::getPath(self::$fileDir) . DIRECTORY_SEPARATOR . $file->filename)) {
             $file->entity = get_class($model);
             $file->EXid = $model->getPrimaryKey();
             $file->uid = Yii::app()->user->id;
             $file->tag = $this->tag;
             $file->weight = 0;
             $file->timestamp = time();
             $file->filemime = CFileHelper::getMimeTypeByExtension($_FILES[self::NAME]['name']);
             $file->filesize = $_FILES[self::NAME]['size'];
             $file->status = File::STATUS_SAVED;
             // Ensure all other files of the entity are deleted
             //UploadUtils::deleteAllFiles(get_class($this->getOwner()), self::$fileDir);
             if ($file->save()) {
                 Yii::trace("File saved " . $file . "!!!!");
             } else {
                 Yii::log("Could not save File " . print_r($file->getErrors(), true), CLogger::LEVEL_ERROR);
             }
         } else {
             Yii::log("Couldnt move the file", CLogger::LEVEL_ERROR);
         }
     } else {
         Yii::log("Files empty!!!", CLogger::LEVEL_ERROR);
     }
 }
Example #9
0
 /**
  * Helper method. Return an appropriate CFile instance for a given filesystem object path.
  *
  * @static
  * @param string $filepath Path to the file.
  * @param bool $greedy If `True` file properties (such as 'Size', 'Owner', 'Permission', etc.) would be autoloaded
  * @return CFile
  */
 public static function get($filepath, $greedy = false)
 {
     if (self::$_obj === null) {
         self::$_obj = new self();
     }
     return self::$_obj->set($filepath, $greedy);
 }
 public function run($thumb)
 {
     $key = key($_GET);
     if (NULL == ($file = Files::model()->findByPk($key))) {
         throw new CException('Page not found', 404);
     }
     $path = Yii::getPathOfAlias('webroot') . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'photos';
     $src_file = $file->id . '.' . $file->extension;
     $in_file = $path . DIRECTORY_SEPARATOR . $src_file;
     $out_file = $path . DIRECTORY_SEPARATOR . $thumb . DIRECTORY_SEPARATOR . $src_file;
     if (is_file($out_file)) {
         $mime = CFileHelper::getMimeType($out_file);
         header('Content-Type: ' . $mime);
         readfile($out_file);
         exit;
     }
     if (is_file($in_file)) {
         $dir = $path . DIRECTORY_SEPARATOR . $thumb;
         if (YII_DEBUG && !file_exists($dir)) {
             mkdir($dir, 0777);
         }
         if (file_exists($dir)) {
             if (($out_file = $file->resize($thumb)) == 0) {
                 throw new CException('Page not found', 404);
             }
             $mime = CFileHelper::getMimeType($in_file);
             header('Content-Type: ' . $mime);
             readfile($out_file);
             exit;
         }
     }
     return parent::run($thumb);
 }
Example #11
0
 public function up()
 {
     CFileHelper::removeDirectory(Yii::app()->basePath . "/components/dashboard/");
     CFileHelper::removeDirectory(Yii::app()->basePath . "/../update/");
     CFileHelper::removeDirectory(Yii::app()->basePath . "/../assets/lib/chosen/");
     $this->update('openformat', array("export" => "this.reg_date", "import" => 'this.reg_date'), "id='1362'");
 }
Example #12
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();
     }
 }
Example #13
0
 /**
  * Feltölt egy fájlt a megadott tantárgyhoz.
  * @param int $id A tantárgy azonosítója
  */
 public function actionUpload($id)
 {
     if (!Yii::app()->user->getId()) {
         throw new CHttpException(403, 'A funkció használatához be kell jelentkeznie');
     }
     $id = (int) $id;
     $file = CUploadedFile::getInstanceByName("to_upload");
     if ($file == null) {
         throw new CHttpException(404, 'Nem lett fájl kiválasztva a feltöltéshez');
     }
     $filename = $file->getName();
     $localFileName = sha1($filename . microtime()) . "." . CFileHelper::getExtension($filename);
     if (in_array(strtolower(CFileHelper::getExtension($filename)), Yii::app()->params["deniedexts"])) {
         throw new CHttpException(403, ucfirst(CFileHelper::getExtension($filename)) . ' kiterjesztésű fájl nem tölthető fel a szerverre');
     }
     $model = new File();
     $model->subject_id = $id;
     $model->filename_real = $filename;
     $model->filename_local = $localFileName;
     $model->description = htmlspecialchars($_POST["description"]);
     $model->user_id = Yii::app()->user->getId();
     $model->date_created = new CDbExpression('NOW()');
     $model->date_updated = new CDbExpression('NOW()');
     $model->downloads = 0;
     $model->save();
     if ($file->saveAs("upload/" . $localFileName)) {
         $this->redirect(Yii::App()->createUrl("file/list", array("id" => $id)));
     }
 }
Example #14
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;
 }
 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";
         }
     }
 }
 /**
  * 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.');
     }
 }
 public function run($class_name)
 {
     $path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $class_name);
     $class_name = ucfirst($class_name);
     if ($path && is_dir($path) && is_writable($path)) {
         $dir = key($_GET);
         $filename = $_GET[$dir];
         $pk = pathinfo($filename, PATHINFO_FILENAME);
         $image = Images::model()->findByPk($pk);
         if ($image != null) {
             $image->resize($dir);
         }
     } elseif (class_exists($class_name)) {
         $dir = key($_GET);
         $filename = $_GET[$dir];
         $size = explode('x', $dir);
         $path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $class_name);
         if (YII_DEBUG && !file_exists($path . DIRECTORY_SEPARATOR . $dir)) {
             mkdir($path . DIRECTORY_SEPARATOR . $dir, 0777);
         }
         if ($path !== FALSE && file_exists($path . DIRECTORY_SEPARATOR . $dir) && is_file($path . DIRECTORY_SEPARATOR . $filename) && $size[0] > 0 && $size[1] > 0) {
             Yii::import('ext.iwi.Iwi');
             $image = new Iwi($path . DIRECTORY_SEPARATOR . $filename);
             $image->adaptive($size[0], $size[1]);
             $image->save($path . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $filename, 0644, TRUE);
             $mime = CFileHelper::getMimeType($path . DIRECTORY_SEPARATOR . $filename);
             header('Content-Type: ' . $mime);
             $image->render();
             exit;
         }
     }
     return parent::run($class_name);
 }
Example #18
0
 public function prepare()
 {
     $this->files = array();
     $templatePath = $this->templatePath;
     $controllerTemplateFile = $templatePath . DIRECTORY_SEPARATOR . 'controller.php';
     $this->files[] = new CCodeFile($this->controllerFile, $this->render($controllerTemplateFile));
     $this->files[] = new CCodeFile(str_replace("Controller.php", "AdminController.php", $this->controllerFile), $this->render(str_replace("controller.php", "adminController.php", $controllerTemplateFile)));
     $files = scandir($templatePath);
     foreach ($files as $file) {
         if (is_file($templatePath . '/' . $file) && CFileHelper::getExtension($file) === 'php' && $file !== 'controller.php') {
             $path = $this->viewPath . DIRECTORY_SEPARATOR . $file;
             if ($file == "adminController.php") {
                 continue;
             }
             if ($file == "form.php") {
                 //                    $path = str_replace('\\', '/', $path);
                 //
                 //                    $path_params = str_replace(
                 //                        array("/form.php", MODULES_PATH),
                 //                        null,
                 //                        $path
                 //                    );
                 //
                 //                    $path_params = explode("/", $path_params);
                 //
                 //                    $module_name = $path_params[0];
                 //                    $model_name  = ucfirst($path_params[2]);
                 //
                 //                    $module_dir = MODULES_PATH . $module_name . "/";
                 //
                 //                    $forms_dir = $module_dir . "forms/";
                 //
                 //
                 //                    if (!is_dir($forms_dir))
                 //                    {
                 //                        mkdir($forms_dir);
                 //                        chmod($forms_dir, 0777);
                 //                    }
                 //
                 //                    $path = $forms_dir . $model_name . "Form.php";
             }
             $this->files[] = new CCodeFile($path, $this->render($templatePath . '/' . $file));
         }
     }
     $templatePath = $templatePath . "/admin/";
     $viewPath = $this->viewPath . "Admin/";
     //        if (!is_dir($viewPath))
     //        {
     //            mkdir($viewPath);
     //            chmod($viewPath, 0777);
     //        }
     $files = scandir($templatePath);
     foreach ($files as $file) {
         if ($file[0] == ".") {
             continue;
         }
         $path = $viewPath . $file;
         $this->files[] = new CCodeFile($path, $this->render($templatePath . '/' . $file));
     }
 }
 /**
  * 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";
     }
 }
Example #20
0
 public function tearDown()
 {
     $filePath = $this->getTestFilePath();
     if (file_exists($filePath)) {
         FileHelper::removeDirectory($filePath);
     }
 }
 /**
  * @param CUploadedFile $image
  * @return bool
  */
 public static function isAllowedType(CUploadedFile $image)
 {
     $type = CFileHelper::getMimeType($image->getTempName());
     if (!$type) {
         $type = CFileHelper::getMimeTypeByExtension($image->getName());
     }
     return in_array($type, EventsImagesConfig::get('types'));
 }
Example #22
0
 /**
  * @param CUploadedFile $image
  * @return bool
  */
 public static function isAllowedType(CUploadedFile $image)
 {
     $type = CFileHelper::getMimeType($image->getTempName());
     if (!$type) {
         $type = CFileHelper::getMimeTypeByExtension($image->getName());
     }
     return in_array($type, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png'));
 }
Example #23
0
 /**
  * @static
  * @param $fullPath
  * @return bool|CsvImage
  */
 public static function create($fullPath)
 {
     if (!file_exists($fullPath)) {
         return false;
     }
     $name = explode(DS, $fullPath);
     return new C1ProductImage(end($name), $fullPath, CFileHelper::getMimeType($fullPath), filesize($fullPath), false);
 }
Example #24
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;
 }
 /**
  * @param CUploadedFile $image
  * @return bool
  */
 public static function isAllowedType(CUploadedFile $image)
 {
     $type = CFileHelper::getMimeType($image->getTempName());
     if (!$type) {
         $type = CFileHelper::getMimeTypeByExtension($image->getName());
     }
     //return in_array($type, Yii::app()->params['storeImages']['types']);
     return in_array($type, StoreImagesConfig::get('types'));
 }
Example #26
0
 protected static function geraFilename($url, $outDir = null, $hash = false)
 {
     if ($outDir === null) {
         $outDir = Yii::app()->runtimePath;
     }
     $name = $hash ? md5($url) : tempnam('', 'external');
     $ext = CFileHelper::getExtension(basename($url));
     return "{$outDir}/{$name}.{$ext}";
 }
Example #27
0
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         $model = new UserAvatarForm();
         if (isset($_POST['UserAvatarForm'])) {
             $model->attributes = $_POST['UserAvatarForm'];
             $model->image = CUploadedFile::getInstance($model, 'image');
             if ($model->validate()) {
                 //Get the User Id to determine the folder
                 $folder = user()->id >= 1000 ? (string) (round(user()->id / 1000) * 1000) : '1000';
                 $filename = user()->id . '_' . gen_uuid();
                 if (!(file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder) && AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder)) {
                     mkdir(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder, 0777, true);
                 }
                 if (file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $filename . '.' . strtolower(CFileHelper::getExtension($model->image->name)))) {
                     $filename .= '_' . time();
                 }
                 $filename = $filename . '.' . strtolower(CFileHelper::getExtension($model->image->name));
                 $path = $folder . DIRECTORY_SEPARATOR . $filename;
                 if ($model->image->saveAs(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $path)) {
                     //Generate thumbs
                     //
                     GxcHelpers::generateAvatarThumb($filename, $folder, $filename);
                     //So we will start to check the info from the user
                     $current_user = User::model()->findByPk(user()->id);
                     if ($current_user) {
                         if ($current_user->avatar != null && $current_user->avatar != '') {
                             //We will delete the old avatar here
                             $old_avatar_path = $current_user->avatar;
                             $current_user->avatar = $path;
                             if (file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $old_avatar_path)) {
                                 @unlink(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $old_avatar_path);
                             }
                             //Delete old file Sizes
                             $sizes = AvatarSize::getSizes();
                             foreach ($sizes as $size) {
                                 if (file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . $size['id'] . DIRECTORY_SEPARATOR . $old_avatar_path)) {
                                     @unlink(AVATAR_FOLDER . DIRECTORY_SEPARATOR . $size['id'] . DIRECTORY_SEPARATOR . $old_avatar_path);
                                 }
                             }
                         } else {
                             //$current_user
                             $current_user->avatar = $path;
                         }
                         $current_user->save();
                     }
                 } else {
                     throw new CHttpException('503', 'Error while uploading!');
                 }
             }
         }
         $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model));
     } else {
         echo '';
     }
 }
Example #28
0
 public function up()
 {
     CFileHelper::removeDirectory(Yii::app()->basePath . "/components/dashboard/");
     CFileHelper::removeDirectory(Yii::app()->basePath . "/../update/");
     CFileHelper::removeDirectory(Yii::app()->basePath . "/../assets/lib/chosen/");
     $companys = Company::model()->findAll();
     foreach ($companys as $company) {
         $this->alterColumn($company->prefix . 'itemCategories', "id", 'INT(11) NOT NULL AUTO_INCREMENT');
     }
 }
Example #29
0
 public function testSetGroupRecursive()
 {
     $cf = $this->cf;
     $cf->createDir();
     $cf_sub = CFileHelper::get($cf->getRealPath() . '/' . uniqid('sub'));
     $cf_sub->create();
     $group_name = $cf->getGroup();
     $this->assertNotEquals($cf->setGroup($group_name, True), False);
     $cf_sub->delete();
 }
Example #30
0
 /**
  * @param string $fileName
  * @return string
  */
 public static function getExtensionByMimeType($fileName)
 {
     $mimeTypes = (require Yii::getPathOfAlias('system.utils.mimeTypes') . '.php');
     $unsetArray = array('jpe', 'jpeg');
     foreach ($unsetArray as $key) {
         unset($mimeTypes[$key]);
     }
     $mimeType = CFileHelper::getMimeType($fileName);
     return (string) array_search($mimeType, $mimeTypes);
 }