/** * Make the url with id = $cid the main url * in case of duplicates. Also set the previous * main url as secondary, swapping their rank * * @param integer $cid */ public function makeMainUrl($cid) { // get this url record $newMain = $this->getById($cid); $error = $this->getError(); if (!empty($error)) { return; } // is this already the main url ? if ($newMain->rank == 0) { return; } // now get the current main url $options = array('rank' => 0, 'oldurl' => $newMain->oldurl); $previousMains = $this->getByAttr($options); try { // if we got it, do the swapping if (!empty($previousMains)) { foreach ($previousMains as $previousMain) { Sh404sefHelperDb::update($this->_getTableName(), array('rank' => $newMain->rank), array('id' => $previousMain->id)); // another thing we have to do is attach any meta data to the new // main url, so that they keep showing. Meta data are attached to // a NON-sef url, which has the benefit of keeping the attachement // whenever sef url creations are modified and sef urls recreated // but require a bit more work in that case Sh404sefHelperDb::update('#__sh404sef_metas', array('newurl' => $newMain->newurl), array('newurl' => $previousMain->newurl)); } } // finally make it the main url Sh404sefHelperDb::update($this->_getTableName(), array('rank' => 0), array('id' => $newMain->id)); } catch (Sh404sefExceptionDefault $e) { $this->setError('Internal database error # ' . $e->getMessage()); } }
/** * 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']); }
private function _shInstallModule($module, $source, $extensionConfig, $moduleConfig) { $app =& JFactory::getApplication(); $path = $source . DS . 'admin' . DS . 'modules' . DS . $module; $installer = new JInstaller(); $result = $installer->install($path); if ($result) { // if files moved to destination, setup module in Joomla database $shouldRestore = $this->_shShouldRestore(); if ($shouldRestore) { // read stored params from disk $this->_shGetExtensionSavedParams($module . '_extension', $extensionConfig); } // update elements in db, only if we need to restore past configuration try { if (!empty($extensionConfig)) { // load module details from extension table $moduleDetails = Sh404sefHelperDb::selectAssoc('#__extensions', array('*'), array('type' => 'module', 'element' => $module)); // merge with saved details and write back to disk $details = array_merge($moduleDetails, $extensionConfig); Sh404sefHelperDb::update('#__extensions', $details, array('extension_id' => (int) $moduleDetails['extension_id'])); } } catch (Sh404sefExceptionDefault $e) { $app->enqueueMessage('Error: ' . $e->getMessage()); } if ($shouldRestore) { // read stored params from disk $this->_shGetExtensionSavedParams($module . '_modules', $moduleConfig); } // update elements in db, if we need to restore past configuration try { $instanceDetails = Sh404sefHelperDb::selectAssoc('#__modules', array('*'), array('module' => $module)); // merge with saved details and write back to disk $details = array_merge($instanceDetails, $moduleConfig); Sh404sefHelperDb::update('#__modules', $details, array('id' => (int) $instanceDetails['id'])); } catch (Sh404sefExceptionDefault $e) { $app->enqueueMessage('Error: ' . $e->getMessage()); } // and finally we make sure there is a menu item associated with the module $details = array('menuid' => 0); if ($shouldRestore) { // read stored params from disk $this->_shGetExtensionSavedParams($module . '_modules_menu', $details); } $details = array_merge($details, array('moduleid' => (int) $instanceDetails['id'])); // insert or update elements in db, if we need to restore past configuration try { sh404sefHelperDb::insertUpdate('#__modules_menu', $details, array('moduleid' => (int) $instanceDetails['id'])); } catch (Sh404sefExceptionDefault $e) { $app->enqueueMessage('Error: ' . $e->getMessage()); } } else { $app->enqueueMessage('Error installing sh404sef module: ' . $module); } return $result; }