/** * 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(); }
/** * 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']); }
/** * Remove a library * * @param array $fields * @return void */ public function process(array $fields) { if (isset($fields['rm_media_libraries'])) { foreach ($fields['rm_media_libraries'] as $id) { $library = Table\MediaLibraries::findById((int) $id); if (isset($library->id)) { $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/' . $library->folder); $dir->emptyDir(true); $library->delete(); } } } else { if (isset($fields['process_media_libraries'])) { foreach ($fields['process_media_libraries'] as $id) { $library = new self(); $library->getById((int) $id); if (isset($library->id)) { $class = 'Pop\\Image\\' . $library->adapter; $formats = array_keys($class::getFormats()); $media = Table\Media::findBy(['library_id' => $library->id]); if ($media->count() > 0) { $med = new Media(); foreach ($media->rows() as $m) { $fileParts = pathinfo($m->file); if (!empty($fileParts['extension']) && in_array($fileParts['extension'], $formats)) { $med->processImage($m->file, $library); } } } } } } } }