0) { $message = 20; } else { $acronym_count = Acronym_Manager::import_acronyms( file_get_contents($_FILES['acronym_file_name']['tmp_name']) ); $message = 21; wp_redirect("$parent_file&message=$message&acronym_count=$acronym_count"); break; } wp_redirect("$parent_file&message=$message"); break; case 'export_acronyms': $message = 8; wp_redirect(Acronym_Manager::export_acronyms()); break; case 'search': $s = '&s=' . urlencode($_GET['search']); $p = isset($_GET['p']) ? '&p=' . $_GET['p'] : ''; $n = isset($_GET['n']) && 15 != $_GET['n'] ? '&n=' . $_GET['n'] : ''; wp_redirect("$parent_file$s$p$n"); break; } } } function admin_tabs($current) { $tabs = array( 'manage' => __('Manage Collection'), 'import' => __('Import'), 'export' => __('Export') ); $links = array(); foreach( $tabs as $tab => $name ) { if ( $tab == $current ) { $links[] = "$name"; } else { $links[] = "$name"; } } echo '

'; foreach ( $links as $link ) echo $link; echo '

'; } // Function to generate options page function admin_page() { global $pagenow; if ( isset ( $_GET['tab'] ) ) $current_tab = $_GET['tab']; else $current_tab = 'manage'; //display the tab menu, setting the active tab to $current_tab Acronym_Manager::admin_tabs($current_tab); //display any messages reporting success/failure of functions if ( isset ($_GET['message']) ) Acronym_Manager::check_messages($_GET['message']); ?>



Import Acronym File










'; $header = file_get_contents(get_template_directory() . '/header.php'); if (strpos($header, $doctype) !== false) { update_option('acronym_html5', 1); } else { update_option('acronym_html5', 0); } } /* string acronym_replace ( string $text, array $acronyms ) * * Replaces known acronyms in $text with appropriate acronyms. * Note: acronym replacement is case-sensitive. */ function acronym_replace($text) { $acronyms = get_option('acronym_acronyms'); $html5 = get_option('acronym_html5'); $text = " $text "; if ($html5 == 1) { foreach ($acronyms as $acronym => $fulltext) { $text = preg_replace("|(?!<[^<>]*?)(?]*?>)|msU", "$acronym", $text); } } else { foreach ($acronyms as $acronym => $fulltext) { $text = preg_replace("|(?!<[^<>]*?)(?]*?>)|msU", "$acronym", $text); } } $text = trim($text); return $text; } /* string show_acronym_list ( string $s, int $n, int $p ) * * Displays the list of acronyms, filtered by search term $s and showing page # $p based on $n per page */ function show_acronym_list($s, $n, $p = '1') { $domain = Acronym_Manager::get_textdomain(); // Sort the acronyms appropriately $acronyms = get_option('acronym_acronyms'); uksort($acronyms, "strnatcasecmp"); ?> $fulltext) { if (( '' == $s ) || ( ( false !== strpos(strtolower($acronym), strtolower($s)) ) || ( false !== strpos(strtolower($fulltext), strtolower($s)) ) )) { if (0 == $n || (++$index >= $index_start && $index <= $index_end )) { ?>
') ) { return true;}return false;"/> ') ) { return true;}return false;"/>
add_query_arg('p', '%#%'), 'format' => '', 'total' => $t, 'current' => $p, 'add_args' => $n )); if (0 < $n && $page_links) { echo '
'; $range = $n * ( $p - 1 ) + 1 . '-' . $n * $p; $total = Acronym_Manager::count_acronyms($s); echo ''; _e("Displaying $range of $total"); echo ''; echo "$page_links
"; } ?>

'; $action = 'edit-acronym'; $nonce_action = 'edit_acronym'; } else { $heading = __('Add Acronym', $domain); $submit_text = __('Add Acronym', $domain); $form = '
'; $action = 'add-acronym'; $nonce_action = 'add_acronym'; } ?>

/>

' . __('Cancel') . '' ?>

$fulltext){ unset($acronyms[$acronym]); } update_option('acronym_acronyms', $acronyms); } /* int count_acronyms ( string $s ) * * Get the number of acronyms based on the search term if provided */ function count_acronyms($s = '') { $acronyms = get_option('acronym_acronyms'); if (empty($s)) return count($acronyms); else { $index = 0; foreach ($acronyms as $acronym => $fulltext) { if (false !== strpos(strtolower($acronym), strtolower($s)) || ( false !== strpos(strtolower($fulltext), strtolower($s)) )) { $index++; } } return $index; } } /* string get_parent_url () * */ function get_parent_url() { return $_GET['page']; } /* export_acronym () * * create a temporary file, load with acronym output, and return URL to file */ function export_acronyms() { $export_file_contents = ""; $domain = Acronym_Manager::get_textdomain(); // Sort the acronyms appropriately $acronyms = get_option('acronym_acronyms'); uksort($acronyms, "strnatcasecmp"); foreach ($acronyms as $acronym => $fulltext) { $export_file_contents .= $acronym . "==" . $fulltext . ";;"; } return $export_file_contents; } /* import_acronym () * * parse acronym file of format ARC==definition;;\n */ function import_acronyms($acronym_import_string) { $a_acronyms = explode( ';;', $acronym_import_string); $acronym_count = 0; foreach ($a_acronyms as $key => $current_acronym) { list($acronym, $fulltext) = explode( '==', $current_acronym); $acronym = Acronym_Manager::str_trim($acronym); $acronym_added = Acronym_Manager::update($acronym, $fulltext); if ($acronym_added) $acronym_count++; } return $acronym_count; } /* str_trim ($to_trim) * * functions like PERL trim, removes white space around string */ function str_trim($to_trim) { $to_trim = str_replace(' ', '', $to_trim); $to_trim = str_replace('\n', '', $to_trim); return $to_trim; } /* print_glossary_list () * * create a table, load with acronym output, and return html code */ function print_glossary_list() { $domain = Acronym_Manager::get_textdomain(); // Sort the acronyms appropriately $acronyms = get_option('acronym_acronyms'); uksort($acronyms, "strnatcasecmp"); ?> $fulltext) { ?>