Minor changes on get slug from content
This commit is contained in:
parent
c3cfa54149
commit
7c55ac704c
|
@ -24,6 +24,8 @@ echo '
|
||||||
function table($status, $icon='arrow-circle-o-down') {
|
function table($status, $icon='arrow-circle-o-down') {
|
||||||
global $pages;
|
global $pages;
|
||||||
global $Url;
|
global $Url;
|
||||||
|
global $Language;
|
||||||
|
|
||||||
$showLegend = true;
|
$showLegend = true;
|
||||||
foreach ($pages as $key=>$page) {
|
foreach ($pages as $key=>$page) {
|
||||||
if ($page->status()==$status) {
|
if ($page->status()==$status) {
|
||||||
|
|
|
@ -31,20 +31,12 @@ class dbPages extends dbJSON
|
||||||
{
|
{
|
||||||
$dataForDb = array(); // This data will be saved in the database
|
$dataForDb = array(); // This data will be saved in the database
|
||||||
$dataForFile = array(); // This data will be saved in the file
|
$dataForFile = array(); // This data will be saved in the file
|
||||||
|
|
||||||
// Generate title if empty
|
// Generate slug from content if the title is empty
|
||||||
if( empty($args['title']) ) {
|
if (empty($args['title'])) {
|
||||||
$args['title'] = Text::truncate($args['content'], 60);
|
$args['slug'] = Text::truncate($args['content'], 60, '');
|
||||||
|
|
||||||
// Assign the new title to the slug as well.
|
|
||||||
$args['slug'] = $args['title'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate description if empty
|
|
||||||
if( empty($args['description']) ) {
|
|
||||||
$args['description'] = Text::truncate($args['content'], 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate key
|
// Generate key
|
||||||
$key = $this->generateKey($args['slug'], $args['parent']);
|
$key = $this->generateKey($args['slug'], $args['parent']);
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ class Text {
|
||||||
$string = str_replace(array_keys(self::$specialChars), self::$specialChars, $string);
|
$string = str_replace(array_keys(self::$specialChars), self::$specialChars, $string);
|
||||||
|
|
||||||
if(function_exists('iconv')) {
|
if(function_exists('iconv')) {
|
||||||
$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
|
$string = iconv(CHARSET, 'ASCII//TRANSLIT', $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
$string = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $string);
|
$string = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $string);
|
||||||
|
@ -152,26 +152,26 @@ class Text {
|
||||||
}
|
}
|
||||||
|
|
||||||
// String to lowercase
|
// String to lowercase
|
||||||
public static function lowercase($string, $encoding='UTF-8')
|
public static function lowercase($string)
|
||||||
{
|
{
|
||||||
return mb_strtolower($string, $encoding);
|
return mb_strtolower($string, CHARSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a string's first character uppercase
|
// Make a string's first character uppercase
|
||||||
public static function firstCharUp($string, $encoding='UTF-8')
|
public static function firstCharUp($string)
|
||||||
{
|
{
|
||||||
// Thanks http://stackoverflow.com/questions/2517947/ucfirst-function-for-multibyte-character-encodings
|
// Thanks http://stackoverflow.com/questions/2517947/ucfirst-function-for-multibyte-character-encodings
|
||||||
$strlen = mb_strlen($string, $encoding);
|
$strlen = mb_strlen($string, CHARSET);
|
||||||
$firstChar = mb_substr($string, 0, 1, $encoding);
|
$firstChar = mb_substr($string, 0, 1, CHARSET);
|
||||||
$then = mb_substr($string, 1, $strlen - 1, $encoding);
|
$then = mb_substr($string, 1, $strlen - 1, CHARSET);
|
||||||
|
|
||||||
return mb_strtoupper($firstChar, $encoding).$then;
|
return mb_strtoupper($firstChar, CHARSET).$then;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find position of first occurrence of substring in a string otherwise returns FALSE.
|
// Find position of first occurrence of substring in a string otherwise returns FALSE.
|
||||||
public static function stringPosition($string, $substring)
|
public static function stringPosition($string, $substring)
|
||||||
{
|
{
|
||||||
return mb_strpos($string, $substring, 0, 'UTF-8');
|
return mb_strpos($string, $substring, 0, CHARSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function stringContains($string, $substring)
|
public static function stringContains($string, $substring)
|
||||||
|
@ -182,7 +182,7 @@ class Text {
|
||||||
// Returns the portion of string specified by the start and length parameters.
|
// Returns the portion of string specified by the start and length parameters.
|
||||||
public static function cut($string, $start, $length)
|
public static function cut($string, $start, $length)
|
||||||
{
|
{
|
||||||
$cut = mb_substr($string, $start, $length, 'UTF-8');
|
$cut = mb_substr($string, $start, $length, CHARSET);
|
||||||
|
|
||||||
if(empty($cut)) {
|
if(empty($cut)) {
|
||||||
return '';
|
return '';
|
||||||
|
@ -194,7 +194,7 @@ class Text {
|
||||||
// Return string length
|
// Return string length
|
||||||
public static function length($string)
|
public static function length($string)
|
||||||
{
|
{
|
||||||
return mb_strlen($string, 'UTF-8');
|
return mb_strlen($string, CHARSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isEmpty($string)
|
public static function isEmpty($string)
|
||||||
|
@ -227,26 +227,26 @@ class Text {
|
||||||
create_function('$input', 'return "<pre><code $input[1]>".htmlentities($input[2])."</code></pre>";'),
|
create_function('$input', 'return "<pre><code $input[1]>".htmlentities($input[2])."</code></pre>";'),
|
||||||
$string);
|
$string);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Truncates the string under the limit specified by the limit parameter.
|
// Truncates the string under the limit specified by the limit parameter.
|
||||||
public static function truncate($string, $limit, $end = '...')
|
public static function truncate($string, $limit, $end = '...')
|
||||||
{
|
{
|
||||||
// Check if over $limit
|
// Check if over $limit
|
||||||
if(mb_strlen($string) > $limit) {
|
if(mb_strlen($string) > $limit) {
|
||||||
|
|
||||||
// Check if string is only one word
|
// Check if string is only one word
|
||||||
if(preg_match('/\s/', $string)) {
|
if(preg_match('/\s/', $string)) {
|
||||||
|
|
||||||
// Append the string specified by the end parameter to the end of the string as it is over the limit.
|
// Append the string specified by the end parameter to the end of the string as it is over the limit.
|
||||||
$truncate = trim(mb_substr($string, 0, mb_strpos($string, ' ', $limit, 'UTF-8'), 'UTF-8'));
|
$truncate = trim(mb_substr($string, 0, mb_strpos($string, ' ', $limit, CHARSET), CHARSET));
|
||||||
} else {
|
} else {
|
||||||
$truncate = trim(mb_substr($string, 0, $limit, 'UTF-8'));
|
$truncate = trim(mb_substr($string, 0, $limit, CHARSET));
|
||||||
}
|
}
|
||||||
$truncate = $truncate.$end;
|
$truncate = $truncate.$end;
|
||||||
} else {
|
} else {
|
||||||
$truncate = $string;
|
$truncate = $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($truncate)) {
|
if(empty($truncate)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,9 +61,6 @@ class pluginsimpleMDE extends Plugin {
|
||||||
// SimpleMDE css
|
// SimpleMDE css
|
||||||
$html .= '<link rel="stylesheet" href="'.$pluginPath.'css/simplemde.min.css">';
|
$html .= '<link rel="stylesheet" href="'.$pluginPath.'css/simplemde.min.css">';
|
||||||
|
|
||||||
// Font-awesome is a dependency of SimpleMDE
|
|
||||||
$html .= '<link rel="stylesheet" href="'.HTML_PATH_CORE_CSS.'font-awesome/font-awesome.min.css">';
|
|
||||||
|
|
||||||
// SimpleMDE js
|
// SimpleMDE js
|
||||||
$html .= '<script src="'.$pluginPath.'js/simplemde.min.js"></script>';
|
$html .= '<script src="'.$pluginPath.'js/simplemde.min.js"></script>';
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ class pluginVersion extends Plugin {
|
||||||
$output = TCP::http($url);
|
$output = TCP::http($url);
|
||||||
|
|
||||||
$json = json_decode($output, true);
|
$json = json_decode($output, true);
|
||||||
if(empty($json)) {
|
if (empty($json)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue