Ejemplo n.º 1
1
function parseSessions($xml)
{
    $session_array = array();
    /* Parse the XML into tags */
    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, $xml, $values, $tags);
    xml_parser_free($parser);
    // loop through the structures
    foreach ($tags as $key => $value) {
        if ($key == "session") {
            $molranges = $value;
            // each contiguous pair of array entries are the
            // lower and upper range for each molecule definition
            for ($i = 0; $i < count($molranges); $i += 2) {
                $offset = $molranges[$i] + 1;
                $len = $molranges[$i + 1] - $offset;
                $session_array[] = parseSession(array_slice($values, $offset, $len));
            }
        } else {
            continue;
        }
    }
    return $session_array;
}
Ejemplo n.º 2
0
function parseXML($xml)
{
    $parser = xml_parser_create();
    $output = array();
    xml_parse_into_struct($parser, $xml, $output);
    return $output;
}
Ejemplo n.º 3
0
 public function __construct($dataDirectory)
 {
     //
     // Default to English for lack of anything better
     //
     $this->clientLang = 'en-us';
     //
     // See if we can find anything better
     //
     $matches = array();
     if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
         setlocale(LC_ALL, 'en-US');
         if (preg_match('/(en-US|fr-FR|de-DE|it-IT|es-ES|sv-SV|sv-SE|nl-NL)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches)) {
             $this->clientLang = strtolower($matches[1]);
         }
     }
     //
     // Pull in all of the strings we need
     //
     $lang2file = array("es-es" => "es-ES.xml", "en-us" => "en-US.xml", "de-de" => "de-DE.xml", "fr-fr" => "fr-FR.xml", "it-it" => "it-IT.xml", "nl-nl" => "nl-NL.xml", "sv-sv" => "sv-SE.xml", "sv-se" => "sv-SE.xml");
     $xml_parser = xml_parser_create();
     $l10nValues = array();
     $l10nIndexes = array();
     $l10nContents = file_get_contents("{$dataDirectory}/" . $lang2file[$this->getClientLang()]);
     if (!xml_parse_into_struct($xml_parser, $l10nContents, $l10nValues, $l10nIndexes)) {
         die(sprintf("l10n: XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
     } else {
         foreach ($l10nIndexes["STRING"] as $l10nStringIndex) {
             $this->l10n[$l10nValues[$l10nStringIndex]["attributes"]["ID"]] = $l10nValues[$l10nStringIndex]["value"];
         }
     }
     xml_parser_free($xml_parser);
 }
Ejemplo n.º 4
0
function parseRSS($url)
{
    //PARSE RSS FEED
    $feedeed = implode('', file($url));
    $parser = xml_parser_create();
    xml_parse_into_struct($parser, $feedeed, $valueals, $index);
    xml_parser_free($parser);
    //CONSTRUCT ARRAY
    foreach ($valueals as $keyey => $valueal) {
        if ($valueal['type'] != 'cdata') {
            $item[$keyey] = $valueal;
        }
    }
    $i = 0;
    foreach ($item as $key => $value) {
        if ($value['type'] == 'open') {
            $i++;
            $itemame[$i] = $value['tag'];
        } elseif ($value['type'] == 'close') {
            $feed = $values[$i];
            $item = $itemame[$i];
            $i--;
            if (count($values[$i]) > 1) {
                $values[$i][$item][] = $feed;
            } else {
                $values[$i][$item] = $feed;
            }
        } else {
            $values[$i][$value['tag']] = $value['value'];
        }
    }
    //RETURN ARRAY VALUES
    return $values[0];
}
 function GetStatus($ip, $port, $pw)
 {
     error_reporting(0);
     $fp = fsockopen($ip, $port, $errno, $errstr, 1);
     if (!$fp) {
         error_reporting(E_ALL);
         $this->error = "{$errstr} ({$errno})";
         return 0;
     } else {
         error_reporting(E_ALL);
         socket_set_timeout($fp, 2);
         fputs($fp, "GET /stats?sid=1?pass="******"&mode=viewxml HTTP/1.1\r\n");
         //  original --> admin.cgi?pass
         fputs($fp, "User-Agent: Mozilla\r\n\r\n");
         while (!feof($fp)) {
             $this->SHOUTcastData .= fgets($fp, 512);
         }
         fclose($fp);
         if (stristr($this->SHOUTcastData, "HTTP/1.1 200 OK") == true) {
             $this->SHOUTcastData = trim(substr($this->SHOUTcastData, 58));
         } else {
             $this->error = "Bad login";
             return 0;
         }
         $xmlparser = xml_parser_create('UTF-8');
         //xml_parse_into_struct($xmlparser, $this->SHOUTcastData, $this->values, $this->indexes);
         if (!xml_parse_into_struct($xmlparser, $this->SHOUTcastData, $this->values, $this->indexes)) {
             $this->error = "Unparsable XML";
             return 0;
         }
         xml_parser_free($this->values);
         return 1;
     }
 }
Ejemplo n.º 6
0
 public function parse($data)
 {
     $p = xml_parser_create();
     xml_parse_into_struct($p, $data, $vals, $index);
     xml_parser_free($p);
     return $vals;
 }
 function postToEWAY($payment_id, $url, $vars)
 {
     global $db;
     $varsx = array();
     foreach ($vars as $k => $v) {
         $varsx[] = urlencode($k) . "=" . urlencode($v);
     }
     $result = get_url($url = $url . "?" . join('&', $varsx));
     $payment = $db->get_payment($payment_id);
     $payment['data'][] = $vars;
     $payment['data'][] = array('result' => $result);
     // Simple parser
     $parser = xml_parser_create();
     xml_parse_into_struct($parser, $result, $vals, $index);
     xml_parser_free($parser);
     foreach ($index as $k => $v) {
         foreach ($v as $vv) {
             if ($vals[$vv]['value']) {
                 $ret[$k] = $vals[$vv]['value'];
             }
         }
     }
     $payment['data'][] = $ret;
     $db->update_payment($payment_id, $payment);
     return $ret;
 }
Ejemplo n.º 8
0
function processXML($filename)
{
    // read the xml document
    $data = implode("", file($filename));
    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, $data, $values, $tags);
    xml_parser_free($parser);
    $talks = array();
    // loop through the structures
    foreach ($tags as $key => $val) {
        if ($key == "talk") {
            $ranges = $val;
            $nranges = count($ranges);
            // each contiguous pair of array entries are the
            // lower and upper range for each talk elements
            for ($i = 0; $i < $nranges; $i += 2) {
                $offset = $ranges[$i] + 1;
                $len = $ranges[$i + 1] - $offset;
                $talks[] =& parseTalk(array_slice($values, $offset, $len));
            }
        } else {
            continue;
        }
    }
    return $talks;
}
Ejemplo n.º 9
0
function xmlParse($data, $bList = "")
{
    $bArray = array();
    // if any attributes were passed to the function, add them to the array
    if (strlen($bList) > 0) {
        $bArray = explode(",", $bList);
    }
    // by: waldo@wh-e.com - trim space around tags not within
    $data = eregi_replace(">" . "[[:space:]]+" . "<", "><", $data);
    // XML functions
    $p = xml_parser_create();
    // by: anony@mous.com - meets XML 1.0 specification
    xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
    xml_parse_into_struct($p, $data, $vals, $index);
    xml_parser_free($p);
    for ($x = 0; $x < count($vals); $x++) {
        if (array_key_exists("attributes", $vals[$x])) {
            foreach ($vals[$x]["attributes"] as $thiskey => $thisvalue) {
                // if the attribute name exists in the "bList" then re-cast the string to a boolean
                if (is_string($thisvalue) && array_search($thiskey, $bArray) !== false && (strtolower($thisvalue) == "true" || strtolower($thisvalue) == "false")) {
                    $vals[$x]["attributes"][$thiskey] = strtolower($thisvalue) == "true";
                }
            }
        }
    }
    $i = 0;
    $tree["xmlChildren"] = array();
    $tree["xmlChildren"][] = array('xmlName' => $vals[$i]['tag'], 'xmlAttributes' => getAttributes($vals, $i), 'xmlValue' => getValue($vals, $i), 'xmlChildren' => GetChildren($vals, $i));
    return $tree;
}
Ejemplo n.º 10
0
function GetXMLTree($data) {
 
 // $data = implode('', file($file));
 // by: waldo@wh-e.com - trim space around tags not within
 
 //$data = eregi_replace(">"."[[:space:]]+"."<","><",$data);
 $data = preg_replace('/>\s+</', '><', $data);
 // XML functions
 $p = xml_parser_create();
 
 // by: anony@mous.com - meets XML 1.0 specification
 xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
 
 xml_parse_into_struct($p, $data, &$vals, &$index);
 
 xml_parser_free($p);
 
 $i = 0;
 $tree = array();
 $tree[] = array(
  'tag' => $vals[$i]['tag'], 
  'attributes' => $vals[$i]['attributes'], 
  'value' => $vals[$i]['value'], 
  'children' => GetChildren($vals, $i)
 );
 //debmes('xmltree - step 6');
 return $tree;
}
Ejemplo n.º 11
0
function pfp_resize_image($image_tag, $height, $width)
{
    $final_image_tag = $image_tag;
    $parser = xml_parser_create();
    xml_parse_into_struct($parser, $image_tag, $values);
    foreach ($values as $key => $val) {
        if ($val['tag'] == 'IMG') {
            $image_url = $val['attributes']['SRC'];
            break;
        }
    }
    //echo "height: " . $height;
    if ($height != '' && $width != '') {
        $final_image_tag = "<img src=" . $image_url . " style='width:" . $width . "px" . ";height:" . $height . "px" . "' />";
        //echo "1";
    } else {
        if ($height != '') {
            $final_image_tag = "<img src=" . $image_url . " style='height:" . $height . "px" . "' />";
            //echo "2";
        } else {
            if ($width != '') {
                $final_image_tag = "<img src=" . $image_url . " style='width:" . $width . "px" . "' />";
                //echo "3";
            }
        }
    }
    return $final_image_tag;
}
Ejemplo n.º 12
0
function xmlize($data, $WHITE=1)
{

    $data = trim($data);
    $vals = $index = $array = array();
    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $WHITE);
    if ( !xml_parse_into_struct($parser, $data, $vals, $index) ) {
	die(sprintf("XML error: %s at line %d",
		    xml_error_string(xml_get_error_code($parser)),
		    xml_get_current_line_number($parser)));

    }
    xml_parser_free($parser);

    $i = 0;

    $tagname = $vals[$i]['tag'];
    if ( isset ($vals[$i]['attributes'] ) ) {
	$array[$tagname]['@'] = $vals[$i]['attributes'];
    } else {
	$array[$tagname]['@'] = array();
    }

    $array[$tagname]["#"] = xml_depth($vals, $i);

    return $array;
}
Ejemplo n.º 13
0
function GetXMLTree($xmldata)
{
    // we want to know if an error occurs
    ini_set('track_errors', '1');
    $xmlreaderror = false;
    $parser = xml_parser_create('ISO-8859-1');
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    if (!xml_parse_into_struct($parser, $xmldata, $vals, $index)) {
        $xmlreaderror = true;
        $err = PEAR::raiseError("XML Read error", 1, E_USER_WARNING, null, "Could not parse xml into structure.");
        return $err;
    }
    xml_parser_free($parser);
    if (!$xmlreaderror) {
        $result = array();
        $i = 0;
        $attributes = array();
        if (isset($vals[$i]['attributes'])) {
            foreach (array_keys($vals[$i]['attributes']) as $attkey) {
                $attributes[$attkey] = $vals[$i]['attributes'][$attkey];
            }
        }
        $result[$vals[$i]['tag']] = array_merge($attributes, GetChildren($vals, $i, 'open'));
    }
    ini_set('track_errors', '0');
    return $result;
}
Ejemplo n.º 14
0
function parse_file()
{
    if (file_exists('japancar_krasnoyarsk.xml')) {
        $data = implode("", file('japancar_krasnoyarsk.xml'));
        $parser = xml_parser_create();
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
        xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
        xml_parse_into_struct($parser, $data, $values, $tags);
        xml_parser_free($parser);
        // проход через структуры
        foreach ($tags as $key => $val) {
            if ($key == "data") {
                $molranges = $val;
                // каждая смежная пара значений массивов является верхней и
                // нижней границей определения
                for ($i = 0; $i < count($molranges); $i += 2) {
                    $offset = $molranges[$i] + 1;
                    $len = $molranges[$i + 1] - $offset;
                    $tdb[] = parseString(array_slice($values, $offset, $len));
                }
            } else {
                continue;
            }
        }
        return $tdb;
    } else {
        exit('Не удалось открыть файл japancar_krasnoyarsk.xml.');
    }
}
Ejemplo n.º 15
0
 /**
  * reads an xml file, parses it into a structure
  * constructor
  * @param String file the xml file to read
  * @return XmlReader
  * @access public
  */
 function XmlReader($file)
 {
     $requested_file = $file;
     #the given path can be a absolute path
     #if it's not a file, look in the default CMS xml directory and the default xml directory for the given file
     if (is_file($file)) {
         $file = file($file);
     } elseif (is_file(CMS_XML_PATH . $file)) {
         $file = file(CMS_XML_PATH . $file);
     } else {
         $file = file(XML_PATH . $file);
     }
     #if the file still does not exist, raise error
     if (!is_array($file)) {
         new ErrorHandler(get_class($this), "constructor", "", "FILE DOES NOT EXIST", "The file does not exist: {$requested_file}");
     }
     $parser = xml_parser_create('ISO-8859-1');
     $data = implode($file, "");
     #this is how a complete node looks like, when unnecessary data is excluded:
     #Array ( [tag] => PAGE [type] => open [level] => 2 [value] => [node] => 1 )
     #Array ( [tag] => PAGENAME [type] => complete [level] => 3 [value] => billing [node] => 2 )
     #Array ( [tag] => PAGERIGHT [type] => complete [level] => 3 [value] => all [node] => 3 )
     #Array ( [tag] => PAGEAUTHORIZE [type] => complete [level] => 3 [value] => 0 [node] => 4 )
     #Array ( [tag] => PAGETITLE [type] => complete [level] => 3 [value] => Billing [node] => 5 )
     #Array ( [tag] => PAGEFRAME [type] => complete [level] => 3 [value] => body [node] => 6 )
     #Array ( [tag] => PAGEDEFAULT [type] => complete [level] => 3 [value] => 0 [node] => 7 )
     #Array ( [tag] => PAGE [type] => close [level] => 2 [node] => 8 )
     xml_parse_into_struct($parser, $data, $struct);
     $this->_struct = $struct;
     #exclude every array where the key is "type" and the value is "cdata"
     #for more details see the function exclude()
     $this->_excluded = $this->exclude('type', 'cdata');
 }
Ejemplo n.º 16
0
/**
 * wallabag, self hostable application allowing you to not miss any content anymore
 *
 * @category   wallabag
 * @author     Nicolas Lœuillet <*****@*****.**>
 * @copyright  2013
 * @license    http://opensource.org/licenses/MIT see COPYING file
 */
function status()
{
    $app_name = 'wallabag';
    $php_ok = function_exists('version_compare') && version_compare(phpversion(), '5.3.3', '>=');
    $pdo_ok = class_exists('PDO');
    $pcre_ok = extension_loaded('pcre');
    $zlib_ok = extension_loaded('zlib');
    $mbstring_ok = extension_loaded('mbstring');
    $dom_ok = extension_loaded('DOM');
    $iconv_ok = extension_loaded('iconv');
    $tidy_ok = function_exists('tidy_parse_string');
    $curl_ok = function_exists('curl_exec');
    $parse_ini_ok = function_exists('parse_ini_file');
    $parallel_ok = extension_loaded('http') && class_exists('HttpRequestPool') || $curl_ok && function_exists('curl_multi_init');
    $allow_url_fopen_ok = (bool) ini_get('allow_url_fopen');
    $filter_ok = extension_loaded('filter');
    $gettext_ok = function_exists("gettext");
    $gd_ok = extension_loaded('gd');
    $pdo_drivers = pdoDrivers();
    $pdo_drivers_passing = $pdo_drivers['sqlite'] || $pdo_drivers['mysql'] || $pdo_drivers['postgres'];
    $urlfetching = $curl_ok || $allow_url_fopen_ok;
    if (extension_loaded('xmlreader')) {
        $xml_ok = true;
    } elseif (extension_loaded('xml')) {
        $parser_check = xml_parser_create();
        xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
        xml_parser_free($parser_check);
        $xml_ok = isset($values[0]['value']);
    } else {
        $xml_ok = false;
    }
    $status = array('app_name' => $app_name, 'php' => $php_ok, 'pdo' => $pdo_ok, 'pdo_drivers_passing' => $pdo_drivers_passing, 'xml' => $xml_ok, 'pcre' => $pcre_ok, 'zlib' => $zlib_ok, 'mbstring' => $mbstring_ok, 'dom' => $dom_ok, 'iconv' => $iconv_ok, 'tidy' => $tidy_ok, 'curl' => $curl_ok, 'parse_ini' => $parse_ini_ok, 'parallel' => $parallel_ok, 'allow_url_fopen' => $allow_url_fopen_ok, 'filter' => $filter_ok, 'gettext' => $gettext_ok, 'gd' => $gd_ok, 'urlfetching' => $urlfetching);
    return $status;
}
Ejemplo n.º 17
0
 /**
  * rss push
  */
 public function getPushList($id)
 {
     $rssInfo = $this->where('id=' . $id)->find();
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $rssInfo['url']);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $result = curl_exec($ch);
     curl_close($ch);
     $parser = xml_parser_create();
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     xml_parse_into_struct($parser, $result, $values, $tags);
     xml_parser_free($parser);
     for ($i = 0; $i < $rssInfo['count']; $i++) {
         foreach ($tags as $k => $v) {
             if ($k == 'title') {
                 $newsList[$i]['title'] = $values[$v[$i + 2]]['value'];
             } elseif ($k == 'description') {
                 $description = $values[$v[$i + 1]]['value'];
                 //如果简介中有图片,就将其作为图文封面
                 $pattern = '/<img(.*)src="(.*)"/Us';
                 preg_match($pattern, $description, $content);
                 $newsList[$i]['cover'] = $content['2'];
                 $newsList[$i]['description'] = $values[$v[$i + 1]]['value'];
             } elseif ($k == 'link') {
                 $newsList[$i]['url'] = $values[$v[$i + 2]]['value'];
             }
         }
     }
     return $newsList;
 }
Ejemplo n.º 18
0
 function xml2php($xmlcontent)
 {
     $xml_parser = xml_parser_create();
     xml_parse_into_struct($xml_parser, $xmlcontent, $arr_vals);
     xml_parser_free($xml_parser);
     return $arr_vals;
 }
Ejemplo n.º 19
0
 /**
  * 获取xml树
  * @param string $xmldata xml数据
  * @param array $result xml内容
  */
 static function get_xml_tree($xmldata, &$result)
 {
     ini_set('track_errors', '1');
     $xmlreaderror = false;
     $parser = xml_parser_create();
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     if (!xml_parse_into_struct($parser, $xmldata, $vals, $index)) {
         $xmlreaderror = true;
         return 0;
     }
     xml_parser_free($parser);
     if (!$xmlreaderror) {
         $result = array();
         $i = 0;
         if (isset($vals[$i]['attributes'])) {
             foreach (array_keys($vals[$i]['attributes']) as $attkey) {
                 $attributes[$attkey] = $vals[$i]['attributes'][$attkey];
             }
         }
         $result[$vals[$i]['tag']] = array_merge((array) $attributes, self::get_children($vals, $i, 'open'));
     }
     ini_set('track_errors', '0');
     return 1;
 }
Ejemplo n.º 20
0
 /**
  * Méthode qui charge le fichier plugins.xml (ancien format)
  *
  * @return	null
  * @author	Stephane F
  **/
 public function loadConfig()
 {
     $aPlugins = array();
     if (!is_file(path('XMLFILE_PLUGINS'))) {
         return false;
     }
     # Mise en place du parseur XML
     $data = implode('', file(path('XMLFILE_PLUGINS')));
     $parser = xml_parser_create(PLX_CHARSET);
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
     xml_parse_into_struct($parser, $data, $values, $iTags);
     xml_parser_free($parser);
     # On verifie qu'il existe des tags "plugin"
     if (isset($iTags['plugin'])) {
         # On compte le nombre de tags "plugin"
         $nb = sizeof($iTags['plugin']);
         # On boucle sur $nb
         for ($i = 0; $i < $nb; $i++) {
             $name = $values[$iTags['plugin'][$i]]['attributes']['name'];
             $activate = $values[$iTags['plugin'][$i]]['attributes']['activate'];
             $value = isset($values[$iTags['plugin'][$i]]['value']) ? $values[$iTags['plugin'][$i]]['value'] : '';
             $aPlugins[$name] = array('activate' => $activate, 'title' => $value, 'instance' => null);
         }
     }
     return $aPlugins;
 }
Ejemplo n.º 21
0
function info($fisbn, &$isbn10, &$isbn13, &$title, &$title_ext, &$author, &$publisher, $dump = false) {
    global $LOOKUP_URL, $LOOKUP_KEY;
    $full_url = $LOOKUP_URL . "access_key=" . $LOOKUP_KEY . "&index1=isbn&value1=" . $fisbn;
    $contents = file_get_contents($full_url);
    $parser = xml_parser_create();
    xml_parse_into_struct($parser, $contents, $values, $index);
    xml_parser_free($parser);
    $num_results = $values[$index['BOOKLIST'][0]];
    if($num_results == 0) { // bad ISBN
        return false;
    }
    $indx = $index['BOOKDATA'][0];
    $isbn10 = $values[$indx]['attributes']['ISBN'];
    $isbn13 = $values[$indx]['attributes']['ISBN13'];
    $title = $values[$index['TITLE'][0]]['value'];
    $title_ext = $values[$index['TITLELONG'][0]]['value'];
    $author = $values[$index['AUTHORSTEXT'][0]]['value'];
    $publisher = $values[$index['PUBLISHERTEXT'][0]]['value'];
    
    if(!$dump)
        return true;
    print_r($index);
    echo '<br />';
    print_r($values);
    return true;
}
Ejemplo n.º 22
0
 public function actionLrc()
 {
     $song_id = intval($this->post("song_id", 0));
     if (!$song_id) {
         return $this->renderJSON([], "歌曲不存在", -1);
     }
     $info = Music::findOne(['song_id' => $song_id, 'status' => 1]);
     if (!$info) {
         return $this->renderJSON([], "歌曲不存在", -1);
     }
     /*获取歌词*/
     $lrc_url = QQMusicService::getSongLrcUrl($song_id);
     $lrc_data = HttpClient::get($lrc_url);
     $lrc = '';
     if (substr($lrc_data, 0, 5) == "<?xml") {
         if (stripos(strtolower($lrc_data), 'encoding="GB2312"') !== false) {
             $lrc_data = mb_convert_encoding($lrc_data, "utf-8", "gb2312");
             $lrc_data = str_replace('encoding="GB2312"', 'encoding="utf-8"', $lrc_data);
         }
         //var_dump($lrc_data);exit();
         $parser = xml_parser_create();
         xml_parse_into_struct($parser, $lrc_data, $values, $index);
         //解析到数组
         xml_parser_free($parser);
         $lrc = isset($values[0]['value']) ? $values[0]['value'] : '';
     }
     $data = ['lrc' => $lrc, 'song_url' => QQMusicService::getSongUrl($song_id)];
     return $this->renderJSON($data);
 }
Ejemplo n.º 23
0
 /**
  * 使用discuz词库
  * @param unknown_type $title
  * @param unknown_type $content
  */
 public static function discuz($title = '', $content = '')
 {
     $subjectenc = rawurlencode(strip_tags($title));
     $messageenc = rawurlencode(strip_tags(preg_replace("/\\[.+?\\]/U", '', $content)));
     $data = @implode('', file("http://keyword.discuz.com/related_kw.html?title={$subjectenc}&content={$messageenc}&ics=utf-8&ocs=utf-8"));
     if ($data) {
         $parser = xml_parser_create();
         xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
         xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
         xml_parse_into_struct($parser, $data, $values, $index);
         xml_parser_free($parser);
         $kws = array();
         foreach ($values as $valuearray) {
             if ($valuearray['tag'] == 'kw' || $valuearray['tag'] == 'ekw') {
                 $kws[] = trim($valuearray['value']);
             }
         }
         $return = '';
         if ($kws) {
             foreach ($kws as $kw) {
                 $kw = CHtml::encode(strip_tags($kw));
                 $return .= $dot . $kw;
                 $dot = ',';
             }
             $return = trim($return);
         }
         return $return;
     }
 }
 public function basic_view($alias, $display_item, $parent_item, $image_types, $encoded_seek_search_params, $search_position, $seek_search_params, $isthisCompoundObject, $previous_item, $next_item, $current_item_num, $totalitems)
 {
     $conf =& dmGetCollectionFieldInfo($alias);
     $itnum = $display_item['ptr'];
     $rc = dmGetItemInfo($alias, $itnum, $data);
     $parser = xml_parser_create();
     xml_parse_into_struct($parser, $data, $structure, $index);
     xml_parser_free($parser);
     dmGetImageInfo($alias, $itnum, $filename, $type, $width, $height);
     $filename = substr($filename, strrpos($filename, "/") + 1);
     $file_extension = GetFileExt($filename);
     if (in_array($file_extension, $image_types)) {
         $is_image = true;
         $dimensions = Image::fit_width($width, $height, 640);
         $scaled_width = $dimensions[0];
         $scaled_height = $dimensions[1];
         $scaling_factor = $dimensions[2];
         $file_url = "http://cdm9006.cdmhost.com/cgi-bin/getimage.exe?CISOROOT=" . $alias . "&amp;CISOPTR=" . $itnum;
         $file_url .= "&amp;DMWIDTH=" . $scaled_width . "&amp;DMHEIGHT=" . $scaled_height . "&amp;DMSCALE=" . $scaling_factor;
     } else {
         $is_image = false;
         $file_url = "http://cdm9006.cdmhost.com/cgi-bin/showfile.exe?CISOROOT=" . $alias . "&amp;CISOPTR=" . $itnum;
         $encoded_file_url = urlencode("http://cdm9006.cdmhost.com/cgi-bin/showfile.exe?CISOROOT=" . $alias . "&amp;CISOPTR=" . $itnum);
     }
     include 'basic_view.php';
 }
Ejemplo n.º 25
0
 public function parseXML($xml)
 {
     $xmlArray = null;
     $parser = xml_parser_create();
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
     xml_parse_into_struct($parser, $xml, $xmlArray, $indexdata);
     xml_parser_free($parser);
     $elements = array();
     $child = array();
     foreach ($xmlArray as $item) {
         $current = count($elements);
         if ($item['type'] == 'open' || $item['type'] == 'complete') {
             $elements[$current] = new \stdClass();
             $elements[$current]->tag = $item['tag'];
             $elements[$current]->attributes = array_key_exists('attributes', $item) ? $item['attributes'] : '';
             $elements[$current]->value = array_key_exists('value', $item) ? $item['value'] : '';
             if ($item['type'] == "open") {
                 $elements[$current]->children = array();
                 $child[count($child)] =& $elements;
                 $elements =& $elements[$current]->children;
             }
         } else {
             if ($item['type'] == 'close') {
                 $elements =& $child[count($child) - 1];
                 unset($child[count($child) - 1]);
             }
         }
     }
     if ($elements) {
         return $elements[0];
     } else {
         return null;
     }
 }
Ejemplo n.º 26
0
 public function correct(string $input) : string
 {
     if (!mb_check_encoding($input, 'UTF-8')) {
         throw new SyntaxException(_('SVGファイルの符号化方式 (文字コード) は UTF-8 でなければなりません。'));
     }
     $parser = xml_parser_create_ns();
     $isValid = xml_parse_into_struct($parser, $input, $nodes);
     xml_parser_free($parser);
     if (!$isValid) {
         throw new SyntaxException(_('整形式になっていません。'));
     }
     $document = new \DOMDocument('1.0', 'UTF-8');
     $document->loadXML($input);
     // ノードの削除
     $root = $document->documentElement;
     foreach ((new \DOMXPath($document))->query(self::BLACKLIST) as $node) {
         if ($node === $root) {
             throw new SyntaxException(_('ルート要素がSVG名前空間に属していません。'));
         }
         $this->logger->error(sprintf(_('SVG中にノード %s を含めることはできません。'), $node->nodeName));
         if ($node->nodeType === XML_ATTRIBUTE_NODE) {
             $node->ownerElement->removeAttributeNode($node);
         } elseif ($node->parentNode) {
             $node->parentNode->removeChild($node);
         }
     }
     return $document->saveXML();
 }
Ejemplo n.º 27
0
 function readConfig($filename)
 {
     // read the xml database
     //print "FILE: $filename";
     $data = implode("", file($filename));
     $parser = xml_parser_create();
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     xml_parse_into_struct($parser, $data, $values, $tags);
     xml_parser_free($parser);
     // loop through the structures
     foreach ($tags as $key => $val) {
         if ($key == "node") {
             $noderanges = $val;
             // each contiguous pair of array entries are the
             // lower and upper range for each node definition
             for ($i = 0; $i < count($noderanges); $i += 2) {
                 $offset = $noderanges[$i] + 1;
                 $len = $noderanges[$i + 1] - $offset;
                 $tdb[] = $this->parseXML(array_slice($values, $offset, $len));
             }
         } else {
             continue;
         }
     }
     return $tdb;
 }
Ejemplo n.º 28
0
function get_trueknowledge_result()
{
    global $trueknowledge_in;
    global $global_id;
    $return = '';
    $xml_parser = xml_parser_create("UTF-8");
    xml_parse_into_struct($xml_parser, $trueknowledge_in, $values);
    //print_r($values);
    $tk_response = $values[0];
    if ($tk_response['attributes']['UNDERSTOOD'] == 'true' && $tk_response['attributes']['ANSWERED'] == 'true') {
        $tk_status = $values[1];
        $completeness = $tk_status['value'];
        //Status of the output to assign prirority
        //Answer
        $tk_text_result = $values[3];
        $type = $tk_text_result['type'];
        $return = $tk_text_result['value'];
        if ($return == 'Result set may be incomplete' || strpos($return, 'true knowledge') !== false) {
            $return = false;
        } else {
            file_put_contents(DATA_PATH . "/trueknowledge/{$global_id}", $return);
        }
    } else {
        $return = false;
    }
    return $return;
}
Ejemplo n.º 29
0
 function openstats()
 {
     $fp = fsockopen($this->host, $this->port, $errno, $errstr, 10);
     if (!$fp) {
         $this->_error = "{$errstr} ({$errno})";
         return 0;
     } else {
         fputs($fp, "GET /admin.cgi?pass="******"&mode=viewxml HTTP/1.0\r\n");
         fputs($fp, "User-Agent: Mozilla\r\n\r\n");
         while (!feof($fp)) {
             $this->_xml .= fgets($fp, 512);
         }
         fclose($fp);
         if (stristr($this->_xml, "HTTP/1.0 200 OK") == true) {
             // <-H> Thanks to Blaster for this fix.. trim();
             $this->_xml = trim(substr($this->_xml, 42));
         } else {
             $this->_error = "Bad login";
             return 0;
         }
         $xmlparser = xml_parser_create();
         if (!xml_parse_into_struct($xmlparser, $this->_xml, $this->_values, $this->_indexes)) {
             $this->_error = "Unparsable XML";
             return 0;
         }
         xml_parser_free($xmlparser);
         return 1;
     }
 }
Ejemplo n.º 30
0
function parse_conf_file($conf_path)
{
    $data = file_get_contents($conf_path);
    if ($data === FALSE || strlen($data) == 0) {
        echo "configuration file[{$conf_path}] is empty\n";
        return FALSE;
    }
    $parser = xml_parser_create();
    if (!xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0)) {
        echo "xml_parser_set_option failed\n";
        xml_parser_free($parser);
        return FALSE;
    }
    $result = array();
    $index = array();
    if (xml_parse_into_struct($parser, $data, $result, $index) === 0) {
        echo "xml_parse_into_struct failed\n";
        xml_parser_free($parser);
        return FALSE;
    }
    xml_parser_free($parser);
    if (count($index['name']) !== count($index['value'])) {
        echo "index parsed out is invalid\n";
        return FALSE;
    }
    $name_index = $index['name'];
    $value_index = $index['value'];
    $conf = array();
    for ($i = 0, $l = count($name_index); $i < $l; $i++) {
        $ni = $name_index[$i];
        $vi = $value_index[$i];
        $conf[trim($result[$ni]['value'])] = trim($result[$vi]['value']);
    }
    return $conf;
}