/** * XML转成数组 (XML to array) * @param string $xml XML字符串 * @return array */ function xml_to_array($xml) { if (stripos($xml, '<?xml') !== false) { $xml = preg_replace('/<\\?xml.*?\\?>/is', '', $xml); } $result = array(); $pattern = '/<\\s*(.*?)(\\s+.*?)?>(.*?)<\\s*\\/\\s*\\1\\s*>/is'; preg_match_all($pattern, $xml, $matches); if (!empty($matches[3][0])) { foreach ($matches[3] as $key => $value) { preg_match_all($pattern, $value, $matches_v); if (!empty($matches_v[3][0])) { $ret = xml_to_array($value); } else { $ret = $value; } if (array_key_exists($matches[1][$key], $result) && !empty($result[$matches[1][$key]])) { if (is_array($result[$matches[1][$key]]) && array_key_exists(0, $result[$matches[1][$key]])) { $result[$matches[1][$key]][] = $ret; } else { $result[$matches[1][$key]] = array($result[$matches[1][$key]], $ret); } } else { $result[$matches[1][$key]] = $ret; } } } return $result; }
public function sendSMS() { $post_code = isset($_POST['post_code']) ? $_POST['post_code'] : ''; $phone_num = isset($_POST['telephone']) ? $_POST['telephone'] : ''; // $post_code='U2FsdGVkX1+zY61T/9h6KxyTBWVwbNR9Z01QjZN5EmT5BzDIEROXMFb9it8VgTrW // Yippi/B79Y0u+ZXJMwSLXGo8imoz9OTrB3k0uhvjIEyi4pF27xCm/Cg0pW0T3SoS // 9oCORpIFF/600rCAvhDsMOADCKCBtvLhpL4YpLKHQ3/jqQFsjWF8YUVMc0x9LtPa // 3eeGQIFsdRDr2nSWMlnGQExvNvyKnfLWUrH+YkJDIJlYzXihdv32yMw+vCf/DDa2 // Oq4CU2BkzLqff4IjGmA/9+FP2SS19kDMzdf5e1DO132QBhHDrLy1ffrSIabFRHVf // SVDsy1qZSsC7Ea24RdmQBQ=='; if ($phone_num == '') { return show(103, '手机号不能为空'); } if (preg_match('/^1[34578][0-9]{9}$/', $phone_num)) { } else { return show(101, '手机号格式不正确'); } $mobile_code = random(6, 1); //random()是公共自定义函数 $target = "http://106.ihuyi.cn/webservice/sms.php?method=Submit"; $post_data = "account=cf_guoqingyu&password=luping521&mobile=" . $phone_num . "&content=" . rawurlencode("您的校验码是:" . $mobile_code . "。请不要把校验码泄露给其他人。如非本人操作,可不用理会!"); //密码可以使用明文密码或使用32位MD5加密 $gets = xml_to_array(Post($post_data, $target)); if ($gets['SubmitResult']['code'] == 2) { S('phone_num', $phone_num, 60); S($phone_num . 'mobile_code', $mobile_code, 60); return show(104, '发送成功'); } else { return show(102, '发送失败'); } }
function xml_to_array($root) { $result = array(); if ($root->hasAttributes()) { $attrs = $root->attributes; foreach ($attrs as $attr) { $result['@attributes'][$attr->name] = $attr->value; } } if ($root->hasChildNodes()) { $children = $root->childNodes; if ($children->length == 1) { $child = $children->item(0); if ($child->nodeType == XML_TEXT_NODE) { $result['_value'] = $child->nodeValue; return count($result) == 1 ? $result['_value'] : $result; } } $groups = array(); foreach ($children as $child) { if (!isset($result[$child->nodeName])) { $result[$child->nodeName] = xml_to_array($child); } else { if (!isset($groups[$child->nodeName])) { $result[$child->nodeName] = array($result[$child->nodeName]); $groups[$child->nodeName] = 1; } $result[$child->nodeName][] = xml_to_array($child); } } } return $result; }
function xml_to_array($xml) { $reg = "/<(\\w+)[^>]*?>([\\x00-\\xFF]*?)<\\/\\1>/"; if (preg_match_all($reg, $xml, $matches)) { $count = count($matches[0]); $arr = array(); for ($i = 0; $i < $count; $i++) { $key = $matches[1][$i]; $val = xml_to_array($matches[2][$i]); // 递归 if (array_key_exists($key, $arr)) { if (is_array($arr[$key])) { if (!array_key_exists(0, $arr[$key])) { $arr[$key] = array($arr[$key]); } } else { $arr[$key] = array($arr[$key]); } $arr[$key][] = $val; } else { $arr[$key] = $val; } } return $arr; } else { return $xml; } }
function xml_to_array($xml) { $fils = 0; $tab = false; $array = array(); foreach ($xml->children() as $key => $value) { $child = xml_to_array($value); //To deal with the attributes //foreach ($node->attributes() as $ak => $av) { // $child[$ak] = (string)$av; //} //Let see if the new child is not in the array if ($tab == false && in_array($key, array_keys($array))) { //If this element is already in the array we will create an indexed array $tmp = $array[$key]; $array[$key] = NULL; $array[$key][] = $tmp; $array[$key][] = $child; $tab = true; } elseif ($tab == true) { //Add an element in an existing array $array[$key][] = $child; } else { //Add a simple element $array[$key] = $child; } $fils++; } if ($fils == 0) { return (string) $xml; } return $array; }
function xml_to_array($xml_object) { $out = array(); foreach ((array) $xml_object as $index => $node) { $out[$index] = is_object($node) ? xml_to_array($node) : $node; } return (array) $out; }
protected function xml_to_array($xml_object) { if (defined('STRICT_TYPES') && CAMEL_CASE == '1') { return (array) self::parameters(['xml_object' => DT::TYPE_ARRAY])->call(__FUNCTION__)->with($xml_object)->returning(DT::TYPE_ARRAY); } else { return (array) xml_to_array($xml_object); } }
function discover_api() { // designed to run the built in api functions (if the exist) to get valid values for some api method calls $idTypes = new SimpleXMLElement($this->getIdTypes()); $this->idTypes = xml_to_array($idTypes, 'idTypeList', 'idName'); $relaTypes = new SimpleXMLElement($this->getRelaTypes()); $this->relaTypes = xml_to_array($relaTypes, 'relationTypeList', 'relationType'); $sourceTypes = new SimpleXMLElement($this->getSourceTypes()); $this->sourceTypes = xml_to_array($sourceTypes, 'sourceTypeList', 'sourceName'); }
function xmltoarray($xml) { if ($xml) { $arr = xml_to_array($xml); $key = array_keys($arr); return $arr[$key[0]]; } else { return ''; } }
/** * @ticket UT32 */ function test_items() { $this->go_to('/feed/'); $feed = $this->do_rss2(); $xml = xml_to_array($feed); // get all the rss -> channel -> item elements $items = xml_find($xml, 'rss', 'channel', 'item'); $posts = get_posts('numberposts=' . $this->post_count); // check each of the items against the known post data for ($i = 0; $i < $this->post_count; $i++) { // title $title = xml_find($items[$i]['child'], 'title'); $this->assertEquals($posts[$i]->post_title, $title[0]['content']); // link $link = xml_find($items[$i]['child'], 'link'); $this->assertEquals(get_permalink($posts[$i]->ID), $link[0]['content']); // comment link $comments_link = xml_find($items[$i]['child'], 'comments'); $this->assertEquals(get_permalink($posts[$i]->ID) . '#comments', $comments_link[0]['content']); // pub date $pubdate = xml_find($items[$i]['child'], 'pubDate'); $this->assertEquals(strtotime($posts[$i]->post_date), strtotime($pubdate[0]['content'])); // author $creator = xml_find($items[$i]['child'], 'dc:creator'); $this->assertEquals($this->author->user_nicename, $creator[0]['content']); // categories (perhaps multiple) $categories = xml_find($items[$i]['child'], 'category'); $cat_ids = wp_get_post_categories($post->ID); if (empty($cat_ids)) { $cat_ids = array(1); } // should be the same number of categories $this->assertEquals(count($cat_ids), count($categories)); // ..with the same names for ($j = 0; $j < count($cat_ids); $j++) { $this->assertEquals(get_cat_name($cat_ids[$j]), $categories[$j]['content']); } // GUID $guid = xml_find($items[$i]['child'], 'guid'); $this->assertEquals('false', $guid[0]['attributes']['isPermaLink']); $this->assertEquals($posts[$i]->guid, $guid[0]['content']); // description/excerpt $description = xml_find($items[$i]['child'], 'description'); $this->assertEquals(trim($posts[$i]->post_excerpt), trim($description[0]['content'])); // post content if (!$this->excerpt_only) { $content = xml_find($items[$i]['child'], 'content:encoded'); $this->assertEquals(trim(apply_filters('the_content', $posts[$i]->post_content)), trim($content[0]['content'])); } // comment rss $comment_rss = xml_find($items[$i]['child'], 'wfw:commentRss'); $this->assertEquals(html_entity_decode(get_post_comments_feed_link($posts[$i]->ID)), $comment_rss[0]['content']); } }
public function testToArray() { $content = '<foo> <bar hello="hello world"> Hello </bar> </foo>'; $array_data = xml_to_array($content); $this->assertTrue(is_array($array_data)); // Array //( // [0] => Array // ( // [tag] => FOO // [type] => open // [level] => 1 // [value] => // // ) // // [1] => Array // ( // [tag] => BAR // [type] => complete // [level] => 2 // [attributes] => Array // ( // [HELLO] => hello world // ) // // [value] => Hello // ) // // [2] => Array // ( // [tag] => FOO // [value] => // [type] => cdata // [level] => 1 // ) // // [3] => Array // ( // [tag] => FOO // [type] => close // [level] => 1 // ) // // ) //) }
function get_xml($id) { $folder = $this->dir_root . "plugins/" . $id . "/"; if (!is_dir($folder)) { return false; } $rs = array(); if (is_file($folder . "config.xml")) { $rs = xml_to_array(file_get_contents($folder . "config.xml")); } $rs["id"] = $id; $rs["path"] = $folder; return $rs; }
function send_sms($phoneNumber, $message) { global $smsUserName, $smsPassword; $target = "http://106.ihuyi.cn/webservice/sms.php?method=Submit"; $userName = $smsUserName; $passWord = $smsPassword; $post_data = "account={$userName}&password={$passWord}&mobile={$phoneNumber}&content=" . rawurlencode($message); $gets = xml_to_array(send_server($post_data, $target)); $ret = ""; if ($gets['SubmitResult']['code'] == 2) { return true; } else { printResultByMessage($gets['SubmitResult']['msg'], 109); } }
public function actionMonitorTask($task_id) { $task = DcmdTask::findOne($task_id); ///非系统管理员只能操作同一产品组的该任务 if (Yii::$app->user->getIdentity()->admin != 1) { if ($task->opr_uid != Yii::$app->user->getId()) { ///判断是否为同一产品组 $app = DcmdApp::findOne($task->app_id); $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $app['svr_gid']]); if ($query == NULL) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!"); return $this->redirect(array('dcmd-task/index')); } } } else { ///系统管理员产品所属同一系统组 $app = DcmdApp::findOne($task->app_id); $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $app['sa_gid']]); if ($query == NULL) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!"); return $this->redirect(array('dcmd-task/index')); } } if (Yii::$app->request->post()) { $timeout = Yii::$app->request->post()['timeout']; $auto = Yii::$app->request->post()['auto']; $concurrent_rate = Yii::$app->request->post()['concurrent_rate']; $this->updateTask($task_id, $timeout, $auto, $concurrent_rate); ////var_dump(Yii::$app->request->post());exit; } ///获取产品名称 ///$query = DcmdService::findOne($task->svr_id); $app_id = $task->app_id; /// $query->app_id; ///$query = DcmdApp::findOne($app_id); $app_name = $task->app_name; $ret = xml_to_array($task->task_arg); $args = ""; if (is_array($ret['env'])) { foreach ($ret['env'] as $k => $v) { $args .= $k . '=' . $v . " ; "; } } return $this->render('monitor', ['task_id' => $task_id, 'task' => $task, 'args' => $args, 'app_name' => $app_name, 'app_id' => $app_id]); }
public static function xml_to_array($xml) { $reg = "/<(\\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/"; if (preg_match_all($reg, $xml, $matches)) { $count = count($matches[0]); for ($i = 0; $i < $count; $i++) { $subxml = $matches[2][$i]; $key = $matches[1][$i]; if (preg_match($reg, $subxml)) { $arr[$key] = xml_to_array($subxml); } else { $arr[$key] = $subxml; } } } return $arr; }
function invokeGetMatchingProductForId(MarketplaceWebServiceProducts_Interface $service, $request) { try { $response = $service->GetMatchingProductForId($request); $dom = new DOMDocument(); $dom->loadXML($response->toXML()); $arrResult = xml_to_array($dom); return $arrResult; } catch (MarketplaceWebServiceProducts_Exception $ex) { echo "Caught Exception: " . $ex->getMessage() . "\n"; echo "Response Status Code: " . $ex->getStatusCode() . "\n"; echo "Error Code: " . $ex->getErrorCode() . "\n"; echo "Error Type: " . $ex->getErrorType() . "\n"; echo "Request ID: " . $ex->getRequestId() . "\n"; echo "XML: " . $ex->getXML() . "\n"; echo "ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n"; } }
/** * 加载数据 数组 或XML * @param array $data 格式: 微信键名=>键值 * @param xml $data 格式: 微信标准的XML * @return Object */ public function load($data, $denyxml) { if (is_array($data)) { $this->type = 0; $this->data = $data; } else { $postObj = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA); if ($postObj instanceof SimpleXMLElement) { $packet = array(); $packet = xml_to_array($postObj, array('ToUserName', 'FromUserName', 'CreateTime')); $this->type = 1; $this->data = $packet; } else { $this->type = 2; $this->data['Content'] = $data; } } return $this; }
function GetProductInfoByTitle($title) { $conf = new GenericConfiguration(); try { $conf->setCountry('com')->setAccessKey(AWS_API_KEY)->setSecretKey(AWS_API_SECRET_KEY)->setAssociateTag(AWS_ASSOCIATE_TAG); } catch (\Exception $e) { echo $e->getMessage(); } $apaiIO = new ApaiIO($conf); $search = new Search(); // $lookup->setItemId('B0040PBK32,B00MEKHLLA'); $search->setCategory('Books'); $search->setKeywords($title); $formattedResponse = $apaiIO->runOperation($search); $dom = new DOMDocument(); $dom->loadXML($formattedResponse); $arrResponse = xml_to_array($dom); return $arrResponse; }
public function send($nickName, $sendName, $openid, $minValue, $maxValue, $wishing, $actName, $remark) { //发送红包 $this->nickName = $nickName; $this->sendName = $sendName; $this->openid = $openid; $this->minValue = $minValue; $this->maxValue = $maxValue; $this->wishing = $wishing; $this->remake = $remark; $this->actName = $actName; $sendValue = rand($minValue, $maxValue); $xmlData = $this->createXml($sendValue); $returnStr = xml_to_array($this->postXmlSSLCurl($xmlData, $this->url)); //正确返回信息,写返回状态SUCCESS,写库 if (isset($returnStr['return_code']) && $returnStr['return_code'] == "SUCCESS" && $returnStr['result_code'] == "SUCCESS") { $WechatRedpacketModel = new WechatRedpacketModel(); $WechatRedpacketModel->addData($nickName, $sendName, $openid, $minValue, $maxValue, $sendValue, $wishing, $actName, $remark, $returnStr); } }
/** * Displays a single DcmdTaskHistory model. * @param integer $id * @return mixed */ public function actionView($id) { $task = $this->findModel($id); $app_id = $task->app_id; ////$query->app_id; $app_name = $task->app_name; $ret = xml_to_array($task->task_arg); $args = ""; if (is_array($ret['env'])) { foreach ($ret['env'] as $k => $v) { $args .= $k . '=' . $v . " ; "; } } ///服务池子 $query = DcmdTaskServicePoolHistory::find()->andWhere(['task_id' => $id]); $svr_dataProvider = new ActiveDataProvider(['query' => $query]); $svr_searchModel = new DcmdTaskServicePoolHistorySearch(); ///未运行的任务 $con = array('task_id' => $id, 'state' => 0); $query = DcmdTaskNodeHistory::find()->andWhere($con)->orderBy("utime desc")->limit(5); $init_dataProvider = new ActiveDataProvider(['query' => $query]); $init_searchModel = new DcmdTaskNodeHistorySearch(); ///在运行 $con = array('task_id' => $id, 'state' => 1); $query = DcmdTaskNodeHistory::find()->andWhere($con)->orderBy("utime desc")->limit(5); $run_dataProvider = new ActiveDataProvider(['query' => $query]); $run_searchModel = new DcmdTaskNodeHistorySearch(); ///失败任务 $con = array('task_id' => $id, 'state' => 3); $query = DcmdTaskNodeHistory::find()->andWhere($con)->orderBy("utime desc")->limit(5); $fail_dataProvider = new ActiveDataProvider(['query' => $query]); $fail_searchModel = new DcmdTaskNodeHistorySearch(); ///完成任务 $con = array('task_id' => $id, 'state' => 2); $query = DcmdTaskNodeHistory::find()->andWhere($con)->orderBy("utime desc")->limit(5); $suc_dataProvider = new ActiveDataProvider(['query' => $query]); $suc_searchModel = new DcmdTaskNodeHistorySearch(); return $this->render('monitor', ['task' => $task, 'app_id' => $app_id, 'app_name' => $app_name, 'args' => $args, 'svr_dataProvider' => $svr_dataProvider, 'svr_searchModel' => $svr_searchModel, 'init_dataProvider' => $init_dataProvider, 'init_searchModel' => $init_searchModel, 'run_dataProvider' => $run_dataProvider, 'run_searchModel' => $run_searchModel, 'fail_dataProvider' => $fail_dataProvider, 'fail_searchModel' => $fail_searchModel, 'suc_dataProvider' => $suc_dataProvider, 'suc_searchModel' => $suc_searchModel]); }
public function indexAction() { //不进行任何的过滤,获取XML数据,并转化为数组 $xml = I('globals.HTTP_RAW_POST_DATA', '', false); if ($xml == '') { return; } $postArr = xml_to_array($xml); /* * 验证签名的有效性,证明是微信官方发回的文件 * 很重要 * 不然会有服务欺骗 * 验证成功,返回success * 不成功,直接跳出 */ $sign = $postArr['sign']; unset($postArr['sign']); if ($sign == get_wechat_sign($postArr)) { echo 'SUCCESS'; } else { return; } /* * 依据PAYID进行订单状态的更新操作. * 1.更新支付ID表 * 2.更新订单表 */ $orderRelation = new OrderRelationModel(); $res = $orderRelation->saveInfo($postArr); //返回值为false,证明数据重复提交,直接退出 if ($res == false) { return; } $orderForm = new OrderFormModel(); $orderForm->setPostArr($postArr); $orderForm->saveInfo(); return; }
private function showTaskArg($arg_xml, $task_cmd_id) { $content = ""; /// $ar = xml_to_array($arg_xml); $args = array(); if (array_key_exists('env', $ar)) { $args = $ar['env']; } $query = DcmdTaskCmdArg::find()->andWhere(['task_cmd_id' => $task_cmd_id])->asArray()->all(); if ($query) { ///获取模板参数 $content = '<table class="table table-striped table-bordered detail-view"> <tr><td>参数名称</td> <td>是否可选</td> <td>值</td></tr>'; foreach ($query as $item) { $content .= "<tr><td>" . $item['arg_name'] . '</td>'; $content .= "<td>"; if ($item['optional'] == 0) { $content .= "否"; } else { $content .= "是"; } $content .= "</td>"; if (is_array($args) && array_key_exists($item['arg_name'], $args)) { $content .= "<td><input name='Arg" . $item['arg_name'] . "' type='text' value='" . $args[$item['arg_name']] . "' >"; } else { $content .= "<td><input name='Arg" . $item['arg_name'] . "' type='text' value='' >"; } $content .= "</td><tr>"; } $content .= "</table>"; } return $content; }
function generate_updates_cache() { global $forum_db, $forum_config; $return = ($hook = get_hook('ch_fn_generate_updates_cache_start')) ? eval($hook) : null; if ($return != null) { return; } // Get a list of installed hotfix extensions $query = array('SELECT' => 'e.id', 'FROM' => 'extensions AS e', 'WHERE' => 'e.id LIKE \'hotfix_%\''); ($hook = get_hook('ch_fn_generate_updates_cache_qr_get_hotfixes')) ? eval($hook) : null; $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); $num_hotfixes = $forum_db->num_rows($result); $hotfixes = array(); for ($i = 0; $i < $num_hotfixes; ++$i) { $hotfixes[] = urlencode($forum_db->result($result, $i)); } // Contact the punbb.informer.com updates service $result = get_remote_file('http://punbb.informer.com/update/?type=xml&version=' . urlencode($forum_config['o_cur_version']) . '&hotfixes=' . implode(',', $hotfixes), 8); // Make sure we got everything we need if ($result != null && strpos($result['content'], '</updates>') !== false) { if (!defined('FORUM_XML_FUNCTIONS_LOADED')) { require FORUM_ROOT . 'include/xml.php'; } $output = xml_to_array(forum_trim($result['content'])); $output = current($output); if (!empty($output['hotfix']) && is_array($output['hotfix']) && !is_array(current($output['hotfix']))) { $output['hotfix'] = array($output['hotfix']); } $output['cached'] = time(); $output['fail'] = false; } else { // If the update check failed, set the fail flag $output = array('cached' => time(), 'fail' => true); } // This hook could potentially (and responsibly) be used by an extension to do its own little update check ($hook = get_hook('ch_fn_generate_updates_cache_write')) ? eval($hook) : null; // Output update status as PHP code $fh = @fopen(FORUM_CACHE_DIR . 'cache_updates.php', 'wb'); if (!$fh) { error('Unable to write updates cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'.', __FILE__, __LINE__); } fwrite($fh, '<?php' . "\n\n" . 'if (!defined(\'FORUM_UPDATES_LOADED\')) define(\'FORUM_UPDATES_LOADED\', 1);' . "\n\n" . '$forum_updates = ' . var_export($output, true) . ';' . "\n\n" . '?>'); fclose($fh); }
function pun_repository_download_extension($ext_id, &$ext_data, $ext_path = FALSE) { global $base_url, $lang_pun_repository; ($hook = get_hook('pun_repository_download_extension_start')) ? eval($hook) : null; clearstatcache(); if (!$ext_path) { $ext_path = FORUM_ROOT . 'extensions/' . $ext_id; $extract_folder = FORUM_ROOT . 'extensions/'; $manifiest_path = $ext_path . '/manifest.xml'; } else { $extract_folder = $ext_path; $manifiest_path = $ext_path . '/' . $ext_id . '/manifest.xml'; } if (!is_dir($ext_path)) { // Create new directory with 777 mode if (@mkdir($ext_path) == false) { return sprintf($lang_pun_repository['Can\'t create directory'], $ext_path); } @chmod($ext_path, 0777); } else { return sprintf($lang_pun_repository['Directory already exists'], $ext_path); } // Download extension archive $pun_repository_archive = get_remote_file(PUN_REPOSITORY_URL . '/' . $ext_id . '/' . $ext_id . '.tgz', 10); if (empty($pun_repository_archive) || empty($pun_repository_archive['content'])) { rmdir($ext_path); return $lang_pun_repository['Extension download failed']; } // Save extension to file $pun_repository_archive_file = @fopen(FORUM_ROOT . 'extensions/' . $ext_id . '.tgz', 'wb'); if ($pun_repository_archive_file === false) { return $lang_pun_repository['No writting right']; } fwrite($pun_repository_archive_file, $pun_repository_archive['content']); fclose($pun_repository_archive_file); if (!defined('PUN_REPOSITORY_TAR_EXTRACT_INCLUDED')) { require 'pun_repository_tar_extract.php'; } // Extract files from archive $pun_repository_tar = new Archive_Tar_Ex(FORUM_ROOT . 'extensions/' . $ext_id . '.tgz'); if (!$pun_repository_tar->extract($extract_folder, 0777)) { $error = $lang_pun_repository['Can\'t extract']; if (isset($pun_repository_tar->errors)) { $error .= ' ' . $lang_pun_repository['Extract errors:'] . '<br />' . implode('<br />', $pun_repository_tar->errors); } unlink(FORUM_ROOT . 'extensions/' . $ext_id . '.tgz'); @pun_repository_rm_recursive($ext_path); return $error; } // Remove archive unlink(FORUM_ROOT . 'extensions/' . $ext_id . '.tgz'); // Verify downloaded and extracted extension $ext_data = xml_to_array(@file_get_contents($manifiest_path)); ($hook = get_hook('pun_repository_download_extension_end')) ? eval($hook) : null; return ''; }
private function _get_global_data() { // xpath $xpath = '//global'; $match = $this->_content_xml->xpath($xpath); if (!isset($match[0])) { return null; } return xml_to_array($match[0]); }
/** * Validate <entry> child elements. */ function test_entry_elements() { $this->go_to('/?feed=atom'); $feed = $this->do_atom(); $xml = xml_to_array($feed); // Get all the <entry> child elements of the <feed> element. $entries = xml_find($xml, 'feed', 'entry'); // Verify we are displaying the correct number of posts. $this->assertCount($this->post_count, $entries); // We Really only need to test X number of entries unless the content is different $entries = array_slice($entries, 1); // Check each of the desired entries against the known post data. foreach ($entries as $key => $entry) { // Get post for comparison $id = xml_find($entries[$key]['child'], 'id'); preg_match('/\\?p=(\\d+)/', $id[0]['content'], $matches); $post = get_post($matches[1]); // Author $author = xml_find($entries[$key]['child'], 'author', 'name'); $user = new WP_User($post->post_author); $this->assertEquals($user->display_name, $author[0]['content']); // Title $title = xml_find($entries[$key]['child'], 'title'); $this->assertEquals($post->post_title, $title[0]['content']); // Link rel="alternate" $link_alts = xml_find($entries[$key]['child'], 'link'); foreach ($link_alts as $link_alt) { if ('alternate' == $link_alt['attributes']['rel']) { $this->assertEquals(get_permalink($post), $link_alt['attributes']['href']); } } // Id $guid = xml_find($entries[$key]['child'], 'id'); $this->assertEquals($post->guid, $id[0]['content']); // Updated $updated = xml_find($entries[$key]['child'], 'updated'); $this->assertEquals(strtotime($post->post_modified_gmt), strtotime($updated[0]['content'])); // Published $published = xml_find($entries[$key]['child'], 'published'); $this->assertEquals(strtotime($post->post_date_gmt), strtotime($published[0]['content'])); // Category foreach (get_the_category($post->ID) as $term) { $terms[] = $term->name; } $categories = xml_find($entries[$key]['child'], 'category'); foreach ($categories as $category) { $this->assertTrue(in_array($category['attributes']['term'], $terms)); } unset($terms); // Content if (!$this->excerpt_only) { $content = xml_find($entries[$key]['child'], 'content'); $this->assertEquals(trim(apply_filters('the_content', $post->post_content)), trim($content[0]['content'])); } // Link rel="replies" $link_replies = xml_find($entries[$key]['child'], 'link'); foreach ($link_replies as $link_reply) { if ('replies' == $link_reply['attributes']['rel'] && 'application/atom+xml' == $link_reply['attributes']['type']) { $this->assertEquals(get_post_comments_feed_link($post->ID, 'atom'), $link_reply['attributes']['href']); } } } }
/** * @ticket 9134 */ function test_items_comments_closed() { add_filter('comments_open', '__return_false'); $this->go_to('/?feed=rss2'); $feed = $this->do_rss2(); $xml = xml_to_array($feed); // get all the rss -> channel -> item elements $items = xml_find($xml, 'rss', 'channel', 'item'); // check each of the items against the known post data foreach ($items as $key => $item) { // Get post for comparison $guid = xml_find($items[$key]['child'], 'guid'); preg_match('/\\?p=(\\d+)/', $guid[0]['content'], $matches); $post = get_post($matches[1]); // comment link $comments_link = xml_find($items[$key]['child'], 'comments'); $this->assertEmpty($comments_link); // comment rss $comment_rss = xml_find($items[$key]['child'], 'wfw:commentRss'); $this->assertEmpty($comment_rss); } remove_filter('comments_open', '__return_false'); }
$d = dir(FORUM_ROOT . 'extensions'); while (($entry = $d->read()) !== false) { if ($entry[0] != '.' && is_dir(FORUM_ROOT . 'extensions/' . $entry)) { if (preg_match('/[^0-9a-z_]/', $entry)) { $forum_page['ext_error'][] = '<div class="ext-error databox db' . ++$forum_page['item_num'] . '">' . "\n\t\t\t\t" . '<h3 class="legend"><span>' . sprintf($lang_admin_ext['Extension loading error'], forum_htmlencode($entry)) . '</span></h3>' . "\n\t\t\t\t" . '<p>' . $lang_admin_ext['Illegal ID'] . '</p>' . "\n\t\t\t" . '</div>'; ++$num_failed; continue; } else { if (!file_exists(FORUM_ROOT . 'extensions/' . $entry . '/manifest.xml')) { $forum_page['ext_error'][] = '<div class="ext-error databox db' . ++$forum_page['item_num'] . '">' . "\n\t\t\t\t" . '<h3 class="legend"><span>' . sprintf($lang_admin_ext['Extension loading error'], forum_htmlencode($entry)) . '<span></h3>' . "\n\t\t\t\t" . '<p>' . $lang_admin_ext['Missing manifest'] . '</p>' . "\n\t\t\t" . '</div>'; ++$num_failed; continue; } } // Parse manifest.xml into an array $ext_data = is_readable(FORUM_ROOT . 'extensions/' . $entry . '/manifest.xml') ? xml_to_array(file_get_contents(FORUM_ROOT . 'extensions/' . $entry . '/manifest.xml')) : ''; if (empty($ext_data)) { $forum_page['ext_error'][] = '<div class="ext-error databox db' . ++$forum_page['item_num'] . '">' . "\n\t\t\t\t" . '<h3 class="legend"><span>' . sprintf($lang_admin_ext['Extension loading error'], forum_htmlencode($entry)) . '<span></h3>' . "\n\t\t\t\t" . '<p>' . $lang_admin_ext['Failed parse manifest'] . '</p>' . "\n\t\t\t" . '</div>'; ++$num_failed; continue; } // Validate manifest $errors = validate_manifest($ext_data, $entry); if (!empty($errors)) { $forum_page['ext_error'][] = '<div class="ext-error databox db' . ++$forum_page['item_num'] . '">' . "\n\t\t\t\t" . '<h3 class="legend"><span>' . sprintf($lang_admin_ext['Extension loading error'], forum_htmlencode($entry)) . '</span></h3>' . "\n\t\t\t\t" . '<p>' . implode(' ', $errors) . '</p>' . "\n\t\t\t" . '</div>'; ++$num_failed; } else { if (!array_key_exists($entry, $inst_exts) || version_compare($inst_exts[$entry]['version'], $ext_data['extension']['version'], '!=')) { $forum_page['ext_item'][] = '<div class="ct-box info-box extension available">' . "\n\t\t\t" . '<h3 class="ct-legend hn">' . forum_htmlencode($ext_data['extension']['title']) . ' <em>' . $ext_data['extension']['version'] . '</em></h3>' . "\n\t\t\t" . '<ul class="data-list">' . "\n\t\t\t\t" . '<li><span>' . sprintf($lang_admin_ext['Extension by'], forum_htmlencode($ext_data['extension']['author'])) . '</span></li>' . ($ext_data['extension']['description'] != '' ? "\n\t\t\t\t" . '<li><span>' . forum_htmlencode($ext_data['extension']['description']) . '</span></li>' : '') . "\n\t\t\t" . '</ul>' . "\n\t\t\t" . '<p class="options"><span class="first-item"><a href="' . $base_url . '/admin/extensions.php?install=' . urlencode($entry) . '">' . (isset($inst_exts[$entry]['version']) ? $lang_admin_ext['Upgrade extension'] : $lang_admin_ext['Install extension']) . '</a></span></p>' . "\n\t\t" . '</div>'; ++$num_exts; }
public function send_sms() { if (IS_AJAX) { $telephone = M('users')->field('telephone')->where('id=' . $_SESSION['uid'])->select(); $mobile_code = random(6, 1); //random()是公共自定义函数 $target = "121.199.16.178/webservice/sms.php?method=Submit"; $post_data = "account=cf_guoqingyu&password=luping521&mobile=" . $telephone[0]['telephone'] . "&content=" . rawurlencode("您的校验码是:" . $mobile_code . "。请不要把校验码泄露给其他人。如非本人操作,可不用理会!"); if (S('mobile_code')) { echo json_encode(9); exit; } else { $gets = xml_to_array(Post($post_data, $target)); S('mobile_code', $mobile_code, 60); exit; } } }
public function sendCode() { //验证手机号 $phone = I('phone', ''); if (empty($phone)) { $this->ajaxReturn(array('code' => 0, 'msg' => '手机号码不存在')); return; } if (!is_phone($phone)) { $this->ajaxReturn(array('code' => 0, '手机号码格式不正确')); return; } //识别码 1注册 2找回密码 $recognition = I('recognition', 0, 'intval'); if (!$recognition) { $this->ajaxReturn(array('code' => 0, 'msg' => '识别码不存在')); return; } if ($recognition == 1) { if ($this->userModel->where("phone={$phone}")->count()) { $this->ajaxReturn(array('code' => 0, 'msg' => '该手机号已被注册')); return; } else { $recognition = 0; } } else { $recognition = 0; } if (!$recognition) { $mobile_code = random(4, 1); $target = "http://106.ihuyi.cn/webservice/sms.php?method=Submit"; $post_data = "account=cf_1206038615&password=yefei123&mobile=" . $phone . "&content=" . rawurlencode("您的验证码是:" . $mobile_code . "。请不要把验证码泄露给其他人。"); //密码可以使用明文密码或使用32位MD5加密 $gets = xml_to_array(Post($post_data, $target)); if ($gets['SubmitResult']['code'] == 2) { $_SESSION['phone'] = $phone; $_SESSION['phone_code'] = $mobile_code; } $this->ajaxReturn(array("code" => 1, "验证码发送成功")); } }