Last active
January 1, 2016 04:59
-
-
Save GDmac/8095086 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
$plugin_info = array( | |
'pi_name' => 'Admin edit link', | |
'pi_version' => '1.0', | |
'pi_author' => 'GDmac', | |
'pi_author_url' => '', | |
'pi_description'=> 'Admin Edit link', | |
'pi_usage' => Admin_edit_link::usage() | |
); | |
class Admin_edit_link { | |
public $return_data = ""; | |
static $sess_id = ""; | |
// ----------------------------------------------------------------- | |
public function __construct() | |
{ | |
if (Admin_edit_link::$sess_id == "") | |
{ | |
$sess_type = ee()->config->item('admin_session_type'); | |
Admin_edit_link::$sess_id = ($sess_type == 'c') ? '0' : ee()->session->userdata['session_id']; | |
if (version_compare(APP_VER, '2.6.0', '>=') AND $sess_type == 'cs') | |
{ | |
Admin_edit_link::$sess_id = ee()->session->userdata['fingerprint']; | |
} | |
} | |
} | |
// ----------------------------------------------------------------- | |
public function fingerprint() | |
{ | |
return Admin_edit_link::$sess_id; | |
} | |
// ----------------------------------------------------------------- | |
public function edit() | |
{ | |
// # fetch parameters | |
$channel_id = ee()->TMPL->fetch_param('channel_id', false); | |
$entry_id = ee()->TMPL->fetch_param('entry_id', false); | |
$group_id = ee()->TMPL->fetch_param('group_id', false); | |
$extra = ee()->TMPL->fetch_param('extra', false); | |
// # channel_id and entry_id required | |
if ($channel_id == false || $entry_id == false) return false; | |
// # default member group 1 (super-admins) | |
if ($group_id == false) | |
{ | |
$group_id = 1; | |
} | |
else | |
{ | |
// # fetch groups and add superadmin group anyway | |
$group_id = explode('|', $group_id); | |
if (! in_array('1', $group_id)) $group_id[] = '1'; | |
} | |
// # is current user in provide (allowed) groups? | |
if (! in_array(ee()->session->userdata['group_id'], $group_id)) return false; | |
// create the url | |
$cp_url = ee()->config->default_ini['cp_url']; | |
$cp_url .= "?S=" . Admin_edit_link::$sess_id; | |
$cp_url .= "&D=cp&C=content_publish&M=entry_form&channel_id={$channel_id}&entry_id={$entry_id}"; | |
$this->return_data = ' | |
<div class="admin_edit"'.$extra.'> | |
<a href="'.$cp_url.'" target="cpsystem"> | |
Edit <!-- img src="/css/edit.gif" style="border:none;" --> | |
</a> | |
</div> | |
'; | |
return $this->return_data; | |
} | |
// ---------------------------------------------------------------- | |
/** | |
* Plugin Usage | |
*/ | |
public static function usage() | |
{ | |
ob_start(); | |
?> | |
include the plugin in the entries loop, provide parameters channel_id="{channel_id}" and | |
entry_id="{entry_id}" and each entry will have an "edit" link to the control-panel edit-entry form. | |
and provide member_group="1|6" for member groups. | |
{exp:admin_edit_link:edit channel_id="{channel_id}" entry_id="{entry_id}" group_id="1"} | |
(plugin needed because we need to set S=session in the url) | |
<?php | |
$buffer = ob_get_contents(); | |
ob_end_clean(); | |
return $buffer; | |
} | |
} | |
/* End of file pi.admin_edit_link.php */ | |
/* Location: /system/expressionengine/third_party/admin_edit_link/pi.admin_edit_link.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment