예제 #1
0
 protected static function load_classes()
 {
     $store_key = array(__DIR__, '__autoload');
     if (Store::has($store_key)) {
         $classes = Store::get($store_key);
     } else {
         $classes = array();
         $modules = array();
         $dir = path('libs');
         $itr = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
         $pattern = '/^' . preg_quote($dir, '/') . '\\/(.+?)\\.php$/';
         foreach ($itr as $elem) {
             if ($elem->isFile() && preg_match($pattern, $elem->getPathname(), $match)) {
                 $class_name = $elem->getBasename('.php');
                 if ($class_name == basename($elem->getPath())) {
                     $modules[$class_name] = str_replace('/', '.', substr($elem->getPath(), strlen($dir) + 1));
                 } else {
                     if ($class_name !== __CLASS__) {
                         $classes[$class_name] = str_replace('/', '.', $match[1]);
                     }
                 }
             }
         }
         foreach ($modules as $module_name => $module_path) {
             foreach ($classes as $class_name => $class_path) {
                 if (strpos($class_path, $module_path) === 0) {
                     unset($classes[$class_name]);
                 }
             }
         }
         $classes = $modules + $classes;
         Store::set($store_key, $classes);
     }
     self::$classes = $classes;
 }
예제 #2
0
파일: customer.php 프로젝트: camigreen/ttop
 public function set($resource, $value)
 {
     if (is_array($value)) {
         $value = $this->array2object($value);
     }
     parent::set($resource, $value);
     return $this;
 }
예제 #3
0
 /** @dataProvider dataMerge */
 public function testMerge($mode, $newBarValue)
 {
     $store = new Store(':');
     $store->set('foo:bar', 'baz');
     $mergeData = ['foo' => ['bar' => 'quux', 'fizz' => 'buzz']];
     $store->merge($mergeData, $mode);
     self::assertEquals($newBarValue, $store->get('foo:bar'));
     self::assertEquals('buzz', $store->get('foo:fizz'));
 }
예제 #4
0
 public static function unread_count(OpenpearMaintainer $maintainer)
 {
     $key = array('openpear_message_unread', $maintainer->id());
     if (Store::has($key)) {
         return Store::get($key);
     }
     $unread_messages_count = C(__CLASS__)->find_count(Q::eq('maintainer_to_id', $maintainer->id()), Q::eq('unread', true));
     Store::set($key, $unread_messages_count);
     return $unread_messages_count;
 }
예제 #5
0
 /**
  * linktitleHandler
  */
 public static function linktitleHandler($url)
 {
     if (module_const('is_cache', false)) {
         $store_key = array('__hatenaformat_linktitlehandler', $url);
         if (Store::has($store_key)) {
             return Store::get($store_key);
         }
     }
     if (Tag::setof($title, Http::read($url), 'title')) {
         $url = $title->value();
         if (module_const('is_cache', false)) {
             Store::set($store_key, $url, self::CACHE_EXPIRE);
         }
     }
     return $url;
 }
예제 #6
0
 /**
  * チェンジセットを取得する
  * @param int $revision
  * @param bool $cache
  * @return OpenpearChangeset
  **/
 public static function get_changeset($revision, $cache = true)
 {
     $cache_key = self::cache_key($revision);
     if ($cache) {
         if (isset(self::$cached_changesets[$revision])) {
             return self::$cached_changesets[$revision];
         } else {
             if (Store::has($cache_key)) {
                 $changeset = Store::get($cache_key);
                 self::$cached_changesets[$revision] = $changeset;
                 return $changeset;
             }
         }
     }
     $changeset = C(__CLASS__)->find_get(Q::eq('revision', $revision));
     Store::set($cache_key, $changeset);
     return $changeset;
 }
예제 #7
0
 public static function packages(OpenpearMaintainer $maintainer)
 {
     $store_key = array('charges_maintainer', $maintainer->id());
     if (Store::has($store_key, self::CACHE_TIMEOUT)) {
         $packages = Store::get($store_key);
     } else {
         try {
             $packages = array();
             $charges = C(OpenpearCharge)->find_all(Q::eq('maintainer_id', $maintainer->id()));
             foreach ($charges as $charge) {
                 $packages[] = $charge->package();
             }
         } catch (Exception $e) {
             $packages = array();
         }
         Store::set($store_key, $packages, self::CACHE_TIMEOUT);
     }
     return $packages;
 }
예제 #8
0
 /**
  * xml定義からhandlerを処理する
  * @param string $file アプリケーションXMLのファイルパス
  */
 public static final function load($file = null)
 {
     if (!isset($file)) {
         $file = App::mode() . App::called_filename();
     }
     if (!self::$is_app_cache || !Store::has($file)) {
         $parse_app = self::parse_app($file, false);
         if (self::$is_app_cache) {
             Store::set($file, $parse_app);
         }
     }
     if (self::$is_app_cache) {
         $parse_app = Store::get($file);
     }
     if (empty($parse_app['apps'])) {
         throw new RuntimeException('undef app');
     }
     $app_result = null;
     $in_app = $match_handle = false;
     $app_index = 0;
     try {
         foreach ($parse_app['apps'] as $app) {
             switch ($app['type']) {
                 case 'handle':
                     $self = new self('_inc_session_=false');
                     foreach ($app['modules'] as $module) {
                         $self->add_module(self::import_instance($module));
                     }
                     if ($self->has_module('flow_handle_begin')) {
                         $self->call_module('flow_handle_begin', $self);
                     }
                     try {
                         if ($self->handler($app['maps'], $app_index++)->is_pattern()) {
                             $self->cp(self::execute_var($app['vars']));
                             $src = $self->read();
                             if ($self->has_module('flow_handle_end')) {
                                 $self->call_module('flow_handle_end', $src, $self);
                             }
                             print $src;
                             $in_app = true;
                             $match_handle = true;
                             if (!$parse_app["handler_multiple"]) {
                                 exit;
                             }
                         }
                     } catch (Exception $e) {
                         Log::warn($e);
                         if (isset($app['on_error']['status'])) {
                             Http::status_header((int) $app['on_error']['status']);
                         }
                         if (isset($app['on_error']['redirect'])) {
                             $this->save_exception($e);
                             $this->redirect($app['on_error']['redirect']);
                         } else {
                             if (isset($app['on_error']['template'])) {
                                 if (!$e instanceof Exceptions) {
                                     Exceptions::add($e);
                                 }
                                 $self->output($app['on_error']['template']);
                             } else {
                                 throw $e;
                             }
                         }
                     }
                     break;
                 case 'invoke':
                     $class_name = isset($app['class']) ? Lib::import($app['class']) : get_class($app_result);
                     $ref_class = new ReflectionClass($class_name);
                     foreach ($app['methods'] as $method) {
                         $invoke_class = $ref_class->getMethod($method['method'])->isStatic() ? $class_name : (isset($app['class']) ? new $class_name() : $app_result);
                         $args = array();
                         foreach ($method['args'] as $arg) {
                             if ($arg['type'] === 'result') {
                                 $args[] =& $app_result;
                             } else {
                                 $args[] = $arg['value'];
                             }
                         }
                         if (is_object($invoke_class)) {
                             foreach ($app['modules'] as $module) {
                                 $invoke_class->add_module(self::import_instance($module));
                             }
                         }
                         $app_result = call_user_func_array(array($invoke_class, $method['method']), $args);
                         $in_app = true;
                     }
                     break;
             }
         }
         if (!$match_handle) {
             Log::debug("nomatch");
             if ($parse_app["nomatch_redirect"] !== null) {
                 Http::redirect(App::url($parse_app["nomatch_redirect"]));
             }
             if ($parse_app["nomatch_template"] !== null) {
                 Http::status_header(404);
                 $self = new self();
                 $self->output($parse_app["nomatch_template"]);
             }
         }
         if (!$in_app) {
             Http::status_header(404);
         }
     } catch (Exception $e) {
         if (!$e instanceof Exceptions) {
             Exceptions::add($e);
         }
     }
     exit;
 }
예제 #9
0
 /**
  * メンテナ情報を取得する
  * @param int $id
  * @param bool $cache
  * @return OpenpearMaintainar
  **/
 public static function get_maintainer($id, $cache = true)
 {
     $cache_key = self::cache_key($id);
     if ($cache) {
         Log::debug('cache on');
         if (isset(self::$cached_maintainers[$id])) {
             return self::$cached_maintainers[$id];
         } else {
             if (Store::has($cache_key)) {
                 $maintainer = Store::get($cache_key);
                 self::$cached_maintainers[$id] = $maintainer;
                 return $maintainer;
             }
         }
     }
     $maintainer = C(__CLASS__)->find_get(Q::eq('id', $id));
     Store::set($cache_key, $maintainer, OpenpearConfig::object_cache_timeout(3600));
     return $maintainer;
 }
예제 #10
0
 /**
  * 存储uid的网关地址
  * @param int $uid
  */
 public static function storeUid($uid)
 {
     $address = array('local_ip' => Context::$local_ip, 'local_port' => Context::$local_port, 'socket_id' => Context::$socket_id);
     Store::set($uid, $address);
 }
예제 #11
0
         $product_amount = $earned_currency_order['product_amount'];
         // If the order is settled, the developer will receive this
         // amount of credits as payment.
         $credits_amount = $earned_currency_order['credits_amount'];
         // We're giving out our virtual currency for all offers
         $product_name = $GLOBALS['catalog']['1a']['item_name'];
     } else {
         $request_item = $order_details['items'][0];
         $sku = $GLOBALS['catalog'][$request_item['item_id']];
         $product_amount = $sku['item_quantity'];
         $product_name = $sku['item_name'];
         $credits_amount = $request_item['price'] * $GLOBALS['payrate'];
     }
     $oldBalance = Store::get(Store::META, $order_details['receiver'], $product_name);
     Store::set(Store::META, $order_details['receiver'], $product_name, $oldBalance + $product_amount);
     Store::set(Store::META, 'ourCut', 'creds', Store::get(Store::META, 'ourCut', 'creds') + $credits_amount);
     $next_order_status = 'settled';
     // Construct response.
     $response = array('content' => array('status' => $next_order_status, 'order_id' => $order_details['order_id']), 'method' => $request_type);
     // Response must be JSON encoded.
     $response = json_encode($response);
 } else {
     if ($current_order_status == 'disputed') {
         // 1. Track disputed item orders.
         // 2. Investigate user's dispute and resolve by settling or refunding the order.
         // 3. Update the order status asychronously using Graph API.
     } else {
         if ($current_order_status == 'refunded') {
             // Track refunded item orders initiated by Facebook. No need to respond.
         } else {
             // Track other order statuses.
예제 #12
0
 /**
  * ?????
  * @const string $svn_url リポジトリのURL
  */
 public function source_browse($package_name, $path = '')
 {
     if (empty($path)) {
         $this->redirect_method('source_browse', $package_name, '/trunk');
     }
     // TODO 仕様の確認
     // TODO SVNとの連携
     $package = C(OpenpearPackage)->find_get(Q::eq('name', $package_name));
     $path = rtrim(ltrim($path, ' /.'), '/');
     $local_root = File::absolute(OpenpearConfig::svn_root(), $package->name());
     $repo_path = File::absolute($local_root, $path);
     $info = Subversion::cmd('info', array($repo_path));
     if ($info['kind'] === 'dir') {
         $this->vars('tree', self::format_tree(Subversion::cmd('list', array($info['url']), array('revision' => $this->in_vars('rev', 'HEAD')))));
     } else {
         if ($info['kind'] === 'file') {
             $this->put_block('package/source_viewfile.html');
             $p = explode('.', $info['path']);
             $ext = array_pop($p);
             if (in_array($ext, $this->allowed_ext)) {
                 $source = Subversion::cmd('cat', array($info['url']), array('revision' => $this->in_vars('rev', 'HEAD')));
                 $this->vars('code', $source);
                 try {
                     $cache_key = array('syntax_highlight', md5($source));
                     if (Store::has($cache_key)) {
                         $this->vars('code', Store::get($cache_key));
                     } else {
                         include_once 'geshi/geshi.php';
                         $geshi = new Geshi($source, $ext);
                         $code = $geshi->parse_code();
                         Store::set($cache_key, $code);
                         $this->vars('code', $code);
                     }
                     $this->vars('geshi', true);
                 } catch (Exception $e) {
                     Log::debug($e);
                     $this->vars('geshi', false);
                 }
             }
         } else {
             $this->redirect_by_map('package', $package_name);
         }
     }
     $this->vars('path', $path);
     $this->vars('info', self::format_info($info));
     $this->vars('package', $package);
     $this->vars('real_url', File::absolute(OpenpearConfig::svn_url(), implode('/', array($package->name(), $path))));
     $this->vars('externals', Subversion::cmd('propget', array('svn:externals', $info['url'])));
     $this->add_vars_other_tree($package_name);
 }
예제 #13
0
 /**
  * 存储全局的通信地址
  * @param string $address
  * @todo 用锁机制等保证数据完整性
  */
 protected function registerAddress($address)
 {
     \Man\Core\Lib\Mutex::get();
     $key = 'GLOBAL_GATEWAY_ADDRESS';
     $addresses_list = Store::get($key);
     if (empty($addresses_list)) {
         $addresses_list = array();
     }
     $addresses_list[$address] = $address;
     Store::set($key, $addresses_list);
     \Man\Core\Lib\Mutex::release();
 }
예제 #14
0
function respondToInvite($user, $params)
{
    $matchID = getParam('m');
    $m = Store::get(Store::MATCH, $matchID);
    if (!$m) {
        // catch this
        trigger_error("ERROR: r Invalid mid ({$matchID}) user {$user}", E_USER_ERROR);
    }
    $participants = $m->getParticipants();
    if ($participants[$user]) {
        trigger_error("ERROR: r user {$user} already played {$matchID}", E_USER_ERROR);
    }
    $m->updateParticipants($user, array());
    Store::set(Store::MATCH, $matchID, $m);
    $spec = array('matchID' => $m->getMatchID(), 'timeLimit' => $m->getTimeLimit(), 'letterSet' => $m->getLetterSet()->getLetters(), 'details' => $m->getLetterSet()->getDetails(), 'rules' => $m->getRules());
    restReturn($spec);
}
예제 #15
0
 /**
 * Override modResourceUpdateProcessor::beforeSave to provide custom functionality, saving settings for the container
 * to a custom field in the DB.
 *
 * The Post data comes thru flattened (boo)
 *
        [specs_4] => on
        [specs_12] => on
        [taxonomies_3] => on
        [taxonomies_4] => on
        [variations_1] => Option Only
        [variations_2] => Variant
        [variations_3]
 * On the flip side, it should be available in JS via this path: MODx.activePage.config.record.properties.moxycart
 *
 * {@inheritDoc}
 * @return boolean
 */
 public function beforeSave()
 {
     $raw = $this->getProperties();
     // <-- this will have raw values
     $properties = $this->object->getProperties('moxycart');
     //<-- we need to update these values
     $this->object->set('class_key', 'Store');
     //$this->modx->log(1,'beforeSave raw values: '.print_r($raw,true));
     //$this->modx->log(1,'existing values: '.print_r($properties,true));
     //$this->modx->log(1,'beforeSave raw POST values: '.print_r($_POST,true));
     $properties['product_type'] = $this->modx->getOption('product_type', $raw);
     $properties['product_template'] = $this->modx->getOption('product_template', $raw);
     $properties['track_inventory'] = $this->modx->getOption('track_inventory', $raw) == 'Yes' ? 1 : 0;
     $properties['sort_order'] = $this->modx->getOption('sort_order', $raw);
     $properties['qty_alert'] = $this->modx->getOption('qty_alert', $raw);
     // Fresh start...
     $properties['specs'] = array();
     $properties['taxonomies'] = array();
     $properties['variations'] = array();
     foreach ($raw as $k => $v) {
         $len = strlen($k);
         if ($this->starts_with($k, 'specs')) {
             $properties['specs'][substr($k, 6 - $len)] = true;
         }
         if ($this->starts_with($k, 'taxonomies')) {
             $properties['taxonomies'][substr($k, 11 - $len)] = true;
         }
         if ($this->starts_with($k, 'variations')) {
             $properties['variations'][substr($k, 11 - $len)] = $v;
         }
     }
     $this->object->setProperties($properties, 'moxycart');
     return parent::beforeSave();
 }
예제 #16
0
 /**
  * ファイルから生成する
  * @param string $filename テンプレートファイルパス
  * @param string $template_name 対象となるテンプレート名
  * @return string
  */
 public function read($filename = null, $template_name = null)
 {
     if (!empty($filename)) {
         $this->filename($filename);
     }
     $this->selected_template = $template_name;
     $cfilename = $this->filename() . $this->selected_template;
     if (!self::$is_cache || !Store::has($cfilename, true)) {
         if (strpos($filename, '://') === false) {
             $src = $this->parse(File::read($this->filename()));
         } else {
             if (empty($this->media_url)) {
                 $this->media_url($this->filename());
             }
             $src = $this->parse(Http::read($this->filename()));
         }
         if (self::$is_cache) {
             Store::set($cfilename, $src);
         }
     } else {
         $src = Store::get($cfilename);
     }
     $src = $this->html_reform($this->exec($src));
     $this->call_module('after_read_template', $src, $this);
     return $this->replace_ptag($src);
 }