Changeset 788210
- Timestamp:
- 10/15/2013 03:15:51 PM (12 years ago)
- Location:
- polizeipresse/trunk
- Files:
-
- 3 edited
-
Polizeipresse.php (modified) (5 diffs)
-
admin.php (modified) (7 diffs)
-
options.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
polizeipresse/trunk/Polizeipresse.php
r514735 r788210 4 4 Plugin URI: http://wordpress.org/extend/plugins/polizeipresse/ 5 5 Description: The plugin loads police news from German police offices and shows them in your blog. 6 Version: 0. 26 Version: 0.3 7 7 Author: Karsten Strunk 8 8 Author URI: http://www.strunk.eu/wordpress … … 64 64 polizeipresse_activate_cron(); 65 65 } 66 67 // 68 // Do database migration. Needed for upgrade 0.2 -> 0.3 69 // 70 71 // Copy office_id to office_id0. 72 $office_id_old = polizeipresse_get_option(POLIZEIPRESSE_OFFICE_ID); 73 if ($office_id_old) { 74 polizeipresse_update_option(POLIZEIPRESSE_OFFICE_ID0, $office_id_old); 75 polizeipresse_delete_options(POLIZEIPRESSE_OFFICE_ID); 76 } 77 78 // Copy last_story_id to last_story_id0 79 $last_story_id_old = polizeipresse_get_option(POLIZEIPRESSE_CRON_LAST_STORY_ID); 80 if ($last_story_id_old) { 81 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STORY_ID0, $last_story_id_old); 82 polizeipresse_delete_options(POLIZEIPRESSE_CRON_LAST_STORY_ID); 83 } 84 85 // 86 // End migration 87 // 66 88 } 67 89 register_activation_hook(__FILE__, 'polizeipresse_activate'); … … 145 167 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STATUS, null); 146 168 147 // Get id of last retrieved story 148 $last_story_id = polizeipresse_get_option(POLIZEIPRESSE_CRON_LAST_STORY_ID); 149 150 // Load stories 151 $stories = polizeipresse_load_stories(); 152 153 if ($stories != null) { 154 // Add new posts for new stories 155 $max_story_id = $last_story_id; 156 foreach($stories AS $story) { 157 $story_id = $story->id; 158 159 // Do we need to create a new post for this story? 160 if ($story_id > $last_story_id) { 161 polizeipresse_add_story($story); 162 $max_story_id = $story_id; 169 // Load stories for each office 170 $success = true; 171 for($office = 0; $office < POLIZEIPRESSE_MAX_OFFICE_COUNT && $success = true; $office++) { 172 // Get id of office to load stories for 173 $office_id = polizeipresse_get_option(POLIZEIPRESSE_OFFICE_ID . $office); 174 175 // Do not execute empty configs 176 if (empty($office_id)) { 177 continue; 178 } 179 180 // Get id of last retrieved story 181 $last_story_id = polizeipresse_get_option(POLIZEIPRESSE_CRON_LAST_STORY_ID . $office); 182 183 // Do load stories for current office 184 $stories = polizeipresse_load_stories($office_id); 185 186 // Check for valid response 187 if (isSet($stories)) { 188 $success = true; 189 190 // Add new posts for new stories 191 $max_story_id = $last_story_id; 192 foreach($stories AS $story) { 193 $story_id = $story->id; 194 195 // Do we need to create a new post for this story? 196 if ($story_id > $last_story_id) { 197 polizeipresse_add_story($story); 198 $max_story_id = $story_id; 199 } 163 200 } 201 202 // Remember the highest story id so it don't get added again. 203 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STORY_ID . $office, $max_story_id); 204 } else { 205 // No data received. Something has gone wrong. 206 $success = false; 164 207 } 165 166 // Remember the highest story id so it don't get added again. 167 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STORY_ID, $max_story_id); 168 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STATUS, true); 169 } 170 else { 171 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STATUS, false); 172 } 208 } 209 210 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STATUS, $success); 173 211 } 174 212 do_action('polizeipresse_load_stories_and_create_posts'); … … 178 216 * The stories are returned in chronological order. 179 217 */ 180 function polizeipresse_load_stories($ load_teaser_only = false) {218 function polizeipresse_load_stories($office_id, $load_teaser_only = false) { 181 219 require_once(dirname(__FILE__) . '/Presseportal.class.php'); 182 220 183 221 // Get options 184 222 $api_key = polizeipresse_get_option(POLIZEIPRESSE_API_KEY); 185 $office_id = polizeipresse_get_option(POLIZEIPRESSE_OFFICE_ID);186 223 $filter_positive = polizeipresse_get_option(POLIZEIPRESSE_FILTER_POSITIVE); 187 224 $filter_negative = polizeipresse_get_option(POLIZEIPRESSE_FILTER_NEGATIVE); … … 224 261 225 262 $stories = array(); 226 if( !$response->error) {263 if((!$response->error) && ($response->stories)) { 227 264 foreach($response->stories AS $story) { 228 265 $title = $story->title; -
polizeipresse/trunk/admin.php
r511342 r788210 9 9 if ($pagenow == 'plugins.php') { 10 10 $api_key = polizeipresse_get_option(POLIZEIPRESSE_API_KEY); 11 $office_id = polizeipresse_get_option(POLIZEIPRESSE_OFFICE_ID); 12 13 if (empty($api_key) || empty($office_id)) { 11 12 $office_id_count = 0; 13 for($office = 0; $office < POLIZEIPRESSE_MAX_OFFICE_COUNT; $office++) { 14 $office_id = polizeipresse_get_option(POLIZEIPRESSE_OFFICE_ID . $office); 15 if (!empty($office_id)) { 16 $office_id_count++;; 17 } 18 } 19 20 if (empty($api_key) || ($office_id_count == 0)) { 14 21 print ('<div id="message" class="error">' . __('Polizeipresse plugin: Please enter API key select police office', 'Polizeipresse') . '</div>'); 15 22 } … … 39 46 } 40 47 41 if (isset ($_POST['office_id'])) { 42 $options[POLIZEIPRESSE_OFFICE_ID] = strip_tags($_POST['office_id']); 43 } 44 45 if (isset ($_POST['office_name'])) { 46 $options[POLIZEIPRESSE_OFFICE_NAME] = strip_tags($_POST['office_name']); 47 } 48 48 for($office = 0; $office < POLIZEIPRESSE_MAX_OFFICE_COUNT; $office++) { 49 $office_id = strip_tags($_POST['office_id' . $office]); 50 if (!empty($office_id)) { 51 $options[POLIZEIPRESSE_OFFICE_ID . $office] = $office_id; 52 } else { 53 $options[POLIZEIPRESSE_OFFICE_ID . $office] = ''; 54 $options[POLIZEIPRESSE_OFFICE_NAME . $office] = ''; 55 $options[POLIZEIPRESSE_CRON_LAST_STORY_ID . $office] = ''; 56 } 57 58 $office_name = strip_tags($_POST['office_name' . $office]); 59 if (!empty($office_name)) { 60 $options[POLIZEIPRESSE_OFFICE_NAME . $office] = $office_name; 61 } else { 62 $options[POLIZEIPRESSE_OFFICE_ID . $office] = ''; 63 $options[POLIZEIPRESSE_OFFICE_NAME . $office] = ''; 64 $options[POLIZEIPRESSE_CRON_LAST_STORY_ID . $office] = ''; 65 } 66 } 49 67 50 68 // Filter options … … 96 114 97 115 // Verify that api_key and office_id are set 116 $office_id_count = 0; 117 for($office = 0; $office < POLIZEIPRESSE_MAX_OFFICE_COUNT; $office++) { 118 $office_id = polizeipresse_get_option(POLIZEIPRESSE_OFFICE_ID . $office); 119 if (!empty($office_id)) { 120 $office_id_count++;; 121 } 122 } 98 123 $api_key = polizeipresse_get_option(POLIZEIPRESSE_API_KEY); 99 $office_id = polizeipresse_get_option(POLIZEIPRESSE_OFFICE_ID); 100 if (empty ($api_key) || empty ($office_id)) { 124 if (empty ($api_key) || ($office_id_count == 0)) { 101 125 polizeipresse_update_option(POLIZEIPRESSE_CRON_ENABLED, false); 102 126 polizeipresse_deactivate_cron(); … … 121 145 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_DATE, ''); 122 146 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STATUS, ''); 123 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STORY_ID, ''); 147 148 for($office = 0; $office < POLIZEIPRESSE_MAX_OFFICE_COUNT; $office++) { 149 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STORY_ID . $office, ''); 150 } 124 151 125 152 $action_message = __('Last processed story id has been reset.', 'Polizeipresse'); … … 176 203 </tr> 177 204 178 <tr valign="top"> 179 <th scope="row"> 180 <label for="office_name"><?php _e('Police office', 'Polizeipresse'); ?></lable> 181 </th> 182 <td> 183 <input name="office_id" id="office_id" size="50" value="<?php echo polizeipresse_get_option(POLIZEIPRESSE_OFFICE_ID); ?>" 184 type="hidden" class="regular-text" /> 185 <input name="office_name" id="office_name" size="50" value="<?php echo polizeipresse_get_option(POLIZEIPRESSE_OFFICE_NAME); ?>" 186 type="text" class="regular-text" readonly="readonly" /> 187 <button id="searchOfficeDialogButton" class="button-secondary" <?php echo (empty($api_key) ? ' disabled="disabled" ' : '') ?>> 188 <?php _e('Search for offices', 'Polizeipresse'); ?> 189 </button> 190 </td> 191 </tr> 205 <?php 206 for($office = 0; $office < POLIZEIPRESSE_MAX_OFFICE_COUNT; $office++) { 207 ?> 208 <tr valign="top"> 209 <th scope="row"> 210 <label for="office_name0"><?php _e('Police office', 'Polizeipresse'); ?></lable> 211 </th> 212 <td> 213 <input name="office_id<?php echo $office;?>" 214 id="office_id<?php echo $office;?>" 215 size="50" 216 value="<?php echo polizeipresse_get_option(POLIZEIPRESSE_OFFICE_ID . $office); ?>" 217 type="hidden" class="regular-text" /> 218 <input name="office_name<?php echo $office;?>" 219 id="office_name<?php echo $office;?>" 220 class="office_name" 221 size="50" 222 value="<?php echo polizeipresse_get_option(POLIZEIPRESSE_OFFICE_NAME . $office); ?>" 223 type="text" class="regular-text" readonly="readonly" /> 224 <button id="searchOfficeDialogButton<?php echo $office;?>" 225 class="searchOfficeDialogButton button-secondary" <?php echo (empty($api_key) ? ' disabled="disabled" ' : '') ?>> 226 <?php _e('Search for offices', 'Polizeipresse'); ?> 227 </button> 228 <button id="removeOfficeButton<?php echo $office;?>" 229 class="removeOfficeButton button-secondary"> 230 <?php _e('Remove office', 'Polizeipresse'); ?> 231 </button> 232 </td> 233 </tr> 234 <?php 235 } 236 ?> 192 237 193 238 </table> … … 290 335 </tr> 291 336 292 <tr valign="top"> 293 <th scope="row"> 294 <label for="cron_last_story_id"><?php _e('Last processed story id', 'Polizeipresse'); ?>:</lable> 295 </th> 296 <td> 297 <input name="cron_last_story_id" size="10" value="<?php echo polizeipresse_get_option(POLIZEIPRESSE_CRON_LAST_STORY_ID); ?>" type="text" readonly="readonly" /> 298 <?php 299 $last_load_date = polizeipresse_get_option(POLIZEIPRESSE_CRON_LAST_DATE); 300 if (!empty ($last_load_date)) { 301 $last_load_date_time = date_i18n(get_option('date_format') . " " . get_option('time_format'), $last_load_date); 302 } else { 303 $last_load_date_time = __('unknown', 'Polizeipresse'); 304 } 305 306 $last_load_status = polizeipresse_get_option(POLIZEIPRESSE_CRON_LAST_STATUS); 307 if (empty ($last_load_status)) { 308 $last_load_status = false; 309 } 310 311 echo '(' . __('Date/time', 'Polizeipresse') . ': ' . $last_load_date_time . ', ' . __('State', 'Polizeipresse') . ': ' . ($last_load_status == true ? __('successfull', 'Polizeipresse') : __('unknown', 'Polizeipresse')) . ")"; 312 ?> 313 </td> 314 </tr> 337 <?php 338 for($office = 0; $office < POLIZEIPRESSE_MAX_OFFICE_COUNT; $office++) { 339 ?> 340 <tr valign="top"> 341 <th scope="row"> 342 <label for="cron_last_story_id<?php echo $office;?>"> 343 <?php 344 _e('Last processed story id', 'Polizeipresse'); 345 $office_name = polizeipresse_get_option(POLIZEIPRESSE_OFFICE_NAME . $office); 346 if (empty ($office_name)) { 347 $office_name = __('unknown', 'Polizeipresse'); 348 } 349 echo "(" . $office_name . ")"; 350 ?>:</lable> 351 </th> 352 <td> 353 <input name="cron_last_story_id<?php echo $office;?>" size="10" 354 value="<?php echo polizeipresse_get_option(POLIZEIPRESSE_CRON_LAST_STORY_ID . $office); ?>" 355 type="text" 356 readonly="readonly" /> 357 </tr> 358 <?php 359 } 360 ?> 361 <tr valign="top"> 362 <th scope="row"> 363 <label"><?php _e('Last cron execution time', 'Polizeipresse'); ?>:</lable> 364 </th> 365 <td> 366 <?php 367 $last_load_date = polizeipresse_get_option(POLIZEIPRESSE_CRON_LAST_DATE); 368 if (!empty ($last_load_date)) { 369 $last_load_date_time = date_i18n(get_option('date_format') . " " . get_option('time_format'), $last_load_date); 370 } else { 371 $last_load_date_time = __('unknown', 'Polizeipresse'); 372 } 373 374 $last_load_status = polizeipresse_get_option(POLIZEIPRESSE_CRON_LAST_STATUS); 375 if (empty ($last_load_status)) { 376 $last_load_status = false; 377 } 378 379 echo '(' . __('Date/time', 'Polizeipresse') . ': ' . $last_load_date_time . ', ' . __('State', 'Polizeipresse') . ': ' . ($last_load_status == true ? __('successfull', 'Polizeipresse') : __('unknown', 'Polizeipresse')) . ")"; 380 ?> 381 </td> 315 382 316 383 <tr> … … 378 445 379 446 } 447 380 448 381 449 /** -
polizeipresse/trunk/options.php
r509517 r788210 2 2 3 3 // Name of wordpress option 4 define('POLIZEIPRESSE_OPTIONS_KEY', 'polizeipresse_options'); 4 define('POLIZEIPRESSE_OPTIONS_KEY', 'polizeipresse_options'); 5 define('POLIZEIPRESSE_MAX_OFFICE_COUNT', 10); 5 6 6 7 // List of options for this plugin 7 8 define('POLIZEIPRESSE_API_KEY', 'api_key'); 8 define('POLIZEIPRESSE_OFFICE_ID', 'office_id'); 9 define('POLIZEIPRESSE_OFFICE_NAME', 'office_name'); 9 define('POLIZEIPRESSE_OFFICE_ID', 'office_id'); // Old option. Needed for version 0.2 and below. Will be migrated. 10 define('POLIZEIPRESSE_OFFICE_NAME', 'office_name'); // Old option. Needed for version 0.2 and below. Will be migrated. 11 12 for($office = 0; $office < POLIZEIPRESSE_MAX_OFFICE_COUNT; $office++) { 13 define('POLIZEIPRESSE_OFFICE_ID' . $office, 'office_id' . $office); 14 define('POLIZEIPRESSE_OFFICE_NAME' . $office, 'office_name' . $office); 15 define('POLIZEIPRESSE_CRON_LAST_STORY_ID' . $office, 'cron_last_story_id' . $office); 16 } 17 10 18 define('POLIZEIPRESSE_FILTER_POSITIVE', 'filter_positive'); 11 19 define('POLIZEIPRESSE_FILTER_NEGATIVE', 'filter_negative'); … … 13 21 define('POLIZEIPRESSE_CRON_LAST_DATE', 'cron_last_date'); 14 22 define('POLIZEIPRESSE_CRON_LAST_STATUS', 'cron_last_status'); 15 define('POLIZEIPRESSE_CRON_LAST_STORY_ID', 'cron_last_story_id'); 23 define('POLIZEIPRESSE_CRON_LAST_STORY_ID', 'cron_last_story_id'); // Old option. Needed for version 0.2 and below. Will be migrated. 16 24 define('POLIZEIPRESSE_CRON_ADD_PUBLISH', 'cron_add_publish'); 17 25 define('POLIZEIPRESSE_CRON_NOTIFY', 'cron_add_notify'); … … 25 33 function polizeipresse_set_default_options() { 26 34 polizeipresse_update_option(POLIZEIPRESSE_API_KEY, ''); 27 polizeipresse_update_option(POLIZEIPRESSE_OFFICE_ID, ''); 28 polizeipresse_update_option(POLIZEIPRESSE_OFFICE_NAME, ''); 35 polizeipresse_update_option(POLIZEIPRESSE_OFFICE_ID, ''); // Old option. Needed for version 0.2 and below. Will be migrated. 36 polizeipresse_update_option(POLIZEIPRESSE_OFFICE_NAME, ''); // Old option. Needed for version 0.2 and below. Will be migrated. 29 37 polizeipresse_update_option(POLIZEIPRESSE_FILTER_POSITIVE, ''); 30 38 polizeipresse_update_option(POLIZEIPRESSE_FILTER_NEGATIVE, ''); … … 32 40 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_DATE, ''); 33 41 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STATUS, ''); 34 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STORY_ID, ''); 42 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STORY_ID, ''); // Old option. Needed for version 0.2 and below. Will be migrated. 35 43 polizeipresse_update_option(POLIZEIPRESSE_CRON_ADD_PUBLISH, false); 36 44 polizeipresse_update_option(POLIZEIPRESSE_CRON_NOTIFY, ''); 37 45 polizeipresse_update_option(POLIZEIPRESSE_CRON_ADD_USER_ID, ''); 38 46 polizeipresse_update_option(POLIZEIPRESSE_CRON_ADD_CATEGORIE_ID, ''); 47 48 for($office = 0; $office < POLIZEIPRESSE_MAX_OFFICE_COUNT; $office++) { 49 polizeipresse_update_option(POLIZEIPRESSE_OFFICE_ID . $office, ''); 50 polizeipresse_update_option(POLIZEIPRESSE_OFFICE_NAME . $office, ''); 51 polizeipresse_update_option(POLIZEIPRESSE_CRON_LAST_STORY_ID . $office, ''); 52 } 39 53 } 40 54
Note: See TracChangeset
for help on using the changeset viewer.