Example #1
0
 public function backupInit($config)
 {
     F('_backup_', '[del]');
     //创建目录
     if (!is_dir($config['dir']) && !mkdir($config['dir'], 0755, true)) {
         View::error('目录创建失败', $config['url']);
     }
     $table = Db::getAllTableInfo();
     $table = $table['table'];
     foreach ($table as $d) {
         //limit起始数
         $table[$d['tablename']]['first'] = 0;
         //文件编号
         $table[$d['tablename']]['fileId'] = 1;
     }
     $cache['table'] = $table;
     $cache['config'] = $config;
     //备份表结构
     $tables = Db::getAllTableInfo();
     $sql = "<?php if(!defined('HDPHP_PATH'))EXIT;\n";
     foreach ($tables['table'] as $table => $data) {
         $createSql = Db::select("SHOW CREATE TABLE {$table}");
         $sql .= "Db::execute(\"DROP TABLE IF EXISTS {$table}\");\n";
         $sql .= "Db::execute(\"{$createSql[0]['Create Table']}\");\n";
     }
     if (file_put_contents($config['dir'] . '/structure.php', $sql)) {
         file_put_contents($config['dir'] . '/config.php', "<?php return " . var_export($config, true) . ";");
         F('_backup_', $cache);
         return true;
     } else {
         F('_backup_' . '[del]');
         $this->error = '表结构备份失败';
         return false;
     }
 }
Example #2
0
 /**
  * Forgot password
  */
 private function forgotpwd()
 {
     if (isset($_POST['forgotpwd'])) {
         $email = $_POST['email'];
         if (!Validate::len($email)) {
             $error = 'Email character count must be between 4 and 64';
         } elseif (!Validate::email($email)) {
             $error = 'Please enter a valid email';
         }
         if (!$error) {
             $user = User::where('email', $email)->select('id')->findOne();
             if (!$user) {
                 $error = 'Email address not found';
             }
         }
         if ($error) {
             View::error('user/forgotpwd', $error);
         }
         // Makes an internal session
         $pwd = Session::set('pwd', $user->id, 0);
         View::set('session_pwd', $pwd);
         Base::sendMail($email, 'forgotpwd');
         Base::redirect('', 'Go to your email and follow the instructions');
     } elseif (isset($_GET['pwd'])) {
     }
 }
 /**
  * [login 登录]
  * @return [type] [description]
  */
 public function login()
 {
     if (IS_POST) {
         if (strtoupper(I('post.code')) != strtoupper(myRedis::get('code'))) {
             View::error('验证码错误!', 'http://' . __HOST__ . '/admin/login/');
             die;
         }
         $userName = I('post.username');
         $password = I('post.password');
         $pwd = md5('ISirweb' . $password);
         $userData = Admin::where(['who' => $userName, 'mypwd' => $pwd])->get()->toArray();
         if (empty($userData)) {
             View::error('用户名或密码错误!', 'http://' . __HOST__ . '/admin/login/');
             die;
         }
         //如果未修改php.ini下面两行注释去掉
         // ini_set('session.save_handler', 'redis');
         // ini_set('session.save_path', 'tcp://127.0.0.1:6379');
         session_start();
         $_SESSION['uid'] = $userData[0]['id'];
         $_SESSION['name'] = $userData[0]['who'];
         $_SESSION['email'] = $userData[0]['email'];
         View::success('登录成功', 'http://' . __HOST__ . '/admin/');
         die;
     }
     $this->smarty->assign('title', '登录_ISisWeb中文网_ISirPHPFramework');
     $this->smarty->display('Admin/Login/login.html');
     die;
 }
Example #4
0
 public function edit()
 {
     if (IS_POST) {
         if ($this->db->edit()) {
             View::success('操作成功', 'index');
         } else {
             View::error($this->db->getError());
         }
     } else {
         //商品分类
         $cate = new \Admin\Model\ShopCate();
         $cateData = $cate->getAll();
         View::with('cateData', $cateData);
         //商品品牌
         $brand = new \Admin\Model\ShopBrand();
         $brandData = $brand->getAll();
         View::with('brandData', $brandData);
         //获取图集信息
         $pics = new \Admin\Model\Pics();
         $picsData = $pics->getAll();
         View::with('picsData', $picsData);
         //商品类型列表
         $type = new \Admin\Model\ShopType();
         $typeData = $type->getAll();
         View::with('typeData', $typeData);
         //商品属性列表
         $attr = new \Admin\Model\GoodsAttr();
         $attrData = $attr->getAll(Q('goods_id'));
         View::with('attrData', $attrData);
         //读取商品信息
         $field = $this->db->getOne();
         View::with('field', $field)->make();
     }
 }
Example #5
0
 /**
  * Starting point for every page request. Loads required core modules, gets data from url and calls
  * necessary modules to make things happen.
  */
 public static function init()
 {
     if (!self::$_inited) {
         self::$_inited = true;
         foreach (self::$_requiredCore as $module) {
             require_once ROOT . 'core/' . $module . '/' . $module . EXT;
         }
         // Set the Load::auto method to handle all class loading from now on
         spl_autoload_register('Load::auto');
         Load::loadSetupFiles();
         // If CLI mode, everything thats needed has been loaded
         if (IS_CLI) {
             return;
         }
         date_default_timezone_set(Config::get('system.timezone'));
         Event::trigger('caffeine.started');
         // If maintenance mode has been set in the config, stop everything and load mainteance view
         if (Config::get('system.maintenance_mode')) {
             View::error(ERROR_MAINTENANCE);
         } else {
             list($route, $data) = Router::getRouteData();
             if ($data) {
                 if (self::_hasPermission($route, $data)) {
                     list($module, $controller, $method) = $data['callback'];
                     $params = Router::getParams();
                     // Make sure controller words are upper-case
                     $conBits = explode('_', $controller);
                     foreach ($conBits as &$bit) {
                         $bit = ucfirst($bit);
                     }
                     $controller = implode('_', $conBits);
                     $controller = sprintf('%s_%sController', ucfirst($module), ucwords($controller));
                     // Call the routes controller and method
                     if (method_exists($controller, $method)) {
                         $response = call_user_func_array(array($controller, $method), $params);
                         if (!self::_isErrorResponse($response)) {
                             Event::trigger('module.response', array($response));
                             View::load($module, $controller, $method);
                         } else {
                             View::error($response);
                         }
                     } else {
                         Log::error($module, sprintf('The method %s::%s() called by route %s doesn\'t exist.', $controller, $method, $route));
                         View::error(ERROR_500);
                     }
                 } else {
                     View::error(ERROR_ACCESSDENIED);
                 }
             } else {
                 if ($route !== '[index]' || !View::directLoad('index')) {
                     View::error(ERROR_404);
                 }
             }
         }
         View::output();
         Event::trigger('caffeine.finished');
     } else {
         die('Why are you trying to re-initialize Caffeine?');
     }
 }
 public function __construct()
 {
     parent::__construct();
     session_start();
     if (!isset($_SESSION['uid'])) {
         View::error('请登录。。。', 'http://' . __HOST__ . '/admin/login/');
         die;
     }
 }
 /**
  * Callback que se ejecuta antes de los métodos de todos los controladores
  */
 protected final function initialize()
 {
     /**
      * Si el método de entrada es ajax, el tipo de respuesta es sólo la vista
      */
     if (Input::isAjax()) {
         View::template(null);
     }
     /**
      * Verifico que haya iniciado sesión
      */
     if (!MkcAuth::isLogged()) {
         //Verifico que no genere una redirección infinita
         if ($this->controller_name != 'login' && ($this->action_name != 'entrar' && $this->action_name != 'salir')) {
             MkcMessage::warning('No has iniciado sesión o ha caducado.');
             //Verifico que no sea una ventana emergente
             if ($this->module_name == 'reporte') {
                 View::error();
                 //TODO: crear el método error()
             } else {
                 MkcRedirect::toLogin('sistema/login/entrar/');
             }
             return false;
         }
     } else {
         if (MkcAuth::isLogged() && $this->controller_name != 'login') {
             $acl = new MkcAcl();
             //Cargo los permisos y templates
             if (APP_UPDATE && Session::get('perfil_id') != Perfil::SUPER_USUARIO) {
                 //Solo el super usuario puede hacer todo
                 if ($this->module_name != 'dashboard' && $this->controller_name != 'index') {
                     $msj = 'Estamos en labores de actualización y mantenimiento.';
                     $msj .= '<br />';
                     $msj .= 'El servicio se reanudará dentro de ' . APP_UPDATE_TIME;
                     if (Input::isAjax()) {
                         View::update();
                     } else {
                         MkcMessage::info($msj);
                         MkcRedirect::to("dashboard");
                     }
                     return FALSE;
                 }
             }
             if (!$acl->check(Session::get('perfil_id'))) {
                 MkcMessage::error('Tu no posees privilegios para acceder a <b>' . Router::get('route') . '</b>');
                 Input::isAjax() ? View::ajax() : View::select(NULL);
                 return false;
             }
             if (!defined('SKIN')) {
                 define('SKIN', Session::get('tema'));
             }
         }
     }
 }
 public function edit()
 {
     if (IS_POST) {
         if ($this->db->edit()) {
             View::success('操作成功', 'index');
         } else {
             View::error($this->db->getError());
         }
     } else {
         $field = $this->db->getOne();
         View::with('field', $field)->make();
     }
 }
 /**
  * Método para listar las autitorías del sistema
  * @param type $fecha
  * @return type
  */
 public function listar($fecha = '', $formato = 'html')
 {
     $fecha = empty($fecha) ? date("Y-m-d") : Filter::get($fecha, 'date');
     if (empty($fecha)) {
         DwMessage::info('Selecciona la fecha del archivo');
         return View::error();
     }
     $audits = Sistema::getAudit($fecha);
     $this->audits = $audits;
     $this->fecha = $fecha;
     $this->page_module = 'Auditorías del sistema ' . $fecha;
     $this->page_format = $formato;
 }
Example #10
0
 public function add()
 {
     if (IS_POST) {
         // p($_POST);exit;
         if ($this->db->store()) {
             View::success('发表成功', 'index');
         } else {
             View::error($this->db->getError());
         }
     } else {
         $cat = $this->category->getAll();
         View::with('cat', $cat)->make();
     }
 }
Example #11
0
 /**
  * Método para verificar si la llave es válida
  * 
  * @param string $id
  * @param string $action
  * @param string $filter Filtro a aplicar al id devuelto
  * @return boolean
  */
 public static function isValidKey($valueKey, $action = '', $filter = '', $popup = FALSE)
 {
     $key = explode('.', $valueKey);
     $id = $key[0];
     $validKey = self::getKey($id, $action);
     $valid = $validKey === $valueKey ? TRUE : FALSE;
     if (!$valid) {
         DwMessage::error('Acceso denegado. La llave de seguridad es incorrecta.');
         if ($popup) {
             View::error();
         }
         return FALSE;
     }
     return $filter ? Filter::get($id, $filter) : $id;
 }
 public function edit()
 {
     if (IS_POST) {
         if ($this->db->edit()) {
             View::success('操作成功', 'index');
         } else {
             View::error($this->db->getError());
         }
     } else {
         //分配品牌分类
         $cate = new \Admin\Model\ShopCate();
         $cateData = $cate->getAll();
         $field = $this->db->getOne();
         View::with('field', $field)->with('cateData', $cateData)->make();
     }
 }
Example #13
0
 public function edit()
 {
     if (IS_POST) {
         p($_POST['thumb']);
         if ($this->db->update()) {
             View::success('修改成功', 'index');
         } else {
             View::error($this->db->getError());
         }
     }
     $id = Q('id', 0, 'intval');
     $data = $this->db->where('id', $id)->first();
     p($data);
     $data2 = new \Sadmin2\Model\Category();
     $data2 = $data2->getAll();
     View::with('data', $data)->with('data2', $data2)->make();
 }
Example #14
0
 public function edit()
 {
     if (IS_POST) {
         if ($this->db->edit()) {
             View::success('操作成功', 'index');
         } else {
             View::error($this->db->getError());
         }
     } else {
         //搜索页规格分类
         $type = new \Admin\Model\ShopType();
         $typeData = $type->getAll();
         View::with('typeData', $typeData);
         $data = $this->db->getAll();
         $field = $this->db->getOne();
         View::with('data', $data)->with('field', $field)->make();
     }
 }
Example #15
0
 public function edit()
 {
     if (IS_POST) {
         if ($this->db->update()) {
             View::success('修改成功', 'index');
         } else {
             View::error($this->db->getError());
         }
     } else {
         //读取栏目数据
         $category = new \Admin\Model\Category();
         $cat = $category->getAll();
         //原文章的数据
         $field = Db::table('article')->where('id', $_GET['id'])->first();
         View::with('cat', $cat)->with('field', $field);
         View::make();
     }
 }
Example #16
0
 public static function to($location = null)
 {
     if ($location) {
         if (is_numeric($location)) {
             switch ($location) {
                 case 401:
                     header('HTTP/1.1 401 Unauthorized');
                     View::error('401');
                     exit;
                     break;
                 case 404:
                     header('HTTP/1.0 404 Not Found');
                     View::error('404');
                     exit;
                     break;
             }
         }
         header('Location: ' . $location);
         exit;
     }
 }
Example #17
0
 public function __construct()
 {
     if (!isset($_GET['q'])) {
         View::error('search/search');
     }
     // Allows algorithm to process search input
     $this->query = Base::searchQuery($_GET['q']);
     if (!$this->query) {
         View::error('search/search');
     }
     // Set search query in view
     View::set('search_query', str_replace('%', ' ', $this->query));
     if (SECOND_PARAMETER === 'playlists' || SECOND_PARAMETER === 'users' || SECOND_PARAMETER === 'tracks') {
         $func = SECOND_PARAMETER;
         $this->{$func}();
         View::set('page_title', ucfirst($func));
         View::show('search/' . $func);
     }
     $this->search();
     View::set('page_title', 'Search');
     View::show('search/search');
 }
 /**
  * [article_update 更新文章]
  * @return [type] [description]
  */
 public function article_update($slug)
 {
     if (IS_POST) {
         //实例化上传类
         $storage = new \Upload\Storage\FileSystem(__UPLOAD__);
         $file = new \Upload\File('foo', $storage);
         $fileName = $file->getNameWithExtension();
         if (!empty($fileName)) {
             // Optionally you can rename the file on upload
             $new_filename = uniqid();
             $file->setName($new_filename);
             // Validate file upload
             // MimeType List => http://www.webmaster-toolkit.com/mime-types.shtml
             $file->addValidations([new \Upload\Validation\Mimetype(['image/png', 'image/gif', 'image/jpeg', 'image/jpg']), new \Upload\Validation\Size('5M')]);
             // Access data about the file that has been uploaded
             $data = ['name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5(), 'dimensions' => $file->getDimensions()];
             // Try to upload file
             try {
                 // Success!
                 $file->upload();
                 $arcData = ['title' => I('post.title'), 'thumb' => $data['name'], 'keywords' => I('post.keywords'), 'content' => I('post.content'), 'description' => I('post.description'), 'category_id' => I('post.category_id'), 'click' => I('post.click'), 'writer' => I('post.writer'), 'source' => I('post.source'), 'pubdate' => time()];
                 Article::where(['id' => $slug])->update($arcData);
                 View::success('修改成功');
                 die;
             } catch (\Exception $e) {
                 // Fail!
                 $errors = $file->getErrors();
                 View::error($errors['0']);
                 die;
             }
         }
         if (isset($_POST['del_img'])) {
             $arcData = ['title' => I('post.title'), 'keywords' => I('post.keywords'), 'thumb' => '', 'content' => I('post.content'), 'description' => I('post.description'), 'category_id' => I('post.category_id'), 'click' => I('post.click'), 'writer' => I('post.writer'), 'source' => I('post.source'), 'pubdate' => time()];
             Article::where(['id' => $slug])->update($arcData);
             View::success('修改成功');
             die;
         } else {
             $arcData = ['title' => I('post.title'), 'keywords' => I('post.keywords'), 'content' => I('post.content'), 'category_id' => I('post.category_id'), 'click' => I('post.click'), 'writer' => I('post.writer'), 'source' => I('post.source'), 'pubdate' => time()];
             Article::where(['id' => $slug])->update($arcData);
             View::success('修改成功');
             die;
         }
     }
     $arcData = Article::find($slug)->toArray();
     //print_r($arcData);
     $topcate = Category::where(['pid' => 0, 'is_del' => 0])->get()->toArray();
     //组合分类数据
     foreach ($topcate as $k => $v) {
         $soncate = Category::where(['pid' => $v['id'], 'is_del' => 0])->get()->toArray();
         $topcate[$k]['soncate'] = $soncate;
     }
     $allcate = $topcate;
     $this->smarty->assign('title', '修改文章_ISisWeb中文网后台管理_ISirPHPFramework');
     $this->smarty->assign('cate', $allcate);
     $this->smarty->assign('arcData', $arcData);
     $this->smarty->display('Admin/Article/update.html');
     // die();
     // $this->view = View::make('/Admin/Article/update')
     // 				->with('cate',$allcate)
     // 				->with('arcData',$arcData)
     // 				->with('title','修改文章_ISirWeb中文网后台');
 }
 /**
  * [category_delete 删除分类信息]
  * @return [type] [description]
  */
 public function category_delete($slug)
 {
     $cate = Category::where(['id' => $slug])->firstOrFail();
     $pdateNum = Category::where(['pid' => $slug])->count();
     if ($pdateNum > 0) {
         View::error('请先删除该栏目下的子栏目', 'http://' . __HOST__ . '/admin/category/');
         die;
     }
     $cate->is_del = 1;
     $cate->save();
     View::success('删除成功', 'http://' . __HOST__ . '/admin/category/');
     die;
 }
Example #20
0
 /**
  * Abort the request with an error, default is 500.
  *
  * @param int $code The error code to return in the response.
  * @param boolean|string|\Closure $action Optional template or Closure function.
  */
 public function error($code = 500, $action = false)
 {
     \View::error($code, $action);
 }
Example #21
0
 /**
  * Edit a playlist
  */
 private function edit()
 {
     Base::requireLogged();
     if (LOGGED !== $this->playlist->user_id) {
         Base::requireAdmin();
     }
     // Set page title
     View::set('page_title', 'Edit playlist');
     // Set playlist
     $playlist = $this->playlist->asArray();
     $playlist['tracks'] = $this->playlist->tracks();
     $tags = $this->playlist->tags();
     if ($tags) {
         $playlist['tags'] = implode(', ', $tags);
     }
     View::set('playlist', $playlist);
     // Not submitted
     if (!isset($_POST['playlist']) && !isset($_POST['draft'])) {
         View::show('playlist/edit');
     }
     /**
      * Add playlist title and playlist description
      */
     if (!Validate::len($_POST['title'], 2, 64)) {
         $error = 'Playlist title must be between 2 and 64 chars';
     } elseif (!Validate::len($_POST['description'], 0, 512)) {
         $error = 'Playlist description must be lesser than 512 chars';
     }
     if ($error) {
         View::error('playlist/edit', $error);
     }
     // Raw HTML may enter the db but it's automatically
     // encoded at output by Mustache
     $this->playlist->title = $_POST['title'];
     $this->playlist->description = $_POST['description'];
     /**
      * Uploads cover image
      */
     if (!empty($_FILES['cover']) && $_FILES['cover']['size'] > 0) {
         Base::uploadImage($_FILES['cover'], $cover, $error);
         if ($error) {
             View::error('playlist/edit', $error);
         }
         $this->playlist->cover = $cover;
     }
     /**
      * Inserts tags into database
      */
     if (!empty($_POST['tags'])) {
         // Separates tags by commas
         $tags = strtolower($_POST['tags']);
         $tags = explode(',', $tags, 6);
         // Tag limit
         $tags = array_slice($tags, 0, 5);
         // Filter tags
         foreach ($tags as $k => &$tag) {
             if (!ADMIN && $tag === 'staff') {
                 continue;
             }
             $tag = preg_replace('/[^a-z]+/', ' ', $tag);
             $tag = trim($tag, ' ');
             // Tag must have at least 2 chars
             // And it must be lesser than 32 chars
             if (!Validate::len($tag, 1, 32)) {
                 unset($tags[$k]);
             }
         }
         if (!empty($tags)) {
             // Remove tags from PlaylistTag
             PlaylistTag::where('playlist_id', $this->playlist->id)->deleteMany();
             // Insert tags
             $sql = str_repeat(',(?)', count($tags));
             $sql[0] = ' ';
             Tag::rawExecute("INSERT IGNORE INTO tag(name) VALUES {$sql}", $tags);
             // Get inserted tags ids and point them to the new playlist
             $tags = Tag::select('id')->whereIn('name', $tags)->findMany();
             foreach ($tags as $tag) {
                 $link = PlaylistTag::create();
                 $link->playlist_id = $this->playlist->id;
                 $link->tag_id = $tag->id;
                 $link->save();
             }
         }
     }
     // Published status
     $this->playlist->published = isset($_POST['playlist']);
     /**
      * Add tracks into db
      */
     if (!isset($_POST['tracks'])) {
         $error = 'You can\'t publish without any tracks';
         $this->playlist->published = 0;
     } else {
         if (is_array($_POST['tracks'])) {
             $max = Base::$g['playlist_max_tracks'];
             $min = Base::$g['playlist_min_tracks'];
             $tracks = $_POST['tracks'];
             if (!isset($tracks[$min - 1])) {
                 $error = "You can't publish without at least {$min} tracks";
                 $this->playlist->published = 0;
             } elseif (isset($track[$max])) {
                 $error = "You can't have more than {$max} tracks in a playlist";
                 $tracks = array_slice($tracks, 0, $max);
             }
             /**
              * Check for haxing
              */
             foreach ($tracks as $k => &$item) {
                 $item = Validate::int($item);
                 if ($item === false) {
                     unset($tracks[$k]);
                 }
             }
             // Also get duration
             $row = Track::whereIn('id', $tracks)->selectExpr('COUNT(id)', 'count')->selectExpr('SUM(duration)', 'duration')->findOne();
             if ($row->count != count(array_unique($tracks))) {
                 View::error('playlist/edit', 'Massive error 2. Contact the admin');
             }
             // Store duration in minutes
             $this->playlist->tracks_count = $row->count;
             $this->playlist->duration = $row->duration / 60;
             // Delete the ones already in
             PlaylistTrack::where('playlist_id', $this->playlist->id)->deleteMany();
             // Add new ones
             foreach ($tracks as $track) {
                 $table = PlaylistTrack::create();
                 $table->playlist_id = $this->playlist->id;
                 $table->track_id = $track;
                 $table->save();
             }
         } else {
             View::error('playlist/edit', 'Massive error. Contact the admin');
         }
     }
     /**
      * Update playlist in database
      */
     $this->playlist->save();
     $msg = $error ?: 'Playlist succesfully edited';
     Base::redirect('/' . $this->playlist->id, $msg);
 }
Example #22
0
 /**
  * User settings
  */
 private function settings()
 {
     Base::requireLogged();
     if (LOGGED !== $this->user->id) {
         Base::requireAdmin();
     }
     if (!isset($_POST['usr']) && !isset($_POST['avatar']) && !isset($_POST['pwd'])) {
         View::show('profile/settings');
     }
     // Username or email change
     if (isset($_POST['usr'])) {
     } elseif (isset($_POST['avatar'])) {
         Base::uploadImage($_FILES['avatar'], $avatar, $error);
         if ($error) {
             View::error('profile/settings', $error);
         }
         $this->user->avatar = $avatar;
         $this->user->save();
         View::set('success', 'Avatar successfully changed');
         View::set('user', $this->user->asArray());
         // Actualized user
         View::show('profile/settings');
     } elseif (isset($_POST['password'])) {
         $currentPwd = $_POST['current_pwd'];
         $password = $_POST['password'];
         $password2 = $_POST['password2'];
         if (!Base::checkPassword($currentPwd, $this->user->password)) {
             $error = 'You misspelled your current password';
             // Need help? Forgot pwd
         } elseif (!Validate::len($password, 4, 128)) {
             $error = 'Password must have more than 4 characters';
         } elseif ($password != $password2) {
             $error = 'Passwords don\'t match';
         }
         if ($error) {
             View::error('profile/settings', $error);
         }
         $this->user->password = Base::hashPassword($password);
         $this->user->save();
         View::set('success', 'Password successfully changed');
         View::show('profile/settings');
     }
 }
Example #23
0
 protected function error($message = '操作失败', $url = null, $time = 1)
 {
     View::error($message, $url, $time);
 }