Skip to content

Commit

Permalink
Merge pull request #75 from youranreus/dev3.0
Browse files Browse the repository at this point in the history
version3.3.3
  • Loading branch information
youranreus authored Apr 25, 2022
2 parents 65a7dbc + 044e3b6 commit 573874a
Show file tree
Hide file tree
Showing 13 changed files with 501 additions and 79 deletions.
20 changes: 17 additions & 3 deletions components/header.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
<?php
if (!defined('__TYPECHO_ROOT_DIR__'))
exit;
$minInfix = !defined('__TYPECHO_DEBUG__') || __TYPECHO_DEBUG__ != true ? ".min" : "";
$devTag = !defined('__TYPECHO_DEBUG__') || __TYPECHO_DEBUG__ != true ? G::$version : time(); ?>
$devTag = !defined('__TYPECHO_DEBUG__') || __TYPECHO_DEBUG__ != true ? G::$version : time();

if (isset($_POST['DYLM'])) {
exit(G::DYLM('add'));
}
?>
<!DOCTYPE HTML>
<html lang="zh">
<head>
Expand Down Expand Up @@ -35,7 +42,14 @@
<style>
/* 设置自定义背景[颜色/图片] */
html::before {
<?php echo G::getBackground(); ?>
<?php echo G::getBackground(); ?>
<?php if ($this->options->repeatBackground): ?>
background-repeat: repeat;
-webkit-background-size: unset;
-o-background-size: unset;
background-size: unset;
background-position: top left;
<?php endif; ?>
}

<?php $this->options->customCSS(); ?>
Expand Down
68 changes: 1 addition & 67 deletions components/sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,73 +27,7 @@
</div>

<div id="widgets">
<?php
if($this->options->customWidgets != '')
{
$widgets = json_decode($this->options->customWidgets);
if (is_array($widgets))
{
foreach($widgets as $w)
{
if($w->type == "photo")
{
echo '
<div class="widget widget-photo '.($w->size == 'large' ? 'large' : '').'" style="background-image:url('.$w->url.')">
<div>
<p>'.$w->desc.'</p>
</div>
</div>
';
}
else if ($w->type == "cate")
{
echo '
<div class="widget category-list '.($w->size == 'large' ? 'large' : '').'">
<div class="category-content">
<li><a onclick="toggleSidebar()" href="'.$w->content[0]->url.'">'.$w->content[0]->name.'</a></li>
<li><a onclick="toggleSidebar()" href="'.$w->content[1]->url.'">'.$w->content[1]->name.'</a></li>
<li><a onclick="toggleSidebar()" href="'.$w->content[2]->url.'">'.$w->content[2]->name.'</a></li>
</div>
</div>
';
}
else if ($w->type == "video")
{
echo '
<div class="widget widget-photo '.($w->size == 'large' ? 'large' : '').'">
<video class="widget-video" loop muted autoplay src="'.$w->url.'"></video>
<div>
<p>'.$w->desc.'</p>
</div>
</div>
';
}
}
}
else
{
echo '<script>alert("widgets配置出错");</script>';
}
}
else
{ ?>
<div class="widget category-list" style="<?php if ($this->options->profilePhoto == ''): ?>width: 15rem;<?php endif; ?>">
<div class="category-content">
<?php $this->widget('Widget_Metas_Category_List')->parse('<li><a onclick="toggleSidebar()" href="{permalink}">{name}</a></li>'); ?>
</div>
</div>
<?php if ($this->options->profilePhoto != ''): ?>
<div class="widget widget-photo" style="background-image:url(<?php echo $this->options->profilePhoto; ?>)">
<?php if ($this->options->profileVideo != ''): ?>
<video class="widget-video" loop muted autoplay src="<?php echo $this->options->profileVideo; ?>" poster="<?php echo $this->options->profilePhoto; ?>"></video>
<?php endif; ?>
<div>
<p><?php echo $this->options->profilePhotoDes; ?></p>
</div>
</div>
<?php endif; ?>
<?php }
?>
<?php $this->need('/components/widgets.php'); ?>
</div>
</div>
<div id="sliderbar-cover" onclick="toggleSidebar()"></div>
143 changes: 143 additions & 0 deletions components/widgets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php
if($this->options->customWidgets != '')
{
$widgets = json_decode($this->options->customWidgets);
if (is_array($widgets))
{
foreach($widgets as $w)
{
switch ($w->type)
{
case 'photo':
echo '
<div class="widget widget-photo '.($w->size == 'large' ? 'large' : '').'" style="background-image:url('.$w->url.')">
<div>
<p>'.$w->desc.'</p>
</div>
</div>
';
break;
case 'video':
echo '
<div class="widget widget-photo '.($w->size == 'large' ? 'large' : '').'">
<video class="widget-video" loop muted autoplay src="'.$w->url.'"></video>
<div>
<p>'.$w->desc.'</p>
</div>
</div>
';
break;
case 'cate':
echo '
<div class="widget category-list '.($w->size == 'large' ? 'large' : '').'">
<div class="category-content">
<li><a onclick="toggleSidebar()" href="'.$w->content[0]->url.'">'.$w->content[0]->name.'</a></li>
<li><a onclick="toggleSidebar()" href="'.$w->content[1]->url.'">'.$w->content[1]->name.'</a></li>
<li><a onclick="toggleSidebar()" href="'.$w->content[2]->url.'">'.$w->content[2]->name.'</a></li>
</div>
</div>
';
break;
case 'hitokoto':
$c = '';
$cs = explode(',', $w->cate);
foreach($cs as $_)
$c = $c.'&c='.$_;

$hitokoto = json_decode(file_get_contents('https://v1.hitokoto.cn?encode=json'.$c));

echo '
<div class="widget widget-hitokoto">
<div>
<p>'. $hitokoto->hitokoto .'</p>
<span>'. $hitokoto->from_who .'</span>
</div>
</div>
';
break;
case 'like':
echo '
<div class="widget '.($w->size == 'large' ? 'large' : 'normal').'" id="DoYouLikeMe" onclick="DYLM(\''.$this->options->siteUrl.'\')">
<p>
❤ <span>'.G::DYLM('query').'</span>
</p>
</div>
';
break;
case 'comments':
echo '<div class="widget widget-recent-comment">';
$len = $w->len ?? 5;
$obj = $this->widget('Widget_Comments_Recent', 'ignoreAuthor=true');
if($obj->have()) {
while($obj->next() && $len) {
echo '
<div class="recent-comment-item">
<img class="avatar" src="https://sdn.geekzu.org/avatar/'.md5($obj->mail).'?s=60" alt="'.$obj->author.'" title="'.$obj->author.'">
<a href="'.G::getArticleInfo($obj->cid)["permalink"].'">
<div class="recent-comment-content">
<div class="meta">
<span>'.$obj->author.'</span>
<span>'.G::getSemanticDate($obj->created).'</span>
</div>
<p>'.G::analyzeMeme($obj->text).'</p>
<div class="meta">
<span></span>
<span>《'.G::getTitleByID($obj->cid).'》</span>
</div>
</div>
</a>
</div>
';

$len--;
}
}
else echo '无最新回复';

echo '</div>';
break;
case 'randomPost':
$data = G::randomArticle($w->len);
echo '<div class="widget widget-random-post">';
echo ' <h3>随机文章</h3>';
foreach($data as $item) {
echo '
<a href="'.$item["permalink"].'">
<div class="item">
<h4>'.$item["title"].'</h4><span>'.G::getSemanticDate($item['created']).'</span>
</div>
</a>
';
}

echo '</div>';
break;
default:
break;
}
}
}
else
{
echo '<script>alert("widgets配置出错");</script>';
}
}
else
{ ?>
<div class="widget category-list" style="<?php if ($this->options->profilePhoto == ''): ?>width: 15rem;<?php endif; ?>">
<div class="category-content">
<?php $this->widget('Widget_Metas_Category_List')->parse('<li><a onclick="toggleSidebar()" href="{permalink}">{name}</a></li>'); ?>
</div>
</div>
<?php if ($this->options->profilePhoto != ''): ?>
<div class="widget widget-photo" style="background-image:url(<?php echo $this->options->profilePhoto; ?>)">
<?php if ($this->options->profileVideo != ''): ?>
<video class="widget-video" loop muted autoplay src="<?php echo $this->options->profileVideo; ?>" poster="<?php echo $this->options->profilePhoto; ?>"></video>
<?php endif; ?>
<div>
<p><?php echo $this->options->profilePhotoDes; ?></p>
</div>
</div>
<?php endif; ?>
<?php }
?>
6 changes: 6 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ function themeConfig($form)
$background = new Typecho_Widget_Helper_Form_Element_Text('background', null, null, _t('背景图片'), _t('可填颜色代码或者图片url'));
$form->addInput($background);

$repeatBackground = new Typecho_Widget_Helper_Form_Element_Radio('repeatBackground', array(
'1' => _t('开启'),
'0' => _t('关闭')
), '0', _t('重复元素背景图片'), _t('默认关闭'));
$form->addInput($repeatBackground);

$themeColor = new Typecho_Widget_Helper_Form_Element_Text('themeColor', null, '#07F', _t('主题色'), _t('一般在链接、按钮的颜色中体现'));
$form->addInput($themeColor);

Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package G
* @author 季悠然
* @version 3.3.2
* @version 3.3.3
* @link https://季悠然.space
*/

Expand Down
82 changes: 78 additions & 4 deletions libs/G.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class G
*
* @var string
*/
public static $version = "3.3.2";
public static $version = "3.3.3";

/**
* 主题配置
Expand Down Expand Up @@ -71,11 +71,15 @@ public static function init()
public static function getBackground()
{
$background = "background";
$regex = '@(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))@';
if (self::$config['background'] == '')
return $background . ": #fff;";

$regex = '@(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))@';
if (preg_match($regex, self::$config['background']) == 0)
else if (self::$config['background'] == 'bing')
{
$bingP = json_decode(file_get_contents('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1'));
return $background . "-image: url(https://cn.bing.com" . $bingP->{'images'}[0]->{'url'} . ");";
}
else if (preg_match($regex, self::$config['background']) == 0)
return ($background . ": " . self::$config['background'] . ";");
return $background . "-image: url(" . self::$config['background'] . ");";
}
Expand Down Expand Up @@ -515,4 +519,74 @@ public static function getTitleByID($id)
return '标题获取失败';
}
}

/**
* 点赞小组件
*
* @param string $action
* @return string
*/
public static function DYLM($action)
{
$db = Typecho_Db::get();
$data = $db->fetchRow($db->select()->from('table.options')->where('name = ?', 'G:likes'));

if($data == NULL) {
$insert = $db->insert('table.options')->rows(['name'=> 'G:likes', "user"=> '0', "value" => "0"]);
$db->query($insert);
$data = $db->fetchRow($db->select()->from('table.options')->where('name = ?', 'G:likes'));
}

if($action == 'query')
{
return (int)$data['value'];
}
else if ($action == 'add')
{
$update = $db->update('table.options')->rows(["value"=> ((int)$data['value']) + 1])->where('name = ?', 'G:likes');
return $db->query($update) == 1 ? 'success' : 'error';
}

return 'error param';
}

/**
* 随机文章
*
* @param integer $limit
* @return array
*/
public static function randomArticle($limit = 5)
{
$db = Typecho_Db::get();
$sql = $db->select()->from('table.contents')
->where('status = ?','publish')
->where('type = ?', 'post')
->where('created <= unix_timestamp(now())', 'post')
->limit($limit)
->order('RAND()');

$result = $db->fetchAll($sql);
for($i = 0; $i < $limit; $i++)
$result[$i] = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($result[$i]);

return $result;
}

/**
* 通过cid获取文章信息
*
* @param string|integer $cid
* @return array
*/
public static function getArticleInfo($cid)
{
$db = Typecho_Db::get();
$select = $db->select()->from('table.contents')
->where('status = ?', 'publish')
->where('type = ?', 'post')
->where('cid = ?', $cid);

return Typecho_Widget::widget('Widget_Abstract_Contents')->filter($db->fetchRow($select));
}
}
2 changes: 1 addition & 1 deletion static/css/G.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/css/G.css.map

Large diffs are not rendered by default.

Loading

0 comments on commit 573874a

Please sign in to comment.