Support Forum

Topic Expire Plugin question

LE laurent enselme
laurent enselme
Member

Hello,

I’m going to use a lot this plugin as soon has i’ll have finished to configure my forum, that perfectly meets my needs except that once the date has been set I wish this may be readily visible , such as in the title of the topics (see attachment), would be a great help for moderators and members too – is that possible please ? Thanks in advance

Sans-titre-1-1.jpg

14 Answers

New Answer

MP Mr Papa
Mr Papa
Member

sure… we should actually make this easier for you… and save some queries… but this should work for you…

in you topic view template, ie spTopicView.php of the SP theme you are using, find the topic header display… something like this:

                    sp_TopicHeaderIcon('tagClass=spHeaderIcon spLeft');
                    sp_TopicHeaderName('tagClass=spHeaderName');

from our default theme…  after that, just add:

                    $topic_expire = spdb_table(SFTOPICS, "topic_id=$spThisTopic->topic_id", 'expire_date');
                    echo 'Topic Expires: '.date('l, F j, Y', strtotime($topic_expire));

which will output the topic expiration date…  feel free to customize as you like including date formatting…  I dont know if you have all topics expiring or not, so you might need a check for it existing…

as always, we strongly recommend that you make a child theme or a custom theme for this change to keep from losing your changes on update…

btw, in next release of the plugin (maybe this weekend), will make it easier so you dont have to do that db query…

LE laurent enselme
laurent enselme
Member

Hi Mr Papa and thank you very much.

 

It’s almost working, but i got an error message saying that there is an invalid database request, and the date shown is 01/01/1970

 

I’m using the Unified theme, pasted the first line of the code in the very beginning of the file spTopicView.php, just before # == ADD POST FORM – OBJECT DEFINITION ========================

Then i have pasted the second line where i wanted the dateto be shown, just after:

if (function_exists(‘sp_RelatedTopicsButton’)) sp_RelatedTopicsButton(‘tagClass=spRelated spLeft spButton’, __sp(‘Related Tags’), __sp(‘Get a list of related topics based on tags for this topic’));
}

 

The result is exactly what i needed excepted the error.

I did something wrong ?

Sans-titre-1-2.jpg
YS Yellow Swordfish
Yellow Swordfish
Member

Is it just that there was a faulty entity in Steve’s code. It should be:

$topic_expire = spdb_table(SFTOPICS, "topic_id=$spThisTopic->topic_id", 'expire_date');
echo 'Topic Expires: '.date('l, F j, Y', strtotime($topic_expire));

Note the -> in $spThisTopic->topic_id…

Could that be the problem?

LE laurent enselme
laurent enselme
Member

Thank you, but no the problem is still the same.

 

Btw here is what i git in the error journal:

 

9 août 2015 à 15:14 | spaErrError | 2 | database


file: /var/www/catalogues/wp-content/sp-resources/forum-themes/unified/templates/spTopicView.php
line: 13
function: spdb_table
error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ” at line 1

SELECT expire_date FROM wp_sftopics WHERE topic_id=

 

Could help ?

YS Yellow Swordfish
Yellow Swordfish
Member

Could you copy and paste this part of the code here that you have used on your template please?

LE laurent enselme
laurent enselme
Member

Edit: solved – working fine, was my fault the second time 🙂

 

Thanks a lot for the help !

MP Mr Papa
Mr Papa
Member

interesting… we might need to check how my code (pasted directly from my working test) got converted to html entities… that should not be happening…

but glad you got it working…

LE laurent enselme
laurent enselme
Member

Got a new question about this plugin please.

In the topic list, is it possible to have a visualization when an expiration date has been set ?

Something like that:

Sans-titre-1-3.jpg
YS Yellow Swordfish
Yellow Swordfish
Member

I will let @mr-papa correct me if I am wrong as well as give more detail – but I do know that we have added a new template tag for this in the next plugin release which will along very soon now.

MP Mr Papa
Mr Papa
Member

No, that is not quite correct..   the change to the topic expire plugin was such to expose the expiration date in the standard forum and topic view classes so they could be more easily used…  in the code I provided previously, you had to do the query yourself…  once released, you will just need to do the display code (which will aid page loading times too)…

so to do what you want, easiest thing to do is add the following code to your spFunctions.php file of your them…

add_filter('sph_TopicIndexStatusIconsLast', 'my_expire_status');
function my_expire_status($out) {
    global $spThisTopic;
    $topic_expire = spdb_table(SFTOPICS, "topic_id=$spThisTopic->topic_id", 'expire_date');
    if ($topic_expire) $out.= sp_paint_icon('spIcon spIconNoAction', SPTHEMEICONSURL, 'sp_DeletePost.png', 'This topic has an expiration date');
    return $out;
}

as always, you should have a child or custom theme vice editing ours directly…

We can consider adding the capability for the status icon, as well as expiration date, directly into the plugin, but afraid that wont make it into the plugin release due any day..  would take bit more time to implement and test… and with WordPress 4.3 due in about a week, we will be focused on that…

you can customize the tooltip text if you like… and the icon… I just picked on that comes with all our themes…

LE laurent enselme
laurent enselme
Member

Thank you very much Mr Papa, working perfectly, and good luck for the updates !

Btw you stil have a problem with the “>” wink

“topic_id=$spThisTopic->topic_id”, ‘expire_date’);

LE laurent enselme
laurent enselme
Member

If it can help someone else, i have modified a bit the code, now showing the date in the topic list too:

 

add_filter(‘sph_TopicIndexStatusIconsLast’, ‘my_expire_status’);
function my_expire_status($out) {
global $spThisTopic;
$topic_expire = spdb_table(SFTOPICS, “topic_id=$spThisTopic->topic_id”, ‘expire_date’);
if ($topic_expire) $out.= sp_paint_icon(‘spIcon spIconNoAction’, SPTHEMEICONSURL, ‘sp_DeletePost.png’, ‘Ce sujet expire le ‘ .date(‘d/m/Y’, strtotime($topic_expire)));
return $out;
}

Sans-titre-1-4.jpg
YS Yellow Swordfish
Yellow Swordfish
Member

Nicely done there!
We have opened tickets to do something ‘official’ when we are able.

MP Mr Papa
Mr Papa
Member

yup. nice!

going to open a ticket because that htmlentities conversion should not be happening…  might be something has happened in tinymce in wp 4.3 and need to investigate before they release it…