/** * Get list by member * * @access public * @param int $member_id target member_id * @return Response (html) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function get_member($member_id = null) { $this->api_accept_formats = array('html'); $this->controller_common_api(function () use($member_id) { $member_id = \Input::get('member_id', 0) ?: $member_id; list($is_mypage, $member) = $member_id ? $this->check_auth_and_is_mypage($member_id, true) : array(null, false); list($limit, $page) = $this->common_get_pager_list_params(conf('articles.limit', 'album'), conf('articles.limit_max', 'album')); $data = Site_Model::get_album_images($limit, $page, get_uid(), $member, $is_mypage, null, $this->format != 'html'); $data['liked_album_image_ids'] = conf('like.isEnabled') && \Auth::check() ? \Site_Model::get_liked_ids('album_image', $this->u->id, $data['list']) : array(); if ($this->format == 'html') { if ($member) { $data['member'] = $member; } } else { $list_array = array(); foreach ($data['list'] as $key => $obj) { $row = $obj->to_array(); $row['album']['member'] = \Model_Member::get_one_basic4id($obj->album->member_id); $list_array[] = $row; } // json response $data = $list_array; } $this->set_response_body_api($data, $this->format == 'html' ? 'image/_parts/list' : null); }); }
function __construct() { // check whether params are set $params = array('dbServer', 'dbUser', 'dbPassword', 'dbDatabase'); $missingParams = array(); foreach ($params as $param) { if (!conf($param)) { $missingParams[] = $param; } } if (count($missingParams)) { throw new Exception('Missing parameters for database connection.'); } // initialize DB connection #var_dump($this->db->connect_errno); $this->db = @new \mysqli(conf('dbServer'), conf('dbUser'), conf('dbPassword'), conf('dbDatabase')); #var_dump($params,$this->db,$this->db->connect_errno); if (!$this->db or $this->db->connect_errno) { if ($this->db) { $info = $this->db->connect_error; } else { $info = 'Mysqli construction error'; } throw new Exception('Database connection error'); } $this->db->query("SET NAMES utf8"); // finish init TODO $this->isInit = true; }
/** * Upload images * * @access public * @return Response (json|html) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function post_upload($parent_id = null) { $this->api_accept_formats = array('html', 'json'); $this->api_not_check_csrf = true; $this->controller_common_api(function () use($parent_id) { $upload_type = 'img'; $news = \News\Model_News::check_authority($parent_id); if (!in_array($this->format, array('html', 'json'))) { throw new HttpNotFoundException(); } $thumbnail_size = \Input::post('thumbnail_size'); if (!\Validation::_validation_in_array($thumbnail_size, array('M', 'S'))) { throw new \HttpInvalidInputException('Invalid input data'); } $insert_target = \Input::post('insert_target'); $is_insert_body_image = conf('image.isInsertBody', 'news'); $options = \Site_Upload::get_upload_handler_options($this->u->id, true, false, 'nw', $parent_id, true, 'img', $is_insert_body_image); $uploadhandler = new \MyUploadHandler($options, false); \DB::start_transaction(); $files = $uploadhandler->post(false); $files['files'] = \News\Model_NewsImage::save_images($parent_id, $files['files']); \DB::commit_transaction(); $files['upload_type'] = $upload_type; $files['thumbnail_size'] = $thumbnail_size; $files['insert_target'] = $insert_target; $files['model'] = 'news'; $this->set_response_body_api($files, $this->format == 'html' ? 'filetmp/_parts/upload_images' : null); }); }
public function before_delete(\Orm\Model $obj) { // delete profile image. if (conf('upload.types.img.types.m.save_as_album_image') && $obj->file_name && ($file = \Model_File::get4name($obj->file_name))) { $file->delete(); } }
public function error_404($message = '') { if ($this->ctx->hook('Response.404')) { return; } $this->error($message == '' ? conf('cms.sys-error-404', 'Page not found') : $message); }
/** */ function send(array $params = [], &$error_message = '') { $CRLF = "\r\n"; $TAB = "\t"; $params['charset'] = $params['charset'] ?: conf('charset') ?: $this->PARENT->DEFAULT_CHARSET ?: 'utf-8'; $params['mailer_name'] = $params['mailer_name'] ?: $this->PARENT->DEFAULT_MAILER_NAME; $params['text'] = $params['text'] ?: 'Sorry, but you need an html mailer to read this mail.'; $OB = '----=_OuterBoundary_000'; $IB = '----=_InnerBoundery_001'; $headers = 'MIME-Version: 1.0' . $CRLF; $headers .= $params['email_from'] ? 'From:' . $params['name_from'] . '<' . $params['email_from'] . '>' . $CRLF : ''; $headers .= $params['email_to'] ? 'To:' . $params['name_to'] . '<' . $params['email_to'] . '>' . $CRLF : ''; $headers .= $params['email_from'] ? 'Reply-To:' . $params['name_from'] . '<' . $params['email_from'] . '>' . $CRLF : ''; $params['priority'] && ($headers .= 'X-Priority:' . intval($params['priority']) . $CRLF); $headers .= 'X-Mailer:' . $params['mailer_name'] . $CRLF; $headers .= 'Content-Type:multipart/mixed;' . $CRLF . $TAB . 'boundary="' . $OB . '"' . $CRLF; // Messages start with text/html alternatives in OB $msg = 'This is a multi-part message in MIME format.' . $CRLF; $msg .= $CRLF . '--' . $OB . $CRLF; if (strlen($params['text']) || strlen($params['html'])) { $msg .= 'Content-Type: multipart/alternative;' . $CRLF . $TAB . 'boundary="' . $IB . '"' . $CRLF . $CRLF; } // plaintext section if (strlen($params['text'])) { $msg .= $CRLF . '--' . $IB . $CRLF; $msg .= 'Content-Type: text/plain;' . $CRLF . $TAB . 'charset="' . $params['charset'] . '"' . $CRLF; $msg .= 'Content-Transfer-Encoding: quoted-printable' . $CRLF . $CRLF; // plaintext goes here $msg .= $params['text'] . $CRLF . $CRLF; } // html section if (strlen($params['html'])) { $msg .= $CRLF . '--' . $IB . $CRLF; $msg .= 'Content-Type: text/html;' . $CRLF . $TAB . 'charset="' . $params['charset'] . '"' . $CRLF; $msg .= 'Content-Transfer-Encoding: base64' . $CRLF . $CRLF; // html goes here $msg .= chunk_split(base64_encode($params['html'])) . $CRLF . $CRLF; } // end of IB if (strlen($params['text']) || strlen($params['html'])) { $msg .= $CRLF . '--' . $IB . '--' . $CRLF; } // attachments if ($this->ALLOW_ATTACHMENTS) { foreach ((array) $params['attaches'] as $att_file) { $file_name = basename($att_file); $msg .= $CRLF . '--' . $OB . $CRLF; $msg .= 'Content-Type: application/octetstream;' . $CRLF . $TAB . 'name="' . $file_name . '"' . $CRLF; $msg .= 'Content-Transfer-Encoding: base64' . $CRLF; $msg .= 'Content-Disposition: attachment;' . $CRLF . $TAB . 'filename="' . $file_name . '"' . $CRLF . $CRLF; // file goes here $msg .= chunk_split(base64_encode(@file_get_contents($att_file))); $msg .= $CRLF . $CRLF; } } // message ends $msg .= $CRLF . '--' . $OB . '--' . $CRLF; // Send composed email return mail($params['email_to'], $params['subject'], $msg, $headers, implode('', $params['mta_params'])); }
public static function move_from_file_tmp(Model_FileTmp $file_tmp, $new_filename_prefix = '', $upload_type = 'img') { $file = static::forge(); $file->name = $file_tmp->name; if ($new_filename_prefix) { $file->name = Site_Upload::change_filename_prefix($file_tmp->name, $new_filename_prefix); } $file->filesize = $file_tmp->filesize; $file->original_filename = $file_tmp->original_filename; $file->type = $file_tmp->type; $file->member_id = $file_tmp->member_id; $file->user_type = $file_tmp->user_type; if (!is_null($file_tmp->exif)) { $file->exif = $file_tmp->exif; } if (!empty($file_tmp->shot_at)) { $file->shot_at = $file_tmp->shot_at; } $file->save(); if (conf('upload.storageType') == 'db') { $file_bin = Model_FileBin::get4name($file_tmp->name); $file_bin->name = $file->name; $file_bin->save(); } elseif (conf('upload.storageType') == 'S3') { Site_S3::move($file_tmp->name, $file->name, $upload_type); } $file_tmp->delete(); return $file; }
function isTraining() { if ('training' === conf('app.env')) { return true; } return false; }
public function __construct() { parent::__construct(); global $mobile_cfg; if ($mobile_cfg == null) { $mobile_cfg = (require_once APP_ROOT_PATH . "system/mobile_cfg/" . APP_TYPE . "/webnav_cfg.php"); } check_install(); //重新处理后台的语言加载机制,后台语言环境配置于后台config.php文件 $langSet = conf('DEFAULT_LANG'); // 定义当前语言 define('LANG_SET', strtolower($langSet)); // 读取项目公共语言包 if (is_file(LANG_PATH . $langSet . '/common.php')) { L(include LANG_PATH . $langSet . '/common.php'); $this->lang_pack = (require LANG_PATH . $langSet . '/common.php'); if (!file_exists(APP_ROOT_PATH . "public/runtime/admin/lang.js")) { $str = "var LANG = {"; foreach ($this->lang_pack as $k => $lang) { $str .= "\"" . $k . "\":\"" . $lang . "\","; } $str = substr($str, 0, -1); $str .= "};"; file_put_contents(APP_ROOT_PATH . "public/runtime/admin/lang.js", $str); } } es_session::close(); }
public function update() { $conf_res = M("Conf")->where("is_effect = 1 and is_conf = 1")->findAll(); foreach ($conf_res as $k => $v) { conf($v['name'], $_REQUEST[$v['name']]); if ($v['name'] == 'URL_MODEL' && $v['value'] != $_REQUEST[$v['name']]) { clear_dir_file(get_real_path() . "public/runtime/app/data_caches/"); clear_dir_file(get_real_path() . "public/runtime/app/tpl_caches/"); clear_dir_file(get_real_path() . "public/runtime/app/tpl_compiled/"); clear_dir_file(get_real_path() . "public/runtime/app/data_caches/"); clear_dir_file(get_real_path() . "public/runtime/data/page_static_cache/"); clear_dir_file(get_real_path() . "public/runtime/data/dynamic_avatar_cache/"); } } //开始写入配置文件 $sys_configs = M("Conf")->findAll(); $config_str = "<?php\n"; $config_str .= "return array(\n"; foreach ($sys_configs as $k => $v) { $config_str .= "'" . $v['name'] . "'=>'" . addslashes($v['value']) . "',\n"; } $config_str .= ");\n ?>"; $filename = get_real_path() . "public/sys_config.php"; if (!($handle = fopen($filename, 'w'))) { $this->error(l("OPEN_FILE_ERROR") . $filename); } if (fwrite($handle, $config_str) === FALSE) { $this->error(l("WRITE_FILE_ERROR") . $filename); } fclose($handle); save_log(l("CONF_UPDATED"), 1); //clear_cache(); write_timezone(); $this->success(L("UPDATE_SUCCESS")); }
/** * Thread detail * * @access public * @params integer * @return Response */ public function action_detail($id = null) { $thread_id = (int) $id; $thread = Model_Thread::check_authority($thread_id); $this->check_browse_authority($thread->public_flag, $thread->member_id); // 既読処理 if (\Auth::check()) { $this->change_notice_status2read($this->u->id, 'thread', $id); } // thread_image $images = Model_ThreadImage::get4thread_id($thread_id); // thread_comment $default_params = array('latest' => 1); list($limit, $is_latest, $is_desc, $since_id, $max_id) = $this->common_get_list_params($default_params, conf('view_params_default.detail.comment.limit_max')); list($list, $next_id, $all_comment_count) = Model_ThreadComment::get_list(array('thread_id' => $thread_id), $limit, $is_latest, $is_desc, $since_id, $max_id, null, false, true); // thread_like $is_liked_self = \Auth::check() ? Model_ThreadLike::check_liked($id, $this->u->id) : false; $title = array('name' => $thread->title); $header_info = array(); $ogp_infos = array('title' => $thread->title, 'description' => $thread->body); if ($images) { $ogp_infos['image'] = \Site_Util::get_image_uri4image_list($images, 't', 'raw'); } $this->set_title_and_breadcrumbs($title, array('thread' => term('thread', 'site.list')), null, 'thread', $header_info, false, false, $ogp_infos); $this->template->subtitle = \View::forge('_parts/detail_subtitle', array('thread' => $thread)); $this->template->post_footer = \View::forge('_parts/comment/handlebars_template'); $data = array('thread' => $thread, 'images' => $images, 'comments' => $list, 'all_comment_count' => $all_comment_count, 'comment_next_id' => $next_id, 'is_liked_self' => $is_liked_self, 'liked_ids' => conf('like.isEnabled') && \Auth::check() && $list ? \Site_Model::get_liked_ids('thread_comment', $this->u->id, $list) : array()); $this->template->content = \View::forge('detail', $data); }
function index() { $data['install_scripts'] = array(); $data['uninstall_scripts'] = array(); // Get required modules from config $use_modules = conf('modules'); // Collect install scripts from modules foreach (scandir(conf('module_path')) as $module) { // Skip everything that starts with a dot if (strpos($module, '.') === 0) { continue; } // Check if we need to uninstall this module if ($use_modules && !in_array($module, $use_modules)) { // Check if there is an uninstall script if (is_file(conf('module_path') . $module . '/scripts/uninstall.sh')) { $data['uninstall_scripts'][$module] = conf('module_path') . $module . '/scripts/uninstall.sh'; } continue; } // Check if there is a install script if (is_file(conf('module_path') . $module . '/scripts/install.sh')) { $data['install_scripts'][$module] = conf('module_path') . $module . '/scripts/install.sh'; } } $obj = new View(); $obj->view('install/install_script', $data); }
/** * */ protected function webhook() { $status = attrib('status'); switch (strtolower($status)) { case 'on': put('根據測試, 必須夾帶 crt 檔案才能正確設定 web hook, 請手動設定.'); /* $telegram = new \Telegram\Bot\Api(conf('bot.token')); $response = $telegram->setWebhook([ 'url' => conf('bot.hook_file') ]); put( $response ); */ return; case 'off': // 該指令關閉 web hook, 通常用於開發環境 $telegram = new \Telegram\Bot\Api(conf('bot.token')); $response = $telegram->removeWebhook(); put($response->getDecodedBody()); return; default: break; } put('fail'); }
/** * Login form */ function _show_form() { // Already logged in users not needed to login again if (main()->USER_ID) { return js_redirect($this->DEF_REDIRECT_URL); } // Default resirect after login $_url_after_login = $this->DEF_REDIRECT_URL; // Process special redirect format if (!empty($_GET['go_url'])) { if (false !== ($pos1 = strpos($_GET['go_url'], ';'))) { $_GET['go_url'] = substr($_GET['go_url'], 0, $pos1) . '&action=' . substr($_GET['go_url'], $pos1 + 1); } $_url_after_login = '******' . str_replace(';', '&', $_GET['go_url']); } elseif (conf('_force_login_go_url')) { $_url_after_login = conf('_force_login_go_url'); } if (strlen($_url_after_login) > 3 && !$_SESSION['user_go_url']) { if (substr($_url_after_login, 0, 3) == './?') { $_url_after_login = substr($_url_after_login, 3); } $_SESSION['user_go_url'] = $_url_after_login; } // To prevent multiple login forms displayed on one page conf('_login_form_displayed', true); return form(['form_action' => './?task=login'], ['class' => 'form-horizontal', 'legend' => 'Member Login', 'hide_empty' => 1])->validate(['__form_id__' => 'login_full_form', $this->LOGIN_FIELD => 'trim|required', 'password' => 'trim|required'])->login($this->LOGIN_FIELD, '', ['class' => 'input-medium', 'type' => $this->LOGIN_FIELD != 'login' ? $this->LOGIN_FIELD : 'text'])->password(['class' => 'input-medium'])->check_box('remember_me', '', ['no_label' => 1])->submit(['value' => 'Login', 'link_name' => 'Register', 'link_url' => './?object=register'])->container($this->oauth(['only_icons' => 1]), ['wide' => 0])->link('Retrieve lost password', './?object=get_pswd', ['class' => 'btn btn-mini btn-xs'])->hidden('action', null, ['value' => 'login']); }
public static function _init() { static::$_properties['name']['label'] = term('member.name'); static::$_properties['name']['validation']['min_length'][] = conf('member.name.validation.length.min'); static::$_properties['name']['validation']['max_length'][] = conf('member.name.validation.length.max'); if (is_enabled('notice') && conf('mention.isEnabled', 'notice')) { static::$_properties['name']['validation']['match_pattern'][] = sprintf('/^(%s)$/u', conf('member.name.validation.match_patterns.register')); $method = conf('member.name.validation.blacklist.method'); if (is_callable($method)) { static::$_properties['name']['validation']['not_in_array'][] = call_user_func($method); } } static::$_properties['register_type']['validation']['in_array'][] = Site_Member::get_accept_member_register_types(); $sex_options = Site_Form::get_form_options4config('term.member.sex.options'); static::$_properties['sex']['label'] = term('member.sex.label'); static::$_properties['sex']['form']['options'] = $sex_options; static::$_properties['sex']['validation']['in_array'][] = array_keys($sex_options); $options_public_flag = Site_Util::get_public_flags(); static::$_properties['sex_public_flag']['label'] = sprintf('%sの%s', term('member.sex.label'), term('public_flag.label')); static::$_properties['sex_public_flag']['form'] = Site_Form::get_public_flag_configs(); static::$_properties['sex_public_flag']['validation']['in_array'][] = $options_public_flag; static::$_properties['birthyear']['label'] = term('member.birthyear'); $options = Form_Util::get_year_options(conf('member.profile.birthday.year_from'), conf('member.profile.birthday.year_to')); static::$_properties['birthyear']['form']['options'] = $options; static::$_properties['birthyear']['validation']['in_array'][] = array_keys($options); static::$_properties['birthyear_public_flag']['label'] = sprintf('%sの%s', term('member.birthyear'), term('public_flag.label')); static::$_properties['birthyear_public_flag']['form'] = Site_Form::get_public_flag_configs(); static::$_properties['birthyear_public_flag']['validation']['in_array'][] = $options_public_flag; static::$_properties['birthday']['label'] = term('member.birthday'); static::$_properties['birthday_public_flag']['label'] = sprintf('%sの%s', term('member.birthday'), term('public_flag.label')); static::$_properties['birthday_public_flag']['form'] = Site_Form::get_public_flag_configs(); static::$_properties['birthday_public_flag']['validation']['in_array'][] = $options_public_flag; static::$_properties['invite_member_id'] = Util_Orm::get_relational_numeric_key_prop(false); }
/** * Site index * * @access public * @return Response */ public function action_index() { $data = array(); if (Config::get('page.site.index.timeline.isEnabled') && is_enabled('timeline')) { $data['timelines'] = \Timeline\Site_Util::get_list4view(\Auth::check() ? $this->u->id : 0, 0, false, null, $this->common_get_list_params(array('desc' => 1, 'latest' => 1, 'limit' => Config::get('page.site.index.timeline.list.limit')), Config::get('page.site.index.timeline.list.limit_max'), true)); $data['timelines']['see_more_link'] = array('uri' => 'timeline'); //$this->template->post_footer = \View::forge('timeline::_parts/load_timelines'); } if (Config::get('page.site.index.news.isEnabled') && is_enabled('news')) { list($limit, $page) = $this->common_get_pager_list_params(\Config::get('page.site.index.news.list.limit'), \Config::get('page.site.index.news.list.limit_max')); $data['news_list'] = \News\Site_Model::get_list($limit, $page, \Auth::check()); $data['news_list']['see_more_link'] = array('uri' => 'news'); } if (Config::get('page.site.index.albumImage.isEnabled') && is_enabled('album')) { list($limit, $page) = $this->common_get_pager_list_params(\Config::get('page.site.index.albumImage.list.limit'), \Config::get('page.site.index.albumImage.list.limit_max')); $data['album_images'] = \Album\Model_AlbumImage::get_pager_list(array('related' => array('album'), 'where' => \Site_Model::get_where_params4list(0, \Auth::check() ? $this->u->id : 0), 'order_by' => array('id' => 'desc'), 'limit' => $limit), $page); $data['album_images']['liked_album_image_ids'] = conf('like.isEnabled') && \Auth::check() ? \Site_Model::get_liked_ids('album_image', $this->u->id, $data['album_images']['list']) : array(); $data['album_images']['column_count'] = \Config::get('page.site.index.albumImage.list.column_count'); //$this->template->post_footer = \View::forge('image/_parts/list_footer'); } $this->template->post_footer = \View::forge('site/_parts/index_footer'); if (conf('site.index.slide.isEnabled', 'page')) { if (conf('site.index.slide.recentAlbumImage.isEnabled', 'page')) { $images = \Album\Site_Util::get_top_slide_image_uris(); } else { $images = Config::get('page.site.index.slide.images'); } $this->template->post_header_content = View::forge('site/_parts/slide', array('image_uris' => $images)); } $this->set_title_and_breadcrumbs('', null, null, null, null, true, true); $this->template->content = View::forge('site/index', $data); if (!empty($data['news_list']['list'])) { $this->template->content->set_safe('html_bodys', \News\Site_Model::convert_raw_bodys($data['news_list']['list'])); } }
function clear_patterns() { $html = table('SELECT * FROM ' . db('shop_patterns'), ['table_attr' => 'id="patterns_list"', 'filter' => $_SESSION[$_GET['object'] . '__patterns'], 'filter_params' => ['search' => 'like', 'repalce' => 'like', 'cat_id' => 'in']])->text('search', ['header_tip' => $this->SEARCH_TIP])->text('replace')->text('description')->func('cat_id', function ($value, $extra, $row_info) { $category = conf('all_cats::' . $value); $category = !empty($category) ? $category['name'] : t('In all categories'); return '<span class="badge badge-warning">' . $category . '</span>'; }, ['desc' => 'Category'])->func('id', function ($value, $extra, $row_info) { $where = ''; if (!empty($row_info['cat_id'])) { $cat_ids = _class('cats')->_get_recursive_cat_ids($row_info['cat_id']); $where = ' AND (cat_id IN (' . implode(',', $cat_ids) . ') OR id IN (SELECT product_id FROM ' . db('shop_product_to_category') . ' WHERE category_id IN (' . implode(',', $cat_ids) . ')))'; } $sql = 'SELECT COUNT(*) AS `0` FROM ' . db('shop_products') . ' WHERE LOWER(name) REGEXP \'[[:<:]]' . mb_strtolower($row_info['search'], 'UTF-8') . '[[:>:]]\'' . $where; list($count) = db()->query_fetch($sql); return '<span class="badge badge-info pattern_count">' . $count . '</span>'; }, ['desc' => 'Products for changing'])->btn_func('Run', function ($row_info, $params, $instance_params, $_this) { if ($row_info['process']) { return '<button class="btn btn-mini btn-xs run_item btn-warning" data-id="' . $row_info['id'] . '"><i class="icon-refresh fa fa-refresh icon-spin fa-spin"></i> <span>' . t('Process') . '...</span></button>'; } else { return '<button class="btn btn-mini btn-xs btn-info run_item" data-id="' . $row_info['id'] . '"><i class="icon-play fa fa-play"></i> <span>' . t('Run') . '</span></button>'; } })->btn_func('Rollback', function ($row_info, $params, $instance_params, $_this) { if ($row_info['process']) { return '<button class="btn btn-mini btn-xs btn-warning rollback_item" data-id="' . $row_info['id'] . '"><i class="icon-refresh fa fa-refresh icon-spin fa-spin"></i> <span>' . t('Process') . '...</span></button>'; } else { return '<button class="btn btn-mini btn-xs btn-danger rollback_item" data-id="' . $row_info['id'] . '"><i class="icon-undo fa fa-undo"></i> <span>' . t('Rollback') . '</span></button>'; } })->btn('List of changes', './?object=manage_shop&action=clear_pattern_list&id=%d', ['icon' => 'icon-th-list fa fa-th-list'])->btn_edit('', './?object=manage_shop&action=clear_pattern_edit&id=%d', ['no_ajax' => 1])->btn_delete('', './?object=manage_shop&action=clear_pattern_delete&id=%d')->footer_add('Add pattern', './?object=manage_shop&action=clear_pattern_add', ['no_ajax' => 1]); $replace = ['pattern_run_url' => './?object=manage_shop&action=clear_pattern_run', 'pattern_stop_url' => './?object=manage_shop&action=clear_pattern_stop', 'pattern_status_url' => './?object=manage_shop&action=clear_pattern_status', 'pattern_rollback_url' => './?object=manage_shop&action=clear_pattern_rollback']; $html .= tpl()->parse('manage_shop/product_clear_patterns', $replace); return $html; }
public function delete() { //彻底删除指定记录 $ajax = intval($_REQUEST['ajax']); $id = $_REQUEST['id']; if (isset($id)) { $condition = array('id' => array('in', explode(',', $id))); $rel_data = M(MODULE_NAME)->where($condition)->findAll(); foreach ($rel_data as $data) { $info[] = $data['name']; if (conf("DEFAULT_ADMIN") == $data['name']) { $this->error($data['name'] . l("DEFAULT_ADMIN_CANNOT_DELETE"), $ajax); } } if ($info) { $info = implode(",", $info); } $list = M(MODULE_NAME)->where($condition)->delete(); if ($list !== false) { save_log($info . l("FOREVER_DELETE_SUCCESS"), 1); $this->success(l("FOREVER_DELETE_SUCCESS"), $ajax); } else { save_log($info . l("FOREVER_DELETE_FAILED"), 0); $this->error(l("FOREVER_DELETE_FAILED"), $ajax); } } else { $this->error(l("INVALID_OPERATION"), $ajax); } }
/** * test to master id */ protected function send() { $chatId = conf('bot.master_id'); $text = 'Hello World'; $messageId = BotHelper::sendMessage($chatId, $text); put($messageId); }
/** * validate message */ protected function _validateMessage($message) { if (!$message) { di('log')->record("message not found at " . date('Y-m-d H:i:s')); exit; } // 已處理過的 message 將不再處理 if ($message->getIsUsed()) { di('log')->record("message {$id} is used"); exit; } // 回應的 chat_id 必須在白名單之內 $chatId = $message->getChatId(); $allowIds = conf('bot.allow_chat_ids'); if (!in_array($chatId, $allowIds)) { di('log')->record("message can not allow send to {$chatId} ({$message->getName()})"); // debug -> 如果不在予許的名單內, 發送警告訊息 if (isTraining()) { $userId = $message->getUserId(); $text = '您不在白名單之內 by BOT'; BotHelper::sendMessage($userId, $text); } exit; } }
/** * Basis URL aplikasi * * @param string Permalink * @return string */ function siteUrl($permalink = '') { if (in_array(substr($permalink, 0, 1), ['#', '?'])) { $permalink = app('uri')->path() . $permalink; } return conf('baseurl') . $permalink; }
static function init() { if (!self::$connection) { self::$connection = new self(conf()->getItem('db.host'), conf()->getItem('db.port'), conf()->getItem('db.dbname'), conf()->getItem('db.username'), conf()->getItem('db.password', '')); } return self::$connection; }
/** * Get a list of layout options and their names. Useful for * layout selection in forms. */ public static function options() { $layout = conf('General', 'default_layout'); if ($layout === 'default') { $layouts = self::all(); $out = array(); foreach ($layouts as $layout) { $out[$layout] = ucfirst($layout); } return $out; } if (file_exists('layouts/' . $layout . '/elefant.json')) { $info = json_decode(file_get_contents('layouts/' . $layout . '/elefant.json')); if (isset($info->layouts) && is_object($info->layouts)) { return array_merge(array('default' => __('Default')), (array) $info->layouts); } } $files = glob('layouts/' . $layout . '/*.html'); $layouts = array('default' => __('Default')); if ($files) { foreach ($files as $file) { $name = basename($file, '.html'); if ($name !== $layout) { $layouts[$layout . '/' . $name] = ucfirst($name); } } } return $layouts; }
/** * Track user error message * * @param string * @return void */ function _track_error($error_message = "") { if (empty($error_message)) { return false; } // Try to get user error message source $backtrace = debug_backtrace(); $cur_trace = $backtrace[1]; $next_trace = $backtrace[2]; // Prepare log text $text = "## LOG STARTS AT " . date("Y-m-d H:i:s") . "; QUERY_STRING: " . $_SERVER["QUERY_STRING"] . "; REFERER: " . $_SERVER["HTTP_REFERER"] . "; USER_ID: " . main()->USER_ID . "; USER_GROUP: " . main()->USER_GROUP . "; SITE_ID: " . SITE_ID . "; USER_AGENT: " . $_SERVER["HTTP_USER_AGENT"] . " ##\r\n"; $text .= "URL: http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "\r\n"; $text .= "SOURCE FILE: \"" . $cur_trace["file"] . "\" at LINE " . $cur_trace["line"] . "; " . (!empty($next_trace["class"]) ? "METHOD: " . $next_trace["class"] . "->" . $next_trace["function"] : "FUNCTION: " . $next_trace["function"]) . ";\r\n"; $text .= "MESSAGE: " . $error_message . "\r\n"; $text .= "## LOG ENDS ##\r\n"; // Do add current error info to the log file $h = fopen(INCLUDE_PATH . $this->LOG_USER_ERRORS_FILE_NAME, "a"); fwrite($h, $text); fclose($h); // Do store message into database (also check if that possible) if ($this->LOG_INTO_DB && is_object(db())) { $error_type = 0; db()->insert_safe('log_user_errors', ['error_level' => intval($error_type), 'error_text' => $error_message, 'source_file' => $cur_trace['file'], 'source_line' => intval($cur_trace['line']), 'date' => time(), 'site_id' => (int) conf('SITE_ID'), 'user_id' => intval($_SESSION[MAIN_TYPE_ADMIN ? 'admin_id' : 'user_id']), 'user_group' => intval($_SESSION[MAIN_TYPE_ADMIN ? 'admin_group' : 'user_group']), 'is_admin' => MAIN_TYPE_ADMIN ? 1 : 0, 'ip' => common()->get_ip(), 'query_string' => WEB_PATH . '?' . $_SERVER['QUERY_STRING'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referer' => $_SERVER['HTTP_REFERER'], 'request_uri' => $_SERVER['REQUEST_URI'], 'env_data' => $this->DB_LOG_ENV ? $this->_prepare_env() : '', 'object' => $_GET['object'], 'action' => $_GET['action']]); } }
public function __construct(callable $conf) { $endpoint = sprintf($conf('FS_AZURE_PROTOCOL'), $conf('FS_AZURE_USERNAME'), conf('FS_AZURE_API_KEY')); $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($endpoint); $adapter = new AzureAdapter($blobRestProxy, conf('FS_AZURE_CONTAINER')); $this->constructFileSystem($adapter); }
public function __construct() { parent::__construct(); check_install(); //重新处理后台的语言加载机制,后台语言环境配置于后台config.php文件 $langSet = conf('DEFAULT_LANG'); // 定义当前语言 define('LANG_SET', strtolower($langSet)); // 读取项目公共语言包 if (is_file(LANG_PATH . $langSet . '/common.php')) { L(include LANG_PATH . $langSet . '/common.php'); $this->lang_pack = (require LANG_PATH . $langSet . '/common.php'); if (is_file(LANG_PATH . $langSet . '/weixin.php')) { L(include LANG_PATH . $langSet . '/weixin.php'); $weixin_lang = (require LANG_PATH . $langSet . '/weixin.php'); $this->lang_pack = array_merge($this->lang_pack, $weixin_lang); } if (!file_exists(APP_ROOT_PATH . "public/runtime/admin/lang.js")) { $str = "var LANG = {"; foreach ($this->lang_pack as $k => $lang) { $str .= "\"" . $k . "\":\"" . $lang . "\","; } $str = substr($str, 0, -1); $str .= "};"; file_put_contents(APP_ROOT_PATH . "public/runtime/admin/lang.js", $str); } } }
/** * */ protected function send() { if (!attrib('to') || !attrib('body')) { pr(<<<'EOD' ------------------------------------------------------------ arguments: --to send to email address --subject email subject --body email content message example: php send --to xxx@gmail.com --subject "hello" --body "hi" php send --to xxx@gmail.com --body "$(cat message.txt)" ------------------------------------------------------------ EOD ); exit; } $getFrom = function () { $fromEmail = conf('gmail.email'); $fromName = conf('gmail.name'); return "{$fromName} <{$fromEmail}>"; }; $to = attrib('to'); $subject = attrib('subject', 'not-subject'); $body = attrib('body'); $result = \GmailManager::sendMessage($getFrom(), $to, $subject, $body); if ($result) { pr('Send success'); } else { pr('Send fail !'); } }
function process($data) { //list of bundleids to ignore $bundleid_ignorelist = is_array(conf('bundleid_ignorelist')) ? conf('bundleid_ignorelist') : array(); $regex = '/^' . implode('|', $bundleid_ignorelist) . '$/'; // List of paths to ignore $bundlepath_ignorelist = is_array(conf('bundlepath_ignorelist')) ? conf('bundlepath_ignorelist') : array(); $path_regex = ':^' . implode('|', $bundlepath_ignorelist) . '$:'; require_once APP_PATH . 'lib/CFPropertyList/CFPropertyList.php'; $parser = new CFPropertyList(); $parser->parse($data, CFPropertyList::FORMAT_XML); $inventory_list = $parser->toArray(); if (count($inventory_list)) { // clear existing inventory items $this->delete_set($this->serial); // insert current inventory items foreach ($inventory_list as $item) { if (preg_match($regex, $item['bundleid'])) { continue; } if (preg_match($path_regex, $item['path'])) { continue; } $item['bundlename'] = isset($item['CFBundleName']) ? $item['CFBundleName'] : ''; $this->id = 0; $this->merge($item)->save(); } } }
/** * Divide pages */ function go($sql = '', $url_path = '', $render_type = '', $records_on_page = 0, $num_records = 0, $tpls_path = '', $add_get_vars = 1, $extra = []) { if (is_array($url_path)) { $extra = $url_path; $url_path = ''; } if (empty($url_path)) { if ($extra['url_path']) { $url_path = $extra['url_path']; } elseif ($extra['path']) { $url_path = $extra['path']; } } if (!$url_path) { $url_path = './?object=' . $_GET['object'] . '&action=' . $_GET['action'] . (isset($_GET['id']) ? '&id=' . $_GET['id'] : ''); } if (!strlen($render_type)) { if ($extra['render_type']) { $render_type = $extra['render_type']; } elseif ($extra['type']) { $render_type = $extra['type']; } } if (!$render_type) { $render_type = $this->DEFAULT_RENDER_TYPE; } $requested_page = isset($extra['requested_page']) ? $extra['requested_page'] : $_GET['page']; $records_on_page = abs(intval($extra['records_on_page'] ?: $records_on_page)); $per_page = $records_on_page ?: (MAIN_TYPE_ADMIN ? conf('admin_per_page') : conf('user_per_page')); if (!$per_page) { $per_page = conf('per_page') ?: $this->DEFAULT_PER_PAGE; } $num_records = abs(intval($extra['num_records'] ?: $num_records)); $tpls_path = $extra['tpls_path'] ?: $tpls_path; if (!strlen($tpls_path)) { $tpls_path = $this->DEFAULT_TPLS_PATH; } $add_get_vars = isset($extra['add_get_vars']) ? $extra['add_get_vars'] : ($add_get_vars ?: 1); $total_records = (int) $this->get_total_records($sql, $num_records, $extra); $total_pages = $per_page ? ceil($total_records / $per_page) : 0; // Global number of pages limit (only for user section) if (MAIN_TYPE_USER && $this->PAGES_LIMIT && $total_pages > $this->PAGES_LIMIT) { $old_total_pages = $total_pages; $total_pages = $this->PAGES_LIMIT; } // Filter not existing pages numbers if (!$requested_page || $requested_page < 1) { $cur_page = 1; } elseif ($requested_page > $total_pages) { $cur_page = $total_pages; } else { $cur_page = $requested_page; } $render_func = 'render_type_' . $render_type; $rendered = $this->{$render_func}(['total_records' => $total_records, 'per_page' => $per_page, 'requested_page' => $requested_page, 'cur_page' => $cur_page, 'total_pages' => $total_pages, 'url_path' => $url_path . ($add_get_vars ? _add_get(['page']) : ''), 'tpls_path' => $tpls_path, 'pages_per_block' => $extra['pages_per_block'] ?: $this->PAGES_PER_BLOCK]); $result = ['limit_sql' => ' LIMIT ' . intval($rendered['first']) . ', ' . intval($per_page), 'pages_html' => trim($rendered['html']), 'total_records' => intval($total_records), 'first_record' => intval($rendered['first']), 'total_pages' => intval($total_pages), 'limited_pages' => intval($limited_pages), 'per_page' => intval($per_page), 'requested_page' => intval($requested_page)]; return array_values($result); // Needed for compatibility with tons of legacy code, that using list(...) = divide_pages(...) }
function delete_machine($serial_number = '') { $status = array('status' => 'undefined', 'rowcount' => 0); if (!$this->authorized('delete_machine')) { $status['status'] = 'unauthorized'; } else { // Delete machine entry from all tables $machine = new Machine_model(); // List tables (unfortunately this is not db-agnostic) switch ($machine->get_driver()) { case 'sqlite': $tbl_query = "SELECT name FROM sqlite_master \n\t\t\t\t\t\tWHERE type = 'table' AND name NOT LIKE 'sqlite_%'"; break; default: // Get database name from dsn string if (conf('dbname')) { $tbl_query = "SELECT TABLE_NAME AS name FROM information_schema.TABLES \n\t\t\t\t\t\tWHERE TABLE_TYPE='BASE TABLE' AND TABLE_SCHEMA='" . conf('dbname') . "'"; } else { die('Admin:delete_machine: Cannot find database name.'); } } // Get tables $tables = array(); foreach ($machine->query($tbl_query) as $obj) { $tables[] = $obj->name; } // Get database handle $dbh = getdbh(); $dbh->beginTransaction(); // Affected rows counter $cnt = 0; // Delete entries foreach ($tables as $table) { // Migration has no serial number if ($table == 'migration') { continue; } // hash and inventoryitem use serial FIXME if ($table == 'hash' or $table == 'inventoryitem') { $serial = 'serial'; } else { $serial = 'serial_number'; } $sql = "DELETE FROM {$table} WHERE `{$serial}`=?"; if (!($stmt = $dbh->prepare($sql))) { die('Prepare ' . $sql . ' failed'); } $stmt->bindValue(1, $serial_number); $stmt->execute(); $cnt += $stmt->rowCount(); } $dbh->commit(); // Return status $status['status'] = 'success'; $status['rowcount'] = $cnt; } $obj = new View(); $obj->view('json', array('msg' => $status)); }