Ejemplo n.º 1
0
/**
 * Transforme un objet SimpleXML en tableau PHP
 * http://www.php.net/manual/pt_BR/book.simplexml.php#108688
 * xaviered at gmail dot com 17-May-2012 07:00
 *
 * @param object $obj
 * @param bool $utiliser_namespace
 * @return array
**/
function xmlObjToArr($obj, $utiliser_namespace = false)
{
    $tableau = array();
    // Cette fonction getDocNamespaces() est longue sur de gros xml. On permet donc
    // de l'activer ou pas suivant le contenu supposé du XML
    if (is_object($obj)) {
        if (is_array($utiliser_namespace)) {
            $namespace = $utiliser_namespace;
        } else {
            if ($utiliser_namespace) {
                $namespace = $obj->getDocNamespaces(true);
            }
            $namespace[NULL] = NULL;
        }
        $name = strtolower((string) $obj->getName());
        $text = trim((string) $obj);
        if (strlen($text) <= 0) {
            $text = NULL;
        }
        $children = array();
        $attributes = array();
        // get info for all namespaces
        foreach ($namespace as $ns => $nsUrl) {
            // attributes
            $objAttributes = $obj->attributes($ns, true);
            foreach ($objAttributes as $attributeName => $attributeValue) {
                $attribName = strtolower(trim((string) $attributeName));
                $attribVal = trim((string) $attributeValue);
                if (!empty($ns)) {
                    $attribName = $ns . ':' . $attribName;
                }
                $attributes[$attribName] = $attribVal;
            }
            // children
            $objChildren = $obj->children($ns, true);
            foreach ($objChildren as $childName => $child) {
                $childName = strtolower((string) $childName);
                if (!empty($ns)) {
                    $childName = $ns . ':' . $childName;
                }
                $children[$childName][] = xmlObjToArr($child, $namespace);
            }
        }
        $tableau = array('name' => $name);
        if ($text) {
            $tableau['text'] = $text;
        }
        if ($attributes) {
            $tableau['attributes'] = $attributes;
        }
        if ($children) {
            $tableau['children'] = $children;
        }
    }
    return $tableau;
}
function xmlObjToArr($obj) {
    # Cette fonction getDocNamespaces est tres gourmande sur de gros fichiers
    # $namespace = $obj->getDocNamespaces(true);
     
            $namespace[NULL] = NULL;
     
            $children = array();
            $attributes = array();
            $name = strtolower((string)$obj->getName());
     
            $text = trim((string)$obj);
            if( strlen($text) <= 0 ) {
                $text = NULL;
            }
     
            // get info for all namespaces
            if(is_object($obj)) {
                foreach( $namespace as $ns=>$nsUrl ) {
                    // atributes
                    $objAttributes = $obj->attributes($ns, true);
                    foreach( $objAttributes as $attributeName => $attributeValue ) {
                        $attribName = strtolower(trim((string)$attributeName));
                        $attribVal = trim((string)$attributeValue);
                        if (!empty($ns)) {
                            $attribName = $ns . ':' . $attribName;
                        }
                        $attributes[$attribName] = $attribVal;
                    }
     
                    // children
                    $objChildren = $obj->children($ns, true);
                    foreach( $objChildren as $childName=>$child ) {
                        $childName = strtolower((string)$childName);
                        if( !empty($ns) ) {
                            $childName = $ns.':'.$childName;
                        }
                        $children[$childName][] = xmlObjToArr($child);
                    }
                }
            }
     
            return array(
                'name'=>$name,
                'text'=>$text,
                'attributes'=>$attributes,
                'children'=>$children
            );
        }
Ejemplo n.º 3
0
 /**
  * Get Proxy file path by guid from crawford server.
  * 
  * @param string $guid
  * @return boolean/array
  */
 function proxy_files($guid)
 {
     $proxy_guid = str_replace('/', '-', $guid);
     $proxy_response = file_get_contents("http://cpbaaaccess.crawfordmedia.com/xml.php?GUID={$proxy_guid}");
     $x = @simplexml_load_string($proxy_response);
     if (is_object($x)) {
         $data = xmlObjToArr($x);
         $child = $data['children'];
         if (isset($data['name']) && $data['name'] == 'error') {
             return FALSE;
         } else {
             if (isset($child['mediaurl'][0])) {
                 $media['url'] = $child['mediaurl'][0]['text'];
             }
             if (isset($child['format'][0])) {
                 $media['format'] = $child['format'][0]['text'];
             }
             return $media;
         }
     }
     return FALSE;
 }
Ejemplo n.º 4
0
 /**
  * Process all pending PBCore 1.x files.
  * @param type $folder_id
  * @param type $station_cpb_id
  * @param type $offset
  * @param type $limit 
  */
 function process_xml_file_child($folder_id, $station_cpb_id, $offset = 0, $limit = 100)
 {
     error_reporting(E_ALL);
     ini_set('display_errors', 1);
     $station_data = $this->station_model->get_station_by_cpb_id($station_cpb_id);
     if (isset($station_data) && !empty($station_data) && isset($station_data->id)) {
         $folder_data = $this->cron_model->get_data_folder_by_id($folder_id);
         if ($folder_data) {
             $data_files = $this->cron_model->get_pbcore_file_by_folder_id($folder_data->id, $offset, $limit);
             if (isset($data_files) && !is_empty($data_files)) {
                 foreach ($data_files as $d_file) {
                     if ($d_file->is_processed == 0) {
                         $this->cron_model->update_prcoess_data(array("processed_start_at" => date('Y-m-d H:i:s')), $d_file->id);
                         $file_path = '';
                         $file_path = trim($folder_data->folder_path . $d_file->file_path);
                         if (file_exists($file_path)) {
                             //																																$this->myLog("Currently Parsing Files "	.	$file_path);
                             $asset_data = file_get_contents($file_path);
                             if (isset($asset_data) && !empty($asset_data)) {
                                 $asset_xml_data = @simplexml_load_string($asset_data);
                                 $asset_d = xmlObjToArr($asset_xml_data);
                                 //$this->db->trans_start	();
                                 $asset_id = $this->assets_model->insert_assets(array("stations_id" => $station_data->id, "created" => date("Y-m-d H:i:s")));
                                 //																																				echo	"\n in Process \n";
                                 $asset_children = $asset_d['children'];
                                 if (isset($asset_children)) {
                                     //echo "<pre>";
                                     //print_r($asset_children);
                                     // Assets Start
                                     //																																								$this->myLog(" Assets Start ");
                                     $this->import_assets($asset_children, $asset_id);
                                     //																																								$this->myLog(" Assets Ends ");
                                     // Assets End
                                     // Instantiation Start
                                     //																																								$this->myLog(" Instantiation Start ");
                                     $this->import_instantiations($asset_children, $asset_id);
                                     // Instantiation End
                                     //																																								$this->myLog(" Instantiation End ");
                                     $this->cron_model->update_prcoess_data(array('is_processed' => 1, "processed_at" => date('Y-m-d H:i:s'), 'status_reason' => 'Complete'), $d_file->id);
                                 } else {
                                     $this->myLog(" Attribut children not found " . $file_path);
                                     $this->cron_model->update_prcoess_data(array('status_reason' => 'attribut_children_not_found'), $d_file->id);
                                 }
                                 //$this->db->trans_complete	();
                                 unset($asset_d);
                                 unset($asset_xml_data);
                                 unset($asset_data);
                             } else {
                                 $this->myLog(" Data is empty in file " . $file_path);
                                 $this->cron_model->update_prcoess_data(array('status_reason' => 'data_empty'), $d_file->id);
                             }
                         } else {
                             $this->myLog(" Is File Check Issues " . $file_path);
                             $this->cron_model->update_prcoess_data(array('status_reason' => 'file_not_found'), $d_file->id);
                         }
                     } else {
                         $this->myLog(" Already Processed " . $file_path);
                         $this->cron_model->update_prcoess_data(array('status_reason' => 'already_processed'), $d_file->id);
                     }
                 }
                 unset($data_files);
             } else {
                 $this->myLog(" Data files not found " . $file_path);
             }
         } else {
             $this->myLog(" folders Data not found " . $file_path);
         }
     } else {
         $this->myLog(" Station data not Found against " . $station_cpb_id);
     }
 }
Ejemplo n.º 5
0
 /**
  * Parse XML file for importing.
  * 
  * @param string $path file path
  */
 function parse_xml_file($path, $station_id)
 {
     error_reporting(E_ALL);
     ini_set('display_errors', 1);
     @ini_set("max_execution_time", 999999999999.0);
     myLog($path);
     $file_content = file_get_contents($this->mint_path . 'unzipped/' . $path);
     $xml_string = @simplexml_load_string($file_content);
     unset($file_content);
     $xmlArray = xmlObjToArr($xml_string);
     foreach ($xmlArray['children']['ams:pbcoredescriptiondocument'] as $document) {
         if (isset($document['children'])) {
             $asset_id = $this->assets_model->insert_assets(array("stations_id" => $station_id, "created" => date("Y-m-d H:i:s")));
             myLog('Created Asset ID ' . $asset_id);
             $this->import_asset_info($asset_id, $station_id, $document['children']);
             myLog('Successfully inserted assets info.');
             $this->import_instantiation_info($asset_id, $document['children']);
             myLog('Successfully imported all the information to AMS');
         }
     }
 }
Ejemplo n.º 6
0
function xmlObjToArr($obj)
{
    /**
     * convert xml objects to array
     * function from http://php.net/manual/pt_BR/book.simplexml.php
     * as posted by xaviered at gmail dot com 17-May-2012 07:00
     * NOTE: return array() ('name'=>$name) commented out; not needed to parse xlsx
     */
    $namespace = $obj->getDocNamespaces(true);
    $namespace[NULL] = NULL;
    $children = array();
    $attributes = array();
    $name = strtolower((string) $obj->getName());
    $text = trim((string) $obj);
    if (strlen($text) <= 0) {
        $text = NULL;
    }
    // get info for all namespaces
    if (is_object($obj)) {
        foreach ($namespace as $ns => $nsUrl) {
            // atributes
            $objAttributes = $obj->attributes($ns, true);
            foreach ($objAttributes as $attributeName => $attributeValue) {
                $attribName = strtolower(trim((string) $attributeName));
                $attribVal = trim((string) $attributeValue);
                if (!empty($ns)) {
                    $attribName = $ns . ':' . $attribName;
                }
                $attributes[$attribName] = $attribVal;
            }
            // children
            $objChildren = $obj->children($ns, true);
            foreach ($objChildren as $childName => $child) {
                $childName = strtolower((string) $childName);
                if (!empty($ns)) {
                    $childName = $ns . ':' . $childName;
                }
                $children[$childName][] = xmlObjToArr($child);
            }
        }
    }
    return array('text' => $text, 'attributes' => $attributes, 'children' => $children);
}
Ejemplo n.º 7
0
function convert_file_to_xml($file_path)
{
    $data = file_get_contents($file_path);
    $x = @simplexml_load_string($data);
    return xmlObjToArr($x);
}