public function bin() { // auth Util\Auth::isAdminAuthorized($this->signedUser, 'admin.dev', true, '/'); // check $result = ''; $empty = Util\Converter::bool('empty'); $contentItems = []; // content items $options = []; $options['where'][] = 'module.has_content = 1'; $modules = \Rebond\Cms\Module\Data::loadAll($options); $options = []; $options['where'][] = ['content.version IN (?)', [4, 5]]; $options['order'][] = 'content.modified_date'; foreach ($modules as $module) { $appData = '\\Rebond\\App\\' . $module->getTitle() . '\\Data'; $items = $appData::loadAll($options); if (count($items) > 0) { if ($empty) { foreach ($items as $item) { $item->delete(); } } else { $contentItems[$module->getTitle()] = $items; } } } // CSS $filePath = \Rebond\Config::getPath('siteFolder') . '/css/skin/'; $skins = Util\File::getFolders($filePath); $cssFiles = []; foreach ($skins as $skin) { $cssFiles[$skin] = []; $path = $filePath . $skin . '/'; $files = Util\File::getFiles($path); foreach ($files as $file) { if (Util\File::getExtension($file) == 'css') { continue; } if ($empty) { Util\File::delete($path, $file); } else { $date = Util\Format::date(filemtime(FULL_PATH . $path . $file), 'smart'); $cssFiles[$skin][] = ['name' => $file, 'date' => $date]; } } } // Main Templates $path = 'views/' . \Rebond\Config::getPath('siteFolder') . '/'; $templates = Util\File::getFiles($path); $mainTpl = []; foreach ($templates as $tpl) { if (Util\File::getExtension($tpl) == 'tpl') { continue; } if ($empty) { Util\File::delete($path, $tpl); } else { $date = Util\Format::date(filemtime(FULL_PATH . $path . $tpl), 'smart'); $mainTpl[] = ['name' => $tpl, 'date' => $date]; } } // App Templates $appFolders = Util\File::getFolders('Rebond/App/'); $appTpl = []; foreach ($appFolders as $app) { $appTpl[$app] = []; $path = 'Rebond/App/' . $app . '/template/'; $templates = Util\File::getFiles($path); foreach ($templates as $tpl) { if (Util\File::getExtension($tpl) == 'tpl') { continue; } if ($empty) { Util\File::delete($path, $tpl); } else { $date = Util\Format::date(filemtime(FULL_PATH . $path . $tpl), 'smart'); $appTpl[$app][] = ['name' => $tpl, 'date' => $date]; } } } if ($empty) { $result = '<p class="bg-success">' . Util\Lang::lang('binEmptied') . '</p>'; } // view $this->setTpl(); // main $tplMain = new Util\Template(Util\Template::SITE, ['admin', 'dev']); $tplMain->set('contentItems', $contentItems); $tplMain->set('cssFiles', $cssFiles); $tplMain->set('mainTpl', $mainTpl); $tplMain->set('appTpl', $appTpl); $tplMain->set('result', $result); // layout $this->tplLayout->set('column1', $tplMain->render('bin')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); $this->tplMaster->set('jsLauncher', 'dev'); return $this->tplMaster->render('tpl-default'); }
public function tpl_edit() { // auth Util\Auth::isAdminAuthorized($this->signedUser, 'admin.designer', true, '/'); // check $file = Util\Converter::string('f'); $app = Util\Converter::string('app'); $save = Util\Converter::string('save', 'post'); if (empty($file)) { Util\Session::adminError('itemNotFound', [$file], '/designer/tpl'); } $validator = Util\Validate::validateFilename('file', $file, true); if (!$validator->isValid()) { Util\Session::setAndRedirect('adminError', $validator->getMessage(), '/designer/tpl'); } $filePath = FULL_PATH . 'views/www/'; if (!empty($app)) { $filePath = FULL_PATH . 'Rebond/App/' . $app . '/template/'; $validator = Util\Validate::validateAlphaNumeric('app', $app, true); if (!$validator->isValid()) { Util\Session::setAndRedirect('adminError', $validator->getMessage(), '/designer/tpl'); } } if (!file_exists($filePath)) { Util\Session::adminError('itemNotFound', [$filePath], '/designer/tpl'); } // action if (isset($save)) { $filePost = Util\Converter::string('file', 'post'); $tplFile = Util\Converter::string('tpl-file', 'post'); $appPost = Util\Converter::string('app', 'post'); $file = FULL_PATH . 'views/' . \Rebond\Config::getPath('siteFolder') . '/' . $filePost; if (!empty($appPost)) { $file = \Rebond\Config::getPath('rebond') . 'App/' . $appPost . '/template/' . $filePost; } if (!isset($file) || Util\File::getExtension($file) != 'tpl') { Util\Session::adminError('fileNotFoundOrValid', [$file], '/designer/css'); } if (!copy($file, Util\File::getNoExtension($file) . '-' . Util\Format::date(time(), 'string') . '.bak')) { Util\Session::adminError('itemNotCopied', [$file], '/designer/css'); } file_put_contents($file, $tplFile); Util\Session::adminSuccess('saved', '/designer/tpl'); } // view $this->setTpl(); // main $tplMain = new Util\Template(Util\Template::SITE, ['admin', 'designer']); $tplMain->set('file', $file); $tplMain->set('app', $app); $tplMain->set('filePath', $filePath); $tplMain->set('editable', Util\File::getExtension($file) == 'tpl'); // layout $this->tplLayout->set('column1', $tplMain->render('tpl-form')); // master $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col')); $this->tplMaster->set('jsLauncher', 'designerTpl'); $this->tplMaster->addCss('/css/codemirror.css'); $this->tplMaster->addJs('/js/codemirror/codemirror.js'); $this->tplMaster->addJs('/js/codemirror/htmlmixed.js'); $this->tplMaster->addJs('/js/codemirror/xml.js'); $this->tplMaster->addJs('/js/codemirror/clike.js'); $this->tplMaster->addJs('/js/codemirror/php.js'); return $this->tplMaster->render('tpl-default'); }
private static function validateFilename($serverPath, $path, $filename) { if ($filename == '' || !file_exists($serverPath . $path . $filename)) { return ['', 'default.png']; } $ext = File::getExtension($filename); switch ($ext) { case 'png': case 'gif': case 'jpg': case 'jpeg': return [$path, $filename]; break; case 'doc': case 'docx': return ['', 'doc.png']; break; case 'pdf': return ['', 'pdf.png']; break; case 'txt': case 'xml': return ['', 'txt.png']; break; case 'mp3': return ['', 'music.png']; break; case 'mp4': case 'avi': return ['', 'video.png']; break; case 'xls': case 'xlsx': return ['', 'xls.png']; break; } return ['', 'default.png']; }
public function uploadify() { $json = []; $json['result'] = ResultType::ERROR; // check $id = Converter::int('userId', 'post', 0); $this->signedUser = \Rebond\Core\User\Data::loadById($id); if (!isset($this->signedUser)) { $json['message'] = Lang::lang('accessNonAuthorized'); return json_encode($json); } if (!$this->hasPrivilege('admin.media.upload')) { return $this->noPrivilege('admin.media.upload'); } $folderId = Converter::int('folderId', 'post'); $isSelectable = Converter::int('isSelectable', 'post', 1); if (!isset($folderId)) { $json['message'] = Lang::lang('errorInvalidParameters'); return json_encode($json); } $upload = \Rebond\Util\Media::upload('', $_FILES['Filedata']); $originalName = $_FILES['Filedata']['name']; if ($upload == ResultType::ERROR) { $json['message'] = Lang::lang('errorFileUpload', [$originalName]); Log::log(Error::MEDIA_NOT_SAVED, $json['message'], __FILE__, __LINE__); return json_encode($json); } list($w, $h) = getimagesize(\Rebond\Config::getPath('media') . $upload); $ext = \Rebond\Util\File::getExtension(\Rebond\Config::getPath('media') . $upload); $noExt = \Rebond\Util\File::getNoExtension($originalName); $media = new \Rebond\Core\Media\Model(); $media->setFolderId($folderId); $media->setTitle($noExt); $media->setAlt($noExt); $media->setOriginalFilename($originalName); $media->setExtension($ext); $media->setWidth($w); $media->setHeight($h); $media->setFilesize(filesize(\Rebond\Config::getPath('media') . $upload)); $mimeType = new \finfo(FILEINFO_MIME_TYPE); $media->setMimetype($mimeType->file(\Rebond\Config::getPath('media') . $upload)); $media->setUpload($upload); $media->setIsSelectable($isSelectable); $media->save(); $json['result'] = ResultType::SUCCESS; $json['id'] = $media->getId(); $json['message'] = Lang::lang('mediaUploaded', [$originalName]); return json_encode($json); }