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 deleteBin() { if (!$this->hasPrivilege('admin.dev')) { return $this->noPrivilege('admin.dev'); } $json = []; $json['result'] = ResultType::ERROR; // file selected $module = Converter::string('module', 'post'); $contentId = Converter::int('contentId', 'post'); $file = Converter::string('file', 'post'); if (isset($module) && isset($contentId)) { $appData = '\\Rebond\\App\\' . $module . '\\Data'; $item = $appData::loadById($contentId); if (!isset($item)) { $json['message'] = Lang::lang('itemNotFound', [$contentId]); return json_encode($json); } $item->delete(); $json['result'] = ResultType::SUCCESS; $json['message'] = Lang::lang('deleted'); return json_encode($json); } if (isset($file)) { $skin = Converter::string('skin', 'post'); $app = Converter::string('app', 'post'); if (isset($skin)) { $toDelete = \Rebond\Config::getPath('siteFolder') . '/css/skin/' . $skin . '/'; } else { if (isset($app)) { $toDelete = 'Rebond/App/' . $app . '/template/'; } else { $toDelete = 'views/' . \Rebond\Config::getPath('siteFolder') . '/'; } } if (!file_exists(FULL_PATH . $toDelete . $file)) { $json['message'] = Lang::lang('itemNotFound', [$file]); return json_encode($json); } if (!File::delete($toDelete, $file)) { $json['message'] = Lang::lang('itemNotDeleted', [$file]); return json_encode($json); } $json['result'] = ResultType::SUCCESS; $json['message'] = Lang::lang('deleted'); return json_encode($json); } $json['message'] = Lang::lang('errorInvalidParameters'); return json_encode($json); }