Beispiel #1
0
 /**
  * Prepare output comment post information array
  * @return array|null
  */
 public function make()
 {
     if ($this->_record === null) {
         return null;
     }
     // build user data
     $userName = __('Unknown');
     $userAvatar = App::$Alias->scriptUrl . '/upload/user/avatar/small/default.jpg';
     $userObject = $this->_record->getUser();
     if ($userObject !== null) {
         $userName = $userObject->getProfile()->getNickname();
         $userAvatar = $userObject->getProfile()->getAvatarUrl('small');
     } else {
         if (!Str::likeEmpty($this->_record->guest_name)) {
             $userName = App::$Security->strip_tags($this->_record->guest_name);
         }
     }
     // return output json data
     $res = ['type' => $this->_type, 'id' => $this->_record->id, 'text' => $this->_record->message, 'date' => Date::convertToDatetime($this->_record->created_at, Date::FORMAT_TO_HOUR), 'pathway' => $this->_record->pathway, 'moderate' => (int) $this->_record->moderate, 'user' => ['id' => $this->_record->user_id, 'name' => $userName, 'avatar' => $userAvatar]];
     if ($this->_type === 'post' && method_exists($this->_record, 'getAnswerCount') && $this->_calcAnswers) {
         $res['answers'] = $this->_record->getAnswerCount();
     } elseif ($this->_type === 'answer') {
         $res['comment_id'] = $this->_record->comment_id;
     }
     return $res;
 }
Beispiel #2
0
 /**
  * Check comment add conditions. On bad conditions will be throw'd exception.
  * @throws JsonException
  * @return boolean
  */
 public function check()
 {
     // check if user is auth'd or guest name is defined
     if (!App::$User->isAuth() && ((int) $this->_configs['guestAdd'] !== 1 || Str::length($this->guestName) < 2)) {
         throw new JsonException(__('Guest name is not defined'));
     }
     // check if pathway is empty
     if (Str::likeEmpty($this->pathway)) {
         throw new JsonException(__('Wrong target pathway'));
     }
     // check if message length is correct
     if (Str::length($this->message) < (int) $this->_configs['minLength'] || Str::length($this->message) > (int) $this->_configs['maxLength']) {
         throw new JsonException(__('Message length is incorrect. Current: %cur%, min - %min%, max - %max%', ['cur' => Str::length($this->message), 'min' => $this->_configs['minLength'], 'max' => $this->_configs['maxLength']]));
     }
     // guest moderation
     if (!App::$User->isAuth() && (bool) $this->_configs['guestModerate']) {
         $captcha = App::$Request->request->get('captcha');
         if (!App::$Captcha->validate($captcha)) {
             throw new JsonException(__('Captcha is incorrect! Click on image to refresh and try again'));
         }
     }
     // check delay between 2 comments from 1 user or 1 ip
     $query = CommentPost::where('user_id', '=', $this->_userId)->orWhere('ip', '=', $this->ip)->orderBy('created_at', 'DESC')->first();
     // check if latest post time for this user is founded
     if ($query !== null) {
         $postTime = Date::convertToTimestamp($query->created_at);
         $delay = $postTime + $this->_configs['delay'] - time();
         if ($delay > 0) {
             throw new JsonException(__('Spam protection: please, wait %sec% seconds', ['sec' => $delay]));
         }
     }
     return true;
 }
Beispiel #3
0
 /**
  * Build search results
  * @return array[AbstractSearchResult]
  */
 public function getResult()
 {
     // relevant search by string query
     $records = Content::where('display', '=', 1)->search($this->query)->take($this->limit)->get();
     // check if result is not empty
     if ($records->count() < 1) {
         return [];
     }
     // build result items
     $result = [];
     foreach ($records as $item) {
         /** @var \Apps\ActiveRecord\Content $item */
         $title = $item->getLocaled('title');
         $text = App::$Security->strip_tags($item->getLocaled('text'));
         $snippet = Text::snippet($text);
         // prevent empty items
         if (Str::likeEmpty($title)) {
             continue;
         }
         // initialize abstract response pattern
         $res = new AbstractSearchResult();
         $res->setTitle($title);
         $res->setSnippet($snippet);
         $res->setDate($item->created_at);
         $res->setRelevance((int) $item->relevance);
         $res->setUri('/content/read/' . $item->getPath());
         // accumulate response var
         $result[] = $res;
     }
     return $result;
 }
Beispiel #4
0
 /**
  * Set model attributes from record object
  */
 public function before()
 {
     if ($this->_record->id === null) {
         $this->_new = true;
         // pass owner id category from construct model
         $this->dependId = $this->_tmpDependId < 1 ? 1 : $this->_tmpDependId;
     } else {
         // make tmp id for frontend form
         $this->id = $this->_record->id;
         $path = $this->_record->path;
         // nesting levels
         if (Str::contains('/', $path)) {
             $nestedPath = explode('/', $path);
             $this->path = array_pop($nestedPath);
             $this->_pathNested = implode('/', $nestedPath);
             // get owner category id by nesting path
             $owner = ContentCategory::getByPath($this->_pathNested);
             if ($owner !== null) {
                 $this->dependId = $owner->id;
             }
         } else {
             $this->path = $path;
         }
         // set data from record
         $this->title = $this->_record->title;
         $this->description = $this->_record->description;
         if ($this->_record->configs !== null && !Str::likeEmpty($this->_record->configs)) {
             $this->configs = $this->_record->configs;
         }
     }
 }
Beispiel #5
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;
 }
Beispiel #6
0
 /**
  * Form constructor. Build form based on model properties
  * @param Model $model
  * @param array|null $property
  * @param array|null $layerFiles
  * @throws SyntaxException
  */
 public function __construct($model, array $property = null, array $layerFiles = null)
 {
     // prevent white-screen locks when model is not passed or passed wrong
     if (!$model instanceof Model) {
         throw new SyntaxException('Bad model type passed in form builder. Check for init: new Form()');
     }
     $this->model = $model;
     $this->name = $model->getFormName();
     // check if passed custom layer file
     if (Obj::isArray($layerFiles) && count($layerFiles) > 0) {
         foreach (array_keys(static::$structLayer) as $type) {
             if (isset($layerFiles[$type]) && Obj::isString($layerFiles[$type])) {
                 static::$structLayer[$type] = $layerFiles[$type];
             }
         }
     }
     // set model submit method
     $property['method'] = $this->model->getSubmitMethod();
     $property['id'] = $this->name;
     // define form id
     // if action is not defined - define it
     if (Str::likeEmpty($property['action'])) {
         $property['action'] = App::$Request->getFullUrl();
     }
     // set property global for this form
     $this->formProperty = $property;
 }
Beispiel #7
0
 /**
  * Build variables and display output html
  */
 public function buildOutput()
 {
     $this->after();
     // if layout is not required and this is just standalone app
     if ($this->layout === null) {
         $content = $this->output;
     } else {
         $layoutPath = App::$Alias->currentViewPath . '/layout/' . $this->layout . '.php';
         if (!File::exist($layoutPath)) {
             throw new NativeException('Layout not founded: ' . $layoutPath);
         }
         $body = $this->output;
         // pass global data to config viewer
         if (App::$Debug !== null) {
             App::$Debug->bar->getCollector('config')->setData(['Global Vars' => Variables::instance()->getGlobalsArray()]);
         }
         // cleanup buffer from random shits after exception throw'd
         ob_clean();
         // start buffering to render layout
         ob_start();
         include $layoutPath;
         $content = ob_get_clean();
         // read buffer content & stop buffering
         // set custom css library's not included on static call
         $cssIncludeCode = App::$View->showCodeLink('css');
         if (!Str::likeEmpty($cssIncludeCode)) {
             $content = Str::replace('</head>', $cssIncludeCode . '</head>', $content);
         }
         // add debug bar
         if (App::$Debug !== null) {
             $content = Str::replace(['</body>', '</head>'], [App::$Debug->renderOut() . '</body>', App::$Debug->renderHead() . '</head>'], $content);
         }
     }
     return $content;
 }
Beispiel #8
0
 /**
  * Main search method
  * @return string
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws NotFoundException
  * @throws \Ffcms\Core\Exception\SyntaxException
  */
 public function actionIndex()
 {
     // get search query value from GET headers
     $query = (string) $this->request->query->get('query', null);
     // strip html tags
     $query = App::$Security->strip_tags(trim($query));
     // get configs
     $configs = $this->getConfigs();
     // check search query length
     if (Str::likeEmpty($query) || Str::length($query) < (int) $configs['minLength']) {
         throw new NotFoundException(__('Search query is too short!'));
     }
     // prevent sh@t query's with big length
     if (Str::length($query) > static::QUERY_MAX_LENGTH) {
         throw new NotFoundException(__('Search query is too long!'));
     }
     // initialize search controller model
     $model = new EntitySearchMain($query, $configs);
     // try to search by default apps
     $model->make();
     // register search event to allow extend it model results
     App::$Event->run(static::EVENT_SEARCH_RUNNED, ['model' => $model]);
     // render output view with search result
     return $this->view->render('index', ['model' => $model, 'query' => $query]);
 }
 /**
  * Build fake page with error based on fake controller initiation
  */
 protected function buildFakePage()
 {
     // initialize fake controller to display page with exception
     $fakeController = new Controller();
     // check if used no layout template
     if (defined('env_no_layout') && env_no_layout === true) {
         $fakeController->layout = null;
     }
     // add global title tag value
     $fakeController->setGlobalVar('title', App::$Translate->get('Default', $this->title));
     // build error text
     $rawResponse = 'error';
     try {
         $rawResponse = App::$View->render('native/errors/' . $this->tpl, ['msg' => $this->text]);
         if (Str::likeEmpty($rawResponse)) {
             $rawResponse = $this->text;
         }
     } catch (SyntaxException $e) {
         $rawResponse = $this->text;
     }
     // set controller body response
     $fakeController->setOutput($rawResponse);
     // set status code for header
     App::$Response->setStatusCode((int) $this->status);
     // return compiled html output
     return $fakeController->buildOutput();
 }
Beispiel #10
0
 /**
  * Get user nickname. If is empty - return 'id+userId'
  * @return string
  */
 public function getNickname()
 {
     $userNick = $this->nick;
     if ($userNick === null || Str::likeEmpty($userNick)) {
         $userNick = 'id' . $this->id;
     }
     return $userNick;
 }
Beispiel #11
0
 /**
  * Save new user group data in database after submit
  */
 public function save()
 {
     $this->_role->name = $this->name;
     if (Str::likeEmpty($this->permissions) || !Str::contains(';', $this->permissions)) {
         $this->_role->permissions = '';
     } else {
         $this->_role->permissions = implode(';', $this->permissions);
     }
     $this->_role->save();
 }
Beispiel #12
0
 /**
  * Special function for locale stored attributes under serialization.
  * @param string $attribute
  * @return array|null|string
  */
 public function getLocaled($attribute)
 {
     // if always decoded
     if (Obj::isArray($this->{$attribute})) {
         return $this->{$attribute}[App::$Request->getLanguage()];
     }
     if (!Obj::isString($attribute) || Str::likeEmpty($this->{$attribute})) {
         return null;
     }
     return Serialize::getDecodeLocale($this->{$attribute});
 }
Beispiel #13
0
 /**
  * List user profiles on website by defined filter
  * @param string $filter_name
  * @param null|string|int $filter_value
  * @return string
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws NotFoundException
  * @throws \Ffcms\Core\Exception\SyntaxException
  */
 public function actionIndex($filter_name, $filter_value = null)
 {
     $records = null;
     // set current page and offset
     $page = (int) $this->request->query->get('page', 0);
     $cfgs = $this->application->configs;
     $userPerPage = (int) $cfgs['usersOnPage'];
     if ($userPerPage < 1) {
         $userPerPage = 1;
     }
     $offset = $page * $userPerPage;
     switch ($filter_name) {
         case 'rating':
             // rating list, order by rating DESC
             // check if rating is enabled
             if ((int) $cfgs['rating'] !== 1) {
                 throw new NotFoundException();
             }
             $records = (new ProfileRecords())->orderBy('rating', 'DESC');
             break;
         case 'hobby':
             // search by hobby
             if (Str::likeEmpty($filter_value)) {
                 throw new NotFoundException();
             }
             $records = (new ProfileRecords())->where('hobby', 'like', '%' . $filter_value . '%');
             break;
         case 'city':
             if (Str::likeEmpty($filter_value)) {
                 throw new NotFoundException();
             }
             $records = (new ProfileRecords())->where('city', '=', $filter_value);
             break;
         case 'born':
             if ($filter_value === null || !Obj::isLikeInt($filter_value)) {
                 throw new NotFoundException();
             }
             $records = (new ProfileRecords())->where('birthday', 'like', $filter_value . '-%');
             break;
         case 'all':
             $records = (new ProfileRecords())->orderBy('id', 'DESC');
             break;
         default:
             $this->response->redirect('profile/index/all');
             break;
     }
     // build pagination
     $pagination = new SimplePagination(['url' => ['profile/index', $filter_name, $filter_value], 'page' => $page, 'step' => $userPerPage, 'total' => $records->count()]);
     return $this->view->render('index', ['records' => $records->skip($offset)->take($userPerPage)->get(), 'pagination' => $pagination, 'id' => $filter_name, 'add' => $filter_value, 'ratingOn' => (int) $cfgs['rating']]);
 }
Beispiel #14
0
 /**
  * Build console controllers.
  * php console.php Controller/Action index
  */
 public static function run()
 {
     global $argv;
     $output = null;
     if (!Obj::isArray($argv) || Str::likeEmpty($argv[1])) {
         $output = 'Console command is unknown! Type "console main/help" to get help guide';
     } else {
         $controller_action = $argv[1];
         $arrInput = explode('/', $controller_action);
         $controller = ucfirst(strtolower($arrInput[0]));
         $action = ucfirst(strtolower($arrInput[1]));
         if ($action == null) {
             $action = 'Index';
         }
         // set action and id
         $action = 'action' . $action;
         $id = null;
         if (isset($argv[2])) {
             $id = $argv[2];
         }
         try {
             $controller_path = '/Apps/Controller/' . env_name . '/' . $controller . '.php';
             if (file_exists(root . $controller_path) && is_readable(root . $controller_path)) {
                 include_once root . $controller_path;
                 $cname = 'Apps\\Controller\\' . env_name . '\\' . $controller;
                 if (class_exists($cname)) {
                     $load = new $cname();
                     if (method_exists($cname, $action)) {
                         if ($id !== null) {
                             $output = @$load->{$action}($id);
                         } else {
                             $output = @$load->{$action}();
                         }
                     } else {
                         throw new NativeException('Method ' . $action . '() not founded in ' . $cname . ' in file {root}' . $controller_path);
                     }
                     unset($load);
                 } else {
                     throw new NativeException('Namespace\\Class - ' . $cname . ' not founded in {root}' . $controller_path);
                 }
             } else {
                 throw new NativeException('Controller not founded: {root}' . $controller_path);
             }
         } catch (NativeException $e) {
             $e->display($e->getMessage());
         }
     }
     return self::$Output->write($output);
 }
Beispiel #15
0
 /**
  * Print json response for search query based on standard model
  * @return string
  * @throws JsonException
  */
 public function actionIndex()
 {
     $this->setJsonHeader();
     // get search query as string from request
     $query = $this->request->query->get('query', null);
     if (Str::likeEmpty($query) || Str::length($query) < 2) {
         throw new JsonException('Short query');
     }
     // initialize basic search model
     $model = new EntitySearchMain($query, ['itemPerApp' => 3]);
     $model->make();
     // build response by relevance as array
     $response = $model->getRelevanceSortedResult();
     return json_encode(['status' => 1, 'count' => count($response), 'data' => $response]);
 }
Beispiel #16
0
 /**
  * List comments as json object with defined offset index
  * @param int $index
  * @return string
  * @throws NotFoundException
  */
 public function actionList($index)
 {
     // set header
     $this->setJsonHeader();
     // get configs
     $configs = AppRecord::getConfigs('widget', 'Comments');
     // items per page
     $perPage = (int) $configs['perPage'];
     // offset can be only integer
     $index = (int) $index;
     $offset = $perPage * $index;
     // get comment target path and check
     $path = (string) $this->request->query->get('path');
     if (Str::likeEmpty($path)) {
         throw new NotFoundException('Wrong path');
     }
     // select comments from db and check it
     $query = CommentPost::where('pathway', '=', $path)->where('moderate', '=', 0);
     // check if comments is depend of language locale
     if ((int) $configs['onlyLocale'] === 1) {
         $query = $query->where('lang', '=', $this->request->getLanguage());
     }
     // get comments with offset and limit
     $records = $query->skip($offset)->take($perPage)->get();
     // check if records is not empty
     if ($records->count() < 1) {
         throw new NotFoundException(__('There is no comments found yet. You can be the first!'));
     }
     // build output json data as array
     $data = [];
     foreach ($records as $comment) {
         // prepare specified data to output response, based on entity model
         $commentResponse = new EntityCommentData($comment);
         // build output json data
         $data[] = $commentResponse->make();
         $commentResponse = null;
     }
     // calculate comments left count
     $count = CommentPost::where('pathway', '=', $path)->where('moderate', '=', 0)->count();
     $count -= $offset + $perPage;
     if ($count < 0) {
         $count = 0;
     }
     return json_encode(['status' => 1, 'data' => $data, 'leftCount' => $count]);
 }
Beispiel #17
0
 /**
  * Get label value by variable name
  * @param string $param
  * @return mixed
  */
 public final function getLabel($param)
 {
     $labels = $this->labels();
     $response = null;
     // maybe array-dotted declaration?
     if (Str::contains('.', $param)) {
         // not defined for all array-dotted nesting?
         if (Str::likeEmpty($labels[$param])) {
             // lets set default array label (before first dot-separation)
             $response = $labels[Str::firstIn($param, '.')];
         } else {
             $response = $labels[$param];
         }
     } else {
         $response = $labels[$param];
     }
     return Str::likeEmpty($response) ? Str::replace('.', ' ', Str::splitCamelCase($param)) : $response;
 }
 /**
  * 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);
     }
 }
 /**
  * Build notification list as array
  */
 public function make()
 {
     // check if records is not empty
     if ($this->_records === null) {
         return;
     }
     // list records and build response
     foreach ($this->_records as $record) {
         /** @var UserNotification $record */
         $vars = null;
         if (!Str::likeEmpty($record->vars)) {
             $vars = $record->vars;
         }
         if (!$vars !== null && isset($vars['snippet'])) {
             $vars['snippet'] = Url::standaloneLink($vars['snippet'], $record->uri, App::$Request->getLanguage());
         }
         $text = App::$Translate->get('Profile', $record->msg, $vars);
         $this->items[] = ['text' => $text, 'date' => Date::humanize($record->created_at), 'new' => (bool) $record->readed === false];
     }
 }
Beispiel #20
0
 /**
  * Alias constructor. Build alias properties for system data to provide fast-access from apps and other places.
  */
 public function __construct()
 {
     // make alias for view pathway
     $this->currentViewPath = App::$View->themePath;
     // make alias for baseUrl, script url and domain
     $this->baseDomain = App::$Request->getHttpHost();
     if (Str::likeEmpty($this->baseDomain)) {
         $this->baseDomain = App::$Properties->get('baseDomain');
     }
     // build script url
     $this->scriptUrl = App::$Request->getScheme() . '://' . $this->baseDomain;
     if (App::$Properties->get('basePath') !== '/') {
         $this->scriptUrl .= rtrim(App::$Properties->get('basePath'), '/');
     }
     // build base url (with current used interface path slug)
     $this->baseUrl = $this->scriptUrl;
     if (App::$Request->getInterfaceSlug() !== null) {
         $this->baseUrl .= App::$Request->getInterfaceSlug();
     }
     $this->baseUrlNoLang = $this->baseUrl;
     if (App::$Request->languageInPath() && App::$Request->getLanguage() !== null) {
         $this->baseUrl .= '/' . App::$Request->getLanguage();
     }
     // add cron initiation from user if enabled
     if ((bool) App::$Properties->get('userCron') && env_name === 'Front') {
         $this->addPlainCode('js', 'if(Math.random() > 0.8) { $.get("' . $this->scriptUrl . '/cron.php?rand=" + Math.random()); }');
     }
     // build vendor libs alias
     $this->vendorNamedLibrary['js']['jquery'] = $this->scriptUrl . '/vendor/bower/jquery/dist/jquery.min.js';
     $this->vendorNamedLibrary['css']['bootstrap'] = $this->scriptUrl . '/vendor/bower/bootstrap/dist/css/bootstrap.min.css';
     $this->vendorNamedLibrary['js']['bootstrap'] = $this->scriptUrl . '/vendor/bower/bootstrap/dist/js/bootstrap.min.js';
     $this->vendorNamedLibrary['css']['fa'] = $this->scriptUrl . '/vendor/bower/components-font-awesome/css/font-awesome.min.css';
     $this->vendorNamedLibrary['js']['jquery-ui'] = $this->scriptUrl . '/vendor/bower/jquery-ui/jquery-ui.min.js';
     $this->vendorNamedLibrary['css']['jquery-ui'] = $this->scriptUrl . '/vendor/bower/jquery-ui/themes/base/jquery-ui.min.css';
     $themeAll = App::$Properties->get('theme');
     if (!isset($themeAll[env_name]) || Str::length($themeAll[env_name]) < 1) {
         $themeAll[env_name] = 'default';
     }
     $this->currentViewUrl = $this->scriptUrl . '/Apps/View/' . env_name . '/' . $themeAll[env_name];
 }
Beispiel #21
0
 /**
  * Get wall answer's count by post-ids list
  * @param int $postIds
  * @throws NativeException
  * @return string
  */
 public function actionWallanswercount($postIds)
 {
     // set header
     $this->setJsonHeader();
     // check query length
     if (Str::likeEmpty($postIds)) {
         throw new NativeException('Wrong input count');
     }
     $list = explode(',', $postIds);
     $itemCount = count($list);
     // empty or is biggest then limit?
     if ($itemCount < 1 || $itemCount > self::ITEM_PER_PAGE) {
         throw new NativeException('Wrong input count');
     }
     // prepare response
     $response = [];
     foreach ($list as $post) {
         $response[$post] = WallAnswer::where('post_id', '=', $post)->count();
     }
     // display json data
     return json_encode(['status' => 1, 'data' => $response]);
 }
Beispiel #22
0
 /**
  * Build id-title array of sorted by nesting level categories
  * @return array
  */
 public static function getSortedCategories()
 {
     $response = [];
     $tmpData = self::getSortedAll();
     foreach ($tmpData as $path => $data) {
         $title = null;
         if (Str::likeEmpty($path)) {
             $title .= '--';
         } else {
             // set level marker based on slashes count in pathway
             $slashCount = Str::entryCount($path, '/');
             for ($i = -1; $i <= $slashCount; $i++) {
                 $title .= '--';
             }
         }
         // add canonical title from db
         $title .= ' ' . $data->getLocaled('title');
         // set response as array [id => title, ... ]
         $response[$data->id] = $title;
     }
     return $response;
 }
Beispiel #23
0
<?php

/** @var object $records */
use Ffcms\Core\Helper\Date;
use Ffcms\Core\Helper\Text;
use Ffcms\Core\Helper\Type\Str;
foreach ($records as $record) {
    $title = \App::$Translate->getLocaleText($record->title);
    if (Str::likeEmpty($title)) {
        continue;
    }
    $title = Text::snippet($title, 50);
    $date = Date::humanize($record->created_at);
    $categoryUrl = \App::$Alias->baseUrl . '/content/list/' . $record->cpath;
    $categoryLink = '<a href="' . $categoryUrl . '">' . \App::$Translate->getLocaleText($record->ctitle) . '</a>';
    $newsLink = \App::$Alias->baseUrl . '/content/read/' . $record->cpath;
    $newsLink = rtrim($newsLink, '/') . '/' . $record->path;
    echo '<div class="row"><div class="col-md-12">';
    echo '<a href="' . $newsLink . '">&rarr; ' . $title . '</a><br />';
    echo '<small class="pull-left">' . $categoryLink . '</small>';
    echo '<small class="pull-right">' . $date . '</small>';
    echo '</div></div>';
    echo '<hr class="pretty" />';
}
Beispiel #24
0
<?php

use Ffcms\Core\Helper\HTML\Bootstrap\Nav;
use Ffcms\Core\Helper\Type\Str;
if (Str::likeEmpty($rating)) {
    $rating = 0;
}
$items = [];
$items[] = ['type' => 'link', 'link' => ['profile/index', 'all'], 'text' => __('All')];
if ($rating === 1) {
    $items[] = ['type' => 'link', 'link' => ['profile/index', 'rating'], 'text' => __('Rating')];
}
$items[] = ['type' => 'link', 'link' => ['profile/search'], 'text' => __('Search')];
?>

<?php 
echo Nav::display(['property' => ['class' => 'nav-tabs'], 'activeOrder' => 'id', 'items' => $items]);
Beispiel #25
0
 /**
  * Prepare field global properties - name, id and value
  * @param string $name
  * @param string|null $value
  * @param array $properties
  */
 private function globalProperties($name, $value = null, &$properties)
 {
     // standard property data definition
     $properties['name'] = $properties['id'] = $this->formName;
     // form global name
     if ($value !== null && !Str::likeEmpty($value)) {
         $properties['value'] = $value;
     }
     // sounds like a array-path based obj name
     if (Str::contains('.', $name)) {
         $splitedName = explode('.', $name);
         foreach ($splitedName as $nameKey) {
             $properties['name'] .= '[' . $nameKey . ']';
             $properties['id'] .= '-' . $nameKey;
         }
     } else {
         // standard property definition - add field name
         $properties['name'] .= '[' . $name . ']';
         $properties['id'] .= '-' . $name;
     }
 }
Beispiel #26
0
$this->title = $model->category['title'];
if (!\App::$Request->isPathInjected()) {
    $this->breadcrumbs = [Url::to('/') => __('Home'), Url::to('content/list') => __('Contents'), $model->category['title']];
}
?>
<script>
// content id array
var contentItemList = {path: {}}
</script>
<?php 
if (!\App::$Request->isPathInjected()) {
    ?>
<h1>
<?php 
    echo $model->category['title'];
    if (!Str::likeEmpty($model->category['rss'])) {
        ?>
	<small><a href="<?php 
        echo $model->category['rss'];
        ?>
" target="_blank"><i class="fa fa-rss"></i></a></small>
<?php 
    }
    ?>
	<div class="pull-right">
		<div class="btn-group">
			<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
				<i class="fa fa-sort-amount-desc "></i> <?php 
    echo __('Sorting');
    ?>
 <span class="caret"></span>
Beispiel #27
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 #28
0
<?php

/** @var $msg string */
if (\Ffcms\Core\Helper\Type\Str::likeEmpty($msg)) {
    $msg = 'Access forbidden';
}
?>

    <p class="alert alert-danger">
        <?php 
echo $msg;
?>
    </p>
Beispiel #29
0
foreach ($records as $profile) {
    ?>
    <?php 
    /** @var \Apps\ActiveRecord\Profile $profile */
    ?>
    <div class="row" style="padding-top: 10px">
        <div class="col-md-2">
            <div class="text-center"><img src="<?php 
    echo $profile->getAvatarUrl('small');
    ?>
" class="img-responsive img-circle img-thumbnail"/></div>
        </div>
        <div class="col-md-8">
            <h3>
                <?php 
    echo Url::link(['profile/show', $profile->user_id], Str::likeEmpty($profile->nick) ? __('No name') . '(id' . $profile->user_id . ')' : $profile->nick);
    ?>
            </h3>
            <p><?php 
    echo __('Registered');
    ?>
: <?php 
    echo Date::convertToDatetime($profile->created_at, Date::FORMAT_TO_DAY);
    ?>
</p>
            <?php 
    if (\App::$User->identity() !== null && $profile->user_id !== \App::$User->identity()->getId()) {
        ?>
                <?php 
        echo Url::link(['profile/messages', null, null, ['newdialog' => $profile->user_id]], '<i class="fa fa-pencil-square-o"></i> ' . __('New message'), ['class' => 'btn btn-info']);
        ?>
Beispiel #30
0
 /**
  * Save changes in database
  */
 public function save()
 {
     $this->_content->title = $this->title;
     $this->_content->text = $this->text;
     $this->_content->path = $this->path;
     $this->_content->category_id = $this->categoryId;
     $this->_content->author_id = $this->authorId;
     $this->_content->display = $this->display;
     $this->_content->meta_title = $this->metaTitle;
     $this->_content->meta_keywords = $this->metaKeywords;
     $this->_content->meta_description = $this->metaDescription;
     $this->_content->source = $this->source;
     // check if rating is changed
     if ((int) $this->addRating !== 0) {
         $this->_content->rating += (int) $this->addRating;
     }
     // check if special comment hash is exist
     if ($this->_new || Str::length($this->_content->comment_hash) < 32) {
         $this->_content->comment_hash = $this->generateCommentHash();
     }
     // check if date is updated
     if (!Str::likeEmpty($this->createdAt) && !Str::startsWith('0000', Date::convertToDatetime($this->createdAt, Date::FORMAT_SQL_TIMESTAMP))) {
         $this->_content->created_at = Date::convertToDatetime($this->createdAt, Date::FORMAT_SQL_TIMESTAMP);
     }
     // save poster data
     $posterPath = '/upload/gallery/' . $this->galleryFreeId . '/orig/' . $this->poster;
     if (File::exist($posterPath)) {
         $this->_content->poster = $this->poster;
     }
     // get temporary gallery id
     $tmpGalleryId = $this->galleryFreeId;
     // save row
     $this->_content->save();
     // update tags data in special table (relation: content->content_tags = oneToMany)
     ContentTag::where('content_id', '=', $this->_content->id)->delete();
     $insertData = [];
     foreach ($this->metaKeywords as $lang => $keys) {
         // split keywords to tag array
         $tags = explode(',', $keys);
         foreach ($tags as $tag) {
             // cleanup tag from white spaces
             $tag = trim($tag);
             // prepare data to insert
             if (Str::length($tag) > 0) {
                 $insertData[] = ['content_id' => $this->_content->id, 'lang' => $lang, 'tag' => $tag];
             }
         }
     }
     // insert tags
     ContentTag::insert($insertData);
     // move files
     if ($tmpGalleryId !== $this->_content->id) {
         Directory::rename('/upload/gallery/' . $tmpGalleryId, $this->_content->id);
     }
 }