/** * Returns an instance of class (singleton pattern implementation). * * @return OASEO_BOL_Service */ public static function getInstance() { if (self::$classInstance === null) { self::$classInstance = new self(); } return self::$classInstance; }
function oaseo_add_slugs(OW_Event $e) { // add slugs OASEO_BOL_Service::getInstance()->initSlugs(); // init urls OASEO_BOL_Service::getInstance()->initUrls(); }
public function getDispatchAttrs() { $attrs = parent::getDispatchAttrs(); $str = urldecode($attrs[OW_Route::DISPATCH_ATTRS_VARLIST][$this->pathProperty]); /* @var $slug OASEO_BOL_Slug */ $slug = $this->seoService->getSlugForString($this->entityType, $str); if ($slug === null) { $rnSlug = $this->seoService->findActiveSlugForInactiveOne($this->entityType, $str); if ($rnSlug !== null) { $generatedUri = ''; foreach ($this->pathArray as $value) { if (mb_substr($value, 0, 1) !== ':') { $generatedUri .= $value . '/'; } else { $varName = mb_substr($value, 1); $generatedUri .= urlencode($varName == $this->pathProperty ? $rnSlug->getString() : $attrs[OW_Route::DISPATCH_ATTRS_VARLIST][$varName]) . '/'; } } throw new RedirectException(OW_URL_HOME . mb_substr($generatedUri, 0, -1)); } else { if (is_numeric($str)) { $slug = $this->seoService->findActiveSlugForEntityItem($this->entityType, $str); if ($slug !== null) { $key = array_search(':' . $this->pathProperty, $this->pathArray); if ($key) { $pathArray = explode('/', OW::getRequest()->getRequestUri()); $pathArray[$key] = $slug->getString(); $redirectUri = implode('/', $pathArray); OW::getApplication()->redirect(OW_URL_HOME . $redirectUri); } } } } } if ($slug !== null) { $attrs[OW_Route::DISPATCH_ATTRS_VARLIST][$this->pathProperty] = $slug->getEntityId(); if (!$this->slugChecked) { $this->seoService->checkEntityUpdate($this->entityType, $slug->getEntityId(), $this->serviceCallback, $this->dtoProperty); $this->slugChecked = true; } } return $attrs; }
public function xmlImageSitemapGz() { if (file_exists($this->metaService->getImageMapPath(true))) { header("Content-Encoding: gzip"); header("Content-Type: text/xml"); exit(file_get_contents($this->metaService->getImageMapPath(true))); } else { header("HTTP/1.0 404 Not Found"); exit('Sitemap generation in progress...'); } }
public function sitemapInfo() { $config = OW::getConfig(); if (!(bool) $config->getValue('oaseo', 'sitemap_init')) { $this->assign('init', false); return; } if ($this->service->getToProcessPagesCount() > 0) { $this->assign('in_process_message', OW::getLanguage()->text('oaseo', 'in_progress_label')); $this->assign('url', $this->service->getNextUrlToProcess()); $this->assign('processed', $this->service->getProcessedPagesCount()); $this->assign('to_process', $this->service->getToProcessPagesCount()); return; } $page = !empty($_GET['page']) && (int) $_GET['page'] > 0 ? (int) $_GET['page'] : 1; $numOnPage = 25; $first = $numOnPage * ($page - 1); $count = $numOnPage; $itemsCountArr = array('pages' => $this->service->findAllPagesCount(), 'broken_links' => $this->service->findBrokenPagesCount(), 'images' => $this->service->findItemsCount(OASEO_BOL_Service::ITEM_VAL_IMAGE), 'broken_images' => $this->service->findItemsCount(OASEO_BOL_Service::ITEM_VAL_BROKEN_IMAGE), 'ext_links' => $this->service->findItemsCount(OASEO_BOL_Service::ITEM_VAL_EXT_LINK), 'brok_ext_links' => $this->service->findItemsCount(OASEO_BOL_Service::ITEM_VAL_BROKEN_EXT_LINK)); $router = OW::getRouter(); $urlArr = array('pages' => $router->urlFor('OASEO_CTRL_Admin', 'sitemapInfo'), 'broken' => $router->urlFor('OASEO_CTRL_Admin', 'sitemapInfo') . '?list=broken', 'images' => $router->urlFor('OASEO_CTRL_Admin', 'sitemapInfo') . '?list=images', 'broken_images' => $router->urlFor('OASEO_CTRL_Admin', 'sitemapInfo') . '?list=broken_images', 'ext_links' => $router->urlFor('OASEO_CTRL_Admin', 'sitemapInfo') . '?list=ext_links', 'broken_ext_links' => $router->urlFor('OASEO_CTRL_Admin', 'sitemapInfo') . '?list=broken_ext_links'); $this->assign('urlArray', $urlArr); $this->assign('counts', $itemsCountArr); $list = empty($_GET['list']) ? 'std' : trim($_GET['list']); $finalArray = array(); switch ($list) { case 'broken': $items = $this->service->findPages($first, $count, true); $itemsCount = $itemsCountArr['broken_links']; foreach ($items as $item) { if (!isset($finalArray[$item['burl']])) { $finalArray[$item['burl']] = array(); } $finalArray[$item['burl']][] = $item['url']; } break; case 'images': $items = $this->service->findItems(OASEO_BOL_Service::ITEM_VAL_IMAGE, $first, $count); $itemsCount = $itemsCountArr['images']; $list = 'images'; $finalArray = $this->processPageItems($items); break; case 'broken_images': $items = $this->service->findItems(OASEO_BOL_Service::ITEM_VAL_BROKEN_IMAGE, $first, $count); $itemsCount = $itemsCountArr['broken_images']; $list = 'broken_images'; $finalArray = $this->processPageItems($items); break; case 'ext_links': $items = $this->service->findItems(OASEO_BOL_Service::ITEM_VAL_EXT_LINK, $first, $count); $itemsCount = $itemsCountArr['ext_links']; $list = 'ext_links'; $finalArray = $this->processPageItems($items); break; case 'broken_ext_links': $items = $this->service->findItems(OASEO_BOL_Service::ITEM_VAL_BROKEN_EXT_LINK, $first, $count); $itemsCount = $itemsCountArr['brok_ext_links']; $list = 'broken_ext_links'; $finalArray = $this->processPageItems($items); break; default: $items = $this->service->findPages($first, $count); $itemsCount = $itemsCountArr['pages']; $list = 'pages'; foreach ($items as $item) { $metaInfo = json_decode($item['meta'], true); $keywords = empty($metaInfo['keywords']) ? '<span style="color:red;">_NO_KEYWORDS_</span>' : $metaInfo['keywords']; $desc = empty($metaInfo['description']) ? '<span style="color:red;">_NO_DESCRIPTION_</span>' : $metaInfo['description']; $finalArray[] = array('keywords' => $keywords, 'desc' => $desc, 'url' => urldecode($item['url']), 'title' => empty($item['title']) ? '<span style="color:red;">_NO_TITLE_</span>' : $item['title']); } } $this->assign('list', $list); $this->assign('items', $finalArray); $this->addComponent('paging', new BASE_CMP_Paging($page, ceil($itemsCount / $numOnPage), 5)); }
/** * @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 );"); } }
public function run() { OASEO_BOL_Service::getInstance()->startSitemapGenerator(); OASEO_BOL_Service::getInstance()->updateConfigMaps(); OASEO_BOL_Service::getInstance()->scheduleInfoUpdate(); }