Guest User

Untitled

a guest
Jun 15th, 2011
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.01 KB | None | 0 0
  1. <?php
  2. $padd_themename = 'Marikit-Blue';
  3. $padd_shortname = 'marikit-blue';
  4. $padd_prefix = 'padd';
  5. //Activate post-image functionality (WP 2.9+)
  6. if ( function_exists( 'add_theme_support' ) )
  7. add_theme_support( 'post-thumbnails' );
  8.  
  9. function get_image_path ($post_id = null) {
  10. if ($post_id == null) {
  11. global $post;
  12. $post_id = $post->ID;
  13. }
  14. $theImageSrc = wp_get_attachment_url( get_post_thumbnail_id($post_id) );
  15. global $blog_id;
  16. if (isset($blog_id) && $blog_id > 0) {
  17. $imageParts = explode('/files/', $theImageSrc);
  18. if (isset($imageParts[1])) {
  19. $theImageSrc = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
  20. }
  21. }
  22. return $theImageSrc;
  23. }
  24.  
  25.  
  26. if (function_exists('register_sidebar')) {
  27. register_sidebar(array(
  28. 'name' => 'Side Bar',
  29. 'before_widget' => '<div class="box box-%2$s">',
  30. 'after_widget' => '</div></div>',
  31. 'before_title' => '<div class="title"><h2>',
  32. 'after_title' => '</h2></div><div class="interior">',
  33. )
  34. );
  35. }
  36.  
  37. require get_theme_root() . '/' . $padd_shortname . '/functions/option.php';
  38. require get_theme_root() . '/' . $padd_shortname . '/functions/advertisement.php';
  39.  
  40. $options_general = array(
  41. new Option(
  42. $padd_prefix . '_facebook_id',
  43. 'Faceboook ID',
  44. 'Your <a href="http://www.facebook.com">Facebook</a> profile ID.',
  45. 'textbox',
  46. '250'
  47. ),
  48. new Option(
  49. $padd_prefix . '_twitter_username',
  50. 'Twitter Username',
  51. 'Your <a href="http://twitter.com">Twitter</a> user name. You may leave it blank if you don\'t have one but we recommend
  52. to <a href="http://twitter.com/signup">create an account</a>.',
  53. 'textbox',
  54. '250'
  55. ),
  56. new Option(
  57. $padd_prefix . '_stumbleupon_id',
  58. 'StumbleUpon ID',
  59. 'Your <a href="http://www.stumbleupon.com">StumbleUpon</a> ID.',
  60. 'textbox',
  61. '250'
  62. ),
  63. new Option(
  64. $padd_prefix . '_delicious_id',
  65. 'Delicious ID',
  66. 'Your <a href="http://www.delicious.com">Delicious</a> ID.',
  67. 'textbox',
  68. '250'
  69. ),
  70. new Option(
  71. $padd_prefix . '_digg_id',
  72. 'Digg ID',
  73. 'Your <a href="http://www.digg.com">Digg</a> ID.',
  74. 'textbox',
  75. '250'
  76. ),
  77.  
  78. new Option(
  79. $padd_prefix . '_google_analytics',
  80. 'Google Analytics Code',
  81. 'The code provided by Google Analytics. This is optional, though.',
  82. 'textarea'
  83. ),
  84. new Option(
  85. $padd_prefix . '_youtube_code',
  86. 'YouTube Embed Code',
  87. 'The code provided by YouTube for displaying a video located at the sidebar. In order to fit inside the sidebar, set the
  88. <code>&lt;object&gt;</code> and <code>&lt;embed&gt;</code> width to 288 and height to 238. The YouTube provides the smallest possible
  89. video size is 320 x 265 (without borders).',
  90. 'textarea'
  91. ),
  92. );
  93.  
  94. $options_google = array(
  95. new Option(
  96. $padd_prefix . '_ad_468_60',
  97. 'Google Adsense Banner (468x60) Ad Code',
  98. 'This is for the Google Adsense Banner Ad located above every blog entry, search result, and categories.',
  99. 'textarea'
  100. ),
  101. );
  102.  
  103. $options_yourads = array(
  104. new Advertisement(
  105. $padd_prefix . '_banner',
  106. 'Full Banner (468x60)',
  107. 'The advertisement found at the right side of the blog title.'
  108. ),
  109. new Advertisement(
  110. $padd_prefix . '_sqbtn_1',
  111. 'Square Ad 1 (125x125)',
  112. 'The advertisement found at the top of the rightmost side bar.'
  113. ),
  114. new Advertisement(
  115. $padd_prefix . '_sqbtn_2',
  116. 'Square Ad 2 (125x125)',
  117. 'The advertisement found at the top of the rightmost side bar.'
  118. ),
  119. new Advertisement(
  120. $padd_prefix . '_sqbtn_3',
  121. 'Square Ad 3 (125x125)',
  122. 'The advertisement found at the top of the rightmost side bar.'
  123. ),
  124. new Advertisement(
  125. $padd_prefix . '_sqbtn_4',
  126. 'Square Ad 4 (125x125)',
  127. 'The advertisement found at the top of the rightmost side bar.'
  128. ),
  129. );
  130.  
  131.  
  132.  
  133. function themefunction_add_admin() {
  134. global $padd_themename, $padd_shortname, $options_general, $options_gallery, $options_google, $options_yourads;
  135.  
  136. if ( $_GET['page'] == basename(__FILE__) ) {
  137. if ( 'save' == $_REQUEST['action'] ) {
  138.  
  139. foreach ($options_general as $opt) {
  140. update_option($opt->getKeyword(),$_REQUEST[$opt->getKeyword()]);
  141. }
  142.  
  143.  
  144. foreach ($options_google as $opt) {
  145. update_option($opt->getKeyword(),stripslashes($_REQUEST[$opt->getKeyword()]));
  146. }
  147.  
  148. foreach ($options_yourads as $opt) {
  149. update_option($opt->getKeyword('img'),$_REQUEST[$opt->getKeyword('img')]);
  150. update_option($opt->getKeyword('web'),$_REQUEST[$opt->getKeyword('web')]);
  151. }
  152.  
  153. header("Location: themes.php?page=functions.php&saved=true");
  154. die;
  155.  
  156. } else if ( 'reset' == $_REQUEST['action'] ) {
  157.  
  158. foreach ($options_general as $opt) {
  159. delete_option($opt->getKeyword());
  160. }
  161.  
  162. foreach ($options_gallery as $opt) {
  163. delete_option($opt->getKeyword());
  164. }
  165.  
  166. foreach ($options_google as $opt) {
  167. delete_option($opt->getKeyword());
  168. }
  169.  
  170. foreach ($options_yourads as $opt) {
  171. delete_option($opt->getKeyword('img'));
  172. delete_option($opt->getKeyword('web'));
  173. }
  174.  
  175. header("Location: themes.php?page=functions.php&reset=true");
  176. die;
  177. }
  178. }
  179.  
  180. add_theme_page($padd_themename ." Options", $padd_themename . " Options", 'edit_themes', basename(__FILE__), 'themefunction_admin');
  181. }
  182.  
  183. function themefunction_admin() {
  184. global $padd_themename, $padd_shortname, $options_general, $options_gallery, $options_google, $options_yourads;
  185.  
  186. if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$padd_themename.' settings saved.</strong></p></div>';
  187. if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$padd_themename.' settings reset.</strong></p></div>';
  188.  
  189. require get_theme_root() . '/' . $padd_shortname . '/functions/userinterface.php';
  190. }
  191.  
  192. add_action('admin_menu', 'themefunction_add_admin');
  193.  
  194.  
  195.  
  196. /********************************************/
  197. /**** Functions used for hooking filters ****/
  198. /********************************************/
  199.  
  200. function themefunction_alter_list_pages($string) {
  201. $string = str_replace(array("\n","\r","\t"),'', $string);
  202.  
  203. $pattern = array('/<ul[^<>]*>/','/<\/ul[^<>]*>/');
  204. $replace = array('','');
  205. $string = preg_replace($pattern,$replace,$string);
  206. $pattern = array('/<a[^<>]*>/','/<\/a[^<>]*>/');
  207. $replace = array('$0<span><span>','</span></span>$0');
  208. $string = preg_replace($pattern,$replace,$string);
  209.  
  210. $string = str_replace(array('</a><li','</li></li>'),array('</a></li><li','</li>'),$string);
  211. return $string;
  212. }
  213.  
  214. function themefunction_alter_page_menu($string) {
  215. $string = themefunction_alter_list_pages($string);
  216. $pattern = array('/<div[^<>]*>/','/<\/div[^<>]*>/');
  217. $replace = array('','');
  218. $string = preg_replace($pattern,$replace,$string);
  219. return $string;
  220. }
  221.  
  222. function themefunction_alter_category_menu($string) {
  223. $string = themefunction_alter_list_pages($string);
  224. $pattern = array('/<div[^<>]*>/','/<\/div[^<>]*>/');
  225. $replace = array('<span>$0','$0</span>');
  226. $string = preg_replace($pattern,$replace,$string);
  227. return $string;
  228. }
  229.  
  230. function themefunction_alter_links($string) {
  231. $pattern = array('/<a[^<>]*>/','/<\/a[^<>]*>/');
  232. $replace = array('<span>$0','$0</span>');
  233. $string = preg_replace($pattern,$replace,$string);
  234. return $string;
  235. }
  236.  
  237. /***********************************************/
  238. /**** Add filters when necessary **************/
  239. /***********************************************/
  240.  
  241. add_filter('wp_list_pages','themefunction_alter_links');
  242. add_filter('wp_list_cats','themefunction_alter_links');
  243. add_filter('wp_list_bookmarks','themefunction_alter_links');
  244. add_filter('get_archives_link','themefunction_alter_links');
  245.  
  246.  
  247.  
  248.  
  249. /***********************************************/
  250. /**** Functions used for modifying the look ****/
  251. /***********************************************/
  252.  
  253. function themefunction_page_menu() {
  254. add_filter('wp_page_menu','themefunction_alter_page_menu');
  255. wp_page_menu('show_home=1&title_li=');
  256. remove_filter('wp_page_menu','themefunction_alter_page_menu');
  257. }
  258.  
  259.  
  260. function themefunction_category_menu() {
  261. add_filter('wp_list_categories','themefunction_alter_category_menu');
  262. wp_list_categories('sort_column=name&optioncount=0&hierarchical=0&list=0&title_li=');
  263. remove_filter('wp_list_categories','themefunction_alter_page_menu');
  264. }
  265.  
  266. function themefunction_cleanup($str) {
  267. global $akpc, $post;
  268. $show = true;
  269. $show = apply_filters('akpc_display_popularity', $show, $post);
  270. if (is_feed() || is_admin_page() || get_post_meta($post->ID, 'hide_popularity', true) || !$show) {
  271. return $str;
  272. }
  273. return $str.'';
  274. }
  275.  
  276. function themefunction_list_bookmarks() {
  277. $array = array();
  278. $array[] = 'category_before=';
  279. $array[] = 'category_after=';
  280. $array[] = 'categorize=0';
  281. $array[] = 'title_li=';
  282. wp_list_bookmarks(implode('&',$array));
  283. }
  284.  
  285. function themefunction_recent_post() {
  286. echo '<ul>';
  287. wp_get_archives('type=postbypost&limit=5');
  288. echo '</ul>';
  289. }
  290.  
  291. function themefunction_get_categories($cat_id) {
  292. if ('' != get_the_category_by_ID($cat_id)) {
  293. echo '<li>';
  294. echo '<a href="' . get_category_link($cat_id) . '">' . get_the_category_by_ID($cat_id) . '</a>';
  295. if ('' != (get_category_children($cat_id))) {
  296. echo '<ul>';
  297. wp_list_categories('hide_empty=0&title_li=&child_of=' . $cat_id);
  298. echo '</ul>';
  299. }
  300. echo '</li>';
  301. }
  302. }
  303.  
  304. function themefunction_recent_comments($limit=5) {
  305. global $wpdb, $comments, $comment;
  306.  
  307. if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
  308. $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $limit");
  309. wp_cache_add( 'recent_comments', $comments, 'widget' );
  310. }
  311. ?>
  312. <ul id="recentcomments">
  313. <?php
  314. if ( $comments ) : foreach ( (array) $comments as $comment) :
  315. echo '<li class="recentcomments"><span><span>' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_comment_link($comment->comment_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</span></span></li>';
  316. endforeach; endif;?>
  317. </ul>
  318. <?php
  319. }
  320.  
  321.  
  322. //EXCERPT
  323. function excerpt_length( $length ) {
  324. return 10;
  325. }
  326. add_filter( 'excerpt_length', 'excerpt_length' );
  327.  
  328. function continue_reading_link() {
  329. return '';
  330. }
  331.  
  332. function auto_excerpt_more( $more ) {
  333. return ' &hellip;' . continue_reading_link();
  334. }
  335. add_filter( 'excerpt_more', 'auto_excerpt_more' );
  336.  
  337. function custom_excerpt_more( $output ) {
  338. if ( has_excerpt() && ! is_attachment() ) {
  339. $output .= continue_reading_link();
  340. }
  341. return $output;
  342. }
  343. add_filter( 'get_the_excerpt', 'custom_excerpt_more' );
  344. //EXCERPT
  345.  
  346. function themefunction_comments($comment, $args, $depth) {
  347. $GLOBALS['comment'] = $comment; ?>
  348. <li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
  349. <div class="comment" id="div-comment-<?php comment_ID(); ?>">
  350. <div class="comment-author vcard">
  351. <?php echo get_avatar($comment,$size='32',$default='<path_to_url>' ); ?>
  352. <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
  353. <div class="comment-meta commentmetadata">
  354. <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?></a> <?php edit_comment_link(__('(Edit)'),' ','') ?>
  355. </div>
  356. </div>
  357. <?php if ($comment->comment_approved == '0') : ?>
  358. <em><?php _e('Your comment is awaiting moderation.') ?></em>
  359. <?php endif; ?>
  360.  
  361. <?php comment_text() ?>
  362.  
  363. <div class="reply">
  364. <?php comment_reply_link(array_merge( $args, array('add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  365. </div>
  366. </div>
  367. <?php
  368. }
  369. function themefunction_imageresizer ($atts, $content=null){
  370. return '<img src="' . get_theme_root() . '/' . $padd_shortname . '/functions/timthumb.php?src=' . $content . '&amp;w=300&amp;h=250&amp;zc=1" alt="">';
  371.  
  372. }
  373. add_shortcode('img', 'themefunction_imageresizer');
  374.  
  375. function themefunction_catch_that_image() {
  376. global $post, $posts;
  377. $first_img = '';
  378. ob_start();
  379. ob_end_clean();
  380. $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  381. $first_img = $matches [1] [0];
  382.  
  383. // no image found display default image instead
  384. if(empty($first_img)){
  385. $first_img = get_bloginfo('wpurl') . '/wp-content/themes/marikit-blue/images/thumbnail.png';
  386. }
  387. return $first_img;
  388. }
  389.  
  390. function themefunction_getTinyUrl($url) {
  391. $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
  392. return $tinyurl;
  393. }
  394.  
  395. function themefunction_twitter_parse($feed) {
  396. $stepOne = explode("<content type=\"html\">", $feed);
  397. $stepTwo = explode("</content>", $stepOne[1]);
  398. $tweet = $stepTwo[0];
  399. $tweet = str_replace("&lt;", "<", $tweet);
  400. $tweet = str_replace("&gt;", ">", $tweet);
  401. return $tweet;
  402. }
  403.  
  404. function themefunction_twitter_get_recent_entry($user) {
  405. $feed = 'http://search.twitter.com/search.atom?q=from:' . $user . '&rpp=1';
  406. $twitterFeed = file_get_contents($feed);
  407.  
  408. return themefunction_twitter_parse($twitterFeed);
  409. }
  410.  
  411.  
  412. function themefunction_twitter_get_recent_entries($user) {
  413. $feed = 'http://search.twitter.com/search.atom?q=from:' . $user . '&rpp=3';
  414. $twitterFeed = file_get_contents($feed);
  415.  
  416. $twitterFeed = str_replace("&lt;", "<", $twitterFeed);
  417. $twitterFeed = str_replace("&gt;", ">", $twitterFeed);
  418. $clean = explode("<content type=\"html\">", $twitterFeed);
  419.  
  420. $amount = count($clean) - 1;
  421.  
  422. echo '<ul class="twitter">';
  423.  
  424. for ($i = 1; $i <= $amount-1; $i++) {
  425. $cleaner = explode("</content>", $clean[$i]);
  426. echo '<li class="twitter-item">';
  427. echo $cleaner[0];
  428. echo '</li>';
  429. }
  430. $cleaner = explode("</content>", $clean[$i]);
  431. echo '<li class="twitter-lastitem">';
  432. echo $cleaner[0];
  433. echo '</li>';
  434. echo '</ul>';
  435. }
  436.  
  437.  
  438. //ADD METABOX
  439. $prefix = 'dbt_';
  440.  
  441. $meta_box = array(
  442. 'id' => 'my-meta-box',
  443. 'title' => 'Coupon Information Box',
  444. 'page' => 'post',
  445. 'context' => 'normal',
  446. 'priority' => 'high',
  447. 'fields' => array(
  448. array(
  449. 'name' => 'Coupon Affiliate Link',
  450. 'desc' => 'Enter Coupon Affiliate Link',
  451. 'id' => $prefix . 'affiliate_link',
  452. 'type' => 'text',
  453. 'std' => ''
  454. ),
  455. array(
  456. 'name' => 'Coupon Code',
  457. 'desc' => 'Enter Coupon Code',
  458. 'id' => $prefix . 'coupon_code',
  459. 'type' => 'text',
  460. 'std' => ''
  461. )
  462. )
  463. );
  464.  
  465. add_action('admin_menu', 'mytheme_add_box');
  466.  
  467. // Add meta box
  468. function mytheme_add_box() {
  469. global $meta_box;
  470.  
  471. add_meta_box($meta_box['id'], $meta_box['title'], 'mytheme_show_box', $meta_box['page'], $meta_box['context'], $meta_box['priority']);
  472. }
  473.  
  474. // Callback function to show fields in meta box
  475. function mytheme_show_box() {
  476. global $meta_box, $post;
  477.  
  478. // Use nonce for verification
  479. echo '<input type="hidden" name="mytheme_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
  480.  
  481. echo '<table class="form-table">';
  482.  
  483. foreach ($meta_box['fields'] as $field) {
  484. // get current post meta data
  485. $meta = get_post_meta($post->ID, $field['id'], true);
  486.  
  487. echo '<tr>',
  488. '<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>',
  489. '<td>';
  490. switch ($field['type']) {
  491. case 'text':
  492. echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />',
  493. '<br />', $field['desc'];
  494. break;
  495. case 'textarea':
  496. echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:97%">', $meta ? $meta : $field['std'], '</textarea>',
  497. '<br />', $field['desc'];
  498. break;
  499. case 'select':
  500. echo '<select name="', $field['id'], '" id="', $field['id'], '">';
  501. foreach ($field['options'] as $option) {
  502. echo '<option', $meta == $option ? ' selected="selected"' : '', '>', $option, '</option>';
  503. }
  504. echo '</select>';
  505. break;
  506. case 'radio':
  507. foreach ($field['options'] as $option) {
  508. echo '<input type="radio" name="', $field['id'], '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' />', $option['name'];
  509. }
  510. break;
  511. case 'checkbox':
  512. echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';
  513. break;
  514. }
  515. echo '<td>',
  516. '</tr>';
  517. }
  518.  
  519. echo '</table>';
  520. }
  521.  
  522. add_action('save_post', 'mytheme_save_data');
  523.  
  524. // Save data from meta box
  525. function mytheme_save_data($post_id) {
  526. global $meta_box;
  527.  
  528. // verify nonce
  529. if (!wp_verify_nonce($_POST['mytheme_meta_box_nonce'], basename(__FILE__))) {
  530. return $post_id;
  531. }
  532.  
  533. // check autosave
  534. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
  535. return $post_id;
  536. }
  537.  
  538. // check permissions
  539. if ('page' == $_POST['post_type']) {
  540. if (!current_user_can('edit_page', $post_id)) {
  541. return $post_id;
  542. }
  543. } elseif (!current_user_can('edit_post', $post_id)) {
  544. return $post_id;
  545. }
  546.  
  547. foreach ($meta_box['fields'] as $field) {
  548. $old = get_post_meta($post_id, $field['id'], true);
  549. $new = $_POST[$field['id']];
  550.  
  551. if ($new && $new != $old) {
  552. update_post_meta($post_id, $field['id'], $new);
  553. } elseif ('' == $new && $old) {
  554. delete_post_meta($post_id, $field['id'], $old);
  555. }
  556. }
  557. }
  558. ?>
Add Comment
Please, Sign In to add comment