create() public method

Alternative for make
public create ( boolean $recursive = true ) : boolean
$recursive boolean
return boolean
Beispiel #1
0
 /**
  * Initialisation du cache
  */
 function __construct()
 {
     $this->folder = AdminServConfig::$PATH_RESOURCES . 'cache/';
     if (!file_exists($this->folder)) {
         Folder::create($this->folder);
     }
 }
 public function newFile($name, $contents)
 {
     $file = new File($this->t, $name);
     $path = new Folder($file->getPath());
     $path->exists() || $path->create();
     $file->out()->write($contents);
 }
Beispiel #3
0
 /**
  * add shop to folder
  * 
  */
 function addShopToFolder()
 {
     $name = @$this->request->data['name'];
     $shop_id = @$this->request->data['shop_id'];
     if (!$shop_id || !$name) {
         return $this->responseng('faild to add shop.');
     }
     $dataFolder = array("user_id" => $this->user_id, "name" => $name, "type_folder" => intval(@$this->request->data['type_folder']));
     $ret = $this->FolderUser->save($dataFolder);
     $folder_id_old = @$this->request->data["older_folder_id"];
     $datashopFolder = array("folder_id" => $ret["FolderUser"]["id"], "shop_id" => $shop_id, "rank" => 1, "status" => NO_MY_FOLDER);
     $result = $this->FolderShop->save($datashopFolder);
     App::uses('Folder', 'Utility');
     $folder = new Folder();
     if (!empty($folder_id_old)) {
         $oldFolder = $this->FolderUser->findById($folder_id_old);
         $newFolder = $ret;
         $path = WWW_ROOT . 'shops' . DS . $oldFolder["FolderUser"]["user_id"] . DS . $oldFolder["FolderUser"]["id"] . DS . $shop_id;
         $newPath = WWW_ROOT . 'shops' . DS . $newFolder["FolderUser"]["user_id"] . DS . $newFolder["FolderUser"]["id"] . DS . $result["FolderShop"]["shop_id"];
         if (is_dir($path)) {
             if (!is_dir($newPath)) {
                 $folder->create($newPath);
             }
             $folder->copy(array('to' => $newPath, 'from' => $path, 'mode' => 0777));
         }
     }
     if ($result) {
         return $this->responseOk();
     }
     return $this->responseng('can not save data');
 }
Beispiel #4
0
 public function upload(Model $Model, $arquivo = array(), $altura = 800, $largura = 600, $pasta = null, $nome_arquivo)
 {
     // App::uses('Vendor', 'wideimage');
     App::import('Vendor', 'WideImage', array('file' => 'WideImage' . DS . 'WideImage.php'));
     App::uses('Folder', 'Utility');
     $ext = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/x-jps', 'image/png', 'image/gif');
     if ($arquivo['error'] != 0 || $arquivo['size'] == 0) {
         return false;
     }
     $img = WideImage::load($arquivo['tmp_name']);
     $folder = new Folder();
     $pathinfo = pathinfo($arquivo['name']);
     if ($folder->create(WWW_ROOT . 'img' . DS . $pasta . DS)) {
         //se conseguiu criar o diretório eu dou permissão
         $folder->chmod(WWW_ROOT . 'img' . DS . $pasta . DS, 0755, true);
     } else {
         return false;
     }
     $pathinfo['filename'] = strtolower(Inflector::slug($pathinfo['filename'], '-'));
     $arquivo['name'] = $nome_arquivo . '.' . $pathinfo['extension'];
     $img->saveToFile(WWW_ROOT . 'img' . DS . $pasta . DS . 'original_' . $arquivo['name']);
     $img = $img->resize($largura, $altura, 'fill');
     $img->saveToFile(WWW_ROOT . 'img' . DS . $pasta . DS . $arquivo['name']);
     // debug(WWW_ROOT.'img'.DS.$pasta.DS.$arquivo['name']); die;
     return $arquivo['name'];
 }
Beispiel #5
0
 function find($conditions = null, $fields = array(), $order = null, $recursive = null)
 {
     if ($conditions != 'range') {
         return parent::find($conditions, $fields, $order, $recursive);
     }
     $file = Set::extract($fields, 'file');
     if (empty($file)) {
         $file = ROOT . DS . APP_DIR . DS . 'plugins/mobileip/config/mobile_ips.yml';
     }
     if (!file_exists($file)) {
         return false;
     }
     $cacheDir = $this->getCacheDir();
     $folder = new Folder($cacheDir);
     $folder->create($cacheDir, 0777);
     $cacheFile = $this->getCacheFile();
     if (file_exists($cacheFile) && $this->_getLastModified($file) <= filemtime($cacheFile)) {
         return include $cacheFile;
     }
     $mobile_ips =& Spyc::YAMLLoad($file);
     if (!is_array($mobile_ips)) {
         return false;
     }
     $data = $this->_get_ranges($mobile_ips);
     $file = new File($cacheFile, true);
     $file->write($data);
     $file->close();
     return include $cacheFile;
 }
Beispiel #6
0
 function save_asset($file)
 {
     $result['status'] = false;
     $this->log('file info: ', 7);
     $this->log($file, 7);
     $info = $this->fileinfo($file);
     if (empty($info['content_type']) || !in_array($info['content_type'], $this->options['valid_types'])) {
         $this->log('not saving, invalid filetype...', 7);
         $result['message'] = 'Invalid filetype';
         return $result;
     }
     if ($this->save($info)) {
         $this->log('saved on line 52', 7);
         $folder = new Folder();
         if ($folder->create($this->path() . $this->id . DS . 'original')) {
             move_uploaded_file($file['tmp_name'], $this->path() . $this->id . DS . 'original' . DS . $info['filename']);
             if (in_array($info['content_type'], $this->options['image_types'])) {
                 if ($this->create_folders($this->id) && $this->process_styles($this->id, $info)) {
                     $result['message'] = 'files resized and saved';
                     $result['status'] = true;
                 }
             }
         } else {
             $result['message'] = "There was a problem creating a folder, check your permissions";
             return $result;
         }
     }
     return $result;
 }
Beispiel #7
0
 public function __construct()
 {
     $this->path = STORAGE_DIR . 'Cache/';
     if (!is_dir($this->path)) {
         \Folder::create($this->path, 0755);
     }
     \Support::writable($this->path);
 }
 public function admin_export($id = null)
 {
     if (!$id) {
         $this->notice('invalid');
     }
     $this->Template->recursive = -1;
     $template = $this->Template->read(array('name', 'description', 'author', 'header', 'footer'), $id);
     if (empty($template)) {
         $this->notice('invalid');
     }
     $pattern = "/src=[\\\"']?([^\\\"']?.*(png|jpg|gif|jpeg))[\\\"']?/i";
     preg_match_all($pattern, $template['Template']['header'], $images);
     $path = TMP . 'cache' . DS . 'newsletter' . DS . 'template' . DS . $template['Template']['name'];
     $Folder = new Folder($path, 0777);
     $slash = $Folder->correctSlashFor($path);
     App::import('File');
     App::import('Folder');
     $File = new File($path . DS . 'template.xml', true, 0777);
     $imageFiles = array();
     if (!empty($images[1])) {
         foreach ($images[1] as $img) {
             $img = str_replace('/', $slash, $img);
             $img = str_replace('\\', $slash . $slash, $img);
             $imageFiles[] = $img;
             if (is_file(APP . 'webroot' . $img)) {
                 $Folder->create(dirname($path . $img), 0777);
                 $File->path = APP . 'webroot' . $img;
                 $File->copy(dirname($path . $img) . DS . basename($img));
             }
         }
     }
     $xml['template']['name'] = 'Infinitas Newsletter Template';
     $xml['template']['generator'] = 'Infinitas Template Generator';
     $xml['template']['version'] = $this->version;
     $xml['template']['template'] = $template['Template']['name'];
     $xml['template']['description'] = $template['Template']['description'];
     $xml['template']['author'] = $template['Template']['author'];
     $xml['data']['header'] = $template['Template']['header'];
     $xml['data']['footer'] = $template['Template']['footer'];
     $xml['files']['images'] = $imageFiles;
     App::Import('Helper', 'Xml');
     $Xml = new XmlHelper();
     $File->path = $path . DS . 'template.xml';
     $File->write($Xml->serialize($xml));
     App::import('Vendor', 'Zip', array('file' => 'zip.php'));
     $Zip = new CreateZipFile();
     $Zip->zipDirectory($path, null);
     $File = new File($path . DS . 'template.zip', true, 0777);
     $File->write($Zip->getZippedfile());
     $this->view = 'Media';
     $params = array('id' => 'template.zip', 'name' => $template['Template']['name'], 'download' => true, 'extension' => 'zip', 'path' => $path . DS);
     $this->set($params);
     $Folder = new Folder($path);
     $Folder->read();
     $Folder->delete($path);
 }
Beispiel #9
0
 /**
  * Extract an archive file to a directory.
  *
  * @param   string  $archivename  The name of the archive file
  * @param   string  $extractdir   Directory to unpack into
  *
  * @return  boolean  True for success
  *
  * @since   1.0
  * @throws  \InvalidArgumentException
  */
 public function extract($archivename, $extractdir)
 {
     $ext = pathinfo($archivename, PATHINFO_EXTENSION);
     $path = pathinfo($archivename, PATHINFO_DIRNAME);
     $filename = pathinfo($archivename, PATHINFO_FILENAME);
     switch ($ext) {
         case 'zip':
             $result = $this->getAdapter('zip')->extract($archivename, $extractdir);
             break;
         case 'tar':
             $result = $this->getAdapter('tar')->extract($archivename, $extractdir);
             break;
         case 'tgz':
         case 'gz':
         case 'gzip':
             // This may just be an individual file (e.g. sql script)
             $tmpfname = $this->options['tmp_path'] . '/' . uniqid('gzip');
             $gzresult = $this->getAdapter('gzip')->extract($archivename, $tmpfname);
             if ($gzresult instanceof \Exception) {
                 @unlink($tmpfname);
                 return false;
             }
             if ($ext === 'tgz' || stripos($filename, '.tar') !== false) {
                 $result = $this->getAdapter('tar')->extract($tmpfname, $extractdir);
             } else {
                 Folder::create($path);
                 $result = File::copy($tmpfname, $extractdir, null, 0);
             }
             @unlink($tmpfname);
             break;
         case 'tbz2':
         case 'bz2':
         case 'bzip2':
             // This may just be an individual file (e.g. sql script)
             $tmpfname = $this->options['tmp_path'] . '/' . uniqid('bzip2');
             $bzresult = $this->getAdapter('bzip2')->extract($archivename, $tmpfname);
             if ($bzresult instanceof \Exception) {
                 @unlink($tmpfname);
                 return false;
             }
             if ($ext === 'tbz2' || stripos($filename, '.tar') !== false) {
                 $result = $this->getAdapter('tar')->extract($tmpfname, $extractdir);
             } else {
                 Folder::create($path);
                 $result = File::copy($tmpfname, $extractdir, null, 0);
             }
             @unlink($tmpfname);
             break;
         default:
             throw new Exception(sprintf('Unknown archive type: %s', $ext));
     }
     if (!$result || $result instanceof Exception) {
         return false;
     }
     return true;
 }
Beispiel #10
0
 /**
  * Create temporary file for upload test.
  *
  * @param string $fileName Temporary file name
  * @return void
  */
 public function createTmpFile($fileName)
 {
     //アップロードテストのためのテンポラリファイル生成
     $folder = new Folder();
     $folder->create(TMP . 'tests' . DS . 'files' . DS . 'tmp');
     $file = new File(APP . 'Plugin' . DS . 'Files' . DS . 'Test' . DS . 'Fixture' . DS . $fileName);
     $file->copy(TMP . 'tests' . DS . 'files' . DS . 'tmp' . DS . $fileName);
     $file->close();
     unset($folder, $file);
 }
Beispiel #11
0
 function makeDir($dir)
 {
     if (!is_dir($dir)) {
         $parent_perms = $this->getPerms(dirname($dir));
         $f = new Folder();
         if ($f->create($dir, octdec($parent_perms))) {
             return true;
         } else {
             if ($parent_perms == '0755') {
                 if ($f->chmod($dir, 0777) && $f->create($dir)) {
                     return true;
                 }
             }
         }
         return false;
     } else {
         return true;
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->console = new ConsoleOutput();
     $this->temp_dir = sys_get_temp_dir() . '/FilesystemDatasourceWorkdir/';
     $folder = new Folder();
     $folder->create($this->temp_dir);
     $this->console->write('<info>Using temporary dir: "' . $this->temp_dir . '"</info>');
     $config = array('baseDir' => $this->temp_dir);
     $this->datasource = new FilesystemSource($config);
 }
Beispiel #13
0
 public function __construct()
 {
     // Dil doyalarının yer alacağı dizinin belirtiliyor.
     $this->appdir = STORAGE_DIR . 'MultiLanguage/';
     // Eğer dizin mevcut değilse oluşturulması sağlanıyor.
     if (!is_dir($this->appdir)) {
         Folder::create($this->appdir, 0777);
     }
     // Aktif dil dosyasının yolu belirtiliyor.
     $this->lang = $this->appdir . getLang() . $this->extension;
 }
 /**
  * Apply the cache settings.
  *
  * @param array $config
  */
 public function __construct($config = array())
 {
     parent::__construct($config);
     if (Cache::config('feeds') === false) {
         $cachePath = CACHE . 'feeds' . DS;
         if (!file_exists($cachePath)) {
             $folder = new Folder();
             $folder->create($cachePath, 0777);
         }
         Cache::config('feeds', array('engine' => 'File', 'serialize' => true, 'prefix' => 'feed_', 'path' => $cachePath, 'duration' => '+1 day'));
     }
 }
Beispiel #15
0
 public function __construct( $request = NULL, $response = NULL ) {
     Configure::load('report_manager.bootstrap');        
     $reportPath = Configure::read('ReportManager.reportPath');
     if ( !isset($reportPath) )
         $reportPath = 'tmp'.DS.'reports'.DS;
     $this->path = $reportPath;
     if(!is_dir(APP.$this->path)) {
         $folder = new Folder();
         $folder->create(APP.$this->path);
     }
     parent::__construct($request,$response);
 }    
 function createPath($path = null)
 {
     $path_config = explode('/', $path);
     $count = count($path_config);
     $dir = WWW_ROOT . '/';
     foreach ($path_config as $f) {
         $count--;
         $dir .= $f;
         $folder = new Folder();
         $folder->create($dir);
         $dir .= '/';
     }
     return str_replace(WWW_ROOT, '', $dir);
 }
 /**
  * createTemporaryFolder
  *
  * @param string $folderName temporary middle name
  * @return Folder
  */
 public function createTemporaryFolder($controller, $folderName = 'download')
 {
     $folder = new Folder();
     if (!$folder) {
         throw new Exception(__d('net_commons', 'can not create folder'));
     }
     $folderName = TMP . $controller->plugin . DS . $folderName . DS . microtime(true);
     $folder->create($folderName);
     if (!$folder->cd($folderName)) {
         throw new Exception(__d('net_commons', 'can not change folder'));
     }
     $this->_workingFolder = $folder;
     return $folder;
 }
Beispiel #18
0
 /**
  * Edit method
  * 
  * Edits the view file for the specified params
  * 
  * @param string $plugin
  * @param string $controller
  * @param string $action
  */
 public function edit($plugin, $controller = null, $action = null)
 {
     App::uses('Folder', 'Utility');
     App::uses('File', 'Utility');
     $plugin = Inflector::camelize($plugin);
     if (!in_array($plugin, CakePlugin::loaded())) {
         $this->Session->setFlash(__('This file cannot be customized'));
         $this->redirect($this->referer());
     }
     $controller = Inflector::camelize($controller);
     $paths = App::path('View', $plugin);
     $action = !empty($this->request->params['named']['view']) ? $this->request->params['named']['view'] : $action;
     if ($this->request->is('post')) {
         // otherwise create the folder and write the file
         if (!file_exists($paths[0] . $controller)) {
             // create the folder first
             $folder = new Folder();
             if ($folder->create($paths[0] . $controller)) {
                 // Successfully created the nested folders
             } else {
                 throw new Exception(__('Could not create folder, check permissions'));
             }
         }
         $file = new File($paths[0] . $controller . DS . $action . '.ctp');
         if ($file->write($this->request->data['ViewFile']['contents'])) {
             // created file
             $this->Session->setFlash(__('%s Updated', $controller . DS . $action . '.ctp'));
             $this->redirect($this->referer());
         } else {
             throw new Exception(__('File save failed.'));
         }
     }
     // view Vars
     foreach ($paths as $path) {
         if (file_exists($path . $controller . DS . $action . '.ctp')) {
             $file = new File($path . $controller . DS . $action . '.ctp');
             $contents = $file->read();
             break;
         }
     }
     if (!empty($contents)) {
         $this->set(compact('contents'));
         $this->set('saveRedirect', '/' . implode('/', func_get_args()));
         $this->set('page_title_for_layout', __('Edit <small>%s</small>', $controller . DS . $action . '.ctp'));
     } else {
         $this->Session->setFlash(__('No view file found.'));
         $this->redirect($this->referer());
     }
 }
 /**
  * Processes the image according to $actions, saves and displays the generated thumbnail
  *
  * @param string $srcPath Absolute path to the source image
  * @param string $dstPath Absolute path to the destination image
  * @param string $fileType The fileType of the destination image (currently jpg, png or gif)
  * @param array $actions Array of the actions with their parameters as described in the PHPThumb documentation: http://github.com/masterexploder/PHPThumb/wiki/GD-API
  */
 function processImage($srcPath, $dstPath, $fileType, $actions)
 {
     $thumb = PhpThumbFactory::create($srcPath, Configure::read('ImageEditor.PHPThumb'));
     // Going through all the actions
     foreach ($actions as $action => $params) {
         if (is_array($params)) {
             $thumb->{$action}(@$params[0], @$params[1], @$params[3], @$params[4]);
         } else {
             $thumb->{$action}(@$params);
         }
     }
     // Creating the folder to store the thumbs
     Folder::create(dirname($dstPath), 0755);
     $thumb->save($dstPath, strtoupper($fileType));
     $thumb->show();
 }
Beispiel #20
0
 /**
  * beforeSave callback
  * 
  */
 public function beforeSave()
 {
     // Using the Folder utility because I can
     App::uses('Folder', 'Utility');
     $folder = new Folder();
     // Create a folder for the item: app/Attachments/$item_id if it doesn't exist
     if (!$folder->create(APP . 'Attachments' . DS . $this->data['Attachment']['item_id'])) {
         // Failed to create the folder! I told them we didn't have enough space to mirror the entire Ubuntu repo...
         return false;
     }
     // Move uploaded file from tmp to app/Attachemnts/$item_id folder
     if (!move_uploaded_file($this->data['Attachment']['file']['tmp_name'], APP . 'Attachments' . DS . $this->data['Attachment']['item_id'] . DS . $this->data['Attachment']['name'])) {
         // Failed to move the file!
         return false;
     }
     return true;
 }
Beispiel #21
0
 /**
  *	__construct
  *	@param string $path
  *	@param BOOL $create
  *	@param string $mode
  */
 public function __construct($path, $create = null, $mode = null)
 {
     if (!empty($path)) {
         if (is_array($path)) {
             $path = call_user_func_array("static::buildPath", $path);
         }
         if (!is_dir($path)) {
             $this->folder = Folder::create(dirname($path), $create, $mode);
             $this->name = basename($path);
             $this->path = $this->folder->path . $this->name;
             if ($create && !$this->exists()) {
                 $this->create();
             }
             $this->info();
         }
     }
 }
Beispiel #22
0
 public function beforeSave(&$model)
 {
     if (!empty($model->data[$model->alias]['src'])) {
         if ($model->data[$model->alias]['src'] != '' && !empty($model->data[$model->alias]['src']) && !is_array($model->data[$model->alias]['src']) && ($model->data[$model->alias]['type'] == 'embed/youtube' || $model->data[$model->alias]['type'] == 'embed/vimeo')) {
             //Get the file
             $content = file_get_contents($model->data[$model->alias]['src']);
             $name = 'embed_' . preg_replace('/[^a-z0-9_.]/i', '', $model->data[$model->alias]['name'] . '.jpg');
             $folder = new Folder();
             $path = WWW_ROOT . 'files' . DS . date("Y") . DS . date("m");
             $folder->create($path, false);
             $model->data[$model->alias]['src'] = 'files' . DS . date("Y") . DS . date("m") . DS . $name;
             //Store in the filesystem.
             $fp = fopen($path . DS . $name, "w");
             fwrite($fp, $content);
             fclose($fp);
             $model->data[$model->alias]['size'] = filesize($path . DS . $name);
         }
     }
     return true;
 }
 /**
  * Execute action
  *
  * @return  int
  */
 public function perform()
 {
     $this->archive->open(ARCHIVE_READ);
     $args = $this->getArguments();
     while ($entry = $this->archive->getEntry()) {
         if (!$this->_filter($entry, $args)) {
             continue;
         }
         $f = new File($entry);
         $data = $this->archive->extract($entry);
         if (!($this->options & Options::SIMULATE)) {
             // Create folder on demand. Note that inside a XAR, the directory
             // separator is *ALWAYS* a forward slash, so we need to change
             // it to whatever the OS we're currently running on uses.
             $dir = new Folder(str_replace('/', DIRECTORY_SEPARATOR, dirname($entry)));
             if (!$dir->exists()) {
                 $dir->create();
             }
             FileUtil::setContents($f, $data);
         }
         $this->options & Options::VERBOSE && $this->out->writeLinef('%10s %s', number_format(strlen($data), 0, FALSE, '.'), $entry);
     }
     $this->archive->close();
 }
Beispiel #24
0
 /**
  * Bake the plugin, create directories and files
  *
  * @params $plugin name of the plugin in CamelCased format
  * @access public
  * @return bool
  */
 function bake($plugin)
 {
     $pluginPath = Inflector::underscore($plugin);
     $this->hr();
     $this->out("Plugin Name: {$plugin}");
     $this->out("Plugin Directory: {$this->path}{$pluginPath}");
     $this->hr();
     $looksGood = $this->in('Look okay?', array('y', 'n', 'q'), 'y');
     if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
         $verbose = $this->in(__('Do you want verbose output?', true), array('y', 'n'), 'n');
         $Folder = new Folder($this->path . $pluginPath);
         $directories = array('models' . DS . 'behaviors', 'controllers' . DS . 'components', 'views' . DS . 'helpers');
         foreach ($directories as $directory) {
             $Folder->create($this->path . $pluginPath . DS . $directory);
         }
         if (low($verbose) == 'y' || low($verbose) == 'yes') {
             foreach ($Folder->messages() as $message) {
                 $this->out($message);
             }
         }
         $errors = $Folder->errors();
         if (!empty($errors)) {
             return false;
         }
         $controllerFileName = $pluginPath . '_app_controller.php';
         $out = "<?php\n\n";
         $out .= "class {$plugin}AppController extends AppController {\n\n";
         $out .= "}\n\n";
         $out .= "?>";
         $this->createFile($this->path . $pluginPath . DS . $controllerFileName, $out);
         $modelFileName = $pluginPath . '_app_model.php';
         $out = "<?php\n\n";
         $out .= "class {$plugin}AppModel extends AppModel {\n\n";
         $out .= "}\n\n";
         $out .= "?>";
         $this->createFile($this->path . $pluginPath . DS . $modelFileName, $out);
         $this->hr();
         $this->out(sprintf(__("Created: %s in %s", true), $plugin, $this->path . $pluginPath));
         $this->hr();
     }
     return true;
 }
 /**
  * 利用可能なデータソースを取得する
  *
  * @return array
  * @access	protected
  */
 protected function _getDbSource()
 {
     /* DBソース取得 */
     $dbsource = array();
     $folder = new Folder();
     $pdoDrivers = PDO::getAvailableDrivers();
     /* MySQL利用可否 */
     if (in_array('mysql', $pdoDrivers)) {
         $dbsource['mysql'] = 'MySQL';
     }
     /* PostgreSQL利用可否 */
     if (in_array('pgsql', $pdoDrivers)) {
         $dbsource['postgres'] = 'PostgreSQL';
     }
     /* SQLite利用可否チェック */
     // windowsは一旦非サポート
     if (version_compare(preg_replace('/[a-z-]/', '', phpversion()), '5', '>=') && DS != '\\') {
         if (in_array('sqlite', $pdoDrivers)) {
             $dbFolderPath = APP . 'db' . DS . 'sqlite';
             if (is_writable(dirname($dbFolderPath)) && $folder->create($dbFolderPath, 0777)) {
                 $dbsource['sqlite'] = 'SQLite';
             }
         }
     }
     /* CSV利用可否 */
     /* $dbFolderPath = APP.'db'.DS.'csv';
     	  if(is_writable(dirname($dbFolderPath)) && $folder->create($dbFolderPath, 0777)){
     	  $dbsource['csv'] = 'CSV';
     	  } */
     return $dbsource;
 }
 /**
  * Bake the plugin, create directories and files
  *
  * @param string $plugin Name of the plugin in CamelCased format
  * @return bool
  */
 public function bake($plugin)
 {
     $pathOptions = App::path('plugins');
     if (count($pathOptions) > 1) {
         $this->findPath($pathOptions);
     }
     $this->hr();
     $this->out(__d('cake_console', "<info>Plugin Name:</info> %s", $plugin));
     $this->out(__d('cake_console', "<info>Plugin Directory:</info> %s", $this->path . $plugin));
     $this->hr();
     $looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n', 'q'), 'y');
     if (strtolower($looksGood) === 'y') {
         $Folder = new Folder($this->path . $plugin);
         $directories = array('Config' . DS . 'Schema', 'Model' . DS . 'Behavior', 'Model' . DS . 'Datasource', 'Console' . DS . 'Command' . DS . 'Task', 'Controller' . DS . 'Component', 'Lib', 'View' . DS . 'Helper', 'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component', 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper', 'Test' . DS . 'Case' . DS . 'Model' . DS . 'Behavior', 'Test' . DS . 'Fixture', 'Vendor', 'webroot');
         foreach ($directories as $directory) {
             $dirPath = $this->path . $plugin . DS . $directory;
             $Folder->create($dirPath);
             new File($dirPath . DS . 'empty', true);
         }
         foreach ($Folder->messages() as $message) {
             $this->out($message, 1, Shell::VERBOSE);
         }
         $errors = $Folder->errors();
         if (!empty($errors)) {
             foreach ($errors as $message) {
                 $this->error($message);
             }
             return false;
         }
         $controllerFileName = $plugin . 'AppController.php';
         $out = "<?php\n\n";
         $out .= "App::uses('AppController', 'Controller');\n\n";
         $out .= "class {$plugin}AppController extends AppController {\n\n";
         $out .= "}\n";
         $this->createFile($this->path . $plugin . DS . 'Controller' . DS . $controllerFileName, $out);
         $modelFileName = $plugin . 'AppModel.php';
         $out = "<?php\n\n";
         $out .= "App::uses('AppModel', 'Model');\n\n";
         $out .= "class {$plugin}AppModel extends AppModel {\n\n";
         $out .= "}\n";
         $this->createFile($this->path . $plugin . DS . 'Model' . DS . $modelFileName, $out);
         $this->_modifyBootstrap($plugin);
         $this->hr();
         $this->out(__d('cake_console', '<success>Created:</success> %s in %s', $plugin, $this->path . $plugin), 2);
     }
     return true;
 }
 /**
  * Creates thumbnail folders if they do not already exist
  *
  * @param string $dir Path to uploads
  * @param string $thumbDir Path to thumbnails
  * @param array $thumbsizes
  * @param integer $folderPermission octal value of created folder permission
  * @return void
  * @access protected
  */
 function _createFolders($dir, $thumbDir, $thumbsizes, $folderPermission)
 {
     if ($dir[0] !== '/') {
         $dir = WWW_ROOT . $dir;
     }
     $folder = new Folder();
     if (!$folder->cd($dir)) {
         $folder->create($dir, $folderPermission);
     }
     if (!$folder->cd($dir . DS . $thumbDir)) {
         $folder->create($dir . DS . $thumbDir, $folderPermission);
     }
     foreach ($thumbsizes as $thumbsize) {
         if ($thumbsize != 'normal' && !$folder->cd($dir . DS . $thumbDir . DS . $thumbsize)) {
             $folder->create($dir . DS . $thumbDir . DS . $thumbsize, $folderPermission);
         }
     }
 }
Beispiel #28
0
 /**
  * testFindRecursive method
  *
  * @return void
  */
 public function testFindRecursive()
 {
     $Folder = new Folder();
     $Folder->cd(CAKE);
     $result = $Folder->findRecursive('(config|paths)\\.php');
     $expected = array(CAKE . 'Config' . DS . 'config.php');
     $this->assertSame(array_diff($expected, $result), array());
     $this->assertSame(array_diff($expected, $result), array());
     $result = $Folder->findRecursive('(config|paths)\\.php', true);
     $expected = array(CAKE . 'Config' . DS . 'config.php');
     $this->assertSame($expected, $result);
     $Folder->cd(TMP);
     $Folder->create($Folder->pwd() . DS . 'testme');
     $Folder->cd('testme');
     $File = new File($Folder->pwd() . DS . 'paths.php');
     $File->create();
     $Folder->cd(TMP . 'sessions');
     $result = $Folder->findRecursive('paths\\.php');
     $expected = array();
     $this->assertSame($expected, $result);
     $Folder->cd(TMP . 'testme');
     $File = new File($Folder->pwd() . DS . 'my.php');
     $File->create();
     $Folder->cd($Folder->pwd() . '/../..');
     $result = $Folder->findRecursive('(paths|my)\\.php');
     $expected = array(TMP . 'testme' . DS . 'my.php', TMP . 'testme' . DS . 'paths.php');
     $this->assertSame(array_diff($expected, $result), array());
     $this->assertSame(array_diff($expected, $result), array());
     $result = $Folder->findRecursive('(paths|my)\\.php', true);
     $expected = array(TMP . 'testme' . DS . 'my.php', TMP . 'testme' . DS . 'paths.php');
     $this->assertSame($expected, $result);
     $Folder->cd(CAKE . 'Config');
     $Folder->cd(TMP);
     $Folder->delete($Folder->pwd() . DS . 'testme');
     $File->delete();
 }
 /**
  * Utility method to create a {@link FolderSecured} object and save to the test DB.
  * 
  * @param string $can
  * @param string $type
  * @param array $props
  * @return Folder
  */
 private function createSecuredFolder($can, $type, $props = array())
 {
     $folder = Folder::create();
     $folder->Secured = true;
     $folder->{$can} = $type;
     $folder->ParentID = 1;
     foreach ($props as $prop => $val) {
         $folder->{$prop} = $val;
     }
     $folder->write();
     return $folder;
 }
 /**
  * startup
  * 
  * @param string $pre actionのprefix
  * @param string $action action名
  * @param string $methods $Controller->methods の値
  * @param boolean $view viewファイルの作成を行うか
  * @param array $expected 期待値
  * @dataProvider startupDataProvider
  */
 public function testStartup($pre, $action, $methods, $view, $expected)
 {
     // 初期化
     $this->Controller->params['prefix'] = $pre;
     $this->Controller->action = $action;
     $this->Controller->methods = array($methods);
     $this->BcReplacePrefix->allowedPureActions = array('action');
     if ($view) {
         $this->Controller->name = 'Test';
         $FolderPath = ROOT . '/app/webroot/Test' . DS . $pre . DS;
         $filename = 'action.ctp';
         $Folder = new Folder();
         $Folder->create($FolderPath);
         touch($FolderPath . $filename);
     }
     // Initializes
     $this->BcReplacePrefix->initialize($this->Controller);
     // 実行
     $this->BcReplacePrefix->startup($this->Controller);
     if ($view) {
         $Folder->delete(ROOT . '/app/webroot/Test');
     }
     $this->assertEquals($expected[0], $this->Controller->action, 'startupが正しく動作していません');
     $this->assertEquals($expected[1], $this->Controller->layoutPath, 'startupが正しく動作していません');
     $this->assertEquals($expected[2], $this->Controller->subDir, 'startupが正しく動作していません');
 }