예제 #1
0
 /**
  * Find all bootatble instances and set it to object map
  */
 public function compileBootableClasses()
 {
     // list app root's
     foreach ($this->appRoots as $app) {
         $app .= '/Apps/Controller/' . env_name;
         $files = File::listFiles($app, ['.php'], true);
         foreach ($files as $file) {
             // define full class name with namespace
             $class = 'Apps\\Controller\\' . env_name . '\\' . Str::cleanExtension($file);
             // check if class exists (must be loaded over autoloader), boot method exist and this is controller instanceof
             if (class_exists($class) && method_exists($class, 'boot') && is_a($class, 'Ffcms\\Core\\Arch\\Controller', true)) {
                 $this->objects[] = $class;
             }
         }
     }
     // list widget root's
     foreach ($this->widgetRoots as $widget) {
         $widget .= '/Widgets/' . env_name;
         // widgets are packed in directory, classname should be the same with root directory name
         $dirs = Directory::scan($widget, GLOB_ONLYDIR, true);
         if (!Obj::isArray($dirs)) {
             continue;
         }
         foreach ($dirs as $instance) {
             $class = 'Widgets\\' . env_name . '\\' . $instance . '\\' . $instance;
             if (class_exists($class) && method_exists($class, 'boot') && is_a($class, 'Ffcms\\Core\\Arch\\Widget', true)) {
                 $this->objects[] = $class;
             }
         }
     }
 }
예제 #2
0
파일: Main.php 프로젝트: phpffcms/ffcms
 /**
  * Scan available permissions and write to cfg file
  * @return string
  */
 public function actionBuildperms()
 {
     // default permissions
     $permissions = ['global/write', 'global/modify', 'global/file', 'global/all'];
     // admin controllers
     $AdminAppControllers = '/Apps/Controller/Admin/';
     // scan directory
     $scan = File::listFiles($AdminAppControllers, ['.php']);
     foreach ($scan as $file) {
         $className = Str::firstIn(Str::lastIn($file, DIRECTORY_SEPARATOR, true), '.');
         // read as plain text
         $byte = File::read($file);
         preg_match_all('/public function action(\\w*?)\\(/', $byte, $matches);
         // matches[0] contains all methods ;)
         if (Obj::isArray($matches[1]) && count($matches[1]) > 0) {
             foreach ($matches[1] as $perm) {
                 $permissions[] = 'Admin/' . $className . '/' . $perm;
             }
         }
     }
     // prepare save string
     $stringSave = "<?php \n\nreturn " . var_export($permissions, true) . ';';
     File::write('/Private/Config/Permissions.php', $stringSave);
     return 'Permissions configuration is successful updated! Founded permissions: ' . count($permissions);
 }
예제 #3
0
 /**
  * Find update files with sql queries
  */
 public function findUpdateFiles()
 {
     // find all file with update sql queries between $dbVersion<->scriptVersion (dbVer <= x <= scriptVer)
     $all = File::listFiles('/Private/Database/Updates/', ['.php'], true);
     foreach ($all as $file) {
         $file = Str::cleanExtension(basename($file));
         // $file="3.0.0-3.0.1" become to $start = 3.0.0,$end=3.0.1
         list($start, $end) = explode('-', $file);
         // true: start <= db & script >= $end
         if (version_compare($this->dbVersion, $start) !== 1 && version_compare($this->scriptVersion, $end) !== -1) {
             $this->updateQueries[] = $file;
         }
     }
     sort($this->updateQueries);
 }
예제 #4
0
 /**
  * Try to find sitemap indexes in storage directory
  * @throws SyntaxException
  */
 public function before()
 {
     if (!Directory::exist(static::INDEX_PATH)) {
         throw new SyntaxException(__('Directory %dir% for sitemaps is not exists', ['dir' => static::INDEX_PATH]));
     }
     $scan = File::listFiles(static::INDEX_PATH, ['.xml'], true);
     if (Obj::isArray($scan)) {
         foreach ($scan as $file) {
             if ($this->_lang !== null && !Str::contains('.' . $this->_lang, $file)) {
                 continue;
             }
             $this->files[] = static::INDEX_PATH . '/' . $file;
         }
     }
 }
예제 #5
0
 /**
  * Browse files from ckeditor
  * @param string $type
  * @throws NativeException
  * @throws \Ffcms\Core\Exception\SyntaxException
  */
 public function actionBrowse($type)
 {
     $files = null;
     $relative = null;
     // check if request type is defined
     if ($this->allowedExt[$type] === null || !Obj::isArray($this->allowedExt[$type])) {
         throw new NativeException('Hack attempt');
     }
     // list files in directory
     $files = File::listFiles('/upload/' . $type, $this->allowedExt[$type]);
     // absolute path to relative URI
     foreach ($files as $file) {
         $newName = Str::sub($file, Str::length(root) + 1);
         $relative[] = trim(Str::replace(DIRECTORY_SEPARATOR, '/', $newName), '/');
     }
     // generate response
     return App::$View->render('editor/browse', ['callbackName' => App::$Security->strip_tags(App::$Request->query->get('CKEditor')), 'callbackId' => (int) App::$Request->query->get('CKEditorFuncNum'), 'files' => $relative, 'type' => $type], __DIR__);
 }
예제 #6
0
 /**
  * Prepare model attributes from passed objects
  * @throws ForbiddenException
  */
 public function before()
 {
     $this->id = $this->_content->id;
     $this->title = $this->_content->getLocaled('title');
     $this->text = $this->_content->getLocaled('text');
     // check if title and text are exists
     if (Str::length($this->title) < 1 || Str::length($this->text) < 1) {
         throw new ForbiddenException();
     }
     // get meta data
     $this->metaTitle = $this->_content->getLocaled('meta_title');
     if (Str::likeEmpty($this->metaTitle)) {
         $this->metaTitle = $this->title;
     }
     $this->metaDescription = $this->_content->getLocaled('meta_description');
     $tmpKeywords = $this->_content->getLocaled('meta_keywords');
     $this->metaKeywords = explode(',', $tmpKeywords);
     // set content date, category data
     $this->createDate = Date::humanize($this->_content->created_at);
     $this->catName = $this->_category->getLocaled('title');
     $this->catPath = $this->_category->path;
     // set user data
     if (App::$User->isExist($this->_content->author_id)) {
         $this->authorId = $this->_content->author_id;
         $profile = App::$User->identity($this->authorId)->getProfile();
         $this->authorName = $profile->getNickname();
     }
     $this->source = $this->_content->source;
     $this->views = $this->_content->views + 1;
     // check for dependence, add '' for general cat, ex: general/depend1/depend2/.../depend-n
     $catNestingArray = Arr::merge([0 => ''], explode('/', $this->catPath));
     if ($catNestingArray > 1) {
         // latest element its a current nesting level, lets cleanup it
         array_pop($catNestingArray);
         $catNestingPath = null;
         foreach ($catNestingArray as $cPath) {
             $catNestingPath .= $cPath;
             // try to find category by path in db
             $record = ContentCategory::getByPath($catNestingPath);
             if ($record !== null && $record->count() > 0) {
                 // if founded - add to nesting data
                 $this->catNesting[] = ['name' => $record->getLocaled('title'), 'path' => $record->path];
             }
             if (!Str::likeEmpty($catNestingPath)) {
                 $catNestingPath .= '/';
             }
         }
     }
     // build array of category nesting level
     $this->catNesting[] = ['name' => $this->catName, 'path' => $this->catPath];
     // get gallery images and poster data
     $galleryPath = '/upload/gallery/' . $this->_content->id;
     // check if gallery folder is exist
     if (Directory::exist($galleryPath)) {
         $originImages = File::listFiles($galleryPath . '/orig/', ['.jpg', '.png', '.gif', '.jpeg', '.bmp', '.webp'], true);
         // generate poster data
         if (Arr::in($this->_content->poster, $originImages)) {
             // original poster
             $posterName = $this->_content->poster;
             $this->posterFull = $galleryPath . '/orig/' . $posterName;
             if (!File::exist($this->posterFull)) {
                 $this->posterFull = null;
             }
             // thumb poster
             $posterSplit = explode('.', $posterName);
             array_pop($posterSplit);
             $posterCleanName = implode('.', $posterSplit);
             $this->posterThumb = $galleryPath . '/thumb/' . $posterCleanName . '.jpg';
             if (!File::exist($this->posterThumb)) {
                 $this->posterThumb = null;
             }
         }
         // generate full gallery
         foreach ($originImages as $image) {
             $imageSplit = explode('.', $image);
             array_pop($imageSplit);
             $imageClearName = implode('.', $imageSplit);
             // skip image used in poster
             if (Str::startsWith($imageClearName, $this->_content->poster)) {
                 continue;
             }
             $thumbPath = $galleryPath . '/thumb/' . $imageClearName . '.jpg';
             if (File::exist($thumbPath)) {
                 $this->galleryItems[$thumbPath] = $galleryPath . '/orig/' . $image;
             }
         }
     }
     // set rating data
     $this->rating = $this->_content->rating;
     $ignoredRate = App::$Session->get('content.rate.ignore');
     $this->canRate = true;
     if (Obj::isArray($ignoredRate) && Arr::in((string) $this->id, $ignoredRate)) {
         $this->canRate = false;
     }
     if (!App::$User->isAuth()) {
         $this->canRate = false;
     } elseif ($this->authorId === App::$User->identity()->getId()) {
         $this->canRate = false;
     }
     // update views count
     $this->_content->views += 1;
     $this->_content->save();
 }
예제 #7
0
 /**
  * Prepare scan list on first run. Scan directory's and save as JSON
  */
 private function prepareScanlist()
 {
     $files = (object) File::listFiles(root, $this->affectedExt);
     File::write('/Private/Antivirus/ScanFiles.json', json_encode($files));
 }