mirror of
https://github.com/e107inc/e107.git
synced 2025-08-02 20:57:26 +02:00
Bbcode code optimization and test.
This commit is contained in:
@@ -11,276 +11,300 @@
|
|||||||
// Currently defaults class to 'floatnone' - overridden by bbcode
|
// Currently defaults class to 'floatnone' - overridden by bbcode
|
||||||
|
|
||||||
|
|
||||||
if (!defined('e107_INIT')) { exit; }
|
if(!defined('e107_INIT'))
|
||||||
|
|
||||||
class bb_img extends e_bb_base
|
|
||||||
{
|
|
||||||
function toDB($code_text, $parm)
|
|
||||||
{
|
{
|
||||||
$parms = eHelper::scParams($parm);
|
exit;
|
||||||
$safe = array();
|
|
||||||
|
|
||||||
if(!empty($parms['class'])) $safe['class'] = eHelper::secureClassAttr($parms['class']);
|
|
||||||
if(!empty($parms['id'])) $safe['id'] = eHelper::secureIdAttr($parms['id']);
|
|
||||||
if(!empty($parms['style'])) $safe['style'] = eHelper::secureStyleAttr($parms['style']);
|
|
||||||
if(!empty($parms['alt'])) $safe['alt'] = e107::getParser()->filter($parms['alt']);
|
|
||||||
if(isset($parms['width'])) $safe['width'] = (int) $parms['width'];
|
|
||||||
|
|
||||||
if(!empty($safe))
|
|
||||||
{
|
|
||||||
return '[img '.eHelper::buildAttr($safe).']'.$code_text.'[/img]';
|
|
||||||
}
|
|
||||||
|
|
||||||
return '[img]'.$code_text.'[/img]';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Media Manager bbcode. eg. using {e_MEDIA_IMAGE} and auto-resizing.
|
|
||||||
* @param $code_text
|
|
||||||
* @param $parm
|
|
||||||
* @return string <img> tag with resized image.
|
|
||||||
*/
|
|
||||||
private function mediaImage($code_text,$parm)
|
|
||||||
{
|
|
||||||
$tp = e107::getParser();
|
|
||||||
|
|
||||||
// Replace the bbcode path with a real one.
|
class bb_img extends e_bb_base
|
||||||
$code_text = str_replace('{e_MEDIA}images/','{e_MEDIA_IMAGE}',$code_text); //BC 0.8 fix.
|
{
|
||||||
// $code_text = str_replace('{e_MEDIA_IMAGE}', e_HTTP."thumb.php?src=e_MEDIA_IMAGE/", $code_text);
|
|
||||||
// $code_text = str_replace('{e_THEME}', e_HTTP."thumb.php?src=e_THEME/", $code_text);
|
|
||||||
$imgParms = $this->processParm($code_text, $parm);
|
|
||||||
|
|
||||||
$figcaption = false;
|
function toDB($code_text, $parm)
|
||||||
|
|
||||||
if(!empty($imgParms['figcaption']))
|
|
||||||
{
|
|
||||||
$figcaption = $imgParms['figcaption'];
|
|
||||||
unset($imgParms['figcaption']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
foreach($imgParms as $k => $v)
|
|
||||||
{
|
|
||||||
// $parmStr .= " ".$k.'="'.$v.'"';
|
|
||||||
if($v !== '')
|
|
||||||
{
|
|
||||||
$p[] = $tp->toAttribute($k).'="'.$tp->toAttribute($v).'"';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$resizeWidth = e107::getBB()->resizeWidth();
|
|
||||||
$w = vartrue($imgParms['width']) ? intval($imgParms['width']) : vartrue($resizeWidth,0);
|
|
||||||
// $h = vartrue($imgParms['height']) ? intval($imgParms['height']) : e107::getBB()->resizeHeight();
|
|
||||||
|
|
||||||
// $resize = "&w=".$w; // Always resize - otherwise the thumbnailer returns nothing.
|
|
||||||
// $parmStr = implode(" ",$p);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// $url = e107::getParser()->thumbUrl($code_text, $resize);
|
|
||||||
|
|
||||||
$imgParms['w'] = $w;
|
|
||||||
|
|
||||||
if(!empty($figcaption))
|
|
||||||
{
|
{
|
||||||
$html = "<figure>\n";
|
|
||||||
// $html .= "<img src=\"".$url."\" {$parmStr} />";
|
|
||||||
$html .= $tp->toImage($code_text, $imgParms);
|
|
||||||
$html .= "<figcaption>".e107::getParser()->filter($figcaption)."</figcaption>\n";
|
|
||||||
$html .= "</figure>";
|
|
||||||
|
|
||||||
return $html;
|
$parms = eHelper::scParams($parm);
|
||||||
|
$safe = array();
|
||||||
|
|
||||||
|
if(!empty($parms['class']))
|
||||||
|
{
|
||||||
|
$safe['class'] = eHelper::secureClassAttr($parms['class']);
|
||||||
|
}
|
||||||
|
if(!empty($parms['id']))
|
||||||
|
{
|
||||||
|
$safe['id'] = eHelper::secureIdAttr($parms['id']);
|
||||||
|
}
|
||||||
|
if(!empty($parms['style']))
|
||||||
|
{
|
||||||
|
$safe['style'] = eHelper::secureStyleAttr($parms['style']);
|
||||||
|
}
|
||||||
|
if(!empty($parms['alt']))
|
||||||
|
{
|
||||||
|
$safe['alt'] = e107::getParser()->filter($parms['alt']);
|
||||||
|
}
|
||||||
|
if(isset($parms['width']))
|
||||||
|
{
|
||||||
|
$safe['width'] = (int) $parms['width'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($safe))
|
||||||
|
{
|
||||||
|
return '[img ' . eHelper::buildAttr($safe) . ']' . $code_text . '[/img]';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '[img]' . $code_text . '[/img]';
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
/**
|
||||||
|
* Media Manager bbcode. eg. using {e_MEDIA_IMAGE} and auto-resizing.
|
||||||
|
*
|
||||||
|
* @param $code_text
|
||||||
|
* @param $parm
|
||||||
|
* @return string <img> tag with resized image.
|
||||||
|
*/
|
||||||
|
private function mediaImage($code_text, $parm)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$tp = e107::getParser();
|
||||||
|
|
||||||
|
// Replace the bbcode path with a real one.
|
||||||
|
$code_text = str_replace('{e_MEDIA}images/', '{e_MEDIA_IMAGE}', $code_text); //BC 0.8 fix.
|
||||||
|
|
||||||
|
$imgParms = $this->processParm($code_text, $parm);
|
||||||
|
|
||||||
|
$figcaption = false;
|
||||||
|
|
||||||
|
if(!empty($imgParms['figcaption']))
|
||||||
|
{
|
||||||
|
$figcaption = $imgParms['figcaption'];
|
||||||
|
unset($imgParms['figcaption']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$resizeWidth = e107::getBB()->resizeWidth();
|
||||||
|
|
||||||
|
$w = !empty($imgParms['width']) ? (int) $imgParms['width'] : vartrue($resizeWidth, 0);
|
||||||
|
|
||||||
|
$imgParms['w'] = $w;
|
||||||
|
|
||||||
|
if(!empty($figcaption))
|
||||||
|
{
|
||||||
|
$html = "<figure>\n";
|
||||||
|
// $html .= "<img src=\"".$url."\" {$parmStr} />";
|
||||||
|
$html .= $tp->toImage($code_text, $imgParms);
|
||||||
|
$html .= "<figcaption>" . e107::getParser()->filter($figcaption) . "</figcaption>\n";
|
||||||
|
$html .= "</figure>";
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
return $tp->toImage($code_text, $imgParms);
|
return $tp->toImage($code_text, $imgParms);
|
||||||
// return "<img src=\"".$url."\" {$parmStr} />";
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the [img] bbcode parm. ie. [img parms]something[/img]
|
* Process the [img] bbcode parm. ie. [img parms]something[/img]
|
||||||
* @param $code_text
|
*
|
||||||
* @param $parm
|
* @param string $code_text
|
||||||
* @param string $mode
|
* @param string $parm
|
||||||
* @return array|string
|
* @param string $mode
|
||||||
*/
|
* @return array|string
|
||||||
private function processParm($code_text, $parm, $mode='')
|
*/
|
||||||
{
|
private function processParm($code_text, $parm, $mode = '')
|
||||||
|
{
|
||||||
|
|
||||||
$tp = e107::getParser();
|
$tp = e107::getParser();
|
||||||
$imgParms = array();
|
$imgParms = array();
|
||||||
|
|
||||||
$parm = preg_replace('#onerror *=#i','',$parm);
|
|
||||||
$parm = str_replace("amp;", "&", $parm);
|
|
||||||
|
|
||||||
// $parm = str_replace(" ","&",$parm); // Needed as parse_str() doesn't know how to handle spaces. Could return [width] => '400 AltValue'
|
|
||||||
|
|
||||||
parse_str($parm,$imgParms);
|
|
||||||
|
|
||||||
|
|
||||||
if(!vartrue($imgParms['width']) && strpos($parm,'width')!==false) // Calculate thumbnail width from style.
|
$parm = preg_replace('#onerror *=#i', '', $parm);
|
||||||
{
|
$parm = str_replace("amp;", "&", $parm);
|
||||||
preg_match("/width:([\d]*)[p|x|%|;]*/i", $parm, $m);
|
|
||||||
if($m[1] > 0)
|
// $parm = str_replace(" ","&",$parm); // Needed as parse_str() doesn't know how to handle spaces. Could return [width] => '400 AltValue'
|
||||||
|
|
||||||
|
parse_str($parm, $imgParms);
|
||||||
|
|
||||||
|
|
||||||
|
if(empty($imgParms['width']) && strpos($parm, 'width') !== false) // Calculate thumbnail width from style.
|
||||||
{
|
{
|
||||||
$imgParms['width'] = $m[1];
|
preg_match("/width:([\d]*)[p|x|%|;]*/i", $parm, $m);
|
||||||
$imgParms['style'] = str_replace($m[0],'',$imgParms['style']); // strip hard-coded width styling.
|
if($m[1] > 0)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!vartrue($imgParms['alt'])) // Generate an Alt value from filename if one not found.
|
|
||||||
{
|
|
||||||
preg_match("/([\w]*)(?:\.png|\.jpg|\.jpeg|\.gif)/i", $code_text, $match); // Generate required Alt attribute.
|
|
||||||
$imgParms['alt'] = ucwords(str_replace("_"," ",$match[1]));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$imgParms['figcaption'] = $imgParms['alt'] ;
|
|
||||||
}
|
|
||||||
|
|
||||||
$imgParms['title'] = $imgParms['alt'] ;
|
|
||||||
|
|
||||||
$class = !empty($imgParms['class']) ? ' '.$imgParms['class'] : '';
|
|
||||||
|
|
||||||
$imgParms['class'] = "img-rounded rounded bbcode ".e107::getBB()->getClass('img').$class; // This will be overridden if a new class is specified
|
|
||||||
|
|
||||||
if($mode == 'string')
|
|
||||||
{
|
|
||||||
$text = '';
|
|
||||||
foreach($imgParms as $key => $val)
|
|
||||||
{
|
|
||||||
$text .= $key."='".$tp->toAttribute($val)."' ";
|
|
||||||
}
|
|
||||||
return $text;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return $imgParms;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function toHTML($code_text, $parm)
|
|
||||||
{
|
|
||||||
|
|
||||||
$tp = e107::getParser();
|
|
||||||
$pref = e107::getPref();
|
|
||||||
|
|
||||||
if (trim($code_text) == "") return ""; // Do nothing on empty file
|
|
||||||
|
|
||||||
if(substr($code_text,0,15) == '{e_MEDIA_IMAGE}' || substr($code_text,0,9) == '{e_MEDIA}' || substr($code_text,0,9) == '{e_THEME}') // Image from Media-Manager.
|
|
||||||
{
|
|
||||||
return $this->mediaImage($code_text, $parm);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (preg_match("#\.php\?.*#",$code_text)){return "";} //XXX Breaks MediaManager Images, so do it after mediaManager check.
|
|
||||||
|
|
||||||
$addlink = FALSE;
|
|
||||||
|
|
||||||
|
|
||||||
// Automatic Img Resizing --
|
|
||||||
$w = e107::getBB()->resizeWidth(); // varies depending on the class set by external script. see admin->media-manager->prefs
|
|
||||||
$h = e107::getBB()->resizeHeight();
|
|
||||||
|
|
||||||
// No resizing on v1.x legacy images.
|
|
||||||
if(strpos($code_text,"://")==false && ($w || $h) && strpos($code_text,"{e_IMAGE}custom")===false && strpos($code_text,"newspost_images/")===false) // local file.
|
|
||||||
{
|
|
||||||
$code_text = $tp->thumbUrl($code_text,'w='.$w.'&h='.$h);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------
|
|
||||||
|
|
||||||
$search = array('"', '{E_IMAGE}', '{E_FILE}', '{e_IMAGE}', '{e_FILE}');
|
|
||||||
$replace = array(''', e_IMAGE_ABS, e_FILE_ABS, e_IMAGE_ABS, e_FILE_ABS);
|
|
||||||
$replaceInt = array(''', e_IMAGE, e_FILE, e_IMAGE, e_FILE);
|
|
||||||
$intName = str_replace($search, $replaceInt, $code_text); // Server-relative file names
|
|
||||||
|
|
||||||
|
|
||||||
$code_text = str_replace($search, $replace, $code_text);
|
|
||||||
$code_text = $tp -> toAttribute($code_text);
|
|
||||||
|
|
||||||
$img_file = pathinfo($code_text); // 'External' file name. N.B. - might still contain a constant such as e_IMAGE
|
|
||||||
|
|
||||||
$parmStr = $this->processParm($code_text, $parm, 'string');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Select a random file if required
|
|
||||||
if (strpos($img_file['basename'],'*') !== FALSE)
|
|
||||||
{
|
|
||||||
$fileList = array();
|
|
||||||
$intFile = pathinfo($intName); // N.B. - might still contain a constant such as e_IMAGE
|
|
||||||
$matchString = '#'.str_replace('*','.*?',$intFile['basename']).'#';
|
|
||||||
$dirName = $tp->replaceConstants($intFile['dirname'].'/'); // we want server-relative directory
|
|
||||||
if (($h = opendir($dirName)) !== FALSE)
|
|
||||||
{
|
|
||||||
while (($f = readdir($h)) !== FALSE)
|
|
||||||
{
|
{
|
||||||
if (preg_match($matchString,$f))
|
$imgParms['width'] = $m[1];
|
||||||
{
|
$imgParms['style'] = str_replace($m[0], '', $imgParms['style']); // strip hard-coded width styling.
|
||||||
$fileList[] = $f; // Just need to note file names
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(empty($imgParms['alt'])) // Generate an Alt value from filename if one not found.
|
||||||
|
{
|
||||||
|
preg_match("/([\w]*)(?:\.png|\.jpg|\.jpeg|\.gif)/i", $code_text, $match); // Generate required Alt attribute.
|
||||||
|
|
||||||
|
if(!empty($match[1]))
|
||||||
|
{
|
||||||
|
$imgParms['alt'] = ucwords(str_replace("_", " ", $match[1]));
|
||||||
}
|
}
|
||||||
closedir($h);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo "Error opening directory: {$dirName}<br />";
|
$imgParms['figcaption'] = $imgParms['alt'];
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
if (count($fileList))
|
|
||||||
|
if(!empty($imgParms['alt']))
|
||||||
{
|
{
|
||||||
$img_file['basename'] = $fileList[mt_rand(0,count($fileList)-1)]; // Just change name of displayed file - no change on directory
|
$imgParms['title'] = $imgParms['alt'];
|
||||||
$code_text = $img_file['dirname']."/".$img_file['basename'];
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
$class = !empty($imgParms['class']) ? ' ' . $imgParms['class'] : '';
|
||||||
|
|
||||||
|
$imgParms['class'] = "img-rounded rounded bbcode " . e107::getBB()->getClass('img') . $class; // This will be overridden if a new class is specified
|
||||||
|
|
||||||
|
if($mode == 'string')
|
||||||
{
|
{
|
||||||
echo 'No file: '.$code_text;
|
$text = '';
|
||||||
return '';
|
foreach($imgParms as $key => $val)
|
||||||
|
{
|
||||||
|
$text .= $key . "='" . $tp->toAttribute($val) . "' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $imgParms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
// Check for whether we can display image down here - so we can show image name if appropriate
|
* @param string $code_text
|
||||||
if (!vartrue($pref['image_post']) || !check_class($pref['image_post_class']))
|
* @param string $parm width=x etc.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function toHTML($code_text, $parm)
|
||||||
{
|
{
|
||||||
switch ($pref['image_post_disabled_method'])
|
|
||||||
|
$tp = e107::getParser();
|
||||||
|
$pref = e107::getPref();
|
||||||
|
|
||||||
|
$code_text = trim($code_text);
|
||||||
|
|
||||||
|
if(empty($code_text))
|
||||||
{
|
{
|
||||||
case '1' :
|
return "";
|
||||||
return CORE_LAN17;
|
} // Do nothing on empty file
|
||||||
case '2' :
|
|
||||||
|
if(strpos($code_text, '{e_MEDIA_IMAGE}') === 0 || strpos($code_text, '{e_MEDIA}') === 0 || strpos($code_text, '{e_THEME}') === 0) // Image from Media-Manager.
|
||||||
|
{
|
||||||
|
return $this->mediaImage($code_text, $parm);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(preg_match("#\.php\?.*#", $code_text))
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
} //XXX Breaks MediaManager Images, so do it after mediaManager check.
|
||||||
|
|
||||||
|
$addlink = false;
|
||||||
|
|
||||||
|
|
||||||
|
// Automatic Img Resizing --
|
||||||
|
$w = e107::getBB()->resizeWidth(); // varies depending on the class set by external script. see admin->media-manager->prefs
|
||||||
|
$h = e107::getBB()->resizeHeight();
|
||||||
|
|
||||||
|
// No resizing on v1.x legacy images.
|
||||||
|
if(strpos($code_text, "://") == false && ($w || $h) && strpos($code_text, "{e_IMAGE}custom") === false && strpos($code_text, "newspost_images/") === false) // local file.
|
||||||
|
{
|
||||||
|
$code_text = $tp->thumbUrl($code_text, 'w=' . $w . '&h=' . $h);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
$search = array('"', '{E_IMAGE}', '{E_FILE}', '{e_IMAGE}', '{e_FILE}');
|
||||||
|
$replace = array(''', e_IMAGE_ABS, e_FILE_ABS, e_IMAGE_ABS, e_FILE_ABS);
|
||||||
|
$replaceInt = array(''', e_IMAGE, e_FILE, e_IMAGE, e_FILE);
|
||||||
|
$intName = str_replace($search, $replaceInt, $code_text); // Server-relative file names
|
||||||
|
|
||||||
|
|
||||||
|
$code_text = str_replace($search, $replace, $code_text);
|
||||||
|
$code_text = $tp->toAttribute($code_text);
|
||||||
|
|
||||||
|
$img_file = pathinfo($code_text); // 'External' file name. N.B. - might still contain a constant such as e_IMAGE
|
||||||
|
|
||||||
|
$parmStr = $this->processParm($code_text, $parm, 'string');
|
||||||
|
|
||||||
|
|
||||||
|
// Select a random file if required
|
||||||
|
if(strpos($img_file['basename'], '*') !== false)
|
||||||
|
{
|
||||||
|
$fileList = array();
|
||||||
|
$intFile = pathinfo($intName); // N.B. - might still contain a constant such as e_IMAGE
|
||||||
|
$matchString = '#' . str_replace('*', '.*?', $intFile['basename']) . '#';
|
||||||
|
$dirName = $tp->replaceConstants($intFile['dirname'] . '/'); // we want server-relative directory
|
||||||
|
if(($h = opendir($dirName)) !== false)
|
||||||
|
{
|
||||||
|
while(($f = readdir($h)) !== false)
|
||||||
|
{
|
||||||
|
if(preg_match($matchString, $f))
|
||||||
|
{
|
||||||
|
$fileList[] = $f; // Just need to note file names
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($h);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo "Error opening directory: {$dirName}<br />";
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
|
}
|
||||||
|
if(count($fileList))
|
||||||
|
{
|
||||||
|
$img_file['basename'] = $fileList[mt_rand(0, count($fileList) - 1)]; // Just change name of displayed file - no change on directory
|
||||||
|
$code_text = $img_file['dirname'] . "/" . $img_file['basename'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo 'No file: ' . $code_text;
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return CORE_LAN18.$code_text;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Check for link to main image if required
|
// Check for whether we can display image down here - so we can show image name if appropriate
|
||||||
if (strpos($img_file['basename'],'th_') === 0)
|
if(!vartrue($pref['image_post']) || !check_class($pref['image_post_class']))
|
||||||
{
|
{
|
||||||
$addlink = TRUE;
|
switch($pref['image_post_disabled_method'])
|
||||||
$main_name = $img_file['dirname']."/".substr($img_file['basename'],3); // delete the 'th' prefix from file name
|
{
|
||||||
}
|
case '1' :
|
||||||
elseif (strpos($img_file['basename'],'thumb_') === 0)
|
return CORE_LAN17;
|
||||||
{
|
case '2' :
|
||||||
$addlink = TRUE;
|
return '';
|
||||||
$main_name = $img_file['dirname']."/".substr($img_file['basename'],6); // delete the 'thumb' prefix from file name
|
}
|
||||||
}
|
|
||||||
|
return CORE_LAN18 . $code_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Check for link to main image if required
|
||||||
|
if(strpos($img_file['basename'], 'th_') === 0)
|
||||||
|
{
|
||||||
|
$addlink = true;
|
||||||
|
$main_name = $img_file['dirname'] . "/" . substr($img_file['basename'], 3); // delete the 'th' prefix from file name
|
||||||
|
}
|
||||||
|
elseif(strpos($img_file['basename'], 'thumb_') === 0)
|
||||||
|
{
|
||||||
|
$addlink = true;
|
||||||
|
$main_name = $img_file['dirname'] . "/" . substr($img_file['basename'], 6); // delete the 'thumb' prefix from file name
|
||||||
|
}
|
||||||
|
|
||||||
if ($addlink)
|
|
||||||
{
|
if($addlink)
|
||||||
return "<a href='".$main_name."' rel='external'><img src='".$code_text."' {$parmStr} /></a>";
|
{
|
||||||
}
|
return "<a href='" . $main_name . "' rel='external'><img src='" . $code_text . "' {$parmStr} /></a>";
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
return "<img src='".$code_text."' {$parmStr} />";
|
{
|
||||||
|
return "<img src='" . $code_text . "' {$parmStr} />";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -176,7 +176,7 @@ class receiveMail
|
|||||||
{
|
{
|
||||||
$body = $this->get_part($this->marubox, $mid, "TEXT/HTML");
|
$body = $this->get_part($this->marubox, $mid, "TEXT/HTML");
|
||||||
}
|
}
|
||||||
if (($body == "") || $mode == 'plain')
|
if (empty($body) || $mode == 'plain')
|
||||||
$body = $this->get_part($this->marubox, $mid, "TEXT/PLAIN");
|
$body = $this->get_part($this->marubox, $mid, "TEXT/PLAIN");
|
||||||
if ($body == "") {
|
if ($body == "") {
|
||||||
return "";
|
return "";
|
||||||
|
@@ -910,8 +910,9 @@ class e107_user_extended
|
|||||||
{
|
{
|
||||||
$tp = e107::getParser();
|
$tp = e107::getParser();
|
||||||
$frm = e107::getForm();
|
$frm = e107::getForm();
|
||||||
|
$curval = trim($curval);
|
||||||
|
|
||||||
if(trim($curval) == "" && $struct['user_extended_struct_default'] != "")
|
if(empty($curval) && !empty($struct['user_extended_struct_default']))
|
||||||
{
|
{
|
||||||
$curval = $struct['user_extended_struct_default'];
|
$curval = $struct['user_extended_struct_default'];
|
||||||
}
|
}
|
||||||
|
@@ -1422,7 +1422,7 @@ $columnInfo = array(
|
|||||||
</tr>";
|
</tr>";
|
||||||
} // End of mirror-related stuff
|
} // End of mirror-related stuff
|
||||||
|
|
||||||
$download_author = $subAction != "edit" && $download_author == "" ? USERNAME : $download_author;//TODO what if editing an no author specified
|
$download_author = ($subAction !== "edit" && empty($download_author)) ? USERNAME : $download_author;//TODO what if editing an no author specified
|
||||||
$download_author_email = $subAction != "edit" && $download_author_email == "" ? USEREMAIL : $download_author_email;
|
$download_author_email = $subAction != "edit" && $download_author_email == "" ? USEREMAIL : $download_author_email;
|
||||||
$text .= "
|
$text .= "
|
||||||
</table>
|
</table>
|
||||||
|
@@ -1393,7 +1393,7 @@ function admin_config_adminmenu()
|
|||||||
$tmp = explode(".", e_QUERY);
|
$tmp = explode(".", e_QUERY);
|
||||||
$action = $tmp[0];
|
$action = $tmp[0];
|
||||||
}
|
}
|
||||||
if (!isset($action) || ($action == "")) $action = "config";
|
if (empty($action)) $action = "config";
|
||||||
|
|
||||||
$var['config']['text'] = ADSTAT_LAN_35;
|
$var['config']['text'] = ADSTAT_LAN_35;
|
||||||
$var['config']['link'] = 'admin_config.php';
|
$var['config']['link'] = 'admin_config.php';
|
||||||
|
@@ -470,7 +470,7 @@ class logConsolidate
|
|||||||
list($pageName,$tmp) = explode("?",$pageName);
|
list($pageName,$tmp) = explode("?",$pageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($pageName == "")
|
if(empty($pageName))
|
||||||
{
|
{
|
||||||
$pageName = "index";
|
$pageName = "index";
|
||||||
}
|
}
|
||||||
|
@@ -1119,7 +1119,7 @@ class siteStats
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($image == "")
|
if(empty($image))
|
||||||
{
|
{
|
||||||
$image = "unknown.png";
|
$image = "unknown.png";
|
||||||
}
|
}
|
||||||
|
@@ -581,7 +581,7 @@ class newsletter
|
|||||||
*/
|
*/
|
||||||
function show_options($action)
|
function show_options($action)
|
||||||
{
|
{
|
||||||
if ($action == "")
|
if (empty($action))
|
||||||
{
|
{
|
||||||
$action = "main";
|
$action = "main";
|
||||||
}
|
}
|
||||||
|
79
e107_tests/tests/unit/bbcodes/bb_imgTest.php
Normal file
79
e107_tests/tests/unit/bbcodes/bb_imgTest.php
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* e107 website system
|
||||||
|
*
|
||||||
|
* Copyright (C) 2008-2020 e107 Inc (e107.org)
|
||||||
|
* Released under the terms and conditions of the
|
||||||
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class bb_imgTest extends \Codeception\Test\Unit
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var bb_img */
|
||||||
|
protected $bb;
|
||||||
|
|
||||||
|
protected function _before()
|
||||||
|
{
|
||||||
|
|
||||||
|
require_once(e_CORE."bbcodes/bb_img.php");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$this->bb = $this->make('bb_img');
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
$this->assertTrue(false, "Couldn't load bb_img object");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToDB()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testToHTML()
|
||||||
|
{
|
||||||
|
$tests = array(
|
||||||
|
array(
|
||||||
|
'codetext' => '{e_MEDIA_IMAGE}2020-12/5.sm.webp',
|
||||||
|
'parm' => '',
|
||||||
|
'expected' => '<img class="img-rounded rounded bbcode bbcode-img" src="thumb.php?src=e_MEDIA_IMAGE%2F2020-12%2F5.sm.webp&w=0&h=0" alt="5.sm.webp" />'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'codetext' => '{e_MEDIA}images/2020-12/horse.jpg',
|
||||||
|
'parm' => 'width=300',
|
||||||
|
'expected' => '<img class="img-rounded rounded bbcode bbcode-img" src="thumb.php?src=e_MEDIA_IMAGE%2F2020-12%2Fhorse.jpg&w=300&h=0" alt="Horse" srcset="thumb.php?src=e_MEDIA_IMAGE%2F2020-12%2Fhorse.jpg&w=600&h=0 2x" width="300" title="Horse" />'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'codetext' => '{e_MEDIA_IMAGE}2020-12/horse.jpg',
|
||||||
|
'parm' => 'width=300',
|
||||||
|
'expected' => '<img class="img-rounded rounded bbcode bbcode-img" src="thumb.php?src=e_MEDIA_IMAGE%2F2020-12%2Fhorse.jpg&w=300&h=0" alt="Horse" srcset="thumb.php?src=e_MEDIA_IMAGE%2F2020-12%2Fhorse.jpg&w=600&h=0 2x" width="300" title="Horse" />'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'codetext' => '{e_THEME}voux/install/gasmask.jpg',
|
||||||
|
'parm' => 'width=300&alt=Custom',
|
||||||
|
'expected' => "<figure>
|
||||||
|
<img class=\"img-rounded rounded bbcode bbcode-img\" src=\"thumb.php?src=e_THEME%2Fvoux%2Finstall%2Fgasmask.jpg&w=300&h=0\" alt=\"Custom\" srcset=\"thumb.php?src=e_THEME%2Fvoux%2Finstall%2Fgasmask.jpg&w=600&h=0 2x\" width=\"300\" title=\"Custom\" /><figcaption>Custom</figcaption>
|
||||||
|
</figure>"
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach($tests as $var)
|
||||||
|
{
|
||||||
|
$result = $this->bb->toHTML($var['codetext'], $var['parm']);
|
||||||
|
$result = preg_replace('/"([^"]*)thumb.php/','"thumb.php', $result); // remove the path before thumb.php
|
||||||
|
|
||||||
|
$this->assertSame($var['expected'], $result);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -65,7 +65,7 @@ TMP;
|
|||||||
|
|
||||||
$actual = $this->tp->toHTML($src,true);
|
$actual = $this->tp->toHTML($src,true);
|
||||||
|
|
||||||
$expected = "<div class='bbcode-center' style='text-align:center'><img src='".e_HTTP."e107_images/generic/blank_avatar.jpg' width='' alt='Blank Avatar' title='Blank Avatar' class='img-rounded rounded bbcode bbcode-img' /></div>";
|
$expected = "<div class='bbcode-center' style='text-align:center'><img src='".e_HTTP."e107_images/generic/blank_avatar.jpg' alt='Blank Avatar' title='Blank Avatar' class='img-rounded rounded bbcode bbcode-img' /></div>";
|
||||||
|
|
||||||
$this->assertEquals($expected, $actual, "BBcode parsing failed on [img]");
|
$this->assertEquals($expected, $actual, "BBcode parsing failed on [img]");
|
||||||
|
|
||||||
@@ -1034,6 +1034,24 @@ while($row = $sql->fetch())
|
|||||||
$this->tp->setConvertToWebP(false);
|
$this->tp->setConvertToWebP(false);
|
||||||
|
|
||||||
|
|
||||||
|
$tests = array(
|
||||||
|
0 => array(
|
||||||
|
'src' => '{e_PLUGIN}gallery/images/butterfly.jpg',
|
||||||
|
'parms' => array('w'=>300, 'alt'=>"Custom"),
|
||||||
|
'expected' => '<img class="img-responsive img-fluid" src="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=300&h=0" alt="Custom" srcset="thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=600&h=0 2x" width="300" />'
|
||||||
|
),
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach($tests as $index => $var)
|
||||||
|
{
|
||||||
|
$result = $this->tp->toImage($var['src'], $var['parms']);
|
||||||
|
$result = preg_replace('/"([^"]*)thumb.php/','"thumb.php', $result);
|
||||||
|
$this->assertSame($var['expected'], $result);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testThumbSrcSet()
|
public function testThumbSrcSet()
|
||||||
|
Reference in New Issue
Block a user