* Statistic

  • *Total Posts: 14957
  • *Total Topics: 2275
  • *Online Today: 10
  • *Most Online: 292
(2016 November 12, 09:37:31 am)
  • *Users: 0
  • *Guests: 0
  • *Spiders: 3
  • *Total: 3

  • *Yahoo!
  • *Baidu (2)

Sitemap extension for Portamx

Started by Fisch.666, 2012 January 15, 03:52:40 pm

previous topic - next topic

0 Members and 0 Guests are viewing this topic.

Fisch.666

2012 January 15, 03:52:40 pm Last Edit: 2012 July 04, 03:28:27 pm by Fisch.666
Hi!

To add portamx single pages and articles to the Sitemap (http://custom.simplemachines.org/mods/index.php?mod=755) mod i've created an extension for the sitemap addon. I've added this extension as an attachment to this post.

Please Note
---------------
I have only very basic knowledge of php and smf so use this extension at your own risk. Maybe a more experienced user can have a look at this extension.

Please Note for PortaMx versions prior 1.5
---------------
For the singlepages in the .xml sitemap priority is statically set to 1.0 and lastchange to the current timestamp (with time())
because we have no create date for the single page.

[attachment deleted by admin]

feline

#1
2012 January 16, 03:37:34 pm
Well .. I find only one file named "dummy" in the archive  :o seems like that is not correct  ;)
Same on SMF forum ...
Many are stubborn in relation to the path, a few in relation to the target.

Fisch.666

#2
2012 January 16, 04:26:11 pm
Hi Feline,

do you have removed the .zip ending from the filename? As i wrote above, the forums here doesn't allow .tar.gz files as an attachment, thats the reason why i have added the .zip ending to the file.  :)

feline

#3
2012 January 16, 11:28:42 pm
of course .. but a good tool can extract any file  ;)
Look at your attached archive here and on SMF .. both are same buggy...
Many are stubborn in relation to the path, a few in relation to the target.

Fisch.666

#4
2012 January 17, 12:49:25 am
Mhhh, very strange. Thats a normal "tar.gz" file from an linux system which extracts on linux without a problem. Only windows programs (i've tested 2 of them) get this "dummy" file. Anyway, i've attached a new file as a .zip archive to the first post.

feline

#5
2012 January 19, 10:37:01 am
Well .. your small mod worked, but I found smaller problems and bugs ...
1.. you can use the forum default language for the titles, this is stored in the variable $language
2.. for Single pages you have to check, if the page enabled.
3.. for articles you have to check, if the article enabled and approved
4.. for pages and articles you have to check, if a user can see the page/article (for xml must have guest access)

Fix for all points:
In sitemap_spages.php the function list_getSpages:
Code Select

function list_getSpages($start, $items_per_page, $sort)
{
global $smcFunc, $language;

$request = $smcFunc['db_query']('','
SELECT id, side, config, acsgrp
FROM {db_prefix}portamx_blocks
WHERE side = "pages" AND active > 0
ORDER BY {raw:sort}',
array(
'sort' => $sort == '1=1' ? 'id DESC' : $sort,
)
);

$spages = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if(allowPmxGroup($row['acsgrp']))
{
$cfg = unserialize($row['config']);
$row['title'] = $cfg['title'][$language];
$row['name'] = $cfg['pagename'];
$spages[] = $row;
}
}
$smcFunc['db_free_result']($request);

return $spages;
}


In sitemap_articles.php the function list_getArticles:
Code Select

function list_getArticles($start, $items_per_page, $sort)
{
global $smcFunc, $language;

$request = $smcFunc['db_query']('','
SELECT a.config, a.name, a.id, a.created, a.acsgrp, mem.real_name, mem.id_member
FROM {db_prefix}portamx_articles as a
LEFT JOIN {db_prefix}members as mem ON (mem.id_member = a.owner)
WHERE a.active > 0 AND a.approved > 0
ORDER BY {raw:sort}',
array(
'sort' => $sort == '1=1' ? 'a.id DESC' : $sort,
)
);

$articles = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if(allowPmxGroup($row['acsgrp']))
{
$cfg = unserialize($row['config']);
$row['title'] = $cfg['title'][$language];
$articles[] = $row;
}
}
$smcFunc['db_free_result']($request);

return $articles;
}


Now it works as well ...  ;)
I attached the both files here...

[attachment deleted by admin]
Many are stubborn in relation to the path, a few in relation to the target.

Fisch.666

#6
2012 January 19, 11:01:40 am
Wow great, thanks for this fixes. O0 I didn't think of the access and approved/enabled levels in Portamx.  :-[

Only one question before i update the package:

Quote from: feline ,  2012 January 19, 10:37:01 am
1.. you can use the forum default language for the titles, this is stored in the variable $language


What happens if the forum default language is e.g. german-utf8 and the title is only written in english (The title for german-utf8 should be empty)?

feline

#7
2012 January 19, 11:31:28 am
Well .. in this case the title is empty. But .. you can use follow:

replace:
Code Select

$row['title'] = $cfg['title'][$language];


with:
Code Select

$row['title'] = !empty($cfg['title'][$language]) ? $cfg['title'][$language] : $cfg['title']['english'];


in both files. Now if the $language title empty, the english is used ...
Many are stubborn in relation to the path, a few in relation to the target.

Fisch.666

#8
2012 January 19, 12:10:04 pm
Hey, thanks again for this info. I've just updated my first post with the new version.

feline

#9
2012 January 20, 02:20:52 pm
Quote from: Fisch.666 ,  2012 January 15, 03:52:40 pm
For singlepages in the .xml sitemap priority is statically set to 1.0 and lastchange to the current timestamp (with time()) because we have no create date for the single page.

Well .. for the next PortaMx release (1.50) we added a "created" element to the config array, this hold the time of the last block save time. This can used for xml.
It's only a small change on the file sitemap_spages.php
Find:
Code Select

function SpagesXML()
{
global $modSettings, $scripturl;

// Get our information from the database
if (($spages = cache_get_data('xml_spages', $modSettings['sitemap_cache_ttl'])) == null)
{
$temp_spages = list_getSpages(0, 0, 'id DESC');
// And assign it to an array
$spages = array();
foreach ($temp_spages as $row)
{
$spages[] = array(
'url' => fix_possible_url($scripturl . '?spage=' . $row['name']),
'time' => date_iso8601(time()),
'priority' => '1.0',
);
}
cache_put_data('xml_spages', $spages, $modSettings['sitemap_cache_ttl']);
}

return $spages;
}


Replace with:
Code Select

function SpagesXML()
{
global $modSettings, $scripturl;

// Get our information from the database
if (($spages = cache_get_data('xml_spages', $modSettings['sitemap_cache_ttl'])) == null)
{
$temp_spages = list_getSpages(0, 0, 'id DESC');
// And assign it to an array
$spages = array();
foreach ($temp_spages as $row)
{
$spages[] = array(
'url' => fix_possible_url($scripturl . '?spage=' . $row['name']),
'time' => date_iso8601($row['created']),
'priority' => priority($row['created']),
);
}
cache_put_data('xml_spages', $spages, $modSettings['sitemap_cache_ttl']);
}

return $spages;
}


Find:
Code Select

function list_getSpages($start, $items_per_page, $sort)
{
global $smcFunc, $language;

$request = $smcFunc['db_query']('','
SELECT id, side, config, acsgrp
FROM {db_prefix}portamx_blocks
WHERE side = "pages" AND active > 0
ORDER BY {raw:sort}',
array(
'sort' => $sort == '1=1' ? 'id DESC' : $sort,
)
);

$spages = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if(allowPmxGroup($row['acsgrp']))
{
$cfg = unserialize($row['config']);
$row['title'] = $cfg['title'][$language];
$row['name'] = $cfg['pagename'];
$spages[] = $row;
}
}
$smcFunc['db_free_result']($request);

return $spages;
}


Replace with:
Code Select

function list_getSpages($start, $items_per_page, $sort)
{
global $smcFunc, $language;

$request = $smcFunc['db_query']('','
SELECT id, side, config, acsgrp
FROM {db_prefix}portamx_blocks
WHERE side = "pages" AND active > 0
ORDER BY {raw:sort}',
array(
'sort' => $sort == '1=1' ? 'id DESC' : $sort,
)
);

$spages = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if(allowPmxGroup($row['acsgrp']))
{
$cfg = unserialize($row['config']);
$row['title'] = !empty($cfg['title'][$language]) ? $cfg['title'][$language] : $cfg['title']['english'];
$row['name'] = $cfg['pagename'];
$row['created'] = !empty($cfg['created']) ? $cfg['created'] : time();
$spages[] = $row;
}
}
$smcFunc['db_free_result']($request);

return $spages;
}


Then .. up from the next release the time/priority is show correct  ;)
Many are stubborn in relation to the path, a few in relation to the target.

feline

#10
2012 January 20, 10:19:51 pm
and more for the next release about your sitemap extension ...
we added a checkbox for all block (only on single pages) and for articles to enable/disable to show the block in sitemaps.
this settings is stored in the config array as "show_sitemap" and is not empty on show.
Then can to check pages/articles:
a) without access checking:
Code Select

if(!empty($cfg['show_sitemap']))

or
b) with access checking:
Code Select

if(!empty($cfg['show_sitemap']) && allowPmxGroup($row['acsgrp']))

I prefer the second methode ... if a guest have no access, he becomes a error massage (no access) and can register  ;)
Many are stubborn in relation to the path, a few in relation to the target.

Fisch.666

#11
2012 January 28, 04:00:31 pm
Hi!

Thanks for this info. Atm i'm quite busy because i'm doing my exams. But i will have a look at this after the exams and the release of portamx 1.50.

Fisch.666

#12
2012 July 04, 03:26:18 pm
Hi,

i've just updated my first post with the changes needed for PortaMx 1.5.

Fisch.666

#13
2014 December 08, 07:30:15 am
Quote from: Fisch.666 ,  2012 January 15, 03:52:40 pm
[attachment deleted by admin]


Mhhh, any reasons why the attachment was deleted? Still works here with Portamx 1.53.