/** * Block Send XML order to Moulton * @author Oleg D. */ function send_order() { $result = array(); $xml_order = $this->build_order_xml(); $xml_order = preg_replace("/(\\s+)?(\\<.+\\>)(\\s+)?/", "\$2", $xml_order); $xml_order = str_replace('&', '&', $xml_order); echo $xml_order; $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_order); if ($this->testing) { curl_setopt($ch, CURLOPT_URL, $this->send_order_url_test); } else { curl_setopt($ch, CURLOPT_URL, $this->send_order_url); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); $moulton_answer = curl_exec($ch); curl_close($ch); include 'xmlparser.class.php'; $Parser = new XmlParser(); $result = $Parser->xml2array($moulton_answer); return $result; }
/** * get logs of the log file * @param $type string of log direcroty, like store * @param $logFile - log files name like 12.27.2009.xml * @param $userID * @author Oleg D. */ function getLogs($type, $logFile, $userID = null) { $logFile .= '.xml'; $date = explode('.', $logFile); $year = $date[2]; $month = $date[0]; App::import('Vendor', 'XmlParser', array('file' => 'xmlparser.class.php')); $XmlParser = new XmlParser(); $file = file_get_contents(ROOT . DS . 'app' . DS . 'logs' . DS . $type . DS . $year . DS . $month . DS . $logFile); $file = str_replace('&', 'and', $file); if (!$file) { echo 'file error'; exit; } $file = '<All>' . $file . '</All>'; $logsParse = $XmlParser->xml2array($file); $logs = array(); if (isset($logsParse['All']['Log'])) { $logs = $logsParse['All']['Log']; } if ($userID) { $myLogs = array(); foreach ($logs as $log) { if ($log['Uid'] == $userID) { $myLogs[] = $log; } } } else { $myLogs = $logs; } $myLogs = array_reverse($myLogs); //echo "<pre>"; //print_r($myLogs); return $myLogs; }
/** * 从XML文件读取信息 * @param string $data XML数据 * @param string $startNode 返回结果的起始节点 * @return array 返回XML内容数组 */ function loadFromData($data, $startNode = '') { if (isset($data)) { $xml = XmlParser::xml2array($data); if ($startNode) { $startNode = explode('/', $startNode); foreach ($startNode as $node) { } $xml = isset($xml[$node]) ? $xml = $xml[$node] : array(); } } else { $xml = array(); } return $xml; }
/** * CRON update video process status * @author Oleg D. */ function cronUpdateVideoStatus() { Configure::write('debug', 1); // set is_processed for all videos who uploaded mor then 15 minutes ago $sql = "UPDATE videos SET is_processed = 1 WHERE uploaded AND is_processed = 0 AND uploaded < date_add(now(), interval -25 minute)"; $this->Video->query($sql); App::import('Vendor', 'XmlParser', array('file' => 'xmlparser.class.php')); $XmlParser = new XmlParser(); $videos = $this->Video->find('all', array('conditions' => array('is_processed' => 0, 'is_deleted' => 0, 'is_file' => 1, 'youtube_id is not null'))); //pr($videos); foreach ($videos as $video) { if ($video['Video']['youtube_id']) { $content = $this->file_get_contents_curl('http://gdata.youtube.com/feeds/api/videos/' . $video['Video']['youtube_id']); $ansverArray = $XmlParser->xml2array($content); if (!empty($ansverArray['entry'])) { if (!empty($ansverArray['entry']['app:control']['yt:state_attr'])) { //echo "processing"; echo $video['Video']['youtube_id'] . ' - ' . 'processing<br/>'; } else { //echo "processing finished"; $this->Video->save(array('id' => $video['Video']['id'], 'is_processed' => 1)); echo $video['Video']['youtube_id'] . ' - ' . 'processed<br/>'; } } } } Cache::delete('last_videos'); exit; }
/** * Get Twitter information * @author Oleg D. */ function getTwitterInfo($twitterID) { App::import('Vendor', 'XmlParser', array('file' => 'xmlparser.class.php')); $XmlParser = new XmlParser(); for ($i = 0; $i < 5; $i++) { $info = $this->file_get_contents_curl('http://api.twitter.com/1/users/show.xml?user_id=' . $twitterID); $info = $XmlParser->xml2array($info); if (!empty($info['user']['id'])) { break; } } if (!empty($info['user'])) { $info = $info['user']; } else { return false; } return $info; }