Exemplo n.º 1
0
 /**
  * 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) : '';
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 3
0
 /**
  * @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);
 }
Exemplo n.º 4
0
 /**
  * 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')) {
         call_user_func('ow_service_actions');
     }
     $this->handleHttps();
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
 /**
  * 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);
 }
Exemplo n.º 7
0
 /**
  * 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;
 }
Exemplo n.º 8
0
 private function getStorageUrl($uri)
 {
     return self::UPDATE_SERVER . UTIL_String::removeFirstAndLastSlashes($uri) . "/";
 }
Exemplo n.º 9
0
 /**
  * @param string $url
  * @return boolean
  */
 public function activate($url)
 {
     if (UTIL_String::removeFirstAndLastSlashes($this->url) === UTIL_String::removeFirstAndLastSlashes($url)) {
         $this->setActive(true);
     }
 }
Exemplo n.º 10
0
 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;
 }
Exemplo n.º 11
0
 /**
  * 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;
 }
Exemplo n.º 12
0
 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;
 }
Exemplo n.º 13
0
 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);
 }
Exemplo n.º 14
0
 /**
  * @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        );");
     }
 }