WordPress.org

Plugin Directory

Changeset 594711


Ignore:
Timestamp:
09/05/12 03:09:55 (20 months ago)
Author:
toppa
Message:

version 1.1

Location:
extensible-html-editor-buttons/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • extensible-html-editor-buttons/trunk/Buttonable.php

    r491918 r594711  
    22 
    33class Buttonable { 
    4     private $version = '1.0'; 
    5     private $autoLoader; 
    6  
    7     public function __construct(ToppaAutoloader $autoLoader) { 
    8         $this->autoLoader = $autoLoader; 
     4    private $version = '1.1'; 
     5    private $customDialogPath; 
     6    private $customDialogBackupPath; 
     7 
     8    public function __construct() { 
     9        $this->customDialogPath = dirname(__FILE__) . '/Display/custom-dialogs.html'; 
     10        $this->customDialogBackupPath = dirname(__FILE__) . '/../custom-dialogs.html'; 
    911    } 
    1012 
     
    1517    public function install() { 
    1618        try { 
    17             $container = new ButtonableContainer($this->autoLoader); 
     19            $container = new ButtonableContainer(); 
    1820            $installer = $container->getInstaller(); 
    1921            $status = $installer->run(); 
     
    2830 
    2931    public function run() { 
     32        add_action('admin_init', array($this, 'runtimeUpgrade')); 
     33        add_filter('upgrader_pre_install', 'backupCustomDialogs'); 
     34        add_filter('upgrader_post_install', 'restoreCustomDialogs'); 
    3035        add_action('admin_menu', array($this, 'initSettingsMenu')); 
    3136        add_action('admin_footer', array($this, 'initButtons')); 
    3237        add_action('admin_head', array($this, 'hideInactiveElements')); 
     38    } 
     39 
     40    public function runtimeUpgrade() { 
     41        try { 
     42            $container = new ButtonableContainer(); 
     43            $installer = $container->getInstaller(); 
     44            $status = $installer->runtimeUpgrade(); 
     45            return $status; 
     46        } 
     47 
     48        catch (Exception $e) { 
     49            return $this->formatExceptionMessage($e); 
     50        } 
     51    } 
     52 
     53    // inspired by http://hungred.com/how-to/prevent-wordpress-plugin-update-deleting-important-folder-plugin/ 
     54    public function backupCustomDialogs() { 
     55        if (file_exists($this->customDialogPath)) { 
     56            return copy($this->customDialogPath, $this->customDialogBackupPath); 
     57 
     58        } 
     59 
     60        return true; 
     61    } 
     62 
     63    public function restoreCustomDialogs() { 
     64        if (file_exists($this->customDialogBackupPath)) { 
     65            $status = copy($this->customDialogBackupPath, $this->customDialogPath); 
     66 
     67            if ($status) { 
     68                return unlink($this->customDialogBackupPath); 
     69            } 
     70        } 
     71 
     72        return true; 
    3373    } 
    3474 
     
    4585    public function displaySettingsMenu() { 
    4686        try { 
    47             $container = new ButtonableContainer($this->autoLoader); 
     87            $container = new ButtonableContainer(); 
    4888            $settingsMenuHandler = $container->getSettingsMenuHandler(); 
    4989            echo $settingsMenuHandler->run(); 
     
    5797    public function initButtons() { 
    5898        try { 
    59             $container = new ButtonableContainer($this->autoLoader); 
     99            $container = new ButtonableContainer(); 
    60100            $editorHandler = $container->getEditorHandler(); 
    61101            echo $editorHandler->addButtons(); 
     
    69109    public function hideInactiveElements() { 
    70110        try { 
    71             $container = new ButtonableContainer($this->autoLoader); 
     111            $container = new ButtonableContainer(); 
    72112            $editorHandler = $container->getEditorHandler(); 
    73113            echo $editorHandler->hideInactiveElements(); 
     
    82122    public function uninstall() { 
    83123        try { 
    84             $container = new ButtonableContainer($this->autoLoader); 
    85             $settings = $container->getSettings(); 
    86             $settings->delete(); 
    87         } 
    88  
    89         catch (Exception $e) { 
    90             echo $this->formatExceptionMessage($e); 
    91         } 
    92  
    93         return true; 
     124            $container = new ButtonableContainer(); 
     125            $functionsFacade = $container->getFunctionsFacade(); 
     126            return $this->functionsFacade->callFunctionForNetworkSites(array($this, 'uninstallForNetworkSites')); 
     127        } 
     128 
     129        catch (Exception $e) { 
     130            echo $this->formatExceptionMessage($e); 
     131        } 
     132 
     133        return false; 
     134    } 
     135 
     136    public function uninstallForNetworkSites() { 
     137        $container = new ButtonableContainer(); 
     138        $settings = $container->getSettings(); 
     139        return $settings->delete(); 
    94140    } 
    95141 
     
    120166        try { 
    121167            $buttonableAutoLoader = new ToppaAutoLoaderWp('/extensible-html-editor-buttons'); 
    122             $container = new ButtonableContainer($buttonableAutoLoader); 
     168            $container = new ButtonableContainer(); 
    123169            $externalButtonHandler = $container->getExternalButtonHandler(); 
    124170            $externalButtonHandler->registerButton($handle, $tag, $title, $id, $selfClose, $shortcode, $path); 
     
    142188        try { 
    143189            $buttonableAutoLoader = new ToppaAutoLoaderWp('/extensible-html-editor-buttons'); 
    144             $container = new ButtonableContainer($buttonableAutoLoader); 
     190            $container = new ButtonableContainer(); 
    145191            $externalButtonHandler = $container->getExternalButtonHandler(); 
    146192            $externalButtonHandler->deregisterButton($handle); 
  • extensible-html-editor-buttons/trunk/ButtonableContainer.php

    r490039 r594711  
    22 
    33class ButtonableContainer { 
    4     private $autoLoader; 
    54    private $functionsFacade; 
    65    private $settings; 
     
    1211    private $externalButtonHandler; 
    1312 
    14     public function __construct($autoLoader) { 
    15         $this->autoLoader = $autoLoader; 
     13    public function __construct() { 
    1614    } 
    1715 
     
    3634        if (!$this->installer) { 
    3735            $this->getSettings(); 
     36            $this->getFunctionsFacade(); 
    3837            $this->installer = new ButtonableInstall(); 
    3938            $this->installer->setSettings($this->settings); 
     39            $this->installer->setFunctionsFacade($this->functionsFacade); 
    4040        } 
    4141 
  • extensible-html-editor-buttons/trunk/ButtonableEditorHandler.php

    r491918 r594711  
    7676    public function enqueueScriptsAndStylesheets() { 
    7777        $displayUrl = $this->functionsFacade->getPluginsUrl('/Display/', __FILE__); 
    78         $this->functionsFacade->enqueueScript('buttonableJs', $displayUrl . 'buttonController.js', array('quicktags'), false); 
    79         $this->functionsFacade->enqueueScript('jquery', false); 
    80         $this->functionsFacade->enqueueScript('jquery-form', false); 
    81         $this->functionsFacade->enqueueScript('jquery-ui-dialog', false); 
    82         $this->functionsFacade->enqueueScript('jquery-ui-draggable', false); 
     78        $this->functionsFacade->enqueueScript( 
     79            'buttonableJs', 
     80            $displayUrl . 'buttonController.js', 
     81            array( 
     82                'jquery', 
     83                'jquery-form', 
     84                'jquery-ui-dialog', 
     85                'jquery-ui-draggable', 
     86                'quicktags'), 
     87            false 
     88        ); 
    8389        $this->functionsFacade->enqueueStylesheet('buttonableStyle', $displayUrl . 'buttonable.css'); 
    8490        return true; 
     
    102108            foreach ($this->settings->$group as $handle=>$button) { 
    103109                if ($button['active'] == 'y') { 
    104                     $handles[] = $handle; 
     110                    $handles[] = strtolower($handle); 
    105111                    $tags[] = $button['tag']; 
    106112                    $titles[] = $button['title']; 
  • extensible-html-editor-buttons/trunk/ButtonableInstall.php

    r490039 r594711  
    5050    } 
    5151 
     52    public function setFunctionsFacade(ToppaFunctionsFacade $functionsFacade) { 
     53        $this->functionsFacade = $functionsFacade; 
     54        return $this->functionsFacade; 
     55    } 
     56 
    5257    public function run() { 
     58        return $this->functionsFacade->callFunctionForNetworkSites(array($this, 'runForNetworkSites')); 
     59    } 
     60 
     61    public function runForNetworkSites() { 
    5362        return $this->settings->set($this->settingsDefaults, true); 
    5463    } 
     64 
     65    public function runtimeUpgrade() { 
     66        $status = buttonableActivationChecks(); 
     67 
     68        if (is_string($status)) { 
     69            buttonableCancelActivation($status); 
     70            return null; 
     71        } 
     72 
     73        return $this->run(); 
     74    } 
     75 
    5576} 
  • extensible-html-editor-buttons/trunk/ButtonableSettingsMenuDisplayer.php

    r490039 r594711  
    7979 
    8080                foreach ($values as $k=>$v) { 
     81                    $buttonRefData[$k]['options'] = isset($buttonRefData[$k]['options']) 
     82                        ? $buttonRefData[$k]['options'] 
     83                        : null; 
     84 
    8185                    $refData = $this->getRefDataForButtonProperty( 
    8286                        $buttonRefData[$k]['type'], 
     
    165169 
    166170        foreach ($buttonRefData as $k=>$v) { 
     171            $v['options'] = isset($v['options']) ? $v['options'] : null; 
    167172            $refData = $this->getRefDataForButtonProperty($v['type'], $v['options']); 
    168173            $inputValue = ($addButtonValidation) ? $addButtonValidation["settings[$k]"] : $v['default']; 
  • extensible-html-editor-buttons/trunk/ButtonableSettingsMenuHandler.php

    r490039 r594711  
    3434        $this->setCleanRequest(); 
    3535 
    36         switch ($this->cleanRequest['buttonableAction']) { 
    37             case 'addButton': 
    38                 $validateStatus = $this->validateNewCustomButton(); 
    39                 $finalActionStatus = $this->saveNewCustomButton($validateStatus); 
    40                 break; 
    41             case 'updateButtons': 
    42                 $validateStatusForBuiltInButtons = $this->validateUpdatedBuiltInButtons(); 
    43                 $saveStatusForBuiltInButtons = $this->saveUpdatedBuiltInButtons($validateStatusForBuiltInButtons); 
    44                 $validateStatusForCustomButtons = $this->validateUpdatedCustomButtons($saveStatusForBuiltInButtons); 
    45                 $saveStatusForCustomButtons = $this->saveUpdatedCustomButtons($validateStatusForCustomButtons); 
    46                 $finalActionStatus = $this->deleteCustomButtons($saveStatusForCustomButtons); 
    47                 break; 
    48             case null: 
    49                 break; 
    50             default: 
    51                 throw New Exception(__('Requested action not recognized', 'buttonable')); 
    52         } 
    53  
    54         if ($finalActionStatus === false) { 
     36        if (isset($this->cleanRequest['buttonableAction'])) { 
     37            switch ($this->cleanRequest['buttonableAction']) { 
     38                case 'addButton': 
     39                    $validateStatus = $this->validateNewCustomButton(); 
     40                    $finalActionStatus = $this->saveNewCustomButton($validateStatus); 
     41                    break; 
     42                case 'updateButtons': 
     43                    $validateStatusForBuiltInButtons = $this->validateUpdatedBuiltInButtons(); 
     44                    $saveStatusForBuiltInButtons = $this->saveUpdatedBuiltInButtons($validateStatusForBuiltInButtons); 
     45                    $validateStatusForCustomButtons = $this->validateUpdatedCustomButtons($saveStatusForBuiltInButtons); 
     46                    $saveStatusForCustomButtons = $this->saveUpdatedCustomButtons($validateStatusForCustomButtons); 
     47                    $finalActionStatus = $this->deleteCustomButtons($saveStatusForCustomButtons); 
     48                    break; 
     49                case null: 
     50                    break; 
     51                default: 
     52                    throw New Exception(__('Requested action not recognized', 'buttonable')); 
     53            } 
     54        } 
     55 
     56        if (isset($finalActionStatus) && $finalActionStatus === false) { 
    5557            $message = __('Settings not saved. All fields for custom buttons are required', 'buttonable'); 
    5658        } 
    5759 
    58         elseif (is_array($finalActionStatus)) { 
     60        elseif (isset($finalActionStatus) && is_array($finalActionStatus)) { 
    5961            $message = __('Settings saved', 'buttonable'); 
    6062        } 
     
    8284 
    8385        foreach ($buttonRefData as $k=>$v) { 
    84             if (!$this->cleanRequest['buttonableNewButton']['settings'][$k]) { 
     86            if (!isset($this->cleanRequest['buttonableNewButton']['settings'][$k])) { 
    8587                return false; 
    8688            } 
     
    114116    private function validateRequestedButtons($formName, $settingsName) { 
    115117        foreach ($this->cleanRequest[$formName] as $handle=>$newSettings) { 
    116             if ($newSettings['active'] != 'y' && $newSettings['active'] != 'n') { 
     118            if (isset($newSettings['active']) && $newSettings['active'] != 'y' && $newSettings['active'] != 'n') { 
    117119                return false; 
    118120            } 
     
    139141 
    140142        foreach ($this->cleanRequest[$formName] as $handle=>$newSettings) { 
    141             $settings[$settingsName][$handle]['active'] = $newSettings['active']; 
     143            $settings[$settingsName][$handle]['active'] = $newSettings; 
    142144        } 
    143145 
     
    161163        $buttonRefData = $this->customButtonRefData->getRefData(); 
    162164 
    163         if ($this->cleanRequest['buttonableCustomButtons']) { 
     165        if (isset($this->cleanRequest['buttonableCustomButtons'])) { 
    164166            foreach ($this->cleanRequest['buttonableCustomButtons'] as $handle=>$properties) { 
    165167                if (!array_key_exists($handle, $this->settings->customButtons)) { 
     
    186188        $settings['customButtons'] = $this->settings->customButtons; 
    187189 
    188         if ($this->cleanRequest['buttonableCustomButtons']) { 
     190        if (isset($this->cleanRequest['buttonableCustomButtons'])) { 
    189191            foreach ($this->cleanRequest['buttonableCustomButtons'] as $handle=>$properties) { 
    190192                $settings['customButtons'][$handle] = $properties; 
  • extensible-html-editor-buttons/trunk/Tests/UnitButtonableEditorHandler.php

    r490039 r594711  
    9191        $functionsFacade->setReturnValue('checkFileExists', true); 
    9292        $handler->setFunctionsFacade($functionsFacade); 
     93        $settings = new MockButtonableSettings(); 
     94        $handler->setSettings($settings); 
    9395        $fakeDir = '/some/path/to/file.php'; 
    9496        $handler->setDisplayDir($fakeDir); 
  • extensible-html-editor-buttons/trunk/Tests/UnitButtonableInstall.php

    r490039 r594711  
    22 
    33Mock::generate('ButtonableSettings'); 
     4Mock::generate('ToppaFunctionsFacadeWp'); 
    45 
    56class UnitButtonableInstall extends UnitTestCase { 
     
    2021        $settings = new MockButtonableSettings(); 
    2122        $settings->setReturnValue('set', array()); 
     23        $functionsFacade = new MockToppaFunctionsFacadeWp(); 
     24        $functionsFacade->setReturnValue('callFunctionForNetworkSites', true); 
    2225        $installer = new ButtonableInstall(); 
    2326        $installer->setSettings($settings); 
    24         $this->assertTrue(is_array($installer->run())); 
     27        $installer->setFunctionsFacade($functionsFacade); 
     28        $this->assertTrue($installer->run()); 
    2529    } 
    2630} 
  • extensible-html-editor-buttons/trunk/Tests/UnitButtonableSettingsMenuHandler.php

    r490039 r594711  
    264264    } 
    265265 
    266     public function testValidateUpdatedBuiltInButtonsWithAnInvalidProperty() { 
     266    public function testValidateUpdatedBuiltInButtonsWithAnInvalidButtons() { 
    267267        $newButtonActiveStatus = array( 
    268268        'buttonableBuiltInButtons' => array( 
    269269            'div' => array( 
    270                 'foo' => 'bar'), // bad property 
     270                'active' => 'bar'), // bad value 
    271271            'span' => array( 
    272272                'active' => 'n'), 
     
    306306    public function testSaveUpdatedBuiltInButtonsWithValidButtons() { 
    307307        $newButtonActiveStatus = array( 
    308         'buttonableBuiltInButtons' => array( 
    309             'div' => array( 
    310                 'active' => 'n'), 
    311             'span' => array( 
    312                 'active' => 'n'), 
    313             'anchor' => array( 
    314                 'active' => 'n'), 
    315             'img' => array( 
    316                 'active' => 'n'), 
     308            'buttonableBuiltInButtons' => array( 
     309                'div' => 'n', 
     310                'span' => 'n', 
     311                'anchor' => 'n', 
     312                'img' => 'n', 
    317313            ) 
    318314        ); 
     
    390386    public function testSaveUpdatedExternalPluginButtonsWithValidButtons() { 
    391387        $newButtonActiveStatus = array( 
    392         'buttonableExternalPluginButtons' => array( 
    393             'div' => array( 
    394                 'active' => 'n'), 
    395             'span' => array( 
    396                 'active' => 'n'), 
    397             'anchor' => array( 
    398                 'active' => 'n'), 
    399             'img' => array( 
    400                 'active' => 'n'), 
     388            'buttonableExternalPluginButtons' => array( 
     389                'div' => 'n', 
     390                'span' => 'n', 
     391                'anchor' => 'n', 
     392                'img' => 'n', 
    401393            ) 
    402394        ); 
  • extensible-html-editor-buttons/trunk/readme.txt

    r491918 r594711  
    44Tags: post, admin, button, editor, jquery, quicktag 
    55Requires at least: 3.3 
    6 Tested up to: 3.3.1 
    7 Stable tag: 1.0.1 
     6Tested up to: 3.4.1 
     7Stable tag: 1.1 
    88 
    99A plugin for adding custom buttons to the WordPress HTML Editor, including custom modal dialogs. 
     
    4040== Changelog == 
    4141 
     42= 1.1 = 
     43 
     44* Backup and restore custom dialogs file when upgrading 
     45* Support runtime upgrades (e.g via FTP with de/activate cycle on plugin menu) 
     46* Support use in multisite networks 
     47* Code cleanup: remove unneeded passing around of autoLoader object 
     48* Code cleanup: remove all PHP warnings 
     49 
    4250= 1.0.1 = Bug fix: Hide dialogs for inactive buttons 
     51 
    4352= 1.0 = First version 
  • extensible-html-editor-buttons/trunk/start.php

    r491918 r594711  
    55Description: A plugin for adding custom buttons to the WordPress HTML Editor. 
    66Author: Michael Toppa 
    7 Version: 1.0.1 
     7Version: 1.1 
    88Author URI: http://www.toppa.com 
    99*/ 
    1010 
    1111$buttonableAutoLoaderPath = dirname(__FILE__) . '/../toppa-plugin-libraries-for-wordpress/ToppaAutoLoaderWp.php'; 
     12add_action('wpmu_new_blog', 'buttonableActivateForNewNetworkSite'); 
    1213register_activation_hook(__FILE__, 'buttonableActivate'); 
    13 register_deactivation_hook(__FILE__, 'buttonableDeactivate'); 
    1414load_plugin_textdomain('buttonable', false, basename(dirname(__FILE__)) . '/Languages/'); 
    1515 
     
    1818    $buttonableToppaAutoLoader = new ToppaAutoLoaderWp('/toppa-plugin-libraries-for-wordpress'); 
    1919    $buttonableAutoLoader = new ToppaAutoLoaderWp('/extensible-html-editor-buttons'); 
    20     $buttonable = new Buttonable($buttonableAutoLoader); 
     20    $buttonable = new Buttonable(); 
    2121    $buttonable->run(); 
     22} 
     23 
     24function buttonableActivateForNewNetworkSite($blog_id) { 
     25    global $wpdb; 
     26 
     27    if (is_plugin_active_for_network(__FILE__)) { 
     28        $old_blog = $wpdb->blogid; 
     29        switch_to_blog($blog_id); 
     30        buttonableActivate(); 
     31        switch_to_blog($old_blog); 
     32    } 
    2233} 
    2334 
     
    2536    $autoLoaderPath = dirname(__FILE__) . '/../toppa-plugin-libraries-for-wordpress/ToppaAutoLoaderWp.php'; 
    2637 
    27     if (!file_exists($autoLoaderPath)) { 
    28         $message = __('To activate Extensible HTML Editor Buttons you need to first install', 'buttonable') 
    29             . ' <a href="http://wordpress.org/extend/plugins/toppa-plugin-libraries-for-wordpress/">Toppa Plugins Libraries for WordPress</a>'; 
    30         buttonableCancelActivation($message); 
     38    $status = buttonableActivationChecks(); 
     39 
     40    if (is_string($status)) { 
     41        buttonableCancelActivation($status); 
    3142    } 
    3243 
    33     elseif (!function_exists('spl_autoload_register')) { 
    34         buttonableCancelActivation(__('You must have at least PHP 5.1.2 to use Extensible HTML Editor Buttons', 'buttonable')); 
     44    require_once($autoLoaderPath); 
     45    $toppaAutoLoader = new ToppaAutoLoaderWp('/toppa-plugin-libraries-for-wordpress'); 
     46    $buttonableAutoLoader = new ToppaAutoLoaderWp('/extensible-html-editor-buttons'); 
     47    $buttonable = new Buttonable(); 
     48    $status = $buttonable->install(); 
     49 
     50    if (is_string($status)) { 
     51        buttonableCancelActivation($status); 
     52        return null; 
    3553    } 
    3654 
    37     elseif (version_compare(get_bloginfo('version'), '3.1', '<')) { 
    38         buttonableCancelActivation(__('You must have at least WordPress 3.1 to use Extensible HTML Editor Buttons', 'buttonable')); 
     55    return null; 
     56} 
     57 
     58function buttonableActivationChecks() { 
     59    $autoLoaderPath = dirname(__FILE__) . '/../toppa-plugin-libraries-for-wordpress/ToppaAutoLoaderWp.php'; 
     60    $toppaLibsVersion = get_option('toppaLibsVersion'); 
     61 
     62    if (!file_exists($autoLoaderPath) || !$toppaLibsVersion || version_compare($toppaLibsVersion, '1.3.6', '<')) { 
     63        return __('To activate Extensible HTML Editor Buttons you need to have the current version of', 'buttonable') 
     64            . ' <a href="plugin-install.php?tab=plugin-information&plugin=toppa-plugin-libraries-for-wordpress">Toppa Plugins Libraries for WordPress</a>. ' 
     65            . __('Click the link to view details, and then click the "Install Now" button to get the current version. Then you can activate Extensible HTML Editor Buttons.', 'buttonable'); 
    3966    } 
    4067 
    41     else { 
    42         require_once($autoLoaderPath); 
    43         $toppaAutoLoader = new ToppaAutoLoaderWp('/toppa-plugin-libraries-for-wordpress'); 
    44         $buttonableAutoLoader = new ToppaAutoLoaderWp('/extensible-html-editor-buttons'); 
    45         $buttonable = new Buttonable($buttonableAutoLoader); 
    46         $status = $buttonable->install(); 
     68    if (!function_exists('spl_autoload_register')) { 
     69        return __('You must have at least PHP 5.1.2 to use Extensible HTML Editor Buttons', 'buttonable'); 
     70    } 
    4771 
    48         if (is_string($status)) { 
    49             buttonableCancelActivation($status); 
    50         } 
     72    if (version_compare(get_bloginfo('version'), '3.1', '<')) { 
     73        return __('You must have at least WordPress 3.1 to use Extensible HTML Editor Buttons', 'buttonable'); 
    5174    } 
     75 
     76    return true; 
    5277} 
    53  
    5478function buttonableCancelActivation($message) { 
    55     deactivate_plugins(basename(__FILE__)); 
     79    deactivate_plugins('extensible-html-editor-buttons/start.php'); 
    5680    wp_die($message); 
    5781} 
    5882 
    59 function buttonableDeactivate() { 
    60 } 
Note: See TracChangeset for help on using the changeset viewer.