コード例 #1
0
ファイル: ImageUtils.php プロジェクト: swayok/utils
 /**
  * Save uploaded image ($fileInfo) and create several resized versions ($resizeProfiles)
  * @param array $uploadedFileInfo - data from $_FILES
  * @param string $imagesPath - folder to save images in
  * @param string $baseFileNameWithoutExtension - base file name (used as prefix for resized file name)
  * @param ImageVersionConfig[] $imageVersionsConfigs - set of resize settings
  * @return array - false: file's content type not supported | true: saved & resized
  * @throws ImageUtilsException
  */
 public static function resize(array $uploadedFileInfo, $imagesPath, $baseFileNameWithoutExtension, array $imageVersionsConfigs)
 {
     $contentType = self::getContentTypeForUploadedFile($uploadedFileInfo);
     if (!self::isContentTypeSupported($contentType) || empty($imagesPath) || empty($baseFileNameWithoutExtension)) {
         throw new ImageUtilsException('Uploaded image type is not supported', 403);
     }
     if (is_dir($imagesPath)) {
         self::deleteExistingFiles($imagesPath, self::getFileNamesRegexp($baseFileNameWithoutExtension));
     } else {
         Folder::add($imagesPath, 0777);
     }
     // save original file (limited by w and h)
     if (empty($imageVersionsConfigs[ImageVersionConfig::SOURCE_VERSION_NAME])) {
         $originalFileResizeConfig = self::getDefaultOriginalFileVersionConfig();
     } else {
         $originalFileResizeConfig = $imageVersionsConfigs[ImageVersionConfig::SOURCE_VERSION_NAME];
     }
     $originalFileName = $baseFileNameWithoutExtension . self::applyResize($uploadedFileInfo['tmp_name'], $imagesPath . $baseFileNameWithoutExtension, $originalFileResizeConfig, $contentType);
     @File::remove($uploadedFileInfo['tmp_name']);
     //< remove temp file and use original file
     $filesNames = array(ImageVersionConfig::SOURCE_VERSION_NAME => $originalFileName);
     // save other file versions
     foreach ($imageVersionsConfigs as $versionName => $resizeSettings) {
         if ($versionName !== ImageVersionConfig::SOURCE_VERSION_NAME) {
             $newFileName = $baseFileNameWithoutExtension . $resizeSettings->getFileNameSuffix($versionName);
             $ext = self::applyResize($imagesPath . $originalFileName, $imagesPath . $newFileName, $resizeSettings, $contentType);
             $filesNames[$versionName] = $newFileName . $ext;
         }
     }
     return $filesNames;
 }
コード例 #2
0
ファイル: CmfAdminsTable.php プロジェクト: swayok/PeskyCMF
 public function fire()
 {
     $folder = Folder::load(database_path('/migrations'), true, 0755);
     $dontRenderTrigger = !!$this->input->getOption('without-trigger');
     if (!$dontRenderTrigger) {
         File::load($folder->pwd() . '/' . date('Y_m_d_His', time()) . '_create_timestsmp_renew_trigger_function.php', true, 0755, 0644)->write(view('cmf::install.db.create_timestsmp_renew_trigger_function_migration')->render());
     }
     File::load($folder->pwd() . '/' . date('Y_m_d_His', time() + 1) . '_create_admins_table.php', true, 0755, 0644)->write(view('cmf::install.db.create_admins_table_migration', ['withoutTrigger' => $dontRenderTrigger])->render());
     $this->line('Done');
     $this->line('Run [artisan migrate] (and [composer dump-autoload] if migration classes not found)');
 }
コード例 #3
0
ファイル: MakeMigration.php プロジェクト: magicians/PeskyCMF
 protected function getFilePath($name, $forSqlFile = false, $forRollbackSqlFile = false)
 {
     $basePath = preg_replace('%[/\\\\]%', DIRECTORY_SEPARATOR, parent::getMigrationPath()) . DIRECTORY_SEPARATOR;
     if ($forSqlFile) {
         $basePath .= $this->sqlSubdir . DIRECTORY_SEPARATOR;
         if ($forRollbackSqlFile) {
             $basePath .= $this->sqlRollbackSubdir . DIRECTORY_SEPARATOR;
         }
     }
     if (!Folder::exist($basePath)) {
         Folder::add($basePath, 0775);
     }
     return $basePath . date('Y_m_d_His') . '_' . $name . ($forSqlFile ? '.sql' : '.php');
 }
コード例 #4
0
ファイル: CmfInstall.php プロジェクト: swayok/PeskyCMF
 public function fire()
 {
     $appSubfolder = ucfirst(trim(trim($this->input->getArgument('app_subfolder')), '/\\'));
     $lowercasedSubfolder = snake_case($appSubfolder);
     $folderPath = app_path('/' . $appSubfolder);
     if (Folder::exist($folderPath)) {
         $this->line('Terminated. Folder [' . $folderPath . '] already exist');
     }
     $folder = Folder::load($folderPath, true, 0755);
     $dataForViews = ['sectionName' => $appSubfolder, 'urlPrefix' => trim(trim($this->input->getArgument('url_prefix'), '/\\')), 'dbClassesAppSubfolder' => $this->input->getArgument('database_classes_app_subfolder')];
     // create site loader
     $file = File::load($folder->pwd() . '/' . $appSubfolder . 'SiteLoader.php', true, 0755, 0644);
     $file->write(view('cmf::install.cmf_site_loader', $dataForViews)->render());
     // copy configs
     $subfolder = Folder::load($folder->pwd() . '/Config', true, 0755);
     $file = File::load($subfolder->pwd() . '/' . $appSubfolder . 'Config.php', true, 0755, 0644);
     $file->write(view('cmf::install.cmf_config', $dataForViews)->render());
     $file = File::load($subfolder->pwd() . '/' . $lowercasedSubfolder . '.routes.php', true, 0755, 0644);
     $file->write(view('cmf::install.cmf_routes', $dataForViews)->render());
     // copy pages controller
     $subfolder = Folder::load($folder->pwd() . '/Http/Controllers', true, 0755);
     $file = File::load($subfolder->pwd() . '/PagesController.php', true, 0755, 0644);
     $file->write(view('cmf::install.pages_controller', $dataForViews)->render());
     // create middleware folder
     File::load($folder->pwd() . '/Http/Middleware/empty', true, 0755, 0644);
     // make folder in resources
     File::load(resource_path('/views/' . $lowercasedSubfolder . '/empty'), true, 0755, 0644);
     if (!$this->input->getOption('no-db-classes')) {
         // copy base db classes
         $dbFolder = Folder::load(app_path('/' . $this->input->getArgument('database_classes_app_subfolder')), true, 0755);
         $file = File::load($dbFolder->pwd() . '/BaseDbModel.php', true, 0755, 0644);
         $file->write(view('cmf::install.db.base_db_model')->render());
         $file = File::load($dbFolder->pwd() . '/BaseDbObject.php', true, 0755, 0644);
         $file->write(view('cmf::install.db.base_db_object')->render());
         // copy admin table classes
         $subfolder = Folder::load($dbFolder->pwd() . '/Admin', true, 0755);
         $file = File::load($subfolder->pwd() . '/Admin.php', true, 0755, 0644);
         $file->write(view('cmf::install.db.admin_object')->render());
         $file = File::load($subfolder->pwd() . '/AdminModel.php', true, 0755, 0644);
         $file->write(view('cmf::install.db.admin_model')->render());
         $file = File::load($subfolder->pwd() . '/AdminTableConfig.php', true, 0755, 0644);
         $file->write(view('cmf::install.db.admin_table_config')->render());
         $file = File::load($subfolder->pwd() . '/AdminScaffoldConfig.php', true, 0755, 0644);
         $file->write(view('cmf::install.db.admin_scaffold_config')->render());
     }
     $this->line('Done');
 }
コード例 #5
0
ファイル: Folder.php プロジェクト: swayok/utils
 /**
  * Get the real path (taking ".." and such into account)
  *
  * @param string $path Path to resolve
  * @return string The resolved path
  * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::realpath
  */
 public function realpath($path)
 {
     $path = str_replace('/', DIRECTORY_SEPARATOR, trim($path));
     if (strpos($path, '..') === false) {
         if (!Folder::isAbsolute($path)) {
             $path = Folder::addPathElement($this->path, $path);
         }
         return $path;
     }
     $parts = explode(DIRECTORY_SEPARATOR, $path);
     $newparts = array();
     $newpath = '';
     if ($path[0] === DIRECTORY_SEPARATOR) {
         $newpath = DIRECTORY_SEPARATOR;
     }
     while (($part = array_shift($parts)) !== null) {
         if ($part === '.' || $part === '') {
             continue;
         }
         if ($part === '..') {
             if (!empty($newparts)) {
                 array_pop($newparts);
                 continue;
             }
             return false;
         }
         $newparts[] = $part;
     }
     $newpath .= implode(DIRECTORY_SEPARATOR, $newparts);
     return Folder::slashTerm($newpath);
 }
コード例 #6
0
ファイル: MakeDbClasses.php プロジェクト: swayok/PeskyCMF
 protected function preapareAndGetDataForViews()
 {
     $tableName = $this->argument('table_name');
     $modelClass = call_user_func([$this->modelParentClass, 'getFullModelClassByTableName'], $tableName);
     $folder = $this->getFolderAndValidate($tableName, $modelClass);
     if (empty($folder)) {
         return false;
     }
     $tableSchema = $this->getDbSchema();
     $columns = $this->getColumns($tableName, $tableSchema);
     if (empty($columns)) {
         return false;
     }
     $dataForViews = ['folder' => $folder, 'table' => $tableName, 'schema' => $tableSchema, 'columns' => $columns, 'modelParentClass' => $this->modelParentClass, 'objectParentClass' => $this->objectParentClass, 'tableConfigParentClass' => $this->tableConfigParentClass, 'scaffoldConfigParentClass' => $this->scaffoldConfigParentClass, 'modelClassName' => call_user_func([$this->modelParentClass, 'getModelNameByTableName'], $tableName), 'objectClassName' => call_user_func([$this->modelParentClass, 'getObjectNameByTableName'], $tableName), 'tableConfigClassName' => call_user_func([$this->modelParentClass, 'getTableConfigNameByTableName'], $tableName), 'scaffoldConfigClassName' => CmfConfig::getInstance()->getScaffoldConfigNameByTableName($tableName), 'traitsForTableConfig' => $this->getTraitsForTableConfig()];
     $dataForViews['modelAlias'] = $dataForViews['objectClassName'];
     $dataForViews['namespace'] = call_user_func([$this->modelParentClass, 'getRootNamespace']) . '\\' . $dataForViews['objectClassName'];
     $dataForViews['files']['model'] = $folder . DIRECTORY_SEPARATOR . $dataForViews['modelClassName'] . '.php';
     $dataForViews['files']['object'] = $folder . DIRECTORY_SEPARATOR . $dataForViews['objectClassName'] . '.php';
     $dataForViews['files']['table_config'] = $folder . DIRECTORY_SEPARATOR . $dataForViews['tableConfigClassName'] . '.php';
     $dataForViews['files']['scaffold_config'] = $folder . DIRECTORY_SEPARATOR . $dataForViews['scaffoldConfigClassName'] . '.php';
     Folder::load($folder, true, 0775);
     return $dataForViews;
 }