Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#61 2010-09-21 10:17:29

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: smd_lately: recently viewed site articles

Sure Stef there you go:

In a simple form call:

<txp:gbp_disable_permlinks>
<txp:smd_lately by="SMD_ALL" wraptag="ul" break="li" section="collections" limit="6">
<txp:variable name="art_img" value='<txp:article_image />' />
<txp:if_variable name="art_img" value="">
<txp:else />
<a href="<txp:site_url /><txp:section /><txp:category />" title="<txp:title />">
<span class="bgf">&nbsp;</span>
<span class="thumb">
<txp:upm_article_image limit="1" form="dor_coll" />
</span>
<span class="article-title">
<txp:rvm_substr length="15"><txp:title /></txp:rvm_substr>
</span>
</a>
</txp:if_variable>
</txp:smd_lately>
</txp:gbp_disable_permlinks>

Is currently what I’m using…

<txp:category /> 

outputs nothing….

One last point:

<txp:smd_lately by="SMD_ALL" wraptag="ul" break="li" section="collections" limit="6">

outputs 4 articles even browsed on the site all around thus creating new log entries…

Edit: Last point solved by adding the sort=“popularity” option.

Last edited by hablablow (2010-09-21 10:40:33)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#62 2010-09-21 10:40:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,468
Website GitHub

Re: smd_lately: recently viewed site articles

hablablow wrote

<txp:category /> outputs nothing

I’m not sure this is directly related to the plugin. If you’re using <txp:category /> without any attributes in an article form it’ll only be populated if you are viewing a list of articles in a category! (i.e. site.com/category/name-of-cat. Check Textbook). This may well explain why it’s empty on an individual article page.

In that case you’ll either need to use <txp:category1 /> (or 2) to use the corresponding article category or figure out some alternative logic to populate the category with a known name that you can filter using some gbp_pl rules or other magic.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#63 2010-09-21 11:56:18

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: smd_lately: recently viewed site articles

But of course…

Switched to <txp:category1 />

And it works.

Thank you very much Stef !


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#64 2010-09-21 16:19:29

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_lately: recently viewed site articles

Hi Bloke,

thanks for follow up and the code to make it 4.0.7-compatible.

However, if I enable the caching feature (by adding cache_time="1600"), I get a Fatal error: Allowed memory size of 12582912 bytes exhausted (tried to allocate 320745 bytes) in /home/sites/xxxxxx/website/textpattern/plugins/active/smd_lately_v0.30.php on line 274

Of course, this probably isn’t an issue with smd_lately itself, but with the plugin usage and the server environment (basically, my home computer), which is probably eating a lot of resources in the query and when creating/writing the file (which, after this error, the file is created, but it’s empty).
I’m using smd_lately this way:

<txp:smd_lately by="" sort="popularity" within="30 days" limit="10" wraptag="ul" break="li" cache_time="1600"> ... </txp:smd_lately>

By now, as said on previous post, I’ll keep caching turned off an use aks_cache to do the caching job.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#65 2010-09-21 18:36:04

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,468
Website GitHub

Re: smd_lately: recently viewed site articles

maniqui wrote:

Fatal error: Allowed memory size of 12582912 bytes exhausted… <snip>

Hmmm, you’ve probably got a lot of records then. It’ll either be the serialize() function having a hissy fit because of the huge record set or the fwrite() as it dumps everything to the file. Out of morbid curiosity, try adding:

dmp($rs);

After line 263 ($rs = getRows($query, $debug);) and see if you have bajillions of rows (you don’t have to count them(!) although you can add dmp(count($rs)) to find out if you wish).

Next, try the following in the section of code after the get_pref():

$stuff = serialize($rs);
$fh = fopen($var_data, 'wb');
fwrite($fh, $stuff);
fclose($fh);

When you refresh and it caches the results (you might have to delete the smd_lately_lmod_NNNNN pref value to make this happen on your terms) see on what line the error lies: is it the serialize() or the fwrite()? That’ll give me a better chance of figuring out something better.

Also, see what happens if you reduce the within attribute to, say, 10 days or something. Does it make any difference? (I know this isn’t what you want to do: just humour me please). Thanks mr super sleuth.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#66 2010-10-21 04:08:38

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_lately: recently viewed site articles

Hi Bloke,

I’ve modded smd_lately a little, to accept a method parameter on include and exclude attributes.
Really easy to do: on lines 150 and 180, add
case "method":

And done!
You can now do, for example exclude="method:POST" or include="method:GET", to filter stuff.

exclude="method:POST" is useful to filter out comment previewing/submitting hits. This becomes useful if your site is heavily visited by spammer robots that are trapped by the built-in preview mechanism of TXP.
It made a huge difference on the accurate (by “accurate” I mean: trying, as much as possible, to count visits by human beings) calculation of popularity.

BTW, you may also want to include /file_download/ on the default list of excluded pages.

Finally, a question, but first, a disclaimer: I know nothing about MySQL, how to craft queries, how to benchmark them, how they work exactly behind the scene.
But, for example, this query (created by smd_lately), for calculating popularity:

SELECT count(page) as popularity, page, MAX(time) as time FROM txp_log WHERE 1=1 AND page NOT LIKE '/' AND page NOT LIKE '%q=%' AND page NOT LIKE '%c=%' AND page NOT LIKE '%pg=%' AND page NOT LIKE '%category=%' AND page NOT LIKE '/category/%' AND page NOT LIKE '%author=%' AND page NOT LIKE '/author/%' AND page NOT REGEXP '^/(about|contact|default|downloads|features|feed|gallery|home|label|lists|mixes|news|next|playlists|podcast|reviews|search|signup-overlay|txt-reviews)/?$' AND page NOT LIKE '%cpreview%' AND page NOT LIKE '%file_download%' AND page NOT LIKE '%utm_%' AND host NOT LIKE '%.googlebot.com%' AND host NOT LIKE '%.search.live.com%' AND host NOT LIKE '%.picsearch.com%' AND host NOT LIKE '%robot%' AND host NOT LIKE '%crawl%' AND host NOT LIKE '%msnbot%' AND method != 'POST' AND UNIX_TIMESTAMP(time) > 1285030673 AND status = 200 GROUP BY page ORDER BY popularity desc

Again, I don’t know how this works, but… if there is a time window (for example: @within=“30 days”), wouldn’t it be performance-wise to use a first query to filter all visitor log entries by that criteria (timestamp), and then, once you got them, run a second query to filter entries by all the other criteria?

Thanks.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#67 2011-01-03 20:52:54

MotorSQ
New Member
Registered: 2011-01-03
Posts: 1

Re: smd_lately: recently viewed site articles

I use this code to sort by popularity

   <txp:smd_lately by="" limit="6" status="live" sort="popularity" wraptag="" break="" >         
           <txp:permlink><txp:article_image/></txp:permlink>
           <txp:category1 title="1" />
           <txp:permlink><txp:title /></txp:permlink>
   </txp:smd_lately> 

when the articles will be more than 6, would like to see pagination
such a type: [<< Prev] 1… 4 5 6 7 8 …12 [Next >> ]
Is this possible? And how to do it if so? Thank you, sorry for my horrible English)

Offline

#68 2011-02-15 19:53:37

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: smd_lately: recently viewed site articles

Hi Stef just a quick and simple question:

Will the plugin work in a multisite environment where the temp folder is located elsewhere ? In the site folder > site_name > public folder precisely.

As long as I specify the path in the txp prefs and the give the correct permissions it should be fine, right ?

Thanks….

Last edited by hablablow (2011-02-15 19:55:15)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#69 2011-02-15 21:11:10

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,468
Website GitHub

Re: smd_lately: recently viewed site articles

hablablow wrote:

a quick and simple question: Will the plugin work in a multisite environment

And a quick and simple answer: I have absolutely no idea, sorry! My guess is it will work fine. The temp file just stores cached info from each smd_lately tag and each ‘front end’ will get its own unique temp file. So you probably don’t even need to use different temp dirs, although it might be a good idea to do so.

Best approach is to try it and see what happens. If you start getting clashes, we could see if adding a plugin attribute to specify the unique file name might help.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#70 2011-02-15 21:19:07

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: smd_lately: recently viewed site articles

Alright, thank you Stef. I’ll let you know if something weird happens…

Last edited by hablablow (2011-02-15 21:20:43)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#71 2011-02-19 00:43:03

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: smd_lately: recently viewed site articles

Stef, smd_lately is writting the cache data in the tmp folder inside the Textpattern folder, unfortunately, not in the Temporary directory path specified in the preferences, in the case of a multisite environement…

While reading your code I came accross this function:

find_temp_dir()

I assume you are using this function so that if a user omits to specify the Temporary directory path in his preferences, the function is still able to find the temp directory and add the cache data there…

Could you craft it a different way that if a user has not specified the temp path, by following this scenario:
A – Follow first the path to the temp directory such as defined in Temporary directory path and write the cache data there
B – If the path is not defined then use the find_temp_dir() function

That would make smd_lately run in a multisite environement and store it’s cache data in separate tmp folders under each site…

Is this suggestion correct ?

As you mentioned earlier, that’s probably a better way to go than to store each smd_lately cache file in one single folder, currently the Textpattern folder…

Cheese…

Last edited by hablablow (2011-02-19 00:47:47)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#72 2011-02-22 22:28:33

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: smd_lately: recently viewed site articles

Stef,

“If you start getting clashes, we could see if adding a plugin attribute to specify the unique file name might help…”

Well, not exactly clashes but on a mutlisite environement the temp log files, written only under the main Textpattern folder as I said earlier, replace each other for each site :(

For site A and another B, the tmp log file will update it’s data for A… As a result B will fail in trying to fetch the data by reading the content of popular data for site A… =:(

In fact a very cool feature would be to be able to specify a name for the temp file and so every site A and B would only read his A_smd_lately and B_smd_lately file….

That would be supa-freshhhhhh !

Last edited by hablablow (2011-02-22 22:31:06)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

Board footer

Powered by FluxBB