Skip to content

Commit

Permalink
migrate to CI3 plugin system (Closes: #518)
Browse files Browse the repository at this point in the history
Fixes #518
  • Loading branch information
tenzap committed Oct 29, 2024
1 parent 43047ce commit 26b9f0b
Show file tree
Hide file tree
Showing 48 changed files with 2,943 additions and 1,726 deletions.
9 changes: 7 additions & 2 deletions application/config/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
| Plugins Directory
|--------------------------------------------------------------------------
|
| Set plugin directory, DO NOT CHANGE!
| Where are the plugins kept?
|
| Default: FCPATH . 'plugins/' (<root>/plugins/)
*/
// Use plugin_path instead of plugin_dir because that's what is used in
// Plugins_lib.php of upstream. Using 'plugin_dir' is actually a bug in upstream.
$config['plugin_path'] = APPPATH . 'plugins/';

$config['plugins_dir'] = APPPATH . 'plugins/';
require_once( APPPATH . 'libraries/abstract.plugins.php' );
require_once( APPPATH . 'libraries/trait.plugins.php' );
6 changes: 3 additions & 3 deletions application/controllers/Daemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function __construct()
// Commented this for allow access from other machine
// if($_SERVER['REMOTE_ADDR']!='127.0.0.1') exit("Access Denied.");
parent::__construct();
$this->load->library('Plugins');
$this->load->library('Plugins_lib_kalkun');
$this->load->database();
}

Expand Down Expand Up @@ -63,7 +63,7 @@ function message_routine()
if ( ! $is_spam)
{
// hook for incoming message (before ownership)
$status = do_action('message.incoming.before', $tmp_message);
$status = do_action_kalkun('message.incoming.before', $tmp_message);

// message deleted, do not process later part
if (isset($status) && $status === 'break')
Expand All @@ -80,7 +80,7 @@ function message_routine()
{
// hook for incoming message (after ownership)
$tmp_message->msg_user = $msg_user;
$status = do_action('message.incoming.after', $tmp_message);
$status = do_action_kalkun('message.incoming.after', $tmp_message);

// message deleted, do not process later part
if (isset($status) && $status === 'break')
Expand Down
10 changes: 10 additions & 0 deletions application/controllers/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ function _upgrade()
}
}

// Update SQL schema to version 0.8.3
if ( ! $this->Kalkun_model->plugins_table_has_status_column())
{
$error = $this->_execute_kalkun_sql_file('upgrade_kalkun_0.8.3.sql');
if ($error !== 0)
{
return $error;
}
}

// Update b8 table from v2 (of b8 0.5) to v3 schema (of b8 0.7)
$b8_db_version = NULL;
if ($this->db->field_exists('count', 'b8_wordlist'))
Expand Down
8 changes: 4 additions & 4 deletions application/controllers/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function __construct()
$param['uid'] = $this->session->userdata('id_user');

$this->load->model('Phonebook_model');
$this->load->library('Plugins');
$this->load->library('Plugins_lib_kalkun');
}

// --------------------------------------------------------------------
Expand Down Expand Up @@ -498,10 +498,10 @@ function compose_process()
// hook for outgoing message
if (isset($dest))
{
$dest = do_action('message.outgoing', $dest);
$sms = do_action('message.outgoing_all', $data);
$dest = do_action_kalkun('message.outgoing', $dest);
$sms = do_action_kalkun('message.outgoing_all', $data);

$dest_data = do_action('message.outgoing_dest_data', array($dest, $data));
$dest_data = do_action_kalkun('message.outgoing_dest_data', array($dest, $data));
if (sizeof($dest_data) === 2)
{
$dest = $dest_data[0];
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/Phonebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function __construct()
{
parent::__construct();
$this->load->model('Phonebook_model');
$this->load->library('Plugins');
$this->load->library('Plugins_lib_kalkun');
}

// --------------------------------------------------------------------
Expand Down Expand Up @@ -476,7 +476,7 @@ function get_phonebook($type = NULL)
}

// hook for contact get
$contact = do_action('phonebook.contact.get');
$contact = do_action_kalkun('phonebook.contact.get');
if (empty($contact))
{
$contact = array();
Expand Down
86 changes: 19 additions & 67 deletions application/controllers/Pluginss.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ function __construct()
redirect('/');
}

$this->load->library('Plugins');
$this->load->model('Plugin_model');
$this->load->library('Plugins_lib_kalkun');
$this->load->model('Plugins_kalkun_model');

$this->plugins_lib_kalkun->restore_orphaned_plugins();
$this->plugins_lib_kalkun->update_all_plugin_headers();

}

// --------------------------------------------------------------------
Expand All @@ -59,47 +63,27 @@ function index($type = 'installed')
if ($type === 'installed')
{
$data['title'] .= ' - '.tr_raw('Installed', 'Plural');
$data['plugins'] = $this->Plugin_model->get_plugins()->result_array();
foreach ($data['plugins'] as $key => $plugin)
foreach ($this->Plugins_kalkun_model->get_plugins() as $key => $plugin)
{
$data['plugins'][$key]['plugin_controller_has_index'] = $this->_plugin_controller_has_index($plugin['plugin_system_name']);
if (intval($plugin->status) === 1)
{
$data['plugins'][$key] = $plugin;
$data['plugins'][$key]->controller_has_index = $this->_plugin_controller_has_index($plugin->system_name);
}
}
}
else
{
$data['title'] .= ' - '.tr_raw('Available', 'Plural');
$plugins = $this->plugins->print_plugins();
$no = 0;

if ( ! empty($plugins))
foreach ($this->Plugins_kalkun_model->get_plugins() as $key => $plugin)
{
// do cleanup array key
foreach ($plugins as $key => $tmp)
{
$this->plugins->get_plugin_headers($key);
$new_plugin[$no] = array_merge (
array ('plugin_system_name' => $key),
$this->plugins->plugin_info($key)
);
$no++;
}
$installed = $this->Plugin_model->get_plugins()->result_array();

foreach ($new_plugin as $key => $tmp)
if (intval($plugin->status) !== 1)
{
foreach ($installed as $tmp2)
{
if (in_array($tmp['plugin_system_name'], $tmp2))
{
unset($new_plugin[$key]);
}
}
$data['plugins'][$key] = $plugin;
}
$result = $new_plugin;
uasort($result, array($this, '_plugins_cmp_plugin_name'));
$data['plugins'] = $result;
}
}
uasort($data['plugins'], array($this, '_plugins_cmp_plugin_name'));
$this->load->view('main/layout', $data);
}

Expand All @@ -114,7 +98,7 @@ function index($type = 'installed')
*/
function install($plugin_name)
{
$this->plugins->activate_plugin($plugin_name);
$this->plugins_lib_kalkun->enable_plugin($plugin_name);
$this->session->set_flashdata('notif', tr_raw('Plugin {0} installed successfully.', NULL, $plugin_name));
redirect('pluginss');
}
Expand All @@ -130,51 +114,19 @@ function install($plugin_name)
*/
function uninstall($plugin_name)
{
$this->plugins->deactivate_plugin($plugin_name);
$this->plugins_lib_kalkun->disable_plugin($plugin_name);
$this->session->set_flashdata('notif', tr_raw('Plugin {0} uninstalled successfully.', NULL, $plugin_name));
redirect('pluginss');
}

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

/**
* Activate
*
* Activated a plugin
*
* @access public
*/
function activate($plugin_name)
{
$data = array('plugin_status' => 'true');
$this->db->where('plugin_name', $plugin_name);
$this->db->update('plugin', $data);
}

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

/**
* Deactivate
*
* Deactivated a plugin
*
* @access public
*/
function deactivate($plugin_name)
{
$data = array('plugin_status' => 'false');
$this->db->where('plugin_name', $plugin_name);
$this->db->update('plugin', $data);
}

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

/**
* Callback function used to order the array of plugins by plugin name
*/
function _plugins_cmp_plugin_name($p1, $p2)
{
return strcasecmp ($p1['plugin_name'], $p2['plugin_name']);
return strcasecmp ($p1->name, $p2->name);
}

// --------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 26b9f0b

Please sign in to comment.