Exemple #1
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'];
 }
 /**
  * テーマをアップロードして適用する
  */
 public function admin_add()
 {
     $this->pageTitle = 'テーマアップロード';
     $this->subMenuElements = array('themes');
     if ($this->request->data) {
         if (empty($this->request->data['Theme']['file']['tmp_name'])) {
             $this->setMessage('ファイルのアップロードに失敗しました。', true);
         } else {
             $name = $this->request->data['Theme']['file']['name'];
             move_uploaded_file($this->request->data['Theme']['file']['tmp_name'], TMP . $name);
             exec('unzip -o ' . TMP . $name . ' -d ' . BASER_THEMES, $return);
             if (!empty($return[2])) {
                 $theme = str_replace('  inflating: ' . BASER_THEMES, '', $return[2]);
                 $theme = explode(DS, $theme);
                 $theme = $theme[0];
                 $themePath = BASER_THEMES . $theme;
                 $Folder = new Folder();
                 $Folder->chmod($themePath, 0777);
                 unlink(TMP . $name);
                 $this->_applyTheme($theme);
                 $this->redirect(array('action' => 'index'));
             } else {
                 $msg = 'アップロードしたZIPファイルの展開に失敗しました。';
                 exec('unzip 2>&1', $errs);
                 $msg .= '<br />' . implode('<br />', $errs);
                 $this->setMessage($msg, true);
             }
         }
     }
 }
 /**
  * Finish install, set .installed file on
  * module path
  * 
  * @param string $module
  * @return boolean
  */
 public function finishInstall($module)
 {
     $modulePath = CLOGGY_PATH_MODULE . $module . DS;
     $modulePathInstalled = $modulePath . '.installed';
     $folder = new Folder();
     $folder->chmod($modulePath, 0755, true);
     $file = new File($modulePathInstalled);
     return $file->create();
 }
 function setFolderPermissions($folder, $permission = '0755')
 {
     if (is_string($folder)) {
         $folder = array($folder);
     }
     App::import('core', 'Folder');
     $return = true;
     foreach ($folder as $dir) {
         $dir = APP . str_replace('/', DS, $dir);
         //$dir = new Folder($dir, $permission);
         $Folder = new Folder($dir);
         if (!$Folder->chmod($dir, $permission)) {
             $this->validationErrors['dir'][] = 'Attenzione: la directory ' . $dir . ' deve avere i permessi di scrittura';
             $return = false;
         }
     }
     return $return;
 }
Exemple #5
0
 /**
  * ZIP を展開する
  *
  * @param $source
  * @param $target
  * @return bool
  */
 public function extract($source, $target)
 {
     $this->error = null;
     $this->topArchiveName = null;
     if ($this->Zip) {
         $result = $this->_extractByPhpLib($source, $target);
     } else {
         $result = $this->_extractByCommand($source, $target);
     }
     if ($result) {
         $extractedPath = $target . $this->topArchiveName;
         $Folder = new Folder();
         $Folder->chmod($extractedPath, 0777);
         return true;
     } else {
         return false;
     }
 }
 /**
  * Checks that given project path does not already exist, and
  * finds the app directory in it. Then it calls bake() with that information.
  *
  * @param string $project Project path
  */
 public function execute()
 {
     $project = null;
     if (isset($this->args[0])) {
         $project = $this->args[0];
     }
     if ($project && isset($_SERVER['PWD'])) {
         $project = $_SERVER['PWD'] . DS . $project;
     }
     if (empty($this->params['skel'])) {
         $core = App::core('shells');
         $skelPath = dirname($core[0]) . DS . 'templates' . DS . 'skel';
         if (is_dir($skelPath) === true) {
             $this->params['skel'] = $skelPath;
         }
     }
     while (!$project) {
         $prompt = __("What is the full path for this app including the app directory name?\n Example:");
         $default = APP_PATH . 'myapp';
         $project = $this->in($prompt . $default, null, $default);
     }
     if ($project) {
         $response = false;
         while ($response == false && is_dir($project) === true && file_exists($project . 'config' . 'core.php')) {
             $prompt = __('<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
             $response = $this->in($prompt, array('y', 'n'), 'n');
             if (strtolower($response) === 'n') {
                 $response = $project = false;
             }
         }
     }
     $success = true;
     if ($this->bake($project)) {
         $path = Folder::slashTerm($project);
         if ($this->createHome($path)) {
             $this->out(__(' * Welcome page created'));
         } else {
             $this->err(__('The Welcome page was <error>NOT</error> created'));
             $success = false;
         }
         if ($this->securitySalt($path) === true) {
             $this->out(__(' * Random hash key created for \'Security.salt\''));
         } else {
             $this->err(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', CONFIGS . 'core.php'));
             $success = false;
         }
         if ($this->securityCipherSeed($path) === true) {
             $this->out(__(' * Random seed created for \'Security.cipherSeed\''));
         } else {
             $this->err(__('Unable to generate random seed for \'Security.cipherSeed\', you should change it in %s', CONFIGS . 'core.php'));
             $success = false;
         }
         if ($this->corePath($path) === true) {
             $this->out(__(' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', CAKE_CORE_INCLUDE_PATH));
             $this->out(__(' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/test.php', CAKE_CORE_INCLUDE_PATH));
             $this->out(__('   * <warning>Remember to check these value after moving to production server</warning>'));
         } else {
             $this->err(__('Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', $path . 'webroot' . DS . 'index.php'));
             $success = false;
         }
         if ($this->consolePath($path) === true) {
             $this->out(__(' * app/console/cake.php path set.'));
         } else {
             $this->err(__('Unable to set console path for app/console.'));
             $success = false;
         }
         $Folder = new Folder($path);
         if (!$Folder->chmod($path . 'tmp', 0777)) {
             $this->err(__('Could not set permissions on %s', $path . DS . 'tmp'));
             $this->out(__('chmod -R 0777 %s', $path . DS . 'tmp'));
             $success = false;
         }
         if ($success) {
             $this->out(__('<success>Project baked successfully!</success>'));
         } else {
             $this->out(__('Project baked but with <warning>some issues.</warning>.'));
         }
         return $path;
     }
 }
 /**
  * Looks for a skeleton template of a Cake application,
  * and if not found asks the user for a path. When there is a path
  * this method will make a deep copy of the skeleton to the project directory.
  * A default home page will be added, and the tmp file storage will be chmod'ed to 0777.
  *
  * @param string $path Project path
  * @access private
  */
 function __buildDirLayout($path)
 {
     $skel = $this->params['skel'];
     while ($skel == '') {
         $skel = $this->in("What is the path to the app directory you wish to copy?\nExample: " . APP, null, ROOT . DS . 'myapp' . DS);
         if ($skel == '') {
             $this->out('The directory path you supplied was empty. Please try again.');
         } else {
             while (is_dir($skel) === false) {
                 $skel = $this->in('Directory path does not exist please choose another:');
             }
         }
     }
     $app = basename($path);
     $this->out('Bake Project');
     $this->out("Skel Directory: {$skel}");
     $this->out("Will be copied to: {$path}");
     $this->hr();
     $looksGood = $this->in('Look okay?', array('y', 'n', 'q'), 'y');
     if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
         $verboseOuptut = $this->in('Do you want verbose output?', array('y', 'n'), 'n');
         $verbose = false;
         if (low($verboseOuptut) == 'y' || low($verboseOuptut) == 'yes') {
             $verbose = true;
         }
         $Folder = new Folder($skel);
         if ($Folder->copy($path)) {
             $path = $Folder->slashTerm($path);
             $this->hr();
             $this->out(sprintf(__("Created: %s in %s", true), $app, $path));
             $this->hr();
             if ($this->createHome($path)) {
                 $this->out('Welcome page created');
             } else {
                 $this->out('The Welcome page was NOT created');
             }
             if ($this->securitySalt($path) === true) {
                 $this->out('Random hash key created for \'Security.salt\'');
             } else {
                 $this->err('Unable to generate random hash for \'Security.salt\', please change this yourself in ' . CONFIGS . 'core.php');
             }
             $corePath = $this->corePath($path);
             if ($corePath === true) {
                 $this->out('CAKE_CORE_INCLUDE_PATH set to ' . CAKE_CORE_INCLUDE_PATH);
             } elseif ($corePath === false) {
                 $this->err('Unable to to set CAKE_CORE_INCLUDE_PATH, please change this yourself in ' . $path . 'webroot' . DS . 'index.php');
             }
             if (!$Folder->chmod($path . 'tmp', 0777)) {
                 $this->err('Could not set permissions on ' . $path . DS . 'tmp');
                 $this->out('You must manually check that these directories can be wrote to by the server');
             }
         } else {
             $this->err(" '" . $app . "' could not be created properly");
         }
         if ($verbose) {
             foreach ($Folder->messages() as $message) {
                 $this->out($message);
             }
         }
         return;
     } elseif (low($looksGood) == 'q' || low($looksGood) == 'quit') {
         $this->out('Bake Aborted.');
     } else {
         $this->params['working'] = null;
         $this->params['app'] = null;
         $this->execute(false);
     }
 }
Exemple #8
0
 /**
  * プラグインをアップロードしてインストールする
  *
  * @return void
  */
 public function admin_add()
 {
     $this->pageTitle = 'プラグインアップロード';
     $this->subMenuElements = array('plugins');
     if ($this->request->data) {
         if (empty($this->request->data['Plugin']['file']['tmp_name'])) {
             $this->setMessage('ファイルのアップロードに失敗しました。', true);
         } else {
             $name = $this->request->data['Plugin']['file']['name'];
             move_uploaded_file($this->request->data['Plugin']['file']['tmp_name'], TMP . $name);
             exec('unzip -o ' . TMP . $name . ' -d ' . APP . 'Plugin' . DS, $return);
             if (!empty($return[2])) {
                 $plugin = preg_replace('/^\\s*?(creating|inflating):\\s*' . preg_quote(APP . 'Plugin' . DS, '/') . '/', '', $return[2]);
                 $plugin = explode(DS, $plugin);
                 $plugin = $plugin[0];
                 $pluginPath = BASER_THEMES . $plugin;
                 $Folder = new Folder();
                 $Folder->chmod($pluginPath, 0777);
                 $plugin = Inflector::camelize($plugin);
                 $Folder->move(array('to' => BASER_THEMES . $plugin, 'from' => $pluginPath, 'mode' => 0777));
                 unlink(TMP . $name);
                 // プラグインをインストール
                 if ($this->BcManager->installPlugin($plugin)) {
                     clearAllCache();
                     $this->setMessage('新規プラグイン「' . $plugin . '」を baserCMS に登録しました。', false, true);
                     $this->redirect(array('action' => 'index'));
                 } else {
                     $this->setMessage('プラグインに問題がある為インストールを完了できません。プラグインの開発者に確認してください。', true);
                 }
             } else {
                 $msg = 'アップロードしたZIPファイルの展開に失敗しました。';
                 exec('unzip 2>&1', $errs);
                 $msg .= '<br />' . implode('<br />', $errs);
                 $this->setMessage($msg, true);
                 $this->redirect(array('action' => 'add'));
             }
         }
     }
 }
 /**
  * Create sub folder
  * 
  * @param  string $subFolderPath
  * @return void
  */
 protected static function _createSubFolder($subFolderPath)
 {
     if (!is_dir($subFolderPath)) {
         $dir = new Folder();
         $dir->create($subFolderPath);
         $dir->chmod($subFolderPath, '777');
     }
 }
 /**
  * Applies this CHMOD to the specified file or folder.
  *
  * The script will abort if no CHMOD is set.
  *
  * @param	mixed	Path to the file or directory
  * @return	boolean	Returns TRUE on success or FALSE on failure.
  */
 public function apply($path)
 {
     if (is_dir($path) == true) {
         $dir = new Folder(path);
         return $dir->chmod($this);
     } else {
         $file = new File($path);
         return $file->chmod($this);
     }
 }
Exemple #11
0
 /**
  * testChmod method
  *
  * @return void
  */
 public function testChmod()
 {
     $this->skipIf(DIRECTORY_SEPARATOR === '\\', 'Folder permissions tests not supported on Windows.');
     $path = TMP;
     $Folder = new Folder($path);
     $subdir = 'test_folder_new';
     $new = TMP . $subdir;
     $this->assertTrue($Folder->create($new));
     $this->assertTrue($Folder->create($new . DS . 'test1'));
     $this->assertTrue($Folder->create($new . DS . 'test2'));
     $filePath = $new . DS . 'test1.php';
     $File = new File($filePath);
     $this->assertTrue($File->create());
     $filePath = $new . DS . 'skip_me.php';
     $File = new File($filePath);
     $this->assertTrue($File->create());
     $this->assertTrue($Folder->chmod($new, 0755, true));
     $perms = substr(sprintf('%o', fileperms($new . DS . 'test2')), -4);
     $this->assertEquals('0755', $perms);
     $this->assertTrue($Folder->chmod($new, 0744, true, array('skip_me.php', 'test2')));
     $perms = substr(sprintf('%o', fileperms($new . DS . 'test2')), -4);
     $this->assertEquals('0755', $perms);
     $perms = substr(sprintf('%o', fileperms($new . DS . 'test1')), -4);
     $this->assertEquals('0744', $perms);
     $Folder->delete($new);
 }
 /**
  * プラグインをアップロードしてインストールする
  *
  * @return void
  */
 public function admin_add()
 {
     $this->pageTitle = 'プラグインアップロード';
     $this->subMenuElements = array('plugins');
     //データなし
     if (empty($this->request->data)) {
         return;
     }
     //アップロード失敗
     if (empty($this->request->data['Plugin']['file']['tmp_name'])) {
         $this->setMessage('ファイルのアップロードに失敗しました。', true);
         return;
     }
     $zippedName = $this->request->data['Plugin']['file']['name'];
     move_uploaded_file($this->request->data['Plugin']['file']['tmp_name'], TMP . $zippedName);
     App::uses('BcZip', 'Lib');
     $BcZip = new BcZip();
     if (!$BcZip->extract(TMP . $zippedName, APP . 'Plugin' . DS)) {
         $msg = 'アップロードしたZIPファイルの展開に失敗しました。';
         $msg .= '<br />' . $BcZip->error;
         $this->setMessage($msg, true);
         $this->redirect(array('action' => 'add'));
         return;
     }
     $plugin = $BcZip->topArchiveName;
     // 解凍したプラグインフォルダがキャメルケースでない場合にキャメルケースに変換
     $plugin = preg_replace('/^\\s*?(creating|inflating):\\s*' . preg_quote(APP . 'Plugin' . DS, '/') . '/', '', $plugin);
     $plugin = explode(DS, $plugin);
     $plugin = $plugin[0];
     $srcPluginPath = APP . 'Plugin' . DS . $plugin;
     $Folder = new Folder();
     $Folder->chmod($srcPluginPath, 0777);
     $tgtPluginPath = APP . 'Plugin' . DS . Inflector::camelize($plugin);
     if ($srcPluginPath != $tgtPluginPath) {
         $Folder->move(array('to' => $tgtPluginPath, 'from' => $srcPluginPath, 'mode' => 0777));
     }
     unlink(TMP . $zippedName);
     // プラグインをインストール
     if ($this->BcManager->installPlugin($plugin)) {
         clearAllCache();
         $this->setMessage('新規プラグイン「' . $plugin . '」を baserCMS に登録しました。', false, true);
         $this->Plugin->addFavoriteAdminLink($plugin, $this->BcAuth->user());
         $this->redirect(array('action' => 'index'));
     } else {
         $this->setMessage('プラグインに問題がある為インストールを完了できません。プラグインの開発者に確認してください。', true);
     }
 }
Exemple #13
0
 /**
  * フィールドベースのファイル名を取得する
  *
  * @param Model $Model
  * @param array $setting
  * @param string $ext
  * @return mixed false / string
  * @access public
  */
 public function getFieldBasename(Model $Model, $setting, $ext)
 {
     if (empty($setting['namefield'])) {
         return false;
     }
     $data = $Model->data[$Model->alias];
     if (!isset($data[$setting['namefield']])) {
         if ($setting['namefield'] == 'id' && $Model->id) {
             $basename = $Model->id;
         } else {
             return false;
         }
     } else {
         $basename = $data[$setting['namefield']];
     }
     if (!empty($setting['nameformat'])) {
         $basename = sprintf($setting['nameformat'], $basename);
     }
     if (!isset($setting['nameadd']) || $setting['nameadd'] !== false) {
         $basename .= '_' . $setting['name'];
     }
     $subdir = '';
     if (!empty($this->settings[$Model->alias]['subdirDateFormat'])) {
         $subdir = date($this->settings[$Model->alias]['subdirDateFormat']);
         if (!preg_match('/\\/$/', $subdir)) {
             $subdir .= '/';
         }
         $subdir = str_replace('/', DS, $subdir);
         $path = $this->savePath[$Model->alias] . $subdir;
         if (!is_dir($path)) {
             $Folder = new Folder();
             $Folder->create($path);
             $Folder->chmod($path, 0777);
         }
     }
     return $subdir . $basename . '.' . $ext;
 }
	/**
	 * Check the destination folder. If it does not exist or isn't writable, fix it!
	 *
	 * @access public
	 * @uses Folder
	 * @return void
	 */
	public function checkDirectory() {
		$Folder = new Folder();
		$uploadDir = trim($this->uploadDir, '/');
		$finalDir = $this->formatPath($uploadDir .'/');

		if (!is_dir($finalDir)) {
			$dirParts = explode('/', $uploadDir);
			$dirCurrent = rtrim($this->baseDir, '/');

			foreach ($dirParts as $part) {
				$Folder->create($dirCurrent . DS . $part, 0777);
				$dirCurrent .= DS . $part;
			}
		} else if (!is_writable($finalDir)) {
			$Folder->chmod($finalDir, 0777, false);
		}

		$this->finalDir = $finalDir;
	}
 /**
  * Check file name and setup filepath
  */
 private function __proceedFileName()
 {
     //get error status
     $checkError = $this->isError();
     if (!$checkError) {
         $filename = $this->__uploadData['name'];
         if (empty($this->__folderDestPath)) {
             $this->setupError(__d('cloggy', 'Folder destination not configured.'));
         } else {
             /*
              * create folder if not exists
              */
             if (!is_dir($this->__folderDestPath)) {
                 /*
                  * create folder
                  */
                 $folder = new Folder();
                 $folder->create($this->__folderDestPath);
                 $folder->chmod($this->__folderDestPath, 0755);
             }
             $filepath = $this->__folderDestPath . $filename;
             /*
              * check if exists
              */
             if (file_exists($filepath)) {
                 /*
                  * raise an error if forDupFile set to false
                  * and there is an existed file
                  */
                 if ($this->__forceDupFile) {
                     $filename = $this->__rewriteFile($filename);
                     $this->__filepath = $this->__folderDestPath . $filename;
                 } else {
                     $this->setupError(__d('cloggy', 'Cannot upload file due to duplicate file.'));
                 }
             } else {
                 $this->__filepath = $filepath;
             }
         }
     }
 }
Exemple #16
0
 /**
  * プラグインをアップロードしてインストールする
  *
  * @return void
  */
 public function admin_add()
 {
     $this->pageTitle = 'プラグインアップロード';
     $this->subMenuElements = array('plugins');
     //データなし
     if (empty($this->request->data)) {
         return;
     }
     //アップロード失敗
     if (empty($this->request->data['Plugin']['file']['tmp_name'])) {
         $this->setMessage('ファイルのアップロードに失敗しました。', true);
         return;
     }
     $zippedName = $this->request->data['Plugin']['file']['name'];
     move_uploaded_file($this->request->data['Plugin']['file']['tmp_name'], TMP . $zippedName);
     $format = 'unzip -o ' . TMP . '%s' . ' -d ' . APP . 'Plugin' . DS;
     $command = sprintf($format, escapeshellarg($zippedName));
     exec($command, $return);
     //ZIPファイル展開失敗
     if (empty($return[2])) {
         $msg = 'アップロードしたZIPファイルの展開に失敗しました。';
         exec('unzip 2>&1', $errs);
         $msg .= '<br />' . implode('<br />', $errs);
         $this->setMessage($msg, true);
         $this->redirect(array('action' => 'add'));
         return;
     }
     // 解凍したプラグインフォルダがキャメルケースでない場合にキャメルケースに変換
     $plugin = preg_replace('/^\\s*?(creating|inflating):\\s*' . preg_quote(APP . 'Plugin' . DS, '/') . '/', '', $return[2]);
     $plugin = explode(DS, $plugin);
     $plugin = $plugin[0];
     $srcPluginPath = APP . 'Plugin' . DS . $plugin;
     $Folder = new Folder();
     $Folder->chmod($srcPluginPath, 0777);
     $tgtPluginPath = APP . 'Plugin' . DS . Inflector::camelize($plugin);
     if ($srcPluginPath != $tgtPluginPath) {
         $Folder->move(array('to' => $tgtPluginPath, 'from' => $srcPluginPath, 'mode' => 0777));
     }
     unlink(TMP . $zippedName);
     // プラグインをインストール
     if ($this->BcManager->installPlugin($plugin)) {
         clearAllCache();
         $this->setMessage('新規プラグイン「' . $plugin . '」を baserCMS に登録しました。', false, true);
         $this->Plugin->addFavoriteAdminLink($plugin, $this->BcAuth->user());
         $this->redirect(array('action' => 'index'));
     } else {
         $this->setMessage('プラグインに問題がある為インストールを完了できません。プラグインの開発者に確認してください。', true);
     }
 }
Exemple #17
0
 /**
  * Checks that given project path does not already exist, and
  * finds the app directory in it. Then it calls bake() with that information.
  *
  * @param string $project Project path
  * @access public
  */
 function execute($project = null)
 {
     if ($project === null) {
         if (isset($this->args[0])) {
             $project = $this->args[0];
             $this->Dispatch->shiftArgs();
         }
     }
     if ($project) {
         if ($project[0] == '/' || $project[0] == DS) {
             $this->Dispatch->parseParams(array('-working', $project));
         } else {
             $this->Dispatch->parseParams(array('-app', $project));
         }
     }
     $project = $this->params['working'];
     if (empty($this->params['skel'])) {
         $this->params['skel'] = '';
         if (is_dir(CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'console' . DS . 'libs' . DS . 'templates' . DS . 'skel') === true) {
             $this->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'console' . DS . 'libs' . DS . 'templates' . DS . 'skel';
         }
     }
     if ($project) {
         $response = false;
         while ($response == false && is_dir($project) === true && config('core') === true) {
             $response = $this->in('A project already exists in this location: ' . $project . ' Overwrite?', array('y', 'n'), 'n');
             if (low($response) === 'n') {
                 $response = false;
                 while (!$response) {
                     $response = $this->in("What is the full path for this app including the app directory name?\nExample: " . $this->params['root'] . DS . "myapp\n[Q]uit", null, 'Q');
                     if (strtoupper($response) === 'Q') {
                         $this->out('Bake Aborted');
                         exit;
                     }
                     $this->params['working'] = null;
                     $this->params['app'] = null;
                     $this->execute($response);
                     exit;
                 }
             }
         }
     }
     while (!$project) {
         $project = $this->in("What is the full path for this app including the app directory name?\nExample: " . $this->params['root'] . DS . "myapp", null, $this->params['root'] . DS . 'myapp');
         $this->execute($project);
         exit;
     }
     if (!is_dir($this->params['root'])) {
         $this->err(__('The directory path you supplied was not found. Please try again.', true));
     }
     if ($this->bake($project)) {
         $path = Folder::slashTerm($project);
         if ($this->createHome($path)) {
             $this->out(__('Welcome page created', true));
         } else {
             $this->out(__('The Welcome page was NOT created', true));
         }
         if ($this->securitySalt($path) === true) {
             $this->out(__('Random hash key created for \'Security.salt\'', true));
         } else {
             $this->err(sprintf(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', true), CONFIGS . 'core.php'));
         }
         $corePath = $this->corePath($path);
         if ($corePath === true) {
             $this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s'), true, CAKE_CORE_INCLUDE_PATH));
         } elseif ($corePath === false) {
             $this->err(sprintf(__('Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', true), $path . 'webroot' . DS . 'index.php'));
         }
         $Folder = new Folder($path);
         if (!$Folder->chmod($path . 'tmp', 0777)) {
             $this->err(sprintf(__('Could not set permissions on %s', true), $path . DS . 'tmp'));
             $this->out(sprintf(__('chmod -R 0777 %s', true), $path . DS . 'tmp'));
         }
     }
     exit;
 }
 function setPerms($dir)
 {
     if (!is_dir($dir)) {
         return $this->makeDir($dir);
     } elseif (is_writable($dir)) {
         return true;
     } else {
         $test_file = $dir . DS . '___test___';
         $f = @fopen($test_file, 'a');
         if ($f === false) {
             $fd = new Folder();
             return $fd->chmod($dir, 0777);
         } else {
             fclose($f);
             @unlink($test_file);
             return true;
         }
     }
 }
Exemple #19
0
<?php

if (!defined('MIGRATE')) {
    exit;
}
$oldies = $this->_query("SELECT id, path FROM {$atbl} WHERE path NOT LIKE 'album-%' AND path IS NOT NULL LIMIT 1");
if ($this->_rows($oldies) == 1) {
    $row = $this->_array($oldies);
    $old = ALBUMS . DS . $row['path'];
    $path = 'album-' . $row['id'];
    $new = ALBUMS . DS . $path;
    if (is_dir($old)) {
        $f = new Folder($old);
        $f->chmod($old, 0777);
        if ($f->move($new)) {
            $this->_query("UPDATE {$atbl} SET path = '{$path}-old-{$row['path']}' WHERE id = {$row['id']}");
        }
    } else {
        $this->_query("UPDATE {$atbl} SET path = '{$path}-old-{$row['path']}' WHERE id = {$row['id']}");
    }
    die('again');
}
Exemple #20
0
 /**
  * Fix permission for `tmp` directory
  * 
  * @param string $path
  * @return boolean
  */
 protected function _fixPermissionForDirs($path)
 {
     $Folder = new Folder($path);
     $success = true;
     if (!$Folder->chmod($path . 'tmp', 0777)) {
         $this->err(__d('cake_console', 'Could not set permissions on %s', $path . 'tmp'));
         $this->out('chmod -R 0777 ' . $path . 'tmp');
         $success = false;
     }
     return $success;
 }
Exemple #21
0
 /**
  * testChmod method
  *
  * @return void
  */
 public function testChmod()
 {
     $this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Folder permissions tests not supported on Windows');
     $path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel';
     $Folder = new Folder($path);
     $subdir = 'test_folder_new';
     $new = TMP . $subdir;
     $this->assertTrue($Folder->create($new));
     $this->assertTrue($Folder->create($new . DS . 'test1'));
     $this->assertTrue($Folder->create($new . DS . 'test2'));
     $filePath = $new . DS . 'test1.php';
     $File = new File($filePath);
     $this->assertTrue($File->create());
     $copy = TMP . 'test_folder_copy';
     $this->assertTrue($Folder->chmod($new, 0777, true));
     $this->assertEqual($File->perms(), '0777');
     $Folder->delete($new);
 }
Exemple #22
0
 /**
  * Checks that given project path does not already exist, and
  * finds the app directory in it. Then it calls bake() with that information.
  *
  * @param string $project Project path
  * @access public
  */
 function execute($project = null)
 {
     if ($project === null) {
         if (isset($this->args[0])) {
             $project = $this->args[0];
         }
     }
     if ($project) {
         $this->Dispatch->parseParams(array('-app', $project));
         $project = $this->params['working'];
     }
     if (empty($this->params['skel'])) {
         $this->params['skel'] = '';
         if (is_dir(CAKE . 'console' . DS . 'templates' . DS . 'skel') === true) {
             $this->params['skel'] = CAKE . 'console' . DS . 'templates' . DS . 'skel';
         }
     }
     while (!$project) {
         $prompt = __("What is the full path for this app including the app directory name?\n Example:", true);
         $default = $this->params['working'] . DS . 'myapp';
         $project = $this->in($prompt . $default, null, $default);
     }
     if ($project) {
         $response = false;
         while ($response == false && is_dir($project) === true && file_exists($project . 'config' . 'core.php')) {
             $prompt = sprintf(__('A project already exists in this location: %s Overwrite?', true), $project);
             $response = $this->in($prompt, array('y', 'n'), 'n');
             if (strtolower($response) === 'n') {
                 $response = $project = false;
             }
         }
     }
     if ($this->bake($project)) {
         $path = Folder::slashTerm($project);
         if ($this->createHome($path)) {
             $this->out(__('Welcome page created', true));
         } else {
             $this->out(__('The Welcome page was NOT created', true));
         }
         if ($this->securitySalt($path) === true) {
             $this->out(__('Random hash key created for \'Security.salt\'', true));
         } else {
             $this->err(sprintf(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', true), CONFIGS . 'core.php'));
         }
         $corePath = $this->corePath($path);
         if ($corePath === true) {
             $this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', true), CAKE_CORE_INCLUDE_PATH));
             $this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s in webroot/test.php', true), CAKE_CORE_INCLUDE_PATH));
             $this->out(__('Remember to check these value after moving to production server', true));
         } elseif ($corePath === false) {
             $this->err(sprintf(__('Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', true), $path . 'webroot' . DS . 'index.php'));
         }
         $Folder = new Folder($path);
         if (!$Folder->chmod($path . 'tmp', 0777)) {
             $this->err(sprintf(__('Could not set permissions on %s', true), $path . DS . 'tmp'));
             $this->out(sprintf(__('chmod -R 0777 %s', true), $path . DS . 'tmp'));
         }
         $this->params['working'] = $path;
         $this->params['app'] = basename($path);
         return true;
     }
 }
 private function __upload()
 {
     if (!empty($_FILES) && isset($_FILES['file_upload']) && $_FILES['file_upload']['error'] == 0) {
         $folder = WWW_ROOT . 'files' . DS . 'chat_uploads';
         if (!is_dir($folder)) {
             $Folder = new Folder();
             $Folder->create($folder);
             $Folder->chmod($folder, 0755);
         }
         $file = $folder . DS . 'attach_' . time() . '_' . $_FILES['file_upload']['name'];
         if (move_uploaded_file($_FILES['file_upload']['tmp_name'], $file)) {
             return $file;
         }
     }
     return false;
 }
 /**
  * Checks that given project path does not already exist, and
  * finds the app directory in it. Then it calls bake() with that information.
  *
  * @return mixed
  */
 public function execute()
 {
     $project = null;
     if (isset($this->args[0])) {
         $project = $this->args[0];
     } else {
         $appContents = array_diff(scandir(APP), array('.', '..'));
         if (empty($appContents)) {
             $suggestedPath = rtrim(APP, DS);
         } else {
             $suggestedPath = APP . 'myapp';
         }
     }
     while (!$project) {
         $prompt = __d('cake_console', "What is the path to the project you want to bake?");
         $project = $this->in($prompt, null, $suggestedPath);
     }
     if ($project && !Folder::isAbsolute($project) && isset($_SERVER['PWD'])) {
         $project = $_SERVER['PWD'] . DS . $project;
     }
     $response = false;
     while (!$response && is_dir($project) === true && file_exists($project . 'Config' . 'core.php')) {
         $prompt = __d('cake_console', '<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
         $response = $this->in($prompt, array('y', 'n'), 'n');
         if (strtolower($response) === 'n') {
             $response = $project = false;
         }
     }
     $success = true;
     if ($this->bake($project)) {
         $path = Folder::slashTerm($project);
         if ($this->securitySalt($path) === true) {
             $this->out(__d('cake_console', ' * Random hash key created for \'Security.salt\''));
         } else {
             $this->err(__d('cake_console', 'Unable to generate random hash for \'Security.salt\', you should change it in %s', APP . 'Config' . DS . 'core.php'));
             $success = false;
         }
         if ($this->securityCipherSeed($path) === true) {
             $this->out(__d('cake_console', ' * Random seed created for \'Security.cipherSeed\''));
         } else {
             $this->err(__d('cake_console', 'Unable to generate random seed for \'Security.cipherSeed\', you should change it in %s', APP . 'Config' . DS . 'core.php'));
             $success = false;
         }
         if ($this->cachePrefix($path)) {
             $this->out(__d('cake_console', ' * Cache prefix set'));
         } else {
             $this->err(__d('cake_console', 'The cache prefix was <error>NOT</error> set'));
             $success = false;
         }
         if ($this->consolePath($path) === true) {
             $this->out(__d('cake_console', ' * app/Console/cake.php path set.'));
         } else {
             $this->err(__d('cake_console', 'Unable to set console path for app/Console.'));
             $success = false;
         }
         $hardCode = false;
         if ($this->cakeOnIncludePath()) {
             $this->out(__d('cake_console', '<info>CakePHP is on your `include_path`. CAKE_CORE_INCLUDE_PATH will be set, but commented out.</info>'));
         } else {
             $this->out(__d('cake_console', '<warning>CakePHP is not on your `include_path`, CAKE_CORE_INCLUDE_PATH will be hard coded.</warning>'));
             $this->out(__d('cake_console', 'You can fix this by adding CakePHP to your `include_path`.'));
             $hardCode = true;
         }
         $success = $this->corePath($path, $hardCode) === true;
         if ($success) {
             $this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in %s', CAKE_CORE_INCLUDE_PATH, 'webroot/index.php'));
             $this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in %s', CAKE_CORE_INCLUDE_PATH, 'webroot/test.php'));
         } else {
             $this->err(__d('cake_console', 'Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', $path . 'webroot' . DS . 'index.php'));
             $success = false;
         }
         if ($success && $hardCode) {
             $this->out(__d('cake_console', '   * <warning>Remember to check these values after moving to production server</warning>'));
         }
         $Folder = new Folder($path);
         if (!$Folder->chmod($path . 'tmp', 0777)) {
             $this->err(__d('cake_console', 'Could not set permissions on %s', $path . DS . 'tmp'));
             $this->out('chmod -R 0777 ' . $path . DS . 'tmp');
             $success = false;
         }
         if ($success) {
             $this->out(__d('cake_console', '<success>Project baked successfully!</success>'));
         } else {
             $this->out(__d('cake_console', 'Project baked but with <warning>some issues.</warning>.'));
         }
         return $path;
     }
 }
Exemple #25
0
 /**
  * Checks that given project path does not already exist, and
  * finds the app directory in it. Then it calls bake() with that information.
  *
  * @param string $project Project path
  */
 public function execute()
 {
     $project = null;
     if (isset($this->args[0])) {
         $project = $this->args[0];
     }
     while (!$project) {
         $prompt = __d('cake_console', "What is the path to the project you want to bake?");
         $project = $this->in($prompt, null, APP_PATH . 'myapp');
     }
     if ($project && !Folder::isAbsolute($project) && isset($_SERVER['PWD'])) {
         $project = $_SERVER['PWD'] . DS . $project;
     }
     $response = false;
     while ($response == false && is_dir($project) === true && file_exists($project . 'Config' . 'core.php')) {
         $prompt = __d('cake_console', '<warning>A project already exists in this location:</warning> %s Overwrite?', $project);
         $response = $this->in($prompt, array('y', 'n'), 'n');
         if (strtolower($response) === 'n') {
             $response = $project = false;
         }
     }
     $success = true;
     if ($this->bake($project)) {
         $path = Folder::slashTerm($project);
         if ($this->createHome($path)) {
             $this->out(__d('cake_console', ' * Welcome page created'));
         } else {
             $this->err(__d('cake_console', 'The Welcome page was <error>NOT</error> created'));
             $success = false;
         }
         if ($this->securitySalt($path) === true) {
             $this->out(__d('cake_console', ' * Random hash key created for \'Security.salt\''));
         } else {
             $this->err(__d('cake_console', 'Unable to generate random hash for \'Security.salt\', you should change it in %s', APP . 'Config' . DS . 'core.php'));
             $success = false;
         }
         if ($this->securityCipherSeed($path) === true) {
             $this->out(__d('cake_console', ' * Random seed created for \'Security.cipherSeed\''));
         } else {
             $this->err(__d('cake_console', 'Unable to generate random seed for \'Security.cipherSeed\', you should change it in %s', APP . 'Config' . DS . 'core.php'));
             $success = false;
         }
         if ($this->consolePath($path) === true) {
             $this->out(__d('cake_console', ' * app/Console/cake.php path set.'));
         } else {
             $this->err(__d('cake_console', 'Unable to set console path for app/Console.'));
             $success = false;
         }
         $this->out(__d('cake_console', 'The value for CAKE_CORE_INCLUDE_PATH can be hardcoded set to %s in webroot/index.php', CAKE_CORE_INCLUDE_PATH));
         $this->out(__d('cake_console', '<warning>If you hard code it, the project will possibly run only in your computer.</warning>'));
         $setConstants = $this->in(__d('cake_console', 'Do you want to set CAKE_CORE_INCLUDE_PATH in webroot/index.php?'), array('y', 'n'), 'n');
         if (strtolower($setConstants) === 'y') {
             if ($this->corePath($path) === true) {
                 $this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', CAKE_CORE_INCLUDE_PATH));
                 $this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/test.php', CAKE_CORE_INCLUDE_PATH));
                 $this->out(__d('cake_console', '   * <warning>Remember to check these values after moving to production server</warning>'));
             } else {
                 $this->err(__d('cake_console', 'Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', $path . 'webroot' . DS . 'index.php'));
                 $success = false;
             }
         } else {
             $this->out(__d('cake_console', '<warning>Please make sure your cake core is accessible, if you have problems edit CAKE_CORE_INCLUDE_PATH in webroot/index.php</warning>'));
         }
         $Folder = new Folder($path);
         if (!$Folder->chmod($path . 'tmp', 0777)) {
             $this->err(__d('cake_console', 'Could not set permissions on %s', $path . DS . 'tmp'));
             $this->out(__d('cake_console', 'chmod -R 0777 %s', $path . DS . 'tmp'));
             $success = false;
         }
         if ($success) {
             $this->out(__d('cake_console', '<success>Project baked successfully!</success>'));
         } else {
             $this->out(__d('cake_console', 'Project baked but with <warning>some issues.</warning>.'));
         }
         return $path;
     }
 }