Problems, need help? Have a tip or advice? Post it here.
10 posts Page 1 of 1
Hi Guys!
Good afternoon!

I developing a news web that implement citizen journalism. So someone can register to the web and can submit a news.

What i want is, the user can submit news, but only publishd for 30 days, and after 30 days, it will auto unpublishd.

Any help needd. Thx guys!
As soon as possible!

Touch me up : abada[dot]zulma[at]gmail[dot]com
Hi :)

I think you'll find the following discussion useful -
viewtopic.php?f=4&t=9361

The solution proposed above automatically removes the stale posts from all cms:pages listings.
However, the pages will still be available if somebody accesses them using their direct URLs.
Usually this is fine but if you'd want the stale pages to be completely inaccessible, let me know.

Hope it helps.
KK wrote: Hi :)

I think you'll find the following discussion useful -
viewtopic.php?f=4&t=9361

The solution proposed above automatically removes the stale posts from all cms:pages listings.
However, the pages will still be available if somebody accesses them using their direct URLs.
Usually this is fine but if you'd want the stale pages to be completely inaccessible, let me know.

Hope it helps.

Thx for pointing KK, but i need to make the unpublishd clonable page totally inaccessible, also i need some indicator on couch admin, like theres a date on publishd page, and "Unpublised" text for unpublished page.
As soon as possible!

Touch me up : abada[dot]zulma[at]gmail[dot]com
Please tell me one thing -
suppose the template where all user-submitted news go is 'news.php', do *all* cloned-pages of this template need to have a 30 days life? Or will there be some pages in it that need to be exempted from being discarded after 30 days of their publishing?
KK wrote: Please tell me one thing -
suppose the template where all user-submitted news go is 'news.php', do *all* cloned-pages of this template need to have a 30 days life? Or will there be some pages in it that need to be exempted from being discarded after 30 days of their publishing?


Kk, Is it possible to add a field that i can enter how many days the news will publishd? Or maybe a date picker?
Thx!
As soon as possible!

Touch me up : abada[dot]zulma[at]gmail[dot]com
Is it possible to add a field that i can enter how many days the news will publishd? Or maybe a date picker?
Yes, of course it is possible.
So am I to understand then that each news item can have a different expiry date or the field you mentioned will be 'global' and affect all news pages - this, incidentally, was my original question that you did not answer. Could you please do that now?

Thanks.
KK wrote:
Is it possible to add a field that i can enter how many days the news will publishd? Or maybe a date picker?
Yes, of course it is possible.
So am I to understand then that each news item can have a different expiry date or the field you mentioned will be 'global' and affect all news pages - this, incidentally, was my original question that you did not answer. Could you please do that now?

Thanks.

Sorry KK, Yes KK, it will affect all page under news.php.
Thx KK.
As soon as possible!

Touch me up : abada[dot]zulma[at]gmail[dot]com
Ok, thanks.

Limiting the pages to a certain time-period will not require any additional editable-region.

While listing all pages, we just need to calculate the date 30 days (e.g.) before the current date and then ask cms:pages to fetch pages starting from that date.

To do the calculation we'll fall back on a little PHP (you can find many more examples here - viewtopic.php?f=8&t=8316) -
Code: Select all
<cms:php>
    global $CTX;
   
    // calculate start date that is minus 30 days from now
    $ts_now = strtotime( "<cms:date format='Y-m-d H:i:s' />" );
    $CTX->set( 'my_start_date', date('Y-m-d H:i:s', strtotime("-30 days", $ts_now)), 'global' );
</cms:php>

The 'my_start_date' variable will now always contain the date from one month back.
Use it with cms:pages as follows -
<cms:pages masterpage='whatever.php' start_on=my_start_date >
..
</cms:pages>

And now you'll never list any pages older than 30 days.

That takes care of the list-view.
Let us tackle the page-view next so that if someone (other than the admins) directly visits an expired page she should get a 404 Not found error.

To do that use the following in the page_view -
Code: Select all
<cms:if k_page_date lt my_start_date >
    <cms:if k_user_access_level lt '7'>
        <cms:abort is_404='1' />
    </cms:if>   
</cms:if>

All the examples above had a period of 30 days hardcoded into them.
To make that period user-configurable, define an editable region in a global template (http://docs.couchcms.com/tutorials/port ... bal-values) as follows -
Code: Select all
<cms:editable 
    type='text'
    name='expiry_duration'
    label='Expiry Duration'
    desc='set the number of days after which a submitted news item expires e.g. 30'
    validator='non_negative_integer'
    required='1'
>30</cms:editable>

And now modify our original PHP code calculating the date as follows to use the global region -
Code: Select all
<cms:php>
    global $CTX;
   
    // calculate start date that is minus user-configured days from now
    $ts_now = strtotime( "<cms:date format='Y-m-d H:i:s' />" );
    $CTX->set( 'my_start_date', date('Y-m-d H:i:s', strtotime("-<cms:get_custom_field 'expiry_duration' masterpage='globals.php' /> days", $ts_now)), 'global' );
</cms:php>

Hope it helps.
After 6 days, i can confirm that this worked :D

Thx KK!
As soon as possible!

Touch me up : abada[dot]zulma[at]gmail[dot]com
I'm glad it did, @GoingMarryAsap :)
10 posts Page 1 of 1