protected function load() { if (!class_exists('lessc')) { $path = !empty(WS::env()->config->less->lessphp_dir) ? WS::env()->config->less->lessphp_dir : Templates_HTML_Preprocess::option('less_php_dir'); include_once $path . '/lessc.inc.php'; } }
protected function map_select_component($component) { if (is_null($component)) { $component = WS::env()->adminvars->component; } return $this->where("component = :component", (string) $component)->order_by('parent_id,ord'); }
public function __construct(DB_ORM_Mapper $parent = null) { parent::__construct($parent); CMS_ORM_Entity::$db = $this; CMS_Controller_Base::$db = $this; $this->cache = WS::env()->cache; }
public function setup() { if (CMS::vars()->storage_type() == 'orm') { $this->orm_name = 'vars'; } if (CMS::vars()->storage_type() == 'storage') { $this->storage_name = 'vars'; } $this->merge_options(); Templates_HTML::add_scripts_settings(array('adminvars' => $this->js_config)); $this->auth_realm = CMS::$admin_realm; if (isset(CMS::$cfg->vars->use_tinymce)) { $s = trim(CMS::$cfg->vars->use_tinymce); if ($s == '' || $s == '0') { $this->use_tinymce = false; } } $this->use_views_from(CMS::views_path('admin/vars'))->use_views_from(CMS::views_path('admin/vars2')); if (CMS::vars()->storage_type() == 'orm') { $types = WS::env()->orm->vars->types(); $this->form_fields = $types->fields; $types->end(); } if (CMS::vars()->storage_type() == 'storage') { $this->form_fields = $this->storage()->make_entity()->fields(); // var_dump($this->form_fields); } $this->component = WS::env()->adminvars->component; //TODO: configure fields if (empty($this->tree_fields)) { $this->tree_fields = array('title' => array('caption' => 'Комментарий', 'flex' => 1), 'var_description' => array('caption' => 'Тип', 'flex' => 1), 'full_code' => array('caption' => 'Идентификатор', 'width' => 200)); } return parent::setup(); }
public function make_url() { $args = func_get_args(); $path = CMS::admin_path() . self::$prefix . '/' . ($args[0] == 'dir' ? $args[1] : implode('/', $args)); $component = WS::env()->vars->component; $url = $path . ($component ? '?component=' . $component : ''); return $url; }
public function select_component($component) { if (is_null($component)) { $component = WS::env()->adminvars->component; } $this->current_query->eq("component", (string) $component)->order_by('parent_id')->order_by('ord'); return $this; }
public static function db() { switch (self::$type) { case 'orm': return WS::env()->orm->vars; case 'storage': return Storage::manager()->vars; } }
public function action_prefix($name, $data, $item = false, $fields = array()) { $id = (int) WS::env()->request['id']; $item = CMS::vars()->db()->find($id); if ($item) { return $item->full_code . '.'; } return ''; }
static function start() { if (self::$clear_on_start && self::check_filters()) { $fh = fopen(self::$log_file, 'w'); fwrite($fh, "*** http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\n"); fwrite($fh, "*** " . date("Y.m.d - G:i") . "\n\n"); fclose($fh); } WS::env()->db->default->listener(new CMS_DBLogger()); }
/** * * @param Context $context */ public function handle(Context $context) { $ws = WS::getInstance(); $ws->handle($context); if (!$context->hasNext()) { $context->throwException("Unexpected end of JSON"); } $this->handleChar($context); $ws->handle($context); }
public function __construct($name) { $this->name = $name; $this->cache = WS::env()->cache; $this->setup(); if ($this->autodump_assets()) { $this->assets_dump_all(); } //TODO: config source (file, cache, vars ...) }
/** * Выполняет обработку запроса * * @param WS_Environment $env * * @return mixed */ public function run(WS_Environment $env) { if ($this->spawn) { $env = WS::Environment($env); } foreach ($this->values as $k => $v) { $env[$k] = $v; } return $this->application->run($env); }
protected function get_filename() { $file = $this->request('file'); if (empty($file)) { $fdata = json_decode(WS::env()->request->content, true); if (!empty($fdata['name'])) { $file = $fdata['name']; } } return $file; }
/** * * @param Context $context * @throws DecodeException */ public function handle(Context $context) { $ws = WS::getInstance(); $ws->handle($context); $value = new Value(); $value->handle($context); $ws->handle($context); if ($context->hasNext()) { $current = $context->current(); $context->throwException("Unexpected character('{$current}')"); } $this->result = $value->getResult(); }
public function fire($job, $data) { $content = Content::findOrFail($data['id']); $url = Config::get('app.iframely_host') . '/oembed'; $response = Guzzle::get($url, ['query' => ['url' => $content->url]])->json(); $content->type = $response['type']; $content->save(); if ($data['thumbnail'] && array_key_exists('thumbnail_url', $response)) { $content->setThumbnail($response['thumbnail_url']); } $content->autoThumbnail(); WS::send(json_encode(['topic' => 'content.' . $content->getKey() . '.thumbnail', 'url' => $content->getThumbnailPath(100, 75)])); $content->unset('thumbnail_loading'); $job->delete(); }
public function setup() { $this->orm_module = $this->getp('orm_module'); $this->admin_module = $this->getp('admin_module'); $this->schema_module = $this->getp('schema_module'); $this->orm_fields = $this->getp('orm_fields'); $this->admin_fields = $this->getp('admin_fields'); $this->component = $this->getp('component'); $this->component_module = "Component.{$this->component}"; $this->admin_tabs = (bool) $this->getp('admin_tabs', 0); $this->item_name = "{$this->orm_module}.Item"; $this->urls = WS::env()->urls->cmscomponentfactory; $this->auth_realm = CMS::$admin_realm; return parent::setup()->use_views_from(CMS::views_path('admin/factory'))->render_defaults('tables', 'urls', 'table', 'fields', 'key_field'); }
protected function load() { if ($this->loaded) { return true; } $this->loaded = true; if (!class_exists('scssc')) { $path = !empty(WS::env()->config->scss->scss_dir) ? WS::env()->config->less->lessphp_dir : self::option('scss_php_dir'); @(include_once $path . '/scss.inc.php'); } if (class_exists('scssc')) { $this->setup(); return true; } return false; }
public function action($name, $data, $action, $item = false, $fields = array()) { $args = func_get_args(); $res = Net_HTTP::Response(); $res->content_type('application/json'); $query = WS::env()->request['query']; $ents = CMS::items_for_select(Core::invoke($data['search'], array($query))); $values = array(); $empty = $this->get_empty($data); if ($empty && empty($query)) { $values[] = $empty; } foreach ($ents as $k => $e) { $values[] = array('id' => (int) $k, 'title' => (string) $e); } $res->body(json_encode(array('data' => $values))); return $res; }
public function sql_query() { $query = reset($this->args); if (!$query) { return; } $dsn = WS::env()->db->default->dsn; $cmd = $this->sql_command($dsn); switch ($dsn->type) { case "mysql": $cmd .= " -e \"{$query}\""; break; case "pgsql": $cmd .= " -c \"{$query}\""; break; } $rc = !(bool) $this->popen($cmd); return $rc; }
protected function load_helperes_from_cache($helpers) { if (!CMS::is_lazy_components()) { return; } if ($this->is_cache_loaded) { return; } $this->is_cache_loaded = true; if ($classes = WS::env()->cache->get('cms:viwes:helpers_classes')) { foreach ($classes as $name => $class) { $helpers->append($class, $name); } } else { Events::add_once('cms.load_components', function () use($helpers) { WS::env()->cache->set('cms:viwes:helpers_classes', $helpers->classes, 0); }); CMS::load_components(); } }
public function cloud($table, $name, $parms = array()) { if (isset($parms['cache'])) { $tags = WS::env()->cache->get($parms['cache']); if (is_array($tags)) { return $tags; } } $table_tags = self::table_tags($table, $name); $table_rels = self::table_rels($table, $name); $tags = array(); $cursor = CMS::orm()->connection->prepare("SELECT tags.id id,tags.title title, count(rels.item_id) cnt FROM {$table_rels} rels LEFT JOIN {$table_tags} tags ON tags.id=rels.tag_id GROUP BY tags.id, tags.title ORDER BY tags.title")->execute(); foreach ($cursor as $row) { $url = false; if (isset($parms['urls'])) { $url = call_user_func($parms['urls'], $row['id']); } $tags[$row['id']] = array('id' => $row['id'], 'title' => $row['title'], 'count' => $row['cnt'], 'url' => $url); } if (isset($parms['cache'])) { WS::env()->cache->set($parms['cache'], $tags); } return $tags; }
protected function action_update($name, $data, $action, $item = false, $fields = array()) { $fdatas = json_decode(WS::env()->request->content, true); $single = isset($fdatas['name']); $fdatas = $single ? array($fdatas) : $fdatas; $files = $single ? $this->files_data($name, $data, $item) : array('files'); foreach ($fdatas as $fk => $fdata) { if (isset($fdata['date'])) { $fdata['date'] = date('d.m.Y', strtotime($fdata['date'])); } if ($single) { foreach ($files['files'] as $k => $f) { if ($f['name'] == $fdata['name']) { $files['files'][$k] = $fdata; } } } else { $files['files'][$fk] = $fdata; } } Events::call('admin.change'); $this->update_files_data($files, $name, $data, $item); return json_encode(array('success' => true, 'items' => $fdatas)); }
public function action_delete($name, $data, $action, $item = false, $fields = array()) { if (!$item) { return json_encode(array('success' => true)); } $r = WS::env()->request; $iname = $r['item_name']; $data['__item'] = $item; $e = $this->get_assoc_mapper($name, $data)->make_entity(); $e['id'] = $r['item_id']; $e[$data['assoc']['value_column']] = $r['item_data']; $e[$data['assoc']['key_column']] = $item->id(); $e->delete(); return json_encode(array()); }
*/ if (!(in_array(substr($_SERVER['REMOTE_ADDR'], 0, 10), $ip) && isset($_POST['transactionType']) && (int) $_POST['referenceNumber'])) { die; } $msql = SafeMySQL::getInstance(); $sql = 'SELECT `attempt_id`, NOW() AS `timestamp`, `a`.`created` AS `ac` FROM `attempts` AS `a` WHERE `tracking_number` = ?i'; $data = $msql->getRow($sql, $_POST['referenceNumber']); if (!$data['attempt_id']) { $sql = 'INSERT IGNORE INTO `attempts_temp` (`type`, `tracking_number`) VALUES (?s, ?i)'; $msql->query($sql, $_POST['transactionType'], $_POST['referenceNumber']); /* $headers = 'From: "BLS' . Config::get()->prefix . ' IPN" <*****@*****.**>'; mail('*****@*****.**', 'UNKNOWN ATTEMPT', print_r($_POST,1), $headers); */ die; } // finalize order (success and declined) $ws = new WS(); $ws->bsReturn($data['attempt_id'], $_POST['transactionType']); switch ($_POST['transactionType']) { case 'CHARGE': case 'UNDER_REVIEW': case 'DECLINE': case 'REFUND': case 'CANCELLATION_REFUND': break; default: $headers = 'From: "BLS' . Config::get()->prefix . ' IPN" <*****@*****.**>'; mail('*****@*****.**', 'UNKNOWN TYPE DATA', print_r($data, 1) . "\n\n" . print_r($_POST, 1), $headers); break; }
public function cache($backend = null) { if (!is_null($backend)) { $this->cache = $backend; } if (is_null($this->cache)) { $this->cache = clone WS::env()->cache; } return $this->cache; }
protected function fallback($name, $parms, $args) { $name = trim($name, '/'); $this->views_paths[] = ''; $template = $this->search_fallback_template($name); if ($template) { $args = array('env' => WS::env(), 'request' => WS::env()->request, 'args' => $parms, 'args_array' => $args, 'insertion_name' => $name); Events::call("cms.insertions.template.{$name}", $template, $args); if (isset($this->args['layout'])) { return $this->args['layout']->root->partial($template, $args); } return Templates::HTML($template)->with($args)->render(); } return null; }
/** * Запускает приложение * * @param WS_ServiceInterface $app * * @return WS_Runner */ public function run(WS_ServiceInterface $app) { $environment = WS::env(); $environment->request = $this->adapter->make_request(); $rc = Events::call('ws.run'); if (!is_null($rc)) { return $rc; } $environment->response = Net_HTTP::Response(); $body = $app->run($environment); $response = Net_HTTP::merge_response($body, $environment->response); return $this->adapter->process_response($response); }
/** * Возвращает пулл соединений с БД * * @todo сделать что-нибудь с WS * * @return array; */ public static function connections_pool() { return WS::env()->pdo_connections ? WS::env()->pdo_connections : array(); }
<?php //开启服务 //http://192.168.22.171:8080/WS.php //访问服务 //http://192.168.22.171:8080/chating.html // http://www.jb51.net/article/48019.htm error_reporting(E_ALL); ob_implicit_flush(true); set_time_limit(0); $ws = new WS('192.168.22.171', 8000); $ws->run(); class WS { public $sockets; public $users; public $master; public function __construct($address, $port) { $this->master = $this->WebSocket($address, $port); $this->sockets = array('s' => $this->master); } function run() { while (true) { $changes = $this->sockets; socket_select($changes, $write = NULL, $except = NULL, NULL); $this->logs("run ===> 1"); foreach ($changes as $sock) { if ($sock == $this->master) { $this->logs("run ===> 2");
<?php require_once '../config.php'; require_once FILE_ROOT . "db/answer/getdata.php"; $action = $_REQUEST['action']; $request = new WS(); switch ($_SERVER['REQUEST_METHOD']) { case "GET": $request->get($action, $_REQUEST); break; case "POST": $request->post($action, $_REQUEST); break; default: break; } class WS { function get($action, $_REQUEST) { switch ($action) { case "list": $this->listAnswers($_REQUEST); break; case "questioninfo": $this->answerInfo($_REQUEST); break; default: break; } }