Ejemplo n.º 1
2
 /**
  * Inject
  *
  * @return void
  */
 public function onInject()
 {
     parent::onInject();
     //$this->_session = BEAR::dependency('BEAR_Session');
     $this->_resource = BEAR::dependency('BEAR_Resource');
 }
Ejemplo n.º 2
0
 /**
  * UAインジェクト
  *
  * 携帯3キャリア/iPhone/iPad/Androidの判定を行います。
  * BEAR_Agentの$config['ua_inject']でこのクラスが指定されています。
  *
  * @param BEAR_Main &$object BEAR_Agentオブジェクト
  * @param array     $config 設定
  *
  * @return void
  * @see http://code.google.com/p/bear-project/wiki/agent
  */
 public static function inject($object, $config)
 {
     if (!isset($config['user_agent'])) {
         $object->setService('_ua', BEAR_Agent::UA_DEFAULT);
         return;
     }
     $agentMobile = BEAR::dependency('BEAR_Agent_Mobile', array('user_agent' => $config['user_agent']));
     if ($agentMobile->isNonMobile()) {
         if (strpos($config['user_agent'], 'iPhone') !== false) {
             // iPhoneの場合
             $ua = BEAR_Agent::UA_IPHONE;
         } else {
             if (strpos($config['user_agent'], 'iPad') !== false) {
                 // iPadの場合
                 $ua = BEAR_Agent::UA_IPAD;
             } else {
                 if (strpos($config['user_agent'], 'Android') !== false) {
                     // Androidの場合
                     $ua = BEAR_Agent::UA_ANDROID;
                 } else {
                     $ua = BEAR_Agent::UA_DEFAULT;
                 }
             }
         }
     } else {
         $ua = ucwords(strtolower($agentMobile->getCarrierLongName()));
     }
     $object->setService('_ua', $ua);
 }
Ejemplo n.º 3
0
/**
 * エージェントブロック関数
 *
 * <pre>
 * エージェントによって表示/非表示を制御します。
 * エージェントの指定は大文字でも小文字問いません。
 *
 * Example
 * </pre>
 *
 * <code>
 * {agent in='docomo,au'}ドコモとAUだけ表示{/agent}
 * {agent out='softbank'}SBのみ非表示{/agent}
 * {agent in='iphone' func='upper_case'}iPhoneのみ大文字で{/agent}
 * </code>
 * <pre>
 *
 * $params
 *
 *  'in'   mixed  カンマ区切りで含まれていたら表示。
 *  'out'  string カンマ区切りで含まれていなかったら表示
 *  'func' string ユーザー関数
 * </pre>
 *
 * @category   BEAR
 * @package    BEAR_Smarty
 * @subpackage Plugin
 * @author     Akihito Koriyama <*****@*****.**>
 * @copyright  2008-2011 Akihito Koriyama  All rights reserved.
 * @license    http://opensource.org/licenses/bsd-license.php BSD
 * @version    SVN: Release: @package_version@ $Id:$
 * @link       http://www.bear-project.net/
 *
 * @param string $params  パラメーター
 * @param string $content HTML
 * @param Smarty &$smarty &Smarty object
 * @param bool   &$repeat &$repeat 呼び出し回数
 *
 * @return string
 */
function smarty_block_agent($params, $content, &$smarty, &$repeat)
{
    $ua = strtolower(BEAR::dependency('BEAR_Agent')->getUa());
    //開始タグ
    if (is_null($content)) {
        $valid = false;
        if (array_key_exists('in', $params)) {
            $in = explode(',', $params['in']);
            if (in_array($ua, $in)) {
                $valid = true;
            }
        }
        if (!$valid) {
            if (array_key_exists('out', $params)) {
                $out = explode(',', $params['out']);
                if (!in_array($ua, $out)) {
                    $valid = true;
                }
            }
        }
        if (!$valid) {
            $repeat = false;
        }
    } else {
        if (array_key_exists('func', $params)) {
            assert(function_exists($params['func']));
            return call_user_func($params['func'], $content);
        } else {
            return $content;
        }
    }
    return '';
}
Ejemplo n.º 4
0
/**
 * emoji
 *
 * <pre>
 * スタティックな絵文字を表示します。テンプレート生成時のみ動作します。
 * </pre>
 *
 * @category   BEAR
 * @package    BEAR_Smarty
 * @subpackage Plugin
 * @author     Akihito Koriyama <*****@*****.**>
 * @copyright  2008-2011 Akihito Koriyama  All rights reserved.
 * @license    http://opensource.org/licenses/bsd-license.php BSD
 * @version    SVN: Release: @package_version@ $Id:$
 * @link       http://www.bear-project.net/
 *
 * @param string $tagArg
 * @param Smarty &$smarty Smarty object
 *
 * @return string
 */
function smarty_compiler_emoji($tagArg, &$smarty)
{
    $emoji = BEAR::dependency('BEAR_Emoji')->getAgentEmoji($tagArg);
    // SBの絵文字のエラーを避けるためecho文を使わない
    return '?>' . "{$emoji}" . '<?php ';
    //    return 'echo "' . "{$emoji}" . '";';
}
Ejemplo n.º 5
0
 /**
  * Constructor取得
  *
  * @param array $config
  *
  * @see http://jp.php.net/manual/ja/function.memcache-addserver.php
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     $options = array('cacheDir' => _BEAR_APP_HOME . '/tmp/cache_lite/', 'automaticSerialization' => true, 'automaticCleaningFactor' => 100);
     // _adapterをCache_Liteに
     $this->_adapter = BEAR::dependency('Cache_Lite', $options);
 }
Ejemplo n.º 6
0
 /**
  * UAインジェクト
  *
  * @param BEAR_Main &$object BEAR_Mainオブジェクト
  * @param array     $config 設定
  *
  * @return void
  */
 public static function inject($object, $config)
 {
     $userAgent = isset($config['http_user_agent']) ? $config['http_user_agent'] : (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
     $agent = BEAR::dependency('BEAR_Agent', array('user_agent' => $userAgent));
     $object->setService('_agent', $agent);
     $object->setConfig('ua', $agent->getUa());
     $object->setConfig('enable_ua_sniffing', true);
     //エージェント依存サブミット(絵文字、コード)
     $agent->adapter->submit();
 }
 public function test_isTokenPoeValidFailure()
 {
     $val = '03c88eb462460abeeff7' . '6ca881e559ef98901975';
     $_POST['_token'] = $val;
     $token = new BEAR_Form_Token(array());
     $token->onInject();
     BEAR::dependency('BEAR_Session')->set(BEAR_Form_Token::SESSION_POE, array($val));
     $isValid = $token->isTokenPoeValid();
     $this->assertFalse($isValid);
 }
Ejemplo n.º 8
0
 /**
  * Resource request
  *
  * @return BEAR_Ro
  *
  * @see BEAR_Resource_Request::request()
  */
 public function request()
 {
     $query = http_build_query($this->_config['values']);
     if ($query) {
         $query = '?' . $query;
     }
     $resurceQuery = $this->_config['method'] . ' ' . $this->_config['uri'] . (string) $query;
     BEAR::dependency('BEAR_Log')->log('resource', $resurceQuery);
     $result = parent::request();
     return $result;
 }
Ejemplo n.º 9
0
 /**
  * @see BEAR_Base::onInject()
  */
 public function onInject()
 {
     $this->_tokenStrage = BEAR::dependency('BEAR_Session');
     if (isset($_POST['_token'])) {
         $token = $_POST['_token'];
     } elseif (isset($_GET['_token'])) {
         $token = $_POST['_token'];
     } else {
         $token = '';
     }
     $this->_submitToken = $token;
 }
Ejemplo n.º 10
0
 /**
  * セキュリティチェック
  *
  * AJAXリクエストが不正なものでないかチェックします。
  *
  * @return void
  * @throws BEAR_Page_Exception
  */
 public function checkSecurity()
 {
     if (!$this->isAjaxRequest()) {
         return;
     }
     $this->_session = BEAR::dependency('BEAR_Session');
     $this->_session->start();
     // AJAXセキュリティチェック
     $isOk = $this->_isValidAjaxDoubleSubmitionCookie();
     if ($isOk === false) {
         $info = array('verify' => $this->_header->getRequestHeader('X_BEAR_AJAX_ARGS'), 'session_id' => session_id(), '$_SERVER' => $_SERVER);
         throw $this->_exception('Ajax Validation NG or This is not AJAX', compact('info'));
     }
 }
Ejemplo n.º 11
0
 /**
  * Constructor
  *
  * @param array $config
  *
  * @see http://jp.php.net/manual/ja/function.Apc-addserver.php
  * @throws BEAR_Cache_Exception
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     $app = BEAR::get('app');
     $this->_config['info'] = $config['info'];
     if (!extension_loaded('apc') || !ini_get('apc.enabled') || !function_exists('apc_sma_info')) {
         throw new BEAR_Cache_Exception('APC extention is not loaded');
     } else {
         if ($this->_config['debug']) {
             $apcSmaInfo = apc_sma_info();
             BEAR::dependency('BEAR_Log')->log('APC', $apcSmaInfo);
         }
     }
 }
Ejemplo n.º 12
0
 /**
  * Inject
  *
  * @param BEAR_Agent &$object BEAR_Agentオブジェクト
  * @param array      $config
  *
  * @return void
  */
 public static function inject($object, $config)
 {
     $agent = BEAR::dependency('BEAR_Agent');
     $ua = $agent->getUa();
     $config = $agent->adapter->getConfig();
     $role = $config['role'];
     foreach ($role as $agent) {
         $method = 'onInject' . $agent;
         if (method_exists($object, $method)) {
             $object->{$method}();
             return;
         }
     }
     $object->onInject();
 }
Ejemplo n.º 13
0
 /**
  * Form
  *
  * @return void
  */
 public function build()
 {
     $form = BEAR::dependency('BEAR_Form', $this->_form);
     $form->setDefaults(array('name' => 'Kuma', 'email' => '*****@*****.**'));
     //  フォームヘッダー
     $form->addElement('header', 'main', '入力(確認)してください');
     //  フォームインプットフィールド
     $form->addElement('text', 'name', '名前', 'size=30 maxlength=30');
     $form->addElement('text', 'email', 'メールアドレス', 'size=30 maxlength=30');
     $form->addElement('textarea', 'body', '感想');
     $form->addElement('submit', '_submit', '送信', '');
     // フィルタと検証ルール
     $form->applyFilter('__ALL__', 'trim');
     $form->applyFilter('__ALL__', 'strip_tags');
     $form->addRule('name', '名前を入力してください', 'required', null, 'client');
     $form->addRule('email', 'emailを入力してください', 'required', null, 'client');
     $form->addRule('email', 'emailの形式で入力してください', 'email', null, 'client');
 }
Ejemplo n.º 14
0
/**
 * JSON出力
 *
 * @param array $values  値
 * @param array $options オプション
 *
 * @return BEAR_Ro
 */
function outputAjax($values, array $options)
{
    $ajax = BEAR::get('BEAR_Page_Ajax');
    $values = $ajax->getAjaxValues();
    //    $body = json_encode($values);
    // Services_JSONの方が信頼性が高いため採用
    $json = new Services_JSON();
    $body = $json->encode($values);
    $log = BEAR::dependency('BEAR_Log');
    /* @var $log BEAR_Log */
    $log->log('AJAX', $values);
    $headers = array('X-BEAR-Output: AJAX' => 'Content-Type: text/javascript+json; charset=utf-8');
    $ro = BEAR::factory('BEAR_Ro');
    /* @var $ro BEAR_Ro */
    $ro->setBody($body);
    $ro->setHeaders($headers);
    return $ro;
}
Ejemplo n.º 15
0
 /**
  * Inject
  *
  * @return void
  */
 public function onInject()
 {
     $this->_header = BEAR::dependency('BEAR_Page_Header');
     $this->_session = BEAR::dependency('BEAR_Session');
     switch (true) {
         case isset($_GET['extend']):
             // セッション延長
             $this->_mode = self::EXTEND;
             break;
         case isset($_GET['logout']):
             // セッション破棄
             $this->_mode = self::LOGOUT;
             break;
         default:
             // どうしますか画面
             $this->_mode = null;
     }
 }
Ejemplo n.º 16
0
 /**
  * Constructor
  *
  * @param array $config
  *
  * @see http://jp.php.net/manual/ja/function.memcache-addserver.php
  * @throws BEAR_Cache_Exception
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     if (!extension_loaded('memcache')) {
         throw new BEAR_Cache_Exception('Memcached extention is not loaded');
     }
     $this->_adapter = new Memcache();
     //キャッシュサーバー追加
     if (isset($this->_config['path'])) {
         foreach ($this->_config['path'] as $path) {
             $this->_adapter->connect($path);
         }
     }
     $log = array();
     if ($this->_config['debug'] && isset($this->_config['path'])) {
         $log['Ver'] = $this->_adapter->getVersion();
         BEAR::dependency('BEAR_Log')->log('Memcache', $log);
     }
     return $this->_adapter;
 }
Ejemplo n.º 17
0
 /**
  * リソースのリンクをつなげる
  *
  * <pre>リソースをリンクした結果をHEADER_LINK_BODYヘッダーに付加します</pre>
  *
  * @return void
  */
 public function chainLink(BEAR_Ro $rootRo, array $chain)
 {
     if ($chain === array()) {
         return;
     }
     $config = $rootRo->getConfig();
     if (!isset($config['options']['cache']['link'])) {
         $result = $this->_chainLink($rootRo, $chain);
     } else {
         $cacheKey = serialize($chain);
         $cache = BEAR::dependency('BEAR_Cache');
         if (isset($config['options']['cache']['life'])) {
             $cache->setLife($config['options']['cache']['life']);
         }
         $result = $cache->get($cacheKey);
         if (!$result) {
             $result = $this->_chainLink($rootRo, $chain);
         }
     }
     return $result;
 }
Ejemplo n.º 18
0
 /**
  * プロファイリングストップ
  *
  * プロファイラーリンクの表示します
  *
  * @param int $type 0:xhprof 1:xh gui
  *
  * @return void
  */
 public static function stop($type = 0)
 {
     $xhprof_data = xhprof_disable();
     $isAjax = BEAR::dependency('BEAR_Page_Ajax')->isAjaxRequest();
     if ($isAjax === true || PHP_SAPI === 'cli') {
         return;
     }
     $xhprofRuns = new XHProfRuns_Default();
     if (BEAR::exists('app')) {
         $app = BEAR::get('app');
         $appName = $app['core']['info']['id'];
     } else {
         $appName = 'bear.app';
     }
     $baseHref = self::$_profilerInfo[$type]['href'];
     $runId = $xhprofRuns->save_run($xhprof_data, $appName);
     $href = "{$baseHref}/index.php?run={$runId}&source={$appName}";
     $link = '<br><a style="padding: 3px; background-color: red; color: white; font-family:';
     $link .= 'Verdana; font-style: normal; font-variant: normal; font-weight: bold; font-size: 8pt;';
     $link .= ' " name="" target="_blank" href="' . $href . '"">' . self::$_profilerInfo[$type]['label'] . '</a>';
     echo $link;
 }
Ejemplo n.º 19
0
 /**
  * インジェクタ
  *
  * SELECTクエリーをCOUNTに変更します
  *
  */
 public function onInjectCount()
 {
     $this->onInject();
     $this->_query = BEAR::dependency('BEAR_Query_Count', $this->_queryConfig);
 }
Ejemplo n.º 20
0
 /**
  * リンクされたbody配列を取得
  *
  * @return array
  */
 public function getLinkedBody()
 {
     $this->_doRequest();
     $result = BEAR::dependency('BEAR_Ro_Prototype_Link', $this->_prototypeLink)->chainLink($this->_ro, $this->_chainLink);
     return $result;
 }
Ejemplo n.º 21
0
 /**
  * セレクト
  *
  * <pre>
  * 通常のselect文の他にDB結果の一部だけをSELECTする機能と、HTMLページングの機能が合わさった
  * メソッドです。getAll()メソッドの引数に加えて一画面に表示するデータ数を
  * 引数に指示するとページング(スライス)されたデータ結果と
  * エージェントに合わせたリンクHTML文字列が返ります。
  * $valuesが配列<array($key => $values)>ならWHERE $key1 = $id1 AND $key2 = $id2 ..と条件を作ってselectします。
  * リソース内で受け取った$valuesを条件にSELETするときに使います。
  *
  * $paramsが空だと通常のSQL、連想配列が入っていると$queryをpreparedステートメート文として期待して実行します。
  * </pre>
  *
  * @param string $query  SQL
  * @param array  $params プリペアードステートメントにする場合にバインドする変数
  * @param array  $values where条件配列
  * @return BEAR_Ro
  */
 public function select($query, array $params = array(), array $values = null, $id = 'id')
 {
     assert(is_object($this->_config['db']));
     assert(is_object($this->_config['ro']));
     $db =& $this->_config['db'];
     $ro = $this->_config['ro'];
     // Row取得
     if (!is_null($values)) {
         $result = $this->_selectRow($db, $query, $params, $values, $id);
         if ($result !== false) {
             return $result;
         }
     }
     // All取得
     // 論理削除
     if (isset($this->_config['deleted_at']) && $this->_config['deleted_at'] === true) {
         if (stripos($query, 'WHERE') === false) {
             $query .= ' WHERE deleted_at IS NULL';
         } else {
             $query = str_ireplace('WHERE', 'WHERE deleted_at IS NULL AND', $query);
         }
     }
     // ソート
     if (isset($this->_config['sort'])) {
         $query = $this->_sort($query);
     }
     if (!isset($this->_config['pager']) || !$this->_config['pager'] || $this->_config['perPage'] <= 0) {
         if (isset($this->_config['offset']) && $this->_config['perPage'] > 0) {
             // LIMIT & Offset
             $query .= ' LIMIT ' . $this->_config['offset'] . ',' . $this->_config['perPage'];
         } elseif (isset($this->_config['perPage']) && $this->_config['perPage'] > 0) {
             // LIMIT
             $query .= ' LIMIT ' . $this->_config['perPage'];
         }
         if ($params) {
             $sth = $db->prepare($query);
             $result = $sth->execute($params)->fetchAll();
         } else {
             $result = $db->queryAll($query);
         }
         return $result;
     }
     // DBページャー
     $pagerOptions = $this->_config['options'];
     $pagerOptions['perPage'] = $this->_config['perPage'];
     if (!array_key_exists('totalItems', $pagerOptions)) {
         $pagerOptions['totalItems'] = $this->_countQuery($query, $params);
     }
     // ページング
     $pager = BEAR::dependency('BEAR_Pager');
     // totalItems以外のBEAR_Pagerデフォルトオプションを使用
     $defaultPagerOptions = $pager->getPagerOptions();
     unset($defaultPagerOptions['totalItems']);
     $pagerOptions = $pagerOptions + $defaultPagerOptions;
     $pager->setOptions($pagerOptions);
     $pager->pager->build();
     // 情報
     $info['totalItems'] = $pagerOptions['totalItems'];
     $pager->makeLinks($pagerOptions['delta'], $pagerOptions['totalItems']);
     $links = $pager->pager->getLinks();
     $info['page_numbers'] = array('current' => $pager->pager->getCurrentPageID(), 'total' => $pager->pager->numPages());
     list($info['from'], $info['to']) = $pager->pager->getOffsetByPageId();
     $info['limit'] = $info['to'] - $info['from'] + 1;
     $db->setLimit($pagerOptions['perPage'], $info['from'] - 1);
     if ($params) {
         $sth = $db->prepare($query);
         $result = $sth->execute($params)->fetchAll();
     } else {
         $result = $db->queryAll($query);
     }
     if (PEAR::isError($result)) {
         return $result;
     }
     // ROオブジェクトで返す
     /* @var $ro BEAR_Ro */
     $ro->setBody($result);
     $ro->setHeaders($info);
     $pager->setPagerLinks($links, $info);
     $pager = array('links' => $links, 'info' => $info);
     $ro->setLinks(array('pager' => $pager));
     $log = BEAR::dependency('BEAR_Log')->log('DB Pager', $info);
     return $ro;
 }
Ejemplo n.º 22
0
 /**
  * Inject
  *
  * @return void
  */
 public function onInject()
 {
     $this->_log = BEAR::dependency('BEAR_Log');
 }
Ejemplo n.º 23
0
 /**
  * スクリプトシャットダウン時のログ処理
  *
  * <pre>
  * アプリケーションログ、smartyアサインログ、グローバル変数ログ、
  * リクエストURIをシリアライズしてファイル保存します。
  * デバックモードの時のみ使用します。
  * 保存されたログは/__bear/のLogタブでブラウズできます。
  * シャットダウン時実行のメソッドとしてフレームワーク内で登録され、
  * スクリプト終了時に実行されます。
  * フレームワーク内で使用されます。
  * </pre>
  *
  * @return void
  * @ignore
  * @throws BEAR_Log_Exception
  */
 public function shutdownDebug($return = true)
 {
     if (PHP_SAPI === 'cli') {
         return;
     }
     if (strpos($_SERVER['REQUEST_URI'], '__bear/') !== false) {
         return;
     }
     restore_error_handler();
     error_reporting(0);
     try {
         $isBeardev = isset($_SERVER['__bear']);
         $pageLogPath = _BEAR_APP_HOME . '/logs/' . 'debug' . '.log';
         file_put_contents($pageLogPath, $this->_config['debug']);
         if ($isBeardev || PHP_SAPI === 'cli') {
             return;
         }
         $log = array();
         $pageLogPath = _BEAR_APP_HOME . '/logs/page.log';
         if (file_exists($pageLogPath) && !is_writable($pageLogPath)) {
             // 書き込み権限のエラー
             Panda::error('Permission denied.', "[{$pageLogPath}] is not writable.");
             return;
         }
         // page ログ
         $pageLog = file_exists($pageLogPath) ? BEAR_Util::unserialize(file_get_contents($pageLogPath)) : '';
         // show_vars
         if (!function_exists('show_vars')) {
             include 'BEAR/vendors/debuglib.php';
         }
         $log['var'] = show_vars('trim_tabs:2;show_objects:1;max_y:100;avoid@:1; return:1');
         if (class_exists('BEAR_Smarty', false)) {
             $smarty = BEAR::dependency('BEAR_Smarty');
             unset($smarty->_tpl_vars['content_for_layout']);
             $log['smarty'] = $smarty->_tpl_vars;
         } else {
             $log['smarty'] = '';
         }
         $oldPageLog = isset($pageLog['page']) ? $pageLog['page'] : array();
         $newPageLog = array('page' => $this->_logs, 'uri' => $_SERVER['REQUEST_URI']);
         $oldPageLog[] = $newPageLog;
         if (count($oldPageLog) > 3) {
             array_shift($oldPageLog);
         }
         $log += array('page' => $oldPageLog, 'include' => get_included_files(), 'class' => get_declared_classes());
         if (isset($_SERVER['REQUEST_URI'])) {
             $log += array('uri' => $_SERVER['REQUEST_URI']);
         }
         $reg = BEAR_Util::getObjectVarsRecursive(BEAR::getAll());
         $log['reg'] = $reg;
         if ($return === true) {
             return $log;
         } else {
             file_put_contents($pageLogPath, serialize($log));
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
Ejemplo n.º 24
0
 /**
  * UAスニッフィングインジェクト
  *
  * UAスニッフィングOnの時のインジェクタです。BEAR_Viewで指定していされています。
  *
  * @return void
  */
 public function onInjectUaSniffing()
 {
     $this->onInject();
     $this->_config['values']['agent'] = $this->_config['agent_config'];
     $this->_enableJs = $this->_config['agent_config']['enable_js'];
     $this->_role = $this->_config['agent_config']['role'];
     $this->_emoji = BEAR::dependency('BEAR_Emoji');
 }
Ejemplo n.º 25
0
 /**
  * インスタンス変更
  *
  * <pre>
  * 画像エンジンを変更します。イメージオブジェクトは引き継がれます。
  * GDでjpegを読み込み、Cairoで文字を合成、GDでGIF出力などのように使えます。
  * </pre>
  *
  * @param string $adapter self::ADAPTER_GD | self::ADAPTER_MAGICK | self::ADAPTER_CAIRO
  *
  * @return BEAR_Img_Adapter_GD | BEAR_Img_Adapter_Magick | BEAR_Img_Adapter_Cairo
  */
 public static function changeAdapter($adapter)
 {
     // 保存
     $tmpFile = self::$_instance->getTmpFileName();
     self::$_instance->save($tmpFile, 'png');
     self::$deleteFiles[] = $tmpFile;
     // イメージインスタンス
     switch ($adapter) {
         case self::ADAPTER_GD:
             self::$_instance = BEAR::dependency('BEAR_Img_Adapter_GD');
             break;
         case self::ADAPTER_MAGICK:
             self::$_instance = BEAR::dependency('BEAR_Img_Adapter_Magick');
             break;
         case self::ADAPTER_CAIRO:
             self::$_instance = BEAR::dependency('BEAR_Img_Adapter_Cairo');
             break;
         default:
             trigger_error("No engine supported {$adapter}");
     }
     self::$_instance->load($tmpFile);
     return self::$_instance;
 }
Ejemplo n.º 26
0
 /**
  * サブミット処理
  *
  * エージェントの設定に応じてサブミットされた$_POSTまたは$_GETの文字列を
  * 絵文字エンティティや文字コード変換をします。
  *
  * @return void
  * @internal グローバル変数を直接変更してるのはそれに依存してるHTML_Quickformなどのライブラリのためです
  */
 public function submit()
 {
     static $done = false;
     $hasSubmit = isset($_POST['_token']) || isset($_GET['_token']) ? true : false;
     if (!$hasSubmit && $done) {
         return;
     }
     if (isset($_POST['_token'])) {
         $input =& $_POST;
     } elseif (isset($_GET['_token'])) {
         $input =& $_GET;
     } else {
         return;
     }
     $done = true;
     $app = BEAR::get('app');
     $emojiSubmit = isset($app['BEAR_Emoji']['submit']) ? $app['BEAR_Emoji']['submit'] : 'pass';
     switch ($emojiSubmit) {
         // 何もしない
         case 'pass':
             break;
         case 'entity':
             // 絵文字をエンティティに変換
             // 3GCsエンコード変換必須
             if ($this->_config['is_mobile']) {
                 array_walk_recursive($input, array('BEAR_Emoji', 'onEntityEmoji'), BEAR::dependency('BEAR_Emoji'));
             }
             break;
             // 絵文字除去
         // 絵文字除去
         case 'remove':
             array_walk_recursive($input, array('BEAR_Emoji', 'removeEmoji'), BEAR::dependency('BEAR_Emoji'));
             break;
         default:
             trigger_error('Illigal $this->_config[\'agent\'] error', E_USER_WARNING);
             break;
     }
     // UTF8に文字コード変換
     if (isset($this->_config['input_encode'])) {
         array_walk_recursive($input, array(__CLASS__, 'onUTF8'), $this->_config['input_encode']);
     }
 }
Ejemplo n.º 27
0
 /**
  * データ受信ハンドラ
  *
  * @param string $clientId クライアントID
  * @param string $data     受信データ
  *
  * @return void
  */
 public function onReceiveData($clientId = 0, $data = "")
 {
     $data = trim($data);
     $parsed = explode(' ', $data);
     $method = strtolower($parsed[0]);
     $uri = $parsed[1];
     switch ($method) {
         case '':
             break;
         case '/info':
             $info = $this->_server->getClientInfo();
             $this->_server->sendData($clientId, var_export($info, true));
             exit;
         case '/close':
             $this->_server->closeConnection($clientId);
             exit;
         case '/help':
             $help = 'Usage: <method> <url>' . PHP_EOL;
             $this->_server->sendData($clientId, $help);
             exit;
         default:
     }
     $resource = BEAR::dependency('BEAR_Resource');
     $params = array('uri' => $uri);
     switch ($method) {
         case 'create':
         case 'post':
             $resource->create($params);
             break;
         case 'read':
         case 'broadcast':
         case 'get':
             $resource->read($params);
             break;
         case 'update':
         case 'put':
             $resource->update($params);
             break;
         case 'delete':
             $resource->delete($params);
             break;
         default:
             $resource = false;
             break;
     }
     if ($resource !== false) {
         $ro = $resource->getRo();
         $this->sendData($clientId, $method, $ro);
     } else {
         // BAD Request
         $data = BEAR::CODE_BAD_REQUEST;
         $data .= PHP_EOL . PHP_EOL;
         $this->_server->sendData($clientId, $data);
     }
 }
Ejemplo n.º 28
0
 /**
  * キャッシュファクトリー
  *
  * 指定のキャッシュアダプターでキャッシュオブジェクトを返します
  *
  * @return BEAR_Cache_Adapter
  */
 public function factory()
 {
     switch ($this->_config['adapter']) {
         case self::ADAPTER_MEMCACHE:
             $instance = BEAR::dependency('BEAR_Cache_Adapter_Memcache', $this->_config);
             break;
         case self::ADAPTER_CACHELITE:
             $instance = BEAR::dependency('BEAR_Cache_Adapter_Lite', $this->_config);
             break;
         case self::ADAPTER_APC:
             $instance = BEAR::dependency('BEAR_Cache_Adapter_Apc', $this->_config);
             break;
         default:
             if (is_string($this->_config['adapter'])) {
                 self::$_instance = BEAR::dependency('App_Cache_Adapter_' . $this->_config['adapter']);
                 break;
             }
             $instance = BEAR::dependency('BEAR_Cache_Adapter_Void', $this->_config);
     }
     return $instance;
 }
Ejemplo n.º 29
0
 /**
  * BEARバッジ表示
  *
  * <pre>
  * エラー状態を表し、__bearページにリンクするデバック時に
  * 画面右上に現れる「BEARバッジ」を表示します。
  *
  * ページの状態によって色が変わります。
  * </pre>
  * <ur>
  * <li>赤 Fatal, PEARエラーなど</li>
  * <li>黄 Warningレベルのエラーはあり</li>
  * <li>青 noticeは出てる</li>
  * <li>緑 noticeも出てない</li>
  * </url>
  *
  * @return string
  */
 public static function onOutpuHtmlDebug($html)
 {
     $ua = BEAR::dependency('BEAR_Agent')->getUa();
     $hasResource = BEAR::factory('BEAR_Ro_Debug')->hasResourceDebug();
     $app = BEAR::get('app');
     if (!$app['core']['debug']) {
         return;
     }
     // エラー統計
     $errorFgColor = "white";
     $errors = Panda::getAllErrors();
     $errorStat = Panda::getErrorStat();
     $errorMsg = implode("\n", $errors);
     if ($errorStat & E_ERROR || $errorStat & E_USER_ERROR || $errorStat & E_RECOVERABLE_ERROR) {
         $errorBgColor = "red";
         $errorMsg = "Fatal Error: {$errorMsg}";
         $bear = "BEAR - Error";
     } elseif ($errorStat & E_WARNING || $errorStat & E_USER_WARNING) {
         $errorBgColor = "yellow";
         $errorFgColor = "black";
         $errorMsg = "WARNING: {$errorMsg}";
         $bear = "BEAR - Warning";
     } elseif ($errorStat & E_NOTICE || $errorStat & E_USER_NOTICE) {
         $errorBgColor = "#2D41D7";
         $errorMsg = "NOTICE: {$errorMsg}";
         $bear = "BEAR";
     } else {
         $errorBgColor = "green";
         $errorMsg = "{$errorMsg}";
         $bear = "BEAR";
     }
     // デバック情報表示HTML
     // bear.jsを使用する場合はbear_debuggingがtrueになる
     if (file_exists(_BEAR_APP_HOME . '/htdocs/__edit')) {
         $editHtml = '<a href="/__edit/?id=@@@log_id@@@"';
         $editHtml .= ' class="bear_page_edit" style="padding:5px 3px 3px 3px;background-color: gray';
         $editHtml .= ';color:white; font:bold 8pt Verdana;';
         $editHtml .= 'border: 1px solid #dddddd">EDIT</a>';
     } else {
         $editHtml = '';
     }
     // リソースBoxリンク
     $color = "blue";
     $res = array();
     if (!isset($_GET['_resource'])) {
         $mode = 'box';
         $title = "Resource Box";
         $color = "grey";
     } elseif ($_GET['_resource'] == 'box') {
         $mode = 'body';
         $title = "Resource Body";
     } elseif ($_GET['_resource'] == 'body') {
         $mode = 'html';
         $title = "Resource HTML";
     } else {
         $mode = false;
         $title = "No Resource Box";
     }
     $currentMode = isset($_GET['_resource']) ? $_GET['_resource'] : 'none';
     $res = $mode ? array('_resource' => $mode) : array();
     unset($_GET['_resource']);
     $resourceBoxUrl = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?' . http_build_query(array_merge($_GET, $res));
     $budgeHtml = '<div id="bear_badge">';
     $budgeHtml .= $editHtml;
     if ($hasResource === true) {
         $budgeHtml .= '<a href="' . $resourceBoxUrl . '" class="bear_resource_' . $currentMode . '" title="' . $title . '">RES</a>';
     }
     $budgeHtml .= '<a href="/__bear/?id=@@@log_id@@@" class="bear_badge" title="';
     $budgeHtml .= $errorMsg . '" style="background-color:' . $errorBgColor;
     $budgeHtml .= ';color:' . $errorFgColor . ';';
     $budgeHtml .= '">' . $bear . '</a><a href="?_bearinfo" class="bear_info">i</a></div>';
     $budgeHtml = str_replace('</body>', "{$budgeHtml}" . '<link rel="stylesheet" href="/__bear/css/debug.css" type="text/css">' . "</body>", $html);
     return $budgeHtml;
 }
Ejemplo n.º 30
0
 /**
  * プロトタイプリソースをページバリューにセット
  *
  * リソースのsetでスタックに積まれた複数のプロトタイプリソースを取り出しページにsetします。
  *
  * 'lazy' lazy Roとしてsetします。viewで出現したタイミングで実リソースリクエストが行われます。
  * 'object' roオブジェクトとしてsetされます。
  * 'value' 変数(多くの場合連想配列)としてsetされます。
  *
  * @todo ajaxオプション実装
  *
  * @return void
  */
 public function setPrototypeRo()
 {
     static $_registerResourceOnShutdown = false;
     // initでsetされたroをバリューに
     $stackedRos = BEAR::dependency('BEAR_Ro_Prototype')->popAll();
     foreach ($stackedRos as $item) {
         list($key, $prototypeRo) = each($item);
         /* @var $prototypeRo BEAR_Ro_Prototype */
         $setOption = $prototypeRo->getSetOption();
         $config = $prototypeRo->getConfig();
         $options = $config['request']['options'];
         switch ($setOption) {
             case 'ajax':
                 $prototypeRo->setConfig('is_ajax_set', true);
             case 'lazy':
                 $this->set($key, $prototypeRo);
                 break;
             case 'object':
                 $ro = $prototypeRo->request();
                 $this->set($key, $ro);
                 break;
             case 'shutdown':
                 BEAR::dependency('BEAR_Ro_Shutdown')->register()->set($prototypeRo);
                 break;
             case 'value':
             default:
                 $value = $prototypeRo->getValue();
                 $this->set($key, $value);
         }
     }
 }