function autoMetadata($sef_url, $meta) { $no_auto_meta = empty($meta['title']) && empty($meta['description']) && empty($meta['keywords']); if ($no_auto_meta) { return; } static $checked = array(); if (!isset($checked[$sef_url])) { $m = Mijosef::get('cache')->checkMetadata($sef_url); $checked[$sef_url] = "checked"; } if ($checked[$sef_url] != "saved" && isset($m) && !is_object($m)) { $meta['description'] = ltrim($meta['description']); $values = "(" . MijoDatabase::quote($sef_url) . ", '{$meta['title']}', '{$meta['description']}', '{$meta['keywords']}')"; MijoDatabase::query("INSERT IGNORE INTO #__mijosef_metadata (url_sef, title, description, keywords) VALUES {$values}"); $checked[$sef_url] = "saved"; } }
function checkTags($tag, $all = false) { static $tags = array(); static $tags_db; if ($this->MijosefConfig->cache_tags == 1) { $cache = Mijosef::getCache(); $tags_cached = $cache->load('tags'); if ($all && !empty($tags_cached)) { return $tags_cached; } elseif (!empty($tags_cached[$tag])) { return $tags_cached[$tag]; } } if ($this->MijosefConfig->cache_instant == 1 || $this->MijosefConfig->cache_instant == 0 && $all) { if (!isset($tags_db)) { $tags_db = MijoDatabase::loadObjectList("SELECT * FROM #__mijosef_tags WHERE published = '1' ORDER BY {$this->MijosefConfig->tags_order}", "title"); } if ($all) { if ($this->MijosefConfig->cache_tags == 1) { $cache->save($tags_db, 'tags'); } return $tags_db; } elseif (isset($tags_db[$tag])) { if ($this->MijosefConfig->cache_tags == 1) { $tags_cached[$tag] = $tags_db[$tag]; $cache->save($tags_cached, 'tags'); } return $tags_db[$tag]; } } if (!$all) { if (!isset($tags[$tag])) { $t = MijoDatabase::quote($tag); $row = MijoDatabase::loadObject("SELECT * FROM #__mijosef_tags WHERE title = {$t} AND published = '1'"); if (is_object($row)) { $tags[$tag] = $row; } } if (isset($tags[$tag])) { if ($this->MijosefConfig->cache_instant == 1) { $tags[$tag] = $tags[$tag]; } if ($this->MijosefConfig->cache_tags == 1) { $tags_cached[$tag] = $tags[$tag]; $cache->save($tags_cached, 'tags'); } return $tags[$tag]; } } return false; }
function _newVars($old_uri, $sef_url, $query, $lang = null) { $mainframe = JFactory::getApplication(); $vars = array(); // A quick fix for not loading translated menus if (!empty($lang) && strpos($sef_url, $lang . '/', 0) !== 0) { $sef_url = $lang . '/' . $sef_url; } $row = Mijosef::get('cache')->checkURL($sef_url, true); if (is_object($row) && Mijosef::get('utility')->getParam($row->params, 'published') == '1') { // Use the already created URL $url_real = $row->url_real; // Update hits MijoDatabase::query("UPDATE #__mijosef_urls SET hits = (hits+1) WHERE id = '{$row->id}'"); // Set query string $url_real = str_replace('&', '&', $url_real); $QUERY_STRING = str_replace('index.php?', '', $url_real); parse_str($QUERY_STRING, $vars); // Set mainframe vars $mainframe->set('mijosef.url.id', $row->id); $mainframe->set('mijosef.url.sef', $row->url_sef); $mainframe->set('mijosef.url.real', $row->url_real); $mainframe->set('mijosef.url.params', $row->params); $meta = Mijosef::get('cache')->checkMetadata($row->url_sef); if (is_object($meta)) { if (!empty($meta->title)) { $mainframe->set('mijosef.meta.title', $meta->title); } if (!empty($meta->description)) { $mainframe->set('mijosef.meta.desc', $meta->description); } if (!empty($meta->keywords)) { $mainframe->set('mijosef.meta.key', $meta->keywords); } if (!empty($meta->lang)) { $mainframe->set('mijosef.meta.lang', $meta->lang); } if (!empty($meta->robots)) { $mainframe->set('mijosef.meta.robots', $meta->robots); } if (!empty($meta->google)) { $mainframe->set('mijosef.meta.google', $meta->google); } if (!empty($meta->canonical)) { $mainframe->set('mijosef.link.canonical', $meta->canonical); } } } else { // Moved URL $m_url = $sef_url; if (empty($query)) { $row = Mijosef::get('cache')->checkMovedURL($sef_url); } else { $m_url .= '?' . $query; $found_with_query = true; $row = Mijosef::get('cache')->checkMovedURL($m_url); if (!is_object($row)) { $found_with_query = false; $row = Mijosef::get('cache')->checkMovedURL($sef_url); } } if (is_object($row)) { // URL found, update the last hit and hit counter MijoDatabase::query("UPDATE #__mijosef_urls_moved SET last_hit = NOW(), hits = (hits+1) WHERE id = " . $row->id); $root = JURI::root(); $f = $l = ''; if (!headers_sent($f, $l)) { // Let's build absolute URL from our link if (strstr($row->url_new, $root) === false) { if (preg_match("/^(https?|ftps?|itpc|telnet|gopher):\\/\\//i", $row->url_new)) { $url = $row->url_new; } else { $url = $root; if (substr($url, -1) != '/') { $url .= '/'; } if (substr($row->url_new, 0, 1) == '/') { $row->url_new = substr($row->url_new, 1); } $url .= $row->url_new; } } else { $url = $row->url_new; } if (!empty($query) && !$found_with_query) { $url .= '?' . $query; } // Use the link to redirect header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $url); header('Connection: close'); exit; } else { self::_showHeadersSentError($f, $l, __FILE__, __LINE__); } } elseif ($this->MijosefConfig->jsef_to_mijosef == 1) { // Joomla! SEF to MijoSEF $juri = clone $old_uri; $old_sef_url = $old_uri->toString(array('path', 'query', 'fragment')); $router = $mainframe->get('mijosef.global.jrouter'); $router->setMode(JROUTER_MODE_SEF); $jvars = $router->parse($old_uri); $router->setMode(JROUTER_MODE_DONT_PARSE); // Check 404 if (isset($jvars['option']) && $jvars['option'] == 'com_content' && isset($jvars['view']) && isset($jvars['id']) && $jvars['id'] == 0) { $jvars = array(); } if (!empty($jvars) && (!empty($jvars['option']) || !empty($jvars['Itemid']))) { // If Itemid is empty, destroy it if (array_key_exists('Itemid', $jvars) && is_null($jvars['Itemid'])) { unset($jvars['Itemid']); } // Empty query to set the new vars $juri->setQuery(''); // Set new vars if (!empty($jvars)) { $juri->setQuery($jvars); } $juri->setPath('index.php'); // Convert URI to string $real_url = $juri->toString(array('path', 'query', 'fragment')); if (!empty($real_url) && substr($real_url, 0, 10) == 'index.php?') { // Generate the new SEF URL using MijoSEF $new_sef_url = JRoute::_($real_url); //if ($new_sef_url != $old_sef_url) {} // Remove path from the URL that will be stored in db $path = str_replace($juri->getScheme(), '', JURI::root()); $path = str_replace($juri->getHost(), '', $path); $path = str_replace('://', '', $path); //$db_sef_url = str_replace($path, '', $new_sef_url); if ($path != '/') { $db_sef_url = str_replace($path, '', $new_sef_url); } else { $db_sef_url = substr($new_sef_url, 1); // to remove the leading '/' } // Store it to Moved URLs MijoDatabase::query("INSERT IGNORE INTO #__mijosef_urls_moved (url_old, url_new) VALUES (" . MijoDatabase::quote($sef_url) . ", " . MijoDatabase::quote($db_sef_url) . ")"); $f = $l = ''; if (count($_POST) == 0 && !headers_sent($f, $l)) { // Use the link to redirect header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $new_sef_url); header('Connection: close'); exit; } else { if ($this->MijosefConfig->sent_headers_error == 1) { self::_showHeadersSentError($f, $l, __FILE__, __LINE__); } } } } } } return $vars; }