Exemplo n.º 1
0
 public static function updateShurls()
 {
     $pageInfo =& Sh404sefFactory::getPageInfo();
     $sefConfig =& Sh404sefFactory::getConfig();
     $pageInfo->shURL = empty($pageInfo->shURL) ? '' : $pageInfo->shURL;
     if ($sefConfig->enablePageId && !$sefConfig->stopCreatingShurls) {
         try {
             jimport('joomla.utilities.string');
             $nonSefUrl = JString::ltrim($pageInfo->shCurrentPageNonSef, '/');
             $nonSefUrl = shSortURL($nonSefUrl);
             // make sure we have a language
             $nonSefUrl = shSetURLVar($nonSefUrl, 'lang', $pageInfo->shMosConfig_shortcode);
             // remove tracking vars (Google Analytics)
             $nonSefUrl = Sh404sefHelperGeneral::stripTrackingVarsFromNonSef($nonSefUrl);
             // try to get the current shURL, if any
             $shURL = Sh404sefHelperDb::selectResult('#__sh404sef_pageids', array('pageid'), array('newurl' => $nonSefUrl));
             // if none, we may have to create one
             if (empty($shURL)) {
                 $shURL = self::_createShurl($nonSefUrl);
             }
             // insert in head and header, if not empty
             if (!empty($shURL)) {
                 $fullShURL = JString::ltrim($pageInfo->getDefaultLiveSite(), '/') . '/' . $shURL;
                 $document =& JFactory::getDocument();
                 if ($sefConfig->insertShortlinkTag) {
                     $document->addHeadLink($fullShURL, 'shortlink');
                     // also add header, especially for HEAD requests
                     JResponse::setHeader('Link', '<' . $fullShURL . '>; rel=shortlink', true);
                 }
                 if ($sefConfig->insertRevCanTag) {
                     $document->addHeadLink($fullShURL, 'canonical', 'rev', array('type' => 'text/html'));
                 }
                 if ($sefConfig->insertAltShorterTag) {
                     $document->addHeadLink($fullShURL, 'alternate shorter');
                 }
                 // store for reuse
                 $pageInfo->shURL = $shURL;
             }
         } catch (Sh404sefExceptionDefault $e) {
         }
     }
 }
Exemplo n.º 2
0
 public function createPageId($sefUrl, $nonSefUrl)
 {
     $shURL = '';
     if (!$this->_mustCreatePageid($nonSefUrl)) {
         return $shURL;
     }
     jimport('joomla.utilities.string');
     $sefUrl = JString::ltrim($sefUrl, '/');
     try {
         if (!empty($sefUrl)) {
             // check that we don't already have a shURL for the same SEF url, even if non-sef differ
             $result = (int) Sh404sefHelperDb::count('#__redirection', '*', $this->_db->nameQuote('oldurl') . ' = ? and ' . $this->_db->nameQuote('newurl') . ' <> ?', array($sefUrl, ''));
             if (!empty($result) && $result > 1) {
                 // we already have a SEF URL, so we must already have a shURL as well
                 return $shURL;
             }
         }
         // check this nonsef url does not already have a shURL
         $existingShurl = Sh404sefHelperDb::selectResult('#__sh404sef_pageids', 'pageid', array('newurl' => $nonSefUrl));
         // there already is a shurl for the same non-sef
         if (!empty($existingShurl)) {
             return $existingShurl;
         }
         // if we don't already have a shURL, create the new one
         $shURL = $this->_buildPageId();
         if (!empty($shURL)) {
             // insert in db
             Sh404sefHelperDb::insert('#__sh404sef_pageids', array('newurl' => $nonSefUrl, 'pageid' => $shURL, 'type' => Sh404sefHelperGeneral::COM_SH404SEF_URLTYPE_PAGEID, 'hits' => 0));
         }
     } catch (Sh404sefExceptionDefault $e) {
         _log('DB error creating pageId ' . $e->getMessage());
     }
     // don't need to add the pageid to cache, won't be needed when building up the page,
     //only when decoding incoming url
     return $shURL;
 }
Exemplo n.º 3
0
 protected function _checkShurls($uri)
 {
     if (self::$requestParsed) {
         return;
     }
     // sanitize
     $path = $uri->getPath();
     if (empty($path)) {
         // no path in request, no possible short url
         return;
     }
     // our configuration object
     $sefConfig = Sh404sefFactory::getConfig();
     // check short url based on request path
     if ($sefConfig->enablePageId) {
         try {
             $dest = Sh404sefHelperDb::selectResult('#__sh404sef_pageids', array('newurl'), array('pageid' => $path));
             // check on $dest: if empty, prevent loop, plus stitch back query string, if any
             if (!empty($dest)) {
                 $queryString = $uri->getQuery();
                 if (!empty($queryString)) {
                     $dest .= JString::strpos($dest, '?') !== false ? '&' . $queryString : '?' . $queryString;
                 }
                 shCheckRedirect($dest, $uri->get('_uri'));
             }
         } catch (Sh404sefException $e) {
             // if error, just log
             _log(__METHOD__ . '/' . __LINE__ . '/' . __CLASS__ . 'Database error reading aliases: ' . $e->getMessage());
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Prepare saving of  Error documents configuration options set
  */
 private function _saveErrordocs()
 {
     // update 404 error page
     $quoteGPC = get_magic_quotes_gpc();
     $shIntroText = empty($_POST) ? '' : ($quoteGPC ? stripslashes($_POST['introtext']) : $_POST['introtext']);
     try {
         // is there already a 404 page article?
         $id = Sh404sefHelperDb::selectResult('#__content', 'id', array('title' => '__404__', 'language' => '*'));
         if (!empty($id)) {
             // yes, update it
             Sh404sefHelperDb::update('#__content', array('introtext' => $shIntroText, 'modified' => date("Y-m-d H:i:s")), array('id' => $id));
         } else {
             $catid = Sh404sefHelperCategories::getSh404sefContentCat();
             if (empty($catid)) {
                 $this->setError(JText::_('COM_SH404SEF_CANNOT_SAVE_404_NO_UNCAT'));
                 return;
             }
             $contentTable = JTable::getInstance('content');
             $content = array('title' => '__404__', 'alias' => '__404__', 'title_alias' => '__404__', 'introtext' => $shIntroText, 'state' => 1, 'catid' => $catid, 'attribs' => '{"menu_image":"-1","show_title":"0","show_section":"0","show_category":"0","show_vote":"0","show_author":"0","show_create_date":"0","show_modify_date":"0","show_pdf_icon":"0","show_print_icon":"0","show_email_icon":"0","pageclass_sfx":""', 'language' => '*');
             $saved = $contentTable->save($content);
             if (!$saved) {
                 $this->setError($contentTable->getError());
             }
         }
     } catch (Sh404sefExceptionDefault $e) {
         $this->setError($e->getMEssage());
     }
     // prevent from being added later on to $sefConfig
     unset($_POST['introtext']);
 }
Exemplo n.º 5
0
 public function check()
 {
     //initialize
     $this->newurl = JString::trim($this->newurl);
     $this->metadesc = JString::trim($this->metadesc);
     $this->metakey = JString::trim($this->metakey);
     $this->metatitle = JString::trim($this->metatitle);
     $this->metalang = JString::trim($this->metalang);
     $this->metarobots = JString::trim($this->metarobots);
     $this->canonical = JString::trim($this->canonical);
     // Open graph data
     $this->og_site_name = JString::trim($this->og_site_name);
     $this->fb_admin_ids = JString::trim($this->fb_admin_ids);
     $this->og_latitude = JString::trim($this->og_latitude);
     $this->og_longitude = JString::trim($this->og_longitude);
     $this->og_street_address = JString::trim($this->og_street_address);
     $this->og_locality = JString::trim($this->og_locality);
     $this->og_postal_code = JString::trim($this->og_postal_code);
     $this->og_region = JString::trim($this->og_region);
     $this->og_country_name = JString::trim($this->og_country_name);
     $this->og_email = JString::trim($this->og_email);
     $this->og_phone_number = JString::trim($this->og_phone_number);
     $this->og_fax_number = JString::trim($this->og_fax_number);
     if ($this->newurl == '/') {
         $this->newurl = sh404SEF_HOMEPAGE_CODE;
     }
     // check for valid URLs
     if ($this->newurl == '') {
         $this->setError(JText::_('COM_SH404SEF_EMPTYURL'));
         return false;
     }
     if (JString::substr($this->newurl, 0, 9) != 'index.php') {
         $this->setError(JText::_('COM_SH404SEF_BADURL'));
         return false;
     }
     // check for existing record, even if id is empty. This may happen
     // in some circumstances, when saving data from popup, ajaxified, dialog boxes
     if (empty($this->id)) {
         try {
             $existingId = Sh404sefHelperDb::selectResult($this->_tbl, 'id', array('newurl' => $this->newurl));
             if (!empty($existingId)) {
                 $this->id = $existingId;
             }
         } catch (Sh404sefExceptionDefault $e) {
         }
     }
     return true;
 }
Exemplo n.º 6
0
 /**
  * Insert in the db the previously retrieved parameters for a plugin
  * including publication information. Also move files as required
  *
  * @param string $pluginFolder
  * @param string $pluginElement
  * @param string $basePath
  */
 private function _shInstallPlugin($pluginFolder, $pluginElement, $sourcePath)
 {
     $app =& JFactory::getApplication();
     // use J! installer to fully install the plugin
     $installer = new JInstaller();
     $result = $installer->install($sourcePath . DS . $pluginElement);
     if ($result) {
         $overrides = array('ordering' => 10, 'enabled' => 1);
         $shouldRestore = $this->_shShouldRestore();
         if ($shouldRestore) {
             // read stored params from disk
             $saved = array();
             $this->_shGetExtensionSavedParams($pluginFolder . '.' . $pluginElement, $saved);
             $overrides = array_merge($overrides, $saved);
         }
         // overrides data in extension table, possibly overriding some columns from saved data
         if (!empty($overrides)) {
             try {
                 $pluginId = Sh404sefHelperDb::selectResult('#__extensions', array('extension_id'), array('type' => 'plugin', 'element' => $pluginElement, 'folder' => $pluginFolder));
                 if (!empty($pluginId)) {
                     jimport('joomla.database.table.extension');
                     $extension =& JTable::getInstance('Extension');
                     $extension->load($pluginId);
                     $extension->bind($overrides);
                     $status = $extension->store();
                     if (!$status) {
                         $app->enqueueMessage('Error: ' . $extension->getError());
                     }
                 } else {
                     $app->enqueueMessage('Error updating plugin DB record: ' . $pluginFolder . ' / ' . $pluginElement);
                 }
             } catch (Sh404sefExceptionDefault $e) {
                 $status = false;
                 $app->enqueueMessage('Error: ' . $e->getMessage());
             }
         }
     } else {
         $app->enqueueMessage('Error installing sh404sef plugin: ' . $pluginFolder . ' / ' . $pluginElement);
         $status = false;
     }
     return $status;
 }