function write($logStr, $logArray = [], $errorType = self::WARNING) { if (empty($logStr)) { return false; } if (count($logArray) > 0) { foreach ($logArray as $key => $value) { $logStr = str_replace("{" . $key . "}", $value, $logStr); } } $logStr .= "\n"; $folder = $this->customFolder != null ? PATH . DIRECTORY_SEPARATOR . $this->customFolder : LOG; $file = $this->customFile != null ? $this->customFile : Route::getUrl()[0]; $file .= "_" . date("d-m-Y") . ".log"; $full_path = $folder . DIRECTORY_SEPARATOR . $file; if (!file_exists($file) and !is_writable($folder)) { return false; } $handler = fopen($full_path, "a"); if ($handler) { fwrite($handler, "[" . date("H:i:s") . "] [" . $errorType . "] " . $logStr); } else { return false; } fclose($handler); return true; }
public function saveRobots($data) { $file = DIR . '/' . PATH . 'robots.txt'; if (!file_put_contents($file, $data)) { Bufer::add(array('errors' => 'Ошибка сохранения данных')); } else { header("location:" . Route::getUrl('?mode=admin&route=robots_txt&file=robots.txt')); } }
/** * @param Route $route * @return bool */ public function includes(Route $route) { foreach ($this->routes as $match_route) { if ($route->getUrl() == $match_route->getUrl()) { return true; } } return false; }
public function saveCss($css, $fileCss) { $path = DIR . '/' . PATH . 'app/css/'; if (!file_put_contents($path . $fileCss, $css)) { Bufer::add(array('errors' => 'Ошибка сохранения данных')); } else { header("location:" . Route::getUrl('?mode=admin&route=css&file=' . $fileCss)); } }
public function deleteUser($uid) { $result = $this->model->deleteUser($uid); if ($result['success'] === true) { header("location:" . Route::getUrl('?mode=admin&route=users')); } else { Bufer::add(array('errors' => $result['error'])); } }
public function deleteHtmlSnippet($hsid) { $hsid = isset($_GET['delete']) ? (int) $_GET['delete'] : 0; $result = $this->model->deleteHtmlSnippet($hsid); if ($result['success'] === false) { Bufer::add(array('errors' => $result['error'])); } else { header("location:" . Route::getUrl('?mode=admin&route=htmlsnippets')); } }
public function addsection($data) { $sindex = $this->escape($data['sindex']); $sname = $this->escape($data['sname']); $sdescription = $this->escape($data['sdescription']); $sql = "insert into section (sindex,sname,sdescription) values ('" . $sindex . "', '" . $sname . "', '" . $sdescription . "')"; $result = $this->sqlQuery($sql); if ($result !== false) { header("location: " . Route::getUrl('?mode=admin&route=sections')); } else { return array('success' => false, 'errors' => array('Произошла ошибка при добавлении нового раздела')); } }
public function Savesection($data) { $sid = (int) $data['sid']; $sindex = $this->escape($data['sindex']); $sname = $this->escape($data['sname']); $sdescription = $this->escape($data['sdescription']); $sql = "insert into section (sindex,sname,sdescription) values ('" . $sindex . "', '" . $sname . "', '" . $sdescription . "')"; $sql = "update section set \n sindex = '" . $sindex . "',\n sname = '" . $sname . "',\n sdescription = '" . $sdescription . "'\n where sid = " . $sid; $result = $this->updateData($sql); if ($result !== false) { header("location: " . Route::getUrl('?mode=admin&route=editsection&sid=' . $sid)); } else { return array('success' => false, 'errors' => array('Произошла ошибка при редактировании раздела')); } }
/** * @param array $routeConfig * @param Route|null $parentRoute * * @return Route */ private function processRoute(array $routeConfig, Route $parentRoute = null) { $name = $routeConfig['name']; $url = isset($routeConfig['options']['route']) ? $routeConfig['options']['route'] : ''; $controller = isset($routeConfig['options']['defaults']['controller']) ? $routeConfig['options']['defaults']['controller'] : null; $action = isset($routeConfig['options']['defaults']['action']) ? $routeConfig['options']['defaults']['action'] : null; if (null !== $parentRoute) { $name = $parentRoute->getName() . '/' . $name; $url = $parentRoute->getUrl() . $url; if (null === $controller) { $controller = $parentRoute->getController(); } } if (null === $action) { $action = 'index'; } $action .= 'Action'; return new Route($name, $url, $controller, $action); }
$errors[] = 'Ошибка удаления папки с превью изображений галереи'; } if (!@rmdir('uploads/images/galery/' . $glid)) { $errors[] = 'Ошибка удаления папки галереи'; } if (isset($errors)) { return array('success' => false, 'error' => array($errors)); } else { return array('success' => true); } } public function deleteGalery($glid) { return $this->model->deleteGalery($glid); } } $controller = new GaleryController(); $controller->getListGalery(); if (isset($_GET['deletegalery'])) { $glid = (int) $_GET['deletegalery']; $deleteFoldersGalery = $controller->deleteAllFoldersGalery($glid); $result = $controller->deleteGalery($glid); if ($result['success'] === false) { Bufer::add(array('errors' => $result['error'])); } else { header('location: ' . Route::getUrl('?mode=admin&route=galery')); } } $controller->view(ADMIN_TPLS_DIR . '/header.tpl'); $controller->view(ADMIN_TPLS_DIR . '/galery.tpl'); $controller->view(ADMIN_TPLS_DIR . '/footer.tpl');
public static function go($url) { echo '<script type="text/javascript">location.href="' . Route::getUrl($url) . '"</script>'; }
/** * 根据配置文件的URL参数重新生成URL地址 * @param String $path 访问url * @param array $args GET参数 * <code> * $args = "nid=2&cid=1" * $args=array("nid"=>2,"cid"=>1) * </code> * @return string */ function U($path, $args = array()) { return Route::getUrl($path, $args); }
</div> <?php } ?> <div class="row"> <div class="col-md-3"> <div> <button class="btn btn-success" type="submit" name="saveChanges">Сохранить</button> <button class="btn btn-default" type="submit" formnovalidate name="cancel">Отмена</button> </div> </div> <div class="col-md-2"> <div> <?php if ($canDelete) { ?> <a class="btn btn-link" href="<?php echo Route::getUrl('deleteUser', array('userId' => $user->id)); ?> " onclick="return confirm('Вы уверены, что хотите удалить пользователя?')">Удалить</a> <?php } ?> </div> </div> </div> </form> <?php include TEMPLATE_PATH . "/include/footer.php";
{ $result = $this->model->killPage($pid); return $result; } public function recoveryPage($pid) { $result = $this->model->recoveryPage($pid); return $result; } } $controller = new DeletedpagesController(); if (isset($_GET['killpage'])) { $delete = $controller->killPage((int) $_GET['killpage']); if ($delete === false) { Bufer::set(array('errors' => array('Ошибка при удалении страницы'), 'listPages' => array('data' => $controller->getListPages(), 'paginate' => $controller->paginate()), 'listSections' => $controller->getListSections())); } else { header("location: " . Route::getUrl('?mode=admin&route=deletedpages')); } } if (isset($_GET['recoverypage'])) { $delete = $controller->recoveryPage((int) $_GET['recoverypage']); if ($delete === false) { Bufer::set(array('errors' => array('Ошибка при восстановлении страницы'), 'listPages' => array('data' => $controller->getListPages(), 'paginate' => $controller->paginate()), 'listSections' => $controller->getListSections())); } else { header("location: " . Route::getUrl('?mode=admin&route=deletedpages')); } } Bufer::set(array('listPages' => array('data' => $controller->getListPages(), 'paginate' => $controller->paginate()), 'listSections' => $controller->getListSections())); $controller->view(ADMIN_TPLS_DIR . '/header.tpl'); $controller->view(ADMIN_TPLS_DIR . '/deletedpages.tpl'); $controller->view(ADMIN_TPLS_DIR . '/footer.tpl');
/** * * @return string URL для перехода в пункт меню */ public function getUrl() { return Route::getUrl($this->baseAction); }
public function actionUrl($action, $controller = null, array $routeValues = array()) { $routeValues['action'] = $action; $routeValues['controller'] = $controller ?: $this->context->controller->getControllerName(); return Route::getUrl($this->context->routes, $routeValues); }
<?php include TEMPLATE_PATH . "/include/header.php"; ?> <form action="<?php echo Route::getUrl('login'); ?> " method="post" style="width: 50%;"> <input type="hidden" name="login" value="true" /> <div class="form-group"> <label for="username">Логин</label> <input class="form-control" type="text" name="username" id="username" placeholder="*****@*****.**" required autofocus maxlength="20" /> </div> <div class="form-group"> <label for="password">Пароль</label> <input class="form-control" type="password" name="password" id="password" placeholder="Пароль" required maxlength="20" /> </div> <input class="btn btn-default" type="submit" name="login" value="Вход" /> </form> <?php include TEMPLATE_PATH . "/include/footer.php";
public function __construct() { parent::__construct(); $this->setModel('Groupsusers'); } public function getGroupsUsersList() { return $this->model->getGroupsUsersList(); } public function deleteGroupUsers($acid) { $result = $this->model->deleteGroupUsers($acid); if (isset($result['error'])) { Bufer::add(array('errors' => $result['error'])); } } } $controller = new GroupsusersController(); $acid = isset($_GET['deletegroupusers']) ? (int) $_GET['deletegroupusers'] : false; if ($acid !== false) { $result = $controller->deleteGroupUsers($acid); if ($result['success'] === false) { Bufer::add(array('errors' => $result['error'])); } else { header("location:" . Route::getUrl('?mode=admin&route=groupsusers')); } } Bufer::set(array('groupsUsersList' => $controller->getGroupsUsersList())); $controller->view(ADMIN_TPLS_DIR . '/header.tpl'); $controller->view(ADMIN_TPLS_DIR . '/groupsusers.tpl'); $controller->view(ADMIN_TPLS_DIR . '/footer.tpl');
} else { ?> <li><a href="<?php echo $menu->getUrl(); ?> "><?php echo $menu->label; ?> </a></li> <?php } ?> <?php } ?> </ul> <ul class="nav navbar-nav navbar-right"> <p class="navbar-text">Добро пожаловать, <b><?php echo htmlspecialchars(User::get()->username); ?> </b></p> <li><a href="<?php echo Route::getUrl('logout'); ?> ">Выход</a></li> </ul> </div><!--/.nav-collapse --> </div> </nav> <?php }
<li class="list-group-item"> <div class="row"> <div class="col-md-10"> <?php echo htmlspecialchars($user->username); ?> </div> <div class="col-md-2 pull-right"> <a href="<?php echo Route::getUrl('editUser', array('userId' => $user->id)); ?> "><span class="glyphicon glyphicon-edit"></span> Редактировать</a> </div> </div> </li> <?php } ?> <?php } ?> </ul> <a class="btn btn-default" href="<?php echo Route::getUrl('newUser'); ?> "><span class="glyphicon glyphicon-plus"></span> Добавить пользователя</a></p> <?php include TEMPLATE_PATH . "/include/footer.php";
echo $article->getTitle(); ?> </a> </div> <div class="col-md-2"> <a href="<?php echo Route::getUrl('editArticle', array('articleId' => $article->id)); ?> "><span class="glyphicon glyphicon-edit"></span> Редактировать</a> </div> </div> </li> <?php } ?> </ul> <p>Всего статей: <?php echo $results['totalRows']; ?> .</p> <a class="btn btn-default" href="<?php echo Route::getUrl('newArticle'); ?> "><span class="glyphicon glyphicon-plus"></span> Добавить статью</a> <?php include TEMPLATE_PATH . "/include/footer.php";
</div> <div class="row"> <div class="col-md-3"> <div> <button class="btn btn-success" type="submit" name="saveChanges">Сохранить</button> <button class="btn btn-default" type="submit" formnovalidate name="cancel">Отмена</button> </div> </div> <div class="col-md-2"> <div> <?php if ($results['article']->id) { ?> <a class="btn btn-link" href="<?php echo Route::getUrl('deleteArticle', array('articleId' => $results['article']->id)); ?> " onclick="return confirm('Вы уверены, что хотите удалить статью?')">Удалить</a> <?php } ?> </div> </div> </div> <script> // Replace the <textarea id="content"> with a CKEditor // instance, using default configuration. CKEDITOR.replace('content'); </script> </form>
public function __construct() { parent::__construct(); $this->setModel('Sections'); } public function getSectionsList() { return $this->model->getSectionsList(); } public function deleteSection($sid) { $result = $this->model->deleteSection($sid); if ($result['success'] === false) { Bufer::set(array('errors' => $result['errors'])); } } } $controller = new SectionsController(); Bufer::set(array('sectionsList' => array('data' => $controller->model->getSectionsList(), 'paginate' => $controller->paginate()))); if (isset($_GET['deletesection'])) { $sid = (int) $_GET['deletesection']; $result = $controller->deleteSection($sid); if ($result['success'] === false) { Bufer::set(array('errors' => $errors, 'sectionsList' => array('data' => $controller->model->getSectionsList(), 'paginate' => $controller->paginate()))); } else { header("location: " . Route::getUrl('?mode=admin&route=sections')); } } $controller->view(ADMIN_TPLS_DIR . '/header.tpl'); $controller->view(ADMIN_TPLS_DIR . '/sections.tpl'); $controller->view(ADMIN_TPLS_DIR . '/footer.tpl');
/** * Перенаправление на указанный маршрут. * @param string $action * @param array $values */ public static function redirectTo($action = null, array $values = array()) { header("Location: " . Route::getUrl($action, $values)); }