2014-07-31 10:17:38 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2014-09-14 20:32:59 +00:00
|
|
|
* Includes the Convert Class.
|
|
|
|
*
|
|
|
|
* @filesource
|
|
|
|
* @author Stefan Herndler
|
|
|
|
* @since 1.5.0 12.09.14 10:56
|
2014-07-31 10:17:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-09-14 20:32:59 +00:00
|
|
|
* Converts data types and Footnotes specific values.
|
|
|
|
*
|
|
|
|
* @author Stefan Herndler
|
|
|
|
* @since 1.5.0
|
2014-07-31 10:17:38 +00:00
|
|
|
*/
|
|
|
|
class MCI_Footnotes_Convert {
|
|
|
|
|
|
|
|
/**
|
2014-09-14 20:32:59 +00:00
|
|
|
* Converts a integer into the user-defined counter style for the footnotes.
|
|
|
|
*
|
|
|
|
* @author Stefan Herndler
|
|
|
|
* @since 1.5.0
|
|
|
|
* @param int $p_int_Index Index to be converted.
|
|
|
|
* @param string $p_str_ConvertStyle Style of the new/converted Index.
|
|
|
|
* @return string Converted Index as string in the defined counter style.
|
2014-07-31 10:17:38 +00:00
|
|
|
*/
|
|
|
|
public static function Index($p_int_Index, $p_str_ConvertStyle = "arabic_plain") {
|
|
|
|
switch ($p_str_ConvertStyle) {
|
|
|
|
case "romanic":
|
|
|
|
return self::toRomanic($p_int_Index);
|
|
|
|
case "latin_high":
|
|
|
|
return self::toLatin($p_int_Index, true);
|
|
|
|
case "latin_low":
|
|
|
|
return self::toLatin($p_int_Index, false);
|
|
|
|
case "arabic_leading":
|
|
|
|
return self::toArabicLeading($p_int_Index);
|
|
|
|
case "arabic_plain":
|
|
|
|
default:
|
|
|
|
return $p_int_Index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-14 20:32:59 +00:00
|
|
|
* Converts an integer into latin ascii characters, either lower or upper-case.
|
|
|
|
* Function available from A to ZZ ( means 676 footnotes at 1 page possible).
|
|
|
|
*
|
|
|
|
* @author Stefan Herndler
|
2014-07-31 10:17:38 +00:00
|
|
|
* @since 1.0-gamma
|
2014-09-14 20:32:59 +00:00
|
|
|
* @param int $p_int_Value Value/Index to be converted.
|
|
|
|
* @param bool $p_bool_UpperCase True to convert the value to upper case letter, otherwise to lower case.
|
2014-07-31 10:17:38 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private static function toLatin($p_int_Value, $p_bool_UpperCase) {
|
|
|
|
// output string
|
|
|
|
$l_str_Return = "";
|
|
|
|
$l_int_Offset = 0;
|
|
|
|
// check if the value is higher then 26 = Z
|
|
|
|
while ($p_int_Value > 26) {
|
|
|
|
// increase offset and reduce counter
|
|
|
|
$l_int_Offset++;
|
|
|
|
$p_int_Value -= 26;
|
|
|
|
}
|
|
|
|
// if offset set (more then Z), then add a new letter in front
|
|
|
|
if ($l_int_Offset > 0) {
|
2014-09-14 20:32:59 +00:00
|
|
|
$l_str_Return = chr($l_int_Offset + 64);
|
2014-07-31 10:17:38 +00:00
|
|
|
}
|
|
|
|
// add the origin letter
|
2014-09-14 20:32:59 +00:00
|
|
|
$l_str_Return .= chr($p_int_Value + 64);
|
2014-07-31 10:17:38 +00:00
|
|
|
// return the latin character representing the integer
|
2014-09-14 20:32:59 +00:00
|
|
|
if ($p_bool_UpperCase) {
|
|
|
|
return strtoupper($l_str_Return);
|
|
|
|
}
|
|
|
|
return strtolower($l_str_Return);
|
2014-07-31 10:17:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-14 20:32:59 +00:00
|
|
|
* Converts an integer to a leading-0 integer.
|
|
|
|
*
|
|
|
|
* @author Stefan Herndler
|
2014-07-31 10:17:38 +00:00
|
|
|
* @since 1.0-gamma
|
2014-09-14 20:32:59 +00:00
|
|
|
* @param int $p_int_Value Value/Index to be converted.
|
|
|
|
* @return string Value with a leading zero.
|
2014-07-31 10:17:38 +00:00
|
|
|
*/
|
|
|
|
private static function toArabicLeading($p_int_Value) {
|
|
|
|
// add a leading 0 if number lower then 10
|
|
|
|
if ($p_int_Value < 10) {
|
|
|
|
return "0" . $p_int_Value;
|
|
|
|
}
|
|
|
|
return $p_int_Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-14 20:32:59 +00:00
|
|
|
* Converts an integer to a romanic letter.
|
|
|
|
*
|
|
|
|
* @author Stefan Herndler
|
2014-07-31 10:17:38 +00:00
|
|
|
* @since 1.0-gamma
|
2014-09-14 20:32:59 +00:00
|
|
|
* @param int $p_int_Value Value/Index to be converted.
|
2014-07-31 10:17:38 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private static function toRomanic($p_int_Value) {
|
|
|
|
// table containing all necessary romanic letters
|
|
|
|
$l_arr_RomanicLetters = 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
|
|
|
|
);
|
|
|
|
// return value
|
|
|
|
$l_str_Return = '';
|
|
|
|
// iterate through integer value until it is reduced to 0
|
|
|
|
while ($p_int_Value > 0) {
|
|
|
|
foreach ($l_arr_RomanicLetters as $l_str_Romanic => $l_int_Arabic) {
|
|
|
|
if ($p_int_Value >= $l_int_Arabic) {
|
|
|
|
$p_int_Value -= $l_int_Arabic;
|
|
|
|
$l_str_Return .= $l_str_Romanic;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// return romanic letters as string
|
|
|
|
return $l_str_Return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-14 20:32:59 +00:00
|
|
|
* Converts a string depending on its value to a boolean.
|
|
|
|
*
|
|
|
|
* @author Stefan Herndler
|
2014-07-31 10:17:38 +00:00
|
|
|
* @since 1.0-beta
|
2014-09-14 20:32:59 +00:00
|
|
|
* @param string $p_str_Value String to be converted to boolean.
|
|
|
|
* @return bool Boolean representing the string.
|
2014-07-31 10:17:38 +00:00
|
|
|
*/
|
|
|
|
public static function toBool($p_str_Value) {
|
2014-09-14 20:32:59 +00:00
|
|
|
// convert string to lower-case to make it easier
|
2014-07-31 10:17:38 +00:00
|
|
|
$p_str_Value = strtolower($p_str_Value);
|
2014-09-14 20:32:59 +00:00
|
|
|
// check if string seems to contain a "true" value
|
2014-07-31 10:17:38 +00:00
|
|
|
switch ($p_str_Value) {
|
|
|
|
case "checked":
|
|
|
|
case "yes":
|
|
|
|
case "true":
|
|
|
|
case "on":
|
|
|
|
case "1":
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-14 20:32:59 +00:00
|
|
|
// nothing found that says "true", so we return false
|
2014-07-31 10:17:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-21 08:43:53 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-14 20:32:59 +00:00
|
|
|
* Get a html Array short code depending on Arrow-Array key index.
|
|
|
|
*
|
|
|
|
* @author Stefan Herndler
|
2014-08-21 08:43:53 +00:00
|
|
|
* @since 1.3.2
|
2014-09-14 20:32:59 +00:00
|
|
|
* @param int $p_int_Index Index representing the Arrow. If empty all Arrows are specified.
|
|
|
|
* @return array|string Array of all Arrows if Index is empty otherwise html tag of a specific arrow.
|
2014-08-21 08:43:53 +00:00
|
|
|
*/
|
|
|
|
public static function getArrow($p_int_Index = -1) {
|
|
|
|
// define all possible arrows
|
|
|
|
$l_arr_Arrows = array("↑", "↥", "↟", "↩", "↲", "↵", "⇑", "⇡", "⇧", "↑");
|
|
|
|
// convert index to an integer
|
|
|
|
if (!is_int($p_int_Index)) {
|
|
|
|
$p_int_Index = intval($p_int_Index);
|
|
|
|
}
|
|
|
|
// return the whole arrow array
|
|
|
|
if ($p_int_Index < 0 || $p_int_Index > count($l_arr_Arrows)) {
|
|
|
|
return $l_arr_Arrows;
|
|
|
|
}
|
|
|
|
// return a single arrow
|
|
|
|
return $l_arr_Arrows[$p_int_Index];
|
|
|
|
}
|
2014-09-28 11:23:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a Variable.
|
|
|
|
*
|
|
|
|
* @author Stefan Herndler
|
|
|
|
* @since 1.5.0
|
|
|
|
* @param mixed $p_mixed_Value
|
|
|
|
*/
|
|
|
|
public static function debug($p_mixed_Value) {
|
|
|
|
if (empty($p_mixed_Value)) {
|
|
|
|
var_dump($p_mixed_Value);
|
|
|
|
|
|
|
|
} else if (is_array($p_mixed_Value)) {
|
|
|
|
printf("<pre>");
|
|
|
|
print_r($p_mixed_Value);
|
|
|
|
printf("</pre>");
|
|
|
|
|
|
|
|
} else if (is_object($p_mixed_Value)) {
|
|
|
|
printf("<pre>");
|
|
|
|
print_r($p_mixed_Value);
|
|
|
|
printf("</pre>");
|
|
|
|
|
|
|
|
} else if (is_numeric($p_mixed_Value) || is_int($p_mixed_Value)) {
|
2014-10-01 20:57:16 +00:00
|
|
|
var_dump($p_mixed_Value);
|
2014-09-28 11:23:09 +00:00
|
|
|
|
|
|
|
} else if (is_date($p_mixed_Value)) {
|
2014-10-01 20:57:16 +00:00
|
|
|
var_dump($p_mixed_Value);
|
2014-09-28 11:23:09 +00:00
|
|
|
|
|
|
|
} else {
|
2014-10-01 20:57:16 +00:00
|
|
|
var_dump($p_mixed_Value);
|
2014-09-28 11:23:09 +00:00
|
|
|
}
|
|
|
|
echo "<br/>";
|
|
|
|
}
|
2020-12-06 17:54:59 +00:00
|
|
|
}
|