Пример #1
0
 /**
  * method to run after an install/update/uninstall method
  *
  * @param $type
  * @param $parent
  *
  * @return void
  */
 public function postflight($type, $parent)
 {
     $db =& JFactory::getDBO();
     $handle = fopen("components/com_vproductfeed/assets/data/GoogleCategories.txt", "r");
     $previous = array();
     $root = array("id" => 0, "name" => "");
     $child = array("id" => 0, "name" => "");
     $count = 0;
     $parent_id = 0;
     while (($line = fgets($handle)) !== false) {
         $nodes = explode(">", $line);
         if (count($nodes) > 1) {
             //process the nodes
             foreach ($nodes as $value) {
                 $count++;
                 $child[0] = $count;
                 $child[1] = htmlspecialchars(trim($value), ENT_QUOTES);
                 //insert into database and xref
                 $q = "Insert Into google_category (category_id, category_name) \r\n\t\t\t\t\t  values (" . $child[0] . ", '" . $child[1] . "')";
                 $db->setQuery($q);
                 $result = $db->query();
                 //$result = mysql_query($q);
                 if ($result == true) {
                     //This checks if the category_name already exists
                     $q = "Insert Into google_category_xref (category_parent_id, category_child_id) \r\n\t\t\t\t\t\tvalues (" . $parent_id . ", " . $child[0] . ")";
                     $db->setQuery($q);
                     $result = $db->query();
                     //$result = mysql_query($q);
                 } else {
                     //get the Id of the category already in db
                     $q = "select `category_id` from `google_category` where `category_name`='" . $child[1] . "'";
                     //echo "Query: " . $q . "<br />";
                     $db->setQuery($q);
                     $result = $db->query();
                     //$result = mysql_query($q);
                     if (!$result) {
                         echo "Problem Executing Query";
                         exit;
                     }
                     $row = $db->loadRow();
                     //$row = mysql_fetch_row($result);
                     $parent_id = $row[0];
                     $count--;
                 }
             }
             $parent_id = $root[0];
         } else {
             //process the root node
             $count++;
             $root[0] = $count;
             $root[1] = htmlspecialchars(trim($nodes[0]), ENT_QUOTES);
             $parent_id = $root[0];
             echo "Writing root: " . $root[1] . "<br />";
             //insert into database and xref
             $q = "Insert Into google_category (category_id, category_name) values (" . $root[0] . ", '" . $root[1] . "')";
             //mysql_query($q);
             $db->setQuery($q);
             $result = $db->query();
             $q = "Insert Into google_category_xref (category_parent_id, category_child_id) values (0, " . $root[0] . ")";
             //mysql_query($q);
             $db->setQuery($q);
             $result = $db->query();
         }
         foreach ($nodes as $value) {
             $previous[] = $value;
         }
     }
     //now put vm categories in an xml file
     $params = JComponentHelper::getParams('com_languages');
     $lang = $params->get('site', 'en-GB');
     //use default joomla
     $lang = strtolower(strtr($lang, '-', '_'));
     $q = "SELECT c.virtuemart_category_id, c.category_name FROM `#__virtuemart_categories_{$lang}` as c\r\n\t\t\t  JOIN `#__virtuemart_category_categories` as x\r\n\t\t\t  ON x.category_child_id = c.virtuemart_category_id\r\n\t\t\t  WHERE x.category_parent_id = 0\r\n\t\t\t  ORDER BY c.category_name";
     $db->setQuery($q);
     //$result = $db->query();
     //$result = mysql_query($q);
     $error = $db->getErrorMsg();
     if (!empty($error)) {
         $app = JFactory::getApplication();
         $app->enqueueMessage('Error Getting Data: ' . $error);
     }
     $writer = new XMLWriter();
     $writer->openURI('components/com_vproductfeed/assets/data/file.xml');
     $writer->startDocument('1.0');
     $writer->setIndent(4);
     $writer->startElement('tree');
     $writer->writeAttribute('id', '0');
     $row = $db->loadRowList();
     for ($i = 0; $i < sizeof($row); $i++) {
         echo "Root Row: " . $row[$i][0] . " - " . $row[$i][1] . "<br />";
         $writer->StartElement('item');
         $writer->writeAttribute('id', $row[$i][0]);
         $writer->writeAttribute('text', $row[$i][1]);
         $writer->writeAttribute('select', '1');
         $db1 =& JFactory::getDBO();
         $q1 = "SELECT c.virtuemart_category_id, c.category_name FROM `#__virtuemart_categories_{$lang}` as c\r\n\t\t \t\t\t   JOIN `#__virtuemart_category_categories` as x\r\n\t\t\t\t\t   ON x.category_child_id = c.virtuemart_category_id\r\n\t\t\t\t\t   WHERE x.category_parent_id = " . $row[$i][0] . " order by c.category_name";
         $db1->setQuery($q1);
         $row1 = $db1->loadRowList();
         for ($i1 = 0; $i1 < sizeof($row1); $i1++) {
             echo "&nbsp;&nbsp;&nbsp;Level 1 Row: " . $row1[$i1][0] . " - " . $row1[$i1][1] . "<br />";
             $writer->StartElement('item');
             $writer->writeAttribute('id', $row1[$i1][0]);
             $writer->writeAttribute('text', $row1[$i1][1]);
             $writer->writeAttribute('select', '1');
             $db2 =& JFactory::getDBO();
             $q2 = "SELECT c.virtuemart_category_id, c.category_name FROM `#__virtuemart_categories_{$lang}` as c\r\n\t\t \t\t\t   JOIN `#__virtuemart_category_categories` as x\r\n\t\t\t\t\t   ON x.category_child_id = c.virtuemart_category_id\r\n\t\t\t\t\t   WHERE x.category_parent_id = " . $row1[$i1][0] . " order by c.category_name";
             $db2->setQuery($q2);
             $row2 = $db2->loadRowList();
             for ($i2 = 0; $i2 < sizeof($row2); $i2++) {
                 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Level 2 Row: " . $row2[$i2][0] . " - " . $row2[$i2][1] . "<br />";
                 $writer->StartElement('item');
                 $writer->writeAttribute('id', $row2[$i2][0]);
                 $writer->writeAttribute('text', $row2[$i2][1]);
                 $writer->writeAttribute('select', '1');
                 $db3 =& JFactory::getDBO();
                 $q3 = "SELECT c.virtuemart_category_id, c.category_name FROM `#__virtuemart_categories_{$lang}` as c\r\n\t\t \t\t\t   JOIN `#__virtuemart_category_categories` as x\r\n\t\t\t\t\t   ON x.category_child_id = c.virtuemart_category_id\r\n\t\t\t\t\t   WHERE x.category_parent_id = " . $row2[$i2][0] . " order by c.category_name";
                 $db3->setQuery($q3);
                 $row3 = $db3->loadRowList();
                 for ($i3 = 0; $i3 < sizeof($row3); $i3++) {
                     echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Level 2 Row: " . $row3[$i3][0] . " - " . $row3[$i3][1] . "<br />";
                     $writer->StartElement('item');
                     $writer->writeAttribute('id', $row3[$i3][0]);
                     $writer->writeAttribute('text', $row3[$i3][1]);
                     $writer->writeAttribute('select', '1');
                     $db4 =& JFactory::getDBO();
                     $q4 = "SELECT c.virtuemart_category_id, c.category_name FROM `#__virtuemart_categories_{$lang}` as c\r\n\t\t \t\t\t   JOIN `#__virtuemart_category_categories` as x\r\n\t\t\t\t\t   ON x.category_child_id = c.virtuemart_category_id\r\n\t\t\t\t\t   WHERE x.category_parent_id = " . $row3[$i3][0] . " order by c.category_name";
                     $db4->setQuery($q4);
                     $row4 = $db4->loadRowList();
                     for ($i4 = 0; $i4 < sizeof($row4); $i4++) {
                         echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Level 2 Row: " . $row4[$i4][0] . " - " . $row4[$i4][1] . "<br />";
                         $writer->StartElement('item');
                         $writer->writeAttribute('id', $row4[$i4][0]);
                         $writer->writeAttribute('text', $row4[$i4][1]);
                         $writer->writeAttribute('select', '1');
                         $db5 =& JFactory::getDBO();
                         $q5 = "SELECT c.virtuemart_category_id, c.category_name FROM `#__virtuemart_categories_{$lang}` as c\r\n\t\t \t\t\t   JOIN `#__virtuemart_category_categories` as x\r\n\t\t\t\t\t   ON x.category_child_id = c.virtuemart_category_id\r\n\t\t\t\t\t   WHERE x.category_parent_id = " . $row4[$i4][0] . " order by c.category_name";
                         $db5->setQuery($q5);
                         $row5 = $db5->loadRowList();
                         for ($i5 = 0; $i5 < sizeof($row5); $i5++) {
                             echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Level 2 Row: " . $row5[$i5][0] . " - " . $row5[$i5][1] . "<br />";
                             $writer->StartElement('item');
                             $writer->writeAttribute('id', $row5[$i5][0]);
                             $writer->writeAttribute('text', $row5[$i5][1]);
                             $writer->writeAttribute('select', '1');
                             $writer->endElement();
                         }
                         $writer->endElement();
                     }
                     $writer->endElement();
                 }
                 $writer->endElement();
             }
             $writer->endElement();
         }
         $writer->endElement();
     }
     $writer->endElement();
     $writer->flush();
 }
Пример #2
0
//$result = mysql_query($q);
$error = $db->getErrorMsg();
if (!empty($error)) {
    $app = JFactory::getApplication();
    $app->enqueueMessage('Error Getting Data: ' . $error);
}
$writer = new XMLWriter();
$writer->openURI('components/com_vproductfeed/assets/data/file.xml');
$writer->startDocument('1.0');
$writer->setIndent(4);
$writer->startElement('tree');
$writer->writeAttribute('id', '0');
$row = $db->loadRowList();
for ($i = 0; $i < sizeof($row); $i++) {
    //echo "Root Row: " . $row[$i][0] . " - " . $row[$i][1] . "<br />";
    $writer->StartElement('item');
    $writer->writeAttribute('id', $row[$i][0]);
    $writer->writeAttribute('text', $row[$i][1]);
    $writer->writeAttribute('select', '1');
    $db1 =& JFactory::getDBO();
    $q1 = "SELECT c.virtuemart_category_id, c.category_name FROM `#__virtuemart_categories_{$lang}` as c\r\n\t\t \t\t\t   JOIN `#__virtuemart_category_categories` as x\r\n\t\t\t\t\t   ON x.category_child_id = c.virtuemart_category_id\r\n\t\t\t\t\t   WHERE x.category_parent_id = " . $row[$i][0] . " order by c.category_name";
    $db1->setQuery($q1);
    $row1 = $db1->loadRowList();
    for ($i1 = 0; $i1 < sizeof($row1); $i1++) {
        //echo "&nbsp;&nbsp;&nbsp;Level 1 Row: " . $row1[$i1][0] . " - " . $row1[$i1][1] . "<br />";
        $writer->StartElement('item');
        $writer->writeAttribute('id', $row1[$i1][0]);
        $writer->writeAttribute('text', $row1[$i1][1]);
        $writer->writeAttribute('select', '1');
        $db2 =& JFactory::getDBO();
        $q2 = "SELECT c.virtuemart_category_id, c.category_name FROM `#__virtuemart_categories_{$lang}` as c\r\n\t\t \t\t\t   JOIN `#__virtuemart_category_categories` as x\r\n\t\t\t\t\t   ON x.category_child_id = c.virtuemart_category_id\r\n\t\t\t\t\t   WHERE x.category_parent_id = " . $row1[$i1][0] . " order by c.category_name";
 public function generateMPD($duration, $nStart, $nSegs)
 {
     $id = $this->__file->getId();
     $savePath = $this->__file->getSavedir() . "{$id}.mpd";
     $xml = new XMLWriter();
     if (file_exists($savePath)) {
         unlink($savePath);
     }
     $xml->openURI($savePath);
     $xml->setIndent(TRUE);
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElement('MPD');
     $xml->writeAttribute('xmlns', 'urn:mpeg:dash:schema:mpd:2011');
     $xml->writeAttribute('minBufferTime', 'PT1.500000S');
     $xml->writeAttribute('type', 'static');
     $xml->writeAttribute('mediaPresentationDuration', 'PT0H9M56.50S');
     $xml->writeAttribute('profiles', 'urn:mpeg:dash:profile:isoff-main:2011');
     $xml->writeElement('BaseURL', 'http://pilatus.d1.comp.nus.edu.sg/');
     //$xml->writeElement('BaseURL', 'http://pluto.comp.nus.edu.sg/');
     $xml->StartElement('Period');
     $xml->writeAttribute('duration', "PT{$duration[0]}H{$duration[1]}M{$duration[2]}S");
     $xml->writeElement('BaseURL', "~team08/video_repo/{$id}/");
     //$xml->writeElement('BaseURL', "dash/video_repo/$id/" );
     $xml->StartElement('AdaptationSet');
     $xml->writeAttribute('segmentAlignment', 'true');
     $xml->writeAttribute('maxWidth', '720');
     $xml->writeAttribute('maxHeight', '480');
     $xml->writeAttribute('maxFrameRate', '30');
     $xml->writeAttribute('par', '3:2');
     $xml->StartElement('ContentComponent');
     $xml->writeAttribute('id', '1');
     $xml->writeAttribute('contentType', 'video');
     $xml->EndElement();
     $xml->StartElement('ContentComponent');
     $xml->writeAttribute('id', '2');
     $xml->writeAttribute('contentType', 'audio');
     $xml->EndElement();
     $xml->StartElement('Representation');
     $xml->writeAttribute('id', 'HIGH');
     $xml->writeAttribute('mimeType', 'video/mp4');
     $xml->writeAttribute('codecs', 'avc1,mp4a');
     $xml->writeAttribute('width', '720');
     $xml->writeAttribute('height', '480');
     $xml->writeAttribute('frameRate', '30');
     $xml->writeAttribute('sar', '1:1');
     $xml->writeAttribute('audioSamplingRate', '48000');
     $xml->writeAttribute('bandwidth', '3000000');
     $xml->StartElement('SegmentList');
     $xml->writeAttribute('duration', '3');
     for ($i = $nStart; $i <= $nSegs; $i++) {
         $xml->StartElement('SegmentURL');
         $xml->writeAttribute('media', "{$i}_720x480.mp4");
         $xml->EndElement();
     }
     $xml->EndElement();
     $xml->EndElement();
     $xml->StartElement('Representation');
     $xml->writeAttribute('id', 'MEDIUM');
     $xml->writeAttribute('mimeType', 'video/mp4');
     $xml->writeAttribute('codecs', 'avc1,mp4a');
     $xml->writeAttribute('width', '480');
     $xml->writeAttribute('height', '320');
     $xml->writeAttribute('frameRate', '30');
     $xml->writeAttribute('sar', '1:1');
     $xml->writeAttribute('audioSamplingRate', '48000');
     $xml->writeAttribute('bandwidth', '768000');
     $xml->StartElement('SegmentList');
     $xml->writeAttribute('duration', '3');
     for ($i = $nStart; $i <= $nSegs; $i++) {
         $xml->StartElement('SegmentURL');
         $xml->writeAttribute('media', "{$i}_480x320.mp4");
         $xml->EndElement();
     }
     $xml->EndElement();
     $xml->EndElement();
     $xml->StartElement('Representation');
     $xml->writeAttribute('id', 'LOW');
     $xml->writeAttribute('mimeType', 'video/mp4');
     $xml->writeAttribute('codecs', 'avc1,mp4a');
     $xml->writeAttribute('width', '240');
     $xml->writeAttribute('height', '160');
     $xml->writeAttribute('frameRate', '30');
     $xml->writeAttribute('sar', '1:1');
     $xml->writeAttribute('audioSamplingRate', '48000');
     $xml->writeAttribute('bandwidth', '200000');
     $xml->StartElement('SegmentList');
     $xml->writeAttribute('duration', '3');
     for ($i = $nStart; $i <= $nSegs; $i++) {
         $xml->StartElement('SegmentURL');
         $xml->writeAttribute('media', "{$i}_240x160.mp4");
         $xml->EndElement();
     }
     $xml->EndElement();
     $xml->EndElement();
     $xml->EndElement();
     $xml->EndElement();
     $xml->EndElement();
     $xml->endDocument();
     $xml->flush();
 }