Exemplo n.º 1
0
 /**
  * Bootstrap the module
  *
  * @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-media');
     $models = isset($config['models']) ? $config['models'] : null;
     $libraries = Table\MediaLibraries::findAll(['order' => 'order ASC']);
     foreach ($libraries->rows() as $library) {
         if (null !== $models) {
             if (!isset($models['Phire\\Media\\Model\\Media'])) {
                 $models['Phire\\Media\\Model\\Media'] = [];
             }
             $models['Phire\\Media\\Model\\Media'][] = ['type_field' => 'library_id', 'type_value' => $library->id, 'type_name' => $library->name];
         }
         $resources['media-library-' . $library->id . '|media-library-' . str_replace(' ', '-', strtolower($library->name))] = ['index', 'add', 'edit', 'remove'];
         if (!isset($params['tree']['media']['children'])) {
             $params['tree']['media']['children'] = [];
         }
         $params['tree']['media']['children']['media-library-' . $library->id] = ['name' => $library->name, 'href' => '/media/' . $library->id, 'acl' => ['resource' => 'media-library-' . $library->id, 'permission' => 'index']];
     }
     $application->mergeConfig(['resources' => $resources]);
     $application->services()->setParams('nav.phire', $params);
     if (null !== $models) {
         $application->module('phire-media')->mergeConfig(['models' => $models]);
     }
 }
Exemplo n.º 2
0
 /**
  * Index action method
  *
  * @return void
  */
 public function index($id = null)
 {
     $this->prepareView('image/index.phtml');
     $libraries = [];
     if (class_exists('Phire\\Media\\Table\\MediaLibraries')) {
         $libs = \Phire\Media\Table\MediaLibraries::findAll(['order' => 'order ASC']);
         foreach ($libs->rows() as $lib) {
             $libraries[$lib->id] = $lib->name;
         }
     }
     $this->view->editor_height = $this->application->module('phire-image')['editor_height'];
     $this->view->libraries = $libraries;
     if (null !== $id) {
         $media = new \Phire\Media\Model\Media();
         $media->getById($id);
         $this->view->image_id = $id;
         $this->view->image_file = $media->file;
         $this->view->library_id = $media->library_id;
         $this->view->library_folder = $media->library_folder;
     }
     if ($this->request->isPost()) {
         $image = new Model\Image();
         $image->process($this->request->getPost(), $this->application->module('phire-image')['adapter'], $this->application->module('phire-image')['history']);
         $this->sess->setRequestValue('saved', true);
         $this->redirect(BASE_PATH . APP_URI . '/image/' . $image->image_id);
     } else {
         $this->view->title = 'Image Editor';
     }
     $this->send();
 }
Exemplo n.º 3
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return MediaLibrary
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->name && null !== $this->folder) {
         // Check for dupe name
         $library = Table\MediaLibraries::findBy(['name' => $this->name]);
         if (isset($library->id) && $this->id != $library->id) {
             $this->getElement('name')->addValidator(new Validator\NotEqual($this->name, 'That name already exists.'));
         }
         // Check for dupe name
         $library = Table\MediaLibraries::findBy(['folder' => $this->folder]);
         if (isset($library->id) && $this->id != $library->id) {
             $this->getElement('folder')->addValidator(new Validator\NotEqual($this->folder, 'That folder already exists.'));
             if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $this->folder)) {
                 $this->getElement('folder')->addValidator(new Validator\NotEqual($this->folder, 'That folder already exists on disk.'));
             }
         }
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * JSON action method
  *
  * @param  int $id
  * @return void
  */
 public function json($id)
 {
     $json = [];
     $library = Table\MediaLibraries::findById($id);
     if (isset($library->id)) {
         if (null !== $library->actions) {
             $actions = unserialize($library->actions);
             $keys = array_keys($actions);
             $values = array_values($actions);
             if (count($keys) > 1 && count($values) > 1) {
                 for ($i = 1; $i < count($keys); $i++) {
                     if (isset($keys[$i]) && isset($values[$i])) {
                         $json[] = ['name' => $keys[$i], 'method' => $values[$i]['method'], 'params' => $values[$i]['params'], 'quality' => $values[$i]['quality']];
                     }
                 }
             }
         }
     }
     $this->response->setBody(json_encode($json, JSON_PRETTY_PRINT));
     $this->send(200, ['Content-Type' => 'application/json']);
 }
Exemplo n.º 5
0
 /**
  * Format the feed item
  *
  * @param  mixed  $item
  * @param  string $type
  * @param  string $feedType
  * @return array
  */
 public function formatItem($item, $type, $feedType)
 {
     if ($type == 'content') {
         $item->link = 'http://' . $_SERVER['HTTP_HOST'] . BASE_PATH . $item->uri;
         $item->pubDate = $item->publish;
         if (isset($item->description)) {
             $item->summary = $item->description;
         }
         unset($item->id);
         unset($item->type_id);
         unset($item->parent_id);
         unset($item->uri);
         unset($item->slug);
         unset($item->status);
         unset($item->template);
         unset($item->order);
         unset($item->roles);
         unset($item->force_ssl);
         unset($item->hierarchy);
         unset($item->created_by);
         unset($item->updated_by);
         unset($item->content_type);
         unset($item->content_type_force_ssl);
         unset($item->strict_publishing);
         unset($item->publish_month);
         unset($item->publish_day);
         unset($item->publish_year);
         unset($item->publish_hour);
         unset($item->publish_minute);
         unset($item->created_by_username);
         unset($item->updated_by_username);
         unset($item->content_parent_id);
         unset($item->content_status);
         unset($item->content_template);
         unset($item->breadcrumb);
         unset($item->breadcrumb_text);
         if (null === $item->expire) {
             unset($item->expire);
         }
     } else {
         if ($type == 'media') {
             $library = \Phire\Media\Table\MediaLibraries::findById($item->library_id);
             $item->link = 'http://' . $_SERVER['HTTP_HOST'] . BASE_PATH . CONTENT_PATH . '/' . $library->folder . '/' . $item->file;
             $item->pubDate = $item->uploaded;
             $item->icon = 'http://' . $_SERVER['HTTP_HOST'] . $item->icon;
             if (isset($item->description)) {
                 $item->summary = $item->description;
                 if ($feedType == 'rss') {
                     $item->description = '<![CDATA[<img src="' . $item->link . '" width="320" /><p>' . $item->description . '</p>]]>';
                 }
             } else {
                 if ($feedType == 'rss') {
                     $item->description = '<![CDATA[<img src="' . $item->link . '" width="320" />]]>';
                 }
             }
             unset($item->id);
             unset($item->library_id);
             unset($item->library_folder);
             unset($item->order);
         }
     }
     return $item->toArray();
 }
Exemplo n.º 6
0
 /**
  * Get count of libraries
  *
  * @return int
  */
 public function getCount()
 {
     return Table\MediaLibraries::findAll()->count();
 }