2011-03-19 11:54:12 +00:00
< ? php
2006-12-02 04:36:16 +00:00
/*
2009-01-03 22:32:54 +00:00
* e107 website system
*
2016-12-24 16:54:31 +00:00
* Copyright ( C ) 2008 - 2016 e107 Inc ( e107 . org )
2009-01-03 22:32:54 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Text processing and parsing functions
*
2006-12-02 04:36:16 +00:00
*/
2010-01-24 12:05:53 +00:00
2021-01-14 17:32:08 -08:00
if ( ! defined ( 'e107_INIT' ))
{
exit ();
}
2006-12-02 04:36:16 +00:00
2009-10-30 19:57:28 +00:00
2020-12-14 16:21:48 -08:00
define ( 'E_NL' , chr ( 2 ));
2008-11-13 20:41:20 +00:00
2021-01-14 17:32:08 -08:00
class e_parse
2006-12-02 04:36:16 +00:00
{
2021-01-14 17:32:08 -08:00
2009-10-30 23:31:08 +00:00
/**
* Determine how to handle utf - 8.
* 0 = 'do nothing'
* 1 = 'use mb_string'
* 2 = emulation
2010-01-12 13:11:48 +00:00
*
2009-10-30 23:31:08 +00:00
* @ var integer
*/
2021-01-15 09:03:07 -08:00
private $multibyte = false ; // previously $utfAction
2009-10-30 19:57:28 +00:00
2021-01-15 12:47:26 -08:00
private $pref ; // core prefs used in toHTML.
2009-10-30 19:57:28 +00:00
// 'Hooked' parsers (array)
2021-01-15 09:03:07 -08:00
private $e_hook = array ();
2009-10-30 19:57:28 +00:00
2021-01-19 18:52:56 -08:00
// Used in search_class.php (move??)
public $search = array ( '&#039;' , ''' , ''' , '"' , 'onerror' , '>' , '&quot;' , ' & ' );
2009-10-30 19:57:28 +00:00
2021-01-19 18:52:56 -08:00
public $replace = array ( " ' " , " ' " , " ' " , '"' , 'one<i></i>rror' , '>' , '"' , ' & ' );
2007-01-20 16:19:43 +00:00
2009-10-30 19:57:28 +00:00
// Set to TRUE or FALSE once it has been calculated
2020-12-08 07:29:17 -08:00
protected $e_highlighting ;
2009-10-30 19:57:28 +00:00
// Highlight query
2020-12-08 07:29:17 -08:00
protected $e_query ;
2021-01-14 17:32:08 -08:00
2021-01-15 09:03:07 -08:00
private $thumbWidth = 100 ;
2021-01-14 17:32:08 -08:00
2021-01-15 09:03:07 -08:00
private $thumbHeight = 0 ;
2021-01-14 17:32:08 -08:00
2021-01-15 09:03:07 -08:00
private $thumbCrop = 0 ;
2009-10-30 19:57:28 +00:00
2016-02-09 22:53:03 -08:00
private $thumbEncode = 0 ;
2017-10-25 19:02:10 -07:00
private $staticCount = 0 ;
2021-01-14 18:30:32 -08:00
protected $staticUrl ;
2020-12-03 14:20:34 -08:00
2020-12-21 06:41:45 -08:00
/** @var array Stored relative paths - used by replaceConstants() */
private $relativePaths = array ();
2020-12-03 14:20:34 -08:00
2017-01-28 17:34:47 -08:00
// BBcode that contain preformatted code.
private $preformatted = array ( 'html' , 'markdown' );
2009-10-30 19:57:28 +00:00
// Set up the defaults
2021-01-14 18:30:32 -08:00
private $e_optDefault = array (
2009-10-30 19:57:28 +00:00
// default context: reflects legacy settings (many items enabled)
2021-01-14 17:32:08 -08:00
'context' => 'OLDDEFAULT' ,
2009-10-30 19:57:28 +00:00
//
2021-01-14 17:32:08 -08:00
'fromadmin' => false ,
2009-10-30 19:57:28 +00:00
// Enable emote display
2021-01-14 17:32:08 -08:00
'emotes' => true ,
2009-10-30 19:57:28 +00:00
// Convert defines(constants) within text.
2021-01-14 17:32:08 -08:00
'defs' => false ,
2009-10-30 19:57:28 +00:00
// replace all {e_XXX} constants with their e107 value - 'rel' or 'abs'
2021-01-14 17:32:08 -08:00
'constants' => false ,
2009-10-30 19:57:28 +00:00
// Enable hooked parsers
2021-01-14 17:32:08 -08:00
'hook' => true ,
2009-10-30 19:57:28 +00:00
// Allow scripts through (new for 0.8)
2021-01-14 17:32:08 -08:00
'scripts' => true ,
2009-10-30 19:57:28 +00:00
// Make links clickable
2021-01-14 17:32:08 -08:00
'link_click' => true ,
2009-10-30 19:57:28 +00:00
// Substitute on clickable links (only if link_click == TRUE)
2021-01-14 17:32:08 -08:00
'link_replace' => true ,
2009-10-30 19:57:28 +00:00
// Parse shortcodes - TRUE enables parsing
2021-01-14 17:32:08 -08:00
'parse_sc' => false ,
2021-01-15 12:47:26 -08:00
2009-10-30 19:57:28 +00:00
// remove HTML tags.
2021-01-14 17:32:08 -08:00
'no_tags' => false ,
2009-10-30 19:57:28 +00:00
// Restore entity form of quotes and such to single characters - TRUE disables
2021-01-14 17:32:08 -08:00
'value' => false ,
2009-10-30 19:57:28 +00:00
// Line break compression - TRUE removes newline characters
2021-01-14 17:32:08 -08:00
'nobreak' => false ,
2009-10-30 19:57:28 +00:00
// Retain newlines - wraps to \n instead of <br /> if TRUE (for non-HTML email text etc)
2021-01-14 17:32:08 -08:00
'retain_nl' => false
);
2008-12-30 13:51:41 +00:00
2009-10-30 19:57:28 +00:00
// Super modifiers override default option values
2021-01-14 18:30:32 -08:00
private $e_SuperMods = array (
2021-01-14 17:32:08 -08:00
//text is part of a title (e.g. news title)
'TITLE' =>
array (
'nobreak' => true , 'retain_nl' => true , 'link_click' => false , 'emotes' => false , 'defs' => true , 'parse_sc' => true
),
'TITLE_PLAIN' =>
array (
'nobreak' => true , 'retain_nl' => true , 'link_click' => false , 'emotes' => false , 'defs' => true , 'parse_sc' => true , 'no_tags' => true
),
//text is user-entered (i.e. untrusted) and part of a title (e.g. forum title)
'USER_TITLE' =>
array (
'nobreak' => true , 'retain_nl' => true , 'link_click' => false , 'scripts' => false , 'emotes' => false , 'hook' => false
),
// text is 'body' of email or similar - being sent 'off-site' so don't rely on server availability
'E_TITLE' =>
array (
'nobreak' => true , 'retain_nl' => true , 'defs' => true , 'parse_sc' => true , 'emotes' => false , 'scripts' => false , 'link_click' => false
),
// text is part of the summary of a longer item (e.g. content summary)
'SUMMARY' =>
array (
'defs' => true , 'constants' => 'full' , 'parse_sc' => true
),
// text is the description of an item (e.g. download, link)
'DESCRIPTION' =>
array (
'defs' => true , 'constants' => 'full' , 'parse_sc' => true
),
// text is 'body' or 'bulk' text (e.g. custom page body, content body)
'BODY' =>
array (
'defs' => true , 'constants' => 'full' , 'parse_sc' => true
),
// text is parsed by the Wysiwyg editor. eg. TinyMce
'WYSIWYG' =>
array (
'hook' => false , 'link_click' => false , 'link_replace' => false , 'retain_nl' => true
),
// text is user-entered (i.e. untrusted)'body' or 'bulk' text (e.g. custom page body, content body)
'USER_BODY' =>
array (
'constants' => 'full' , 'scripts' => false , 'nostrip' => false
),
// text is 'body' of email or similar - being sent 'off-site' so don't rely on server availability
'E_BODY' =>
array (
'defs' => true , 'constants' => 'full' , 'parse_sc' => true , 'emotes' => false , 'scripts' => false , 'link_click' => false
),
// text is text-only 'body' of email or similar - being sent 'off-site' so don't rely on server availability
'E_BODY_PLAIN' =>
array (
'defs' => true , 'constants' => 'full' , 'parse_sc' => true , 'emotes' => false , 'scripts' => false , 'link_click' => false , 'retain_nl' => true , 'no_tags' => true
),
// text is the 'content' of a link (A tag, etc)
'LINKTEXT' =>
array (
'nobreak' => true , 'retain_nl' => true , 'link_click' => false , 'emotes' => false , 'hook' => false , 'defs' => true , 'parse_sc' => true
),
// text is used (for admin edit) without fancy conversions or html.
'RAWTEXT' =>
array (
'nobreak' => true , 'retain_nl' => true , 'link_click' => false , 'emotes' => false , 'hook' => false , 'no_tags' => true
2021-01-15 12:47:26 -08:00
),
'NODEFAULT' =>
array ( 'context' => false , 'fromadmin' => false , 'emotes' => false , 'defs' => false , 'constants' => false , 'hook' => false ,
'scripts' => false , 'link_click' => false , 'link_replace' => false , 'parse_sc' => false , 'no_tags' => false , 'value' => false ,
'nobreak' => false , 'retain_nl' => false
2021-01-14 17:32:08 -08:00
)
);
2007-01-20 16:19:43 +00:00
2009-01-03 22:32:54 +00:00
// Individual modifiers change the current context
2021-01-14 18:30:32 -08:00
private $e_Modifiers = array (
2021-01-14 17:32:08 -08:00
'emotes_off' => array ( 'emotes' => false ),
'emotes_on' => array ( 'emotes' => true ),
'no_hook' => array ( 'hook' => false ),
'do_hook' => array ( 'hook' => true ),
// New for 0.8
'scripts_off' => array ( 'scripts' => false ),
// New for 0.8
'scripts_on' => array ( 'scripts' => true ),
'no_make_clickable' => array ( 'link_click' => false ),
'make_clickable' => array ( 'link_click' => true ),
'no_replace' => array ( 'link_replace' => false ),
// Replace text of clickable links (only if make_clickable option set)
'replace' => array ( 'link_replace' => true ),
// No path replacement
'consts_off' => array ( 'constants' => false ),
// Relative path replacement
'consts_rel' => array ( 'constants' => 'rel' ),
// Absolute path replacement
'consts_abs' => array ( 'constants' => 'abs' ),
// Full path replacement
'consts_full' => array ( 'constants' => 'full' ),
// No shortcode parsing
'scparse_off' => array ( 'parse_sc' => false ),
'scparse_on' => array ( 'parse_sc' => true ),
// Strip tags
'no_tags' => array ( 'no_tags' => true ),
// Leave tags
'do_tags' => array ( 'no_tags' => false ),
'fromadmin' => array ( 'fromadmin' => true ),
'notadmin' => array ( 'fromadmin' => false ),
// entity replacement
'er_off' => array ( 'value' => false ),
'er_on' => array ( 'value' => true ),
// Decode constant if exists
'defs_off' => array ( 'defs' => false ),
'defs_on' => array ( 'defs' => true ),
'dobreak' => array ( 'nobreak' => false ),
'nobreak' => array ( 'nobreak' => true ),
// Line break using \n
'lb_nl' => array ( 'retain_nl' => true ),
// Line break using <br />
'lb_br' => array ( 'retain_nl' => false ),
// Legacy option names below here - discontinue later
'retain_nl' => array ( 'retain_nl' => true ),
'defs' => array ( 'defs' => true ),
'parse_sc' => array ( 'parse_sc' => true ),
'constants' => array ( 'constants' => 'rel' ),
'value' => array ( 'value' => true ),
'wysiwyg' => array ( 'wysiwyg' => true )
);
/**
* @ var DOMDocument
*/
2021-01-14 18:30:32 -08:00
private $domObj ;
private $isHtml = false ;
2021-01-14 17:32:08 -08:00
2021-01-14 18:30:32 -08:00
private $bootstrap ;
private $fontawesome ;
private $convertToWebP = false ;
2021-01-14 17:32:08 -08:00
2021-01-14 18:30:32 -08:00
private $removedList = array ();
private $nodesToDelete = array ();
private $nodesToConvert = array ();
private $nodesToDisableSC = array ();
private $pathList = array ();
2009-01-03 22:32:54 +00:00
2021-02-05 19:57:53 -08:00
private $allowedAttributes = array ();
2021-01-14 17:32:08 -08:00
2021-02-05 19:57:53 -08:00
private $badAttrValues = array ();
2021-01-14 17:32:08 -08:00
2021-02-05 19:57:53 -08:00
private $replaceAttrValues = array ();
2021-01-14 17:32:08 -08:00
2021-02-05 19:57:53 -08:00
private $allowedTags = array ();
private $scriptTags = array ();
2021-01-14 17:32:08 -08:00
2021-02-05 19:57:53 -08:00
private $scriptAttributes = array ();
2021-01-14 17:32:08 -08:00
2021-02-05 19:57:53 -08:00
private $blockTags = array ();
2021-01-14 17:32:08 -08:00
private $scriptAccess = false ; // nobody.
2009-01-03 22:32:54 +00:00
2009-10-30 20:58:52 +00:00
/**
* Constructor - keep it public for backward compatibility
2021-01-14 17:32:08 -08:00
* still some new e_parse () in the core
2009-10-30 20:58:52 +00:00
*
*/
public function __construct ()
2007-01-20 16:19:43 +00:00
{
2015-04-29 10:22:46 -07:00
2021-01-14 17:32:08 -08:00
// initialise the type of UTF-8 processing methods depending on PHP version and mb string extension
$this -> domObj = new DOMDocument ( '1.0' , 'utf-8' );
2013-03-01 18:17:03 -08:00
$this -> init ();
2021-01-14 17:32:08 -08:00
$this -> compileAttributeDefaults ();
2021-01-14 18:30:32 -08:00
2007-12-30 16:54:31 +00:00
}
2021-01-15 12:47:26 -08:00
public function getModifierList ( $type = '' )
2021-01-14 18:30:32 -08:00
{
2021-01-15 12:47:26 -08:00
if ( $type === 'super' )
{
return $this -> e_SuperMods ;
}
return $this -> e_Modifiers ;
2021-01-14 18:30:32 -08:00
}
2007-12-30 16:54:31 +00:00
2009-10-30 20:58:52 +00:00
/**
* Initialise the type of UTF - 8 processing methods depending on PHP version and mb string extension .
2020-12-08 07:29:17 -08:00
* Note : mb string is required during installation of e107 .
2009-10-30 20:58:52 +00:00
* NOTE : can ' t be called until CHARSET is known
2021-01-14 17:32:08 -08:00
* but we all know that it is UTF - 8 now
2009-10-30 20:58:52 +00:00
*
* @ return void
*/
2021-01-15 09:03:07 -08:00
public function setMultibyte ( $bool )
2008-11-13 20:41:20 +00:00
{
2021-01-15 10:59:52 -08:00
2021-01-15 09:03:07 -08:00
if ( $bool === false )
{
$this -> multibyte = false ;
return null ;
}
2021-01-14 17:32:08 -08:00
2021-01-15 09:03:07 -08:00
if ( extension_loaded ( 'mbstring' ))
2020-12-08 07:29:17 -08:00
{
2021-01-15 09:03:07 -08:00
$this -> multibyte = true ;
2020-12-08 07:29:17 -08:00
mb_internal_encoding ( 'UTF-8' );
}
2008-11-13 20:41:20 +00:00
}
2010-01-12 13:11:48 +00:00
2008-11-13 20:41:20 +00:00
2009-10-30 22:19:56 +00:00
/**
* Returns the length of the given string .
2021-01-15 09:03:07 -08:00
* Unicode ( UTF - 8 ) analogue of standard @ link http :// php . net / strlen strlen PHP function .
2010-01-12 13:11:48 +00:00
*
2009-10-30 23:31:08 +00:00
* @ param string $str The UTF - 8 encoded string being measured for length .
* @ return integer The length ( amount of UTF - 8 characters ) of the string on success , and 0 if the string is empty .
2009-10-30 22:19:56 +00:00
*/
2010-01-12 13:11:48 +00:00
public function ustrlen ( $str )
2008-11-13 20:41:20 +00:00
{
2021-01-15 09:03:07 -08:00
if ( $this -> multibyte )
2008-11-13 20:41:20 +00:00
{
2021-01-15 09:03:07 -08:00
return mb_strlen ( $str );
2008-11-13 20:41:20 +00:00
}
2021-01-15 09:03:07 -08:00
return strlen ( $str );
// return strlen(utf8_decode($str));
2008-11-13 20:41:20 +00:00
}
2009-10-30 22:19:56 +00:00
/**
* Make a string lowercase .
2021-01-15 09:03:07 -08:00
* Unicode ( UTF - 8 ) analogue of standard @ link http :// php . net / strtolower strtolower PHP function .
2010-01-12 13:11:48 +00:00
*
2009-10-30 23:31:08 +00:00
* @ param string $str The UTF - 8 encoded string to be lowercased .
* @ return string Specified string with all alphabetic characters converted to lowercase .
2009-10-30 22:19:56 +00:00
*/
2010-01-12 13:11:48 +00:00
public function ustrtolower ( $str )
2008-11-13 20:41:20 +00:00
{
2021-01-15 09:03:07 -08:00
if ( $this -> multibyte )
2008-11-13 20:41:20 +00:00
{
2021-01-15 09:03:07 -08:00
return mb_strtolower ( $str );
2008-11-13 20:41:20 +00:00
}
2020-12-08 07:29:17 -08:00
2021-01-15 09:03:07 -08:00
return strtolower ( $str );
2008-11-13 20:41:20 +00:00
}
2009-01-03 22:32:54 +00:00
2009-10-30 22:19:56 +00:00
/**
* Make a string uppercase .
2021-01-15 09:03:07 -08:00
* Unicode ( UTF - 8 ) analogue of standard @ link http :// php . net / strtoupper strtoupper PHP function .
2009-10-30 22:19:56 +00:00
*
2009-10-30 23:31:08 +00:00
* @ param string $str The UTF - 8 encoded string to be uppercased .
* @ return string Specified string with all alphabetic characters converted to uppercase .
2009-10-30 22:19:56 +00:00
*/
2010-01-12 13:11:48 +00:00
public function ustrtoupper ( $str )
2008-11-13 20:41:20 +00:00
{
2021-01-14 17:32:08 -08:00
2021-01-15 09:03:07 -08:00
if ( $this -> multibyte )
2008-11-13 20:41:20 +00:00
{
2020-12-14 16:21:48 -08:00
return mb_strtoupper ( $str );
2008-11-13 20:41:20 +00:00
}
2021-01-14 17:32:08 -08:00
2020-12-14 16:21:48 -08:00
return strtoupper ( $str );
2020-12-08 07:29:17 -08:00
2008-11-13 20:41:20 +00:00
}
2009-10-30 22:19:56 +00:00
/**
* Find the position of the first occurrence of a case - sensitive UTF - 8 encoded string .
2021-01-15 09:03:07 -08:00
* Unicode ( UTF - 8 ) analogue of standard @ link http :// php . net / strpos strpos PHP function .
*
2009-10-30 22:19:56 +00:00
* Returns the numeric position ( offset in amount of UTF - 8 characters )
* of the first occurrence of needle in the haystack string .
2010-01-12 13:11:48 +00:00
*
2009-10-30 23:31:08 +00:00
* @ param string $haystack The UTF - 8 encoded string being searched in .
* @ param integer $needle The UTF - 8 encoded string being searched for .
* @ param integer $offset [ optional ] The optional offset parameter allows you to specify which character in haystack to start searching .
2021-01-14 17:32:08 -08:00
* The position returned is still relative to the beginning of haystack .
2009-10-30 23:31:08 +00:00
* @ return integer | boolean Returns the position as an integer . If needle is not found , the function will return boolean FALSE .
2009-10-30 22:19:56 +00:00
*/
2010-01-12 13:11:48 +00:00
public function ustrpos ( $haystack , $needle , $offset = 0 )
2008-11-13 20:41:20 +00:00
{
2021-01-14 17:32:08 -08:00
2021-01-15 09:03:07 -08:00
if ( $this -> multibyte )
2008-11-13 20:41:20 +00:00
{
2020-12-14 16:21:48 -08:00
return mb_strpos ( $haystack , $needle , $offset );
2008-11-13 20:41:20 +00:00
}
2021-01-14 17:32:08 -08:00
2020-12-14 16:21:48 -08:00
return strpos ( $haystack , $needle , $offset );
2008-11-13 20:41:20 +00:00
}
2009-01-03 22:32:54 +00:00
2009-10-30 22:19:56 +00:00
/**
* Find the position of the last occurrence of a case - sensitive UTF - 8 encoded string .
2021-01-15 09:03:07 -08:00
* Unicode ( UTF - 8 ) analogue of standard @ link http :// php . net / strrpos strrpos PHP function .
2009-10-30 22:19:56 +00:00
* Returns the numeric position ( offset in amount of UTF - 8 characters )
* of the last occurrence of needle in the haystack string .
2010-01-12 13:11:48 +00:00
*
2009-10-30 23:31:08 +00:00
* @ param string $haystack The UTF - 8 encoded string being searched in .
* @ param integer $needle The UTF - 8 encoded string being searched for .
2009-10-30 22:19:56 +00:00
* @ param integer $offset [ optional ] - The optional offset parameter allows you to specify which character in haystack to start searching .
2021-01-14 17:32:08 -08:00
* The position returned is still relative to the beginning of haystack .
2009-10-30 23:31:08 +00:00
* @ return integer | boolean Returns the position as an integer . If needle is not found , the function will return boolean FALSE .
2009-10-30 22:19:56 +00:00
*/
2010-01-12 13:11:48 +00:00
public function ustrrpos ( $haystack , $needle , $offset = 0 )
2008-11-13 20:41:20 +00:00
{
2021-01-15 09:03:07 -08:00
if ( $this -> multibyte )
2008-11-13 20:41:20 +00:00
{
2020-12-14 16:21:48 -08:00
return mb_strrpos ( $haystack , $needle , $offset );
2008-11-13 20:41:20 +00:00
}
2020-12-08 07:29:17 -08:00
2020-12-14 16:21:48 -08:00
return strrpos ( $haystack , $needle , $offset );
2008-11-13 20:41:20 +00:00
}
2013-10-24 04:15:25 +03:00
/**
* Returns all of haystack starting from and including the first occurrence of needle to the end .
2021-01-15 09:03:07 -08:00
* Unicode ( UTF - 8 ) analogue of standard @ link http :// php . net / stristr stristr PHP function .
2013-10-24 04:15:25 +03:00
*
* @ param string $haystack The UTF - 8 encoded string to search in .
* @ param mixed $needle If needle is not a string , it is converted to an integer and applied as the ordinal value of a character .
2021-01-15 09:03:07 -08:00
* @ param bool $before_needle [ optional ] ( PHP 5.3 + ) If TRUE , returns the part of the haystack before the first occurrence of the needle ( excluding needle ) .
2013-10-24 04:15:25 +03:00
* @ return string Returns the matched substring . If needle is not found , returns FALSE .
*/
public function ustristr ( $haystack , $needle , $before_needle = false )
{
2021-01-14 17:32:08 -08:00
2021-01-15 09:03:07 -08:00
if ( $this -> multibyte )
2013-10-24 04:15:25 +03:00
{
2021-01-15 09:03:07 -08:00
return mb_stristr ( $haystack , $needle , $before_needle );
2013-10-24 04:15:25 +03:00
}
2021-01-14 17:32:08 -08:00
2014-08-17 15:15:40 +03:00
return stristr ( $haystack , $needle , $before_needle );
2021-01-15 09:03:07 -08:00
2013-10-24 04:15:25 +03:00
}
2021-01-14 17:32:08 -08:00
2009-10-30 23:31:08 +00:00
/**
* Returns the portion of string specified by the start and length parameters .
2021-01-15 09:03:07 -08:00
* Unicode ( UTF - 8 ) analogue of standard @ link http :// php . net / substr substr PHP function .
2010-01-12 13:11:48 +00:00
*
2009-10-30 23:31:08 +00:00
* NOTE : May be subtle differences in return values dependent on which routine is used .
* Native substr () routine can return FALSE . mb_substr () and utf8_substr () just return an empty string .
2010-01-12 13:11:48 +00:00
*
2009-10-30 23:31:08 +00:00
* @ param string $str The UTF - 8 encoded string .
* @ param integer $start Start of portion to be returned . Position is counted in amount of UTF - 8 characters from the beginning of str .
2021-01-14 17:32:08 -08:00
* First character ' s position is 0. Second character position is 1 , and so on .
2010-01-12 13:11:48 +00:00
* @ param integer $length [ optional ] If length is given , the string returned will contain at most length characters beginning from start
2021-01-14 17:32:08 -08:00
* ( depending on the length of string ) . If length is omitted , the rest of string from start will be returned .
2009-10-30 23:31:08 +00:00
* @ return string The extracted UTF - 8 encoded part of input string .
*/
2021-01-14 17:32:08 -08:00
public function usubstr ( $str , $start , $length = null )
2008-11-13 20:41:20 +00:00
{
2021-01-14 17:32:08 -08:00
2021-01-15 09:03:07 -08:00
if ( $this -> multibyte )
2008-11-13 20:41:20 +00:00
{
2021-01-14 17:32:08 -08:00
return ( $length === null ) ? mb_substr ( $str , $start ) : mb_substr ( $str , $start , $length );
2008-11-13 20:41:20 +00:00
}
2021-01-14 17:32:08 -08:00
2020-12-14 16:21:48 -08:00
return substr ( $str , $start , $length );
2020-12-08 07:29:17 -08:00
2008-11-13 20:41:20 +00:00
}
2009-10-30 23:31:08 +00:00
/**
* Converts the supplied text ( presumed to be from user input ) to a format suitable for storing in a database table .
*
2018-03-05 14:37:56 -08:00
* @ param mixed $data
2009-10-30 23:31:08 +00:00
* @ param boolean $nostrip [ optional ] Assumes all data is GPC ( $_GET , $_POST , $_COOKIE ) unless indicate otherwise by setting this var to TRUE .
2021-01-14 17:32:08 -08:00
* If magic quotes is enabled on the server and you do not tell toDB () that the data is non GPC then slashes will be stripped when they should not be .
2009-10-30 23:31:08 +00:00
* @ param boolean $no_encode [ optional ] This parameter should nearly always be FALSE . It is used by the save_prefs () function to preserve HTML content within prefs even when
2021-01-14 17:32:08 -08:00
* the save_prefs () function has been called by a non admin user / user without html posting permissions .
2017-01-29 09:47:33 -08:00
* @ param boolean | string $mod [ optional ] model = admin - ui usage . The 'no_html' and 'no_php' modifiers blanket prevent HTML and PHP posting regardless of posting permissions . ( used in logging )
2021-01-14 17:32:08 -08:00
* The 'pReFs' value is for internal use only , when saving prefs , to prevent sanitisation of HTML .
2018-07-21 10:19:04 +02:00
* @ param mixed $parm [ optional ]
2020-12-18 09:39:02 -08:00
* @ return mixed
2009-11-12 21:41:34 +00:00
* @ todo complete the documentation of this essential method
2009-10-30 23:31:08 +00:00
*/
2021-01-14 17:32:08 -08:00
public function toDB ( $data = null , $nostrip = false , $no_encode = false , $mod = false , $parm = null )
2006-12-02 04:36:16 +00:00
{
2021-01-14 17:32:08 -08:00
2020-12-14 07:27:51 -08:00
$variableType = gettype ( $data );
2021-01-14 17:32:08 -08:00
if (( $variableType !== 'string' && $variableType !== 'array' ) || $data === '0' )
2019-03-02 11:03:17 -08:00
{
2020-12-14 07:27:51 -08:00
return $data ;
2019-03-02 11:03:17 -08:00
}
2017-01-29 08:42:18 -08:00
2021-01-14 17:32:08 -08:00
if ( $variableType === 'array' )
2009-01-03 22:32:54 +00:00
{
2015-04-29 10:22:46 -07:00
$ret = array ();
2019-02-26 13:56:07 -08:00
2021-01-14 17:32:08 -08:00
foreach ( $data as $key => $var )
2009-01-03 22:32:54 +00:00
{
2009-10-20 14:47:05 +00:00
//Fix - sanitize keys as well
2021-01-14 17:32:08 -08:00
$key = filter_var ( $key , FILTER_SANITIZE_STRING );
2019-03-02 10:07:07 -08:00
$ret [ $key ] = $this -> toDB ( $var , $nostrip , $no_encode , $mod , $parm );
2006-12-02 04:36:16 +00:00
}
2019-02-26 13:56:07 -08:00
2010-02-12 16:37:42 +00:00
return $ret ;
}
2020-12-14 07:27:51 -08:00
2021-01-14 17:32:08 -08:00
if ( MAGIC_QUOTES_GPC === true && $nostrip === false )
2010-02-12 16:37:42 +00:00
{
$data = stripslashes ( $data );
}
2010-09-06 12:34:06 +00:00
2019-03-02 11:03:17 -08:00
$core_pref = e107 :: getConfig ();
2021-01-14 17:32:08 -08:00
if ( $mod !== 'pReFs' ) //XXX We're not saving prefs.
2010-09-06 12:34:06 +00:00
{
2015-04-11 02:53:51 -07:00
2015-04-29 10:22:46 -07:00
$data = $this -> preFilter ( $data ); // used by bb_xxx.php toDB() functions. bb_code.php toDB() allows us to properly bypass HTML cleaning below.
2019-03-01 16:36:37 -08:00
$data = $this -> cleanHtml ( $data ); // clean it regardless of if it is text or html. (html could have missing closing tags)
2015-03-29 20:26:35 -07:00
2015-05-21 21:49:32 -07:00
if (( $this -> isHtml ( $data )) && strpos ( $mod , 'no_html' ) === false )
2013-04-30 02:57:33 -07:00
{
2015-04-11 12:33:21 -07:00
$this -> isHtml = true ;
2021-01-14 17:32:08 -08:00
// $data = $this->cleanHtml($data); // sanitize all html. (moved above to include everything)
2015-04-29 10:22:46 -07:00
2021-01-14 17:32:08 -08:00
$data = str_replace ( array ( '%7B' , '%7D' ), array ( '{' , '}' ), $data ); // fix for {e_XXX} paths.
2013-04-30 02:57:33 -07:00
}
2021-01-14 17:32:08 -08:00
// else // caused double-encoding of '&'
2015-04-11 12:33:21 -07:00
{
2021-01-14 17:32:08 -08:00
// $data = str_replace('&','&',$data);
// $data = str_replace('<','<',$data);
// $data = str_replace('>','>',$data);
// $data = str_replace('&','&',$data);
2020-02-17 13:13:06 -08:00
2015-04-11 12:33:21 -07:00
}
2015-04-11 11:47:40 -07:00
2019-03-01 16:36:37 -08:00
2021-01-14 17:32:08 -08:00
if ( ! check_class ( $core_pref -> get ( 'post_html' , e_UC_MAINADMIN )))
2010-09-06 21:35:04 +00:00
{
2015-04-14 11:39:35 -07:00
$data = strip_tags ( $data ); // remove tags from cleaned html.
2021-01-14 17:32:08 -08:00
$data = str_replace ( array ( '[html]' , '[/html]' ), '' , $data );
2010-09-06 21:35:04 +00:00
}
2019-03-01 20:01:40 -08:00
2015-04-11 02:53:51 -07:00
// $data = html_entity_decode($data, ENT_QUOTES, 'utf-8'); // Prevent double-entities. Fix for [code] - see bb_code.php toDB();
2010-09-06 12:34:06 +00:00
}
2015-04-11 02:53:51 -07:00
2015-04-11 11:47:40 -07:00
2021-01-14 17:32:08 -08:00
if ( check_class ( $core_pref -> get ( 'post_html' ))) /*$core_pref->is('post_html') && XXX preformecd by cleanHtml() */
2010-02-12 16:37:42 +00:00
{
2015-04-14 11:39:35 -07:00
$no_encode = true ;
2010-02-12 16:37:42 +00:00
}
2019-03-02 10:07:07 -08:00
2017-01-29 11:08:43 -08:00
if ( $parm !== null && is_numeric ( $parm ) && ! check_class ( $core_pref -> get ( 'post_html' ), '' , $parm ))
2010-02-12 16:37:42 +00:00
{
2015-04-14 11:39:35 -07:00
$no_encode = false ;
2010-02-12 16:37:42 +00:00
}
2015-04-11 12:33:21 -07:00
2021-01-14 17:32:08 -08:00
if ( $no_encode === true && strpos ( $mod , 'no_html' ) === false )
2010-02-12 16:37:42 +00:00
{
$search = array ( '$' , '"' , " ' " , '\\' , '<?' );
$replace = array ( '$' , '"' , ''' , '\' , '<?' );
$ret = str_replace ( $search , $replace , $data );
2009-01-08 21:47:44 +00:00
}
2015-04-14 11:39:35 -07:00
else // add entities for everything. we want to save the code.
2009-01-03 22:32:54 +00:00
{
2015-04-12 19:45:55 -07:00
2019-04-01 12:27:03 -07:00
$search = array ( '>' , '<' );
$replace = array ( '>' , '<' );
$data = str_replace ( $search , $replace , $data ); // prevent &gt; etc.
2010-02-12 16:37:42 +00:00
$data = htmlspecialchars ( $data , ENT_QUOTES , 'UTF-8' );
$data = str_replace ( '\\' , '\' , $data );
$ret = preg_replace ( " /&#( \ d*?);/ " , " &# \\ 1; " , $data );
}
2019-03-02 10:07:07 -08:00
// XXX - php_bbcode has been deprecated.
2021-01-14 17:32:08 -08:00
if (( strpos ( $mod , 'no_php' ) !== false ) || ! check_class ( $core_pref -> get ( 'php_bbcode' )))
2010-02-12 16:37:42 +00:00
{
2010-09-06 21:35:04 +00:00
$ret = preg_replace ( " # \ [(php)#i " , " [ \\ 1 " , $ret );
2006-12-02 04:36:16 +00:00
}
2010-02-19 15:10:40 +00:00
2017-01-29 08:42:18 -08:00
// Don't allow hooks to mess with prefs.
2017-01-29 09:47:33 -08:00
if ( $mod !== 'model' )
2017-01-29 08:42:18 -08:00
{
return $ret ;
}
/**
* e_parse hook
*/
$eParseList = $core_pref -> get ( 'e_parse_list' );
if ( ! empty ( $eParseList ))
{
$opts = array (
2021-01-14 17:32:08 -08:00
'nostrip' => $nostrip ,
'noencode' => $no_encode ,
'type' => $parm [ 'type' ],
'field' => $parm [ 'field' ]
2017-01-29 08:42:18 -08:00
);
foreach ( $eParseList as $plugin )
{
$hookObj = e107 :: getAddon ( $plugin , 'e_parse' );
if ( $tmp = e107 :: callMethod ( $hookObj , 'toDB' , $ret , $opts ))
{
$ret = $tmp ;
}
}
}
2006-12-02 04:36:16 +00:00
return $ret ;
}
2007-01-12 21:05:20 +00:00
2010-12-18 22:55:27 +00:00
/**
2021-01-14 17:32:08 -08:00
* Check for umatched 'dangerous' HTML tags
* ( these can destroy page layout where users are able to post HTML )
* @ param string $data
* @ param string $tagList - if empty , uses default list of input tags . Otherwise a CSV list of tags to check ( any type )
2010-12-18 22:55:27 +00:00
*
2021-01-14 17:32:08 -08:00
* @ return boolean TRUE if an unopened closing tag found
* FALSE if nothing found
* @ deprecated
2010-12-18 22:55:27 +00:00
*/
2020-12-14 16:21:48 -08:00
public function htmlAbuseFilter ( $data , $tagList = '' )
2010-12-18 22:55:27 +00:00
{
2021-01-14 17:32:08 -08:00
trigger_error ( '<b>' . __METHOD__ . ' is deprecated. Use $tp->cleanHtml() instead.</b>' , E_USER_WARNING ); // NO LAN
2021-01-14 14:46:49 -08:00
return $data ;
2010-12-18 22:55:27 +00:00
}
2010-09-06 12:34:06 +00:00
/**
2021-01-14 14:46:49 -08:00
* @ deprecated
2021-01-14 17:32:08 -08:00
* Checks a string for potentially dangerous HTML tags , including malformed tags
2010-09-06 12:34:06 +00:00
*
*/
2021-01-14 17:32:08 -08:00
public function dataFilter ( $data , $mode = 'bbcode' )
2010-09-06 12:34:06 +00:00
{
2021-01-14 17:32:08 -08:00
2021-01-14 14:46:49 -08:00
trigger_error ( '$tp->dateFilter() is deprecated. Use $tp->filter() instead.' , E_USER_WARNING );
2021-01-14 17:32:08 -08:00
2021-01-14 14:46:49 -08:00
return $data ;
2011-05-28 16:23:40 +00:00
}
2010-09-06 12:34:06 +00:00
/**
2021-01-14 17:32:08 -08:00
* Processes data as needed before its written to the DB .
* Currently gives bbcodes the opportunity to do something
2010-09-06 12:34:06 +00:00
*
2021-01-14 17:32:08 -08:00
* @ param $data string - data about to be written to DB
* @ return string - modified data
2010-09-06 12:34:06 +00:00
*/
public function preFilter ( $data )
{
2021-01-14 17:32:08 -08:00
2021-01-14 14:46:49 -08:00
if ( ! $this -> isBBcode ( $data ))
2010-09-06 12:34:06 +00:00
{
2021-01-14 14:46:49 -08:00
return $data ;
2010-09-06 12:34:06 +00:00
}
2021-01-14 14:46:49 -08:00
2021-01-14 17:32:08 -08:00
return e107 :: getBB () -> parseBBCodes ( $data , defset ( 'USERID' ), 'default' , 'PRE' ); // $postID = logged in user here
2010-09-06 12:34:06 +00:00
}
2021-02-02 16:06:17 -08:00
/**
* Takes a multi - dimensional array and converts the keys to a list of routing paths .
* paths are the key and value are the top most key .
* @ param array $array
* @ return false | array
*/
public function toRoute ( $array )
{
$res = $this -> _processRoute ( $array );
$tmp = explode ( " _#_ " , $res );
$ret = [];
foreach ( $tmp as $v )
{
list ( $k ) = explode ( '/' , $v );
$ret [ $v ] = $k ;
}
return $ret ;
}
private function _processRoute ( $array , $prefix = '' )
{
$text = [];
if ( is_array ( $array ))
{
foreach ( $array as $key => $val )
{
if ( $tag = $this -> _processRoute ( $val , $key . '/' ))
{
$add = $tag ;
}
else
{
$add = $key ;
}
$text [] = $prefix . $add ;
}
}
return implode ( '_#_' , $text );
}
2020-12-14 16:21:48 -08:00
public function toForm ( $text )
2006-12-02 04:36:16 +00:00
{
2015-04-11 02:53:51 -07:00
2010-10-30 15:34:48 +00:00
if ( empty ( $text )) // fix - handle proper 0, Space etc values.
2009-10-30 19:57:28 +00:00
{
2010-10-30 15:34:48 +00:00
return $text ;
2009-10-30 19:57:28 +00:00
}
2015-04-11 02:53:51 -07:00
2020-12-14 16:21:48 -08:00
if ( is_string ( $text ) && strpos ( $text , '[html]' ) === 0 )
2015-04-11 02:53:51 -07:00
{
2019-02-26 12:22:36 -08:00
// $text = $this->toHTML($text,true);
2021-01-14 17:32:08 -08:00
$search = array ( '"' , ''' , '\' , '&' ,); // '&' must be last.
$replace = array ( '"' , " ' " , " \\ " , '&' );
2015-04-11 11:47:40 -07:00
2021-01-14 17:32:08 -08:00
// return htmlspecialchars_decode($text);
$text = str_replace ( $search , $replace , $text );
// return $text;
2015-04-11 02:53:51 -07:00
//$text = htmlentities($text,ENT_NOQUOTES, "UTF-8");
2021-01-14 17:32:08 -08:00
// return $text;
2015-04-11 02:53:51 -07:00
}
2021-01-14 17:32:08 -08:00
// return htmlentities($text);
2015-04-11 02:53:51 -07:00
2018-07-24 15:52:34 -07:00
$search = array ( '$' , '"' , '<' , '>' , '+' );
$replace = array ( '$' , '"' , '<' , '>' , '%2B' );
2006-12-02 04:36:16 +00:00
$text = str_replace ( $search , $replace , $text );
2021-01-14 18:30:32 -08:00
if ( is_string ( $text ) && e107 :: wysiwyg () !== true )
2009-01-03 22:32:54 +00:00
{
2009-10-30 19:57:28 +00:00
// fix for utf-8 issue with html_entity_decode(); ???
2016-11-11 17:48:46 -08:00
$text = urldecode ( $text );
2021-01-14 17:32:08 -08:00
// $text = str_replace(" ", " ", $text);
2006-12-02 04:36:16 +00:00
}
2021-01-14 17:32:08 -08:00
2006-12-02 04:36:16 +00:00
return $text ;
}
2021-01-14 18:30:32 -08:00
/**
* @ param $text
* @ return array | string
*/
2020-12-14 16:21:48 -08:00
public function post_toForm ( $text )
2009-01-03 22:32:54 +00:00
{
2021-01-14 17:32:08 -08:00
2009-10-20 14:47:05 +00:00
if ( is_array ( $text ))
{
2021-01-14 18:30:32 -08:00
$arr = array ();
2021-01-14 17:32:08 -08:00
foreach ( $text as $key => $value )
2009-10-20 14:47:05 +00:00
{
2021-01-14 18:30:32 -08:00
$key = $this -> post_toForm ( $key );
$arr [ $key ] = $this -> post_toForm ( $value );
2009-10-20 14:47:05 +00:00
}
2021-01-14 17:32:08 -08:00
2021-01-14 18:30:32 -08:00
return $arr ;
2009-10-20 14:47:05 +00:00
}
2021-01-14 18:30:32 -08:00
2021-01-14 17:32:08 -08:00
if ( MAGIC_QUOTES_GPC == true )
2009-01-03 22:32:54 +00:00
{
2006-12-02 04:36:16 +00:00
$text = stripslashes ( $text );
}
2021-01-14 17:32:08 -08:00
2020-12-14 16:21:48 -08:00
return str_replace ( array ( " ' " , '"' , '<' , '>' ), array ( ''' , '"' , '<' , '>' ), $text );
2006-12-02 04:36:16 +00:00
}
2021-01-14 17:32:08 -08:00
public function post_toHTML ( $text , $original_author = false , $extra = '' , $mod = false )
2009-01-03 22:32:54 +00:00
{
2021-01-14 17:32:08 -08:00
$text = $this -> toDB ( $text , false , false , $mod , $original_author );
return $this -> toHTML ( $text , true , $extra );
2006-12-02 04:36:16 +00:00
}
2014-08-17 20:53:44 -07:00
/**
2015-02-15 02:37:36 -08:00
* @ param $text - template to parse .
2014-08-17 20:53:44 -07:00
* @ param boolean $parseSCFiles - parse core 'single' shortcodes
2016-05-24 11:08:22 -07:00
* @ param object | array $extraCodes - shortcode class containing sc_xxxxx methods or an array of key / value pairs or legacy shortcode content ( eg . content within . sc )
2015-02-15 02:37:36 -08:00
* @ param object $eVars - XXX more info needed .
* @ return string
2014-08-17 20:53:44 -07:00
*/
2020-12-14 16:21:48 -08:00
public function parseTemplate ( $text , $parseSCFiles = true , $extraCodes = null , $eVars = null )
2009-01-03 22:32:54 +00:00
{
2015-06-19 09:52:29 -07:00
2016-02-29 15:13:32 -08:00
if ( ! is_bool ( $parseSCFiles ))
{
2020-12-14 16:21:48 -08:00
trigger_error ( '$parseSCFiles in parseTemplate() was given incorrect data' );
2016-02-29 15:13:32 -08:00
}
2010-04-25 15:04:53 +00:00
return e107 :: getScParser () -> parseCodes ( $text , $parseSCFiles , $extraCodes , $eVars );
2006-12-02 04:36:16 +00:00
}
2020-12-08 07:29:17 -08:00
2010-02-27 18:59:57 +00:00
/**
* Simple parser
*
* @ param string $template
2014-07-09 16:32:17 +03:00
* @ param e_vars | array $vars
2010-02-27 18:59:57 +00:00
* @ param string $replaceUnset string to be used if replace variable is not set , false - don ' t replace
* @ return string parsed content
*/
2021-01-14 17:32:08 -08:00
public function simpleParse ( $template , $vars , $replaceUnset = '' )
2010-01-23 03:25:31 +00:00
{
2021-01-14 17:32:08 -08:00
2010-01-23 03:25:31 +00:00
$this -> replaceVars = $vars ;
$this -> replaceUnset = $replaceUnset ;
2021-01-14 17:32:08 -08:00
2021-01-14 18:30:32 -08:00
return preg_replace_callback ( " # \ { ([ \ w]+) \ }# " , array ( $this , 'simpleReplace' ), $template );
2010-01-23 03:25:31 +00:00
}
2010-02-19 15:10:40 +00:00
2021-01-14 14:46:49 -08:00
2021-01-14 17:32:08 -08:00
protected function simpleReplace ( $tmp )
2012-12-02 17:30:41 -08:00
{
2016-02-15 19:59:47 -08:00
2010-02-03 11:06:31 +00:00
$unset = ( $this -> replaceUnset !== false ? $this -> replaceUnset : $tmp [ 0 ]);
2016-02-15 19:59:47 -08:00
2012-12-02 19:10:07 -08:00
if ( is_array ( $this -> replaceVars ))
{
2021-01-14 17:32:08 -08:00
$this -> replaceVars = new e_vars ( $this -> replaceVars );
2014-07-09 16:32:17 +03:00
//return ($this->replaceVars[$key] !== null ? $this->replaceVars[$key]: $unset);
}
2016-02-15 19:59:47 -08:00
$key = $tmp [ 1 ]; // PHP7 fix.
2021-01-14 17:32:08 -08:00
2021-01-08 17:00:23 -08:00
return ( ! empty ( $this -> replaceVars ) && ( $this -> replaceVars -> $key !== null )) ? $this -> replaceVars -> $key : $unset ; // Doesn't work.
2010-01-23 03:25:31 +00:00
}
2010-02-19 15:10:40 +00:00
2021-01-14 14:46:49 -08:00
/**
* @ param $str
* @ param $width
* @ param string $break
* @ param string $nobreak
* @ param string $nobr
* @ param false $utf
* @ return string
2021-01-14 17:32:08 -08:00
* @ todo find a modern replacement
2021-01-14 14:46:49 -08:00
*/
2021-01-14 17:32:08 -08:00
public function htmlwrap ( $str , $width , $break = " \n " , $nobreak = 'a' , $nobr = 'pre' , $utf = false )
2006-12-02 04:36:16 +00:00
{
2021-01-14 17:32:08 -08:00
2006-12-02 04:36:16 +00:00
/*
2008-02-25 22:15:24 +00:00
Pretty well complete rewrite to try and handle utf - 8 properly .
2008-09-04 19:50:18 +00:00
Breaks each utf - 8 'word' every $width characters max . If possible , breaks after 'safe' characters .
2008-02-25 22:15:24 +00:00
$break is the character inserted to flag the break .
2008-09-04 19:50:18 +00:00
$nobreak is a list of tags within which word wrap is to be inactive
2006-12-02 04:36:16 +00:00
*/
2009-08-08 14:14:39 +00:00
//TODO handle htmlwrap somehow
2010-11-15 09:03:54 +00:00
//return $str;
2009-01-03 22:32:54 +00:00
2009-08-08 14:14:39 +00:00
// Don't wrap if non-numeric width
2021-01-14 17:32:08 -08:00
$width = ( int ) $width ;
2009-08-08 14:14:39 +00:00
// And trap stupid wrap counts
2021-01-14 17:32:08 -08:00
if ( $width < 6 )
2020-12-14 16:21:48 -08:00
{
2009-08-08 14:14:39 +00:00
return $str ;
2020-12-14 16:21:48 -08:00
}
2009-01-08 21:47:44 +00:00
2009-01-03 22:32:54 +00:00
// Transform protected element lists into arrays
2020-12-14 16:21:48 -08:00
$nobreak = explode ( ' ' , strtolower ( $nobreak ));
2009-01-08 21:47:44 +00:00
2009-01-03 22:32:54 +00:00
// Variable setup
2020-12-08 07:29:17 -08:00
2009-01-03 22:32:54 +00:00
$innbk = array ();
2020-12-14 16:21:48 -08:00
$drain = '' ;
2009-01-08 21:47:44 +00:00
2009-01-03 22:32:54 +00:00
// List of characters it is "safe" to insert line-breaks at
// It is not necessary to add < and > as they are automatically implied
$lbrks = " /?!%)-}] \\ \" ':;& " ;
2009-01-08 21:47:44 +00:00
2009-01-03 22:32:54 +00:00
// Is $str a UTF8 string?
2021-01-14 17:32:08 -08:00
if ( $utf || strtolower ( CHARSET ) === 'utf-8' )
2009-08-08 14:14:39 +00:00
{
// 0x1680, 0x180e, 0x2000-0x200a, 0x2028, 0x205f, 0x3000 are 'non-ASCII' Unicode UCS-4 codepoints - see http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
2009-01-03 22:32:54 +00:00
// All convert to 3-byte utf-8 sequences:
// 0x1680 0xe1 0x9a 0x80
// 0x180e 0xe1 0xa0 0x8e
// 0x2000 0xe2 0x80 0x80
// -
// 0x200a 0xe2 0x80 0x8a
// 0x2028 0xe2 0x80 0xa8
// 0x205f 0xe2 0x81 0x9f
// 0x3000 0xe3 0x80 0x80
$utf8 = 'u' ;
$whiteSpace = '#([\x20|\x0c]|[\xe1][\x9a][\x80]|[\xe1][\xa0][\x8e]|[\xe2][\x80][\x80-\x8a,\xa8]|[\xe2][\x81][\x9f]|[\xe3][\x80][\x80]+)#' ;
// Have to explicitly enumerate the whitespace chars, and use non-utf-8 mode, otherwise regex fails on badly formed utf-8
}
else
{
$utf8 = '' ;
2009-08-08 14:14:39 +00:00
// For non-utf-8, can use a simple match string
$whiteSpace = '#(\s+)#' ;
2009-01-03 22:32:54 +00:00
}
2009-01-08 21:47:44 +00:00
2009-01-03 22:32:54 +00:00
// Start of the serious stuff - split into HTML tags and text between
2021-01-14 17:32:08 -08:00
$content = preg_split ( '#(<.*?' . '>)#mis' , $str , - 1 , PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
2009-01-03 22:32:54 +00:00
foreach ( $content as $value )
{
2021-01-14 17:32:08 -08:00
if ( $value [ 0 ] === '<' )
2009-08-08 14:14:39 +00:00
{
// We are within an HTML tag
// Create a lowercase copy of this tag's contents
2010-01-12 13:11:48 +00:00
$lvalue = strtolower ( substr ( $value , 1 , - 1 ));
2021-01-14 17:32:08 -08:00
if ( $lvalue )
2009-10-30 19:57:28 +00:00
{
// Tag of non-zero length
2009-08-08 14:14:39 +00:00
// If the first character is not a / then this is an opening tag
2021-01-14 17:32:08 -08:00
if ( $lvalue [ 0 ] !== '/' )
2008-02-25 22:15:24 +00:00
{
2009-08-08 14:14:39 +00:00
// Collect the tag name
preg_match ( " /^( \ w*?)( \ s| $ )/ " , $lvalue , $t );
// If this is a protected element, activate the associated protection flag
2009-10-30 19:57:28 +00:00
if ( in_array ( $t [ 1 ], $nobreak ))
2020-12-14 16:21:48 -08:00
{
2010-01-12 13:11:48 +00:00
array_unshift ( $innbk , $t [ 1 ]);
2020-12-14 16:21:48 -08:00
}
2009-08-08 14:14:39 +00:00
}
else
2009-10-30 19:57:28 +00:00
{
// Otherwise this is a closing tag
2009-08-08 14:14:39 +00:00
// If this is a closing tag for a protected element, unset the flag
2021-01-14 17:32:08 -08:00
if ( in_array ( substr ( $lvalue , 1 ), $nobreak ))
2009-08-08 14:14:39 +00:00
{
reset ( $innbk );
2021-01-14 17:32:08 -08:00
foreach ( $innbk as $key => $tag )
2009-08-08 14:14:39 +00:00
{
2021-01-14 17:32:08 -08:00
if ( substr ( $lvalue , 1 ) == $tag )
2009-08-08 14:14:39 +00:00
{
unset ( $innbk [ $key ]);
break ;
}
}
$innbk = array_values ( $innbk );
}
2008-02-25 22:15:24 +00:00
}
}
2009-08-08 14:14:39 +00:00
else
{
// Eliminate any empty tags altogether
$value = '' ;
}
// Else if we're outside any tags, and with non-zero length string...
2009-01-03 22:32:54 +00:00
}
2021-01-14 17:32:08 -08:00
elseif ( $value )
2009-08-08 14:14:39 +00:00
{
// If unprotected...
2021-01-14 17:32:08 -08:00
if ( ! count ( $innbk ))
2008-02-25 22:15:24 +00:00
{
2009-08-08 14:14:39 +00:00
// Use the ACK (006) ASCII symbol to replace all HTML entities temporarily
2020-12-14 16:21:48 -08:00
$value = str_replace ( " \x06 " , '' , $value );
2009-08-08 14:14:39 +00:00
preg_match_all ( " /&([a-z \ d] { 2,7}|# \ d { 2,5});/i " , $value , $ents );
$value = preg_replace ( " /&([a-z \ d] { 2,7}|# \ d { 2,5});/i " , " \x06 " , $value );
// echo "Found block length ".strlen($value).': '.substr($value,20).'<br />';
// Split at spaces - note that this will fail if presented with invalid utf-8 when doing the regex whitespace search
// $split = preg_split('#(\s)#'.$utf8, $value, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
2021-01-14 17:32:08 -08:00
$split = preg_split ( $whiteSpace , $value , - 1 , PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
2009-08-08 14:14:39 +00:00
$value = '' ;
2021-01-14 17:32:08 -08:00
foreach ( $split as $sp )
2009-08-08 14:14:39 +00:00
{
// echo "Split length ".strlen($sp).': '.substr($sp,20).'<br />';
$loopCount = 0 ;
2021-01-14 17:32:08 -08:00
while ( strlen ( $sp ) > $width )
2009-01-03 22:32:54 +00:00
{
2009-08-08 14:14:39 +00:00
// Enough characters that we may need to do something.
$pulled = '' ;
2021-01-14 17:32:08 -08:00
if ( $utf8 )
2009-01-03 22:32:54 +00:00
{
2009-08-08 14:14:39 +00:00
// Pull out a piece of the maximum permissible length
2021-01-14 17:32:08 -08:00
if ( preg_match ( '#^((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,' . $width . '})(.?).*#s' , $sp , $matches ) == 0 )
2009-08-08 14:14:39 +00:00
{
// Make any problems obvious for now
2021-01-14 17:32:08 -08:00
$value .= '[!<b>invalid utf-8: ' . $sp . '<b>!]' ;
2009-08-08 14:14:39 +00:00
$sp = '' ;
}
2021-01-14 17:32:08 -08:00
elseif ( empty ( $matches [ 2 ]))
2009-10-30 19:57:28 +00:00
{
// utf-8 length is less than specified - treat as a special case
2009-08-08 14:14:39 +00:00
$value .= $sp ;
$sp = '' ;
}
else
2009-10-30 19:57:28 +00:00
{
// Need to find somewhere to break the string
for ( $i = strlen ( $matches [ 1 ]) - 1 ; $i >= 0 ; $i -- )
2009-08-08 14:14:39 +00:00
{
2021-01-14 17:32:08 -08:00
if ( strpos ( $lbrks , $matches [ 1 ][ $i ]) !== false )
2020-12-14 16:21:48 -08:00
{
2009-10-30 19:57:28 +00:00
break ;
2020-12-14 16:21:48 -08:00
}
2009-08-08 14:14:39 +00:00
}
2009-10-30 19:57:28 +00:00
if ( $i < 0 )
{
// No 'special' break character found - break at the word boundary
2009-08-08 14:14:39 +00:00
$pulled = $matches [ 1 ];
}
else
{
2009-10-30 19:57:28 +00:00
$pulled = substr ( $sp , 0 , $i + 1 );
2009-08-08 14:14:39 +00:00
}
}
$loopCount ++ ;
2021-01-14 17:32:08 -08:00
if ( $loopCount > 20 )
2009-08-08 14:14:39 +00:00
{
// Make any problems obvious for now
2021-01-14 17:32:08 -08:00
$value .= '[!<b>loop count exceeded: ' . $sp . '</b>!]' ;
2009-08-08 14:14:39 +00:00
$sp = '' ;
}
2009-01-03 22:32:54 +00:00
}
else
{
2021-01-14 17:32:08 -08:00
for ( $i = min ( $width , strlen ( $sp )); $i > 0 ; $i -- )
2009-08-08 14:14:39 +00:00
{
// No speed advantage to defining match character
2021-01-14 17:32:08 -08:00
if ( strpos ( $lbrks , $sp [ $i - 1 ]) !== false )
2020-12-14 16:21:48 -08:00
{
2009-08-08 14:14:39 +00:00
break ;
2020-12-14 16:21:48 -08:00
}
2009-08-08 14:14:39 +00:00
}
2021-01-14 17:32:08 -08:00
if ( $i == 0 )
2009-08-08 14:14:39 +00:00
{
// No 'special' break boundary character found - break at the word boundary
2009-10-30 19:57:28 +00:00
$pulled = substr ( $sp , 0 , $width );
2009-08-08 14:14:39 +00:00
}
else
{
2009-10-30 19:57:28 +00:00
$pulled = substr ( $sp , 0 , $i );
2009-08-08 14:14:39 +00:00
}
2009-01-03 22:32:54 +00:00
}
2021-01-14 17:32:08 -08:00
if ( $pulled )
2009-01-03 22:32:54 +00:00
{
2021-01-14 17:32:08 -08:00
$value .= $pulled . $break ;
2009-08-08 14:14:39 +00:00
// Shorten $sp by whatever we've processed (will work even for utf-8)
2009-10-30 19:57:28 +00:00
$sp = substr ( $sp , strlen ( $pulled ));
2009-01-03 22:32:54 +00:00
}
}
2009-08-08 14:14:39 +00:00
// Add in any residue
$value .= $sp ;
2008-02-25 22:15:24 +00:00
}
2009-08-08 14:14:39 +00:00
// Put captured HTML entities back into the string
2021-01-14 17:32:08 -08:00
foreach ( $ents [ 0 ] as $ent )
2020-12-14 16:21:48 -08:00
{
2009-10-30 19:57:28 +00:00
$value = preg_replace ( " / \x06 / " , $ent , $value , 1 );
2020-12-14 16:21:48 -08:00
}
2008-02-25 22:15:24 +00:00
}
}
2009-01-03 22:32:54 +00:00
// Send the modified segment down the drain
$drain .= $value ;
}
2021-01-14 17:32:08 -08:00
2009-01-03 22:32:54 +00:00
// Return contents of the drain
2009-01-08 21:47:44 +00:00
return $drain ;
2006-12-02 04:36:16 +00:00
}
2010-01-12 13:11:48 +00:00
2021-01-18 07:40:17 -08:00
/**
* Universal text / bbcode / html truncate method .
* new in v2 . 3.1
* @ param $text
* @ param int $length
* @ param string $ending
*/
public function truncate ( $text , $length = 100 , $ending = '...' )
{
if ( $this -> isHtml ( $text ))
{
return $this -> html_truncate ( $text , $length , $ending );
}
if ( $this -> isBBcode ( $text ))
{
$text = $this -> toText ( $text );
}
return $this -> text_truncate ( $text , $length , $ending );
}
2010-01-09 13:17:45 +00:00
/**
2021-01-18 07:40:17 -08:00
* @ deprecated Soon to be made private . Use $tp -> truncate () instead .
2010-01-09 13:17:45 +00:00
* CakePHP ( tm ) : Rapid Development Framework ( http :// www . cakephp . org )
* Copyright 2005 - 2008 , Cake Software Foundation , Inc . ( http :// www . cakefoundation . org )
2010-01-12 13:11:48 +00:00
*
2010-01-09 13:17:45 +00:00
* Truncate a HTML string
*
* Cuts a string to the length of $length and adds the value of $ending if the text is longer than length .
2021-01-14 17:32:08 -08:00
* @ param string $text String to truncate .
2010-01-09 13:17:45 +00:00
* @ param integer $length Length of returned string , including ellipsis .
* @ param string $ending It will be used as Ending and appended to the trimmed string .
* @ param boolean $exact If false , $text will not be cut mid - word
* @ return string Trimmed string .
*/
2020-12-14 16:21:48 -08:00
public function html_truncate ( $text , $length = 100 , $ending = '...' , $exact = true )
2010-01-12 13:11:48 +00:00
{
2021-01-14 17:32:08 -08:00
2010-01-12 13:11:48 +00:00
if ( $this -> ustrlen ( preg_replace ( '/<.*?>/' , '' , $text )) <= $length )
2010-01-09 13:17:45 +00:00
{
return $text ;
}
$totalLength = 0 ;
$openTags = array ();
$truncate = '' ;
preg_match_all ( '/(<\/?([\w+]+)[^>]*>)?([^<>]*)/' , $text , $tags , PREG_SET_ORDER );
2010-01-12 13:11:48 +00:00
2010-01-09 13:17:45 +00:00
foreach ( $tags as $tag )
{
2020-12-20 11:50:10 -08:00
if ( ! $tag [ 2 ] || ! preg_match ( '/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/i' , $tag [ 2 ]))
2010-01-09 13:17:45 +00:00
{
2020-12-20 11:50:10 -08:00
if ( preg_match ( '/<[\w]+[^>]*>/' , $tag [ 0 ]))
2010-01-09 13:17:45 +00:00
{
array_unshift ( $openTags , $tag [ 2 ]);
}
2021-01-14 17:32:08 -08:00
elseif ( preg_match ( '/<\/([\w]+)[^>]*>/' , $tag [ 0 ], $closeTag ))
2010-01-09 13:17:45 +00:00
{
$pos = array_search ( $closeTag [ 1 ], $openTags );
if ( $pos !== false )
{
array_splice ( $openTags , $pos , 1 );
}
}
}
$truncate .= $tag [ 1 ];
2010-01-12 13:11:48 +00:00
$contentLength = $this -> ustrlen ( preg_replace ( '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i' , ' ' , $tag [ 3 ]));
2010-01-09 13:17:45 +00:00
if ( $contentLength + $totalLength > $length )
{
$left = $length - $totalLength ;
$entitiesLength = 0 ;
if ( preg_match_all ( '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i' , $tag [ 3 ], $entities , PREG_OFFSET_CAPTURE ))
{
foreach ( $entities [ 0 ] as $entity )
{
if ( $entity [ 1 ] + 1 - $entitiesLength <= $left )
{
$left -- ;
2010-01-12 13:11:48 +00:00
$entitiesLength += $this -> ustrlen ( $entity [ 0 ]);
2010-01-09 13:17:45 +00:00
}
else
{
break ;
}
}
}
2010-01-12 13:11:48 +00:00
$truncate .= $this -> usubstr ( $tag [ 3 ], 0 , $left + $entitiesLength );
2010-01-09 13:17:45 +00:00
break ;
}
2020-12-14 16:21:48 -08:00
$truncate .= $tag [ 3 ];
$totalLength += $contentLength ;
2010-01-09 13:17:45 +00:00
if ( $totalLength >= $length )
{
break ;
}
}
if ( ! $exact )
{
2010-01-12 13:11:48 +00:00
$spacepos = $this -> ustrrpos ( $truncate , ' ' );
2010-01-09 13:17:45 +00:00
if ( isset ( $spacepos ))
{
2010-01-12 13:11:48 +00:00
$bits = $this -> usubstr ( $truncate , $spacepos );
2010-01-09 13:17:45 +00:00
preg_match_all ( '/<\/([a-z]+)>/i' , $bits , $droppedTags , PREG_SET_ORDER );
if ( ! empty ( $droppedTags ))
{
foreach ( $droppedTags as $closingTag )
{
if ( ! in_array ( $closingTag [ 1 ], $openTags ))
{
array_unshift ( $openTags , $closingTag [ 1 ]);
}
}
}
2010-01-12 13:11:48 +00:00
$truncate = $this -> usubstr ( $truncate , 0 , $spacepos );
2010-01-09 13:17:45 +00:00
}
}
$truncate .= $ending ;
foreach ( $openTags as $tag )
{
$truncate .= '</' . $tag . '>' ;
}
2021-01-14 17:32:08 -08:00
2010-01-09 13:17:45 +00:00
return $truncate ;
}
2006-12-02 04:36:16 +00:00
2007-06-06 19:28:25 +00:00
2021-01-18 07:40:17 -08:00
2009-10-30 20:58:52 +00:00
/**
2021-01-18 07:40:17 -08:00
* @ deprecated for public use . Will be made private . Use $tp -> truncate () instead .
* Truncate a string of text to a maximum length $len append the string $more if it was truncated
* Uses current CHARSET for utf - 8 , returns $len characters rather than $len bytes
2009-10-30 20:58:52 +00:00
*
2021-01-18 07:40:17 -08:00
* @ param string $text string to process
* @ param integer $len length of characters to be truncated
* @ param string $more string which will be added if truncation
* @ return string Always returns text .
2009-10-30 20:58:52 +00:00
*/
2009-10-30 21:01:13 +00:00
public function text_truncate ( $text , $len = 200 , $more = ' ... ' )
2007-06-06 19:28:25 +00:00
{
2021-01-18 07:40:17 -08:00
2012-12-13 15:08:00 +02:00
if ( $this -> ustrlen ( $text ) <= $len )
2009-11-12 21:41:34 +00:00
{
2009-10-30 19:57:28 +00:00
return $text ;
2009-11-12 21:41:34 +00:00
}
2016-05-21 09:08:46 -07:00
2021-01-18 07:40:17 -08:00
if ( $this -> isBBcode ( $text ) || $this -> isHtml ( $text ))
{
$text = $this -> toText ( $text );
}
2021-01-14 17:32:08 -08:00
$text = html_entity_decode ( $text , ENT_QUOTES , 'utf-8' );
2016-05-21 09:08:46 -07:00
2017-03-31 19:04:34 -07:00
if ( function_exists ( 'mb_strimwidth' ))
{
return mb_strimwidth ( $text , 0 , $len , $more );
}
2021-01-14 17:32:08 -08:00
2017-03-31 19:04:34 -07:00
$ret = $this -> usubstr ( $text , 0 , $len );
2012-12-13 15:08:00 +02:00
2009-01-03 22:32:54 +00:00
// search for possible broken html entities
// - if an & is in the last 8 chars, removing it and whatever follows shouldn't hurt
// it should work for any characters encoding
2016-05-21 09:08:46 -07:00
2013-10-16 18:13:21 +03:00
$leftAmp = $this -> ustrrpos ( $this -> usubstr ( $ret , - 8 ), '&' );
2009-10-30 19:57:28 +00:00
if ( $leftAmp )
2009-11-12 21:41:34 +00:00
{
2013-10-16 18:13:21 +03:00
$ret = $this -> usubstr ( $ret , 0 , $this -> ustrlen ( $ret ) - 8 + $leftAmp );
2009-11-12 21:41:34 +00:00
}
2009-10-30 19:57:28 +00:00
2021-01-14 17:32:08 -08:00
return $ret . $more ;
2017-03-31 19:04:34 -07:00
2006-12-02 04:36:16 +00:00
}
2007-06-06 19:28:25 +00:00
2021-01-14 14:46:49 -08:00
public function textclean ( $text , $wrap = 100 )
2006-12-02 04:36:16 +00:00
{
2021-01-14 17:32:08 -08:00
2009-10-30 19:57:28 +00:00
$text = str_replace ( " \n \n \n " , " \n \n " , $text );
2008-12-30 13:51:41 +00:00
$text = $this -> htmlwrap ( $text , $wrap );
2009-10-30 19:57:28 +00:00
$text = str_replace ( array ( '<br /> ' , ' <br />' , ' <br /> ' ), '<br />' , $text );
2021-01-14 17:32:08 -08:00
2006-12-02 04:36:16 +00:00
/* we can remove any linebreaks added by htmlwrap function as any \n's will be converted later anyway */
2021-01-14 17:32:08 -08:00
2006-12-02 04:36:16 +00:00
return $text ;
}
2009-01-03 22:32:54 +00:00
2006-12-02 04:36:16 +00:00
// Test for text highlighting, and determine the text highlighting transformation
// Returns TRUE if highlighting is active for this page display
2020-12-14 16:21:48 -08:00
public function checkHighlighting ()
2006-12-02 04:36:16 +00:00
{
2021-01-14 17:32:08 -08:00
2006-12-02 04:36:16 +00:00
global $pref ;
2021-01-14 17:32:08 -08:00
if ( ! defined ( 'e_SELF' ))
2006-12-02 04:36:16 +00:00
{
2009-10-30 19:57:28 +00:00
// Still in startup, so can't calculate highlighting
2021-01-14 17:32:08 -08:00
return false ;
2006-12-02 04:36:16 +00:00
}
2009-10-30 19:57:28 +00:00
if ( ! isset ( $this -> e_highlighting ))
2006-12-02 04:36:16 +00:00
{
2021-01-14 17:32:08 -08:00
$this -> e_highlighting = false ;
2020-12-14 16:21:48 -08:00
$shr = ( isset ( $_SERVER [ 'HTTP_REFERER' ]) ? $_SERVER [ 'HTTP_REFERER' ] : '' );
2021-01-14 17:32:08 -08:00
if ( $pref [ 'search_highlight' ] && ( strpos ( e_SELF , 'search.php' ) === false ) && (( strpos ( $shr , 'q=' ) !== false ) || ( strpos ( $shr , 'p=' ) !== false )))
2006-12-02 04:36:16 +00:00
{
2021-01-14 17:32:08 -08:00
$this -> e_highlighting = true ;
2009-10-30 19:57:28 +00:00
if ( ! isset ( $this -> e_query ))
2006-12-02 04:36:16 +00:00
{
2020-12-08 07:29:17 -08:00
preg_match ( '#(q|p)=(.*?)(&|$)#' , $shr , $matches );
2009-10-30 19:57:28 +00:00
$this -> e_query = str_replace ( array ( '+' , '*' , '"' , ' ' ), array ( '' , '.*?' , '' , '\b|\b' ), trim ( urldecode ( $matches [ 2 ])));
2006-12-02 04:36:16 +00:00
}
}
}
2021-01-14 17:32:08 -08:00
2006-12-02 04:36:16 +00:00
return $this -> e_highlighting ;
}
2007-03-11 20:52:47 +00:00
2016-03-09 12:12:15 -08:00
/**
* Replace text represenation of website urls and email addresses with clickable equivalents .
* @ param string $text
* @ param string $type email | url
* @ param array $opts options . ( see below )
2021-01-14 17:32:08 -08:00
* @ param string $opts [ 'sub' ] substitute text within links
* @ param bool $opts [ 'ext' ] load link in new window ( not for email )
2016-03-09 12:12:15 -08:00
* @ return string
*/
2021-01-14 17:32:08 -08:00
public function makeClickable ( $text = '' , $type = 'email' , $opts = array ())
2016-03-09 12:12:15 -08:00
{
if ( empty ( $text ))
{
return '' ;
}
$textReplace = ( ! empty ( $opts [ 'sub' ])) ? $opts [ 'sub' ] : '' ;
2021-01-14 17:32:08 -08:00
if ( substr ( $textReplace , - 6 ) === '.glyph' )
2016-03-09 12:12:15 -08:00
{
2021-01-14 17:32:08 -08:00
$textReplace = $this -> toGlyph ( $textReplace , '' );
2016-03-09 12:12:15 -08:00
}
switch ( $type )
{
default :
2020-12-14 16:21:48 -08:00
case 'email' :
2016-03-09 12:12:15 -08:00
preg_match_all ( " #(?:[ \n \r ]|^)?([a-z0-9 \ -_.]+?)@([ \ w \ -]+ \ .([ \ w \ - \ .]+ \ .)*[ \ w]+)#i " , $text , $match );
if ( ! empty ( $match [ 0 ]))
{
$srch = array ();
$repl = array ();
foreach ( $match [ 0 ] as $eml )
{
$email = trim ( $eml );
$srch [] = $email ;
2021-01-14 17:32:08 -08:00
$repl [] = $this -> emailObfuscate ( $email , $textReplace );
2016-03-09 12:12:15 -08:00
}
2021-01-14 17:32:08 -08:00
$text = str_replace ( $srch , $repl , $text );
2016-03-09 12:12:15 -08:00
}
break ;
2020-12-14 16:21:48 -08:00
case 'url' :
2016-03-09 12:12:15 -08:00
2019-02-28 10:31:06 -08:00
$linktext = ( ! empty ( $textReplace )) ? $textReplace : '$3' ;
$external = ( ! empty ( $opts [ 'ext' ])) ? 'target="_blank"' : '' ;
2016-03-09 12:12:15 -08:00
2021-01-14 17:32:08 -08:00
$text = preg_replace ( " /(^|[ \n \ (])([ \ w]*?)([ \ w]*?: \ / \ /[ \ w]+[^ \ , \" \n \r \t <]*)/is " , '$1$2<a class="e-url" href="$3" ' . $external . '>' . $linktext . '</a>' , $text );
$text = preg_replace ( " /(^|[ \n \ (])([ \ w]*?)((www) \ .[^ \ , \" \t \n \r \ )<]*)/is " , '$1$2<a class="e-url" href="http://$3" ' . $external . '>' . $linktext . '</a>' , $text );
$text = preg_replace ( " /(^|[ \n ])([ \ w]*?)((ftp) \ .[^ \ , \" \t \n \r <]*)/is " , '$1$2<a class="e-url" href="$4://$3" ' . $external . '>' . $linktext . '</a>' , $text );
2016-03-09 12:12:15 -08:00
break ;
}
return $text ;
}
2017-12-27 12:28:29 -08:00
2020-12-14 16:21:48 -08:00
public function parseBBCodes ( $text , $postID )
2017-12-27 12:28:29 -08:00
{
2021-01-14 17:32:08 -08:00
2021-01-14 14:46:49 -08:00
return e107 :: getBB () -> parseBBCodes ( $text , $postID );
2017-12-27 12:28:29 -08:00
}
2021-01-23 14:20:51 -08:00
/**
* Strips block tags from html .
* ie . < p > < div > < blockquote > < h1 > < h2 > < h3 > etc are removed .
* @ param string $text
* @ return string
*/
public function stripBlockTags ( $html )
{
$diff = array_diff ( $this -> allowedTags , $this -> blockTags );
$parm = '' ;
foreach ( $diff as $tag )
{
$parm .= '<' . $tag . '>' ;
}
return strip_tags ( $html , $parm );
}
2017-12-27 12:28:29 -08:00
2009-10-30 09:13:37 +00:00
/**
2009-10-30 23:31:08 +00:00
* Converts the text ( presumably retrieved from the database ) for HTML output .
2009-10-30 19:57:28 +00:00
*
2009-10-30 09:13:37 +00:00
* @ param string $text
* @ param boolean $parseBB [ optional ]
* @ param string $modifiers [ optional ] TITLE | SUMMARY | DESCRIPTION | BODY | RAW | LINKTEXT etc .
2021-01-14 17:32:08 -08:00
* Comma - separated list , no spaces allowed
* first modifier must be a CONTEXT modifier , in UPPER CASE .
* subsequent modifiers are lower case - see $this -> e_Modifiers for possible values
2009-10-30 09:13:37 +00:00
* @ param mixed $postID [ optional ]
* @ param boolean $wrap [ optional ]
2009-10-30 20:05:17 +00:00
* @ return string
2009-11-12 21:41:34 +00:00
* @ todo complete the documentation of this essential method
2009-10-30 09:13:37 +00:00
*/
2021-01-14 17:32:08 -08:00
public function toHTML ( $text , $parseBB = false , $modifiers = '' , $postID = '' , $wrap = false )
2008-06-14 21:01:04 +00:00
{
2021-01-14 17:32:08 -08:00
2020-12-25 10:23:56 -08:00
if ( empty ( $text ) || ! is_string ( $text ))
2009-11-12 21:41:34 +00:00
{
2009-10-30 19:57:28 +00:00
return $text ;
2010-01-12 13:11:48 +00:00
}
2015-04-11 02:53:51 -07:00
2021-01-15 12:47:26 -08:00
if ( empty ( $this -> pref )) // cache the prefs.
{
$prefsUsed = array ( 'smiley_activate' , 'make_clickable' , 'link_replace' , 'main_wordwrap' , 'link_text' ,
'email_text' , 'links_new_window' , 'profanity_filter' , 'tohtml_hook' , 'e_tohtml_list' , 'e_parse_list'
);
$cfg = e107 :: getConfig ();
foreach ( $prefsUsed as $v )
{
$this -> pref [ $v ] = $cfg -> get ( $v );
}
}
2008-12-30 13:51:41 +00:00
2013-05-20 17:10:38 -07:00
global $fromadmin ;
2007-12-30 23:31:18 +00:00
2009-01-03 22:32:54 +00:00
// Set default modifiers to start
2021-01-15 10:59:52 -08:00
$opts = $this -> getModifiers ( $modifiers );
2006-12-02 04:36:16 +00:00
2017-03-26 13:03:58 -07:00
if ( $this -> isHtml ( $text )) //BC FIx for when HTML is saved without [html][/html]
2009-11-12 21:41:34 +00:00
{
2017-03-26 13:03:58 -07:00
$opts [ 'nobreak' ] = true ;
$text = trim ( $text );
2020-05-06 16:15:52 -07:00
2021-01-14 17:32:08 -08:00
if ( strpos ( $text , '[center]' ) === 0 ) // quick bc fix TODO Find a better solution. [center][/center] containing HTML.
{
$text = str_replace ( array ( '[center]' , '[/center]' ), array ( " <div style='text-align:center'> " , '</div>' ), $text );
}
2009-11-12 21:41:34 +00:00
}
2009-01-03 22:32:54 +00:00
$fromadmin = $opts [ 'fromadmin' ];
// Convert defines(constants) within text. eg. Lan_XXXX - must be the entire text string (i.e. not embedded)
2009-10-30 19:57:28 +00:00
// The check for '::' is a workaround for a bug in the Zend Optimiser 3.3.0 and PHP 5.2.4 combination
// - causes crashes if '::' in site name
2014-01-20 10:21:44 -08:00
2021-01-14 17:32:08 -08:00
if ( $opts [ 'defs' ] && ( strlen ( $text ) < 35 ) && (( strpos ( $text , '::' ) === false ) && defined ( trim ( $text ))))
2007-01-17 21:29:28 +00:00
{
2016-01-04 23:10:02 -08:00
$text = constant ( trim ( $text )); // don't return yet, words could be hooked with linkwords etc.
2006-12-02 04:36:16 +00:00
}
2021-01-14 17:32:08 -08:00
if ( $opts [ 'no_tags' ])
2009-01-03 22:32:54 +00:00
{
$text = strip_tags ( $text );
}
2021-01-15 10:59:52 -08:00
/*
2021-01-14 17:32:08 -08:00
if ( MAGIC_QUOTES_GPC === true ) // precaution for badly saved data.
2013-05-07 03:44:12 -07:00
{
$text = stripslashes ( $text );
}
2021-01-15 10:59:52 -08:00
*/
2007-01-17 21:29:28 +00:00
2009-01-03 22:32:54 +00:00
// $text = " ".$text;
2006-12-02 04:36:16 +00:00
2007-01-17 21:29:28 +00:00
2009-10-30 19:57:28 +00:00
// Now get on with the parsing
2009-01-03 22:32:54 +00:00
$ret_parser = '' ;
$last_bbcode = '' ;
2009-10-30 19:57:28 +00:00
// So we can change them on each loop
$saveOpts = $opts ;
2021-01-14 17:32:08 -08:00
if ( $parseBB == false )
2008-06-14 21:01:04 +00:00
{
2009-01-03 22:32:54 +00:00
$content = array ( $text );
2008-06-14 21:01:04 +00:00
}
else
2007-01-17 21:29:28 +00:00
{
2009-01-03 22:32:54 +00:00
// Split each text block into bits which are either within one of the 'key' bbcodes, or outside them
// (Because we have to match end words, the 'extra' capturing subpattern gets added to output array. We strip it later)
2021-01-14 17:32:08 -08:00
$content = preg_split ( '#(\[(table|html|php|code|scode|hide).*?\[/(?:\\2)\])#mis' , $text , - 1 , PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
2008-06-14 21:01:04 +00:00
}
2009-01-03 22:32:54 +00:00
// Use $full_text variable so its available to special bbcodes if required
2021-01-14 17:32:08 -08:00
foreach ( $content as $full_text )
2009-01-03 22:32:54 +00:00
{
2021-01-14 17:32:08 -08:00
$proc_funcs = true ;
$convertNL = true ;
2008-06-14 21:01:04 +00:00
2009-01-03 22:32:54 +00:00
// We may have 'captured' a bbcode word - strip it if so
2021-01-14 17:32:08 -08:00
if ( $last_bbcode == $full_text )
2009-01-03 22:32:54 +00:00
{
$last_bbcode = '' ;
2021-01-14 17:32:08 -08:00
$proc_funcs = false ;
2009-01-03 22:32:54 +00:00
$full_text = '' ;
2008-06-14 21:01:04 +00:00
}
else
2007-01-17 21:29:28 +00:00
{
2009-10-30 19:57:28 +00:00
// Set the options for this pass
2021-01-15 10:59:52 -08:00
2009-10-30 19:57:28 +00:00
$opts = $saveOpts ;
2009-01-30 20:39:03 +00:00
2009-10-30 19:57:28 +00:00
// Have to have a good test in case a 'non-key' bbcode starts the block
// - so pull out the bbcode parameters while we're there
2021-01-14 17:32:08 -08:00
if (( $parseBB !== false ) && preg_match ( '#(^\[(table|html|php|code|scode|hide)(.*?)\])(.*?)(\[/\\2\]$)#is' , $full_text , $matches ))
2009-10-30 19:57:28 +00:00
{
// It's one of the 'key' bbcodes
// Usually don't want 'normal' processing if its a 'special' bbcode
2021-01-14 17:32:08 -08:00
$proc_funcs = false ;
2009-01-03 22:32:54 +00:00
// $matches[0] - complete block from opening bracket of opening tag to closing bracket of closing tag
// $matches[1] - complete opening tag (inclusive of brackets)
// $matches[2] - bbcode word
// $matches[3] - parameter, including '='
// $matches[4] - bit between the tags (i.e. text to process)
// $matches[5] - closing tag
2009-10-30 19:57:28 +00:00
// In case we decide to load a file
2021-01-14 17:32:08 -08:00
2021-01-15 10:59:52 -08:00
// $bbPath = e_CORE . 'bbcodes/';
// $bbFile = strtolower(str_replace('_', '', $matches[2]));
// $bbcode = '';
// $className = '';
2021-01-14 17:32:08 -08:00
$full_text = '' ;
$code_text = $matches [ 4 ];
2021-01-15 10:59:52 -08:00
// $parm = $matches[3] ? substr($matches[3], 1) : '';
2021-01-14 17:32:08 -08:00
$last_bbcode = $matches [ 2 ];
switch ( $matches [ 2 ])
2009-01-03 22:32:54 +00:00
{
case 'php' :
2009-10-30 19:57:28 +00:00
2021-01-15 10:59:52 -08:00
$proc_funcs = false ;
$code_text = '' ;
2009-01-03 22:32:54 +00:00
break ;
2010-01-12 13:11:48 +00:00
2012-07-23 02:25:17 +00:00
case 'html' : // This overrides and deprecates html.bb
2021-01-14 17:32:08 -08:00
$proc_funcs = true ;
2015-04-11 02:53:51 -07:00
2016-04-17 12:49:15 -07:00
2021-01-14 17:32:08 -08:00
// $code_text = str_replace("\r\n", " ", $code_text);
// $code_text = html_entity_decode($code_text, ENT_QUOTES, CHARSET);
// $code_text = str_replace('&','&',$code_text); // validation safe.
2020-12-14 16:21:48 -08:00
$html_start = '<!-- bbcode-html-start -->' ; // markers for html-to-bbcode replacement.
2021-01-14 17:32:08 -08:00
$html_end = '<!-- bbcode-html-end -->' ;
$full_text = str_replace ( array ( '[html]' , '[/html]' ), '' , $code_text ); // quick fix.. security issue?
2017-12-27 12:28:29 -08:00
$full_text = $this -> parseBBCodes ( $full_text , $postID ); // parse any embedded bbcodes eg. [img]
2021-01-14 17:32:08 -08:00
$full_text = $this -> replaceConstants ( $full_text , 'abs' ); // parse any other paths using {e_....
$full_text = $html_start . $full_text . $html_end ;
2013-03-18 22:14:05 -07:00
$full_text = $this -> parseBBTags ( $full_text ); // strip <bbcode> tags.
2013-03-23 03:49:49 -07:00
$opts [ 'nobreak' ] = true ;
2017-12-27 12:28:29 -08:00
$parseBB = false ; // prevent further bbcode processing.
2015-04-11 02:53:51 -07:00
2009-01-30 20:39:03 +00:00
break ;
2015-04-11 02:53:51 -07:00
2013-06-14 16:26:56 -07:00
case 'table' : // strip <br /> from inside of <table>
2021-01-14 17:32:08 -08:00
$convertNL = false ;
2012-06-09 12:01:24 +00:00
// break;
2010-01-12 13:11:48 +00:00
2009-01-03 22:32:54 +00:00
case 'hide' :
2021-01-14 17:32:08 -08:00
$proc_funcs = true ;
2010-01-12 13:11:48 +00:00
2021-01-15 10:59:52 -08:00
case 'scode' :
case 'code' :
$parseBB = false ;
2021-01-18 10:27:41 -08:00
$full_text = $this -> parseBBCodes ( '[' . $last_bbcode . ']' . $code_text . '[/' . $last_bbcode . ']' , $postID );
2021-01-15 10:59:52 -08:00
break ;
2009-01-03 22:32:54 +00:00
}
2021-01-15 10:59:52 -08:00
2008-06-14 21:01:04 +00:00
}
2009-01-03 22:32:54 +00:00
}
2006-12-02 04:36:16 +00:00
2007-01-17 21:29:28 +00:00
2009-10-30 19:57:28 +00:00
// Do the 'normal' processing - in principle, as previously - but think about the order.
2021-01-14 17:32:08 -08:00
if ( $proc_funcs && ! empty ( $full_text )) // some more speed
2009-10-30 19:57:28 +00:00
{
2009-01-03 22:32:54 +00:00
// Split out and ignore any scripts and style blocks. With just two choices we can match the closing tag in the regex
2021-01-14 17:32:08 -08:00
$subcon = preg_split ( '#((?:<s)(?:cript[^>]+>.*?</script>|tyle[^>]+>.*?</style>))#mis' , $full_text , - 1 , PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
foreach ( $subcon as $sub_blk )
2008-06-14 21:01:04 +00:00
{
2017-01-29 08:42:18 -08:00
2021-01-14 17:32:08 -08:00
if ( strpos ( $sub_blk , '<script' ) === 0 ) // Strip scripts unless permitted
2009-01-03 22:32:54 +00:00
{
2009-10-30 19:57:28 +00:00
if ( $opts [ 'scripts' ])
2009-01-03 22:32:54 +00:00
{
2016-04-17 12:49:15 -07:00
$ret_parser .= html_entity_decode ( $sub_blk , ENT_QUOTES );
2009-01-03 22:32:54 +00:00
}
}
2021-01-14 17:32:08 -08:00
elseif ( strpos ( $sub_blk , '<style' ) === 0 )
2009-10-30 19:57:28 +00:00
{
// Its a style block - just pass it through unaltered - except, do we need the line break stuff? - QUERY XXX-01
2015-03-29 20:26:35 -07:00
if ( defined ( 'DB_INF_SHOW' ))
2009-11-12 21:41:34 +00:00
{
2009-10-30 19:57:28 +00:00
echo " Processing stylesheet: { $sub_blk } <br /> " ;
2009-11-12 21:41:34 +00:00
}
2015-03-29 20:26:35 -07:00
2009-01-03 22:32:54 +00:00
$ret_parser .= $sub_blk ;
}
else
{
// Do 'normal' processing on a chunk
2009-01-08 21:47:44 +00:00
2009-01-03 22:32:54 +00:00
// Could put tag stripping in here
2021-01-14 17:32:08 -08:00
/*
// Line break compression - filter white space after HTML tags - among other things, ensures HTML tables display properly
// Hopefully now achieved by other means
if ( $convertNL && ! $opts [ 'nobreak' ])
{
$sub_blk = preg_replace ( " #> \ s*[ \r ]* \n [ \r ]*# " , " > " , $sub_blk );
}
*/
2009-01-08 21:47:44 +00:00
2009-01-03 22:32:54 +00:00
// Link substitution
// Convert URL's to clickable links, unless modifiers or prefs override
2021-01-15 13:20:38 -08:00
$sub_blk = $this -> processModifiers ( $opts , $sub_blk , $convertNL , $parseBB , $modifiers , $postID );
2008-06-14 21:01:04 +00:00
2009-01-03 22:32:54 +00:00
$ret_parser .= $sub_blk ;
2021-01-14 17:32:08 -08:00
} // End of 'normal' processing for a block of text
2006-12-02 04:36:16 +00:00
2021-01-14 17:32:08 -08:00
} // End of 'foreach() on each block of non-script text
2008-06-14 21:01:04 +00:00
2021-01-14 17:32:08 -08:00
} // End of 'normal' parsing (non-script text)
2009-01-03 22:32:54 +00:00
else
{
2009-10-30 19:57:28 +00:00
// Text block that needed no processing at all
$ret_parser .= $full_text ;
2009-01-03 22:32:54 +00:00
}
2008-06-14 21:01:04 +00:00
}
2013-06-14 16:26:56 -07:00
// Quick Fix - Remove trailing <br /> on block-level elements (eg. div, pre, table, etc. )
$srch = array ();
$repl = array ();
2021-01-14 17:32:08 -08:00
2013-06-14 16:26:56 -07:00
foreach ( $this -> blockTags as $val )
{
2021-01-14 17:32:08 -08:00
$srch [] = '</' . $val . '><br />' ;
$repl [] = '</' . $val . '>' ;
2013-06-14 16:26:56 -07:00
}
2021-01-14 17:32:08 -08:00
2013-06-14 16:26:56 -07:00
$ret_parser = str_replace ( $srch , $repl , $ret_parser );
2009-01-03 22:32:54 +00:00
return trim ( $ret_parser );
2006-12-02 04:36:16 +00:00
}
2015-04-29 10:22:46 -07:00
2017-01-28 17:34:47 -08:00
/**
* Check if a string begins with a preformatter flag .
* @ param $str
* @ return bool
*/
private function preformatted ( $str )
{
2021-01-14 17:32:08 -08:00
2017-01-28 17:34:47 -08:00
foreach ( $this -> preformatted as $type )
{
2021-01-14 17:32:08 -08:00
$code = '[' . $type . ']' ;
2017-01-28 17:34:47 -08:00
if ( strpos ( $str , $code ) === 0 )
{
return true ;
}
}
return false ;
}
2020-03-24 13:57:05 -07:00
/**
* @ param $mixed
* @ return array | false | string
*/
public function toUTF8 ( $mixed )
{
2017-01-28 17:34:47 -08:00
2020-03-24 13:57:05 -07:00
if ( is_array ( $mixed ))
{
foreach ( $mixed as $k => $v )
{
unset ( $mixed [ $k ]);
$mixed [ $this -> toUTF8 ( $k )] = $this -> toUTF8 ( $v );
}
}
elseif ( is_object ( $mixed ))
{
$objVars = get_object_vars ( $mixed );
foreach ( $objVars as $key => $value )
{
$mixed -> $key = $this -> toUTF8 ( $value );
}
}
elseif ( is_string ( $mixed ))
{
return iconv ( 'UTF-8' , 'UTF-8//IGNORE' , utf8_encode ( $mixed ));
}
return $mixed ;
}
2017-01-28 17:34:47 -08:00
2020-12-14 16:21:48 -08:00
public function toASCII ( $text )
2016-12-08 07:24:31 -08:00
{
2016-12-08 08:21:58 -08:00
$char_map = array (
// Latin
'À' => 'A' , 'Á' => 'A' , 'Â' => 'A' , 'Ã' => 'A' , 'Ä' => 'A' , 'Å' => 'A' , 'Æ' => 'AE' , 'Ç' => 'C' ,
'È' => 'E' , 'É' => 'E' , 'Ê' => 'E' , 'Ë' => 'E' , 'Ì' => 'I' , 'Í' => 'I' , 'Î' => 'I' , 'Ï' => 'I' ,
'Ð' => 'D' , 'Ñ' => 'N' , 'Ò' => 'O' , 'Ó' => 'O' , 'Ô' => 'O' , 'Õ' => 'O' , 'Ö' => 'O' , 'Ő' => 'O' ,
'Ø' => 'O' , 'Ù' => 'U' , 'Ú' => 'U' , 'Û' => 'U' , 'Ü' => 'U' , 'Ű' => 'U' , 'Ý' => 'Y' , 'Þ' => 'TH' ,
'ß' => 'ss' ,
'à' => 'a' , 'á' => 'a' , 'â' => 'a' , 'ã' => 'a' , 'ä' => 'a' , 'å' => 'a' , 'æ' => 'ae' , 'ç' => 'c' ,
'è' => 'e' , 'é' => 'e' , 'ê' => 'e' , 'ë' => 'e' , 'ì' => 'i' , 'í' => 'i' , 'î' => 'i' , 'ï' => 'i' ,
'ð' => 'd' , 'ñ' => 'n' , 'ò' => 'o' , 'ó' => 'o' , 'ô' => 'o' , 'õ' => 'o' , 'ö' => 'o' , 'ő' => 'o' ,
'ø' => 'o' , 'ù' => 'u' , 'ú' => 'u' , 'û' => 'u' , 'ü' => 'u' , 'ű' => 'u' , 'ý' => 'y' , 'þ' => 'th' ,
'ÿ' => 'y' ,
// Latin symbols
'©' => '(c)' ,
// Greek
'Α ' => 'A' , 'Β ' => 'B' , 'Γ' => 'G' , 'Δ' => 'D' , 'Ε ' => 'E' , 'Ζ ' => 'Z' , 'Η ' => 'H' , 'Θ' => '8' ,
'Ι ' => 'I' , 'Κ ' => 'K' , 'Λ' => 'L' , 'Μ ' => 'M' , 'Ν ' => 'N' , 'Ξ' => '3' , 'Ο ' => 'O' , 'Π' => 'P' ,
'Ρ ' => 'R' , 'Σ' => 'S' , 'Τ ' => 'T' , 'Υ ' => 'Y' , 'Φ' => 'F' , 'Χ ' => 'X' , 'Ψ' => 'PS' , 'Ω' => 'W' ,
'Ά' => 'A' , 'Έ' => 'E' , 'Ί' => 'I' , 'Ό' => 'O' , 'Ύ' => 'Y' , 'Ή' => 'H' , 'Ώ' => 'W' , 'Ϊ' => 'I' ,
'Ϋ' => 'Y' ,
'α ' => 'a' , 'β' => 'b' , 'γ ' => 'g' , 'δ' => 'd' , 'ε' => 'e' , 'ζ' => 'z' , 'η' => 'h' , 'θ' => '8' ,
'ι ' => 'i' , 'κ' => 'k' , 'λ' => 'l' , 'μ' => 'm' , 'ν ' => 'n' , 'ξ' => '3' , 'ο ' => 'o' , 'π' => 'p' ,
'ρ ' => 'r' , 'σ ' => 's' , 'τ' => 't' , 'υ ' => 'y' , 'φ' => 'f' , 'χ' => 'x' , 'ψ' => 'ps' , 'ω' => 'w' ,
'ά' => 'a' , 'έ' => 'e' , 'ί' => 'i' , 'ό' => 'o' , 'ύ' => 'y' , 'ή' => 'h' , 'ώ' => 'w' , 'ς' => 's' ,
'ϊ' => 'i' , 'ΰ' => 'y' , 'ϋ' => 'y' , 'ΐ' => 'i' ,
// Turkish
2021-01-14 17:32:08 -08:00
'Ş' => 'S' , 'İ' => 'I' , /*'Ç' => 'C', 'Ü' => 'U', 'Ö' => 'O',*/
'Ğ' => 'G' ,
'ş' => 's' , 'ı ' => 'i' , /*'ç' => 'c', 'ü' => 'u', 'ö' => 'o',*/
'ğ' => 'g' ,
2016-12-08 08:21:58 -08:00
// Russian
'А ' => 'A' , 'Б' => 'B' , 'В ' => 'V' , 'Г' => 'G' , 'Д' => 'D' , 'Е ' => 'E' , 'Ё' => 'Yo' , 'Ж' => 'Zh' ,
'З ' => 'Z' , 'И' => 'I' , 'Й' => 'J' , 'К ' => 'K' , 'Л' => 'L' , 'М ' => 'M' , 'Н ' => 'N' , 'О ' => 'O' ,
'П' => 'P' , 'Р ' => 'R' , 'С ' => 'S' , 'Т ' => 'T' , 'У ' => 'U' , 'Ф' => 'F' , 'Х ' => 'H' , 'Ц' => 'C' ,
'Ч' => 'Ch' , 'Ш' => 'Sh' , 'Щ' => 'Sh' , 'Ъ' => '' , 'Ы' => 'Y' , 'Ь ' => '' , 'Э' => 'E' , 'Ю' => 'Yu' ,
'Я' => 'Ya' ,
'а ' => 'a' , 'б ' => 'b' , 'в' => 'v' , 'г ' => 'g' , 'д' => 'd' , 'е ' => 'e' , 'ё' => 'yo' , 'ж' => 'zh' ,
'з' => 'z' , 'и' => 'i' , 'й' => 'j' , 'к' => 'k' , 'л' => 'l' , 'м' => 'm' , 'н' => 'n' , 'о ' => 'o' ,
'п' => 'p' , 'р ' => 'r' , 'с ' => 's' , 'т' => 't' , 'у ' => 'u' , 'ф' => 'f' , 'х ' => 'h' , 'ц' => 'c' ,
'ч' => 'ch' , 'ш' => 'sh' , 'щ' => 'sh' , 'ъ' => '' , 'ы' => 'y' , 'ь' => '' , 'э' => 'e' , 'ю' => 'yu' ,
'я' => 'ya' ,
// Ukrainian
'Є' => 'Ye' , 'І ' => 'I' , 'Ї' => 'Yi' , 'Ґ' => 'G' ,
'є' => 'ye' , 'і ' => 'i' , 'ї' => 'yi' , 'ґ' => 'g' ,
// Czech
'Č' => 'C' , 'Ď' => 'D' , 'Ě' => 'E' , 'Ň' => 'N' , 'Ř' => 'R' , 'Š' => 'S' , 'Ť' => 'T' , 'Ů' => 'U' ,
'Ž' => 'Z' ,
'č' => 'c' , 'ď' => 'd' , 'ě' => 'e' , 'ň' => 'n' , 'ř' => 'r' , 'š' => 's' , 'ť' => 't' , 'ů' => 'u' ,
'ž' => 'z' ,
// Polish
2021-01-14 17:32:08 -08:00
'Ą' => 'A' , 'Ć' => 'C' , 'Ę' => 'e' , 'Ł' => 'L' , 'Ń' => 'N' , /*'Ó' => 'o',*/
'Ś' => 'S' , 'Ź' => 'Z' ,
2016-12-08 08:21:58 -08:00
'Ż' => 'Z' ,
2021-01-14 17:32:08 -08:00
'ą' => 'a' , 'ć' => 'c' , 'ę' => 'e' , 'ł' => 'l' , 'ń' => 'n' , /* 'ó' => 'o',*/
'ś' => 's' , 'ź' => 'z' ,
2016-12-08 08:21:58 -08:00
'ż' => 'z' ,
// Latvian
2021-01-14 17:32:08 -08:00
'Ā' => 'A' , /* 'Č' => 'C',*/
'Ē' => 'E' , 'Ģ' => 'G' , 'Ī' => 'i' , 'Ķ' => 'k' , 'Ļ' => 'L' , 'Ņ' => 'N' ,
/*'Š' => 'S',*/
'Ū' => 'u' ,
2020-12-08 07:29:17 -08:00
'ā' => 'a' , 'ē' => 'e' , 'ģ' => 'g' , 'ī' => 'i' , 'ķ' => 'k' , 'ļ' => 'l' , 'ņ' => 'n' ,
2021-01-14 17:32:08 -08:00
'ū' => 'u' ,
2020-02-17 13:43:39 -08:00
2021-01-14 17:32:08 -08:00
'ľ' => 'l' , 'ŕ' => 'r' ,
2016-12-08 08:21:58 -08:00
);
2016-12-08 07:24:31 -08:00
2016-12-08 08:21:58 -08:00
return str_replace ( array_keys ( $char_map ), $char_map , $text );
2016-12-08 07:24:31 -08:00
}
2015-04-29 10:22:46 -07:00
2015-02-01 17:27:05 -08:00
/**
2020-12-09 09:15:16 -08:00
* Use it on html attributes to avoid breaking markup .
* @ param string $text
* @ example echo " <a href='#' title=' " . $tp -> toAttribute ( $text ) . " '>Hello</a> " ;
2015-02-01 17:27:05 -08:00
*/
2020-12-14 16:21:48 -08:00
public function toAttribute ( $text )
2009-01-03 22:32:54 +00:00
{
2021-01-14 17:32:08 -08:00
2009-10-30 19:57:28 +00:00
// URLs posted without HTML access may have an & in them.
2015-04-29 10:22:46 -07:00
2009-10-30 19:57:28 +00:00
// Xhtml compliance.
2009-10-30 20:58:52 +00:00
$text = htmlspecialchars ( $text , ENT_QUOTES , 'UTF-8' );
2015-04-29 10:22:46 -07:00
2015-02-01 17:27:05 -08:00
if ( ! preg_match ( '/&#|\'|"|<|>/s' , $text ))
2007-12-30 23:31:18 +00:00
{
2009-01-03 22:32:54 +00:00
$text = $this -> replaceConstants ( $text );
2021-01-14 17:32:08 -08:00
2009-01-03 22:32:54 +00:00
return $text ;
2009-01-08 21:47:44 +00:00
}
else
2009-01-03 22:32:54 +00:00
{
2016-04-14 16:32:48 -07:00
return $text ;
2006-12-02 04:36:16 +00:00
}
}
2009-01-03 22:32:54 +00:00
2009-09-02 16:39:32 +00:00
/**
* Convert text blocks which are to be embedded within JS
2009-10-30 20:05:17 +00:00
*
2009-10-30 23:31:08 +00:00
* @ param string | array $stringarray
2009-10-30 20:05:17 +00:00
* @ return string
2009-09-02 16:39:32 +00:00
*/
2009-10-30 23:31:08 +00:00
public function toJS ( $stringarray )
2009-01-03 22:32:54 +00:00
{
2021-01-14 17:32:08 -08:00
2020-12-14 16:21:48 -08:00
$search = array ( " \r \n " , " \r " , '<br />' , " ' " );
$replace = array ( " \\ n " , '' , " \\ n " , " \ ' " );
2006-12-02 04:36:16 +00:00
$stringarray = str_replace ( $search , $replace , $stringarray );
2009-10-30 19:57:28 +00:00
$stringarray = strip_tags ( $stringarray );
2006-12-02 04:36:16 +00:00
2009-10-30 19:57:28 +00:00
$trans_tbl = get_html_translation_table ( HTML_ENTITIES );
$trans_tbl = array_flip ( $trans_tbl );
2010-01-12 13:11:48 +00:00
2009-10-30 19:57:28 +00:00
return strtr ( $stringarray , $trans_tbl );
2006-12-02 04:36:16 +00:00
}
2009-01-03 22:32:54 +00:00
2015-12-02 14:23:48 +01:00
/**
* Converts a PHP variable into its JavaScript equivalent .
* We use HTML - safe strings , with several characters escaped .
*
* @ param mixed $var
2017-02-12 21:55:46 +01:00
* PHP variable .
* @ param bool $force_object
* True : Outputs an object rather than an array when a non - associative
* array is used . Especially useful when the recipient of the output
* is expecting an object and the array is empty .
*
2015-12-02 14:23:48 +01:00
* @ return string
*/
2017-02-12 21:55:46 +01:00
public function toJSON ( $var , $force_object = false )
2015-12-02 14:23:48 +01:00
{
2021-01-18 10:27:41 -08:00
if ( $force_object === true )
2015-12-02 14:23:48 +01:00
{
// Encode <, >, ', &, and " using the json_encode() options parameter.
2021-01-18 10:27:41 -08:00
return json_encode ( $var , JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_FORCE_OBJECT );
2015-12-02 14:23:48 +01:00
}
2021-01-18 10:27:41 -08:00
// Encode <, >, ', &, and " using the json_encode() options parameter.
return json_encode ( $var , JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT );
2021-01-14 17:32:08 -08:00
2015-12-02 14:23:48 +01:00
}
2009-09-02 16:39:32 +00:00
/**
2009-10-30 19:57:28 +00:00
* Convert Text for RSS / XML use .
2009-10-30 20:05:17 +00:00
*
2009-10-30 23:31:08 +00:00
* @ param string $text
* @ param boolean $tags [ optional ]
2009-10-30 20:05:17 +00:00
* @ return string
2009-09-02 16:39:32 +00:00
*/
2020-12-14 16:21:48 -08:00
public function toRss ( $text , $tags = false )
2006-12-02 04:36:16 +00:00
{
2021-01-14 17:32:08 -08:00
2015-06-17 11:26:14 -07:00
if ( $tags != true )
2006-12-02 04:36:16 +00:00
{
2019-02-26 12:22:36 -08:00
$text = $this -> toHTML ( $text , true );
2006-12-02 04:36:16 +00:00
$text = strip_tags ( $text );
2021-01-18 10:27:41 -08:00
2006-12-02 04:36:16 +00:00
}
$text = $this -> toEmail ( $text );
2015-07-16 18:12:41 -07:00
2020-12-14 16:21:48 -08:00
$search = array ( '&#039;' , '&#036;' , ''' , '$' , e_BASE , " href='request.php " , '<!-- bbcode-html-start -->' , '<!-- bbcode-html-end -->' );
2021-01-14 17:32:08 -08:00
$replace = array ( " ' " , '$' , " ' " , '$' , SITEURL , " href=' " . SITEURL . 'request.php' , '' , '' );
2009-10-30 20:05:17 +00:00
$text = str_replace ( $search , $replace , $text );
2006-12-02 04:36:16 +00:00
2016-01-27 12:05:15 -08:00
$text = $this -> ampEncode ( $text );
2015-06-17 11:26:14 -07:00
2021-01-05 10:36:58 -08:00
// if CDATA happens to be quoted in the text.
$text = str_replace ([ '<![CDATA' , ']]>' ], [ '<![CDATA' , ']]>' ], $text );
2021-01-18 10:27:41 -08:00
if ( $tags === true )
2006-12-02 04:36:16 +00:00
{
2021-01-18 10:27:41 -08:00
$text = ! empty ( $text ) ? '<![CDATA[' . $text . ']]>' : '' ;
}
else
{
$text = str_replace ([ '<' , '>' ],[ '<' , '>' ], $text );
2006-12-02 04:36:16 +00:00
}
return $text ;
}
2015-06-07 18:16:06 -07:00
2018-05-04 19:27:00 +02:00
/**
* Convert a string to a number ( int / float )
*
* @ param string $value
* @ return int | float
*/
2020-12-14 16:21:48 -08:00
public function toNumber ( $value )
2018-05-04 19:27:00 +02:00
{
2021-01-14 17:32:08 -08:00
2018-05-04 19:27:00 +02:00
// adapted from: https://secure.php.net/manual/en/function.floatval.php#114486
$dotPos = strrpos ( $value , '.' );
$commaPos = strrpos ( $value , ',' );
$sep = (( $dotPos > $commaPos ) && $dotPos ) ? $dotPos :
((( $commaPos > $dotPos ) && $commaPos ) ? $commaPos : false );
2021-01-14 17:32:08 -08:00
if ( ! $sep )
{
2020-12-14 16:21:48 -08:00
return preg_replace ( '/[^-0-9]/' , '' , $value );
2018-05-04 19:27:00 +02:00
}
2021-01-14 17:32:08 -08:00
2018-05-04 19:27:00 +02:00
return (
2020-12-14 16:21:48 -08:00
preg_replace ( '/[^-0-9]/' , '' , substr ( $value , 0 , $sep )) . '.' .
2021-01-14 17:32:08 -08:00
preg_replace ( '/[^0-9]/' , '' , substr ( $value , $sep + 1 , strlen ( $value )))
2018-05-04 19:27:00 +02:00
);
}
2016-01-27 12:05:15 -08:00
/**
* Clean and Encode Ampersands '&' for output to browser .
* @ param string $text
* @ return mixed | string
*/
2021-01-19 09:50:02 -08:00
public function ampEncode ( $text = '' )
2016-01-27 12:05:15 -08:00
{
2021-01-14 17:32:08 -08:00
2016-01-27 12:05:15 -08:00
// Fix any left-over '&'
2020-12-14 16:21:48 -08:00
//first revert any previously converted.
$text = str_replace ( array ( '&' , '&' ), array ( '&' , '&' ), $text );
2016-01-27 12:05:15 -08:00
return $text ;
}
2015-06-07 18:16:06 -07:00
/**
* Convert any string back to plain text .
* @ param $text
* @ return mixed | string
*/
2020-12-14 16:21:48 -08:00
public function toText ( $text )
2006-12-02 04:36:16 +00:00
{
2015-06-07 18:16:06 -07:00
2019-02-26 12:22:36 -08:00
if ( $this -> isBBcode ( $text ) === true ) // convert any bbcodes to html
2017-09-19 16:19:39 -07:00
{
2021-01-14 17:32:08 -08:00
$text = $this -> toHTML ( $text , true );
2017-09-19 16:19:39 -07:00
}
if ( $this -> isHtml ( $text ) === true ) // strip any html.
2015-06-07 18:16:06 -07:00
{
2021-01-14 17:32:08 -08:00
$text = $this -> toHTML ( $text , true );
$text = str_replace ( " \n " , '' , $text ); // clean-out line-breaks.
$text = str_ireplace ( array ( '<br>' , '<br />' , '<br/>' ), " \n " , $text );
2015-06-07 18:16:06 -07:00
$text = strip_tags ( $text );
}
2020-12-14 16:21:48 -08:00
$search = array ( '&#039;' , '&#036;' , ''' , '$' , '\' , '&#092;' );
2006-12-02 04:36:16 +00:00
$replace = array ( " ' " , '$' , " ' " , '$' , " \\ " , " \\ " );
$text = str_replace ( $search , $replace , $text );
2021-01-14 17:32:08 -08:00
2006-12-02 04:36:16 +00:00
return $text ;
}
2013-05-07 18:32:38 -07:00
2013-06-02 21:46:53 -07:00
/**
* Set the dimensions of a thumbNail ( generated by thumbUrl )
*/
2021-01-14 17:32:08 -08:00
public function setThumbSize ( $w = null , $h = null , $crop = null )
2013-05-07 18:32:38 -07:00
{
2021-01-14 17:32:08 -08:00
2016-02-09 11:02:08 -08:00
if ( $w !== null )
2013-05-07 18:32:38 -07:00
{
2020-12-12 11:32:23 -08:00
$this -> thumbWidth = ( int ) $w ;
2013-05-07 18:32:38 -07:00
}
2021-01-14 17:32:08 -08:00
2016-02-09 11:02:08 -08:00
if ( $h !== null )
2013-05-07 18:32:38 -07:00
{
2020-12-12 11:32:23 -08:00
$this -> thumbHeight = ( int ) $h ;
2021-01-14 17:32:08 -08:00
}
2016-02-09 11:02:08 -08:00
if ( $crop !== null )
2013-05-07 18:32:38 -07:00
{
2020-12-12 11:32:23 -08:00
$this -> thumbCrop = ( int ) $crop ;
2021-01-14 17:32:08 -08:00
}
2013-05-07 18:32:38 -07:00
}
2016-02-09 22:53:03 -08:00
public function thumbEncode ( $val = null )
{
if ( $val !== null )
{
2020-12-12 11:32:23 -08:00
$this -> thumbEncode = ( int ) $val ;
2021-01-14 17:32:08 -08:00
2016-02-09 22:53:03 -08:00
return null ;
}
return $this -> thumbEncode ;
}
2013-05-07 18:32:38 -07:00
2016-02-07 13:28:55 -08:00
/**
* Retrieve img tag width and height attributes for current thumbnail .
* @ return string
*/
public function thumbDimensions ( $type = 'single' )
{
2021-01-14 17:32:08 -08:00
2016-02-07 13:28:55 -08:00
if ( ! empty ( $this -> thumbCrop ) && ! empty ( $this -> thumbWidth ) && ! empty ( $this -> thumbHeight )) // dimensions are known.
{
2021-01-14 17:32:08 -08:00
return ( $type === 'double' ) ? 'width="' . $this -> thumbWidth . '" height="' . $this -> thumbHeight . '"' : " width=' " . $this -> thumbWidth . " ' height=' " . $this -> thumbHeight . " ' " ;
2016-02-07 13:28:55 -08:00
}
2013-05-07 18:32:38 -07:00
2016-02-07 13:28:55 -08:00
return null ;
}
2014-01-14 08:16:12 -08:00
/**
2021-01-14 17:32:08 -08:00
* Set or Get the value of the thumbNail Width .
2014-01-14 08:16:12 -08:00
* @ param $width ( optional )
*/
2021-01-14 17:32:08 -08:00
public function thumbWidth ( $width = null )
2014-01-14 08:16:12 -08:00
{
2021-01-14 17:32:08 -08:00
2015-06-28 16:31:02 -07:00
if ( $width !== null )
2014-01-14 08:16:12 -08:00
{
2020-12-12 11:32:23 -08:00
$this -> thumbWidth = ( int ) $width ;
2014-01-14 08:16:12 -08:00
}
2021-01-14 17:32:08 -08:00
return $this -> thumbWidth ;
2014-01-14 08:16:12 -08:00
}
2016-03-13 12:34:58 -07:00
/**
* Set or Get the value of the thumbNailbCrop .
* @ param bool $status = true / false
*/
2021-01-14 17:32:08 -08:00
public function thumbCrop ( $status = false )
2016-03-13 12:34:58 -07:00
{
2021-01-14 17:32:08 -08:00
2016-03-13 12:34:58 -07:00
if ( $status !== false )
{
2020-12-12 11:32:23 -08:00
$this -> thumbCrop = ( int ) $status ;
2016-03-13 12:34:58 -07:00
}
2014-01-14 08:16:12 -08:00
2016-03-13 12:34:58 -07:00
return $this -> thumbCrop ;
}
2014-01-14 08:16:12 -08:00
/**
2021-01-14 17:32:08 -08:00
* Set or Get the value of the thumbNail height .
2014-01-14 08:16:12 -08:00
* @ param $height ( optional )
*/
2021-01-14 17:32:08 -08:00
public function thumbHeight ( $height = null )
2014-01-14 08:16:12 -08:00
{
2021-01-14 17:32:08 -08:00
2014-11-18 21:11:26 +02:00
if ( $height !== null )
2014-01-14 08:16:12 -08:00
{
2020-12-12 11:32:23 -08:00
$this -> thumbHeight = ( int ) $height ;
2014-01-14 08:16:12 -08:00
}
2021-01-14 17:32:08 -08:00
return $this -> thumbHeight ;
2014-01-14 08:16:12 -08:00
}
2016-10-17 11:18:32 -07:00
2017-10-24 11:19:06 -07:00
/**
* Generated a Thumb Cache File Name from path and options .
* @ param string $path
* @ param array $options
2020-12-08 09:10:26 -08:00
* @ param string $log ( optional ) - log file name
2017-10-24 11:19:06 -07:00
* @ return null | string
*/
2021-01-14 17:32:08 -08:00
public function thumbCacheFile ( $path , $options = null , $log = null )
2017-10-24 11:19:06 -07:00
{
2021-01-14 17:32:08 -08:00
2017-10-24 11:19:06 -07:00
if ( empty ( $path ))
{
return null ;
}
2017-10-25 15:17:53 -07:00
if ( is_string ( $options ))
{
2021-01-14 17:32:08 -08:00
parse_str ( $options , $options );
2017-10-25 15:17:53 -07:00
}
$path = str_replace ( $this -> getUrlConstants ( 'raw' ), $this -> getUrlConstants ( 'sc' ), $path );
$path = $this -> replaceConstants ( str_replace ( '..' , '' , $path ));
2021-01-14 17:32:08 -08:00
$filename = basename ( $path );
$tmp = explode ( '.' , $filename );
$ext = end ( $tmp );
$len = strlen ( $ext ) + 1 ;
$start = substr ( $filename , 0 , - $len );
2017-10-25 15:17:53 -07:00
// cleanup.
$newOpts = array (
2021-01-14 17:32:08 -08:00
'w' => ( string ) intval ( $options [ 'w' ]),
'h' => ( string ) intval ( $options [ 'h' ]),
'aw' => ( string ) intval ( $options [ 'aw' ]),
'ah' => ( string ) intval ( $options [ 'ah' ]),
'c' => strtoupper ( vartrue ( $options [ 'c' ], '0' )),
2017-10-25 15:17:53 -07:00
);
2020-12-08 09:10:26 -08:00
if ( ! empty ( $options [ 'type' ]))
2017-10-25 15:17:53 -07:00
{
2020-12-14 16:21:48 -08:00
$newOpts [ 'type' ] = $options [ 'type' ];
$ext = $newOpts [ 'type' ];
2017-10-25 15:17:53 -07:00
}
2017-10-24 11:19:06 -07:00
if ( ! empty ( $options [ 'aw' ]))
{
$options [ 'w' ] = $options [ 'aw' ];
}
if ( ! empty ( $options [ 'ah' ]))
{
$options [ 'h' ] = $options [ 'ah' ];
}
2017-10-25 15:17:53 -07:00
2021-01-14 17:32:08 -08:00
$size = varset ( $options [ 'w' ], 0 ) . 'x' . varset ( $options [ 'h' ], 0 );
2017-10-24 11:19:06 -07:00
2021-01-14 17:32:08 -08:00
$thumbQuality = e107 :: getPref ( 'thumbnail_quality' , 65 );
2017-10-24 11:19:06 -07:00
2021-01-14 17:32:08 -08:00
$cache_str = md5 ( serialize ( $newOpts ) . $path . $thumbQuality );
2017-10-24 11:19:06 -07:00
$pre = 'thumb_' ;
$post = '.cache.bin' ;
2017-10-25 15:17:53 -07:00
2021-01-14 17:32:08 -08:00
// $cache_str = http_build_query($newOpts,null,'_'); // testing files.
2017-10-25 15:17:53 -07:00
if ( defined ( 'e_MEDIA_STATIC' )) // experimental - subject to change.
{
$pre = '' ;
$post = '' ;
}
2017-10-24 11:19:06 -07:00
2021-01-14 17:32:08 -08:00
$fname = $pre . strtolower ( $start . '_' . $cache_str . '_' . $size . '.' . $ext ) . $post ;
2017-10-24 11:19:06 -07:00
2020-12-08 09:10:26 -08:00
if ( $log !== null )
{
2021-01-14 17:32:08 -08:00
file_put_contents ( e_LOG . $log , " \n ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n \n " , FILE_APPEND );
$message = 'Name: ' . $fname . " \n " ;
$message .= $path . " \n " . var_export ( $newOpts , true ) . " \n \n \n " ;
file_put_contents ( e_LOG . $log , $message , FILE_APPEND );
2020-12-08 09:10:26 -08:00
2021-01-14 17:32:08 -08:00
// file_put_contents(e_LOG.$log, "\t\tFOUND!!\n\n\n", FILE_APPEND);
2020-12-08 09:10:26 -08:00
}
2017-10-24 11:19:06 -07:00
return $fname ;
}
2016-10-17 11:18:32 -07:00
2021-01-14 17:32:08 -08:00
private function staticCount ( $val = false )
2017-10-25 19:02:10 -07:00
{
$count = $this -> staticCount ;
if ( $val === 0 )
{
$this -> staticCount = 0 ;
}
elseif ( $val !== false )
{
2021-01-14 17:32:08 -08:00
$this -> staticCount += ( int ) $val ;
2017-10-25 19:02:10 -07:00
}
2020-12-14 16:21:48 -08:00
return $count ;
2017-10-25 19:02:10 -07:00
}
/**
2020-12-03 11:44:59 -08:00
* @ param string $path - absolute path or e107 path { e_PLUGIN } etc .
* @ param array $opts - when $opts [ 'full' ] is true , a full siteurl will be used instead of an absolute path . ( unless static url is found )
2020-12-03 10:31:19 -08:00
* @ return string - full path or static path .
2021-01-14 17:32:08 -08:00
* @ todo Move to e107_class ?
2017-10-25 19:02:10 -07:00
*/
2021-01-14 17:32:08 -08:00
public function staticUrl ( $path = null , $opts = array ())
2017-10-25 19:02:10 -07:00
{
2021-01-14 17:32:08 -08:00
2020-12-03 14:20:34 -08:00
if ( empty ( $this -> staticUrl ) || deftrue ( 'e_ADMIN_AREA' ))
2017-10-25 19:02:10 -07:00
{
2017-10-26 14:50:38 -07:00
// e107::getDebug()->log("e_HTTP_STATIC not defined");
2018-01-26 18:12:12 -08:00
if ( $path === null )
{
return ! empty ( $opts [ 'full' ]) ? SITEURL : e_HTTP ;
}
2020-12-14 16:21:48 -08:00
return ! empty ( $opts [ 'full' ]) ? $this -> replaceConstants ( $path , 'full' ) : $this -> replaceConstants ( $path , 'abs' ); // self::replaceConstants($path, 'full');
2017-10-25 19:02:10 -07:00
}
2020-12-03 14:20:34 -08:00
$staticArray = $this -> staticUrl ; // e_HTTP_STATIC;
2017-10-25 19:02:10 -07:00
if ( is_array ( $staticArray ))
{
$cnt = count ( $staticArray );
$staticCount = $this -> staticCount ();
2021-01-14 17:32:08 -08:00
if ( $staticCount > ( $cnt - 1 ))
2017-10-25 19:02:10 -07:00
{
$staticCount = 0 ;
$this -> staticCount ( 0 );
}
$http = ! empty ( $staticArray [ $staticCount ]) ? $staticArray [ $staticCount ] : e_HTTP ;
}
else
{
2020-12-03 14:20:34 -08:00
$http = $this -> staticUrl ;
2017-10-25 19:02:10 -07:00
}
$this -> staticCount ( 1 );
if ( empty ( $path ))
{
return $http ;
}
$base = '' ;
2020-12-14 16:21:48 -08:00
$path = $this -> replaceConstants ( $path , 'abs' ); // replace any {THEME} etc.
2020-12-03 10:31:19 -08:00
2017-10-25 19:02:10 -07:00
$srch = array (
e_PLUGIN_ABS ,
e_THEME_ABS ,
e_WEB_ABS ,
e_CACHE_IMAGE_ABS ,
);
$repl = array (
2021-01-14 17:32:08 -08:00
$http . $base . e107 :: getFolder ( 'plugins' ),
$http . $base . e107 :: getFolder ( 'themes' ),
$http . $base . e107 :: getFolder ( 'web' ),
$http . $base . str_replace ( '../' , '' , e_CACHE_IMAGE ),
2017-10-25 19:02:10 -07:00
);
2021-01-14 17:32:08 -08:00
$ret = str_replace ( $srch , $repl , $path );
2017-10-25 19:02:10 -07:00
2018-01-19 14:16:15 -08:00
if ( strpos ( $ret , 'http' ) !== 0 ) // if not converted, check media folder also.
{
2021-01-14 17:32:08 -08:00
$ret = str_replace ( e_MEDIA_ABS , $http . $base . e107 :: getFolder ( 'media' ), $ret );
2018-01-19 14:16:15 -08:00
}
2017-10-25 19:02:10 -07:00
return $ret ;
}
2020-12-03 14:20:34 -08:00
/**
* Used internally to store e_HTTP_STATIC .
* @ param string | null $url The static URL ie . e_HTTP_STATIC
*/
public function setStaticUrl ( $url )
{
2021-01-14 17:32:08 -08:00
2020-12-03 14:20:34 -08:00
$this -> staticUrl = $url ;
}
2017-10-25 19:02:10 -07:00
2013-03-31 00:06:21 -07:00
/**
2016-10-17 11:18:32 -07:00
* Generate an auto - sized Image URL .
2016-10-17 16:22:24 -07:00
* @ param $url - path to image or leave blank for a placeholder . eg . { e_MEDIA } folder / my - image . jpg
2016-10-17 11:18:32 -07:00
* @ param array $options - width and height , but leaving this empty and using $this -> thumbWidth () and $this -> thumbHeight () is preferred . ie . { SETWIDTH : w = x & y = x }
2021-01-14 17:32:08 -08:00
* @ param int $options [ 'w' ] width ( optional )
* @ param int $options [ 'h' ] height ( optional )
2016-10-17 11:18:32 -07:00
* @ param bool | string $options [ 'crop' ] true / false or A ( auto ) or T ( op ) or B ( ottom ) or C ( enter ) or L ( eft ) or R ( right )
2021-01-14 17:32:08 -08:00
* @ param string $options [ 'scale' ] '2x' ( optional )
* @ param bool $options [ 'x' ] encode / mask the url parms ( optional )
* @ param bool $options [ 'nosef' ] when set to true disabled SEF Url being returned ( optional )
2016-10-17 11:18:32 -07:00
* @ param bool $raw set to true when the $url does not being with an e107 variable ie . " { e_XXXX} " eg . { e_MEDIA } ( optional )
* @ param bool $full when true returns full http :// url . ( optional )
* @ return string
2013-03-31 00:06:21 -07:00
*/
2021-01-14 17:32:08 -08:00
public function thumbUrl ( $url = null , $options = array (), $raw = false , $full = false )
2010-03-09 16:05:41 +00:00
{
2021-01-14 17:32:08 -08:00
2017-10-25 19:02:10 -07:00
$this -> staticCount ++ ; // increment counter.
2018-07-27 12:41:14 -07:00
$ext = pathinfo ( $url , PATHINFO_EXTENSION );
if ( $ext === 'svg' )
{
return $this -> replaceConstants ( $url , 'abs' );
}
2020-12-14 16:21:48 -08:00
if ( strpos ( $url , '{e_' ) === 0 ) // Fix for broken links that use {e_MEDIA} etc.
2011-08-19 23:39:44 +00:00
{
2013-03-18 12:26:55 +02:00
//$url = $this->replaceConstants($url,'abs');
// always switch to 'nice' urls when SC is used
2021-01-14 17:32:08 -08:00
$url = str_replace ( $this -> getUrlConstants ( 'sc' ), $this -> getUrlConstants ( 'raw' ), $url );
2011-08-19 23:39:44 +00:00
}
2021-01-14 17:32:08 -08:00
2017-10-25 19:02:10 -07:00
if ( is_string ( $options ))
2010-03-09 16:05:41 +00:00
{
parse_str ( $options , $options );
}
2016-10-17 11:18:32 -07:00
if ( ! empty ( $options [ 'scale' ])) // eg. scale the width height 2x 3x 4x. etc.
{
$options [ 'return' ] = 'src' ;
$options [ 'size' ] = $options [ 'scale' ];
unset ( $options [ 'scale' ]);
2021-01-14 17:32:08 -08:00
return $this -> thumbSrcSet ( $url , $options );
2016-10-17 11:18:32 -07:00
}
2020-12-20 11:50:10 -08:00
if ( strpos ( $url , e_MEDIA ) !== false || strpos ( $url , e_SYSTEM ) !== false ) // prevent disclosure of 'hashed' path.
2013-04-27 13:15:04 -07:00
{
2021-01-14 17:32:08 -08:00
$raw = true ;
2013-04-27 13:15:04 -07:00
}
2010-03-09 16:05:41 +00:00
2020-12-14 16:21:48 -08:00
if ( $raw )
{
$url = $this -> createConstants ( $url , 'mix' );
}
2021-01-14 17:32:08 -08:00
$baseurl = ( $full ? SITEURL : e_HTTP ) . 'thumb.php?' ;
2017-04-28 15:07:36 -07:00
2020-12-03 14:20:34 -08:00
if ( ! empty ( $this -> staticUrl ))
2017-04-28 15:07:36 -07:00
{
2021-01-14 17:32:08 -08:00
$baseurl = $this -> staticUrl () . 'thumb.php?' ;
2017-04-28 15:07:36 -07:00
}
2016-02-09 22:53:03 -08:00
2021-01-14 17:32:08 -08:00
$thurl = 'src=' . urlencode ( $url ) . '&' ;
// e107::getDebug()->log("Thumb: ".basename($url). print_a($options,true), E107_DBG_BASIC);
2016-04-12 19:56:29 -07:00
2016-10-17 16:22:24 -07:00
if ( ! empty ( $options ) && ( isset ( $options [ 'w' ]) || isset ( $options [ 'aw' ]) || isset ( $options [ 'h' ])))
2016-02-09 22:53:03 -08:00
{
2021-01-14 17:32:08 -08:00
$options [ 'w' ] = varset ( $options [ 'w' ]);
$options [ 'h' ] = varset ( $options [ 'h' ]);
$options [ 'crop' ] = ( isset ( $options [ 'aw' ]) || isset ( $options [ 'ah' ])) ? 1 : varset ( $options [ 'crop' ]);
$options [ 'aw' ] = varset ( $options [ 'aw' ]);
$options [ 'ah' ] = varset ( $options [ 'ah' ]);
$options [ 'x' ] = varset ( $options [ 'x' ]);
2016-02-09 22:53:03 -08:00
}
2016-04-13 14:30:42 -07:00
else
2016-02-09 22:53:03 -08:00
{
2021-01-14 17:32:08 -08:00
$options [ 'w' ] = $this -> thumbWidth ;
$options [ 'h' ] = $this -> thumbHeight ;
$options [ 'crop' ] = $this -> thumbCrop ;
$options [ 'aw' ] = null ;
$options [ 'ah' ] = null ;
$options [ 'x' ] = $this -> thumbEncode ;
2016-04-13 14:30:42 -07:00
2016-02-09 22:53:03 -08:00
}
2016-04-13 14:30:42 -07:00
if ( ! empty ( $options [ 'crop' ]))
2010-03-09 16:05:41 +00:00
{
2016-04-13 14:30:42 -07:00
if ( ! empty ( $options [ 'aw' ]) || ! empty ( $options [ 'ah' ]))
2013-03-24 03:03:31 -07:00
{
2021-01-14 17:32:08 -08:00
$options [ 'w' ] = $options [ 'aw' ];
$options [ 'h' ] = $options [ 'ah' ];
2013-03-24 03:03:31 -07:00
}
2016-04-13 14:30:42 -07:00
2021-01-14 17:32:08 -08:00
$thurl .= 'aw=' . ( int ) $options [ 'w' ] . '&ah=' . ( int ) $options [ 'h' ];
2016-04-13 14:30:42 -07:00
2016-10-18 10:20:10 -07:00
if ( ! is_numeric ( $options [ 'crop' ]))
2016-10-11 14:58:08 -07:00
{
2021-01-14 17:32:08 -08:00
$thurl .= '&c=' . $options [ 'crop' ];
2016-10-11 14:58:08 -07:00
$options [ 'nosef' ] = true ;
}
2010-03-09 16:05:41 +00:00
}
else
{
2016-04-13 14:30:42 -07:00
2021-01-14 17:32:08 -08:00
$thurl .= 'w=' . ( int ) $options [ 'w' ] . '&h=' . ( int ) $options [ 'h' ];
2016-04-13 14:30:42 -07:00
2010-03-09 16:05:41 +00:00
}
2016-02-03 18:17:14 -08:00
2020-12-08 09:10:26 -08:00
if ( ! empty ( $options [ 'type' ]) && ( $options [ 'type' ] === 'webp' ))
{
$thurl .= '&type=webp' ;
}
2016-02-03 18:17:14 -08:00
2017-10-25 15:17:53 -07:00
if ( defined ( 'e_MEDIA_STATIC' )) // experimental - subject to change.
{
$opts = str_replace ( '&' , '&' , $thurl );
$staticFile = $this -> thumbCacheFile ( $url , $opts );
2017-12-27 12:28:29 -08:00
2021-01-14 17:32:08 -08:00
if ( ! empty ( $staticFile ) && is_readable ( e_CACHE_IMAGE . $staticFile ))
2017-10-25 15:17:53 -07:00
{
2021-01-14 18:30:32 -08:00
return $this -> staticUrl ( e_CACHE_IMAGE_ABS . $staticFile );
2021-01-14 17:32:08 -08:00
2017-10-25 15:17:53 -07:00
}
2021-01-14 17:32:08 -08:00
// echo "<br />static-not-found: ".$staticFile;
2017-12-27 12:28:29 -08:00
2017-10-25 15:17:53 -07:00
$options [ 'nosef' ] = true ;
2017-10-26 14:50:38 -07:00
$options [ 'x' ] = null ;
2017-10-25 15:17:53 -07:00
// file_put_contents(e_LOG."thumb.log", "\n++++++++++++++++++++++++++++++++++\n\n", FILE_APPEND);
}
2021-01-14 17:32:08 -08:00
if ( e_MOD_REWRITE_MEDIA == true && empty ( $options [ 'nosef' ])) // Experimental SEF URL support.
2016-02-03 18:17:14 -08:00
{
$options [ 'full' ] = $full ;
2021-01-14 17:32:08 -08:00
$options [ 'ext' ] = substr ( $url , - 3 );
2016-02-03 18:17:14 -08:00
$options [ 'thurl' ] = $thurl ;
2021-01-14 17:32:08 -08:00
// $options['x'] = $this->thumbEncode();
2016-02-04 12:42:48 -08:00
2021-01-14 17:32:08 -08:00
if ( $sefUrl = $this -> thumbUrlSEF ( $url , $options ))
2016-02-04 12:42:48 -08:00
{
return $sefUrl ;
}
2016-02-03 18:17:14 -08:00
}
2021-01-14 17:32:08 -08:00
if ( ! empty ( $options [ 'x' ])) //base64 encode url
2012-07-02 01:32:56 +00:00
{
2021-01-14 17:32:08 -08:00
$thurl = 'id=' . base64_encode ( $thurl );
2012-07-02 01:32:56 +00:00
}
2010-03-09 16:05:41 +00:00
2021-01-14 17:32:08 -08:00
return $baseurl . $thurl ;
2010-03-09 16:05:41 +00:00
}
2009-09-02 16:39:32 +00:00
2016-02-08 21:33:55 -08:00
2017-12-27 20:58:59 -08:00
/**
* Split a thumb . php url into an array which can be parsed back into the thumbUrl method . .
* @ param $src
* @ return array
*/
2020-12-14 16:21:48 -08:00
public function thumbUrlDecode ( $src )
2017-12-27 20:58:59 -08:00
{
2021-01-14 17:32:08 -08:00
list ( $url , $qry ) = array_pad ( explode ( '?' , $src ), 2 , null );
2017-12-27 20:58:59 -08:00
$ret = array ();
2020-12-20 11:50:10 -08:00
if ( ! empty ( $qry ) && strpos ( $url , 'thumb.php' ) !== false ) // Regular
2017-12-27 20:58:59 -08:00
{
2021-01-14 17:32:08 -08:00
parse_str ( $qry , $val );
2017-12-27 20:58:59 -08:00
$ret = $val ;
}
2021-01-14 17:32:08 -08:00
elseif ( preg_match ( '/media\/img\/(a)?([\d]*)x(a)?([\d]*)\/(.*)/' , $url , $match )) // SEF
2017-12-27 20:58:59 -08:00
{
2021-01-14 17:32:08 -08:00
$wKey = $match [ 1 ] . 'w' ;
$hKey = $match [ 3 ] . 'h' ;
2017-12-27 20:58:59 -08:00
$ret = array (
2021-01-14 17:32:08 -08:00
'src' => 'e_MEDIA_IMAGE/' . $match [ 5 ],
2017-12-27 20:58:59 -08:00
$wKey => $match [ 2 ],
$hKey => $match [ 4 ]
);
}
elseif ( preg_match ( '/theme\/img\/(a)?([\d]*)x(a)?([\d]*)\/(.*)/' , $url , $match )) // Theme-image SEF Urls
{
2021-01-14 17:32:08 -08:00
$wKey = $match [ 1 ] . 'w' ;
$hKey = $match [ 3 ] . 'h' ;
2017-12-27 20:58:59 -08:00
$ret = array (
2021-01-14 17:32:08 -08:00
'src' => 'e_THEME/' . $match [ 5 ],
2017-12-27 20:58:59 -08:00
$wKey => $match [ 2 ],
$hKey => $match [ 4 ]
);
}
elseif ( defined ( 'TINYMCE_DEBUG' ))
{
2020-12-14 16:21:48 -08:00
print_a ( 'thumbUrlDecode: No Matches' );
2017-12-27 20:58:59 -08:00
}
return $ret ;
}
2016-02-08 21:33:55 -08:00
/**
* Experimental : Generate a Thumb URL for use in the img srcset attribute .
* @ param string $src eg . { e_MEDIA_IMAGE } myimage . jpg
2020-03-02 11:03:28 -08:00
* @ param int | string | array $width - desired size in px or '2x' or '3x' or null for all or array (
2016-02-08 21:33:55 -08:00
* @ return string
*/
2021-01-14 17:32:08 -08:00
public function thumbSrcSet ( $src = '' , $width = null )
2016-02-08 21:33:55 -08:00
{
2021-01-14 17:32:08 -08:00
2017-04-19 13:20:59 -07:00
$multiply = null ;
2020-03-02 11:03:28 -08:00
$encode = false ;
2020-12-14 16:21:48 -08:00
$parm = array ();
2017-04-19 13:20:59 -07:00
2016-02-09 22:53:03 -08:00
if ( is_array ( $width ))
{
$parm = $width ;
2016-04-13 14:30:42 -07:00
$multiply = $width [ 'size' ];
2016-09-17 11:10:25 -07:00
$encode = ( ! empty ( $width [ 'x' ])) ? $width [ 'x' ] : false ;
2016-02-09 22:53:03 -08:00
$width = $width [ 'size' ];
}
2016-02-08 21:33:55 -08:00
2016-04-13 14:30:42 -07:00
2021-01-14 17:32:08 -08:00
// $encode = $this->thumbEncode();;
2020-12-14 16:21:48 -08:00
if ( $width == null || $width === 'all' )
2016-02-08 21:33:55 -08:00
{
$links = array ();
2021-01-14 17:32:08 -08:00
$mag = ( $width == null ) ? array ( 1 , 2 ) : array ( 160 , 320 , 460 , 600 , 780 , 920 , 1100 );
2016-02-08 21:33:55 -08:00
foreach ( $mag as $v )
{
$w = ( $this -> thumbWidth * $v );
2021-01-14 17:32:08 -08:00
$h = ( $this -> thumbHeight * $v );
2016-02-08 21:33:55 -08:00
2020-12-14 16:21:48 -08:00
$att = ( ! empty ( $this -> thumbCrop )) ? array ( 'aw' => $w , 'ah' => $h ) : compact ( 'w' , 'h' );
2016-02-09 22:53:03 -08:00
$att [ 'x' ] = $encode ;
2016-02-08 21:33:55 -08:00
2021-01-14 17:32:08 -08:00
$add = ( $width == null ) ? ' ' . $v . 'x' : ' ' . $v . 'w' ;
$links [] = $this -> thumbUrl ( $src , $att ) . $add ; // " w".$width; //
2016-02-08 21:33:55 -08:00
}
2021-01-14 17:32:08 -08:00
return implode ( ', ' , $links );
2016-02-08 21:33:55 -08:00
}
2017-01-29 18:43:52 -08:00
elseif ( $multiply === '2x' || $multiply === '3x' || $multiply === '4x' )
2016-02-08 21:33:55 -08:00
{
2020-04-10 09:47:17 -07:00
$multiInt = ( int ) $multiply ;
2016-04-13 14:30:42 -07:00
if ( empty ( $parm [ 'w' ]) && isset ( $parm [ 'h' ]))
{
2021-01-14 17:32:08 -08:00
$parm [ 'h' ] = ( $parm [ 'h' ] * $multiInt );
return $this -> thumbUrl ( $src , $parm ) . ' ' . $multiply ;
2016-04-13 14:30:42 -07:00
}
2020-03-02 11:03:28 -08:00
if ( isset ( $parm [ 'w' ]) && ! isset ( $parm [ 'h' ])) // if w set, assume h value of 0 is set.
{
$parm [ 'h' ] = 0 ;
}
2020-04-10 09:47:17 -07:00
$width = ! empty ( $parm [ 'w' ]) ? ( intval ( $parm [ 'w' ]) * $multiInt ) : ( intval ( $this -> thumbWidth ) * $multiInt );
$height = isset ( $parm [ 'h' ]) ? ( intval ( $parm [ 'h' ]) * $multiInt ) : ( intval ( $this -> thumbHeight ) * $multiInt );
2016-12-23 08:53:47 -08:00
2016-03-12 00:15:29 -08:00
}
2016-02-08 21:33:55 -08:00
else
{
$height = (( $this -> thumbHeight * $width ) / $this -> thumbWidth );
2016-12-23 08:53:47 -08:00
2016-02-08 21:33:55 -08:00
}
2016-12-23 08:53:47 -08:00
2016-05-13 07:14:49 -07:00
if ( ! isset ( $parm [ 'aw' ]))
{
$parm [ 'aw' ] = null ;
}
if ( ! isset ( $parm [ 'ah' ]))
{
$parm [ 'ah' ] = null ;
}
2016-09-17 11:10:25 -07:00
if ( ! isset ( $parm [ 'x' ]))
{
$parm [ 'x' ] = null ;
}
if ( ! isset ( $parm [ 'crop' ]))
{
$parm [ 'crop' ] = null ;
}
2021-01-14 17:32:08 -08:00
$parms = array ( 'w' => $width , 'h' => $height , 'crop' => $parm [ 'crop' ], 'x' => $parm [ 'x' ], 'aw' => $parm [ 'aw' ], 'ah' => $parm [ 'ah' ]);
2016-04-13 14:30:42 -07:00
2020-12-08 09:10:26 -08:00
if ( ! empty ( $parm [ 'type' ]))
{
$parms [ 'type' ] = $parm [ 'type' ];
}
2021-01-14 17:32:08 -08:00
// $parms = !empty($this->thumbCrop) ? array('aw' => $width, 'ah' => $height, 'x'=>$encode) : array('w' => $width, 'h' => $height, 'x'=>$encode );
2016-04-13 14:30:42 -07:00
// $parms['x'] = $encode;
2016-02-08 21:33:55 -08:00
2017-01-29 18:43:52 -08:00
if ( ! empty ( $parm [ 'return' ]) && $parm [ 'return' ] === 'src' )
2016-10-17 11:18:32 -07:00
{
return $this -> thumbUrl ( $src , $parms );
}
2020-04-10 09:47:17 -07:00
$ret = $this -> thumbUrl ( $src , $parms );
2016-02-08 21:33:55 -08:00
2021-01-14 17:32:08 -08:00
$ret .= ( $multiply ) ? ' ' . $multiply : ' ' . $width . 'w' ;
2020-04-10 09:47:17 -07:00
2021-01-14 17:32:08 -08:00
return $ret ;
2016-04-13 14:30:42 -07:00
2016-02-08 21:33:55 -08:00
}
2021-01-14 17:32:08 -08:00
public function thumbUrlScale ( $src , $parm )
2016-10-17 11:18:32 -07:00
{
}
2016-02-03 18:17:14 -08:00
/**
2021-01-14 17:32:08 -08:00
* Used by thumbUrl when SEF Image URLS is active . @ param $url
2016-02-03 18:17:14 -08:00
* @ param array $options
* @ return string
2021-01-14 17:32:08 -08:00
* @ see e107 . htaccess
2016-02-03 18:17:14 -08:00
*/
2021-01-15 14:24:28 -08:00
public function thumbUrlSEF ( $url = '' , $options = array ())
2016-02-03 18:17:14 -08:00
{
2021-01-14 17:32:08 -08:00
2016-03-10 13:33:11 -08:00
if ( ! empty ( $options [ 'full' ]))
{
$base = SITEURL ;
}
else
{
$base = ( ! empty ( $options [ 'ebase' ])) ? '{e_BASE}' : e_HTTP ;
}
2017-04-28 15:07:36 -07:00
2020-12-03 14:20:34 -08:00
if ( ! empty ( $this -> staticUrl ))
2017-04-28 15:07:36 -07:00
{
2017-10-25 19:02:10 -07:00
$base = $this -> staticUrl ();
2017-04-28 15:07:36 -07:00
}
2021-01-14 17:32:08 -08:00
// $base = (!empty($options['full'])) ? SITEURL : e_HTTP;
2016-02-03 18:17:14 -08:00
2021-01-14 17:32:08 -08:00
if ( ! empty ( $options [ 'x' ]) && ! empty ( $options [ 'ext' ])) // base64 encoded. Build URL for: RewriteRule ^media\/img\/([-A-Za-z0-9+/]*={0,3})\.(jpg|gif|png)?$ thumb.php?id=$1
2016-02-03 18:17:14 -08:00
{
$ext = strtolower ( $options [ 'ext' ]);
2021-01-14 17:32:08 -08:00
return $base . 'media/img/' . base64_encode ( $options [ 'thurl' ]) . '.' . str_replace ( 'jpeg' , 'jpg' , $ext );
2016-02-03 18:17:14 -08:00
}
2020-12-20 11:50:10 -08:00
elseif ( strpos ( $url , 'e_MEDIA_IMAGE' ) !== false ) // media images.
2016-02-04 12:42:48 -08:00
{
$sefPath = 'media/img/' ;
2021-01-14 17:32:08 -08:00
$clean = array ( '{e_MEDIA_IMAGE}' , 'e_MEDIA_IMAGE/' );
2016-02-04 12:42:48 -08:00
}
2020-12-20 11:50:10 -08:00
elseif ( strpos ( $url , 'e_AVATAR' ) !== false ) // avatars
2016-02-04 12:42:48 -08:00
{
$sefPath = 'media/avatar/' ;
2021-01-14 17:32:08 -08:00
$clean = array ( '{e_AVATAR}' , 'e_AVATAR/' );
2016-02-04 12:42:48 -08:00
}
2020-12-20 11:50:10 -08:00
elseif ( strpos ( $url , 'e_THEME' ) !== false ) // theme folder images.
2016-02-06 19:33:23 -08:00
{
$sefPath = 'theme/img/' ;
2021-01-14 17:32:08 -08:00
$clean = array ( '{e_THEME}' , 'e_THEME/' );
2016-02-06 19:33:23 -08:00
}
2016-02-04 12:42:48 -08:00
else
{
2016-04-13 14:30:42 -07:00
// e107::getDebug()->log("SEF URL False: ".$url);
2016-02-04 12:42:48 -08:00
return false ;
}
2016-02-03 18:17:14 -08:00
// Build URL for ReWriteRule ^media\/img\/(a)?([\d]*)x(a)?([\d]*)\/(.*)?$ thumb.php?src=e_MEDIA_IMAGE/$5&$1w=$2&$3h=$4
2021-01-14 17:32:08 -08:00
$sefUrl = $base . $sefPath ;
2016-02-03 18:17:14 -08:00
2021-01-15 14:24:28 -08:00
if ( ! empty ( $options [ 'scale' ]))
{
$multiInt = ( int ) $options [ 'scale' ];
$options [ 'w' ] = $options [ 'w' ] * $multiInt ;
$options [ 'h' ] = $options [ 'h' ] * $multiInt ;
}
2020-12-20 11:50:10 -08:00
if ( ! empty ( $options [ 'aw' ]) || ! empty ( $options [ 'ah' ]))
2016-02-03 18:17:14 -08:00
{
2021-01-14 17:32:08 -08:00
$sefUrl .= 'a' . intval ( $options [ 'aw' ]) . 'xa' . intval ( $options [ 'ah' ]);
2016-02-03 18:17:14 -08:00
}
2016-04-13 14:30:42 -07:00
elseif ( ! empty ( $options [ 'crop' ]))
{
2016-10-11 14:58:08 -07:00
2016-10-18 10:20:10 -07:00
if ( ! is_numeric ( $options [ 'crop' ]))
2016-10-11 14:58:08 -07:00
{
2021-01-14 17:32:08 -08:00
$sefUrl .= strtolower ( $options [ 'crop' ]) . intval ( $options [ 'w' ]) . 'x' . strtolower ( $options [ 'crop' ]) . intval ( $options [ 'h' ]);
2016-10-11 14:58:08 -07:00
}
else
{
2021-01-14 17:32:08 -08:00
$sefUrl .= 'a' . intval ( $options [ 'w' ]) . 'xa' . intval ( $options [ 'h' ]);
2016-10-11 14:58:08 -07:00
}
2016-04-13 14:30:42 -07:00
}
2016-02-03 18:17:14 -08:00
else
{
2021-01-14 17:32:08 -08:00
$sefUrl .= intval ( $options [ 'w' ]) . 'x' . intval ( $options [ 'h' ]);
2016-02-03 18:17:14 -08:00
}
$sefUrl .= '/' ;
2021-01-14 17:32:08 -08:00
$sefUrl .= str_replace ( $clean , '' , $url );
2016-02-03 18:17:14 -08:00
return $sefUrl ;
}
2010-03-10 12:48:05 +00:00
/**
* Help for converting to more safe URLs
* e . g . { e_MEDIA_FILE } path / to / video . flv => e_MEDIA_FILE / path / to / video . flv
*
* @ param string $type sc | raw | rev | all
* @ return array
2021-01-14 17:32:08 -08:00
* @ todo support for ALL URL shortcodes ( replacement methods )
2010-03-10 12:48:05 +00:00
*/
public function getUrlConstants ( $type = 'sc' )
{
2021-01-14 17:32:08 -08:00
2010-03-10 15:43:42 +00:00
// sub-folders first!
2010-03-10 12:48:05 +00:00
static $array = array (
2021-01-14 17:32:08 -08:00
'e_MEDIA_FILE/' => '{e_MEDIA_FILE}' ,
'e_MEDIA_VIDEO/' => '{e_MEDIA_VIDEO}' ,
'e_MEDIA_IMAGE/' => '{e_MEDIA_IMAGE}' ,
'e_MEDIA_ICON/' => '{e_MEDIA_ICON}' ,
'e_AVATAR/' => '{e_AVATAR}' ,
2013-05-07 20:30:20 -07:00
'e_AVATAR_DEFAULT/' => '{e_AVATAR_DEFAULT}' ,
2021-01-14 17:32:08 -08:00
'e_AVATAR_UPLOAD/' => '{e_AVATAR_UPLOAD}' ,
'e_WEB_JS/' => '{e_WEB_JS}' ,
'e_WEB_CSS/' => '{e_WEB_CSS}' ,
'e_WEB_IMAGE/' => '{e_WEB_IMAGE}' ,
'e_IMPORT/' => '{e_IMPORT}' ,
// 'e_WEB_PACK/' => '{e_WEB_PACK}',
'e_BASE/' => '{e_BASE}' ,
'e_ADMIN/' => '{e_ADMIN}' ,
'e_IMAGE/' => '{e_IMAGE}' ,
'e_THEME/' => '{e_THEME}' ,
'e_PLUGIN/' => '{e_PLUGIN}' ,
'e_HANDLER/' => '{e_HANDLER}' , // BC
'e_MEDIA/' => '{e_MEDIA}' ,
'e_WEB/' => '{e_ADMIN}' ,
// 'THEME/' => '{THEME}',
2010-03-10 12:48:05 +00:00
);
2021-01-14 17:32:08 -08:00
switch ( $type )
2010-03-10 12:48:05 +00:00
{
case 'sc' :
return array_values ( $array );
2021-01-14 17:32:08 -08:00
break ;
2010-03-10 12:48:05 +00:00
case 'raw' :
return array_keys ( $array );
2021-01-14 17:32:08 -08:00
break ;
2010-03-10 12:48:05 +00:00
case 'rev' :
return array_reverse ( $array , true );
2021-01-14 17:32:08 -08:00
break ;
2010-03-10 12:48:05 +00:00
case 'all' :
return $array ;
2021-01-14 17:32:08 -08:00
break ;
2010-03-10 12:48:05 +00:00
}
2021-01-14 17:32:08 -08:00
2010-03-10 12:48:05 +00:00
return array ();
}
2013-04-22 20:46:06 -07:00
2020-12-14 16:21:48 -08:00
public function getEmotes ()
2013-04-22 20:46:06 -07:00
{
2021-01-14 17:32:08 -08:00
2021-01-14 17:26:15 -08:00
return e107 :: getEmote () -> getList ();
2013-04-22 20:46:06 -07:00
}
2009-09-02 16:39:32 +00:00
/**
* Replace e107 path constants
2009-10-30 19:57:28 +00:00
* Note : only an ADMIN user can convert { e_ADMIN }
2011-01-03 10:54:08 +00:00
* TODO - runtime cache of search / replace arrays ( object property ) when $mode !== ''
2009-09-12 18:20:23 +00:00
* @ param string $text
2021-01-14 17:32:08 -08:00
* @ param string $mode [ optional ] abs | full " full " = produce absolute URL path , e . g . http :// sitename . com / e107_plugins / etc
* 'abs' = produce truncated URL path , e . g . e107plugins / etc
* " " ( default ) = URL ' s get relative path e . g . ../ e107_plugins / etc
* @ param mixed $all [ optional ] if TRUE , then when $mode is " full " or TRUE , USERID is also replaced ...
* when $mode is " " ( default ), ALL other e107 constants are replaced
2020-12-18 19:55:12 -08:00
* @ return string | array
2009-09-02 16:39:32 +00:00
*/
2021-01-14 17:32:08 -08:00
public function replaceConstants ( $text , $mode = '' , $all = false )
2006-12-02 04:36:16 +00:00
{
2021-01-14 17:32:08 -08:00
2017-01-27 14:18:12 -08:00
if ( is_array ( $text ))
{
$new = array ();
2021-01-14 17:32:08 -08:00
foreach ( $text as $k => $v )
2017-01-27 14:18:12 -08:00
{
2021-01-14 17:32:08 -08:00
$new [ $k ] = $this -> replaceConstants ( $v , $mode , $all );
2017-01-27 14:18:12 -08:00
}
return $new ;
}
2021-01-14 14:46:49 -08:00
$replace_absolute = array ();
2020-12-21 06:41:45 -08:00
if ( ! empty ( $mode ))
2006-12-02 04:36:16 +00:00
{
2009-08-19 14:39:57 +00:00
$e107 = e107 :: getInstance ();
2009-10-30 19:57:28 +00:00
2020-12-21 06:41:45 -08:00
if ( empty ( $this -> relativePaths )) // prevent multiple lookups.
{
$this -> relativePaths = array (
$e107 :: getFolder ( 'media_files' ),
$e107 :: getFolder ( 'media_video' ),
$e107 :: getFolder ( 'media_image' ),
$e107 :: getFolder ( 'media_icon' ),
$e107 :: getFolder ( 'avatars' ),
$e107 :: getFolder ( 'web_js' ),
$e107 :: getFolder ( 'web_css' ),
$e107 :: getFolder ( 'web_image' ),
//$e107->getFolder('web_pack'),
e_IMAGE_ABS ,
e_THEME_ABS ,
$e107 :: getFolder ( 'images' ),
$e107 :: getFolder ( 'plugins' ),
$e107 :: getFolder ( 'files' ),
$e107 :: getFolder ( 'themes' ),
2021-01-14 17:32:08 -08:00
// $e107->getFolder('downloads'),
2020-12-21 06:41:45 -08:00
$e107 :: getFolder ( 'handlers' ),
$e107 :: getFolder ( 'media' ),
$e107 :: getFolder ( 'web' ),
2021-01-14 17:32:08 -08:00
$e107 -> site_theme ? $e107 :: getFolder ( 'themes' ) . $e107 -> site_theme . '/' : '' ,
2020-12-21 06:41:45 -08:00
defset ( 'THEME_ABS' ),
( ADMIN ? $e107 :: getFolder ( 'admin' ) : '' ),
'' ,
$e107 :: getFolder ( 'core' ),
$e107 :: getFolder ( 'system' ),
);
}
$replace_relative = $this -> relativePaths ;
2009-08-19 14:39:57 +00:00
2021-01-14 17:32:08 -08:00
switch ( $mode )
2009-07-17 02:28:49 +00:00
{
2009-08-19 14:39:57 +00:00
case 'abs' :
2009-10-30 19:57:28 +00:00
$replace_absolute = array (
2010-03-10 15:43:42 +00:00
e_MEDIA_FILE_ABS ,
e_MEDIA_VIDEO_ABS ,
e_MEDIA_IMAGE_ABS ,
e_MEDIA_ICON_ABS ,
2013-04-19 22:50:41 -07:00
e_AVATAR_ABS ,
2010-03-10 15:43:42 +00:00
e_JS_ABS ,
e_CSS_ABS ,
e_WEB_IMAGE_ABS ,
2021-01-14 17:32:08 -08:00
// e_PACK_ABS,
2009-08-19 14:39:57 +00:00
e_IMAGE_ABS ,
e_THEME_ABS ,
e_IMAGE_ABS ,
e_PLUGIN_ABS ,
e_FILE_ABS ,
e_THEME_ABS ,
2021-01-14 17:32:08 -08:00
// e_DOWNLOAD_ABS, //impossible when download is done via php.
2012-12-16 19:23:11 +00:00
'' , // handlers - no ABS path available
2010-03-10 15:43:42 +00:00
e_MEDIA_ABS ,
e_WEB_ABS ,
2011-01-03 10:54:08 +00:00
defset ( 'THEME_ABS' ),
defset ( 'THEME_ABS' ),
( ADMIN ? e_ADMIN_ABS : '' ),
2011-11-25 17:36:40 +00:00
$e107 -> server_path ,
'' , // no e_CORE absolute path
'' , // no e_SYSTEM absolute path
2009-08-19 14:39:57 +00:00
);
2021-01-14 17:32:08 -08:00
break ;
2009-10-30 19:57:28 +00:00
2009-08-19 14:39:57 +00:00
case 'full' :
$replace_absolute = array (
2021-01-14 17:32:08 -08:00
SITEURLBASE . e_MEDIA_FILE_ABS ,
SITEURLBASE . e_MEDIA_VIDEO_ABS ,
SITEURLBASE . e_MEDIA_IMAGE_ABS ,
SITEURLBASE . e_MEDIA_ICON_ABS ,
SITEURLBASE . e_AVATAR_ABS ,
SITEURLBASE . e_JS_ABS ,
SITEURLBASE . e_CSS_ABS ,
SITEURLBASE . e_WEB_IMAGE_ABS ,
// SITEURLBASE.e_PACK_ABS,
SITEURLBASE . e_IMAGE_ABS ,
SITEURLBASE . e_THEME_ABS ,
SITEURLBASE . e_IMAGE_ABS ,
SITEURLBASE . e_PLUGIN_ABS ,
SITEURLBASE . e_FILE_ABS , // deprecated
SITEURLBASE . e_THEME_ABS ,
2010-03-10 15:43:42 +00:00
//SITEURL.$e107->getFolder('downloads'),
2012-12-16 19:23:11 +00:00
'' , // handlers - no ABS path available
2021-01-14 17:32:08 -08:00
SITEURLBASE . e_MEDIA_ABS ,
SITEURLBASE . e_WEB_ABS ,
defset ( 'THEME_ABS' ) ? SITEURLBASE . THEME_ABS : '' ,
defset ( 'THEME_ABS' ) ? SITEURLBASE . THEME_ABS : '' ,
( ADMIN ? SITEURLBASE . e_ADMIN_ABS : '' ),
2011-11-25 17:36:40 +00:00
SITEURL ,
'' , // no e_CORE absolute path
'' , // no e_SYSTEM absolute path
2009-08-19 14:39:57 +00:00
);
2021-01-14 17:32:08 -08:00
break ;
2009-07-17 02:28:49 +00:00
}
2010-03-10 15:43:42 +00:00
// sub-folders first!
$search = array (
'{e_MEDIA_FILE}' ,
'{e_MEDIA_VIDEO}' ,
'{e_MEDIA_IMAGE}' ,
'{e_MEDIA_ICON}' ,
2013-04-19 22:50:41 -07:00
'{e_AVATAR}' ,
2010-03-10 15:43:42 +00:00
'{e_WEB_JS}' ,
'{e_WEB_CSS}' ,
'{e_WEB_IMAGE}' ,
2021-01-14 17:32:08 -08:00
// '{e_WEB_PACK}',
2020-12-14 16:21:48 -08:00
'{e_IMAGE_ABS}' ,
'{e_THEME_ABS}' ,
'{e_IMAGE}' ,
'{e_PLUGIN}' ,
'{e_FILE}' ,
'{e_THEME}' ,
2010-03-10 15:43:42 +00:00
//,"{e_DOWNLOAD}"
2020-12-14 16:21:48 -08:00
'{e_HANDLER}' ,
'{e_MEDIA}' ,
'{e_WEB}' ,
'{THEME}' ,
'{THEME_ABS}' ,
'{e_ADMIN}' ,
'{e_BASE}' ,
'{e_CORE}' ,
'{e_SYSTEM}' ,
2009-11-14 04:13:11 +00:00
);
2009-07-17 02:28:49 +00:00
2011-01-03 10:54:08 +00:00
/* if ( ADMIN )
2009-01-03 22:32:54 +00:00
{
2009-08-20 12:27:26 +00:00
$replace_relative [] = $e107 -> getFolder ( 'admin' );
$replace_absolute [] = SITEURL . $e107 -> getFolder ( 'admin' );
2006-12-02 04:36:16 +00:00
$search [] = " { e_ADMIN} " ;
2011-01-03 10:54:08 +00:00
} */
2009-07-17 02:28:49 +00:00
2021-01-14 17:32:08 -08:00
if ( $all )
2009-01-03 22:32:54 +00:00
{
2021-01-14 17:32:08 -08:00
if ( USER )
2009-01-03 22:32:54 +00:00
{ // Can only replace with valid number for logged in users
$replace_relative [] = USERID ;
$replace_absolute [] = USERID ;
}
else
{
$replace_relative [] = '' ;
$replace_absolute [] = '' ;
}
2020-12-14 16:21:48 -08:00
$search [] = '{USERID}' ;
2010-01-12 13:11:48 +00:00
}
2011-03-19 11:54:12 +00:00
2011-01-03 10:54:08 +00:00
// current THEME
/* if ( ! defined ( 'THEME' ))
{
//if not already parsed by doReplace
$text = str_replace ( array ( '{THEME}' , '{THEME_ABS}' ), '' , $text );
}
else
{
$replace_relative [] = THEME ;
$replace_absolute [] = THEME_ABS ;
$search [] = " { THEME} " ;
$replace_relative [] = THEME ;
$replace_absolute [] = THEME_ABS ;
$search [] = " { THEME_ABS} " ;
} */
2009-07-17 02:28:49 +00:00
2021-01-14 17:32:08 -08:00
$replace = (( string ) $mode === 'full' || ( string ) $mode === 'abs' ) ? $replace_absolute : $replace_relative ;
return str_replace ( $search , $replace , $text );
2006-12-02 04:36:16 +00:00
}
2009-07-17 02:28:49 +00:00
2007-12-30 23:31:18 +00:00
// $pattern = ($all ? "#\{([A-Za-z_0-9]*)\}#s" : "#\{(e_[A-Z]*)\}#s");
2010-03-16 18:41:35 +00:00
$pattern = ( $all ? '#\{([A-Za-z_0-9]*)\}#s' : '#\{(e_[A-Z]*(?:_IMAGE|_VIDEO|_FILE|_CONTENT|_ICON|_AVATAR|_JS|_CSS|_PACK|_DB|_ABS){0,1})\}#s' );
2009-10-30 19:57:28 +00:00
$text = preg_replace_callback ( $pattern , array ( $this , 'doReplace' ), $text );
if ( ! defined ( 'THEME' ))
{
//if not already parsed by doReplace
$text = str_replace ( array ( '{THEME}' , '{THEME_ABS}' ), '' , $text );
}
2009-11-19 13:46:29 +00:00
else
{
$srch = array ( '{THEME}' , '{THEME_ABS}' );
$repl = array ( THEME , THEME_ABS );
2010-01-12 13:11:48 +00:00
$text = str_replace ( $srch , $repl , $text );
2009-11-19 13:46:29 +00:00
}
2006-12-02 04:36:16 +00:00
return $text ;
}
2009-01-03 22:32:54 +00:00
2021-01-14 17:26:15 -08:00
private function doReplace ( $matches )
2006-12-02 04:36:16 +00:00
{
2021-01-14 17:32:08 -08:00
if ( defined ( $matches [ 1 ]) && ( deftrue ( 'ADMIN' ) || strpos ( $matches [ 1 ], 'ADMIN' ) === false ))
2006-12-02 04:36:16 +00:00
{
return constant ( $matches [ 1 ]);
}
2021-01-14 17:32:08 -08:00
2006-12-02 04:36:16 +00:00
return $matches [ 1 ];
}
2009-09-28 19:17:59 +00:00
/**
* Create and substitute e107 constants in passed URL
2009-10-30 19:57:28 +00:00
*
2009-09-28 19:17:59 +00:00
* @ param string $url
2009-11-16 20:40:39 +00:00
* @ param integer $mode 0 - folders , 1 - relative ( 'rel' ), 2 - absolute ( 'abs' ), 3 - full ( 'full' ) ( with domain ), 4 - absolute & relative ( 'mix' ) ( combination of 1 , 2 , 3 )
2009-10-30 20:05:17 +00:00
* @ return string
2009-09-28 19:17:59 +00:00
*/
2009-10-30 23:31:08 +00:00
public function createConstants ( $url , $mode = 0 )
2009-10-30 19:57:28 +00:00
{
2021-01-14 17:32:08 -08:00
2009-10-30 19:57:28 +00:00
//FIXME - create constants for absolute paths and site URL's
2021-01-14 17:32:08 -08:00
if ( ! is_numeric ( $mode ))
2009-11-16 20:40:39 +00:00
{
2021-01-14 17:32:08 -08:00
switch ( $mode )
2009-11-16 20:40:39 +00:00
{
2021-01-14 17:32:08 -08:00
case 'rel' :
$mode = 1 ;
break ;
case 'abs' :
$mode = 2 ;
break ;
case 'full' :
$mode = 3 ;
break ;
case 'mix' :
$mode = 4 ;
break ;
case 'nice' :
$mode = 5 ;
break ;
2009-11-16 20:40:39 +00:00
}
}
2009-09-28 19:17:59 +00:00
$e107 = e107 :: getInstance ();
switch ( $mode )
2006-12-02 04:36:16 +00:00
{
2009-09-28 19:17:59 +00:00
case 0 : // folder name only.
$tmp = array (
2021-01-14 17:32:08 -08:00
'{e_MEDIA_FILE}' => $e107 :: getFolder ( 'media_files' ),
'{e_MEDIA_VIDEO}' => $e107 :: getFolder ( 'media_videos' ),
'{e_MEDIA_IMAGE}' => $e107 :: getFolder ( 'media_images' ),
'{e_MEDIA_ICON}' => $e107 :: getFolder ( 'media_icons' ),
'{e_AVATAR}' => $e107 :: getFolder ( 'avatars' ),
'{e_WEB_JS}' => $e107 :: getFolder ( 'web_js' ),
'{e_WEB_CSS}' => $e107 :: getFolder ( 'web_css' ),
'{e_WEB_IMAGE}' => $e107 :: getFolder ( 'web_images' ),
// '{e_WEB_PACK}' => $e107::getFolder('web_packs'),
'{e_IMAGE}' => $e107 :: getFolder ( 'images' ),
'{e_PLUGIN}' => $e107 :: getFolder ( 'plugins' ),
'{e_FILE}' => $e107 :: getFolder ( 'files' ),
'{e_THEME}' => $e107 :: getFolder ( 'themes' ),
'{e_DOWNLOAD}' => $e107 :: getFolder ( 'downloads' ),
'{e_ADMIN}' => $e107 :: getFolder ( 'admin' ),
'{e_HANDLER}' => $e107 :: getFolder ( 'handlers' ),
'{e_MEDIA}' => $e107 :: getFolder ( 'media' ),
'{e_WEB}' => $e107 :: getFolder ( 'web' ),
'{e_UPLOAD}' => $e107 :: getFolder ( 'uploads' ),
);
break ;
2009-10-30 19:57:28 +00:00
2011-05-10 12:36:11 +00:00
2009-09-28 19:17:59 +00:00
case 1 : // relative path only
$tmp = array (
2021-01-14 17:32:08 -08:00
'{e_MEDIA_FILE}' => e_MEDIA_FILE ,
'{e_MEDIA_VIDEO}' => e_MEDIA_VIDEO ,
'{e_MEDIA_IMAGE}' => e_MEDIA_IMAGE ,
'{e_MEDIA_ICON}' => e_MEDIA_ICON ,
'{e_AVATAR}' => e_AVATAR ,
'{e_IMPORT}' => e_IMPORT ,
'{e_WEB_JS}' => e_WEB_JS ,
'{e_WEB_CSS}' => e_WEB_CSS ,
'{e_WEB_IMAGE}' => e_WEB_IMAGE ,
// '{e_WEB_PACK}' => e_WEB_PACK,
'{e_IMAGE}' => e_IMAGE ,
'{e_PLUGIN}' => e_PLUGIN ,
'{e_FILE}' => e_FILE ,
'{e_THEME}' => e_THEME ,
'{e_DOWNLOAD}' => e_DOWNLOAD ,
'{e_ADMIN}' => e_ADMIN ,
'{e_HANDLER}' => e_HANDLER ,
'{e_MEDIA}' => e_MEDIA ,
'{e_WEB}' => e_WEB ,
'{e_UPLOAD}' => e_UPLOAD ,
2009-09-28 19:17:59 +00:00
);
2021-01-14 17:32:08 -08:00
break ;
2009-10-30 19:57:28 +00:00
2009-09-28 19:17:59 +00:00
case 2 : // absolute path only
$tmp = array (
2021-01-14 17:32:08 -08:00
'{e_MEDIA_FILE}' => e_MEDIA_FILE_ABS ,
'{e_MEDIA_VIDEO}' => e_MEDIA_VIDEO_ABS ,
'{e_MEDIA_IMAGE}' => e_MEDIA_IMAGE_ABS ,
'{e_MEDIA_ICON}' => e_MEDIA_ICON_ABS ,
'{e_AVATAR}' => e_AVATAR_ABS ,
'{e_WEB_JS}' => e_JS_ABS ,
'{e_WEB_CSS}' => e_CSS_ABS ,
'{e_WEB_IMAGE}' => e_WEB_IMAGE_ABS ,
// '{e_WEB_PACK}' => e_PACK_ABS,
'{e_IMAGE}' => e_IMAGE_ABS ,
'{e_PLUGIN}' => e_PLUGIN_ABS ,
'{e_FILE}' => e_FILE_ABS , // deprecated
'{e_THEME}' => e_THEME_ABS ,
'{e_DOWNLOAD}' => e_HTTP . 'request.php?' , // FIXME - we need solution!
'{e_ADMIN}' => e_ADMIN_ABS ,
2010-03-08 16:00:36 +00:00
//'{e_HANDLER}' => e_HANDLER_ABS, - no ABS path available
2021-01-14 17:32:08 -08:00
'{e_MEDIA}' => e_MEDIA_ABS ,
'{e_WEB}' => e_WEB_ABS ,
'{e_BASE}' => e_HTTP ,
2009-09-28 19:17:59 +00:00
);
2021-01-14 17:32:08 -08:00
break ;
2009-10-30 19:57:28 +00:00
2009-09-28 19:17:59 +00:00
case 3 : // full path (e.g http://domain.com/e107_images/)
$tmp = array (
2021-01-14 17:32:08 -08:00
'{e_MEDIA_FILE}' => SITEURLBASE . e_MEDIA_FILE_ABS ,
'{e_MEDIA_VIDEO}' => SITEURLBASE . e_MEDIA_VIDEO_ABS ,
'{e_MEDIA_IMAGE}' => SITEURLBASE . e_MEDIA_IMAGE_ABS ,
'{e_MEDIA_ICON}' => SITEURLBASE . e_MEDIA_ICON_ABS ,
'{e_AVATAR}' => SITEURLBASE . e_AVATAR_ABS ,
'{e_WEB_JS}' => SITEURLBASE . e_JS_ABS ,
'{e_WEB_CSS}' => SITEURLBASE . e_CSS_ABS ,
'{e_WEB_IMAGE}' => SITEURLBASE . e_WEB_IMAGE_ABS ,
// '{e_WEB_PACK}' => SITEURLBASE.e_PACK_ABS,
'{e_IMAGE}' => SITEURLBASE . e_IMAGE_ABS ,
'{e_PLUGIN}' => SITEURLBASE . e_PLUGIN_ABS ,
'{e_FILE}' => SITEURLBASE . e_FILE_ABS , // deprecated
'{e_THEME}' => SITEURLBASE . e_THEME_ABS ,
'{e_DOWNLOAD}' => SITEURLBASE . e_HTTP . 'request.php?' , // FIXME - we need solution!
'{e_ADMIN}' => SITEURLBASE . e_ADMIN_ABS ,
2010-03-10 15:43:42 +00:00
//'{e_HANDLER}' => e_HANDLER_ABS, - no ABS path available
2021-01-14 17:32:08 -08:00
'{e_MEDIA}' => SITEURLBASE . e_MEDIA_ABS ,
'{e_WEB}' => SITEURLBASE . e_WEB_ABS ,
'{e_BASE}' => SITEURL ,
2009-09-28 19:17:59 +00:00
);
2021-01-14 17:32:08 -08:00
break ;
2009-10-30 19:57:28 +00:00
2009-09-28 19:17:59 +00:00
case 4 : // absolute & relative paths
2009-09-29 11:32:09 +00:00
$url = $this -> createConstants ( $url , 3 );
$url = $this -> createConstants ( $url , 2 );
$url = $this -> createConstants ( $url , 1 );
2021-01-14 17:32:08 -08:00
2009-09-28 19:17:59 +00:00
return $url ;
2021-01-14 17:32:08 -08:00
break ;
2009-10-30 19:57:28 +00:00
2010-03-10 12:48:05 +00:00
case 5 : // nice urls - e.g. e_MEDIA_VIDEO/mystream.flv
$url = $this -> createConstants ( $url , 4 );
2021-01-14 17:32:08 -08:00
2010-03-10 12:48:05 +00:00
return str_replace ( $this -> getUrlConstants ( 'sc' ), $this -> getUrlConstants ( 'raw' ), $url );
2021-01-14 17:32:08 -08:00
break ;
2010-03-10 12:48:05 +00:00
2009-09-28 19:17:59 +00:00
default :
$tmp = array ();
2021-01-14 17:32:08 -08:00
break ;
2006-12-02 04:36:16 +00:00
}
2009-09-28 19:17:59 +00:00
2016-01-15 13:50:41 +02:00
$hasCDN = strpos ( $url , '//' ) === 0 ;
2021-01-14 17:32:08 -08:00
foreach ( $tmp as $key => $val )
2006-12-02 04:36:16 +00:00
{
2016-01-15 13:50:41 +02:00
// Fix - don't break the CDN '//cdn.com' URLs
2021-01-14 17:32:08 -08:00
if ( $hasCDN && $val === '/' )
{
2016-01-15 13:50:41 +02:00
continue ;
}
2009-10-30 19:57:28 +00:00
$len = strlen ( $val );
if ( substr ( $url , 0 , $len ) == $val )
2006-12-02 04:36:16 +00:00
{
2009-10-30 19:57:28 +00:00
// replace the first instance only
return substr_replace ( $url , $key , 0 , $len );
2006-12-02 04:36:16 +00:00
}
}
return $url ;
2009-10-30 19:57:28 +00:00
}
2006-12-02 04:36:16 +00:00
2009-10-30 19:57:28 +00:00
//FIXME - $match not used?
2020-12-14 16:21:48 -08:00
public function e_highlight ( $text , $match )
2009-01-03 22:32:54 +00:00
{
2021-01-14 17:32:08 -08:00
2009-08-20 12:27:26 +00:00
$tags = array ();
preg_match_all ( '#<[^>]+>#' , $text , $tags );
$text = preg_replace ( '#<[^>]+>#' , '<|>' , $text );
$text = preg_replace ( '#(\b".$match."\b)#i' , '<span class="searchhighlight">\\1</span>' , $text );
2021-01-14 17:32:08 -08:00
foreach ( $tags [ 0 ] as $tag )
2009-01-03 22:32:54 +00:00
{
2009-08-20 12:27:26 +00:00
$text = preg_replace ( '#<\|>#' , $tag , $text , 1 );
2006-12-02 04:36:16 +00:00
}
2021-01-14 17:32:08 -08:00
2006-12-02 04:36:16 +00:00
return $text ;
}
2013-07-12 13:52:39 -07:00
2013-06-02 21:46:53 -07:00
/**
2021-01-14 17:32:08 -08:00
* Convert Text to a suitable format for use in emails . eg . relative links will be replaced with full links etc .
2013-06-02 21:46:53 -07:00
* @ param string $text
* @ param boolean $posted - if the text has been posted . ( uses stripslashes etc )
2021-01-14 17:32:08 -08:00
* @ param string $mods - flags for text transformation .
2013-06-02 21:46:53 -07:00
*/
2020-12-14 16:21:48 -08:00
public function toEmail ( $text , $posted = '' , $mods = 'parse_sc, no_make_clickable' )
2006-12-02 04:36:16 +00:00
{
2021-01-14 17:32:08 -08:00
if ( $posted === true )
2007-12-30 23:31:18 +00:00
{
2021-01-14 17:32:08 -08:00
if ( MAGIC_QUOTES_GPC )
2011-03-19 11:54:12 +00:00
{
$text = stripslashes ( $text );
}
$text = preg_replace ( '#\[(php)#i' , '[\\1' , $text );
2006-12-02 04:36:16 +00:00
}
2020-12-14 16:21:48 -08:00
$text = ( strtolower ( $mods ) !== 'rawtext' ) ? $this -> replaceConstants ( $text , 'full' ) : $text ;
2015-05-21 21:49:32 -07:00
if ( $this -> isHtml ( $text ))
{
2020-12-14 16:21:48 -08:00
$text = str_replace ( array ( '[html]' , '[/html]' ), '' , $text );
2021-01-14 17:32:08 -08:00
$text = html_entity_decode ( $text , ENT_COMPAT , 'UTF-8' );
2015-05-21 21:49:32 -07:00
}
else
{
2015-07-16 18:12:41 -07:00
2015-05-21 21:49:32 -07:00
$text = $this -> toHTML ( $text , true , $mods );
}
2009-10-30 19:57:28 +00:00
return $text ;
2006-12-02 04:36:16 +00:00
}
2008-10-30 22:42:41 +00:00
2013-06-02 21:46:53 -07:00
/**
2016-03-09 12:12:15 -08:00
* Given an email address , returns a link including with obfuscated text .
* e - email css in e107 . css inserts the user / domain data for display .
*
* @ param string $email
* @ param string $words [ optional ] text to display
* @ param null $subject [ optional ] default subject for email .
* @ return string
2013-06-02 21:46:53 -07:00
*/
2021-01-14 17:32:08 -08:00
public function emailObfuscate ( $email , $words = null , $subject = null )
2008-10-30 22:42:41 +00:00
{
2021-01-14 17:32:08 -08:00
2016-03-09 12:12:15 -08:00
if ( strpos ( $email , '@' ) === false )
2008-10-30 22:42:41 +00:00
{
return '' ;
}
2016-03-09 12:12:15 -08:00
2021-01-14 17:32:08 -08:00
if ( $subject )
2008-10-30 22:42:41 +00:00
{
2021-01-14 17:32:08 -08:00
$subject = '?subject=' . $subject ;
2008-10-30 22:42:41 +00:00
}
2016-03-09 12:12:15 -08:00
2009-10-30 19:57:28 +00:00
list ( $name , $address ) = explode ( '@' , $email , 2 );
2016-03-09 12:12:15 -08:00
if ( empty ( $words ))
{
2020-12-14 16:21:48 -08:00
$words = '@' ;
2021-01-14 17:32:08 -08:00
$user = " data-user=' " . $this -> obfuscate ( $name ) . " ' " ;
$dom = " data-dom=' " . $this -> obfuscate ( $address ) . " ' " ;
2016-03-09 12:12:15 -08:00
}
else
{
$user = '' ;
$dom = '' ;
}
2021-01-14 17:32:08 -08:00
$url = 'mailto:' . $email . $subject ;
2016-03-09 12:12:15 -08:00
$safe = $this -> obfuscate ( $url );
2021-01-14 17:32:08 -08:00
return " <a class='e-email' { $user } { $dom } rel='external' href=' " . $safe . " '> " . $words . '</a>' ;
2008-10-30 22:42:41 +00:00
}
2016-03-09 12:12:15 -08:00
/**
* Obfuscate text from bots using Randomized encoding .
* @ param $text
* @ return string
*/
public function obfuscate ( $text )
{
2021-01-14 17:32:08 -08:00
2016-03-09 12:12:15 -08:00
$ret = '' ;
2021-01-14 17:32:08 -08:00
foreach ( str_split ( $text ) as $letter )
2016-03-09 12:12:15 -08:00
{
2021-01-14 17:32:08 -08:00
switch ( mt_rand ( 1 , 3 ))
2016-03-09 12:12:15 -08:00
{
// HTML entity code
case 1 :
2021-01-14 17:32:08 -08:00
$ret .= '&#' . ord ( $letter ) . ';' ;
break ;
2016-03-09 12:12:15 -08:00
// Hex character code
case 2 :
2021-01-14 17:32:08 -08:00
$ret .= '&#x' . dechex ( ord ( $letter )) . ';' ;
break ;
2016-03-09 12:12:15 -08:00
// Raw (no) encoding
case 3 :
$ret .= $letter ;
}
}
return $ret ;
}
2009-07-23 15:29:07 +00:00
public function __get ( $name )
2009-10-30 19:57:28 +00:00
{
2021-01-14 17:32:08 -08:00
2009-10-30 19:57:28 +00:00
switch ( $name )
2009-07-23 15:29:07 +00:00
{
case 'e_sc' :
2009-10-30 19:57:28 +00:00
$ret = e107 :: getScParser ();
2021-01-14 17:32:08 -08:00
break ;
2009-10-30 19:57:28 +00:00
2010-01-12 13:11:48 +00:00
2009-07-23 15:29:07 +00:00
default :
2021-01-14 17:32:08 -08:00
// trigger_error('$e107->$'.$name.' not defined', E_USER_WARNING);
return null ;
break ;
2009-07-23 15:29:07 +00:00
}
2009-10-30 19:57:28 +00:00
2010-01-12 13:11:48 +00:00
2009-07-23 15:29:07 +00:00
$this -> $name = $ret ;
2021-01-14 17:32:08 -08:00
2009-07-23 15:29:07 +00:00
return $ret ;
}
2021-01-14 17:32:08 -08:00
// Formerly located in e_parser --------------------------
2006-12-02 04:36:16 +00:00
2013-03-01 00:19:53 -08:00
2019-02-26 12:22:36 -08:00
/**
2021-01-14 17:32:08 -08:00
* Merge default 'global' attributes into assigned tags .
2019-02-26 12:22:36 -08:00
*/
2021-01-14 17:32:08 -08:00
private function compileAttributeDefaults ()
{
2019-02-26 15:03:29 -08:00
2021-01-14 17:32:08 -08:00
foreach ( $this -> allowedAttributes as $tag => $array )
{
if ( $tag === 'default' )
{
continue ;
}
2019-02-26 15:03:29 -08:00
2021-01-14 17:32:08 -08:00
foreach ( $this -> allowedAttributes [ 'default' ] as $def )
{
$this -> allowedAttributes [ $tag ][] = $def ;
}
}
2020-12-03 14:20:34 -08:00
2021-01-14 17:32:08 -08:00
}
2015-04-29 10:22:46 -07:00
2016-05-20 15:04:51 -07:00
/**
2021-01-14 17:32:08 -08:00
* Used by e_parse to start
2016-05-20 15:04:51 -07:00
*/
2021-01-14 17:32:08 -08:00
public function init ()
{
2015-04-29 10:22:46 -07:00
2019-02-26 15:03:29 -08:00
if ( defined ( 'FONTAWESOME' ))
{
$this -> fontawesome = ( int ) FONTAWESOME ;
}
if ( defined ( 'BOOTSTRAP' ))
{
$this -> bootstrap = ( int ) BOOTSTRAP ;
}
2015-04-29 10:22:46 -07:00
2020-12-03 14:20:34 -08:00
if ( defined ( 'e_HTTP_STATIC' ))
{
$this -> staticUrl = e_HTTP_STATIC ;
}
2021-01-14 18:30:32 -08:00
// Preprocess the supermods to be useful default arrays with all values
foreach ( $this -> e_SuperMods as $key => $val )
{
// precalculate super defaults
$this -> e_SuperMods [ $key ] = array_merge ( $this -> e_optDefault , $this -> e_SuperMods [ $key ]);
$this -> e_SuperMods [ $key ][ 'context' ] = $key ;
}
2020-12-08 18:15:08 -08:00
2021-02-05 19:57:53 -08:00
$this -> allowedTags = array ( 'html' , 'body' , 'div' , 'a' , 'img' , 'table' , 'tr' , 'td' , 'th' , 'tbody' , 'thead' , 'colgroup' , 'b' ,
'i' , 'pre' , 'code' , 'strong' , 'u' , 'em' , 'ul' , 'ol' , 'li' , 'img' , 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' , 'p' ,
'section' , 'article' , 'blockquote' , 'hgroup' , 'aside' , 'figure' , 'figcaption' , 'abbr' , 'span' , 'audio' , 'video' , 'source' , 'br' ,
'small' , 'caption' , 'noscript' , 'hr' , 'section' , 'iframe' , 'sub' , 'sup' , 'cite' , 'x-bbcode' , 'label'
);
$this -> scriptTags = array ( 'script' , 'applet' , 'form' , 'input' , 'button' , 'embed' , 'object' , 'ins' , 'select' , 'textarea' ); //allowed when $pref['post_script'] is enabled.
$this -> allowedAttributes = array (
'default' => array ( 'id' , 'style' , 'class' , 'title' , 'lang' , 'accesskey' ),
'img' => array ( 'src' , 'alt' , 'width' , 'height' ),
'a' => array ( 'href' , 'target' , 'rel' ),
'script' => array ( 'type' , 'src' , 'language' , 'async' ),
'iframe' => array ( 'src' , 'frameborder' , 'width' , 'height' ),
'input' => array ( 'type' , 'name' , 'value' ),
'form' => array ( 'action' , 'method' , 'target' ),
'audio' => array ( 'src' , 'controls' , 'autoplay' , 'loop' , 'muted' , 'preload' ),
'video' => array ( 'autoplay' , 'controls' , 'height' , 'loop' , 'muted' , 'poster' , 'preload' , 'src' , 'width' ),
'td' => array ( 'colspan' , 'rowspan' ),
'th' => array ( 'colspan' , 'rowspan' ),
'col' => array ( 'span' ),
'embed' => array ( 'src' , 'wmode' , 'type' , 'width' , 'height' ),
'x-bbcode' => array ( 'alt' ),
'label' => array ( 'for' ),
'source' => array ( 'media' , 'sizes' , 'src' , 'srcset' , 'type' ),
);
$this -> scriptAttributes = array ( 'onclick' , 'onchange' , 'onblur' , 'onload' , 'onfocus' , 'onkeydown' , 'onkeypress' , 'onkeyup' ,
'ondblclick' , 'onmousedown' , 'onmousemove' , 'onmouseout' , 'onmouseover' , 'onmouseup' , 'onmousewheel' ,
'onwheel' , 'oncopy' , 'oncut' , 'onpaste'
);
$this -> blockTags = array ( 'p' , 'pre' , 'div' , 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' , 'blockquote' ); // element includes its own line-break.
$this -> badAttrValues = array ( 'javascript[\s]*?:' , 'alert\(' , 'vbscript[\s]*?:' , 'data:text\/html' , 'mhtml[\s]*?:' , 'data:[\s]*?image' );
$this -> replaceAttrValues = array (
'default' => array ()
);
2021-01-14 17:32:08 -08:00
}
2015-04-16 15:23:21 -07:00
/**
* Add Allowed Tags .
* @ param string
*/
public function addAllowedTag ( $tag )
{
2021-01-14 17:32:08 -08:00
2015-04-16 15:23:21 -07:00
$this -> allowedTags [] = $tag ;
}
/**
* @ param $tag - html tag .
* @ param $attArray - array of attributes . eg . array ( 'style' , 'id' , 'class' ) etc .
*/
public function addAllowedAttribute ( $tag , $attArray )
{
2021-01-14 17:32:08 -08:00
2015-04-16 15:23:21 -07:00
$this -> allowedAttributes [ $tag ] = ( array ) $attArray ;
}
/**
2021-01-14 17:32:08 -08:00
* Set Allowed Tags .
* @ param $array
*/
public function setAllowedTags ( $array = array ())
{
$this -> allowedTags = $array ;
}
2013-03-01 00:19:53 -08:00
2015-04-29 10:22:46 -07:00
/**
* Set Script Access
* @ param $val int e_UC_MEMBER , e_UC_NOBODY , e_UC_MAINADMIN or userclass number .
*/
public function setScriptAccess ( $val )
{
2021-01-14 17:32:08 -08:00
2015-04-29 10:22:46 -07:00
$this -> scriptAccess = $val ;
}
2021-02-05 18:31:54 -08:00
public function setScriptAttibutes ( $arr )
{
$this -> scriptAttributes = ( array ) $arr ;
}
2015-04-29 10:22:46 -07:00
public function getAllowedTags ()
{
2021-01-14 17:32:08 -08:00
2015-04-29 10:22:46 -07:00
return $this -> allowedTags ;
2020-04-30 14:52:44 -07:00
}
2015-04-29 10:22:46 -07:00
2021-01-14 17:32:08 -08:00
public function getAllowedAttributes ()
2020-04-30 14:52:44 -07:00
{
2021-01-14 17:32:08 -08:00
2020-04-30 14:52:44 -07:00
return $this -> allowedAttributes ;
2015-04-29 10:22:46 -07:00
}
public function getScriptAccess ()
{
2021-01-14 17:32:08 -08:00
2015-04-29 10:22:46 -07:00
return $this -> scriptAccess ;
}
2020-04-30 14:52:44 -07:00
public function getRemoved ()
2021-01-14 17:32:08 -08:00
{
return $this -> removedList ;
}
2020-04-30 14:52:44 -07:00
2015-04-29 10:22:46 -07:00
/**
2021-01-14 17:32:08 -08:00
* Set Allowed Attributes .
* @ param $array
*/
public function setAllowedAttributes ( $array = array ())
{
$this -> allowedAttributes = $array ;
}
/**
* Set Script Tags .
* @ param $array
*/
public function setScriptTags ( $array = array ())
{
$this -> scriptTags = $array ;
}
2013-03-31 00:06:21 -07:00
2019-02-26 15:03:29 -08:00
/**
* @ param int $version
*/
public function setFontAwesome ( $version )
2021-01-14 17:32:08 -08:00
{
$this -> fontawesome = ( int ) $version ;
}
2019-02-26 15:03:29 -08:00
/**
* @ param int $version
*/
public function setBootstrap ( $version )
2021-01-14 17:32:08 -08:00
{
$this -> bootstrap = ( int ) $version ;
}
2019-02-26 15:03:29 -08:00
2021-01-14 17:32:08 -08:00
/**
2020-12-08 18:15:08 -08:00
* @ param bool $bool
*/
2020-12-09 10:54:15 -08:00
public function setConvertToWebP ( $bool )
2021-01-14 17:32:08 -08:00
{
$this -> convertToWebP = ( bool ) $bool ;
}
2020-12-08 18:15:08 -08:00
2019-02-26 15:03:29 -08:00
2013-03-31 00:06:21 -07:00
/**
* Add leading zeros to a number . eg . 3 might become 000003
2021-01-14 17:32:08 -08:00
* @ param $num integer
2013-03-31 00:06:21 -07:00
* @ param $numDigits - total number of digits
2019-02-26 13:56:07 -08:00
* @ return string number with leading zeros .
2013-03-31 00:06:21 -07:00
*/
2021-01-14 17:32:08 -08:00
public function leadingZeros ( $num , $numDigits )
2013-03-31 00:06:21 -07:00
{
2021-01-14 17:32:08 -08:00
return ( string ) sprintf ( '%0' . $numDigits . 'd' , $num );
2013-03-31 00:06:21 -07:00
}
2013-10-29 18:41:02 -07:00
/**
2015-04-12 22:45:13 -07:00
* Generic variable translator for LAN definitions .
2013-10-29 18:41:02 -07:00
* @ param $lan - string LAN
2015-04-12 22:45:13 -07:00
* @ param string | array $vals - either a single value , which will replace '[x]' or an array with key => value pairs .
* @ return string
2021-01-14 17:32:08 -08:00
* @ example $tp -> lanVars ( " My name is [x] and I own a [y] " , array ( " John " , " Cat " ));
* @ example $tp -> lanVars ( " My name is [x] and I own a [y] " , array ( 'x' => " John " , 'y' => " Cat " ));
2013-10-29 12:20:23 -07:00
*/
2021-01-14 17:32:08 -08:00
public function lanVars ( $lan , $vals , $bold = false )
2013-10-29 12:20:23 -07:00
{
2021-01-14 17:32:08 -08:00
$array = ( ! is_array ( $vals )) ? array ( 'x' => $vals ) : $vals ;
2015-04-12 22:45:13 -07:00
$search = array ();
$replace = array ();
2015-06-26 20:24:53 -07:00
$defaults = array ( 'x' , 'y' , 'z' );
2021-01-14 17:32:08 -08:00
foreach ( $array as $k => $v )
2013-10-29 12:20:23 -07:00
{
2015-06-26 20:24:53 -07:00
if ( is_numeric ( $k )) // convert array of numeric to x,y,z
{
$k = $defaults [ $k ];
}
2021-01-14 17:32:08 -08:00
$search [] = '[' . $k . ']' ;
$replace [] = ( $bold === true ) ? '<strong>' . $v . '</strong>' : $v ;
2013-10-29 12:20:23 -07:00
}
2021-01-14 17:32:08 -08:00
2013-10-29 12:20:23 -07:00
return str_replace ( $search , $replace , $lan );
}
2021-01-14 17:32:08 -08:00
2013-03-05 23:46:51 -08:00
/**
2021-01-14 17:32:08 -08:00
* Return an Array of all specific tags found in an HTML document and their attributes .
2013-03-06 01:24:04 -08:00
* @ param $html - raw html code
2021-01-14 17:32:08 -08:00
* @ param $taglist - comma separated list of tags to search or '*' for all .
* @ param $header - if the $html includes the html head or body tags - it should be set to true .
2013-03-05 23:46:51 -08:00
*/
2021-01-14 17:32:08 -08:00
public function getTags ( $html , $taglist = '*' , $header = false )
2013-03-05 23:46:51 -08:00
{
2021-01-14 17:32:08 -08:00
2013-03-06 01:24:04 -08:00
if ( $header == false )
{
2021-01-14 17:32:08 -08:00
$html = '<html><body>' . $html . '</body></html>' ;
}
$doc = $this -> domObj ;
2013-03-19 19:05:58 -07:00
$doc -> preserveWhiteSpace = true ;
2013-04-29 16:21:46 -07:00
libxml_use_internal_errors ( true );
2021-01-14 17:32:08 -08:00
$doc -> loadHTML ( $html );
2020-12-14 16:21:48 -08:00
$tg = explode ( ',' , $taglist );
2013-03-06 01:24:04 -08:00
$ret = array ();
2021-01-14 17:32:08 -08:00
2013-03-06 01:24:04 -08:00
foreach ( $tg as $find )
2013-03-05 23:46:51 -08:00
{
2021-01-14 17:32:08 -08:00
$tmp = $doc -> getElementsByTagName ( $find );
/**
* @ var $k
* @ var DOMDocument $node
*/
foreach ( $tmp as $k => $node )
2013-03-06 01:24:04 -08:00
{
$tag = $node -> nodeName ;
2013-03-18 22:14:05 -07:00
$inner = $node -> C14N ();
2021-01-14 17:32:08 -08:00
$inner = str_replace ( '
' , '' , $inner );
foreach ( $node -> attributes as $attr )
{
2013-03-06 01:24:04 -08:00
$name = $attr -> nodeName ;
2021-01-14 17:32:08 -08:00
$value = $attr -> nodeValue ;
$ret [ $tag ][ $k ][ $name ] = $value ;
2013-03-18 22:14:05 -07:00
}
2021-01-14 17:32:08 -08:00
$ret [ $tag ][ $k ][ '@value' ] = $inner ;
2013-03-06 01:24:04 -08:00
}
2013-03-05 23:46:51 -08:00
}
2021-01-14 17:32:08 -08:00
2013-03-18 22:14:05 -07:00
if ( $header == false )
{
2021-01-14 17:32:08 -08:00
unset ( $ret [ 'html' ], $ret [ 'body' ]);
}
2013-03-05 23:46:51 -08:00
return $ret ;
}
2021-01-14 17:32:08 -08:00
2013-07-12 07:13:10 -07:00
/**
2017-10-20 11:38:31 -07:00
* Parse xxxxx . glyph file to bootstrap glyph format .
2021-01-31 13:09:53 -08:00
* @ param string $text ie . fa - xxxx , fab - xxx , fas - xxxx
2017-10-20 11:38:31 -07:00
* @ param array | string $options
2021-01-14 17:32:08 -08:00
* @ param bool $options [ 'size' ] 2 x , 3 x , 4 x , or 5 x
* @ param bool $options [ 'fw' ] Fixed - Width
* @ param bool $options [ 'spin' ] Spin
* @ param int $options [ 'rotate' ] Rotate in Degrees .
2021-01-31 13:09:53 -08:00
* @ example $tp -> toGlyph ( 'fab-mailchimp' );
* @ example $tp -> toGlyph ( 'fas-camera' );
2016-02-11 12:01:26 -08:00
* @ example $tp -> toGlyph ( 'fa-spinner' , 'spin=1' );
* @ example $tp -> toGlyph ( 'fa-spinner' , array ( 'spin' => 1 ));
* @ example $tp -> toGlyph ( 'fa-shield' , array ( 'rotate' => 90 , 'size' => '2x' ));
2017-10-20 11:38:31 -07:00
*/
2021-01-14 17:32:08 -08:00
public function toGlyph ( $text , $options = ' ' )
2013-03-08 20:16:49 -08:00
{
2016-02-03 13:48:35 -08:00
2017-01-12 12:28:37 -08:00
if ( empty ( $text ))
2013-07-12 07:13:10 -07:00
{
2017-10-20 11:38:31 -07:00
return false ;
2013-07-12 07:13:10 -07:00
}
2016-02-11 12:01:26 -08:00
2017-10-20 11:38:31 -07:00
if ( is_array ( $options ))
2014-01-17 06:49:55 -08:00
{
2017-10-20 11:38:31 -07:00
$parm = $options ;
2021-01-14 17:32:08 -08:00
$options = varset ( $parm [ 'space' ], '' );
2014-01-17 06:49:55 -08:00
}
2021-01-14 17:32:08 -08:00
elseif ( strpos ( $options , '=' ))
2014-07-05 20:27:03 -07:00
{
2021-01-14 17:32:08 -08:00
parse_str ( $options , $parm );
$options = varset ( $parm [ 'space' ], '' );
2014-07-05 20:27:03 -07:00
}
2017-10-20 11:38:31 -07:00
else
2014-01-17 06:49:55 -08:00
{
$parm = array ();
}
2021-01-31 13:09:53 -08:00
$cat = '' ;
$name = '' ;
list ( $id ) = explode ( '.glyph' , $text , 2 ); // trim .glyph from the end.
if ( strpos ( $id , '-' ) !== false )
2014-01-22 06:10:44 -08:00
{
2021-01-31 13:09:53 -08:00
list ( $cat , $name ) = explode ( '-' , $id , 2 );
2016-11-01 16:42:47 -07:00
2021-01-31 13:09:53 -08:00
if ( empty ( $name )) // eg. missing something after 'fa-'
2016-11-01 16:42:47 -07:00
{
2021-01-31 13:09:53 -08:00
return null ;
2016-11-01 16:42:47 -07:00
}
2014-01-22 06:10:44 -08:00
}
2016-02-11 12:01:26 -08:00
2021-01-14 17:32:08 -08:00
$spin = null ;
$rotate = null ;
$fixedW = null ;
$prefix = 'glyphicon glyphicon-' ; // fallback
$size = null ;
$tag = 'i' ;
2017-10-20 11:38:31 -07:00
2021-01-31 13:09:53 -08:00
2021-01-30 19:21:23 -08:00
// FontAwesome General settings.
2021-01-31 13:09:53 -08:00
switch ( $cat )
2017-11-03 18:52:49 -07:00
{
2021-01-31 13:09:53 -08:00
// Core eg. e-database-32
case 'e' :
2019-02-26 15:03:29 -08:00
2021-01-31 13:09:53 -08:00
$size = ( substr ( $text , - 3 ) === '-32' ) ? 'S32' : 'S16' ;
2019-02-26 15:03:29 -08:00
2021-01-31 13:09:53 -08:00
if ( substr ( $text , - 3 ) === '-24' )
{
$size = 'S24' ;
}
2019-02-26 15:03:29 -08:00
2021-01-31 13:09:53 -08:00
return " <i class=' " . $size . ' ' . $text . " '></i> " ;
2019-02-26 15:03:29 -08:00
2021-01-31 13:09:53 -08:00
break ;
2019-02-26 15:03:29 -08:00
2017-11-03 18:52:49 -07:00
2021-01-31 13:09:53 -08:00
case " far " :
case " fab " :
case " fas " :
$prefix = $cat . ' ' ;
$id = str_replace ( $cat . '-' , 'fa-' , $id );
break ;
case " fa " :
default :
if ( $this -> fontawesome === 5 )
{
$fab = e107 :: getMedia () -> getGlyphs ( 'fab' );
$fas = e107 :: getMedia () -> getGlyphs ( 'fas' );
$far = e107 :: getMedia () -> getGlyphs ( 'far' );
$shims = e107 :: getMedia () -> getGlyphs ( 'fa5-shims' );
$fa4 = e107 :: getMedia () -> getGlyphs ( 'fa4' );
list ( $tmp ) = explode ( '-' , $id );
$code = str_replace ( $tmp . '-' , '' , $id );
2017-11-03 18:52:49 -07:00
2021-01-31 13:09:53 -08:00
if ( isset ( $shims [ $code ]))
{
$prefix = '' ;
$id = $shims [ $code ];
}
elseif ( in_array ( $code , $fab ))
{
$prefix = 'fab ' ;
}
elseif ( in_array ( $code , $fas ))
{
$prefix = 'fas ' ;
$id = 'fa-' . $code ;
}
elseif ( in_array ( $code , $far ))
{
$prefix = 'far ' ;
}
elseif ( in_array ( $code , $fa4 ))
{
$prefix = 'fa ' ;
$id = 'fa-' . $code ;
}
else
{
$prefix = ( $this -> bootstrap === 3 ) ? 'glyphicon glyphicon-' : 'fa fa-' ;
}
}
elseif ( $this -> fontawesome === 4 )
{
$fa4 = e107 :: getMedia () -> getGlyphs ( 'fa4' );
if ( isset ( $fa4 [ $name ]))
{
$prefix = 'fa ' ;
$id = 'fa-' . $name ;
}
}
elseif ( strpos ( $text , 'glyphicon-' ) === 0 ) // Bootstrap 3
{
$prefix = 'glyphicon ' ;
$tag = 'span' ;
}
elseif ( strpos ( $text , 'icon-' ) === 0 ) // Bootstrap 2
{
if ( $this -> bootstrap !== 2 ) // bootrap 2 icon but running bootstrap3.
{
$prefix = 'glyphicon ' ;
$tag = 'span' ;
$id = str_replace ( 'icon-' , 'glyphicon-' , $id );
}
else
{
$prefix = '' ;
$tag = 'i' ;
}
}
2017-11-03 18:52:49 -07:00
}
2021-01-31 13:09:53 -08:00
if ( $custom = e107 :: getThemeGlyphs ()) // Custom Glyphs
2017-11-03 18:52:49 -07:00
{
foreach ( $custom as $glyphConfig )
{
if ( strpos ( $text , $glyphConfig [ 'prefix' ]) === 0 )
{
2020-12-14 16:21:48 -08:00
$prefix = $glyphConfig [ 'class' ] . ' ' ;
2017-11-03 18:52:49 -07:00
$tag = $glyphConfig [ 'tag' ];
continue ;
}
}
2021-01-31 13:09:53 -08:00
}
else // FontAwesome shouldn't hurt legacy icons.
{
$size = ! empty ( $parm [ 'size' ]) ? ' fa-' . $parm [ 'size' ] : '' ;
$spin = ! empty ( $parm [ 'spin' ]) ? ' fa-spin' : '' ;
$rotate = ! empty ( $parm [ 'rotate' ]) ? ' fa-rotate-' . ( int ) $parm [ 'rotate' ] : '' ;
$fixedW = ! empty ( $parm [ 'fw' ]) ? ' fa-fw' : '' ;
2017-11-03 18:52:49 -07:00
}
2016-02-11 12:47:28 -08:00
2021-01-14 17:32:08 -08:00
$idAtt = ( ! empty ( $parm [ 'id' ])) ? " id=' " . $parm [ 'id' ] . " ' " : '' ;
$style = ( ! empty ( $parm [ 'style' ])) ? " style=' " . $parm [ 'style' ] . " ' " : '' ;
$class = ( ! empty ( $parm [ 'class' ])) ? $parm [ 'class' ] . ' ' : '' ;
2020-12-14 16:21:48 -08:00
$placeholder = isset ( $parm [ 'placeholder' ]) ? $parm [ 'placeholder' ] : '<!-- -->' ;
2021-01-14 17:32:08 -08:00
$title = ( ! empty ( $parm [ 'title' ])) ? " title=' " . $this -> toAttribute ( $parm [ 'title' ]) . " ' " : '' ;
2017-10-20 11:38:31 -07:00
2021-01-14 17:32:08 -08:00
$text = '<' . $tag . " { $idAtt } class=' " . $class . $prefix . $id . $size . $spin . $rotate . $fixedW . " ' " . $style . $title . '>' . $placeholder . '</' . $tag . '>' ;
2020-12-14 16:21:48 -08:00
$text .= ( $options !== false ) ? $options : '' ;
2017-10-20 11:38:31 -07:00
2014-01-22 06:10:44 -08:00
return $text ;
2017-10-20 11:38:31 -07:00
2013-03-08 20:16:49 -08:00
}
2014-01-15 04:02:05 -08:00
2016-12-07 08:23:53 -08:00
/**
2019-06-20 11:33:05 -07:00
* Return a Bootstrap Badge tag
2016-12-07 08:23:53 -08:00
* @ param $text
* @ return string
*/
2021-01-14 17:32:08 -08:00
public function toBadge ( $text , $parm = null )
2016-12-07 08:23:53 -08:00
{
2019-06-20 11:33:05 -07:00
2021-01-14 17:32:08 -08:00
$class = ! empty ( $parm [ 'class' ]) ? ' ' . $parm [ 'class' ] : ' bg-secondary rounded-pill badge-secondary' ;
return " <span class='badge " . $class . " '> " . $text . '</span>' ;
2016-12-07 08:23:53 -08:00
}
2014-01-15 04:02:05 -08:00
2017-01-21 13:42:36 -08:00
/**
2019-06-20 11:33:05 -07:00
* Return a Bootstrap Label tag
2017-01-21 13:42:36 -08:00
* @ param $text
* @ return string
*/
public function toLabel ( $text , $type = null )
{
2021-01-14 17:32:08 -08:00
2017-01-21 13:42:36 -08:00
if ( $type === null )
{
$type = 'default' ;
}
2021-01-14 17:32:08 -08:00
$tmp = explode ( ',' , $text );
2017-01-21 13:42:36 -08:00
$opt = array ();
foreach ( $tmp as $v )
{
2021-01-14 17:32:08 -08:00
$opt [] = " <span class='label label- " . $type . " '> " . $v . '</span>' ;
2017-01-21 13:42:36 -08:00
}
2021-01-14 17:32:08 -08:00
return implode ( ' ' , $opt );
2017-01-21 13:42:36 -08:00
}
/**
* Take a file - path and convert it to a download link .
* @ param $text
* @ return string
*/
2021-01-14 17:32:08 -08:00
public function toFile ( $text , $parm = array ())
2017-01-21 13:42:36 -08:00
{
2021-01-14 17:32:08 -08:00
2017-01-23 10:31:30 -08:00
$srch = array (
'{e_MEDIA_FILE}' => 'e_MEDIA_FILE/' ,
2021-01-14 17:32:08 -08:00
'{e_PLUGIN}' => 'e_PLUGIN/'
2017-01-23 10:31:30 -08:00
);
2021-01-14 17:32:08 -08:00
$link = e_HTTP . 'request.php?file=' . str_replace ( array_keys ( $srch ), $srch , $text );
2017-01-21 13:42:36 -08:00
2017-01-21 13:59:55 -08:00
if ( ! empty ( $parm [ 'raw' ]))
{
return $link ;
}
2021-01-14 17:32:08 -08:00
return " <a href=' " . $link . " '>-attachment-</a> " ; //TODO Add pref for this.
2017-01-21 13:42:36 -08:00
}
2015-02-04 20:36:56 -08:00
/**
2021-01-14 17:32:08 -08:00
* Render an avatar based on supplied user data or current user when missing .
* @ param array $userData - user data from e107_user . ie . user_image , user_id etc .
2020-01-19 15:35:36 -08:00
* @ param array $options
2021-01-14 17:32:08 -08:00
* @ param int $options [ 'w' ] - image width in px
* @ param int $options [ 'h' ] - image height in px
* @ param int | bool $options [ 'crop' ] = enables cropping when true
* @ param string $options [ 'shape' ] - ( optional ) rounded | circle | thumbnail
* @ param string $options [ 'id' ] - 'id' attribute will be added to tag .
* @ param string $options [ 'class' ] - override default 'class' attribute in tag .
* @ param string $options [ 'alt' ] - override default 'alt' attribute in tag .
* @ param bool $options [ 'base64' ] - use embedded base64 for image src .
* @ param bool $options [ 'hd' ] - double the resolution of the image . Useful for retina displays .
* @ param string $options [ 'type' ] - when set to 'url' returns the URL value instead of the tag .
* @ param string $options [ 'style' ] - sets the style attribute .
* @ param string $options [ 'mode' ] - 'full' url mode .
2019-05-16 10:50:18 -07:00
* @ return string < img > tag of avatar .
2015-02-04 20:36:56 -08:00
*/
2021-01-14 17:32:08 -08:00
public function toAvatar ( $userData = null , $options = array ())
2015-02-04 20:36:56 -08:00
{
2021-01-14 17:32:08 -08:00
$tp = e107 :: getParser ();
$width = ! empty ( $options [ 'w' ]) ? intval ( $options [ 'w' ]) : $tp -> thumbWidth ;
$height = ( $tp -> thumbHeight !== 0 ) ? $tp -> thumbHeight : '' ;
$crop = isset ( $options [ 'crop' ]) ? $options [ 'crop' ] : $tp -> thumbCrop ;
$linkStart = '' ;
$linkEnd = '' ;
$full = ! empty ( $options [ 'base64' ]) ? true : false ;
$file = '' ;
2017-01-08 08:53:36 -08:00
2020-06-01 13:05:50 -07:00
if ( ! empty ( $options [ 'mode' ]) && $options [ 'mode' ] === 'full' )
{
$full = true ;
}
2017-01-16 13:27:26 -08:00
if ( ! empty ( $options [ 'h' ]))
{
$height = intval ( $options [ 'h' ]);
}
2020-01-27 11:37:57 -08:00
if ( ! empty ( $options [ 'hd' ])) // Fix resolution on Retina display.
{
2020-12-14 16:21:48 -08:00
$width *= 2 ;
$height *= 2 ;
2020-01-27 11:37:57 -08:00
}
2017-01-16 13:27:26 -08:00
2017-01-08 08:53:36 -08:00
if ( $userData === null && USERID )
2015-02-04 20:36:56 -08:00
{
2016-06-09 16:43:36 -07:00
$userData = array ();
2021-01-14 17:32:08 -08:00
$userData [ 'user_id' ] = USERID ;
$userData [ 'user_image' ] = deftrue ( 'USERIMAGE' );
$userData [ 'user_name' ] = deftrue ( 'USERNAME' );
2020-12-20 13:25:03 -08:00
$userData [ 'user_currentvisit' ] = deftrue ( 'USERCURRENTVISIT' );
2015-02-04 20:36:56 -08:00
}
2017-01-08 08:53:36 -08:00
2021-01-14 17:32:08 -08:00
2016-03-08 17:51:29 -08:00
$image = ( ! empty ( $userData [ 'user_image' ])) ? varset ( $userData [ 'user_image' ]) : null ;
2017-01-09 11:52:12 -08:00
2021-01-14 17:32:08 -08:00
$genericFile = e_IMAGE . 'generic/blank_avatar.jpg' ;
$genericImg = $tp -> thumbUrl ( $genericFile , 'w=' . $width . '&h=' . $height , true , $full );
if ( ! empty ( $image ))
2015-02-04 20:36:56 -08:00
{
2021-01-14 17:32:08 -08:00
if ( strpos ( $image , '://' ) !== false ) // Remote Image
2015-02-04 20:36:56 -08:00
{
2021-01-14 17:32:08 -08:00
$url = $image ;
2015-02-04 20:36:56 -08:00
}
2021-01-14 18:30:32 -08:00
elseif ( strpos ( $image , '-upload-' ) === 0 )
2015-02-04 20:36:56 -08:00
{
2021-01-14 17:32:08 -08:00
$image = substr ( $image , 8 ); // strip the -upload- from the beginning.
if ( file_exists ( e_AVATAR_UPLOAD . $image ))
2020-01-19 15:35:36 -08:00
{
2021-01-14 17:32:08 -08:00
$file = e_AVATAR_UPLOAD . $image ;
$url = $tp -> thumbUrl ( $file , 'w=' . $width . '&h=' . $height . '&crop=' . $crop , false , $full );
2020-01-19 15:35:36 -08:00
}
else
{
$file = $genericFile ;
$url = $genericImg ;
}
2015-02-04 20:36:56 -08:00
}
2021-01-14 17:32:08 -08:00
elseif ( file_exists ( e_AVATAR_DEFAULT . $image )) // User-Uplaoded Image
2015-02-04 20:36:56 -08:00
{
2021-01-14 17:32:08 -08:00
$file = e_AVATAR_DEFAULT . $image ;
$url = $tp -> thumbUrl ( $file , 'w=' . $width . '&h=' . $height . '&crop=' . $crop , false , $full );
2015-02-04 20:36:56 -08:00
}
2021-01-14 17:32:08 -08:00
else // Image Missing.
2015-02-04 20:36:56 -08:00
{
2020-01-19 15:35:36 -08:00
$url = $genericImg ;
$file = $genericFile ;
2015-02-04 20:36:56 -08:00
}
}
2021-01-14 17:32:08 -08:00
else // No image provided - so send generic.
2015-02-04 20:36:56 -08:00
{
2020-01-19 15:35:36 -08:00
$url = $genericImg ;
$file = $genericFile ;
2015-02-04 20:36:56 -08:00
}
2016-02-25 18:43:49 -08:00
2020-01-19 15:35:36 -08:00
if ( ! empty ( $options [ 'base64' ])) // embed image data into URL.
{
2021-01-14 17:32:08 -08:00
$content = e107 :: getFile () -> getRemoteContent ( $url ); // returns false during unit tests, works otherwise.
2020-01-19 15:35:36 -08:00
if ( ! empty ( $content ))
{
2021-01-14 17:32:08 -08:00
$ext = strtolower ( pathinfo ( $file , PATHINFO_EXTENSION ));
$url = 'data:image/' . $ext . ';base64,' . base64_encode ( $content );
2020-01-19 15:35:36 -08:00
}
2020-01-27 11:37:57 -08:00
}
2020-01-19 15:35:36 -08:00
2020-01-27 11:37:57 -08:00
if ( ! empty ( $options [ 'hd' ])) // Fix resolution on Retina display.
{
$width = $width / 2 ;
$height = ( $height / 2 );
2020-01-19 15:35:36 -08:00
}
2021-01-14 17:32:08 -08:00
if (( $url == $genericImg ) && ! empty ( $userData [ 'user_id' ]) && (( $userData [ 'user_id' ] == USERID )) && ! empty ( $options [ 'link' ]))
2016-02-25 18:43:49 -08:00
{
2021-01-14 17:32:08 -08:00
$linkStart = " <a class='e-tip' title= \" " . LAN_EDIT . " \" href=' " . e107 :: getUrl () -> create ( 'user/myprofile/edit' ) . " '> " ;
2020-12-14 16:21:48 -08:00
$linkEnd = '</a>' ;
2016-02-25 18:43:49 -08:00
}
2021-01-14 17:32:08 -08:00
2015-02-04 20:36:56 -08:00
$title = ( ADMIN ) ? $image : $tp -> toAttribute ( $userData [ 'user_name' ]);
2021-01-14 17:32:08 -08:00
$shape = ( ! empty ( $options [ 'shape' ])) ? 'img-' . $options [ 'shape' ] : 'img-rounded rounded' ;
2016-03-08 17:51:29 -08:00
2020-12-30 07:57:43 -08:00
if ( $shape === 'img-circle' )
{
2021-01-14 18:30:32 -08:00
$shape .= ' rounded-circle' ;
2020-12-30 07:57:43 -08:00
}
2017-11-01 15:13:02 -07:00
2017-01-29 18:43:52 -08:00
if ( ! empty ( $options [ 'type' ]) && $options [ 'type' ] === 'url' )
2016-03-08 17:51:29 -08:00
{
2020-01-19 15:35:36 -08:00
return $url ;
2016-03-08 17:51:29 -08:00
}
2015-12-16 15:28:05 +01:00
2020-01-19 15:35:36 -08:00
if ( ! empty ( $options [ 'alt' ]))
{
2021-01-14 17:32:08 -08:00
$title = $tp -> toAttribute ( $options [ 'alt' ]);
2020-01-19 15:35:36 -08:00
}
2016-01-30 18:39:01 -08:00
2021-01-14 17:32:08 -08:00
$heightInsert = empty ( $height ) ? '' : " height=' " . $height . " ' " ;
$id = ( ! empty ( $options [ 'id' ])) ? " id=' " . $options [ 'id' ] . " ' " : '' ;
2016-01-30 18:39:01 -08:00
2020-12-14 16:21:48 -08:00
$classOnline = ( ! empty ( $userData [ 'user_currentvisit' ]) && intval ( $userData [ 'user_currentvisit' ]) > ( time () - 300 )) ? ' user-avatar-online' : '' ;
2017-01-13 12:22:47 -08:00
2021-01-14 17:32:08 -08:00
$class = ! empty ( $options [ 'class' ]) ? $options [ 'class' ] : $shape . ' user-avatar' ;
$style = ! empty ( $options [ 'style' ]) ? " style=' " . $options [ 'style' ] . " ' " : '' ;
2017-11-01 15:13:02 -07:00
2016-02-25 18:43:49 -08:00
$text = $linkStart ;
2021-01-14 17:32:08 -08:00
$text .= '<img ' . $id . " class=' " . $class . $classOnline . " ' alt= \" " . $title . " \" src=' " . $url . " ' width=' " . $width . " ' " . $heightInsert . $style . ' />' ;
2016-02-25 18:43:49 -08:00
$text .= $linkEnd ;
2021-01-14 17:32:08 -08:00
// return $url;
2015-02-04 20:36:56 -08:00
return $text ;
2021-01-14 17:32:08 -08:00
2015-02-04 20:36:56 -08:00
}
2013-07-12 13:52:39 -07:00
/**
2021-01-14 17:32:08 -08:00
* Display an icon .
* @ param string $icon
* @ example $tp -> toIcon ( " { e_IMAGES}icons/something.png " );
2013-07-12 13:52:39 -07:00
*/
2021-01-14 17:32:08 -08:00
public function toIcon ( $icon = '' , $parm = array ())
2013-07-12 13:52:39 -07:00
{
2016-04-15 10:46:58 -07:00
2017-01-31 14:50:55 -08:00
if ( empty ( $icon ))
2013-07-12 13:52:39 -07:00
{
2017-01-31 14:50:55 -08:00
return null ;
2013-07-12 13:52:39 -07:00
}
2016-02-03 13:48:35 -08:00
2021-01-14 17:32:08 -08:00
// if(strpos($icon,'e_MEDIA_IMAGE')!==false)
// {
2016-02-09 22:53:03 -08:00
// return "<div class='alert alert-danger'>Use \$tp->toImage() instead of toIcon() for ".$icon."</div>"; // debug info only.
2021-01-14 17:32:08 -08:00
// }
2016-02-09 22:53:03 -08:00
2020-12-14 16:21:48 -08:00
if ( strpos ( $icon , '<i ' ) === 0 ) // if it's html (ie. css sprite) return the code.
2016-02-03 13:48:35 -08:00
{
return $icon ;
}
2021-01-14 17:32:08 -08:00
2014-01-22 06:10:44 -08:00
$ext = pathinfo ( $icon , PATHINFO_EXTENSION );
2016-02-07 13:37:45 -08:00
$dimensions = null ;
2021-01-14 17:32:08 -08:00
2020-12-14 16:21:48 -08:00
if ( ! $ext || $ext === 'glyph' ) // Bootstrap or Font-Awesome.
2013-12-30 03:56:27 -08:00
{
2021-01-14 17:32:08 -08:00
return $this -> toGlyph ( $icon , $parm );
2013-12-30 03:56:27 -08:00
}
2021-01-14 17:32:08 -08:00
if ( strpos ( $icon , 'e_MEDIA_IMAGE' ) !== false )
2013-12-30 03:56:27 -08:00
{
2014-01-04 06:02:24 -08:00
$path = $this -> thumbUrl ( $icon );
2016-02-07 13:37:45 -08:00
$dimensions = $this -> thumbDimensions ();
2014-01-04 10:14:38 -08:00
}
2017-01-29 18:43:52 -08:00
elseif ( $icon [ 0 ] === '{' )
2014-01-04 10:14:38 -08:00
{
2021-01-14 17:32:08 -08:00
$path = $this -> replaceConstants ( $icon , 'abs' );
2013-12-30 03:56:27 -08:00
}
2016-04-15 10:46:58 -07:00
elseif ( ! empty ( $parm [ 'legacy' ]))
2013-12-30 03:56:27 -08:00
{
2016-04-15 10:46:58 -07:00
$legacyList = ( ! is_array ( $parm [ 'legacy' ])) ? array ( $parm [ 'legacy' ]) : $parm [ 'legacy' ];
foreach ( $legacyList as $legPath )
2013-12-30 03:56:27 -08:00
{
2021-01-14 17:32:08 -08:00
$legacyPath = $legPath . $icon ;
2016-04-15 10:46:58 -07:00
$filePath = $this -> replaceConstants ( $legacyPath );
if ( is_readable ( $filePath ))
{
2021-01-14 17:32:08 -08:00
$path = $this -> replaceConstants ( $legacyPath , 'full' );
2016-04-15 10:46:58 -07:00
break ;
}
2013-12-30 03:56:27 -08:00
}
2016-04-15 10:46:58 -07:00
if ( empty ( $path ))
2013-12-30 03:56:27 -08:00
{
2020-12-21 10:00:28 -08:00
$log = e107 :: getLog ();
2021-01-14 17:32:08 -08:00
$log -> addDebug ( 'Broken Icon Path: ' . $icon . " \n " . print_r ( debug_backtrace ( null , 2 ), true ), false ) -> save ( 'IMALAN_00' );
e107 :: getDebug () -> log ( 'Broken Icon Path: ' . $icon );
2016-04-15 10:46:58 -07:00
return null ;
2013-12-30 03:56:27 -08:00
}
2021-01-14 17:32:08 -08:00
2013-12-30 03:56:27 -08:00
}
2021-01-14 17:32:08 -08:00
else
2014-01-15 04:02:05 -08:00
{
$path = $icon ;
}
2016-02-07 13:37:45 -08:00
2016-04-15 10:46:58 -07:00
$alt = ( ! empty ( $parm [ 'alt' ])) ? $this -> toAttribute ( $parm [ 'alt' ]) : basename ( $path );
$class = ( ! empty ( $parm [ 'class' ])) ? $parm [ 'class' ] : 'icon' ;
2021-01-14 17:32:08 -08:00
2021-01-30 19:21:23 -08:00
if ( $ext === 'svg' )
{
$class .= ' icon-svg fa-2x' ;
if ( ! empty ( $parm [ 'size' ]))
{
$class .= ' icon-svg-' . $parm [ 'size' ];
}
}
2021-01-14 17:32:08 -08:00
return " <img class=' " . $class . " ' src=' " . $path . " ' alt=' " . $alt . " ' " . $dimensions . ' />' ;
2015-04-05 20:24:51 -07:00
}
2014-01-15 04:02:05 -08:00
2015-04-05 20:24:51 -07:00
/**
2020-04-17 12:02:10 -07:00
* Render an img tag .
2016-02-09 11:02:08 -08:00
* @ param string $file
2021-01-14 17:32:08 -08:00
* @ param array $parm keys : legacy | w | h | alt | class | id | crop | loading
* @ param array $parm [ 'legacy' ] Usually a legacy path like { e_FILE }
* @ param array $parm [ 'type' ] Force the returned image to be a jpg , webp etc .
2015-04-05 20:24:51 -07:00
* @ return string
* @ example $tp -> toImage ( 'welcome.png' , array ( 'legacy' => { e_IMAGE } newspost_images / ',' w ' => 200 ));
*/
2021-01-14 17:32:08 -08:00
public function toImage ( $file , $parm = array ())
2015-04-05 20:24:51 -07:00
{
2021-01-14 17:32:08 -08:00
if ( strpos ( $file , 'e_AVATAR' ) !== false )
2016-02-09 22:53:03 -08:00
{
2021-01-14 17:32:08 -08:00
return " <div class='alert alert-danger'>Use \$ tp->toAvatar() instead of toImage() for " . $file . '</div>' ; // debug info only.
2016-02-09 22:53:03 -08:00
}
2017-03-04 10:06:53 -08:00
if ( empty ( $file ) && empty ( $parm [ 'placeholder' ]))
2015-04-05 20:24:51 -07:00
{
2016-02-09 11:02:08 -08:00
return null ;
2015-04-05 20:24:51 -07:00
}
2017-03-04 10:06:53 -08:00
if ( ! empty ( $file ))
{
2021-01-14 17:32:08 -08:00
$srcset = null ;
$path = null ;
$file = trim ( $file );
$ext = pathinfo ( $file , PATHINFO_EXTENSION );
$accepted = array ( 'jpg' , 'gif' , 'png' , 'jpeg' , 'svg' , 'webp' );
2017-03-04 10:06:53 -08:00
2021-01-14 17:32:08 -08:00
if ( ! in_array ( $ext , $accepted ))
2017-03-04 10:06:53 -08:00
{
return null ;
}
}
2019-02-26 12:22:36 -08:00
/** @var e_parse $tp */
2021-01-14 17:32:08 -08:00
$tp = $this ;
2017-03-04 10:06:53 -08:00
2021-01-14 17:32:08 -08:00
// e107::getDebug()->log($file);
// e107::getDebug()->log($parm);
2016-12-17 09:43:37 -08:00
2021-01-14 17:32:08 -08:00
if ( strpos ( $file , 'http' ) === 0 )
2017-04-05 12:42:42 -07:00
{
$path = $file ;
}
2021-01-14 17:32:08 -08:00
elseif ( strpos ( $file , 'e_MEDIA' ) !== false || strpos ( $file , 'e_THEME' ) !== false || strpos ( $file , 'e_PLUGIN' ) !== false || strpos ( $file , '{e_IMAGE}' ) !== false ) //v2.x path.
2016-02-09 22:53:03 -08:00
{
2016-04-13 14:30:42 -07:00
if ( ! isset ( $parm [ 'w' ]) && ! isset ( $parm [ 'h' ]))
{
2021-01-14 17:32:08 -08:00
$parm = ( array ) $parm ;
$parm [ 'w' ] = $tp -> thumbWidth ();
$parm [ 'h' ] = $tp -> thumbHeight ();
$parm [ 'crop' ] = $tp -> thumbCrop ();
$parm [ 'x' ] = $tp -> thumbEncode ();
2016-04-13 14:30:42 -07:00
}
unset ( $parm [ 'src' ]);
2021-01-14 17:32:08 -08:00
$path = $tp -> thumbUrl ( $file , $parm );
2016-04-13 14:30:42 -07:00
2017-01-23 13:16:11 -08:00
if ( empty ( $parm [ 'w' ]) && empty ( $parm [ 'h' ]))
{
$parm [ 'srcset' ] = false ;
}
2017-11-02 14:28:53 -07:00
elseif ( ! isset ( $parm [ 'srcset' ]))
2017-01-23 13:16:11 -08:00
{
$srcSetParm = $parm ;
2020-12-02 14:41:48 -08:00
if ( ! isset ( $parm [ 'size' ]))
{
2020-12-29 09:48:36 -08:00
$srcSetParm [ 'size' ] = ( varset ( $parm [ 'w' ]) < 100 ) ? '4x' : '2x' ;
2020-12-02 14:41:48 -08:00
}
else
{
unset ( $parm [ 'size' ]);
}
2017-01-23 13:16:11 -08:00
$parm [ 'srcset' ] = $tp -> thumbSrcSet ( $file , $srcSetParm );
}
2016-02-08 21:33:55 -08:00
2015-04-05 20:24:51 -07:00
}
2021-01-01 10:45:26 -08:00
elseif ( ! empty ( $file ) && $file [ 0 ] === '{' ) // Legacy v1.x path. Example: {e_PLUGIN}myplugin/images/fixedimage.png
2015-04-05 20:24:51 -07:00
{
2021-01-14 17:32:08 -08:00
$path = $tp -> replaceConstants ( $file , 'abs' );
2015-04-05 20:24:51 -07:00
}
2016-02-09 11:02:08 -08:00
elseif ( ! empty ( $parm [ 'legacy' ])) // Search legacy path for image in a specific folder. No path, only file name provided.
2015-04-05 20:24:51 -07:00
{
2021-01-14 17:32:08 -08:00
$legacyPath = rtrim ( $parm [ 'legacy' ], '/' ) . '/' . $file ;
2016-12-05 15:41:19 -08:00
$filePath = $tp -> replaceConstants ( $legacyPath );
2015-04-05 20:24:51 -07:00
if ( is_readable ( $filePath ))
{
2021-01-14 17:32:08 -08:00
$path = $tp -> replaceConstants ( $legacyPath , 'abs' );
2015-04-05 20:24:51 -07:00
}
else
{
2020-12-21 10:00:28 -08:00
$log = e107 :: getLog ();
2021-01-14 17:32:08 -08:00
$log -> addDebug ( 'Broken Image Path: ' . $legacyPath . " \n " . print_r ( debug_backtrace ( null , 2 ), true ), false ) -> save ( 'IMALAN_00' );
e107 :: getDebug () -> log ( 'Broken Image Path: ' . $legacyPath );
2015-04-05 20:24:51 -07:00
}
}
else // usually http://....
{
$path = $file ;
}
2017-03-04 10:06:53 -08:00
if ( empty ( $path ) && ! empty ( $parm [ 'placeholder' ]))
{
2021-01-14 17:32:08 -08:00
$path = $tp -> thumbUrl ( $file , $parm );
2017-03-04 10:06:53 -08:00
}
2016-12-19 13:49:18 -08:00
2021-01-14 17:32:08 -08:00
$id = ( ! empty ( $parm [ 'id' ])) ? 'id="' . $parm [ 'id' ] . '" ' : '' ;
$class = ( ! empty ( $parm [ 'class' ])) ? $parm [ 'class' ] : 'img-responsive img-fluid' ;
$alt = ( ! empty ( $parm [ 'alt' ])) ? $tp -> toAttribute ( $parm [ 'alt' ]) : basename ( $file );
$style = ( ! empty ( $parm [ 'style' ])) ? 'style="' . $parm [ 'style' ] . '" ' : '' ;
$srcset = ( ! empty ( $parm [ 'srcset' ])) ? 'srcset="' . $parm [ 'srcset' ] . '" ' : '' ;
$width = ( ! empty ( $parm [ 'w' ])) ? 'width="' . ( int ) $parm [ 'w' ] . '" ' : '' ;
$title = ( ! empty ( $parm [ 'title' ])) ? 'title="' . $parm [ 'title' ] . '" ' : '' ;
$height = ! empty ( $parm [ 'h' ]) ? 'height="' . ( int ) $parm [ 'h' ] . '" ' : '' ;
$loading = ! empty ( $parm [ 'loading' ]) ? 'loading="' . $parm [ 'loading' ] . '" ' : '' ; // eg. lazy, eager, auto
2015-04-05 20:24:51 -07:00
2020-12-02 14:41:48 -08:00
if ( isset ( $parm [ 'width' ])) // width attribute override (while retaining w)
{
2021-01-14 17:32:08 -08:00
$width = 'width="' . $parm [ 'width' ] . '" ' ;
2020-12-02 14:41:48 -08:00
}
2021-01-14 17:32:08 -08:00
2020-12-02 14:41:48 -08:00
if ( isset ( $parm [ 'height' ])) // height attribute override (while retaining h)
{
2021-01-14 17:32:08 -08:00
$height = 'height="' . $parm [ 'height' ] . '" ' ;
2020-12-02 14:41:48 -08:00
}
2020-12-09 10:54:15 -08:00
$html = '' ;
if ( $this -> convertToWebP )
{
$parm [ 'type' ] = 'webp' ;
2021-01-14 17:32:08 -08:00
$source = $tp -> thumbUrl ( $file , $parm );
2020-12-10 18:57:00 -08:00
$html = " <picture class= \" { $class } \" > \n " ;
2020-12-09 10:54:15 -08:00
if ( ! empty ( $parm [ 'srcset' ]))
{
2021-01-14 17:32:08 -08:00
list ( $webPSourceSet , $webPSize ) = explode ( ' ' , $parm [ 'srcset' ]);
$html .= '<source type="image/webp" srcset="' . $webPSourceSet . '&type=webp ' . $webPSize . '">' ;
2020-12-09 10:54:15 -08:00
$html .= " \n " ;
2021-01-14 17:32:08 -08:00
$html .= '<source type="image/' . str_replace ( 'jpg' , 'jpeg' , $ext ) . '" srcset="' . $parm [ 'srcset' ] . '">' ;
2020-12-09 10:54:15 -08:00
$html .= " \n " ;
$srcset = '' ; // remove it from the img tag below.
}
2020-12-10 18:57:00 -08:00
2021-01-14 17:32:08 -08:00
$html .= '<source type="image/webp" srcset="' . $source . '">' ;
2020-12-10 18:57:00 -08:00
$html .= " \n " ;
2020-12-09 10:54:15 -08:00
}
2021-01-14 14:46:49 -08:00
if ( empty ( $path ))
{
return null ;
}
2021-01-14 17:32:08 -08:00
$html .= " <img { $id } class= \" { $class } \" src= \" " . $path . '" alt="' . $alt . '" ' . $srcset . $width . $height . $style . $loading . $title . ' />' ;
2020-12-09 10:54:15 -08:00
$html .= ( $this -> convertToWebP ) ? " \n </picture> " : '' ;
return $html ;
2015-04-05 20:24:51 -07:00
}
2014-01-15 04:02:05 -08:00
2015-05-21 21:49:32 -07:00
2015-07-16 18:12:41 -07:00
/**
* Check if a string contains bbcode .
* @ param $text
* @ return bool
*/
2020-12-14 16:21:48 -08:00
public function isBBcode ( $text )
2015-07-16 18:12:41 -07:00
{
2021-01-14 17:32:08 -08:00
2020-12-25 10:23:56 -08:00
if ( ! is_string ( $text ))
{
return false ;
}
2021-01-14 17:32:08 -08:00
if ( strpos ( $text , '[' ) === false || preg_match ( '#(?<=<)\w+(?=[^<]*?>)#' , $text ))
2015-07-16 18:12:41 -07:00
{
2017-03-26 13:03:58 -07:00
return false ;
2015-07-16 18:12:41 -07:00
}
2017-03-26 13:03:58 -07:00
2021-01-14 17:32:08 -08:00
$bbsearch = array ( '[/img]' , '[/h]' , '[/b]' , '[/link]' , '[/right]' , '[/center]' , '[/flash]' , '[/code]' , '[/table]' );
2017-03-26 13:03:58 -07:00
foreach ( $bbsearch as $v )
2015-07-16 18:12:41 -07:00
{
2021-01-14 17:32:08 -08:00
if ( strpos ( $text , $v ) !== false )
2017-03-26 13:03:58 -07:00
{
return true ;
}
2015-07-16 18:12:41 -07:00
}
2017-03-26 13:03:58 -07:00
return false ;
2015-07-16 18:12:41 -07:00
}
2015-05-21 21:49:32 -07:00
/**
* Check if a string is HTML
* @ param $text
* @ return bool
*/
2020-12-14 16:21:48 -08:00
public function isHtml ( $text )
2015-05-21 21:49:32 -07:00
{
2021-01-14 17:32:08 -08:00
2020-12-25 10:23:56 -08:00
if ( ! is_string ( $text ))
{
return false ;
}
2015-07-16 18:12:41 -07:00
2021-01-14 17:32:08 -08:00
if ( strpos ( $text , '[html]' ) !== false )
2015-05-21 21:49:32 -07:00
{
return true ;
}
2017-04-12 16:51:10 -07:00
if ( $this -> isBBcode ( $text ))
2015-05-21 21:49:32 -07:00
{
return false ;
}
2017-04-12 16:51:10 -07:00
if ( preg_match ( '#(?<=<)\w+(?=[^<]*?>)#' , $text ))
{
return true ;
}
return false ;
2015-05-21 21:49:32 -07:00
}
2017-01-22 13:31:03 -08:00
/**
* Check if string is json and parse or return false .
* @ param $text
* @ return bool | mixed return false if not json , and json values if true .
*/
public function isJSON ( $text )
{
2021-01-14 17:32:08 -08:00
2017-01-24 19:53:40 -08:00
if ( ! is_string ( $text ))
{
return false ;
}
2021-01-14 17:32:08 -08:00
if ( strpos ( $text , '{' ) === 0 || strpos ( $text , '[' ) === 0 ) // json
{
$dat = json_decode ( $text , true );
2017-01-22 13:31:03 -08:00
2021-01-14 17:32:08 -08:00
if ( json_last_error () != JSON_ERROR_NONE )
{
// e107::getDebug()->log("Json data found");
return false ;
}
2017-01-22 13:31:03 -08:00
2021-01-14 17:32:08 -08:00
return $dat ;
}
2017-01-22 13:31:03 -08:00
return false ;
}
2015-05-21 21:49:32 -07:00
2016-09-28 10:26:39 -07:00
/**
* Checks if string is valid UTF - 8.
*
* Try to detect UTF - 8 using mb_detect_encoding () . If mb string extension is
* not installed , we try to use a simple UTF - 8 - ness checker using a regular
* expression originally created by the W3C . But W3C ' s function scans the
* entire strings and checks that it conforms to UTF - 8.
*
* @ see http :// w3 . org / International / questions / qa - forms - utf - 8. html
*
* So this function is faster and less specific . It only looks for non - ascii
* multibyte sequences in the UTF - 8 range and also to stop once it finds at
* least one multibytes string . This is quite a lot faster .
*
* @ param $string string string being checked .
* @ return bool Returns true if $string is valid UTF - 8 and false otherwise .
*/
public function isUTF8 ( $string )
{
2021-01-14 17:32:08 -08:00
if ( function_exists ( 'mb_check_encoding' ))
2016-09-28 10:26:39 -07:00
{
2017-03-08 11:05:58 -03:00
return ( mb_check_encoding ( $string , 'UTF-8' ));
2016-09-28 10:26:39 -07:00
}
return ( bool ) preg_match ( ' % ( ? :
[ \xC2 - \xDF ][ \x80 - \xBF ] # non-overlong 2-byte
| \xE0 [ \xA0 - \xBF ][ \x80 - \xBF ] # excluding overlongs
| [ \xE1 - \xEC\xEE\xEF ][ \x80 - \xBF ]{ 2 } # straight 3-byte
| \xED [ \x80 - \x9F ][ \x80 - \xBF ] # excluding surrogates
| \xF0 [ \x90 - \xBF ][ \x80 - \xBF ]{ 2 } # planes 1-3
| [ \xF1 - \xF3 ][ \x80 - \xBF ]{ 3 } # planes 4-15
| \xF4 [ \x80 - \x8F ][ \x80 - \xBF ]{ 2 } # plane 16
) +% xs ' , $string );
}
2014-02-04 06:21:05 -08:00
/**
2021-01-14 17:32:08 -08:00
* Check if a file is an video or not .
2014-02-04 06:21:05 -08:00
* @ param $file string
* @ return boolean
*/
2020-12-14 16:21:48 -08:00
public function isVideo ( $file )
2014-02-04 06:21:05 -08:00
{
2021-01-14 17:32:08 -08:00
2020-12-25 10:23:56 -08:00
if ( ! is_string ( $file ))
{
return false ;
}
2021-01-14 17:32:08 -08:00
$ext = pathinfo ( $file , PATHINFO_EXTENSION );
2021-01-14 18:30:32 -08:00
return $ext === 'youtube' || $ext === 'youtubepl' || $ext === 'mp4' ;
2021-01-14 17:32:08 -08:00
2014-02-04 06:21:05 -08:00
}
2015-04-05 20:24:51 -07:00
/**
* Check if a file is an image or not .
* @ param $file string
* @ return boolean
*/
2020-12-14 16:21:48 -08:00
public function isImage ( $file )
2015-04-05 20:24:51 -07:00
{
2021-01-14 17:32:08 -08:00
2020-12-31 15:00:12 -08:00
if ( ! is_string ( $file ))
2020-12-25 10:23:56 -08:00
{
return false ;
}
2021-01-14 18:30:32 -08:00
if ( strpos ( $file , '{e_' ) === 0 )
2015-11-22 13:04:21 -08:00
{
2021-01-14 14:46:49 -08:00
$file = $this -> replaceConstants ( $file );
2015-11-22 13:04:21 -08:00
}
2021-01-14 17:32:08 -08:00
$ext = pathinfo ( $file , PATHINFO_EXTENSION );
2015-04-05 20:24:51 -07:00
2021-01-14 14:46:49 -08:00
return ( $ext === 'jpg' || $ext === 'png' || $ext === 'gif' || $ext === 'jpeg' || $ext === 'webp' );
2015-04-05 20:24:51 -07:00
}
2018-07-18 14:40:29 -07:00
/**
* @ param $file
* @ param array $parm
* @ return string
*/
2021-01-14 17:32:08 -08:00
public function toAudio ( $file , $parm = array ())
2018-07-18 14:40:29 -07:00
{
$file = $this -> replaceConstants ( $file , 'abs' );
2018-07-19 12:43:04 -07:00
$mime = varset ( $parm [ 'mime' ], 'audio/mpeg' );
2020-12-14 16:21:48 -08:00
$autoplay = ! empty ( $parm [ 'autoplay' ]) ? 'autoplay ' : '' ;
$controls = ! empty ( $parm [ 'controls' ]) ? 'controls' : '' ;
2020-02-05 13:26:07 -08:00
2021-01-15 14:24:28 -08:00
$text = '<audio controls style="max-width:100%" ' . $autoplay . $controls . '>' ;
$text .= " \n " ;
$text .= '<source src="' . $file . '" type="' . $mime . '">' ;
$text .= " \n " ;
$text .= 'Your browser does not support the audio tag.' ;
$text .= " \n " ;
$text .= '</audio>' ;
2018-07-18 14:40:29 -07:00
return $text ;
}
2014-01-08 15:51:14 -08:00
/**
2021-01-14 17:32:08 -08:00
* Display a Video file .
* @ param string $file - format : id . type eg . x123dkax . youtube
* @ param boolean $thumbnail - set to 'tag' to return an image thumbnail and 'src' to return the src url or 'video' for a small video thumbnail .
2014-01-08 15:51:14 -08:00
*/
2021-01-14 17:32:08 -08:00
public function toVideo ( $file , $parm = array ())
2014-01-08 15:51:14 -08:00
{
2021-01-14 17:32:08 -08:00
2015-08-24 10:19:34 -07:00
if ( empty ( $file ))
{
return false ;
}
2018-07-19 12:43:04 -07:00
$type = pathinfo ( $file , PATHINFO_EXTENSION );
2015-08-24 10:19:34 -07:00
2021-01-14 17:32:08 -08:00
$id = str_replace ( '.' . $type , '' , $file );
2018-07-25 12:29:52 -07:00
2014-01-08 15:51:14 -08:00
$thumb = vartrue ( $parm [ 'thumb' ]);
2021-01-14 17:32:08 -08:00
$mode = varset ( $parm [ 'mode' ], false ); // tag, url
2015-12-12 16:54:10 -08:00
2014-03-12 14:09:48 -07:00
$pref = e107 :: getPref ();
$ytpref = array ();
2021-01-14 17:32:08 -08:00
foreach ( $pref as $k => $v ) // Find all Youtube Prefs.
2014-03-12 14:09:48 -07:00
{
2020-12-14 16:21:48 -08:00
if ( strpos ( $k , 'youtube_' ) === 0 )
2014-03-12 14:09:48 -07:00
{
2021-01-14 17:32:08 -08:00
$key = substr ( $k , 8 );
2014-03-12 14:09:48 -07:00
$ytpref [ $key ] = $v ;
2021-01-14 17:32:08 -08:00
}
2015-10-01 11:02:24 -07:00
}
unset ( $ytpref [ 'bbcode_responsive' ]); // do not include in embed code.
if ( ! empty ( $ytpref [ 'cc_load_policy' ]))
{
$ytpref [ 'cc_lang_pref' ] = e_LAN ; // switch captions with chosen user language.
}
2018-05-04 17:57:43 -07:00
$ytqry = http_build_query ( $ytpref , null , '&' );
2015-10-01 11:02:24 -07:00
2020-12-14 16:21:48 -08:00
$defClass = ! empty ( $this -> bootstrap ) ? 'embed-responsive embed-responsive-16by9' : 'video-responsive' ; // levacy backup.
2015-10-01 11:02:24 -07:00
2017-01-29 18:43:52 -08:00
if ( $type === 'youtube' )
2015-04-02 03:36:45 -07:00
{
2018-07-25 12:29:52 -07:00
2021-01-14 17:32:08 -08:00
// $thumbSrc = "https://i1.ytimg.com/vi/".$id."/0.jpg";
$thumbSrc = 'https://i1.ytimg.com/vi/' . $id . '/mqdefault.jpg' ;
$video = '<iframe class="embed-responsive-item" width="560" height="315" src="//www.youtube.com/embed/' . $id . '?' . $ytqry . '" style="background-size: 100%;background-image: url(' . $thumbSrc . ');border:0px" allowfullscreen></iframe>' ;
$url = 'http://youtu.be/' . $id ;
2018-07-18 14:40:29 -07:00
if ( $mode === 'url' )
{
return $url ;
}
2015-04-02 03:36:45 -07:00
2021-01-14 17:32:08 -08:00
2017-01-29 18:43:52 -08:00
if ( $thumb === 'tag' )
2014-01-08 15:51:14 -08:00
{
2021-01-14 17:32:08 -08:00
return " <img class='img-responsive img-fluid' src=' " . $thumbSrc . " ' alt='Youtube Video' style='width: " . vartrue ( $parm [ 'w' ], '80' ) . " px'/> " ;
2014-01-08 15:51:14 -08:00
}
2021-01-14 17:32:08 -08:00
2017-01-29 18:43:52 -08:00
if ( $thumb === 'email' )
2014-10-18 15:00:40 -07:00
{
2021-01-14 17:32:08 -08:00
$thumbSrc = 'http://i1.ytimg.com/vi/' . $id . '/maxresdefault.jpg' ; // 640 x 480
$filename = 'temp/yt-thumb-' . md5 ( $id ) . '.jpg' ;
$filepath = e_MEDIA . $filename ;
2018-07-18 14:40:29 -07:00
2014-10-18 15:00:40 -07:00
if ( ! file_exists ( $filepath ))
{
2021-01-14 17:32:08 -08:00
e107 :: getFile () -> getRemoteFile ( $thumbSrc , $filename , 'media' );
2014-10-18 15:00:40 -07:00
}
2021-01-14 17:32:08 -08:00
return " <a href=' " . $url . " '><img class='video-responsive video-thumbnail' src=' { e_MEDIA} " . $filename . " ' alt=' " . LAN_YOUTUBE_VIDEO . " ' title=' " . LAN_CLICK_TO_VIEW . " ' />
< div class = 'video-thumbnail-caption' >< small > " . LAN_CLICK_TO_VIEW . '</small></div></a>';
2014-10-18 15:00:40 -07:00
}
2021-01-14 17:32:08 -08:00
2017-01-29 18:43:52 -08:00
if ( $thumb === 'src' )
2014-01-08 15:51:14 -08:00
{
return $thumbSrc ;
}
2015-10-01 11:02:24 -07:00
2017-01-29 18:43:52 -08:00
if ( $thumb === 'video' )
2014-01-08 15:51:14 -08:00
{
2021-01-14 17:32:08 -08:00
return '<div class="' . $defClass . ' video-thumbnail thumbnail">' . $video . '</div>' ;
2014-01-08 15:51:14 -08:00
}
2021-01-14 17:32:08 -08:00
return '<div class="' . $defClass . ' ' . vartrue ( $parm [ 'class' ]) . '">' . $video . '</div>' ;
2015-03-31 14:48:07 -07:00
}
2017-01-29 18:43:52 -08:00
if ( $type === 'youtubepl' )
2015-03-31 14:48:07 -07:00
{
2017-01-29 18:43:52 -08:00
if ( $thumb === 'tag' )
2015-03-31 14:48:07 -07:00
{
2021-01-14 17:32:08 -08:00
$thumbSrc = e107 :: getMedia () -> getThumb ( $id );
2015-12-12 16:54:10 -08:00
if ( empty ( $thumbSrc ))
{
2021-01-14 17:32:08 -08:00
$thumbSrc = e_IMAGE_ABS . 'generic/playlist_120.png' ;
2015-12-12 16:54:10 -08:00
}
2021-01-14 17:32:08 -08:00
return " <img class='img-responsive img-fluid' src=' " . $thumbSrc . " ' alt=' " . LAN_YOUTUBE_PLAYLIST . " ' style='width: " . vartrue ( $parm [ 'w' ], '80' ) . " px'/> " ;
2015-03-31 14:48:07 -07:00
}
2017-01-29 18:43:52 -08:00
if ( $thumb === 'src' )
2015-03-31 14:48:07 -07:00
{
2015-12-12 16:54:10 -08:00
$thumb = e107 :: getMedia () -> getThumb ( $id );
if ( ! empty ( $thumb ))
{
return $thumb ;
}
2020-12-14 16:21:48 -08:00
// return "https://cdn0.iconfinder.com/data/icons/internet-2-2/64/youtube_playlist_videos_vid_web_online_internet-256.png";
2021-01-14 17:32:08 -08:00
return e_IMAGE_ABS . 'generic/playlist_120.png' ;
2015-03-31 14:48:07 -07:00
}
2021-01-14 17:32:08 -08:00
$video = '<iframe width="560" height="315" src="https://www.youtube.com/embed/videoseries?list=' . $id . '" style="border:0" allowfullscreen></iframe>' ;
return '<div class="' . $defClass . ' ' . vartrue ( $parm [ 'class' ]) . '">' . $video . '</div>' ;
2014-01-08 15:51:14 -08:00
}
2021-01-14 17:32:08 -08:00
2018-07-18 14:40:29 -07:00
if ( $type === 'mp4' )
2014-01-10 18:27:42 -08:00
{
2018-07-18 14:40:29 -07:00
$file = $this -> replaceConstants ( $file , 'abs' );
if ( $mode === 'url' )
{
return $file ;
}
$width = varset ( $parm [ 'w' ], 320 );
$height = varset ( $parm [ 'h' ], 240 );
2018-07-19 12:43:04 -07:00
$mime = varset ( $parm [ 'mime' ], 'video/mp4' );
2018-07-18 14:40:29 -07:00
2014-01-10 18:27:42 -08:00
return '
< div class = " video-responsive " >
2021-01-14 17:32:08 -08:00
< video width = " ' . $width . ' " height = " ' . $height . ' " controls >
< source src = " ' . $file . ' " type = " ' . $mime . ' " >
2014-01-10 18:27:42 -08:00
Your browser does not support the video tag .
</ video >
2021-01-14 17:32:08 -08:00
</ div > ' ;
2014-01-10 18:27:42 -08:00
}
2021-01-14 17:32:08 -08:00
2014-01-08 15:51:14 -08:00
return false ;
}
2021-01-14 17:32:08 -08:00
2014-01-15 04:02:05 -08:00
/**
2021-01-14 17:32:08 -08:00
* Display a Date in the browser .
2014-01-15 04:02:05 -08:00
* Includes support for 'livestamp' ( http :// mattbradley . github . io / livestampjs / )
* @ param integer $datestamp - unix timestamp
2021-01-14 17:32:08 -08:00
* @ param string $format - short | long | relative
2018-03-04 13:02:50 -08:00
* @ return string converted date ( html )
2014-01-15 04:02:05 -08:00
*/
2021-01-14 17:32:08 -08:00
public function toDate ( $datestamp = null , $format = 'short' )
2014-01-15 04:02:05 -08:00
{
2021-01-14 17:32:08 -08:00
if ( ! is_numeric ( $datestamp ))
{
return null ;
}
2014-01-15 04:02:05 -08:00
2018-03-04 13:02:50 -08:00
$value = e107 :: getDate () -> convert_date ( $datestamp , $format );
2021-01-14 17:32:08 -08:00
$inc = ( $format === 'relative' ) ? ' data-livestamp="' . $datestamp . '"' : '' ;
2018-03-04 13:02:50 -08:00
2021-01-14 17:32:08 -08:00
return '<span' . $inc . '>' . $value . '</span>' ;
2014-01-15 04:02:05 -08:00
}
2021-01-14 17:32:08 -08:00
/**
2017-12-14 17:44:29 -08:00
* Parse new < x - bbcode > tags into bbcode output .
* @ param bool $retainTags : when you want to replace html and retain the < bbcode > tags wrapping it .
* @ return string html
2013-03-18 22:14:05 -07:00
*/
2020-12-14 16:21:48 -08:00
public function parseBBTags ( $text , $retainTags = false )
2013-03-18 22:14:05 -07:00
{
2021-01-14 17:32:08 -08:00
2020-12-14 16:21:48 -08:00
$stext = str_replace ( '"' , '"' , $text );
2017-12-14 17:44:29 -08:00
$bbcodes = $this -> getTags ( $stext , 'x-bbcode' );
2013-03-18 22:14:05 -07:00
foreach ( $bbcodes as $v )
{
foreach ( $v as $val )
{
2017-12-14 17:44:29 -08:00
$tag = base64_decode ( $val [ 'alt' ]);
2021-01-14 17:32:08 -08:00
$repl = ( $retainTags == true ) ? '$1' . $tag . '$2' : $tag ;
// $text = preg_replace('/(<x-bbcode[^>]*>).*(<\/x-bbcode>)/i',$repl, $text);
$text = preg_replace ( '/(<x-bbcode alt=(?:"|")' . $val [ 'alt' ] . '(?:"|")>).*(<\/x-bbcode>)/i' , $repl , $text );
2017-12-14 18:04:45 -08:00
2021-01-14 17:32:08 -08:00
}
2013-03-18 22:14:05 -07:00
}
2017-12-14 17:44:29 -08:00
2013-03-18 22:14:05 -07:00
return $text ;
}
2015-04-29 10:22:46 -07:00
/**
* Filters / Validates using the PHP5 filter_var () method .
2021-01-14 14:46:49 -08:00
* @ param string | array $text
* @ param string $type string str | int | email | url | w | wds | file
* @ return string | boolean | array
2015-04-29 10:22:46 -07:00
*/
2021-01-14 17:32:08 -08:00
public function filter ( $text , $type = 'str' , $validate = false )
2015-04-29 10:22:46 -07:00
{
2021-01-14 17:32:08 -08:00
2015-04-29 10:22:46 -07:00
if ( empty ( $text ))
{
return $text ;
}
2021-01-18 10:27:41 -08:00
$regex = array (
'w' => '/[^\w]/' ,
'd' => '/[^\d]/' ,
'wd' => '/[^\w]/' ,
'wds' => '/[^\w ]/' ,
'file' => '/[^\w_\.-]/' ,
'version' => '/[^\d_\.]/' ,
);
2021-01-14 14:46:49 -08:00
switch ( $type )
2015-04-29 10:22:46 -07:00
{
2021-01-14 18:30:32 -08:00
case 'w' :
case 'd' :
case 'wd' :
case 'wds' :
2021-01-18 10:27:41 -08:00
case 'version' :
if ( $validate === true )
{
trigger_error ( " Unsupported type ' " . $type . " ' for validation used in e107::getParser()->filter(). " , E_USER_WARNING );
}
else
{
$reg = $regex [ $type ];
$ret = preg_replace ( $reg , '' , $text );
}
2021-01-14 14:46:49 -08:00
break ;
2015-04-29 10:22:46 -07:00
2021-01-14 18:30:32 -08:00
case 'file' :
2016-12-04 07:50:27 -08:00
2021-01-18 10:27:41 -08:00
if ( $validate === true )
{
trigger_error ( " Unsupported type ' " . $type . " ' used in e107::getParser()->filter(). " , E_USER_WARNING );
}
else
{
$reg = $regex [ 'file' ];
$ret = preg_replace ( '/[^\w_\.-]/' , '-' , $text );
}
2021-01-14 14:46:49 -08:00
break ;
2015-04-29 10:22:46 -07:00
2021-01-14 14:46:49 -08:00
default :
2015-04-29 10:22:46 -07:00
2021-01-18 10:27:41 -08:00
if ( $validate === false )
2021-01-14 14:46:49 -08:00
{
$filterTypes = array (
'int' => FILTER_SANITIZE_NUMBER_INT ,
'str' => FILTER_SANITIZE_STRING , // no html.
'email' => FILTER_SANITIZE_EMAIL ,
'url' => FILTER_SANITIZE_URL ,
'enc' => FILTER_SANITIZE_ENCODED
);
}
else
{
$filterTypes = array (
'int' => FILTER_VALIDATE_INT ,
'email' => FILTER_VALIDATE_EMAIL ,
'ip' => FILTER_VALIDATE_IP ,
'url' => FILTER_VALIDATE_URL ,
2015-04-29 10:22:46 -07:00
2021-01-14 14:46:49 -08:00
);
}
2015-04-29 10:22:46 -07:00
2021-01-18 10:27:41 -08:00
if ( ! isset ( $filterTypes [ $type ]))
{
trigger_error ( " Unsupported type ' " . $type . " ' used in e107::getParser()->filter(). " , E_USER_WARNING );
}
2021-01-14 14:46:49 -08:00
if ( is_array ( $text ))
{
$ret = filter_var_array ( $text , $filterTypes [ $type ]);
}
else
{
$ret = filter_var ( $text , $filterTypes [ $type ]);
}
2015-04-29 10:22:46 -07:00
2021-01-14 14:46:49 -08:00
}
2015-04-29 10:22:46 -07:00
2021-01-14 14:46:49 -08:00
return $ret ;
2015-04-29 10:22:46 -07:00
}
2021-01-14 17:32:08 -08:00
private function grantScriptAccess ()
{
if ( ! in_array ( 'script' , $this -> allowedTags ))
{
$this -> allowedTags = array_merge ( $this -> allowedTags , $this -> scriptTags );
}
2020-04-30 14:52:44 -07:00
2021-01-14 17:32:08 -08:00
foreach ( $this -> allowedAttributes as $tag => $att )
{
foreach ( $this -> scriptAttributes as $new )
{
if ( in_array ( $new , $this -> allowedAttributes [ $tag ]))
{
continue ;
}
2021-01-13 11:20:58 -08:00
2021-01-14 17:32:08 -08:00
$this -> allowedAttributes [ $tag ][] = $new ;
}
}
2020-04-30 14:52:44 -07:00
2021-01-14 17:32:08 -08:00
return null ;
}
2020-04-30 14:52:44 -07:00
2021-01-14 17:32:08 -08:00
/**
* Process and clean HTML from user input .
* TODO Html5 tag support .
* @ param string $html raw HTML
* @ param boolean $checkPref
* @ return string
*/
public function cleanHtml ( $html = '' , $checkPref = true )
{
2020-04-30 14:52:44 -07:00
2021-01-14 17:32:08 -08:00
if ( empty ( $html ))
{
return '' ;
}
2015-04-11 02:53:51 -07:00
2021-01-14 17:32:08 -08:00
if ( $this -> isHtml ( $html ) === false )
{
$html = str_replace ( array ( '<' , '>' ), array ( '<' , '>' ), $html );
}
2020-02-17 13:13:06 -08:00
2021-01-14 17:32:08 -08:00
// prevent replacement of with spaces.
2019-12-25 12:21:13 -08:00
// Workaround for https://bugs.php.net/bug.php?id=76285
// Part 1 of 2
2021-01-14 17:32:08 -08:00
// clean out windows line-breaks.
$html = str_replace ( array ( ' ' , " \r " , " \n " , '{' , '}' ), array ( '__E_PARSER_CLEAN_HTML_NON_BREAKING_SPACE__' , '' , '__E_PARSER_CLEAN_HTML_LINE_BREAK__' , '__E_PARSER_CLEAN_HTML_CURLY_OPEN__' , '__E_PARSER_CLEAN_HTML_CURLY_CLOSED__' ), $html );
2020-02-17 13:13:06 -08:00
2021-01-14 17:32:08 -08:00
if ( strpos ( $html , '<body' ) === false ) // HTML Fragment
2013-03-05 23:46:51 -08:00
{
2021-01-14 17:32:08 -08:00
$html = '<body>' . $html . '</body>' ;
2013-03-05 23:46:51 -08:00
}
2020-12-09 09:15:16 -08:00
2020-12-14 11:18:12 -08:00
2015-04-29 10:22:46 -07:00
if ( $this -> scriptAccess === false )
{
2021-01-14 17:32:08 -08:00
$this -> scriptAccess = e107 :: getConfig () -> get ( 'post_script' , e_UC_NOBODY ); // Pref to Allow <script> tags11;
2015-04-29 10:22:46 -07:00
}
if ( check_class ( $this -> scriptAccess ))
2021-01-14 17:32:08 -08:00
{
$this -> grantScriptAccess ();
}
2014-06-09 21:45:40 +03:00
2021-01-14 17:32:08 -08:00
// Set it up for processing.
2020-12-13 12:19:42 -08:00
2021-01-14 17:32:08 -08:00
libxml_use_internal_errors ( true );
if ( function_exists ( 'mb_convert_encoding' ))
{
2020-12-14 16:21:48 -08:00
$html = mb_convert_encoding ( $html , 'HTML-ENTITIES' , 'UTF-8' );
2020-12-13 12:19:42 -08:00
2021-01-14 17:32:08 -08:00
}
2016-03-01 17:50:53 -08:00
2020-12-13 12:19:42 -08:00
// $fragment = $doc->createDocumentFragment();
// $fragment->appendXML($html);
// $doc->appendChild($fragment);
// $doc->encoding = 'utf-8';
2020-12-14 11:18:12 -08:00
$doc = $this -> domObj ;
2020-12-13 12:19:42 -08:00
$opts = defined ( 'LIBXML_HTML_NOIMPLIED' ) ? LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD : 0 ;
$doc -> loadHTML ( $html , $opts );
2015-04-11 02:53:51 -07:00
2021-01-14 17:32:08 -08:00
$this -> nodesToConvert = array (); // required.
$this -> nodesToDelete = array (); // required.
$this -> removedList = array ();
2013-03-05 15:13:16 -08:00
2014-06-09 21:45:40 +03:00
$tmp = $doc -> getElementsByTagName ( '*' );
2021-01-14 17:32:08 -08:00
/** @var DOMElement $node */
foreach ( $tmp as $node )
{
$path = $node -> getNodePath ();
2014-06-09 21:45:40 +03:00
2021-01-14 17:32:08 -08:00
// echo "<br />Path = ".$path;
// $tag = strval(basename($path));
2016-03-01 13:29:50 -08:00
2021-01-14 17:32:08 -08:00
if ( strpos ( $path , '/code' ) !== false || strpos ( $path , '/pre' ) !== false ) // treat as html.
{
$this -> pathList [] = $path ;
// $this->nodesToConvert[] = $node->parentNode; // $node;
$this -> nodesToDisableSC [] = $node ;
continue ;
}
2016-03-01 17:50:53 -08:00
2021-01-14 17:32:08 -08:00
$tag = preg_replace ( '/([a-z0-9\[\]\/]*)?\/([\w\-]*)(\[(\d)*\])?$/i' , '$2' , $path );
if ( ! in_array ( $tag , $this -> allowedTags ))
{
2016-03-01 13:29:50 -08:00
2021-01-14 17:32:08 -08:00
$this -> removedList [ 'tags' ][] = $tag ;
$this -> nodesToDelete [] = $node ;
continue ;
}
2014-06-09 21:45:40 +03:00
2021-01-14 17:32:08 -08:00
foreach ( $node -> attributes as $attr )
{
$name = $attr -> nodeName ;
$value = $attr -> nodeValue ;
2014-06-09 21:45:40 +03:00
2021-01-14 17:32:08 -08:00
$allow = isset ( $this -> allowedAttributes [ $tag ]) ? $this -> allowedAttributes [ $tag ] : $this -> allowedAttributes [ 'default' ];
2020-04-30 14:52:44 -07:00
2021-01-14 17:32:08 -08:00
$removeAttributes = array ();
2013-03-01 00:19:53 -08:00
2021-01-14 17:32:08 -08:00
if ( ! in_array ( $name , $allow ))
{
2017-04-06 08:48:36 -07:00
2021-01-14 18:30:32 -08:00
if ( $this -> scriptAccess == true && strpos ( $name , 'data-' ) === 0 )
2021-01-14 17:32:08 -08:00
{
continue ;
}
2017-04-06 08:48:36 -07:00
2021-01-14 17:32:08 -08:00
$removeAttributes [] = $name ;
//$node->removeAttribute($name);
$this -> removedList [ 'attributes' ][] = $name . ' from <' . $tag . '>' ;
continue ;
}
2014-06-09 21:45:40 +03:00
2021-01-14 17:32:08 -08:00
if ( $this -> invalidAttributeValue ( $value )) // Check value against blacklisted values.
{
2014-06-09 21:45:40 +03:00
//$node->removeAttribute($name);
2021-01-14 17:32:08 -08:00
$node -> setAttribute ( $name , '#---sanitized---#' );
$this -> removedList [ 'sanitized' ][] = $tag . '[' . $name . ']' ;
}
else
{
$_value = $this -> secureAttributeValue ( $name , $value );
$node -> setAttribute ( $name , $_value );
if ( $_value !== $value )
{
$this -> removedList [ 'sanitized' ][] = $tag . '[' . $name . '] converted "' . $value . '" -> "' . $_value . '"' ;
}
}
}
// required - removing attributes in a loop breaks the loop
if ( ! empty ( $removeAttributes ))
{
foreach ( $removeAttributes as $name )
{
$node -> removeAttribute ( $name );
}
}
}
// Remove some stuff.
foreach ( $this -> nodesToDelete as $node )
{
$node -> parentNode -> removeChild ( $node );
}
2016-03-01 13:29:50 -08:00
// Disable Shortcodes in pre/code
2016-03-01 17:50:53 -08:00
2021-01-14 17:32:08 -08:00
foreach ( $this -> nodesToDisableSC as $key => $node )
{
$value = $node -> C14N ();
if ( empty ( $value ))
{
continue ;
}
$value = str_replace ( '
' , " \r " , $value );
if ( $node -> nodeName === 'pre' )
{
$value = preg_replace ( '/^<pre[^>]*>/' , '' , $value );
$value = str_replace ( array ( '</pre>' , '<br></br>' ), array ( '' , '__E_PARSER_CLEAN_HTML_LINE_BREAK__' ), $value );
}
elseif ( $node -> nodeName === 'code' )
{
$value = preg_replace ( '/^<code[^>]*>/' , '' , $value );
$value = str_replace ( array ( '</code>' , '<br></br>' ), array ( '' , '__E_PARSER_CLEAN_HTML_LINE_BREAK__' ), $value );
}
// temporarily change {e_XXX} to {{{e_XXX}}}
$value = str_replace ( array ( '__E_PARSER_CLEAN_HTML_CURLY_OPEN__' , '__E_PARSER_CLEAN_HTML_CURLY_CLOSED__' ), array ( '{{{' , '}}}' ), $value ); // temporarily change {e_XXX} to {{{e_XXX}}}
$newNode = $doc -> createElement ( $node -> nodeName );
$newNode -> nodeValue = $value ;
if ( $class = $node -> getAttribute ( 'class' ))
{
$newNode -> setAttribute ( 'class' , $class );
}
if ( $style = $node -> getAttribute ( 'style' ))
{
$newNode -> setAttribute ( 'style' , $style );
}
$node -> parentNode -> replaceChild ( $newNode , $node );
}
// Convert <code> and <pre> Tags to Htmlentities.
/* TODO XXX Still necessary ? Perhaps using bbcodes only ?
foreach ( $this -> nodesToConvert as $node )
{
$value = $node -> C14N ();
$value = str_replace ( " 
 " , " " , $value );
// print_a("WOWOWO");
if ( $node -> nodeName == 'pre' )
{
$value = substr ( $value , 5 );
$end = strrpos ( $value , " </pre> " );
$value = substr ( $value , 0 , $end );
}
if ( $node -> nodeName == 'code' )
{
$value = substr ( $value , 6 );
$end = strrpos ( $value , " </code> " );
$value = substr ( $value , 0 , $end );
}
$value = htmlentities ( htmlentities ( $value )); // Needed
$node -> nodeValue = $value ;
}
2016-03-01 17:50:53 -08:00
*/
2016-03-01 13:29:50 -08:00
2019-12-25 12:21:13 -08:00
$cleaned = $doc -> saveHTML ( $doc -> documentElement ); // $doc->documentElement fixes utf-8/entities issue. @see http://stackoverflow.com/questions/8218230/php-domdocument-loadhtml-not-encoding-utf-8-correctly
2020-04-12 12:03:03 -07:00
2021-01-14 17:32:08 -08:00
$cleaned = str_replace (
array ( " \n " , '__E_PARSER_CLEAN_HTML_LINE_BREAK__' , '__E_PARSER_CLEAN_HTML_NON_BREAKING_SPACE__' , '{{{' , '}}}' , '__E_PARSER_CLEAN_HTML_CURLY_OPEN__' , '__E_PARSER_CLEAN_HTML_CURLY_CLOSED__' , '<body>' , '</body>' , '<html>' , '</html>' ),
array ( '' , " \n " , ' ' , '{' , '}' , '{' , '}' , '' , '' , '' , '' ),
$cleaned
); // filter out tags.
return trim ( $cleaned );
}
public function secureAttributeValue ( $attribute , $value )
{
$search = isset ( $this -> replaceAttrValues [ $attribute ]) ? $this -> replaceAttrValues [ $attribute ] : $this -> replaceAttrValues [ 'default' ];
if ( ! empty ( $search ))
{
$value = str_replace ( $search , '' , $value );
}
return $value ;
}
/**
* Check for Invalid Attribute Values
* @ param $value string
* @ return bool true / false
*/
public function invalidAttributeValue ( $value )
{
2019-02-26 12:22:36 -08:00
2021-01-14 17:32:08 -08:00
foreach ( $this -> badAttrValues as $v ) // global list because a bad value is bad regardless of the attribute it's in. ;-)
{
if ( preg_match ( '/' . $v . '/i' , $value ) == true )
{
$this -> removedList [ 'blacklist' ][] = " Match found for ' { $v } ' in ' { $value } ' " ;
return true ;
}
}
return false ;
}
2021-01-15 10:59:52 -08:00
/**
* @ param $modifiers
* @ return array
*/
private function getModifiers ( $modifiers )
{
$opts = $this -> e_optDefault ;
2021-01-15 12:47:26 -08:00
if ( strpos ( $modifiers , 'defaults_off' ) !== false )
{
$opts = $this -> e_SuperMods [ 'NODEFAULT' ];
}
2021-01-15 10:59:52 -08:00
// Now process any modifiers that are specified
$aMods = explode ( ',' , $modifiers );
// If there's a supermodifier, it must be first, and in uppercase
$psm = trim ( $aMods [ 0 ]);
if ( isset ( $this -> e_SuperMods [ $psm ]))
{
// Supermodifier found - override default values where necessary
$opts = array_merge ( $opts , $this -> e_SuperMods [ $psm ]);
$opts [ 'context' ] = $psm ;
unset ( $aMods [ 0 ]);
}
// Now find any regular modifiers; use them to modify the context
// (there should only be one or two out of the list of possibles)
foreach ( $aMods as $mod )
{
// Slight concession to varying coding styles - stripping spaces is a waste of CPU cycles!
$mod = trim ( $mod );
if ( isset ( $this -> e_Modifiers [ $mod ]))
{
// This is probably quicker than array_merge
// - especially as usually only one or two loops
foreach ( $this -> e_Modifiers [ $mod ] as $k => $v )
{
// Update our context-specific options
$opts [ $k ] = $v ;
}
}
}
2021-01-15 12:47:26 -08:00
// Turn off a few things if not enabled in options
if ( empty ( $this -> pref [ 'smiley_activate' ]))
{
$opts [ 'emotes' ] = false ;
}
if ( empty ( $this -> pref [ 'make_clickable' ]))
{
$opts [ 'link_click' ] = false ;
}
if ( empty ( $this -> pref [ 'link_replace' ]))
{
$opts [ 'link_replace' ] = false ;
}
2021-01-15 10:59:52 -08:00
2021-01-15 13:20:38 -08:00
2021-01-15 10:59:52 -08:00
return $opts ;
}
2021-01-15 13:20:38 -08:00
/**
* @ param array $opts
* @ param string $text
* @ param bool $convertNL
* @ param bool | string $parseBB
* @ param $modifiers
* @ param int $postID
* @ return array | bool | mixed | string | null
*/
private function processModifiers ( $opts , $text , $convertNL , $parseBB , $modifiers , $postID )
{
if ( $opts [ 'link_click' ])
{
if ( $opts [ 'link_replace' ] && defset ( 'ADMIN_AREA' ) !== true )
{
$link_text = $this -> pref [ 'link_text' ];
$email_text = ( $this -> pref [ 'email_text' ]) ? $this -> replaceConstants ( $this -> pref [ 'email_text' ]) : LAN_EMAIL_SUBS ;
$text = $this -> makeClickable ( $text , 'url' , array ( 'sub' => $link_text , 'ext' => $this -> pref [ 'links_new_window' ]));
$text = $this -> makeClickable ( $text , 'email' , array ( 'sub' => $email_text ));
}
else
{
$text = $this -> makeClickable ( $text , 'url' , array ( 'ext' => true ));
$text = $this -> makeClickable ( $text , 'email' );
}
}
// Convert emoticons to graphical icons, if enabled
if ( $opts [ 'emotes' ])
{
$text = e107 :: getEmote () -> filterEmotes ( $text );
}
// Reduce newlines in all forms to a single newline character (finds '\n', '\r\n', '\n\r')
if ( ! $opts [ 'nobreak' ])
{
if ( $convertNL && ( $this -> preformatted ( $text ) === false )) // eg. html or markdown
{
// We may need to convert to <br /> later
$text = preg_replace ( " #[ \r ]* \n [ \r ]*# " , E_NL , $text );
}
else
{
// Not doing any more - its HTML or Markdown so keep it as is.
$text = preg_replace ( " #[ \r ]* \n [ \r ]*# " , " \n " , $text );
}
}
// Entity conversion
// Restore entity form of quotes and such to single characters, except for text destined for tag attributes or JS.
if ( $opts [ 'value' ])
{
// output used for attribute values.
$text = str_replace ( $this -> replace , $this -> search , $text );
}
else
{
// output not used for attribute values.
$text = str_replace ( $this -> search , $this -> replace , $text );
}
// BBCode processing (other than the four already done, which shouldn't appear at all in the text)
if ( $parseBB !== false )
{
if ( $parseBB === true )
{
// 'Normal' or 'legacy' processing
if ( $modifiers === 'WYSIWYG' )
{
$text = e107 :: getBB () -> parseBBCodes ( $text , $postID , 'wysiwyg' );
}
else
{
$text = e107 :: getBB () -> parseBBCodes ( $text , $postID );
}
}
elseif ( $parseBB === 'STRIP' ) // Need to strip all BBCodes
{
$text = e107 :: getBB () -> parseBBCodes ( $text , $postID , 'default' , true );
}
else // Need to strip just some BBCodes
{
$text = e107 :: getBB () -> parseBBCodes ( $text , $postID , 'default' , $parseBB );
}
}
// replace all {e_XXX} constants with their e107 value. modifier determines relative/absolute conversion
// (Moved to after bbcode processing by Cameron)
if ( $opts [ 'constants' ])
{
$text = $this -> replaceConstants ( $text , $opts [ 'constants' ]); // Now decodes text values
}
// profanity filter
if ( $this -> pref [ 'profanity_filter' ])
{
$text = e107 :: getProfanity () -> filterProfanities ( $text );
}
// Optional short-code conversion
if ( $opts [ 'parse_sc' ])
{
$text = $this -> parseTemplate ( $text , true );
}
/**
* / @ deprecated
*/
if ( $opts [ 'hook' ]) //Run any hooked in parsers
{
if ( ! empty ( $this -> pref [ 'tohtml_hook' ]))
{
// trigger_error('<b>tohtml_hook is deprecated.</b> Use e_parse.php instead.', E_USER_DEPRECATED); // NO LAN
//Process the older tohtml_hook pref (deprecated)
foreach ( explode ( ',' , $this -> pref [ 'tohtml_hook' ]) as $hook )
{
if ( ! is_object ( $this -> e_hook [ $hook ]) && is_readable ( e_PLUGIN . $hook . '/' . $hook . '.php' ))
{
require_once ( e_PLUGIN . $hook . '/' . $hook . '.php' );
$hook_class = 'e_' . $hook ;
$this -> e_hook [ $hook ] = new $hook_class ;
}
if ( is_object ( $this -> e_hook [ $hook ])) // precaution for old plugins.
{
$text = $this -> e_hook [ $hook ] -> $hook ( $text , $opts [ 'context' ]);
}
}
}
/**
* / @ deprecated
*/
if ( isset ( $this -> pref [ 'e_tohtml_list' ]) && is_array ( $this -> pref [ 'e_tohtml_list' ]))
{
foreach ( $this -> pref [ 'e_tohtml_list' ] as $hook )
{
if ( empty ( $hook ))
{
continue ;
}
if ( empty ( $this -> e_hook [ $hook ]) && is_readable ( e_PLUGIN . $hook . '/e_tohtml.php' ) /*&& !is_object($this->e_hook[$hook])*/ )
{
require_once ( e_PLUGIN . $hook . '/e_tohtml.php' );
$hook_class = 'e_tohtml_' . $hook ;
$this -> e_hook [ $hook ] = new $hook_class ;
}
if ( is_object ( $this -> e_hook [ $hook ]))
{
/** @var e_tohtml_linkwords $deprecatedHook */
$deprecatedHook = $this -> e_hook [ $hook ];
$text = $deprecatedHook -> to_html ( $text , $opts [ 'context' ]);
}
}
}
/**
* / Preferred 'hook'
*/
if ( ! empty ( $this -> pref [ 'e_parse_list' ]))
{
foreach ( $this -> pref [ 'e_parse_list' ] as $plugin )
{
$hookObj = e107 :: getAddon ( $plugin , 'e_parse' );
if ( $tmp = e107 :: callMethod ( $hookObj , 'toHTML' , $text , $opts [ 'context' ]))
{
$text = $tmp ;
}
}
}
}
// Word wrap
if ( ! empty ( $this -> pref [ 'main_wordwrap' ]) && ! $opts [ 'nobreak' ])
{
$text = $this -> textclean ( $text , $this -> pref [ 'main_wordwrap' ]);
}
// Search highlighting
if ( $opts [ 'emotes' ] && $this -> checkHighlighting ()) // Why??
{
$text = $this -> e_highlight ( $text , $this -> e_query );
}
if ( $convertNL == true )
{
// Default replaces all \n with <br /> for HTML display
$nl_replace = '<br />' ;
if ( $opts [ 'nobreak' ])
{
$nl_replace = '' ;
}
elseif ( $opts [ 'retain_nl' ])
{
$nl_replace = " \n " ;
}
$text = str_replace ( E_NL , $nl_replace , $text );
}
return $text ;
}
2019-02-26 12:22:36 -08:00
2013-03-01 00:19:53 -08:00
}
2013-05-20 17:10:38 -07:00