PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website xem phim online PHP/thudang/public_html/mnet/wp-content/plugins/wordpress-seo/admin/yst_plugin_tools.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 406 lines | 301 code | 58 blank | 47 comment | 90 complexity | 516e25cd150cd65e84a54de397e539e2 MD5 | raw file
  1. <?php
  2. /**
  3. * Backend Class for use in all Yoast plugins
  4. * Version 0.2.1
  5. */
  6. if ( !class_exists('Yoast_WPSEO_Plugin_Admin') ) {
  7. class Yoast_WPSEO_Plugin_Admin {
  8. var $hook = '';
  9. var $filename = '';
  10. var $longname = '';
  11. var $shortname = '';
  12. var $ozhicon = '';
  13. var $optionname = '';
  14. var $homepage = '';
  15. var $feed = 'http://yoast.com/feed/';
  16. var $accesslvl = 'manage_options';
  17. var $adminpages = array( 'wpseo_dashboard', 'wpseo_rss', 'wpseo_files', 'wpseo_permalinks', 'wpseo_internal-links', 'wpseo_import', 'wpseo_titles', 'wpseo_xml', 'wpseo_social');
  18. function __construct() {
  19. }
  20. function add_ozh_adminmenu_icon( $hook ) {
  21. if ($hook == $this->hook)
  22. return WPSEO_URL.$this->ozhicon;
  23. return $hook;
  24. }
  25. function config_page_styles() {
  26. global $pagenow;
  27. if ( $pagenow == 'admin.php' && isset($_GET['page']) && in_array($_GET['page'], $this->adminpages) ) {
  28. wp_enqueue_style('dashboard');
  29. wp_enqueue_style('thickbox');
  30. wp_enqueue_style('global');
  31. wp_enqueue_style('wp-admin');
  32. wp_enqueue_style('yoast-admin-css', WPSEO_URL . 'css/yst_plugin_tools.css', WPSEO_VERSION );
  33. }
  34. }
  35. function register_network_settings_page() {
  36. add_menu_page($this->longname, $this->shortname, 'delete_users', 'wpseo_dashboard', array(&$this,'network_config_page'), WPSEO_URL.'images/yoast-icon.png');
  37. }
  38. function register_settings_page() {
  39. add_menu_page($this->longname, $this->shortname, $this->accesslvl, 'wpseo_dashboard', array(&$this,'config_page'), WPSEO_URL.'images/yoast-icon.png');
  40. add_submenu_page('wpseo_dashboard',__( 'Titles &amp; Metas', 'wordpress-seo' ),__( 'Titles &amp; Metas', 'wordpress-seo' ),$this->accesslvl, 'wpseo_titles', array(&$this,'titles_page'));
  41. add_submenu_page('wpseo_dashboard',__( 'Social', 'wordpress-seo' ),__( 'Social', 'wordpress-seo' ),$this->accesslvl, 'wpseo_social', array(&$this,'social_page'));
  42. add_submenu_page('wpseo_dashboard',__( 'XML Sitemaps', 'wordpress-seo' ),__( 'XML Sitemaps', 'wordpress-seo' ),$this->accesslvl, 'wpseo_xml', array(&$this,'xml_sitemaps_page'));
  43. add_submenu_page('wpseo_dashboard',__( 'Permalinks', 'wordpress-seo' ),__( 'Permalinks', 'wordpress-seo' ),$this->accesslvl, 'wpseo_permalinks', array(&$this,'permalinks_page'));
  44. add_submenu_page('wpseo_dashboard',__( 'Internal Links', 'wordpress-seo' ),__( 'Internal Links', 'wordpress-seo' ),$this->accesslvl, 'wpseo_internal-links', array(&$this,'internallinks_page'));
  45. add_submenu_page('wpseo_dashboard',__( 'RSS', 'wordpress-seo' ),__( 'RSS', 'wordpress-seo' ),$this->accesslvl, 'wpseo_rss', array(&$this,'rss_page'));
  46. add_submenu_page('wpseo_dashboard',__( 'Import & Export', 'wordpress-seo' ),__( 'Import & Export', 'wordpress-seo' ),$this->accesslvl, 'wpseo_import', array(&$this,'import_page'));
  47. // Make sure on a multi site install only super admins can edit .htaccess and robots.txt
  48. if ( !function_exists('is_multisite') || !is_multisite() )
  49. add_submenu_page('wpseo_dashboard',__( 'Edit files', 'wordpress-seo' ),__( 'Edit files', 'wordpress-seo' ),$this->accesslvl, 'wpseo_files', array(&$this,'files_page'));
  50. else
  51. add_submenu_page('wpseo_dashboard',__( 'Edit files', 'wordpress-seo' ),__( 'Edit files', 'wordpress-seo' ),'delete_users', 'wpseo_files', array(&$this,'files_page'));
  52. global $submenu;
  53. if ( isset($submenu['wpseo_dashboard']) )
  54. $submenu['wpseo_dashboard'][0][0] = __( 'Dashboard', 'wordpress-seo' );
  55. }
  56. function plugin_options_url() {
  57. return admin_url( 'admin.php?page=wpseo_dashboard' );
  58. }
  59. /**
  60. * Add a link to the settings page to the plugins list
  61. */
  62. function add_action_link( $links, $file ) {
  63. static $this_plugin;
  64. if( empty($this_plugin) ) $this_plugin = $this->filename;
  65. if ( $file == $this_plugin ) {
  66. $settings_link = '<a href="' . $this->plugin_options_url() . '">' . __('Settings', 'wordpress-seo' ) . '</a>';
  67. array_unshift( $links, $settings_link );
  68. }
  69. return $links;
  70. }
  71. function config_page() {
  72. }
  73. function config_page_scripts() {
  74. global $pagenow;
  75. wp_enqueue_script( 'wpseo-admin-global-script', WPSEO_URL.'js/wp-seo-admin-global.js', array('jquery'), WPSEO_VERSION, true );
  76. if ( $pagenow == 'admin.php' && isset($_GET['page']) && in_array($_GET['page'], $this->adminpages) ) {
  77. wp_enqueue_script( 'wpseo-admin-script', WPSEO_URL.'js/wp-seo-admin.js', array('jquery'), WPSEO_VERSION, true );
  78. wp_enqueue_script( 'postbox' );
  79. wp_enqueue_script( 'dashboard' );
  80. wp_enqueue_script( 'thickbox' );
  81. }
  82. }
  83. /**
  84. * Create a Checkbox input field
  85. */
  86. function checkbox($id, $label, $label_left = false, $option = '') {
  87. if ( $option == '' ) {
  88. $options = get_wpseo_options();
  89. $option = !empty($option) ? $option : $this->currentoption;
  90. } else {
  91. if ( function_exists('is_network_admin') && is_network_admin() ) {
  92. $options = get_site_option($option);
  93. } else {
  94. $options = get_option($option);
  95. }
  96. }
  97. if (!isset($options[$id]))
  98. $options[$id] = false;
  99. if ( $label_left !== false ) {
  100. if ( !empty( $label_left ) )
  101. $label_left .= ':';
  102. $output_label = '<label class="checkbox" for="'.$id.'">'.$label_left.'</label>';
  103. $class = 'checkbox';
  104. } else {
  105. $output_label = '<label for="'.$id.'">'.$label.'</label>';
  106. $class = 'checkbox double';
  107. }
  108. $output_input = '<input class="'.$class.'" type="checkbox" id="'.$id.'" name="'.$option.'['.$id.']"'. checked($options[$id],'on',false).'/>';
  109. if( $label_left !== false ) {
  110. $output = $output_label . $output_input . '<label class="checkbox" for="'.$id.'">'.$label.'</label>';
  111. } else {
  112. $output = $output_input . $output_label;
  113. }
  114. return $output . '<br class="clear" />';
  115. }
  116. /**
  117. * Create a Text input field
  118. */
  119. function textinput($id, $label, $option = '') {
  120. if ( $option == '') {
  121. $options = get_wpseo_options();
  122. $option = !empty($option) ? $option : $this->currentoption;
  123. } else {
  124. if ( function_exists('is_network_admin') && is_network_admin() ) {
  125. $options = get_site_option($option);
  126. } else {
  127. $options = get_option($option);
  128. }
  129. }
  130. $val = '';
  131. if (isset($options[$id]))
  132. $val = htmlspecialchars($options[$id]);
  133. return '<label class="textinput" for="'.$id.'">'.$label.':</label><input class="textinput" type="text" id="'.$id.'" name="'.$option.'['.$id.']" value="'.$val.'"/>' . '<br class="clear" />';
  134. }
  135. /**
  136. * Create a small textarea
  137. */
  138. function textarea($id, $label, $option = '', $class = '') {
  139. if ( $option == '') {
  140. $options = get_wpseo_options();
  141. $option = !empty($option) ? $option : $this->currentoption;
  142. } else {
  143. if ( function_exists('is_network_admin') && is_network_admin() ) {
  144. $options = get_site_option($option);
  145. } else {
  146. $options = get_option($option);
  147. }
  148. }
  149. $val = '';
  150. if (isset($options[$id]))
  151. $val = esc_html($options[$id]);
  152. return '<label class="textinput" for="'.$id.'">'.$label.':</label><textarea class="textinput '.$class.'" id="'.$id.'" name="'.$option.'['.$id.']">' . $val . '</textarea>' . '<br class="clear" />';
  153. }
  154. /**
  155. * Create a Hidden input field
  156. */
  157. function hiddeninput($id, $option = '') {
  158. if ( $option == '') {
  159. $options = get_wpseo_options();
  160. $option = !empty($option) ? $option : $this->currentoption;
  161. } else {
  162. if ( function_exists('is_network_admin') && is_network_admin() ) {
  163. $options = get_site_option($option);
  164. } else {
  165. $options = get_option($option);
  166. }
  167. }
  168. $val = '';
  169. if (isset($options[$id]))
  170. $val = htmlspecialchars($options[$id]);
  171. return '<input class="hidden" type="hidden" id="'.$id.'" name="'.$option.'['.$id.']" value="'.$val.'"/>';
  172. }
  173. /**
  174. * Create a Select Box
  175. */
  176. function select($id, $label, $values, $option = '') {
  177. if ( $option == '') {
  178. $options = get_wpseo_options();
  179. $option = !empty($option) ? $option : $this->currentoption;
  180. } else {
  181. if ( function_exists('is_network_admin') && is_network_admin() ) {
  182. $options = get_site_option($option);
  183. } else {
  184. $options = get_option($option);
  185. }
  186. }
  187. $output = '<label class="select" for="'.$id.'">'.$label.':</label>';
  188. $output .= '<select class="select" name="'.$option.'['.$id.']" id="'.$id.'">';
  189. foreach($values as $value => $label) {
  190. $sel = '';
  191. if (isset($options[$id]) && $options[$id] == $value)
  192. $sel = 'selected="selected" ';
  193. if (!empty($label))
  194. $output .= '<option '.$sel.'value="'.$value.'">'.$label.'</option>';
  195. }
  196. $output .= '</select>';
  197. return $output . '<br class="clear"/>';
  198. }
  199. /**
  200. * Create a File upload
  201. */
  202. function file_upload($id, $label, $option = '') {
  203. $option = !empty($option) ? $option : $this->currentoption;
  204. $options = get_wpseo_options();
  205. $val = '';
  206. if (isset($options[$id]) && strtolower(gettype($options[$id])) == 'array') {
  207. $val = $options[$id]['url'];
  208. }
  209. $output = '<label class="select" for="'.$id.'">'.$label.':</label>';
  210. $output .= '<input type="file" value="' . $val . '" class="textinput" name="'.$option.'['.$id.']" id="'.$id.'"/>';
  211. // Need to save separate array items in hidden inputs, because empty file inputs type will be deleted by settings API.
  212. if(!empty($options[$id])) {
  213. $output .= '<input class="hidden" type="hidden" id="' . $id . '_file" name="wpseo_local[' . $id . '][file]" value="' . $options[$id]['file'] . '"/>';
  214. $output .= '<input class="hidden" type="hidden" id="' . $id . '_url" name="wpseo_local[' . $id . '][url]" value="' . $options[$id]['url'] . '"/>';
  215. $output .= '<input class="hidden" type="hidden" id="' . $id . '_type" name="wpseo_local[' . $id . '][type]" value="' . $options[$id]['type'] . '"/>';
  216. }
  217. $output .= '<br class="clear"/>';
  218. return $output;
  219. }
  220. /**
  221. * Create a Radio input field
  222. */
  223. function radio($id, $values, $label, $option = '') {
  224. if ( $option == '') {
  225. $options = get_wpseo_options();
  226. $option = !empty($option) ? $option : $this->currentoption;
  227. } else {
  228. if ( function_exists('is_network_admin') && is_network_admin() ) {
  229. $options = get_site_option($option);
  230. } else {
  231. $options = get_option($option);
  232. }
  233. }
  234. if (!isset($options[$id]))
  235. $options[$id] = false;
  236. $output = '<br/><label class="select">'.$label.':</label>';
  237. foreach($values as $key => $value) {
  238. $output .= '<input type="radio" class="radio" id="'.$id.'-' . $key . '" name="'.$option.'['.$id.']" value="'. $key.'" ' . ($options[$id] == $key ? ' checked="checked"' : '') . ' /> <label class="radio" for="'.$id.'-' . $key . '">'.$value.'</label>';
  239. }
  240. $output .= '<br/>';
  241. return $output;
  242. }
  243. /**
  244. * Create a hidden input field
  245. */
  246. function hidden($id, $option = '') {
  247. if ( $option == '') {
  248. $options = get_wpseo_options();
  249. $option = !empty($option) ? $option : $this->currentoption;
  250. } else {
  251. if ( function_exists('is_network_admin') && is_network_admin() ) {
  252. $options = get_site_option($option);
  253. } else {
  254. $options = get_option($option);
  255. }
  256. }
  257. if (!isset($options[$id]))
  258. $options[$id] = '';
  259. return '<input type="hidden" id="hidden_'.$id.'" name="'.$option.'['.$id.']" value="'.$options[$id].'"/>';
  260. }
  261. /**
  262. * Create a potbox widget
  263. */
  264. function postbox($id, $title, $content) {
  265. ?>
  266. <div id="<?php echo $id; ?>" class="yoastbox">
  267. <h2><?php echo $title; ?></h2>
  268. <?php echo $content; ?>
  269. </div>
  270. <?php
  271. }
  272. /**
  273. * Create a form table from an array of rows
  274. */
  275. function form_table($rows) {
  276. $content = '<table class="form-table">';
  277. foreach ($rows as $row) {
  278. $content .= '<tr><th valign="top" scrope="row">';
  279. if (isset($row['id']) && $row['id'] != '')
  280. $content .= '<label for="'.$row['id'].'">'.$row['label'].':</label>';
  281. else
  282. $content .= $row['label'];
  283. if (isset($row['desc']) && $row['desc'] != '')
  284. $content .= '<br/><small>'.$row['desc'].'</small>';
  285. $content .= '</th><td valign="top">';
  286. $content .= $row['content'];
  287. $content .= '</td></tr>';
  288. }
  289. $content .= '</table>';
  290. return $content;
  291. }
  292. /**
  293. * Info box with link to the support forums.
  294. */
  295. function plugin_support() {
  296. $content = '<p>'.__('If you are having problems with this plugin, please talk about them in the', 'wordpress-seo' ).' <a href="http://wordpress.org/support/plugin/'.$this->hook.'">'.__("Support forums", 'wordpress-seo' ).'</a>.</p>';
  297. $this->postbox($this->hook.'support', __('Need support?', 'wordpress-seo' ), $content);
  298. }
  299. function text_limit( $text, $limit, $finish = '&hellip;') {
  300. if( strlen( $text ) > $limit ) {
  301. $text = substr( $text, 0, $limit );
  302. $text = substr( $text, 0, - ( strlen( strrchr( $text,' ') ) ) );
  303. $text .= $finish;
  304. }
  305. return $text;
  306. }
  307. function fetch_rss_items( $num ) {
  308. include_once(ABSPATH . WPINC . '/feed.php');
  309. $rss = fetch_feed( $this->feed );
  310. // Bail if feed doesn't work
  311. if ( is_wp_error($rss) )
  312. return false;
  313. $rss_items = $rss->get_items( 0, $rss->get_item_quantity( $num ) );
  314. // If the feed was erroneously
  315. if ( !$rss_items ) {
  316. $md5 = md5( $this->feed );
  317. delete_transient( 'feed_' . $md5 );
  318. delete_transient( 'feed_mod_' . $md5 );
  319. $rss = fetch_feed( $this->feed );
  320. $rss_items = $rss->get_items( 0, $rss->get_item_quantity( $num ) );
  321. }
  322. return $rss_items;
  323. }
  324. /**
  325. * Box with latest news from Yoast.com for sidebar
  326. */
  327. function news() {
  328. $rss_items = $this->fetch_rss_items( 3 );
  329. $content = '<ul>';
  330. if ( !$rss_items ) {
  331. $content .= '<li class="yoast">'.__( 'No news items, feed might be broken...', 'wordpress-seo' ).'</li>';
  332. } else {
  333. foreach ( $rss_items as $item ) {
  334. $url = preg_replace( '/#.*/', '', esc_url( $item->get_permalink(), $protocolls=null, 'display' ) );
  335. $content .= '<li class="yoast">';
  336. $content .= '<a class="rsswidget" href="'.$url.'#utm_source=wpadmin&utm_medium=sidebarwidget&utm_term=newsitem&utm_campaign=wpseoplugin">'. esc_html( $item->get_title() ) .'</a> ';
  337. $content .= '</li>';
  338. }
  339. }
  340. $content .= '<li class="facebook"><a href="https://www.facebook.com/yoast">'.__( 'Like Yoast on Facebook', 'wordpress-seo' ).'</a></li>';
  341. $content .= '<li class="twitter"><a href="http://twitter.com/yoast">'.__( 'Follow Yoast on Twitter', 'wordpress-seo' ).'</a></li>';
  342. $content .= '<li class="googleplus"><a href="https://plus.google.com/115369062315673853712/posts">'.__( 'Circle Yoast on Google+', 'wordpress-seo' ).'</a></li>';
  343. $content .= '<li class="email"><a href="http://yoast.com/wordpress-newsletter/">'.__( 'Subscribe by email', 'wordpress-seo' ).'</a></li>';
  344. $content .= '</ul>';
  345. $this->postbox('yoastlatest', __( 'Latest news from Yoast', 'wordpress-seo' ), $content);
  346. }
  347. }
  348. }