Exemple #1
0
 public function getOutput()
 {
     $this->setAttribute('data', $this->filename);
     $url = new HTMLElement('param');
     $url->setAttribute('name', 'src');
     $url->setAttribute('value', $this->filename);
     $this->appendChild($url);
     $url = new HTMLElement('param');
     $url->setAttribute('name', 'url');
     $url->setAttribute('value', $this->filename);
     $this->appendChild($url);
     $url = new HTMLElement('param');
     $url->setAttribute('name', 'autoplay');
     $url->setAttribute('value', $this->autostart);
     $this->appendChild($url);
     $color = new HTMLElement('param');
     $color->setAttribute('name', 'color');
     $color->setAttribute('value', '#FFFFFF');
     $this->appendChild($color);
     return parent::getOutput();
 }
 /**
  * @return HTMLElement
  */
 public function parseDropDownList()
 {
     $dropDownListContainer = new HTMLElement(HTMLElement::SELECT);
     $options = $this->getOptions();
     foreach ($options as $option) {
         $optionContainer = new HTMLElement(HTMLElement::OPTION);
         $optionText = (string) $option[0]['wdisplayText'];
         $optionValue = (string) $option[0]['wvalue'];
         $optionContainer->setInnerText($optionText);
         $optionContainer->setAttribute('value', $optionValue);
         $dropDownListContainer->addInnerElement($optionContainer);
     }
     return $dropDownListContainer;
 }
 /**
  * @param $contents
  * @return HTMLElement
  */
 private function constructTOCHeader($contents)
 {
     $headerRow = new HTMLElement(HTMLElement::TR);
     $headerCell = new HTMLElement(HTMLElement::TD);
     $textContainer = new HTMLElement(HTMLElement::SPAN);
     $textContainer->setInnerText($contents);
     $textContainer->setAttribute('style', 'font-size:14pt;font-weight:bold');
     $headerRow->addInnerElement($headerCell);
     $headerCell->setAttribute('colspan', 3);
     $headerCell->addInnerElement($textContainer);
     return $headerRow;
 }
 public function testCanSetMultipleValuesForSameAttribute()
 {
     $expected = "<h1 class='one two'>{$this->testContent}</h1>";
     $el = new HTMLElement();
     $el->setNodeType('h1');
     $el->setContent($this->testContent);
     $el->class = 'one';
     $el->setAttribute('class', 'two');
     $this->assertEquals($expected, $el->getNode());
 }
Exemple #5
0
 public function parseTableCell()
 {
     $cellContainer = new HTMLElement(HTMLElement::TD);
     $paragraphs = $this->getParagraphs();
     foreach ($paragraphs as $javaParagraph) {
         $paragraph = new XWPFParagraph($javaParagraph, $this->mainStyleSheet);
         $paragraphContainer = $paragraph->parseParagraph();
         $styleClass = $paragraph->processParagraphStyle();
         $paragraphStyle = $this->extractParagraphStyles();
         // Merge inherited styles
         if ($paragraphStyle->hasAttributes()) {
             $styleClass = $styleClass->mergeStyleClass($paragraphStyle);
         }
         $className = $this->mainStyleSheet->getClassName($styleClass);
         $paragraphContainer->setClass('textframe horizontal common_style1 ' . $className);
         // Add id attribute to container for this paragraph
         if (!empty($paragraph->getId())) {
             $paragraphContainer->setAttribute('id', 'div_' . $paragraph->getId());
         }
         $cellContainer->addInnerElement($paragraphContainer);
     }
     //Set Attributes
     $colspan = $this->getColspan();
     if (!empty($colspan)) {
         $cellContainer->setAttribute('colspan', $colspan);
     }
     //TODO Find values for rowspan
     //        $rowspan = $this->getRowspan();
     //        if($rowspan == "restart") $cellContainer->setAttribute('rowspan', 2);
     return $cellContainer;
 }
 /**
  * parses a picture element of HWPF document
  * @param HWPFSection $picture
  * @param isPicture - if false, then it is an external picture URL that needs to be treated like external picture
  * @return HTMLElement
  */
 private function processPicture($picture, $isPicture)
 {
     // take aspect ratio if picture
     $aspectRatioX = java_values($picture->getHorizontalScalingFactor());
     $aspectRatioY = java_values($picture->getVerticalScalingFactor());
     //not sure what this means yet
     $dxaGoal = java_values($picture->getDxaGoal());
     $dyaGoal = java_values($picture->getDyaGoal());
     // calculate the used image width and height, we can either save picture file in that size, or save them in buigger size, but use size on img element
     $imageWidth = $aspectRatioX > 0 ? $dxaGoal * $aspectRatioX / 1000 / HWPFWrapper::TWIPS_PER_INCH : $dxaGoal / HWPFWrapper::TWIPS_PER_INCH;
     $imageHeight = $aspectRatioY > 0 ? $dyaGoal * $aspectRatioY / 1000 / HWPFWrapper::TWIPS_PER_INCH : $dyaGoal / HWPFWrapper::TWIPS_PER_INCH;
     //taking main picture data and saving it to the file system (this part needs to be enhanced)
     $picContent = java_values($picture->getContent());
     $picType = java_values($picture->suggestPictureType()->getMime());
     $picName = java_values($picture->suggestFullFileName());
     $path = "tmp/{$picName}";
     $fp = fopen($path, 'w');
     fwrite($fp, $picContent);
     fclose($fp);
     $this->images[$picName] = $picName;
     //creating img element with path to newly created picture
     $container = new HTMLElement(HTMLElement::IMG);
     $container->setAttribute("src", '../images/' . $picName);
     //$container->setAttribute("width",  $imageWidth.'in');
     //$container->setAttribute("height",   $imageHeight.'in');
     return $container;
 }
 /**
  * Parse the table of contents
  * @param $paragraph
  * @return HTMLElement
  */
 public function parseToc($paragraph)
 {
     $this->tocLevel++;
     $this->toc = true;
     //Create row
     $toc_row = new HTMLElement(HTMLElement::TR);
     //Get characters
     $runs = java_values($paragraph->getRuns());
     //Get all the HTML characters in the paragraph
     $tocRow = array();
     for ($i = 0; $i < count($runs); $i++) {
         $character = $runs[$i];
         $run = new XWPFRun($character, $this->mainStyleSheet);
         $runHTMLElement = $run->parseRun();
         //$runHTMLElement = $this->parseCharacterRun($character);
         $tocRow[$i] = $runHTMLElement;
     }
     $tocNum = $tocRow[0];
     $a = 1;
     //Find last element
     while ($tocRow[count($runs) - $a]->getInnerText() == "<br />") {
         $a++;
     }
     $a++;
     $desLevel = count($runs) - $a;
     if ($desLevel >= 0) {
         $tocPage = $tocRow[$desLevel];
     } else {
         $tocPage = $tocRow[0];
     }
     //Add all the elements of description
     $toc_cell = new HTMLElement(HTMLElement::TD);
     $toc_link = new HTMLElement(HTMLElement::A);
     for ($i = 1; $i < $desLevel; $i++) {
         $testText = $tocRow[$i]->getInnerText();
         $valid = strpos($testText, "<");
         if ($valid == false) {
             if (is_a($tocRow[$i], 'HTMLElement')) {
                 if (!empty(trim($tocRow[$i]->getInnerText()))) {
                     $toc_link->addInnerElement($tocRow[$i]);
                 }
             }
         }
     }
     //Apply styles for toc num and toc page number
     $tocNum->setAttribute('style', 'margin-right:10px');
     $toc_link->setAttribute('style', 'margin-right:10px');
     $toc_link->setAttribute('style', 'text-decoration:inherit');
     $tocPage->setAttribute('style', 'float:right');
     //Set link direction
     $link = '#toc' . $this->headlineId;
     $toc_link->setAttribute('href', $link);
     $this->headlineId++;
     //Add elements to toc cell
     $toc_cell->addInnerElement($tocNum);
     $toc_cell->addInnerElement($toc_link);
     $toc_cell->addInnerElement($tocPage);
     //Get table of contents
     $needles = array('<strong >', '</strong>');
     $textList = $toc_link->getLastElement();
     if (is_a($textList, 'HTMLElement')) {
         $text = trim(str_replace($needles, "", $textList->getInnerText()));
     } else {
         $text = trim(str_replace($needles, "", $textList));
     }
     $textNum = trim(str_replace($needles, "", $tocNum->getInnerText()));
     $textPage = trim(str_replace($needles, "", $tocPage->getInnerText()));
     $this->tableOfContents[] = array('num' => $textNum, 'description' => $text, 'page' => $textPage);
     //Add cell to toc row
     $toc_row->addInnerElement($toc_cell);
     //Add row to table or create table if it's the first toc entry
     if ($this->tocLevel == 1) {
         $container = new HTMLElement(HTMLElement::NAV);
         $tableContainer = new HTMLElement(HTMLElement::TABLE);
         $tableContainer->addInnerElement($toc_row);
         $container->addInnerElement($tableContainer);
     } else {
         $container = $toc_row;
     }
     return $container;
 }
Exemple #8
0
 /**
  * @param $name
  * @return HTMLElement
  */
 private function returnUnssuportedImageMessage($name)
 {
     $messageBox = new HTMLElement(HTMLElement::DIV);
     $boxStyleClass = new StyleClass();
     $messageText = "This image could not be imported. It's not supported format.";
     $messageParagraph = new HTMLElement(HTMLElement::P);
     $messageParagraph->setInnerText($messageText);
     $messageParagraph->setAttribute('style', "font-weight: bold");
     $messageBox->addInnerElement($messageParagraph);
     $imageName = (string) $name;
     $nameParagraph = new HTMLElement(HTMLElement::P);
     $nameParagraph->setInnerText($imageName);
     $messageBox->addInnerElement($nameParagraph);
     $boxStyleClass->setAttribute('width', '75%');
     $boxStyleClass->setAttribute('margin', '0 auto');
     $boxStyleClass->setAttribute('background-color', '#ffcfba');
     $boxStyleClass->setAttribute('color', '#d91c24');
     $boxStyleClass->setAttribute('font-size', '14px');
     $boxStyleClass->setAttribute('font-family', 'Roboto, sans-serif');
     $boxStyleClass->setAttribute('padding-bottom', '25px');
     $boxStyleClass->setAttribute('padding-top', '25px');
     $boxStyleClass->setAttribute('padding-right', '25px');
     $boxStyleClass->setAttribute('padding-left', '25px');
     $boxStyleClass->setAttribute('text-align', 'center');
     $className = $this->mainStyleSheet->getClassName($boxStyleClass);
     $messageBox->setClass($className);
     return $messageBox;
 }
Exemple #9
0
 public function parseTableHeaderContent($stdRow)
 {
     $stdCellInfoContainer = new HTMLElement(HTMLElement::TD);
     $wsdtContentParagraphs = $stdRow->xpath('wsdtContent/wtc/wtbl/wtr/wsdt/wsdtPr/walias');
     foreach ($wsdtContentParagraphs as $sdtParagraph) {
         //Paragraph Conversion
         $stdParagraphContainer = new HTMLElement(HTMLElement::P);
         $backgroundColor = $stdRow->xpath('wsdtContent/wtc/wtcPr/wshd')[0]['wfill'];
         $stdCellInfoContainer->setAttribute('style', 'background-color:#' . $backgroundColor);
         //Setting text to the cell
         $paragraphContent = (string) $sdtParagraph[0]['wval'];
         $text = XhtmlEntityConverter::convertToNumericalEntities(htmlentities($paragraphContent, ENT_COMPAT | ENT_XHTML));
         $stdParagraphContainer->setInnerText($text);
         $stdCellInfoContainer->addInnerElement($stdParagraphContainer);
     }
     return $stdCellInfoContainer;
 }
Exemple #10
0
 /**
  * Process a list of the document
  * @param $numberingInfo
  * @param $container
  * @param $paragraph
  * @param $key
  */
 public function processList($numberingInfo, $container, $paragraph, $key, $listNumId)
 {
     //Extract List Properties
     $abstractNum = $this->getAbstractNum($numberingInfo);
     $listProperties = $this->extractListProperties($abstractNum, $numberingInfo);
     //If this is set to true a new list container should be created
     $newListActivator = false;
     echo $this->listNumId;
     echo "-------------------";
     echo $numberingInfo['numId'];
     echo "<br/>";
     if ($listNumId != $numberingInfo['numId']) {
         echo "Activado " . "<br/>";
         $newListActivator = true;
     }
     $levelCount = $numberingInfo['lvl'];
     //Check if the list level state has change
     if ($this->listLevelState != $levelCount) {
         //Create new list
         $newList = new HTMLElement(HTMLElement::UL);
         $newList->setAttribute('style', 'list-style-type:' . $listProperties['type']);
         //Get last ul element to add the new list ul container
         $lastContainer = $container->getLastElement();
         for ($i = 0; $i < $this->listLevelState; $i++) {
             $lastContainer = $lastContainer->getLastElement();
         }
         //Add new list in the last container
         if (is_object($lastContainer)) {
             $lastContainer->addInnerElement($newList);
         }
     }
     //Assign new list level state and num id
     $this->listLevelState = $numberingInfo['lvl'];
     $this->listNumId = $numberingInfo['numId'];
     //        echo $this->listLevelState;
     //        echo "-------------------";
     //        echo $this->listNumId;
     //        echo "<br/>";
     // Parse list item
     $listItemHTMLElement = $this->parseList($paragraph);
     $listItemHTMLElement->setId($key);
     //Check if the container has a last element to avoid non object exception
     if (is_object($container->getLastElement()) and !$newListActivator) {
         //Assign the tag name
         $containerLastElement = $container->getLastElement()->getTagName();
     } elseif ($newListActivator) {
         //Add another level list
         $containerLastElement = "innerul";
     } else {
         //Set default in case the container has no inner elements
         $containerLastElement = "text";
     }
     // Check if the actual container has a list container as last element
     if ($containerLastElement == "ul") {
         //Initialize last container
         $lastContainer = $container->getLastElement();
         //Find current list element
         for ($i = 0; $i < $this->listLevelState; $i++) {
             if (is_object($lastContainer)) {
                 $lastContainer = $lastContainer->getLastElement();
             }
         }
         //Check if the container is fill
         if (is_object($lastContainer)) {
             $listItemHTMLElement->setId($key);
             $lastContainer->addInnerElement($listItemHTMLElement);
         }
     } elseif ($containerLastElement == 'innerul' or $containerLastElement != "ul") {
         //Create a new list container
         $listContainer = new HTMLElement(HTMLElement::UL);
         $listContainer->setId($key);
         //Set list type style
         $listContainer->setAttribute('style', 'list-style-type:' . $listProperties['type'] . ';' . 'margin-left:' . $listProperties['indentation'] . 'px');
         //Fill the list with the first li item
         $firstItemId = $key + 1;
         $listItemHTMLElement->setId($firstItemId);
         $listContainer->addInnerElement($listItemHTMLElement);
         //Set the list to the container
         $container->addInnerElement($listContainer);
     }
 }