Ejemplo n.º 1
0
 function updateURLs($rows, $where)
 {
     // Nothing to update
     if (is_null($rows) || count($rows) == 0) {
         return 0;
     }
     // Load the needed classes
     jimport('joomla.environment.uri');
     jimport('joomla.application.router');
     jimport('joomla.application.application');
     require_once JPATH_ROOT . '/includes/application.php';
     require_once JPATH_MIJOSEF_ADMIN . '/library/router.php';
     if (Mijosef::get('utility')->JoomFishInstalled()) {
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_joomfish' . DS . 'helpers' . DS . 'defines.php';
         JLoader::register('JoomfishManager', JOOMFISH_ADMINPATH . DS . 'classes' . DS . 'JoomfishManager.class.php');
         JLoader::register('JoomFishVersion', JOOMFISH_ADMINPATH . DS . 'version.php');
         JLoader::register('JoomFish', JOOMFISH_PATH . DS . 'helpers' . DS . 'joomfish.class.php');
     }
     // First, delete all the URLs
     if (!MijoDatabase::query("DELETE FROM #__mijosef_urls{$where}")) {
         return 0;
     }
     // ön-panel olmalı
     JFactory::$application = JApplication::getInstance('site', array(), 'J');
     // Create MijoSEF router
     $router = new JRouterMijosef();
     // JoomFish patch
     if (Mijosef::get('utility')->JoomFishInstalled()) {
         $mainframe = JFactory::getApplication();
         // Set mainframe as frontend
         $mainframe->set('_clientId', 0);
         // Initialize JoomFish plugin
         if (!class_exists('plgSystemJFDatabase')) {
             require JPATH_PLUGINS . '/system/jfdatabase.php';
         }
         $params = JPluginHelper::getPlugin('system', 'jfdatabase');
         $dispatcher = JDispatcher::getInstance();
         $plugin = new plgSystemJFDatabase($dispatcher, (array) $params);
         $plugin->onAfterInitialise();
         // Get the mainframe back to backend
         $mainframe->set('_clientId', 1);
     }
     // Update URLs one by one
     foreach ($rows as $row) {
         $old_real_url = $row->url_real;
         $old_sef_url = $row->url_sef;
         $uri = new JURI($old_real_url);
         $new_sef_uri = $router->build($router, $uri);
         //$new_sef_url = ltrim(str_replace(JURI::root(), '', $new_sef_uri->getQuery()), '/');
         $new_sef_url = $new_sef_uri->toString();
         $host = JFactory::getURI()->toString(array('scheme', 'host'));
         $new_sef_url = str_replace($host . '/index.php', '', $new_sef_url);
         $new_sef_url = str_replace($host . 'index.php', '', $new_sef_url);
         $new_sef_url = ltrim($new_sef_url, '/');
         // SEF URL changed, add it to Moved URLs
         if (!empty($new_sef_url) && strcmp($old_sef_url, $new_sef_url) != 0) {
             // Already exists?
             $id = MijoDatabase::loadResult("SELECT id FROM #__mijosef_urls_moved WHERE url_old = " . MijoDatabase::quote($old_sef_url) . " AND url_new = " . MijoDatabase::quote($new_sef_url) . " LIMIT 1");
             if (!$id) {
                 MijoDatabase::query("INSERT IGNORE INTO #__mijosef_urls_moved (url_old, url_new) VALUES (" . MijoDatabase::quote($old_sef_url) . ", " . MijoDatabase::quote($new_sef_url) . ")");
             }
         }
     }
     // arka-panel olmalı
     JFactory::$application = JApplication::getInstance('administrator', array(), 'J');
     return count($rows);
 }
Ejemplo n.º 2
0
 function updateURLs($rows, $where)
 {
     // Nothing to update
     if (is_null($rows) || count($rows) == 0) {
         return 0;
     }
     // Load the needed classes
     jimport('joomla.application.router');
     require_once JPATH_ROOT . '/' . 'includes' . '/' . 'application.php';
     require_once JPATH_ACESEF_ADMIN . '/' . 'library' . '/' . 'router.php';
     if (AcesefUtility::JoomFishInstalled()) {
         require_once JPATH_ROOT . '/' . 'components' . '/' . 'com_joomfish' . '/' . 'helpers' . '/' . 'defines.php';
         JLoader::register('JoomfishManager', JOOMFISH_ADMINPATH . '/' . 'classes' . '/' . 'JoomfishManager.class.php');
         JLoader::register('JoomFishVersion', JOOMFISH_ADMINPATH . '/' . 'version.php');
         JLoader::register('JoomFish', JOOMFISH_PATH . '/' . 'helpers' . '/' . 'joomfish.class.php');
     }
     // First, delete all the URLs
     if (!AceDatabase::query("DELETE FROM #__acesef_urls{$where}")) {
         return 0;
     }
     // Create AceSEF router
     $router = new JRouterAcesef();
     // JoomFish patch
     if (AcesefUtility::JoomFishInstalled()) {
         $mainframe = JFactory::getApplication();
         // Set mainframe as frontend
         $mainframe->_clientId = 0;
         // Initialize JoomFish plugin
         if (!class_exists('plgSystemJFDatabase')) {
             require JPATH_PLUGINS . '/' . 'system' . '/' . 'jfdatabase.php';
         }
         $params = JPluginHelper::getPlugin('system', 'jfdatabase');
         $dispatcher = JDispatcher::getInstance();
         $plugin = new plgSystemJFDatabase($dispatcher, (array) $params);
         $plugin->onAfterInitialise();
         // Get the mainframe back to backend
         $mainframe->_clientId = 1;
     }
     // Update URLs one by one
     for ($i = 0, $n = count($rows); $i < $n; $i++) {
         $row =& $rows[$i];
         $old_real_url = $row->url_real;
         $old_sef_url = $row->url_sef;
         $new_sef_uri = $router->build($old_real_url);
         $new_sef_url = ltrim(str_replace(JURI::root(), '', $new_sef_uri->_uri), '/');
         // SEF URL changed, add it to Moved URLs
         if ($old_sef_url != $new_sef_url) {
             // Already exists?
             $id = AceDatabase::loadResult("SELECT id FROM #__acesef_urls_moved WHERE url_old = " . AceDatabase::quote($old_sef_url) . " AND url_new = " . AceDatabase::quote($new_sef_url) . " LIMIT 1");
             if (!$id) {
                 AceDatabase::query("INSERT IGNORE INTO #__acesef_urls_moved (url_old, url_new) VALUES (" . AceDatabase::quote($old_sef_url) . ", " . AceDatabase::quote($new_sef_url) . ")");
             }
         }
     }
     return count($rows);
 }
Ejemplo n.º 3
0
 function updateMetaNext()
 {
     $db =& JFactory::getDBO();
     $sefConfig =& SEFConfig::getConfig();
     // Load all the URLs
     $query = "SELECT `id`, `sefurl`, `origurl`, `Itemid` FROM `#__sefurls` WHERE `locked` = '0' AND `trashed` = '0' AND `flag` = '1' LIMIT 25";
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     // Check that there's anything to update
     if (is_null($rows) || count($rows) == 0) {
         // Done
         //$db->setQuery("SELECT COUNT(`id`) FROM `#__sefurls` WHERE `dateadd` = '0000-00-00' AND `locked` = '0' AND `trashed` = '0'");
         //$count = $db->loadResult();
         $obj = new stdClass();
         $obj->type = 'completed';
         $obj->updated = 0;
         return json_encode($obj);
     }
     // Load the needed classes
     jimport('joomla.application.router');
     require_once JPATH_ROOT . DS . 'includes' . DS . 'application.php';
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_sef' . DS . 'sef.router.php';
     if (SEFTools::JoomFishInstalled()) {
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_joomfish' . DS . 'helpers' . DS . 'defines.php';
         JLoader::register('JoomfishManager', JOOMFISH_ADMINPATH . DS . 'classes' . DS . 'JoomfishManager.class.php');
         JLoader::register('JoomFishVersion', JOOMFISH_ADMINPATH . DS . 'version.php');
         JLoader::register('JoomFish', JOOMFISH_PATH . DS . 'helpers' . DS . 'joomfish.class.php');
     }
     // OK, we've got some data, let's update them
     $count = count($rows);
     // Check if JoomFish is present
     if (SEFTools::JoomFishInstalled()) {
         // We need to fool JoomFish to think we're running in frontend
         $mainframe =& JFactory::getApplication();
         $mainframe->_clientId = 0;
         // Load and initialize JoomFish plugin
         if (!class_exists('plgSystemJFDatabase')) {
             require JPATH_PLUGINS . DS . 'system' . DS . 'jfdatabase.php';
         }
         $params =& JPluginHelper::getPlugin('system', 'jfdatabase');
         $dispatcher =& JDispatcher::getInstance();
         $plugin = new plgSystemJFDatabase($dispatcher, (array) $params);
         $plugin->onAfterInitialise();
         // Set the mainframe back to its original state
         $mainframe->_clientId = 1;
     }
     // Suppress all the normal output
     ob_start();
     // Loop through URLs and update them one by one
     for ($i = 0; $i < $count; $i++) {
         $row =& $rows[$i];
         $url = $row->origurl;
         if (!empty($row->Itemid)) {
             if (strpos($url, '?') !== false) {
                 $url .= '&';
             } else {
                 $url .= '?';
             }
             $url .= 'Itemid=' . $row->Itemid;
         }
         $uri = new JURI($url);
         // Check if we have an extension for this URL
         $updated = false;
         $option = $uri->getVar('option');
         if (!empty($option)) {
             $file = JPATH_ROOT . DS . 'components' . DS . 'com_sef' . DS . 'sef_ext' . DS . $option . '.php';
             $class = 'SefExt_' . $option;
             if (!class_exists($class) && file_exists($file)) {
                 require $file;
             }
             if (class_exists($class)) {
                 $ext = new $class();
                 $metadata = $ext->generateMeta($uri);
                 if (is_array($metadata) && count($metadata) > 0) {
                     $metas = '';
                     foreach ($metadata as $metakey => $metaval) {
                         $metas .= ", `{$metakey}` = " . $db->Quote($metaval, true);
                     }
                     $query = "UPDATE `#__sefurls` SET `flag` = '0'" . $metas . " WHERE `id` = '{$row->id}'";
                     $db->setQuery($query);
                     if (!$db->query()) {
                         return $db->stderr(true);
                         $updated = false;
                     } else {
                         $updated = true;
                     }
                 }
             }
         }
         if ($updated == false) {
             // Remove flag
             $query = "UPDATE `#__sefurls` SET `flag` = '0' WHERE `id` = '{$row->id}'";
             $db->setQuery($query);
             $db->query();
         }
     }
     ob_end_clean();
     $obj = new stdClass();
     $obj->type = 'updatestep';
     $obj->updated = $count;
     return json_encode($obj);
 }