images
12 years ago
class-wpfront-base-menu.php
12 years ago
class-wpfront-base.php
12 years ago
class-wpfront-options-base.php
12 years ago
class-wpfront-static.php
12 years ago
class-wpfront-base.php
213 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | WPFront Plugins Base |
| 5 | Copyright (C) 2013, WPFront.com |
| 6 | Website: wpfront.com |
| 7 | Contact: syam@wpfront.com |
| 8 | |
| 9 | WPFront Plugins are distributed under the GNU General Public License, Version 3, |
| 10 | June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin |
| 11 | St, Fifth Floor, Boston, MA 02110, USA |
| 12 | |
| 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | */ |
| 24 | |
| 25 | require_once("class-wpfront-static.php"); |
| 26 | require_once("class-wpfront-base-menu.php"); |
| 27 | |
| 28 | if (!class_exists('WPFront_Base')) { |
| 29 | |
| 30 | /** |
| 31 | * Plugin framework base class |
| 32 | * |
| 33 | * @author Syam Mohan <syam@wpfront.com> |
| 34 | * @copyright 2013 WPFront.com |
| 35 | */ |
| 36 | class WPFront_Base { |
| 37 | |
| 38 | private $plugin_slug; |
| 39 | private $options_page_slug; |
| 40 | protected $pluginURLRoot; |
| 41 | protected $pluginDIRRoot; |
| 42 | private static $menu_data = array(); |
| 43 | |
| 44 | function __construct($file, $pluginSlug, $wpfrontBaseMenu = NULL) { |
| 45 | $this->plugin_slug = $pluginSlug; |
| 46 | $this->options_page_slug = $this->plugin_slug; |
| 47 | if ($wpfrontBaseMenu == NULL) |
| 48 | $wpfrontBaseMenu = new WPFront_Base_Menu($this); |
| 49 | |
| 50 | $this->pluginURLRoot = plugins_url() . '/' . $this->plugin_slug . '/'; |
| 51 | $this->pluginDIRRoot = dirname($file) . '/../'; |
| 52 | |
| 53 | add_action('init', array(&$this, 'init')); |
| 54 | add_action('plugins_loaded', array(&$this, 'plugins_loaded_base')); |
| 55 | |
| 56 | //register actions |
| 57 | if (is_admin()) { |
| 58 | add_action('admin_init', array(&$this, 'admin_init')); |
| 59 | add_action('admin_menu', array(&$this, 'admin_menu')); |
| 60 | add_filter('plugin_action_links', array(&$this, 'action_links'), 10, 2); |
| 61 | } else { |
| 62 | add_action('wp_enqueue_scripts', array(&$this, 'enqueue_styles')); |
| 63 | add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | protected function add_menu($title, $link) { |
| 68 | self::$menu_data[] = array( |
| 69 | 'title' => $title, |
| 70 | 'link' => $link, |
| 71 | 'this' => $this, |
| 72 | 'slug' => $this->options_page_slug |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | public function init() { |
| 77 | |
| 78 | } |
| 79 | |
| 80 | public function plugins_loaded_base() { |
| 81 | //for localization |
| 82 | load_plugin_textdomain($this->plugin_slug, FALSE, $this->plugin_slug . '/languages/'); |
| 83 | |
| 84 | $this->plugins_loaded(); |
| 85 | } |
| 86 | |
| 87 | public function plugins_loaded() { |
| 88 | |
| 89 | } |
| 90 | |
| 91 | public function admin_init() { |
| 92 | |
| 93 | } |
| 94 | |
| 95 | public function admin_menu() { |
| 96 | WPFront_Base_Menu::admin_menu(self::$menu_data); |
| 97 | } |
| 98 | |
| 99 | public static function submenu_compare($a, $b) { |
| 100 | return strcmp($a[0], $b[0]); |
| 101 | } |
| 102 | |
| 103 | public function action_links($links, $file) { |
| 104 | if ($file == $this->plugin_slug . '/' . $this->plugin_slug . '.php') { |
| 105 | $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=' . $this->options_page_slug . '">' . $this->__('Settings') . '</a>'; |
| 106 | array_unshift($links, $settings_link); |
| 107 | } |
| 108 | return $links; |
| 109 | } |
| 110 | |
| 111 | public function enqueue_styles() { |
| 112 | |
| 113 | } |
| 114 | |
| 115 | public function enqueue_scripts() { |
| 116 | |
| 117 | } |
| 118 | |
| 119 | public function enqueue_options_styles() { |
| 120 | |
| 121 | } |
| 122 | |
| 123 | public function enqueue_options_scripts() { |
| 124 | |
| 125 | } |
| 126 | |
| 127 | //creates options page |
| 128 | public function options_page() { |
| 129 | if (!current_user_can('manage_options')) { |
| 130 | wp_die($this->__('You do not have sufficient permissions to access this page.')); |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | include($this->pluginDIRRoot . 'templates/options-template.php'); |
| 135 | } |
| 136 | |
| 137 | protected function options_page_header($title, $optionsGroupName) { |
| 138 | echo '<div class="wrap">'; |
| 139 | @screen_icon($this->options_page_slug); |
| 140 | echo '<h2>' . $title . '</h2>'; |
| 141 | echo '<div id="' . $this->options_page_slug . '-options" class="inside">'; |
| 142 | echo '<form method="post" action="options.php">'; |
| 143 | @settings_fields($optionsGroupName); |
| 144 | @do_settings_sections($this->options_page_slug); |
| 145 | |
| 146 | if ((isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true') || (isset($_GET['updated']) && $_GET['updated'] == 'true')) { |
| 147 | echo ' |
| 148 | <div class="updated"> |
| 149 | <p> |
| 150 | <strong>' . $this->__('If you have a caching plugin, clear the cache for the new settings to take effect.') . '</strong> |
| 151 | </p> |
| 152 | </div> |
| 153 | '; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | protected function options_page_footer($settingsLink, $FAQLink, $extraLinks = NULL) { |
| 158 | @$this->submit_button(); |
| 159 | |
| 160 | if ($extraLinks != NULL) { |
| 161 | foreach ($extraLinks as $value) { |
| 162 | echo '<a href="' . $value['href'] . '" target="' . $value['target'] . '">' . $value['text'] . '</a>'; |
| 163 | echo ' | '; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | echo ' |
| 168 | <a href="http://wpfront.com/' . $settingsLink . '" target="_blank">' . $this->__('Settings Description') . '</a> |
| 169 | | |
| 170 | <a href="http://wpfront.com/' . $FAQLink . '" target="_blank">' . $this->__('Plugin FAQ') . '</a> |
| 171 | | |
| 172 | <a href="http://wpfront.com/contact/" target="_blank">' . $this->__('Feature Request') . '</a> |
| 173 | | |
| 174 | <a href="http://wpfront.com/contact/" target="_blank">' . $this->__('Report Bug') . '</a> |
| 175 | | |
| 176 | <a href="http://wordpress.org/support/view/plugin-reviews/' . $this->plugin_slug . '" target="_blank">' . $this->__('Write Review') . '</a> |
| 177 | | |
| 178 | <a href="mailto:syam@wpfront.com">' . $this->__('Contact Me (syam@wpfront.com)') . '</a> |
| 179 | | |
| 180 | <a href="http://wpfront.com/donate/" target="_blank">' . $this->__('Buy me a Beer or Coffee') . '</a> |
| 181 | '; |
| 182 | echo '</form>'; |
| 183 | echo '</div>'; |
| 184 | echo '</div>'; |
| 185 | } |
| 186 | |
| 187 | //returns localized string |
| 188 | public function __($key) { |
| 189 | return __($key, $this->plugin_slug); |
| 190 | } |
| 191 | |
| 192 | //for compatibility |
| 193 | public function submit_button() { |
| 194 | if (function_exists('submit_button')) { |
| 195 | submit_button(); |
| 196 | } else { |
| 197 | echo '<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="' . $this->__('Save Changes') . '" /></p>'; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | public function pluginURL() { |
| 202 | return $this->pluginURLRoot; |
| 203 | } |
| 204 | |
| 205 | public function pluginDIR() { |
| 206 | return $this->pluginDIRRoot; |
| 207 | } |
| 208 | |
| 209 | } |
| 210 | |
| 211 | } |
| 212 | |
| 213 |