public function post_new_city() { $rules = array('city' => 'required|unique:photos', 'picture' => 'required'); $v = Validator::make(Input::all(), $rules); if ($v->fails()) { return Redirect::to('admin/cityphotos')->with_errors($v)->with_input(); } else { $new_photo = array('city' => ucwords(Input::get('city'))); $photo = new Photo($new_photo); if ($photo->save()) { $upload_path = path('public') . Photo::$upload_path_city . $photo->city; if (!File::exists($upload_path)) { File::mkdir($upload_path); } $filename = $photo->city . '.jpg'; $path_to_file = $upload_path . '/' . $filename; $dynamic_path = '/' . Photo::$upload_path_city . $photo->city . '/' . $filename; $success = Resizer::open(Input::file('picture'))->resize(1024, 724, 'auto')->save($path_to_file, 75); if ($success) { $new_photo = Photo::find($photo->id); $new_photo->location = $dynamic_path; $new_photo->save(); } return Redirect::to('admin/cityphotos')->with('msg', '<div class="alert alert-success"><strong>City foto is geupload!</strong></div>'); } else { return Redirect::to('admin/cityphotos')->with('msg', '<div class="alert alert-error"><strong>Er is iets mis gegaan bij het toevoegen.</strong></div>'); } } }
public static function instance($model, $db = null, $options = []) { $db = is_null($db) ? SITE_NAME : $db; $class = __NAMESPACE__ . '\\Model\\' . ucfirst(Inflector::lower($model)); $file = APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . ucfirst(Inflector::lower($db)) . DS . ucfirst(Inflector::lower($model)) . '.php'; if (File::exists($file)) { require_once $file; return new $class(); } if (!class_exists($class)) { $code = 'namespace ' . __NAMESPACE__ . '\\Model;' . "\n" . ' class ' . ucfirst(Inflector::lower($model)) . ' extends \\Thin\\MyOrm { public $timestamps = false; protected $table = "' . Inflector::lower($model) . '"; public static function boot() { static::unguard(); } }'; if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql')) { $dir = APPLICATION_PATH . DS . 'models' . DS . 'Mysql'; File::mkdir($dir); } if (!is_dir(APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . ucfirst(Inflector::lower($db)))) { $dir = APPLICATION_PATH . DS . 'models' . DS . 'Mysql' . DS . ucfirst(Inflector::lower($db)); File::mkdir($dir); } File::put($file, '<?php' . "\n" . $code); require_once $file; return new $class(); } }
public static function text($str) { $config = HTMLPurifier_Config::createDefault(); $cache_dir = Tiny::getPath('cache') . "/htmlpurifier/"; if (!file_exists($cache_dir)) { File::mkdir($cache_dir); } $config = HTMLPurifier_Config::createDefault(); //配置 缓存目录 $config->set('Cache.SerializerPath', $cache_dir); //设置cache目录 //配置 允许flash $config->set('HTML.SafeEmbed', true); $config->set('HTML.SafeObject', true); $config->set('Output.FlashCompat', true); //$config->set('HTML.Allowed', 'p'); //$config->set('AutoFormat.AutoParagraph', true); //$config->set('AutoFormat.RemoveEmpty', true); //允许<a>的target属性 $def = $config->getHTMLDefinition(true); $def->addAttribute('a', 'target', 'Enum#_blank,_self,_target,_top'); $purifier = new HTMLPurifier($config); if (get_magic_quotes_gpc()) { $str = stripslashes($str); $str = $purifier->purify($str); $str = addslashes($str); } else { $str = $purifier->purify($str); } return self::sql($str); }
/** * Compile an asset collection. * * @param Basset\Collection $collection * @return void */ protected function compile(Collection $collection) { $force = isset($_SERVER['CLI']['FORCE']); // If the compile path does not exist attempt to create it. if (!File::exists($this->compilePath)) { File::mkdir($this->compilePath); } $groups = $collection->getAssets(); if (empty($groups)) { echo "The collection '{$collection->getName()}' has no assets to compile.\n"; } foreach ($groups as $group => $assets) { $path = $this->compilePath . '/' . $collection->getCompiledName($group); // We only compile a collection if a compiled file doesn't exist yet or if a change to one of the assets // in the collection is detected by comparing the last modified times. if (File::exists($path) and File::modified($path) >= $collection->lastModified($group)) { // If the force flag has been set then we'll recompile, otherwise this collection does not need // to be changed. if (!$force) { echo "The {$group}s for the collection '{$collection->getName()}' do not need to be compiled.\n"; continue; } } $compiled = $collection->compile($group); echo "Successfully compiled {$collection->getCompiledName($group)}\n"; File::put($path, $compiled); } }
private function log() { if (!$this->output || strlen($this->output) < 1) { return false; } $endTime = time(); $this->console('//--------'); $this->console('Time: ' . ($endTime - $this->startTime) . ' sec.'); $this->console('Start script: ' . $this->startTime); $this->console('End script: ' . $endTime); $dir = LOG_DIR . DS . 'cron' . DS . Request::get('app') . DS . Request::get('module') . DS; $name = Request::get('action') . '.' . time() . '.' . LOG_FILE_EXTENTION; File::mkdir($dir); $log = new File($dir . $name, true); $log->write($this->output); $files = array_map(function ($a) { return array('file' => $a, 'time' => filemtime($a)); }, glob($dir . Request::get('action') . '.*.' . LOG_FILE_EXTENTION)); usort($files, function ($a, $b) { if ($a['time'] == $b['time']) { return 0; } return $a['time'] > $b['time'] ? -1 : 1; }); $delete = array_slice($files, 10); foreach ($delete as $file) { unlink($file['file']); } }
function execute() { Load::file('nodatabase.class.php', $this->source_dir); File::mkdir(TEMP_DIR . DS . 'nodatabase'); $noDataBase = new noDataBase(); $noDataBase->basesDir = TEMP_DIR . DS . 'nodatabase' . DS; return $noDataBase; }
public function __construct($ns = 'core') { $native = Config::get('dir.ephemere', session_save_path()); $this->dir = $native . DS . $ns; if (!is_dir($this->dir)) { File::mkdir($this->dir); } }
public function write_jpg($sec, $output_filename) { if (!preg_match("/\\.(jpg|jpeg)\$/i", $output_filename)) { $output_filename = $output_filename . ".jpg"; } File::mkdir(dirname($output_filename)); new Command(sprintf("%s -ss %01.3f -i %s -f image2 %s", $this->cmd, $sec, $this->filename, $output_filename)); }
/** * Create a directory if it doesn't exist. The operation is implicitly recursive, i.e. it will create all * intermediate directories if they do not already exist. * * @param string $dirName The full path of the directory to create * @param integer $permissions The permissions of the created directory * * @return boolean True on success */ public function mkdir($dirName, $permissions = 0755) { $ret = $this->fileAdapter->mkdir($dirName, $permissions); if (!$ret && is_object($this->abstractionAdapter)) { return $this->abstractionAdapter->mkdir($dirName, $permissions); } return $ret; }
public function __construct() { $dir = Config::get('app.logs.dir', '/home/storage/logs'); $dir .= DS . APPLICATION_ENV; if (!is_dir($dir)) { File::mkdir($dir); } }
public function post_new() { $rules = array('title' => 'required|min:5|max:128', 'street' => 'required', 'postalcode' => 'required|match:#^[1-9][0-9]{3}\\h*[A-Z]{2}$#i', 'city' => 'required', 'type' => 'required', 'surface' => 'required|integer', 'price' => 'required|numeric|max:1500|min:100', 'date' => 'required|after:' . date('d-m-Y'), 'pictures' => 'required|image|max:3000', 'register' => 'required', 'email' => 'required|email|same:email2', 'description' => 'required|min:30', 'captchatest' => 'laracaptcha|required', 'terms' => 'accepted'); $v = Validator::make(Input::all(), $rules, Room::$messages); if ($v->fails()) { return Redirect::to('kamer-verhuren')->with_errors($v)->with('msg', '<div class="alert alert-error"><strong>Verplichte velden zijn niet volledig ingevuld</strong><br />Loop het formulier nogmaals na.</div>')->with_input(); } else { if (Auth::check()) { $status = 'publish'; } else { $status = 'pending'; } $new_room = array('title' => ucfirst(Input::get('title')), 'street' => ucwords(Input::get('street')), 'housenr' => Input::get('housenr'), 'postalcode' => Input::get('postalcode'), 'city' => ucwords(Input::get('city')), 'type' => Input::get('type'), 'surface' => Input::get('surface'), 'price' => Input::get('price'), 'available' => date("Y-m-d", strtotime(Input::get('date'))), 'gender' => Input::get('gender'), 'pets' => Input::get('pets'), 'smoking' => Input::get('smoking'), 'toilet' => Input::get('toilet'), 'shower' => Input::get('shower'), 'kitchen' => Input::get('kitchen'), 'register' => Input::get('register'), 'social' => Input::get('social'), 'email' => strtolower(Input::get('email')), 'description' => ucfirst(Input::get('description')), 'status' => $status, 'url' => Str::slug(Input::get('city')), 'delkey' => Str::random(32, 'alpha'), 'del_date' => date('y-m-d', strtotime('+2 months'))); $room = new Room($new_room); if ($room->save()) { $upload_path = path('public') . Photo::$upload_path_room . $room->id; if (!File::exists($upload_path)) { File::mkdir($upload_path); chmod($upload_path, 0777); } $photos = Photo::getNormalizedFiles(Input::file('pictures')); foreach ($photos as $photo) { $filename = md5(rand()) . '.jpg'; $path_to_file = $upload_path . '/' . $filename; $dynamic_path = '/' . Photo::$upload_path_room . $room->id . '/' . $filename; $success = Resizer::open($photo)->resize(800, 533, 'auto')->save($path_to_file, 80); chmod($path_to_file, 0777); if ($success) { $new_photo = new Photo(); $new_photo->location = $dynamic_path; $new_photo->room_id = $room->id; $new_photo->save(); } } Message::send(function ($message) use($room) { $message->to($room->email); $message->from('*****@*****.**', 'Kamergenood'); $message->subject('In afwachting op acceptatie: "' . $room->title . '"'); $message->body('view: emails.submit'); $message->body->id = $room->id; $message->body->title = $room->title; $message->body->price = $room->price; $message->body->type = $room->type; $message->body->surface = $room->surface; $message->body->available = $room->available; $message->body->description = $room->description; $message->body->url = $room->url; $message->body->delkey = $room->delkey; $message->html(true); }); if (Message::was_sent()) { return Redirect::to('kamer-verhuren')->with('msg', '<div class="alert alert-success"><strong>Hartelijk dank voor het vertrouwen in Kamergenood!</strong> De kameradvertentie zal binnen 24 uur worden gecontroleerd en geplaatst.</div>'); } } else { return Redirect::to('kamer-verhuren')->with('msg', '<div class="alert alert-error"><strong>Er is iets mis gegaan bij het toevoegen.</strong> Probeer het later nog eens.</div>')->with_input(); } } }
function execute() { Load::file('Smarty.class.php', $this->source_dir); $smarty = new Smarty(); $smarty->setCompileDir(File::mkdir(TEMP_DIR . DS . $this->name . DS . 'templates_c') . DS); $smarty->setConfigDir(File::mkdir(TEMP_DIR . DS . $this->name . DS . 'configs') . DS); $smarty->setCacheDir(File::mkdir(TEMP_DIR . DS . $this->name . DS . 'cache') . DS); return $smarty; }
/** * Build path */ public function buildPath() { $file = $this->image->getFile(); $dir = dirname($file); $filename = basename($file); $path = $dir . DS . self::DIR . DS . $this->name . DS . $filename; File::mkdir(dirname($path)); return $path; }
public function __construct(array $array, $callback = null) { $path = CACHE_PATH . DS . Utils::UUID(); File::mkdir($path); File::put($file, "<?php\nreturn " . var_export($array, 1) . ';'); $this->assoc = Arrays::isAssoc($array); $this->file = $file; $this->callback = $callback; $this->count = count($array); }
public function convertToFlv($name, $user, $videoID) { $dir = $this->uploadDir . DS . 'user' . $user . DS . $videoID; File::mkdir($dir); $command = 'C:\\ffmpeg\\bin\\ffmpeg -i ' . $this->tmpDir . DS . $name . ' -ss 00:00:01 -vframes 1 ' . $dir . DS . 'image.png'; system($command); $command = 'C:\\ffmpeg\\bin\\ffmpeg -i ' . $this->tmpDir . DS . $name . ' -vcodec libx264 -crf 25 -acodec libmp3lame -ar 44100 -ab 56k -f flv ' . $dir . DS . 'video.flv'; system($command); unlink($this->tmpDir . DS . $name); }
/** * Распаковка архива по указанному пути * * @param string $path * @param array $entries */ public function extract($path, $entries = NULL) { is_dir($path) or File::mkdir($path); if ($this->check()) { if ($this->extractTo($path, $entries)) { return TRUE; } } $this->error(t('Вы загружаете архив неверного формата!')); return FALSE; }
public static function write($sql = false, $obj = false) { if (!($data = self::_data($sql)) || !$obj) { return false; } // attempt to create the subfolder File::mkdir($data['path']); if (!File::write($data['path'] . $data['file'], serialize($obj))) { return false; } return true; }
public function post_create() { $validation = Validator::make(Input::get(), array('galleryName' => 'required|max:60')); if ($validation->fails()) { return Redirect::to('admin/galleries'); } $galleryName = Input::get('galleryName'); $galleryID = Galleries::create($galleryName); File::mkdir(path('public') . 'images/' . $galleryID); File::mkdir(path('public') . 'images/' . $galleryID . '/thumbs'); return Redirect::to('admin/galleries'); }
public function __construct($ns = 'core') { $dir = STORAGE_PATH . DS . 'ini'; if (!is_dir($dir)) { File::mkdir($dir); } $dir .= DS . $ns; if (!is_dir($dir)) { File::mkdir($dir); } $this->dir = $dir; $this->ns = $ns; }
function create($name, $iso, $flag = '') { if (empty($name) || empty($iso)) { return false; } $iso = strtolower($iso); $dir = APP_DIR . DS . App::getAppName() . DS . APP_LOCALE . DS . $iso . DS; File::mkdir($dir); $file = new File($dir . $iso . '.locale.php', true); $file->write('<?php' . PHP_EOL . 'return array();'); $file->create($dir . 'config.php'); self::setConfig($iso, array('name' => $name, 'iso' => $iso, 'flag' => str_replace('.png', '', $flag), 'default' => false)); }
public function addFile($file, $user) { $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); $dir = UPLOAD_DIR . DS . 'attachment'; File::mkdir($dir); if (in_array($extension, $this->extension)) { $name = md5(basename($file['name']) . strtotime('now') . uniqid()) . '.' . $extension; if (move_uploaded_file($file['tmp_name'], $dir . DS . $name)) { return $this->insert(array('file' => $name, 'user' => (int) $user)); } } return false; }
/** * Write to cache * * @param string $name * @param mixed $value * @param array $tags * @param int $ttl */ public function write($name, $value, $tags = NULL, $ttl = NULL) { $name = $this->prepareKey($name); $data = array('value' => $value, 'ttl' => $ttl ? time() + $ttl : 0); if ($tags) { $data['tags'] = $tags; foreach ($tags as $tag) { $this->write('tags/' . $tag, '', array()); } } $this->stats->write++; File::mkdir(dirname($this->options->path . DS . $name)); file_put_contents($this->options->path . DS . $name, PHP_FILE_PREFIX . 'return ' . var_export($data, TRUE) . ';'); }
public function create($table = false) { if (!$table) { return false; } $dir = $this->basesDir . $table; if (is_dir($dir)) { return true; } File::mkdir($dir); $file = new File($dir . DS . NODATABASE_TABLE_FILE, true); $this->save($table, array()); return true; }
public static function file($path, $type = 'public', $app = false) { if (!$app) { $app = App::$activeAppName; } $dir = self::getDir($type) . $app . DS; if (!is_dir($dir)) { File::mkdir($dir); } $file = $dir . $path; if (is_file($file)) { return $file; } return false; }
public static function init($cli) { register_shutdown_function(['\\Thin\\Bootstrap', 'finish']); Timer::start(); lib('app'); forever(); $storage_dir = STORAGE_PATH; if (!is_writable(STORAGE_PATH)) { die('Please give 0777 right to ' . STORAGE_PATH); } if (!is_dir(CACHE_PATH)) { File::mkdir(CACHE_PATH); } $dir = APPLICATION_PATH; Config::set('app.module.dir', APPLICATION_PATH); Config::set('mvc.dir', APPLICATION_PATH); Config::set('app.module.dirstorage', $dir . DS . 'storage'); Config::set('app.module.assets', $dir . DS . 'assets'); Config::set('app.module.config', $dir . DS . 'config'); Config::set('dir.raw.store', $storage_dir . DS . 'db'); Config::set('dir.ardb.store', $storage_dir . DS . 'db'); Config::set('dir.ephemere', $storage_dir . DS . 'ephemere'); Config::set('dir.flight.store', $storage_dir . DS . 'flight'); Config::set('dir.flat.store', $storage_dir . DS . 'flat'); Config::set('dir.cache.store', $storage_dir . DS . 'cache'); Config::set('dir.nosql.store', $storage_dir . DS . 'nosql'); Config::set('dir.module.logs', $storage_dir . DS . 'logs'); path('module', $dir); path('pages', $dir . DS . 'app' . DS . 'pages'); path('layouts', $dir . DS . 'app' . DS . 'layouts'); path('store', $storage_dir); path('config', Config::get('app.module.config')); path('cache', CACHE_PATH); loaderProject('entity'); loaderProject('system'); Alias::facade('DB', 'EntityProject', 'Thin'); Alias::facade('System', 'SystemProject', 'Thin'); System::Db()->firstOrCreate(['name' => SITE_NAME]); require_once path('config') . DS . 'application.php'; if (!$cli) { if (fnmatch('*/mytests', $_SERVER['REQUEST_URI'])) { self::tests(); } else { self::router(); } } }
/** * Upload one Files * * @param array $file * @return type */ private function uploadOne($path) { $file = new Core_ArrayObject(); event('file_url.preupload', $file); $file['errors'] = array(); $file->source = $path; $file->ext = pathinfo($path, PATHINFO_EXTENSION); strpos($this->options->path, ROOT) !== FALSE or $this->options->path = UPLOADS . DS . $this->options->path; if (!($data = file_get_contents($path))) { $file->errors[] = t('Не удаётся загрузить файл с указанного URL.'); } else { File::mkdir($this->path); if (!is_dir($this->path)) { $file['errors'][] = t('Папка загрузки <b>%s</b> не существует.', $this->options->path); } $file->name = $this->prepareFileName($this->rename ? $this->rename : basename($path)); $file->path = $this->path . DS . $file->name; if ($size = file_put_contents($file->path, $data)) { $file->size = $size; if ($this->options->allowed_types) { $types = is_string($this->options->allowed_types) ? new Core_ArrayObject(preg_split('#[^a-z]#', $this->options->allowed_types, -1, PREG_SPLIT_NO_EMPTY)) : $this->options->allowed_types; $ext = pathinfo($file->name, PATHINFO_EXTENSION); $result = FALSE; foreach ($types as $type) { $type == $ext && ($result = TRUE); } !$result && ($file['errors'][] = t('Разрешены только следующие типы файлов: <b>%s</b>.', NULL, $types->toString('</b>, <b>'))); } $this->options->maxsize && $this->checkMaxSize($file['size'], $this->options->maxsize); if (!$this->options->path) { $file['errors'][] = t('Путь для загрузки файла не указан.'); } if ($file['errors']) { unlink($file->path); return $file; } else { $this->uploaded = TRUE; $file->uri_full = File::pathToUri($file->path, ROOT); $file->uri = File::pathToUri($file->path, UPLOADS); return $file; } } } return FALSE; }
public function __construct($db = null, $table = null) { $this->db = is_null($db) ? SITE_NAME : $db; $this->table = is_null($table) ? 'core' : $table; $dir = Config::get('dir.flat.store', session_save_path()); if (!is_dir($dir)) { File::mkdir($dir); } $dir .= DS . Inflector::urlize(Inflector::uncamelize($this->db)); if (!is_dir($dir)) { File::mkdir($dir); } $this->file = $dir . DS . Inflector::urlize(Inflector::uncamelize($this->table)) . '.flat'; if (!file_exists($this->file)) { File::put($this->file, serialize([])); } Now::set('flat.collection.' . $this->db . '.' . $this->table, lib('sessy', [$this->db, $this->table, unserialize(File::read($this->file))])); }
public function upload($args = []) { $data = isAke($args, 'data', null); if (!$data) { $this->forbidden('no data'); } $name = isAke($args, 'name', null); if (!$name) { $this->forbidden('no name'); } $name = Utils::UUID() . '-' . $name; if (!is_dir($this->dir . 'upload')) { File::mkdir($this->dir . 'upload'); } $fileData = $this->dir . 'upload/' . $name; $url = core('request')->setUrl('/bucket/' . $this->bucket . '/' . $name); $this->putFile($fileData, $data); $this->success($url); }
public function config($arguments = array()) { if (count($arguments) < 4) { throw new BadMethodCallException('At least four arguments expected.'); } $credentials = explode(':', $arguments[3], 2); $username = $credentials[0]; $password = isset($credentials[1]) ? $credentials[1] : ''; $prefix = isset($arguments[4]) ? $arguments[4] : ''; $conf = array('default' => 'fluxbb_' . $arguments[0], 'connections' => array('fluxbb_' . $arguments[0] => array('driver' => $arguments[0], 'host' => $arguments[1], 'database' => $arguments[2], 'username' => $username, 'password' => $password, 'charset' => 'utf8', 'prefix' => $prefix))); $config = '<?php' . "\n\n" . 'return ' . var_export($conf, true) . ';' . "\n"; $conf_dir = path('app') . 'config/fluxbb/'; $conf_file = $conf_dir . 'database.php'; $dir_exists = File::mkdir($conf_dir); $file_exists = File::put($conf_dir . 'database.php', $config); if (!$dir_exists || !$file_exists) { throw new RuntimeException('Unable to write config file. Please create the file "' . $conf_file . '" with the following contents:' . "\n\n" . $config); } }
/** * Склеивает содержимое файлов * * @return string адрес файла */ protected function glue() { $filename = $this->options->filename or $this->genFilename(); $dir = CACHE . DS . 'assets'; is_dir($dir) or File::mkdir($dir); $file = $dir . DS . $filename; // Если файл не существует или пришло время обновления if (!$this->is_glued && (!file_exists($file) or time() - filemtime($file) > $this->options->refresh)) { $output = ''; // Парсим все файлы foreach ($this as $path) { $output .= $this->parse($path) . "\n"; } file_put_contents($file, $output); // Ставим флаг $this->is_glued = TRUE; } return $file; }