26/07/2011, 00:42
|
| | Fecha de Ingreso: julio-2011
Mensajes: 17
Antigüedad: 13 años, 3 meses Puntos: 0 | |
Respuesta: Como coger solo paginas publicadas Tienes toda la razón, sorry...
es un codigo antiguo que he ido ajustando a los requerimientos actuales de google news.
Código:
header("Content-type: text/xml; charset=UTF-8");
header("Content-encoding: UTF-8");
// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
$lg = &JFactory::getLanguage();
$language = $lg->getLocale();
$language = str_replace(Array('.UTF-8','@euro'),'',$language[4]);
$config =& JFactory::getConfig();
$use_suffix = $config->getValue('config.sef_suffix');
$offset = $config->getValue('config.offset');
list($hours, $minutes) = explode('.', $offset);
$minutes = 60 * "0.$minutes";
if ($hours >= 0) {
$hours = "+$hours";
}
if (strlen($hours) == 2) {
$hours = substr($hours, 0, 1) . '0' . substr($hours, 1, 1);
}
if (strlen($minutes) == 1) {
$minutes = "0$minutes";
}
$timezone = "$hours:$minutes";
$threedaysago = date('Y-m-d h:i:s',(time()-172800));
$db =& JFactory::getDBO();
$get_all_cfg = 'SELECT * FROM #__gnsg_cfg';
$db->setQuery($get_all_cfg);
$rows = $db->loadAssocList();
$cfg = Array();
if (is_array($rows))
foreach ($rows as $row)
$cfg[$row['key']] = $row['value'];
if ($cfg['language'])
$language = $cfg['language'];
switch ($cfg['sef-component']) {
case 'sh404' :
$query = '
SELECT
oldurl,newurl
FROM
`jos_redirection`
WHERE
`newurl`
REGEXP
"option=com_content&Itemid=[0-9]*&catid=[0-9]*&id=[0-9]*&lang=[a-zA-Z]*&view=article"
LIMIT
5000
';
$gg_q = @mysql_query($query);
$db->setQuery( $query );
$rows = $db->loadAssocList();
for ( $a=0; $a<sizeof($rows); $a++ ) {
$row = $rows[$a];
$rm = preg_match('/option=com_content&Itemid=[0-9]*&catid=[0-9]*&id=([0-9]*)&lang=[a-zA-Z]*&view=article/',$row['newurl'],$matches);
$lookfor_content = '
SELECT
a.created,
a.title AS title
a.metakey AS metakey
a.publish_up AS publish_up
FROM
#__content AS a
WHERE
a.id = '.$matches[1].' AND
a.created >="'.$threedaysago.'"
ORDER BY
a.created DESC
LIMIT 1
';
$db->setQuery( $lookfor_content );
$thise = $db->loadAssocList();
if ($thise[0]['created']) {
$rows[$a] = Array(
'id' => $matches[1],
'cont' => '',
'created' => $thise[0]['created'],
'cat' => '',
'catid' => '',
'title' => $thise[0]['title'],
'new' => $row['oldurl']
);
} else {
$rows[$a]=Array();
}
}
break;
case 'no-sef' :
case 'no-modrewrite' :
case 'core' :
default :
$query = '
SELECT
a.id,
a.alias AS cont,
a.created,
b.alias AS cat,
a.catid AS catid,
c.alias AS `sec`,
a.sectionid AS secid,
a.title AS title,
a.metakey AS metakey,
a.publish_up AS publish_up
FROM
#__content AS a,
#__categories AS b,
#__sections as c
WHERE
c.id = a.sectionid AND
b.id = a.catid AND
a.created >="'.$threedaysago.'"
ORDER BY a.created DESC
LIMIT 50000
';
$db->setQuery( $query );
$rows = $db->loadAssocList();
break;
}
echo '<?xml version="1.0" encoding="UTF-8"?>'.chr(10);
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'.chr(10);
echo ' xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">'.chr(10);
foreach ($rows as $row) {
if (!$row['id'])
continue;
if ($cfg['keywords']!='')
$keyz = htmlspecialchars($cfg['keywords']);
else
$keyz = htmlspecialchars($row['metakey']);
switch ($cfg['sef-component']) {
case 'sh404' :
$url = JURI::root().$row['new'];
break;
case 'no-sef':
$url = JURI::root().'index.php?option=com_content&view=article&id='.$row['id'].':'.$row['cont'].'&catid='.$row['catid'].':'.$row['cat'];
break;
case 'no-modrewrite' :
$url = JURI::root().'noticias/'.$row['cat'].'/'.$row['id'].'-'.$row['cont'].'';
break;
case 'core' :
default :
$find_menu = '
SELECT
alias
FROM
#__menu
WHERE
link LIKE "index.php?option=com_content&view=section&id='.$row['secid'].'"
';
$db->setQuery( $find_menu );
$menus = $db->loadAssocList();
if ($menus[0]['alias']) {
$prefix = $menus[0]['alias'].'/'.$row['catid'].'-';
} else {
$prefix = '';
}
$find_menu = '
SELECT
alias
FROM
#__menu
WHERE
link LIKE "index.php?option=com_content&view=categoru&id='.$row['catid'].'" OR
link LIKE "index.php?option=com_content&view=category&layout=blog&id='.$row['catid'].'"
';
$db->setQuery( $find_menu );
$menus = $db->loadAssocList();
if ($menus[0]['alias']) {
$row['cat'] = $menus[0]['alias'];
}
if ($use_suffix) {
$url = JURI::root().$prefix.$row['cat'].'/'.$row['id'].'-'.$row['cont'].'.html';
} else {
$url = JURI::root().$prefix.$row['cat'].'/'.$row['id'].'-'.$row['cont'].'/';
}
break;
}
echo '
<url>
<loc>'.$url.'</loc>
<news:news>
<news:publication>
<news:name>'.$cfg['pub-name'].'</news:name>
<news:language>'.es.'</news:language>
</news:publication>
<news:publication_date>'.substr($row['created'],0,10).'</news:publication_date>
<news:title>'.htmlspecialchars($row['title']).'</news:title>
<news:keywords>'.$keyz.'</news:keywords>
</news:news>
</url>';
}
echo '</urlset>'.chr(10);
JRequest::getInt('no_html', 0);
$no_html = intval(JRequest::getInt('no_html', 0));
if ($scriptname != 'index2.php' || $no_html != 1) {
die();
}
|