CGBlog post date older than 10 years ago can't choose year

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

CGBlog post date older than 10 years ago can't choose year

Post by paulbaker »

I have used Calguy's Wordpress to CGBlog converter to convert an old blog site which has been in existance since 2004 in to CMSMS. It works great. Thanks yet again CG. :D

However, some of the blog entries were posted more than 10 years ago, in 2004 & 2005 etc.

When they got converted the date was set to (or perhaps got changed to when later editing) 2006. This is because the Post Date drop down shows the years going back only 10 years:
CGBlog Post Date year drop down, going back only 10 years
CGBlog Post Date year drop down, going back only 10 years
dropdown.jpg (41.21 KiB) Viewed 1028 times
So, over time this will cause an error if you go into and edit a blog post more than 10 years old. Even though the year in the database might be stored correctly (say 2005), the HTML of the article edit page doesn't include 2005 in the drop down options and so it will default to the first item in the list (2006 here). Then when you save (without spotting what has happened), 2006 is stored as the year. So post date will be corrupted over time.

How can I show > 10 years back in the drop down to prevent this happening?

This sounds like a (pretty minor) bug to me?

----------------------------------------------
Cms Version: 2.1.2
Installed Modules:
AdminSearch: 1.0
CGBlog: 1.13.3
CGExtensions: 1.52.2
CGSimpleSmarty: 2.0.5
CG_WP2CGBlog: 1.0.6
CMSContentManager: 1.1
CMSMailer: 6.2.14
DesignManager: 1.1.1
FileManager: 1.5.2
FrontEndUsers: 1.31.1
JQueryTools: 1.3.8
MicroTiny: 2.0.3
ModuleManager: 2.0.2
Navigator: 1.0.2
News: 2.50.4
Search: 1.50.2

Config Information:
php_memory_limit:
max_upload_size: 32000000
url_rewriting: none
page_extension:
query_var: page
auto_alias_content: true
locale:
set_names: true
timezone: Europe/London
permissive_smarty: false

Php Information:
phpversion: 5.5.30
md5_function: On (True)
json_function: On (True)
gd_version: 2
tempnam_function: On (True)
magic_quotes_runtime: Off (False)
E_ALL: 22519
E_STRICT: 0
E_DEPRECATED: 0
test_file_timedifference: No time difference found
test_db_timedifference: No time difference found
create_dir_and_file: 1
memory_limit: 128M
max_execution_time: 120
register_globals: Off (False)
output_buffering: 4096
disable_functions:
open_basedir:
test_remote_url: Success
file_uploads: On (True)
post_max_size: 8M
upload_max_filesize: 32M
session_save_path: /tmp (1777)
session_use_cookies: On (True)
xml_function: On (True)
xmlreader_class: On (True)
check_ini_set: On (True)
curl: On

Performance Information:
allow_browser_cache: Off (False)
browser_cache_expiry: 60
php_opcache: Off (False)
smarty_cache: Off (False)
smarty_compilecheck: Off (False)
smarty_cache_udt: Off (False)
auto_clear_cache_age: On (True)
Server Information:
Server Software: Apache
Server Api: cgi-fcgi
Server Os: Linux 2.6.18-471.3.1.el5.lve0.8.72 On x86_64
Server Db Type: MySQL (mysqli)
Server Db Version: 5.5.48
Server Db Grants: Found a "GRANT ALL" statement that appears to be suitable

Permission Information:
tmp: /home/maidblokeadmin/public_html/mb/tmp (0755)
tmp_cache: /home/maidblokeadmin/public_html/mb/tmp/cache (0755)
templates_c: /home/maidblokeadmin/public_html/mb/tmp/templates_c (0755)
modules: /home/maidblokeadmin/public_html/mb/modules (0755)
uploads: /home/maidblokeadmin/public_html/mb/uploads (0755)
File Creation Mask (umask): /home/maidblokeadmin/public_html/mb/tmp/cache (0755)
config_file: 0444
----------------------------------------------
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: CGBlog post date older than 10 years ago can't choose ye

Post by velden »

module_custom to the rescue!

create a folder: 'module_custom/CGBlog/templates' relative to the CMSMS install root.
Copy editarticle.tpl from modules/CGBlog/templates/editarticle.tpl to this new folder.

Search and replace some occurences of '-10' with e.g. '-20' like this:

Code: Select all

{html_select_date prefix=$postdateprefix time=$postdate start_year="-10" end_year="+15"}

Code: Select all

{html_select_date prefix=$postdateprefix time=$postdate start_year="-20" end_year="+15"}
PS: don't forget about this change because future upgrades of CGBlog might need an updates editarticle.tpl. So perhaps good to add a line in the template reminding you if this customization in backend:

CUSTOM TEMPLATE
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: CGBlog post date older than 10 years ago can't choose ye

Post by paulbaker »

Thanks velden! Yes you have found a solution of sorts there.

I have used module_custom before. I used your idea but improved upon it a bit more, because over time if you put a fixed figure for the year in there (like -20) it will eventually fail. This is because the dropdown will run out of years and won't show the correct year (stored in the database) in the HTML, and so when submitted the form will corrupt the data, putting the wrong year in.

I improved this by changing

Code: Select all

{html_select_date prefix=$postdateprefix time=$postdate start_year="-10" end_year="+15"}
to

Code: Select all

{html_select_date prefix=$postdateprefix time=$postdate start_year="{$postdate|date_format:"%Y" - 10}" end_year="+15"}
so the form shows 10 years back from the date stored in the database, what ever that is. So even in (say) 30 years time, the edit article form will still display the correct post date year in the drop down.

I am still calling this a bug though, because CGBlog as shipped will corrupt data. So I have raised a bug report:
http://dev.cmsmadesimple.org/bug/view/10942
velden wrote:PS: don't forget about this change
Yes that's tripped me up before which is why I have gone off module_custom a bit. :-\
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
Post Reply

Return to “Modules/Add-Ons”