PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website shop bán domain hosting PHP/wp-content/themes/mimboPro/functions.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 441 lines | 295 code | 126 blank | 20 comment | 68 complexity | fd559764822496d07f7ea1ddb633cd24 MD5 | raw file
  1. <?php
  2. $bmTheme = "Mimbo Pro";
  3. // sidebar stuff
  4. if ( function_exists('register_sidebar') ) {
  5. register_sidebar(
  6. array(
  7. 'before_title' => '<h3 class="widgettitle">',
  8. 'after_title' => '</h3>',
  9. 'name' => 'Left Sidebar'
  10. )
  11. );
  12. register_sidebar(
  13. array(
  14. 'name' => 'Right Sidebar'
  15. )
  16. );
  17. unregister_sidebar_widget ( "search" );
  18. }
  19. // custom header stuff
  20. define( 'HEADER_TEXTCOLOR', '' );
  21. define( 'HEADER_IMAGE', '%s/images/header_bg.jpg' ); // %s is theme dir uri
  22. define( 'HEADER_IMAGE_WIDTH', 946 );
  23. define( 'HEADER_IMAGE_HEIGHT', 108 );
  24. define( 'HEADER_IMG_DIR', 'mimbopro' );
  25. define( 'NO_HEADER_TEXT', true );
  26. add_custom_image_header( 'bm_adminHeaderStyle', 'bm_adminHeaderStyle' );
  27. function bm_adminHeaderStyle() {}
  28. // the rest of the stuff....
  29. function bm_addThemePage() {
  30. global $bmTheme;
  31. if ( $_GET['page'] == basename(__FILE__) ) {
  32. // save settings
  33. if ( 'save' == $_REQUEST['action'] ) {
  34. check_admin_referer( 'save-theme-properties' );
  35. // text input
  36. update_option( 'bm_carouselCount', $_REQUEST[ 'bm_carouselCount' ] );
  37. update_option( 'bm_navigation', $_REQUEST[ 'bm_navigation' ] );
  38. update_option( 'bm_feedlinkURL', $_REQUEST[ 'bm_feedlinkURL' ] );
  39. update_option( 'bm_feedlinkComments', $_REQUEST[ 'bm_feedlinkComments' ] );
  40. update_option( 'bm_analytics', $_REQUEST[ 'bm_analytics' ] );
  41. update_option( 'bm_style', $_REQUEST[ 'bm_style' ] );
  42. update_option( 'mim_homeCat', $_REQUEST[ "mim_homeCat" ] );
  43. update_option( 'mim_carousel', $_REQUEST[ 'mim_carousel' ] );
  44. update_option( 'mim_feature', $_REQUEST[ 'mim_feature' ] );
  45. update_option( 'mim_contactEmail', $_REQUEST[ 'mim_contactEmail' ] );
  46. update_option( 'mim_contactSubject', $_REQUEST[ 'mim_contactSubject' ] );
  47. update_option( 'mim_contactSuccess', $_REQUEST[ 'mim_contactSuccess' ] );
  48. update_option( 'bm_adImage_1', $_REQUEST[ 'bm_adImage_1' ] );
  49. update_option( 'bm_adURL_1', $_REQUEST[ 'bm_adURL_1' ] );
  50. update_option( 'bm_adImage_2', $_REQUEST[ 'bm_adImage_2' ] );
  51. update_option( 'bm_adURL_2', $_REQUEST[ 'bm_adURL_2' ] );
  52. update_option( 'bm_adImage_3', $_REQUEST[ 'bm_adImage_3' ] );
  53. update_option( 'bm_adURL_3', $_REQUEST[ 'bm_adURL_3' ] );
  54. update_option( 'bm_adImage_4', $_REQUEST[ 'bm_adImage_4' ] );
  55. update_option( 'bm_adURL_4', $_REQUEST[ 'bm_adURL_4' ] );
  56. // checkboxes
  57. if( isset( $_REQUEST[ 'bm_logo' ] ) ) { update_option( 'bm_logo', 1 ); } else { delete_option( 'bm_logo' ); }
  58. if( isset( $_REQUEST[ 'bm_title' ] ) ) { update_option( 'bm_title', 1 ); } else { delete_option( 'bm_title' ); }
  59. if( isset( $_REQUEST[ 'bm_useCustomHeader' ] ) ) { update_option( 'bm_useCustomHeader', 1 ); } else { delete_option( 'bm_useCustomHeader' ); }
  60. // goto theme edit page
  61. header("Location: themes.php?page=functions.php&saved=true");
  62. die;
  63. // reset settings
  64. } else if( 'reset' == $_REQUEST['action'] ) {
  65. delete_option( 'bm_carouselCount' );
  66. delete_option( 'bm_navigation' );
  67. delete_option( 'bm_feedlinkURL' );
  68. delete_option( 'bm_feedlinkComments' );
  69. delete_option( 'bm_analytics' );
  70. delete_option( 'bm_style' );
  71. delete_option( 'mim_contactEmail' );
  72. delete_option( 'mim_contactSubject' );
  73. delete_option( 'mim_contactSuccess' );
  74. delete_option( 'mim_homeCat' );
  75. delete_option( 'mim_carousel' );
  76. delete_option( 'mim_feature' );
  77. delete_option( 'bm_adImage_1' );
  78. delete_option( 'bm_adURL_1' );
  79. delete_option( 'bm_adImage_2' );
  80. delete_option( 'bm_adURL_2' );
  81. delete_option( 'bm_adImage_3' );
  82. delete_option( 'bm_adURL_3' );
  83. delete_option( 'bm_adImage_4' );
  84. delete_option( 'bm_adURL_4' );
  85. // goto theme edit page
  86. header("Location: themes.php?page=functions.php&reset=true");
  87. die;
  88. }
  89. }
  90. add_theme_page( $bmTheme . ' Theme Options', $bmTheme . ' Options', 'edit_themes', basename(__FILE__), 'bm_themePage' );
  91. }
  92. function bm_themePage() {
  93. global $bmTheme;
  94. include( "scripts/bm_helpers.php" );
  95. if ( $_REQUEST[ 'saved' ] ) echo '<div id="message" class="updated fade"><p><strong>Settings saved</strong></p></div>';
  96. if ( $_REQUEST[ 'reset' ] ) echo '<div id="message" class="updated fade"><p><strong>Settings reset</strong></p></div>';
  97. ?>
  98. <div class="wrap">
  99. <h2><?php echo $bmTheme; ?></h2>
  100. <form method="post">
  101. <?php if ( function_exists('wp_nonce_field') ) { wp_nonce_field( 'save-theme-properties' ); } ?>
  102. <h3>Blog Settings</h3>
  103. <p>Some general blog settings to set up the layout of your site</p>
  104. <table width="100%" cellspacing="2" cellpadding="5" class="editform form-table">
  105. <?php
  106. // ------------
  107. // Theme Styles
  108. // ------------
  109. bm_th( 'Style' );
  110. // get styles
  111. $bm_styleDir = opendir( TEMPLATEPATH . "/skins/" );
  112. $bm_styles[] = array( "", "None (default)" );
  113. // Open a known directory, and proceed to read its contents
  114. while (false !== ( $bm_styleFolder = readdir( $bm_styleDir ) ) ) {
  115. if( $bm_styleFolder != "." && $bm_styleFolder != ".." ) {
  116. $bm_styleName = $bm_styleFolder;
  117. $bm_styleName = str_replace( "-", " ", $bm_styleName );
  118. $bm_styleName = str_replace( "_", " ", $bm_styleName );
  119. $bm_styles[] = array( $bm_styleFolder, $bm_styleName );
  120. }
  121. }
  122. bm_select( "bm_style", $bm_styles, get_settings( "bm_style" ), "" );
  123. closedir( $bm_styleDir );
  124. bm_cth();
  125. bm_th( "Header Properties" );
  126. bm_input( "bm_logo", "checkbox", "Show Logo?", "1", get_settings( 'bm_logo' ) );
  127. bm_input( "bm_useCustomHeader", "checkbox", "User custom header image?", "1", get_settings( 'bm_useCustomHeader' ) );
  128. bm_cth();
  129. bm_th( "Carousel Quantity" );
  130. bm_input( "bm_carouselCount", "text", "Number of Carousel items to show on the homepage. Defaults to 12, recommended greater than 4", get_settings( "bm_carouselCount" ) );
  131. bm_cth();
  132. $bm_nav[] = array( 0, "Categories (Default)" );
  133. $bm_nav[] = array( 1, "Pages" );
  134. bm_th( "Main Navigation" );
  135. bm_select( "bm_navigation", $bm_nav, get_settings( "bm_navigation" ), "" );
  136. bm_cth();
  137. // --------------
  138. // Other settings
  139. // --------------
  140. bm_th( "Feedburner URL" );
  141. bm_input( "bm_feedlinkURL", "text", "Optional Feedburner URL. Will replace rss feed links if used", get_settings( "bm_feedlinkURL" ) );
  142. bm_cth();
  143. bm_th( "Feedburner Comments URL" );
  144. bm_input( "bm_feedlinkComments", "text", "Optional Feedburner id. Will replace rss comment feed links if used", get_settings( "bm_feedlinkComments" ) );
  145. bm_cth();
  146. bm_th( "Google Analytics ID" );
  147. bm_input( "bm_analytics", "text", "Optional Google Analytics ID", get_settings( "bm_analytics" ) );
  148. bm_cth();
  149. ?>
  150. </table>
  151. <h3>Homepage Settings</h3>
  152. <p>Homepage specific settings. These control the content shown on the first page of your site.</p>
  153. <table width="100%" cellspacing="2" cellpadding="5" class="editform form-table">
  154. <?php
  155. $bm_categories = get_categories('hide_empty=0');
  156. foreach ( $bm_categories as $b ) {
  157. $bm_cat[] = array( $b->cat_ID, $b->cat_name );
  158. }
  159. bm_th( "Lead Category" );
  160. bm_select( "mim_feature", $bm_cat, get_settings( "mim_feature" ), "" );
  161. bm_cth();
  162. bm_th( "Carousel Category" );
  163. bm_select( "mim_carousel", $bm_cat, get_settings( "mim_carousel" ), "" );
  164. bm_cth();
  165. bm_th( "Category Summaries" );
  166. bm_multiSelect( "mim_homeCat[]", $bm_cat, get_settings( "mim_homeCat" ), "", "Hold down Control to select multiple categories" );
  167. bm_cth();
  168. ?>
  169. </table>
  170. <h3>Banner Ads</h3>
  171. <p>The Ads that will appear on the righthand sidebar of the homepage. To set up a new ad simply <strong>upload the image to the ads folder in your theme folder</strong></p>
  172. <table width="100%" cellspacing="2" cellpadding="5" class="editform form-table">
  173. <?php
  174. // get styles
  175. $bm_adsDir = opendir( TEMPLATEPATH . "/ads/" );
  176. $bm_ads[] = array( "", "None (default)" );
  177. // Open a known directory, and proceed to read its contents
  178. while (false !== ( $bm_adsFolder = readdir( $bm_adsDir ) ) ) {
  179. if( $bm_adsFolder != "." && $bm_adsFolder != ".." ) {
  180. $bm_adName = $bm_adsFolder;
  181. $bm_adName = str_replace( "-", " ", $bm_adName );
  182. $bm_adName = str_replace( ".jpg", "", $bm_adName );
  183. $bm_adName = str_replace( ".gif", "", $bm_adName );
  184. $bm_adName = str_replace( "_", " ", $bm_adName );
  185. $bm_ads[] = array( $bm_adsFolder, $bm_adName );
  186. }
  187. }
  188. closedir( $bm_adsDir );
  189. bm_th( "Advert 1" );
  190. bm_select( "bm_adImage_1", $bm_ads, get_settings( "bm_adImage_1" ), "" );
  191. echo "<br />";
  192. bm_input( "bm_adURL_1", "text", "Advert 1 click URL", get_settings( "bm_adURL_1" ) );
  193. bm_cth();
  194. bm_th( "Advert 2" );
  195. bm_select( "bm_adImage_2", $bm_ads, get_settings( "bm_adImage_2" ), "" );
  196. echo "<br />";
  197. bm_input( "bm_adURL_2", "text", "Advert 2 click URL", get_settings( "bm_adURL_2" ) );
  198. bm_cth();
  199. bm_th( "Advert 3" );
  200. bm_select( "bm_adImage_3", $bm_ads, get_settings( "bm_adImage_3" ), "" );
  201. echo "<br />";
  202. bm_input( "bm_adURL_3", "text", "Advert 3 click URL", get_settings( "bm_adURL_3" ) );
  203. bm_cth();
  204. bm_th( "Advert 4" );
  205. bm_select( "bm_adImage_4", $bm_ads, get_settings( "bm_adImage_4" ), "" );
  206. echo "<br />";
  207. bm_input( "bm_adURL_4", "text", "Advert 4 click URL", get_settings( "bm_adURL_4" ) );
  208. bm_cth();
  209. ?>
  210. </table>
  211. <h3>Contact Page properties</h3>
  212. <p>Some general settings for your contact form</p>
  213. <table width="100%" cellspacing="2" cellpadding="5" class="editform form-table">
  214. <?php
  215. bm_th( "Email Address" );
  216. bm_input( "mim_contactEmail", "text", "contact email address", get_settings( "mim_contactEmail" ) );
  217. bm_cth();
  218. bm_th( "Contact Form Email Subject" );
  219. bm_input( "mim_contactSubject", "text", "Enter a subject for the contact submission", get_settings( "mim_contactSubject" ) );
  220. bm_cth();
  221. bm_th( "Contact Form Email Success Message" );
  222. bm_input( "mim_contactSuccess", "text", "Enter a success message that will be displayed to the user after their submission.", get_settings( "mim_contactSuccess" ) );
  223. bm_cth();
  224. ?>
  225. </table>
  226. <input type="hidden" name="action" value="save" />
  227. <?php bm_input( "save", "submit", "", "Save Settings" ); ?>
  228. </form>
  229. </div>
  230. <?php
  231. }
  232. function bm_getProperty( $property ) {
  233. global $bmTheme;
  234. $value = get_settings( "bmTheme_" . $property );
  235. if( $value == "1" ) { return 1; } else { return 0; }
  236. }
  237. $bm_trackbacks = array();
  238. $bm_comments = array();
  239. function bm_splitComments( $source ) {
  240. if ( $source ) {
  241. global $bm_trackbacks;
  242. global $bm_comments;
  243. foreach ( $source as $comment ) {
  244. if ( $comment->comment_type == 'trackback' || $comment->comment_type == 'pingback' ) {
  245. $bm_trackbacks[] = $comment;
  246. } else {
  247. $bm_comments[] = $comment;
  248. }
  249. }
  250. }
  251. }
  252. function bm_catProperties( $id ) {
  253. global $bm_categories;
  254. forEach( $bm_categories as $bC ) {
  255. if( $bC->cat_ID == $id ) {
  256. return $bC;
  257. exit;
  258. }
  259. }
  260. }
  261. // based upon the work done by Steve Smith - http://orderedlist.com/wordpress-plugins/feedburner-plugin/ and feedburner - http://www.feedburner.com/fb/a/help/wordpress_quickstart
  262. function feed_redirect() {
  263. global $wp, $feed, $withcomments;
  264. $newURL1 = trim( get_settings( "bm_feedlinkURL" ) );
  265. $newURL2 = trim( get_settings( "bm_feedlinkComments" ) );
  266. if( is_feed() ) {
  267. if ( $feed != 'comments-rss2'
  268. && !is_single()
  269. && $wp->query_vars[ 'category_name' ] == ''
  270. && !is_author()
  271. && ( $withcomments != 1 )
  272. && $newURL1 != '' ) {
  273. if ( function_exists( 'status_header' ) ) { status_header( 302 ); }
  274. header( "Location:" . $newURL1 );
  275. header( "HTTP/1.1 302 Temporary Redirect" );
  276. exit();
  277. } elseif ( ( $feed == 'comments-rss2' || $withcomments == 1 ) && $newURL2 != '' ) {
  278. if ( function_exists( 'status_header' ) ) { status_header( 302 ); }
  279. header( "Location:" . $newURL2 );
  280. header( "HTTP/1.1 302 Temporary Redirect" );
  281. exit();
  282. }
  283. }
  284. }
  285. function feed_check_url() {
  286. switch ( basename( $_SERVER[ 'PHP_SELF' ] ) ) {
  287. case 'wp-rss.php':
  288. case 'wp-rss2.php':
  289. case 'wp-atom.php':
  290. case 'wp-rdf.php':
  291. $newURL = trim( get_settings( "bm_feedlinkURL" ) );
  292. if ( $newURL != '' ) {
  293. if ( function_exists('status_header') ) { status_header( 302 ); }
  294. header( "Location:" . $newURL );
  295. header( "HTTP/1.1 302 Temporary Redirect" );
  296. exit();
  297. }
  298. break;
  299. case 'wp-commentsrss2.php':
  300. $newURL = trim( get_settings( "bm_feedlinkComments" ) );
  301. if ( $newURL != '' ) {
  302. if ( function_exists('status_header') ) { status_header( 302 ); }
  303. header( "Location:" . $newURL );
  304. header( "HTTP/1.1 302 Temporary Redirect" );
  305. exit();
  306. }
  307. break;
  308. }
  309. }
  310. if (!preg_match("/feedburner|feedvalidator/i", $_SERVER['HTTP_USER_AGENT'])) {
  311. add_action('template_redirect', 'feed_redirect');
  312. add_action('init','feed_check_url');
  313. }
  314. add_action( 'admin_menu', 'bm_addThemePage' );
  315. ?>