本文整理汇总了PHP中PKPString类的典型用法代码示例。如果您正苦于以下问题:PHP PKPString类的具体用法?PHP PKPString怎么用?PHP PKPString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PKPString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display user login form.
* Redirect to user index page if user is already validated.
*/
function index($args, $request)
{
$this->setupTemplate($request);
if (Validation::isLoggedIn()) {
$this->sendHome($request);
}
if (Config::getVar('security', 'force_login_ssl') && $request->getProtocol() != 'https') {
// Force SSL connections for login
$request->redirectSSL();
}
$sessionManager = SessionManager::getManager();
$session = $sessionManager->getUserSession();
$templateMgr = TemplateManager::getManager($request);
// If the user wasn't expecting a login page, i.e. if they're new to the
// site and want to submit a paper, it helps to explain why they need to
// register.
if ($request->getUserVar('loginMessage')) {
$templateMgr->assign('loginMessage', $request->getUserVar('loginMessage'));
}
$templateMgr->assign('username', $session->getSessionVar('username'));
$templateMgr->assign('remember', $request->getUserVar('remember'));
$templateMgr->assign('source', $request->getUserVar('source'));
$templateMgr->assign('showRemember', Config::getVar('general', 'session_lifetime') > 0);
// For force_login_ssl with base_url[...]: make sure SSL used for login form
$loginUrl = $this->_getLoginUrl($request);
if (Config::getVar('security', 'force_login_ssl')) {
$loginUrl = PKPString::regexp_replace('/^http:/', 'https:', $loginUrl);
}
$templateMgr->assign('loginUrl', $loginUrl);
$templateMgr->display('frontend/pages/userLogin.tpl');
}
示例2: generateFileName
/**
* Generate a filename for a library file.
* @param $type int LIBRARY_FILE_TYPE_...
* @param $originalFileName string
* @return string
*/
function generateFileName($type, $originalFileName)
{
$libraryFileDao = DAORegistry::getDAO('LibraryFileDAO');
$suffix = $this->getFileSuffixFromType($type);
$ext = $this->getExtension($originalFileName);
$truncated = $this->truncateFileName($originalFileName, 127 - PKPString::strlen($suffix) - 1);
$baseName = PKPString::substr($truncated, 0, PKPString::strpos($originalFileName, $ext) - 1);
// Try a simple syntax first
$fileName = $baseName . '-' . $suffix . '.' . $ext;
if (!$libraryFileDao->filenameExists($this->contextId, $fileName)) {
return $fileName;
}
for ($i = 1;; $i++) {
$fullSuffix = $suffix . '-' . $i;
//truncate more if necessary
$truncated = $this->truncateFileName($originalFileName, 127 - PKPString::strlen($fullSuffix) - 1);
// get the base name and append the suffix
$baseName = PKPString::substr($truncated, 0, PKPString::strpos($originalFileName, $ext) - 1);
//try the following
$fileName = $baseName . '-' . $fullSuffix . '.' . $ext;
if (!$libraryFileDao->filenameExists($this->contextId, $fileName)) {
return $fileName;
}
}
}
示例3: formatElement
/**
* Format XML for single DC element.
* @param $propertyName string
* @param $value array
* @param $multilingual boolean optional
*/
function formatElement($propertyName, $values, $multilingual = false)
{
if (!is_array($values)) {
$values = array($values);
}
// Translate the property name to XML syntax.
$openingElement = str_replace(array('[@', ']'), array(' ', ''), $propertyName);
$closingElement = PKPString::regexp_replace('/\\[@.*/', '', $propertyName);
// Create the actual XML entry.
$response = '';
foreach ($values as $key => $value) {
if ($multilingual) {
$key = str_replace('_', '-', $key);
assert(is_array($value));
foreach ($value as $subValue) {
if ($key == METADATA_DESCRIPTION_UNKNOWN_LOCALE) {
$response .= "\t<{$openingElement}>" . OAIUtils::prepOutput($subValue) . "</{$closingElement}>\n";
} else {
$response .= "\t<{$openingElement} xml:lang=\"{$key}\">" . OAIUtils::prepOutput($subValue) . "</{$closingElement}>\n";
}
}
} else {
assert(is_scalar($value));
$response .= "\t<{$openingElement}>" . OAIUtils::prepOutput($value) . "</{$closingElement}>\n";
}
}
return $response;
}
示例4: filterKeywords
/**
* Split a string into a clean array of keywords
* @param $text string
* @param $allowWildcards boolean
* @return array of keywords
*/
static function filterKeywords($text, $allowWildcards = false)
{
$minLength = Config::getVar('search', 'min_word_length');
$stopwords = self::_loadStopwords();
// Join multiple lines into a single string
if (is_array($text)) {
$text = join("\n", $text);
}
$cleanText = Core::cleanVar($text);
// Remove punctuation
$cleanText = PKPString::regexp_replace('/[!"\\#\\$%\'\\(\\)\\.\\?@\\[\\]\\^`\\{\\}~]/', '', $cleanText);
$cleanText = PKPString::regexp_replace('/[\\+,:;&\\/<=>\\|\\\\]/', ' ', $cleanText);
$cleanText = PKPString::regexp_replace('/[\\*]/', $allowWildcards ? '%' : ' ', $cleanText);
$cleanText = PKPString::strtolower($cleanText);
// Split into words
$words = PKPString::regexp_split('/\\s+/', $cleanText);
// FIXME Do not perform further filtering for some fields, e.g., author names?
// Remove stopwords
$keywords = array();
foreach ($words as $k) {
if (!isset($stopwords[$k]) && PKPString::strlen($k) >= $minLength && !is_numeric($k)) {
$keywords[] = PKPString::substr($k, 0, SEARCH_KEYWORD_MAX_LENGTH);
}
}
return $keywords;
}
示例5: parseTypeName
/**
* @see TypeDescription::parseTypeName()
*/
function parseTypeName($typeName)
{
// Standard validators are based on string input.
parent::parseTypeName('string');
// Split the type name into validator name and arguments.
$typeNameParts = explode('(', $typeName, 2);
switch (count($typeNameParts)) {
case 1:
// no argument
$this->_validatorArgs = '';
break;
case 2:
// parse arguments (no UTF8-treatment necessary)
if (substr($typeNameParts[1], -1) != ')') {
return false;
}
// FIXME: Escape for PHP code inclusion?
$this->_validatorArgs = substr($typeNameParts[1], 0, -1);
break;
}
// Validator name must start with a lower case letter
// and may contain only alphanumeric letters.
if (!PKPString::regexp_match('/^[a-z][a-zA-Z0-9]+$/', $typeNameParts[0])) {
return false;
}
// Translate the validator name into a validator class name.
$this->_validatorClassName = 'Validator' . PKPString::ucfirst($typeNameParts[0]);
return true;
}
示例6: array
/**
* @copydoc Filter::process()
* @param $citationString string
* @return MetadataDescription
*/
function &process(&$input)
{
$nullVar = null;
$queryParams = array('demo' => '3', 'textlines' => $input);
// Parscit web form - the result is (mal-formed) HTML
if (is_null($result = $this->callWebService(PARSCIT_WEBSERVICE, $queryParams, XSL_TRANSFORMER_DOCTYPE_STRING, 'POST'))) {
return $nullVar;
}
$result = html_entity_decode($result);
// Detect errors.
if (!PKPString::regexp_match('/.*<algorithm[^>]+>.*<\\/algorithm>.*/s', $result)) {
$translationParams = array('filterName' => $this->getDisplayName());
$this->addError(__('submission.citations.filter.webserviceResultTransformationError', $translationParams));
return $nullVar;
}
// Screen-scrape the tagged portion and turn it into XML.
$xmlResult = PKPString::regexp_replace('/.*<algorithm[^>]+>(.*)<\\/algorithm>.*/s', '\\1', $result);
$xmlResult = PKPString::regexp_replace('/&/', '&', $xmlResult);
// Transform the result into an array of meta-data.
if (is_null($metadata = $this->transformWebServiceResults($xmlResult, dirname(__FILE__) . DIRECTORY_SEPARATOR . 'parscit.xsl'))) {
return $nullVar;
}
// Extract a publisher from the place string if possible.
$metadata =& $this->fixPublisherNameAndLocation($metadata);
return $this->getNlm30CitationDescriptionFromMetadataArray($metadata);
}
开发者ID:PublishingWithoutWalls,项目名称:pkp-lib,代码行数:31,代码来源:ParscitRawCitationNlm30CitationSchemaFilter.inc.php
示例7: display
/**
* @copydoc Form::display
*/
function display($request = null, $template = null)
{
import('lib.pkp.classes.xslt.XSLTransformer');
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign(array('localeOptions' => $this->supportedLocales, 'localesComplete' => $this->localesComplete, 'clientCharsetOptions' => $this->supportedClientCharsets, 'connectionCharsetOptions' => $this->supportedConnectionCharsets, 'databaseCharsetOptions' => $this->supportedDatabaseCharsets, 'allowFileUploads' => get_cfg_var('file_uploads') ? __('common.yes') : __('common.no'), 'maxFileUploadSize' => get_cfg_var('upload_max_filesize'), 'databaseDriverOptions' => $this->checkDBDrivers(), 'supportsMBString' => PKPString::hasMBString() ? __('common.yes') : __('common.no'), 'phpIsSupportedVersion' => version_compare(PHP_REQUIRED_VERSION, PHP_VERSION) != 1, 'xslEnabled' => XSLTransformer::checkSupport(), 'xslRequired' => REQUIRES_XSL, 'phpRequiredVersion' => PHP_REQUIRED_VERSION, 'phpVersion' => PHP_VERSION));
parent::display();
}
示例8: assignParams
/**
* Assign parameters to template
* @param $paramArray array
*/
function assignParams($paramArray = array())
{
$submission = $this->submission;
$application = PKPApplication::getApplication();
$request = $application->getRequest();
parent::assignParams(array_merge(array('submissionTitle' => strip_tags($submission->getLocalizedTitle()), 'submissionId' => $submission->getId(), 'submissionAbstract' => PKPString::html2text($submission->getLocalizedAbstract()), 'authorString' => strip_tags($submission->getAuthorString())), $paramArray));
}
示例9: array
/**
* @copydoc Filter::process()
* @param $isbn string
* @return MetadataDescription a looked up citation description
* or null if the filter fails
*/
function &process($isbn)
{
$nullVar = null;
// Instantiate the web service request
$lookupParams = array('access_key' => $this->getApiKey(), 'index1' => 'isbn', 'results' => 'details,authors', 'value1' => $isbn);
// Call the web service
if (is_null($resultDOM =& $this->callWebService(ISBNDB_WEBSERVICE_URL, $lookupParams))) {
return $nullVar;
}
// Transform and pre-process the web service result
if (is_null($metadata =& $this->transformWebServiceResults($resultDOM, dirname(__FILE__) . DIRECTORY_SEPARATOR . 'isbndb.xsl'))) {
return $nullVar;
}
// Extract place and publisher from the combined entry.
$metadata['publisher-loc'] = PKPString::trimPunctuation(PKPString::regexp_replace('/^(.+):.*/', '\\1', $metadata['place-publisher']));
$metadata['publisher-name'] = PKPString::trimPunctuation(PKPString::regexp_replace('/.*:([^,]+),?.*/', '\\1', $metadata['place-publisher']));
unset($metadata['place-publisher']);
// Reformat the publication date
$metadata['date'] = PKPString::regexp_replace('/^[^\\d{4}]+(\\d{4}).*/', '\\1', $metadata['date']);
// Clean non-numerics from ISBN
$metadata['isbn'] = PKPString::regexp_replace('/[^\\dX]*/', '', $isbn);
// Set the publicationType
$metadata['[@publication-type]'] = NLM30_PUBLICATION_TYPE_BOOK;
return $this->getNlm30CitationDescriptionFromMetadataArray($metadata);
}
示例10: getLocalizedFullTitle
/**
* Get the chapter full title (with title and subtitle).
* @return string
*/
function getLocalizedFullTitle()
{
$fullTitle = $this->getLocalizedTitle();
if ($subtitle = $this->getLocalizedSubtitle()) {
$fullTitle = PKPString::concatTitleFields(array($fullTitle, $subtitle));
}
return $fullTitle;
}
示例11: _parseQueryInternal
/**
* Query parsing helper routine.
* Returned structure is based on that used by the Search::QueryParser Perl module.
*/
function _parseQueryInternal($signTokens, $tokens, &$pos, $total)
{
$return = array('+' => array(), '' => array(), '-' => array());
$postBool = $preBool = '';
$submissionSearchIndex = new SubmissionSearchIndex();
$notOperator = PKPString::strtolower(__('search.operator.not'));
$andOperator = PKPString::strtolower(__('search.operator.and'));
$orOperator = PKPString::strtolower(__('search.operator.or'));
while ($pos < $total) {
if (!empty($signTokens[$pos])) {
$sign = $signTokens[$pos];
} else {
if (empty($sign)) {
$sign = '+';
}
}
$token = PKPString::strtolower($tokens[$pos++]);
switch ($token) {
case $notOperator:
$sign = '-';
break;
case ')':
return $return;
case '(':
$token = $this->_parseQueryInternal($signTokens, $tokens, $pos, $total);
default:
$postBool = '';
if ($pos < $total) {
$peek = PKPString::strtolower($tokens[$pos]);
if ($peek == $orOperator) {
$postBool = 'or';
$pos++;
} else {
if ($peek == $andOperator) {
$postBool = 'and';
$pos++;
}
}
}
$bool = empty($postBool) ? $preBool : $postBool;
$preBool = $postBool;
if ($bool == 'or') {
$sign = '';
}
if (is_array($token)) {
$k = $token;
} else {
$k = $submissionSearchIndex->filterKeywords($token, true);
}
if (!empty($k)) {
$return[$sign][] = $k;
}
$sign = '';
break;
}
}
return $return;
}
示例12: toXml
/**
* @see OAIMetadataFormat#toXml
*/
function toXml(&$record, $format = null)
{
$article = $record->getData('article');
$journal = $record->getData('journal');
$templateMgr = TemplateManager::getManager();
$templateMgr->assign(array('journal' => $journal, 'article' => $article, 'issue' => $record->getData('issue'), 'section' => $record->getData('section')));
$subjects = array_merge_recursive($this->stripAssocArray((array) $article->getDiscipline(null)), $this->stripAssocArray((array) $article->getSubject(null)));
$templateMgr->assign(array('subject' => isset($subjects[$journal->getPrimaryLocale()]) ? $subjects[$journal->getPrimaryLocale()] : '', 'abstract' => PKPString::html2text($article->getAbstract($article->getLocale())), 'language' => AppLocale::get3LetterIsoFromLocale($article->getLocale())));
return $templateMgr->fetch(dirname(__FILE__) . '/record.tpl');
}
示例13: getXmlOnExport
/**
* Retrieve the export as an XML string.
* @param $pluginUrl string the url to be requested for export.
* @param $postParams array additional post parameters
* @return string
*/
protected function getXmlOnExport($pluginUrl, $postParams = array())
{
// Prepare HTTP session.
$curlCh = curl_init();
curl_setopt($curlCh, CURLOPT_POST, true);
// Create a cookie file (required for log-in).
$cookies = tempnam(sys_get_temp_dir(), 'curlcookies');
// Log in.
$loginUrl = $this->baseUrl . '/index.php/test/login/signIn';
// Bug #8518 safety work-around
if ($this->password[0] == '@') {
die('CURL parameters may not begin with @.');
}
$loginParams = array('username' => 'admin', 'password' => $this->password);
curl_setopt($curlCh, CURLOPT_URL, $loginUrl);
curl_setopt($curlCh, CURLOPT_POSTFIELDS, $loginParams);
curl_setopt($curlCh, CURLOPT_COOKIEJAR, $cookies);
self::assertTrue(curl_exec($curlCh));
// Request export document.
$exportUrl = $this->baseUrl . '/index.php/test/manager/importexport/plugin/' . $pluginUrl;
curl_setopt($curlCh, CURLOPT_URL, $exportUrl);
// Bug #8518 safety work-around
foreach ($postParams as $paramValue) {
if ($paramValue[0] == '@') {
die('CURL parameters may not begin with @.');
}
}
curl_setopt($curlCh, CURLOPT_POSTFIELDS, $postParams);
curl_setopt($curlCh, CURLOPT_HTTPHEADER, array('Accept: application/xml, application/x-gtar, */*'));
curl_setopt($curlCh, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlCh, CURLOPT_HEADER, true);
$response = curl_exec($curlCh);
do {
list($header, $response) = explode("\r\n\r\n", $response, 2);
} while (PKPString::regexp_match('#HTTP/.*100#', $header));
// Check whether we got a tar file.
if (PKPString::regexp_match('#Content-Type: application/x-gtar#', $header)) {
// Save the data to a temporary file.
$tempfile = tempnam(sys_get_temp_dir(), 'tst');
file_put_contents($tempfile, $response);
// Recursively extract tar file.
$result = $this->extractTarFile($tempfile);
unlink($tempfile);
} else {
$matches = null;
PKPString::regexp_match_get('#filename="([^"]+)"#', $header, $matches);
self::assertTrue(isset($matches[1]));
$result = array($matches[1] => $response);
}
// Destroy HTTP session.
curl_close($curlCh);
unlink($cookies);
return $result;
}
示例14: getLocalizedFullTitle
/**
* Get the series full title (with title and subtitle).
* @return string
*/
function getLocalizedFullTitle()
{
$fullTitle = null;
if ($prefix = $this->getLocalizedPrefix()) {
$fullTitle = $prefix . ' ';
}
$fullTitle .= $this->getLocalizedTitle();
if ($subtitle = $this->getLocalizedSubtitle()) {
$fullTitle = PKPString::concatTitleFields(array($fullTitle, $subtitle));
}
return $fullTitle;
}
示例15: getTemplateVarsFromRowColumn
/**
* Extracts variables for a given column from a data element
* so that they may be assigned to template before rendering.
* @param $row GridRow
* @param $column GridColumn
* @return array
*/
function getTemplateVarsFromRowColumn($row, $column)
{
$element =& $row->getData();
$columnId = $column->getId();
assert(!empty($columnId));
switch ($columnId) {
case 'url':
return array('label' => '<a href="' . PKPString::stripUnsafeHtml($element['url']) . '" target="_blank">' . PKPString::stripUnsafeHtml($element['url']) . '</a>');
case 'shares':
return array('label' => $element['shares']);
}
}