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-menu.php
256 lines
| 1 | <?php |
| 2 | /* |
| 3 | WPFront Plugins Base Menu |
| 4 | Copyright (C) 2013, WPFront.com |
| 5 | Website: wpfront.com |
| 6 | Contact: syam@wpfront.com |
| 7 | |
| 8 | WPFront Plugins are distributed under the GNU General Public License, Version 3, |
| 9 | June 2007. Copyright (C) 2007 Free Software Foundation, Inc., 51 Franklin |
| 10 | St, Fifth Floor, Boston, MA 02110, USA |
| 11 | |
| 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 14 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 15 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 16 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 17 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 18 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 19 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 20 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 21 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 22 | */ |
| 23 | |
| 24 | if (!class_exists('WPFront_Base_Menu')) { |
| 25 | |
| 26 | class WPFront_Base_Menu { |
| 27 | |
| 28 | const MENU_SLUG = 'wpfront-plugins'; |
| 29 | |
| 30 | private static $wpfrontBase = NULL; |
| 31 | private static $wpfrontBaseMenu = NULL; |
| 32 | |
| 33 | function __construct($wpfrontBase) { |
| 34 | if (self::$wpfrontBase == NULL) { |
| 35 | self::$wpfrontBase = $wpfrontBase; |
| 36 | self::$wpfrontBaseMenu = $this; |
| 37 | } else { |
| 38 | if (version_compare($this->version(), self::$wpfrontBaseMenu->version()) > 0) { |
| 39 | self::$wpfrontBase = $wpfrontBase; |
| 40 | self::$wpfrontBaseMenu = $this; |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | protected function version() { |
| 46 | return '1.0'; |
| 47 | } |
| 48 | |
| 49 | protected function print_column_headers($tag = 'thead') { |
| 50 | echo '<' . $tag . '><tr>' |
| 51 | . '<th class="check-column"></th>' |
| 52 | . '<th scope="col" id="name" class="manage-column column-name">' . $this->__('Name') . '</th>' |
| 53 | . '<th scope="col" id="version" class="manage-column column-version">' . $this->__('Version') . '</th>' |
| 54 | . '<th scope="col" id="rating" class="manage-column column-rating">' . $this->__('Rating') . '</th>' |
| 55 | . '<th scope="col" id="description" class="manage-column column-description">' . $this->__('Description') . '</th>' |
| 56 | . '</tr></' . $tag . '>'; |
| 57 | } |
| 58 | |
| 59 | protected function print_column_footers() { |
| 60 | $this->print_column_headers('tfoot'); |
| 61 | } |
| 62 | |
| 63 | protected function wp_star_rating($args) { |
| 64 | if (function_exists('wp_star_rating')) { |
| 65 | echo wp_star_rating($args); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | echo '<div class="star-holder" title="' . sprintf($this->__('based on %s rating(s)'), number_format_i18n($args['number'])) . '">' |
| 70 | . '<div class="star star-rating" style="width:' . esc_attr(str_replace(',', '.', $args['rating'])) . 'px"></div>' |
| 71 | . '</div>'; |
| 72 | } |
| 73 | |
| 74 | protected function create_plugin_list() { |
| 75 | if (isset($_GET['action'])) { |
| 76 | if ($_GET['action'] == 'activate') { |
| 77 | if (isset($_GET['plugin'])) { |
| 78 | activate_plugin($_GET['plugin'] . '/' . $_GET['plugin'] . '.php'); |
| 79 | // echo '<script type="text/javascript">window.location="' . WPFront_Static::self_admin_url('admin.php?page=' . self::MENU_SLUG) . '";</script>'; |
| 80 | // wp_die(); |
| 81 | // return; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | $plugins_allowedtags = array( |
| 87 | 'a' => array('href' => array(), 'title' => array(), 'target' => array()), |
| 88 | 'abbr' => array('title' => array()), 'acronym' => array('title' => array()), |
| 89 | 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(), |
| 90 | 'ul' => array(), 'ol' => array(), 'li' => array(), 'p' => array(), 'br' => array() |
| 91 | ); |
| 92 | |
| 93 | if (!function_exists('plugins_api')) |
| 94 | require_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); |
| 95 | add_thickbox(); |
| 96 | |
| 97 | $args = array(); |
| 98 | $args['page'] = 1; |
| 99 | $args['per_page'] = 30; |
| 100 | $args['author'] = 'syammohanm'; |
| 101 | |
| 102 | $api = plugins_api('query_plugins', $args); |
| 103 | |
| 104 | if (is_wp_error($api)) { |
| 105 | wp_die($this->__('Unable to communicate with WordPress.org')); |
| 106 | return; |
| 107 | } |
| 108 | ?> |
| 109 | <style type="text/css"> |
| 110 | div.wpfront-container table.plugins { |
| 111 | margin-top: 16px; |
| 112 | margin-bottom: 16px; |
| 113 | } |
| 114 | div.wpfront-container table.plugins th.check-column { |
| 115 | width: 0px; |
| 116 | } |
| 117 | div.wpfront-container div.footer { |
| 118 | text-align: center; |
| 119 | } |
| 120 | </style> |
| 121 | <?php |
| 122 | echo '<div class="wrap wpfront-container">'; |
| 123 | echo '<h2>' . $this->__('WPFront Plugins') . '</h2>'; |
| 124 | echo '<table class="wp-list-table widefat plugins plugin-install">'; |
| 125 | $this->print_column_headers(); |
| 126 | |
| 127 | foreach ((array) $api->plugins as $plugin) { |
| 128 | if (is_object($plugin)) |
| 129 | $plugin = (array) $plugin; |
| 130 | |
| 131 | $title = wp_kses($plugin['name'], $plugins_allowedtags); |
| 132 | $description = strip_tags($plugin['description']); |
| 133 | if (strlen($description) > 400) |
| 134 | $description = mb_substr($description, 0, 400) . '…'; |
| 135 | //remove any trailing entities |
| 136 | $description = preg_replace('/&[^;\s]{0,6}$/', '', $description); |
| 137 | //strip leading/trailing & multiple consecutive lines |
| 138 | $description = trim($description); |
| 139 | $description = preg_replace("|(\r?\n)+|", "\n", $description); |
| 140 | //\n => <br> |
| 141 | $description = nl2br($description); |
| 142 | $version = wp_kses($plugin['version'], $plugins_allowedtags); |
| 143 | |
| 144 | $name = strip_tags($title . ' ' . $version); |
| 145 | $author = $plugin['author']; |
| 146 | if (!empty($plugin['author'])) |
| 147 | $author = ' <cite>' . sprintf($this->__('By %s'), $author) . '.</cite>'; |
| 148 | |
| 149 | $author = wp_kses($author, $plugins_allowedtags); |
| 150 | |
| 151 | $action_links = array(); |
| 152 | $action_links[] = '<a href="' . WPFront_Static::self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $plugin['slug'] . |
| 153 | '&TB_iframe=true&width=600&height=550') . '" class="thickbox" title="' . |
| 154 | esc_attr(sprintf($this->__('More information about %s'), $name)) . '">' . $this->__('Details') . '</a>'; |
| 155 | |
| 156 | $class = 'inactive'; |
| 157 | if (current_user_can('install_plugins') || current_user_can('update_plugins')) { |
| 158 | $status = install_plugin_install_status($plugin); |
| 159 | |
| 160 | switch ($status['status']) { |
| 161 | case 'install': |
| 162 | if ($status['url']) |
| 163 | $action_links[] = '<a class="install-now" href="' . $status['url'] . '" title="' . esc_attr(sprintf($this->__('Install %s'), $name)) . '">' . $this->__('Install Now') . '</a>'; |
| 164 | $class = 'active'; |
| 165 | break; |
| 166 | case 'update_available': |
| 167 | if ($status['url']) |
| 168 | $action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr(sprintf($this->__('Update to version %s'), $status['version'])) . '">' . sprintf($this->__('Update Now'), $status['version']) . '</a>'; |
| 169 | $class = 'active update'; |
| 170 | break; |
| 171 | case 'latest_installed': |
| 172 | case 'newer_installed': |
| 173 | $action_links[] = '<span title="' . esc_attr__($this->__('This plugin is already installed and is up to date')) . ' ">' . $this->__('Installed') . '</span>'; |
| 174 | if (is_plugin_active($plugin['slug'] . '/' . $plugin['slug'] . '.php')) |
| 175 | $action_links[] = '<a href="' . WPFront_Static::self_admin_url('admin.php?page=' . $plugin['slug']) . '">' . $this->__('Settings') . '</a>'; |
| 176 | else |
| 177 | $action_links[] = '<a href="' . WPFront_Static::self_admin_url('admin.php?page=' . self::MENU_SLUG . '&action=activate&plugin=' . $plugin['slug']) . '">' . $this->__('Activate') . '</a>'; |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | $action_links = apply_filters('plugin_install_action_links', $action_links, $plugin); |
| 182 | ?> |
| 183 | <tr class="<?php echo $class; ?>"> |
| 184 | <th class="check-column"></th> |
| 185 | <td class="name column-name"><strong><?php echo $title; ?></strong> |
| 186 | <div class="action-links"><?php if (!empty($action_links)) echo implode(' | ', $action_links); ?></div> |
| 187 | </td> |
| 188 | <td class="vers column-version"><?php echo $version; ?></td> |
| 189 | <td class="vers column-rating"> |
| 190 | <?php $this->wp_star_rating(array('rating' => $plugin['rating'], 'type' => 'percent', 'number' => $plugin['num_ratings'])); ?> |
| 191 | </td> |
| 192 | <td class="desc column-description"><?php echo $description, $author; ?></td> |
| 193 | </tr> |
| 194 | <?php |
| 195 | } |
| 196 | |
| 197 | $this->print_column_footers(); |
| 198 | echo '</table>'; |
| 199 | echo '<div class="footer"><a href="http://wpfront.com/contact" target="_blank">' . $this->__('Feedback') . '</a> | <a href="http://wpfront.com" target="_blank">wpfront.com</a></div>'; |
| 200 | echo '</div>'; |
| 201 | } |
| 202 | |
| 203 | public static function plugin_list() { |
| 204 | self::$wpfrontBaseMenu->create_plugin_list(); |
| 205 | } |
| 206 | |
| 207 | protected function __($key) { |
| 208 | return self::$wpfrontBase->__($key); |
| 209 | } |
| 210 | |
| 211 | protected function create_admin_menu($menu_data) { |
| 212 | $menu_slug = self::MENU_SLUG; |
| 213 | |
| 214 | global $admin_page_hooks, $submenu; |
| 215 | if (!isset($admin_page_hooks[$menu_slug])) { |
| 216 | add_menu_page($this->__('WPFront'), $this->__('WPFront'), 'manage_options', $menu_slug, null, self::$wpfrontBase->pluginURL() . 'classes/base/images/wpfront_menu.png'); |
| 217 | add_submenu_page($menu_slug, $this->__('WPFront Plugins'), $this->__('All Plugins'), 'manage_options', $menu_slug, array('WPFront_Base_Menu', 'plugin_list')); |
| 218 | } |
| 219 | |
| 220 | if (empty($submenu[$menu_slug])) { |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | //$extra_menu = array_pop($submenu[$menu_slug]); |
| 225 | |
| 226 | foreach ($menu_data as $value) { |
| 227 | $flag = FALSE; |
| 228 | |
| 229 | foreach ($submenu[$menu_slug] as $s) { |
| 230 | if ($s[2] == $value['slug']) { |
| 231 | $flag = TRUE; |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | if ($flag == TRUE) |
| 237 | continue; |
| 238 | |
| 239 | $page_hook_suffix = add_submenu_page($menu_slug, $value['title'], $value['link'], 'manage_options', $value['slug'], array($value['this'], 'options_page')); |
| 240 | |
| 241 | add_action('admin_print_scripts-' . $page_hook_suffix, array($value['this'], 'enqueue_options_scripts')); |
| 242 | add_action('admin_print_styles-' . $page_hook_suffix, array($value['this'], 'enqueue_options_styles')); |
| 243 | } |
| 244 | |
| 245 | //usort($submenu[$menu_slug], array('WPFront_Base', 'submenu_compare')); |
| 246 | //$submenu[$menu_slug][] = $extra_menu; |
| 247 | } |
| 248 | |
| 249 | public static function admin_menu($menu_data) { |
| 250 | self::$wpfrontBaseMenu->create_admin_menu($menu_data); |
| 251 | } |
| 252 | |
| 253 | } |
| 254 | |
| 255 | } |
| 256 |