1
|
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(']]>', ']]>', $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 |
} |
2
|
244 |
|