Esempio n. 1
0
 /**
  * Get allowed category ids as array
  * @return array
  */
 public function categoryIds()
 {
     $data = ContentCategory::getSortedCategories();
     return array_keys($data);
 }
Esempio n. 2
0
 /**
  * Get category relation of this content id
  * @return \Apps\ActiveRecord\ContentCategory|null
  */
 public function getCategory()
 {
     return ContentCategory::getById($this->category_id);
 }
Esempio n. 3
0
 /**
  * Validate pathway
  * @param string $path
  * @return bool
  * @throws SyntaxException
  */
 public function pathIsFree($path)
 {
     $owner = ContentCategory::getById($this->dependId);
     if ($owner === null || $owner === false) {
         throw new SyntaxException();
     }
     // build path with owner category
     $this->_pathNested = $owner->path;
     if (Str::length($this->_pathNested) > 0) {
         $path = $this->_pathNested . '/' . $path;
     }
     // make select for check
     $query = ContentCategory::where('path', '=', $path);
     if ($this->_new !== true) {
         // exclude current category from checking path's
         $query->where('id', '!=', $this->_record->id);
     }
     return $query->count() === 0;
 }
Esempio n. 4
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();
 }
Esempio n. 5
0
 /**
  * Find multiple categories child of current
  * @throws NotFoundException
  */
 private function findCategories()
 {
     // get all categories for current path and child of it
     $query = ContentCategory::where('path', 'like', $this->_path . '%');
     if ($query->count() < 1) {
         throw new NotFoundException(__('Category is not founded'));
     }
     // get result as object
     $result = $query->get();
     // extract ids from result as array by key id
     $this->_catIds = Arr::ploke('id', $result->toArray());
     // get current category matching
     foreach ($result as $row) {
         if ($row->path === $this->_path) {
             $this->_currentCategory = $row;
         }
     }
     // set result to property
     $this->_allCategories = $result;
 }
Esempio n. 6
0
 /**
  * Cron schedule action - build content sitemap
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws \Ffcms\Core\Exception\SyntaxException
  */
 public static function buildSitemapSchedule()
 {
     // get records from database as activerecord object
     $contents = \Apps\ActiveRecord\Content::where('display', '=', 1);
     if ($contents->count() < 1) {
         return;
     }
     // get languages if multilanguage enabled
     $langs = null;
     if (App::$Properties->get('multiLanguage')) {
         $langs = App::$Properties->get('languages');
     }
     // build sitemap from content items via business model
     $sitemap = new EntityBuildMap($langs);
     foreach ($contents->get() as $content) {
         $category = $content->getCategory();
         $uri = '/content/read/';
         if (!Str::likeEmpty($category->path)) {
             $uri .= $category->path . '/';
         }
         $uri .= $content->path;
         $sitemap->add($uri, $content->created_at, 'weekly', 0.7);
     }
     // add categories
     $categories = ContentCategory::all();
     foreach ($categories as $item) {
         if ((bool) $item->getProperty('showCategory')) {
             $uri = '/content/list/' . $item->path;
             $sitemap->add($uri, date('c'), 'daily', 0.9);
         }
     }
     // save data to xml file
     $sitemap->save('content');
 }
Esempio n. 7
0
 /**
  * Get all categories as sorted array
  * @return array
  */
 public function getCategories()
 {
     return ContentCategory::getSortedCategories();
 }
Esempio n. 8
0
<?php 
$form = new Form($model, ['class' => 'form-horizontal', 'enctype' => 'multipart/form-data']);
echo $form->start();
?>

<?php 
$items = [];
foreach (\App::$Properties->get('languages') as $lang) {
    $items[] = ['type' => 'tab', 'text' => __('Lang') . ': ' . Str::upperCase($lang), 'content' => $form->field('title.' . $lang, 'text', ['class' => 'form-control'], __('Please, enter the title of your material for current language locale')) . $form->field('text.' . $lang, 'textarea', ['class' => 'form-control wysiwyg', 'rows' => 7, 'html' => true]), 'html' => true, 'active' => $lang === \App::$Request->getLanguage(), '!secure' => true];
}
echo Nav::display(['property' => ['class' => 'nav-pills'], 'blockProperty' => ['class' => 'nav-locale-block'], 'tabAnchor' => 'content-update-general-locale', 'items' => $items]);
?>

<?php 
echo $form->field('path', 'text', ['class' => 'form-control'], __('Set path slug for content item. Allowed items: a-z, 0-9, -'));
echo $form->field('categoryId', 'select', ['class' => 'form-control', 'size' => 4, 'options' => ContentCategory::getSortedCategories(), 'optionsKey' => true], __('Select content category'));
?>

<?php 
echo $form->field('poster', 'file', null, __('Select poster image for this content'));
?>

<div class="col-md-offset-3 col-md-9">
    <?php 
echo $form->submitButton(__('Save'), ['class' => 'btn btn-primary']);
?>
</div>

<?php 
echo $form->finish();
?>
Esempio n. 9
0
 /**
  * Show category edit and create
  * @param int|null $id
  * @return string
  * @throws \Ffcms\Core\Exception\SyntaxException
  * @throws \Ffcms\Core\Exception\NativeException
  */
 public function actionCategoryupdate($id = null)
 {
     // get owner id for new rows
     $parentId = (int) $this->request->query->get('parent');
     // get relation and pass to model
     $record = ContentCategory::findOrNew($id);
     $isNew = $record->id === null;
     $model = new FormCategoryUpdate($record, $parentId);
     // if model is submited
     if ($model->send() && $model->validate()) {
         $model->save();
         // if is new - redirect to list after submit
         if ($isNew) {
             $this->response->redirect('content/categories');
         }
         // show notify message
         App::$Session->getFlashBag()->add('success', __('Category is successful updated'));
     }
     // draw response view and pass model properties
     return $this->view->render('category_update', ['model' => $model]);
 }
Esempio n. 10
0
                    <li><?php 
echo Url::link(['content/index', null, null, ['type' => 'moderate']], '<i class="fa fa-exclamation"></i> ' . __('Moderate'));
?>
</li>
                    <li><?php 
echo Url::link(['content/index', null, null, ['type' => 'trash']], '<i class="fa fa-trash"></i> ' . __('Trash'));
?>
</li>
                    <li>
                        <a class="trigger right-caret"><i class="fa fa-table"></i> <?php 
echo __('Categories');
?>
</a>
                        <ul class="dropdown-menu sub-menu">
                            <?php 
foreach (ContentCategory::getSortedCategories() as $id => $name) {
    ?>
                            <li><?php 
    echo Url::link(['content/index', null, null, ['type' => $id]], $name);
    ?>
</li>
                            <?php 
}
?>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
        <?php 
if ($type === 'trash') {