00001 <?php
00002
00015
00016
00017 import('paper.PaperGalley');
00018
00019 class PaperHTMLGalley extends PaperGalley {
00020
00024 function PaperHTMLGalley() {
00025 parent::PaperGalley();
00026 }
00027
00032 function isHTMLGalley() {
00033 return true;
00034 }
00035
00042 function getHTMLContents() {
00043 import('file.PaperFileManager');
00044 $fileManager = new PaperFileManager($this->getPaperId());
00045 $contents = $fileManager->readFile($this->getFileId());
00046
00047
00048 $images =& $this->getImageFiles();
00049
00050 foreach ($images as $image) {
00051 $imageUrl = Request::url(null, 'paper', 'viewFile', array($this->getPaperId(), $this->getGalleyId(), $image->getFileId()));
00052 $pattern = preg_quote(rawurlencode($image->getOriginalFileName()));
00053 $contents = preg_replace(
00054 '/[Ss][Rr][Cc]\s*=\s*"([^"]*' . $pattern . ')"/',
00055 'src="' . $imageUrl . '"',
00056 $contents
00057 );
00058 $contents = preg_replace(
00059 '/[Hh][Rr][Ee][Ff]\s*=\s*"([^"]*' . $pattern . ')"/',
00060 'href="' . $imageUrl . '"',
00061 $contents
00062 );
00063 }
00064
00065
00066 $contents = preg_replace_callback(
00067 '/(<[^<>]*")[Oo][Jj][Ss]:\/\/([^"]+)("[^<>]*>)/',
00068 array(&$this, '_handleOcsUrl'),
00069 $contents
00070 );
00071
00072 // Perform variable replacement for site info etc.
00073 $schedConf =& Request::getSchedConf();
00074 $site =& Request::getSite();
00075
00076 $paramArray = array(
00077 'confTitle' => $schedConf->getSchedConfTitle(),
00078 'siteTitle' => $site->getLocalizedTitle(),
00079 'currentUrl' => Request::getRequestUrl()
00080 );
00081
00082 foreach ($paramArray as $key => $value) {
00083 $contents = str_replace('{$' . $key . '}', $value, $contents);
00084 }
00085 return $contents;
00086 }
00087
00088 function _handleOcsUrl($matchArray) {
00089 $url = $matchArray[2];
00090 $anchor = null;
00091 if (($i = strpos($url, '#')) !== false) {
00092 $anchor = substr($url, $i+1);
00093 $url = substr($url, 0, $i);
00094 }
00095 $urlParts = explode('/', $url);
00096 if (isset($urlParts[0])) switch(String::strtolower($urlParts[0])) {
00097 case 'conference':
00098 $url = Request::url(
00099 isset($urlParts[1]) ?
00100 $urlParts[1] :
00101 Request::getRequestedConferencePath(),
00102 null,
00103 null,
00104 null,
00105 null,
00106 null,
00107 $anchor
00108 );
00109 break;
00110 case 'paper':
00111 if (isset($urlParts[1])) {
00112 $url = Request::url(
00113 null,
00114 null,
00115 'paper',
00116 'view',
00117 $urlParts[1],
00118 null,
00119 $anchor
00120 );
00121 }
00122 break;
00123 case 'schedConf':
00124 if (isset($urlParts[1])) {
00125 $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00126 $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00127 $thisSchedConf =& $schedConfDao->getSchedConfByPath($urlParts[1]);
00128 if (!$thisSchedConf) break;
00129 $thisConference =& $conferenceDao->getConference($thisSchedConf->getConferenceId());
00130 $url = Request::url(
00131 $thisConference->getPath(),
00132 $thisSchedConf->getPath(),
00133 null,
00134 null,
00135 null,
00136 null,
00137 $anchor
00138 );
00139 } else {
00140 $url = Request::url(
00141 null,
00142 null,
00143 'schedConfs',
00144 'current',
00145 null,
00146 null,
00147 $anchor
00148 );
00149 }
00150 break;
00151 case 'suppfile':
00152 if (isset($urlParts[1]) && isset($urlParts[2])) {
00153 $url = Request::url(
00154 null,
00155 null,
00156 'paper',
00157 'downloadSuppFile',
00158 array($urlParts[1], $urlParts[2]),
00159 null,
00160 $anchor
00161 );
00162 }
00163 break;
00164 case 'sitepublic':
00165 array_shift($urlParts);
00166 import ('file.PublicFileManager');
00167 $publicFileManager = new PublicFileManager();
00168 $url = Request::getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath() . '/' . implode('/', $urlParts) . ($anchor?'#' . $anchor:'');
00169 break;
00170 case 'public':
00171 array_shift($urlParts);
00172 $schedConf =& Request::getSchedConf();
00173 import ('file.PublicFileManager');
00174 $publicFileManager = new PublicFileManager();
00175 $url = Request::getBaseUrl() . '/' . $publicFileManager->getSchedConfFilesPath($schedConf->getId()) . '/' . implode('/', $urlParts) . ($anchor?'#' . $anchor:'');
00176 break;
00177 }
00178 return $matchArray[1] . $url . $matchArray[3];
00179 }
00180
00186 function isDependentFile($fileId) {
00187 if ($this->getStyleFileId() == $fileId) return true;
00188 foreach ($this->getImageFiles() as $image) {
00189 if ($image->getFileId() == $fileId) return true;
00190 }
00191 return false;
00192 }
00193
00194 //
00195 // Get/set methods
00196 //
00197
00202 function getStyleFileId() {
00203 return $this->getData('styleFileId');
00204 }
00205
00210 function setStyleFileId($styleFileId) {
00211 return $this->setData('styleFileId', $styleFileId);
00212 }
00213
00218 function &getStyleFile() {
00219 $styleFile =& $this->getData('styleFile');
00220 return $styleFile;
00221 }
00222
00227 function setStyleFile(&$styleFile) {
00228 $this->setData('styleFile', $styleFile);
00229 }
00230
00235 function &getImageFiles() {
00236 $images =& $this->getData('images');
00237 return $images;
00238 }
00239
00245 function setImageFiles(&$images) {
00246 return $this->setData('images', $images);
00247 }
00248
00249 }
00250
00251 ?>