Exemple #1
0
 /**
  * Get a Extplugin object for the requested extension
  * If no specific plugin is found, the default, generic
  * public is used instead
  *
  * @param string $option the Joomla! component name. Should begin with "com_"
  * @return object Sh404sefExtpluginBaseextplugin descendant
  */
 public static function &getExtensionPlugin($option)
 {
     static $_plugins = array();
     if (empty($option)) {
         $option = 'default';
     }
     // plugin is cached, check if we already created
     // the plugin for $option
     if (empty($_plugins[$option])) {
         // build the class name for this plugin
         // autolaoder will find the appropriate file and load it
         // if not loaded
         if ($option !== 'default' && strpos($option, 'com_') !== 0) {
             $option = 'com_' . $option;
         }
         $className = 'Sh404sefExtplugin' . ucfirst(strtolower($option));
         // does this class exists?
         $sefConfig =& shRouter::shGetConfig();
         if (class_exists($className, $autoload = true)) {
             // instantiate plugin
             $_plugins[$option] = new $className($option, $sefConfig);
         } else {
             // else use generic plugin
             $_plugins[$option] = new Sh404sefExtpluginDefault($option, $sefConfig);
         }
     }
     // return cached plugin
     return $_plugins[$option];
 }
Exemple #2
0
 function shGetNEWSPCategories($catId, $option, $shLangName, &$cat, &$sec)
 {
     if (empty($catId)) {
         return false;
     }
     static $catData = null;
     $sefConfig =& shRouter::shGetConfig();
     if (!is_null($catData[$shLangName][$catId])) {
         // get DB
         $database =& JFactory::getDBO();
         $query = "SELECT c.id, c.section, c.title, s.id as sectionid, s.title as stitle" . "\n FROM #__categories as c, #__sections as s" . "\n WHERE " . "\n s.id = c.section" . "\n AND c.id = '" . $catId . "'";
         $database->setQuery($query);
         if (shTranslateUrl($option, $shLangName)) {
             $categories = $database->loadObjectList();
         } else {
             $categories = $database->loadObjectList(false);
         }
         if (!empty($categories)) {
             $sec = ($sefConfig->shNewsPInsertSecId ? $sectionId . $sefConfig->replacement : '') . $categories[0]->stitle;
             // section
             $cat = ($sefConfig->shNewsPInsertCatId ? $sectionId . $sefConfig->replacement : '') . $categories[0]->title;
             // category
             $catData[$shLangName][$catId]['cat'] = $cat;
             $catData[$shLangName][$catId]['sec'] = $sec;
         }
     } else {
         $cat = $catData[$shLangName][$catId]['cat'];
         $sec = $catData[$shLangName][$catId]['sec'];
     }
     return !empty($cat);
 }
Exemple #3
0
 function dm_sef_get_category_array($category_id, $option, $shLangName)
 {
     global $shMosConfig_locale;
     $sefConfig =& shRouter::shGetConfig();
     // get DB
     $database =& JFactory::getDBO();
     static $DMtree = null;
     if (empty($tree[$shMosConfig_locale])) {
         $q = "SELECT id, title, parent_id FROM #__categories";
         // load them all in memory
         $database->setQuery($q);
         if (!shTranslateUrl($option, $shLangName)) {
             // V 1.2.4.m
             $DMtree[$shMosConfig_locale] = $database->loadObjectList('id', false);
         } else {
             $DMtree[$shMosConfig_locale] = $database->loadObjectList('id');
         }
     }
     $title = array();
     if ($sefConfig->shDMInsertCategories == 1) {
         // only one category
         $title[] = ($sefConfig->shDMInsertCategoryId ? $DMtree[$shMosConfig_locale][$category_id]->id . $sefConfig->replacement : '') . $DMtree[$shMosConfig_locale][$category_id]->title;
     } else {
         do {
             // all categories and subcategories. We don't really need id, as path
             $title[] = ($sefConfig->shDMInsertCategoryId ? $DMtree[$shMosConfig_locale][$category_id]->id . $sefConfig->replacement : '') . $DMtree[$shMosConfig_locale][$category_id]->title;
             // will always be unique
             $category_id = $DMtree[$shMosConfig_locale][$category_id]->parent_id;
         } while ($category_id != 0);
     }
     return array_reverse($title);
 }
Exemple #4
0
function vm_sef_get_category_title(&$db, &$catDesc, $category_id, $option, $shLangName)
{
    global $shMosConfig_locale;
    $sefConfig =& shRouter::shGetConfig();
    if (empty($category_id)) {
        return '';
    }
    $q = "SELECT c.category_name, c.category_id, c.category_description, x.category_parent_id FROM #__vm_category AS c";
    $q .= "\n LEFT JOIN #__vm_category_xref AS x ON c.category_id = x.category_child_id;";
    $db->setQuery($q);
    if (!shTranslateUrl($option, $shLangName)) {
        // V 1.2.4.m
        $tree = $db->loadObjectList('category_id', false);
    } else {
        $tree = $db->loadObjectList('category_id');
    }
    $catDesc = $tree[$category_id]->category_description;
    $title = '';
    $securityCounter = 0;
    do {
        // all categories and subcategories
        $securityCounter++;
        $title .= ($sefConfig->shInsertCategoryId ? $tree[$category_id]->category_id . $sefConfig->replacement : '') . $tree[$category_id]->category_name . ' | ';
        $category_id = $tree[$category_id]->category_parent_id;
    } while ($category_id != 0 && $securityCounter < 10);
    if ($securityCounter >= 10) {
        JError::raiseError(500, 'Unable to create SEF url for Virtuemart: could not find category with id : ' . $category_id);
    }
    return JString::rtrim($title, ' | ');
}
Exemple #5
0
 public function display($tpl = null)
 {
     // get model and update context with current
     $model =& $this->getModel();
     $context = $model->setContext($this->_context . '.' . $this->getLayout());
     // display type: simple for very large sites/slow slq servers
     $sefConfig =& shRouter::shGetConfig();
     // if set for a slowServer, display simplified version of the url manager
     $this->assign('slowServer', $sefConfig->slowServer);
     // read data from model
     $list =& $model->getList((object) array('layout' => $this->getLayout(), 'simpleUrlList' => $this->slowServer, 'slowServer' => $sefConfig->slowServer));
     // and push it into the view for display
     $this->assign('items', $list);
     $this->assign('itemCount', count($this->items));
     $this->assign('pagination', $model->getPagination((object) array('layout' => $this->getLayout(), 'simpleUrlList' => $this->slowServer, 'slowServer' => $sefConfig->slowServer)));
     $options = $model->getDisplayOptions();
     $this->assign('options', $options);
     $this->assign('optionsSelect', $this->_makeOptionsSelect($options));
     // add behaviors and styles as needed
     $modalSelector = 'a.modalediturl';
     $js = '\\function(){shAlreadySqueezed = false;if(parent.shReloadModal) {parent.window.location=\'' . $this->defaultRedirectUrl . '\';parent.shReloadModal=true}}';
     $params = array('overlayOpacity' => 0, 'classWindow' => 'sh404sef-popup', 'classOverlay' => 'sh404sef-popup', 'onClose' => $js);
     Sh404sefHelperHtml::modal($modalSelector, $params);
     // build the toolbar
     $toolbarMethod = '_makeToolbar' . ucfirst($this->getLayout());
     if (is_callable(array($this, $toolbarMethod))) {
         $this->{$toolbarMethod}($params);
     }
     // add our own css
     JHtml::styleSheet('urls.css', Sh404sefHelperGeneral::getComponentUrl() . '/assets/css/');
     // link to  custom javascript
     JHtml::script('list.js', Sh404sefHelperGeneral::getComponentUrl() . '/assets/js/');
     // now display normally
     parent::display($tpl);
 }
Exemple #6
0
 private function _prepareControlPanelData()
 {
     $sefConfig =& shRouter::shGetConfig();
     $this->assign('sefConfig', $sefConfig);
     // update information
     $versionsInfo = Sh404sefHelperUpdates::getUpdatesInfos();
     $this->assign('updates', $versionsInfo);
     // url databases stats
     $database =& JFactory::getDBO();
     $sql = 'SELECT count(*) FROM #__redirection WHERE ';
     $database->setQuery($sql . "`dateadd` > '0000-00-00' and `newurl` = '' ");
     // 404
     $Count404 = $database->loadResult();
     $database->setQuery($sql . "`dateadd` > '0000-00-00' and `newurl` != '' ");
     // custom
     $customCount = $database->loadResult();
     $database->setQuery($sql . "`dateadd` = '0000-00-00'");
     // regular
     $sefCount = $database->loadResult();
     // calculate security stats
     $default = empty($sefConfig->shSecLastUpdated) ? '- -' : '0';
     $this->assign('sefCount', $sefCount);
     $this->assign('Count404', $Count404);
     $this->assign('customCount', $customCount);
 }
Exemple #7
0
 /**
  * Prepare and display the control panel
  * dashboard, which is a simplified view
  * of main analytics results
  * 
  * @param string $tpl layout name
  */
 private function _makeViewDashboard($tpl)
 {
     // get configuration object
     $sefConfig =& shRouter::shGetConfig();
     // push it into to the view
     $this->assignRef('sefConfig', $sefConfig);
     // get analytics data using helper, possibly from cache
     $analyticsData = Sh404sefHelperAnalytics::getData($this->options);
     // push analytics stats into view
     $this->assign('analytics', $analyticsData);
 }
 function shAkeebasubsMenuName($task, $Itemid, $option, $shLangName)
 {
     $sefConfig =& shRouter::shGetConfig();
     $shArsDownloadName = shGetComponentPrefix($option);
     if (empty($shArsDownloadName)) {
         $shArsDownloadName = getMenuTitle($option, $task, $Itemid, null, $shLangName);
     }
     if (empty($shArsDownloadName) || $shArsDownloadName == '/') {
         $shArsDownloadName = 'AkeebaReleaseSystem';
     }
     return str_replace('.', $sefConfig->replacement, $shArsDownloadName);
 }
Exemple #9
0
 protected static function &_getInstance($type = 'file')
 {
     static $_instance = null;
     if (empty($_instance)) {
         // get global config
         $config =& shRouter::shGetConfig();
         // instantiate object
         $className = 'Sh404sefClass' . $type . 'cache';
         $_instance = new $className($config);
     }
     return $_instance;
 }
Exemple #10
0
 function shGetContactCategory($id, $shLangName)
 {
     $sefConfig =& shRouter::shGetConfig();
     if (empty($sefConfig->insertContactCat)) {
         return '';
     }
     if (empty($id)) {
         return '';
     }
     $cat = sef_404::getcategories($id, $shLangName, 'com_contact_details');
     return $cat;
 }
Exemple #11
0
 function shSobi2GetItemName($id)
 {
     $database =& JFactory::getDBO();
     if (empty($id)) {
         return '';
     }
     $sefConfig = shRouter::shGetConfig();
     $query = "SELECT `title` FROM `#__sobi2_item` WHERE (`itemid`={$id} AND `published` = 1)";
     $database->setQuery($query);
     $ret = (sh404SEF_SOBI2_PARAMS_INCLUDE_ENTRY_ID ? $id . $sefConfig->replacement : '') . html_entity_decode($database->loadResult());
     // V 1.2.4.t added html_entit_decode
     return $ret;
 }
Exemple #12
0
 private function _doQuickControl($tpl)
 {
     // get configuration object
     $sefConfig =& shRouter::shGetConfig();
     // push it into to the view
     $this->assignRef('sefConfig', $sefConfig);
     // push any message
     $error = $this->getError();
     if (empty($error)) {
         $noMsg = JRequest::getInt('noMsg', 0);
         if (empty($noMsg)) {
             $this->assign('message', JText16::_('COM_SH404SEF_ELEMENT_SAVED'));
         }
     }
     parent::display($tpl);
 }
Exemple #13
0
 private function _shDecodeSecLogLine($line)
 {
     $sefConfig =& shRouter::shGetConfig();
     if (preg_match('/[0-9]{2}\\-[0-9]{2}\\-[0-9]{2}/', $line)) {
         // this is not header or comment line
         $sefConfig->shSecTotalAttacks++;
         $bits = explode("\t", $line);
         switch (substr($bits[2], 0, 15)) {
             case 'Flooding':
                 $sefConfig->shSecTotalFlooding++;
                 break;
             case 'Caught by Honey':
                 $sefConfig->shSecTotalPHP++;
                 break;
             case 'Honey Pot but u':
                 $sefConfig->shSecTotalPHPUserClicked++;
                 break;
             case 'Var not numeric':
             case 'Var not alpha-n':
             case 'Var contains ou':
                 $sefConfig->shSecTotalStandardVars++;
                 break;
             case 'Image file name':
                 $sefConfig->shSecTotalImgTxtCmd++;
                 break;
             case '<script> tag in':
                 $sefConfig->shSecTotalScripts++;
                 break;
             case 'Base 64 encoded':
                 $sefConfig->shSecTotalBase64++;
                 break;
             case 'mosConfig_var i':
                 $sefConfig->shSecTotalConfigVars++;
                 break;
             case 'Blacklisted IP':
                 $sefConfig->shSecTotalIPDenied++;
                 break;
             case 'Blacklisted use':
                 $sefConfig->shSecTotalUserAgentDenied++;
                 break;
             default:
                 // if not one of those, then it's a 404, don't count it as an attack
                 $sefConfig->shSecTotalAttacks--;
                 break;
         }
     }
 }
 function shSimpleLogger($siteName, $basePath, $fileName, $isActive)
 {
     $sefConfig = shRouter::shGetConfig();
     if (empty($isActive)) {
         $this->isActive = 0;
         return;
     } else {
         $this->isActive = 1;
     }
     $traceFileName = $basePath . $sefConfig->debugStartedAt . '.' . $fileName . '_' . str_replace('/', '_', str_replace('http://', '', $siteName)) . '.log';
     // Create file
     $fileIsThere = file_exists($traceFileName);
     $sep = "\t";
     if (!$fileIsThere) {
         // create file
         $fileHeader = 'sh404SEF trace file - created : ' . $this->logTime() . ' for ' . $siteName . "\n\n" . str_repeat('-', 25) . ' PHP Configuration ' . str_repeat('-', 25) . "\n\n";
         $config = $this->parsePHPConfig();
         $line = str_repeat('-', 69) . "\n\n";
         // look for ob handlers, as we cannot use print_r from one (thanks Moovur !)
         $handlers = ob_list_handlers();
         $line .= "\nHandlers found : " . count($handlers);
         if (!empty($handlers)) {
             foreach ($handlers as $key => $handler) {
                 $line .= "\nHandler " . ($key + 1) . ' : ' . $handler;
             }
         }
         $line .= "\n" . str_repeat('-', 69) . "\n\n";
     } else {
         $fileHeader = '';
     }
     $file = fopen($traceFileName, 'ab');
     if ($file) {
         if (!empty($fileHeader)) {
             fWrite($file, $fileHeader);
             fWrite($file, print_r($config, true));
             fwrite($file, $line);
         }
         $this->logFile = $file;
     } else {
         $this->isActive = 0;
         return;
     }
 }
Exemple #15
0
 public static function updateShurls()
 {
     $sefConfig =& shRouter::shGetConfig();
     // set the short link tag
     $shPageInfo =& shRouter::shPageInfo();
     $shPageInfo->shURL = '';
     if ($sefConfig->enablePageId && !$sefConfig->stopCreatingShurls) {
         try {
             jimport('joomla.utilities.string');
             $nonSefUrl = JString::ltrim($shPageInfo->shCurrentPageNonSef, '/');
             $nonSefUrl = shSortURL($nonSefUrl);
             // 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($GLOBALS['shConfigLiveSite'], '/') . '/' . $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
                 $shPageInfo->shURL = $shURL;
             }
         } catch (Sh404sefExceptionDefault $e) {
         }
     }
 }
Exemple #16
0
 function shGetFileName($id, $option, $shLangName)
 {
     if (empty($id)) {
         return null;
     }
     $sefConfig =& shRouter::shGetConfig();
     // get DB
     $database =& JFactory::getDBO();
     $database->setQuery('SELECT id, filetitle, containerid FROM #__downloads_files WHERE id = ' . $database->Quote($id));
     if (!shTranslateUrl($option, $shLangName)) {
         $rows = $database->loadRow(false);
     } else {
         $rows = $database->loadRow();
     }
     $title = shGetContainerName($rows[2], $option, $shLangName);
     if (count($title) > 1) {
         array_pop($title);
     }
     // V w 27/08/2007 13:56:13 remove trailling slash
     $title[] = ($sefConfig->shRemoInsertDocId ? $id . $sefConfig->replacement : '') . $rows[1];
     return $title;
 }
Exemple #17
0
 function dp_sef_get_category_array($category_id, $option, $shLangName)
 {
     global $shMosConfig_locale;
     $sefConfig =& shRouter::shGetConfig();
     // get DB
     $db =& JFactory::getDBO();
     static $tree = null;
     // V 1.2.4.m  $tree must an array based on current language
     $title = array();
     if (SH404SEF_DP_INSERT_ALL_CATEGORIES == 0) {
         return $title;
     }
     if (empty($tree[$shMosConfig_lang])) {
         // load up all cat details
         $q = 'SELECT title, id, parent_id FROM #__dp_categories';
         $q .= "\n WHERE published <> '0';";
         // V x
         $db->setQuery($q);
         if (!shTranslateUrl($option, $shLangName)) {
             // V 1.2.4.m
             $tree[$shMosConfig_lang] = $db->loadObjectList('id', false);
         } else {
             $tree[$shMosConfig_lang] = $db->loadObjectList('id');
         }
     }
     if (SH404SEF_DP_INSERT_ALL_CATEGORIES == 1) {
         // only one category
         $title[] = (SH404SEF_DP_INSERT_CAT_ID != 0 ? $tree[$shMosConfig_lang][$category_id]->id . $sefConfig->replacement : '') . $tree[$shMosConfig_lang][$category_id]->title;
     } else {
         do {
             // all categories and subcategories.
             $title[] = (SH404SEF_DP_INSERT_CAT_ID ? $tree[$shMosConfig_lang][$category_id]->id . $sefConfig->replacement : '') . $tree[$shMosConfig_lang][$category_id]->title;
             // will always be unique
             $category_id = $tree[$shMosConfig_lang][$category_id]->parent_id;
         } while ($category_id != 0);
     }
     return array_reverse($title);
 }
Exemple #18
0
 function shAppendListing($link_name, $link_id, $add_details = false, $shLangIso, $option, $shLangName)
 {
     global $sh_LANG;
     $sefConfig =& shRouter::shGetConfig();
     $sef = array();
     if ($sefConfig->shMTreeInsertListingId) {
         if (!$sefConfig->shMTreePrependListingId) {
             $sef[] = ($sefConfig->shMTreeInsertListingName ? $link_name . $sefConfig->replacement : '') . $link_id;
         } else {
             $sef[] = $link_id . ($sefConfig->shMTreeInsertListingName ? $sefConfig->replacement . $link_name : '');
         }
     } else {
         if ($sefConfig->shMTreeInsertListingName) {
             $sef[] = $link_name;
         }
     }
     if ($add_details) {
         $sef[] = $sh_LANG[$shLangIso]['_MT_SEF_DETAILS'];
     }
     if ($sefConfig->shMTreeInsertListingName || $sefConfig->shMTreeInsertListingId) {
         shRemoveFromGETVarsList('link_id');
     }
     return $sef;
 }
Exemple #19
0
function shCheckAlias($incomingUrl)
{
    $sefConfig =& shRouter::shGetConfig();
    $db =& JFactory::getDBO();
    $query = 'SELECT newurl FROM #__sh404sef_aliases WHERE alias = ' . $db->Quote($incomingUrl);
    $db->setQuery($query);
    $dest = $db->loadResult();
    shCheckRedirect($dest, $incomingUrl);
}
Exemple #20
0
 /**
  * Save an url to the database, updating various elements
  * at the same time like ranking of duplicates
  *
  * @param integer $type force url type, used when saving a custom url
  */
 private function _saveUrl($type = sh404SEF_URLTYPE_AUTO)
 {
     // check for homepage handling
     if (!empty($this->_data['newurl']) && ($this->_data['newurl'] == '/' || $this->_data['newurl'] == sh404SEF_HOMEPAGE_CODE)) {
         $this->_saveHomeUrl();
         return sh404SEF_HOMEPAGE_CODE;
     }
     // check for importing urls : if importing, rank will already be set in
     // incoming data. If saving a url from the UI, rank is never set
     // as it is caculated upon saving the url
     $importing = isset($this->_data['rank']);
     // get required tools
     jimport('joomla.database.table');
     $row =& JTable::getInstance($this->_defaultTable, 'Sh404sefTable');
     // now bind incoming data to table row
     if (!$row->bind($this->_data)) {
         $this->setError($row->getError());
         return 0;
     }
     // pre-save checks
     if (!$row->check()) {
         $this->setError($row->getError());
         return 0;
     }
     // must load cache from disk, so that it can be written back later, with new url
     require_once JPATH_ROOT . '/components/com_sh404sef/shCache.php';
     shLoadURLCache();
     // find if we are adding a custom or automatic url
     $urlType = $row->dateadd == '0000-00-00' ? sh404SEF_URLTYPE_AUTO : sh404SEF_URLTYPE_CUSTOM;
     // override with user supplied
     if (!empty($type)) {
         $urlType = $type;
     }
     // adjust date added field if needed
     if ($urlType == sh404SEF_URLTYPE_CUSTOM) {
         $row->dateadd = date("Y-m-d");
     }
     // if custom url, and no language string, let's add default one
     if ($urlType == sh404SEF_URLTYPE_CUSTOM && !preg_match('/(&|\\?)lang=[a-zA-Z]{2,3}/iU', $row->newurl)) {
         $shTemp = explode('-', shGetDefaultLang());
         $shLangTemp = $shTemp[0] ? $shTemp[0] : 'en';
         $row->newurl .= '&lang=' . $shLangTemp;
     }
     // normalize the non-sef url representation, sorting query parts alphabetically
     $row->newurl = shSortUrl($row->newurl);
     // retrieve previous values of sef and non sef urls
     $previousSefUrl = JRequest::getVar('previousSefUrl', null, 'POST');
     $previousNonSefUrl = JRequest::getVar('previousNonSefUrl', null, 'POST');
     // if both were set, and nothing has changed, then nothing to do
     if (!empty($previousSefUrl) && !empty($previousNonSefUrl) && $previousNonSefUrl == $row->newurl && $previousSefUrl == $row->oldurl) {
         // nothing changed ! must be changing meta or aliases
         $this->_url = $row;
         return $row->id;
     }
     // search DB for urls pairs with same SEF url
     $query = 'SELECT * FROM #__redirection WHERE oldurl = ' . $this->_db->Quote($row->oldurl) . ' ORDER BY rank ASC';
     $this->_db->setQuery($query);
     $dbUrlList = $this->_db->loadObjectList();
     // do we have urls in the db with same SEF ?
     if (count($dbUrlList) > 0) {
         // yes we do
         // get config object
         $sefConfig = shRouter::shGetConfig();
         if (!$sefConfig->shRecordDuplicates) {
             // we don't allow duplicates : reject this URL
             $this->setError(COM_SH404SEF_DUPLICATE_NOT_ALLOWED);
         } else {
             // same SEF, but we allow duplicates
             $existingRecord = null;
             // importing meta data for instance
             foreach ($dbUrlList as $urlInDB) {
                 // same SEF, but is the incoming non-sef in this list of URl with same SEF ?
                 if ($urlInDB->newurl == $row->newurl) {
                     $existingRecord = $urlInDB;
                     $this->setError(COM_SH404SEF_URLEXIST);
                 }
             }
             if (empty($existingRecord)) {
                 // this new non-sef does not already exists
                 $shTemp = array('nonSefURL' => $row->newurl);
                 // which means we must update the record for the old non-sef url
                 Sh404sefHelperCache::removeURLFromCache($shTemp);
                 // remove the old url from cache
                 // then find new rank (as we are adding a duplicate, we add it at the end of the duplicate list)
                 // but only if not importing. When importing, rank is already set
                 if (!$importing) {
                     $row->rank = $dbUrlList[count($dbUrlList) - 1]->rank + 1;
                 }
                 // store will create a new record if id=0, or update existing if id non 0
                 $row->store();
                 // put custom URL in DB and cache
                 Sh404sefHelperCache::addSefUrlToCache($row->newurl, $row->oldurl, $urlType);
                 // we must add the previous SEF url to the alias list, only if
                 //   - not already there
                 //   - this sef url does not already exists in the DB; which will happen if the url
                 //     being saved was customized and also had duplicates
                 // TODO this code is duplicated just a few line below, need refactoring
                 if (!empty($previousSefUrl) && strpos($this->_data['shAliasList'], $previousSefUrl) === false) {
                     // check if not already a valid SEF url in the DB
                     $query = 'SELECT count(id) FROM #__redirection WHERE oldurl = ' . $this->_db->Quote($previousSefUrl);
                     $this->_db->setQuery($query);
                     $isThere = $this->_db->loadResult();
                     if (empty($isThere)) {
                         $this->_data['shAliasList'] .= $previousSefUrl . "\n";
                     }
                 }
             } else {
                 // there is already a record with both this sef and non sef.
                 // just do nothing but return success (ie: record id).
                 // Later, controller may store new aliases or metas
                 // This should never happen when saving regular data as we added
                 // a check for this case earlier
                 // May happen when importing though
                 $this->_url = $row;
                 return $row->id;
             }
             // additional step : if we are here, it may be because we have modified
             // an existing url, and specifically changed it sef value to something else
             // Now it may be that this record was the one with rank = 0 in a series
             // of duplicate urls. If so, the urls which was ranked above must now become
             // the main url, having rank = 0
             // note : when importing, we don't enter this test as previousSefUrl is empty
             // TODO this code is duplicated just a few line below, need refactoring
             if (!empty($previousSefUrl) && $previousSefUrl != $row->newurl) {
                 // search for the old #2 record in duplicate list
                 $query = 'SELECT id FROM #__redirection WHERE oldurl = ' . $this->_db->Quote($previousSefUrl) . ' ORDER BY rank ASC';
                 $this->_db->setQuery($query);
                 $previousRanked2 = $this->_db->loadObject();
                 // there was more than one duplicate in the same series, promote #2 to top spot
                 if (!empty($previousRanked2)) {
                     $query = 'UPDATE #__redirection SET rank="0" WHERE id = ' . $this->_db->Quote($previousRanked2->id);
                     $this->_db->setQuery($query);
                     $this->_db->query();
                 }
             }
         }
     } else {
         // there is no URL with same SEF URL, we are customizing an existing SEF url
         $shTemp = array('nonSefURL' => $row->newurl);
         Sh404sefHelperCache::removeURLFromCache($shTemp);
         // remove it from cache
         // simply store URL. If there is already one with same non-sef, this will raise an error in store()
         // as we don't allow creating a custom url for an already existing non-sef. User should
         // directly edit the existing non-sef/sef pair
         if (!$row->check()) {
             $this->setError($row->getError());
             return 0;
         }
         if (!$row->store()) {
             $this->setError($row->getError());
             return 0;
         }
         // add also to cache if saved to db
         Sh404sefHelperCache::addSefUrlToCache($row->newurl, $row->oldurl, $urlType);
         // we must add the previous SEF url to the alias list, only if
         //   - not already there
         //   - this sef url does not already exists in the DB; which will happen if the url
         //     begin saved was customized and also had duplicates
         // note : when importing, we don't enter this test as previousSefUrl is empty
         // TODO this code is duplicated just a few line above, need refactoring
         if (!empty($previousSefUrl) && strpos($this->_data['shAliasList'], $previousSefUrl) === false) {
             // check if not already a valid SEF url in the DB
             $query = 'SELECT count(id) FROM #__redirection WHERE oldurl = ' . $this->_db->Quote($previousSefUrl);
             $this->_db->setQuery($query);
             $isThere = $this->_db->loadResult();
             if (empty($isThere)) {
                 $this->_data['shAliasList'] .= $previousSefUrl . "\n";
             }
         }
         // finally, also check db for urls with same sef as previous SEF if any. We need
         // to search for the first duplicate of this old sef, and set it to be
         // the new main url
         // note : when importing, we don't enter this test as previousSefUrl is empty
         // TODO this code is duplicated just a few line above, need refactoring
         if (!empty($previousSefUrl) && $previousSefUrl != $row->newurl) {
             // search for the old #2 record in duplicate list
             $query = 'SELECT id FROM #__redirection WHERE oldurl = ' . $this->_db->Quote($previousSefUrl) . ' ORDER BY rank ASC';
             $this->_db->setQuery($query);
             $previousRanked2 = $this->_db->loadObject();
             // there was more than one duplicate in the same series, promote #2 to top spot
             if (!empty($previousRanked2)) {
                 $query = 'UPDATE #__redirection SET rank="0" WHERE id = ' . $this->_db->Quote($previousRanked2->id);
                 $this->_db->setQuery($query);
                 $this->_db->query();
             }
         }
     }
     // store saved url object
     $this->_url = $row;
     // return what should be a non-zero id
     return $this->_url->id;
 }
Exemple #21
0
 /**
  * Due to the fact that SH404 doesn't rewrite urls from the back end, we need to check if they exist
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public static function isSh404Enabled()
 {
     $file = JPATH_ADMINISTRATOR . '/components/com_sh404sef/sh404sef.class.php';
     $enabled = false;
     if (defined('sh404SEF_AUTOLOADER_LOADED') && JFile::exists($file)) {
         require_once $file;
         if (class_exists('shRouter')) {
             $sh404Config = shRouter::shGetConfig();
             if ($sh404Config->Enabled) {
                 $enabled = true;
             }
         }
     }
     return $enabled;
 }
 /**
  * Create sh404SEF URLs
  *
  * @copyright
  * @author 		RolandD
  * @todo
  * @see 		http://dev.anything-digital.com/sh404SEF/
  * @see			getSiteRoute()
  * @access 		private
  * @param 		string	$url	the original URL to turn into SEF
  * @return 		string SEF URL
  * @since 		3.0
  */
 private function _sh404Sef($url)
 {
     // Load sh404SEF
     require_once JPATH_ADMINISTRATOR . '/components/com_sh404sef/sh404sef.class.php';
     $sefConfig = shRouter::shGetConfig();
     // Turn off any security and flooding setting
     $sefConfig->shSecEnableSecurity = 0;
     $sefConfig->shSecActivateAntiFlood = 0;
     // Require some necessary files
     require_once JPATH_ROOT . '/components/com_sh404sef/shCache.php';
     require_once JPATH_ROOT . '/components/com_sh404sef/shSec.php';
     // Start the sh404sef Router
     if (class_exists('shRouter')) {
         $shRouter = new shRouter();
     } else {
         return $this->_domainname . '/' . $url;
     }
     // Force the domain name
     $GLOBALS['shConfigLiveSite'] = $this->_domainname;
     // Initialize sh404sef
     include_once JPATH_ROOT . '/components/com_sh404sef/shInit.php';
     // Build the SEF URL
     $uri = $shRouter->build($url);
     $sefurl = $uri->toString();
     if (strpos($sefurl, 'http://') === false) {
         $sefurl = str_ireplace('http:/', 'http://', $sefurl);
     }
     return $sefurl;
 }
Exemple #23
0
 function &_createURI($url)
 {
     // prevent double Itemid param
     $itemid = shGetURLVar($url, 'Itemid');
     $i = intval($itemid);
     if (!empty($itemid) && (string) $i != $itemid) {
         $tmp = '?Itemid=' . $i;
         $url = str_replace($tmp . $tmp, $tmp, $url);
     }
     //Create the URI
     $uri =& parent::_createURI($url);
     // Get the itemid form the URI
     $itemid = $uri->getVar('Itemid');
     if (is_null($itemid)) {
         if ($option = $uri->getVar('option')) {
             $menu =& shRouter::shGetMenu();
             $item = $menu->getItem($itemid);
             if (isset($item) && $item->component == $option) {
                 $uri->setVar('Itemid', $item->id);
             }
         } else {
             if ($option = $this->getVar('option')) {
                 $uri->setVar('option', $option);
             }
             if ($itemid = $this->getVar('Itemid')) {
                 $uri->setVar('Itemid', $itemid);
             }
         }
     } else {
         if (!$uri->getVar('option')) {
             $menu =& shRouter::shGetMenu();
             $item = $menu->getItem($itemid);
             $uri->setVar('option', $item->component);
         }
     }
     return $uri;
 }
Exemple #24
0
 /**
  * Check if user set parameters and request
  * data allow inserting tracking snippet
  */
 protected function _shouldInsertSnippet()
 {
     // get config
     $sefConfig =& shRouter::shGetConfig();
     // check if we have a tracking code, no need to insert snippet if no tracking code
     if (empty($sefConfig->analyticsId)) {
         return false;
     }
     // check if we are set to include tracking code for current user
     $user = JFactory::getUser();
     if (!empty($sefConfig->analyticsMaxUserLevel) && $sefConfig->analyticsMaxUserLevel != 'Public Frontend' && Sh404sefHelperGeneral::compareGroups($user->usertype, $sefConfig->analyticsMaxUserLevel) == 1) {
         return false;
     }
     // check if current IP is on exclusion list
     if (!empty($sefConfig->analyticsExcludeIP)) {
         $ip = empty($_SERVER['REMOTE_ADDR']) ? '' : $_SERVER['REMOTE_ADDR'];
         $exclude = Sh404sefHelperGeneral::checkIPList($ip, $sefConfig->analyticsExcludeIP);
         if ($exclude) {
             return false;
         }
     }
     return true;
 }
Exemple #25
0
<?php

defined('_JEXEC') or die('Restricted access');
/* ------------------------------------------------------------------------
 * Bang2Joom Contact for Joomla 3.0+
 * ------------------------------------------------------------------------
 * Copyright (C) 2011-2013 Bang2Joom. All Rights Reserved.
 * Fork of Fox Contact by Fox Joomla Extensions
 * @license - GNU/GPL, http://www.gnu.org/licenses/gpl.html
 * Author: Bang2Joom
 * Websites: http://www.bang2joom.com
  ------------------------------------------------------------------------
 */
global $sh_LANG;
$sefConfig =& shRouter::shGetConfig();
$shLangName = '';
$shLangIso = '';
$title = array();
$shItemidString = '';
$dosef = shInitializePlugin($lang, $shLangName, $shLangIso, $option);
if ($dosef == false) {
    return;
}
if (isset($Itemid)) {
    shRemoveFromGETVarsList('Itemid');
} else {
    $Itemid = null;
}
shRemoveFromGETVarsList('lang');
shRemoveFromGETVarsList('option');
shRemoveFromGETVarsList('bid');
Exemple #26
0
 function getcategories($catid, $shLang = null, $section = '')
 {
     $sefConfig =& shRouter::shGetConfig();
     $catid = empty($catid) ? 0 : intval($catid);
     // get DB
     $database =& JFactory::getDBO();
     $title = '';
     // V 1.2.4.q
     $shLang = empty($shLang) ? $shMosConfig_locale : $shLang;
     if (isset($catid) && $catid != 0) {
         $query = 'SELECT title' . (shTranslateURL('com_content', $shLang) ? ',id' : '') . ' FROM #__categories WHERE id = "' . $catid . '"' . (empty($section) ? '' : ' AND section = \'' . $section . '\'');
         $database->setQuery($query);
         $rows = $database->loadObjectList();
         if ($database->getErrorNum()) {
             die($database->stderr());
         } elseif (@count($rows) > 0) {
             if (!empty($rows[0]->title)) {
                 $title = $rows[0]->title;
             }
         }
     }
     return $title;
 }
Exemple #27
0
function shRemoveURLFromCache($nonSefURLList)
{
    global $shURLMemCache, $shURLDiskCache, $shURLTotalCount;
    $sefConfig =& shRouter::shGetConfig();
    if (!$sefConfig->shUseURLCache || empty($nonSefURLList)) {
        return null;
    }
    $foundInDiskCache = false;
    $foundInMemCache = false;
    foreach ($nonSefURLList as $nonSefURL) {
        if (!empty($shURLMemCache)) {
            foreach ($shURLMemCache as $key => $cacheItem) {
                // look up in memory cache
                $tmp = explode('#', $cacheItem);
                $cacheNonSef = html_entity_decode($tmp[0], ENT_QUOTES);
                if ($cacheNonSef == $nonSefURL) {
                    unset($shURLMemCache[$key]);
                    $shURLTotalCount--;
                    $foundInMemCache = true;
                }
            }
        }
        if (!empty($shURLDiskCache)) {
            foreach ($shURLDiskCache as $key => $cacheItem) {
                // look up disk cache
                $tmp = explode('#', $cacheItem);
                $cacheNonSef = html_entity_decode($tmp[0], ENT_QUOTES);
                if ($cacheNonSef == $nonSefURL) {
                    unset($shURLDiskCache[$key]);
                    $shURLTotalCount--;
                    $foundInDiskCache = true;
                }
            }
        }
    }
    if ($foundInMemCache) {
        $shURLMemCache = array_values($shURLMemCache);
        // simply reindex mem cache
        return;
    }
    if ($foundInDiskCache) {
        // we need to remove these url from the disk cache file
        // to make it simpler, I simply rewrite the complete file
        $shURLMemCache = empty($shURLMemCache) ? array_values($shURLDiskCache) : array_merge($shURLDiskCache, $shURLMemCache);
        $shURLDiskCache = array();
        // don't need disk cache anymore, as all URL are in mem cache
        // so we remove both on disk cache and in memory copy of on disk cache
        $cacheFile = sh404SEF_FRONT_ABS_PATH . 'cache/shCacheContent.php';
        if (file_exists($cacheFile)) {
            unlink($cacheFile);
        }
        // no need to write new URL list in disk file, as this will be done automatically at shutdown
    }
}
Exemple #28
0
 function vmSefGetProductName($productId, $option, $shLangName, $shLangIso)
 {
     if (empty($productId)) {
         return null;
     }
     global $sh_LANG;
     $sefConfig =& shRouter::shGetConfig();
     // get DB
     $database =& JFactory::getDBO();
     $q = "SELECT product_id, product_sku, product_name FROM #__vm_product";
     // then try to add its name as well
     $q .= "\n WHERE product_id = " . $database->Quote($productId);
     $database->setQuery($q);
     if (!shTranslateUrl($option, $shLangName)) {
         $row = $database->loadObject(false);
     } else {
         $row = $database->loadObject();
     }
     if (empty($row)) {
         // non name available
         return $sh_LANG[$shLangIso]['_PHPSHOP_PRODUCT'] . $sefConfig->replacement . $product_id;
     }
     $shName = '';
     if ($sefConfig->shInsertProductId) {
         $shName .= $row->product_id;
     }
     if ($sefConfig->shVmUseProductSKU) {
         $shName .= (empty($shName) ? '' : $sefConfig->replacement) . $row->product_sku;
     }
     if ($sefConfig->shVmInsertProductName) {
         $shName .= (empty($shName) ? '' : $sefConfig->replacement) . $row->product_name;
     }
     if (empty($shName)) {
         $shName = $row->product_name;
     }
     return $shName;
 }
Exemple #29
0
 /**
  * Handle processing of some special parts of configuration
  * will be removed when moving to DB backed config
  *
  * @param string $key
  * @param string $value
  */
 private function _advancedConfig($key, $value)
 {
     $sefConfig =& shRouter::shGetConfig();
     if (strpos($key, "com_") !== false) {
         // V 1.2.4.m
         $key = str_replace('com_', '', $key);
         $param = explode('___', $key);
         switch ($param[1]) {
             case 'manageURL':
                 switch ($value) {
                     case 1:
                         array_push($sefConfig->nocache, $param[0]);
                         break;
                     case 2:
                         array_push($sefConfig->skip, $param[0]);
                         break;
                 }
                 break;
             case 'translateURL':
                 if ($value == 1) {
                     array_push($sefConfig->notTranslateURLList, $param[0]);
                 }
                 break;
             case 'insertIsoCode':
                 if ($value == 1) {
                     array_push($sefConfig->notInsertIsoCodeList, $param[0]);
                 }
                 break;
             case 'shDoNotOverrideOwnSef':
                 if ($value == 1) {
                     array_push($sefConfig->shDoNotOverrideOwnSef, $param[0]);
                 }
                 break;
             case 'compEnablePageId':
                 if ($value == 1) {
                     array_push($sefConfig->compEnablePageId, $param[0]);
                 }
                 break;
             case 'defaultComponentString':
                 $cleanedUpValue = empty($value) ? '' : titleToLocation($value);
                 $cleanedUpValue = JString::trim($cleanedUpValue, $sefConfig->friendlytrim);
                 $sefConfig->defaultComponentStringList[$param[0]] = $cleanedUpValue;
                 break;
         }
     } else {
         switch ($key) {
             case 'shSecOnlyNumVars':
                 $this->_shSetArrayParam($value, $sefConfig->shSecOnlyNumVars);
                 break;
             case 'shSecAlphaNumVars':
                 $this->_shSetArrayParam($value, $sefConfig->shSecAlphaNumVars);
                 break;
             case 'shSecNoProtocolVars':
                 $this->_shSetArrayParam($value, $sefConfig->shSecNoProtocolVars);
                 break;
         }
         if (preg_match('/languages_([a-zA-Z]{2}-[a-zA-Z]{2})_translateURL/U', $key, $matches)) {
             $sefConfig->shLangTranslateList[$matches[1]] = $value;
         }
         if (preg_match('/languages_([a-zA-Z]{2}-[a-zA-Z]{2})_insertCode/U', $key, $matches)) {
             $sefConfig->shLangInsertCodeList[$matches[1]] = $value;
         }
         if (preg_match('/languages_([a-zA-Z]{2}-[a-zA-Z]{2})_pageText/U', $key, $matches)) {
             $sefConfig->pageTexts[$matches[1]] = $value;
         }
     }
 }
function shComputeItemidString( $nonSefUrl, &$title, $shLangName) {


  $sefConfig = & shRouter::shGetConfig();

  $shHomePageFlag = shIsHomepage ($nonSefUrl);

  if (!$shHomePageFlag) {
    // we may have found that this is homepage, so we msut return an empty string
    // do something about that Itemid thing
    if (!preg_match( '/Itemid=[0-9]+/i', $nonSefUrl)) {
      // if no Itemid in non-sef URL
      // V 1.2.4.t moved back here
      $shCurrentItemid = JRequest::getInt( 'Itemid');
      if ($sefConfig->shInsertGlobalItemidIfNone && !empty($shCurrentItemid)) {
        $nonSefUrl .= '&Itemid='.$shCurrentItemid; ;  // append current Itemid
        $Itemid = $shCurrentItemid;
        shAddToGETVarsList('Itemid', $Itemid); // V 1.2.4.m
      }

      $shItemidString = '';
      if ($sefConfig->shAlwaysInsertItemid && (!empty($Itemid) || !empty($shCurrentItemid))) {
        $shItemidString = JText::_('COM_SH404SEF_ALWAYS_INSERT_ITEMID_PREFIX').$sefConfig->replacement
        .(empty($Itemid)? $shCurrentItemid :$Itemid);
      }
    } else {  // if Itemid in non-sef URL
      $shItemidString = $sefConfig->shAlwaysInsertItemid ?
      JText::_('COM_SH404SEF_ALWAYS_INSERT_ITEMID_PREFIX').$sefConfig->replacement . shGetURLVar($nonSefUrl, 'Itemid')
      : '';
    }

  }

  return $shItemidString;
}