Exemplo n.º 1
0
 /**
  * Make app installation
  * @return bool
  */
 public function make()
 {
     $cName = ucfirst(Str::lowerCase($this->sysname));
     $cPath = 'Apps\\Controller\\Admin\\' . $cName;
     // if object class is not loaded - prevent install
     if (!class_exists($cPath) || !defined($cPath . '::VERSION')) {
         return false;
     }
     // get ext version
     $cVersion = constant($cPath . '::VERSION');
     if ($cVersion === null || Str::likeEmpty($cVersion)) {
         $cVersion = '1.0.0';
     }
     // save row to db
     $record = new AppRecord();
     $record->type = $this->_type;
     $record->sys_name = $cName;
     $record->name = '';
     $record->disabled = 1;
     $record->version = $cVersion;
     $record->save();
     // callback to install method in extension
     if (method_exists($cPath, 'install')) {
         call_user_func($cPath . '::install');
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * Make update actions
  */
 public function make()
 {
     // make query to ClassController::update(version)
     @forward_static_call_array([$this->_callback, 'update'], [$this->_record->version]);
     // update version in db
     $this->_record->version = $this->_record->getScriptVersion();
     $this->_record->save();
 }
Exemplo n.º 3
0
 /**
  * Load application table in memory & cache. All applications as object is available in $this->apps
  */
 private function loadAppsTable()
 {
     if (App::$Memory->get('table.apps') !== null) {
         $this->table = App::$Memory->get('table.apps');
     } else {
         $this->table = AppRecord::all();
         App::$Memory->set('table.apps', $this->table);
     }
 }
Exemplo n.º 4
0
 /**
  * Prepare configuratins before initialization
  */
 public function before()
 {
     parent::before();
     $configs = AppRecord::getConfigs('app', 'Content');
     // prevent null-type config data
     if ((int) $configs['gallerySize'] > 0) {
         $this->maxSize = (int) $configs['gallerySize'] * 1024;
     }
     if ((int) $configs['galleryResize'] > 0) {
         $this->maxResize = (int) $configs['galleryResize'];
     }
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
    </script>
</head>
<body>
<header class="container nopadding">
<?php 
$items = LanguageSwitcher::widget(['onlyArrayItems' => true]);
if (\App::$User->isAuth()) {
    $userId = \App::$User->identity()->getId();
    // show 'add content' button if current controller is Content and user add is enabled
    if (\App::$Request->getController() === 'Content' && (bool) AppRecord::getConfig('app', 'Content', 'userAdd')) {
        $items[] = ['type' => 'link', 'link' => ['content/update'], 'text' => '<i class="fa fa-plus"></i> ' . __('Add content'), 'html' => true, 'position' => 'right'];
    }
    $accountDropdown[] = ['link' => ['profile/show', $userId], 'text' => __('My profile')];
    $accountDropdown[] = ['link' => ['profile/messages'], 'text' => __('Messages') . ' <span class="badge" id="pm-count-block">0</span>', 'html' => true, '!secure' => true];
    $accountDropdown[] = ['link' => ['profile/notifications'], 'text' => __('Notifications') . ' <span class="badge" id="notify-count-block">0</span>', 'html' => true, '!secure' => true];
    if ((bool) AppRecord::getConfig('app', 'Content', 'userAdd')) {
        $accountDropdown[] = ['link' => ['content/my'], 'text' => __('My content')];
    }
    $accountDropdown[] = ['link' => ['profile/settings'], 'text' => __('Settings')];
    $items[] = ['type' => 'dropdown', 'text' => '<i class="fa fa-user"></i> ' . __('Account') . ' <span class="badge" id="summary-count-block">0</span>', 'html' => true, '!secure' => true, 'position' => 'right', 'items' => $accountDropdown];
    if (\App::$User->identity()->getRole()->can('Admin/Main/Index')) {
        $items[] = ['type' => 'link', 'link' => \App::$Alias->scriptUrl . '/admin/', 'text' => '<i class="fa fa-cogs"></i> Admin', 'position' => 'right', 'html' => true];
    }
    $items[] = ['type' => 'link', 'link' => ['user/logout'], 'text' => '<i class="fa fa-user-times"></i> ' . __('Logout'), 'html' => true, 'position' => 'right'];
} else {
    $items[] = ['type' => 'link', 'link' => ['user/login'], 'text' => '<i class="fa fa-sign-in"></i> ' . __('Sign in'), 'position' => 'right', 'html' => true];
    $items[] = ['type' => 'link', 'link' => ['user/signup'], 'text' => '<i class="fa fa-check-square-o"></i> ' . __('Sign up'), 'position' => 'right', 'html' => true];
}
echo Navbar::display(['nav' => ['class' => 'navbar-inverse', 'style' => 'padding-left: 0'], 'property' => ['id' => 'headmenu', 'class' => 'navbar-nav'], 'activeOrder' => 'action', 'container' => 'container', 'collapseId' => 'collapse-object', 'items' => $items]);
?>
</header>
Exemplo n.º 8
0
 /**
  * Save extension configs
  * @param array $configs
  * @return bool
  */
 public function setConfigs(array $configs = null)
 {
     if ($configs === null || !Obj::isArray($configs) || count($configs) < 1) {
         return false;
     }
     // get extension is based on it type
     $id = 0;
     if ($this->type === 'app') {
         $id = $this->application->id;
     } elseif ($this->type === 'widget') {
         $id = $this->widget->id;
     }
     // get active record relation for this id
     $obj = \Apps\ActiveRecord\App::find($id);
     if ($obj === null) {
         return false;
     }
     // save data in db
     $obj->configs = $configs;
     $obj->save();
     return true;
 }
Exemplo n.º 9
0
>
                        <a href="#"><i class="fa fa-fire fa-fw"></i> <?php 
echo __('System');
?>
<span class="fa arrow"></span></a>
                        <?php 
echo Listing::display(['type' => 'ul', 'property' => ['class' => 'nav nav-second-level'], 'items' => [['type' => 'link', 'link' => ['main/settings'], 'text' => '<i class="fa fa-cogs"></i> ' . __('Settings'), 'html' => true], ['type' => 'link', 'link' => ['main/files'], 'text' => '<i class="fa fa-file-o"></i> ' . __('Files'), 'html' => true], ['type' => 'link', 'link' => ['main/antivirus'], 'text' => '<i class="fa fa-shield"></i> ' . __('Antivirus'), 'html' => true], ['type' => 'link', 'link' => ['main/routing'], 'text' => '<i class="fa fa-code"></i> ' . __('Routing'), 'html' => true], ['type' => 'link', 'link' => ['main/updates'], 'text' => '<i class="fa fa-gavel"></i> ' . __('Updates'), 'html' => true]]]);
?>
                        <!-- /.nav-second-level -->
                    </li>
                    <?php 
$extTable = null;
if (method_exists($this, 'getTable')) {
    $extTable = $this->getTable();
} else {
    $extTable = \Apps\ActiveRecord\App::all();
}
$appMenuItems = null;
$widgetMenuItems = null;
$appControllers = [];
$widgetControllers = [];
foreach ($extTable as $item) {
    $menuItem = ['type' => 'link', 'link' => [Str::lowerCase($item->sys_name) . '/index'], 'text' => $item->getLocaleName() . (!$item->checkVersion() ? ' <i class="fa fa-wrench" style="color: #ffbd26;"></i>' : null), 'html' => true];
    if ($item->type === 'app') {
        $appControllers[] = $item->sys_name;
        $appMenuItems[] = $menuItem;
    } elseif ($item->type === 'widget') {
        $widgetControllers[] = $item->sys_name;
        $widgetMenuItems[] = $menuItem;
    }
}
Exemplo n.º 10
0
 /**
  * Install function callback
  */
 public static function install()
 {
     // prepare application information to extend inserted before row to table apps
     $appData = new \stdClass();
     $appData->configs = ['textCfg' => 'Some value', 'intCfg' => 10, 'boolCfg' => true];
     $appData->name = ['ru' => 'Демо приложение', 'en' => 'Demo app'];
     // get current app row from db (like SELECT ... WHERE type='app' and sys_name='Demoapp')
     $query = AppRecord::where('type', '=', 'app')->where('sys_name', '=', 'Demoapp');
     if ($query->count() !== 1) {
         return;
     }
     $query->update(['name' => Serialize::encode($appData->name), 'configs' => Serialize::encode($appData->configs), 'disabled' => 0]);
     // create your own table in database
     App::$Database->schema()->create('demos', function ($table) {
         $table->increments('id');
         $table->string('text', 1024);
         $table->timestamps();
     });
     $now = Date::convertToDatetime(time(), Date::FORMAT_SQL_DATE);
     // insert some data in table, id|text columns, id is autoincrement
     App::$Database->connection()->table('demos')->insert([['text' => 'Hello world 1', 'created_at' => $now, 'updated_at' => $now], ['text' => 'Hello world 2', 'created_at' => $now, 'updated_at' => $now]]);
 }
Exemplo n.º 11
0
 /**
  * Get commentaries count for pathway. Pathway should be array [itemId => pathway]
  * @throws NativeException
  * @return string
  */
 public function actionCount()
 {
     // set headers
     $this->setJsonHeader();
     // get configs
     $configs = AppRecord::getConfigs('widget', 'Comments');
     // get path array from request
     $path = $this->request->query->get('path');
     if (!Obj::isArray($path) || count($path) < 1) {
         throw new NativeException('Wrong query params');
     }
     $count = [];
     // for each item in path array calculate comments count
     foreach ($path as $id => $uri) {
         $query = CommentPost::where('pathway', '=', $uri)->where('moderate', '=', 0);
         // check if comments is depend of language locale
         if ((int) $configs['onlyLocale'] === 1) {
             $query = $query->where('lang', '=', $this->request->getLanguage());
         }
         // set itemId => count
         $count[(int) $id] = $query->count();
     }
     // render json response
     return json_encode(['status' => 1, 'count' => $count]);
 }
Exemplo n.º 12
0
 /**
  * Allow turn on/off widget
  * @param string $controllerName
  * @return string
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws ForbiddenException
  * @throws \Ffcms\Core\Exception\SyntaxException
  */
 public function actionTurn($controllerName)
 {
     // get controller name & find object in db
     $controllerName = ucfirst(Str::lowerCase($controllerName));
     $record = \Apps\ActiveRecord\App::where('sys_name', '=', $controllerName)->where('type', '=', 'widget')->first();
     // check if widget admin controller exists
     if ($record === null || (int) $record->id < 1) {
         throw new ForbiddenException('Widget is not founded');
     }
     // initialize turn on/off model
     $model = new FormTurn($record);
     if ($model->send()) {
         $model->update();
         App::$Session->getFlashBag()->add('success', __('Widget status was changed'));
     }
     // render view
     return $this->view->render('turn', ['widget' => $record, 'model' => $model]);
 }
Exemplo n.º 13
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);
 }
Exemplo n.º 14
0
 /**
  * Allow turn on/off applications
  * @param $controllerName
  * @return string
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws ForbiddenException
  * @throws \Ffcms\Core\Exception\SyntaxException
  */
 public function actionTurn($controllerName)
 {
     $controllerName = ucfirst(Str::lowerCase($controllerName));
     $search = \Apps\ActiveRecord\App::where('sys_name', '=', $controllerName)->where('type', '=', 'app')->first();
     if ($search === null || (int) $search->id < 1) {
         throw new ForbiddenException('App is not founded');
     }
     $model = new FormTurn($search);
     if ($model->send()) {
         $model->update();
         App::$Session->getFlashBag()->add('success', __('Application status was changed'));
     }
     return $this->view->render('turn', ['app' => $search, 'model' => $model]);
 }
Exemplo n.º 15
0
 /**
  * Change user rating action
  * @throws ForbiddenException
  * @throws NativeException
  * @throws NotFoundException
  * @return string
  */
 public function actionChangerating()
 {
     if (!App::$User->isAuth()) {
         throw new ForbiddenException('Auth required');
     }
     $this->setJsonHeader();
     // get operation type and target user id
     $target_id = (int) $this->request->get('target');
     $type = $this->request->get('type');
     // check type of query
     if ($type !== '+' && $type !== '-') {
         throw new NativeException('Wrong data');
     }
     // check if passed user id is exist
     if (!Obj::isLikeInt($target_id) || $target_id < 1 || !App::$User->isExist($target_id)) {
         throw new NotFoundException('Wrong user info');
     }
     $cfg = \Apps\ActiveRecord\App::getConfigs('app', 'Profile');
     // check if rating is enabled for website
     if ((int) $cfg['rating'] !== 1) {
         throw new NativeException('Rating is disabled');
     }
     // get target and sender objects
     $target = App::$User->identity($target_id);
     $sender = App::$User->identity();
     // disable self-based changes ;)
     if ($target->getId() === $sender->getId()) {
         throw new ForbiddenException('Self change prevented');
     }
     // check delay
     $diff = Date::convertToTimestamp(time() - $cfg['ratingDelay'], Date::FORMAT_SQL_TIMESTAMP);
     $query = ProfileRating::where('target_id', '=', $target->getId())->where('sender_id', '=', $sender->getId())->where('created_at', '>=', $diff)->orderBy('id', 'DESC');
     if ($query !== null && $query->count() > 0) {
         throw new ForbiddenException('Delay required');
     }
     // delay is ok, lets insert a row
     $record = new ProfileRating();
     $record->target_id = $target->getId();
     $record->sender_id = $sender->getId();
     $record->type = $type;
     $record->save();
     // update target profile
     $profile = $target->getProfile();
     if ($type === '+') {
         $profile->rating += 1;
     } else {
         $profile->rating -= 1;
     }
     $profile->save();
     return json_encode(['status' => 1, 'data' => 'ok']);
 }