Example #1
0
function _log_focus($openid, $operation, $user_info = NULL)
{
    R::addDatabase('wechat_csc', $GLOBALS['db_wechat_csc_url'], $GLOBALS['db_wechat_csc_user'], $GLOBALS['db_wechat_csc_pass']);
    R::selectDatabase('wechat_csc');
    if (!R::testConnection()) {
        exit('DB failed' . PHP_EOL);
    }
    R::freeze(true);
    try {
        $user = R::getRedBean()->dispense('wxcsc_focus');
        $user->openid = $openid;
        $user->operation = $operation;
        if ($operation == 'focus' && $user_info != NULL) {
            $user->nickname = $user_info['nickname'];
            $user->sex = $user_info['sex'];
            $user->language = $user_info['language'];
            $user->city = $user_info['city'];
            $user->province = $user_info['province'];
            $user->country = $user_info['country'];
        }
        $user_id = R::store($user);
    } catch (Exception $e) {
        header('Content-type:text/json;charset=utf-8');
        echo json_encode(['result' => 'failed', 'error' => 'db error wechat', 'details' => $e->getMessage()]);
        die;
    }
    R::close();
}
 function tearDown()
 {
     // Must use nuke() to clear caches etc.
     R::nuke();
     R::close();
     $this->bbs = NULL;
     system("rm -rf " . self::DATA);
 }
Example #3
0
 /**
  * Test closing database connection.
  * 
  * @return void
  */
 public function testClose()
 {
     asrt(R::$adapter->getDatabase()->isConnected(), TRUE);
     R::close();
     asrt(R::$adapter->getDatabase()->isConnected(), FALSE);
     // Can we create a database using empty setup?
     R::setup();
     $id = R::store(R::dispense('bean'));
     asrt($id > 0, TRUE);
     // Test freeze via kickstart in setup
     $toolbox = RedBean_Setup::kickstart('sqlite:/tmp/bla.txt', NULL, NULL, TRUE);
     asrt($toolbox->getRedBean()->isFrozen(), TRUE);
     // Test Oracle setup
     $toolbox = RedBean_Setup::kickstart('oracle:test-value', 'test', 'test', FALSE);
     asrt($toolbox instanceof RedBean_ToolBox, TRUE);
 }
Example #4
0
    $_SESSION['openid'] = $openid;
}
// Query
R::addDatabase('wechat_csc', $GLOBALS['db_wechat_csc_url'], $GLOBALS['db_wechat_csc_user'], $GLOBALS['db_wechat_csc_pass']);
R::selectDatabase('wechat_csc');
if (!R::testConnection()) {
    exit('DB failed' . PHP_EOL);
}
R::freeze(true);
try {
    $user_email = R::getCell('SELECT wu.email' . '  FROM wxcsc_users wu' . ' WHERE wu.openid = :openid' . ' LIMIT 1', [':openid' => $openid]);
} catch (Exception $e) {
    header('Location: ' . $csc_url_base . '/static/html/error_message.html?msg=' . urlencode($e->getMesage()) . '&rand=' . rand() . '#mp.weixin.qq.com');
    die;
}
R::close();
_log(json_encode(['openid' => $openid, 'user_email' => $user_email]));
// Error return
if ($user_email == '') {
    if ($callback == 'user_bind_check_csc') {
        header('Location: ' . $csc_url_base . '/static/html/user_bind_1_csc.html?rand=' . rand() . '#mp.weixin.qq.com');
        die;
    } else {
        if (in_array($callback, ['extra_news', 'extra_expert', 'dc_guide', 'extra_contact'])) {
            header('Location: ' . $csc_url_base . '/static/html/' . $callback . '.html?rand=' . rand() . '#mp.weixin.qq.com');
            die;
        } else {
            if (in_array($callback, ['extra_neighbour', 'extra_docs', 'user_dcs', 'user_tasks'])) {
                header('Location: ' . $csc_url_base . '/static/html/' . $callback . '.html?rand=' . rand() . '#mp.weixin.qq.com');
                die;
            } else {
 function __destruct()
 {
     R::close();
 }
 /**
  * Shutdown function - this is used to catch certain errors that are not otherwise trapped and
  * generate a clean screen as well as an error report to the developers.
  *
  * It also closes the RedBean connection
  */
 public function shutdown()
 {
     if ($error = error_get_last()) {
         # are we terminating with an error?
         if (isset($error['type']) && ($error['type'] == E_ERROR || $error['type'] == E_PARSE || $error['type'] == E_COMPILE_ERROR)) {
             # tell the developers about this
             $this->telladmin($error['message'], $error['type'], $error['file'], $error['line']);
             $this->make500();
         } else {
             echo '<div>There has been a system error</div>';
         }
     }
     R::close();
     # close RedBean connection
 }
Example #7
0
 private function shortIt($url, $md5)
 {
     if (!self::API_SHORT) {
         return $url;
     }
     parent::RedBeanConnect('short');
     if ($fetch = @R::findOne('short_url', '`title` = ?', [$md5])) {
         return self::API_SHORT . $fetch->keyword;
     }
     $timestamp = date('Y-m-d H:i:s');
     do {
         $uniq = '';
         $base = strtolower(hash('sha256', uniqid()));
         while (strlen($uniq) < 8) {
             $uniq .= substr($base, (int) -(strlen($base) / (1 + strlen($uniq))), 1);
         }
     } while (@R::findOne('short_url', '`keyword` = ?', [$uniq]));
     $sql = 'INSERT INTO `short`.`short_url` ';
     $sql .= "(`keyword`, `url`, `title`, `timestamp`, `ip`, `clicks`) ";
     $sql .= "VALUES ('{$uniq}', '{$url}', '{$md5}', '{$timestamp}', '";
     $sql .= getHostByName(getHostName()) . "', '0')";
     R::exec($sql);
     R::close();
     return 'http://exsubs.anidb.pl/short/' . $uniq;
 }
Example #8
0
 public function __destruct()
 {
     $this->connection = null;
     R::close();
 }
Example #9
0
 protected function _closeDBConnection()
 {
     R::close();
 }
Example #10
0
function get_pe_wechat($staff_email)
{
    // Wechat PE
    //R::addDatabase('wechat_pe', $GLOBALS['db_wechat_pe_url'], $GLOBALS['db_wechat_pe_user'], $GLOBALS['db_wechat_pe_pass']);
    R::selectDatabase('wechat_pe');
    if (!R::testConnection()) {
        exit('DB failed' . PHP_EOL);
    }
    R::freeze(true);
    if (TEST_SEND) {
        $staff_email = DEBUG_EMAIL;
    }
    $email_prefix = explode("@", $staff_email);
    try {
        $openids = R::getAll(' SELECT openid ' . '   FROM wechat_pe.wxpe_users ' . '  WHERE email = :email_1 ' . '     OR email = :email_2 ', [':email_1' => $email_prefix[0], ':email_2' => ucfirst($email_prefix[0])]);
    } catch (Exception $e) {
        die(json_encode(['result' => 'failed', 'error' => 'db error wechat_pe', 'details' => $e->getMessage()]));
    }
    R::close();
    return $openids;
}
Example #11
0
 public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
 {
     \R::nuke();
     \R::close();
 }
Example #12
0
 public function __destruct()
 {
     self::$dbh = null;
     R::close();
 }
Example #13
0
 public static function disconnect()
 {
     R::close();
 }
Example #14
0
 private function createTable()
 {
     parent::RedBeanConnect(self::DB_NAME);
     $sql = 'CREATE TABLE IF NOT EXISTS `' . self::TB_NAME . '`(';
     $sql .= '`id` int(10) NOT NULL AUTO_INCREMENT,';
     $sql .= '`name` varchar(25),';
     $sql .= '`orginal` varchar(45) NOT NULL,';
     $sql .= '`icon` varchar(100) NOT NULL,';
     $sql .= '`link` varchar(100) NOT NULL,';
     $sql .= '`linkgc` varchar(100) NOT NULL,';
     $sql .= 'PRIMARY KEY (`id`)';
     $sql .= ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;';
     $sql = trim($sql);
     R::exec($sql);
     R::close();
 }