00001 <?php
00002
00015
00016
00017
00018 import('article.ArticleGalley');
00019
00020 class ArticleHTMLGalley extends ArticleGalley {
00021
00025 function ArticleHTMLGalley() {
00026 parent::ArticleGalley();
00027 }
00028
00033 function isHTMLGalley() {
00034 return true;
00035 }
00036
00043 function getHTMLContents() {
00044 import('file.ArticleFileManager');
00045 $fileManager = &new ArticleFileManager($this->getArticleId());
00046 $contents = $fileManager->readFile($this->getFileId());
00047 $journal =& Request::getJournal();
00048
00049
00050 $images = &$this->getImageFiles();
00051
00052 foreach ($images as $image) {
00053 $imageUrl = Request::url(null, 'article', 'viewFile', array($this->getArticleId(), $this->getBestGalleyId($journal), $image->getFileId()));
00054 $pattern = preg_quote(rawurlencode($image->getOriginalFileName()));
00055
00056 $contents = preg_replace(
00057 '/([Ss][Rr][Cc]|[Hh][Rr][Ee][Ff]|[Dd][Aa][Tt][Aa])\s*=\s*"([^"]*' . $pattern . ')"/',
00058 '\1="' . $imageUrl . '"',
00059 $contents
00060 );
00061
00062
00063 $contents = preg_replace(
00064 '/[Uu][Rr][Ll]\s*\:\s*\'(' . $pattern . ')\'/',
00065 'url:\'' . $imageUrl . '\'',
00066 $contents
00067 );
00068
00069
00070 $contents = preg_replace(
00071 '/[Uu][Rr][Ll]=([^"]*' . $pattern . ')/',
00072 'url=' . $imageUrl ,
00073 $contents
00074 );
00075
00076 }
00077
00078
00079 $contents = String::regexp_replace_callback(
00080 '/(<[^<>]*")[Oo][Jj][Ss]:\/\/([^"]+)("[^<>]*>)/',
00081 array(&$this, '_handleOjsUrl'),
00082 $contents
00083 );
00084
00085
00086 $issueDao =& DAORegistry::getDAO('IssueDAO');
00087 $issue =& $issueDao->getIssueByArticleId($this->getArticleId());
00088
00089 $journal =& Request::getJournal();
00090 $site =& Request::getSite();
00091
00092 $paramArray = array(
00093 'issueTitle' => $issue?$issue->getIssueIdentification():Locale::translate('editor.article.scheduleForPublication.toBeAssigned'),
00094 'journalTitle' => $journal->getJournalTitle(),
00095 'siteTitle' => $site->getSiteTitle(),
00096 'currentUrl' => Request::getRequestUrl()
00097 );
00098
00099 foreach ($paramArray as $key => $value) {
00100 $contents = str_replace('{$' . $key . '}', $value, $contents);
00101 }
00102
00103 return $contents;
00104 }
00105
00106 function _handleOjsUrl($matchArray) {
00107 $url = $matchArray[2];
00108 $anchor = null;
00109 if (($i = strpos($url, '#')) !== false) {
00110 $anchor = substr($url, $i+1);
00111 $url = substr($url, 0, $i);
00112 }
00113 $urlParts = explode('/', $url);
00114 if (isset($urlParts[0])) switch(String::strtolower($urlParts[0])) {
00115 case 'journal':
00116 $url = Request::url(
00117 isset($urlParts[1]) ?
00118 $urlParts[1] :
00119 Request::getRequestedJournalPath(),
00120 null,
00121 null,
00122 null,
00123 null,
00124 $anchor
00125 );
00126 break;
00127 case 'article':
00128 if (isset($urlParts[1])) {
00129 $url = Request::url(
00130 null,
00131 'article',
00132 'view',
00133 $urlParts[1],
00134 null,
00135 $anchor
00136 );
00137 }
00138 break;
00139 case 'issue':
00140 if (isset($urlParts[1])) {
00141 $url = Request::url(
00142 null,
00143 'issue',
00144 'view',
00145 $urlParts[1],
00146 null,
00147 $anchor
00148 );
00149 } else {
00150 $url = Request::url(
00151 null,
00152 'issue',
00153 'current',
00154 null,
00155 null,
00156 $anchor
00157 );
00158 }
00159 break;
00160 case 'suppfile':
00161 if (isset($urlParts[1]) && isset($urlParts[2])) {
00162 $url = Request::url(
00163 null,
00164 'article',
00165 'downloadSuppFile',
00166 array($urlParts[1], $urlParts[2]),
00167 null,
00168 $anchor
00169 );
00170 }
00171 break;
00172 case 'sitepublic':
00173 array_shift($urlParts);
00174 import ('file.PublicFileManager');
00175 $publicFileManager = &new PublicFileManager();
00176 $url = Request::getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath() . '/' . implode('/', $urlParts) . ($anchor?'#' . $anchor:'');
00177 break;
00178 case 'public':
00179 array_shift($urlParts);
00180 $journal = &Request::getJournal();
00181 import ('file.PublicFileManager');
00182 $publicFileManager = &new PublicFileManager();
00183 $url = Request::getBaseUrl() . '/' . $publicFileManager->getJournalFilesPath($journal->getJournalId()) . '/' . implode('/', $urlParts) . ($anchor?'#' . $anchor:'');
00184 break;
00185 }
00186 return $matchArray[1] . $url . $matchArray[3];
00187 }
00188
00194 function isDependentFile($fileId) {
00195 if ($this->getStyleFileId() == $fileId) return true;
00196 foreach ($this->getImageFiles() as $image) {
00197 if ($image->getFileId() == $fileId) return true;
00198 }
00199 return false;
00200 }
00201
00202
00203
00204
00205
00210 function getStyleFileId() {
00211 return $this->getData('styleFileId');
00212 }
00213
00218 function setStyleFileId($styleFileId) {
00219 return $this->setData('styleFileId', $styleFileId);
00220 }
00221
00226 function &getStyleFile() {
00227 $styleFile = &$this->getData('styleFile');
00228 return $styleFile;
00229 }
00230
00235 function setStyleFile(&$styleFile) {
00236 $this->setData('styleFile', $styleFile);
00237 }
00238
00243 function &getImageFiles() {
00244 $images = &$this->getData('images');
00245 return $images;
00246 }
00247
00253 function setImageFiles(&$images) {
00254 return $this->setData('images', $images);
00255 }
00256
00257 }
00258
00259 ?>