-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathext.last_editor.php
170 lines (132 loc) · 3.47 KB
/
ext.last_editor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* 3Easy Last Editor Extension
*
* @package 3Easy Last Editor
* @version 1.0.0
* @author 3Easy <http://3easy.org>
* @copyright Copyright (c) 2011 3Easy <http://3easy.org>
* @license http://creativecommons.org/licenses/by-sa/3.0/
* @see https://github.com/3Easy/last_editor.ee2_addon
*/
class Last_editor_ext
{
public $name = '3Easy Last Editor';
public $version = '1.0.0';
public $description = 'Add {last_editor} tag to exp:channel:entries';
public $settings_exist = 'n';
public $docs_url = 'https://github.com/3Easy/last_editor.ee2_addon';
/**
* Constructor
*
* @access public
* @return void
*
*/
function __construct($settings = '')
{
$this->EE =& get_instance();
// $this->settings = $settings;
}
/**
* Activate
*
* @access public
* @return void
*
**/
public function activate_extension()
{
$this->settings = array(
);
$data = array(
'class' => __CLASS__,
'method' => 'set_last_editor',
'hook' => 'entry_submission_end',
'settings' => serialize($this->settings),
'priority' => 10,
'version' => $this->version,
'enabled' => 'y'
);
$this->EE->db->insert('extensions', $data);
$data = array(
'class' => __CLASS__,
'method' => 'get_last_editor',
'hook' => 'channel_entries_tagdata_end',
'settings' => serialize($this->settings),
'priority' => 10,
'version' => $this->version,
'enabled' => 'y'
);
$this->EE->db->insert('extensions', $data);
$this->EE->db->query("ALTER TABLE exp_channel_titles ADD last_editor_id int(10) AFTER author_id");
}
/**
* Disable
*
* @access public
* @return void
*
*/
public function disable_extension()
{
$this->EE->db->where('class', __CLASS__);
$this->EE->db->delete('extensions');
$this->EE->db->query("ALTER TABLE exp_channel_titles DROP last_editor_id");
}
/**
* Update
*
* @access public
* @return void
*
*/
public function update_extension($current=FALSE)
{
if ($current == '' OR $current == $this->version)
{
return FALSE;
}
if ($current < '1.0')
{
// Update to version 1.0
}
$this->EE->db->where('class', __CLASS__);
$this->EE->db->update(
'extensions',
array('version' => $this->version)
);
}
/**
* Set Last Editor
*
* @access public
* @return void
*
*/
public function set_last_editor($entry_id)
{
$last_editor = $this->EE->session->userdata['member_id'];
$this->EE->db->query("UPDATE exp_channel_titles SET last_editor_id = '" . $last_editor . "' WHERE entry_id = '" . $entry_id ."'");
}
/**
* Get Last Editor
*
* @access public
* @return $tagdata
*
*/
public function get_last_editor($tagdata, $row)
{
if(in_array('last_editor', $this->EE->TMPL->var_single))
{
$result = $this->EE->db->query("SELECT last_editor_id, screen_name FROM exp_channel_titles INNER JOIN exp_members ON member_id = IF(last_editor_id IS NULL, author_id, last_editor_id) WHERE entry_id = '" . $row['entry_id'] ."'");
$last_editor_name = $result->row('screen_name');
$tagdata = $this->EE->TMPL->swap_var_single('last_editor', $last_editor_name, $tagdata);
}
return $tagdata;
}
}
// END CLASS
/* End of file ext.last_editor.php */
/* Location: ./system/expressionengine/third_party/last_editor/ext.last_editor.php */