Beispiel #1
0
 /**
  * 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);
 }
Beispiel #2
0
 /**
  * Check is current instance of application is enabled and can be executed
  * @return bool
  */
 public function isEnabled()
 {
     $appName = App::$Request->getController();
     // if app class extend current class we can get origin name
     $nativeName = Str::lastIn(get_class($this), '\\', true);
     // check if this controller is enabled
     $this->application = AppRecord::getItem('app', [$appName, $nativeName]);
     // not exist? false
     if ($this->application === null) {
         return false;
     }
     // check if disabled (0 = enabled, anything else = on)
     return (int) $this->application->disabled === 0;
 }
Beispiel #3
0
 /**
  * Build apps/widgets table in local property
  */
 private function buildExtensions()
 {
     $controller = Str::lastIn(get_class($this), '\\', true);
     foreach ($this->table as $item) {
         if ($item->type === 'app') {
             $this->applications[] = $item;
             if ($this->type === 'app' && $item->sys_name === $controller) {
                 $this->application = $item;
             }
         } elseif ($item->type === 'widget') {
             $this->widgets[] = $item;
             if ($this->type === 'widget' && $item->sys_name === $controller) {
                 $this->widget = $item;
             }
         }
     }
 }
Beispiel #4
0
 /**
  * Check if widget is enabled
  * @param string|null $class
  * @return bool
  */
 public static function enabled($class = null)
 {
     self::$class = $class !== null ? $class : get_called_class();
     // get widget classname from passed data or from stacttrace
     if (!class_exists(self::$class)) {
         App::$Debug->addMessage(__('Widget autoload is disabled for class: %class%', ['class' => self::$class]));
         return false;
     }
     // get widget name
     self::$name = Str::lastIn(self::$class, '\\', true);
     $wData = AppRecord::getItem('widget', self::$name);
     // widget is not founded, deny run
     if ($wData === null) {
         if (App::$Debug !== null) {
             App::$Debug->addMessage(__('Widget with name %name%[%class%] is not found', ['name' => self::$name, 'class' => self::$class]));
         }
         return false;
     }
     // if widget is disabled - lets return nothing
     return !(bool) $wData->disabled;
 }
Beispiel #5
0
 /**
  * Build pathway from array $to. Example: ['controller/action', 'id', 'add', ['get' => 'value'], '#anchor']
  * @param array $to
  * @param bool $encode
  * @return string|null
  */
 public static function buildPathway(array $to = null, $encode = true)
 {
     // if empty passed - let show main page
     if ($to === null) {
         return null;
     }
     $response = Str::lowerCase(trim($to[0], '/'));
     // controller/action
     list($controller, $action) = explode('/', $response);
     $routing = App::$Properties->getAll('Routing');
     // sounds like dynamic callback
     if (Str::startsWith('@', $controller)) {
         $controller = trim($controller, '@');
         // search callback in properties
         if (isset($routing['Callback'][env_name]) && Arr::in($controller, $routing['Callback'][env_name])) {
             $pathInject = array_search($controller, $routing['Callback'][env_name]);
             // if path is founded - lets set source
             if ($pathInject !== false) {
                 $controller = Str::lowerCase($pathInject);
             }
         }
         // if controller still looks like path injection - define last entity like controller name
         if (Str::contains('\\', $controller)) {
             $controller = Str::lastIn($controller, '\\', true);
         }
         $response = $controller . '/' . $action;
     }
     // check if controller and action is defined
     if (Str::likeEmpty($controller) || Str::likeEmpty($action)) {
         return null;
     }
     // id is defined?
     if (isset($to[1]) && !Str::likeEmpty($to[1])) {
         $response .= '/' . self::safeUri($to[1], $encode);
     }
     // add param is defined?
     if (isset($to[2]) && !Str::likeEmpty($to[2])) {
         $response .= '/' . self::safeUri($to[2], $encode);
     }
     // try to find static alias
     if (isset($routing['Alias'][env_name]) && Arr::in('/' . $response, $routing['Alias'][env_name])) {
         $pathAlias = array_search('/' . $response, $routing['Alias'][env_name]);
         if ($pathAlias !== false) {
             $response = Str::lowerCase(trim($pathAlias, '/'));
         }
     }
     // parse get attributes
     if (isset($to[3]) && Obj::isArray($to[3]) && count($to[3]) > 0) {
         // check if anchor bindig is exist
         $anchor = false;
         if (isset($to[3]['#']) && Obj::isString($to[3]['#']) && Str::startsWith('#', $to[3]['#'])) {
             $anchor = $to[3]['#'];
             unset($to[3]['#']);
         }
         $queryString = http_build_query($to[3]);
         if (Str::length($queryString) > 0) {
             $response .= '?' . http_build_query($to[3]);
         }
         if ($anchor !== false) {
             $response .= $anchor;
         }
     }
     // parse anchor link part #item-related-id-1
     if (isset($to[4]) && Obj::isString($to[4]) && Str::startsWith('#', $to[4])) {
         $response .= $to[4];
     }
     return $response;
 }
Beispiel #6
0
        <?php 
echo \Ffcms\Core\Helper\HTML\Bootstrap\Nav::display(['property' => ['class' => 'nav-tabs'], 'tabAnchor' => 'n', 'items' => [['type' => 'link', 'text' => __('Images'), 'link' => ['ckbrowser/browse', 'images', null, ['CKEditor' => $callbackName, 'CKEditorFuncNum' => $callbackId]]], ['type' => 'link', 'text' => __('Flash'), 'link' => ['ckbrowser/browse', 'flash', null, ['CKEditor' => $callbackName, 'CKEditorFuncNum' => $callbackId]]], ['type' => 'link', 'text' => __('Files'), 'link' => ['ckbrowser/browse', 'files', null, ['CKEditor' => $callbackName, 'CKEditorFuncNum' => $callbackId]]]]]);
?>
    </div>
</div>

<div class="row" style="padding-top: 10px;margin-left: 5px;">
    <?php 
if ($files !== null && count($files) > 0) {
    ?>
        <?php 
    foreach ($files as $file) {
        ?>
            <div class="col-md-2 well" style="margin-left: 5px;">
                <div class="text-center"><strong><?php 
        echo Str::lastIn($file, '/', true);
        ?>
</strong></div>
                <?php 
        if ($type === 'images') {
            ?>
                <img src="<?php 
            echo \App::$Alias->scriptUrl . '/' . $file;
            ?>
" class="img-responsive image-item" />
                <?php 
        } elseif ($type === 'flash') {
            ?>
                    <div class="text-center"><i class="fa fa-file-video-o fa-4x"></i></div>
                <?php 
        } else {
Beispiel #7
0
 /**
  * Try to download and parse remote avatar
  * @param string $url
  * @param int $userId
  */
 protected function parseAvatar($url, $userId)
 {
     // check if user is defined
     if ((int) $userId < 1) {
         return;
     }
     // check remote image extension
     $imageExtension = Str::lastIn($url, '.', true);
     if (!Arr::in($imageExtension, ['png', 'gif', 'jpg', 'jpeg'])) {
         return;
     }
     // try to get image binary data
     $imageContent = Url::download($url);
     if ($imageContent === null || Str::likeEmpty($imageContent)) {
         return;
     }
     // write image to filesystem
     $imagePath = '/upload/user/avatar/original/' . $userId . '.' . $imageExtension;
     $write = File::write($imagePath, $imageContent);
     if ($write === false) {
         return;
     }
     // try to write and resize file
     try {
         $fileObject = new FileObject(root . $imagePath);
         $avatarUpload = new FormAvatarUpload();
         $avatarUpload->resizeAndSave($fileObject, $userId, 'small');
         $avatarUpload->resizeAndSave($fileObject, $userId, 'medium');
         $avatarUpload->resizeAndSave($fileObject, $userId, 'big');
     } catch (\Exception $e) {
         if (App::$Debug) {
             App::$Debug->addException($e);
         }
     }
 }
Beispiel #8
0
 /**
  * Recursive scan directory, based on $path and allowed extensions $ext or without it
  * @param string $path
  * @param array $ext
  * @param bool $returnRelative
  * @param $files
  * @return array
  */
 public static function listFiles($path, array $ext = null, $returnRelative = false, &$files = [])
 {
     $path = Normalize::diskFullPath($path);
     if (!Directory::exist($path)) {
         return [];
     }
     $dir = opendir($path . '/.');
     while ($item = readdir($dir)) {
         if (is_file($sub = $path . '/' . $item)) {
             $item_ext = Str::lastIn($item, '.');
             if ($ext === null || Arr::in($item_ext, $ext)) {
                 if ($returnRelative) {
                     $files[] = $item;
                 } else {
                     $files[] = $path . DIRECTORY_SEPARATOR . $item;
                 }
             }
         } else {
             if ($item !== '.' && $item !== '..') {
                 self::listFiles($sub, $ext, $returnRelative, $files);
             }
         }
     }
     return $files;
 }
Beispiel #9
0
 /**
  * Get widget configs from admin part as array $cfg=>$value
  * @return array|null|string
  */
 public function getConfigs()
 {
     $realName = Str::lastIn(self::$class, '\\', true);
     return AppRecord::getConfigs('widget', $realName);
 }
Beispiel #10
0
 /**
  * Remove items from gallery (preview+full)
  * @param int $id
  * @param string $file
  * @throws ForbiddenException
  * @throws NativeException
  * @return string
  */
 public function actionGallerydelete($id, $file = null)
 {
     if ($file === null || Str::likeEmpty($file)) {
         $file = (string) $this->request->query->get('file', null);
     }
     // check passed data
     if (Str::likeEmpty($file) || !Obj::isLikeInt($id)) {
         throw new NativeException('Wrong input data');
     }
     // check passed file extension
     $fileExt = Str::lastIn($file, '.', true);
     $fileName = Str::firstIn($file, '.');
     if (!Arr::in($fileExt, $this->allowedExt)) {
         throw new ForbiddenException('Wrong file extension');
     }
     // generate path
     $thumb = '/upload/gallery/' . $id . '/thumb/' . $fileName . '.jpg';
     $full = '/upload/gallery/' . $id . '/orig/' . $file;
     // check if file exists and remove
     if (File::exist($thumb) || File::exist($full)) {
         File::remove($thumb);
         File::remove($full);
     } else {
         throw new NativeException('Image is not founded');
     }
     return json_encode(['status' => 1, 'msg' => 'Image is removed']);
 }