Esempio n. 1
0
$pom = new POMPage('Testeintrag', join(file('http://localhost/wiki/index.php?title=Testeintrag&action=raw')), array('POMExtendedParser'));
# iterate trough the templates
$iterator = $pom->getTemplateByTitle("Post")->listIterator();
while ($iterator->hasNext()) {
    $template =& $iterator->getNextNodeValueByReference();
    # get reference for direct changes
    if ($template->getParameter("PARAMETERNAME") !== NULL) {
        # check if the parameter exists
        if ($template->getParameter("PARAMETERNAME")->getValue()->getElement() !== NULL) {
            # a parameter value exists
            # get the first subelement of the page object representing the parameter value
            var_dump($template->getParameter("PARAMETERNAME"));
            $anElement =& $template->getParameter("PARAMETERNAME")->getValueByReference()->getElement();
            var_dump($anElement);
        } else {
            # add a new text element
            $parameterValue =& $template->getParameter("PARAMETERNAME")->getValueByReference();
            $simpleText = new POMSimpleText("A simple text element!");
            $parameterValue->addElement($simpleText);
            # show the changes
            $pom->sync();
            print $pom->text;
            print "### Now changing the parameter value .. ###\n";
            $parameterValue = new POMPage("A-STRING", "");
            $simpleText = new POMSimpleText("String changed!");
            $parameterValue->addElement($simpleText);
        }
    }
}
$pom->sync();
print $pom->text;
Esempio n. 2
0
 /**
  * Reads serialized data in JSON format and saves the requested chages.
  *
  * @param JSON $sfdata The posted data including page and SF attributes.
  * @param string $methodType The action to be performed: c(create) or u(update) or d(delete).
  * @param string $username The username provided.
  * @param string $userId The user ID provided.
  * @param string $loginToken The login token provided.
  */
 public function setSerializedJsonForm($sfdata, $methodType, $username = NULL, $userId = NULL, $loginToken = NULL)
 {
     $__jsonData = json_decode(str_replace('#U002B#', '+', $sfdata), true);
     $__serverUtility = new PCPServer();
     $__userCredentials = new PCPUserCredentials($username, NULL, $userId, $loginToken);
     //print_r($__jsonData);die;
     $__pageNs = utf8_decode($__jsonData['sfdata']['page']['ns']);
     $__pageTitle = $__jsonData['sfdata']['page']['title'];
     $__pageRId = $__jsonData['sfdata']['page']['rid'];
     $__page = $__serverUtility->readPage($__userCredentials, $__pageTitle, $__pageRId);
     if (stristr($methodType, "c")) {
         // the requested method is create
         if ($__page->pageid == NULL || $__page->pageid == "") {
             // the page doesn't exist so we have to create it
             // the XML data is read and a template is created for each SF
             // since the attributes will be read together with the SF elements unset them
             unset($__jsonData['sfdata']['page']['title']);
             unset($__jsonData['sfdata']['page']['ns']);
             unset($__jsonData['sfdata']['page']['rid']);
             $__sfNames = array_keys($__jsonData['sfdata']['page']);
             $__tmplString = "";
             // used for the creation of all template strings
             $__tmplNames = "";
             // used for adding addtional info to the summary
             foreach ($__sfNames as $__sfName) {
                 $__sf = $__jsonData['sfdata']['page'][$__sfName];
                 if (isset($__sf['mfi'])) {
                     // multiple SF instancies detected - multiple SFs to be saved in one request
                     // TODO: implement
                 } else {
                     // build the template string for each SF element
                     foreach ($__sf as $template) {
                         $__tmplString .= "\n{{" . utf8_decode($template['tmpl_name']) . "\n";
                         // the tempalte name
                         $__tmplNames .= utf8_decode($template['tmpl_name']) . "\t";
                         // since @array will be read together with the SF field elements unset it
                         foreach ($template as $__field) {
                             // in the SF element are listed all SF fields
                             // add the field name and value to the template
                             if (array_key_exists('template_field', $__field)) {
                                 $__tmplString .= "|" . utf8_decode($__field['template_field']['field_name']) . "=" . utf8_decode($__field['cur_value']) . "\n";
                             }
                         }
                         $__tmplString .= "}}\n";
                         // add closing brackets to the template
                     }
                 }
             }
             return $__serverUtility->createPage($__userCredentials, $__pageTitle, $__tmplString, "SF data added to the page via the SF API. Templates:\t" . $__tmplNames);
         } else {
             // create the POM object for the requested page
             $__pom = new POMPage($__pageTitle, $__page->text, array('POMExtendedParser'));
             // since the attributes will be read together with the SF elements unset them
             unset($__jsonData['sfdata']['page']['title']);
             unset($__jsonData['sfdata']['page']['ns']);
             unset($__jsonData['sfdata']['page']['rid']);
             $__sfNames = array_keys($__jsonData['sfdata']['page']);
             $__tmplString = $__pom->text;
             // used for the creation of all template strings - preserve the existing page text if any
             $__tmplNames = "";
             // used for adding addtional info to the summary
             foreach ($__sfNames as $__sfName) {
                 $__sf = $__jsonData['sfdata']['page'][$__sfName];
                 foreach ($__sf as $template) {
                     $__iterator = $__pom->getTemplateByTitle($template['tmpl_name'])->listIterator();
                     if (isset($__sf['mfi'])) {
                         // multiple SF instances detected
                         // TODO: implement
                     } else {
                         // build the template string for each SF element
                         $__tmplString .= "\n{{" . utf8_decode($template['tmpl_name']) . "\n";
                         // the tempalte name
                         $__tmplNames .= utf8_decode($__sf['tmpl_name']) . "\t";
                         // since @array will be read together with the SF field elements unset it
                         unset($__sf['tmpl_name']);
                         foreach ($template as $__field) {
                             // in the SF element are listed all SF fields
                             // add the field name and value to the template
                             $__tmplString .= "|" . utf8_decode($__field['template_field']['field_name']) . "=" . utf8_decode($__field['cur_value']) . "\n";
                         }
                         $__tmplString .= "}}\n";
                         // add closing brackets to the template
                     }
                 }
             }
             return $__serverUtility->updatePage($__userCredentials, $__pageTitle, $__tmplString, "SF data added to the page via the SF API. Templates:\t" . $__tmplNames);
         }
     }
     if (stristr($methodType, "u")) {
         // the requested method is update
         if ($__page->pageid != NULL && $__page->pageid != "") {
             // the page exists
             // create the POM object for the requested page
             $__pom = new POMPage($__pageTitle, $__page->text, array('POMExtendedParser'));
             // since the attributes will be read together with the SF elements unset them
             unset($__jsonData['sfdata']['page']['title']);
             unset($__jsonData['sfdata']['page']['ns']);
             unset($__jsonData['sfdata']['page']['rid']);
             $__sfNames = array_keys($__jsonData['sfdata']['page']);
             $__tmplNames = "";
             // used for adding addtional info to the summary
             foreach ($__sfNames as $__sfName) {
                 $__sf = $__jsonData['sfdata']['page'][$__sfName];
                 foreach ($__sf as $template) {
                     $__iterator = $__pom->getTemplateByTitle(utf8_decode($template['tmpl_name']))->listIterator();
                     $__tmplNames .= $template . " ";
                     if (isset($__sf['mfi'])) {
                         // multiple SF instances detected
                         // TODO: implement
                     } else {
                         $__template =& $__iterator->getNextNodeValueByReference();
                         # get reference for direct changes
                         // since the attribute will be read together with the SF field elements unset it
                         unset($template['tmpl_name']);
                         //print_r($__sf); die;
                         foreach ($template as $__field) {
                             // in the SF element are listed all SF fields
                             if ($__template->getParameter($__field['template_field']['field_name']) !== NULL) {
                                 $__paramValue =& $__template->getParameterValue(utf8_decode($__field['template_field']['field_name']));
                                 $__paramValue = new POMSimpleText(utf8_decode($__field['cur_value']));
                             }
                         }
                     }
                 }
             }
             $__pom->sync();
             //print($__pom->text);die;
             return $__serverUtility->updatePage($__userCredentials, $__pageTitle, $__pom->text, "SF data updated on the page via the SF API. Templates:\t" . $__tmplNames);
         } else {
             // the page does not exist
             $this->dieUsage("Request cancelled. Page " . $__pageTitle . " does not exist.", 'param_xmldata');
         }
     }
     if (stristr($methodType, "d")) {
         // the requested method is delete
         if ($__page->pageid != NULL && $__page->pageid != "") {
             // the page exists
             // create the POM object for the requested page
             $__pom = new POMPage($__pageTitle, $__page->text, array('POMExtendedParser'));
             // since the attributes will be read together with the SF elements unset them
             unset($__jsonData['sfdata']['page']['title']);
             unset($__jsonData['sfdata']['page']['ns']);
             unset($__jsonData['sfdata']['page']['rid']);
             $__sfNames = array_keys($__jsonData['sfdata']['page']);
             $__tmplNames = "";
             // used for adding addtional info to the summary
             foreach ($__sfNames as $__sfName) {
                 $__sf = $__jsonData['sfdata']['page'][$__sfName];
                 $__iterator = $__pom->getTemplateByTitle(utf8_decode($__sf['tmpl_name']))->listIterator();
                 $__tmplNames .= $__sf . " ";
                 if (isset($__sf['@attributes']['mfi'])) {
                     // multiple SF instances detected
                     // TODO: implement
                 } else {
                     $__template =& $__iterator->getNextNodeValueByReference();
                     # get reference for direct changes
                     $__template = new POMSimpleText("");
                 }
             }
             $__pom->sync();
             return $__serverUtility->updatePage($__userCredentials, $__pageTitle, $__pom->text, "SF data deleted on the page via the SF API. Templates:\t" . $__tmplNames);
         } else {
             // the page does not exist
             $this->dieUsage("Request cancelled. Page " . $__pageTitle . " does not exist.", 'param_xmldata');
         }
     }
     return "";
 }