public function text_editor() { // auth Auth::isAdminAuthorized($this->signedUser, 'admin.media.image', true, '/media'); // check $info = null; $generate = Converter::bool('generate'); $imageListPath = \Rebond\Config::getPath('admin') . 'js/tinymce/imageList.js'; // action if ($generate) { $url = \Rebond\Config::getPath('siteUrl') . \Rebond\Config::getPath('mediaFolder'); $list = '['; $options = []; $options['clearSelect'] = true; $options['select'][] = \Rebond\Core\Media\Data::getList(['id', 'title', 'path', 'upload']); $options['where'][] = 'media.status = 1'; $options['where'][] = 'media.extension IN ("png", "gif", "jpg", "jpeg")'; $options['order'][] = 'media.title'; $medium = \Rebond\Core\Media\Data::loadAll($options); foreach ($medium as $media) { $list .= '{title:"' . $media->getTitle() . '", value:"http://' . $url . $media->getPath() . $media->getUpload() . '"},' . chr(10); } if (count($medium) > 0) { $list = substr($list, 0, -2); } $list .= ']'; File::save($imageListPath, 'w', $list); $info = '<p class="bg-success">' . count($medium) . ' ' . Lang::lang('photosGenerated') . '</p>'; } // view $this->setTpl(); // main $tplMain = new Template(Template::SITE, ['admin', 'media']); $tplMain->set('info', $info); if (file_exists($imageListPath)) { $tplMain->set('date', \Rebond\Util\Format::smartDate(filemtime($imageListPath))); $tplMain->set('link', '/js/tinymce/imageList.js'); } else { $tplMain->set('date', 'n/a'); } // layout $this->tplLayout->set('column1', $tplMain->render('text-editor')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); return $this->tplMaster->render('tpl-default'); }
public function selectMedia() { if (!$this->hasPrivilege('admin.content.edit')) { return $this->noPrivilege('admin.content.edit'); } $json = []; $json['result'] = ResultType::ERROR; // check $field = Converter::string('field', 'post'); $hashParam = Converter::string('hash', 'post'); $search = Converter::string('search', 'post'); if (!isset($field) || !isset($hashParam)) { $json['message'] = Lang::lang('errorInvalidParameters'); return json_encode($json); } $hash = explode('/', $hashParam); $hash = array_slice($hash, 1); $folderId = isset($hash[0]) && $hash[0] != '' ? (int) $hash[0] : 0; $page = isset($hash[1]) && $hash[1] != '' ? (int) $hash[1] : 1; $type = isset($hash[2]) && $hash[2] != '' ? $hash[2] : 'all'; $order = isset($hash[3]) && $hash[3] != '' ? $hash[3] : 'modified_date'; $orderType = isset($hash[4]) && $hash[4] != '' ? $hash[4] : 'desc'; if (!in_array($type, ['all', 'images', 'videos', 'documents'])) { $type = 'all'; } if (!in_array($order, ['title', 'extension', 'modified_date'])) { $order = 'modified_date'; } if (!in_array($orderType, ['asc', 'desc'])) { $orderType = 'desc'; } $options = []; $options['where'][] = 'media.status = 1'; $options['where'][] = 'media.is_selectable = 1'; if ($folderId != 0) { $options['where'][] = ['media.folder_id = ?', $folderId]; } if (isset($search) && $search != '') { $options['where'][] = ['media.title LIKE ?', '%' . $search . '%']; } if ($type != 'all') { switch ($type) { case 'images': $options['where'][] = 'media.extension IN ("jpg", "jpeg", "png")'; break; case 'videos': $options['where'][] = 'media.extension IN ("avi", "mov")'; break; case 'documents': $options['where'][] = 'media.extension IN ("pdf", "xls", "xlsx", "doc", "docx")'; break; } } $mediaCount = \Rebond\Core\Media\Data::count($options); // get user settings $userSettings = \Rebond\Cms\UserSettings\Data::loadByUserId($this->signedUser->getId()); $mediaView = 'grid'; $mediaListCount = 10; if (isset($userSettings)) { $mediaView = $userSettings->getMediaView() == 0 ? 'grid' : 'list'; $mediaListCount = (int) $userSettings->getMediaPagingValue(); } if ($page < 1) { $page = 1; } if ($page > ceil($mediaCount / $mediaListCount) && $mediaCount > 0) { $page = ceil($mediaCount / $mediaListCount); } $folders = \Rebond\Core\Folder\Service::renderList(); // add paging and order $options['order'][] = 'media.' . $order . ' ' . $orderType; $options['limit'][] = ($page - 1) * $mediaListCount . ', ' . $mediaListCount; $media = \Rebond\Core\Media\Data::loadAll($options); $tpl = new Template(Template::MODULE, ['core', 'media']); $tpl->set('items', $media); $tpl->set('field', $field); $tplFilter = new Template(Template::MODULE, ['core', 'media']); $tplFilter->set('current', $page); $tplFilter->set('folders', $folders); $tplFilter->set('maxByPage', $mediaListCount); $tplFilter->set('count', $mediaCount); $tplFilter->set('mediaView', $mediaView); $tplFilter->set('order', $order . '_' . $orderType); $tplFilter->set('type', $type); $tplFilter->set('folderId', $folderId); $tplFilter->set('hash', '#!/' . $folderId . '/' . $page . '/' . $type . '/' . $order . '/' . $orderType); $tplFilter->set('search', $search); $json['result'] = ResultType::SUCCESS; $json['message'] = Lang::lang('listUpdated') . ' (' . count($media) . ')'; $json['html'] = $tplFilter->render('select-filter'); $json['html'] .= $tpl->render('select-' . $mediaView); return json_encode($json); }