<?php

$action = false;
$galleryBlocks = \CoasterCms\Models\Block::where('type', '=', 'gallery')->get();
if (!$galleryBlocks->isEmpty()) {
    $galleryStorage = public_path() . '/uploads/system/gallery/';
    foreach ($galleryBlocks as $galleryBlock) {
        $oldGalleryDir = $galleryStorage . $galleryBlock->id;
        $newGalleryDir = $galleryStorage . $galleryBlock->name;
        if (is_dir($oldGalleryDir)) {
            $action = true;
            \CoasterCms\Helpers\Cms\File\Directory::copy($oldGalleryDir, $newGalleryDir);
            \CoasterCms\Helpers\Cms\File\Directory::remove($oldGalleryDir);
        }
    }
}
if ($action) {
    echo "Coaster Framework: Moved gallery files so they are stored by block name\n";
}
示例#2
0
 /**
  * Saves page data
  * @param PageVersion $pageVersion
  * @param array $pagePost
  * @param array $pageLangPost
  * @param array $pageGroupsPost
  * @param array $pageInfoOther
  * @return bool
  */
 public function savePostData($pageVersion, $pagePost, $pageLangPost, $pageGroupsPost, $pageInfoOther = [])
 {
     /*
      * Post data fixes
      */
     foreach ($pagePost as $k => $pagePostField) {
         if (is_array($pagePostField) && array_key_exists('exists', $pagePostField)) {
             $pagePost[$k] = array_key_exists('select', $pagePostField) ? $pagePostField['select'] : 0;
         }
     }
     if (array_key_exists('live_start', $pagePost)) {
         $pagePost['live_start'] = DateTimeHelper::jQueryToMysql($pagePost['live_start']) ?: null;
     }
     if (array_key_exists('live_end', $pagePost)) {
         $pagePost['live_end'] = DateTimeHelper::jQueryToMysql($pagePost['live_end']) ?: null;
     }
     foreach ($pageInfoOther as $k => $pageInfoOtherField) {
         if (is_array($pageInfoOtherField) && array_key_exists('exists', $pageInfoOtherField) && array_key_exists('select', $pageInfoOtherField)) {
             $pageInfoOther[$k] = $pageInfoOtherField['select'];
         }
     }
     /*
      * Overwrite default/existing data with posted data
      */
     $pageDefaults = array_merge(['template' => 0, 'parent' => 0, 'child_template' => 0, 'order' => 0, 'group_container' => 0, 'group_container_url_priority' => 0, 'canonical_parent' => 0, 'link' => 0, 'live' => 0, 'sitemap' => 1, 'live_start' => null, 'live_end' => null], $this->getAttributes());
     foreach ($pageDefaults as $pageAttribute => $pageDefault) {
         $this->{$pageAttribute} = $pageDefault;
         switch ($pageAttribute) {
             case 'template':
                 $pageVersion->{$pageAttribute} = $pagePost[$pageAttribute];
                 break;
             default:
                 $this->{$pageAttribute} = array_key_exists($pageAttribute, $pagePost) ? $pagePost[$pageAttribute] : $this->{$pageAttribute};
         }
     }
     if (!$this->pageCurrentLang) {
         $this->setRelation('pageCurrentLang', ($d = $this->pageDefaultLang) ? $d->replicate() : new PageLang());
         unset($this->pageCurrentLang->language_id);
     }
     $pageLang = $this->pageLang();
     $pageLangDefaults = array_merge(['language_id' => Language::current(), 'url' => '', 'name' => '', 'live_version' => 1], $pageLang->getAttributes());
     foreach ($pageLangDefaults as $pageLangAttribute => $pageLangDefault) {
         $pageLang->{$pageLangAttribute} = array_key_exists($pageLangAttribute, $pageLangPost) ? $pageLangPost[$pageLangAttribute] : $pageLangDefault;
     }
     /*
      * Check page parent exists if set and page limit is not hit
      */
     $parent = static::find($this->parent);
     if ($this->parent > 0 && !$parent) {
         return false;
     }
     if (!$this->id && !$this->link && static::at_limit($this->parent == -1)) {
         return false;
     }
     /*
      * Check page name/url set and does not conflict
      */
     $pageLang->url = trim($pageLang->url);
     if (!$this->link) {
         $pageLang->url = strtolower(str_replace(['/', ' '], '-', $pageLang->url));
         if (preg_match('#^[-]+$#', $pageLang->url)) {
             $pageLang->url = '';
         }
         if ($pageLang->url == '' && !$this->parent) {
             $pageLang->url = '/';
         }
         $siblings = [];
         foreach ($pageGroupsPost as $pageGroupId => $checkedVal) {
             $pageGroup = PageGroup::preload($pageGroupId);
             $siblings = array_merge($pageGroup->exists ? $pageGroup->itemPageIds() : [], $siblings);
         }
         if ($this->parent >= 0) {
             $siblings = array_merge(static::getChildPageIds($this->parent), $siblings);
         }
         $siblings = array_unique($siblings);
     }
     if (!$pageLang->name) {
         FormMessage::add('page_info_lang[name]', 'page name required');
     }
     if (!$pageLang->url) {
         FormMessage::add('page_info_lang[url]', 'page url required');
     }
     if (!empty($siblings)) {
         $same_level = PageLang::where('url', '=', $pageLang->url)->whereIn('page_id', $siblings);
         $same_level = $this->id ? $same_level->where('page_id', '!=', $this->id) : $same_level;
         if (!$same_level->get()->isEmpty()) {
             FormMessage::add('page_info_lang[url]', 'url in use by another page!');
             $pageLang->url = '';
         }
     }
     if (!$pageLang->name || !$pageLang->url) {
         return false;
     }
     /*
      * If adding a page as a group container, create container / check exists
      */
     if ($this->group_container == -1) {
         $groupContainer = new PageGroup();
         $groupContainer->name = $pageLang->name;
         $groupContainer->item_name = 'Page';
         $groupContainer->default_template = 0;
         $groupContainer->save();
         $this->group_container = $groupContainer->id;
     } elseif ($this->group_container) {
         $groupContainer = PageGroup::preload($this->group_container);
         if (!$groupContainer->exists || $pageDefaults['group_container'] != $this->group_container && !$groupContainer->canEditItems()) {
             $this->group_container = 0;
         }
     }
     /*
      * Check if page info can be updated (based on publishing auth action, or allowed if new page)
      */
     $authPageIdCheck = $this->id ?: ($this->parent > 0 ? $this->parent : 0);
     $canPublish = config('coaster::admin.publishing') > 0 && Auth::action('pages.version-publish', ['page_id' => $authPageIdCheck]) || config('coaster::admin.publishing') == 0 && Auth::action('pages.edit', ['page_id' => $authPageIdCheck]);
     $canPublish = $canPublish || isset($groupContainer) && (config('coaster::admin.publishing') > 0 && $groupContainer->canPublishItems() || config('coaster::admin.publishing') == 0 && $groupContainer->canEditItems());
     $willPublish = !$this->id || $canPublish;
     /*
      * Check and save page changes
      */
     if ($willPublish) {
         // if new page set as last ordered page
         if ($this->parent >= 0 && !$this->id) {
             $lastSibling = static::where('parent', '=', $this->parent)->orderBy('order', 'desc')->first();
             $this->order = $lastSibling ? $lastSibling->order + 1 : 1;
         }
         // if new page publish template
         $this->template = $this->id ? $this->template : $pageVersion->template;
         // if link remove live template
         $this->template = $this->link ? 0 : $this->template;
         // set page live between but no dates set set as hidden, or if can't publish set as hidden
         $this->live = $this->live == 2 && is_null($this->live_end) && is_null($this->live_start) ? 0 : $this->live;
         $this->live = $canPublish ? $this->live : 0;
         // save page data
         $this->save();
         $pageLang->page_id = $this->id;
         $pageLang->save();
     }
     $pageVersion->page_id = $this->id;
     $pageVersion->save();
     /*
      * Update title block to the page name is new page
      */
     if (!$this->id && ($titleBlock = Block::where('name', '=', config('coaster::admin.title_block'))->first())) {
         $titleBlock->setVersionId($pageVersion->version_id)->setPageId($this->id)->getTypeObject()->save($pageLang->name);
         PageSearchData::updateText(strip_tags($pageLang->name), 0, $this->id);
     }
     /*
      * Save Page Groups
      */
     $currentGroupIds = $this->groupIds();
     $newGroupIds = array_keys($pageGroupsPost);
     PageGroupPage::where('page_id', '=', $this->id)->whereIn('group_id', array_diff($currentGroupIds, $newGroupIds))->delete();
     foreach (array_diff($newGroupIds, $currentGroupIds) as $addGroupId) {
         $this->groups()->attach($addGroupId);
     }
     /*
      * Save other page info
      */
     if ($willPublish && Auth::action('menus')) {
         MenuItem::set_page_menus($this->id, array_key_exists('menus', $pageInfoOther) ? $pageInfoOther['menus'] : []);
     }
     if ($canPublish && array_key_exists('beacons', $pageInfoOther) && Auth::action('themes.beacons-update')) {
         BlockBeacon::updatePage($this->id, $pageInfoOther['beacons']);
     }
     return true;
 }
 public function getSelects($blockId = null, $import = 0)
 {
     if ($blockId) {
         $block = Block::where('type', 'LIKE', '%select%')->where('type', 'NOT LIKE', '%selectpage%')->where('id', '=', $blockId)->first();
     }
     if (!empty($block)) {
         if ($import) {
             $import = ['fa-4.6' => 'Font Awesome Class List 4.6.1'];
             $this->layoutData['content'] = View::make('coaster::pages.themes.selects', ['block' => $block, 'import' => $import]);
         } else {
             $options = BlockSelectOption::where('block_id', '=', $blockId)->get();
             $options = $options->isEmpty() ? [] : $options;
             $this->layoutData['content'] = View::make('coaster::pages.themes.selects', ['block' => $block, 'options' => $options]);
         }
     } else {
         $selectBlocks = [];
         $blocks = Block::where('type', 'LIKE', '%select%')->where('type', 'NOT LIKE', '%selectpage%')->get();
         if (!$blocks->isEmpty()) {
             foreach ($blocks as $block) {
                 $selectBlocks[$block->id] = $block->name;
             }
         }
         $this->layoutData['content'] = View::make('coaster::pages.themes.selects', ['blocks' => $selectBlocks]);
     }
 }
示例#4
0
 public function createPost($data)
 {
     $pageLang = PageLang::where('name', '=', $data->title->rendered)->first();
     $uporc = 'updated';
     if (empty($pageLang)) {
         $uporc = 'created';
         $page = new Page();
         $pageLang = new PageLang();
     } else {
         $page = Page::find($pageLang->page_id);
         $comments = $this->getComments($data, $page);
         $latestVersion = PageVersion::latest_version($page->id, true);
         if (!empty($latestVersion)) {
             $latestVersion->publish();
         }
         if (!empty($data->yoast)) {
             $this->getMetas($data->yoast, $data, $page->id);
         }
         $res = new \stdClass();
         $res->message = 'Post ' . $uporc . ': ' . $pageLang->name;
         $res->oldLink = $data->link;
         $res->newLink = Path::getFullUrl($page->id);
         $res->categories = 'UPDATE RUN';
         $res->tags = 'UPDATE RUN';
         return $res;
     }
     $page->live = 2;
     $page->live_start = $this->carbonDate($data->date)->format("Y-m-d H:i:s");
     $page->created_at = $this->carbonDate($data->date);
     $page->updated_at = $this->carbonDate($data->modified);
     $page->parent = $this->groupPage->id;
     $page->template = $this->group->default_template;
     $page->save();
     $page->groups()->sync([$this->group->id]);
     $comments = $this->getComments($data, $page);
     $categories = $this->getCategory($data->_embedded->{"wp:term"}, $page->id);
     // Page Lang
     $pageLang->live_version = 0;
     $pageLang->page_id = $page->id;
     $pageLang->language_id = Language::current();
     $pageLang->name = $data->title->rendered;
     $pageLang->url = str_slug($pageLang->name);
     $pageLang->save();
     $tags = $this->syncTags($page, $data->_embedded->{"wp:term"});
     $date_block = Block::where('name', '=', 'post_date')->first();
     if (!empty($date_block)) {
         $date_block->setPageId($page->id)->getTypeObject()->save($this->carbonDate($data->date)->format("Y-m-d H:i:s"));
     }
     $title_block = Block::where('name', '=', config('coaster::admin.title_block'))->first();
     if (!empty($title_block)) {
         $title_block->setPageId($page->id)->getTypeObject()->save($pageLang->name);
     }
     $content_block = Block::where('name', '=', 'content')->first();
     if (!empty($content_block)) {
         $content_block->setPageId($page->id)->getTypeObject()->save($this->processContent($data->content->rendered));
     }
     $leadText_block = Block::where('name', '=', 'lead_text')->first();
     if (!empty($leadText_block)) {
         $leadText_block->setPageId($page->id)->getTypeObject()->save($data->excerpt->rendered);
     }
     $latestVersion = PageVersion::latest_version($page->id, true);
     if (!empty($latestVersion)) {
         $latestVersion->publish();
     }
     if (!empty($data->yoast)) {
         $this->getMetas($data->yoast, $data, $page->id);
     }
     $res = new \stdClass();
     $res->message = 'Post ' . $uporc . ': ' . $pageLang->name;
     $res->oldLink = $data->link;
     $res->newLink = Path::getFullUrl($page->id);
     $res->categories = $categories;
     $res->tags = $tags;
     return $res;
 }