コード例 #1
0
function parseRSS($url)
{
	$ret=array();
	$xml=xml2ary(file_get_contents($url));
	$ret=$xml['rss']['_c']['channel']['_c']['item'];
	return $ret;
}
コード例 #2
0
ファイル: heat_helper.php プロジェクト: ReedME/heatCMS
function theme($return = false)
{
    $ci =& get_instance();
    $theme = array();
    $theme['name'] = $ci->Database->get_config['theme'];
    $theme['xml'] = file_get_contents('../../themes/' . $theme['name'] . '/' . $theme['name'] . '.xml', FILE_USE_INCLUDE_PATH);
    $theme['raw'] = xml2ary($theme['xml']);
    return $theme['raw'];
}
コード例 #3
0
ファイル: compile.php プロジェクト: ReedME/heatCMS
/*
 * compile.php
 * 
 * Retrieves the selected theme's xml file, and retrieves all the resources for it.
 * this is the file that compiles the entire front-end aspect of all pages.
 * 
 * THIS IS NOT a theme's template file, they are located in
 * /assets/themes/YOURTHEME, this file fills a theme's template with data and
 * inserts the compressed assets (js/cs).
 */
// Get the current theme and load its xml file
$theme = array();
$theme['name'] = $this->Database->get_config('theme');
$theme['xml'] = file_get_contents(str_replace('//', '/', dirname(__FILE__) . '/') . '../../assets/themes/' . $theme['name'] . '/' . $theme['name'] . '.xml');
$theme['raw'] = xml2ary($theme['xml']);
$theme['template'] = $theme['raw']['theme']['_c']['resources']['_c']['php']['_c']['file']['_c']['src']['_v'];
// retrieve the js/css assets from the xml
$theme['assets']['css'] = @$theme['raw']['theme']['_c']['resources']['_c']['css']['_c'];
$theme['assets']['js'] = @$theme['raw']['theme']['_c']['resources']['_c']['js']['_c'];
$css = array();
$js = array();
// convert each asset entry from xml data to an array entry
foreach ($theme['assets'] as $type => $files) {
    $files = $files['file'];
    if (!empty($files)) {
        foreach ($files as $file) {
            if (!empty($file['_c'])) {
                $file = $file['_c'];
            }
            $asset_title = $file['title']['_v'];
コード例 #4
0
ファイル: report.inc.php プロジェクト: edt82/ona
function rpt_get_data($form)
{
    global $base, $onadb;
    // If they want to perform a scan on an existing file
    if ($form['subnet']) {
        $rptdata['scansource'] = "Based on an existing scan file for '{$form['subnet']}'";
        //$xml = shell_exec("{$nmapcommand} -sP -R -oX - {$form['subnet']}");
        list($status, $rows, $subnet) = ona_find_subnet($form['subnet']);
        if ($rows) {
            $netip = ip_mangle($subnet['ip_addr'], 'dotted');
            $netcidr = ip_mangle($subnet['ip_mask'], 'cidr');
            $nmapxmlfile = "{$base}/local/nmap_scans/subnets/{$netip}-{$netcidr}.xml";
            if (file_exists($nmapxmlfile)) {
                $xml[0] = xml2ary(file_get_contents($nmapxmlfile));
            } else {
                $self['error'] = "ERROR => The subnet '{$form['subnet']}' does not have an nmap scan XML file on this server. {$nmapxmlfile}";
                return array(2, $self['error'] . "\n");
            }
        } else {
            $self['error'] = "ERROR => The subnet '{$form['subnet']}' does not exist.";
            return array(2, $self['error'] . "\n");
        }
    }
    // If they want to build a report on ALL the nmap data
    if ($form['all']) {
        $rptdata['scansource'] = "Showing all scan data";
        $nmapdir = "{$base}/local/nmap_scans/subnets";
        $dh = @opendir($nmapdir);
        $c = 0;
        while (false !== ($filename = @readdir($dh))) {
            if (strpos($filename, 'xml')) {
                $xml[$c] = xml2ary(file_get_contents($nmapdir . '/' . $filename));
            }
            $c++;
        }
    }
    // If they pass a file from the remote host via CLI
    if ($form['file']) {
        $rptdata['scansource'] = "Based on an uploaded XML file";
        $nmapxmlfile = $form['file'];
        // clean up escaped characters
        $nmapxmlfile = preg_replace('/\\\\"/', '"', $nmapxmlfile);
        $nmapxmlfile = preg_replace('/\\\\=/', '=', $nmapxmlfile);
        $nmapxmlfile = preg_replace('/\\\\&/', '&', $nmapxmlfile);
        $xml[0] = xml2ary($nmapxmlfile);
    }
    // loop through all the xml arrays that have been built.
    for ($z = 0; $z < count($xml); $z++) {
        // Find out how many total hosts we have in the array
        $rptdata['totalhosts'] = $xml[$z]['nmaprun']['_c']['runstats']['_c']['hosts']['_a']['total'];
        $rptdata['runtime'] = $xml[$z]['nmaprun']['_c']['runstats']['_c']['finished']['_a']['timestr'];
        // pull args to find subnet/cidr
        $rptdata['args'] = $xml[$z]['nmaprun']['_a']['args'];
        // process args
        list($subnetaddr, $netcidr) = explode('/', preg_replace("/.* (.*)\\/(\\d+)\$/", "\\1/\\2", $rptdata['args']));
        $netip = ip_mangle($subnetaddr, 'dotted');
        $netcidr = ip_mangle($netcidr, 'cidr');
        // Process the array for the total amount of hosts reported
        for ($i = 0; $i < $rptdata['totalhosts']; $i++) {
            // Clear MAC each itteration of the loop
            $macaddr = '';
            // Gather some info from the nmap XML file
            $netstatus = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['status']['_a']['state'];
            $ipaddr = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['address']['_a']['addr'];
            //$macaddr = $xml['nmaprun']['_c']['host'][$i]['_c']['address']['_a']['addr'];
            $dnsname = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['hostnames']['_c']['hostname']['_a']['name'];
            $dnsrows = 0;
            $dns = array();
            // Try the older nmap format if no IP found.. not sure of what differences there are in the XSL used?
            if (!$ipaddr) {
                $ipaddr = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['address']['0']['_a']['addr'];
                $macaddr = $xml[$z]['nmaprun']['_c']['host'][$i]['_c']['address']['1']['_a']['addr'];
            }
            // Lookup the IP address in the database
            if ($ipaddr) {
                list($status, $introws, $interface) = ona_find_interface($ipaddr);
                if (!$introws) {
                    $interface['ip_addr_text'] = 'NOT FOUND';
                    list($status, $introws, $tmp) = ona_find_subnet($ipaddr);
                    $interface['subnet_id'] = $tmp['id'];
                } else {
                    // Lookup the DNS name in the database
                    list($status, $dnsrows, $dnscount) = db_get_records($onadb, 'dns', "interface_id = {$interface['id']}", "", 0);
                    list($status, $dnsptrrows, $dnsptr) = ona_get_dns_record(array('interface_id' => $interface['id'], 'type' => 'PTR'));
                    list($status, $dnsprows, $dns) = ona_get_dns_record(array('id' => $dnsptr['dns_id']));
                }
            }
            // Find out if this IP falls inside of a pool
            $inpool = 0;
            $ip = ip_mangle($ipaddr, 'numeric');
            if ($ip > 0) {
                list($status, $poolrows, $pool) = ona_get_dhcp_pool_record("ip_addr_start <= '{$ip}' AND ip_addr_end >= '{$ip}'");
            }
            if ($poolrows) {
                $inpool = 1;
            }
            // some base logic
            // if host is up in nmap but no db ip then put in $nodb
            // if host is up and is in db then put in $noissue
            // if host is down and not in db then skip
            // if host is down and in db then put in $nonet
            // if host is up an in db, does DNS match?
            //    in DNS but not DB
            //    in DB but not DNS
            //    DNS and DB dont match
            // Setup the base array element for the IP
            $rptdata['ip'][$ipaddr] = array();
            $rptdata['ip'][$ipaddr]['netstatus'] = $netstatus;
            $rptdata['ip'][$ipaddr]['netip'] = $ipaddr;
            $rptdata['ip'][$ipaddr]['netdnsname'] = strtolower($dnsname);
            if ($macaddr != -1) {
                $rptdata['ip'][$ipaddr]['netmacaddr'] = $macaddr;
            }
            $rptdata['ip'][$ipaddr]['inpool'] = $inpool;
            $rptdata['ip'][$ipaddr]['dbip'] = $interface['ip_addr_text'];
            $rptdata['ip'][$ipaddr]['dbsubnetid'] = $interface['subnet_id'];
            $rptdata['ip'][$ipaddr]['dbdnsrows'] = $dnsrows;
            if (!$dns['fqdn']) {
                // lets see if its a PTR record
                if ($dnsptrrows) {
                    // If we have a PTR for this interface, use it (never if built from ona?)
                    $rptdata['ip'][$ipaddr]['dbdnsname'] = $dns['fqdn'];
                    $rptdata['ip'][$ipaddr]['dbdnsptrname'] = $dnsp['fqdn'];
                } else {
                    // find the hosts primary DNS record
                    list($status, $hostrows, $host) = ona_get_host_record(array('id' => $interface['host_id']));
                    if ($host['fqdn']) {
                        $host['fqdn'] = "({$host['fqdn']})";
                    }
                    if ($dnsrows) {
                        list($status, $dnstmprows, $dnstmp) = ona_get_dns_record(array('interface_id' => $interface['id']));
                        $rptdata['ip'][$ipaddr]['dbdnsname'] = $dnstmp['fqdn'];
                    } else {
                        $rptdata['ip'][$ipaddr]['dbdnsname'] = 'NO PTR';
                    }
                    $rptdata['ip'][$ipaddr]['dbdnsptrname'] = $host['fqdn'];
                }
            } else {
                if ($dnsptrrows > 1) {
                    $rptdata['ip'][$ipaddr]['dbdnsname'] = $dns['fqdn'];
                    $rptdata['ip'][$ipaddr]['dbdnsptrname'] = $dnsp['fqdn'];
                } else {
                    $rptdata['ip'][$ipaddr]['dbdnsname'] = $dns['fqdn'];
                    $rptdata['ip'][$ipaddr]['dbdnsptrname'] = $dnsp['fqdn'];
                }
            }
            $rptdata['ip'][$ipaddr]['dbmacaddr'] = $interface['mac_addr'];
            $rptdata['netip'] = $netip;
            $rptdata['netcidr'] = $netcidr;
            if ($form['all']) {
                $rptdata['all'] = 1;
            }
            if ($form['update_response']) {
                $rptdata['update_response'] = 1;
            }
        }
    }
    return array(0, $rptdata);
}
コード例 #5
0
============================================================================================
*/
require_once "xml2json.php";
// Filename from where XML contents are to be read.
$testXmlFile = "";
//// Read the filename from the command line.
//if ($argc <= 1) {
//	print("Please provide the XML filename as a command-line argument:\n");
//	print("\tphp -f xml2json_test.php test1.xml\n");
//	return;
//} else {
//	$testXmlFile = $argv[1];
//}
$testXmlFile = "test1.xml";
include 'xml2ary.php';
$xml = xml2ary(file_get_contents('test1.xml'));
//print_r($xml);
echo json_encode($xml);
/*
//Get the XML document loaded into a variable
$xml = file_get_contents($testXmlFile);
//Set up the parser object
$parser = new XMLParser($xml);

//Work the magic...
//$parser->Parse();

echo  json_encode($parser->document);


コード例 #6
0
ファイル: lib_annot.php プロジェクト: gisly/opencorpora
 private function _from_xml($xml)
 {
     $arr = xml2ary($xml);
     $this->token_text = $arr['tfr']['_a']['t'];
     $xml_arr = $arr['tfr']['_c']['v'];
     if (isset($xml_arr['_c']) && is_array($xml_arr['_c'])) {
         //the only variant
         $this->parses[] = new MorphParse();
         $this->parses[0]->from_xml_ary($xml_arr);
         $this->parses[0]->gramlist = self::_fill_gram_info($this->parses[0]->gramlist);
     } elseif (is_array($xml_arr)) {
         //multiple variants
         foreach ($xml_arr as $i => $xml_var_arr) {
             $this->parses[] = new MorphParse();
             $this->parses[$i]->from_xml_ary($xml_var_arr);
             $this->parses[$i]->gramlist = self::_fill_gram_info($this->parses[$i]->gramlist);
         }
     } else {
         throw new Exception();
     }
 }
コード例 #7
0
ファイル: sanrss.php プロジェクト: valhallaGaming/cuatro
            $res[] = ">" . (isset($r['_c']) ? "\n" : '');
            if (isset($r['_c'])) {
                $res[] = ary2xml($r['_c'], $d + 1);
            } elseif (isset($r['_v'])) {
                $res[] = $r['_v'];
            }
            $res[] = (isset($r['_c']) ? $sp : '') . "</{$tag}>\n";
        }
    }
    return implode('', $res);
}
// Insert element into array
function ins2ary(&$ary, $element, $pos)
{
    $ar1 = array_slice($ary, 0, $pos);
    $ar1[] = $element;
    $ary = array_merge($ar1, array_slice($ary, $pos));
}
$html = file_get_contents("http://san.mta.vg/blog/feed/");
$rss = xml2ary($html);
$items = $rss["rss"]["_c"]["channel"]["_c"]["item"];
$array = array();
foreach ($items as $article) {
    $item["title"] = utf8_decode($article["_c"]["title"]["_v"]);
    $item["url"] = $article["_c"]["link"]["_v"];
    $item["autor"] = $article["_c"]["dc:creator"]["_v"];
    $item["date"] = date("F j, Y", strtotime($article["_c"]["pubDate"]["_v"]));
    $array[] = $item;
}
//print_r($array);
mta::doReturn($array);
コード例 #8
0
ファイル: side_last_fm.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_lang('last_fm');
     require_code('files');
     $display = !empty($map['display']) ? $map['display'] : 'artists';
     $period = !empty($map['period']) ? $map['period'] : 12;
     $username = array_key_exists('username', $map) ? $map['username'] : '';
     $width = !empty($map['width']) ? $map['width'] : '100%';
     //default: 100%
     $height = !empty($map['height']) ? $map['height'] : '100%';
     //default: 100%
     $title = !empty($map['title']) ? $map['title'] : do_lang_tempcode('BLOCK_LAST_FM_TITLE');
     if ($username == '') {
         $profile_url = 'http://www.last.fm/';
     } else {
         $profile_url = 'http://www.last.fm/user/' . $username;
     }
     if ($height != '100%') {
         $out = '<div style="overflow: auto; width: ' . $width . '!important; height: ' . $height . '!important;">';
     } else {
         $out = '<div style="overflow: auto; width: ' . $width . '!important;">';
     }
     $rss_url = '';
     if ($username == '') {
         if ($display == 'artists') {
             $rss_url = 'http://ws.audioscrobbler.com/2.0/chart/topartists.xml';
         } elseif ($display == 'albums') {
             $rss_url = 'http://ws.audioscrobbler.com/2.0/chart/topalbums.xml';
         } elseif ($display == 'tracks') {
             $rss_url = 'http://ws.audioscrobbler.com/2.0/chart/toptracks.xml';
         }
     } else {
         if ($display == 'artists') {
             $rss_url = 'http://ws.audioscrobbler.com/2.0/user/' . $username . '/topartists.xml';
         } elseif ($display == 'albums') {
             $rss_url = 'http://ws.audioscrobbler.com/2.0/user/' . $username . '/topalbums.xml';
         } elseif ($display == 'tracks') {
             $rss_url = 'http://ws.audioscrobbler.com/2.0/user/' . $username . '/toptracks.xml';
         }
     }
     if ($period == 3) {
         $rss_url .= '?period=3month';
     } elseif ($period == 6) {
         $rss_url .= '?period=6month';
     } elseif ($period == 12) {
         $rss_url .= '?period=12month';
     } elseif ($period == 'overall' || $period == '' || !isset($period)) {
         $rss_url .= '?period=overall';
     }
     //read XML into array
     $xml = xml2ary(http_download_file($rss_url));
     if (preg_match('#toptracks\\.xml#', $rss_url)) {
         if (isset($xml['toptracks']['_c']['track']) && is_array($xml['toptracks']['_c']['track'])) {
             foreach ($xml['toptracks']['_c']['track'] as $track) {
                 $track_name = isset($track['_c']['name']['_v']) && strlen($track['_c']['name']['_v']) > 0 ? $track['_c']['name']['_v'] : '';
                 $playcount = isset($track['_c']['playcount']['_v']) && $track['_c']['playcount']['_v'] > 0 ? $track['_c']['playcount']['_v'] : 0;
                 $track_url = isset($track['_c']['url']['_v']) && strlen($track['_c']['url']['_v']) > 0 ? $track['_c']['url']['_v'] : '';
                 $artist = isset($track['_c']['artist']['_c']['name']['_v']) && strlen($track['_c']['artist']['_c']['name']['_v']) > 0 ? $track['_c']['artist']['_c']['name']['_v'] : '';
                 $artist_url = isset($track['_c']['artist']['_c']['url']['_v']) && strlen($track['_c']['artist']['_c']['url']['_v']) > 0 ? $track['_c']['artist']['_c']['url']['_v'] : '';
                 $images = array();
                 if (isset($track['_c']['image']) && is_array($track['_c']['image'])) {
                     foreach ($track['_c']['image'] as $image) {
                         if (isset($image['_a']['size']) && strlen($image['_a']['size']) > 0) {
                             $images[$image['_a']['size']] = isset($image['_v']) && strlen($image['_v']) > 0 ? $image['_v'] : '';
                         }
                     }
                 }
                 $track_images = isset($images['medium']) ? $images['medium'] : '';
                 if ($track_images == '' && count($images) > 0) {
                     $track_images = array_shift($images);
                 }
                 if ($track_images != '') {
                     $out .= '<div class="float_surrounder"><img width="64" src="' . $track_images . '" title="" style="float: left; margin: 3px;" /><a href="' . $track_url . '" target="_blank">' . $track_name . '</a><br />';
                     $out .= '<a href="' . $artist_url . '" target="_blank" style="font-style: italic;">' . $artist . '</a><br />';
                     $out .= 'Total Plays: ' . $playcount . '</div><br />';
                 } else {
                     $out .= '<div class="float_surrounder"><a href="' . $track_url . '" target="_blank">' . $track_name . '</a><br />';
                     $out .= '<a href="' . $artist_url . '" target="_blank" style="font-style: italic;">' . $artist . '</a><br />';
                     $out .= 'Total Plays: ' . $playcount . '</div><br />';
                 }
             }
         }
     } elseif (preg_match('#topartists\\.xml#', $rss_url)) {
         if (isset($xml['topartists']['_c']['artist']) && is_array($xml['topartists']['_c']['artist'])) {
             foreach ($xml['topartists']['_c']['artist'] as $artist_item) {
                 $playcount = isset($artist_item['_c']['playcount']['_v']) && $artist_item['_c']['playcount']['_v'] > 0 ? $artist_item['_c']['playcount']['_v'] : 0;
                 $artist = isset($artist_item['_c']['name']['_v']) && strlen($artist_item['_c']['name']['_v']) > 0 ? $artist_item['_c']['name']['_v'] : '';
                 $artist_url = isset($artist_item['_c']['url']['_v']) && strlen($artist_item['_c']['url']['_v']) > 0 ? $artist_item['_c']['url']['_v'] : '';
                 $images = array();
                 if (isset($artist_item['_c']['image']) && is_array($artist_item['_c']['image'])) {
                     foreach ($artist_item['_c']['image'] as $image) {
                         if (isset($image['_a']['size']) && strlen($image['_a']['size']) > 0) {
                             $images[$image['_a']['size']] = isset($image['_v']) && strlen($image['_v']) > 0 ? $image['_v'] : '';
                         }
                     }
                 }
                 $artist_image = isset($images['medium']) ? $images['medium'] : '';
                 if ($artist_image == '' && count($images) > 0) {
                     $artist_image = array_shift($images);
                 }
                 if ($artist_image != '') {
                     $out .= '<div class="float_surrounder"><img width="64" src="' . $artist_image . '" title="" style="float: left; margin: 3px;" />';
                     $out .= '<a href="' . $artist_url . '" target="_blank" style="font-style: italic;">' . $artist . '</a><br />';
                     $out .= 'Total Plays: ' . $playcount . '</div><br />';
                 } else {
                     $out .= '<a href="' . $artist_url . '" target="_blank" style="font-style: italic;">' . $artist . '</a><br />';
                     $out .= 'Total Plays: ' . $playcount . '</div><br />';
                 }
             }
         }
     } elseif (preg_match('#topalbums\\.xml#', $rss_url)) {
         if (isset($xml['topalbums']['_c']['album']) && is_array($xml['topalbums']['_c']['album'])) {
             foreach ($xml['topalbums']['_c']['album'] as $album) {
                 $album_name = isset($album['_c']['name']['_v']) && strlen($album['_c']['name']['_v']) > 0 ? $album['_c']['name']['_v'] : '';
                 $playcount = isset($album['_c']['playcount']['_v']) && $album['_c']['playcount']['_v'] > 0 ? $album['_c']['playcount']['_v'] : 0;
                 $album_url = isset($album['_c']['url']['_v']) && strlen($album['_c']['url']['_v']) > 0 ? $album['_c']['url']['_v'] : '';
                 $artist = isset($album['_c']['artist']['_c']['name']['_v']) && strlen($album['_c']['artist']['_c']['name']['_v']) > 0 ? $album['_c']['artist']['_c']['name']['_v'] : '';
                 $artist_url = isset($album['_c']['artist']['_c']['url']['_v']) && strlen($album['_c']['artist']['_c']['url']['_v']) > 0 ? $album['_c']['artist']['_c']['url']['_v'] : '';
                 $images = array();
                 if (isset($album['_c']['image']) && is_array($album['_c']['image'])) {
                     foreach ($album['_c']['image'] as $image) {
                         if (isset($image['_a']['size']) && strlen($image['_a']['size']) > 0) {
                             $images[$image['_a']['size']] = isset($image['_v']) && strlen($image['_v']) > 0 ? $image['_v'] : '';
                         }
                     }
                 }
                 $album_images = isset($images['medium']) ? $images['medium'] : '';
                 if ($album_images == '' && count($images) > 0) {
                     $album_images = array_shift($images);
                 }
                 if ($album_images != '') {
                     $out .= '<div class="float_surrounder"><img width="64" src="' . $album_images . '" title="" style="float: left; margin: 3px;" /><a href="' . $album_url . '" target="_blank">' . $album_name . '</a><br />';
                     $out .= '<a href="' . $artist_url . '" target="_blank" style="font-style: italic;">' . $artist . '</a><br />';
                     $out .= 'Total Plays: ' . $playcount . '</div><br />';
                 } else {
                     $out .= '<div class="float_surrounder"><a href="' . $album_url . '" target="_blank">' . $album_name . '</a><br />';
                     $out .= '<a href="' . $artist_url . '" target="_blank" style="font-style: italic;">' . $artist . '</a><br />';
                     $out .= 'Total Plays: ' . $playcount . '</div><br />';
                 }
             }
         }
     }
     $out .= '<br style="" /><a href="' . escape_html($profile_url) . '" target="_blank" style="font-style: italic;">Click here for more...</a></div>';
     return do_template('BLOCK_SIDE_LAST_FM', array('TITLE' => $title, 'CONTENT' => $out));
 }
コード例 #9
0
ファイル: lib_dict.php プロジェクト: ayunah/opencorpora
function parse_dict_rev($text)
{
    // output has the following structure:
    // lemma => array (text => lemma_text, grm => array (grm1, grm2, ...)),
    // forms => array (
    //     [0] => array (text => form_text, grm => array (grm1, grm2, ...)),
    //     [1] => ...
    // )
    $arr = xml2ary($text);
    $arr = $arr['dr']['_c'];
    $parsed = array();
    $parsed['lemma']['text'] = $arr['l']['_a']['t'];
    //the rest of the function should be refactored
    $t = array();
    foreach ($arr['l']['_c']['g'] as $garr) {
        if (isset($garr['v'])) {
            //if there is only one grammem
            $t[] = $garr['v'];
            break;
        }
        $t[] = $garr['_a']['v'];
    }
    $parsed['lemma']['grm'] = $t;
    if (isset($arr['f']['_a'])) {
        //if there is only one form
        $parsed['forms'][0]['text'] = $arr['f']['_a']['t'];
        $t = array();
        if (isset($arr['f']['_c'])) {
            //if there are grammems at all
            foreach ($arr['f']['_c']['g'] as $garr) {
                if (isset($garr['v'])) {
                    //if there is only one grammem
                    $t[] = $garr['v'];
                    break;
                }
                $t[] = $garr['_a']['v'];
            }
        }
        $parsed['forms'][0]['grm'] = $t;
    } else {
        foreach ($arr['f'] as $k => $farr) {
            $parsed['forms'][$k]['text'] = $farr['_a']['t'];
            $t = array();
            foreach ($farr['_c']['g'] as $garr) {
                if (isset($garr['v'])) {
                    //if there is only one grammem
                    $t[] = $garr['v'];
                    break;
                }
                $t[] = $garr['_a']['v'];
            }
            $parsed['forms'][$k]['grm'] = $t;
        }
    }
    return $parsed;
}
コード例 #10
0
function coordToLocationOk($lat, $lon)
{
    $xml = "";
    $file = fopen('http://maps.google.com/maps/geo?q=' . $lat . ',' . $lon . '&output=xml&oe=utf8&sensor=false&key=your_api_key&hl=pl', 'r');
    while (!feof($file)) {
        $xml .= fread($file, 1024);
    }
    fclose($file);
    $array = xml2ary($xml);
    for ($i = 0; $i < 20; $i++) {
        $country = $array["kml"]["_c"]["Response"]["_c"]["Placemark"][$i]["_c"]["AddressDetails"]["_c"]["Country"]["_c"]["CountryName"]["_v"];
        $adm1 = $array["kml"]["_c"]["Response"]["_c"]["Placemark"][$i]["_c"]["AddressDetails"]["_c"]["Country"]["_c"]["AdministrativeArea"]["_c"]["AdministrativeAreaName"]["_v"];
        $adm2 = $array["kml"]["_c"]["Response"]["_c"]["Placemark"][$i]["_c"]["AddressDetails"]["_c"]["Country"]["_c"]["AdministrativeArea"]["_c"]["SubAdministrativeArea"]["_c"]["SubAdministrativeAreaName"]["_v"];
        if ($country != "" && $adm1 != "") {
            break;
        }
    }
    return array($country, $adm1, $adm2);
}
コード例 #11
0
ファイル: fetch_rank.php プロジェクト: jliman/SEOStat
require_once 'inc/fetch.php';
$fetchGooglePR = true;
$fetchAlexa = true;
$saveToDB = true;
echo 'Start fetch Web Rank: ' . date("Y-m-d H:i:s") . '<br>';
foreach ($accounts as $account) {
    echo 'Get stat for: ' . $account['url'] . ' - ' . date("Y-m-d H:i:s") . '<br>';
    $result = array();
    if ($fetchAlexa) {
        //alexa rank
        //http://xml.alexa.com/data?cli=10&url=[siteurl]
        $ch = getCURLResource();
        curl_setopt($ch, CURLOPT_URL, "http://xml.alexa.com/data?cli=10&url=" . $account['url']);
        $buf2 = curl_exec($ch);
        curl_close($ch);
        $xml = xml2ary($buf2);
        $alexarank = $xml['ALEXA']['_c']['SD']['_c']['POPULARITY']['_a']['TEXT'];
        echo 'Alexa rank: ' . $alexarank . '<br>';
    }
    $result['alexarank'] = $alexarank;
    if ($fetchGooglePR) {
        $gpr = new GooglePR();
        $gpr->userAgent = $_SERVER["HTTP_USER_AGENT"];
        $gpr->cacheDir = dirname(__FILE__) . "/prcache";
        $gpr->maxCacheAge = 86400;
        $gpr->useCache = false;
        $googlepr = $gpr->GetPR($account['url']);
        echo 'Google pagerank: ' . $googlepr . '<br>';
    }
    $result['grank'] = $googlepr;
    if ($saveToDB) {