ADD: class DetectMobile

+ коррекция Ночного режима.
This commit is contained in:
Evg 2023-11-21 03:56:49 +03:00
parent a179dde10b
commit 0d4075ada9
12 changed files with 98 additions and 13 deletions

View File

@ -4,6 +4,7 @@ namespace App\Controllers\Comment;
use Hleb\Constructor\Handlers\Request;
use App\Controllers\Controller;
use App\Services\DetectMobile;
use App\Services\Сheck\{PostPresence, CommentPresence};
use App\Models\{NotificationModel, ActionModel, CommentModel, PostModel};
use App\Validate\Validator;
@ -39,7 +40,7 @@ class AddCommentController extends Controller
$this->union($post, $url_post, $content);
$last_id = CommentModel::add($post['post_id'], $comment_id, $content, $trigger);
$last_id = CommentModel::add($post['post_id'], $comment_id, $content, $trigger, DetectMobile::index());
// Add an audit entry and an alert to the admin
// Аудит и оповещение персоналу

View File

@ -13,7 +13,7 @@ class CommentModel extends \Hleb\Scheme\App\Models\MainModel
// Add an comment
// Добавим ответ
public static function add($post_id, $comment_id, $content, $trigger)
public static function add($post_id, $comment_id, $content, $trigger, $mobile)
{
$params = [
'comment_post_id' => $post_id,
@ -22,6 +22,7 @@ class CommentModel extends \Hleb\Scheme\App\Models\MainModel
'comment_published' => ($trigger === false) ? 0 : 1,
'comment_ip' => Request::getRemoteAddress(),
'comment_user_id' => UserData::getUserId(),
'comment_is_mobile' => ($mobile === false) ? 0 : 1,
];
$sql = "INSERT INTO comments(comment_post_id,
@ -29,13 +30,15 @@ class CommentModel extends \Hleb\Scheme\App\Models\MainModel
comment_content,
comment_published,
comment_ip,
comment_user_id)
comment_user_id,
comment_is_mobile)
VALUES(:comment_post_id,
:comment_parent_id,
:comment_content,
:comment_published,
:comment_ip,
:comment_user_id)";
:comment_user_id,
:comment_is_mobile)";
DB::run($sql, $params);
@ -185,6 +188,7 @@ class CommentModel extends \Hleb\Scheme\App\Models\MainModel
comment_ip,
comment_votes,
comment_lo,
comment_is_mobile,
comment_is_deleted,
votes_comment_item_id,
votes_comment_user_id,

View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace App\Services;
class DetectMobile
{
public static function index()
{
$info = parse_user_agent();
$allowed = ['Android', 'iPhone', 'iPad', 'Windows Phone OS', 'Kindle', 'Kindle Fire', 'BlackBerry', 'Playbook'];
if (in_array($info['platform'], $allowed)) {
return true;
}
return false;
}
}

View File

@ -1632,3 +1632,5 @@ ALTER TABLE `posts` CHANGE `post_answers_count` `post_comments_count` INT(11) NU
UPDATE `audits` SET `action_type` = 'comment' WHERE `action_type` = 'answer';
UPDATE `favorites` SET `action_type` = 'comment' WHERE `action_type` = 'answer';
ALTER TABLE `comments` ADD `comment_is_mobile` TINYINT(1) NOT NULL DEFAULT '0' AFTER `comment_lo`;

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,4 @@
let scrolled;let dHeader=document.querySelector(".d-header");if(dHeader){window.onscroll=function(){scrolled=window.pageYOffset||document.documentElement.scrollTop;if(scrolled>70){document.querySelector(".d-header").classList.add('show')}
if(70>scrolled){document.querySelector(".d-header").classList.remove('show')}}}
let scrolled;let dHeader=document.querySelector(".d-header");if(dHeader){window.onscroll=function(){scrolled=window.pageYOffset||document.documentElement.scrollTop;if(scrolled>70){document.querySelector(".d-header").classList.add('show')}else{document.querySelector(".d-header").classList.remove('show')}}}
let token=document.querySelector("meta[name='csrf-token']").getAttribute("content");queryAll(".add-comment").forEach(el=>el.addEventListener("click",function(e){let comment_id=insert_id=el.dataset.comment_id;let post_id=el.dataset.post_id;if(post_id){insert_id=el.dataset.post_id}
let comment=document.querySelector('#insert_id_'+insert_id);comment.classList.add("block");fetch("/comment/addform",{method:"POST",body:"post_id="+post_id+"&comment_id="+comment_id+"&_token="+token,headers:{'Content-Type':'application/x-www-form-urlencoded'}}).then(response=>{return response.text()}).then(text=>{comment.innerHTML=text;queryAll("#cancel_comment").forEach(el=>el.addEventListener("click",function(e){comment.classList.remove("block")}))})}));isIdEmpty('toggledark').onclick=function(){let mode=getCookie("dayNight");let expires=defTime();if(mode=="dark"){document.cookie="dayNight"+"="+"light"+"; "+expires+";path=/";document.getElementsByTagName('body')[0].classList.remove('dark')}else{document.cookie="dayNight"+"="+"dark"+"; "+expires+";path=/";document.getElementsByTagName('body')[0].classList.add('dark')}}
isIdEmpty('togglemenu').onclick=function(){let mode=getCookie("menuYesNo");let expires=defTime();if(mode=="menuno"){document.cookie="menuYesNo"+"="+"menuyes"+"; "+expires+";path=/";document.getElementsByTagName('body')[0].classList.remove('menuno')}else{document.cookie="menuYesNo"+"="+"menuno"+"; "+expires+";path=/";document.getElementsByTagName('body')[0].classList.add('menuno')}}

View File

@ -88,7 +88,7 @@
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path>
</symbol>
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="comments">
<path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"></path>
<path d="M12 21a9 9 0 1 0-9-9c0 1.488.36 2.89 1 4.127L3 21l4.873-1c1.236.639 2.64 1 4.127 1Z"></path>
</symbol>
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="book">
<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"></path><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"></path>
@ -187,6 +187,9 @@
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="cut">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/><circle cx="7" cy="17" r="3" /><circle cx="17" cy="17" r="3" /><line x1="9.15" y1="14.85" x2="18" y2="4" /><line x1="6" y1="4" x2="14.85" y2="14.85" />
</symbol>
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="mobile">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 5a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v14a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2v-14z" /><path d="M11 4h2" /><path d="M12 17v.01" />
</symbol>
<symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" id="lock">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/><rect x="5" y="11" width="14" height="10" rx="2" /><circle cx="12" cy="16" r="1" /><path d="M8 11v-4a4 4 0 0 1 8 0v4" />
</symbol>

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -13,7 +13,6 @@
function internalRender($nodes, $post, $level = 0)
{
foreach ($nodes as $node) :
$level = $level > 5 ? 5 : $level;
?>
@ -23,7 +22,6 @@
<?php if ($node['comment_published'] == 0 && $node['comment_user_id'] != UserData::getUserId() && !UserData::checkAdmin()) continue; ?>
<ol class="comment-telo">
<li class="relative">
<a class="anchor-top" id="comment_<?= $node['comment_id']; ?>"></a>
@ -39,6 +37,11 @@
<?= $node['login']; ?>
</span>
</a>
<?php if ($node['comment_is_mobile']) : ?>
<svg class="icons icon-small green">
<use xlink:href="/assets/svg/icons.svg#mobile"></use>
</svg>
<?php endif; ?>
<?php if ($post['post_user_id'] == $node['comment_user_id']) : ?>
<svg class="icons icon-small sky">
<use xlink:href="/assets/svg/icons.svg#mic"></use>
@ -48,7 +51,7 @@
<?= Html::langDate($node['comment_date']); ?>
</span>
<?php if (strtotime($node['comment_modified']) < strtotime($node['comment_date'])) : ?>
<span class="gray-600">
<span class="gray-600 mb-none">
(<?= __('app.ed'); ?>.)
</span>
<?php endif; ?>

View File

@ -266,7 +266,7 @@ $blog = $data['blog'][0] ?? null;
</aside>
<script nonce="<?= $_SERVER['nonce']; ?>">
document.addEventListener('DOMContentLoaded', () => {
mediumZoom(document.querySelectorAll('.content_tree img:not(.emoji), .post img:not(.emoji), .content-body p img:not(.emoji)'));
mediumZoom(document.querySelectorAll('.post img:not(.emoji), .content-body .ind-first-p img:not(.emoji)'));
// Добавим цитирование
function get_text() {

View File

@ -318,6 +318,11 @@ a:hover > img { opacity: 0.8; }
margin: 5px;
}
.content-body img.medium-zoom-image {
max-width: 350px;
border: 1px solid #666;
}
.anchor-top:target ~ .content_tree {
background-clip: content-box;
background-color: lightyellow;

View File

@ -76,6 +76,46 @@ main {
background-color: #fff;
padding-left: 10px;
}
.comment-level-1 {
width: 12px;
}
.comment-level-2 {
width: 32px;
}
.comment-level-3 {
width: 52px;
}
.comment-level-4 {
width: 72px;
}
.comment-level-5 {
width: 92px;
}
.comment-level-left-1 {
margin-left: 16px;
}
.comment-level-left-2 {
margin-left: 36px;
}
.comment-level-left-3 {
margin-left: 56px;
}
.comment-level-left-4 {
margin-left: 76px;
}
.comment-level-left-5 {
margin-left: 96px;
}
}
@media (max-width: 780px) {
@ -106,7 +146,11 @@ main {
.mb-text-xl {
font-size: 1.25rem;
}
.text-2xl {
font-size: 1.1rem;
}
.logo {
font-size: 18px;
}

View File

@ -101,4 +101,8 @@ body.dark :not(pre)>code[class*=language-], pre[class*=language-] {
body.dark code[class*=language-], pre[class*=language-] {
color: #eee;
text-shadow: none;
}
body.dark .anchor-top:target~.content_tree {
background-color: #2f3b4a;
}