Пример #1
0
 /**
  * Builder::CreateAsCopySXMLNode()
  *
  * @param $node
  * @param string $tag
  * @param array $attrs
  * @return DOMNode|mixed
  */
 public function CreateAsCopySXMLNode($node, $tag = '', $attrs = array())
 {
     $xml = new SimpleXMLElement("<{$tag}/>");
     foreach ($node->children() as $subnode) {
         xml_join($xml, $subnode);
     }
     $node = new DOMDocument();
     $node->loadXML($xml->asXML());
     $node = $this->doc->importNode($node->documentElement, true);
     return $node;
 }
Пример #2
0
function xml_join(&$root, &$append)
{
    if (is_object($append) && get_class($append) == 'SimpleXMLElement') {
        if (strlen(trim((string) $append)) == 0) {
            $xml = $root->addChild($append->getName());
            foreach ($append->children() as $child) {
                xml_join($xml, $child);
            }
        } else {
            $value = (string) $append;
            MakeCdata($value);
            $xml = $root->addChild($append->getName(), $value);
        }
        foreach ($append->attributes() as $n => $v) {
            $xml->addAttribute($n, $v);
        }
    } else {
    }
}
Пример #3
0
/**
 * Convert XML result into videoDB result array
 *
 * @author  Andreas Goetz <*****@*****.**>
 * @param   domNode dvd     Parent XML document node to start search
 * @param   boolean short   Return title & id only
 * @return  array    	    The converted result set for a single item
 */
function awsNodeData($item, $short = false)
{
    $data = array();
    // Id
    $data['id'] = (string) $item->ASIN;
    // Title
    $data['title'] = (string) $item->ItemAttributes->Title;
    // small image for overview
    $data['imgsmall'] = (string) $item->SmallImage->URL;
    // cover url for image lookup
    $data['coverurl'] = (string) $item->LargeImage->URL;
    if (empty($data['coverurl'])) {
        $data['coverurl'] = $data['imgsmall'];
    }
    /**
     * Purchase-specific data
     */
    // Title
    $data['price'] = (string) $item->ItemAttributes->ListPrice->FormattedPrice;
    // url
    $data['url'] = (string) $item->DetailPageURL;
    // exit if called from search function
    if ($short) {
        return $data;
    }
    // Year
    $date = $item->ItemAttributes->TheatricalReleaseDate;
    if (empty($date)) {
        $date = $item->ItemAttributes->ReleaseDate;
    }
    if (preg_match('/\\d{4}/', $date, $m)) {
        $data['year'] = $m[0];
    }
    // MPAA Rating
    $data['mpaa'] = (string) $item->ItemAttributes->AudienceRating;
    // Runtime
    $data['runtime'] = (string) $item->ItemAttributes->RunningTime;
    // Director
    $data['director'] = xml_join($item->ItemAttributes->Director, ',');
    // Rating
    $data['rating'] = round($item->CustomerReviews->AverageRating * 2, 1);
    // Countries
    #	$data['country']  = join(' ',$m[1]));
    // Media
    $data['mediatype'] = awsGetMediatypeId((string) $item->ItemAttributes->Binding);
    /*
    	// Genres (as Array), map to nearest match
    	$genres = getElement($dvd, 'BrowseList/BrowseNode/BrowseName', ',');
        foreach (mapGenres(explode(',', $genres)) as $genre)
        {
            $data['genres'][] = $genre;
        }
    */
    // Cast
    $data['cast'] = xml_join($item->ItemAttributes->Actor);
    // Plot
    $data['plot'] = xml_join($item->EditorialReviews->EditorialReview->Content, "\n\n");
    if (empty($data['plot'])) {
        // use customer reviews if plot not found
        $data['plot'] = xml_join($item->CustomerReviews->Review->Content);
    }
    // Country
    foreach ($item->ItemAttributes->Languages->Language as $row) {
        $lang = strtolower(trim($row->Name));
        if (!stristr($data['language'], $lang)) {
            $data['language'] .= $data['language'] ? ', ' : '';
            $data['language'] .= $lang;
        }
    }
    /*	
    	// Tracks
    	$tracks				= xml_join($item->Tracks->Track);
    	$data['tracks']		= $tracks;
    
        // convert to numbered track list
    	$track_number		= 1;
        foreach (explode("\n", $tracks) as $track)
        {
    		$track = trim($track);
    		if ($tracks) {
    			$tracks_formatted .= $track_number++;
    			$tracks_formatted .= '. '.$track."\n";
    		}
    	}
    
        // append to plot as long as we don't have a separate field
    	if ($data['plot']) $data['plot'] .= "\n\n";
    	$data['plot']   .= $tracks_formatted;
    */
    foreach (array('AspectRatio', 'Format', 'Label') as $node) {
        $val = $node . ': ' . xml_join($item->ItemAttributes->{$node});
        if ($val) {
            $data['comment'] .= ($data['comment'] ? "\n" : '') . $val;
        }
    }
    return $data;
}
Пример #4
0
 function AgregateNode($id)
 {
     $node = $this->xml_blocks[$id]['content'];
     foreach ($this->xml_blocks[$id]['children'] as $child_id) {
         $child = $this->AgregateNode($child_id);
         xml_join($node, $child);
     }
     return $node;
 }
Пример #5
0
function xml_join($root, $append)
{
    if ($append) {
        if (strlen(trim((string) $append)) == 0) {
            $xml = $root->addChild($append->getName());
            foreach ($append->children() as $child) {
                xml_join($xml, $child);
            }
        } else {
            $xml = $root->addChild($append->getName(), (string) $append);
        }
        foreach ($append->attributes() as $n => $v) {
            $xml->addAttribute($n, $v);
        }
    }
}