PluginProbe
FeedWordPress / 2022.0204
FeedWordPress v2022.0204
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / admin-ui.php

admin-ui.php in FeedWordPress 2022.0204, at admin-ui.php

468 lines 17.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * admin-ui.php: This is kind of a junk pile of utility functions mostly created to smooth
4 * out interactions to make things show up, or behave correctly, within the WordPress admin
5 * settings interface. Major chunks of this code that deal with making it easy for FWP,
6 * add-on modules, etc. to create new settings panels have since been hived off into class
7 * FeedWordPressAdminPage. Many of the functions that remain here were created to handle
8 * compatibility across multiple, sometimes very old, versions of WordPress, many of which
9 * are no longer supported anymore. It's likely that some of these functions will be
10 * re-evaluated, re-organized, deprecated, or clipped out in the next few versions.
11 * -cj 2017-10-27
12 */
13
14 $dir = dirname(__FILE__);
15 require_once("${dir}/feedwordpressadminpage.class.php");
16 require_once("${dir}/feedwordpresssettingsui.class.php");
17
18 function fwp_form_class_attr( $className ) {
19
20 if ( is_string($className) ) :
21 if (strlen($className) > 0 ) :
22 $sClassName = sanitize_html_class( $className );
23 print sprintf( 'class="%s"', esc_attr( $sClassName ) );
24 endif;
25 endif;
26 } /* fwp_form_class_attr() */
27
28 function fwp_selected_flag( /* mixed */ $arg = null, $key = null, $flag = "selected" ) {
29
30 $bIsOn = false;
31
32 $theArg = $arg;
33 if (is_array($arg) and !is_null($key)) :
34 if (array_key_exists($key, $arg)) :
35 $theArg = $arg[$key];
36 else :
37 $theArg = false;
38 endif;
39 endif;
40
41 if (is_string($theArg)) :
42 $bIsOn = (strlen($theArg) > 0);
43 else :
44 $bIsOn = !!($theArg);
45 endif;
46
47 if ( $bIsOn ) :
48 print sprintf( '%s="%s"', esc_attr($flag), esc_attr($flag) );
49 endif;
50 } /* fwp_selected_flag() */
51
52 function fwp_checked_flag( /* mixed */ $arg = null, $key = null ) {
53 fwp_selected_flag( $arg, $key, "checked" );
54 } /* fwp_checked_flag() */
55
56 function fwp_update_set_results_message ($delta, $joiner = ';') {
57 $mesg = array();
58 if (isset($delta['new'])) : $mesg[] = ' '.$delta['new'].' new posts were syndicated'; endif;
59 if (isset($delta['updated']) and ($delta['updated'] != 0)) : $mesg[] = ' '.$delta['updated'].' existing posts were updated'; endif;
60 if (isset($delta['stored']) and ($delta['stored'] != 0)) : $mesg[] = ' '.$delta['stored'].' alternate versions of existing posts were stored for reference'; endif;
61
62 if (!is_null($joiner)) :
63 $mesg = implode($joiner, $mesg);
64 endif;
65 return $mesg;
66 } /* function fwp_update_set_results_message () */
67
68 function fwp_authors_single_submit ($link = NULL) {
69 ?>
70 <div class="submitbox" id="submitlink">
71 <div id="previewview">
72 </div>
73 <div class="inside">
74 </div>
75
76 <p class="submit">
77 <input type="submit" name="save" value="<?php _e('Save') ?>" />
78 </p>
79 </div>
80 <?php
81 }
82
83 function fwp_tags_box ($tags, $object, $params = array()) {
84 $params = wp_parse_args($params, array( // Default values
85 'taxonomy' => 'post_tag',
86 'textarea_name' => NULL,
87 'textarea_id' => NULL,
88 'input_id' => NULL,
89 'input_name' => NULL,
90 'id' => NULL,
91 'box_title' => __('Post Tags'),
92 ));
93
94 if (!is_array($tags)) : $tags = array(); endif;
95
96 $tax_name = $params['taxonomy'];
97
98 $oTax = get_taxonomy($params['taxonomy']);
99 $oTaxLabels = get_taxonomy_labels($oTax);
100
101 $disabled = (!current_user_can($oTax->cap->assign_terms) ? 'disabled="disabled"' : '');
102
103 $desc = "<p style=\"font-size:smaller;font-style:bold;margin:0\">Tag $object as...</p>";
104
105 if (is_null($params['textarea_name'])) :
106 $params['textarea_name'] = "tax_input[$tax_name]";
107 endif;
108 if (is_null($params['textarea_id'])) :
109 $params['textarea_id'] = "tax-input-${tax_name}";
110 endif;
111 if (is_null($params['input_id'])) :
112 $params['input_id'] = "new-tag-${tax_name}";
113 endif;
114 if (is_null($params['input_name'])) :
115 $params['input_name'] = "newtag[$tax_name]";
116 endif;
117
118 if (is_null($params['id'])) :
119 $params['id'] = $tax_name;
120 endif;
121
122 print $desc;
123 $helps = __('Separate tags with commas.');
124 $box['title'] = __('Tags');
125 ?>
126 <div class="tagsdiv" id="<?php echo esc_attr( $params['id'] ); ?>">
127 <div class="jaxtag">
128 <div class="nojs-tags hide-if-js">
129 <p><?php echo esc_html( $oTaxLabels->add_or_remove_items ); ?></p>
130 <textarea name="<?php echo esc_attr( $params['textarea_name'] ); ?>" class="the-tags" id="<?php echo esc_attr( $params['textarea_id'] ); ?>"><?php echo esc_attr(implode(",", $tags)); ?></textarea></div>
131
132 <?php if ( current_user_can($oTax->cap->assign_terms) ) :?>
133 <div class="ajaxtag hide-if-no-js">
134 <label class="screen-reader-text" for="<?php echo esc_attr( $params['input_id'] ); ?>"><?php echo esc_html( $params['box_title'] ); ?></label>
135 <div class="taghint"><?php echo esc_html( $oTaxLabels->add_new_item ); ?></div>
136 <p><input type="text" id="<?php print esc_attr( $params['input_id'] ); ?>" name="<?php print esc_attr( $params['input_name'] ); ?>" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
137 <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" tabindex="3" /></p>
138 </div>
139 <p class="howto"><?php echo esc_attr( $oTaxLabels->separate_items_with_commas ); ?></p>
140 <?php endif; ?>
141 </div>
142
143 <div class="tagchecklist"></div>
144 </div>
145 <?php if ( current_user_can($oTax->cap->assign_terms) ) : ?>
146 <p class="hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-<?php echo esc_attr( $tax_name ); ?>"><?php echo esc_html( $oTaxLabels->choose_from_most_used ); ?></a></p>
147 <?php endif;
148
149 }
150
151 function fwp_category_box ($checked, $object, $tags = array(), $params = array()) {
152 global $wp_db_version;
153
154 if (is_string($params)) :
155 $prefix = $params;
156 $taxonomy = 'category';
157 elseif (is_array($params)) :
158 $prefix = (isset($params['prefix']) ? $params['prefix'] : '');
159 $taxonomy = (isset($params['taxonomy']) ? $params['taxonomy'] : 'category');
160 endif;
161
162 $oTax = get_taxonomy($taxonomy);
163 $oTaxLabels = get_taxonomy_labels($oTax);
164
165 if (strlen($prefix) > 0) :
166 $idPrefix = $prefix.'-';
167 $idSuffix = "-".$prefix;
168 $namePrefix = $prefix . '_';
169 else :
170 $idPrefix = 'feedwordpress-';
171 $idSuffix = "-feedwordpress";
172 $namePrefix = 'feedwordpress_';
173 endif;
174
175 $boxDivId = sanitize_html_class( $idPrefix . 'taxonomy-' . $taxonomy );
176 $tabsUlId = sanitize_html_class( $idPrefix . $taxonomy . '-tabs' );
177 $allTabId = sanitize_html_class( $idPrefix . $taxonomy . '-all' );
178 $chkLstId = sanitize_html_class( $idPrefix . $taxonomy . 'checklist' );
179 $addTaxId = sanitize_html_class( $idPrefix . $taxonomy . '-adder' );
180 $addTogId = sanitize_html_class( $idPrefix . $taxonomy . '-add-toggle' );
181 $addCatId = sanitize_html_class( $idPrefix . $taxonomy . '-add' );
182 $newTaxId = sanitize_html_class( $idPrefix . 'new' . $taxonomy );
183 $taxIdAddSubmit = sanitize_html_class( $idPrefix . $taxonomy . '-add-sumbit' );
184 ?>
185 <div id="<?php print esc_attr( $boxDivId ); ?>" class="feedwordpress-category-div">
186 <ul id="<?php print esc_attr( $tabsUlId ); ?>" class="category-tabs">
187 <li class="ui-tabs-selected tabs"><a href="#<?php print esc_attr( $allTabId ); ?>" tabindex="3"><?php _e( 'All posts' ); ?></a>
188 <p style="font-size:smaller;font-style:bold;margin:0">Give <?php print esc_html( $object ); ?> these <?php print esc_html( $oTaxLabels->name ); ?></p>
189 </li>
190 </ul>
191
192 <div id="<?php print esc_attr( $allTabId); ?>" class="tabs-panel">
193 <input type="hidden" value="0" name="tax_input[<?php print esc_attr( $taxonomy ); ?>][]" />
194 <ul id="<?php print esc_attr($chkLstId); ?>" class="list:<?php print esc_attr( $taxonomy ); ?> categorychecklist form-no-clear">
195 <?php fwp_category_checklist(null, false, $checked, $params) ?>
196 </ul>
197 </div>
198
199 <div id="<?php print esc_attr( $addTaxId ); ?>" class="<?php print esc_attr( $taxonomy ); ?>-adder wp-hidden-children">
200 <h4><a id="<?php print esc_attr( $addTogId ); ?>" class="category-add-toggle" href="#<?php print esc_attr( $addCatId ); ?>" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4>
201 <p id="<?php print esc_attr($addCatId); ?>" class="category-add wp-hidden-child">
202 <?php
203 $newcat = 'new' . $taxonomy;
204 ?>
205 <label class="screen-reader-text" for="<?php print esc_attr($newTaxId); ?>"><?php _e('Add New Category'); ?></label>
206 <input
207 id="<?php print esc_attr($newTaxId); ?>"
208 class="<?php print esc_attr( $newcat ); ?> form-required form-input-tip"
209 aria-required="true"
210 tabindex="3"
211 type="text" name="<?php print esc_attr( $newcat ); ?>"
212 value="<?php _e( 'New category name' ); ?>"
213 />
214 <label class="screen-reader-text" for="<?php print esc_attr( $newTaxId ); ?>-parent"><?php _e('Parent Category:'); ?></label>
215 <?php wp_dropdown_categories( array(
216 'taxonomy' => $taxonomy,
217 'hide_empty' => 0,
218 'id' => $newTaxId . '-parent',
219 'class' => $newcat . '-parent',
220 'name' => $newcat . '_parent',
221 'orderby' => 'name',
222 'hierarchical' => 1,
223 'show_option_none' => __('Parent category'),
224 'tab_index' => 3,
225 ) ); ?>
226 <input type="button" id="<?php print esc_attr( $taxIdAddSubmit ); ?>" class="add:<?php print esc_attr( $idPrefix . $taxonomy ); ?>checklist:<?php print esc_attr( $idPrefix . $taxonomy ); ?>-add add-categorychecklist-category-add button category-add-submit" value="<?php _e( 'Add' ); ?>" tabindex="3" />
227 <?php /* wp_nonce_field currently doesn't let us set an id different from name, but we need a non-unique name and a unique id */ ?>
228 <input type="hidden" id="_ajax_nonce<?php print esc_html($idSuffix); ?>" name="_ajax_nonce" value="<?php print wp_create_nonce('add-'.$taxonomy); ?>" />
229 <input type="hidden" id="_ajax_nonce-add-<?php print esc_attr( $taxonomy . $idSuffix ); ?>" name="_ajax_nonce-add-<?php print esc_attr( $taxonomy ); ?>" value="<?php print wp_create_nonce('add-'.$taxonomy); ?>" />
230 <span id="<?php print esc_attr( $idPrefix . $taxonomy ); ?>-ajax-response" class="<?php print esc_attr( $taxonomy ); ?>-ajax-response"></span>
231 </p>
232 </div>
233
234 </div>
235 <?php
236 }
237
238 function update_feeds_mention ($feed) {
239 echo "<li>Updating <cite>".$feed['link/name']."</cite> from &lt;<a href=\""
240 .$feed['link/uri']."\">".$feed['link/uri']."</a>&gt; ...";
241 flush();
242 }
243 function update_feeds_finish ($feed, $added, $dt) {
244 if (is_wp_error($added)) :
245 $mesgs = $added->get_error_messages();
246 foreach ($mesgs as $mesg) :
247 echo "<br/><strong>Feed error:</strong> <code>$mesg</code>";
248 endforeach;
249 echo "</li>\n";
250 else :
251 echo " completed in $dt second".(($dt==1)?'':'s')."</li>\n";
252 endif;
253 flush();
254 }
255
256 function fwp_author_list () {
257 global $wpdb;
258 $ret = array();
259
260 $users = get_users();
261 if (is_array($users)) :
262 foreach ($users as $user) :
263 $id = (int) $user->ID;
264 $ret[$id] = $user->display_name;
265 if (strlen(trim($ret[$id])) == 0) :
266 $ret[$id] = $user->user_login;
267 endif;
268 endforeach;
269 endif;
270 return $ret;
271 }
272
273 function fwp_insert_new_user ($newuser_name) {
274 global $wpdb;
275
276 $ret = null;
277 if (strlen($newuser_name) > 0) :
278 $userdata = array();
279 $userdata['ID'] = NULL;
280 $userdata['user_login'] = apply_filters('pre_user_login', sanitize_user($newuser_name));
281 $userdata['user_nicename'] = apply_filters('pre_user_nicename', sanitize_title($newuser_name));
282 $userdata['display_name'] = $newuser_name;
283 $userdata['user_pass'] = substr(md5(uniqid(microtime())), 0, 6); // just something random to lock it up
284
285 $blahUrl = get_bloginfo('url'); $url = parse_url($blahUrl);
286 $userdata['user_email'] = substr(md5(uniqid(microtime())), 0, 6).'@'.$url['host'];
287
288 $newuser_id = wp_insert_user($userdata);
289 $ret = $newuser_id; // Either a numeric ID or a WP_Error object
290 else :
291 // TODO: Add some error reporting
292 endif;
293 return $ret;
294 } /* fwp_insert_new_user () */
295
296 function fwp_syndication_manage_page_links_table_rows ($links, $page, $visible = 'Y') {
297
298 $fwp_syndicated_sources_columns = array(__('Name'), __('Feed'), __('Updated'));
299
300 $subscribed = ('Y' == strtoupper($visible));
301 if ($subscribed or (count($links) > 0)) :
302 ?>
303 <table class="widefat<?php if (!$subscribed) : ?> unsubscribed<?php endif; ?>">
304 <thead>
305 <tr>
306 <th class="check-column" scope="col"><input type="checkbox" /></th>
307 <?php
308 foreach ($fwp_syndicated_sources_columns as $col) :
309 print "\t<th scope='col'>${col}</th>\n";
310 endforeach;
311 print "</tr>\n";
312 print "</thead>\n";
313 print "\n";
314 print "<tbody>\n";
315
316 $alt_row = true;
317 if (count($links) > 0):
318 foreach ($links as $link):
319 $trClass = array();
320
321 // Prep: Get last updated timestamp
322 $sLink = new SyndicatedLink($link->link_id);
323 if (!is_null($sLink->setting('update/last'))) :
324 $lastUpdated = 'Last checked '. fwp_time_elapsed($sLink->setting('update/last'));
325 else :
326 $lastUpdated = __('None yet');
327 endif;
328
329 // Prep: get last error timestamp, if any
330 $fileSizeLines = array();
331 $feed_type = $sLink->get_feed_type();
332 if (is_null($sLink->setting('update/error'))) :
333 $errorsSince = '';
334 if (!is_null($sLink->setting('link/item count'))) :
335 $N = $sLink->setting('link/item count');
336 $fileSizeLines[] = sprintf((($N==1) ? __('%d item') : __('%d items')), $N) . ", " . $feed_type;
337 endif;
338
339 if (!is_null($sLink->setting('link/filesize'))) :
340 $fileSizeLines[] = size_format($sLink->setting('link/filesize')). ' total';
341 endif;
342 else :
343 $trClass[] = 'feed-error';
344
345 $theError = unserialize($sLink->setting('update/error'));
346
347 $errorsSince = "<div class=\"returning-errors\">"
348 ."<p><strong>Returning errors</strong> since "
349 .fwp_time_elapsed($theError['since'])
350 ."</p>"
351 ."<p>Most recent ("
352 .fwp_time_elapsed($theError['ts'])
353 ."):<br/><code>"
354 .implode("</code><br/><code>", $theError['object']->get_error_messages())
355 ."</code></p>"
356 ."</div>\n";
357 endif;
358
359 $nextUpdate = "<div style='max-width: 30.0em; font-size: 0.9em;'><div style='font-style:italic;'>";
360
361 $ttl = $sLink->setting('update/ttl');
362 if (is_numeric($ttl)) :
363 $next = $sLink->setting('update/last') + $sLink->setting('update/fudge') + ((int) $ttl * 60);
364 if ('automatically'==$sLink->setting('update/timed')) :
365 if ($next < time()) :
366 $nextUpdate .= 'Ready and waiting to be updated since ';
367 else :
368 $nextUpdate .= 'Scheduled for next update ';
369 endif;
370 $nextUpdate .= fwp_time_elapsed($next);
371 if (FEEDWORDPRESS_DEBUG) : $nextUpdate .= " [".(($next-time())/60)." minutes]"; endif;
372 else :
373 $lastUpdated .= " &middot; Next ";
374 if ($next < time()) :
375 $lastUpdated .= 'ASAP';
376 elseif ($next - time() < 60) :
377 $lastUpdated .= fwp_time_elapsed($next);
378 elseif ($next - time() < 60*60*24) :
379 $lastUpdated .= gmdate('g:ia', $next + (get_option('gmt_offset') * 3600));
380 else :
381 $lastUpdated .= gmdate('F j', $next + (get_option('gmt_offset') * 3600));
382 endif;
383
384 $nextUpdate .= "Scheduled to be checked for updates every ".$ttl." minute".(($ttl!=1)?"s":"")."</div><div style='size:0.9em; margin-top: 0.5em'> This update schedule was requested by the feed provider";
385 if ($sLink->setting('update/xml')) :
386 $nextUpdate .= " using a standard <code style=\"font-size: inherit; padding: 0; background: transparent\">&lt;".$sLink->setting('update/xml')."&gt;</code> element";
387 endif;
388 $nextUpdate .= ".";
389 endif;
390 else:
391 $nextUpdate .= "Scheduled for update as soon as possible";
392 endif;
393 $nextUpdate .= "</div></div>";
394
395 $fileSize = '';
396 if (count($fileSizeLines) > 0) :
397 $fileSize = '<div>'.implode(" / ", $fileSizeLines)."</div>";
398 endif;
399
400 unset($sLink);
401
402 $alt_row = !$alt_row;
403
404 if ($alt_row) :
405 $trClass[] = 'alternate';
406 endif;
407 ?>
408 <tr<?php echo ((count($trClass) > 0) ? ' class="'.implode(" ", $trClass).'"':''); ?>>
409 <th class="check-column" scope="row"><input type="checkbox" name="link_ids[]" value="<?php echo esc_attr( $link->link_id ); ?>" /></th>
410 <?php
411 $caption = (
412 (strlen($link->link_rss) > 0)
413 ? __('Switch Feed')
414 : $caption=__('Find Feed')
415 );
416 ?>
417 <td>
418 <strong><a href="<?php print esc_url( $page->admin_page_href('feeds-page.php', array(), $link) ); ?>"><?php print esc_html($link->link_name); ?></a></strong>
419 <div class="row-actions"><?php if ($subscribed) :
420 $page->display_feed_settings_page_links(array(
421 'before' => '<div><strong>Settings &gt;</strong> ',
422 'after' => '</div>',
423 'subscription' => $link,
424 ));
425 endif; ?>
426
427 <div><strong>Actions &gt;</strong>
428 <?php if ($subscribed) : ?>
429 <a href="<?php print esc_url( $page->admin_page_href('syndication.php', array('action' => 'feedfinder'), $link) ); ?>"><?php echo esc_html( $caption ); ?></a>
430 <?php else : ?>
431 <a href="<?php print esc_url( $page->admin_page_href('syndication.php', array('action' => FWP_RESUB_CHECKED), $link) ); ?>"><?php _e('Re-subscribe'); ?></a>
432 <?php endif; ?>
433 | <a href="<?php print esc_url( $page->admin_page_href( 'syndication.php', array('action' => 'Unsubscribe'), $link ) ); ?>"><?php _e( ( $subscribed ? 'Unsubscribe' : 'Delete permanently' ) ); ?></a>
434 | <a href="<?php print esc_url( $link->link_url ); ?>"><?php _e('View')?></a></div>
435 </div>
436 </td>
437 <?php if (strlen($link->link_rss) > 0): ?>
438 <td><div><a href="<?php echo esc_html($link->link_rss); ?>"><?php echo esc_html(feedwordpress_display_url($link->link_rss, 32)); ?></a></div></td>
439 <?php else: ?>
440 <td class="feed-missing"><p><strong>no feed assigned</strong></p></td>
441 <?php endif; ?>
442
443 <td><div style="float: right; padding-left: 10px">
444 <input type="submit" class="button" name="update_uri[<?php print esc_html($link->link_rss); ?>]" value="<?php _e('Update Now'); ?>" />
445 </div>
446 <?php
447 print $lastUpdated;
448 print $fileSize;
449 print $errorsSince;
450 print $nextUpdate;
451 ?>
452 </td>
453 </tr>
454 <?php
455 endforeach;
456 else :
457 ?>
458 <tr><td colspan="4"><p>There are no websites currently listed for syndication.</p></td></tr>
459 <?php
460 endif;
461 ?>
462 </tbody>
463 </table>
464 <?php
465 endif;
466 } /* function fwp_syndication_manage_page_links_table_rows () */
467
468