public function action_email($action, $email, $link, $data = array(), $server = 'master') { if (!H::valid_email($email)) { $user_info = $this->model('account')->get_user_info_by_uid($email); if ($user_info['email_settings'][$action] == 'N') { return false; } $email = $user_info['email']; } if (!$email) { return false; } $email_message = (array) AWS_APP::config()->get('email_message'); foreach ($email_message[$action] as $key => $val) { ${$key} = str_replace('[#user_name#]', $data['user_name'], $val); ${$key} = str_replace('[#site_name#]', get_setting('site_name'), ${$key}); foreach ($data as $k => $v) { ${$key} = str_replace('[#' . $k . '#]', $data[$k], ${$key}); } } if (in_array($action, array('VALID_EMAIL', 'INVITE_REG', 'FIND_PASSWORD'))) { return $this->send($email, $subject, $message, $link, null, $server); } else { return $this->insert('mail_queue', array('send_to' => $email, 'subject' => $subject, 'message' => $this->get_mail_template($user_info['user_name'], $subject, $message, $link))); } }
public function run_action() { header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: no-cache, must-revalidate'); // HTTP/1.1 header('Pragma: no-cache'); // HTTP/1.0 @set_time_limit(0); if ($call_actions = $this->model('crond')->start()) { foreach ($call_actions as $call_action) { if ($plugins = AWS_APP::plugins()->parse('crond', 'main', $call_action)) { foreach ($plugins as $plugin_file) { include $plugin_file; } } $call_function = $call_action; $this->model('crond')->{$call_function}(); } } if (AWS_APP::config()->get('system')->debug) { TPL::output('global/debuger.tpl.htm'); } }
/** * 系统初始化 */ private static function init() { set_exception_handler(array('AWS_APP', 'exception_handle')); self::$config = load_class('core_config'); self::$db = load_class('core_db'); self::$plugins = load_class('core_plugins'); self::$settings = self::model('setting')->get_settings(); if ((!defined('G_SESSION_SAVE') or G_SESSION_SAVE == 'db') and get_setting('db_version') > 20121123) { Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable(array('name' => get_table('sessions'), 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime'))); self::$session_type = 'db'; } Zend_Session::setOptions(array('name' => G_COOKIE_PREFIX . '_Session', 'cookie_domain' => G_COOKIE_DOMAIN)); if (G_SESSION_SAVE == 'file' and G_SESSION_SAVE_PATH) { Zend_Session::setOptions(array('save_path' => G_SESSION_SAVE_PATH)); } Zend_Session::start(); self::$session = new Zend_Session_Namespace(G_COOKIE_PREFIX . '_Anwsion'); if ($default_timezone = get_setting('default_timezone')) { date_default_timezone_set($default_timezone); } if ($img_url = get_setting('img_url')) { define('G_STATIC_URL', $img_url); } else { define('G_STATIC_URL', base_url() . '/static'); } if (self::config()->get('system')->debug) { if ($cornd_timer = self::cache()->getGroup('crond')) { foreach ($cornd_timer as $cornd_tag) { if ($cornd_runtime = self::cache()->get($cornd_tag)) { AWS_APP::debug_log('crond', 0, 'Tag: ' . str_replace('crond_timer_', '', $cornd_tag) . ', Last run time: ' . date('Y-m-d H:i:s', $cornd_runtime)); } } } } }
public function setup() { if ($this->notify_action_details = AWS_APP::config()->get('notification')->action_details) { foreach ($this->notify_action_details as $key => $val) { $this->notify_actions[] = $key; } } }
public function sql_action() { $sql_file = ROOT_PATH . 'app/upgrade/db/' . str_replace('.', '', $_GET['id']) . '.sql'; if (file_exists($sql_file)) { $sql_query = file_get_contents($sql_file); } if (trim($sql_query)) { $sql_query .= "\n\nUPDATE `[#DB_PREFIX#]system_setting` SET `value` = 's:8:\"" . ($_GET['id'] + 1) . "\";' WHERE `varname` = 'db_version';"; header('Content-type: text/plain; charset=UTF-8'); echo str_replace(array('[#DB_PREFIX#]', '[#DB_ENGINE#]'), array(AWS_APP::config()->get('database')->prefix, $this->db_engine), $sql_query); die; } }
public function run_query($sql_query) { $sql_query = str_replace("\n", "\r", $sql_query); if ($db_table_querys = explode(";\r", str_replace(array('[#DB_PREFIX#]', '[#DB_ENGINE#]'), array(AWS_APP::config()->get('database')->prefix, $this->db_engine), $sql_query))) { foreach ($db_table_querys as $_sql) { if ($query_string = trim(str_replace(array("\r", "\n", "\t"), '', $_sql))) { try { $this->db()->query($query_string); } catch (Exception $e) { return "<b>SQL:</b> <i>{$query_string}</i><br /><b>错误描述:</b> " . $e->getMessage(); } } } } }
public function save_slide_action() { if (!$_POST['title']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请填写幻灯片标题'))); } if (!$_POST['category']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请选择幻灯片分类'))); } if ($_POST['id']) { $slide_info = $this->model('slide')->get_slide_by_id($_POST['id']); if (!$slide_info) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('指定幻灯片不存在'))); } } if ($slide_info) { $this->model('slide')->save_slide($slide_info['id'], $_POST['title'], $_POST['description'], $_POST['link'], $_POST['category']); $id = $slide_info['id']; } else { $id = $this->model('slide')->save_slide(null, $_POST['title'], $_POST['description'], $_POST['link']); if (!$id) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('保存失败'))); } } if ($_FILES['img']['name']) { AWS_APP::upload()->initialize(array('allowed_types' => 'jpg,jpeg,png,gif', 'upload_path' => get_setting('upload_dir') . '/slide', 'is_image' => TRUE))->do_upload('img'); if (AWS_APP::upload()->get_error()) { switch (AWS_APP::upload()->get_error()) { default: H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('错误代码') . ': ' . AWS_APP::upload()->get_error())); break; case 'upload_invalid_filetype': H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('文件类型无效'))); break; } } $upload_data = AWS_APP::upload()->data(); if (!$upload_data) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('上传失败, 请与管理员联系'))); } foreach (AWS_APP::config()->get('image')->slide_thumbnail as $key => $val) { $thumb_file[$key] = $upload_data['file_path'] . $id . "-" . $key . '.jpg'; AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $upload_data['full_path'], 'new_image' => $thumb_file[$key], 'width' => $val['w'], 'height' => $val['h']))->resize(); } @unlink($upload_data['full_path']); } H::ajax_json_output(AWS_APP::RSM(array('url' => get_js_url('/admin/slide/list/')), 1, null)); }
public function fetch_menu_list($select_id) { $admin_menu = (array) AWS_APP::config()->get('admin_menu'); if (!$admin_menu) { return false; } foreach ($admin_menu as $m_id => $menu) { if ($menu['children']) { foreach ($menu['children'] as $c_id => $c_menu) { if ($select_id == $c_menu['id']) { $admin_menu[$m_id]['children'][$c_id]['select'] = true; $admin_menu[$m_id]['select'] = true; } } } } return $admin_menu; }
/** * GET * @param $key */ public function get($key) { if (AWS_APP::config()->get('system')->debug) { list($usec, $sec) = explode(' ', microtime()); $start_time = (double) $usec + (double) $sec; } if (!$key) { return false; } $result = $this->cache_factory->load($this->cachePrefix . $key); if (AWS_APP::config()->get('system')->debug) { list($usec, $sec) = explode(' ', microtime()); $end_time = (double) $usec + (double) $sec; $stime = sprintf("%06f", $end_time - $start_time); AWS_APP::debug_log('cache', $stime, 'Get Cache: ' . str_replace($this->groupPrefix, '', $key) . ', result type: ' . gettype($result)); } return $result; }
public function index_action() { $this->crumb(AWS_APP::lang()->_t('概述'), 'admin/main/'); if (!defined('IN_SAE')) { $writable_check = array('cache' => is_really_writable(ROOT_PATH . 'cache/'), 'tmp' => is_really_writable(ROOT_PATH . './tmp/'), get_setting('upload_dir') => is_really_writable(get_setting('upload_dir'))); TPL::assign('writable_check', $writable_check); } TPL::assign('users_count', $this->model('system')->count('users')); TPL::assign('users_valid_email_count', $this->model('system')->count('users', 'valid_email = 1')); TPL::assign('question_count', $this->model('system')->count('question')); TPL::assign('answer_count', $this->model('system')->count('answer')); TPL::assign('question_count', $this->model('system')->count('question')); TPL::assign('question_no_answer_count', $this->model('system')->count('question', 'answer_count = 0')); TPL::assign('best_answer_count', $this->model('system')->count('question', 'best_answer > 0')); TPL::assign('topic_count', $this->model('system')->count('topic')); TPL::assign('attach_count', $this->model('system')->count('attach')); TPL::assign('approval_question_count', $this->model('publish')->count('approval', "type = 'question'")); TPL::assign('approval_answer_count', $this->model('publish')->count('approval', "type = 'answer'")); $admin_menu = (array) AWS_APP::config()->get('admin_menu'); $admin_menu[0]['select'] = true; TPL::assign('menu_list', $admin_menu); TPL::output('admin/index'); }
function avatar_upload_action() { AWS_APP::upload()->initialize(array('allowed_types' => 'jpg,jpeg,png,gif', 'upload_path' => get_setting('upload_dir') . '/avatar/' . $this->model('account')->get_avatar($this->user_id, '', 1), 'is_image' => TRUE, 'max_size' => get_setting('upload_avatar_size_limit'), 'file_name' => $this->model('account')->get_avatar($this->user_id, '', 2), 'encrypt_name' => FALSE))->do_upload('user_avatar'); if (AWS_APP::upload()->get_error()) { switch (AWS_APP::upload()->get_error()) { default: H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('错误代码') . ': ' . AWS_APP::upload()->get_error())); break; case 'upload_invalid_filetype': H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('文件类型无效'))); break; case 'upload_invalid_filesize': H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('文件尺寸过大, 最大允许尺寸为 %s KB', get_setting('upload_size_limit')))); break; } } if (!($upload_data = AWS_APP::upload()->data())) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('上传失败, 请与管理员联系'))); } if ($upload_data['is_image'] == 1) { foreach (AWS_APP::config()->get('image')->avatar_thumbnail as $key => $val) { $thumb_file[$key] = $upload_data['file_path'] . $this->model('account')->get_avatar($this->user_id, $key, 2); AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $upload_data['full_path'], 'new_image' => $thumb_file[$key], 'width' => $val['w'], 'height' => $val['h']))->resize(); } } $update_data['avatar_file'] = $this->model('account')->get_avatar($this->user_id, null, 1) . basename($thumb_file['min']); // 更新主表 $this->model('account')->update_users_fields($update_data, $this->user_id); if (!$this->model('integral')->fetch_log($this->user_id, 'UPLOAD_AVATAR')) { $this->model('integral')->process($this->user_id, 'UPLOAD_AVATAR', round(get_setting('integral_system_config_profile') * 0.2), '上传头像'); } H::ajax_json_output(AWS_APP::RSM(array('preview' => get_setting('upload_url') . '/avatar/' . $this->model('account')->get_avatar($this->user_id, null, 1) . basename($thumb_file['max'])), 1, null)); }
public function save_user_action() { if ($_POST['uid']) { if (!($user_info = $this->model('account')->get_user_info_by_uid($_POST['uid']))) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('用户不存在'))); } if ($user_info['group_id'] == 1 and !$this->user_info['permission']['is_administortar']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('你没有权限编辑管理员账号'))); } if ($_POST['user_name'] != $user_info['user_name'] and $this->model('account')->get_user_info_by_username($_POST['user_name'])) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('用户名已存在'))); } if ($_POST['email'] != $user_info['email'] and $this->model('account')->get_user_info_by_username($_POST['email'])) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('E-mail 已存在'))); } if ($_FILES['user_avatar']['name']) { AWS_APP::upload()->initialize(array('allowed_types' => 'jpg,jpeg,png,gif', 'upload_path' => get_setting('upload_dir') . '/avatar/' . $this->model('account')->get_avatar($user_info['uid'], '', 1), 'is_image' => TRUE, 'max_size' => get_setting('upload_avatar_size_limit'), 'file_name' => $this->model('account')->get_avatar($user_info['uid'], '', 2), 'encrypt_name' => FALSE))->do_upload('user_avatar'); if (AWS_APP::upload()->get_error()) { switch (AWS_APP::upload()->get_error()) { default: H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('错误代码') . ': ' . AWS_APP::upload()->get_error())); break; case 'upload_invalid_filetype': H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('文件类型无效'))); break; case 'upload_invalid_filesize': H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('文件尺寸过大, 最大允许尺寸为 %s KB', get_setting('upload_size_limit')))); break; } } if (!($upload_data = AWS_APP::upload()->data())) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('上传失败, 请与管理员联系'))); } if ($upload_data['is_image'] == 1) { foreach (AWS_APP::config()->get('image')->avatar_thumbnail as $key => $val) { $thumb_file[$key] = $upload_data['file_path'] . $this->model('account')->get_avatar($user_info['uid'], $key, 2); AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $upload_data['full_path'], 'new_image' => $thumb_file[$key], 'width' => $val['w'], 'height' => $val['h']))->resize(); } } $update_data['avatar_file'] = $this->model('account')->get_avatar($user_info['uid'], null, 1) . basename($thumb_file['min']); } if ($_POST['email']) { $update_data['email'] = htmlspecialchars($_POST['email']); } $update_data['invitation_available'] = intval($_POST['invitation_available']); $verify_apply = $this->model('verify')->fetch_apply($user_info['uid']); if ($verify_apply) { $update_data['verified'] = $_POST['verified']; if (!$update_data['verified']) { $this->model('verify')->decline_verify($user_info['uid']); } else { if ($update_data['verified'] != $verify_apply['type']) { $this->model('verify')->update_apply($user_info['uid'], null, null, null, null, $update_data['verified']); } } } else { if ($_POST['verified']) { $verified_id = $this->model('verify')->add_apply($user_info['uid'], null, null, $_POST['verified']); $this->model('verify')->approval_verify($verified_id); } } $update_data['valid_email'] = intval($_POST['valid_email']); $update_data['forbidden'] = intval($_POST['forbidden']); $update_data['group_id'] = intval($_POST['group_id']); if ($update_data['group_id'] == 1 and !$this->user_info['permission']['is_administortar']) { unset($update_data['group_id']); } $update_data['province'] = htmlspecialchars($_POST['province']); $update_data['city'] = htmlspecialchars($_POST['city']); $update_data['job_id'] = intval($_POST['job_id']); $update_data['mobile'] = htmlspecialchars($_POST['mobile']); $update_data['sex'] = intval($_POST['sex']); $this->model('account')->update_users_fields($update_data, $user_info['uid']); if ($_POST['delete_avatar']) { $this->model('account')->delete_avatar($user_info['uid']); } if ($_POST['password']) { $this->model('account')->update_user_password_ingore_oldpassword($_POST['password'], $user_info['uid'], fetch_salt(4)); } $this->model('account')->update_users_attrib_fields(array('signature' => htmlspecialchars($_POST['signature']), 'qq' => htmlspecialchars($_POST['qq']), 'homepage' => htmlspecialchars($_POST['homepage'])), $user_info['uid']); if ($_POST['user_name'] != $user_info['user_name']) { $this->model('account')->update_user_name($_POST['user_name'], $user_info['uid']); } H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('用户资料更新成功'))); } else { $_POST['user_name'] = trim($_POST['user_name']); $_POST['email'] = trim($_POST['email']); $_POST['password'] = trim($_POST['password']); $_POST['group_id'] = intval($_POST['group_id']); if (!$_POST['user_name']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入用户名'))); } if ($this->model('account')->check_username($_POST['user_name'])) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('用户名已经存在'))); } if ($this->model('account')->check_email($_POST['email'])) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('E-Mail 已经被使用, 或格式不正确'))); } if (strlen($_POST['password']) < 6 or strlen($_POST['password']) > 16) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('密码长度不符合规则'))); } $uid = $this->model('account')->user_register($_POST['user_name'], $_POST['password'], $_POST['email']); $this->model('active')->set_user_email_valid_by_uid($uid); $this->model('active')->active_user_by_uid($uid); if ($_POST['group_id'] == 1 and !$this->user_info['permission']['is_administortar']) { $_POST['group_id'] = 4; } if ($_POST['group_id'] != 4) { $this->model('account')->update('users', array('group_id' => $_POST['group_id']), 'uid = ' . $uid); } H::ajax_json_output(AWS_APP::RSM(array('url' => get_js_url('/admin/user/list/')), 1, null)); } }
public function publish_question_action() { if (!$this->user_info['permission']['publish_question']) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('你没有权限发布问题'))); } if ($this->user_info['integral'] < 0 and get_setting('integral_system_enabled') == 'Y') { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('你的剩余积分已经不足以进行此操作'))); } if (!$_POST['question_content']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入问题标题'))); } if (get_setting('category_enable') == 'N') { $_POST['category_id'] = 1; } if (!$_POST['category_id']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请选择问题分类'))); } if (cjk_strlen($_POST['question_content']) < 5) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('问题标题字数不得少于 5 个字'))); } if (get_setting('question_title_limit') > 0 and cjk_strlen($_POST['question_content']) > get_setting('question_title_limit')) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('问题标题字数不得大于 %s 字节', get_setting('question_title_limit')))); } if (!$this->user_info['permission']['publish_url'] and FORMAT::outside_url_exists($_POST['question_detail'])) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('你所在的用户组不允许发布站外链接'))); } if (human_valid('question_valid_hour') and !AWS_APP::captcha()->is_validate($_POST['seccode_verify'])) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('请填写正确的验证码'))); } if ($_POST['topics']) { foreach ($_POST['topics'] as $key => $topic_title) { $topic_title = trim($topic_title); if (!$topic_title) { unset($_POST['topics'][$key]); } else { $_POST['topics'][$key] = $topic_title; } } if (get_setting('question_topics_limit') and sizeof($_POST['topics']) > get_setting('question_topics_limit')) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('单个问题话题数量最多为 %s 个, 请调整话题数量', get_setting('question_topics_limit')))); } } if (!$_POST['topics'] and get_setting('new_question_force_add_topic') == 'Y') { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('请为问题添加话题'))); } if (!$this->model('publish')->insert_attach_is_self_upload($_POST['question_detail'], $_POST['attach_ids'])) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('只允许插入当前页面上传的附件'))); } if ($_POST['weixin_media_id']) { $_POST['weixin_media_id'] = base64_decode($_POST['weixin_media_id']); $weixin_pic_url = AWS_APP::cache()->get('weixin_pic_url_' . md5($_POST['weixin_media_id'])); if (!$weixin_pic_url) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('图片已过期或 media_id 无效'))); } $file = $this->model('openid_weixin_weixin')->get_file($_POST['weixin_media_id']); if (!$file) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('远程服务器忙'))); } if (is_array($file) and $file['errmsg']) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('获取图片失败,错误为: %s', $file['errmsg']))); } AWS_APP::upload()->initialize(array('allowed_types' => get_setting('allowed_upload_types'), 'upload_path' => get_setting('upload_dir') . '/questions/' . gmdate('Ymd'), 'is_image' => TRUE, 'max_size' => get_setting('upload_size_limit'))); AWS_APP::upload()->do_upload($_POST['weixin_media_id'] . '.jpg', $file); $upload_error = AWS_APP::upload()->get_error(); if ($upload_error) { switch ($upload_error) { default: H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('保存图片失败,错误为 %s' . $upload_error))); break; case 'upload_invalid_filetype': H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('保存图片失败,本站不允许上传 jpeg 格式的图片'))); break; case 'upload_invalid_filesize': H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('图片尺寸过大, 最大允许尺寸为 %s KB', get_setting('upload_size_limit')))); break; } } $upload_data = AWS_APP::upload()->data(); if (!$upload_data) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('保存图片失败,请与管理员联系'))); } foreach (AWS_APP::config()->get('image')->attachment_thumbnail as $key => $val) { $thumb_file[$key] = $upload_data['file_path'] . $val['w'] . 'x' . $val['h'] . '_' . basename($upload_data['full_path']); AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $upload_data['full_path'], 'new_image' => $thumb_file[$key], 'width' => $val['w'], 'height' => $val['h']))->resize(); } $this->model('publish')->add_attach('question', $upload_data['orig_name'], $_POST['attach_access_key'], time(), basename($upload_data['full_path']), true); } // !注: 来路检测后面不能再放报错提示 if (!valid_post_hash($_POST['post_hash'])) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('页面停留时间过长,或内容已提交,请刷新页面'))); } $this->model('draft')->delete_draft(1, 'question', $this->user_id); if ($this->publish_approval_valid()) { $this->model('publish')->publish_approval('question', array('question_content' => $_POST['question_content'], 'question_detail' => $_POST['question_detail'], 'category_id' => $_POST['category_id'], 'topics' => $_POST['topics'], 'anonymous' => $_POST['anonymous'], 'attach_access_key' => $_POST['attach_access_key'], 'ask_user_id' => $_POST['ask_user_id'], 'permission_create_topic' => $this->user_info['permission']['create_topic']), $this->user_id, $_POST['attach_access_key']); H::ajax_json_output(AWS_APP::RSM(array('url' => get_js_url('/publish/wait_approval/')), 1, null)); } else { $question_id = $this->model('publish')->publish_question($_POST['question_content'], $_POST['question_detail'], $_POST['category_id'], $this->user_id, $_POST['topics'], $_POST['anonymous'], $_POST['attach_access_key'], $_POST['ask_user_id'], $this->user_info['permission']['create_topic']); if ($_POST['_is_mobile']) { if ($weixin_user = $this->model('openid_weixin_weixin')->get_user_info_by_uid($this->user_id)) { if ($weixin_user['location_update'] > time() - 7200) { $this->model('geo')->set_location('question', $question_id, $weixin_user['longitude'], $weixin_user['latitude']); } } $url = get_js_url('/m/question/' . $question_id); } else { $url = get_js_url('/question/' . $question_id); } H::ajax_json_output(AWS_APP::RSM(array('url' => $url), 1, null)); } }
public function associate_avatar($uid, $headimgurl) { if ($headimgurl) { if (!($user_info = $this->model('account')->get_user_info_by_uid($uid))) { return false; } if ($user_info['avatar_file']) { return false; } if ($avatar_stream = curl_get_contents($headimgurl, 1)) { $avatar_location = get_setting('upload_dir') . '/avatar/' . $this->model('account')->get_avatar($uid, '', 1) . $this->model('account')->get_avatar($uid, '', 2); $avatar_dir = str_replace(basename($avatar_location), '', $avatar_location); if (!is_dir($avatar_dir)) { make_dir($avatar_dir); } if (@file_put_contents($avatar_location, $avatar_stream)) { foreach (AWS_APP::config()->get('image')->avatar_thumbnail as $key => $val) { $thumb_file[$key] = $avatar_dir . $this->model('account')->get_avatar($uid, $key, 2); AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $avatar_location, 'new_image' => $thumb_file[$key], 'width' => $val['w'], 'height' => $val['h']))->resize(); } $avatar_file = $this->model('account')->get_avatar($uid, null, 1) . basename($thumb_file['min']); } } } if ($avatar_file) { return $this->model('account')->update('users', array('avatar_file' => $avatar_file), 'uid = ' . intval($uid)); } }
/** * 获取专题图片指定尺寸的完整url地址 * @param string $size 三种图片尺寸 max(100px)|mid(50px)|min(32px) * @param string $pic_file 某一尺寸的图片文件名 * @return string 取出专题图片的完整url地址 */ function get_feature_pic_url($size = null, $pic_file = null) { if (!$pic_file) { return false; } else { if ($size) { $pic_file = str_replace(AWS_APP::config()->get('image')->feature_thumbnail['min']['w'] . '_' . AWS_APP::config()->get('image')->feature_thumbnail['min']['h'], AWS_APP::config()->get('image')->feature_thumbnail[$size]['w'] . '_' . AWS_APP::config()->get('image')->feature_thumbnail[$size]['h'], $pic_file); } } return get_setting('upload_url') . '/feature/' . $pic_file; }
/** * 计算字段总和, SELECT SUM() 方法 * * 面向对象数据库操作, 表名无需加表前缀, 数据也无需使用 $this->quote 进行过滤 ($where 条件除外) * * @param string * @param string * @param string * @return int */ public function sum($table, $column, $where = '') { $this->slave(); $select = $this->select(); $select->from($this->get_table($table), 'SUM(' . $column . ') AS n'); if ($where) { $select->where($where); } $sql = $select->__toString(); if (AWS_APP::config()->get('system')->debug) { $start_time = microtime(TRUE); } try { $result = $this->db()->fetchRow($select); } catch (Exception $e) { show_error("Database error\n------\n\nSQL: {$sql}\n\nError Message: " . $e->getMessage(), $e->getMessage()); } if (AWS_APP::config()->get('system')->debug) { AWS_APP::debug_log('database', microtime(TRUE) - $start_time, $sql); } return intval($result['n']); }
public function is_language($string, $type) { if (!($characteristic = AWS_APP::config()->get('weixin')->language_characteristic[$type])) { return false; } $string = trim(strtolower($string)); foreach ($characteristic as $key => $text) { if ($string == $text) { return true; } } }
public function get_msg_from_sina_crond() { $now = time(); $lock_time = AWS_APP::cache()->get('weibo_msg_locker'); if ($lock_time and $now - $lock_time <= 600) { return false; } if (!get_setting('sina_akey') or !get_setting('sina_skey')) { return false; } $services_info = $this->get_services_info(); if (!$services_info) { return false; } AWS_APP::cache()->set('weibo_msg_locker', $now, 600); foreach ($services_info as $service_info) { $service_user_info = $this->model('account')->get_user_info_by_uid($service_info['uid']); if (!$service_user_info) { continue; } if (!$service_info['access_token'] or $service_info['expires_time'] <= time()) { $this->notification_of_refresh_access_token($service_user_info['uid'], $service_user_info['user_name']); continue; } $result = $this->model('openid_weibo_oauth')->get_msg_from_sina($service_info['access_token'], $service_info['last_msg_id']); if (!$result) { continue; } if ($result['error_code']) { if ($result['error_code'] == 21332) { $this->notification_of_refresh_access_token($service_user_info['uid'], $service_user_info['user_name']); } continue; } $this->notification_of_refresh_access_token($service_user_info['uid'], null); foreach ($result['statuses'] as $msg) { $msg_info['created_at'] = strtotime($msg['created_at']); $msg_info['id'] = $msg['id']; if ($now - $msg_info['created_at'] > 604800 or $this->fetch_row('weibo_msg', 'id = "' . $this->quote($msg_info['id']) . '"')) { continue; } $msg_info['text'] = htmlspecialchars_decode(str_replace('@' . $service_info['name'], '', $msg['text'])); $msg_info['uid'] = $service_user_info['uid']; $msg_info['weibo_uid'] = $service_info['id']; $msg_info['msg_author_uid'] = $msg['user']['id']; $now++; $msg_info['access_key'] = md5($msg_info['uid'] . $now); if ($msg['pic_urls'] and get_setting('upload_enable') == 'Y') { foreach ($msg['pic_urls'] as $pic_url) { $pic_url_array = explode('/', substr($pic_url['thumbnail_pic'], 7)); $pic_url_array[2] = 'large'; $pic_url = 'http://' . implode('/', $pic_url_array); $result = curl_get_contents($pic_url); if (!$result) { continue; } AWS_APP::upload()->initialize(array('allowed_types' => get_setting('allowed_upload_types'), 'upload_path' => get_setting('upload_dir') . '/questions/' . gmdate('Ymd'), 'is_image' => TRUE, 'max_size' => get_setting('upload_size_limit'))); AWS_APP::upload()->do_upload($pic_url_array[3], $result); if (AWS_APP::upload()->get_error()) { continue; } $upload_data = AWS_APP::upload()->data(); if (!$upload_data) { continue; } foreach (AWS_APP::config()->get('image')->attachment_thumbnail as $key => $val) { $thumb_file[$key] = $upload_data['file_path'] . $val['w'] . 'x' . $val['h'] . '_' . basename($upload_data['full_path']); AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $upload_data['full_path'], 'new_image' => $thumb_file[$key], 'width' => $val['w'], 'height' => $val['h']))->resize(); } $this->model('publish')->add_attach('weibo_msg', $upload_data['orig_name'], $msg_info['access_key'], $now, basename($upload_data['full_path']), true); } $this->model('publish')->update_attach('weibo_msg', $msg_info['id'], $msg_info['access_key']); } else { $msg_info['has_attach'] = 0; } $this->insert('weibo_msg', $msg_info); $this->update_service_account($msg_info['uid'], null, $msg_info['id']); } } AWS_APP::cache()->delete('weibo_msg_locker'); return true; }
function login($_username, $_password) { if (H::valid_email($_username)) { // 使用 E-mail 登录 list($uc_uid, $username, $password, $email) = uc_user_login($_username, $_password, 2); } if ($this->ucenter_charset != 'utf-8') { $username = convert_encoding($username, $this->ucenter_charset, 'UTF-8'); } if (!$uc_uid) { if ($this->ucenter_charset != 'utf-8') { list($uc_uid, $username, $password, $email) = uc_user_login(convert_encoding($_username, 'utf-8', $this->ucenter_charset), $_password); if ($username) { $username = convert_encoding($username, $this->ucenter_charset, 'UTF-8'); } } else { list($uc_uid, $username, $password, $email) = uc_user_login($_username, $_password); } } if ($username) { $username = htmlspecialchars($username); } if ($uc_uid > 0) { if ($user_info = $this->get_uc_user_info($uc_uid)) { // Update password $this->model('account')->update_user_password_ingore_oldpassword($_password, $user_info['uid'], $user_info['salt']); // Update username if ($user_info['user_name'] != $username) { if (!$this->model('account')->check_username($username)) { $this->model('account')->update_user_name($username, $user_info['uid']); $this->update('users_ucenter', array('username' => htmlspecialchars($username)), 'uc_uid = ' . intval($uc_uid)); } } } else { if ($site_user_info = $this->model('account')->get_user_info_by_email($email)) { $this->insert('users_ucenter', array('uid' => $site_user_info['uid'], 'uc_uid' => $uc_uid, 'username' => $username, 'email' => $email)); return false; } if ($new_user_id = $this->model('account')->user_register($username, $_password, $email, TRUE)) { if ($exists_uc_id = $this->is_uc_user($email)) { $this->update('users_ucenter', array('username' => $username, 'uid' => $new_user_id), 'uc_uid = ' . intval($exists_uc_id)); } else { $this->insert('users_ucenter', array('uid' => $new_user_id, 'uc_uid' => $uc_uid, 'username' => $username, 'email' => $email)); } $user_info = $this->model('account')->get_user_info_by_uid($new_user_id, true, false); } } } if (uc_check_avatar($uc_uid, 'big')) { if (!$user_info['avatar_file']) { $this->model('account')->associate_remote_avatar($user_info['uid'], UC_API . '/avatar.php?uid=' . $uc_uid . '&size=big'); } } else { if ($user_info['avatar_file'] and get_setting('ucenter_path')) { $avatar = get_setting('upload_dir') . '/avatar/' . $this->model('account')->get_avatar($user_info['uid'], ''); $uc_avatar_dir = get_setting('ucenter_path') . '/data/avatar/' . $this->model('account')->get_avatar($uc_uid, '', 1); if (!file_exists($uc_avatar_dir)) { make_dir($uc_avatar_dir); } foreach (AWS_APP::config()->get('image')->uc_avatar_thumbnail as $key => $val) { AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $avatar, 'new_image' => $uc_avatar_dir . $this->model('account')->get_avatar($uc_uid, $key, 2), 'width' => $val['w'], 'height' => $val['h']))->resize(); } } } return $user_info; }
public function send_msg_action() { $group_id = intval($_POST['group_id']); $groups = $this->model('weixin')->get_groups(); $group_name = $groups[$group_id]['name']; if (!isset($group_name)) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('选择的分组不存在'))); } if (!$_POST['main_msg_title']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入封面的标题'))); } if (!$_POST['main_msg_author']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入封面的作者'))); } if (!$_POST['main_msg_content']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入封面的内容'))); } if (!$_POST['main_msg_url']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请输入封面的原文链接'))); } if ($_POST['show_cover_pic'] != 0 and $_POST['show_cover_pic'] != 1) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请选择是否显示封面'))); } $article_ids = array_unique(array_filter(explode(',', trim($_POST['article_ids'], ',')))); $question_ids = array_unique(array_filter(explode(',', trim($_POST['question_ids'], ',')))); /* if (!$article_ids AND !$question_ids) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请添加要群发的文章或问题'))); } */ if (count($article_ids) + count($question_ids) > 9) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('最多可添加 9 个文章和问题'))); } if ($_FILES['main_msg_img']['error'] === UPLOAD_ERR_OK) { if (!in_array($_FILES['main_msg_img']['type'], array('image/bmp', 'image/png', 'image/jpeg', 'image/gif'))) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('只允许上传 bmp/png/jpeg/jpg/gif 格式的图片'))); } if ($_FILES['main_msg_img']['size'] > '2097152') { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('图片最大为 2M'))); } $main_msg_img = TEMP_PATH . 'weixin_img.jpg'; if (!is_uploaded_file($_FILES['main_msg_img']['tmp_name']) or !move_uploaded_file($_FILES['main_msg_img']['tmp_name'], $main_msg_img)) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('上传失败, 请与管理员联系'))); } } else { $main_msg_img = AWS_APP::config()->get('weixin')->default_list_image_path; } $main_msg = array('author' => $_POST['main_msg_author'], 'title' => $_POST['main_msg_title'], 'url' => $_POST['main_msg_url'], 'content' => $_POST['main_msg_content'], 'img' => $main_msg_img, 'show_cover_pic' => $_POST['show_cover_pic']); $error_msg = $this->model('weixin')->add_main_msg_to_mpnews($main_msg); if (isset($error_msg)) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('上传封面图失败, 错误信息: %s', $error_msg))); } if ($article_ids) { $error_msg = $this->model('weixin')->add_articles_to_mpnews($article_ids); if (isset($error_msg)) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('上传文章作者的头像失败, 错误信息: %s', $error_msg))); } } if ($question_ids) { $error_msg = $this->model('weixin')->add_questions_to_mpnews($question_ids); if (isset($error_msg)) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('上传问题作者的头像失败, 错误信息: %s', $error_msg))); } } $error_msg = $this->model('weixin')->upload_mpnews(); if (isset($error_msg)) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('上传图文消息失败, 错误为: %s', $error_msg))); } $error_msg = $this->model('weixin')->send_msg($group_id, 'mpnews'); if (isset($error_msg)) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('群发任务提交失败, 错误信息: %s', $error_msg))); } $msg_id = $this->model('weixin')->save_sent_msg($group_name, $groups[$group_id]['count']); if (is_file(TEMP_PATH . 'weixin_img.jpg')) { @unlink(TEMP_PATH . 'weixin_img.jpg'); } H::ajax_json_output(AWS_APP::RSM(array('url' => get_js_url('/admin/weixin/sent_msg_details/id-' . $msg_id)), 1, null)); }
/** * 物理删除话题及其关联的图片等 * * @param $topic_id */ public function remove_topic_by_ids($topic_id) { if (!$topic_id) { return false; } if (is_array($topic_id)) { $topic_ids = $topic_id; } else { $topic_ids[] = $topic_id; } array_walk_recursive($topic_ids, 'intval_string'); foreach ($topic_ids as $topic_id) { if (!($topic_info = $this->get_topic_by_id($topic_id))) { continue; } if ($topic_info['topic_pic']) { foreach (AWS_APP::config()->get('image')->topic_thumbnail as $size) { @unlink(get_setting('upload_dir') . '/topic/' . str_replace(AWS_APP::config()->get('image')->topic_thumbnail['min']['w'] . '_' . AWS_APP::config()->get('image')->topic_thumbnail['min']['h'], $size['w'] . '_' . $size['h'], $topic_info['topic_pic'])); } @unlink(get_setting('upload_dir') . '/topic/' . str_replace('_' . AWS_APP::config()->get('image')->topic_thumbnail['min']['w'] . '_' . AWS_APP::config()->get('image')->topic_thumbnail['min']['h'], '', $topic_info['topic_pic'])); } // 删除动作 ACTION_LOG::delete_action_history('associate_type = ' . ACTION_LOG::CATEGORY_TOPIC . ' AND associate_id = ' . intval($topic_id)); ACTION_LOG::delete_action_history('associate_type = ' . ACTION_LOG::CATEGORY_QUESTION . ' AND associate_action = ' . ACTION_LOG::ADD_TOPIC . ' AND associate_attached = ' . intval($topic_id)); $this->delete('topic_focus', 'topic_id = ' . intval($topic_id)); $this->delete('topic_relation', 'topic_id = ' . intval($topic_id)); $this->delete('feature_topic', 'topic_id = ' . intval($topic_id)); $this->delete('related_topic', 'topic_id = ' . intval($topic_id) . ' OR related_id = ' . intval($topic_id)); $this->delete('reputation_topic', ' topic_id = ' . intval($topic_id)); $this->delete('topic', 'topic_id = ' . intval($topic_id)); $this->update('topic', array('parent_id' => 0), 'parent_id = ' . intval($topic_id)); } return true; }
public function setup() { $admin_menu = (array) AWS_APP::config()->get('admin_menu'); $admin_menu['mobile_app_config']['select'] = true; TPL::assign('menu_list', $admin_menu); }
public function avatar_upload_action() { AWS_APP::upload()->initialize(array('allowed_types' => '', 'upload_path' => get_setting('upload_dir') . '/avatar/' . $this->model('account')->get_avatar($this->user_id, '', 1), 'is_image' => FALSE, 'max_size' => get_setting('upload_avatar_size_limit'), 'file_name' => '', 'encrypt_name' => FALSE))->do_upload('aws_upload_file'); AWS_APP::upload()->initialize(array('allowed_types' => '', 'upload_path' => get_setting('upload_dir') . '/avatar/' . $this->model('account')->get_avatar($this->user_id, '', 1), 'is_image' => FALSE, 'max_size' => get_setting('upload_avatar_size_limit'), 'file_name' => $this->model('account')->get_avatar($this->user_id, '', 2), 'encrypt_name' => FALSE))->do_upload('aws_upload_file'); if (AWS_APP::upload()->get_error()) { switch (AWS_APP::upload()->get_error()) { default: die("{'error':'错误代码: " . AWS_APP::upload()->get_error() . "'}"); break; case 'upload_invalid_filetype': die("{'error':'文件类型无效'}"); break; case 'upload_invalid_filesize': die("{'error':'文件尺寸过大, 最大允许尺寸为 " . get_setting('upload_size_limit') . " KB'}"); break; } } if (!($upload_data = AWS_APP::upload()->data())) { die("{'error':'上传失败, 请与管理员联系'}"); } if ($upload_data['is_image'] == 1) { foreach (AWS_APP::config()->get('image')->avatar_thumbnail as $key => $val) { $thumb_file[$key] = $upload_data['file_path'] . $this->model('account')->get_avatar($this->user_id, $key, 2, $_FILES['name']); AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $upload_data['full_path'], 'new_image' => $thumb_file[$key], 'width' => $val['w'], 'height' => $val['h']))->resize(); } } $update_data['avatar_file'] = $this->model('account')->get_avatar($this->user_id, null, 1, $_FILES['name']) . basename($thumb_file['min']); // 更新主表 $this->model('account')->update_users_fields($update_data, $this->user_id); if (!$this->model('integral')->fetch_log($this->user_id, 'UPLOAD_AVATAR')) { $this->model('integral')->process($this->user_id, 'UPLOAD_AVATAR', round(get_setting('integral_system_config_profile') * 0.2), '上传头像'); } # echo htmlspecialchars(json_encode(array( echo json_encode(array('success' => true, 'thumb' => get_setting('upload_url') . '/avatar/' . $this->model('account')->get_avatar($this->user_id, null, 1, $_FILES['name']) . basename($thumb_file['max']))), ENT_NOQUOTES; }
public function avatar_upload_action() { AWS_APP::upload()->initialize(array('allowed_types' => 'jpg,jpeg,png,gif', 'upload_path' => get_setting('upload_dir') . '/avatar/' . $this->model('account')->get_avatar($this->user_id, '', 1), 'is_image' => TRUE, 'max_size' => get_setting('upload_avatar_size_limit'), 'file_name' => $this->model('account')->get_avatar($this->user_id, '', 2), 'encrypt_name' => FALSE))->do_upload('aws_upload_file'); if (AWS_APP::upload()->get_error()) { switch (AWS_APP::upload()->get_error()) { default: die("{'error':'错误代码: " . AWS_APP::upload()->get_error() . "'}"); break; case 'upload_invalid_filetype': die("{'error':'文件类型无效'}"); break; case 'upload_invalid_filesize': die("{'error':'文件尺寸过大, 最大允许尺寸为 " . get_setting('upload_size_limit') . " KB'}"); break; } } if (!($upload_data = AWS_APP::upload()->data())) { die("{'error':'上传失败, 请与管理员联系'}"); } if ($upload_data['is_image'] == 1) { foreach (AWS_APP::config()->get('image')->avatar_thumbnail as $key => $val) { $thumb_file[$key] = $upload_data['file_path'] . $this->model('account')->get_avatar($this->user_id, $key, 2); AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $upload_data['full_path'], 'new_image' => $thumb_file[$key], 'width' => $val['w'], 'height' => $val['h']))->resize(); } } $update_data['avatar_file'] = $this->model('account')->get_avatar($this->user_id, null, 1) . basename($thumb_file['min']); $update_data['profile_update_time'] = time(); $version = $update_data['profile_update_time']; // 更新主表 $this->model('account')->update_users_fields($update_data, $this->user_id); if (!$this->model('integral')->fetch_log($this->user_id, 'UPLOAD_AVATAR')) { $this->model('integral')->process($this->user_id, 'UPLOAD_AVATAR', round(get_setting('integral_system_config_profile') * 0.2), '上传头像'); } $result = json_encode(array('success' => true, 'version' => $version, 'thumb' => get_setting('upload_url') . '/avatar/' . $this->model('account')->get_avatar($this->user_id, null, 1) . basename($thumb_file['max']))); echo '<script>parent.window.postMessage(\'' . $result . '\', "*");</script>'; }
/** * 获取带表前缀的数据库表名 * * @param string * @return string */ function get_table($name) { return AWS_APP::config()->get('database')->prefix . $name; }
public function associate_remote_avatar($uid, $headimgurl) { if (!$headimgurl) { return false; } if (!($user_info = $this->get_user_info_by_uid($uid))) { return false; } if ($user_info['avatar_file']) { return false; } if (!($avatar_stream = curl_get_contents($headimgurl, 1))) { return false; } $avatar_location = get_setting('upload_dir') . '/avatar/' . $this->get_avatar($uid, ''); $avatar_dir = dirname($avatar_location) . '/'; if (!file_exists($avatar_dir)) { make_dir($avatar_dir); } if (!@file_put_contents($avatar_location, $avatar_stream)) { return false; } foreach (AWS_APP::config()->get('image')->avatar_thumbnail as $key => $val) { AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $avatar_location, 'new_image' => $avatar_dir . $this->get_avatar($uid, $key, 2), 'width' => $val['w'], 'height' => $val['h']))->resize(); } $this->update('users', array('avatar_file' => $this->get_avatar($uid)), 'uid = ' . intval($uid)); if (!$this->model('integral')->fetch_log($new_user_id, 'UPLOAD_AVATAR')) { $this->model('integral')->process($new_user_id, 'UPLOAD_AVATAR', round(get_setting('integral_system_config_profile') * 0.2), '上传头像'); } return true; }
public function upload_topic_pic_action() { if (!($this->user_info['permission']['is_administortar'] or $this->user_info['permission']['is_moderator'])) { if (!$this->user_info['permission']['edit_topic']) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('你没有权限进行此操作'))); } else { if ($this->model('topic')->has_lock_topic($_GET['topic_id'])) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('锁定的话题不能编辑'))); } } } if (!($topic_info = $this->model('topic')->get_topic_by_id($_GET['topic_id']))) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('话题不存在'))); } AWS_APP::upload()->initialize(array('allowed_types' => 'jpg,jpeg,png,gif', 'upload_path' => get_setting('upload_dir') . '/topic/' . gmdate('Ymd'), 'is_image' => TRUE, 'max_size' => get_setting('upload_avatar_size_limit')))->do_upload('aws_upload_file'); if (AWS_APP::upload()->get_error()) { switch (AWS_APP::upload()->get_error()) { default: H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('错误代码') . ': ' . AWS_APP::upload()->get_error())); break; case 'upload_invalid_filetype': H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('文件类型无效'))); break; case 'upload_invalid_filesize': H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('文件尺寸过大, 最大允许尺寸为 %s KB', get_setting('upload_size_limit')))); break; } } if (!($upload_data = AWS_APP::upload()->data())) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('上传失败, 请与管理员联系'))); } if ($upload_data['is_image'] == 1) { foreach (AWS_APP::config()->get('image')->topic_thumbnail as $key => $val) { $thumb_file[$key] = $upload_data['file_path'] . str_replace($upload_data['file_ext'], '_' . $val['w'] . '_' . $val['h'] . $upload_data['file_ext'], basename($upload_data['full_path'])); AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $upload_data['full_path'], 'new_image' => $thumb_file[$key], 'width' => $val['w'], 'height' => $val['h']))->resize(); @unlink(get_setting('upload_dir') . '/topic/' . str_replace(AWS_APP::config()->get('image')->topic_thumbnail['min']['w'] . '_' . AWS_APP::config()->get('image')->topic_thumbnail['min']['h'], $val['w'] . '_' . $val['h'], $topic_info['topic_pic'])); } @unlink(get_setting('upload_dir') . '/topic/' . str_replace('_' . AWS_APP::config()->get('image')->topic_thumbnail['min']['w'] . '_' . AWS_APP::config()->get('image')->topic_thumbnail['min']['h'], '', $topic_info['topic_pic'])); } $this->model('topic')->update_topic($this->user_id, $_GET['topic_id'], null, null, gmdate('Ymd') . '/' . basename($thumb_file['min'])); # echo htmlspecialchars(json_encode(array( echo json_encode(array('success' => true, 'thumb' => get_setting('upload_url') . '/topic/' . gmdate('Ymd') . '/' . basename($thumb_file['mid']))), ENT_NOQUOTES; }
public function parse_attach_data($attach, $item_type, $size = null) { if (!$attach or !$item_type) { return false; } foreach ($attach as $key => $data) { if ($item_type == 'question' or $item_type == 'weibo_msg') { $item_type = 'questions'; } // Fix 2.0 attach time zone bug $date_dir = gmdate('Ymd', $data['add_time']); if (!file_exists(get_setting('upload_dir') . '/' . $item_type . '/' . $date_dir . '/' . $data['file_location'])) { $date_dir = gmdate('Ymd', $data['add_time'] + 86400); } if (!file_exists(get_setting('upload_dir') . '/' . $item_type . '/' . $date_dir . '/' . $data['file_location'])) { $date_dir = gmdate('Ymd', $data['add_time'] - 86400); } $attach_url = get_setting('upload_url') . '/' . $item_type . '/' . $date_dir . '/'; $attach_list[$data['id']] = array('id' => $data['id'], 'is_image' => $data['is_image'], 'file_name' => $data['file_name'], 'access_key' => $data['access_key'], 'attachment' => $attach_url . $data['file_location']); if ($data['is_image'] == 1 and $size) { $attach_list[$data['id']]['thumb'] = $attach_url . '/' . AWS_APP::config()->get('image')->attachment_thumbnail[$size]['w'] . 'x' . AWS_APP::config()->get('image')->attachment_thumbnail[$size]['h'] . '_' . $data['file_location']; } } return $attach_list; }
function login($_username, $_password) { if (H::valid_email($_username)) { // 使用 E-mail 登录 list($uc_uid, $username, $password, $email) = uc_user_login($_username, $_password, 2); } if ($this->ucenter_charset != 'utf-8') { $username = convert_encoding($username, $this->ucenter_charset, 'UTF-8'); } if (!$uc_uid) { if ($this->ucenter_charset != 'utf-8') { list($uc_uid, $username, $password, $email) = uc_user_login(convert_encoding($_username, 'utf-8', $this->ucenter_charset), $_password); if ($username) { $username = convert_encoding($username, $this->ucenter_charset, 'UTF-8'); } } else { list($uc_uid, $username, $password, $email) = uc_user_login($_username, $_password); } } if ($username) { $username = htmlspecialchars($username); } if ($uc_uid > 0) { if (!($user_info = $this->get_uc_user_info($uc_uid))) { if ($site_user_info = $this->model('account')->get_user_info_by_email($email)) { $this->insert('users_ucenter', array('uid' => $site_user_info['uid'], 'uc_uid' => $uc_uid, 'username' => $username, 'email' => $email)); return false; } if ($new_user_id = $this->model('account')->user_register($username, $_password, $email, TRUE)) { if ($exists_uc_id = $this->is_uc_user($email)) { $this->update('users_ucenter', array('username' => $username, 'uid' => $new_user_id), 'uc_uid = ' . intval($exists_uc_id)); } else { $this->insert('users_ucenter', array('uid' => $new_user_id, 'uc_uid' => $uc_uid, 'username' => $username, 'email' => $email)); if (uc_check_avatar($uc_uid, 'big')) { $avatar = @file_get_contents(UC_API . '/avatar.php?uid=' . $uc_uid . '&size=big'); if ($avatar) { AWS_APP::upload()->initialize(array('allowed_types' => 'jpg,jpeg,png,gif', 'upload_path' => get_setting('upload_dir') . '/avatar/' . $this->model('account')->get_avatar($new_user_id, '', 1), 'is_image' => TRUE, 'max_size' => get_setting('upload_avatar_size_limit'), 'file_name' => $this->model('account')->get_avatar($new_user_id, '', 2), 'encrypt_name' => FALSE))->do_upload('aws_upload_file', $avatar); if (!AWS_APP::upload()->get_error()) { $upload_data = AWS_APP::upload()->data(); if ($upload_data) { if ($upload_data['is_image'] == 1) { foreach (AWS_APP::config()->get('image')->avatar_thumbnail as $key => $val) { $thumb_file[$key] = $upload_data['file_path'] . $this->model('account')->get_avatar($new_user_id, $key, 2); AWS_APP::image()->initialize(array('quality' => 90, 'source_image' => $upload_data['full_path'], 'new_image' => $thumb_file[$key], 'width' => $val['w'], 'height' => $val['h']))->resize(); } } $update_data['avatar_file'] = $this->model('account')->get_avatar($new_user_id, null, 1) . basename($thumb_file['min']); // 更新主表 $this->model('account')->update_users_fields($update_data, $new_user_id); if (!$this->model('integral')->fetch_log($new_user_id, 'UPLOAD_AVATAR')) { $this->model('integral')->process($new_user_id, 'UPLOAD_AVATAR', round(get_setting('integral_system_config_profile') * 0.2), '上传头像'); } } } } } } $user_info = $this->model('account')->get_user_info_by_uid($new_user_id, true, false); } } else { // Update password $this->model('account')->update_user_password_ingore_oldpassword($_password, $user_info['uid'], $user_info['salt']); // Update username if ($user_info['user_name'] != $username) { if (!$this->model('account')->check_username($username)) { $this->model('account')->update_user_name($username, $user_info['uid']); $this->update('users_ucenter', array('username' => htmlspecialchars($username)), 'uc_uid = ' . intval($uc_uid)); } } } } return $user_info; }
public static function output($template_filename, $display = true) { if (!strstr($template_filename, self::$template_ext)) { $template_filename .= self::$template_ext; } $display_template_filename = 'default/' . $template_filename; if (self::$in_app) { if (get_setting('ui_style') != 'default') { $custom_template_filename = get_setting('ui_style') . '/' . $template_filename; if (file_exists(self::$template_path . '/' . $custom_template_filename)) { $display_template_filename = $custom_template_filename; } } self::assign('template_name', get_setting('ui_style')); if (!self::$view->_meta_keywords) { self::set_meta('keywords', get_setting('keywords')); } if (!self::$view->_meta_description) { self::set_meta('description', get_setting('description')); } } else { self::assign('template_name', 'default'); } if (self::$in_app and $display) { if ($plugins = AWS_APP::plugins()->parse($_GET['app'], $_GET['c'], $_GET['act'], str_replace(self::$template_ext, '', $template_filename))) { foreach ($plugins as $plugin_file) { include_once $plugin_file; } } } $output = self::$view->getOutput($display_template_filename); if (self::$in_app and basename($template_filename) != 'debuger.tpl.htm') { $template_dirs = explode('/', $template_filename); /* /if ($template_dirs[0] != 'admin') { $output = H::sensitive_words($output); } */ if (get_setting('url_rewrite_enable') != 'Y' or $template_dirs[0] == 'admin') { //$output = preg_replace('/(href|action)=([\"|\'])(?!http)(?!mailto)(?!file)(?!ftp)(?!javascript)(?![\/|\#])(?!\.\/)([^\"\']+)([\"|\'])/is', '\1=\2' . base_url() . '/' . G_INDEX_SCRIPT . '\3\4', $output); $output = preg_replace('/<([^>]*?)(href|action)=([\\"|\'])(?!http)(?!mailto)(?!file)(?!ftp)(?!javascript)(?![\\/|\\#])(?!\\.\\/)([^\\"\']+)([\\"|\'])([^>]*?)>/is', '<\\1\\2=\\3' . base_url() . '/' . G_INDEX_SCRIPT . '\\4\\5\\6>', $output); } if ($request_routes = get_request_route() and $template_dirs[0] != 'admin' and get_setting('url_rewrite_enable') == 'Y') { foreach ($request_routes as $key => $val) { $output = preg_replace("/href=[\"|']" . $val[0] . "[\\#]/", "href=\"" . $val[1] . "#", $output); $output = preg_replace("/href=[\"|']" . $val[0] . "[\"|']/", "href=\"" . $val[1] . "\"", $output); } } if (get_setting('url_rewrite_enable') == 'Y' and $template_dirs[0] != 'admin') { //$output = preg_replace('/(href|action)=([\"|\'])(?!mailto)(?!file)(?!ftp)(?!http)(?!javascript)(?![\/|\#])(?!\.\/)([^\"\']+)([\"|\'])/is', '\1=\2' . base_url() . '/' . '\3\4', $output); $output = preg_replace('/<([^>]*?)(href|action)=([\\"|\'])(?!mailto)(?!file)(?!ftp)(?!http)(?!javascript)(?![\\/|\\#])(?!\\.\\/)([^\\"\']{0,})([\\"|\'])([^>]*?)>/is', '<\\1\\2=\\3' . base_url() . '/' . '\\4\\5\\6>', $output); } //$output = preg_replace("/([a-zA-Z0-9]+_?[a-zA-Z0-9]+)-__|(__[a-zA-Z0-9]+_?[a-zA-Z0-9]+)-$/i", '', $output); $output = preg_replace('/[a-zA-Z0-9]+_?[a-zA-Z0-9]*\\-__/', '', $output); $output = preg_replace('/(__)?[a-zA-Z0-9]+_?[a-zA-Z0-9]*\\-([\'|"])/', '\\2', $output); if (AWS_APP::config()->get('system')->debug) { $output .= "\r\n<!-- Template End: " . $display_template_filename . " -->\r\n"; } } if ($display) { echo $output; flush(); } else { return $output; } }