本文整理汇总了PHP中UTIL_String::removeFirstAndLastSlashes方法的典型用法代码示例。如果您正苦于以下问题:PHP UTIL_String::removeFirstAndLastSlashes方法的具体用法?PHP UTIL_String::removeFirstAndLastSlashes怎么用?PHP UTIL_String::removeFirstAndLastSlashes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTIL_String
的用法示例。
在下文中一共展示了UTIL_String::removeFirstAndLastSlashes方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRealRequestUri
/**
* Removes site installation subfolder from request URI
*
* @param string $urlHome
* @param string $requestUri
* @return string
*/
public static function getRealRequestUri($urlHome, $requestUri)
{
$urlArray = parse_url($urlHome);
$originalUri = UTIL_String::removeFirstAndLastSlashes($requestUri);
$originalPath = UTIL_String::removeFirstAndLastSlashes($urlArray['path']);
if ($originalPath === '') {
return $originalUri;
}
$uri = mb_substr($originalUri, mb_strpos($originalUri, $originalPath) + mb_strlen($originalPath));
$uri = trim(UTIL_String::removeFirstAndLastSlashes($uri));
return $uri ? self::secureUri($uri) : '';
}
示例2: redirect
/**
* Makes permanent redirect to provided URL or URI.
*
* @param string $redirectTo
*/
public function redirect($redirectTo = null)
{
// if empty redirect location -> current URI is used
if ($redirectTo === null) {
$redirectTo = OW::getRequest()->getRequestUri();
}
// if URI is provided need to add site home URL
if (!strstr($redirectTo, 'http://') && !strstr($redirectTo, 'https://')) {
$redirectTo = OW::getRouter()->getBaseUrl() . UTIL_String::removeFirstAndLastSlashes($redirectTo);
}
UTIL_Url::redirect($redirectTo);
}
示例3: __construct
/**
* @param OW_Route $route
* @param callback $serviceCallback
* @param string $dtoProperty
*/
public function __construct(OW_Route $route, $serviceCallback, $dtoProperty, $pathProperty, $entityType)
{
$this->route = $route;
$objArr = (array) $route;
$name = $objArr["OW_RouterouteName"];
$path = UTIL_String::removeFirstAndLastSlashes($objArr["OW_RouteroutePath"]);
$da = $objArr["OW_RoutedispatchAttrs"];
$paramsOptions = $objArr["OW_RouterouteParamOptions"];
parent::__construct($name, $path, $da['controller'], $da['action'], $paramsOptions);
$this->serviceCallback = $serviceCallback;
$this->seoService = OASEO_BOL_Service::getInstance();
$this->entityType = $entityType;
$this->dtoProperty = $dtoProperty;
$this->pathProperty = $pathProperty;
$this->pathArray = explode('/', $path);
}
示例4: init
/**
* Application init actions.
*/
public function init()
{
// router init - need to set current page uri and base url
$router = OW::getRouter();
$router->setBaseUrl(OW_URL_HOME);
$this->urlHostRedirect();
OW_Auth::getInstance()->setAuthenticator(new OW_SessionAuthenticator());
$this->userAutoLogin();
// setting default time zone
date_default_timezone_set(OW::getConfig()->getValue('base', 'site_timezone'));
// synchronize the db's time zone
OW::getDbo()->setTimezone();
// OW::getRequestHandler()->setIndexPageAttributes('BASE_CTRL_ComponentPanel');
OW::getRequestHandler()->setStaticPageAttributes('BASE_MCTRL_BaseDocument', 'staticDocument');
$uri = OW::getRequest()->getRequestUri();
// before setting in router need to remove get params
if (strstr($uri, '?')) {
$uri = substr($uri, 0, strpos($uri, '?'));
}
$router->setUri($uri);
$defaultRoute = new OW_DefaultRoute();
//$defaultRoute->setControllerNamePrefix('MCTRL');
$router->setDefaultRoute($defaultRoute);
$navService = BOL_NavigationService::getInstance();
//
// // try to find static document with current uri
// $document = $navService->findStaticDocument($uri);
//
// if ( $document !== null )
// {
// $this->documentKey = $document->getKey();
// }
OW::getPluginManager()->initPlugins();
$event = new OW_Event(OW_EventManager::ON_PLUGINS_INIT);
OW::getEventManager()->trigger($event);
$beckend = OW::getEventManager()->call('base.cache_backend_init');
if ($beckend !== null) {
OW::getCacheManager()->setCacheBackend($beckend);
OW::getCacheManager()->setLifetime(3600);
OW::getDbo()->setUseCashe(true);
}
$this->devActions();
OW::getThemeManager()->initDefaultTheme(true);
// setting current theme
$activeThemeName = OW::getEventManager()->call('base.get_active_theme_name');
$activeThemeName = $activeThemeName ? $activeThemeName : OW::getConfig()->getValue('base', 'selectedTheme');
if ($activeThemeName !== BOL_ThemeService::DEFAULT_THEME && OW::getThemeManager()->getThemeService()->themeExists($activeThemeName)) {
OW_ThemeManager::getInstance()->setCurrentTheme(BOL_ThemeService::getInstance()->getThemeObjectByName(trim($activeThemeName), true));
}
// adding static document routes
$staticDocs = $navService->findAllMobileStaticDocuments();
$staticPageDispatchAttrs = OW::getRequestHandler()->getStaticPageAttributes();
/* @var $value BOL_Document */
foreach ($staticDocs as $value) {
OW::getRouter()->addRoute(new OW_Route($value->getKey(), $value->getUri(), $staticPageDispatchAttrs['controller'], $staticPageDispatchAttrs['action'], array('documentKey' => array(OW_Route::PARAM_OPTION_HIDDEN_VAR => $value->getKey()))));
// TODO refactor - hotfix for TOS page
if (UTIL_String::removeFirstAndLastSlashes($value->getUri()) == 'terms-of-use') {
OW::getRequestHandler()->addCatchAllRequestsExclude('base.members_only', $staticPageDispatchAttrs['controller'], $staticPageDispatchAttrs['action'], array('documentKey' => $value->getKey()));
}
}
//adding index page route
$item = BOL_NavigationService::getInstance()->findFirstLocal(OW::getUser()->isAuthenticated() ? BOL_NavigationService::VISIBLE_FOR_MEMBER : BOL_NavigationService::VISIBLE_FOR_GUEST, OW_Navigation::MOBILE_TOP);
if ($item !== null) {
if ($item->getRoutePath()) {
$route = OW::getRouter()->getRoute($item->getRoutePath());
$ddispatchAttrs = $route->getDispatchAttrs();
} else {
$ddispatchAttrs = OW::getRequestHandler()->getStaticPageAttributes();
}
$router->addRoute(new OW_Route('base_default_index', '/', $ddispatchAttrs['controller'], $ddispatchAttrs['action'], array('documentKey' => array(OW_Route::PARAM_OPTION_HIDDEN_VAR => $item->getDocumentKey()))));
$this->indexMenuItem = $item;
OW::getEventManager()->bind(OW_EventManager::ON_AFTER_REQUEST_HANDLE, array($this, 'activateMenuItem'));
} else {
$router->addRoute(new OW_Route('base_default_index', '/', 'BASE_MCTRL_WidgetPanel', 'index'));
}
if (!OW::getRequest()->isAjax()) {
OW::getResponse()->setDocument($this->newDocument());
OW::getDocument()->setMasterPage(new OW_MobileMasterPage());
OW::getResponse()->setHeader(OW_Response::HD_CNT_TYPE, OW::getDocument()->getMime() . '; charset=' . OW::getDocument()->getCharset());
} else {
OW::getResponse()->setDocument(new OW_AjaxDocument());
}
/* additional actions */
if (OW::getUser()->isAuthenticated()) {
BOL_UserService::getInstance()->updateActivityStamp(OW::getUser()->getId(), $this->getContext());
}
// adding global template vars
$currentThemeImagesDir = OW::getThemeManager()->getCurrentTheme()->getStaticImagesUrl();
$viewRenderer = OW_ViewRenderer::getInstance();
$viewRenderer->assignVar('themeImagesUrl', $currentThemeImagesDir);
$viewRenderer->assignVar('siteName', OW::getConfig()->getValue('base', 'site_name'));
$viewRenderer->assignVar('siteTagline', OW::getConfig()->getValue('base', 'site_tagline'));
$viewRenderer->assignVar('siteUrl', OW_URL_HOME);
$viewRenderer->assignVar('isAuthenticated', OW::getUser()->isAuthenticated());
$viewRenderer->assignVar('bottomPoweredByLink', '<a href="http://www.oxwall.org/" target="_blank" title="Powered by Oxwall Community Software"><img src="' . $currentThemeImagesDir . 'powered-by-oxwall.png" alt="Oxwall Community Software" /></a>');
$viewRenderer->assignVar('adminDashboardIframeUrl', "http://static.oxwall.org/spotlight/?platform=oxwall&platform-version=" . OW::getConfig()->getValue('base', 'soft_version') . "&platform-build=" . OW::getConfig()->getValue('base', 'soft_build'));
if (function_exists('ow_service_actions')) {
//.........这里部分代码省略.........
示例5: getDispatchAttrs
/**
* Returns dispatch params (controller, action, vars) for provided URI.
*
* @throws Redirect404Exception
* @param string $uri
* @return array
*/
public function getDispatchAttrs($uri)
{
//TODO check if method is in try/catch
$uriString = UTIL_String::removeFirstAndLastSlashes($uri);
$uriArray = explode('/', $uriString);
if (sizeof($uriArray) < 2) {
throw new Redirect404Exception('Invalid uri was provided for routing!');
}
$controllerNamePrefixAdd = '';
if (strstr($uriArray[0], '-')) {
$uriPartArray = explode('-', $uriArray[0]);
$uriArray[0] = $uriPartArray[1];
$controllerNamePrefixAdd = strtoupper($uriPartArray[0]);
}
$dispatchAttrs = array();
$classPrefix = null;
$arraySize = sizeof($uriArray);
for ($i = 0; $i < $arraySize; $i++) {
if ($i === 0) {
try {
$classPrefix = strtoupper(OW::getPluginManager()->getPluginKey($uriArray[$i])) . '_' . $controllerNamePrefixAdd . $this->controllerNamePrefix;
} catch (InvalidArgumentException $e) {
throw new Redirect404Exception('Invalid uri was provided for routing!');
}
continue;
}
if ($i === 1) {
if ($classPrefix === null) {
throw new Redirect404Exception('Invalid uri was provided for routing!');
}
$ctrClass = $classPrefix . '_' . UTIL_String::delimiterToCaps('-' . $uriArray[$i], '-');
if (!file_exists(OW::getAutoloader()->getClassPath($ctrClass))) {
throw new Redirect404Exception('Invalid uri was provided for routing!');
}
$dispatchAttrs['controller'] = $ctrClass;
continue;
}
if ($i === 2) {
$dispatchAttrs['action'] = UTIL_String::delimiterToCaps($uriArray[$i], '-');
continue;
}
if ($i % 2 !== 0) {
$dispatchAttrs['vars'][$uriArray[$i]] = null;
} else {
$dispatchAttrs['vars'][$uriArray[$i - 1]] = $uriArray[$i];
}
}
return $dispatchAttrs;
}
示例6: redirect
/**
* Makes header redirect to provided URL or URI.
*
* @param string $redirectTo
*/
public function redirect($redirectTo = null, $switchContextTo = false)
{
if ($switchContextTo !== false && in_array($switchContextTo, array(self::CONTEXT_DESKTOP, self::CONTEXT_MOBILE))) {
OW::getSession()->set(self::CONTEXT_NAME, $switchContextTo);
}
// if empty redirect location -> current URI is used
if ($redirectTo === null) {
$redirectTo = OW::getRequest()->getRequestUri();
}
// if URI is provided need to add site home URL
if (!strstr($redirectTo, 'http://') && !strstr($redirectTo, 'https://')) {
$redirectTo = OW::getRouter()->getBaseUrl() . UTIL_String::removeFirstAndLastSlashes($redirectTo);
}
UTIL_Url::redirect($redirectTo);
}
示例7: match
/**
* Tries to match route path and provided URI.
*
* @param string $uri
* @return boolean
*/
public function match($uri)
{
$uri = UTIL_String::removeFirstAndLastSlashes(trim($uri));
$this->dispatchAttrs[self::DISPATCH_ATTRS_VARLIST] = array();
foreach ($this->routeParamOptions as $paramName => $paramArray) {
if (isset($paramArray[self::PARAM_OPTION_HIDDEN_VAR])) {
$this->dispatchAttrs[self::DISPATCH_ATTRS_VARLIST][$paramName] = $paramArray[self::PARAM_OPTION_HIDDEN_VAR];
}
}
if ($this->isStatic) {
$pathArray = explode('/', $this->routePath);
$pathArray = array_map('urlencode', $pathArray);
$tempPath = implode('/', $pathArray);
return mb_strtoupper($uri) === mb_strtoupper($tempPath);
}
$uriArray = explode('/', $uri);
if (sizeof($uriArray) !== sizeof($this->routePathArray)) {
return false;
}
foreach ($this->routePathArray as $key => $value) {
if (!mb_strstr($value, ':')) {
if (mb_strtoupper(urlencode($value)) !== mb_strtoupper($uriArray[$key])) {
return false;
}
} else {
if (isset($this->routeParamOptions[mb_substr($value, 1)][self::PARAM_OPTION_VALUE_REGEXP]) && !preg_match($this->routeParamOptions[mb_substr($value, 1)][self::PARAM_OPTION_VALUE_REGEXP], $uriArray[$key])) {
return false;
}
$this->dispatchAttrs[self::DISPATCH_ATTRS_VARLIST][mb_substr($value, 1)] = $uriArray[$key];
}
}
return true;
}
示例8: getStorageUrl
private function getStorageUrl($uri)
{
return self::UPDATE_SERVER . UTIL_String::removeFirstAndLastSlashes($uri) . "/";
}
示例9: activate
/**
* @param string $url
* @return boolean
*/
public function activate($url)
{
if (UTIL_String::removeFirstAndLastSlashes($this->url) === UTIL_String::removeFirstAndLastSlashes($url)) {
$this->setActive(true);
}
}
示例10: processContent
private function processContent($content)
{
$resultArray = array('foundLinks' => array(), 'foundImages' => array(), 'meta' => array());
// get all page links
$links = array();
preg_match_all('/<a[^<>]+href=["\']([^"\']+)["\']/i', $content, $links, PREG_PATTERN_ORDER);
$links = array_unique($links[1]);
foreach ($links as $link) {
if (mb_strstr($link, 'javascript://')) {
continue;
} else {
if (mb_strstr($link, '.') && in_array(UTIL_File::getExtension($link), array('gif', 'jpg', 'png', 'jpeg'))) {
$resultArray['foundImages'][] = $link;
continue;
}
}
if (mb_strstr($link, '#')) {
$link = mb_substr($link, 0, strpos($link, '#'));
}
$resultArray['foundLinks'][] = UTIL_String::removeFirstAndLastSlashes($link);
}
$images = array();
preg_match_all('/<img\\s+src="(.*?)"/i', $content, $images);
$images = array_unique($images[1]);
foreach ($images as $image) {
if (mb_strstr($image, OW_URL_STATIC_THEMES) || !mb_strstr($image, '.') || !in_array(UTIL_File::getExtension($image), array('gif', 'jpg', 'png', 'jpeg'))) {
continue;
}
if (mb_strstr($image, '?')) {
$image = substr($image, 0, mb_strpos($image, '?'));
}
$resultArray['foundImages'][] = $image;
}
/* spec hack to find hidden images-------------- */
$images = array();
preg_match_all('/showPhotoCmp\\((.+)\\)/i', $content, $images);
$imageIds = array_unique($images[1]);
if (OW::getPluginManager()->isPluginActive('photo')) {
$photoPl = OW::getPluginManager()->getPlugin('photo');
foreach ($imageIds as $id) {
if (intval($id) > 0) {
$resultArray['foundImages'][] = OW_URL_PLUGIN_USERFILES . $photoPl->getModuleName() . DS . 'photo_original_' . intval($id) . '.jpg';
}
}
}
/* --------------spec hack to find hidden images */
$metaList = array();
preg_match_all('/<meta[^\\<\\>]+>/i', $content, $metaList);
foreach ($metaList[0] as $meta) {
if (mb_strstr($meta, 'http-equiv="')) {
continue;
}
$nameArray = array();
preg_match_all('/name\\s*=\\s*"(.*?)"/i', $meta, $nameArray);
$valueArray = array();
preg_match_all('/content\\s*=\\s*"(.*?)"/i', $meta, $valueArray);
if (!empty($nameArray[1][0]) && !empty($valueArray[1][0])) {
$resultArray['meta'][$nameArray[1][0]] = $valueArray[1][0];
}
}
// get title
$start = mb_strpos($content, '<title>') + mb_strlen('<title>');
$end = mb_strpos($content, '</title>');
if ($start) {
$resultArray['title'] = mb_substr($content, $start, $end - $start);
}
return $resultArray;
}
示例11: getRequestUri
/**
* Returns real request uri.
*
* @return string
*/
public function getRequestUri()
{
if ($this->uri === null) {
$urlArray = parse_url(OW::getRouter()->getBaseUrl());
$originalUri = UTIL_String::removeFirstAndLastSlashes($_SERVER['REQUEST_URI']);
$originalPath = UTIL_String::removeFirstAndLastSlashes($urlArray['path']);
if ($originalPath === '') {
$this->uri = $originalUri;
} else {
$uri = substr($originalUri, strpos($originalUri, $originalPath) + strlen($originalPath));
$uri = UTIL_String::removeFirstAndLastSlashes($uri);
$this->uri = $uri ? $uri : '';
}
}
return $this->uri;
}
示例12: isValid
public function isValid($value)
{
if (!empty($_POST['external-url'])) {
return true;
}
$value = str_replace(UTIL_String::removeFirstAndLastSlashes(OW::getRouter()->getBaseUrl()), '', UTIL_String::removeFirstAndLastSlashes($value));
$bool = !(empty($_POST['local-url']) || empty($value));
$this->errCode = $bool == false ? 1 : 0;
if ($bool) {
if (!preg_match('/^[\\w\\-.]+[\\/\\w\\-.]+$/', trim($value))) {
$this->errCode = 2;
return false;
}
}
return $bool;
}
示例13: isValid
public function isValid($value)
{
$value = str_replace(UTIL_String::removeFirstAndLastSlashes(OW::getRouter()->getBaseUrl()), '', UTIL_String::removeFirstAndLastSlashes($value));
if (!trim($value)) {
return false;
}
return $this->uri == $value || BOL_NavigationService::getInstance()->isDocumentUriUnique($value);
}
示例14: __construct
/**
* @return Constructor.
*/
public function __construct($metaData, $uri, $frontend = true)
{
parent::__construct();
$this->metaService = OASEO_BOL_Service::getInstance();
$language = OW::getLanguage();
$uriArray = parse_url($uri);
$uri = !empty($uriArray['path']) ? $uriArray['path'] : '';
// need to get uri if url provided
if (substr($uri, 0, 7) == 'http://') {
$uri = substr($uri, strlen(OW_URL_HOME));
} elseif (UTIL_String::removeFirstAndLastSlashes(substr($uri, 0, strlen(OW_URL_HOME) - 7)) == UTIL_String::removeFirstAndLastSlashes(substr(OW_URL_HOME, 7))) {
$uri = UTIL_String::removeFirstAndLastSlashes(substr($uri, strlen(OW_URL_HOME) - 7));
} else {
$uri = trim($uri);
}
$metaData['routeData'] = $this->metaService->getRouteData($uri);
$dispatchAttrs = $this->metaService->getDispatchParamsForUri($uri);
if ($dispatchAttrs === false) {
$this->assign('no_compile', true);
return;
}
$entry = $this->metaService->getEntryForDispatchParams($dispatchAttrs);
if ($entry !== null) {
$metaArr = json_decode($entry->getMeta(), true);
if (isset($metaArr['title'])) {
$titleString = $metaArr['title'];
}
if (isset($metaArr['keywords'])) {
$keywords = $metaArr['keywords'];
}
if (isset($metaArr['desc'])) {
$descString = $metaArr['desc'];
}
}
if (!isset($titleString)) {
$titleString = $metaData['title'];
}
if (!isset($keywords)) {
$keywords = explode(',', $metaData['keywords']);
$keywords = array_map('trim', $keywords);
}
if (!isset($descString)) {
$descString = $metaData['desc'];
}
$form = new Form('meta_edit');
$form->setAction(OW::getRouter()->urlFor('OASEO_CTRL_Base', 'updateMeta'));
$form->setAjax();
$form->setAjaxResetOnSuccess(false);
$this->addForm($form);
$title = new TextField('title');
$title->setLabel($language->text('oaseo', 'meta_edit_form_title_label'));
$title->setDescription($language->text('oaseo', 'meta_edit_form_title_fr_desc'));
$title->setValue($titleString);
$form->addElement($title);
$keyword = new OA_CCLASS_TagsField('keywords');
$keyword->setLabel($language->text('oaseo', 'meta_edit_form_keyword_label'));
$keyword->setDescription($language->text('oaseo', 'meta_edit_form_keyword_fr_desc'));
$keyword->setValue($keywords);
$form->addElement($keyword);
$desc = new Textarea('desc');
$desc->setLabel($language->text('oaseo', 'meta_edit_form_desc_label'));
$desc->setDescription($language->text('oaseo', 'meta_edit_form_desc_fr_desc'));
$desc->setValue($descString);
$form->addElement($desc);
$hidTitle = new HiddenField('hidTitle');
$hidTitle->setValue($titleString);
$form->addElement($hidTitle);
$hidKeyword = new HiddenField('hidKeywords');
$hidKeyword->setValue(implode('+|+', $keywords));
$form->addElement($hidKeyword);
$hidDesc = new HiddenField('hidDesc');
$hidDesc->setValue($descString);
$form->addElement($hidDesc);
if (!empty($metaData['routeData']) && $uri && $dispatchAttrs['controller'] != 'BASE_CTRL_StaticDocument') {
$this->assign('urlAvail', true);
$urlField = new OASEO_UrlField('url');
$urlField->setValue($metaData['routeData']['path']);
$urlField->setLabel($language->text('oaseo', 'meta_edit_form_url_label'));
$urlField->setDescription($language->text('oaseo', 'meta_edit_form_url_desc'));
$form->addElement($urlField);
$routeName = new HiddenField('routeName');
$routeName->setValue($metaData['routeData']['name']);
$form->addElement($routeName);
}
$uriEl = new HiddenField('uri');
$uriEl->setValue($uri);
$form->addElement($uriEl);
$submit = new Submit('submit');
$submit->setValue($language->text('oaseo', 'meta_edit_form_submit_label'));
$form->addElement($submit);
$id = uniqid();
$this->assign('id', $id);
$this->assign('frontend', $frontend);
$form->bindJsFunction('success', "function(data){if(data.status){OW.info(data.msg);window.oaseoFB.close();}else{OW.error(data.msg);}}");
if ($frontend) {
OW::getDocument()->addOnloadScript("\$('#aoseo_button_{$id}').click(\n function(){\n window.oaseoFB = new OA_FloatBox({\n \$title: '{$language->text('oaseo', 'meta_edit_form_cmp_title')}',\n \$contents: \$('#oaseo_edit_form_{$id}'),\n width: 900,\n icon_class: 'ow_ic_gear'\n });\n }\n );");
}
//.........这里部分代码省略.........