function __construct($app) { $this->app = $app; $this->sitemap = app::get('site')->getConf('sitemaps'); if (!is_array($this->sitemap)) { $sitemap_config = kernel::single('site_module_base')->assemble_config(); if (is_array($sitemap_config)) { $this->sitemap = $sitemap_config; //todo:兼容kvstroe出错的情况下 if (!kernel::single('site_module_base')->write_config($sitemap_config)) { kernel::log('Error: sitemap can\'t save to kvstore'); //todo:如果写入失败,记录于系统日志中,前台不报错,保证网站运行正常 } } else { //if false trigger_error('sitemap is lost!', E_USER_ERROR); //todo:无sitemap时报错 } } foreach ($this->sitemap as $part => $controller) { $urlmap[$controller[0] . ':' . $controller[1]] = $part; } $this->urlmap = $urlmap; $this->_request = kernel::single('base_component_request'); $this->_response = kernel::single('base_component_response'); }
public function __call($method, $params) { //api 版本历史 $apiv_history = array('2.0', '1.0'); $api_info = base_rpc_service::$api_info; $api_obj = NULL; $flag = false; foreach ($apiv_history as $v) { if ($this->apiv == $v) { $flag = true; } if ($flag) { $service = 'apiv_' . $v . '_' . $api_info['api_name']; $api_obj = kernel::service($service); if (method_exists($api_obj, $method)) { break; } else { kernel::log('apiv service:' . $service . ', method:' . $method . ' not found!'); } } } if (!$api_obj || !method_exists($api_obj, $method)) { trigger_error('server reject!', E_USER_ERROR); } //return call_user_func_array(array( &$api_obj, $method ), $params); return $api_obj->{$method}($params[0], $params[1]); }
private function parse_app($app_id) { $app = app::get($app_id); $dir = $app->lang_dir . '/' . $lang; if (!is_dir($dir)) { mkdir($dir, 0775, true); } $file = $dir . '/convert.php'; $array = array(); $this->parse_php($app, $app->app_dir . '/controller', $array); $this->parse_php($app, $app->app_dir . '/dbschema', $array); $this->parse_php($app, $app->app_dir . '/model', $array); $this->parse_php($app, $app->app_dir . '/lib', $array); $this->parse_html($app, $app->app_dir . '/view', $array); $this->parse_html($app, $app->app_dir . '/lang/js', $array); if (!empty($array)) { $content = '<?php' . "\n"; $content .= 'return ' . var_export($array, true) . ';'; $content .= "\n" . '//' . count($array) . ' items'; $content .= "\n" . '?>'; file_put_contents($file, $content); kernel::log(sprintf('%s 语言包转换文件生成成功,共 %d items', $app->app_id, count($array))); } else { kernel::log(sprintf('%s 没有语言包', $app->app_id)); } }
function post_install() { kernel::log('Initial themes'); kernel::single('site_theme_base')->set_last_modify(); kernel::single('site_theme_install')->initthemes(); $themes = kernel::single('site_theme_install')->check_install(); }
public function post_install() { kernel::log('Initial ectools'); kernel::single('base_initial', 'ectools')->init(); kernel::log('Initial Regions'); kernel::single('ectools_regions_mainland')->install(); }
public function command_sync_user() { //kernel::console_output = false; $http = kernel::single('base_httpclient'); $response = $http->get(app::get('suitclient')->getConf('syncuser')); if ($response) { $server_users = json_decode($response); $model = app::get('pam')->model('account'); $result = $model->getList('login_name', array('account_type' => 'shopadmin')); $client_user = array(); foreach ($result as $value) { $client_user[] = $value['login_name']; } $model2 = app::get('desktop')->model('users'); foreach ($server_users as $server_user) { if (!in_array($server_user, $client_user)) { $user = array('name' => $server_user, 'status' => 1, 'super' => 0, 'disabled' => false, 'pam_account' => array('login_name' => $server_user, 'login_password' => md5(time() . rand()), 'account_type' => 'shopadmin'), 'roles' => array(array('role_id' => 1))); $model2->save($user); } } kernel::log('同步成功'); kernel::log('ok.'); //不加 "ok."则会弹提示信息并不能自动关闭@lujy } else { kernel::log('同步失败或套件里没有用户'); kernel::log('ok.'); } exit; }
function trigger() { set_time_limit(0); ignore_user_abort(1); //检查计划任务有没有增减 $status = $this->status(); $service = (array) kernel::servicelist('autotask'); $servicelist = array_values($service['iterator']->getArrayCopy()); $exists_class = array_keys($status); $diff_class = array_diff($servicelist, $exists_class); $add = $delete = array(); foreach ($diff_class as $class_name) { if (in_array($class_name, $exists_class)) { //app::get('base')->model('task')->delete('task'=>$class_name); } else { $class = new $class_name(); if ($class instanceof base_interface_task) { $data = array('task' => $class_name, 'description' => $class->description(), 'rule' => $class->rule(), 'last' => time()); app::get('base')->model('task')->insert($data); } } } //根据规则执行计划任务 $status = $this->status(); $now = time(); foreach ($status as $cron) { if ($cron['enabled'] && $now >= base_crontabparser::parse($cron['rule'], $cron['last'])) { $cron_class = new $cron['task'](); $cron_class->exec(); app::get('base')->model('task')->update(array('last' => $now), array('task' => $cron['task'])); kernel::log('crontab ' . $cron['task'] . ' run at ' . date('Y-m-d H:m:i', $now)); } } }
public function install() { $widgets_name = basename($this->getPathname()); $widgets_app = $this->target_app->app_id; kernel::log('Installing Widgets ' . $widgets_app . ':' . $widgets_name); $data['app'] = $widgets_app; $data['name'] = $widgets_name; app::get('site')->model('widgets')->insert($data); }
static function active() { if (self::get()) { kernel::log('Using exists certificate: config/certi.php'); } else { kernel::log('Request new certificate'); self::register(); } }
function post_install($options) { kernel::log('Create admin account'); //设置用户体系,前后台互不相干 pam_account::register_account_type('desktop', 'shopadmin', '后台管理系统'); //todo: 封装成更简单的函数 $account = array('pam_account' => array('login_name' => $options['admin_uname'], 'login_password' => md5($options['admin_password']), 'account_type' => 'shopadmin'), 'name' => $options['admin_uname'], 'super' => 1, 'status' => 1); app::get('desktop')->model('users')->save($account); }
static function active($app_id = 'b2c') { if (self::get('node_id', $app_id)) { kernel::log('Using exists shopnode: kvstore shop_site_node_id'); } else { kernel::log('Request new shopnode'); self::register($app_id); } }
public function install() { kernel::log('Installing ' . $this->content_typename() . ' ' . $this->key()); $data = $this->row(); $data['content_type'] = 'service_category'; if ($this->current['optname']) { $data['content_title'] = $this->current['optname']; } if ($this->current['opttype']) { $data['content_path'] = $this->current['opttype']; } $obj_app_content = app::get('base')->model('app_content'); $obj_app_content->insert($data); //base_kvstore::instance('service')->fetch($this->key,$service_define); $index = 0; $time = time(); $service_define = array(); foreach ((array) $this->current['class'] as $class) { $row = $this->row(); $row['content_path'] = $class['value']; if ($class['orderby']) { $row['ordernum'] = $class['orderby']; } else { $row['ordernum'] = 50; } $row['input_time'] = $time + $index; $obj_app_content->insert($row); //$service_define['list'][$class['value']] = $class['value']; //todo: interface... check $index++; } $arr_servicelist = $obj_app_content->getList('content_path', array('content_name' => $this->key, 'content_type' => 'service'), 0, -1, 'ordernum ASC, input_time DESC'); foreach ((array) $arr_servicelist as $arr) { $service_define['list'][$arr['content_path']] = $arr['content_path']; } /*if(is_array($service_define['list']) && count($service_define['list'])){ foreach($service_define['list'] AS $service_name){ $strpos = strpos($service_name, "_"); if($strpos){ $app_id = substr($service_name, 0, $strpos); }else{ $app_id = 'base'; } $level = $this->check_service_level($app_id); $service_orders[$level][] = $service_name; } unset($service_define['list']); ksort($service_orders); foreach($service_orders AS $service_order){ foreach($service_order AS $service_name){ $service_define['list'][$service_name] = $service_name; } } }//todo: depends order*/ base_kvstore::instance('service')->store($this->key, $service_define); }
function install() { kernel::log('Installing ' . $this->content_typename() . ' ' . $this->current['id']); $row = app::get('desktop')->model('menus')->dump(array('menu_type' => 'workground', 'workground' => $this->current['id'])); if ($row['menu_id']) { return $row['menu_id']; } else { return app::get('desktop')->model('menus')->insert($this->row()); } }
public function install() { $dir = $this->getPathname(); if (is_dir($dir) && realpath($dir) == realpath($this->target_app->res_dir . '/bundle')) { $spriteinfo = kernel::single('base_application_imgbundle_factory')->reset()->set_app($this->target_app->app_id)->set_directory('bundle')->set_output('ex_' . $this->target_app->app_id . '.png')->create(); kernel::log(sprintf('%s bundle create Ok!', $this->target_app->app_id)); base_kvstore::instance('imgbundle')->store('imgbundle_' . $this->target_app->app_id, $spriteinfo); kernel::log(sprintf('%s spriteinfo save Ok!', $this->target_app->app_id)); } }
public function install() { if (is_dir($this->getPathname())) { $widgets_name = basename($this->getPathname()); $theme = $this->target_theme; kernel::log('Installing Theme Widgets ' . $theme . ':' . $widgets_name); $data['theme'] = $theme; $data['name'] = $widgets_name; app::get('site')->model('widgets')->insert($data); } }
function runtask($task_id) { $http = kernel::single('base_httpclient'); $_POST['task_id'] = $task_id; $url = kernel::api_url('api.queue', 'worker', array('task_id' => $task_id)); kernel::log('Spawn [Task-' . $task_id . '] ' . $url); //99%概率不会有问题 $http->hostaddr = $_SERVER["SERVER_ADDR"] ? $_SERVER["SERVER_ADDR"] : '127.0.0.1'; $http->hostport = $_SERVER["SERVER_PORT"] ? $_SERVER["SERVER_PORT"] : '80'; $ret = $http->post($url, $_POST, null, null, true); }
function write($config) { $this->sample_file = realpath($this->sample_file); $sample = file_get_contents($this->sample_file); foreach ($config as $k => $v) { $arr['#(define\\s*\\(\\s*[\'"]' . strtoupper($k) . '[\'"]\\s*,\\s*)[^;]+;#i'] = '\\1\'' . str_replace('\'', '\\\'', $v) . '\');'; } kernel::log('Using sample :' . $this->sample_file); kernel::log('Writing config file... ok.'); return file_put_contents(ROOT_DIR . '/config/config.php', preg_replace(array_keys($arr), array_values($arr), $sample)); }
function post_install() { kernel::log('Initial image'); kernel::single('base_initial', 'image')->init(); $conf = app::get('image')->getConf('image.default.set'); app::get('image')->setConf('image.set', $conf); $obj_image = app::get('image')->model('image'); $app_dir = app::get('image')->app_dir; foreach ($conf as $item) { $obj_image->store($app_dir . '/initial/default_images/' . $item['default_image'] . '.gif', $item['default_image']); } }
function runtask($task_id) { $http = new base_httpclient(); $_POST['task_id'] = $task_id; $url = kernel::openapi_url('openapi.queue', 'worker', array('task_id' => $task_id)); kernel::log('Spawn [Task-' . $task_id . '] ' . $url); //99%概率不会有问题 $http->hostaddr = $_SERVER["SERVER_ADDR"] ? $_SERVER["SERVER_ADDR"] : '127.0.0.1'; $http->hostport = $_SERVER["SERVER_PORT"] ? $_SERVER["SERVER_PORT"] : '80'; $http->set_timeout(2); kernel::log($http->post($url, $_POST)); }
function write_compat() { $file = ROOT_DIR . '/config/config.php'; if (file_exists($file)) { kernel::log('Writing config compat... ok.'); $sample = preg_replace('/(' . preg_quote('/**************** compat functions begin ****************/', '/') . ')(.*)(' . preg_quote('/**************** compat functions end ****************/', '/') . ')/isU', "\\1" . "\r\n" . join("\r\n", $this->check_compat()) . "\r\n" . '\\3', file_get_contents($file)); return file_put_contents($file, $sample); } else { kernel::log('Writing config compat... failure.'); return false; } }
function post_install($options) { pam_account::register_account_type('b2c', 'member', '前台会员系统'); kernel::log('Register b2c meta'); $obj_goods = app::get('b2c')->model('goods'); $col = array('adjunct' => array('type' => 'text', 'required' => false, 'label' => __('商品配件'), 'width' => 110, 'editable' => false)); $obj_goods->meta_register($col); kernel::log('Initial b2c'); kernel::single('base_initial', 'b2c')->init(); kernel::log('Init b2c member'); $attr_model = app::get('b2c')->model('member_attr')->init(); if ($options['demodata']) { kernel::log('Import demo data'); kernel::single('base_demo')->init(); } $logo = app::get('b2c')->getConf('site.logo'); $obj_image = app::get('image')->model('image'); $app_dir = app::get('b2c')->app_dir; $obj_image->store($app_dir . '/initial/site_logo.png', $logo); $obj_image->store($app_dir . '/initial/default_images/spec_def.bmp', app::get('b2c')->getConf('spec.default.pic')); // set listener and modifier $app_b2c = app::get('b2c'); $all = $app_b2c->getConf('system.event_listener'); if ($this->arr_listener) { foreach ($this->arr_listener as $k => $v) { $k = strtolower($k); $v = strtolower($v); if (!isset($all[$k])) { $all[$k] = array(); } $all[$k][$v] = $v; } } $app_b2c->setConf('system.event_listener', $all); $all = $app_b2c->getConf('system.event_listener_key'); if ($this->arr_lister_keys) { foreach ($this->arr_lister_keys as $k => $v) { $k = strtolower($k); $v = strtolower($v); if (!isset($all[$k])) { $all[$k] = array(); } $all[$k][$v] = $v; } } $app_b2c->setConf('system.event_listener_key', $all); // 获取node_id... if (!base_shopnode::node_id('b2c') && base_certificate::certi_id()) { base_shopnode::active('b2c'); } }
function dl($url, $to = null) { if (!$to) { $to = tempnam(false, 'PDL'); } $this->total = 0; $this->download = 0; $this->_img = 0; $this->sock = fopen($to, 'wb'); $this->last = 0; kernel::log(sprintf('--%s-- %s', date('H:i:s'), $url)); kernel::log(sprintf(' => %s', $to)); echo "\n"; return $this->get($url, null, array(&$this, 'write')); }
public function install() { $dir = $this->getPathname(); $dir = str_replace('\\', '/', $dir); $app_lang_dir = str_replace('\\', '/', $this->target_app->lang_dir); $lang_name = basename($dir); foreach (utils::tree($dir) as $k => $v) { if (!is_file($v)) { continue; } $tree[$lang_name][] = str_replace($app_lang_dir . '/' . $lang_name . '/', '', $v); } kernel::log($this->target_app->app_id . ' "' . $lang_name . '" language resource stored'); lang::set_res($this->target_app->app_id, $tree); }
function command_create($project_name) { $options = $this->get_options(); $options['template'] = $options['template'] ? $options['template'] : 'dev_app'; list($template, $template_args) = explode(':', $options['template']); $project_prototype = kernel::single($template); $project_path = $project_prototype->init($project_name, $template_args); if ($project_path) { $project = array('name' => $project_name, 'path' => $project_path, 'createtime' => time(), 'type' => $options['template']); dev_project::save($project); kernel::log('Write project info... ok.'); } else { kernel::log('error.'); } }
function command_app($app_name = null) { if (!$app_name) { $app_name = readline('app name: '); } do { $app_path = APP_DIR . '/' . $app_name; $app_path = realpath($app_path); } while (!$appname && strlen($app_path) >= strlen(APP_DIR) && file_exites($app_path)); $base_dir = APP_DIR . '/base'; kernel::log('Init App...' . $app_name); utils::cp($base_dir . '/examples/app', APP_DIR . '/' . $app_name); utils::replace_p(APP_DIR . '/' . $project_name, array('%*APP_NAME*%' => $project_name)); kernel::log('. done!'); return true; }
function install() { foreach ($this->current['menugroup'] as $f*g => $val) { foreach ($val['menu'] as $key => $data) { #print_r($data);exit; kernel::log('Installing ' . $this->content_typename() . ' ' . $this->key()); app::get('desktop')->model('menus')->insert($this->row($f*g, $key)); } } if ($this->current['menu']) { foreach ($this->current['menu'] as $f*g => $val) { kernel::log('Installing ' . $this->content_typename() . ' ' . $this->key()); app::get('desktop')->model('menus')->insert($this->menu_row($f*g)); } } }
public function callback($result) { /*$log_file = DATA_DIR.'/logs/b2c/callback/{date}/api_result.php'; $logfile = str_replace('{date}', date("Ymd"), $log_file); if(!file_exists($logfile)) { if(!is_dir(dirname($logfile))) utils::mkdir_p(dirname($logfile)); $fs = fopen($logfile, 'w'); $str_xml .= "<?php exit(0);"; $str_xml .= "'<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; $str_xml .= "<response>"; $str_xml .= "</response>';"; fwrite($fs, $str_xml); fclose($fs); } // 记录api日志 if (filesize($logfile)) { $fs = fopen($logfile, 'a+'); $str_xml = fread($fs, filesize($logfile)); $str_xml = substr($str_xml, 0, strlen($str_xml) - 13); fclose($fs); } $fs = fopen($logfile, 'w');*/ $str_xml .= "<query>"; foreach ($result->response as $key => $value) { $str_xml .= "<{$key}>" . $value . "</{$key}>"; } $str_xml .= "</query>"; //$str_xml .= "</response>';"; /*fwrite($fs, $str_xml); fclose($fs);*/ kernel::log($str_xml); // 生成通知信息 $arr_callback_params = $result->get_callback_params(); $status = $result->get_status(); $res_message = $result->get_result(); $data = $result->get_data(); include_once ROOT_DIR . '/app/b2c/lib/api/rpc/request_api_method.php'; $message = 'msg_id:' . $result->response['msg_id'] . ', ' . $arr_apis[$arr_callback_params['method']] . ($status == 'succ' ? app::get('b2c')->_('成功,') : app::get('b2c')->_('失败,')) . ($res_message ? $res_message . ', ' : '') . app::get('b2c')->_('单号:') . $data['tid']; $arr_msg = array('rsp' => $status, 'res' => $message, 'data' => $data); return $arr_msg; }
function action($action, $url, $headers = null, $callback = null, $data = null, $ping_only = false) { $action = $action == 'post' ? true : false; $headers = array_merge($this->default_headers, (array) $headers); foreach ((array) $headers as $k => $v) { $set_headers[] .= $k . ': ' . $v; } $this->responseBody = ''; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'callback_header')); curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, 'callback_body')); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); if ($set_headers) { curl_setopt($ch, CURLOPT_HTTPHEADER, $set_headers); } curl_setopt($ch, CURLOPT_HTTP_VERSION, $this->http_ver); curl_setopt($ch, CURLOPT_POST, $action == 'post' ? true : false); curl_exec($ch); curl_close($ch); $this->callback = $callback; preg_match('/\\d{3}/', $this->responseHeader, $match); $this->responseCode = $match[0]; switch ($this->responseCode) { case 301: case 302: kernel::log(" Redirect \n\t--> " . $responseHeader['location']); return false; case 200: kernel::log(' OK'); if ($this->callback) { if (!call_user_func_array($this->callback, array($this, $this->responseBody))) { break; } } return $this->responseBody; case 404: kernel::log(' file not found'); return false; default: return false; } }
function command_view() { $app_dir_obj = dir(APP_DIR); $explorer = kernel::single('dev_explorer'); $code = kernel::single('dev_checker_code'); $explorer->set_checker($code); while (($app_file = $app_dir_obj->read()) !== false) { if (substr($app_file, 0, 1) == '.') { continue; } $app_dir = APP_DIR . "/{$app_file}"; chdir($app_dir); $code->current_app_dir = $app_dir; kernel::log('search in ' . $app_dir); $explorer->start('.'); } $code->get_unref_html(); }
function trigger() { set_time_limit(0); ignore_user_abort(1); $status = $this->status(); $now = time(); foreach (kernel::servicelist('autotask') as $k => $o) { foreach ($this->type() as $name => $interval) { if (isset($status[$k][$name]) && $now - $status[$k][$name] < $interval) { continue; } kernel::log($k . '::' . $name); $o->{$name}(); $data = array('last' => $now, 'task' => $k, $name => $now); app::get('base')->model('task')->replace($data, array('task' => $k)); } } }