2014-09-06 01:13:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Collection of static helper methods for managing the documentation
|
|
|
|
*
|
|
|
|
* @package docsviewer
|
|
|
|
*/
|
|
|
|
class DocumentationHelper {
|
2014-09-07 01:26:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* String helper for cleaning a file name to a readable version.
|
|
|
|
*
|
|
|
|
* @param string $name to convert
|
|
|
|
*
|
|
|
|
* @return string $name output
|
|
|
|
*/
|
|
|
|
public static function clean_page_name($name) {
|
|
|
|
$name = self::trim_extension_off($name);
|
|
|
|
$name = self::trim_sort_number($name);
|
|
|
|
|
|
|
|
$name = str_replace(array('-', '_'), ' ', $name);
|
|
|
|
|
|
|
|
|
|
|
|
return ucwords(trim($name));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* String helper for cleaning a file name to a URL safe version.
|
|
|
|
*
|
|
|
|
* @param string $name to convert
|
|
|
|
*
|
|
|
|
* @return string $name output
|
|
|
|
*/
|
|
|
|
public static function clean_page_url($name) {
|
|
|
|
$name = str_replace(array(' '), '_', $name);
|
|
|
|
|
|
|
|
$name = self::trim_extension_off($name);
|
|
|
|
$name = self::trim_sort_number($name);
|
|
|
|
|
|
|
|
if(preg_match('/^[\/]?index[\/]?/', $name)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return strtolower($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes leading numbers from pages (used to control sort order).
|
|
|
|
*
|
|
|
|
* @param string
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function trim_sort_number($name) {
|
|
|
|
$name = preg_replace("/^[0-9]*[_-]+/", '', $name);
|
|
|
|
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to strip the extension off and return the name without
|
|
|
|
* the extension.
|
|
|
|
*
|
|
|
|
* @param string
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function trim_extension_off($name) {
|
|
|
|
if(strrpos($name,'.') !== false) {
|
|
|
|
return substr($name, 0, strrpos($name,'.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $name;
|
|
|
|
}
|
2014-09-07 07:09:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to get the extension of the filename.
|
|
|
|
*
|
|
|
|
* @param string
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function get_extension($name) {
|
2014-09-15 11:47:45 +02:00
|
|
|
if(preg_match('/\.[a-z]+$/', $name)) {
|
2014-09-07 07:09:28 +02:00
|
|
|
return substr($name, strrpos($name,'.') + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2014-09-06 01:13:12 +02:00
|
|
|
}
|