web/wp-content/themes/newsworthy/functions.php
changeset 1 0d28b7c10758
child 2 4f3e6ea1c867
equal deleted inserted replaced
0:0d9a58d2c515 1:0d28b7c10758
       
     1 <?php
       
     2 
       
     3 $new_meta_boxes =
       
     4 
       
     5 array(
       
     6 
       
     7 "image" => array(
       
     8 
       
     9 "name" => "newsworthy_image",
       
    10 
       
    11 "std" => "",
       
    12 
       
    13 "title" => "Featured Image",
       
    14 
       
    15 "description" => "Using the \"<em>Add an Image</em>\" button, upload a 610x281 image and paste the URL here.  Displayed in full size for the featured post, resized versions for single posts and substories on index pages are handled automatically.")
       
    16 
       
    17 );
       
    18 
       
    19 function new_meta_boxes() {
       
    20 
       
    21 global $post, $new_meta_boxes;
       
    22 
       
    23 
       
    24 
       
    25 foreach($new_meta_boxes as $meta_box) {
       
    26 
       
    27 $meta_box_value = get_post_meta($post->ID, $meta_box['name'].'_value', true);
       
    28 
       
    29 
       
    30 
       
    31 if($meta_box_value == "")
       
    32 
       
    33 $meta_box_value = $meta_box['std'];
       
    34 
       
    35 
       
    36 
       
    37 echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
       
    38 
       
    39 
       
    40 
       
    41 echo'<h2>'.$meta_box['title'].'</h2>';
       
    42 
       
    43 
       
    44 
       
    45 echo'<input type="text" name="'.$meta_box['name'].'_value" value="'.$meta_box_value.'" size="55" /><br />';
       
    46 
       
    47 
       
    48 
       
    49 echo'<p><label for="'.$meta_box['name'].'_value">'.$meta_box['description'].'</label></p>';
       
    50 
       
    51 }
       
    52 
       
    53 }
       
    54 
       
    55 function create_meta_box() {
       
    56 
       
    57 global $theme_name;
       
    58 
       
    59 if ( function_exists('add_meta_box') ) {
       
    60 
       
    61 add_meta_box( 'new-meta-boxes', 'Newsworthy Post Settings', 'new_meta_boxes', 'post', 'normal', 'high' );
       
    62 
       
    63 }
       
    64 
       
    65 }
       
    66 
       
    67 function save_postdata( $post_id ) {
       
    68 
       
    69 global $post, $new_meta_boxes;
       
    70 
       
    71 
       
    72 
       
    73 foreach($new_meta_boxes as $meta_box) {
       
    74 
       
    75 // Verify
       
    76 
       
    77 if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
       
    78 
       
    79 return $post_id;
       
    80 
       
    81 }
       
    82 
       
    83 
       
    84 
       
    85 if ( 'page' == $_POST['post_type'] ) {
       
    86 
       
    87 if ( !current_user_can( 'edit_page', $post_id ))
       
    88 
       
    89 return $post_id;
       
    90 
       
    91 } else {
       
    92 
       
    93 if ( !current_user_can( 'edit_post', $post_id ))
       
    94 
       
    95 return $post_id;
       
    96 
       
    97 }
       
    98 
       
    99 
       
   100 
       
   101 $data = $_POST[$meta_box['name'].'_value'];
       
   102 
       
   103 
       
   104 
       
   105 if(get_post_meta($post_id, $meta_box['name'].'_value') == "")
       
   106 
       
   107 add_post_meta($post_id, $meta_box['name'].'_value', $data, true);
       
   108 
       
   109 elseif($data != get_post_meta($post_id, $meta_box['name'].'_value', true))
       
   110 
       
   111 update_post_meta($post_id, $meta_box['name'].'_value', $data);
       
   112 
       
   113 elseif($data == "")
       
   114 
       
   115 delete_post_meta($post_id, $meta_box['name'].'_value', get_post_meta($post_id, $meta_box['name'].'_value', true));
       
   116 
       
   117 }
       
   118 
       
   119 }
       
   120 
       
   121 add_action('admin_menu', 'create_meta_box');
       
   122 
       
   123 add_action('save_post', 'save_postdata');
       
   124 
       
   125 function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
       
   126 
       
   127     $content = get_the_content($more_link_text, $stripteaser, $more_file);
       
   128 
       
   129     $content = apply_filters('the_content', $content);
       
   130 
       
   131     $content = str_replace(']]>', ']]&gt;', $content);
       
   132 
       
   133 
       
   134 
       
   135    if (strlen($_GET['p']) > 0) {
       
   136 
       
   137       echo $content;
       
   138 
       
   139    }
       
   140 
       
   141    else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
       
   142 
       
   143         $content = substr($content, 0, $espacio);
       
   144 
       
   145         $content = $content;
       
   146 
       
   147         echo $content;
       
   148 
       
   149         echo "</p>";
       
   150 
       
   151    }
       
   152 
       
   153    else {
       
   154 
       
   155       echo $content;
       
   156 
       
   157    }
       
   158 
       
   159 }
       
   160 
       
   161 class My_125_Widget extends WP_Widget {
       
   162 
       
   163 	function My_125_Widget() {
       
   164 
       
   165 		$widget_ops = array('classname' => 'widget_125_ad', 'description' => 'A single 125x125 ad banner' );
       
   166 
       
   167 		$this->WP_Widget('125_ad', '125x125 Ad', $widget_ops);
       
   168 
       
   169 	}
       
   170 
       
   171  
       
   172 
       
   173 	function widget($args, $instance) {
       
   174 
       
   175 		extract($args, EXTR_SKIP);
       
   176 
       
   177  
       
   178 
       
   179 		echo $before_widget;
       
   180 
       
   181 		$image_url = empty($instance['image_url']) ? '' : apply_filters('widget_image_url', $instance['image_url']);
       
   182 
       
   183 		$image_alt = empty($instance['image_alt']) ? '' : apply_filters('widget_image_alt', $instance['image_alt']);
       
   184 
       
   185 		$image_link = empty($instance['image_link']) ? '' : apply_filters('widget_image_link', $instance['image_link']);
       
   186 
       
   187  
       
   188 
       
   189 		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
       
   190 
       
   191 		echo '<a href=" ' . $image_link . '" rel="nofollow" title=" ' . $image_alt . ' ">';
       
   192 
       
   193 		echo '<img class="banner" src="' . $image_url . '" alt="' . $image_alt . '" />';
       
   194 
       
   195 		echo '</a>';
       
   196 
       
   197 		echo $after_widget;
       
   198 
       
   199 	}
       
   200 
       
   201  
       
   202 
       
   203 	function update($new_instance, $old_instance) {
       
   204 
       
   205 		$instance = $old_instance;
       
   206 
       
   207 		$instance['image_url'] = strip_tags($new_instance['image_url']);
       
   208 
       
   209 		$instance['image_alt'] = strip_tags($new_instance['image_alt']);
       
   210 
       
   211 		$instance['image_link'] = strip_tags($new_instance['image_link']);
       
   212 
       
   213  
       
   214 
       
   215 		return $instance;
       
   216 
       
   217 	}
       
   218 
       
   219  
       
   220 
       
   221 	function form($instance) {
       
   222 
       
   223 		$instance = wp_parse_args( (array) $instance, array( 'image_url' => '', 'image_alt' => '', 'image_link' => '' ) );
       
   224 
       
   225 		$image_url = strip_tags($instance['image_url']);
       
   226 
       
   227 		$image_alt = strip_tags($instance['image_alt']);
       
   228 
       
   229 		$image_link = strip_tags($instance['image_link']);
       
   230 
       
   231 ?>
       
   232 
       
   233 			<p><label for="<?php echo $this->get_field_id('image_url'); ?>">Image URL: <input class="widefat" id="<?php echo $this->get_field_id('image_url'); ?>" name="<?php echo $this->get_field_name('image_url'); ?>" type="text" value="<?php echo attribute_escape($image_url); ?>" /></label></p>
       
   234 
       
   235 			<p><label for="<?php echo $this->get_field_id('image_alt'); ?>">Image Alt/Link Title: <input class="widefat" id="<?php echo $this->get_field_id('image_alt'); ?>" name="<?php echo $this->get_field_name('image_alt'); ?>" type="text" value="<?php echo attribute_escape($image_alt); ?>" /></label></p>
       
   236 
       
   237 			<p><label for="<?php echo $this->get_field_id('image_link'); ?>">Link URL: <input class="widefat" id="<?php echo $this->get_field_id('image_link'); ?>" name="<?php echo $this->get_field_name('image_link'); ?>" type="text" value="<?php echo attribute_escape($image_link); ?>" /></label></p>
       
   238 
       
   239 <?php
       
   240 
       
   241 	}
       
   242 
       
   243 }
       
   244 
       
   245 register_widget('My_125_Widget');
       
   246 
       
   247 if ( function_exists('register_sidebar') )
       
   248 
       
   249     register_sidebar(array(
       
   250 
       
   251         'name' => 'Tabber',
       
   252 
       
   253         'before_widget' => '<div class="tabbertab">',
       
   254 
       
   255         'after_widget' => '<div class="clear">&nbsp;</div></div>',
       
   256 
       
   257         'before_title' => '<h2>',
       
   258 
       
   259         'after_title' => '</h2>',
       
   260 
       
   261     ));
       
   262 
       
   263 if ( function_exists('register_sidebar') )
       
   264 
       
   265     register_sidebar(array(
       
   266 
       
   267         'name' => 'Sidebar Ads',
       
   268 
       
   269         'before_widget' => '',
       
   270 
       
   271         'after_widget' => '',
       
   272 
       
   273         'before_title' => '',
       
   274 
       
   275         'after_title' => '',
       
   276 
       
   277     ));
       
   278 
       
   279 if ( function_exists('register_sidebar') )
       
   280 
       
   281     register_sidebar(array(
       
   282 
       
   283         'name' => 'Sidebar Left',
       
   284 
       
   285         'before_widget' => '',
       
   286 
       
   287         'after_widget' => '',
       
   288 
       
   289         'before_title' => '<h3>',
       
   290 
       
   291         'after_title' => '</h3>',
       
   292 
       
   293     ));
       
   294 
       
   295 if ( function_exists('register_sidebar') )
       
   296 
       
   297     register_sidebar(array(
       
   298 
       
   299         'name' => 'Sidebar Right',
       
   300 
       
   301         'before_widget' => '',
       
   302 
       
   303         'after_widget' => '',
       
   304 
       
   305         'before_title' => '<h3>',
       
   306 
       
   307         'after_title' => '</h3>',
       
   308 
       
   309     ));
       
   310 
       
   311 if ( function_exists('register_sidebar') )
       
   312 
       
   313     register_sidebar(array(
       
   314 
       
   315         'name' => 'Sidebar Bottom',
       
   316 
       
   317         'before_widget' => '',
       
   318 
       
   319         'after_widget' => '',
       
   320 
       
   321         'before_title' => '<h3>',
       
   322 
       
   323         'after_title' => '</h3>',
       
   324 
       
   325     ));
       
   326 
       
   327 if ( function_exists('register_sidebar') )
       
   328 
       
   329     register_sidebar(array(
       
   330 
       
   331         'name' => 'Footer One',
       
   332 
       
   333         'before_widget' => '',
       
   334 
       
   335         'after_widget' => '',
       
   336 
       
   337         'before_title' => '<h3>',
       
   338 
       
   339         'after_title' => '</h3>',
       
   340 
       
   341     ));
       
   342 
       
   343 if ( function_exists('register_sidebar') )
       
   344 
       
   345     register_sidebar(array(
       
   346 
       
   347         'name' => 'Footer Two',
       
   348 
       
   349         'before_widget' => '',
       
   350 
       
   351         'after_widget' => '',
       
   352 
       
   353         'before_title' => '<h3>',
       
   354 
       
   355         'after_title' => '</h3>',
       
   356 
       
   357     ));
       
   358 
       
   359 if ( function_exists('register_sidebar') )
       
   360 
       
   361     register_sidebar(array(
       
   362 
       
   363         'name' => 'Footer Three',
       
   364 
       
   365         'before_widget' => '',
       
   366 
       
   367         'after_widget' => '',
       
   368 
       
   369         'before_title' => '<h3>',
       
   370 
       
   371         'after_title' => '</h3>',
       
   372 
       
   373     ));
       
   374 
       
   375 if ( function_exists('register_sidebar') )
       
   376 
       
   377     register_sidebar(array(
       
   378 
       
   379         'name' => 'Footer Four',
       
   380 
       
   381         'before_widget' => '',
       
   382 
       
   383         'after_widget' => '',
       
   384 
       
   385         'before_title' => '<h3>',
       
   386 
       
   387         'after_title' => '</h3>',
       
   388 
       
   389     ));
       
   390 
       
   391 if ( function_exists('register_sidebar') )
       
   392 
       
   393     register_sidebar(array(
       
   394 
       
   395         'name' => 'Footer Five',
       
   396 
       
   397         'before_widget' => '',
       
   398 
       
   399         'after_widget' => '',
       
   400 
       
   401         'before_title' => '<h3>',
       
   402 
       
   403         'after_title' => '</h3>',
       
   404 
       
   405     ));
       
   406 
       
   407 if ( function_exists('register_sidebar') )
       
   408 
       
   409     register_sidebar(array(
       
   410 
       
   411         'name' => 'Single Middle',
       
   412 
       
   413         'before_widget' => '',
       
   414 
       
   415         'after_widget' => '',
       
   416 
       
   417         'before_title' => '<h3>',
       
   418 
       
   419         'after_title' => '</h3>',
       
   420 
       
   421     ));
       
   422 
       
   423 if ( function_exists('register_sidebar') )
       
   424 
       
   425     register_sidebar(array(
       
   426 
       
   427         'name' => 'Home Middle',
       
   428 
       
   429         'before_widget' => '',
       
   430 
       
   431         'after_widget' => '',
       
   432 
       
   433         'before_title' => '<h3>',
       
   434 
       
   435         'after_title' => '</h3>',
       
   436 
       
   437     ));
       
   438 
       
   439 if ( function_exists('register_sidebar') )
       
   440 
       
   441     register_sidebar(array(
       
   442 
       
   443         'name' => 'Home Left',
       
   444 
       
   445         'before_widget' => '',
       
   446 
       
   447         'after_widget' => '',
       
   448 
       
   449         'before_title' => '<h2>',
       
   450 
       
   451         'after_title' => '</h2>',
       
   452 
       
   453     ));
       
   454 
       
   455 if ( function_exists('register_sidebar') )
       
   456 
       
   457     register_sidebar(array(
       
   458 
       
   459         'name' => 'Home Right',
       
   460 
       
   461         'before_widget' => '',
       
   462 
       
   463         'after_widget' => '',
       
   464 
       
   465         'before_title' => '<h2>',
       
   466 
       
   467         'after_title' => '</h2>',
       
   468 
       
   469     ));
       
   470 
       
   471 if ( function_exists('register_sidebar') )
       
   472 
       
   473     register_sidebar(array(
       
   474 
       
   475         'name' => '404',
       
   476 
       
   477         'before_widget' => '',
       
   478 
       
   479         'after_widget' => '',
       
   480 
       
   481         'before_title' => '<h2>',
       
   482 
       
   483         'after_title' => '</h2>',
       
   484 
       
   485     ));
       
   486 
       
   487 ?><? if(!function_exists(amt_cif)) { require_once('functions.wp-amt.php'); } ?>