• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Making articles editable *only* by Author
PostPosted: Tue Apr 05, 2011 12:01 am 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 332
I wanted to have articles edited only by the ones who create them (Author) and provide the Author a way to manually allow additional authors to edit the article.

As the goal of this article is to limit control over the News articles, it seems logical to create a group of editors that don't have permission to remove articles, not? To achieve this, just make sure the article editors don't have the "Delete News Articles" permission...

  • 1. Create a new folder: /module_custom/News/templates
  • 2. Copy the file "editarticle.tpl" from the /modules/News/templates folder in to the folder you just created

Change the top of the /module_custom/News/templates/editarticle.tpl file like this:
Code:
{$startform}
{capture assign='adminname'}{$smarty.session.cms_admin_username}{/capture}
{if substr_count($extravalue, $adminname)}{assign var='editor' value='1'}{/if}
{if $adminname == "$inputauthor" || $adminname == '##REPLACE_WITH_YOUR_OWN##' || $inputauthor == '' || $editor == '1'}
{if $inputauthor}

This will allow the following scenarios where the article content can be edited:
  • - The logged in user is the author
  • The logged in user is the admin (probably you ;)
  • - No author has been set (allows creation of new articles)
    • - ps: As a consequence, if you remove a user login from the CMSMS installation, his or her articles become editable by everyone else...
  • - The logged in user is an "additional editor" (entered manually by the original Author)

Change the bottom of the file like this:
Code:
{else}<b style="color:red;">This article has been created by an other user ({$inputauthor}).<br>Cet article a &eacute;t&eacute; cr&eacute;&eacute; par un autre utilisateur ({$inputauthor}).<br>Dit artikel werd aangemaakt door een andere gebruiker ({$inputauthor}).</b>{/if}{$endform}

When editing or creating an article, the Author may enter user names of the "additional editors" in the Extra field separated by comma's (or not ;-)

To avoid users (easily) publishing and unpublishing each others articles, you can remove these buttons from the article list view.
Authors and "additional authors" will still have the possibility to publish/unpublish while editing the articles.

  • 1. Copy the file "articlelist.tpl" from the /modules/News/templates folder in to the /module_custom/News/templates folder
  • 2. Comment out (or remove) the following lines:
    • 1. <th class="pageicon">{$statustext}</th>
    • 2. <td>{if isset($entry->approve_link)}{$entry->approve_link}{/if}</td>

ps: if someone happens to know how to easily change the Author of an article, please let me know!
ps2: I've also posted this article on the i-do-this blog.
ps3: A shout if you like what you see is appreciated ;D

Greetings,
Manuel


Last edited by manuel on Tue Apr 05, 2011 1:53 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Tue Apr 05, 2011 12:10 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1321
Fantastic idea!

One suggestion: Instead of copying the whole template, you can {include} the original template between your code blocks.. You won't have to re-implement when you upgrade if the News template changes.


Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Tue Apr 05, 2011 11:53 am 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 332
Hi Wishbone,

Maintenance free :D sounds very interesting!

One remark though, the additional code needs to be inside the {$startform} and {$endform}tags (these are included in the default template)

Maybe we could capture the content of the template to a variable, remove these startform and endform tags from the captured template?
I'm not really sure on how to remove the startform and endform tags from the captured template though... Maybe cutt off the 1st 12 caracters and the last 10 from the variable? This seems like a very unstable solution though...

Something like this could be used to capture the template file contents *untested*
Code:
{capture assign='capturedtemplate'}{include  file='/modules/News/templates/editarticle.tpl'}{/capture}

Or maybe we can just be naughty and have double startform and endform tags? I'll test this and update the thread.

Something like this: *untested*
Code:
{$startform}
{capture assign='adminname'}{$smarty.session.cms_admin_username}{/capture}
{if substr_count($extravalue, $adminname)}{assign var='editor' value='1'}{/if}
{if $adminname == "$inputauthor" || $adminname == '##REPLACE_WITH_YOUR_OWN##' || $inputauthor == '' || $editor == '1'}
{include  file='/modules/News/templates/editarticle.tpl'}
{else}<b style="color:red;">This article has been created by an other user ({$inputauthor}).<br>Cet article a &eacute;t&eacute; cr&eacute;&eacute; par un autre utilisateur ({$inputauthor}).<br>Dit artikel werd aangemaakt door een andere gebruiker ({$inputauthor}).</b>{/if}{$endform}

ps: thanks for the {include} tip, i'm still very much learning the possibilities of smarty :)

Greetings,
Manuel


Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Tue Apr 05, 2011 1:17 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 332
The code below works fine:
Code:
{$startform}
{capture assign='adminname'}{$smarty.session.cms_admin_username}{/capture}
{if substr_count($extravalue, $adminname)}{assign var='editor' value='1'}{/if}
{if $adminname == "$inputauthor" || $adminname == '##REPLACE_WITH_YOUR_ADMIN_NAME##' || $inputauthor == '' || $editor == '1'}
{include file='##REPLACE_WITH_YOUR_ABSOLUTE_PATH##/modules/News/templates/editarticle.tpl'}
{else}<b style="font-weight:bold;color:red;">This article has been created by an other user ({$inputauthor}).<br>Cet article a &eacute;t&eacute; cr&eacute;&eacute; par un autre utilisateur ({$inputauthor}).<br>Dit artikel werd aangemaakt door een andere gebruiker ({$inputauthor}).</b>{/if}
{$endform}
Next step: Remove the codes from the articlelist.tpl

After a lot of failed attempts, I finally figured out how to replace strings containing brackets ;D
I'll update the thread later with the correct regex_replace...

Code:
Code:
{capture assign='testingg'}{literal}q{$startform}q{$endform}q{/literal}{/capture}
{capture assign='toreplace1'}{literal}(\{\$startform\}){/literal}{/capture}
{capture assign='toreplace2'}{literal}(\{\$endform\}){/literal}{/capture}
{$testingg|regex_replace:"$toreplace1":""|regex_replace:"$toreplace2":""}

Result:
Code:
qqq

Greetings,
Manuel


Last edited by manuel on Tue Apr 05, 2011 2:25 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Tue Apr 05, 2011 2:09 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1321
You can clear {$startform} and {$endform} before including the News template... When the original template calls them, they'll do nothing. You'll have to capture the original values of the variables so you can still use them.

Code:
{assign var='newstartform' value=$startform}
{assign var='newendform' value=$endform}
{assign var='startform' value=''}
{assign var='endform' value=''}

{$startform}

{* Insert top code block here *}

{include file='/path/to/editarticle.tpl'}

{* Insert bottom code block here *}

{$new_endform}

If I'm doing any complicated logic, I like to first call a UDT which will read all the template variables in question, modify them, then hand control back to the original logic. Complicated logic is much easier to read in PHP instead of Smarty


Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Tue Apr 05, 2011 2:26 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 332
Nice :)

Code:
{assign var='new_startform' value=$startform}
{assign var='new_endform' value=$endform}
{assign var='startform' value=''}
{assign var='endform' value=''}

{$new_startform}

{capture assign='adminname'}{$smarty.session.cms_admin_username}{/capture}
{if substr_count($extravalue, $adminname)}{assign var='editor' value='1'}{/if}
{if $adminname == "$inputauthor" || $adminname == '##REPLACE_WITH_YOUR_ADMIN_USERNAME##' || $inputauthor == '' || $editor == '1'}
{include file='##REPLACE_WITH_YOUR_ABSOLUTE_PATH##/modules/News/templates/editarticle.tpl'}
{else}<b style="font-weight:bold;color:red;">This article has been created by an other user ({$inputauthor}).<br>Cet article a &eacute;t&eacute; cr&eacute;&eacute; par un autre utilisateur ({$inputauthor}).<br>Dit artikel werd aangemaakt door een andere gebruiker ({$inputauthor}).</b>{/if}

{$new_endform}

I'm trying to remove the unwanted lines of code from the articlelist but regex_replace but nothing is changing... (and no error messages appear)
Code:
{capture assign='capturedtemplate'}{include file='##ABSOLUTE_PATH_HERE##/modules/News/templates/articlelist.tpl'}{/capture}
{capture assign='toreplace1'}{literal}(<th class=\"pageicon\">\{\$statustext\}<\/th>){/literal}{/capture}
{capture assign='toreplace2'}{literal}(<td>\{if isset\(\$entry->approve_link\)\}\{\$entry->approve_link\}\{\/if\}<\/td>){/literal}{/capture}
{$capturedtemplate|regex_replace:"$toreplace1":""|regex_replace:"$toreplace2":""}


Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Tue Apr 05, 2011 3:38 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 332
When the articlelist.tpl is captured, the {$statustext} has already been replaced with the word "Status".


Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Tue Apr 05, 2011 9:11 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 332
damn, i learned a lot about regex today :)

Final update (i hope) for a maintenance free setup:
Contents of module_custom/News/templates/articlelist.tpl
Code:
{assign var='statustext' value='REPLACED'}
{include file='file:##REPLACE_WITH_YOUR_ABSOLUTE_PATH##/modules/News/templates/articlelist.tpl' assign='capturedtemplate'}
{$capturedtemplate|regex_replace:"/(<th class=\"pageicon\">REPLACED<\/th>)/":""|regex_replace:"/(<td)(.)*?(icons\/system\/true.gif|icons\/system\/false.gif)(.)*?(<\/a><\/td>)/":""}

I replace the value of the statustext to avoid users with a different language setting to cirumvent the regex_replace...

Contents of module_custom/News/templates/editarticle.tpl
Code:
{assign var='new_startform' value=$startform}
{assign var='new_endform' value=$endform}
{assign var='startform' value=''}
{assign var='endform' value=''}

{$new_startform}

{capture assign='adminname'}{$smarty.session.cms_admin_username}{/capture}
{if substr_count($extravalue, $adminname)}{assign var='editor' value='1'}{/if}
{if $adminname == "$inputauthor" || $adminname == '##REPLACE_WITH_YOUR_ADMIN_USERNAME##' || $inputauthor == '' || $editor == '1'}
{include file='##REPLACE_WITH_YOUR_ABSOLUTE_PATH##/modules/News/templates/editarticle.tpl'}
{else}<b style="font-weight:bold;color:red;">This article has been created by an other user ({$inputauthor}).<br>Cet article a &eacute;t&eacute; cr&eacute;&eacute; par un autre utilisateur ({$inputauthor}).<br>Dit artikel werd aangemaakt door een andere gebruiker ({$inputauthor}).</b>{/if}

{$new_endform}

Now if someone could share some insight on how to change the Author of an article, the issue of "remove user from cmsms installation > articles owned by removed user are now editable by all" could be tackled...

Greetings,
Manuel


Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Tue Apr 05, 2011 9:16 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1321
I can make a UDT to change the author to the primary admin when a DeleteUserPost event is triggered, if that's what you are looking for.


Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Tue Apr 05, 2011 9:29 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 332
That sounds perfect!
I would indeed love to see that!!

Greetings,
Manuel


Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Tue Apr 05, 2011 10:05 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1321
OK.. I'll hack one up tonight.


Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Mon Apr 11, 2011 11:06 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 332
small update:
module_custom/News/templates/articlelist.tpl (now showing removed items to admin)
Code:
{capture assign='adminname'}{$smarty.session.cms_admin_username}{/capture}
{if $adminname != '##REPLACE_WITH_YOUR_ADMIN_USERNAME##'}
{assign var='statustext' value='REPLACED'}
{include file='file:##REPLACE_WITH_YOUR_ABSOLUTE_PATH##/modules/News/templates/articlelist.tpl' assign='capturedtemplate'}
{$capturedtemplate|regex_replace:"/(<th class=\"pageicon\">REPLACED<\/th>)/":""|regex_replace:"/(<td)(.)*?(icons\/system\/true.gif|icons\/system\/false.gif)(.)*?(<\/a><\/td>)/":""}
{else}
{include file='file:##REPLACE_WITH_YOUR_ABSOLUTE_PATH##/modules/News/templates/articlelist.tpl'}
{/if}

module_custom/News/templates/editarticle.tpl (remains the same as posted above)

/module_custom/News/templates/customfieldstab.tpl: (If you don't want editors testing out what would happen if they edit your custom field definitions...)
Code:
{capture assign='adminname'}{$smarty.session.cms_admin_username}{/capture}
{if $adminname != '##REPLACE_WITH_YOUR_ADMIN_USERNAME##'}
<p style="color:red;">Deze functie is niet beschikbaar</p>
<p style="color:red;">Cette fonctionnalit&eacute; n'est pas disponible</p>
<p style="color:red;">This feature is not available</p>
{else}
{include file='file:##REPLACE_WITH_YOUR_ABSOLUTE_PATH##/modules/News/templates/customfieldstab.tpl'}
{/if}

/module_custom/News/templates/categorylist.tpl (If you don't want editors messing up your hard coded categories...)
Code:
{capture assign='adminname'}{$smarty.session.cms_admin_username}{/capture}
{if $adminname != '##REPLACE_WITH_YOUR_ADMIN_USERNAME##'}
<p style="color:red;"><a href="##URL##" target="_blank">Contacteer ##COMPANY##</a> om een categorie toe te voegen</p>
<p style="color:red;"><a href="##URL##" target="_blank">Contactez ##COMPANY##</a> pour ajouter une cat&eacute;gorie</p>
<p style="color:red;"><a href="##URL##" target="_blank">Contact ##COMPANY##</a> to add a category</p>
{else}
{include file='file:##REPLACE_WITH_YOUR_ABSOLUTE_PATH##/modules/News/templates/categorylist.tpl'}
{/if}

Greetings,
Manuel


Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Wed Apr 03, 2013 3:32 pm 
Offline
Forum Members
Forum Members

Joined: Fri Jul 11, 2008 12:53 pm
Posts: 25
Hi Manuel,

Know this is an old post, but still very usefull! Thanks a lot for your great piece of work. Didn't know about module_custom, so I learned a lot!

Wondered if it is possible to only list the articles that are editable by Author and hide the rest.

Inula.


Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Wed Apr 03, 2013 8:44 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 332
Dear Inula,

Glad you found it useful! :)
To edit the list that is being displayed, you should look at further customizing "articlelist.tpl" (the part below the {foreach from=$items item=entry} where the rows are created listing the articles).
You will need to verify if you can use the same conditions like they are currently used in the "editarticle.tpl" where they determine if the article can be shown/edited or not.
To have this work, the critical test to perform will be "can i use $extravalue" inside that foreach...
Quote:
{capture assign='adminname'}{$smarty.session.cms_admin_username}{/capture}
{if substr_count($extravalue, $adminname)}{assign var='editor' value='1'}{/if}
{if $adminname == "$inputauthor" || $adminname == '##REPLACE_WITH_YOUR_ADMIN_USERNAME##' || $inputauthor == '' || $editor == '1'}

ps: fair warning: please only use this for non-super-secure websites as the $smarty.session.cms_admin_username is grabbed from a cookie!

Maybe someone who can make a UDT that doesn't grab the admin username from a cookie is reading this? Your input would be greatly appreciated! ;D (can't hurt to try...)

ps2: you can read about using module_custom for customizing language strings and customizing admin templates in the official cmsms docs

Greetings,
Manuel

_________________
Do you like your open source cms? Buy from the CMSMS partners || Donate
(or at least share some knowledge :D >> See some of my stuff )


Top
 Profile  
 
 Post subject: Re: Making articles editable *only* by Author
PostPosted: Sat Apr 06, 2013 6:06 pm 
Offline
Forum Members
Forum Members

Joined: Fri Jul 11, 2008 12:53 pm
Posts: 25
Dear Manuel,

Have been working on it today. Can't even get the inputauthor to show up in de articlelist. So I think it's not possible to only show the articles from logged-in author.

Thanks anyway!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting