configuration = $configuration; /* * Loading events */ load_plugin_textdomain('awshortcode', $configuration->getI18nPath(), $configuration->getI18nPathFromPlugins()); register_activation_hook($configuration->getFilename(), array($this, 'executeActivation')); add_filter('plugin_action_links_'.$configuration->getPluginFilepath(), array($this, 'executeFilterPluginActionLinks')); } /** * Register main functions for plugin's sake * * @static * @author oncletom * @version 1.0 * @since 1.3 * @return null * @param $plugin_home_path String Path to the plugin home (generally given as __FILE__) */ public static function createInstance(AWShortcodesConfiguration $configuration) { $class = __CLASS__; self::$instance = new $class($configuration); return self::$instance; } /** * Returns current configuration instance * * @author oncletom * @return AWShortcodesConfiguration */ public function getConfiguration() { return $this->configuration; } /** * Returns the current instance of the plugin * It does not check if it has been initialized, I guess you are confident enough * * @static * @author oncletom * @return AWShortcodesPlugin */ public static function getInstance() { return self::$instance; } /** * Plugin activation processing * * @author oncletom * @version 2.1 * @since 1.3 * @return $state Mixed null if nothing, else false */ public function executeActivation() { /* * Default options * * We don't do this anymore as plugins better handle default value even if not in the database * It may occurs a slight overload (as WP may query the db to find the option) * It is however in the interest of the owner to setup a first time the plugin */ /* * 1.x -> 2.0 */ $options = $this->getConfiguration()->getOptions(); if (!(string)$options->version && get_option('awshortcode_tracking_id')) { $options->profiles->setValue(array('default' => array( 'id' => get_option('awshortcode_tracking_id'), 'name' => 'Default', 'r' => get_option('awshortcode_region') ))); $options->default_profile->setValue('default'); delete_option('awshortcode_region'); delete_option('awshortcode_tracking_id'); $options->version->setValue('2.0'); } /* * Purge TinyMCE config */ $js_cache_dir = WP_CONTENT_DIR.'/uploads/js_cache'; $dp = opendir($js_cache_dir); while ($element = readdir($dp)) { if (preg_match('/^tinymce/', $element) && is_file($js_cache_dir.'/'.$element)) { unlink($js_cache_dir.'/'.$element); } } closedir($dp); } /** * Filter action plugin action links to add context links * * @author oncletom * @version 1.0 * @since 1.4 * @return array * @param array $action_links */ public function executeFilterPluginActionLinks($action_links) { return array_merge(array(''.__('Configure').''), $action_links); } /** * Register shortcode class & syntax * * @author oncletom * @version 2.0 * @since 1.3 * @return $registered_shortcodes Integer Number of registered shortcodes */ public function registerShortcodes() { $registered_shortcodes = 0; $shortcodes = $this->configuration->getShortcodes(); /* * Feed + feed filtering: we use the dummy widget */ if (is_feed() && !get_option('awshortcode_feed')) { foreach ($shortcodes as $shortcode_id => $shortcode_config) { add_shortcode($shortcode_id, array(new AWShortcodesWidgetDummy, 'render')); } } /* * Other uses, we render as HTML */ else { foreach ($shortcodes as $shortcode_id => $shortcode_config) { add_shortcode($shortcode_id, array(new $shortcode_config['class'], 'render')); $registered_shortcodes++; } } return $registered_shortcodes; } }