Updating Markdown class + use spl_autoload_register

spl_autoload_register now calls the GNUsocial_class_autoload function
instead of us replacing the magic __autoload($cls). This means we can
queue up other autoload functions, such as the one now used for extlib
functions which exist directly in the 'extlib/' folder or have proper
namespacing (which our new Markdown class does).
This commit is contained in:
Mikael Nordfeldth 2014-03-18 10:46:24 +01:00
parent 7cd3879306
commit 3d0994bcca
7 changed files with 3196 additions and 1735 deletions

36
extlib/Michelf/License.md Normal file
View File

@ -0,0 +1,36 @@
PHP Markdown Lib
Copyright (c) 2004-2013 Michel Fortin
<http://michelf.ca/>
All rights reserved.
Based on Markdown
Copyright (c) 2003-2006 John Gruber
<http://daringfireball.net/>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name "Markdown" nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
This software is provided by the copyright holders and contributors "as
is" and any express or implied warranties, including, but not limited
to, the implied warranties of merchantability and fitness for a
particular purpose are disclaimed. In no event shall the copyright owner
or contributors be liable for any direct, indirect, incidental, special,
exemplary, or consequential damages (including, but not limited to,
procurement of substitute goods or services; loss of use, data, or
profits; or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.

3106
extlib/Michelf/Markdown.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
<?php
#
# Markdown - A text-to-HTML conversion tool for web writers
#
# PHP Markdown
# Copyright (c) 2004-2013 Michel Fortin
# <http://michelf.com/projects/php-markdown/>
#
# Original Markdown
# Copyright (c) 2004-2006 John Gruber
# <http://daringfireball.net/projects/markdown/>
#
namespace Michelf;
#
# Markdown Parser Interface
#
interface MarkdownInterface {
#
# Initialize the parser and return the result of its transform method.
# This will work fine for derived classes too.
#
public static function defaultTransform($text);
#
# Main function. Performs some preprocessing on the input text
# and pass it through the document gamut.
#
public function transform($text);
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -105,7 +105,7 @@ function _have_config()
return StatusNet::haveConfig();
}
function __autoload($cls)
function GNUsocial_class_autoload($cls)
{
if (file_exists(INSTALLDIR.'/classes/' . $cls . '.php')) {
require_once(INSTALLDIR.'/classes/' . $cls . '.php');
@ -125,23 +125,17 @@ function __autoload($cls)
// XXX: note that these files should not use config options
// at compile time since DB config options are not yet loaded.
require_once 'Validate.php';
require_once 'markdown.php';
// Autoload queue
spl_autoload_register('GNUsocial_class_autoload');
// XXX: other formats here
/**
* Avoid the NICKNAME_FMT constant; use the Nickname class instead.
*
* Nickname::DISPLAY_FMT is more suitable for inserting into regexes;
* note that it includes the [] and repeating bits, so should be wrapped
* directly in a capture paren usually.
*
* For validation, use Nickname::normalize(), Nickname::isValid() etc.
*
* @deprecated
*/
define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER);
// Extlibs with namespaces (or directly in extlib/)
// such as: Validate and \Michelf\Markdown
spl_autoload_register(function($class){
$file = INSTALLDIR.'/extlib/'.preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php';
if (file_exists($file)) {
require_once $file;
}
});
require_once INSTALLDIR.'/lib/util.php';
require_once INSTALLDIR.'/lib/action.php';

View File

@ -27,8 +27,7 @@ class Nickname
* Nickname::normalize() to get the canonical form, or Nickname::isValid()
* if you just need to check if it's properly formatted.
*
* This, DISPLAY_FMT, and CANONICAL_FMT replace the old NICKNAME_FMT,
* but be aware that these should not be enclosed in []s.
* This, DISPLAY_FMT, and CANONICAL_FMT should not be enclosed in []s.
*
* @fixme would prefer to define in reference to the other constants
*/
@ -36,6 +35,7 @@ class Nickname
/**
* Regex fragment for acceptable user-formatted variant of a nickname.
*
* This includes some chars such as underscore which will be removed
* from the normalized canonical form, but still must fit within
* field length limits.
@ -44,8 +44,7 @@ class Nickname
* Nickname::normalize() to get the canonical form, or Nickname::isValid()
* if you just need to check if it's properly formatted.
*
* This and CANONICAL_FMT replace the old NICKNAME_FMT, but be aware
* that these should not be enclosed in []s.
* This, INPUT_FMT and CANONICAL_FMT should not be enclosed in []s.
*/
const DISPLAY_FMT = '[0-9a-zA-Z_]{1,64}';
@ -60,8 +59,7 @@ class Nickname
* there are multiple possible denormalized forms for each valid
* canonical-form name.
*
* This and DISPLAY_FMT replace the old NICKNAME_FMT, but be aware
* that these should not be enclosed in []s.
* This, INPUT_FMT and DISPLAY_FMT should not be enclosed in []s.
*/
const CANONICAL_FMT = '[0-9a-z]{1,64}';

View File

@ -1992,7 +1992,6 @@ function common_confirmation_code($bits)
}
// convert markup to HTML
function common_markup_to_html($c, $args=null)
{
if ($c === null) {
@ -2013,7 +2012,8 @@ function common_markup_to_html($c, $args=null)
$c = preg_replace_callback('/%%action.(\w+)%%/', function ($m) { return common_local_url($m[1]); }, $c);
$c = preg_replace_callback('/%%doc.(\w+)%%/', function ($m) { return common_local_url('doc', array('title'=>$m[1])); }, $c);
$c = preg_replace_callback('/%%(\w+).(\w+)%%/', function ($m) { return common_config($m[1], $m[2]); }, $c);
return Markdown($c);
return \Michelf\Markdown::defaultTransform($c);
}
function common_user_property($property)