Skip to content

Instantly share code, notes, and snippets.

@phylaxis
Created February 26, 2014 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phylaxis/9237690 to your computer and use it in GitHub Desktop.
Save phylaxis/9237690 to your computer and use it in GitHub Desktop.
Add CKButton to Wygwam
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Bbm_ckbuttons_ext
{
var $name = 'BBM CKButtons';
var $version = '1.0';
var $description = 'Adds custom TMO buttons to Wygwam CKEditor';
var $docs_url = 'http://backbeatmedia.com/';
var $settings_exist = 'n';
private static $_included_resources = FALSE;
private $_hooks = array(
'wygwam_config',
'wygwam_tb_groups',
);
function activate_extension()
{
foreach ($this->_hooks as $hook)
{
ee()->db->insert('extensions', array(
'class' => __CLASS__,
'method' => $hook,
'hook' => $hook,
'settings' => '',
'priority' => 10,
'version' => $this->version,
'enabled' => 'y'
));
}
}
function update_extension($current = NULL)
{
return FALSE;
}
function disable_extension()
{
ee()->db->where('class', __CLASS__)->delete('extensions');
}
function wygwam_config($config, $settings)
{
if (($last_call = ee()->extensions->last_call) !== FALSE)
{
$config = $last_call;
}
// Check if our toolbar button has been added
$include_btn = FALSE;
foreach ($config['toolbar'] as $tbgroup)
{
if (in_array('TMOAddPage', $tbgroup))
{
$include_btn = TRUE;
break;
}
}
if ($include_btn)
{
// Add our plugin to CKEditor
if (!empty($config['extraPlugins']))
{
$config['extraPlugins'] .= ',';
}
$config['extraPlugins'] .= 'tmo-addpage';
$this->_include_resources();
}
return $config;
}
function wygwam_tb_groups($tb_groups)
{
if (($last_call = ee()->extensions->last_call) !== FALSE)
{
$tb_groups = $last_call;
}
$tb_groups[] = array('TMOAddPage');
// Is this the toolbar editor?
if (ee()->input->get('M') == 'show_module_cp')
{
// Give our toolbar button an icon
$icon_url = URL_THIRD_THEMES.'bbm_ckbuttons/tmo-addpage/icons/page_add.png';
ee()->cp->add_to_head('<style type="text/css">.cke_button__tmo-addpage_icon { background-image: url('.$icon_url.'); }</style>');
}
return $tb_groups;
}
private function _include_resources()
{
// Is this the first time we've been called?
if (!self::$_included_resources)
{
// Tell CKEditor where to find our plugin
$plugin_url = URL_THIRD_THEMES.'bbm_ckbuttons/tmo-addpage/';
ee()->cp->add_to_foot('<script type="text/javascript">CKEDITOR.plugins.addExternal("tmo-addpage", "'.$plugin_url.'");</script>');
// Don't do that again
self::$_included_resources = TRUE;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment