header = array('FlexPhoto_Plugin', 'skinhead');
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('FlexPhoto_Plugin','tutu');
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('FlexPhoto_Plugin','tus');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate(){}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
public static function skinhead(){
?>
)?\{flex(.*?)\}(.*?)\{\/flex\}(<\/p>)?(
)?/s';
$rp = '
${3}
';
$new=preg_replace($reg, $rp, $new);
return $new;
}
private static function parsePhotoSetCallBack($match)
{
$new='{flex'.$match[1].'}'. str_replace(['
', '
', '
', '', '
'], '', $match[2]) .'/flex}';
/* 逐个匹配 img 标签,保留原标签里的关键信息(data-src / alt),
并自行生成 Fancybox 触发元素,避免依赖主题对 img 属性顺序的强制要求 */
$new = preg_replace_callback('/
]*>/i', array('FlexPhoto_Plugin', 'buildPhotoItem'), $new);
return $new;
}
private static function buildPhotoItem($match)
{
$tag = $match[0];
$src = '';
if (preg_match('/\bdata-src=["\']([^"\']+)["\']/i', $tag, $m)) {
$src = trim($m[1]);
} elseif (preg_match('/\bsrc=["\']([^"\']+)["\']/i', $tag, $m)) {
$src = trim($m[1]);
}
if ($src === '') {
return '';
}
$alt = preg_match('/\balt=["\']([^"\']*)["\']/i', $tag, $m) ? $m[1] : '';
// 先解码再编码,避免已转义的地址被二次转义
$src = htmlspecialchars(html_entity_decode($src, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
$alt = htmlspecialchars(html_entity_decode($alt, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
return ''
. '
';
}
private static function parsePhotoSetCol($match)
{
if(empty($match[1])){
return '{flex class="flexphoto"}'.$match[2].'/flex}';
}
preg_match_all('/
]*>/i', $match[2], $matches);
// 返回匹配到的数量
$num = count($matches[0]);
$set = preg_replace('/(.*?)set="(.*?)"/', '$2', $match[1]);
$set = explode(",", $set);
$mobile = trim($set[0])==0 ? $num : trim($set[0]);
$tablet = trim($set[1])==0 ? $num : trim($set[1]);
$desktop = trim($set[2])==0 ? $num : trim($set[2]);
return '{flex class="flexphoto diycol" style="--desktop-col: '.$desktop.'; --tablet-col: '.$tablet.'; --mobile-col: '.$mobile.';"}'.$match[2].'/flex}';
}
public static function tus($text, $ojbk)
{
$text = str_replace('{flex}', '', $text);
$text = str_replace('{/flex}', '', $text);
return $text;
}
}