/** * Checks whether the current runtime environment is * compatible with the specified parameters. * @return boolean */ function isCompatible() { // Check PHP version if (!is_null($this->_phpVersionMin) && !checkPhpVersion($this->_phpVersionMin)) { return false; } if (!is_null($this->_phpVersionMax) && version_compare(PHP_VERSION, $this->_phpVersionMax) === 1) { return false; } // Check PHP extensions foreach ($this->_phpExtensions as $requiredExtension) { if (!extension_loaded($requiredExtension)) { return false; } } // Check external programs foreach ($this->_externalPrograms as $requiredProgram) { $externalProgram = Config::getVar('cli', $requiredProgram); if (!file_exists($externalProgram)) { return false; } if (function_exists('is_executable')) { if (!is_executable($filename)) { return false; } } } // Compatibility check was successful return true; }
/** * Display the form * @param $request Request * @param $dispatcher Dispatcher */ function display($request, $dispatcher) { $templateMgr =& TemplateManager::getManager($request); // Add extra style sheets required for ajax components // FIXME: Must be removed after OMP->OJS backporting $templateMgr->addStyleSheet($request->getBaseUrl() . '/styles/ojs.css'); // Add extra java script required for ajax components // FIXME: Must be removed after OMP->OJS backporting $templateMgr->addJavaScript('lib/pkp/js/grid-clickhandler.js'); $templateMgr->addJavaScript('lib/pkp/js/modal.js'); $templateMgr->addJavaScript('lib/pkp/js/lib/jquery/plugins/validate/jquery.validate.min.js'); $templateMgr->addJavaScript('lib/pkp/js/jqueryValidatorI18n.js'); import('classes.mail.MailTemplate'); $mail = new MailTemplate('SUBMISSION_ACK'); if ($mail->isEnabled()) { $templateMgr->assign('submissionAckEnabled', true); } // Citation editor filter configuration // // 1) Check whether PHP5 is available. if (!checkPhpVersion('5.0.0')) { Locale::requireComponents(array(LOCALE_COMPONENT_PKP_SUBMISSION)); $citationEditorError = 'submission.citations.editor.php5Required'; } else { $citationEditorError = null; } $templateMgr->assign('citationEditorError', $citationEditorError); if (!$citationEditorError) { // 2) Add the filter grid URLs $parserFilterGridUrl = $dispatcher->url($request, ROUTE_COMPONENT, null, 'grid.filter.ParserFilterGridHandler', 'fetchGrid'); $templateMgr->assign('parserFilterGridUrl', $parserFilterGridUrl); $lookupFilterGridUrl = $dispatcher->url($request, ROUTE_COMPONENT, null, 'grid.filter.LookupFilterGridHandler', 'fetchGrid'); $templateMgr->assign('lookupFilterGridUrl', $lookupFilterGridUrl); // 3) Create a list of all available citation output filters. $router =& $request->getRouter(); $journal =& $router->getContext($request); import('lib.pkp.classes.metadata.MetadataDescription'); $inputSample = new MetadataDescription('lib.pkp.classes.metadata.nlm.NlmCitationSchema', ASSOC_TYPE_CITATION); $outputSample = 'any string'; $filterDao =& DAORegistry::getDAO('FilterDAO'); $metaCitationOutputFilterObjects =& $filterDao->getCompatibleObjects($inputSample, $outputSample, $journal->getId()); foreach ($metaCitationOutputFilterObjects as $metaCitationOutputFilterObject) { $metaCitationOutputFilters[$metaCitationOutputFilterObject->getId()] = $metaCitationOutputFilterObject->getDisplayName(); } $templateMgr->assign_by_ref('metaCitationOutputFilters', $metaCitationOutputFilters); } $currencyDao =& DAORegistry::getDAO('CurrencyDAO'); $currencies =& $currencyDao->getCurrencies(); $currenciesArray = array(); foreach ($currencies as $currency) { $currenciesArray[$currency->getCodeAlpha()] = $currency->getName() . ' (' . $currency->getCodeAlpha() . ')'; } $templateMgr->assign('currencies', $currenciesArray); $originalSourceCurrencyAlpha = $journal->getSetting('sourceCurrency'); $originalSourceCurrency = $currencyDao->getCurrencyByAlphaCode($originalSourceCurrencyAlpha); $templateMgr->assign('originalSourceCurrency', $originalSourceCurrency->getName() . ' (' . $originalSourceCurrencyAlpha . ')'); $proposalSourceDao =& DAORegistry::getDAO('ProposalSourceDAO'); $templateMgr->assign('countSources', $proposalSourceDao->countSources()); parent::display($request, $dispatcher); }
/** * Check to see whether the tar function exists and appears to be * available for execution from PHP, and various other conditions that * are required for locale downloading to be available. * @return boolean */ function isDownloadAvailable() { // Check to see that proc_open is available if (!function_exists('proc_open')) { return false; } // Check to see that we're using at least PHP 4.3 for // stream_set_blocking. if (!checkPhpVersion('4.3.0')) { return false; } // Check to see that tar can be executed $fds = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')); $pipes = $process = null; @($process = proc_open('tar --version', $fds, $pipes)); if (!is_resource($process)) { return false; } fclose($pipes[0]); // No input necessary stream_get_contents($pipes[1]); // Flush pipes. fflush seems to stream_get_contents($pipes[2]); // behave oddly, so it's avoided fclose($pipes[1]); fclose($pipes[2]); if (proc_close($process) !== 0) { return false; } // Check that we can write to a few locations if (!is_file(LOCALE_REGISTRY_FILE) || !is_writable(LOCALE_REGISTRY_FILE)) { return false; } return true; }
/** * Set the return type * @param $returnType integer */ function setReturnType($returnType) { if ($returnType == XSL_TRANSFORMER_DOCTYPE_DOM) { assert(checkPhpVersion('5.0.0') && extension_loaded('dom')); } $this->_returnType = $returnType; }
/** * Constructor. * Initialize transformer and set parser options. * @return boolean returns false if no XSLT processor could be created */ function XSLTransformer() { $this->externalCommand = Config::getVar('cli', 'xslt_command'); // Determine the appropriate XSLT processor for the system if ($this->externalCommand) { // check the external command to check for %xsl and %xml parameter substitution if (strpos($this->externalCommand, '%xsl') === false) { return false; } if (strpos($this->externalCommand, '%xml') === false) { return false; } $this->processor = 'External'; } elseif (checkPhpVersion('5.0.0') && extension_loaded('xsl') && extension_loaded('dom')) { // PHP5.x with XSL/DOM modules present $this->processor = 'PHP5'; } elseif (checkPhpVersion('4.1.0') && extension_loaded('xslt')) { // PHP4.x with XSLT module present $this->processor = 'PHP4'; } else { // no XSLT support return false; } $this->errors = array(); }
/** * @see Filter::supports() * @param $input mixed * @param $output mixed * @param $fromString boolean true if the filter accepts a string as input. * @param $toString boolean true if the filter produces a string as output. * @return boolean */ function supports(&$input, &$output, $fromString = false, $toString = false) { // Make sure that the filter registry has correctly // checked the environment. assert(checkPhpVersion('5.0.0')); // Check the input if ($fromString) { if (!is_string($input)) { return false; } } else { if (!$this->isNlmCitationDescription($input)) { return false; } // Check that the given publication type is supported by this filter // If no publication type is given then we'll support the description // by default. $publicationType = $input->getStatement('[@publication-type]'); if (!empty($publicationType) && !in_array($publicationType, $this->getSupportedPublicationTypes())) { return false; } } // Check the output if (is_null($output)) { return true; } if ($toString) { return is_string($output); } else { return $this->isNlmCitationDescription($output); } }
/** * Save changes to a conference's settings. * @param $args array * @param $request object */ function updateConference($args, &$request) { $this->validate(); $this->setupTemplate(true); import('admin.form.ConferenceSiteSettingsForm'); if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $settingsForm = new ConferenceSiteSettingsForm($request->getUserVar('conferenceId')); } else { $settingsForm =& new ConferenceSiteSettingsForm($request->getUserVar('conferenceId')); } $settingsForm->readInputData(); if ($settingsForm->validate()) { PluginRegistry::loadCategory('blocks'); $settingsForm->execute(); import('notification.NotificationManager'); $notificationManager = new NotificationManager(); $notificationManager->createTrivialNotification('notification.notification', 'common.changesSaved'); $conferenceDao =& DAORegistry::getDAO('ConferenceDAO'); $conference = $conferenceDao->getFreshestConference(); $conferenceId = $conference->getData('id'); $conferencePath = $conference->getData('path'); if ($settingsForm->getData('scheduleConf')) { $request->redirect($conferencePath, null, 'manager', 'createSchedConf'); } else { $request->redirect(null, null, null, 'conferences'); } } else { $settingsForm->display(); } }
/** * Validate user registration information and register new user. */ function registerUser($args, &$request) { $this->validate(); $this->setupTemplate(true); import('classes.user.form.RegistrationForm'); //%CBP% get registration criteria, if defined $journal =& Request::getJournal(); $CBPPlatformDao =& DAORegistry::getDAO('CBPPlatformDAO'); $templateMgr =& TemplateManager::getManager(); $registrationCriteria = $CBPPlatformDao->getRegistrationCriteria($journal->getId()); $templateMgr->assign('registrationCriteria', $registrationCriteria); if ($registrationCriteria != null) { if (Request::getUserVar('registrationCriteria') == 1) { $reason = null; $templateMgr->assign('registrationCriteriaChecked', 1); } else { $reason = 1; $templateMgr->assign('registrationCriteriaReqd', 1); } } if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $regForm = new RegistrationForm(); } else { $regForm =& new RegistrationForm(); } $regForm->readInputData(); if ($regForm->validate()) { $regForm->execute(); if (Config::getVar('email', 'require_validation')) { // Send them home; they need to deal with the // registration email. Request::redirect(null, 'index'); } $reason = null; if (Config::getVar('security', 'implicit_auth')) { Validation::login('', '', $reason); } else { Validation::login($regForm->getData('username'), $regForm->getData('password'), $reason); } if ($reason !== null) { $this->setupTemplate(true); $templateMgr =& TemplateManager::getManager(); $templateMgr->assign('pageTitle', 'user.login'); $templateMgr->assign('errorMsg', $reason == '' ? 'user.login.accountDisabled' : 'user.login.accountDisabledWithReason'); $templateMgr->assign('errorParams', array('reason' => $reason)); $templateMgr->assign('backLink', Request::url(null, 'login')); $templateMgr->assign('backLinkLabel', 'user.login'); return $templateMgr->display('common/error.tpl'); } if ($source = Request::getUserVar('source')) { Request::redirectUrl($source); } else { Request::redirect(null, 'login'); } } else { $regForm->display(); } }
function getPhpVersion() { $message = null; if (!checkPhpVersion(PHP_NEEDED_MAJOR, PHP_NEEDED_MINOR, PHP_NEEDED_BUILD)) { $message = "<span class=\"lz_index_error_cat\">PHP-Version:<br></span> <span class=\"lz_index_red\">" . str_replace("<!--version-->", PHP_NEEDED_MAJOR . "." . PHP_NEEDED_MINOR . "." . PHP_NEEDED_BUILD, "LiveZilla requires PHP <!--version--> or greater.<br>Installed version is " . @phpversion()) . ".</span>"; } return $message; }
/** * Set the return type * @param $returnType integer */ function setReturnType($returnType) { if ($returnType == XSL_TRANSFORMER_DOCTYPE_DOM) { if (!checkPhpVersion('5.0.0') || !extension_loaded('dom')) { fatalError('This system does not meet minimum requirements!'); } } $this->_returnType = $returnType; }
function getPhpVersion() { global $LZLANG; $message = null; if (!checkPhpVersion(PHP_NEEDED_MAJOR, PHP_NEEDED_MINOR, PHP_NEEDED_BUILD)) { $message = "<span class=\"lz_index_error_cat\">PHP-Version:<br></span> <span class=\"lz_index_red\">" . str_replace("<!--version-->", PHP_NEEDED_MAJOR . "." . PHP_NEEDED_MINOR . "." . PHP_NEEDED_BUILD, $LZLANG["index_phpversion_needed"]) . "</span>"; } return $message; }
/** * Constructor */ function ZendSearchSettingsForm() { $plugin =& PluginRegistry::getPlugin('generic', 'ZendSearchPlugin'); parent::Form($plugin->getTemplatePath() . 'zendSearchSettingsForm.tpl'); $this->addCheck(new FormValidatorPost($this)); if (!checkPhpVersion('5.0.0') && $this->readUserVars(array('solrUrl')) == '') { $this->addCheck(new FormValidator($this, 'solrUrl', 'required', 'plugins.generic.zendSearch.solrMustExist')); } $this->addCheck(new FormValidatorUrl($this, 'solrUrl', 'optional', 'plugins.generic.zendSearch.solrUrl.invalid')); }
/** * Validate user registration information and register new user. * @param $args array * @param $request PKPRequest */ function registerUser($args, &$request) { $this->validate($request); $this->setupTemplate($request, true); import('classes.user.form.RegistrationForm'); if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $regForm = new RegistrationForm(); } else { $regForm =& new RegistrationForm(); } $regForm->readInputData(); if ($regForm->validate()) { $regForm->execute(); $reason = null; if (Config::getVar('security', 'implicit_auth')) { Validation::login('', '', $reason); } else { Validation::login($regForm->getData('username'), $regForm->getData('password'), $reason); } if (!Validation::isLoggedIn()) { if (Config::getVar('email', 'require_validation')) { // Inform the user that they need to deal with the // registration email. $this->setupTemplate($request, true); $templateMgr =& TemplateManager::getManager(); $templateMgr->assign('pageTitle', 'user.register.emailValidation'); $templateMgr->assign('errorMsg', 'user.register.emailValidationDescription'); $templateMgr->assign('backLink', $request->url(null, 'login')); $templateMgr->assign('backLinkLabel', 'user.login'); return $templateMgr->display('common/error.tpl'); } } if ($reason !== null) { $this->setupTemplate($request, true); $templateMgr =& TemplateManager::getManager(); $templateMgr->assign('pageTitle', 'user.login'); $templateMgr->assign('errorMsg', $reason == '' ? 'user.login.accountDisabled' : 'user.login.accountDisabledWithReason'); $templateMgr->assign('errorParams', array('reason' => $reason)); $templateMgr->assign('backLink', $request->url(null, 'login')); $templateMgr->assign('backLinkLabel', 'user.login'); return $templateMgr->display('common/error.tpl'); } if ($source = $request->getUserVar('source')) { $request->redirectUrl($source); } else { $request->redirect(null, 'login'); } } else { $regForm->display(); } }
/** * Transcode a string * @param $string string String to transcode * @return string Result of transcoding */ function trans($string) { // detect existence of encoding conversion libraries $mbstring = function_exists('mb_convert_encoding'); $iconv = function_exists('iconv'); // don't do work unless we have to if (strtolower($this->fromEncoding) == strtolower($this->toEncoding)) { return $string; } // 'HTML-ENTITIES' is not a valid encoding for iconv, so transcode manually if ($this->toEncoding == 'HTML-ENTITIES' && !$mbstring) { // NB: old PHP versions may have issues with htmlentities() if (checkPhpVersion('5.2.3')) { // don't double encode added in PHP 5.2.3 return htmlentities($string, ENT_COMPAT, $this->fromEncoding, false); } else { return htmlentities($string, ENT_COMPAT, $this->fromEncoding); } } elseif ($this->fromEncoding == 'HTML-ENTITIES' && !$mbstring) { // NB: old PHP versions may have issues with html_entity_decode() if (checkPhpVersion('4.3.0')) { // multibyte character handling added in PHP 5.0.0 return html_entity_decode($string, ENT_COMPAT, $this->toEncoding); } else { // use built-in transcoding to UTF8 $string = String::html2utf($string); // make another pass to target encoding $this->fromEncoding = 'UTF-8'; return $this->trans($string); } // Special cases for transliteration ("down-sampling") } elseif ($this->translit && $iconv) { // use the iconv library to transliterate return iconv($this->fromEncoding, $this->toEncoding . '//TRANSLIT', $string); } elseif ($this->translit && $this->fromEncoding == "UTF-8" && $this->toEncoding == "ASCII") { // use the utf2ascii library require_once './lib/pkp/lib/phputf8/utf8_to_ascii.php'; return utf8_to_ascii($string); } elseif ($mbstring) { // use the mbstring library to transcode return mb_convert_encoding($string, $this->toEncoding, $this->fromEncoding); } elseif ($iconv) { // use the iconv library to transcode return iconv($this->fromEncoding, $this->toEncoding . '//IGNORE', $string); } else { // fail gracefully by returning the original string unchanged return $string; } }
/** * Read installation parameters from stdin. * FIXME: May want to implement an abstract "CLIForm" class handling input/validation. * FIXME: Use readline if available? */ function readParams() { if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $installForm = new InstallForm(); } else { $installForm =& new InstallForm(); } // Locale Settings $this->printTitle('installer.localeSettings'); $this->readParamOptions('locale', 'locale.primary', $installForm->supportedLocales, 'en_US'); $this->readParamOptions('additionalLocales', 'installer.additionalLocales', $installForm->supportedLocales, '', true); $this->readParamOptions('clientCharset', 'installer.clientCharset', $installForm->supportedClientCharsets, 'utf-8'); $this->readParamOptions('connectionCharset', 'installer.connectionCharset', $installForm->supportedConnectionCharsets, ''); $this->readParamOptions('databaseCharset', 'installer.databaseCharset', $installForm->supportedDatabaseCharsets, ''); // File Settings $this->printTitle('installer.fileSettings'); $this->readParam('filesDir', 'installer.filesDir'); $this->readParamBoolean('skipFilesDir', 'installer.skipFilesDir'); // Security Settings $this->printTitle('installer.securitySettings'); $this->readParamOptions('encryption', 'installer.encryption', $installForm->supportedEncryptionAlgorithms, 'md5'); // Administrator Account $this->printTitle('installer.administratorAccount'); $this->readParam('adminUsername', 'user.username'); @`/bin/stty -echo`; do { $this->readParam('adminPassword', 'user.password'); printf("\n"); $this->readParam('adminPassword2', 'user.register.repeatPassword'); printf("\n"); } while ($this->params['adminPassword'] != $this->params['adminPassword2']); @`/bin/stty echo`; $this->readParam('adminEmail', 'user.email'); // Database Settings $this->printTitle('installer.databaseSettings'); $this->readParamOptions('databaseDriver', 'installer.databaseDriver', $installForm->checkDBDrivers()); $this->readParam('databaseHost', 'installer.databaseHost', ''); $this->readParam('databaseUsername', 'installer.databaseUsername', ''); $this->readParam('databasePassword', 'installer.databasePassword', ''); $this->readParam('databaseName', 'installer.databaseName'); $this->readParamBoolean('createDatabase', 'installer.createDatabase', 'Y'); // Miscellaneous Settings $this->printTitle('installer.miscSettings'); $this->readParam('oaiRepositoryId', 'installer.oaiRepositoryId'); printf("\n*** "); }
/** * Execute installer. */ function install() { $this->validate(); $this->setupTemplate(); if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $installForm = new InstallForm(); } else { $installForm =& new InstallForm(); } $installForm->readInputData(); if ($installForm->validate()) { $installForm->execute(); } else { $installForm->display(); } }
/** * Display the form * @param $request Request * @param $dispatcher Dispatcher */ function display($request, $dispatcher) { $templateMgr =& TemplateManager::getManager($request); // Add extra style sheets required for ajax components // FIXME: Must be removed after OMP->OJS backporting $templateMgr->addStyleSheet($request->getBaseUrl() . '/styles/ojs.css'); // Add extra java script required for ajax components // FIXME: Must be removed after OMP->OJS backporting $templateMgr->addJavaScript('lib/pkp/js/functions/grid-clickhandler.js'); $templateMgr->addJavaScript('lib/pkp/js/functions/modal.js'); $templateMgr->addJavaScript('lib/pkp/js/lib/jquery/plugins/validate/jquery.validate.min.js'); $templateMgr->addJavaScript('lib/pkp/js/functions/jqueryValidatorI18n.js'); import('classes.mail.MailTemplate'); $mail = new MailTemplate('SUBMISSION_ACK'); if ($mail->isEnabled()) { $templateMgr->assign('submissionAckEnabled', true); } // Citation editor filter configuration // // 1) Check whether PHP5 is available. if (!checkPhpVersion('5.0.0')) { Locale::requireComponents(array(LOCALE_COMPONENT_PKP_SUBMISSION)); $citationEditorError = 'submission.citations.editor.php5Required'; } else { $citationEditorError = null; } $templateMgr->assign('citationEditorError', $citationEditorError); if (!$citationEditorError) { // 2) Add the filter grid URLs $parserFilterGridUrl = $dispatcher->url($request, ROUTE_COMPONENT, null, 'grid.filter.ParserFilterGridHandler', 'fetchGrid'); $templateMgr->assign('parserFilterGridUrl', $parserFilterGridUrl); $lookupFilterGridUrl = $dispatcher->url($request, ROUTE_COMPONENT, null, 'grid.filter.LookupFilterGridHandler', 'fetchGrid'); $templateMgr->assign('lookupFilterGridUrl', $lookupFilterGridUrl); // 3) Create a list of all available citation output filters. $router =& $request->getRouter(); $journal =& $router->getContext($request); $filterDao =& DAORegistry::getDAO('FilterDAO'); /* @var $filterDao FilterDAO */ $metaCitationOutputFilterObjects =& $filterDao->getObjectsByGroup('nlm30-element-citation=>plaintext', $journal->getId()); foreach ($metaCitationOutputFilterObjects as $metaCitationOutputFilterObject) { $metaCitationOutputFilters[$metaCitationOutputFilterObject->getId()] = $metaCitationOutputFilterObject->getDisplayName(); } $templateMgr->assign_by_ref('metaCitationOutputFilters', $metaCitationOutputFilters); } parent::display($request, $dispatcher); }
/** * Register as a block plugin, even though this is a generic plugin. * This will allow the plugin to behave as a block plugin, i.e. to * have layout tasks performed on it. * @param $hookName string * @param $args array */ function callbackLoadCategory($hookName, $args) { $category =& $args[0]; $plugins =& $args[1]; switch ($category) { case 'importexport': // This plugin is only available on PHP5.x. if (!checkPhpVersion('5.0.0')) { break; } $this->import('SwordImportExportPlugin'); $importExportPlugin = new SwordImportExportPlugin($this->getName()); $plugins[$importExportPlugin->getSeq()][$importExportPlugin->getPluginPath()] =& $importExportPlugin; break; } return false; }
/** * Register the plugin, attaching to hooks as necessary. * @param $category string * @param $path string * @return boolean */ function register($category, $path) { if (parent::register($category, $path)) { if ($this->getEnabled()) { $this->import('BlogPagesDAO'); if (checkPhpVersion('5.0.0')) { // WARNING: see http://pkp.sfu.ca/wiki/index.php/Information_for_Developers#Use_of_.24this_in_the_constructor $blogPagesDao = new BlogPagesDAO($this->getName()); } else { $blogPagesDao =& new BlogPagesDAO($this->getName()); } $returner =& DAORegistry::registerDAO('BlogPagesDAO', $blogPagesDao); HookRegistry::register('LoadHandler', array(&$this, 'callbackHandleContent')); } return true; } return false; }
/** * Save changes to a conference's settings. */ function updateConference() { $this->validate(); $this->setupTemplate(true); import('admin.form.ConferenceSiteSettingsForm'); if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $settingsForm = new ConferenceSiteSettingsForm(Request::getUserVar('conferenceId')); } else { $settingsForm =& new ConferenceSiteSettingsForm(Request::getUserVar('conferenceId')); } $settingsForm->readInputData(); if ($settingsForm->validate()) { PluginRegistry::loadCategory('blocks'); $settingsForm->execute(); Request::redirect(null, null, null, 'conferences'); } else { $settingsForm->display(); } }
/** * Sanitize a variable. * Removes leading and trailing whitespace, normalizes all characters to UTF-8. * @param $var string * @return string */ static function cleanVar($var) { // only normalize strings that are not UTF-8 already, and when the system is using UTF-8 if (Config::getVar('i18n', 'charset_normalization') == 'On' && strtolower_codesafe(Config::getVar('i18n', 'client_charset')) == 'utf-8' && !String::utf8_is_valid($var)) { $var = String::utf8_normalize($var); // convert HTML entities into valid UTF-8 characters (do not transcode) $var = html_entity_decode($var, ENT_COMPAT, 'UTF-8'); // strip any invalid UTF-8 sequences $var = String::utf8_bad_strip($var); // re-encode special HTML characters if (checkPhpVersion('5.2.3')) { $var = htmlspecialchars($var, ENT_NOQUOTES, 'UTF-8', false); } else { $var = htmlspecialchars($var, ENT_NOQUOTES, 'UTF-8'); } } // strip any invalid ASCII control characters $var = String::utf8_strip_ascii_ctrl($var); return trim($var); }
function updateTimeline($args) { $this->validate(); $this->setupTemplate(true); import('manager.form.TimelineForm'); if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $timelineForm = new TimelineForm(Request::getUserVar('overrideDates')); } else { $timelineForm =& new TimelineForm(Request::getUserVar('overrideDates')); } $timelineForm->readInputData(); if ($timelineForm->validate()) { $timelineForm->execute(); Request::redirect(null, null, null, 'index'); } else { $timelineForm->setData('errorsExist', true); $timelineForm->display(); } }
/** * Validate user registration information and register new user. */ function registerUser() { $this->validate(); import('classes.user.form.RegistrationForm'); if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $regForm = new RegistrationForm(); } else { $regForm =& new RegistrationForm(); } $regForm->readInputData(); if ($regForm->validate()) { $regForm->execute(); if (Config::getVar('email', 'require_validation')) { // Send them home; they need to deal with the // registration email. Request::redirect(null, 'index'); } $reason = null; Validation::login($regForm->getData('username'), $regForm->getData('password'), $reason); if ($reason !== null) { $this->setupTemplate(true); $templateMgr =& TemplateManager::getManager(); $templateMgr->assign('pageTitle', 'user.login'); $templateMgr->assign('errorMsg', $reason == '' ? 'user.login.accountDisabled' : 'user.login.accountDisabledWithReason'); $templateMgr->assign('errorParams', array('reason' => $reason)); $templateMgr->assign('backLink', Request::url('login')); $templateMgr->assign('backLinkLabel', 'user.login'); return $templateMgr->display('common/error.tpl'); } if ($source = Request::getUserVar('source')) { Request::redirectUrl($source); } else { Request::redirect('login'); } } else { $this->setupTemplate(true); $regForm->display(); } }
/** * Save changes to a journal's settings. * @param $args array * @param $request object */ function updateJournal($args, &$request) { $this->validate(); $this->setupTemplate(); import('classes.admin.form.JournalSiteSettingsForm'); if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $settingsForm = new JournalSiteSettingsForm($request->getUserVar('journalId')); } else { $settingsForm =& new JournalSiteSettingsForm($request->getUserVar('journalId')); } $settingsForm->readInputData(); if ($settingsForm->validate()) { PluginRegistry::loadCategory('blocks'); $settingsForm->execute(); import('lib.pkp.classes.notification.NotificationManager'); $notificationManager = new NotificationManager(); $notificationManager->createTrivialNotification('notification.notification', 'common.changesSaved'); $request->redirect(null, null, 'journals'); } else { $settingsForm->display(); } }
/** * Handle submission of the user registration form */ function register() { $this->addCheck(new HandlerValidatorSchedConf($this)); $this->validate(); $conference =& Request::getConference(); $schedConf =& Request::getSchedConf(); $paymentManager =& OCSPaymentManager::getManager(); if (!$paymentManager->isConfigured()) { Request::redirect(null, null, 'index'); } $user =& Request::getUser(); $registrationDao =& DAORegistry::getDAO('RegistrationDAO'); if ($user && ($registrationId = $registrationDao->getRegistrationIdByUser($user->getId(), $schedConf->getId()))) { // This user has already registered. $registration =& $registrationDao->getRegistration($registrationId); $this->_updateRegistration($registrationDao, $registration); // $isUpdate = Request::getUserVar("update"); if (!$registration || $registration->getDatePaid()) { // And they have already paid. Redirect to a message explaining. // $notifyEmail = Request::getUserVar("notifyEmail"); // // if ($notifyEmail) { // echo "有!"; // exit; // //$this->notifyEmail($registration->getTypeId()); // } // else { // echo '沒有!!'; // exit; // } Request::redirect(null, null, null, 'registration'); } else { // Allow them to resubmit the form to change type or pay again. $registrationDao->deleteRegistrationById($registrationId); } } $templateMgr =& TemplateManager::getManager(); $templateMgr->assign('pageHierarchy', array(array(Request::url(null, 'index', 'index'), $conference->getConferenceTitle(), true), array(Request::url(null, null, 'index'), $schedConf->getSchedConfTitle(), true))); SchedConfHandler::setupTemplate($conference, $schedConf); import('registration.form.UserRegistrationForm'); $typeId = (int) Request::getUserVar('registrationTypeId'); if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $form = new UserRegistrationForm($typeId); } else { $form =& new UserRegistrationForm($typeId); } $form->readInputData(); if ($form->validate()) { if (($registrationError = $form->execute()) != REGISTRATION_SUCCESSFUL) { $templateMgr->assign('isUserLoggedIn', Validation::isLoggedIn()); // In case a user was just created, make sure they appear logged in if ($registrationError == REGISTRATION_FAILED) { // User not created $templateMgr->assign('message', 'schedConf.registration.failed'); $templateMgr->assign('backLinkLabel', 'common.back'); $templateMgr->assign('backLink', Request::url(null, null, 'index')); $templateMgr->display('common/message.tpl'); } elseif ($registrationError == REGISTRATION_NO_PAYMENT) { // Automatic payment failed; display a generic // "you will be contacted" message. $templateMgr->assign('message', 'schedConf.registration.noPaymentMethodAvailable'); $templateMgr->assign('backLinkLabel', 'common.back'); $templateMgr->assign('backLink', Request::url(null, null, 'index')); $templateMgr->display('common/message.tpl'); } elseif ($registrationError == REGISTRATION_FREE) { // Registration successful; no payment required (free) $templateMgr->assign('message', 'schedConf.registration.free'); $templateMgr->assign('backLinkLabel', 'common.back'); $templateMgr->assign('backLink', Request::url(null, null, 'index')); //$templateMgr->display('common/message.tpl'); //$registration =& $registrationDao->getRegistration($registrationId); //$this->_registrationDisplay($registration); //$this->_updateRegistration($registrationDao, $registration); $notifyEmail = Request::getUserVar("notifyEmail"); $registrationTypeId = (int) Request::getUserVar("registrationTypeId"); if ($notifyEmail) { $this->notifyEmail($registrationTypeId); } Request::redirect(null, null, null, 'registration'); return; } } // Otherwise, payment is handled for us. } else { $templateMgr->assign('isUserLoggedIn', Validation::isLoggedIn()); // In case a user was just created, make sure they appear logged in $form->display(); } }
/** * Save changes to a user profile. */ function updateUser() { $this->validate(); $this->setupTemplate(true); $conference =& Request::getConference(); $userId = Request::getUserVar('userId'); if (!empty($userId) && !Validation::canAdminister($conference->getId(), $userId)) { // We don't have administrative rights // over this user. Display an error. $templateMgr =& TemplateManager::getManager(); $templateMgr->assign('pageTitle', 'manager.people'); $templateMgr->assign('errorMsg', 'manager.people.noAdministrativeRights'); $templateMgr->assign('backLink', Request::url(null, null, null, 'people', 'all')); $templateMgr->assign('backLinkLabel', 'manager.people.allUsers'); return $templateMgr->display('common/error.tpl'); } import('classes.manager.form.UserManagementForm'); if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $userForm = new UserManagementForm($userId); } else { $userForm =& new UserManagementForm($userId); } $userForm->readInputData(); if ($userForm->validate()) { $userForm->execute(); if (Request::getUserVar('createAnother')) { $templateMgr =& TemplateManager::getManager(); $templateMgr->assign('currentUrl', Request::url(null, null, null, 'people', 'all')); $templateMgr->assign('userCreated', true); unset($userForm); if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $userForm = new UserManagementForm(); } else { $userForm =& new UserManagementForm(); } $userForm->initData(); $userForm->display(); } else { if ($source = Request::getUserVar('source')) { Request::redirectUrl($source); } else { Request::redirect(null, null, null, 'people', 'all'); } } } else { $userForm->display(); } }
/** * Save user's new password. * @param $args array * @param $request PKPRequest */ function savePassword($args, &$request) { $this->validate(); import('classes.user.form.ChangePasswordForm'); if (checkPhpVersion('5.0.0')) { // WARNING: This form needs $this in constructor $passwordForm = new ChangePasswordForm(); } else { $passwordForm =& new ChangePasswordForm(); } $passwordForm->readInputData(); $this->setupTemplate($request, true); if ($passwordForm->validate()) { $passwordForm->execute(); $request->redirect(null, $request->getRequestedPage()); } else { $passwordForm->display(); } }
/** * Send email to a journal's book for review authors */ function sendJournalReminders($journal, $curDate) { // FIXME: This shouldn't be hard-coded here $bfrPlugin =& PluginRegistry::getPlugin('generic', 'booksforreviewplugin'); if ($bfrPlugin) { $bfrPluginName = $bfrPlugin->getName(); $bfrPlugin->import('classes.BookForReviewDAO'); $bfrPlugin->import('classes.BookForReviewAuthorDAO'); // PHP4 Requires explicit instantiation-by-reference // FIXME: Plugin name hard-coded. if (checkPhpVersion('5.0.0')) { $bfrAuthorDao = new BookForReviewAuthorDAO('booksforreviewplugin'); } else { $bfrAuthorDao =& new BookForReviewAuthorDAO('booksforreviewplugin'); } $returner =& DAORegistry::registerDAO('BookForReviewAuthorDAO', $bfrAuthorDao); // PHP4 Requires explicit instantiation-by-reference // FIXME: Plugin name hard-coded. if (checkPhpVersion('5.0.0')) { $bfrDao = new BookForReviewDAO('booksforreviewplugin'); } else { $bfrDao =& new BookForReviewDAO('booksforreviewplugin'); } $returner =& DAORegistry::registerDAO('BookForReviewDAO', $bfrDao); $journalId = $journal->getId(); $pluginSettingsDao =& DAORegistry::getDAO('PluginSettingsDAO'); $booksForReviewEnabled = $pluginSettingsDao->getSetting($journalId, $bfrPluginName, 'enabled'); } if ($booksForReviewEnabled) { $curYear = $curDate['year']; $curMonth = $curDate['month']; $curDay = $curDate['day']; // Check if before review due reminders are enabled if ($pluginSettingsDao->getSetting($journalId, $bfrPluginName, 'enableDueReminderBefore')) { $beforeDays = $pluginSettingsDao->getSetting($journalId, $bfrPluginName, 'numDaysBeforeDueReminder'); $dueMonth = $curMonth + (int) floor(($curDay + $beforeDays) / 31); $dueYear = $curYear + (int) floor($dueMonth / 12); $dueDay = (int) fmod($curDay + $beforeDays, 31); $dueDate = $dueYear . '-' . $dueMonth . '-' . $dueDay; // Retrieve all books for review that match due date $books =& $bfrDao->getBooksForReviewByDateDue($journalId, $dueDate); while (!$books->eof()) { $bookForReview =& $books->next(); $this->sendReminder($bookForReview, $journal, 'BFR_REVIEW_REMINDER'); } } // Check if after/late review due reminders are enabled if ($pluginSettingsDao->getSetting($journalId, $bfrPluginName, 'enableDueReminderAfter')) { $afterDays = $pluginSettingsDao->getSetting($journalId, $bfrPluginName, 'numDaysAfterDueReminder'); if ($curDay - $afterDays <= 0) { $afterMonths = 1; $dueDay = 31 + ($curDay - $afterDays); } else { $afterMonths = 0; $dueDay = $curDay - $afterDays; } if ($curMonth - $afterMonths == 0) { $afterYears = 1; $dueMonth = 12; } else { $afterYears = 0; $dueMonth = $curMonth - $afterMonths; } $dueYear = $curYear - $afterYears; $dueDate = $dueYear . '-' . $dueMonth . '-' . $dueDay; // Retrieve all books for review that match due date $books =& $bfrDao->getBooksForReviewByDateDue($journalId, $dueDate); while (!$books->eof()) { $bookForReview =& $books->next(); $this->sendReminder($bookForReview, $journal, 'BFR_REVIEW_REMINDER_LATE'); } } } }
/** * Update book for review settings. */ function booksForReviewSettings($args = array(), &$request) { $this->setupTemplate(true); $journal =& $request->getJournal(); $journalId = $journal->getId(); $bfrPlugin =& PluginRegistry::getPlugin('generic', BOOKS_FOR_REVIEW_PLUGIN_NAME); $bfrPlugin->import('classes.form.BooksForReviewSettingsForm'); $templateMgr =& TemplateManager::getManager(); // PHP4 Requires explicit instantiation-by-reference if (checkPhpVersion('5.0.0')) { $form = new BooksForReviewSettingsForm($bfrPlugin, $journalId); } else { $form =& new BooksForReviewSettingsForm($bfrPlugin, $journalId); } if (Config::getVar('general', 'scheduled_tasks')) { $templateMgr->assign('scheduledTasksEnabled', true); } $bfrDao =& DAORegistry::getDAO('BookForReviewDAO'); $templateMgr->assign_by_ref('counts', $bfrDao->getStatusCounts($journalId)); if ($request->getUserVar('save')) { $form->readInputData(); if ($form->validate()) { $form->execute(); $user =& $request->getUser(); import('classes.notification.NotificationManager'); $notificationManager = new NotificationManager(); $notificationManager->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_BOOK_SETTINGS_SAVED); $request->redirect(null, 'editor', 'booksForReviewSettings'); } else { $form->display(); } } else { $form->initData(); $form->display(); } }
/** * Called as a plugin is registered to the registry * @param $category String Name of category plugin was registered to * @return boolean True iff plugin initialized successfully; if false, * the plugin will not be registered. */ function register($category, $path) { $success = parent::register($category, $path); $this->addLocaleData(); if ($success && $this->getEnabled()) { $this->import('classes.BookForReviewDAO'); $this->import('classes.BookForReviewAuthorDAO'); // PHP4 Requires explicit instantiation-by-reference if (checkPhpVersion('5.0.0')) { $bfrAuthorDao = new BookForReviewAuthorDAO($this->getName()); } else { $bfrAuthorDao =& new BookForReviewAuthorDAO($this->getName()); } $returner =& DAORegistry::registerDAO('BookForReviewAuthorDAO', $bfrAuthorDao); // PHP4 Requires explicit instantiation-by-reference if (checkPhpVersion('5.0.0')) { $bfrDao = new BookForReviewDAO($this->getName()); } else { $bfrDao =& new BookForReviewDAO($this->getName()); } $returner =& DAORegistry::registerDAO('BookForReviewDAO', $bfrDao); $journal =& Request::getJournal(); if ($journal) { $mode = $this->getSetting($journal->getId(), 'mode'); $coverPageIssue = $this->getSetting($journal->getId(), 'coverPageIssue'); $coverPageAbstract = $this->getSetting($journal->getId(), 'coverPageAbstract'); } // Handler for editor books for review pages HookRegistry::register('LoadHandler', array($this, 'setupEditorHandler')); // Editor link to books for review pages HookRegistry::register('Templates::Editor::Index::AdditionalItems', array($this, 'displayEditorHomeLink')); // Editor link to book for review metadata in submission view HookRegistry::register('Templates::Submission::Metadata::Metadata::AdditionalEditItems', array($this, 'displayEditorMetadataLink')); // Append book metadata to book review article HookRegistry::register('Templates::Article::Header::Metadata', array($this, 'displayBookMetadata')); // Enable TinyMCE for book for review text fields HookRegistry::register('TinyMCEPlugin::getEnableFields', array($this, 'enableTinyMCE')); // Ensure book for review user assignments are transferred when merging users HookRegistry::register('UserAction::mergeUsers', array($this, 'mergeBooksForReviewAuthors')); // If using book for review cover page as article cover page // then include cover page handlers for issue toc and article abstract views if ($coverPageIssue) { HookRegistry::register('Templates::Issue::Issue::ArticleCoverImage', array($this, 'displayArticleCoverPageIssue')); } if ($coverPageAbstract) { HookRegistry::register('Templates::Article::Article::ArticleCoverImage', array($this, 'displayArticleCoverPageAbstract')); } // If publishing books available for review and managing book reviewers // then include additional links, pages, and handlers if ($mode == BFR_MODE_FULL) { // Handler for public books for review pages HookRegistry::register('LoadHandler', array($this, 'setupPublicHandler')); // Navigation bar link to books for review page HookRegistry::register('Templates::Common::Header::Navbar::CurrentJournal', array($this, 'displayHeaderLink')); // Handler for author books for review pages HookRegistry::register('LoadHandler', array($this, 'setupAuthorHandler')); // Display author's books for review during submission HookRegistry::register('Author::SubmitHandler::saveSubmit', array($this, 'saveSubmitHandler')); HookRegistry::register('Templates::Author::Submit::Step5::AdditionalItems', array($this, 'displayAuthorBooksForReview')); // Author link to books for review pages HookRegistry::register('Templates::Author::Index::AdditionalItems', array($this, 'displayAuthorHomeLink')); } } return $success; }