예제 #1
0
파일: FileSet.php 프로젝트: cyantree/grout
 protected function _getNewId()
 {
     do {
         $id = StringTools::random(16, 'abcdefghijklmnopqrstuvwxyz0123456789');
     } while (is_file($this->_getPath($id)));
     return $id;
 }
예제 #2
0
 public function load($id = null, $checkSession = true)
 {
     if ($id) {
         $this->id = $id;
     } else {
         if ($this->useCookie && isset($_COOKIE[$this->name]) && preg_match('/^[0-9a-zA-Z]{32}$/', $_COOKIE[$this->name])) {
             $this->id = $_COOKIE[$this->name];
         } else {
             $this->id = StringTools::random(32);
         }
     }
     session_id($this->id);
     session_start();
     $this->isNew = !isset($_SESSION['_data']);
     if ($this->useCookie) {
         setcookie($this->name, $this->id, time() + $this->expirationTime * 4, $this->cookiePath, $this->cookieDomain, $this->cookieSecure, $this->cookieHttpOnly);
     }
     if (!$this->isNew) {
         if ($checkSession && !$this->checkSession()) {
             $this->reset();
         } else {
             $this->data = unserialize($_SESSION['_data']);
         }
     } else {
         $this->data = null;
     }
 }
예제 #3
0
 public function __construct($content = null, $escapeContent = true, $name = null)
 {
     parent::__construct();
     if ($name === null) {
         $name = StringTools::random(32);
     }
     $this->name = $name;
     $this->content = $content;
     $this->escapeContent = $escapeContent;
 }
예제 #4
0
 public function queryTask(Task $t)
 {
     if ($t->id === null) {
         $t->id = StringTools::random(16);
     }
     $t->manager = null;
     $t->onSerialize();
     $file = $this->directory . str_pad($t->priority, 3, '0', STR_PAD_LEFT) . '_' . $t->id . '.tsk';
     file_put_contents($file, serialize($t));
     if ($t->executeAt) {
         touch($file, $t->executeAt);
     }
     /** @var $t Task */
     $t->manager = $this;
 }
예제 #5
0
 public function render($mode)
 {
     $isChecked = $this->_data == $this->value;
     if ($mode == Set::MODE_EXPORT) {
         return $isChecked ? $this->label : '';
     }
     $attributes = $isChecked ? ' checked="checked"' : '';
     if ($mode == Set::MODE_SHOW || $mode == Set::MODE_LIST || $mode == Set::MODE_DELETE || !$this->editable) {
         $attributes .= ' disabled="disabled"';
     }
     $id = 'c' . StringTools::random(15);
     $c = '<input id="' . $id . '" type="checkbox" name="' . $this->name . '" value="' . StringTools::escapeHtml($this->value) . '"' . $attributes . ' />';
     if ($this->label != '') {
         $c .= '<label for="' . $id . '">' . StringTools::escapeHtml($this->label) . '</label>';
     }
     return $c;
 }
예제 #6
0
파일: Commands.php 프로젝트: cyantree/grout
 public static function onProjectCreated(Event $e)
 {
     $io = $e->getIO();
     //        return;
     $folder = 'modules/AppModule/';
     if (!is_dir($folder)) {
         $io->write("Couldn't find AppModule. Configuration will be stopped.");
         return;
     }
     $io->write('Configurating AppBaseConfig.php');
     $file = $folder . 'Configs/AppBaseConfig.php';
     $content = file_get_contents($file);
     $content = str_replace('###ACCESS_KEY###', StringTools::random(32), $content);
     file_put_contents($file, $content);
     $io->write('Configurating AppModule.php');
     $file = $folder . 'AppModule.php';
     $content = file_get_contents($file);
     $content = str_replace(array('###AUTH_USER###', '###AUTH_PASS###'), array('console_' . mt_rand(1000, 9999), StringTools::random(16)), $content);
     file_put_contents($file, $content);
     $io->write('Your grout application has been configured.');
 }
예제 #7
0
파일: Bucket.php 프로젝트: cyantree/grout
 public static function createId()
 {
     return StringTools::random(32);
 }
예제 #8
0
 public function createFromContent($content, $expirationDate = 86400, $id = null, $metadata = null, $originalFilename = null)
 {
     if ($this->filesExpire) {
         $t = time();
         if ($expirationDate < 1000000000) {
             $expirationDate += $t;
         }
     } else {
         $t = $expirationDate = 0;
     }
     $f = new TemporaryFile();
     $f->storeMetadata = $this->storeMetadata;
     if ($id !== null) {
         $f->id = $id;
         $f->path = $this->getPathById($id, false);
     } else {
         do {
             $f->id = $this->idPrefix . StringTools::random($this->idLength, $this->idChars) . $this->idSuffix;
             $f->path = $this->getPathById($f->id, false);
             $exists = is_file($f->path) && (!$this->filesExpire || filemtime($f->path) > $t);
         } while ($exists);
     }
     $f->originalFilename = $originalFilename;
     $f->expires = $expirationDate;
     $f->url = $this->baseUrl . $f->id . $this->extension;
     $f->metadata = $metadata;
     if ($this->pathChunkSize) {
         $dir = dirname($f->path);
         if (!is_dir($dir)) {
             FileTools::createDirectory($dir);
         }
     }
     file_put_contents($f->path, $content);
     $f->save();
     return $f;
 }
예제 #9
0
 protected function _finishForm($resetData = false)
 {
     $this->formData->id = StringTools::random(32);
     if ($resetData) {
         $this->formData->reset();
         $this->formData->data = $this->data = $this->_createDataObject();
     } else {
         $this->formData->resetOnNextAccess = true;
     }
     $this->formData->finished = true;
 }