Beispiel #1
0
 public function userAvatarAction($id = false)
 {
     $views = $this->getView();
     $data = $this->getRequest();
     $members = MembersManage::instance();
     $app = $members->getCurrentSession();
     if (!$app) {
         exit;
     }
     $image = new ImagesManage();
     $userControl = new AdminUserManage();
     if ($id and $tmp = explode("?", $id)) {
         $id = $tmp[0];
     }
     $member = new AdminUserManage();
     $user = $member->getUserForId($id);
     $views->assign('user', $user);
     $views->assign('app', $app);
     if ($data->isPost()) {
         switch ($data->getQuery('action')) {
             case 'upload':
                 if ($file = $data->getQuery('file')) {
                     $avatar_id = $image->saveImagesMemberFromCut($file, $data->getPost('x'), $data->getPost('y'), $data->getPost('width'), $data->getPost('height'), $user['id'], 1, true);
                     if ($avatar_id) {
                         $userControl->updateUser($id, array('avatar_id' => $avatar_id));
                         ImagesManage::unlink(ImagesManage::getRealPath($file));
                     }
                 }
                 break;
             case 'crop':
                 $file = $data->getFiles('picture');
                 $path = $image->save($file, $user['id'], 'tmp');
                 $scaled = getimagesize(ImagesManage::getRealPath($path));
                 if ($scaled[0] >= 800 or $scaled[1] >= 800) {
                     MessageManage::createResponse($views, '上传格式错误', '上传图片格式错误,图片长宽小于 800px。');
                     ImagesManage::unlink($path);
                 } else {
                     if (!ImagesManage::hasImageType($scaled[2], true)) {
                         MessageManage::createResponse($views, '上传格式错误', '上传图片格式错误,请上传jpg, gif, png格式的文件。');
                     }
                 }
                 if ($path) {
                     header('Location: /admin/user/avatar/' . $id . '?action=upload&file=' . $path);
                     exit;
                 }
                 break;
             default:
                 # code...
                 break;
         }
     } else {
         if ($data->getQuery('action') == 'upload') {
             if ($file = $data->getQuery('file')) {
                 $views->assign('scaled', ImagesManage::getImageSizeForPath($file, 480));
                 $views->assign('file', ImagesManage::getRelativeImage($file));
                 $views->assign('tmp', $data->getQuery('file'));
                 $views->display('admin/user/user-avatar-crop-modal.html.twig');
             }
         } else {
             $memberImage = $image->getImagesMemberForID($id, 1);
             $coverPath = isset($memberImage['path']) ? ImagesManage::getRelativeImage($memberImage['path']) : false;
             $views->assign('image', $coverPath);
         }
     }
     $views->assign('title', '编辑用户头像');
     $views->display('admin/user/user-avatar-modal.html.twig');
 }
Beispiel #2
0
 public function lessonArticleImageAction($cid, $ccid, $action = 'upload')
 {
     $data = $this->getRequest();
     $rest = Restful::instance();
     $members = MembersManage::instance();
     $app = $members->getCurrentSession();
     if (!$app) {
         exit;
     }
     $image = new ImagesManage();
     if ($action == 'upload' and $data->isPost()) {
         if ($filepath = $image->saveImagesCourseArticle($data->getFiles('file'), $cid, $ccid, $app['uid'], true, 1, true)) {
             $rest->assign('filelink', ImagesManage::getRelativeImage($filepath));
             $rest->response();
         }
     } elseif ($action == 'list') {
         $list = $image->getImagesCourseArticleForID($cid);
         if ($list) {
             $images = array();
             foreach ($list as $key => $value) {
                 $thumb = $value['thumb'] > 0 ? $image->getRealCoverSize($value['path'], 'small', 'jpg') : '';
                 $images[] = array('thumb' => $thumb, 'image' => ImagesManage::getRelativeImage($value['path']), 'title' => $value['filename'], 'folder' => $ccid);
             }
             echo stripslashes(json_encode($images));
             exit;
         }
     }
     exit;
 }
Beispiel #3
0
 /**
  * Login
  *
  * @param String ,$email
  * @param String ,$password
  * @return Boolean or Array
  */
 public function login($email, $password)
 {
     if ($this->getCurrentSession() or empty($email) or empty($password)) {
         return false;
     }
     $email = addslashes($email);
     $password = addslashes($password);
     $wherearr = "email='" . $this->members->escapeString($email) . "' AND password='******'";
     $row = $this->members->field("id,email,username,role_id,published")->where($wherearr)->fetchRow();
     if ($row) {
         if ($user = $this->getCurrentSession()) {
             if ($user['uid'] == $row['id']) {
                 return false;
             }
         } else {
             $roles = new RolesControl();
             $role = $roles->getRolePermissionForId($row['role_id']);
             $permission = $role ? $role['permission'] : false;
             $info_table = $this->memberInfo->table;
             $info = $this->memberInfo->field("{$info_table}.id, {$info_table}.avatar_id, im.path as cover")->joinQuery("images_member as im", "im.imid={$info_table}.avatar_id")->where("{$info_table}.id='" . $row['id'] . "'")->order("{$info_table}.last_dateline DESC")->limit("1")->fetchList();
             $app = array('uid' => $row['id'], 'email' => $row['email'], 'username' => $row['username'], 'cover' => false, 'role_id' => $row['role_id'], 'permission' => $permission);
             $infoArr = array('last_ip' => Registry::get('common')->ip(), 'last_dateline' => UPDATE_TIME);
             $this->memberInfo->where("id='" . $row['id'] . "'")->update($infoArr);
             if (is_array($info)) {
                 foreach ($info as $key => $value) {
                     if (isset($value['avatar_id']) and $value['avatar_id']) {
                         $app['cover_small'] = ImagesManage::getRealCoverSize($value['cover']);
                         $app['cover_medium'] = ImagesManage::getRealCoverSize($value['cover'], "medium");
                         $app['cover'] = ImagesManage::getRelativeImage($value['cover']);
                     }
                 }
             }
             $_SESSION['app'] = $app;
             return $row['id'];
         }
     }
     return false;
 }
Beispiel #4
0
 /**
  * Get BookRow Row
  *
  * @param Array , $option
  * @return Array
  */
 public function getBookRow($option = array())
 {
     if (!is_array($option) or !$option) {
         return false;
     }
     $sql = '';
     $i = 1;
     $count = count($option);
     foreach ($option as $key => $value) {
         if ($i == $count) {
             $sql .= "{$key}='" . $value . "'";
         } else {
             $sql .= "{$key}='" . $value . "' AND ";
         }
         $i++;
     }
     $table = $this->book->table;
     $list = $this->book->field("{$table}.bid,{$table}.cid,bc.name,{$table}.title,{$table}.author,{$table}.pubtime,{$table}.isbn,{$table}.press,f.subtitle,f.oldtitle,f.apple_price as price,{$table}.summary,f.translator,f.tags,f.copyright,f.download_path as path,f.designer,f.proofreader,f.wordcount,f.dateline,bf.uid,bf.verified,bf.published,m.username,ib.path as cover")->joinQuery("book_info as f", "{$table}.bid=f.bid")->joinQuery('book_fields as bf', "{$table}.bid=bf.bid")->joinQuery('book_category as bc', "{$table}.cid=bc.cid")->joinQuery('images_book as ib', "{$table}.cover=ib.ibid")->joinQuery('members as m', 'bf.uid=m.id')->where($sql)->limit(1)->fetchList();
     if ($list and is_array($list)) {
         if (isset($list[0]['cover']) and $list[0]['cover']) {
             $list[0]['cover'] = ImagesManage::getRelativeImage($list[0]['cover']);
         }
         if (isset($list[0]['published']) and $list[0]['published']) {
             $list[0]['published'] = $this->changedBookStatus(intval($list[0]['published']));
         }
         if (isset($list[0]['verified']) and $list[0]['verified']) {
             $list[0]['verified'] = $this->changedBookVerified(intval($list[0]['verified']));
         }
         return $list[0];
     }
     return false;
 }
Beispiel #5
0
 public function courseCheckAction($cid, $ccid, $action = false)
 {
     $rest = Restful::instance();
     $data = $this->getRequest();
     $success = 0;
     $message = '';
     $members = MembersManage::instance();
     $app = $members->getCurrentSession();
     if (!$app) {
         exit;
     }
     if ($data->isPost()) {
         $datas = array('title' => $data->getPost('title'), 'summary' => $data->getPost('summary'));
         $courseControl = AdminCourseManage::instance();
         switch ($action) {
             case 'chapter':
                 $datas['ccid'] = $data->getPost('ccid');
                 if ($datas and $courseControl->updateCourse($cid, $datas)) {
                     $course = $course = $courseControl->getCourseRow(array('course.cid' => $cid, "course.verified" => 3, "course.published" => 4));
                     $success = 1;
                     $message = $course;
                 }
                 if ($cover = $data->getFiles('cover') and $cover['error'] == 0) {
                     $image = new ImagesManage();
                     $coversize = $cover['size'] * 0.001;
                     $covertype = explode('/', $cover['type']);
                     if ($coversize >= 2048) {
                         $message = '文件大小不能超过 2M.';
                     } else {
                         if ($covertype and !ImagesManage::hasImageType($covertype[1])) {
                             $message = '上传图片格式错误,请上传jpg, gif, png格式的文件.';
                         } else {
                             if ($cover) {
                                 if ($aid = $image->saveImagesCourse($cover, $cid, $app['uid'], 1, 1)) {
                                     $courseControl->updateCourse($cid, array('cover' => $aid));
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 'article':
                 $datas['ccid'] = $ccid;
                 if ($datas and $courseControl->createArticle($cid, $datas)) {
                     $success = 1;
                     $message = $courseControl->getArticleForID($ccid);
                 }
                 # code...
                 break;
             case 'chapter-delete':
                 if ($cid and $courseControl->deleteCourse($cid)) {
                     $success = 1;
                     $message = "";
                 }
                 break;
             case 'article-delete':
                 if ($cid and $ccid and $courseControl->deleteArticle($ccid)) {
                     $success = 1;
                     $message = "";
                 }
                 break;
             case 'sort':
                 if ($menus = $data->getPost('ids')) {
                     $menulist = array();
                     foreach ($menus as $key => $value) {
                         $menu_id = explode("-", $value);
                         $menulist[$key + 1] = intval($menu_id[2]);
                     }
                     $courseControl->updateChapterSort($cid, $menulist);
                     $success = 1;
                 }
                 break;
             default:
                 # code...
                 break;
         }
     }
     $rest->assign('success', $success);
     $rest->assign('message', $message);
     $rest->response();
 }
 /**
  * [getCourseList description]
  * @param  array   $option [description]
  * @param  integer $limit  [description]
  * @param  integer $page   [description]
  * @return [type]          [description]
  */
 public function getCourseList($option = array(), $limit = 10, $page = 1, $order = false)
 {
     $sql = $option;
     if (is_array($option) and $option) {
         $i = 1;
         $count = count($option);
         $sql = '';
         foreach ($option as $key => $value) {
             if ($i == $count) {
                 $sql .= "{$key}='" . $value . "'";
             } else {
                 $sql .= "{$key}='" . $value . "' AND ";
             }
             $i++;
         }
     }
     $offset = $page == 1 ? 0 : ($page - 1) * $limit;
     $table = $this->course->table;
     $order = $order ? $order : "{$table}.dateline DESC";
     $list = $this->course->field("{$table}.cid,{$table}.title,{$table}.ccid,{$table}.uid,{$table}.private,{$table}.published,{$table}.verified,{$table}.dateline,{$table}.modified,{$table}.summary,{$table}.tags,{$table}.price,cc.name as category, m.username,ic.path as cover,ic.thumb, im.path as usercover, mi.summary as usersummary, cf.click as clickcount, cf.student as studentcount, cf.chapters as chapterscount")->joinQuery('course_category as cc', "{$table}.ccid=cc.ccid")->joinQuery('course_fields as cf', "{$table}.cid=cf.cid")->joinQuery('images_course as ic', "{$table}.cover=ic.icid")->joinQuery('members as m', "{$table}.uid=m.id")->joinQuery('member_info as mi', "m.id=mi.id")->joinQuery('images_member as im', 'm.id=im.uid')->where($sql)->order($order)->limit("{$offset},{$limit}")->fetchList();
     if (is_array($list)) {
         foreach ($list as $key => $value) {
             if (isset($value['usercover']) and $value['usercover']) {
                 $list[$key]['usercover_s'] = ImagesManage::getRealCoverSize($value['usercover']);
                 $list[$key]['usercover_m'] = ImagesManage::getRealCoverSize($value['usercover'], 'medium');
                 $list[$key]['usercover'] = ImagesManage::getRelativeImage($value['usercover']);
                 empty($list[$key]['usercover_s']) and $list[$key]['usercover_s'] = $list[$key]['usercover_m'];
                 empty($list[$key]['usercover_m']) and $list[$key]['usercover_m'] = $list[$key]['usercover'];
             }
             if (isset($value['title']) and $value['title']) {
                 $list[$key]['ptitle'] = $this->convert($value['title']);
             }
             if (isset($value['cover']) and $value['cover']) {
                 $list[$key]['cover'] = ImagesManage::getRelativeImage($value['cover']);
             }
             if (isset($value['thumb']) and $value['thumb'] == 1) {
                 $list[$key]['cover_m'] = ImagesManage::getRealCoverSize($value['cover'], 'medium', 'jpg');
                 $list[$key]['cover_s'] = ImagesManage::getRealCoverSize($value['cover'], 'small', 'jpg');
                 empty($list[$key]['cover_s']) and $list[$key]['cover_s'] = $list[$key]['cover_m'];
                 empty($list[$key]['cover_m']) and $list[$key]['cover_m'] = $list[$key]['cover'];
             }
             if (isset($value['published']) and $value['published']) {
                 $list[$key]['published'] = $this->changedCourseStatus(intval($value['published']));
             }
             if (isset($value['verified']) and $value['verified']) {
                 $list[$key]['verified'] = $this->changedCourseVerified(intval($value['verified']));
             }
         }
         return $list;
     }
     return false;
 }