Page 1 of 1

{edit_news} tag?

Posted: Mon Apr 07, 2008 3:49 pm
by GDS
It would be nice to be able to access news articles for editing by clicking a icon or link,
like you can edit ordinary pages by using the {edit} tag. I have made a plugin that implements this idea:

This {edit_news} tag is based on the {edit} tag, but is adapted to be used in News templates.

Code: Select all

<?php
function smarty_cms_function_edit_news($params, &$smarty)
{
	global $gCms;

	if (!check_permission(get_userid(false), 'Modify Any Page'))
	  return;

	$text = isset($params['text']) ? $params['text']:'Edit This Article';
	$id = $params['id'];
	
		return '<a target="_blank" href="'.$gCms->config['root_url'].'/'.$gCms->config['admin_dir'].
    '/moduleinterface.php?mact=News,m1_,editarticle,0&m1_articleid='.$id.'"><img 
    align="left" src="'.$gCms->config['root_url'].'/images/cms/editbutton.png" alt="'.$text.'"/></a>';
}

function smarty_cms_help_function_edit_news() {
	?>
	<h3>What does this do?</h3>
	<p>Creates a link to edit the news article</p>
	<h3>How do I use it?</h3>
	<p>Just insert the tag into your News template like: <code>{edit2 showbutton='true' id=$entry->id}</code>
	
        <h3>What parameters does it take?</h3>
        <ul>
                <li><em>(required)</em> id - News article id.</li>
                <li><em>(optional)</em> text - text to show on hoover.</li> 
        </ul>
	<?php
}

function smarty_cms_about_function_edit_news() {
	?>
	<p>Author: Gaute Sandvik</p>
	<p>Version: 1.0</p>
	<p>This {edit_news} tag is based on the {edit} tag, but adapted to be used in News templates.</p>

	Change History:<br/>
          <p>
	  none
	</p>
	<?php
}

?>

It is also possible to merge this functionality into the existing edit tag, like this:


Code: Select all

<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


function smarty_cms_function_edit2($params, &$smarty)

/*
	global $gCms;

	if (!check_permission(get_userid(false), 'Modify Any Page')
	    && !quick_check_authorship($gCms->variables['content_id'],
				       author_pages(get_userid(false))))
	  return;

	$text = isset($params['text']) ? $params['text']:'Edit This Page';
	if (isset($params["showbutton"]))
	{
		return '<a href="'.$gCms->config['root_url'].'/'.$gCms->config['admin_dir'].
  '/editcontent.php?content_id='.$gCms->variables['content_id'].'"><img 
  src="'.$gCms->config['root_url'].'/images/cms/editbutton.png" alt="'.$text.'"/></a>';
	}
	else
	{
		return '<a href="'.$gCms->config['root_url'].'/'.$gCms->config['admin_dir'].
  '/editcontent.php?content_id='.$gCms->variables['content_id'].'">'.$text.'</a>';
	}

*/


{
	global $gCms;

	if (!check_permission(get_userid(false), 'Modify Any Page')
	    && !quick_check_authorship($gCms->variables['content_id'],
				       author_pages(get_userid(false))))
	  return;

	$text = isset($params['text']) ? $params['text']:'Edit This Page';
	if (isset($params["showbutton"]))
	{
		if(isset($params['id']))
  {
		 return '<a target="_blank" href="'.$gCms->config['root_url'].'/'.$gCms->config['admin_dir'].
   '/moduleinterface.php?mact=News,m1_,editarticle,0&m1_articleid='.$params['id'].'"><img  
   align="left" src="'.$gCms->config['root_url'].'/images/cms/editbutton.png" alt="'.$text.'"/></a>';
  }
  else 
  {
		 return '<a href="'.$gCms->config['root_url'].'/'.$gCms->config['admin_dir'].
   '/editcontent.php?content_id='.$gCms->variables['content_id'].'"><img 
   src="'.$gCms->config['root_url'].'/images/cms/editbutton.png" alt="'.$text.'"/></a>';
		} 
	}
	else
	{
	 if(isset($params['id']))
	 {
   return '<a target="_blank" href="'.$gCms->config['root_url'].'/'.$gCms->config['admin_dir'].
   '/moduleinterface.php?mact=News,m1_,editarticle,0&m1_articleid='.$params['id'].'">'.$text.'</a>';
  }
	 else 
  {
	  return '<a href="'.$gCms->config['root_url'].'/'.$gCms->config['admin_dir'].
   '/editcontent.php?content_id='.$gCms->variables['content_id'].'">'.$text.'</a>';
  }
 }
}

function smarty_cms_help_function_edit2() {
	?>
	<h3>What does this do?</h3>
	<p>Creates a link to edit the page.</p>
	<h3>How do I use it?</h3>
	
	<h4>Webpages</h4>
	<p>Just insert the tag into your web template/page like: <code>{edit2 showbutton='true'}</code>,<br>
	or you can apply it in your News templates like: <code>{edit2 showbutton='true' id=$entry->id}</code>
	
	
        <h3>What parameters does it take?</h3>
        <ul>
                <li><em>(optional)</em>showbutton - Set to "true" and will show a edit graphic instead of a text link.</li>
                <li><em>(optional)</em>text - Set this to change default text.</li>
                <li><em>(required for news articles)</em> id  - News article id.</li>
        </ul>
	<?php
}

function smarty_cms_about_function_edit2() {
	?>

	<p>Author: Sorin Sbârnea<sorin2000@intersol.ro> (remove 2000 from address)</p>
	<p>Version: 2.0</p>
	<p>
	Change History:<br/>
	<ul>
	<li>
	  This is a modified version of the {edit} tag.<br/> 
   Modifications made by Gaute Sandvik, gaute_sandvik@c2i.net, 04 april 2008: <br/>
   - id parameter added to be used with News articles.
  </li>
  
  </ul> 
	</p>
	<?php
}

?>


GDS

Re: {edit_news} tag?

Posted: Mon Apr 07, 2008 3:53 pm
by calguy1000
That's the wrong permission..... it should be 'Modify News'.  I think.

Re: {edit_news} tag?

Posted: Tue Apr 08, 2008 6:57 am
by GDS
Hi calguy1000,
'Modify News' works fine. Thanks!

I have changed the first part of the code to:

Code: Select all

<?php
function smarty_cms_function_edit_news($params, &$smarty)
{
	global $gCms;

	if (!check_permission(get_userid(false), 'Modify News'))	  return;


As with the merged version, I don't know enough about the permission system to suggest how to do this 100% correct. I leave it to others to eventually work further on this. For myself, I don't currently have any use of the fine grained permission system, as we only are two editors on our website at the moment.

GDS

Re: {edit_news} tag?

Posted: Thu May 28, 2009 9:17 am
by GDS
It is no longer possible to use this code because of changes in the News module.
This possibility used to save me from much work when editing news articles.

Is there anyone who knows a way to solve this problem?

GDS

Re: {edit_news} tag?

Posted: Fri May 29, 2009 5:55 pm
by GDS
This code seems to work:

Code: Select all

function smarty_cms_function_edit_news($params, &$smarty)
{
	global $gCms;

	if (!check_permission(get_userid(false), 'Modify News')
	    && !quick_check_authorship($gCms->variables['content_id'],
				       author_pages(get_userid(false))))
	  return;
 
	$text = isset($params['text']) ? $params['text']:'Edit This Article';
	$id = $params['id'];
	
	$urlext= CMS_SECURE_PARAM_NAME.'='.$_SESSION[CMS_USER_KEY];
	return '<a href="'.$gCms->config['root_url'].'/'.$gCms->config['admin_dir'].
   '/moduleinterface.php?mact=News,m1_,editarticle,0&'. $urlext .'&m1_articleid='.$id.'"><img
   src="'.$gCms->config['root_url'].'/images/cms/editbutton.png" alt="'.$text.'"/></a>';
}

GDS