plugins/generic/tinymce/TinyMCEPlugin.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00015 //$Id$
00016 
00017 import('classes.plugins.GenericPlugin');
00018 
00019 define('TINYMCE_INSTALL_PATH', 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'tinymce');
00020 define('TINYMCE_JS_PATH', TINYMCE_INSTALL_PATH . DIRECTORY_SEPARATOR . 'jscripts' . DIRECTORY_SEPARATOR . 'tiny_mce');
00021 
00022 class TinyMCEPlugin extends GenericPlugin {
00030    function register($category, $path) {
00031       if (parent::register($category, $path)) {
00032          $this->addLocaleData();
00033          if ($this->isMCEInstalled() && $this->getEnabled()) {
00034             HookRegistry::register('TemplateManager::display',array(&$this, 'callback'));
00035          }
00036          return true;
00037       }
00038       return false;
00039    }
00040 
00046    function getNewConferencePluginSettingsFile() {
00047       return $this->getPluginPath() . '/settings.xml';
00048    }
00049 
00055    function getInstallSitePluginSettingsFile() {
00056       return $this->getPluginPath() . '/settings.xml';
00057    }
00058 
00067    function getEnableFields(&$templateMgr, $page, $op) {
00068       $formLocale = $templateMgr->get_template_vars('formLocale');
00069       $fields = array();
00070       switch ("$page/$op") {
00071          case 'admin/settings':
00072          case 'admin/saveSettings':
00073             $fields[] = 'intro';
00074             $fields[] = 'aboutField';
00075             break;
00076          case 'admin/createConference':
00077          case 'admin/updateConference':
00078          case 'admin/editConference':
00079             $fields[] = 'description';
00080             break;
00081          case 'author/submit':
00082          case 'author/saveSubmit':
00083             switch (array_shift(Request::getRequestedArgs())) {
00084                case 1: $fields[] = 'commentsToDirector'; break;
00085                case 3:
00086                   $count = max(1, count($templateMgr->get_template_vars('authors')));
00087                   for ($i=0; $i<$count; $i++) {
00088                      $fields[] = "authors-$i-affiliation";
00089                      $fields[] = "authors-$i-biography";
00090                   }
00091                   $fields[] = 'abstract';
00092                   $fields[] = 'citations';
00093                   break;
00094             }
00095             break;
00096          case 'author/submitSuppFile': $fields[] = 'description'; break;
00097          case 'manager/createAnnouncement':
00098          case 'manager/editAnnouncement':
00099          case 'manager/updateAnnouncement':
00100             $fields[] = 'descriptionShort';
00101             $fields[] = 'description';
00102             break;
00103          case 'user/profile':
00104          case 'user/account':
00105          case 'user/saveProfile':
00106          case 'manager/createUser':
00107          case 'manager/updateUser':
00108             $fields[] = 'mailingAddress';
00109             $fields[] = 'biography';
00110             break;
00111          case 'manager/editReviewForm':
00112          case 'manager/updateReviewForm':
00113          case 'manager/createReviewForm':
00114             $fields[] = 'description';
00115             break;
00116          case 'manager/editReviewFormElement':
00117          case 'manager/createReviewFormElement':
00118          case 'manager/updateReviewFormElement':
00119             $fields[] = 'question';
00120             break;
00121          case 'manager/editTrack':
00122          case 'manager/updateTrack':
00123          case 'manager/createTrack':
00124             $fields[] = 'policy';
00125             break;
00126          case 'manager/setup':
00127          case 'manager/saveSetup':
00128             switch (array_shift(Request::getRequestedArgs())) {
00129                case 1:
00130                   $fields[] = 'description';
00131                   $fields[] = 'contactMailingAddress';
00132                   $fields[] = 'copyrightNotice';
00133                   $fields[] = 'archiveAccessPolicy';
00134                   $fields[] = 'privacyStatement';
00135                   $customAboutItems = $templateMgr->get_template_vars('customAboutItems');
00136                   $count = max(1, isset($customAboutItems[$formLocale])?count($customAboutItems[$formLocale]):0);
00137                   for ($i=0; $i<$count; $i++) {
00138                      $fields[] = "customAboutItems-$i-content";
00139                   }
00140                   break;
00141                case 2:
00142                   $fields[] = 'additionalHomeContent';
00143                   $fields[] = 'readerInformation';
00144                   $fields[] = 'authorInformation';
00145                   $fields[] = 'announcementsIntroduction';
00146 
00147                   break;
00148                case 3:
00149                   $fields[] = 'conferencePageHeader';
00150                   $fields[] = 'conferencePageFooter';
00151                   break;
00152             }
00153             break;
00154          case 'manager/schedConfSetup':
00155          case 'manager/saveSchedConfSetup':
00156             switch (array_shift(Request::getRequestedArgs())) {
00157                case 1:
00158                   $fields[] = 'introduction';
00159                   $fields[] = 'overview';
00160                   $fields[] = 'locationAddress';
00161                   $fields[] = 'contactMailingAddress';
00162                   $fields[] = 'sponsorNote';
00163                   $fields[] = 'contributorNote';
00164                   $count = max(1, count($templateMgr->get_template_vars('sponsors')));
00165                   for ($i=0; $i<$count; $i++) {
00166                      $fields[] = "sponsors-$i-address";
00167                   }
00168                   break;
00169                case 2:
00170                   $fields[] = 'cfpMessage';
00171                   $fields[] = 'authorGuidelines';
00172                   $submissionChecklist = $templateMgr->get_template_vars('submissionChecklist');
00173                   $count = max(1, isset($submissionChecklist[$formLocale])?count($submissionChecklist[$formLocale]):0);
00174                   for ($i=0; $i<$count; $i++) {
00175                      $fields[] = "submissionChecklist-$i";
00176                   }
00177                   break;
00178                case 3:
00179                   $fields[] = 'reviewPolicy';
00180                   $fields[] = 'reviewGuidelines';
00181                   break;
00182             }
00183          case 'manager/program':
00184          case 'manager/saveProgramSettings':
00185             $fields[] = 'program';
00186          case 'manager/accommodation':
00187          case 'manager/saveAccommodationSettings':
00188             $fields[] = 'accommodationDescription';
00189             break;
00190          case 'manager/createBuilding':
00191          case 'manager/editBuilding':
00192          case 'manager/updateBuilding':
00193             $fields[] = 'description';
00194             break;
00195          case 'manager/createRoom':
00196          case 'manager/editRoom':
00197          case 'manager/updateRoom':
00198             $fields[] = 'description';
00199             break;
00200          case 'manager/createSpecialEvent':
00201          case 'manager/editSpecialEvent':
00202          case 'manager/updateSpecialEvent':
00203             $fields[] = 'description';
00204             break;
00205          case 'rtadmin/editContext':
00206          case 'rtadmin/editSearch':
00207          case 'rtadmin/editVersion':
00208          case 'rtadmin/createContext':
00209          case 'rtadmin/createSearch':
00210          case 'rtadmin/createVersion':
00211             $fields[] = 'description';
00212             break;
00213          case 'director/viewDirectorDecisionComments':
00214          case 'director/postDirectorDecisionComment':
00215          case 'director/editComment':
00216          case 'director/saveComment':
00217          case 'trackDirector/viewDirectorDecisionComments':
00218          case 'trackDirector/postDirectorDecisionComment':
00219          case 'trackDirector/editComment':
00220          case 'trackDirector/saveComment':
00221          case 'reviewer/viewPeerReviewComments':
00222          case 'reviewer/postPeerReviewComment':
00223          case 'reviewer/editComment':
00224          case 'reviewer/saveComment':
00225             $fields[] = 'comments';
00226             $fields[] = 'authorComments';
00227             break;
00228          case 'director/viewDirectorDecisionComments':
00229          case 'director/postDirectorDecisionComment':
00230             $fields[] = 'comments';
00231             break;
00232          case 'director/createReviewer':
00233          case 'trackDirector/createReviewer':
00234             $fields[] = 'mailingAddress';
00235             $fields[] = 'biography';
00236             break;
00237          case 'reviewer/viewPeerReviewComments':
00238          case 'reviewer/postPeerReviewComment':
00239             $fields[] = 'presenterComments';
00240             $fields[] = 'comments';
00241             break;
00242          case 'director/submissionNotes':
00243          case 'trackDirector/submissionNotes':
00244             $fields[] = 'note';
00245             break;
00246          case 'author/viewMetadata':
00247          case 'trackDirector/viewMetadata':
00248          case 'director/viewMetadata':
00249          case 'author/saveMetadata':
00250          case 'trackDirector/saveMetadata':
00251          case 'director/saveMetadata':
00252             $count = max(1, count($templateMgr->get_template_vars('authors')));
00253             for ($i=0; $i<$count; $i++) {
00254                $fields[] = "authors-$i-affiliation";
00255                $fields[] = "authors-$i-biography";
00256             }
00257             $fields[] = 'abstract';
00258             $fields[] = 'citations';
00259             break;
00260          case 'trackDirector/editSuppFile':
00261          case 'director/editSuppFile':
00262          case 'trackDirector/saveSuppFile':
00263          case 'director/saveSuppFile':
00264             $fields[] = 'description';
00265             break;
00266          case 'manager/registrationPolicies':
00267             $fields[] = 'registrationMailingAddress';
00268             $fields[] = 'registrationAdditionalInformation';
00269             $fields[] = 'delayedOpenAccessPolicy';
00270             $fields[] = 'authorSelfArchivePolicy';
00271             break;
00272          case 'manager/editRegistrationType':
00273          case 'manager/createRegistrationType':
00274          case 'manager/updateRegistrationType':
00275             $fields[] = 'description';
00276             break;
00277          case 'comment/add':
00278             $fields[] = 'bodyField';
00279             break;
00280 
00281       }
00282       HookRegistry::call('TinyMCEPlugin::getEnableFields', array(&$this, &$fields));
00283       return $fields;
00284    }
00285 
00292    function callback($hookName, $args) {
00293       $templateManager =& $args[0];
00294 
00295       $page = Request::getRequestedPage();
00296       $op = Request::getRequestedOp();
00297       $enableFields = $this->getEnableFields($templateManager, $page, $op);
00298 
00299       if (!empty($enableFields)) {
00300          $baseUrl = $templateManager->get_template_vars('baseUrl');
00301          $additionalHeadData = $templateManager->get_template_vars('additionalHeadData');
00302          $enableFields = join(',', $enableFields);
00303          $allLocales = AppLocale::getAllLocales();
00304          $localeList = array();
00305          foreach ($allLocales as $key => $locale) {
00306             $localeList[] = String::substr($key, 0, 2);
00307          }
00308 
00309          $tinymceScript = '
00310          <script language="javascript" type="text/javascript" src="'.$baseUrl.'/'.TINYMCE_JS_PATH.'/tiny_mce_gzip.js"></script>
00311          <script language="javascript" type="text/javascript">
00312             tinyMCE_GZ.init({
00313                relative_urls : "false",
00314                plugins : "paste,fullscreen,jbimages",
00315                themes : "advanced",
00316                languages : "' . join(',', $localeList) . '",
00317                disk_cache : true
00318             });
00319          </script>
00320          <script language="javascript" type="text/javascript">
00321             tinyMCE.init({
00322                entity_encoding : "raw",
00323                plugins : "paste,fullscreen,jbimages",
00324                mode : "exact",
00325                language : "' . String::substr(AppLocale::getLocale(), 0, 2) . '",
00326                elements : "' . $enableFields . '",
00327                relative_urls : false,
00328                forced_root_block : false,
00329                paste_auto_cleanup_on_paste : true,
00330                apply_source_formatting : false,
00331                theme : "advanced",
00332                theme_advanced_buttons1 : "cut,copy,paste,|,bold,italic,underline,bullist,numlist,|,link,unlink,help,code,fullscreen,jbimages",
00333                theme_advanced_buttons2 : "",
00334                theme_advanced_buttons3 : ""
00335             });
00336          </script>';
00337 
00338          $templateManager->assign('additionalHeadData', $additionalHeadData."\n".$tinymceScript);
00339       }
00340       return false;
00341    }
00342 
00347    function getName() {
00348       return 'TinyMCEPlugin';
00349    }
00350 
00355    function getDisplayName() {
00356       return __('plugins.generic.tinymce.name');
00357    }
00358 
00363    function getDescription() {
00364       if ($this->isMCEInstalled()) return __('plugins.generic.tinymce.description');
00365       return __('plugins.generic.tinymce.descriptionDisabled', array('tinyMcePath' => TINYMCE_INSTALL_PATH));
00366    }
00367 
00372    function isMCEInstalled() {
00373       return file_exists(TINYMCE_JS_PATH . '/tiny_mce.js');
00374    }
00375 
00380    function getEnabled() {
00381       $conference =& Request::getConference();
00382       $conferenceId = $conference?$conference->getId():0;
00383       return $this->getSetting($conferenceId, 0, 'enabled');
00384    }
00385 
00390    function getManagementVerbs() {
00391       $verbs = array();
00392       if ($this->isMCEInstalled()) $verbs[] = array(
00393          ($this->getEnabled()?'disable':'enable'),
00394          __($this->getEnabled()?'manager.plugins.disable':'manager.plugins.enable')
00395       );
00396       return $verbs;
00397    }
00398 
00399    /*
00400     * Execute a management verb on this plugin
00401     * @param $verb string
00402     * @param $args array
00403     * @param $message string Location for the plugin to put a result msg
00404     * @return boolean
00405     */
00406    function manage($verb, $args, &$message) {
00407       $conference =& Request::getConference();
00408       $conferenceId = $conference?$conference->getId():0;
00409       switch ($verb) {
00410          case 'enable':
00411             $this->updateSetting($conferenceId, 0, 'enabled', true);
00412             $message = __('plugins.generic.tinymce.enabled');
00413             break;
00414          case 'disable':
00415             $this->updateSetting($conferenceId, 0, 'enabled', false);
00416             $message = __('plugins.generic.tinymce.disabled');
00417             break;
00418       }
00419       return false;
00420    }
00421 }
00422 
00423 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7