| | 185 | /** |
| | 186 | * Adds the Management page to WordPress |
| | 187 | * |
| | 188 | * @return void |
| | 189 | **/ |
| | 190 | function add_pages () |
| | 191 | { |
| | 192 | // Add the Manage page |
| | 193 | add_management_page(__('Manage Acronyms'), __('Acronyms'), "manage_options", __FILE__, array( 'Acronyms', 'manage_acronyms') ); |
| | 194 | } |
| | 195 | |
| | 196 | /** |
| | 197 | * Manage Acronyms page |
| | 198 | * |
| | 199 | * @return void |
| | 200 | **/ |
| | 201 | function manage_acronyms () |
| | 202 | { |
| | 203 | $title = __('Acronyms'); |
| | 204 | $parent_file = 'edit.php?page=acronyms.php'; |
| | 205 | $acronyms = get_option( 'acronym_acronyms' ); |
| | 206 | |
| | 207 | wp_reset_vars(array('action', 'acronym')); |
| | 208 | |
| | 209 | if ( isset($_POST['deleteit']) ) |
| | 210 | $action = 'delete'; |
| | 211 | else $action = $_POST['action']; |
| | 212 | |
| | 213 | switch ($action) { |
| | 214 | case 'add': |
| | 215 | check_admin_referer('add-acronym'); |
| | 216 | $acronym = $_POST['acronym']; |
| | 217 | $fulltext = $_POST['fulltext']; |
| | 218 | Acronyms::update ( $acronym, $fulltext ); |
| | 219 | $message = 1; |
| | 220 | break; |
| | 221 | case 'edit': |
| | 222 | $acronym = $_POST['acronym']; |
| | 223 | $fulltext = $_POST['fulltext']; |
| | 224 | check_admin_referer('edit-acronym_' . $acronym); |
| | 225 | Acronyms::update ( $acronym, $fulltext ); |
| | 226 | $message = 3; |
| | 227 | break; |
| | 228 | case 'delete': |
| | 229 | check_admin_referer('bulk-acronyms'); |
| | 230 | |
| | 231 | if ( !current_user_can('manage_categories') ) |
| | 232 | wp_die(__('Cheatin’ uh?')); |
| | 233 | |
| | 234 | $acronyms = $_POST['delete_acronyms']; |
| | 235 | foreach( (array) $acronyms as $acronym ) { |
| | 236 | Acronyms::delete ( $acronym ); |
| | 237 | } |
| | 238 | |
| | 239 | if ( 1 < ( count( $acronyms ) ) ) |
| | 240 | $message = 6; |
| | 241 | else $message = 2; |
| | 242 | |
| | 243 | break; |
| | 244 | } |
| | 245 | |
| | 246 | $messages[1] = __('Acronym added.'); |
| | 247 | $messages[2] = __('Acronym deleted.'); |
| | 248 | $messages[3] = __('Acronym updated.'); |
| | 249 | $messages[4] = __('Acronym not added.'); |
| | 250 | $messages[5] = __('Acronym not updated.'); |
| | 251 | $messages[6] = __('Acronyms deleted.'); |
| | 252 | |
| | 253 | if ( isset( $message ) ) { ?> |
| | 254 | <div id="message" class="updated fade"><p><?php echo $messages[$message] ?></p></div> |
| | 255 | <?php } |
| | 256 | if ( 'edit' == $_GET['action'] && !empty( $_GET['acronym'] ) ) { |
| | 257 | Acronyms::add_acronym_form ( urldecode( $_GET['acronym'] ), urldecode( $_GET['fulltext'] ) ); |
| | 258 | echo '<br class="clear"/><br class="clear"/>'; |
| | 259 | } |
| | 260 | ?> |
| | 261 | <div class="wrap"> |
| | 262 | <form id="posts-filter" action="" method="post"> |
| | 263 | <input type="hidden" name="page" value="acronyms.php" /> |
| | 264 | <h2><?php _e('Manage Acronyms') ?> (<a href="#addacronym"><?php _e('add new')?></a>)</h2> |
| | 265 | <p id="post-search"> |
| | 266 | <input type="text" id="post-search-input" name="s" value="<?php echo attribute_escape(stripslashes($_POST['s'])); ?>" /> |
| | 267 | <input type="submit" value="<?php _e( 'Search acronyms' ); ?>" class="button" /> |
| | 268 | </p> |
| | 269 | <br class="clear" /> |
| | 270 | |
| | 271 | <div class="tablenav"> |
| | 272 | <div class="alignleft"> |
| | 273 | <input type="submit" value="<?php _e('Delete') ?>" name="deleteit" class="button-secondary delete" /> |
| | 274 | <?php wp_nonce_field('bulk-acronyms'); ?> |
| | 275 | </div> |
| | 276 | <br class="clear" /> |
| | 277 | </div> |
| | 278 | <br class="clear" /> |
| | 279 | <?php Acronyms::show_acronym_list($_POST['s']) ?> |
| | 280 | </form> |
| | 281 | </div><?php |
| | 282 | if ( 'edit' != $_GET['action'] || empty( $_GET['acronym'] ) ) { |
| | 283 | echo '<br class="clear"/><br class="clear"/>'; |
| | 284 | Acronyms::add_acronym_form ( '', '' ); |
| | 285 | } |
| | 286 | } |
| | 287 | |
| 234 | | /* void manage_acronyms () |
| 235 | | * |
| 236 | | * Display the admin interface to add, edit and delete acronyms |
| 237 | | */ |
| 238 | | function manage_acronyms () |
| 239 | | { |
| 240 | | ?> |
| 241 | | <div class="wrap acronyms"> |
| 242 | | <h2><?php _e('Manage acronyms') ?></h2> |
| 243 | | <?php |
| 244 | | $action = $_POST['action']; |
| 245 | | switch ( $action ) { |
| 246 | | case 'delete': |
| 247 | | $acronym = $_POST['acronym_acronym']; |
| 248 | | if ( '' != $acronym) |
| 249 | | { |
| 250 | | //Check for confirmation |
| 251 | | if ( isset( $_POST['confirm'] ) && 'true' == $_POST['confirm']) |
| 252 | | { |
| 253 | | Acronyms::delete( $acronym ); |
| 254 | | ?> |
| 255 | | <div id="message" class="updated fade"> |
| 256 | | <p>The acronym for "<?php echo $acronym ?>" has been deleted.</p> |
| 257 | | </div> |
| 258 | | <?php |
| 259 | | Acronyms::show_acronym_list(); |
| 260 | | ?> |
| 261 | | </div> |
| 262 | | <?php |
| 263 | | } |
| 264 | | else |
| 265 | | { |
| 266 | | ?> |
| 267 | | <div id="acronym_form"> |
| 268 | | <h3><?php _e('Delete acronym') ?></h3> |
| 269 | | <p><?php _e('Are you sure you want to delete this acronym?') ?></p> |
| 270 | | <form method="post" action=""> |
| 271 | | <input type="hidden" name="action" value="delete" /> |
| 272 | | <input type="hidden" name="acronym_acronym" value="<?php echo $acronym ?>" /> |
| 273 | | <input type="hidden" name="confirm" value="true" /> |
| 274 | | <input type="submit" value="<?php _e('Delete') ?>" /> |
| 275 | | </form> |
| 276 | | <form method="post" action=""> |
| 277 | | <input type="hidden" name="action" value="delete" /> |
| 278 | | <input type="hidden" name="acronym_acronym" value="<?php echo $acronym ?>" /> |
| 279 | | <input type="hidden" name="confirm" value="false" /> |
| 280 | | <input type="submit" value="<?php _e('Cancel') ?>" /> |
| 281 | | </form> |
| 282 | | </div> |
| 283 | | <?php |
| 284 | | } |
| 285 | | } |
| 286 | | break; |
| 287 | | case 'update': |
| 288 | | $acronym = $_POST['acronym_acronym']; |
| 289 | | $fulltext = $_POST['acronym_fulltext']; |
| 290 | | if ( '' != $acronym && '' != $fulltext ) |
| 291 | | { |
| 292 | | if ( str_word_count( $acronym ) > 1 ) |
| 293 | | { |
| 294 | | ?> |
| 295 | | <div id="message" class="error fade"> |
| 296 | | <p>The acronym must be a single word.</p> |
| 297 | | </div> |
| 298 | | <?php |
| 299 | | } |
| 300 | | else |
| 301 | | { |
| 302 | | Acronyms::update( $acronym, $fulltext ); |
| 303 | | ?> |
| 304 | | <div id="message" class="updated fade"> |
| 305 | | <p>The acronym "<?php echo $acronym ?>" has been added or edited.</p> |
| 306 | | </div> |
| 307 | | <?php |
| 308 | | } |
| 309 | | } |
| 310 | | else |
| 311 | | { |
| 312 | | ?> |
| 313 | | <div id="message" class="error fade"> |
| 314 | | <p>Please fill in both the acronym and full text fields.</p> |
| 315 | | </div> |
| 316 | | <?php |
| 317 | | } |
| 318 | | Acronyms::show_acronym_list(); |
| 319 | | ?> |
| 320 | | </div> |
| 321 | | <?php |
| 322 | | break; |
| 323 | | default: |
| 324 | | Acronyms::show_acronym_list(); |
| 325 | | ?> |
| 326 | | </div> |
| 327 | | <?php |
| 328 | | } |
| 329 | | } |
| 330 | | |
| 331 | | function show_acronym_list () |
| 332 | | { |
| 333 | | ?> |
| 334 | | <form method="post" action=""> |
| 335 | | <div id="acronym_form"> |
| 336 | | <h3><?php _e('Add/Edit acronym') ?></h3> |
| 337 | | <label for="acronym_acronym"><?php _e('Acronym') ?>: </label><input type="text" id="acronym_acronym" name="acronym_acronym" /> |
| 338 | | <label for="acronym_fulltext"><?php _e('Full text')?>: </label><input type="text" id="acronym_fulltext" name="acronym_fulltext" /> |
| 339 | | <input type="hidden" name="action" value="update" /> |
| 340 | | <input type="submit" value="<?php _e('Add/Edit acronym') ?>" /> |
| 341 | | </div> |
| 342 | | </form> |
| 343 | | |
| 344 | | <h3><?php _e('Acronym List') ?></h3> |
| 345 | | <table cellpadding="0" cellspacing="0"> |
| | 312 | function show_acronym_list ( $s ) |
| | 313 | { |
| | 314 | ?> |
| | 315 | <table class="widefat"> |
| | 316 | <thead> |
| | 317 | <tr> |
| | 318 | <th scope="col" class="check-column"><input type="checkbox" onclick="checkAll(document.getElementById('posts-filter'));" /></th> |
| | 319 | <th scope="col"><?php _e('Acronym') ?></th> |
| | 320 | <th scope="col"><?php _e('Full') ?></th> |
| | 321 | </tr> |
| | 322 | </thead> |
| | 323 | <tbody id="the-list" class="list:acronym"> |
| | 346 | |
| | 347 | /* void add_acronym_form ( string $acronym, string $fulltext ) |
| | 348 | * |
| | 349 | * Display the form for adding or editing acronyms |
| | 350 | */ |
| | 351 | function add_acronym_form ( $acronym, $fulltext ) |
| | 352 | { |
| | 353 | if ( ! empty($acronym) ) { |
| | 354 | $heading = __('Edit Acronym'); |
| | 355 | $submit_text = __('Edit Acronym'); |
| | 356 | $form = '<form name="editacronym" id="editacronym" method="post" action="" class="validate">'; |
| | 357 | $action = 'edit'; |
| | 358 | $nonce_action = 'edit-acronym_' . $acronym; |
| | 359 | } else { |
| | 360 | $heading = __('Add Acronym'); |
| | 361 | $submit_text = __('Add Acronym'); |
| | 362 | $form = '<form name="addacronym" id="addacronym" method="post" action="" class="add:the-list: validate">'; |
| | 363 | $action = 'add'; |
| | 364 | $nonce_action = 'add-acronym'; |
| | 365 | } |
| | 366 | ?> |
| | 367 | <div class="wrap"> |
| | 368 | <h2><?php echo $heading ?></h2> |
| | 369 | <div id="ajax-response"></div> |
| | 370 | <?php echo $form ?> |
| | 371 | <input type="hidden" name="page" value="acronyms.php" /> |
| | 372 | <input type="hidden" name="action" value="<?php echo $action ?>" /> |
| | 373 | <?php wp_original_referer_field(true, 'previous'); wp_nonce_field($nonce_action); ?> |
| | 374 | <table class="form-table"> |
| | 375 | <tr class="form-field form-required"> |
| | 376 | <td><label for="acronym"><?php _e('Acronym') ?></label>: <input name="acronym" id="acronym" type="text" value="<?php echo attribute_escape($acronym); ?>" size="20" <?php if ( 'edit' == $action ) echo 'disabled="disabled"'; ?>/></td> |
| | 377 | <td><label for="fulltext"><?php _e('Full') ?></label>: <input name="fulltext" id="fulltext" type="text" value="<?php echo attribute_escape($fulltext); ?>" size="80" /></td> |
| | 378 | </tr> |
| | 379 | </table> |
| | 380 | <p class="submit"><input type="submit" class="button" name="submit" value="<?php echo $submit_text ?>" /></p> |
| | 381 | </form> |
| | 382 | </div> |
| | 383 | <?php } |