| @@ -1,46 +1,34 @@ | ||
| 1 | 1 | <?php |
| 2 | -function fwp_linkedit_single_submit ($status = NULL) { | |
| 3 | - if (fwp_test_wp_version(FWP_SCHEMA_25, FWP_SCHEMA_27)) : | |
| 4 | -?> | |
| 5 | -<div class="submitbox" id="submitlink"> | |
| 6 | -<div id="previewview"></div> | |
| 7 | -<div class="inside"></div> | |
| 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 | + */ | |
| 8 | 13 | |
| 9 | -<p class="submit"> | |
| 10 | -<input type="submit" name="submit" value="<?php _e('Save') ?>" /> | |
| 11 | -</p> | |
| 12 | -</div> | |
| 13 | -<?php | |
| 14 | - endif; | |
| 15 | -} | |
| 14 | +$dir = dirname(__FILE__); | |
| 15 | +require_once("${dir}/feedwordpressadminpage.class.php"); | |
| 16 | +require_once("${dir}/feedwordpresssettingsui.class.php"); | |
| 16 | 17 | |
| 17 | -function fwp_linkedit_periodic_submit ($caption = NULL) { | |
| 18 | - if (!fwp_test_wp_version(FWP_SCHEMA_25)) : | |
| 19 | - if (is_null($caption)) : $caption = __('Save Changes »'); endif; | |
| 20 | -?> | |
| 21 | -<p class="submit"> | |
| 22 | -<input type="submit" name="submit" value="<?php print $caption; ?>" /> | |
| 23 | -</p> | |
| 24 | -<?php | |
| 25 | - endif; | |
| 26 | -} | |
| 18 | +function fwp_update_set_results_message ($delta, $joiner = ';') { | |
| 19 | + $mesg = array(); | |
| 20 | + if (isset($delta['new'])) : $mesg[] = ' '.$delta['new'].' new posts were syndicated'; endif; | |
| 21 | + if (isset($delta['updated']) and ($delta['updated'] != 0)) : $mesg[] = ' '.$delta['updated'].' existing posts were updated'; endif; | |
| 22 | + if (isset($delta['stored']) and ($delta['stored'] != 0)) : $mesg[] = ' '.$delta['stored'].' alternate versions of existing posts were stored for reference'; endif; | |
| 27 | 23 | |
| 28 | -function fwp_linkedit_single_submit_closer ($caption = NULL) { | |
| 29 | - if (fwp_test_wp_version(FWP_SCHEMA_27)) : | |
| 30 | - if (is_null($caption)) : $caption = __('Save Changes'); endif; | |
| 31 | -?> | |
| 32 | -<p class="submit"> | |
| 33 | -<input class="button-primary" type="submit" name="submit" value="<?php print $caption; ?>" /> | |
| 34 | -</p> | |
| 35 | -<?php | |
| 24 | + if (!is_null($joiner)) : | |
| 25 | + $mesg = implode($joiner, $mesg); | |
| 36 | 26 | endif; |
| 37 | -} | |
| 27 | + return $mesg; | |
| 28 | +} /* function fwp_update_set_results_message () */ | |
| 38 | 29 | |
| 39 | 30 | function fwp_authors_single_submit ($link = NULL) { |
| 40 | - global $wp_db_version; | |
| 41 | - | |
| 42 | - if (fwp_test_wp_version(FWP_SCHEMA_25)) : | |
| 43 | 31 | ?> |
| 44 | 32 | <div class="submitbox" id="submitlink"> |
| 45 | 33 | <div id="previewview"> |
| 46 | 34 | </div> |
| @@ -51,106 +39,155 @@ | ||
| 51 | 39 | <input type="submit" name="save" value="<?php _e('Save') ?>" /> |
| 52 | 40 | </p> |
| 53 | 41 | </div> |
| 54 | 42 | <?php |
| 43 | +} | |
| 44 | + | |
| 45 | +function fwp_tags_box ($tags, $object, $params = array()) { | |
| 46 | + $params = wp_parse_args($params, array( // Default values | |
| 47 | + 'taxonomy' => 'post_tag', | |
| 48 | + 'textarea_name' => NULL, | |
| 49 | + 'textarea_id' => NULL, | |
| 50 | + 'input_id' => NULL, | |
| 51 | + 'input_name' => NULL, | |
| 52 | + 'id' => NULL, | |
| 53 | + 'box_title' => __('Post Tags'), | |
| 54 | + )); | |
| 55 | + | |
| 56 | + if (!is_array($tags)) : $tags = array(); endif; | |
| 57 | + | |
| 58 | + $tax_name = $params['taxonomy']; | |
| 59 | + | |
| 60 | + $oTax = get_taxonomy($params['taxonomy']); | |
| 61 | + $oTaxLabels = get_taxonomy_labels($oTax); | |
| 62 | + | |
| 63 | + $disabled = (!current_user_can($oTax->cap->assign_terms) ? 'disabled="disabled"' : ''); | |
| 64 | + | |
| 65 | + $desc = "<p style=\"font-size:smaller;font-style:bold;margin:0\">Tag $object as...</p>"; | |
| 66 | + | |
| 67 | + if (is_null($params['textarea_name'])) : | |
| 68 | + $params['textarea_name'] = "tax_input[$tax_name]"; | |
| 55 | 69 | endif; |
| 70 | + if (is_null($params['textarea_id'])) : | |
| 71 | + $params['textarea_id'] = "tax-input-${tax_name}"; | |
| 72 | + endif; | |
| 73 | + if (is_null($params['input_id'])) : | |
| 74 | + $params['input_id'] = "new-tag-${tax_name}"; | |
| 75 | + endif; | |
| 76 | + if (is_null($params['input_name'])) : | |
| 77 | + $params['input_name'] = "newtag[$tax_name]"; | |
| 78 | + endif; | |
| 79 | + | |
| 80 | + if (is_null($params['id'])) : | |
| 81 | + $params['id'] = $tax_name; | |
| 82 | + endif; | |
| 83 | + | |
| 84 | + print $desc; | |
| 85 | + $helps = __('Separate tags with commas.'); | |
| 86 | + $box['title'] = __('Tags'); | |
| 87 | + ?> | |
| 88 | +<div class="tagsdiv" id="<?php echo $params['id']; ?>"> | |
| 89 | + <div class="jaxtag"> | |
| 90 | + <div class="nojs-tags hide-if-js"> | |
| 91 | + <p><?php echo $oTaxLabels->add_or_remove_items; ?></p> | |
| 92 | + <textarea name="<?php echo $params['textarea_name']; ?>" class="the-tags" id="<?php echo $params['textarea_id']; ?>"><?php echo esc_attr(implode(",", $tags)); ?></textarea></div> | |
| 93 | + | |
| 94 | + <?php if ( current_user_can($oTax->cap->assign_terms) ) :?> | |
| 95 | + <div class="ajaxtag hide-if-no-js"> | |
| 96 | + <label class="screen-reader-text" for="<?php echo $params['input_id']; ?>"><?php echo $params['box_title']; ?></label> | |
| 97 | + <div class="taghint"><?php echo $oTaxLabels->add_new_item; ?></div> | |
| 98 | + <p><input type="text" id="<?php print $params['input_id']; ?>" name="<?php print $params['input_name']; ?>" class="newtag form-input-tip" size="16" autocomplete="off" value="" /> | |
| 99 | + <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" tabindex="3" /></p> | |
| 100 | + </div> | |
| 101 | + <p class="howto"><?php echo esc_attr( $oTaxLabels->separate_items_with_commas ); ?></p> | |
| 102 | + <?php endif; ?> | |
| 103 | + </div> | |
| 104 | + | |
| 105 | + <div class="tagchecklist"></div> | |
| 106 | +</div> | |
| 107 | +<?php if ( current_user_can($oTax->cap->assign_terms) ) : ?> | |
| 108 | +<p class="hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-<?php echo $tax_name; ?>"><?php echo $oTaxLabels->choose_from_most_used; ?></a></p> | |
| 109 | +<?php endif; | |
| 110 | + | |
| 56 | 111 | } |
| 57 | 112 | |
| 58 | -function fwp_option_box_opener ($legend, $id, $class = "stuffbox") { | |
| 113 | +function fwp_category_box ($checked, $object, $tags = array(), $params = array()) { | |
| 59 | 114 | global $wp_db_version; |
| 60 | - if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) : | |
| 61 | -?> | |
| 62 | -<div id="<?php print $id; ?>" class="<?php print $class; ?>"> | |
| 63 | -<h3><?php print htmlspecialchars($legend); ?></h3> | |
| 64 | -<div class="inside"> | |
| 65 | -<?php | |
| 66 | - else : | |
| 67 | -?> | |
| 68 | -<fieldset class="options"><legend><?php print htmlspecialchars($legend); ?></legend> | |
| 69 | -<?php | |
| 115 | + | |
| 116 | + if (is_string($params)) : | |
| 117 | + $prefix = $params; | |
| 118 | + $taxonomy = 'category'; | |
| 119 | + elseif (is_array($params)) : | |
| 120 | + $prefix = (isset($params['prefix']) ? $params['prefix'] : ''); | |
| 121 | + $taxonomy = (isset($params['taxonomy']) ? $params['taxonomy'] : 'category'); | |
| 70 | 122 | endif; |
| 71 | -} | |
| 123 | + | |
| 124 | + $oTax = get_taxonomy($taxonomy); | |
| 125 | + $oTaxLabels = get_taxonomy_labels($oTax); | |
| 72 | 126 | |
| 73 | -function fwp_option_box_closer () { | |
| 74 | - global $wp_db_version; | |
| 75 | - if (isset($wp_db_version) and $wp_db_version >= FWP_SCHEMA_25) : | |
| 76 | -?> | |
| 77 | - </div> <!-- class="inside" --> | |
| 78 | - </div> <!-- class="stuffbox" --> | |
| 79 | -<?php | |
| 127 | + if (strlen($prefix) > 0) : | |
| 128 | + $idPrefix = $prefix.'-'; | |
| 129 | + $idSuffix = "-".$prefix; | |
| 130 | + $namePrefix = $prefix . '_'; | |
| 80 | 131 | else : |
| 81 | -?> | |
| 82 | -</fieldset> | |
| 83 | -<?php | |
| 132 | + $idPrefix = 'feedwordpress-'; | |
| 133 | + $idSuffix = "-feedwordpress"; | |
| 134 | + $namePrefix = 'feedwordpress_'; | |
| 84 | 135 | endif; |
| 85 | -} | |
| 86 | 136 | |
| 87 | -function fwp_tags_box ($tags) { | |
| 88 | - if (!is_array($tags)) : $tags = array(); endif; | |
| 89 | 137 | ?> |
| 90 | -<div id="tagsdiv" class="postbox"> | |
| 91 | - <h3><?php _e('Tags') ?></h3> | |
| 92 | - <p style="font-size:smaller;font-style:bold;margin:0">Place <?php print $object; ?> under...</p> | |
| 93 | - <div class="inside"> | |
| 94 | - <p id="jaxtag"><input type="text" name="tags_input" class="tags-input" id="tags-input" size="40" tabindex="3" value="<?php echo implode(",", $tags); ?>" /></p> | |
| 95 | - <div id="tagchecklist"></div> | |
| 96 | - </div> | |
| 138 | +<div id="<?php print $idPrefix; ?>taxonomy-<?php print $taxonomy; ?>" class="feedwordpress-category-div"> | |
| 139 | + <ul id="<?php print $idPrefix; ?><?php print $taxonomy; ?>-tabs" class="category-tabs"> | |
| 140 | + <li class="ui-tabs-selected tabs"><a href="#<?php print $idPrefix; ?><?php print $taxonomy; ?>-all" tabindex="3"><?php _e( 'All posts' ); ?></a> | |
| 141 | + <p style="font-size:smaller;font-style:bold;margin:0">Give <?php print $object; ?> these <?php print $oTaxLabels->name; ?></p> | |
| 142 | + </li> | |
| 143 | + </ul> | |
| 144 | + | |
| 145 | +<div id="<?php print $idPrefix; ?><?php print $taxonomy; ?>-all" class="tabs-panel"> | |
| 146 | + <input type="hidden" value="0" name="tax_input[<?php print $taxonomy; ?>][]" /> | |
| 147 | + <ul id="<?php print $idPrefix; ?><?php print $taxonomy; ?>checklist" class="list:<?php print $taxonomy; ?> categorychecklist form-no-clear"> | |
| 148 | + <?php fwp_category_checklist(NULL, false, $checked, $params) ?> | |
| 149 | + </ul> | |
| 97 | 150 | </div> |
| 98 | -<?php | |
| 99 | -} | |
| 100 | 151 | |
| 101 | -function fwp_category_box ($checked, $object, $tags = array()) { | |
| 102 | - global $wp_db_version; | |
| 152 | +<div id="<?php print $idPrefix; ?><?php print $taxonomy; ?>-adder" class="<?php print $taxonomy; ?>-adder wp-hidden-children"> | |
| 153 | + <h4><a id="<?php print $idPrefix; ?><?php print $taxonomy; ?>-add-toggle" class="category-add-toggle" href="#<?php print $idPrefix; ?><?php print $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4> | |
| 154 | + <p id="<?php print $idPrefix; ?><?php print $taxonomy; ?>-add" class="category-add wp-hidden-child"> | |
| 155 | + <?php | |
| 156 | + $newcat = 'new'.$taxonomy; | |
| 103 | 157 | |
| 104 | - if (fwp_test_wp_version(FWP_SCHEMA_25)) : // WordPress 2.5.x | |
| 105 | -?> | |
| 106 | -<div id="category-adder" class="wp-hidden-children"> | |
| 107 | - <h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4> | |
| 108 | - <p id="category-add" class="wp-hidden-child"> | |
| 109 | - <input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php _e( 'New category name' ); ?>" tabindex="3" /> | |
| 110 | - <?php wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category'), 'tab_index' => 3 ) ); ?> | |
| 111 | - <input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php _e( 'Add' ); ?>" tabindex="3" /> | |
| 112 | - <?php wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?> | |
| 113 | - <span id="category-ajax-response"></span> | |
| 158 | + ?> | |
| 159 | + <label class="screen-reader-text" for="<?php print $idPrefix; ?>new<?php print $taxonomy; ?>"><?php _e('Add New Category'); ?></label> | |
| 160 | + <input | |
| 161 | + id="<?php print $idPrefix; ?>new<?php print $taxonomy; ?>" | |
| 162 | + class="new<?php print $taxonomy; ?> form-required form-input-tip" | |
| 163 | + aria-required="true" | |
| 164 | + tabindex="3" | |
| 165 | + type="text" name="<?php print $newcat; ?>" | |
| 166 | + value="<?php _e( 'New category name' ); ?>" | |
| 167 | + /> | |
| 168 | + <label class="screen-reader-text" for="<?php print $idPrefix; ?>new<?php print $taxonomy; ?>-parent"><?php _e('Parent Category:'); ?></label> | |
| 169 | + <?php wp_dropdown_categories( array( | |
| 170 | + 'taxonomy' => $taxonomy, | |
| 171 | + 'hide_empty' => 0, | |
| 172 | + 'id' => $idPrefix.'new'.$taxonomy.'-parent', | |
| 173 | + 'class' => 'new'.$taxonomy.'-parent', | |
| 174 | + 'name' => $newcat.'_parent', | |
| 175 | + 'orderby' => 'name', | |
| 176 | + 'hierarchical' => 1, | |
| 177 | + 'show_option_none' => __('Parent category'), | |
| 178 | + 'tab_index' => 3, | |
| 179 | + ) ); ?> | |
| 180 | + <input type="button" id="<?php print $idPrefix; ?><?php print $taxonomy; ?>-add-sumbit" class="add:<?php print $idPrefix; ?><?php print $taxonomy; ?>checklist:<?php print $idPrefix.$taxonomy; ?>-add add-categorychecklist-category-add button category-add-submit" value="<?php _e( 'Add' ); ?>" tabindex="3" /> | |
| 181 | + <?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 */ ?> | |
| 182 | + <input type="hidden" id="_ajax_nonce<?php print esc_html($idSuffix); ?>" name="_ajax_nonce" value="<?php print wp_create_nonce('add-'.$taxonomy); ?>" /> | |
| 183 | + <input type="hidden" id="_ajax_nonce-add-<?php print $taxonomy; ?><?php print esc_html($idSuffix); ?>" name="_ajax_nonce-add-<?php print $taxonomy; ?>" value="<?php print wp_create_nonce('add-'.$taxonomy); ?>" /> | |
| 184 | + <span id="<?php print $idPrefix; ?><?php print $taxonomy; ?>-ajax-response" class="<?php print $taxonomy; ?>-ajax-response"></span> | |
| 114 | 185 | </p> |
| 115 | 186 | </div> |
| 116 | 187 | |
| 117 | -<ul id="category-tabs"> | |
| 118 | - <li class="ui-tabs-selected"><a href="#categories-all" tabindex="3"><?php _e( 'All posts' ); ?></a> | |
| 119 | - <p style="font-size:smaller;font-style:bold;margin:0">Give <?php print $object; ?> these categories</p> | |
| 120 | -</li> | |
| 121 | -</ul> | |
| 122 | - | |
| 123 | -<div id="categories-all" class="ui-tabs-panel"> | |
| 124 | - <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> | |
| 125 | - <?php fwp_category_checklist(NULL, false, $checked) ?> | |
| 126 | - </ul> | |
| 127 | 188 | </div> |
| 128 | 189 | <?php |
| 129 | - elseif (fwp_test_wp_version(FWP_SCHEMA_20)) : // WordPress 2.x | |
| 130 | -?> | |
| 131 | - <div id="moremeta"> | |
| 132 | - <div id="grabit" class="dbx-group"> | |
| 133 | - <fieldset id="categorydiv" class="dbx-box"> | |
| 134 | - <h3 class="dbx-handle"><?php _e('Categories') ?></h3> | |
| 135 | - <div class="dbx-content"> | |
| 136 | - <p style="font-size:smaller;font-style:bold;margin:0">Place <?php print $object; ?> under...</p> | |
| 137 | - <p id="jaxcat"></p> | |
| 138 | - <div id="categorychecklist"><?php fwp_category_checklist(NULL, false, $checked); ?></div> | |
| 139 | - </div> | |
| 140 | - </fieldset> | |
| 141 | - </div> | |
| 142 | - </div> | |
| 143 | -<?php | |
| 144 | - else : // WordPress 1.5 | |
| 145 | -?> | |
| 146 | - <fieldset style="width: 60%;"> | |
| 147 | - <legend><?php _e('Categories') ?></legend> | |
| 148 | - <p style="font-size:smaller;font-style:bold;margin:0">Place <?php print $object; ?> under...</p> | |
| 149 | - <div style="height: 10em; overflow: scroll;"><?php fwp_category_checklist(NULL, false, $checked); ?></div> | |
| 150 | - </fieldset> | |
| 151 | -<?php | |
| 152 | - endif; | |
| 153 | 190 | } |
| 154 | 191 | |
| 155 | 192 | function update_feeds_mention ($feed) { |
| 156 | 193 | echo "<li>Updating <cite>".$feed['link/name']."</cite> from <<a href=\"" |
| @@ -157,9 +194,18 @@ | ||
| 157 | 194 | .$feed['link/uri']."\">".$feed['link/uri']."</a>> ..."; |
| 158 | 195 | flush(); |
| 159 | 196 | } |
| 160 | 197 | function update_feeds_finish ($feed, $added, $dt) { |
| 161 | - echo " completed in $dt second".(($dt==1)?'':'s')."</li>\n"; | |
| 198 | + if (is_wp_error($added)) : | |
| 199 | + $mesgs = $added->get_error_messages(); | |
| 200 | + foreach ($mesgs as $mesg) : | |
| 201 | + echo "<br/><strong>Feed error:</strong> <code>$mesg</code>"; | |
| 202 | + endforeach; | |
| 203 | + echo "</li>\n"; | |
| 204 | + else : | |
| 205 | + echo " completed in $dt second".(($dt==1)?'':'s')."</li>\n"; | |
| 206 | + endif; | |
| 207 | + flush(); | |
| 162 | 208 | } |
| 163 | 209 | |
| 164 | 210 | function fwp_author_list () { |
| 165 | 211 | global $wpdb; |
| @@ -164,20 +210,13 @@ | ||
| 164 | 210 | function fwp_author_list () { |
| 165 | 211 | global $wpdb; |
| 166 | 212 | $ret = array(); |
| 167 | 213 | |
| 168 | - // display_name introduced in WP 2.0 | |
| 169 | - if (fwp_test_wp_version(FWP_SCHEMA_20)) : | |
| 170 | - $name_column = 'display_name'; | |
| 171 | - else : | |
| 172 | - $name_column = 'user_nickname'; | |
| 173 | - endif; | |
| 174 | - | |
| 175 | - $users = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY {$name_column}"); | |
| 214 | + $users = get_users(); | |
| 176 | 215 | if (is_array($users)) : |
| 177 | 216 | foreach ($users as $user) : |
| 178 | 217 | $id = (int) $user->ID; |
| 179 | - $ret[$id] = $user->{$name_column}; | |
| 218 | + $ret[$id] = $user->display_name; | |
| 180 | 219 | if (strlen(trim($ret[$id])) == 0) : |
| 181 | 220 | $ret[$id] = $user->user_login; |
| 182 | 221 | endif; |
| 183 | 222 | endforeach; |
| @@ -184,72 +223,8 @@ | ||
| 184 | 223 | endif; |
| 185 | 224 | return $ret; |
| 186 | 225 | } |
| 187 | 226 | |
| 188 | -class FeedWordPressSettingsUI { | |
| 189 | - function instead_of_posts_box ($link_id = null) { | |
| 190 | - fwp_option_box_opener('Syndicated Posts, Comments & Pings', 'syndicatedpostsdiv', 'postbox'); | |
| 191 | - if (!is_null($link_id)) : | |
| 192 | - $from_this_feed = 'from this feed'; | |
| 193 | - $by_default = ''; | |
| 194 | - $id_param = "&link_id=".$link_id; | |
| 195 | - else : | |
| 196 | - $from_this_feed = 'from syndicated feeds'; | |
| 197 | - $by_default = " by default"; | |
| 198 | - $id_param = ""; | |
| 199 | - endif; | |
| 200 | -?> | |
| 201 | -<p>Use the <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/posts-page.php<?php print $id_param; ?>"><?php _e('Posts'); ?></a> | |
| 202 | -settings page to set up how new posts <?php print $from_this_feed; ?> will be published<?php $by_default; ?>, whether they will accept | |
| 203 | -comments and pings, any custom fields that should be set on each post, etc.</p> | |
| 204 | -<?php | |
| 205 | - fwp_option_box_closer(); | |
| 206 | - } /* FeedWordPressSettingsUI::instead_of_posts_box () */ | |
| 207 | - | |
| 208 | - function instead_of_authors_box ($link_id = null) { | |
| 209 | - if (!is_null($link_id)) : | |
| 210 | - $from_this_feed = 'from this feed'; | |
| 211 | - $by_default = ''; | |
| 212 | - $id_param = "&link_id=".$link_id; | |
| 213 | - else : | |
| 214 | - $from_this_feed = 'from syndicated feeds'; | |
| 215 | - $by_default = " by default"; | |
| 216 | - $id_param = ""; | |
| 217 | - endif; | |
| 218 | - | |
| 219 | - fwp_option_box_opener('Syndicated Authors', 'authordiv', 'postbox') | |
| 220 | -?> | |
| 221 | -<p>Use the <a | |
| 222 | -href="admin.php?page=<?php print $GLOBALS['fwp_path'] | |
| 223 | -?>/authors-page.php<?php print $id_param; ?>"><?php _e('Authors'); | |
| 224 | -?></a> settings page to set up how new posts | |
| 225 | -<?php print $from_this_feed; ?> will be assigned to | |
| 226 | -authors.</p> | |
| 227 | -<?php | |
| 228 | - fwp_option_box_closer(); | |
| 229 | - } /* FeedWordPressSettingsUI::instead_of_authors_box () */ | |
| 230 | - | |
| 231 | - function instead_of_categories_box ($link_id = null) { | |
| 232 | - if (!is_null($link_id)) : | |
| 233 | - $from_this_feed = 'from this feed'; | |
| 234 | - $by_default = ''; | |
| 235 | - $id_param = "&link_id=".$link_id; | |
| 236 | - else : | |
| 237 | - $from_this_feed = 'from syndicated feeds'; | |
| 238 | - $by_default = " by default"; | |
| 239 | - $id_param = ""; | |
| 240 | - endif; | |
| 241 | - | |
| 242 | - fwp_option_box_opener(__('Categories & Tags'), 'categorydiv', 'postbox'); | |
| 243 | -?> | |
| 244 | -<p>Use the <a href="admin.php?page=<?php print $GLOBALS['fwp_path'] ?>/categories-page.php<?php print $id_param; ?>"><?php _e('Categories & Tags'); ?></a> | |
| 245 | -settings page to set up how new posts <?php print $from_this_feed; ?> are assigned categories or tags<?php print $by_default; ?>.</p> | |
| 246 | -<?php | |
| 247 | - fwp_option_box_closer(); | |
| 248 | - } /* FeedWordPressSettingsUI::instead_of_categories_box () */ | |
| 249 | - | |
| 250 | -} /* class FeedWordPressSettingsUI */ | |
| 251 | - | |
| 252 | 227 | function fwp_insert_new_user ($newuser_name) { |
| 253 | 228 | global $wpdb; |
| 254 | 229 | |
| 255 | 230 | $ret = null; |
| @@ -255,25 +230,192 @@ | ||
| 255 | 230 | $ret = null; |
| 256 | 231 | if (strlen($newuser_name) > 0) : |
| 257 | 232 | $userdata = array(); |
| 258 | 233 | $userdata['ID'] = NULL; |
| 259 | - | |
| 260 | - $userdata['user_login'] = sanitize_user($newuser_name); | |
| 261 | - $userdata['user_login'] = apply_filters('pre_user_login', $userdata['user_login']); | |
| 262 | - | |
| 263 | - $userdata['user_nicename'] = sanitize_title($newuser_name); | |
| 264 | - $userdata['user_nicename'] = apply_filters('pre_user_nicename', $userdata['user_nicename']); | |
| 265 | - | |
| 266 | - $userdata['display_name'] = $wpdb->escape($newuser_name); | |
| 234 | + $userdata['user_login'] = apply_filters('pre_user_login', sanitize_user($newuser_name)); | |
| 235 | + $userdata['user_nicename'] = apply_filters('pre_user_nicename', sanitize_title($newuser_name)); | |
| 236 | + $userdata['display_name'] = $newuser_name; | |
| 237 | + $userdata['user_pass'] = substr(md5(uniqid(microtime())), 0, 6); // just something random to lock it up | |
| 267 | 238 | |
| 239 | + $blahUrl = get_bloginfo('url'); $url = parse_url($blahUrl); | |
| 240 | + $userdata['user_email'] = substr(md5(uniqid(microtime())), 0, 6).'@'.$url['host']; | |
| 241 | + | |
| 268 | 242 | $newuser_id = wp_insert_user($userdata); |
| 269 | - if (is_numeric($newuser_id)) : | |
| 270 | - $ret = $newuser_id; | |
| 271 | - else : | |
| 272 | - // TODO: Add some error detection and reporting | |
| 273 | - endif; | |
| 243 | + $ret = $newuser_id; // Either a numeric ID or a WP_Error object | |
| 274 | 244 | else : |
| 275 | 245 | // TODO: Add some error reporting |
| 276 | 246 | endif; |
| 277 | 247 | return $ret; |
| 278 | 248 | } /* fwp_insert_new_user () */ |
| 249 | + | |
| 250 | +function fwp_syndication_manage_page_links_table_rows ($links, $page, $visible = 'Y') { | |
| 251 | + | |
| 252 | + $fwp_syndicated_sources_columns = array(__('Name'), __('Feed'), __('Updated')); | |
| 253 | + | |
| 254 | + $subscribed = ('Y' == strtoupper($visible)); | |
| 255 | + if ($subscribed or (count($links) > 0)) : | |
| 256 | + ?> | |
| 257 | + <table class="widefat<?php if (!$subscribed) : ?> unsubscribed<?php endif; ?>"> | |
| 258 | + <thead> | |
| 259 | + <tr> | |
| 260 | + <th class="check-column" scope="col"><input type="checkbox" /></th> | |
| 261 | +<?php | |
| 262 | + foreach ($fwp_syndicated_sources_columns as $col) : | |
| 263 | + print "\t<th scope='col'>${col}</th>\n"; | |
| 264 | + endforeach; | |
| 265 | + print "</tr>\n"; | |
| 266 | + print "</thead>\n"; | |
| 267 | + print "\n"; | |
| 268 | + print "<tbody>\n"; | |
| 269 | + | |
| 270 | + $alt_row = true; | |
| 271 | + if (count($links) > 0): | |
| 272 | + foreach ($links as $link): | |
| 273 | + $trClass = array(); | |
| 274 | + | |
| 275 | + // Prep: Get last updated timestamp | |
| 276 | + $sLink = new SyndicatedLink($link->link_id); | |
| 277 | + if (!is_null($sLink->setting('update/last'))) : | |
| 278 | + $lastUpdated = 'Last checked '. fwp_time_elapsed($sLink->setting('update/last')); | |
| 279 | + else : | |
| 280 | + $lastUpdated = __('None yet'); | |
| 281 | + endif; | |
| 282 | + | |
| 283 | + // Prep: get last error timestamp, if any | |
| 284 | + $fileSizeLines = array(); | |
| 285 | + $feed_type = $sLink->get_feed_type(); | |
| 286 | + if (is_null($sLink->setting('update/error'))) : | |
| 287 | + $errorsSince = ''; | |
| 288 | + if (!is_null($sLink->setting('link/item count'))) : | |
| 289 | + $N = $sLink->setting('link/item count'); | |
| 290 | + $fileSizeLines[] = sprintf((($N==1) ? __('%d item') : __('%d items')), $N) . ", " . $feed_type; | |
| 291 | + endif; | |
| 292 | + | |
| 293 | + if (!is_null($sLink->setting('link/filesize'))) : | |
| 294 | + $fileSizeLines[] = size_format($sLink->setting('link/filesize')). ' total'; | |
| 295 | + endif; | |
| 296 | + else : | |
| 297 | + $trClass[] = 'feed-error'; | |
| 298 | + | |
| 299 | + $theError = unserialize($sLink->setting('update/error')); | |
| 300 | + | |
| 301 | + $errorsSince = "<div class=\"returning-errors\">" | |
| 302 | + ."<p><strong>Returning errors</strong> since " | |
| 303 | + .fwp_time_elapsed($theError['since']) | |
| 304 | + ."</p>" | |
| 305 | + ."<p>Most recent (" | |
| 306 | + .fwp_time_elapsed($theError['ts']) | |
| 307 | + ."):<br/><code>" | |
| 308 | + .implode("</code><br/><code>", $theError['object']->get_error_messages()) | |
| 309 | + ."</code></p>" | |
| 310 | + ."</div>\n"; | |
| 311 | + endif; | |
| 312 | + | |
| 313 | + $nextUpdate = "<div style='max-width: 30.0em; font-size: 0.9em;'><div style='font-style:italic;'>"; | |
| 314 | + | |
| 315 | + $ttl = $sLink->setting('update/ttl'); | |
| 316 | + if (is_numeric($ttl)) : | |
| 317 | + $next = $sLink->setting('update/last') + $sLink->setting('update/fudge') + ((int) $ttl * 60); | |
| 318 | + if ('automatically'==$sLink->setting('update/timed')) : | |
| 319 | + if ($next < time()) : | |
| 320 | + $nextUpdate .= 'Ready and waiting to be updated since '; | |
| 321 | + else : | |
| 322 | + $nextUpdate .= 'Scheduled for next update '; | |
| 323 | + endif; | |
| 324 | + $nextUpdate .= fwp_time_elapsed($next); | |
| 325 | + if (FEEDWORDPRESS_DEBUG) : $nextUpdate .= " [".(($next-time())/60)." minutes]"; endif; | |
| 326 | + else : | |
| 327 | + $lastUpdated .= " · Next "; | |
| 328 | + if ($next < time()) : | |
| 329 | + $lastUpdated .= 'ASAP'; | |
| 330 | + elseif ($next - time() < 60) : | |
| 331 | + $lastUpdated .= fwp_time_elapsed($next); | |
| 332 | + elseif ($next - time() < 60*60*24) : | |
| 333 | + $lastUpdated .= gmdate('g:ia', $next + (get_option('gmt_offset') * 3600)); | |
| 334 | + else : | |
| 335 | + $lastUpdated .= gmdate('F j', $next + (get_option('gmt_offset') * 3600)); | |
| 336 | + endif; | |
| 337 | + | |
| 338 | + $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"; | |
| 339 | + if ($sLink->setting('update/xml')) : | |
| 340 | + $nextUpdate .= " using a standard <code style=\"font-size: inherit; padding: 0; background: transparent\"><".$sLink->setting('update/xml')."></code> element"; | |
| 341 | + endif; | |
| 342 | + $nextUpdate .= "."; | |
| 343 | + endif; | |
| 344 | + else: | |
| 345 | + $nextUpdate .= "Scheduled for update as soon as possible"; | |
| 346 | + endif; | |
| 347 | + $nextUpdate .= "</div></div>"; | |
| 348 | + | |
| 349 | + $fileSize = ''; | |
| 350 | + if (count($fileSizeLines) > 0) : | |
| 351 | + $fileSize = '<div>'.implode(" / ", $fileSizeLines)."</div>"; | |
| 352 | + endif; | |
| 353 | + | |
| 354 | + unset($sLink); | |
| 355 | + | |
| 356 | + $alt_row = !$alt_row; | |
| 357 | + | |
| 358 | + if ($alt_row) : | |
| 359 | + $trClass[] = 'alternate'; | |
| 360 | + endif; | |
| 361 | + ?> | |
| 362 | + <tr<?php echo ((count($trClass) > 0) ? ' class="'.implode(" ", $trClass).'"':''); ?>> | |
| 363 | + <th class="check-column" scope="row"><input type="checkbox" name="link_ids[]" value="<?php echo $link->link_id; ?>" /></th> | |
| 364 | + <?php | |
| 365 | + $caption = ( | |
| 366 | + (strlen($link->link_rss) > 0) | |
| 367 | + ? __('Switch Feed') | |
| 368 | + : $caption=__('Find Feed') | |
| 369 | + ); | |
| 370 | + ?> | |
| 371 | + <td> | |
| 372 | + <strong><a href="<?php print $page->admin_page_href('feeds-page.php', array(), $link); ?>"><?php print esc_html($link->link_name); ?></a></strong> | |
| 373 | + <div class="row-actions"><?php if ($subscribed) : | |
| 374 | + $page->display_feed_settings_page_links(array( | |
| 375 | + 'before' => '<div><strong>Settings ></strong> ', | |
| 376 | + 'after' => '</div>', | |
| 377 | + 'subscription' => $link, | |
| 378 | + )); | |
| 379 | + endif; ?> | |
| 380 | + | |
| 381 | + <div><strong>Actions ></strong> | |
| 382 | + <?php if ($subscribed) : ?> | |
| 383 | + <a href="<?php print $page->admin_page_href('syndication.php', array('action' => 'feedfinder'), $link); ?>"><?php echo $caption; ?></a> | |
| 384 | + <?php else : ?> | |
| 385 | + <a href="<?php print $page->admin_page_href('syndication.php', array('action' => FWP_RESUB_CHECKED), $link); ?>"><?php _e('Re-subscribe'); ?></a> | |
| 386 | + <?php endif; ?> | |
| 387 | + | <a href="<?php print $page->admin_page_href('syndication.php', array('action' => 'Unsubscribe'), $link); ?>"><?php _e(($subscribed ? 'Unsubscribe' : 'Delete permanently')); ?></a> | |
| 388 | + | <a href="<?php print esc_html($link->link_url); ?>"><?php _e('View')?></a></div> | |
| 389 | + </div> | |
| 390 | + </td> | |
| 391 | + <?php if (strlen($link->link_rss) > 0): ?> | |
| 392 | + <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> | |
| 393 | + <?php else: ?> | |
| 394 | + <td class="feed-missing"><p><strong>no feed assigned</strong></p></td> | |
| 395 | + <?php endif; ?> | |
| 396 | + | |
| 397 | + <td><div style="float: right; padding-left: 10px"> | |
| 398 | + <input type="submit" class="button" name="update_uri[<?php print esc_html($link->link_rss); ?>]" value="<?php _e('Update Now'); ?>" /> | |
| 399 | + </div> | |
| 400 | + <?php | |
| 401 | + print $lastUpdated; | |
| 402 | + print $fileSize; | |
| 403 | + print $errorsSince; | |
| 404 | + print $nextUpdate; | |
| 405 | + ?> | |
| 406 | + </td> | |
| 407 | + </tr> | |
| 408 | + <?php | |
| 409 | + endforeach; | |
| 410 | + else : | |
| 411 | +?> | |
| 412 | +<tr><td colspan="4"><p>There are no websites currently listed for syndication.</p></td></tr> | |
| 413 | +<?php | |
| 414 | + endif; | |
| 415 | +?> | |
| 416 | +</tbody> | |
| 417 | +</table> | |
| 418 | + <?php | |
| 419 | + endif; | |
| 420 | +} /* function fwp_syndication_manage_page_links_table_rows () */ | |
| 279 | 421 | |