/** * 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; }
/** * Set default values from database record */ public function before() { // set data from db record $this->title = $this->_record->title; $this->text = $this->_record->text; $this->path = $this->_record->path; $this->categoryId = $this->_record->category_id; // set current user id $this->authorId = App::$User->identity()->getId(); // set true if it is a new content item if ($this->_record->id === null || (int) $this->_record->id < 1) { $this->_new = true; } // set random path slug if not defined if ($this->path === null || Str::likeEmpty($this->path)) { $randPath = date('d-m-Y') . '-' . Str::randomLatin(mt_rand(8, 12)); $this->path = Str::lowerCase($randPath); } }
/** * Get input param for current model form based on param name and request method * @param string $param * @param string|null $method * @return string|null|array * @throws \InvalidArgumentException */ public function getRequest($param, $method = null) { // build param query for http foundation request $paramQuery = $this->getFormName(); if (Str::contains('.', $param)) { foreach (explode('.', $param) as $item) { $paramQuery .= '[' . $item . ']'; } } else { $paramQuery .= '[' . $param . ']'; } if ($method === null) { $method = $this->_sendMethod; } // get request based on method and param query $method = Str::lowerCase($method); switch ($method) { case 'get': return App::$Request->query->get($paramQuery, null, true); case 'post': return App::$Request->request->get($paramQuery, null, true); case 'file': return App::$Request->files->get($paramQuery, null, true); default: return App::$Request->get($paramQuery, null, true); } }
/** * Try to find exist viewer full path * @param string $path * @param string|null $source * @return null|string * @throws NativeException */ private function findViewer($path, $source = null) { $tmpPath = null; // sounds like a relative path for current view theme if (Str::contains('/', $path)) { // lets try to get full path for current theme $tmpPath = $path; if (!Str::startsWith($this->themePath, $path)) { $tmpPath = Normalize::diskPath($this->themePath . '/' . $path . '.php'); } } else { // sounds like a object-depended view call from controller or etc // get stack trace of callbacks $calledLog = debug_backtrace(); $calledController = null; // lets try to find controller in backtrace foreach ($calledLog as $caller) { if (isset($caller['class']) && Str::startsWith('Apps\\Controller\\', $caller['class'])) { $calledController = (string) $caller['class']; } } // depended controller is not founded? Let finish if ($calledController === null) { throw new NativeException('View render is failed: callback controller not founded! Call with relative path: ' . $path); } // get controller name $controllerName = Str::sub($calledController, Str::length('Apps\\Controller\\' . env_name . '\\')); $controllerName = Str::lowerCase($controllerName); // get full path $tmpPath = $this->themePath . DIRECTORY_SEPARATOR . $controllerName . DIRECTORY_SEPARATOR . $path . '.php'; } // check if builded view full path is exist if (File::exist($tmpPath)) { return $tmpPath; } // hmm, not founded. Lets try to find in caller directory (for widgets, apps packages and other) if ($source !== null) { $tmpPath = Normalize::diskPath($source . DIRECTORY_SEPARATOR . $path . '.php'); if (File::exist($tmpPath)) { // add notify for native views if (App::$Debug !== null) { App::$Debug->addMessage('Render native viewer: ' . Str::replace(root, null, $tmpPath), 'info'); } return $tmpPath; } } if (App::$Debug !== null) { App::$Debug->addMessage('Viewer not founded on rendering: ' . $path, 'warning'); } return null; }
/** * Get pathway without current controller/action path * @return string */ public function getPathWithoutControllerAction() { $path = trim($this->getPathInfo(), '/'); if ($this->aliasPathTarget !== false) { $path = trim($this->aliasPathTarget, '/'); } $pathArray = explode('/', $path); if ($pathArray[0] === Str::lowerCase($this->getController())) { // unset controller array_shift($pathArray); if ($pathArray[0] === Str::lowerCase($this->getAction())) { // unset action array_shift($pathArray); } } return trim(implode('/', $pathArray), '/'); }
/** * Update config data after add new rule */ public function save() { $configData = [ucfirst(Str::lowerCase($this->type)) => [ucfirst(Str::lowerCase($this->loader)) => ['/' . trim($this->source, '/') => '/' . trim($this->target, '/')]]]; App::$Properties->updateConfig('Routing', $configData); }
/** * Write configurations data from array to cfg file * @param string $configFile * @param array $data * @return bool */ public function writeConfig($configFile, array $data) { $path = '/Private/Config/' . ucfirst(Str::lowerCase($configFile)) . '.php'; if (!File::exist($path) || !File::writable($path)) { return false; } $saveData = '<?php return ' . Arr::exportVar($data) . ';'; File::write($path, $saveData); return true; }
</div> <?php $appTableItems = null; foreach ($apps as $app) { /** @var $app Apps\ActiveRecord\App */ if ($app->type !== 'app') { continue; } $route = $app->sys_name . '/index'; $icoStatus = null; $actions = \App::$View->render('native/macro/app_actions', ['controller' => $app->sys_name]); // set action icons based on app status if ((int) $app->disabled !== 0) { $icoStatus = ' <i class="fa fa-pause" style="color: #ff0000;"></i>'; } elseif ($app->checkVersion() !== true) { $icoStatus = ' <i class="fa fa-exclamation" style="color: #ffbd26;"></i>'; $actions = Url::link(['application/update', $app->sys_name], '<i class="fa fa-wrench"></i>'); } else { $icoStatus = ' <i class="fa fa-check" style="color: #008000;"></i>'; } $appTableItems[] = [['text' => $app->id . $icoStatus, 'html' => true, '!secure' => true], ['text' => Url::link([$route], $app->getLocaleName()), 'html' => true], ['text' => '<a target="_blank" href="' . \App::$Alias->scriptUrl . '/' . Str::lowerCase($route) . '">' . $route . '</a>', 'html' => true], ['text' => $app->version], ['text' => Date::convertToDatetime($app->updated_at, Date::FORMAT_TO_HOUR)], ['text' => $actions, 'property' => ['class' => 'text-center'], 'html' => true]]; } ?> <div class="table-responsive"> <?php echo Table::display(['table' => ['class' => 'table table-bordered'], 'thead' => ['titles' => [['text' => '#'], ['text' => __('Application')], ['text' => __('User interface')], ['text' => __('Version')], ['text' => __('Activity')], ['text' => __('Actions')]]], 'tbody' => ['items' => $appTableItems]]); ?> </div>
echo __('This content is placed in trash'); ?> </p> <?php } ?> <div id="content-text"> <?php if ($showPoster === true && $model->posterFull !== null && $model->posterThumb !== null) { ?> <a href="#showPoster" data-toggle="modal" data-target="#showPoster"> <img alt="<?php echo __('Poster for'); ?> : <?php echo Str::lowerCase($model->title); ?> " src="<?php echo \App::$Alias->scriptUrl . $model->posterThumb; ?> " class="image_poster img-thumbnail" /> </a> <!-- Modal poster pop-up --> <div class="modal fade" id="showPoster" tabindex="-1" role="dialog" aria-labelledby="showPosterModal"> <div class="modal-dialog modal-lg" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel"><?php echo __('View poster');
?> <!-- /.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; } } $appMenuItems[] = ['type' => 'link', 'link' => ['application/index'], 'text' => __('All apps') . '...']; $appControllers[] = 'Application'; $widgetMenuItems[] = ['type' => 'link', 'link' => ['widget/index'], 'text' => __('All widgets') . '...']; $widgetControllers[] = 'Widget'; ?> <li<?php echo Arr::in(\App::$Request->getController(), $appControllers) ? ' class="active"' : null;
?> <?php if ($socialInstance !== null) { ?> <div class="row" style="padding-bottom: 5px;"> <div class="col-md-offset-3 col-md-9"> <?php foreach ($socialInstance->getProviders() as $provider => $connected) { ?> <a href="<?php echo Url::to('user/socialauth', $provider); ?> " class="label label-success"> <i class="fa fa-<?php echo Str::lowerCase($provider); ?> "></i> <?php echo $provider; ?> </a> <?php } ?> <p class="help-block"><?php echo __('You can login to website using your social network account'); ?> </p> </div> </div> <?php
/** * 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]); }
/** * Delete scheme route * @throws SyntaxException * @return string * @throws \Ffcms\Core\Exception\NativeException */ public function actionDeleteroute() { $type = (string) $this->request->query->get('type'); $loader = (string) $this->request->query->get('loader'); $source = Str::lowerCase((string) $this->request->query->get('path')); $model = new EntityDeleteRoute($type, $loader, $source); if ($model->send() && $model->validate()) { $model->make(); return $this->view->render('delete_route_save'); } return $this->view->render('delete_route', ['model' => $model]); }
/** * Build current pathway with get data to compare in some methods * @return null|string */ public static function buildPathwayFromRequest() { return self::buildPathway([Str::lowerCase(App::$Request->getController()) . '/' . Str::lowerCase(App::$Request->getAction()), App::$Request->getID(), App::$Request->getAdd(), App::$Request->query->all()]); }
/** * Make parts of URI safe and usable * @param string $string * @param bool $encode * @return string */ public static function safeUri($string, $encode = true) { $string = Str::lowerCase($string); $string = self::nohtml($string); if ($encode === true) { $string = urlencode($string); } return $string; }
<?php } ?> <div class="row"> <div class="col-md-12"> <?php if ($catConfigs['showPoster'] === true && $item['thumb'] !== null) { ?> <img src="<?php echo \App::$Alias->scriptUrl . $item['thumb']; ?> " class="image_poster img-thumbnail hidden-xs" alt="<?php echo __('Poster for'); ?> : <?php echo Str::lowerCase($item['title']); ?> " /> <?php } ?> <div itemprop="text articleBody"> <?php echo $item['text']; ?> </div> </div> </div> <div class="meta"> <?php if ((int) $catConfigs['showRating'] === 1) {
/** * 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]); }