public function output() { header('Content-Type: application/json; charset=utf-8'); if ($this->_content !== null) { file_put_contents('php://output', J($this->_content) . PHP_EOL); } }
function logout() { $_SESSION['id'] = null; setcookie('xing_name', '', time() - 7 * 3600); setcookie('xing_pass', '', time() - 7 * 3600); J("?m=user&a=login"); }
public function __call($method, $params) { if ($method === __FUNCTION__) { return; } if ($this->_path) { $method = $this->_path . '/' . $method; } $id = base_convert($this->_uniqid++, 10, 36); $rpcTimeout = Config::get('rpc.timeout'); $timeout = $rpcTimeout[$method] ?: $rpcTimeout['default']; $this->_header['X-Gini-RPC-Session'] = $_SERVER['HTTP_X_GINI_RPC_SESSION'] ?: $this->_url . '/' . $method; $raw_data = $this->post(J(['jsonrpc' => '2.0', 'method' => $method, 'params' => $params, 'id' => $id]), $timeout); \Gini\Logger::of('http-jsonrpc')->debug('RPC <= {data}', ['data' => $raw_data]); $data = @json_decode($raw_data, true); if (!isset($data['result'])) { if (isset($data['error'])) { $message = sprintf('remote error: %s', $data['error']['message']); $code = $data['error']['code']; throw IoC::construct('\\Gini\\RPC\\Exception', $message, $code); } elseif (is_null($data)) { $message = sprintf('unknown error with raw data: %s', $raw_data ?: '(null)'); throw IoC::construct('\\Gini\\RPC\\Exception', $message, -32400); } elseif ($id != $data['id']) { $message = 'wrong response id!'; throw IoC::construct('\\Gini\\RPC\\Exception', $message, -32400); } } return $data['result']; }
function B($a) { if (C($a)) { $this->D($a); } elseif ($a instanceof E) { $a->F($this); } elseif (G($a)) { } elseif (H($a)) { I($a); foreach ($a as $b => $c) { if (J($b)) { if (!H($c) || !L('M', $c) || !L('O', $c)) { throw new P('Q'); } $d = isset($c['R']) ? $c['R'] : []; $b = $c['M']; $c = $c['O']; } elseif (H($c) && L('O', $c)) { $d = isset($c['R']) ? $c['R'] : []; $c = $c['O']; } else { $d = []; } $this->AB($b); $this->AC($d); $this->B($c); $this->AE(); } } elseif (AF($a)) { throw new P('AH' . AI($a)); } }
public function __toString() { if ($this->_path) { ob_start(); echo "(function () {\n"; foreach ($this->_vars as $k => $v) { echo "var {$k}=" . J($v) . ";\n"; } @(include $this->_path); echo "\n})();"; $output = ob_get_contents(); ob_end_clean(); } return $output; }
public function actionExport($args) { $opt = \Gini\Util::getOpt($args, 'h', ['help', 'json', 'yaml']); if (isset($opt['h']) || isset($opt['help'])) { echo "Usage: gini config export [-h|--help] [--json|--yaml]\n"; return; } \Gini\Config::setup(); $items = \Gini\Config::export(); if (isset($opt['json'])) { echo J($items, JSON_PRETTY_PRINT) . "\n"; } else { echo yaml_emit($items, YAML_UTF8_ENCODING); } }
/** * 初始化模块. **/ public function actionInit($args) { $path = $_SERVER['PWD']; $prompt = ['name' => 'Name', 'description' => 'Description', 'version' => 'Version', 'dependencies' => 'Dependencies']; $default = ['name' => ucwords(str_replace('-', ' ', basename($path))), 'path' => $path, 'description' => 'App description...', 'version' => '0.1.0', 'dependencies' => '{}']; foreach ($prompt as $k => $v) { $data[$k] = readline($v . ' [' . ($default[$k] ?: 'N/A') . ']: '); if (!$data[$k]) { $data[$k] = $default[$k]; } } $data['dependencies'] = @json_decode($data['dependencies']) ?: (object) []; $gini_json = J($data, JSON_PRETTY_PRINT); file_put_contents($path . '/gini.json', $gini_json); }
public function actionSearchOrderStat($criteria) { $result = ['total' => 0, 'token' => '']; $type = $criteria['type']; if (!isset(self::$allowedTypes[$type])) { return $result; } $select = $this->_getSelect($type); $where = $this->_getWhere($criteria); $groupBy = $this->_getGroupBy($type); $sql = $select . $where . $groupBy; $db = \Gini\Database::db(); $query = $db->query($sql); $count = $query ? $query->count() : 0; $token = md5(J($criteria)); $_SESSION[$token] = $criteria; $result = ['total' => $total, 'token' => $token]; return $result; }
public function actionSchedule() { // read cron cache $cron_cache_file = sys_get_temp_dir() . '/cron_cache_' . sha1(APP_PATH); $fh = fopen($cron_cache_file, 'c+'); if ($fh) { if (flock($fh, LOCK_EX | LOCK_NB)) { $cron_cache = @json_decode(fread($fh), true) ?: []; $cron_config = (array) \Gini\Config::get('cron'); foreach ($cron_config as $name => $job) { $schedule = $job['schedule'] ?: $job['interval']; $cron = \Cron\CronExpression::factory($schedule); $cache =& $cron_cache[$name]; if (isset($cache)) { $next = date_create($cache['next']); $now = date_create('now'); if ($next <= $now) { // we have to run it $cache['last_run_at'] = $now->format('c'); \Gini\Logger::of('cron')->info('cron run {command}', ['command' => $job['command']]); $pid = pcntl_fork(); if ($pid == -1) { continue; } elseif ($pid == 0) { $command_args = \Gini\Util::parseArgs($job['command']); \Gini\CLI::dispatch($command_args); exit; } } } $cache['next'] = $cron->getNextRunDate()->format('c'); } while (pcntl_wait($status) > 0) { } ftruncate($fh, 0); fwrite($fh, J($cron_cache)); flock($fh, LOCK_UN); } fclose($fh); } }
/** * 初始化模块. **/ public function actionInit($args) { if (count($args) > 0) { if (in_array('phpunit', $args)) { return $this->_iniPHPUnit(); } return; } $path = $_SERVER['PWD']; $prompt = ['id' => 'Id', 'name' => 'Name', 'description' => 'Description', 'version' => 'Version', 'dependencies' => 'Dependencies']; $default = ['name' => ucwords(str_replace('-', ' ', basename($path))), 'id' => strtolower(basename($path)), 'path' => $path, 'description' => 'App description...', 'version' => '0.1.0', 'dependencies' => '[]']; foreach ($prompt as $k => $v) { $data[$k] = readline($v . ' [' . ($default[$k] ?: 'N/A') . ']: '); if (!$data[$k]) { $data[$k] = $default[$k]; } } $data['dependencies'] = (array) @json_decode($data['dependencies']); $gini_json = J($data, JSON_PRETTY_PRINT); file_put_contents($path . '/gini.json', $gini_json); }
public function actionInit($args) { $app = \Gini\Core::moduleInfo(APP_ID); $composer_json = ['name' => $app->id, 'description' => $app->description ?: '', 'license' => 'proprietary', 'repositories' => [['type' => 'composer', 'url' => 'http://satis.genee.cn']]]; $opt = \Gini\Util::getOpt($args, 'n', ['no-packagist']); if (isset($opt['n']) || isset($opt['--no-packagist'])) { $composer_json['repositories'][] = ['packagist' => false]; echo "Generating Composer configuration file without Packagist...\n"; } else { echo "Generating Composer configuration file...\n"; } $walked = []; $walk = function ($info) use(&$walk, &$walked, &$composer_json) { $walked[$info->id] = true; foreach ($info->dependencies as $name => $version) { if (isset($walked[$name])) { continue; } $app = \Gini\Core::moduleInfo($name); if ($app) { $walk($app); } } $composer_json = \Gini\Util::arrayMergeDeep($info->composer ?: [], $composer_json); }; $walk($app); if (isset($composer_json['require']) || isset($composer_json['require-dev'])) { if (file_exists(APP_PATH . '/composer.json')) { $confirm = strtolower(readline('File exists. Overwrite? [Y/n] ')); if ($confirm && $confirm != 'y') { echo " [33mcanceled.[0m\n"; return; } } file_put_contents(APP_PATH . '/composer.json', J($composer_json, JSON_PRETTY_PRINT)); echo " [32mdone.[0m\n"; } }
public function log($level, $message, array $context = []) { if (!$this->isLoggable($level)) { return; } $replacements = []; $_fillReplacements = function (&$replacements, $context, $prefix = '') use(&$_fillReplacements) { foreach ($context as $key => $val) { if (is_array($val)) { $_fillReplacements($replacements, $val, $prefix . $key . '.'); } else { $replacements['{' . $prefix . $key . '}'] = $val; } } }; $_fillReplacements($replacements, $context); $context['@ident'] = $this->_name; $context['@message'] = strtr($message, $replacements); $message = '@cee: ' . J($context); openlog(APP_ID, LOG_ODELAY, LOG_LOCAL0); syslog(self::$_LEVEL2PRIORITY[$level], $message); closelog(); }
function uploadImg() { import('ORG.Net.UploadFile'); $upload = new UploadFile(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $savepath = './uploads/' . date('Ymd') . '/'; if (!file_exists($savepath)) { mkdir($savepath); } $upload->savePath = $savepath; // 设置附件上传目录 if (!$upload->upload()) { // 上传错误提示错误信息 $this->error($upload->getErrorMsg()); } else { // 上传成功 获取上传文件信息 $info = $upload->getUploadFileInfo(); } print_r(J(__ROOT__ . '/' . $info[0]['savepath'] . '/' . $info[0]['savename'])); }
<?php if ($a['B']) { ?> B<?php echo $b['D']; ?> D<?php echo F($c['G']); ?> G<?php } else { echo 'I', J($d['K']), 'L'; }
/** * Bind some events with specified callback with/without weight. * * @param string $names * @param string $return * @param string $weight */ public static function bind($names, $return, $weight = 0) { $names = static::_normalizeNames($names); \Gini\Logger::of('core')->debug('{name} <= {return} [{weight}]', ['name' => J($names), 'return' => J($return), 'weight' => $weight]); foreach ($names as $name) { static::get($name, true)->addHandler($return, $weight); } }
<?php function B($a) { } ?> B<?php D('E', array('F' => $b, 'G' => $c)); H('I'); J('K', 'L'); M('N'); if (O(P::Q('R') . 'S')) { }
private static function _cacheConfig($env) { $plurals = self::_getORMPlurals(); printf("%s\n", 'Updating config cache...'); $config_items = \Gini\Config::fetch(); // update orm plurals $c = (array) $config_items['orm']['plurals']; $c += array_filter($plurals, function ($v) use($c) { return in_array($v, $c); }); $config_items['orm']['plurals'] = $c; $config_file = APP_PATH . '/cache/config.json'; \Gini\File::ensureDir(APP_PATH . '/cache'); file_put_contents($config_file, J($config_items)); \Gini\Config::setup(); echo " [32mdone.[0m\n"; }
/** * @brief 获取危化品商品搜索使用的token * * @param $params * [ * 'type'=> 'group | vendor | type' * 'type_value'=> '', * 'from'=> * 'to'=> * ] * * @return * [ * 'token'=> string, * 'total'=> int * ] */ public function actionSearchHazardousProducts(array $params) { $result = ['total' => 0, 'token' => '']; $type = $params['type']; $value = $params['type_value']; $from = $params['from']; $to = $params['to']; if (!isset(self::$allowedTypes[$type])) { return $result; } if (!$this->_allowShowDatas($type, $value)) { return $result; } $challenged = $this->_challengeFromTo($from, $to); if ($challenged === false) { return $result; } $newParams = ['type' => $type, 'type_value' => $value, 'conditions' => []]; if ($challenged) { list($from, $to) = $challenged; $newParams['conditions']['from'] = $from; $newParams['conditions']['to'] = $to; } if (!empty($params['allowed_product_types']) && is_array($params['allowed_product_types'])) { $newParams['conditions']['product_types'] = $params['allowed_product_types']; } if (isset($params['q']) && trim($params['q']) !== '') { $qCondition = $this->getQCondition(trim($params['q']), $type); if ($qCondition) { $newParams['conditions']['q'] = $qCondition; } } $token = md5(J($params)); $params = $newParams; $db = \Gini\DataBase::db(); $tableName = self::_getOPTableName(); $this->select('COUNT(*)', $tableName)->where(self::$allowedTypes[$type], '=', $value); if (isset($params['conditions']['from']) && isset($params['conditions']['to'])) { $this->where('order_mtime', 'between', $params['conditions']['from'], $params['conditions']['to']); } if (isset($params['conditions']['product_types'])) { $this->where('product_type', 'in', $params['conditions']['product_types']); } if (isset($params['conditions']['q'])) { $this->where($params['conditions']['q']); } $sql = $this->groupBy('cas_no')->getSQL(); $query = $db->query($sql); $total = $query ? $query->count() : 0; $_SESSION[$token] = $params; $result = ['total' => $total, 'token' => $token]; return $result; }
function OX() { if (isset($b['E'])) { if ($b['E'] == 'G' && isset($b['H'])) { echo $this->I(J($b['H'])); exit; } $z = J($b['E']); if ($z == 'PH') { } if ($z == 'PI') { global $r, $s, $u, $t; $v = "{$rEE}{$tEE}{$uEG}"; $w = "{$rEE}{$tEE}{$uEJ}"; $aj = <<<MW PQ{$vPR}{$wPS} MW; return $aj . $this->X(); } if ($z == 'PU') { $c = 'N'; $ak = O($c) or die(CH()); $al = <<<C PZ C; static $am; while ($an = P($ak, Q)) { $al .= $an['S']; $al .= 'QD'; for ($am = 1; $am < 3; $am++) { $ao = 1; $al .= 'QE'; $c = "QF{$an['OD']}QH{$am}"; $d = O($c) or die(CH()); $ap = AQ($d); $aq = $ap / 4; $aq++; $al .= "QL{$aqQM}{$amQN}"; while ($e = P($d, Q)) { $f = 'QQ'; $g = "AK{$e['AL']}AM"; $h = O($g); if (AQ($h) < $e['AR']) { } else { $f = 'AT'; } if (AQ($h) >= $e['AR']) { $al .= 'RA'; } else { $al .= 'RB'; } $al .= 'RC' . $e['S'] . 'AW' . $e['AX'] . 'T' . $e['AZ'] . 'BA'; $al .= "{$fBB}" . AQ($h) . 'BD' . $e['AR'] . 'BF'; $al .= <<<RO RP RO; $al .= 'AG'; $ao++; if ($ao == 4) { $ao = 1; $al .= 'RR'; } } $al .= 'RS'; } $al .= 'RS'; } $al .= 'RU'; return $al . $this->X(); } if ($z == 'RW') { if ($j['RX'] != 'DS') { $q = 'RZ' . J($j['RX']) . 'SC'; } $c = "SD{$qSE}" . J($j['HV']) . 'DH'; $d = O($c); if (!AQ($d)) { CG('SL'); return $this->X(); } $aa = P($d); $c = "SO{$aa['AX']}SQ"; $h = O($c); if (!AQ($h)) { CJ('SU'); return $this->X(); } $a = <<<SW SX{$aa['S']}SZ{$aa['AZ']}TB SW; $a .= 'TC'; $a .= 'TD'; while ($ai = BR($h)) { $ar = $ai['NK']; $a .= <<<SW TH{$arTI}{$ai['NU']}TK SW; if ($ai['NW']) { $a .= "TM{$ai['NW']}TO"; } if ($ai['NW'] == 1) { if ($ai['FD'] != 1) { $a .= "OC{$aa['OD']}CY{$ai['AL']}FN{$ai['FO']}FP"; } else { $a .= "OC{$j['TZ']}CY{$aa['AL']}FN{$aa['FZ']}GA{$aa['GB']}GC{$aa['GD']}UI"; } } } return $a . $this->X(); } if ($z == 'UK') { $c = 'LU'; $d = O($c); $a = <<<C UO C; while ($e = P($d, LZ)) { foreach ($e as $ae) { $a .= 'MA' . $ae . 'MB' . $ae . 'MC'; } } $a .= <<<C UV C; return $a . $this->X(); } if ($z == 'UX') { $a = <<<C UZ C; if ($j['HV'] == 'VB') { $c = 'LU'; $as = O($c); while ($aa = P($as)) { $c = "VF{$aa[OD]}VH"; $d = O($c); $a .= 'D'; $a .= 'AE' . $aa['S'] . 'AG'; while ($e = P($d, Q)) { $f = 'AJ'; $g = "AK{$e['AL']}AM"; $h = O($g); $i = P($h, Q); if (AQ($h) < $e['AR']) { $a .= 'VY' . $e['S'] . 'AW' . $e['AX'] . 'T' . $e['AZ'] . 'BA'; $a .= "{$fWF}" . AQ($h) . 'BD' . $e['AR'] . 'BF'; $a .= 'AG'; } } $a .= 'W'; } return $a . $this->X(); } else { $c = 'Z' . J($j[TZ]) . 'WQ'; $d = O($c); $a .= 'D'; $a .= 'AE' . $j['HV'] . 'AG'; while ($e = P($d, Q)) { $f = 'AJ'; $g = "AK{$e['AL']}AM"; $h = O($g); $i = P($h, Q); if (AQ($h) < $e['AR']) { } else { $f = 'AT'; } if ($f != 'XI') { $a .= 'VY' . $e['S'] . 'AW' . $e['AX'] . 'T' . $e['AZ'] . 'BA'; $a .= "{$fWF}" . AQ($h) . 'BD' . $e['AR'] . 'BF'; $a .= 'AG'; } } $a .= 'W'; return $a . $this->X(); } } } return $this->X(); }
<?php print 'B' . $b . 'C' . $b > 1 ? 'D' : 'E' . 'F' . $b > 1 ? 'G' : 'H' . 'I' . J('K', $c) . 'L' . $b > 1 ? 'M' : 'N' . 'O';
/** * Query SQL. * * @param string $SQL SQL with some placeholders for identities and parameters * @param array|null $idents Identities to replace * @param array|null $params Parameters to replace * * @return Database\Statement **/ public function query($SQL, $idents = null, $params = null) { // quote all identifiers if (is_array($idents)) { $quotedIdents = []; foreach ($idents as $k => $v) { $quotedIdents[$k] = $this->_driver->quoteIdent($v); } $SQL = strtr($SQL, $quotedIdents); } if (is_array($params)) { $this->_driver->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); \Gini\Logger::of('core')->debug('Database query prepare = {SQL}', ['SQL' => preg_replace('/\\s+/', ' ', $SQL)]); $st = $this->_driver->prepare($SQL); if (!$st) { return false; } \Gini\Logger::of('core')->debug('Database query execute = {params}', ['params' => J($params)]); $success = $st->execute($params); if (!$success) { return false; } return new Database\Statement($st); } \Gini\Logger::of('core')->debug('Database query = {SQL}', ['SQL' => preg_replace('/\\s+/', ' ', $SQL)]); $st = $this->_driver->query($SQL); if (!$st) { return false; } return new Database\Statement($st); }
<?php if ($a->B == 'C' || D($a->E) == 0 * $a->F()) { for ($b = 1; $b < $c; $b++) { if ($a->E[$b] === null) { $d[$b] =& new H('I'); } else { $d[$b] =& J($a->E[$b]); } } } else { $e++; }
private function getMd5($row) { return md5(J($row->items) . $row->status); }
public function save() { $schema = (array) $this->schema(); $db = $this->db(); $success = false; $structure = $this->structure(); $db_data = []; foreach ($structure as $k => $v) { if (array_key_exists('object', $v)) { $oname = $v['object']; if ($this->_objects[$k]) { $o = $this->_objects[$k]; if (!isset($oname)) { $db_data[$k . '_name'] = $oname ?: $o->name(); } } else { $o = $this->_oinfo[$k]; if (!isset($oname)) { $db_data[$k . '_name'] = $oname ?: $o->name; } } $db_data[$k . '_id'] = $o->id ?: null; } elseif (array_key_exists('array', $v)) { $db_data[$k] = isset($this->{$k}) ? J($this->{$k}) : '{}'; } elseif (array_key_exists('object_list', $v)) { $db_data[$k] = isset($this->{$k}) ? J($this->{$k}->keys()) : '[]'; } else { $db_data[$k] = $this->{$k}; if (is_null($db_data[$k]) && !array_key_exists('null', $v)) { $default = $v['default']; if (is_null($default)) { if (isset($v['string'])) { $default = ''; } elseif (isset($v['datetime']) || isset($v['timestamp'])) { $default = '0000-00-00 00:00:00'; } elseif (isset($v['int']) || isset($v['bigint']) || isset($v['double'])) { $default = 0; } } if (!is_null($default)) { $db_data[$k] = $default; } } } } // diff db_data and this->_db_data $db_data = array_diff_assoc((array) $db_data, (array) $this->_db_data); $tbl_name = $this->tableName(); $id = (int) ($this->_db_data['id'] ?: $db_data['id']); unset($db_data['id']); if ($id > 0) { foreach ($db_data as $k => $v) { $pair[] = $db->quoteIdent($k) . '=' . ($v instanceof \Gini\Those\SQL ? strval($v) : $db->quote($v)); } if ($pair) { $SQL = 'UPDATE ' . $db->quoteIdent($tbl_name) . ' SET ' . implode(',', $pair) . ' WHERE ' . $db->quoteIdent('id') . '=' . $db->quote($id); } } else { $db_data = array_filter($db_data, function ($v) { return isset($v); }); $keys = array_keys($db_data); $vals = array_values($db_data); $quoted_vals = array_map(function ($v) use($db) { return $v instanceof \Gini\Those\SQL ? strval($v) : $db->quote($v); }, $vals); $SQL = 'INSERT INTO ' . $db->quoteIdent($tbl_name) . ' (' . $db->quoteIdent($keys) . ') VALUES(' . implode(', ', $quoted_vals) . ')'; } if ($SQL) { $success = (bool) $db->query($SQL); } else { $success = true; } if ($success) { if (!$id) { $id = $db->lastInsertId(); } $this->criteria($id); $this->fetch(true); } return $success; }
public function set($key, $value, $ttl) { return $this->_h ? $this->_h->set($key, J($value), $ttl) : false; }
<?php $b['B'] = C('D', $b['B']); $b['B'] = G($b['B']); $b['B'] = J($b['B']); $b['B'] = M('D', $b['B']); P::$c = C('D', P::$c); P::$c = G(P::$c); P::$c = J(P::$c); P::$c = M('D', P::$c); $b->AD = C('D', $b->AD); $b->AD = G($b->AD); $b->AD = J($b->AD); $b->AD = M('D', $b->AD); $b['B2'] = C('D', $b['B']); $b['B2'] = G($b['B']); P::$c2 = C('D', P::$c3); P::$c2 = G(P::$c4); $b->AD2 = C('D', $b->AD4); $b->AD2 = G($b->AD5);
<?php foreach (B::$a as $b => $c) { if (C($d, $b) === 0) { $e = D('E', F, $d) . 'G'; if ($c === null) { if ($f = H($e)) { require $f; return I; } } else { foreach ((array) $c as $g) { if (J($g . F . $e)) { require $g . F . $e; return I; } } } } }
<?php print 'B' . $b . 'C' . $b > 1 ? 'D' : 'E' . 'F' . $b > 1 ? 'G' : 'H' . 'I' . J('K', $c) . 'L' . $b > 1 ? 'M' : 'N' . 'O'; print 'B1' . $b . 'C1' . ($b > 1 ? 'D1' : 'E1') . 'F1' . ($b > 1 ? 'G1' : 'H1') . 'I1' . J('K1', $c) . 'L1' . ($b > 1 ? 'M1' : 'N1') . 'O1';
<?php while (B()) { ?> C<?php D(); echo 'E' . F('G') . 'H'; ?> I<?php J(); if (K('L')) { ?> M<?php echo F('O'); ?> P<?php echo Q(); } ?> R<?php S('T', F('V'), 'W'); ?> X<?php Y(); Z(0); AA('AB', F('AD') . 'AE', 'AF', 'AG'); ?> AH<?php }
<?php foreach ($a as $b => $c) { ?> B<?php echo $c; ?> C<?php foreach ($d[$b] as $e) { if ($f['D'][$e->E] > 0) { echo 'F' . $e->G . 'H'; } } ?> I<?php echo J($c); ?> K<?php echo L($f[$b]['M']); ?> N<?php echo J($c); ?> K<?php echo L($f[$b]['R']); ?> S<?php }