mp-wp_add-footnot... 1 <?php
mp-wp_add-footnot... 2 /*
mp-wp_add-footnot... 3 Plugin Name: WP-Footnotes
mp-wp_add-footnot... 4 Plugin URI: http://www.elvery.net/drzax/more-things/wordpress-footnotes-plugin/
mp-wp_add-footnot... 5 Version: 4.2
mp-wp_add-footnot... 6 Description: Allows a user to easily add footnotes to a post.
mp-wp_add-footnot... 7 Author: Simon Elvery
mp-wp_add-footnot... 8 Author URI: http://www.elvery.net/drzax/
mp-wp_add-footnot... 9 */
mp-wp_add-footnot... 10
mp-wp_add-footnot... 11 /*
mp-wp_add-footnot... 12 * This file is part of WP-Footnotes a plugin for Word Press
mp-wp_add-footnot... 13 * Copyright (C) 2007 Simon Elvery
mp-wp_add-footnot... 14 *
mp-wp_add-footnot... 15 * This program is free software; you can redistribute it and/or
mp-wp_add-footnot... 16 * modify it under the terms of the GNU General Public License
mp-wp_add-footnot... 17 * as published by the Free Software Foundation; either version 2
mp-wp_add-footnot... 18 * of the License, or (at your option) any later version.
mp-wp_add-footnot... 19 *
mp-wp_add-footnot... 20 * This program is distributed in the hope that it will be useful,
mp-wp_add-footnot... 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mp-wp_add-footnot... 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
mp-wp_add-footnot... 23 * GNU General Public License for more details.
mp-wp_add-footnot... 24 *
mp-wp_add-footnot... 25 * You should have received a copy of the GNU General Public License
mp-wp_add-footnot... 26 * along with this program; if not, write to the Free Software
mp-wp_add-footnot... 27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
mp-wp_add-footnot... 28 */
mp-wp_add-footnot... 29
mp-wp_add-footnot... 30 // Some important constants
mp-wp_add-footnot... 31 define('WP_FOOTNOTES_OPEN', " (("); //You can change this if you really have to, but I wouldn't recommend it.
mp-wp_add-footnot... 32 define('WP_FOOTNOTES_CLOSE', "))"); //Same with this one.
mp-wp_add-footnot... 33 define('WP_FOOTNOTES_VERSION', '4.2');
mp-wp_add-footnot... 34
mp-wp_add-footnot... 35 // Instantiate the class
mp-wp_add-footnot... 36 $swas_wp_footnotes = new swas_wp_footnotes();
mp-wp_add-footnot... 37
mp-wp_add-footnot... 38 // Encapsulate in a class
mp-wp_add-footnot... 39 class swas_wp_footnotes {
mp-wp_add-footnot... 40 var $current_options;
mp-wp_add-footnot... 41 var $default_options;
mp-wp_add-footnot... 42
mp-wp_add-footnot... 43 /**
mp-wp_add-footnot... 44 * Constructor.
mp-wp_add-footnot... 45 */
mp-wp_add-footnot... 46 function swas_wp_footnotes() {
mp-wp_add-footnot... 47 // Define the implemented option styles
mp-wp_add-footnot... 48 $this->styles = array(
mp-wp_add-footnot... 49 'decimal' => '1,2...10',
mp-wp_add-footnot... 50 'decimal-leading-zero' => '01, 02...10',
mp-wp_add-footnot... 51 'lower-alpha' => 'a,b...j',
mp-wp_add-footnot... 52 'upper-alpha' => 'A,B...J',
mp-wp_add-footnot... 53 'lower-roman' => 'i,ii...x',
mp-wp_add-footnot... 54 'upper-roman' => 'I,II...X',
mp-wp_add-footnot... 55 'symbol' => 'Symbol'
mp-wp_add-footnot... 56 );
mp-wp_add-footnot... 57
mp-wp_add-footnot... 58 // Define default options
mp-wp_add-footnot... 59 $this->default_options = array('superscript'=>true,
mp-wp_add-footnot... 60 'pre_backlink'=>' [',
mp-wp_add-footnot... 61 'backlink'=>'↩',
mp-wp_add-footnot... 62 'post_backlink'=>']',
mp-wp_add-footnot... 63 'pre_identifier'=>'',
mp-wp_add-footnot... 64 'list_style_type'=>'decimal',
mp-wp_add-footnot... 65 'list_style_symbol'=>'†',
mp-wp_add-footnot... 66 'post_identifier'=>'',
mp-wp_add-footnot... 67 'pre_footnotes'=>'',
mp-wp_add-footnot... 68 'post_footnotes'=>'',
mp-wp_add-footnot... 69 'style_rules'=>'ol.footnotes{font-size:0.8em; color:#666666;}',
mp-wp_add-footnot... 70 'no_display_home'=>false,
mp-wp_add-footnot... 71 'no_display_archive'=>false,
mp-wp_add-footnot... 72 'no_display_date'=>false,
mp-wp_add-footnot... 73 'no_display_category'=>false,
mp-wp_add-footnot... 74 'no_display_search'=>false,
mp-wp_add-footnot... 75 'no_display_feed'=>false,
mp-wp_add-footnot... 76 'combine_identical_notes'=>false,
mp-wp_add-footnot... 77 'priority'=>11,
mp-wp_add-footnot... 78 'version'=>WP_FOOTNOTES_VERSION);
mp-wp_add-footnot... 79
mp-wp_add-footnot... 80 // Get the current settings or setup some defaults if needed
mp-wp_add-footnot... 81 if (!$this->current_options = get_option('swas_footnote_options')){
mp-wp_add-footnot... 82 $this->current_options = $this->default_options;
mp-wp_add-footnot... 83 update_option('swas_footnote_options', $this->current_options);
mp-wp_add-footnot... 84 } else {
mp-wp_add-footnot... 85 // Set any unset options
mp-wp_add-footnot... 86 if ($this->current_options['version'] != WP_FOOTNOTES_VERSION) {
mp-wp_add-footnot... 87 foreach ($this->default_options as $key => $value) {
mp-wp_add-footnot... 88 if (!isset($this->current_options[$key])) {
mp-wp_add-footnot... 89 $this->current_options[$key] = $value;
mp-wp_add-footnot... 90 }
mp-wp_add-footnot... 91 }
mp-wp_add-footnot... 92 $this->current_options['version'] = WP_FOOTNOTES_VERSION;
mp-wp_add-footnot... 93 update_option('swas_footnote_options', $this->current_options);
mp-wp_add-footnot... 94 }
mp-wp_add-footnot... 95 }
mp-wp_add-footnot... 96
mp-wp_add-footnot... 97 /*
mp-wp_add-footnot... 98 if (!empty($_POST['save_options'])){
mp-wp_add-footnot... 99 $footnotes_options['superscript'] = (array_key_exists('superscript', $_POST)) ? true : false;
mp-wp_add-footnot... 100 $footnotes_options['pre_backlink'] = $_POST['pre_backlink'];
mp-wp_add-footnot... 101 $footnotes_options['backlink'] = $_POST['backlink'];
mp-wp_add-footnot... 102 $footnotes_options['post_backlink'] = $_POST['post_backlink'];
mp-wp_add-footnot... 103 $footnotes_options['pre_identifier'] = $_POST['pre_identifier'];
mp-wp_add-footnot... 104 $footnotes_options['list_style_type'] = $_POST['list_style_type'];
mp-wp_add-footnot... 105 $footnotes_options['post_identifier'] = $_POST['post_identifier'];
mp-wp_add-footnot... 106 $footnotes_options['list_style_symbol'] = $_POST['list_style_symbol'];
mp-wp_add-footnot... 107 $footnotes_options['pre_footnotes'] = stripslashes($_POST['pre_footnotes']);
mp-wp_add-footnot... 108 $footnotes_options['post_footnotes'] = stripslashes($_POST['post_footnotes']);
mp-wp_add-footnot... 109 $footnotes_options['style_rules'] = stripslashes($_POST['style_rules']);
mp-wp_add-footnot... 110 $footnotes_options['no_display_home'] = (array_key_exists('no_display_home', $_POST)) ? true : false;
mp-wp_add-footnot... 111 $footnotes_options['no_display_archive'] = (array_key_exists('no_display_archive', $_POST)) ? true : false;
mp-wp_add-footnot... 112 $footnotes_options['no_display_date'] = (array_key_exists('no_display_date', $_POST)) ? true : false;
mp-wp_add-footnot... 113 $footnotes_options['no_display_category'] = (array_key_exists('no_display_category', $_POST)) ? true : false;
mp-wp_add-footnot... 114 $footnotes_options['no_display_search'] = (array_key_exists('no_display_search', $_POST)) ? true : false;
mp-wp_add-footnot... 115 $footnotes_options['no_display_feed'] = (array_key_exists('no_display_feed', $_POST)) ? true : false;
mp-wp_add-footnot... 116 $footnotes_options['combine_identical_notes'] = (array_key_exists('combine_identical_notes', $_POST)) ? true : false;
mp-wp_add-footnot... 117 $footnotes_options['priority'] = $_POST['priority'];
mp-wp_add-footnot... 118 update_option('swas_footnote_options', $footnotes_options);
mp-wp_add-footnot... 119 }elseif(!empty($_POST['reset_options'])){
mp-wp_add-footnot... 120 update_option('swas_footnote_options', '');
mp-wp_add-footnot... 121 update_option('swas_footnote_options', $this->default_options);
mp-wp_add-footnot... 122 }
mp-wp_add-footnot... 123 */
mp-wp_add-footnot... 124
mp-wp_add-footnot... 125 // Hook me up
mp-wp_add-footnot... 126 add_action('the_content', array($this, 'process'), $this->current_options['priority']);
mp-wp_add-footnot... 127 add_action('admin_menu', array($this, 'add_options_page')); // Insert the Admin panel.
mp-wp_add-footnot... 128 add_action('wp_head', array($this, 'insert_styles'));
mp-wp_add-footnot... 129 }
mp-wp_add-footnot... 130
mp-wp_add-footnot... 131 /**
mp-wp_add-footnot... 132 * Searches the text and extracts footnotes.
mp-wp_add-footnot... 133 * Adds the identifier links and creats footnotes list.
mp-wp_add-footnot... 134 * @param $data string The content of the post.
mp-wp_add-footnot... 135 * @return string The new content with footnotes generated.
mp-wp_add-footnot... 136 */
mp-wp_add-footnot... 137 function process($data) {
mp-wp_add-footnot... 138 global $post;
mp-wp_add-footnot... 139
mp-wp_add-footnot... 140 // Check for and setup the starting number
mp-wp_add-footnot... 141 $start_number = (preg_match("|<!\-\-startnum=(\d+)\-\->|",$data,$start_number_array)==1) ? $start_number_array[1] : 1;
mp-wp_add-footnot... 142
mp-wp_add-footnot... 143 // Regex extraction of all footnotes (or return if there are none)
mp-wp_add-footnot... 144 if (!preg_match_all("/(".preg_quote(WP_FOOTNOTES_OPEN)."|<footnote>)(.*)(".preg_quote(WP_FOOTNOTES_CLOSE)."|<\/footnote>)/Us", $data, $identifiers, PREG_SET_ORDER)) {
mp-wp_add-footnot... 145 return $data;
mp-wp_add-footnot... 146 }
mp-wp_add-footnot... 147
mp-wp_add-footnot... 148 // Check whether we are displaying them or not
mp-wp_add-footnot... 149 $display = true;
mp-wp_add-footnot... 150 if ($this->current_options['no_display_home'] && is_home()) $display = false;
mp-wp_add-footnot... 151 if ($this->current_options['no_display_archive'] && is_archive()) $display = false;
mp-wp_add-footnot... 152 if ($this->current_options['no_display_date'] && is_date()) $display = false;
mp-wp_add-footnot... 153 if ($this->current_options['no_display_category'] && is_category()) $display = false;
mp-wp_add-footnot... 154 if ($this->current_options['no_display_search'] && is_search()) $display = false;
mp-wp_add-footnot... 155 if ($this->current_options['no_display_feed'] && is_feed()) $display = false;
mp-wp_add-footnot... 156
mp-wp_add-footnot... 157 $footnotes = array();
mp-wp_add-footnot... 158
mp-wp_add-footnot... 159 // Check if this post is using a different list style to the settings
mp-wp_add-footnot... 160 if ( array_key_exists(get_post_meta($post->ID, 'footnote_style', true), $this->styles) ) {
mp-wp_add-footnot... 161 $style = get_post_meta($post->ID, 'footnote_style', true);
mp-wp_add-footnot... 162 } else {
mp-wp_add-footnot... 163 $style = $this->current_options['list_style_type'];
mp-wp_add-footnot... 164 }
mp-wp_add-footnot... 165
mp-wp_add-footnot... 166 // Create 'em
mp-wp_add-footnot... 167 for ($i=0; $i<count($identifiers); $i++){
mp-wp_add-footnot... 168 // Look for ref: and replace in identifiers array.
mp-wp_add-footnot... 169 if (substr($identifiers[$i][2],0,4) == 'ref:'){
mp-wp_add-footnot... 170 $ref = (int)substr($identifiers[$i][2],4);
mp-wp_add-footnot... 171 $identifiers[$i]['text'] = $identifiers[$ref-1][2];
mp-wp_add-footnot... 172 }else{
mp-wp_add-footnot... 173 $identifiers[$i]['text'] = $identifiers[$i][2];
mp-wp_add-footnot... 174 }
mp-wp_add-footnot... 175
mp-wp_add-footnot... 176
mp-wp_add-footnot... 177 // if we're combining identical notes check if we've already got one like this & record keys
mp-wp_add-footnot... 178 if ($this->current_options['combine_identical_notes']){
mp-wp_add-footnot... 179 for ($j=0; $j<count($footnotes); $j++){
mp-wp_add-footnot... 180 if ($footnotes[$j]['text'] == $identifiers[$i]['text']){
mp-wp_add-footnot... 181 $identifiers[$i]['use_footnote'] = $j;
mp-wp_add-footnot... 182 $footnotes[$j]['identifiers'][] = $i;
mp-wp_add-footnot... 183 break;
mp-wp_add-footnot... 184 }
mp-wp_add-footnot... 185 }
mp-wp_add-footnot... 186 }
mp-wp_add-footnot... 187
mp-wp_add-footnot... 188 if (!isset($identifiers[$i]['use_footnote'])){
mp-wp_add-footnot... 189 // Add footnote and record the key
mp-wp_add-footnot... 190 $identifiers[$i]['use_footnote'] = count($footnotes);
mp-wp_add-footnot... 191 $footnotes[$identifiers[$i]['use_footnote']]['text'] = $identifiers[$i]['text'];
mp-wp_add-footnot... 192 $footnotes[$identifiers[$i]['use_footnote']]['symbol'] = $identifiers[$i]['symbol'];
mp-wp_add-footnot... 193 $footnotes[$identifiers[$i]['use_footnote']]['identifiers'][] = $i;
mp-wp_add-footnot... 194 }
mp-wp_add-footnot... 195 }
mp-wp_add-footnot... 196
mp-wp_add-footnot... 197 // Footnotes and identifiers are stored in the array
mp-wp_add-footnot... 198 $use_full_link = false;
mp-wp_add-footnot... 199
mp-wp_add-footnot... 200 if (is_feed()) $use_full_link = true;
mp-wp_add-footnot... 201
mp-wp_add-footnot... 202 if (is_preview()) $use_full_link = false;
mp-wp_add-footnot... 203
mp-wp_add-footnot... 204 // Display identifiers
mp-wp_add-footnot... 205 foreach ($identifiers as $key => $value) {
mp-wp_add-footnot... 206 $id_id = "identifier_".$key."_".$post->ID;
mp-wp_add-footnot... 207 $id_num = ($style == 'decimal') ? $value['use_footnote']+$start_number : $this->convert_num($value['use_footnote']+$start_number, $style, count($footnotes));
mp-wp_add-footnot... 208 $id_href = ( ($use_full_link) ? get_permalink($post->ID) : '' ) . "#footnote_".$value['use_footnote']."_".$post->ID;
mp-wp_add-footnot... 209
mp-wp_add-footnot... 210 // $id_title = str_replace('"', """, htmlentities(strip_tags($value['text']), ENT_QUOTES, 'UTF-8'));
mp-wp_add-footnot... 211
mp-wp_add-footnot... 212 $id_title = str_replace('"', '`', strip_tags($value['text']));
mp-wp_add-footnot... 213 $id_replace = $this->current_options['pre_identifier'].'<a href="'.$id_href.'" id="'.$id_id.'" class="footnote-link footnote-identifier-link" title="'.$id_title.'">'.$id_num.'</a>'.$this->current_options['post_identifier'];
mp-wp_add-footnot... 214 if ($this->current_options['superscript']) $id_replace = '<sup>'.$id_replace.'</sup>';
mp-wp_add-footnot... 215 if ($display) $data = substr_replace($data, $id_replace, strpos($data,$value[0]),strlen($value[0]));
mp-wp_add-footnot... 216 else $data = substr_replace($data, '', strpos($data,$value[0]),strlen($value[0]));
mp-wp_add-footnot... 217 }
mp-wp_add-footnot... 218
mp-wp_add-footnot... 219 // Display footnotes
mp-wp_add-footnot... 220 if ($display) {
mp-wp_add-footnot... 221 $start = ($start_number != 1) ? 'start="'.$start_number.'" ' : '';
mp-wp_add-footnot... 222 $data = $data.$this->current_options['pre_footnotes'];
mp-wp_add-footnot... 223
mp-wp_add-footnot... 224 $data = $data . '<ol '.$start.'class="footnotes">';
mp-wp_add-footnot... 225 foreach ($footnotes as $key => $value) {
mp-wp_add-footnot... 226 $data = $data.'<li id="footnote_'.$key.'_'.$post->ID.'" class="footnote"';
mp-wp_add-footnot... 227 if ($style == 'symbol') {
mp-wp_add-footnot... 228 $data = $data . ' style="list-style-type:none;"';
mp-wp_add-footnot... 229 } elseif($style != $this->current_options['list_style_type']) {
mp-wp_add-footnot... 230 $data = $data . ' style="list-style-type:' . $style . ';"';
mp-wp_add-footnot... 231 }
mp-wp_add-footnot... 232 $data = $data . '>';
mp-wp_add-footnot... 233 if ($style == 'symbol') {
mp-wp_add-footnot... 234 $data = $data . '<span class="symbol">' . $this->convert_num($key+$start_number, $style, count($footnotes)) . '</span> ';
mp-wp_add-footnot... 235 }
mp-wp_add-footnot... 236 $data = $data.$value['text'];
mp-wp_add-footnot... 237 if (!is_feed()){
mp-wp_add-footnot... 238 foreach($value['identifiers'] as $identifier){
mp-wp_add-footnot... 239 $data = $data.$this->current_options['pre_backlink'].'<a href="'.( ($use_full_link) ? get_permalink($post->ID) : '' ).'#identifier_'.$identifier.'_'.$post->ID.'" class="footnote-link footnote-back-link">'.$this->current_options['backlink'].'</a>'.$this->current_options['post_backlink'];
mp-wp_add-footnot... 240 }
mp-wp_add-footnot... 241 }
mp-wp_add-footnot... 242 $data = $data . '</li>';
mp-wp_add-footnot... 243 }
mp-wp_add-footnot... 244 $data = $data . '</ol>' . $this->current_options['post_footnotes'];
mp-wp_add-footnot... 245 }
mp-wp_add-footnot... 246 return $data;
mp-wp_add-footnot... 247 }
mp-wp_add-footnot... 248
mp-wp_add-footnot... 249 /**
mp-wp_add-footnot... 250 * Really insert the options page.
mp-wp_add-footnot... 251 */
mp-wp_add-footnot... 252 function footnotes_options_page() {
mp-wp_add-footnot... 253 $this->current_options = get_option('swas_footnote_options');
mp-wp_add-footnot... 254 foreach ($this->current_options as $key=>$setting) {
mp-wp_add-footnot... 255 $new_setting[$key] = htmlentities($setting);
mp-wp_add-footnot... 256 }
mp-wp_add-footnot... 257 $this->current_options = $new_setting;
mp-wp_add-footnot... 258 unset($new_setting);
mp-wp_add-footnot... 259 include (dirname(__FILE__) . '/options.php');
mp-wp_add-footnot... 260 }
mp-wp_add-footnot... 261
mp-wp_add-footnot... 262 /**
mp-wp_add-footnot... 263 * Insert the options page into the admin area.
mp-wp_add-footnot... 264 */
mp-wp_add-footnot... 265 function add_options_page() {
mp-wp_add-footnot... 266 // Add a new menu under Options:
mp-wp_add-footnot... 267 add_options_page('Footnotes', 'Footnotes', 8, __FILE__, array($this, 'footnotes_options_page'));
mp-wp_add-footnot... 268 }
mp-wp_add-footnot... 269
mp-wp_add-footnot... 270 function upgrade_post($data){
mp-wp_add-footnot... 271 $data = str_replace('<footnote>',WP_FOOTNOTES_OPEN,$data);
mp-wp_add-footnot... 272 $data = str_replace('</footnote>',WP_FOOTNOTES_CLOSE,$data);
mp-wp_add-footnot... 273 return $data;
mp-wp_add-footnot... 274 }
mp-wp_add-footnot... 275
mp-wp_add-footnot... 276 function insert_styles(){
mp-wp_add-footnot... 277 ?>
mp-wp_add-footnot... 278 <style type="text/css">
mp-wp_add-footnot... 279 <?php if ($this->current_options['list_style_type'] != 'symbol'): ?>
mp-wp_add-footnot... 280 ol.footnotes li {list-style-type:<?php echo $this->current_options['list_style_type']; ?>;}
mp-wp_add-footnot... 281 <?php endif; ?>
mp-wp_add-footnot... 282 <?php echo $this->current_options['style_rules'];?>
mp-wp_add-footnot... 283 </style>
mp-wp_add-footnot... 284 <?php
mp-wp_add-footnot... 285 }
mp-wp_add-footnot... 286
mp-wp_add-footnot... 287
mp-wp_add-footnot... 288 function convert_num ($num, $style, $total){
mp-wp_add-footnot... 289 switch ($style) {
mp-wp_add-footnot... 290 case 'decimal-leading-zero' :
mp-wp_add-footnot... 291 $width = max(2, strlen($total));
mp-wp_add-footnot... 292 return sprintf("%0{$width}d", $num);
mp-wp_add-footnot... 293 case 'lower-roman' :
mp-wp_add-footnot... 294 return $this->roman($num, 'lower');
mp-wp_add-footnot... 295 case 'upper-roman' :
mp-wp_add-footnot... 296 return $this->roman($num);
mp-wp_add-footnot... 297 case 'lower-alpha' :
mp-wp_add-footnot... 298 return $this->alpha($num, 'lower');
mp-wp_add-footnot... 299 case 'upper-alpha' :
mp-wp_add-footnot... 300 return $this->alpha($num);
mp-wp_add-footnot... 301 case 'symbol' :
mp-wp_add-footnot... 302 $sym = '';
mp-wp_add-footnot... 303 for ($i = 0; $i<$num; $i++) {
mp-wp_add-footnot... 304 $sym .= $this->current_options['list_style_symbol'];
mp-wp_add-footnot... 305 }
mp-wp_add-footnot... 306 return $sym;
mp-wp_add-footnot... 307 }
mp-wp_add-footnot... 308 }
mp-wp_add-footnot... 309
mp-wp_add-footnot... 310
mp-wp_add-footnot... 311 /**
mp-wp_add-footnot... 312 * Convert to a roman numeral.
mp-wp_add-footnot... 313 *
mp-wp_add-footnot... 314 * Thanks to Indi.in.the.Wired for the improved algorithm.
mp-wp_add-footnot... 315 * http://plugins.trac.wordpress.org/ticket/1177
mp-wp_add-footnot... 316 *
mp-wp_add-footnot... 317 * @param int $num The number to convert.
mp-wp_add-footnot... 318 * @param string $case Upper or lower case.
mp-wp_add-footnot... 319 * @return string The roman numeral
mp-wp_add-footnot... 320 */
mp-wp_add-footnot... 321 function roman($num, $case= 'upper'){
mp-wp_add-footnot... 322 $num = (int) $num;
mp-wp_add-footnot... 323 $conversion = array('M'=>1000, 'CM'=>900, 'D'=>500, 'CD'=>400, 'C'=>100, 'XC'=>90, 'L'=>50, 'XL'=>40, 'X'=>10, 'IX'=>9, 'V'=>5, 'IV'=>4, 'I'=>1);
mp-wp_add-footnot... 324 $roman = '';
mp-wp_add-footnot... 325
mp-wp_add-footnot... 326 foreach ($conversion as $r => $d){
mp-wp_add-footnot... 327 $roman .= str_repeat($r, (int)($num / $d));
mp-wp_add-footnot... 328 $num %= $d;
mp-wp_add-footnot... 329 }
mp-wp_add-footnot... 330
mp-wp_add-footnot... 331 return ($case == 'lower') ? strtolower($roman) : $roman;
mp-wp_add-footnot... 332 }
mp-wp_add-footnot... 333
mp-wp_add-footnot... 334 function alpha($num, $case='upper'){
mp-wp_add-footnot... 335 $j = 1;
mp-wp_add-footnot... 336 for ($i = 'A'; $i <= 'ZZ'; $i++){
mp-wp_add-footnot... 337 if ($j == $num){
mp-wp_add-footnot... 338 if ($case == 'lower')
mp-wp_add-footnot... 339 return strtolower($i);
mp-wp_add-footnot... 340 else
mp-wp_add-footnot... 341 return $i;
mp-wp_add-footnot... 342 }
mp-wp_add-footnot... 343 $j++;
mp-wp_add-footnot... 344 }
mp-wp_add-footnot... 345 }
mp-wp_add-footnot... 346 }