00001 <?php
00002
00015
00016
00017
00018 import('classes.plugins.GenericPlugin');
00019
00020 define('TINYMCE_INSTALL_PATH', 'lib/tinymce');
00021 define('TINYMCE_JS_PATH', TINYMCE_INSTALL_PATH . '/jscripts/tiny_mce');
00022
00023 class TinyMCEPlugin extends GenericPlugin {
00031 function register($category, $path) {
00032 if (parent::register($category, $path)) {
00033 $this->addLocaleData();
00034 if ($this->isMCEInstalled() && $this->getEnabled()) {
00035 HookRegistry::register('TemplateManager::display',array(&$this, 'callback'));
00036 }
00037 return true;
00038 }
00039 return false;
00040 }
00041
00047 function getNewJournalPluginSettingsFile() {
00048 return $this->getPluginPath() . '/settings.xml';
00049 }
00050
00056 function getInstallSitePluginSettingsFile() {
00057 return $this->getPluginPath() . '/settings.xml';
00058 }
00059
00068 function getEnableFields(&$templateMgr, $page, $op) {
00069 $formLocale = $templateMgr->get_template_vars('formLocale');
00070 $fields = array();
00071 switch ("$page/$op") {
00072 case 'admin/settings':
00073 case 'admin/saveSettings':
00074 $fields[] = 'intro';
00075 $fields[] = 'about';
00076 break;
00077 case 'admin/createJournal':
00078 case 'admin/updateJournal':
00079 case 'admin/editJournal':
00080 $fields[] = 'description';
00081 break;
00082 case 'author/submit':
00083 case 'author/saveSubmit':
00084 switch (array_shift(Request::getRequestedArgs())) {
00085 case 1: $fields[] = 'commentsToEditor'; break;
00086 case 2:
00087 $count = max(1, count($templateMgr->get_template_vars('authors')));
00088 for ($i=0; $i<$count; $i++) {
00089 $fields[] = "authors-$i-biography";
00090 $fields[] = "authors-$i-competingInterests";
00091 }
00092 $fields[] = 'abstract';
00093 break;
00094 }
00095 break;
00096 case 'author/submitSuppFile': $fields[] = 'description'; break;
00097 case 'editor/createIssue':
00098 case 'editor/issueData':
00099 case 'editor/editIssue':
00100 $fields[] = 'description';
00101 $fields[] = 'coverPageDescription';
00102 break;
00103 case 'manager/createAnnouncement':
00104 case 'manager/editAnnouncement':
00105 $fields[] = 'descriptionShort';
00106 $fields[] = 'description';
00107 break;
00108 case 'user/profile':
00109 case 'user/register':
00110 case 'manager/createUser':
00111 case 'manager/updateUser':
00112 $fields[] = 'mailingAddress';
00113 $fields[] = 'biography';
00114 break;
00115 case 'manager/editReviewForm':
00116 case 'manager/createReviewForm':
00117 $fields[] = 'description';
00118 break;
00119 case 'manager/editReviewFormElement':
00120 case 'manager/createReviewFormElement':
00121 $fields[] = 'question';
00122 break;
00123 case 'manager/editSection':
00124 case 'manager/updateSection':
00125 case 'manager/createSection':
00126 $fields[] = 'policy';
00127 break;
00128 case 'manager/setup':
00129 case 'manager/saveSetup':
00130 switch (array_shift(Request::getRequestedArgs())) {
00131 case 1:
00132 $fields[] = 'mailingAddress';
00133 $fields[] = 'contactMailingAddress';
00134 $fields[] = 'publisherNote';
00135 $fields[] = 'sponsorNote';
00136 $fields[] = 'contributorNote';
00137 break;
00138 case 2:
00139 $fields[] = 'focusScopeDesc';
00140 $fields[] = 'reviewPolicy';
00141 $fields[] = 'reviewGuidelines';
00142 $fields[] = 'privacyStatement';
00143 $customAboutItems = $templateMgr->get_template_vars('customAboutItems');
00144 $count = max(1, isset($customAboutItems[$formLocale])?count($customAboutItems[$formLocale]):0);
00145 for ($i=0; $i<$count; $i++) {
00146
00147 $fields[] = "customAboutItems-$i-content";
00148 }
00149 $fields[] = 'lockssLicense';
00150 break;
00151 case 3:
00152 $fields[] = 'authorGuidelines';
00153 $submissionChecklist = $templateMgr->get_template_vars('submissionChecklist');
00154 $count = max(1, isset($submissionChecklist[$formLocale])?count($submissionChecklist[$formLocale]):0);
00155 for ($i=0; $i<$count; $i++) {
00156 $fields[] = "submissionChecklist-$i";
00157 }
00158 $fields[] = 'copyrightNotice';
00159 $fields[] = 'competingInterestGuidelines';
00160 break;
00161 case 4:
00162 $fields[] = 'openAccessPolicy';
00163 $fields[] = 'pubFreqPolicy';
00164 $fields[] = 'announcementsIntroduction';
00165 $fields[] = 'copyeditInstructions';
00166 $fields[] = 'layoutInstructions';
00167 $fields[] = 'refLinkInstructions';
00168 $fields[] = 'proofInstructions';
00169 break;
00170 case 5:
00171 $fields[] = 'journalDescription';
00172 $fields[] = 'additionalHomeContent';
00173 $fields[] = 'journalPageHeader';
00174 $fields[] = 'journalPageFooter';
00175 $fields[] = 'readerInformation';
00176 $fields[] = 'librarianInformation';
00177 $fields[] = 'authorInformation';
00178 }
00179 case 'reviewer/submission':
00180 $fields[] = 'competingInterests';
00181 break;
00182 case 'rtadmin/editContext':
00183 case 'rtadmin/editSearch':
00184 case 'rtadmin/editVersion':
00185 case 'rtadmin/createContext':
00186 case 'rtadmin/createSearch':
00187 case 'rtadmin/createVersion':
00188 $fields[] = 'description';
00189 break;
00190 case 'editor/createReviewer':
00191 case 'sectionEditor/createReviewer':
00192 $fields[] = 'mailingAddress';
00193 $fields[] = 'biography';
00194 break;
00195 case 'editor/submissionNotes':
00196 case 'sectionEditor/submissionNotes':
00197 $fields[] = 'note';
00198 break;
00199 case 'author/viewMetadata':
00200 case 'sectionEditor/viewMetadata':
00201 case 'editor/viewMetadata':
00202 case 'author/saveMetadata':
00203 case 'sectionEditor/saveMetadata':
00204 case 'editor/saveMetadata':
00205 case 'copyeditor/viewMetadata':
00206 case 'copyeditor/saveMetadata':
00207 $count = max(1, count($templateMgr->get_template_vars('authors')));
00208 for ($i=0; $i<$count; $i++) {
00209 $fields[] = "authors-$i-biography";
00210 $fields[] = "authors-$i-competingInterests";
00211 }
00212 $fields[] = 'abstract';
00213 break;
00214 case 'sectionEditor/editSuppFile':
00215 case 'editor/editSuppFile':
00216 case 'sectionEditor/saveSuppFile':
00217 case 'editor/saveSuppFile':
00218 $fields[] = 'description';
00219 break;
00220 case 'manager/subscriptionPolicies':
00221 case 'manager/saveSubscriptionPolicies':
00222 $fields[] = 'subscriptionMailingAddress';
00223 $fields[] = 'subscriptionAdditionalInformation';
00224 $fields[] = 'delayedOpenAccessPolicy';
00225 $fields[] = 'authorSelfArchivePolicy';
00226 break;
00227 case 'manager/editSubscriptionType':
00228 case 'manager/createSubscriptionType':
00229 case 'manager/updateSubscriptionType':
00230 $fields[] = 'description';
00231 break;
00232 }
00233 HookRegistry::call('TinyMCEPlugin::getEnableFields', array(&$this, &$fields));
00234 return $fields;
00235 }
00236
00243 function callback($hookName, $args) {
00244 $templateManager =& $args[0];
00245
00246 $page = Request::getRequestedPage();
00247 $op = Request::getRequestedOp();
00248 $enableFields = $this->getEnableFields($templateManager, $page, $op);
00249
00250 if (!empty($enableFields)) {
00251 $baseUrl = $templateManager->get_template_vars('baseUrl');
00252 $additionalHeadData = $templateManager->get_template_vars('additionalHeadData');
00253 $enableFields = join(',', $enableFields);
00254 $allLocales = Locale::getAllLocales();
00255 $localeList = array();
00256 foreach ($allLocales as $key => $locale) {
00257 $localeList[] = String::substr($key, 0, 2);
00258 }
00259
00260 $tinyMCE_scipt = '
00261 <script language="javascript" type="text/javascript" src="'.$baseUrl.'/'.TINYMCE_JS_PATH.'/tiny_mce_gzip.js"></script>
00262 <script language="javascript" type="text/javascript">
00263 tinyMCE_GZ.init({
00264 relative_urls : "false",
00265 plugins : "paste,latex",
00266 themes : "advanced",
00267 languages : "' . join(',', $localeList) . '",
00268 disk_cache : true
00269 });
00270 </script>
00271 <script language="javascript" type="text/javascript">
00272 tinyMCE.init({
00273 plugins : "paste,latex",
00274 mode : "exact",
00275 language : "' . String::substr(Locale::getLocale(), 0, 2) . '",
00276 elements : "' . $enableFields . '",
00277 relative_urls : false,
00278 forced_root_block : false,
00279 apply_source_formatting : false,
00280 theme : "advanced",
00281 theme_advanced_buttons1 : "pasteword,bold,italic,underline,bullist,numlist,link,unlink,help,code,latex",
00282 theme_advanced_buttons2 : "",
00283 theme_advanced_buttons3 : ""
00284 });
00285 </script>';
00286
00287 $templateManager->assign('additionalHeadData', $additionalHeadData."\n".$tinyMCE_scipt);
00288 }
00289 return false;
00290 }
00291
00296 function getName() {
00297 return 'TinyMCEPlugin';
00298 }
00299
00304 function getDisplayName() {
00305 return Locale::translate('plugins.generic.tinymce.name');
00306 }
00307
00312 function getDescription() {
00313 if ($this->isMCEInstalled()) return Locale::translate('plugins.generic.tinymce.description');
00314 return Locale::translate('plugins.generic.tinymce.descriptionDisabled', array('tinyMcePath' => TINYMCE_INSTALL_PATH));
00315 }
00316
00321 function isMCEInstalled() {
00322 return file_exists(TINYMCE_JS_PATH . '/tiny_mce.js');
00323 }
00324
00329 function getEnabled() {
00330 $journal =& Request::getJournal();
00331 $journalId = $journal?$journal->getJournalId():0;
00332 return $this->getSetting($journalId, 'enabled');
00333 }
00334
00339 function getManagementVerbs() {
00340 $verbs = array();
00341 if ($this->isMCEInstalled()) $verbs[] = array(
00342 ($this->getEnabled()?'disable':'enable'),
00343 Locale::translate($this->getEnabled()?'manager.plugins.disable':'manager.plugins.enable')
00344 );
00345 return $verbs;
00346 }
00347
00354 function manage($verb, $args) {
00355 $journal =& Request::getJournal();
00356 $journalId = $journal?$journal->getJournalId():0;
00357 switch ($verb) {
00358 case 'enable':
00359 $this->updateSetting($journalId, 'enabled', true);
00360 break;
00361 case 'disable':
00362 $this->updateSetting($journalId, 'enabled', false);
00363 break;
00364 }
00365 return false;
00366 }
00367 }
00368 ?>