/**
  * Searches the DOM for <img>-Tags and <a> Tags with class 'internal', 
  * resolves the local filesystem path and adds it to $aFiles array.
  * @param DOMDocument $oHtml The markup to be searched.
  * @return boolean Well, always true.
  */
 protected function findFiles(&$oHtml)
 {
     //Find all images
     $oImageElements = $oHtml->getElementsByTagName('img');
     foreach ($oImageElements as $oImageElement) {
         $sSrcUrl = urldecode($oImageElement->getAttribute('src'));
         $sSrcFilename = basename($sSrcUrl);
         $bIsThumb = UploadBase::isThumbName($sSrcFilename);
         $sTmpFilename = $sSrcFilename;
         if ($bIsThumb) {
             //HINT: Thumbname-to-filename-conversion taken from includes/Upload/UploadBase.php
             //Check for filenames like 50px- or 180px-, these are mostly thumbnails
             $sTmpFilename = substr($sTmpFilename, strpos($sTmpFilename, '-') + 1);
         }
         $oFileTitle = Title::newFromText($sTmpFilename, NS_FILE);
         $oImage = RepoGroup::singleton()->findFile($oFileTitle);
         if ($oImage instanceof File && $oImage->exists()) {
             $oFileRepoLocalRef = $oImage->getRepo()->getLocalReference($oImage->getPath());
             if (!is_null($oFileRepoLocalRef)) {
                 $sAbsoluteFileSystemPath = $oFileRepoLocalRef->getPath();
             }
             $sSrcFilename = $oImage->getName();
         } else {
             $sAbsoluteFileSystemPath = $this->getFileSystemPath($sSrcUrl);
         }
         // TODO RBV (05.04.12 11:48): Check if urlencode has side effects
         $oImageElement->setAttribute('src', 'images/' . urlencode($sSrcFilename));
         $sFileName = $sSrcFilename;
         wfRunHooks('BSUEModulePDFWebserviceFindFiles', array($this, $oImageElement, $sAbsoluteFileSystemPath, $sFileName, 'IMAGE'));
         $this->aFiles['IMAGE'][$sFileName] = $sAbsoluteFileSystemPath;
     }
     $oDOMXPath = new DOMXPath($oHtml);
     /*
     * This is now in template
     		//Find all CSS files
     		$oLinkElements = $oHtml->getElementsByTagName( 'link' ); // TODO RBV (02.02.11 16:48): Limit to rel="stylesheet" and type="text/css"
     		foreach( $oLinkElements as $oLinkElement ) {
     			$sHrefUrl = $oLinkElement->getAttribute( 'href' );
     			$sHrefFilename           = basename( $sHrefUrl );
     			$sAbsoluteFileSystemPath = $this->getFileSystemPath( $sHrefUrl );
     			$this->aFiles[ $sAbsoluteFileSystemPath ] = array( $sHrefFilename, 'STYLESHEET' );
     			$oLinkElement->setAttribute( 'href', 'stylesheets/'.$sHrefFilename );
     		}
     */
     //Find all files for attaching and merging...
     if ($this->aParams['pdf-merging'] == '1' || $this->aParams['attachments'] == '1') {
         $sUploadPath = BsCore::getInstance()->getAdapter()->get('UploadPath');
         // TODO RBV (08.02.11 15:15): Necessary to exclude images?
         $oFileAnchorElements = $oDOMXPath->query("//a[contains(@class,'internal') and not(contains(@class, 'image'))]");
         foreach ($oFileAnchorElements as $oFileAnchorElement) {
             $sHref = urldecode($oFileAnchorElement->getAttribute('href'));
             $vUploadPathIndex = strpos($sHref, $sUploadPath);
             if ($vUploadPathIndex !== false) {
                 $sRelativeHref = substr($sHref, $vUploadPathIndex);
                 $sHrefFilename = basename($sRelativeHref);
                 $sAbsoluteFileSystemPath = $this->getFileSystemPath($sRelativeHref);
                 if ($this->aParams['attachments'] == '1') {
                     wfRunHooks('BSUEModulePDFWebserviceFindFiles', array($this, $oFileAnchorElement, $sAbsoluteFileSystemPath, $sHrefFilename, 'ATTACHMENT'));
                     $this->aFiles['ATTACHMENT'][$sHrefFilename] = $sAbsoluteFileSystemPath;
                 }
             }
         }
     }
     return true;
 }
 /**
  * Searches the DOM for <img>-Tags and <a> Tags with class 'internal',
  * resolves the local filesystem path and adds it to $aFiles array.
  * @param DOMDocument $oHtml The markup to be searched.
  * @return boolean Well, always true.
  */
 protected function findFiles(&$oHtml)
 {
     //Find all images
     $oImageElements = $oHtml->getElementsByTagName('img');
     foreach ($oImageElements as $oImageElement) {
         $sSrcUrl = urldecode($oImageElement->getAttribute('src'));
         $sSrcFilename = basename($sSrcUrl);
         $bIsThumb = UploadBase::isThumbName($sSrcFilename);
         $sTmpFilename = $sSrcFilename;
         if ($bIsThumb) {
             //HINT: Thumbname-to-filename-conversion taken from includes/Upload/UploadBase.php
             //Check for filenames like 50px- or 180px-, these are mostly thumbnails
             $sTmpFilename = substr($sTmpFilename, strpos($sTmpFilename, '-') + 1);
         }
         $oFileTitle = Title::newFromText($sTmpFilename, NS_FILE);
         $oImage = RepoGroup::singleton()->findFile($oFileTitle);
         if ($oImage instanceof File && $oImage->exists()) {
             $oFileRepoLocalRef = $oImage->getRepo()->getLocalReference($oImage->getPath());
             if (!is_null($oFileRepoLocalRef)) {
                 $sAbsoluteFileSystemPath = $oFileRepoLocalRef->getPath();
             }
             $sSrcFilename = $oImage->getName();
         } else {
             $sAbsoluteFileSystemPath = $this->getFileSystemPath($sSrcUrl);
         }
         // TODO RBV (05.04.12 11:48): Check if urlencode has side effects
         $oImageElement->setAttribute('src', 'images/' . urlencode($sSrcFilename));
         $sFileName = $sSrcFilename;
         wfRunHooks('BSUEModulePDFFindFiles', array($this, $oImageElement, &$sAbsoluteFileSystemPath, &$sFileName, 'images'));
         wfRunHooks('BSUEModulePDFWebserviceFindFiles', array($this, $oImageElement, &$sAbsoluteFileSystemPath, &$sFileName, 'images'));
         $this->aFiles['images'][$sFileName] = $sAbsoluteFileSystemPath;
     }
     $oDOMXPath = new DOMXPath($oHtml);
     /*
     * This is now in template
     		//Find all CSS files
     		$oLinkElements = $oHtml->getElementsByTagName( 'link' ); // TODO RBV (02.02.11 16:48): Limit to rel="stylesheet" and type="text/css"
     		foreach( $oLinkElements as $oLinkElement ) {
     			$sHrefUrl = $oLinkElement->getAttribute( 'href' );
     			$sHrefFilename           = basename( $sHrefUrl );
     			$sAbsoluteFileSystemPath = $this->getFileSystemPath( $sHrefUrl );
     			$this->aFiles[ $sAbsoluteFileSystemPath ] = array( $sHrefFilename, 'STYLESHEET' );
     			$oLinkElement->setAttribute( 'href', 'stylesheets/'.$sHrefFilename );
     		}
     */
     wfRunHooks('BSUEModulePDFAfterFindFiles', array($this, $oHtml, &$this->aFiles, $this->aParams, $oDOMXPath));
     return true;
 }