public function prepareRest()
 {
     /** @var FilterPastResults $model */
     $model = Yii::createObject(['class' => FilterPastResults::className(), 'scenario' => 'filter']);
     $result = ['content' => [], 'total' => [], 'errors' => []];
     include_once Yii::$app->getBasePath() . DIRECTORY_SEPARATOR . 'crons' . DIRECTORY_SEPARATOR . 'api.php';
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $data = ['loc' => $model->loc, 'action' => $model->action, 'DF' => strtotime(date($model->dateFrom . ' 00:00:00')) * 1000, 'DT' => strtotime(date($model->dateTo . ' 23:59:59')) * 1000, 'Sport' => $model->sports, 'collapsedSports' => false, 'substr' => $model->search, 'categoriesPerPage' => $model->categoriesPerPage, 'page' => $model->page];
         $url = 'http://212.38.167.37/resultsproxy/getresultsxml3.aspx';
         $xml = apiReadUrlXml($url, $data);
         $array = apiParseXml($xml);
         if ($array['status'] === true) {
             $array = obj2array($array['result']);
             $result['total'] = $array['@attributes'];
             if ($array['@attributes']['page'] > $array['@attributes']['totalpages']) {
                 $result['status'] = 3;
                 return $result;
             }
             if ($array['@attributes']['count'] == 0) {
                 $result['status'] = 2;
                 $result['errors'][] = Yii::t('bet', 'No results were found that met all the given criteria');
             } else {
                 include_once $this->getViewPath() . DIRECTORY_SEPARATOR . 'template.php';
                 $array = $array['sports']['PSport'];
                 if (sizeof($array) == 2 && isset($array['@attributes']) && isset($array['Groups'])) {
                     $array = [$array];
                 }
                 if ($model->page == 1) {
                     $result['content'][] = '<table role="presentation" cellpadding="0" cellspacing="0">';
                     $result['content'][] = '<tbody>';
                 }
                 foreach ($array as $sport) {
                     if (is_array($sport['@attributes'])) {
                         sportBlock($result['content'], $sport['@attributes']['id'], $sport['@attributes']['code'], $sport['@attributes']['name'], $sport);
                     }
                 }
                 if ($model->page == 1) {
                     $result['content'][] = '</tbody>';
                     $result['content'][] = '</table>';
                 }
                 //$result['content'] = $array;
             }
         } else {
             $result['errors'] = $array['errors'];
         }
     } else {
         $result['status'] = false;
         $result['errors'] = array_values($model->getErrors());
     }
     //?loc=ru-RU&action=GETRESULTS&DF=1436043600000&DT=1436129999999&Sport=1763111,1763108,1763113,1763081,1763099,1762805,
     //1763102,1763049,1763104,1763048,1763105,1763114,1763082,1763068,1763057,1762821,1763040,1763059,1763077,1763085,1763116,
     //1763096,1763070,1763061,1781423,1763112,1763117,1763115,1763109,1763110,1763052,1781422,1763054,1763090,1762785,1763037,
     //1763091,1763072,1781414,1763045,1763044,1763056,1762822,1763106,1763080,1763079,1763060,2576760,1763051,1763053,1763075,
     //1763076,1763062,1763083,1763046,1762818,1762803,1763101,1763118,1762823,1763064,1763100,1763107,1762801,1763043,1763066,
     //1763094,1763067,1763073,1763078,1762798,1762824,1763074,1763038,1763058,1763036,1763097,1763063,1763050,1763069,1762800,
     //1763042,1781407,1763086,1763088,1763103,1763093&collapsedSports=false&page=1
     return $result;
 }
Example #2
0
function obj2array($objects)
{
    $ret = array();
    foreach ($objects as $key => $value) {
        if (is_a($value, 'stdClass')) {
            $ret[$key] = (array) obj2array($value);
        } elseif (is_array($value)) {
            $ret[$key] = obj2array($value);
        } else {
            $ret[$key] = $value;
        }
    }
    return $ret;
}
Example #3
0
function to_json($arr)
{
    $parts = array();
    $is_list = true;
    if (is_object($arr)) {
        $arr = obj2array($arr);
    }
    $i = 0;
    foreach ($arr as $key => $value) {
        if (!is_int($key) || $key != $i) {
            $is_list = false;
            break;
        }
        $i++;
    }
    foreach ($arr as $key => $value) {
        if (is_object($value)) {
            if (!empty_obj($value)) {
                $parts[] = to_json((array) $value);
            } else {
                $parts[] = "\"{$key}\":" . to_json(array());
            }
        } elseif (is_array($value)) {
            $parts[] = $is_list ? to_json($value) : '"' . $key . '":' . to_json($value);
        } else {
            $str = !$is_list ? '"' . $key . '":' : '';
            if (is_int($value)) {
                $str .= (int) $value;
            } elseif ($value === true) {
                $str .= "true";
            } elseif ($value === false) {
                $str .= "false";
            } elseif ($value === null) {
                $str .= "null";
            } elseif (is_string($value)) {
                $patt = array("\\", '"', "\\b", "\t", "\n", "\f", "\r", "\\u");
                $repl = array("\\\\", "\\" . '"', "\\b", "\\t", "\\n", "\\f", "\\r", "\\u");
                $value = str_replace($patt, $repl, $value);
                $str .= '"' . $value . '"';
            }
            $parts[] = $str;
        }
    }
    $json = implode(',', $parts);
    $json = utf8_encode($json);
    return $is_list ? '[' . $json . ']' : '{' . $json . '}';
    // return $is_list && !empty($json) ? '[' . $json . ']' : '{' . $json . '}';
}
Example #4
0
function obj2array($res)
{
    if (is_object($res)) {
        $res = get_object_vars($res);
    }
    if (is_array($res)) {
        while (list($key, $value) = each($res)) {
            if (is_object($value) || is_array($value)) {
                $res[$key] = obj2array($value);
            }
        }
    } else {
        $res = [];
    }
    return $res;
}
Example #5
0
function obj2array($obj)
{
    $new = array();
    foreach ($obj as $prop => &$val) {
        if (is_object($val)) {
            $new[] = obj2array($val);
        } else {
            if (strpos($prop, '_') === 0 && is_numeric(str_replace('_', '', $prop))) {
                $new[(int) str_replace('_', '', $prop)] = $obj->{$prop};
            } else {
                $new[$prop] = $obj->{$prop};
            }
        }
        unset($val);
    }
    return $new;
}
Example #6
0
function obj2array($obj)
{
    $out = array();
    foreach ($obj as $key => $val) {
        switch (true) {
            case is_object($val):
                $out[$key] = obj2array($val);
                break;
            case is_array($val):
                $out[$key] = obj2array($val);
                break;
            default:
                $out[$key] = $val;
        }
    }
    return $out;
}
Example #7
0
function generateDebugReport($method, $defined_vars, $email = "undefined")
{
    $ignorelist = array("HTTP_POST_VARS", "HTTP_GET_VARS", "HTTP_COOKIE_VARS", "HTTP_SERVER_VARS", "HTTP_ENV_VARS", "HTTP_SESSION_VARS", "_ENV", "PHPSESSID", "SESS_DBUSER", "SESS_DBPASS", "HTTP_COOKIE", "CoreFilingMessage", "responseSOAP", "RecordDocketingMessage", "PaymentMessage", "_SERVER", "GLOBALS");
    $timestamp = date("m/d/y h:m:s");
    $message = "Debug report created {$timestamp}\n";
    // Get the last SQL error for good measure, where $link is the resource identifier
    // for mysql_connect. Comment out or modify for your database or abstraction setup.
    //global $link;
    //$sql_error=mysql_error($link);
    //if($sql_error){
    //  $message.="\nMysql Messages:\n".mysql_error($link);
    // }
    // End MySQL
    // Could use a recursive function here. You get the idea ;-)
    foreach ($defined_vars as $key => $val) {
        if (is_object($val)) {
            $val = obj2array($val);
            $message .= ' obj2array: ' . "\n";
        }
        if (is_array($val) && !in_array($key, $ignorelist) && count($val) > 0) {
            $message .= "\n{$key} array (key=value):\n";
            foreach ($val as $subkey => $subval) {
                if (!in_array($subkey, $ignorelist) && !is_array($subval)) {
                    $message .= $subkey . " = " . $subval . "\n";
                } elseif (!in_array($subkey, $ignorelist) && is_array($subval)) {
                    foreach ($subval as $subsubkey => $subsubval) {
                        if (!in_array($subsubkey, $ignorelist)) {
                            $message .= $subsubkey . " = " . $subsubval . "\n";
                        }
                    }
                }
            }
        } elseif (!is_array($val) && !in_array($key, $ignorelist) && $val) {
            if (is_object($val)) {
                $val = obj2array($val);
                $message .= ' obj2array: ' . "\n";
            }
            $message .= "\nVariable " . $key . " = " . $val . "\n";
        }
    }
    if ($method == "browser") {
        //file_put_contents('gjdbg.html', '<pre>'.$message.'</pre>');
        echo nl2br($message);
    } elseif ($method == "email") {
        if ($email == "undefined") {
            $email = $_SERVER["SERVER_ADMIN"];
        }
        $mresult = mail($email, "Debug Report for " . $_ENV["HOSTNAME"] . "", $message);
        if ($mresult == 1) {
            echo "Debug Report sent successfully.\n";
        } else {
            echo "Failed to send Debug Report.\n";
        }
    }
}
    $url = 'http://212.38.167.37/reslive/getreslive2.aspx';
    echo "\r\n------------------------------------------------------------------------------------------\r\n" . "\r\n" . "\r\n" . 'Read url: ' . $url . "\r\n";
    $xml = apiReadUrlXml($url, ['local' => 'en-GB']);
    if (!is_string($xml) && $xml === false) {
        die('Error receiving xml from url:' . $url);
    }
    echo 'Success. String length: ' . strlen($xml) . "\r\n";
    echo substr($xml, 0, 200) . "\r\n";
    echo 'Parsing xml...' . "\r\n";
    $xml = apiParseXml($xml);
    if ($xml['status'] === false) {
        die('Error parsing xml from url:' . $url . ' with errors:' . var_export($xml['errors'], true));
    }
    echo 'Parsing Success.' . "\r\n";
    $file_path = PATH_RUNTIME_LIVE . DIRECTORY_SEPARATOR . 'array_live_' . time() . '.php';
    $xml = var_export(obj2array($xml['result']), true);
    echo substr($xml, 0, 200) . "\r\n";
    echo 'Writing to file.' . $file_path . "\r\n";
    file_put_contents($file_path, '<? return ' . $xml . ';');
    if (file_exists($file_path)) {
        echo 'Success. File size: ' . filesize($file_path) . "\r\n";
    } else {
        echo 'Error writing file. ' . "\r\n";
    }
}
echo 'Deleting old files.' . "\r\n";
$count = 0;
if (is_dir(PATH_RUNTIME_LIVE)) {
    foreach (new DirectoryIterator(PATH_RUNTIME_LIVE) as $fileInfo) {
        if ($fileInfo->isDot()) {
            continue;
Example #9
0
function obj2array($obj)
{
    if (is_array($obj) or is_object($obj)) {
        while (list($key, $val) = each($obj)) {
            $val = obj2array($val);
            $out[$key] = $val;
        }
    } else {
        $out = $obj;
    }
    return $out;
}
 function __construct()
 {
     parent::__construct();
     $this->hackFormValidation();
     $this->load->helper(array('language', 'url', 'common', 'page', 'form'));
     $this->load->library(array('form_validation', 'log', 'fb', 'interceptor_support'));
     if (get_ci_config('enable_audit')) {
         $this->log('The audit manager is enabled for this application');
         $this->load->library('audit_manager');
     }
     if (get_ci_config('enable_transaction')) {
         $this->log('The transaction manager is enabled for this application');
         $this->load->library('transaction_manager');
     }
     if (get_ci_config('enable_security') && !defined('PHPUNIT_TEST')) {
         // Skip the testing environment
         $this->log('The security engine is enabled for this application');
         $this->load->library('security_engine');
     }
     // Load the default language files, if the lang is set
     if ($this->messages != '') {
         $this->loadLang();
     }
     // This is for the js and css auto import support
     $this->jsFolder = $this->config->item('js_folder');
     $this->cssFolder = $this->config->item('css_folder');
     $this->bootstrapFolder = $this->config->item('bootstrap_folder');
     $this->datatablesFloder = $this->config->item('datatables_folder');
     $this->use_less = $this->config->item('use_less');
     // This is used for hacking smarty view
     $this->load->spark('smartyview/0.0.1');
     $arr = obj2array($this->smartyview);
     $this->smarty = $arr['smarty'];
     $this->smarty->addPluginsDir(APPPATH . 'views/smarty_plugins');
     $this->jsFiles = array();
     $this->cssFiles = array();
 }
 /**
  * While customer uses SNS Account to login with gateway at first time
  * @param $oResponse    Oauth response data
  * @param $serial       gateway's serial number
  * @param $sProvider    kind of Oauth
  * @return array
  * @author jake
  * @since 2014-07-31
  */
 public function addNewSnsAccount($oResponse, $serial, $mac, $sProvider, $master = FALSE, $user_id = '')
 {
     $CI =& get_instance();
     $info = array();
     $group = $this->group_model->getUserGroup();
     $group_id = $group->id;
     $oSnsAccount = copy_new($oResponse, $sProvider . '_Provider');
     $aResponse = get_object_vars($oResponse);
     $aSnsAccount = $oSnsAccount->convertToBasic($aResponse, $oResponse);
     $user_info = array('email_address' => $aSnsAccount['uid'] . '@pinet.co', 'password' => 'password', 'username' => substr($aSnsAccount['uid'], 0, 20), 'user_type' => -1, 'group_id' => $group_id, 'name' => $aSnsAccount['nickname'], 'mobile' => '', 'sex' => $aSnsAccount['gender'], 'contact_name' => $aSnsAccount['nickname'], 'contact_country' => '', 'contact_province' => isset($oResponse->province) ? $oResponse->province : '', 'contact_city' => isset($oResponse->city) ? $oResponse->city : '', 'contact_street' => '', 'contact_postalcode' => '', 'contact_profile' => '');
     if (!$master) {
         $user_id = $this->user_model->register($user_info);
     }
     if ($master && !$user_id) {
         $user_id = $this->user_model->getUserByName($this->session->userdata('email_address'));
     }
     $CI->log('Add new account from ' . $sProvider . ' for ' . $user_id);
     $aSnsAccount['user_id'] = $user_id;
     $info['sns_account_id'] = $this->insert($aSnsAccount);
     $device = $this->device_model->getByMac($mac);
     if ($device) {
         $device->owner_id = $user_id;
         $this->device_model->update($device->id, obj2array($device));
         $info['device_id'] = $device->id;
     } else {
         $device = $this->device_model->getOrCreate($serial, $user_id, $mac);
         $info['device_id'] = $device->id;
     }
     return $info;
 }
Example #12
0
 /**
  * 请求人人网服务器,并获得数据<br />
  * @param string $method 请求的方法
  * @param array $params 可选的参数
  * @return array
  * method 方法:<br />
  * connect.getUnconnectedFriendsCount 此方法返回当前用户在此站点上,但还没有建立connect关系的好友数量<br />
  * connect.registerUsers 用来建立站点用户和校内用户之间的映射关系<br />
  * connect.unregisterUsers 删除站点用户和校内用户之间的映射关系<br />
  * friends.areFriends 判断两组用户是否互为好友关系,比较的两组用户数必须相等。<br />
  * friends.get 得到当前登录用户的好友列表,得到的只是含有好友id的列表。<br />
  * friends.getFriends 得到当前登录用户的好友列表。<br />
  * friends.getAppFriends 查询当前用户安装某个应用的好友列表。此接口在新的0.7版本以后提供使用中<br />
  * invitations.createLink 创建站外邀请的链接地址<br />
  * invitations.getInfo 根据邀请的新用户id得到此次邀请的详细信息(邀请人、邀请时间、被邀请人)<br />
  * notifications.send 给指定的用户发送通知<br />
  * notifications.sendEmail 在取得用户的授权后,给用户发送Email。<br />
  * pages.isFan 判断用户是否为Page(公共主页)的粉丝<br />
  * users.getInfo 得到用户信息,此接口在新的0.5版本以后中增加返回是否为星级和紫豆用户节点<br />
  * users.getLoggedInUser 得到当前session的用户ID<br />
  * users.hasAppPermission 根据用户的id,以及相应在人人网的操作权限(接收email,更新状态等),来判断用户是否可以进行此操作,此接口在新的0.8版本以后提供使用<br />
  * users.isAppUser 判断用户是否已对App授权
  */
 function call_api($method, $params = array())
 {
     $post_body = $this->post_body($method, $params);
     //echo $post_body,"\n\n";
     if (function_exists('curl_init')) {
         $request = curl_init();
         curl_setopt($request, CURLOPT_URL, $this->host);
         curl_setopt($request, CURLOPT_POST, 1);
         curl_setopt($request, CURLOPT_POSTFIELDS, $post_body);
         curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
         $result = curl_exec($request);
         curl_close($request);
     } else {
         $context = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded' . "\r\n" . 'User-Agent: Renren API PHP5 Client 1.1 ' . "\r\n" . 'Content-length: ' . strlen($post_body), 'content' => $post_body));
         $contextid = stream_context_create($context);
         $sock = fopen($this->host, 'r', false, $contextid);
         if ($sock) {
             $result = '';
             while (!feof($sock)) {
                 $result .= fgets($sock, 4096);
             }
             fclose($sock);
         }
     }
     $result = obj2array(json_decode($result));
     return $result;
 }
Example #13
0
 /**
  * Association functions
  */
 private function parse_has($prop, $params)
 {
     $params = obj2array($params);
     if (empty($params['foreign_key'])) {
         $params['foreign_key'] = substr(self::t(), 0, strlen(self::t()) - 1) . '_id';
     }
     $conds[] = $params['foreign_key'] . " = ?";
     unset($params['foreign_key']);
     $args['find_params']['conditions'] = array($this->id);
     if (!empty($params['conditions'])) {
         $conds[] = array_shift($params['conditions']);
         foreach ($params['conditions'] as $c) {
             $args['find_params']['conditions'][] = $c;
         }
         unset($c);
         unset($params['conditions']);
     }
     $conds = implode(' AND ', $conds);
     array_unshift($args['find_params']['conditions'], $conds);
     $args['find_params'] = array_merge($args['find_params'], $params);
     return $args;
 }
Example #14
0
 function process()
 {
     if (!isset($this->gpx) || !file_exists($this->gpx)) {
         $this->_err[] = "no gpx file input";
         return false;
     }
     $xml = simplexml_load_file($this->gpx);
     $arr = obj2array($xml);
     // 1. 取得 bounds, 轉換成 twd67 最近的 bounds
     //list($x,$y,$x1,$y1) = $this->get_bound($arr);
     list($x, $y, $x1, $y1) = $this->get_bbox(file_get_contents($this->gpx));
     if ($this->taiwan == 0) {
         $this->_err[] = "超出台澎範圍或檔案剖析有誤,請回報";
         return false;
     }
     if ($this->taiwan == 1) {
         list($tx, $ty) = proj_geto672(array($x, $y));
         list($tx1, $ty1) = proj_geto672(array($x1, $y1));
     } else {
         list($tx, $ty) = proj_geto672_ph(array($x, $y));
         list($tx1, $ty1) = proj_geto672_ph(array($x1, $y1));
     }
     // 若是自動 get_bound 的話  多 expend 一格
     if (isset($this->input_bound67['x'])) {
         // 免算
         $tl = array($this->input_bound67['x'], $this->input_bound67['y']);
         $br = array($this->input_bound67['x1'], $this->input_bound67['y1']);
     } else {
         // 如果需要多 index 的話, 才 expend
         // 並且不是範圍已經輸入了
         if ($this->show_label_wpt == 1) {
             $expend = 1000;
         } else {
             $expend = 0;
         }
         /* 四邊都 expend
         $tl = array( floor($tx / 1000)*1000 - $expend, ceil($ty / 1000)*1000 + $expend);
         $br = array( ceil($tx1 / 1000)*1000 + $expend, floor($ty1 / 1000)*1000 - $expend);
          */
         // 只在右手邊 expend
         $tl = array(floor($tx / 1000) * 1000, ceil($ty / 1000) * 1000);
         $br = array(ceil($tx1 / 1000) * 1000 + $expend, floor($ty1 / 1000) * 1000);
         if ($this->do_fit_a4 == 1) {
             list($tl, $br) = $this->fit_a4($tl, $br);
         }
     }
     // 檢查一下是不是太大範圍
     if ($br[0] - $tl[0] >= $this->limit['km_x'] || $tl[1] - $br[1] >= $this->limit['km_y']) {
         $this->_err[] = sprintf("超出範圍: x=%d y=%d (請刪除不需要之航跡)", $br[0] - $tl[0], $tl[1] - $br[1]);
         return false;
     }
     // 計算字型比例 依照若是標準地圖產生器出圖, 18px (1km 315px)
     $this->fontsize = intval(18 * ($this->width / (($br[0] - $tl[0]) / 1000) / 315));
     // 若是產生縮圖
     if ($this->fontsize < $this->default_fontsize) {
         $this->fontsize = $this->default_fontsize;
     }
     // 存入 bounds
     $this->bound_twd67 = array("tl" => $tl, "br" => $br, "ph" => $this->taiwan == 2 ? 1 : 0);
     if ($this->taiwan == 1) {
         $this->bound = array("tl" => proj_67toge2($tl), "br" => proj_67toge2($br));
     } else {
         $this->bound = array("tl" => proj_67toge2_ph($tl), "br" => proj_67toge2_ph($br));
     }
     // 計算比例
     $this->ratio['x'] = $this->width / ($this->bound['br'][0] - $this->bound['tl'][0]);
     // 經緯度比例這樣會出錯
     //$this->height = round(($this->bound['tl'][1] - $this->bound['br'][1])*$this->ratio);
     $this->height = ($tl[1] - $br[1]) / 1000 * 315;
     $this->ratio['y'] = $this->height / ($this->bound['tl'][1] - $this->bound['br'][1]);
     // 2. 取得所有 trk point 的高度 作為 colorize trk 的依據
     // $this->dump();
     // 像 oruxmap 會產生只有一層的 trk, 而不會有 trk 的 array => 為了不想重寫 parser, 放到 array 去
     if (isset($arr['trk']['trkseg'])) {
         $arr['trk'][0] = $arr['trk'];
     }
     // 共有多少 tracks?
     $total_tracks = count($arr['trk']);
     $min = 8000;
     $max = 0;
     for ($i = 0; $i < $total_tracks; $i++) {
         if (!isset($arr['trk'][$i]['name'])) {
             // skip track without "name"
             // echo "no name:" . var_dump($arr['trk']);
             continue;
         }
         $this->track[$i] = array("name" => $arr['trk'][$i]['name']);
         $j = 0;
         foreach ($arr['trk'][$i]['trkseg']['trkseg'] as $trk_point) {
             // skip route/track without '@attributes'
             // echo "get point:";
             // print_r($trk_point);
             if (!isset($trk_point['@attributes']['lon'])) {
                 if (!isset($trk_point['trkpt']['lon'])) {
                     continue;
                 } else {
                     $trk_point['@attributes']['lon'] = $trk_point['trkpt']['lon'];
                     $trk_point['@attributes']['lat'] = $trk_point['trkpt']['lat'];
                 }
             }
             if ($trk_point['@attributes']['lon'] > $this->bound['br'][0] || $trk_point['@attributes']['lon'] < $this->bound['tl'][0] || $trk_point['@attributes']['lat'] > $this->bound['tl'][1] || $trk_point['@attributes']['lat'] < $this->bound['br'][1]) {
                 // echo "oob!!!!!\n";
                 continue;
             }
             if (isset($trk_point['ele'])) {
                 // 如果高度小於 0
                 if ($trk_point['ele'] < 0) {
                     $trk_point['ele'] = 0;
                     $arr['trk'][$i]['trkseg']['trkseg']['ele'] = 0;
                 }
                 if ($trk_point['ele'] < $min) {
                     $min = $trk_point['ele'];
                 } else {
                     if ($trk_point['ele'] > $max) {
                         $max = $trk_point['ele'];
                     }
                 }
             } else {
                 $trk_point['ele'] = -100;
             }
             $this->track[$i]['point'][$j] = $trk_point;
             $this->track[$i]['point'][$j]['rel'] = $this->rel_px($trk_point['@attributes']['lon'], $trk_point['@attributes']['lat']);
             $j++;
         }
         // 處理 track 的高度
     }
     $this->ele_bound = array($min, $max);
     //$this->dump();
     //$this->waypoint = $arr['wpt'];
     $j = 0;
     if (isset($arr['wpt'])) {
         foreach ($arr['wpt'] as $waypoint) {
             if ($waypoint['@attributes']['lon'] > $this->bound['br'][0] || $waypoint['@attributes']['lon'] < $this->bound['tl'][0] || $waypoint['@attributes']['lat'] > $this->bound['tl'][1] || $waypoint['@attributes']['lat'] < $this->bound['br'][1]) {
                 continue;
             }
             $this->waypoint[$j] = $waypoint;
             $this->waypoint[$j]['rel'] = $this->rel_px($waypoint['@attributes']['lon'], $waypoint['@attributes']['lat']);
             if ($this->taiwan == 1) {
                 $this->waypoint[$j]['tw67'] = proj_geto672(array($waypoint['@attributes']['lon'], $waypoint['@attributes']['lat']));
             } else {
                 $this->waypoint[$j]['tw67'] = proj_geto672_ph(array($waypoint['@attributes']['lon'], $waypoint['@attributes']['lat']));
             }
             $j++;
         }
     }
     unset($arr);
     //$this->dump();
     return true;
 }
Example #15
0
 /**
  * Get a list of entities, eg one of: tasks, comments, timeSheets, projects et al. See also this::get_list_help()
  * @param string $entity the entity of which to get a list
  * @param array $options the various filter options to apply see: ${entity}/lib/${entity}.inc.php -> get_list_filter().
  * @return array the list of entities
  */
 public function get_list($entity, $options = array())
 {
     $current_user =& singleton("current_user");
     if (class_exists($entity)) {
         $options = obj2array($options);
         $e = new $entity();
         if (method_exists($e, "get_list")) {
             ob_start();
             $rtn = $entity::get_list($options);
             $echoed = ob_get_contents();
             if (!$rtn && $echoed) {
                 return array("error" => $echoed);
             } else {
                 if (isset($rtn["rows"])) {
                     return $rtn["rows"];
                 } else {
                     return $rtn;
                 }
             }
         } else {
             die("Entity method '" . $entity . "::get_list()' does not exist.");
         }
     } else {
         die("Entity '" . $entity . "' does not exist.");
     }
 }
 public function testObj2Array()
 {
     $the_text = 'Jack';
     $example = new DummyExample($the_text);
     $arr = obj2array($example);
     $this->assertEquals($arr['you_can_not_see_me'], $the_text);
 }
Example #17
0
 /** }
  * Api methods? {
  */
 static function batch_api_data($posts, $options = array())
 {
     foreach ($posts as $post) {
         $result['posts'][] = $post->api_attributes();
     }
     if (empty($options['exclude_pools'])) {
         $pool_posts = Pool::get_pool_posts_from_posts($posts);
         // $pools = ;
         $result['pools'] = obj2array(Pool::get_pools_from_pool_posts($pool_posts));
         foreach ($pool_posts as $pp) {
             $result['pool_posts'][] = $pp->api_attributes();
         }
     }
     if (empty($options['exclude_tags'])) {
         $result['tags'] = Tag::batch_get_tag_types_for_posts($posts);
     }
     if (!empty($options['user'])) {
         $user = $options['user'];
     } else {
         $user = User::$current;
     }
     # Allow loading votes along with the posts.
     #
     # The post data is cachable and vote data isn't, so keep this data separate from the
     # main post data to make it easier to cache API output later.
     if (empty($options['exclude_votes'])) {
         $vote_map = array();
         if (!empty($posts)) {
             foreach ($posts as $p) {
                 $post_ids[] = $p->id;
             }
             $post_ids = implode(',', $post_ids);
             $sql = sprintf("SELECT v.* FROM post_votes v WHERE v.user_id = %d AND v.post_id IN (%s)", $user->id, $post_ids);
             $votes = PostVotes::find_by_sql(array($sql));
             foreach ($votes as $v) {
                 $vote_map[$v->post_id] = $v->score;
             }
         }
         $result['votes'] = $vote_map;
     }
     return $result;
 }
 public function findAllCustomers($filters = null)
 {
     $this->api_extension = 'customers.json';
     $this->method = 'GET';
     $this->query = '';
     $queryFilters = '';
     if (!empty($filters)) {
         if (is_object($filters)) {
             $filters = obj2array($filters);
         }
         if (is_array($filters)) {
             foreach ($filters as $field => $filter) {
                 $queryFilters .= $field . '=' . $filter . '&';
             }
             $this->query .= $queryFilters;
         } else {
             $this->query .= $filters;
         }
     }
     return $this->submit();
 }
Example #19
0
/**
 * 将obj深度转化成array
 * 
 * @param  $obj 要转换的数据 可能是数组 也可能是个对象 还可能是一般数据类型
 * @return array || 一般数据类型
 */
function obj2array($obj)
{
    if (is_array($obj)) {
        foreach ($obj as &$value) {
            $value = obj2array($value);
        }
        return $obj;
    } elseif (is_object($obj)) {
        $obj = get_object_vars($obj);
        return obj2array($obj);
    } else {
        return $obj;
    }
}
 public function updateSnsSettings($user_id, $data)
 {
     $settings = $this->getSnsSettings($user_id, $data['oauth_type']);
     if (count($settings)) {
         $setting = $settings[0];
         $id = $setting->id;
         $setting = obj2array($setting);
         $setting['type'] = $data['status'];
         if ($data['poi_id']) {
             $setting['poi_id'] = $data['poi_id'];
         }
         if ($data['status'] >= 1) {
             $data['status'] = 1;
         }
         $setting['status'] = $data['status'];
         $sns_config['text'] = $data[$data['oauth_type'] . '_message_content'];
         if (isset($data[$data['oauth_type'] . '_picture'])) {
             $path = 'static/uploads/' . $data[$data['oauth_type'] . '_picture'];
             $file = pathinfo($path);
             $name = $file['filename'];
             $ext = $file['extension'];
             $sns_config['img'] = array('path' => $path, 'name' => $name . '.' . $ext, 'mime' => 'image/' . $ext);
         }
         $setting['content'] = serialize($sns_config);
         return $this->update($id, $setting);
     }
     return 0;
 }
Example #21
0
/**
 * 多级对象转数组
 * @param obj $object 待转换的对象
 * @return array
 */
function obj2array($object = NULL)
{
    $array = (array) $object;
    foreach ($array as $key => $val) {
        //判断是否为对象或数组,因为数组中可能还会存在对象
        if (is_object($val) || is_array($val)) {
            $val = obj2array($val);
        }
        $array[$key] = $val;
    }
    return $array;
}
Example #22
0
 public function __call($name, $arg)
 {
     //如果APIMap不存在相应的api
     if (empty($this->APIMap[$name])) {
         throw new Exception("不存在的API: <span style='color:red;'>{$name}</span>");
     }
     //从APIMap获取api相应参数
     $baseUrl = $this->APIMap[$name][0];
     $argsList = $this->APIMap[$name][1];
     $method = isset($this->APIMap[$name][2]) ? $this->APIMap[$name][2] : "GET";
     if (empty($arg)) {
         $arg[0] = null;
     }
     //对于get_tenpay_addr,特殊处理,php json_decode对\xA312此类字符支持不好
     if ($name == "get_tenpay_addr") {
         $this->oauth->decode_json = false;
         $responseArr = $this->simple_json_parser($this->_applyAPI($arg[0], $argsList, $baseUrl, $method));
     } else {
         $responseArr = obj2array($this->_applyAPI($arg[0], $argsList, $baseUrl, $method));
     }
     //检查返回ret判断api是否成功调用
     if ($responseArr['ret'] == 0) {
         return $responseArr;
     } else {
         throw new Exception($responseArr['msg']);
     }
 }