public function __construct(KalturaYouTubeDistributionProfile $distributionProfile)
 {
     $this->_doc = new DOMDocument();
     $this->_doc->formatOutput = true;
     $this->_doc->appendChild($this->_doc->createElement('feed'));
     $this->_doc->createAttributeNS('http://www.youtube.com/schemas/cms/2.0', 'xmlns');
     $this->_xpath = new DOMXPath($this->_doc);
     $timestampName = date('Ymd-His') . '_' . time();
     $this->_directoryName = '/' . $timestampName;
     if ($distributionProfile->sftpBaseDir) {
         $this->_directoryName = '/' . trim($distributionProfile->sftpBaseDir, '/') . $this->_directoryName;
     }
     $this->_metadataTempFileName = 'youtube_xml20_' . $timestampName . '.xml';
 }
Exemple #2
0
 public function createSitemap()
 {
     $where = "published = 1 and menutype = 'mainmenu' and access IN (1)";
     $result = $this->db->select($this->table_prefix . "menu", "*", "{$where}", 'std');
     $dom = new DOMDocument('1.0');
     $dom->formatOutput = true;
     $root = $dom->createElement('urlset');
     $root = $dom->appendChild($root);
     $ns = $dom->createAttributeNS("http://www.sitemaps.org/schemas/sitemap/0.9", "xmlns");
     foreach ($result["value"] as $row) {
         $link_arr = parse_url($row['link']);
         if (isset($link_arr['query'])) {
             parse_str(html_entity_decode($link_arr['query']), $link_vars);
             $option = HELPER::getValue($link_vars, 'option', '');
             $view = HELPER::getValue($link_vars, 'view', '');
             $layout = HELPER::getValue($link_vars, 'layout', '');
             if ($option == "com_virtuemart" && $view == "category") {
                 $id = HELPER::getValue($link_vars, 'virtuemart_category_id', 0);
             } elseif ($option == "com_fabrik" && $view == "form") {
                 $id = HELPER::getValue($link_vars, 'formid', 0);
             } else {
                 $id = HELPER::getValue($link_vars, 'id', 0);
             }
             $url = $dom->createElement('url');
             $url = $root->appendChild($url);
             $this->setMenuUrl($view, $row, $option, $id, $dom, $root, $url);
         }
     }
     $str = $dom->saveXML();
     echo "Создана карта сайта sitemap.xml, размер " . $dom->save($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $this->SITEMAP_FILE_NAME) . " байт.";
 }
Exemple #3
0
 /**
  *
  * Create new attribute
  * @param string $namespace
  * @param string $name
  * @param string $value
  * @return DOMAttr
  */
 public function create_attribute_ns($namespace, $name, $value = null)
 {
     $result = $this->doc->createAttributeNS($namespace, $name);
     if (!is_null($value)) {
         $result->nodeValue = $value;
     }
     return $result;
 }
 /**
  * @param PropertyMetadata $metadata
  * @param $attributeName
  *
  * @return \DOMAttr
  */
 private function createAttributeNode(PropertyMetadata $metadata, $attributeName)
 {
     if ($namespace = (string) $metadata->xmlNamespace) {
         $prefix = $this->lookupPrefix($namespace);
         $node = $this->document->createAttributeNS($namespace, $prefix . ':' . $attributeName);
     } else {
         $node = $this->document->createAttribute($attributeName);
     }
     return $node;
 }
 public function getNsCode($longNs, $rt = false)
 {
     // if namespace exists - just use its name
     // otherwise add it as nsatrribute to root and use its name
     if (!is_array($this->namespaces)) {
         $this->namespaces = array();
     }
     if (array_key_exists($longNs, $this->namespaces)) {
         return $this->namespaces[$longNs];
     } else {
         $this->namespaces[$longNs] = 'ns' . $this->lastNsKey;
         //$this->logger->debug($this->namespaces[$longNs]);
         if ($rt === false) {
             $nsAttr = $this->dom->createAttributeNS($longNs, $this->namespaces[$longNs] . ":" . $this->rootTagName);
         }
         $this->lastNsKey++;
         return $this->namespaces[$longNs];
     }
 }
/**
 * Handles the GET request
 */
function WS_get()
{
    global $_CONF, $WS_PLUGIN, $WS_INTROSPECTION, $WS_VERBOSE, $_PLUGINS;
    if ($WS_VERBOSE) {
        COM_errorLog("WS: GET request received");
    }
    WS_dissectURI($args);
    if ($WS_INTROSPECTION) {
        header('Content-type: application/atomsvc+xml; charset=UTF-8');
        $atom_uri = $_CONF['site_url'] . '/webservices/atom/';
        /* Determine which plugins have webservices enabled */
        $_ws_plugins = array();
        /* Handle the story 'plugin' separately */
        if (PLG_wsEnabled('story')) {
            $_ws_plugins[] = 'story';
        }
        if (is_array($_PLUGINS)) {
            foreach ($_PLUGINS as $pi) {
                if (PLG_wsEnabled($pi)) {
                    $_ws_plugins[] = $pi;
                }
            }
        }
        /* It might be simpler to do this part directly :-/ */
        $atom_doc = new DOMDocument('1.0', 'utf-8');
        $root_elem = $atom_doc->createElementNS(WS_APP_NS, 'app:service');
        $atom_doc->appendChild($root_elem);
        $atom_doc->createAttributeNS(WS_ATOM_NS, 'atom:service');
        $atom_doc->createAttributeNS(WS_EXTN_NS, 'gl:service');
        $workspace = $atom_doc->createElement('app:workspace');
        $root_elem->appendChild($workspace);
        $title = $atom_doc->createElement('atom:title', $_CONF['site_name']);
        $workspace->appendChild($title);
        foreach ($_ws_plugins as $ws_plugin) {
            $atom_uri_for_plugin = $atom_uri . '?plugin=' . $ws_plugin;
            $collection = $atom_doc->createElement('app:collection');
            $collection->setAttribute('href', $atom_uri_for_plugin);
            $workspace->appendChild($collection);
            $title = $atom_doc->createElement('atom:title', $ws_plugin);
            $collection->appendChild($title);
            $entry = $atom_doc->createElement('app:accept', 'application/atom+xml;type=entry');
            $collection->appendChild($entry);
            $categories = $atom_doc->createElement('app:categories');
            $categories->setAttribute('fixed', 'yes');
            $collection->appendChild($categories);
            $topics = array();
            $msg = array();
            $ret = PLG_invokeService($ws_plugin, 'getTopicList', null, $topics, $msg);
            if ($ret == PLG_RET_OK) {
                foreach ($topics as $t) {
                    $topic = $atom_doc->createElement('atom:category');
                    $topic->setAttribute('term', htmlentities($t));
                    $categories->appendChild($topic);
                }
            }
        }
        WS_write($atom_doc->saveXML());
        return;
    }
    // @TODO Store array $args
    // object id has already been stored from the URI
    /* Indicates that the method is being called by the webservice */
    $args['gl_svc'] = true;
    $ret = PLG_invokeService($WS_PLUGIN, 'get', $args, $out, $svc_msg);
    if ($ret == PLG_RET_OK) {
        header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK');
        header('Content-type: application/atom+xml; charset=UTF-8');
        // Output the actual object/objects here
        if (!$svc_msg['gl_feed']) {
            /* This is an entry, not a feed */
            $etag = '';
            if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
                $etag = trim($_SERVER['HTTP_IF_NONE_MATCH'], '"');
            }
            if (!empty($etag) && $out['updated'] == $etag) {
                header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
                exit;
            } else {
                header('Etag: "' . $out['updated'] . '"');
            }
            $atom_doc = new DOMDocument('1.0', 'utf-8');
            $entry_elem = $atom_doc->createElementNS(WS_ATOM_NS, 'atom:entry');
            $atom_doc->appendChild($entry_elem);
            $atom_doc->createAttributeNS(WS_APP_NS, 'app:entry');
            $atom_doc->createAttributeNS(WS_EXTN_NS, 'gl:entry');
            WS_arrayToEntryXML($out, $svc_msg['output_fields'], $entry_elem, $atom_doc);
            WS_write($atom_doc->saveXML());
        } else {
            /* Output the feed here */
            $atom_doc = new DOMDocument('1.0', 'utf-8');
            $feed_elem = $atom_doc->createElementNS(WS_ATOM_NS, 'atom:feed');
            $atom_doc->appendChild($feed_elem);
            $atom_doc->createAttributeNS(WS_APP_NS, 'app:feed');
            $atom_doc->createAttributeNS(WS_EXTN_NS, 'gl:feed');
            $feed_id = $atom_doc->createElement('atom:id', $_CONF['site_name']);
            $feed_elem->appendChild($feed_id);
            $feed_title = $atom_doc->createElement('atom:title', $_CONF['site_name']);
            $feed_elem->appendChild($feed_title);
            $feed_updated = $atom_doc->createElement('atom:updated', date('c'));
            $feed_elem->appendChild($feed_updated);
            $feed_link = $atom_doc->createElement('atom:link');
            $feed_link->setAttribute('rel', 'self');
            $feed_link->setAttribute('type', 'application/atom+xml');
            $feed_link->setAttribute('href', $_CONF['site_url'] . '/webservices/atom/?plugin=' . htmlentities($WS_PLUGIN));
            $feed_elem->appendChild($feed_link);
            if (!empty($svc_msg['offset'])) {
                $next_link = $atom_doc->createElement('atom:link');
                $next_link->setAttribute('rel', 'next');
                $next_link->setAttribute('type', 'application/atom+xml');
                $next_link->setAttribute('href', $_CONF['site_url'] . '/webservices/atom/?plugin=' . htmlentities($WS_PLUGIN) . '&offset=' . $svc_msg['offset']);
                $feed_elem->appendChild($next_link);
            }
            foreach ($out as $entry_array) {
                $entry_elem = $atom_doc->createElement('atom:entry');
                WS_arrayToEntryXML($entry_array, $svc_msg['output_fields'], $entry_elem, $atom_doc);
                $feed_elem->appendChild($entry_elem);
            }
            WS_write($atom_doc->saveXML());
        }
        return;
    }
    WS_error($ret, $svc_msg['error_desc']);
}
Exemple #7
0
 /**
  * @param  \DOMDocument $doc
  * @param  array        $element
  * @return \DOMElement
  */
 protected function buildElement(\DOMDocument $doc, array $element)
 {
     list($name, $value, $attributes) = $element;
     if ($namespace = strtok($name, ':') and isset($this->namespaces[$namespace])) {
         $doc->createAttributeNS($this->namespaces[$namespace], $namespace . ':attr');
     }
     if (is_array($value)) {
         $item = $doc->createElement($name);
         foreach ($value as $tag => $child) {
             $item->appendChild($this->buildElement($doc, [$tag, $child, []]));
         }
     } elseif (in_array($name, $this->cdata)) {
         $item = $doc->createElement($name);
         $item->appendChild($doc->createCDATASection($value));
     } else {
         $item = $doc->createElement($name);
         $item->appendChild($doc->createTextNode($value));
     }
     return $this->buildAttributes($item, (array) $attributes);
 }
 /**
  * 
  *
  *
  *
  * @return  bool   TRUE if template XMLObject (with format WSDL) was created, FALSE if not.
  */
 private function createWSDL_TPL()
 {
     if (empty($this->nameWSDL)) {
         $this->errorMSG = "WSDL name isn't defined.";
         return false;
     }
     if (empty($this->targetNamespace)) {
         $this->errorMSG = "WSDL targetNamespace isn't defined.";
         return false;
     }
     if (empty($this->soapAddress)) {
         $this->errorMSG = "WSDL soapAddress isn't defined.";
         return false;
     }
     // Create Document XML with namespace
     // xsd  for namespace (schema),  http://www.w3.org/2001/XMLSchema
     // soap for namespace (soap),    http://schemas.xmlsoap.org/wsdl/soap/
     // elx  for namespace (elastix), ex. http://www.elastix.org/webservices/
     try {
         $doc = new DOMDocument("1.0", "UTF-8");
         $root = $doc->createElementNS($this->ns_wsdl, "{$this->prefix_ns_wsdl}:definitions");
         $doc->appendChild($root);
         $doc->createAttributeNS($this->ns_schema, "{$this->prefix_ns_schema}:schema");
         $doc->createAttributeNS($this->ns_soap, "{$this->prefix_ns_soap}:soap");
         $doc->createAttributeNS($this->targetNamespace, "{$this->prefix_ns_elx}:elastix");
         $attrname = $doc->createAttribute('name');
         //WSDL name Attribute
         $root->appendChild($attrname);
         $valname = $doc->createTextNode($this->nameWSDL);
         $attrname->appendChild($valname);
         $attrtns = $doc->createAttribute('targetNamespace');
         //WSDL tns Attribute
         $root->appendChild($attrtns);
         $valtns = $doc->createTextNode($this->targetNamespace);
         $attrtns->appendChild($valtns);
         $tplWSDL = simplexml_import_dom($doc);
         if (!$tplWSDL) {
             echo "ERROR";
             $this->errorMSG = "Failed loading XML\n";
             foreach (libxml_get_errors() as $error) {
                 $this->errorMSG .= "\t" . $error->message;
             }
             return false;
         }
         //Types
         $objTypes = $tplWSDL->addChild("{$this->prefix_ns_wsdl}:types", null, $this->ns_wsdl);
         $objSchem = $objTypes->addChild("{$this->prefix_ns_schema}:schema", null, $this->ns_schema);
         $objSchem->addAttribute("elementFormDefault", "qualified");
         $objSchem->addAttribute("targetNamespace", $this->targetNamespace);
         $this->node_SchemaTypes = $objSchem;
         //Port Type
         $objPortType = $tplWSDL->addChild("{$this->prefix_ns_wsdl}:portType", null, $this->ns_wsdl);
         $objPortType->addAttribute("name", "{$this->nameWSDL}_SOAPPort");
         $this->node_PortType = $objPortType;
         //Binding
         $objBinding = $tplWSDL->addChild("{$this->prefix_ns_wsdl}:binding", null, $this->ns_wsdl);
         $objBinding->addAttribute("name", "{$this->nameWSDL}_SOAP");
         $objBinding->addAttribute("type", "{$this->prefix_ns_elx}:{$this->nameWSDL}_SOAPPort");
         $objSOAPBin = $objBinding->addChild("{$this->prefix_ns_soap}:binding", null, $this->ns_soap);
         $objSOAPBin->addAttribute("style", "document");
         $objSOAPBin->addAttribute("transport", "http://schemas.xmlsoap.org/soap/http");
         $this->node_Binding = $objBinding;
         //Service
         $objService = $tplWSDL->addChild("{$this->prefix_ns_wsdl}:service", null, $this->ns_wsdl);
         $objService->addAttribute("name", "{$this->nameWSDL}_Service");
         $objPort = $objService->addChild("{$this->prefix_ns_wsdl}:port", null, $this->ns_wsdl);
         $objPort->addAttribute("name", "{$this->nameWSDL}_Port");
         $objPort->addAttribute("binding", "{$this->prefix_ns_elx}:{$this->nameWSDL}_SOAP");
         $objAddress = $objPort->addChild("{$this->prefix_ns_soap}:address", null, $this->ns_soap);
         $objAddress->addAttribute("location", $this->soapAddress);
         $this->node_Service = $objService;
         $this->objWSDL = $tplWSDL;
     } catch (DOMException $ex) {
         $this->errorMSG = "Failed generate WSDL - " . $ex->getMessage();
         return false;
     }
     return true;
 }
Exemple #9
0
 protected function update_attribute_ns(DOMDocument &$doc, $attrname, $attrnamespace, $attrvalue, DOMElement &$node)
 {
     $busenew = is_object($node) && $node->hasAttributeNS($attrnamespace, $attrname);
     $nResult = null;
     if (!$busenew && is_null($attrvalue)) {
         $node->removeAttributeNS($attrnamespace, $attrname);
     } else {
         $nResult = $busenew ? $node->getAttributeNodeNS($attrnamespace, $attrname) : $doc->createAttributeNS($attrnamespace, $attrname);
         $nResult->nodeValue = $attrvalue;
         if (!$busenew) {
             $node->appendChild($nResult);
         }
     }
     return $nResult;
 }
 /**
  *  Load template data from a DOMDocument, DOMElement, string or file
  *  @name   load
  *  @type   method
  *  @access public
  *  @param  mixed source
  *  @param  ScaffoldTemplate parentTemplate
  *  @param  bool prepare
  *  @return ScaffoldTemplate
  */
 public function load($source, $parentTemplate = null, $prepare = true)
 {
     $this->_enterPhase(self::PHASE_INIT);
     $data = null;
     if ($source instanceof DOMDocument) {
         $data = $source;
         $this->origin = '(DOMDocument) ' . substr($source->saveXML(), 0, 150);
     } else {
         if ($source instanceof DOMElement) {
             $data = new DOMDocument();
             $data->appendChild($data->importNode($source, true));
             $this->origin = '(DOMElement) ' . substr($source->ownerDocument->saveXML($source), 0, 150);
         } else {
             if (is_string($source)) {
                 $data = new DOMDocument();
                 $file = $this->_getFileName($source);
                 $source = $this->_wrapSource($file ? file_get_contents($file) : $source);
                 $data->loadXML($source);
                 $this->origin = $file ? '(file) ' . $file : '(string) ' . substr($source, 0, 150);
             } else {
                 $this->exception('Cannot load template from (' . gettype($source) . ')' . var_export($source, true));
             }
         }
     }
     if ($data instanceof DOMDocument) {
         foreach ($this->_namespace as $namespace => $path) {
             if (!empty($path)) {
                 $data->createAttributeNS($path, $namespace . ':' . get_class($this));
             }
         }
         $this->_content = $data;
         $this->_xpath = new DOMXPath($this->_content);
         if ($prepare) {
             $this->prepare();
         }
     }
     if ($parentTemplate instanceof self) {
         $parentTemplate->addChild($this);
     }
     $this->_enterPhase(self::PHASE_READY);
     return $this;
 }
Exemple #11
0
echo 'Attribute num exists?: ' . ($node->hasAttribute('num') ? 'Yes' : 'No') . "\n";
echo "Language: " . $node->getAttribute('language') . "\n";
$lang = $node->getAttributeNode('language');
$lang->nodeValue = 'en-US';
$node->setAttributeNode($lang);
echo "Language: " . $node->getAttribute('language') . "\n";
$node->removeAttributeNode($lang);
echo "Language: " . $node->getAttribute('language') . "\n";
echo "\n-- xml:lang --\n";
$node->setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang', 'en');
echo "Language: " . $node->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang') . "\n";
echo 'Attribute xml:lang exists?: ' . ($node->hasAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang') ? 'Yes' : 'No') . "\n";
$node->removeAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang');
echo "Language: " . $node->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang') . "\n";
echo 'Attribute xml:lang exists?: ' . ($node->hasAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang') ? 'Yes' : 'No') . "\n";
$lang = $dom->createAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:lang');
$lang->nodeValue = 'en-GB';
$node->setAttributeNodeNS($lang);
unset($lang);
echo "Language: " . $node->getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang') . "\n";
$lang = $node->getAttributeNodeNS('http://www.w3.org/XML/1998/namespace', 'lang');
echo "Language: " . $lang->value . "\n";
echo "\n-- Elements --\n";
$rows = $node->getElementsByTagName('row');
echo "Row Count: " . $rows->length . "\n";
$element_ns = new DOMElement('newns:myelement', 'default content', 'urn::dummyns');
$node->appendChild($element_ns);
$element_ns = new DOMElement('newns2:myelement', 'second default content', 'urn::dummyns');
$node->appendChild($element_ns);
$myelements = $node->getElementsByTagNameNS('urn::dummyns', 'myelement');
$mylen = $myelements->length;