forked from litzinger/Disposition
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathext.disposition.php
More file actions
188 lines (154 loc) · 5.68 KB
/
ext.disposition.php
File metadata and controls
188 lines (154 loc) · 5.68 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if (! defined('DISPOSITION_VERSION'))
{
// get the version from config.php
require PATH_THIRD.'disposition/config.php';
define('DISPOSITION_VERSION', $config['version']);
define('DISPOSITION_NAME', $config['name']);
define('DISPOSITION_DESCRIPTION', $config['description']);
define('DISPOSITION_DOCS_URL', $config['docs_url']);
}
/**
* ExpressionEngine Disposition Extension Class
*
* @package ExpressionEngine
* @subpackage Extensions
* @category Disposition
* @author Brian Litzinger
* @copyright Copyright 2010 - Brian Litzinger
* @link http://boldminded.com/add-ons/disposition
*/
class Disposition_ext {
var $settings = array();
var $name = DISPOSITION_NAME;
var $version = DISPOSITION_VERSION;
var $description = DISPOSITION_DESCRIPTION;
var $docs_url = DISPOSITION_DOCS_URL;
var $settings_exist = 'y';
function Disposition_ext($settings='')
{
$this->EE =& get_instance();
$settings = $this->_get_settings();
// All settings
$this->global_settings = $settings;
// Site specific settings
$site_id = $this->EE->config->item('site_id');
$this->settings = isset($settings[$site_id]) ? $settings[$site_id] : array();
}
/**
* Custom settings form
*/
function settings_form($vars)
{
$channels = array();
$vars = $this->settings;
$this->EE->lang->loadfile('disposition');
$query = $this->EE->db->get('channels');
foreach($query->result_array() as $channel)
{
$channels[$channel['channel_id']] = $channel['channel_title'];
}
$vars['hidden'] = array('file' => 'disposition');
$vars['channels'] = $channels;
$vars['enabled_channels'] = isset($this->settings['enabled_channels']) ? $this->settings['enabled_channels'] : false;
// Load it up and return it to addons_extensions.php for rendering
return $this->EE->load->view('settings_form', $vars, TRUE);
}
/**
* Custom save action
*/
function save_settings()
{
$insert['enabled_channels'] = $this->EE->input->post('enabled_channels');
// Save our settings to the current site ID for MSM.
$site_id = $this->EE->config->item('site_id');
$settings = $this->global_settings;
$settings[$site_id] = $insert;
$this->EE->db->where('class', strtolower(__CLASS__));
$this->EE->db->update('extensions', array('settings' => serialize($settings)));
$this->EE->session->set_flashdata('message_success', $this->EE->lang->line('preferences_updated'));
}
/**
* Install the extension
*/
function activate_extension()
{
// Delete old hooks
$this->EE->db->query("DELETE FROM exp_extensions WHERE class = '". __CLASS__ ."'");
// Add new hooks
$ext_template = array(
'class' => __CLASS__,
'settings' => '',
'priority' => 5,
'version' => $this->version,
'enabled' => 'y'
);
$extensions = array(
array('hook'=>'bogus_hook', 'method'=>'bogus_hook'),
);
foreach($extensions as $extension)
{
$ext = array_merge($ext_template, $extension);
$this->EE->db->insert('exp_extensions', $ext);
}
$this->EE->db->where('class', 'Disposition_acc')
->update('accessories', array('controllers' => 'content_edit'));
}
/**
* @param string $current currently installed version
*/
function update_extension($current = '')
{
if ($current == '' OR $current == $this->version)
{
return FALSE;
}
}
/**
* Uninstalls extension
*/
function disable_extension()
{
$this->EE->db->delete('extensions', array('class' => __CLASS__));
}
/**
* Get the site specific settings from the extensions table
* Originally written by Leevi Graham? Modified for EE2.0
*
* @param $force_refresh bool Get the settings from the DB even if they are in the session
* @return array If settings are found otherwise false. Site settings are returned by default.
*/
private function _get_settings($force_refresh = FALSE)
{
// assume there are no settings
$settings = FALSE;
$this->EE->load->helper('string');
// Get the settings for the extension
if(isset($this->cache['settings']) === FALSE || $force_refresh === TRUE)
{
// check the db for extension settings
$query = $this->EE->db->query("SELECT settings FROM exp_extensions WHERE enabled = 'y' AND class = '" . __CLASS__ . "' LIMIT 1");
// if there is a row and the row has settings
if ($query->num_rows() > 0 && $query->row('settings') != '')
{
// save them to the cache
$this->cache['settings'] = strip_slashes(unserialize($query->row('settings')));
}
}
// check to see if the session has been set
// if it has return the session
// if not return false
if(empty($this->cache['settings']) !== TRUE)
{
$settings = $this->cache['settings'];
}
return $settings;
}
private function debug($str, $die = false)
{
echo '<pre>';
var_dump($str);
echo '</pre>';
if($die) die('debug terminated');
}
}