예제 #1
0
 /**
  * Add content types to models of the module config for the application
  *
  * @param  Application $application
  * @return void
  */
 public static function bootstrap(Application $application)
 {
     $resources = $application->config()['resources'];
     $params = $application->services()->getParams('nav.phire');
     $config = $application->module('phire-content');
     $models = isset($config['models']) ? $config['models'] : null;
     $types = Table\ContentTypes::findAll(['order' => 'order ASC']);
     foreach ($types->rows() as $type) {
         if (null !== $models) {
             if (!isset($models['Phire\\Content\\Model\\Content'])) {
                 $models['Phire\\Content\\Model\\Content'] = [];
             }
             $models['Phire\\Content\\Model\\Content'][] = ['type_field' => 'type_id', 'type_value' => $type->id, 'type_name' => $type->name];
         }
         $resources['content-type-' . $type->id . '|content-type-' . str_replace(' ', '-', strtolower($type->name))] = ['index', 'add', 'edit', 'remove'];
         if (!isset($params['tree']['content']['children'])) {
             $params['tree']['content']['children'] = [];
         }
         $params['tree']['content']['children']['content-type-' . $type->id] = ['name' => $type->name, 'href' => '/content/' . $type->id, 'acl' => ['resource' => 'content-type-' . $type->id, 'permission' => 'index']];
     }
     $application->mergeConfig(['resources' => $resources]);
     $application->services()->setParams('nav.phire', $params);
     if (null !== $models) {
         $application->module('phire-content')->mergeConfig(['models' => $models]);
     }
     $content = Table\Content::findBy(['roles!=' => 'a:0:{}']);
     if ($content->hasRows()) {
         foreach ($content->rows() as $c) {
             $application->services()->get('acl')->addResource(new \Pop\Acl\Resource\Resource('content-' . $c->id));
         }
     }
 }
예제 #2
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return ContentType
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->name) {
         // Check for dupe name
         $type = Table\ContentTypes::findBy(['name' => $this->name]);
         if (isset($type->id) && $this->id != $type->id) {
             $this->getElement('name')->addValidator(new Validator\NotEqual($this->name, 'That content type already exists.'));
         }
     }
     return $this;
 }
예제 #3
0
 /**
  * Get select from options from the Content and Categories
  *
  * @param boolean $contentLoaded
  * @param boolean $categoriesLoaded
  * @return array
  */
 public function getSelectFrom($contentLoaded = false, $categoriesLoaded = false)
 {
     $options = ['content' => [], 'categories' => []];
     if ($contentLoaded) {
         $sess = Session::getInstance();
         unset($sess->lastSortField);
         unset($sess->lastSortOrder);
         unset($sess->lastPage);
         $types = \Phire\Content\Table\ContentTypes::findAll();
         foreach ($types->rows() as $type) {
             $content = new \Phire\Content\Model\Content();
             $content->getAll($type->id, 'id');
             $options['content'][$type->name] = $content->getFlatMap();
         }
     }
     if ($categoriesLoaded) {
         $categories = new \Phire\Categories\Model\Category();
         $categories->getAll();
         $options['categories'] = $categories->getFlatMap();
     }
     return $options;
 }
 /**
  * Edit action method
  *
  * @param  int $id
  * @return void
  */
 public function edit($id)
 {
     $navigation = new Model\Navigation();
     $navigation->getById($id);
     if (!isset($navigation->id)) {
         $this->redirect(BASE_PATH . APP_URI . '/navigation');
     }
     $this->prepareView('navigation/edit.phtml');
     $this->view->title = 'Navigation';
     $this->view->navigation_title = $navigation->title;
     $fields = $this->application->config()['forms']['Phire\\Navigation\\Form\\Navigation'];
     if ($this->application->isRegistered('phire-content')) {
         $contentTypes = \Phire\Content\Table\ContentTypes::findAll(['order' => 'order ASC']);
         foreach ($contentTypes->rows() as $contentType) {
             $fields[0]['create_nav_from']['value'][$contentType->id] = $contentType->name;
         }
     }
     if ($this->application->isRegistered('phire-categories')) {
         $fields[0]['create_nav_from']['value']['categories'] = 'Categories';
     }
     $fields[1]['title']['attributes']['onkeyup'] = 'phire.changeTitle(this.value);';
     $this->view->form = new Form\Navigation($fields);
     $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($navigation->toArray());
     if ($this->request->isPost()) {
         $this->view->form->setFieldValues($this->request->getPost());
         if ($this->view->form->isValid()) {
             $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
             $navigation = new Model\Navigation();
             $navigation->update($this->view->form->getFields());
             $this->view->id = $navigation->id;
             $this->sess->setRequestValue('saved', true);
             $this->redirect(BASE_PATH . APP_URI . '/navigation/manage/' . $navigation->id);
         }
     }
     $this->send();
 }
예제 #5
0
 /**
  * Browser action method
  *
  * @param  int $lid
  * @return void
  */
 public function browser($lid = null)
 {
     if (null !== $this->request->getQuery('editor') && null !== $this->request->getQuery('type')) {
         $this->prepareView('media/browser.phtml');
         $this->view->title = 'Media Browser';
         if ($this->request->isPost()) {
             $library = new Model\MediaLibrary();
             $library->getById($lid);
             $settings = $library->getSettings();
             if (count($settings) == 4) {
                 $upload = new \Pop\File\Upload($settings['folder'], $settings['max_filesize'], $settings['disallowed_types'], $settings['allowed_types']);
                 if ($upload->test($_FILES['file'])) {
                     $media = new Model\Media();
                     $media->save($_FILES['file'], $this->request->getPost());
                     $this->sess->setRequestValue('saved', true);
                     $this->redirect(str_replace('&error=1', '', $_SERVER['REQUEST_URI']));
                 } else {
                     $this->redirect(str_replace('&error=1', '', $_SERVER['REQUEST_URI']) . '&error=1');
                 }
             }
         }
         if (null !== $lid && null !== $this->request->getQuery('asset') && null !== $this->request->getQuery('asset_type')) {
             $assets = [];
             $limit = $this->config->pagination;
             $page = $this->request->getQuery('page');
             $pages = null;
             $library = new Model\MediaLibrary();
             if ($this->request->getQuery('asset_type') == 'content' && $this->application->isRegistered('phire-content')) {
                 $type = \Phire\Content\Table\ContentTypes::findById($lid);
                 $content = \Phire\Content\Table\Content::findBy(['type_id' => $lid], ['order' => 'order, id ASC']);
                 foreach ($content->rows() as $c) {
                     $assets[] = ['id' => $c->id, 'title' => $c->title, 'uri' => BASE_PATH . $c->uri];
                 }
                 if (isset($type->id)) {
                     $this->view->assetType = $type->name;
                 }
             } else {
                 if ($this->request->getQuery('asset_type') == 'media') {
                     $library->getById($lid);
                     $media = new Model\Media(['lid' => $lid]);
                     if ($this->request->getQuery('asset') == 'file') {
                         $assets = $media->getAll();
                     } else {
                         if ($this->request->getQuery('asset') == 'image') {
                             $assets = $media->getAllImages();
                         }
                     }
                     $this->view->assetType = $library->name;
                 }
             }
             if (count($assets) > $limit) {
                 $pages = new Paginator(count($assets), $limit);
                 $pages->useInput(true);
                 $offset = null !== $page && (int) $page > 1 ? $page * $limit - $limit : 0;
                 $assets = array_slice($assets, $offset, $limit, true);
             }
             $this->view->title = 'Media' . (null !== $this->view->assetType ? ' : ' . $this->view->assetType : null);
             $this->view->lid = $lid;
             $this->view->folder = $library->folder;
             $this->view->sizes = null !== $library->actions ? array_keys($library->actions) : [];
             $this->view->pages = $pages;
             $this->view->browserAssets = $assets;
         } else {
             $libraries = [];
             $limit = null;
             $pages = null;
             if ($this->request->getQuery('type') == 'file' && $this->application->isRegistered('phire-content')) {
                 $types = \Phire\Content\Table\ContentTypes::findAll(['order' => 'order ASC']);
                 if ($types->hasRows()) {
                     $libraries['Content'] = [];
                     foreach ($types->rows() as $type) {
                         $libraries['Content'][$type->id] = $type->name;
                     }
                 }
             }
             $libraries['Media'] = [];
             $library = new Model\MediaLibrary();
             $libs = $library->getAll();
             foreach ($libs as $lib) {
                 $libraries['Media'][$lib->id] = $lib->name;
             }
             $this->view->title = 'Media';
             $this->view->pages = $pages;
             $this->view->lid = $lid;
             $this->view->libraries = $libraries;
         }
         $this->send();
     } else {
         $this->redirect(BASE_PATH . APP_URI . '/media');
     }
 }
예제 #6
0
 /**
  * Browser action
  *
  * @return void
  */
 public function browser()
 {
     if (null !== $this->request->getQuery('editor') && null !== $this->request->getQuery('type')) {
         $this->prepareView('fields/browser.phtml');
         $this->view->title = 'File Browser';
         if (null === $this->request->getQuery('asset')) {
             if ($this->request->getQuery('type') == 'image') {
                 $this->view->pages = null;
                 $this->view->libraries = ['Assets' => ['images' => 'Images']];
             } else {
                 $libraries = [];
                 if ($this->application->isRegistered('phire-content')) {
                     $types = \Phire\Content\Table\ContentTypes::findAll(['order' => 'order ASC']);
                     if ($types->hasRows()) {
                         $libraries['Assets'] = [];
                         foreach ($types->rows() as $type) {
                             $libraries['Assets'][$type->id] = $type->name;
                         }
                     }
                 }
                 $libraries['Assets']['files'] = 'Files';
                 $libraries['Assets']['images'] = 'Images';
                 $this->view->pages = null;
                 $this->view->libraries = $libraries;
             }
         } else {
             $asset = $this->request->getQuery('asset');
             $assets = [];
             $limit = $this->config->pagination;
             $page = $this->request->getQuery('page');
             $pages = null;
             $field = new Model\Field();
             $uploadFolder = BASE_PATH . CONTENT_PATH . '/files';
             switch ($asset) {
                 case 'files':
                     $assets = $field->getAllFiles($uploadFolder);
                     $this->view->assetType = 'Files';
                     break;
                 case 'images':
                     $assets = $field->getAllImages($uploadFolder);
                     $this->view->assetType = 'Images';
                     break;
                 default:
                     if (is_numeric($asset) && $this->application->isRegistered('phire-content')) {
                         $type = \Phire\Content\Table\ContentTypes::findById($asset);
                         $content = \Phire\Content\Table\Content::findBy(['type_id' => $asset], ['order' => 'order, id ASC']);
                         foreach ($content->rows() as $c) {
                             $assets[BASE_PATH . $c->uri] = $c->title;
                         }
                         if (isset($type->id)) {
                             $this->view->assetType = $type->name;
                         }
                     }
                     break;
             }
             if (count($assets) > $limit) {
                 $pages = new Paginator(count($assets), $limit);
                 $pages->useInput(true);
                 $offset = null !== $page && (int) $page > 1 ? $page * $limit - $limit : 0;
                 $assets = array_slice($assets, $offset, $limit, true);
             }
             $this->view->pages = $pages;
             $this->view->browserAssets = $assets;
         }
         $this->send();
     }
 }
예제 #7
0
 /**
  * Get count of content types
  *
  * @return int
  */
 public function getCount()
 {
     return Table\ContentTypes::findAll()->count();
 }