File: Plugin_controller.php

package info (click to toggle)
kalkun 0.8.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 7,340 kB
  • sloc: php: 30,659; javascript: 30,443; sql: 961; sh: 766; xml: 105; makefile: 40
file content (129 lines) | stat: -rw-r--r-- 3,620 bytes parent folder | download | duplicates (2)
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
<?php
/**
 * Kalkun
 * An open source web based SMS Management
 *
 * @package		Kalkun
 * @author		Kalkun Dev Team
 * @license		https://spdx.org/licenses/GPL-2.0-or-later.html
 * @link		https://kalkun.sourceforge.io/
 */

// ------------------------------------------------------------------------

/**
 * Plugin_controller Class
 *
 * Check all plugin requirement before run
 *
 * @package		Kalkun
 * @subpackage	Plugin
 * @category	Controllers
 */
class Plugin_controller extends MY_Controller {

	var $plugin_name = '';
	var $plugin_version = '';
	var $plugin_author = '';
	var $plugin_view_dir = '';

	function __construct($login = TRUE)
	{
		parent::__construct($login);

		$this->load->helper('i18n');

		// Prevent non-admin user
		if ($login && $this->session->userdata('level') !== 'admin')
		{
			$this->session->set_flashdata('notif', tr_raw('Access denied. Only administrators are allowed to manage plugins.'));
			redirect('/');
		}

		$this->plugin_name = strtolower(get_class($this));

		// Prevent this controller from being called directly
		if (__CLASS__ === get_class($this))
		{
			redirect(site_url('/'), 'location', 301);
		}
		//$this->load->library('Plugins');
		//$this->load->library('plugins', array('plugins_dir' => 'application/plugins/'));
		// Check if plugin is active
		$CI = &get_instance();
		$this->load->library('Plugins_lib_kalkun');
		if ( ! isset($this->plugins_lib_kalkun->get_enabled_plugins()[$this->plugin_name]))
		{
			$message = tr_raw('Plugin {0} is not installed.', NULL, $this->plugin_name);
			$this->session->set_flashdata('notif', $message);
			if ($this->plugin_name === 'rest_api')
			{
				// Special case for rest_api. If one makes a call to the rest_api while the plugin
				// is not installed, the user wouldn't be notified because with rest_api plugin
				// we don't use Kalkun's built-in authentification mechanism.
				show_error($message, 503);
			}
			else
			{
				redirect('pluginss');
			}
		}

		// Temporarily add the plugin path to package path to load language, config...
		$this->load->add_package_path(APPPATH . 'plugins/' . $this->plugin_name, FALSE);

		// Load translations
		if (file_exists(APPPATH . 'plugins/' . $this->plugin_name . '/language/english/' . $this->plugin_name . '_lang.php'))
		{
			$this->lang->load($this->plugin_name);
		}

		// Load plugin config
		// Access config items with: $this->config->config[$plugin_name]->item('config_item');
		if (file_exists(APPPATH . 'plugins/' . $this->plugin_name . '/config/' . $this->plugin_name . '.php'))
		{
			$this->load->config($this->plugin_name, TRUE);
		}

		// Remove plugin path from package path now that we finished loading language, config...
		$this->load->remove_package_path(APPPATH . 'plugins/' . $this->plugin_name);
	}

	// --------------------------------------------------------------------

	/**
	 * Initialize
	 *
	 * @access	public
	 * @param	array	initialization parameters
	 * @return	void
	 */
	function initialize($params = array())
	{
		if (count($params) > 0)
		{
			foreach ($params as $key => $val)
			{
				if (isset($this->$key))
				{
					$this->$key = $val;
				}
			}
		}

		// Check if all required value already set, otherwise thrown error
		// ...
		// Check if plugin already installed
		// ..
		// Check if plugin activated
		// ..
		// Set plugin view directory
		$this->plugin_view_dir = 'plugin/' . $this->plugin_name . '/';

		// if models exist
		if (file_exists(APPPATH . 'models/plugin/' . $this->plugin_name . '_model.php'))
		{
			$this->load->model('plugin/' . $this->plugin_name . '_model', $this->plugin_name . '_model');
		}
	}
}