Exemple #1
0
 public function display($tpl = null)
 {
     // version prefix
     $this->joomlaVersionPrefix = Sh404sefHelperGeneral::getJoomlaVersionPrefix();
     // get model and update context with current
     $model = ShlMvcModel_Base::getInstance('urls', 'Sh404sefModel');
     $context = $model->setContext($this->_context . '.' . $this->getLayout());
     // display type: simple for very large sites/slow slq servers
     $sefConfig = Sh404sefFactory::getConfig();
     // store it
     $model = $this->setModel($model, true);
     // read data from model
     $list = $model->getList((object) array('layout' => $this->getLayout(), 'getMetaData' => true, 'simpleUrlList' => true, 'slowServer' => $sefConfig->slowServer));
     // and push it into the view for display
     $this->assign('items', $list);
     $this->assign('itemCount', count($this->items));
     $this->assign('contentcs', Sh404sefHelperGeneral::getDataMD5($this->items, array('metatitle', 'metadesc')));
     $this->assign('pagination', $model->getPagination((object) array('layout' => $this->getLayout(), 'simpleUrlList' => true, 'slowServer' => $sefConfig->slowServer)));
     $options = $model->getDisplayOptions();
     $this->assign('options', $options);
     $this->assign('helpMessage', JText::_('COM_SH404SEF_META_HELP'));
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $document = JFactory::getDocument();
         // add our own css and js
         JHtml::styleSheet(Sh404sefHelperGeneral::getComponentUrl() . '/assets/css/' . $this->joomlaVersionPrefix . '_list.css');
         JHtml::script(Sh404sefHelperGeneral::getComponentUrl() . '/assets/js/shajax.js');
         JHtml::script(Sh404sefHelperGeneral::getComponentUrl() . '/assets/js/j3.js');
         // add modal css and js
         ShlHtmlBs_helper::addBootstrapCss(JFactory::getDocument());
         ShlHtmlBs_helper::addBootstrapJs(JFactory::getDocument());
         // variable for modal, not used in 3..x+
         $params = array();
         $this->_addFilters();
         // render submenu sidebar
         $this->sidebar = Sh404sefHelperHtml::renderSubmenu();
     } else {
         // add our own css
         JHtml::styleSheet(Sh404sefHelperGeneral::getComponentUrl() . '/assets/css/' . $this->joomlaVersionPrefix . '_urls.css');
         // link to  custom javascript
         JHtml::script(Sh404sefHelperGeneral::getComponentUrl() . '/assets/js/list.js');
         JHtml::script(Sh404sefHelperGeneral::getComponentUrl() . '/assets/js/metas.js');
         // add behaviors and styles as needed
         $modalSelector = 'a.modalediturl';
         $js = '\\function(){window.parent.shAlreadySqueezed = false;if(window.parent.shReloadModal) {parent.window.location=\'' . $this->defaultRedirectUrl . '\';window.parent.shReloadModal=true}}';
         $params = array('overlayOpacity' => 0, 'classWindow' => 'sh404sef-popup', 'classOverlay' => 'sh404sef-popup', 'onClose' => $js);
         Sh404sefHelperHtml::modal($modalSelector, $params);
         $this->assign('optionsSelect', $this->_makeOptionsSelect($options));
         // add our own css
         JHtml::styleSheet(Sh404sefHelperGeneral::getComponentUrl() . '/assets/css/list.css');
     }
     // build the toolbar
     $toolbarMethod = '_makeToolbar' . ucfirst($this->getLayout() . ucfirst($this->joomlaVersionPrefix));
     if (is_callable(array($this, $toolbarMethod))) {
         $this->{$toolbarMethod}($params);
     }
     // now display normally
     parent::display($this->joomlaVersionPrefix);
 }
 /**
  * Creates a record in the database, based
  * on data read from import file
  *
  * @param array $header an array of fields, as built from the header line
  * @param string $line raw record obtained from import file
  */
 protected function _createRecord($header, $line)
 {
     // extract the record
     $line = $this->_lineToArray(trim($line));
     // get table object to store record
     $model = ShlMvcModel_Base::getInstance('metas', 'Sh404sefModel');
     // bind table to current record
     $record = array();
     $record['newurl'] = $line[1];
     $record['metatitle'] = $line[4];
     $record['metadesc'] = $line[2];
     $record['metakey'] = $line[3];
     $record['metalang'] = $line[5];
     $record['metarobots'] = $line[6];
     // clean up records
     foreach ($record as $key => $value) {
         if ($value == '&nbsp') {
             $record[$key] = '';
         }
     }
     // find if there is already an url record for this non-sef url. If so
     // we want the imported record to overwrite the existing one.
     // while makinf sure we're doing that with the main url, not one of the duplicates
     $existingRecords = $model->getByAttr(array('newurl' => $record['newurl']));
     if (!empty($existingRecords)) {
         $existingRecord = $existingRecords[0];
         // getByAttr always returns an array
         // use the existing id, this will be enought to override existing record when saving
         $record['id'] = $existingRecord->id;
         // ensure consistency : delete the remaining records, though there is no reason
         // there can be more than one record with same SEF AND same SEF
         array_shift($existingRecords);
         if (!empty($existingRecords)) {
             ShlDbHelper::deleteIn('#__sh404sef_metas', 'id', $existingRecords, ShlDbHelper::INTEGER);
         }
     } else {
         $record['id'] = 0;
     }
     // save record : returns the record id, so failure is when 0 is returned
     $status = $model->save($record);
     if (!$status) {
         // rethrow a more appropriate error message
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_IMPORT_ERROR_INSERTING_INTO_DB', $line[0]));
     }
 }
Exemple #3
0
 public static function updateSecStats()
 {
     $shNum = 12 * (intval(date('Y')) - 2000) + intval(date('m'));
     $shFileName = JPATH_ROOT . '/logs/sh404sef/sec/log_' . date('Y') . '-' . date('m') . '-sh404SEF_security_log.' . $shNum . '.log.php';
     $fileIsThere = file_exists($shFileName) && is_readable($shFileName);
     self::_shResetSecStats();
     if ($fileIsThere) {
         self::_shReadSecStatsFromFile($shFileName);
     }
     self::$_counters['shSecCurMonth'] = date('M') . '-' . date('Y');
     self::$_counters['shSecLastUpdated'] = time();
     // get a configuration model object
     $model = ShlMvcModel_Base::getInstance('configuration', 'Sh404sefModel');
     if (is_callable(array($model, 'save'))) {
         $model->setValues(self::$_counters);
         // update in memory config object
         $sefConfig =& Sh404sefFactory::getConfig(true);
     }
 }
Exemple #4
0
 /**
  * Creates a record in the database, based
  * on data read from import file
  *
  * @param array $header an array of fields, as built from the header line
  * @param string $line raw record obtained from import file
  */
 protected function _createRecord($header, $line)
 {
     // extract the record
     $line = $this->_lineToArray($line);
     // get table object to store record
     $model = ShlMvcModel_Base::getInstance('aliases', 'Sh404sefModel');
     // bind table to current record
     $record = array();
     $record['newurl'] = $line[3];
     if ($record['newurl'] == '__ Homepage __') {
         $record['newurl'] = sh404SEF_HOMEPAGE_CODE;
     }
     $record['alias'] = $line[1];
     $record['type'] = $line[4];
     // find if there is already same alias record for this non-sef url. If so
     // we want the imported record to overwrite the existing one.
     $existingRecords = $model->getByAttr(array('newurl' => $record['newurl'], 'alias' => $record['alias']));
     if (!empty($existingRecords)) {
         $existingRecord = $existingRecords[0];
         // getByAttr always returns an array
         // use the existing id, this will be enought to override existing record when saving
         $record['id'] = $existingRecord->id;
         // ensure consistency : delete the remaining records, though there is no reason
         // there can be more than one record with same alias AND same SEF
         array_shift($existingRecords);
         if (!empty($existingRecords)) {
             ShlDbHelper::deleteIn('#__sh404sef_aliases', 'id', $existingRecords, ShlDbHelper::INTEGER);
         }
     }
     // save record : returns the record id, so failure is when 0 is returned
     $saveId = $model->save($record);
     if (empty($saveId)) {
         // rethrow a more appropriate error message
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_IMPORT_ERROR_INSERTING_INTO_DB', $line[0]));
     }
 }
Exemple #5
0
 protected function _export($start)
 {
     // do we have a valid filename
     $this->_filename = Sh404sefHelperFiles::createFileName($this->_filename, 'sh404sef_export_' . $this->_context);
     // put some data in the file
     $end = $start + self::MAX_PAGEIDS_PER_STEP + 1;
     $end = $end > $this->_total ? $this->_total : $end;
     // fetch pageIds record from model
     $model = ShlMvcModel_Base::getInstance('aliases', 'Sh404sefModel');
     $model->setContext('aliases.default');
     $options = (object) array('layout' => 'default', 'includeHomeData' => true);
     $records = $model->getList($options, $returnZeroElement = false, $start, $forcedLimit = self::MAX_PAGEIDS_PER_STEP);
     // do we need a header written to the file, for first record
     $header = $start == 0 ? Sh404sefHelperGeneral::getExportHeaders($this->_context) . "\n" : '';
     // format them for text file output
     $data = '';
     $counter = $start;
     $glue = Sh404sefHelperFiles::$stringDelimiter . Sh404sefHelperFiles::$fieldDelimiter . Sh404sefHelperFiles::$stringDelimiter;
     if (!empty($records)) {
         foreach ($records as $record) {
             $counter++;
             if ($record->newurl == sh404SEF_HOMEPAGE_CODE) {
                 $record->newurl = '__ Homepage __';
             }
             $textRecord = $record->alias . $glue . $record->oldurl . $glue . $record->newurl . $glue . $record->type . $glue . $record->hits . Sh404sefHelperFiles::$stringDelimiter;
             $line = Sh404sefHelperFiles::$stringDelimiter . $counter . $glue . $textRecord;
             $data .= $line . "\n";
         }
     }
     // prepare data for storage
     if (!empty($header)) {
         // first record written to file, prepend header
         $data = $header . $data;
     }
     // store in file
     $status = Sh404sefHelperFiles::appendToFile($this->_filename, $data);
     // return any error
     return $status;
 }
Exemple #6
0
 /**
  *
  * @param  string $url
  * @param  array $title
  * @param  string $task
  * @param  int $limit
  * @param  int $limitstart
  * @return sefurl
  */
 public static function sefGetLocation($nonSefUrl, &$title, $task = null, $limit = null, $limitstart = null, $langParam = null, $showall = null, $suppressPagination = false)
 {
     try {
         $shPageInfo =& Sh404sefFactory::getPageInfo();
         $sefConfig =& Sh404sefFactory::getConfig();
         $lang = empty($langParam) ? $shPageInfo->currentLanguageTag : $langParam;
         // shumisha : try to avoid duplicate content on multilingual sites by always adding &lang=xx to url (stored in DB).
         // warning : must add &lang=xx only if it does not exists already
         if (!strpos($nonSefUrl, 'lang=')) {
             $shSepString = substr($nonSefUrl, -9) == 'index.php' ? '?' : '&';
             $nonSefUrl .= $shSepString . 'lang=' . shGetIsoCodeFromName($lang);
         }
         // make sure url is consistent
         $nonSefUrl = str_replace('&', '&', $nonSefUrl);
         // detect multipage homepage
         $shMultiPageHomePageFlag = shIsHomepage($nonSefUrl);
         // get all the slugs ready for being urls bits
         $tempSefUrl = array();
         foreach ($title as $titlestring) {
             $decodedTitletring = urldecode($titlestring);
             $tempSefUrl[] = titleToLocation($decodedTitletring);
         }
         // now build the URL
         $tempSefUrl = implode("/", $tempSefUrl);
         // remove duplicate /
         $tempSefUrl = ShlSystem_Strings::pr('/\\/{2,}/u', '/', $tempSefUrl);
         // and truncate to max length, according to param
         $tempSefUrl = JString::substr($tempSefUrl, 0, sh404SEF_MAX_SEF_URL_LENGTH);
         // trim to max length V 1.2.4.t
         // if URL is empty, and unless this is a paginated home page, or home page in non-default language, stop there
         if (empty($tempSefUrl)) {
             if ((!shIsMultilingual() || shIsMultilingual() && shIsDefaultlang($lang)) && !$sefConfig->addFile && !$shMultiPageHomePageFlag) {
                 //
                 return '';
             }
             // if location is empty, and not multilingual site, or multilingual, but this is default language, then there is nothing to add to url
         }
         // we have a valid SEF url, built with the data ($title) sent
         // by plugin. Now we want to check if it's already in the db
         // and add it if not
         // first, we search the memory cache for the non-sef url
         // as it is faster than looking up the db
         $finalSefUrl = '';
         $sefUrlType = Sh404sefHelperCache::getSefUrlFromCache($nonSefUrl, $finalSefUrl);
         // if non-sef was not found in cache - or found, but it was a 404 last time we saw it -
         // we should continue and try adding it
         if ($sefUrlType == sh404SEF_URLTYPE_NONE || $sefUrlType == sh404SEF_URLTYPE_404) {
             $finalSefUrl = false;
             // non-sef was not found in cache, let's look up the database
             if ($sefUrlType == sh404SEF_URLTYPE_NONE) {
                 $finalSefUrl = ShlDbHelper::selectResult('#__sh404sef_urls', 'oldurl', array('newurl' => $nonSefUrl));
             }
             // we found the sef url in database, we're done
             if (!empty($finalSefUrl)) {
                 return $finalSefUrl;
             }
             // the non-sef url is not in memory cache, nor in database
             // that's a new one, we need to finalize its sef (add pagination and language information)
             // After finalizing it, we'll also check that sef is not in the db
             // as it can already be there, associated with another non-sef (ie: a duplicate)
             // Either way we'll add it in the db, but mark it as a duplicate if needed
             // add pagination information, unless we were instructed by extension plugin not to
             // find if we should separate pagination info from sef with a / or not
             if (!empty($tempSefUrl)) {
                 $shSeparator = JString::substr($tempSefUrl, -1) == '/' ? '' : '/';
             } else {
                 $shSeparator = '';
             }
             $finalSefUrl = $suppressPagination ? $tempSefUrl : shAddPaginationInfo($limit, $limitstart, $showall, 1, $nonSefUrl, $tempSefUrl, $shSeparator);
             // v 1.2.4.t
             // if home page, we don't record anything, just return "home page"
             if ($shMultiPageHomePageFlag && '/' . $finalSefUrl == $tempSefUrl && (!shIsMultilingual() || shIsMultilingual() && shIsDefaultLang($lang))) {
                 // but this is default language
                 // this is start page of multipage homepage, return home or forced home
                 if (!empty($sefConfig->shForcedHomePage)) {
                     return str_replace($shPageInfo->getDefaultFrontLiveSite() . '/', '', $sefConfig->shForcedHomePage);
                 } else {
                     return '';
                 }
             }
             // add language information
             // first, remove languages in non-sef, to see if we're on homepage
             // as handling is sligthly different for homepage
             $v1 = shCleanUpLang($nonSefUrl);
             $v2 = shCleanUpLang($shPageInfo->homeLink);
             if ($v1 == $v2 || $v1 == 'index.php') {
                 // check if this is homepage
                 if (shIsMultilingual() && !shIsDefaultLang($lang)) {
                     // if homepage in not-default-language, then add language code regardless of user settings
                     // as we otherwise would not be able to switch language on the frontpage
                     $finalSefUrl = shGetIsoCodeFromName($lang) . '/';
                 } else {
                     $finalSefUrl = '';
                 }
             } else {
                 // not on homepage, insert lang code based on user setting
                 $option = shGetURLVar($nonSefUrl, 'option', '');
                 if (shInsertIsoCodeInUrl($option, $lang)) {
                     // insert language code based on param
                     // pass URL lang info, as may not be current lang
                     $finalSefUrl = shGetIsoCodeFromName($lang) . '/' . $finalSefUrl;
                     //  must be forced lang, not default
                 }
             }
             // after adding pagination part of SEF, and adding language code
             // the new SEF url is now complete and we can try adding to it cache and db
             if ($finalSefUrl != '') {
                 $dburl = null;
                 $dbUrlId = null;
                 $nonSefUrlType = sh404SEF_URLTYPE_NONE;
                 // search the memory cache for this new sef
                 if ($sefConfig->shUseURLCache) {
                     $nonSefUrlType = Sh404sefHelperCache::getNonSefUrlFromCache($finalSefUrl, $dburl);
                 }
                 $newMaxRank = 0;
                 // if the new SEF was not found in memory cache, or if it was found but
                 // we're set to record duplicates, we search for it in the database
                 if ($sefConfig->shRecordDuplicates || $nonSefUrlType == sh404SEF_URLTYPE_NONE) {
                     $dbUrlList = ShlDbHelper::selectObjectList('#__sh404sef_urls', array('id', 'newurl', 'rank', 'dateadd'), array('oldurl' => $finalSefUrl), $aWhereData = array(), $orderBy = array('rank'));
                     if (count($dbUrlList) > 0) {
                         $dburl = $dbUrlList[0]->newurl;
                         $dbUrlId = $dbUrlList[0]->id;
                         if (empty($dburl)) {
                             // V 1.2.4.t url was found in DB, but was a 404
                             $nonSefUrlType = sh404SEF_URLTYPE_404;
                         } else {
                             $newMaxRank = $dbUrlList[count($dbUrlList) - 1]->rank + 1;
                             $nonSefUrlType = $dbUrlList[0]->dateadd == '0000-00-00' ? sh404SEF_URLTYPE_AUTO : sh404SEF_URLTYPE_CUSTOM;
                         }
                     }
                 }
                 if ($nonSefUrlType != sh404SEF_URLTYPE_NONE && $nonSefUrlType != sh404SEF_URLTYPE_404) {
                     // we found the SEF, one or more times in the db, in records which do have a non-sef attached
                     $isDuplicate = $dburl != $nonSefUrl;
                     // This is a duplicate so we must indert it with incremented rank;
                     if (is_null($dburl) || $isDuplicate && $sefConfig->shRecordDuplicates) {
                         // shAddSefUrlToDBAndCache( $nonSefUrl, $finalSefUrl, ($isDuplicate ? $newMaxRank : 0), $nonSefUrlType);
                         $dateAdd = $nonSefUrlType == sh404SEF_URLTYPE_AUTO ? '0000-00-00' : date("Y-m-d");
                         ShlDbHelper::insert('#__sh404sef_urls', array('oldurl' => $finalSefUrl, 'newurl' => $nonSefUrl, 'rank' => $isDuplicate ? $newMaxRank : 0, 'dateadd' => $dateAdd));
                         // store new sef/non-sef pair in memory cache
                         Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $finalSefUrl, $nonSefUrlType);
                         // create shURL : get a shURL model, and ask url creation
                         $model = ShlMvcModel_Base::getInstance('pageids', 'Sh404sefModel');
                         $model->createPageId($finalSefUrl, $nonSefUrl);
                     }
                 } else {
                     // we haven't found the non-sef/sef pair, but maybe there is a record for
                     // a 404 with that SEF. If so, we will "upgrade" the 404 record to a
                     // normal non-sef/sef pair
                     $dbUrlId = empty($dbUrlId) ? 0 : intval($dbUrlId);
                     if ($sefConfig->shLog404Errors) {
                         if ($nonSefUrlType == sh404SEF_URLTYPE_404 && !empty($dbUrlId)) {
                             // we already have seen that it is a 404
                             $id = $dbUrlId;
                         } elseif ($nonSefUrlType == sh404SEF_URLTYPE_404) {
                             $id = ShlDbHelper::selectResult('#__sh404sef_urls', 'id', array('oldurl' => $finalSefUrl, 'newurl' => ''));
                         } else {
                             $id = null;
                         }
                     } else {
                         $id = null;
                         // if we are not logging 404 errors, then no need to check for
                     }
                     // previous hit of this page.
                     if (!empty($id)) {
                         // we found a 404 record matching the SEF url just created. We'll update that record
                         // instead of creating a new one
                         // need to update dateadd to 0, as otherwise this sef/non-sef pair will be seen as custom
                         // this makes all such 404 errors 'disappear' from the 404 log, but no other solution
                         ShlDbHelper::updateIn('#__sh404sef_urls', array('newurl' => $nonSefUrl, 'dateadd' => '0000-00-00'), 'id', array($id));
                         Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $finalSefUrl, sh404SEF_URLTYPE_AUTO);
                     } else {
                         // standard case: creation of a totally new sef/non-sef pair
                         ShlDbHelper::insert('#__sh404sef_urls', array('oldurl' => $finalSefUrl, 'newurl' => $nonSefUrl, 'rank' => 0, 'dateadd' => '0000-00-00'));
                         // store new sef/non-sef pair in memory cache
                         Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $finalSefUrl, sh404SEF_URLTYPE_AUTO);
                         // create shURL : get a shURL model, and ask url creation
                         $model = ShlMvcModel_Base::getInstance('pageids', 'Sh404sefModel');
                         $model->createPageId($finalSefUrl, $nonSefUrl);
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $finalSefUrl = '';
         ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
     }
     return $finalSefUrl;
 }
Exemple #7
0
/**
 * Returns true if current sef url being created can have a shURL
 * Can be set from within a plugin, otherwise default to false
 * Reset to false upon each creation of a new sef url in shInitializePlugin()
 *
 * @param unknown_type $action
 * @param unknown_type $value
 * @return unknown
 */
function shMustCreatePageId($action = 'get', $value = false)
{
    jimport('joomla.application.component.model');
    $model = ShlMvcModel_Base::getInstance('pageids', 'Sh404sefModel');
    $mustCreate = $model->mustCreatePageId($action, $value);
    return $mustCreate;
}
Exemple #8
0
 public function display($tpl = null)
 {
     // version prefix
     $this->joomlaVersionPrefix = Sh404sefHelperGeneral::getJoomlaVersionPrefix();
     // get model and update context with current
     $model = $this->getModel();
     $context = $model->updateContext($this->_context . '.' . $this->getLayout());
     // get url id
     $cid = JRequest::getVar('cid', array(0), 'default', 'array');
     $cid = intval($cid[0]);
     // get home page flag, and make sure id is 0 if editing home data
     $home = JRequest::getInt('home');
     if ($home == 1) {
         $cid = 0;
     }
     $this->assign('home', $home);
     // optional starting pane in case of tabbed edition
     $startOffset = JRequest::getInt('startOffset', 0);
     $this->assign('startOffset', $startOffset);
     // read url data from model
     $url = $model->getById($cid);
     // if editing home, set home url
     if ($this->home == 1) {
         $url->set('newurl', sh404SEF_HOMEPAGE_CODE);
     }
     // controllers may forbid to edit sef or non-sef urls
     $noUrlEditing = empty($this->noUrlEditing) ? false : $this->noUrlEditing;
     $this->assign('noUrlEditing', $noUrlEditing);
     // and push url into the template for display
     $this->assign('url', $url);
     // we only allow editing of non-sef url for new urls, that is when non sef url field is empty
     // of for 404s, when we have a sef but no non-sef
     $newUrl = $url->get('newurl');
     $this->assign('canEditNewUrl', empty($newUrl));
     // are we creating a new url rcord or editing an existing one
     $oldUrl = $url->get('oldurl');
     $existingUrl = !empty($newUrl) || !empty($oldUrl);
     // now read meta for this url, using meta  model
     if ($existingUrl) {
         $metaModel = ShlMvcModel_Base::getInstance('metas', 'Sh404sefModel');
         $metas = $metaModel->getList((object) array('newurl' => $url->get('newurl')), $returnZeroElement = true);
         $meta = $metas[0];
     } else {
         $meta = JTable::getInstance('metas', 'Sh404sefTable');
     }
     $this->assign('meta', $meta);
     // now read aliases for this url, using an aliases model
     if ($existingUrl) {
         $aliasModel = ShlMvcModel_Base::getInstance('aliases', 'Sh404sefModel');
         $aliases = $aliasModel->getDisplayableList((object) array('newurl' => $url->get('newurl')));
     } else {
         $aliases = '';
     }
     $this->assign('aliases', $aliases);
     // now read pageid for this url, using pageid model
     $pageidModel = ShlMvcModel_Base::getInstance('pageids', 'Sh404sefModel');
     $pageids = $pageidModel->getList((object) array('newurl' => $url->get('newurl')), $returnZeroElement = true);
     $this->assign('pageid', $pageids[0]);
     // url used to create QRCode
     $sefConfig = Sh404sefFactory::getConfig();
     $this->qrCodeUrl = JUri::root() . ltrim($sefConfig->shRewriteStrings[$sefConfig->shRewriteMode], '/') . $this->url->get('oldurl');
     // push social seo data
     $this->_pushDataSocial_seo();
     // find active starting panel
     $this->activePanel = $this->_getActiveStartingPanel();
     // add title. If there is an id, we are editing an existing url, or else we create a new one
     // other case : edting home page, there is a specific title
     if ($this->home == 1) {
         $title = JText::_('COM_SH404SEF_HOME_PAGE_EDIT_TITLE');
     } else {
         $title = $url->get('id') ? JText::_('COM_SH404SEF_EDIT_URL_TITLE') : JText::_('COM_SH404SEF_ADD_URL_TITLE');
     }
     if (version_compare(JVERSION, '3.0', 'ge')) {
         // add modal css and js
         ShlHtmlBs_helper::addBootstrapCss(JFactory::getDocument());
         ShlHtmlBs_helper::addBootstrapModalFixCss(JFactory::getDocument());
         ShlHtmlBs_helper::addBootstrapJs(JFactory::getDocument());
         // add title
         JToolbarHelper::title('sh404SEF: ' . $title);
         // prepare layouts objects, to be used by sub-layouts
         $this->layoutRenderer = array();
         $this->layoutRenderer['custom'] = new ShlMvcLayout_File('com_sh404sef.form.fields.custom', sh404SEF_LAYOUTS);
         $this->layoutRenderer['shlegend'] = new ShlMvcLayout_File('com_sh404sef.configuration.fields.legend', sh404SEF_LAYOUTS);
         JHtml::styleSheet(Sh404sefHelperGeneral::getComponentUrl() . '/assets/css/configuration.css');
         JHtml::styleSheet(Sh404sefHelperGeneral::getComponentUrl() . '/assets/css/j3_list.css');
         // add tooltips
         // @TODO replace with a viable jQuery equivalent
         JHTML::_('behavior.tooltip');
     } else {
         // build the toolbar
         $toolBar = $this->_makeToolbar();
         $this->assignRef('toolbar', $toolBar);
         $this->assign('toolbarTitle', Sh404sefHelperGeneral::makeToolbarTitle($title, $icon = 'sh404sef', $class = 'sh404sef-toolbar-title'));
         // add tooltips
         JHTML::_('behavior.tooltip');
         // link to  custom javascript
         JHtml::script(Sh404sefHelperGeneral::getComponentUrl() . '/assets/js/' . $this->joomlaVersionPrefix . '_edit.js');
     }
     // add link to css
     JHtml::styleSheet(Sh404sefHelperGeneral::getComponentUrl() . '/assets/css/' . $this->joomlaVersionPrefix . '_editurl.css');
     // now display normally
     parent::display($this->joomlaVersionPrefix);
 }
Exemple #9
0
 /**
  * Creates a record in the database, based
  * on data read from import file
  *
  * @param array $header an array of fields, as built from the header line
  * @param string $line raw record obtained from import file
  */
 protected function _createRecord($header, $line)
 {
     // extract the record
     $line = $this->_lineToArray($line);
     // get table object to store record
     $model = ShlMvcModel_Base::getInstance('editurl', 'Sh404sefModel');
     // bind table to current record
     $record = array();
     $record['oldurl'] = $line[1];
     $record['newurl'] = $line[2];
     if ($record['newurl'] == '__ Homepage __') {
         $record['newurl'] = sh404SEF_HOMEPAGE_CODE;
     }
     $record['cpt'] = $line[3];
     $record['rank'] = $line[4];
     $record['dateadd'] = $line[5];
     $record['metatitle'] = $line[6];
     $record['metadesc'] = $line[7];
     $record['metakey'] = $line[8];
     $record['metalang'] = $line[9];
     $record['metarobots'] = $line[10];
     // find if there is already an url record for this non-sef url. If so
     // we want the imported record to overwrite the existing one.
     // while makinf sure we're doing that with the main url, not one of the duplicates
     $existingRecords = $model->getByAttr(array('newurl' => $record['newurl'], 'oldurl' => $record['oldurl']));
     if (!empty($existingRecords)) {
         $existingRecord = $existingRecords[0];
         // getByAttr always returns an array
         // use the existing id, this will be enought to override existing record when saving
         $record['id'] = $existingRecord->id;
         // ensure consistency : delete the remaining records, though there is no reason
         // there can be more than one record with same SEF AND same SEF
         array_shift($existingRecords);
         if (!empty($existingRecords)) {
             ShlDbHelper::deleteIn('#__sh404sef_urls', 'id', $existingRecords, ShlDbHelper::INTEGER);
         }
     } else {
         $record['id'] = 0;
     }
     // find if we already have a meta data record for this non-sef url
     // as we want to update it if so, instead of creating a new record
     $metasModel = ShlMvcModel_Base::getInstance('metas', 'Sh404sefModel');
     $existingMetas = $metasModel->getByAttr(array('newurl' => $record['newurl']));
     if (!empty($existingMetas)) {
         $existingMeta = $existingMetas[0];
         // getByAttr always returns an array
         // use the existing id, this will be enought to override existing record when saving
         $record['meta_id'] = $existingMeta->id;
     } else {
         $record['meta_id'] = 0;
     }
     // for aliases, we don't import them here, but we need to create a dummy
     // record so as to preserve possible pre-existing aliases for the same non-sef url
     $aliasesModel = ShlMvcModel_Base::getInstance('editalias', 'Sh404sefModel');
     $existingAliases = $aliasesModel->getByAttr(array('newurl' => $record['newurl']));
     $record['shAliasList'] = '';
     if (!empty($existingAliases)) {
         foreach ($existingAliases as $existingAlias) {
             // build up a text list, just as if we were to edit aliases
             // as this is what the model expect to receive
             $record['shAliasList'] .= $existingAlias->alias . "\n";
         }
     }
     // save record : returns the record id, so failure is when 0 is returned
     $savedId = $model->save($record, sh404SEF_URLTYPE_AUTO);
     if (empty($savedId)) {
         // rethrow a more appropriate error message
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_IMPORT_ERROR_INSERTING_INTO_DB', $line[0]));
     }
 }
Exemple #10
0
 protected static function _createShurl($nonSefUrl)
 {
     if (empty($nonSefUrl)) {
         return '';
     }
     // only create a shURL if current page returns a 200
     $headers = JResponse::getHeaders();
     // check if we have a status
     foreach ($headers as $header) {
         if (strtolower($header['name']) == 'status' && $header['value'] != 200) {
             // error or redirection, don't shurl that
             return '';
         }
     }
     // check various conditions, to avoid overloading ourselves with shURL
     // not on homepage
     if (shIsAnyHomepage($nonSefUrl)) {
         return '';
     }
     // not for format = raw, format = pdf or printing
     $format = shGetURLVar($nonSefUrl, 'format');
     if (in_array(strtolower($format), array('raw', 'pdf'))) {
         return '';
     }
     $print = shGetURLVar($nonSefUrl, 'print');
     if ($print == 1) {
         return '';
     }
     // not if tmpl not empty or not index
     $tmpl = shGetURLVar($nonSefUrl, 'tmpl');
     if (!empty($tmpl) && $tmpl != 'index') {
         return '';
     }
     // force global setting
     shMustCreatePageId('set', true);
     // get a model and create shURL
     $model = ShlMvcModel_Base::getInstance('Pageids', 'Sh404sefModel');
     $shURL = $model->createPageId('', $nonSefUrl);
     return $shURL;
 }
Exemple #11
0
 private function _getPurgeQuerySelected()
 {
     // get model and update context with current
     $model = ShlMvcModel_Base::getInstance('urls', 'Sh404sefModel');
     // use current filters for default layout of shURLs manager
     $context = $model->updateContext($this->_context . '.' . 'default');
     // read url data from model
     $list = $model->getList((object) array('layout' => 'default', 'getPageId' => true));
     $shURLs = array();
     // store meta data records ids for urls with some metat data
     if (!empty($list)) {
         foreach ($list as $urlRecord) {
             $shURLs[] = $this->_db->Quote($urlRecord->pageid, true);
         }
     }
     // if no urls with shURL data, return empty query
     if (empty($shURLs)) {
         return '';
     }
     // start delete query
     $query = 'delete from ' . $this->_db->quoteName($this->_getTableName());
     // call method to build where clause in accordance to current settings and user selection
     $where = implode(', ', $shURLs);
     // stitch where clause
     $query = $query . ' where pageid in (' . $where . ')';
     return $query;
 }
Exemple #12
0
 /**
  * Save aliases entered by user to the db
  * overwriting existing ones
  *
  */
 private function _saveAliases()
 {
     // get an aliases model object
     $model = ShlMvcModel_Base::getInstance('aliases', 'Sh404sefModel');
     // ask it to save the data
     $newUrl = is_object($this->_url) ? $this->_url->newurl : '';
     $status = $model->saveFromInput($this->_data['shAliasList'], $newUrl);
     if (!$status) {
         $this->setError($model->getError());
     }
     return $status;
 }
Exemple #13
0
 /**
  * Returns an object list
  * Overriden to check on respective values
  * of limit and limit start
  * If limit is 0, limitstart should be reset to 0 as well
  *
  * @param string The query
  * @param int Offset
  * @param int The number of records
  * @return  array
  * @access  protected
  * @since 1.5
  */
 protected function _getList($query, $limitstart = 0, $limit = 0)
 {
     // check limit and lim
     $limitstart = $limit === 0 ? 0 : $limitstart;
     // do the job
     $result = parent::_getList($query, $limitstart, $limit);
     return $result;
 }
Exemple #14
0
 protected function _exportHomePageData($start)
 {
     // get data from model
     $model = ShlMvcModel_Base::getInstance('metas', 'Sh404sefModel');
     $model->setContext('metas.default');
     $options = (object) array('layout' => 'default', 'newurl' => sh404SEF_HOMEPAGE_CODE);
     $this->_total += 1;
     $homePageMetaData = $model->getList($options);
     // format them for text file output
     $data = '';
     $counter = $start;
     $glue = Sh404sefHelperFiles::$stringDelimiter . Sh404sefHelperFiles::$fieldDelimiter . Sh404sefHelperFiles::$stringDelimiter;
     if (!empty($homePageMetaData)) {
         foreach ($homePageMetaData as $record) {
             $counter++;
             $record->oldurl = '';
             $record->newurl = '__ Homepage __';
             $data .= $this->_createLine($record, $counter, $glue);
         }
     }
     // prepare data for storage
     if (!empty($header)) {
         // first record written to file, prepend header
         $data = $header . $data;
     }
     // store in file
     $status = Sh404sefHelperFiles::appendToFile($this->_filename, $data);
 }