From 062f672026391a4689d9e041ccbab48bcbd36135 Mon Sep 17 00:00:00 2001 From: flashwave Date: Fri, 18 Sep 2015 23:56:54 +0200 Subject: [PATCH] r20150918 Signed-off-by: Flashwave --- _sakura/changelog.json | 16 ++ _sakura/components/Comments.php | 66 +++++++- _sakura/components/News.php | 6 +- _sakura/components/Session.php | 2 +- _sakura/components/Urls.php | 18 +++ _sakura/sakura.php | 2 +- _sakura/templates/yuuno/elements/comment.tpl | 28 ++++ _sakura/templates/yuuno/elements/comments.tpl | 144 ++---------------- _sakura/templates/yuuno/elements/newsPost.tpl | 2 +- _sakura/templates/yuuno/main/news.tpl | 6 +- _sakura/templates/yuuno/profile/index.tpl | 2 +- public/.htaccess | 1 + public/content/data/yuuno/css/yuuno.css | 66 +++++--- public/settings.php | 56 +++++++ 14 files changed, 254 insertions(+), 161 deletions(-) create mode 100644 _sakura/templates/yuuno/elements/comment.tpl diff --git a/_sakura/changelog.json b/_sakura/changelog.json index 2c67551..614f3e8 100644 --- a/_sakura/changelog.json +++ b/_sakura/changelog.json @@ -2820,6 +2820,22 @@ "user": "Flashwave" } + ], + + "20150918": [ + + "eminence", + { + "type": "UPD", + "change": "Changed report flag to an exclamation thing.", + "user": "Flashwave" + }, + { + "type": "UPD", + "change": "Added more comments stuff.", + "user": "Flashwave" + } + ] } diff --git a/_sakura/components/Comments.php b/_sakura/components/Comments.php index cef71ea..dfd4fd2 100644 --- a/_sakura/components/Comments.php +++ b/_sakura/components/Comments.php @@ -7,9 +7,71 @@ namespace Sakura; class Comments { + public $comments = []; // Array containing comments + private $commenters = []; // Array containing User objects + public $category; // Comment category + public $count = 0; // Amount of comments + // Constructor - public function ___construct() + public function __construct($category) { - // + // Set category + $this->category = $category; + + // Get the comments and assign them to $comments + $comments = Database::fetch( + 'comments', + true, + [ + 'comment_category' => [$this->category, '='], + 'comment_reply_to' => ['0', '='], + ], + ['comment_id', true] + ); + + // Feed them into the sorter + $this->comments = $this->sortComments($comments); + + } + + // Sorting + public function sortComments($comments) + { + + // Create storage array + $layer = []; + + // Sort comments + foreach ($comments as $comment) { + // Check if we already have an object for this user + if (!array_key_exists($comment['comment_poster'], $this->commenters)) { + // Create new object + $this->commenters[$comment['comment_poster']] = new User($comment['comment_poster']); + } + + // Attach the poster + $comment['comment_poster'] = $this->commenters[$comment['comment_poster']]; + + // Add post to posts array + $layer[$comment['comment_id']] = $comment; + + // Up the comment count + $this->count += 1; + + // Attempt to get replies from the database + $replies = Database::fetch('comments', true, [ + 'comment_category' => [$this->category, '='], + 'comment_reply_to' => [$comment['comment_id'], '='], + ]); + + // Check if this was a reply to something + if ($replies) { + // Save the replies + $layer[$comment['comment_id']]['comment_replies'] = $this->sortComments($replies); + } + } + + return $layer; + } } diff --git a/_sakura/components/News.php b/_sakura/components/News.php index 89d68c1..08f6429 100644 --- a/_sakura/components/News.php +++ b/_sakura/components/News.php @@ -11,7 +11,7 @@ class News private $posters = []; // Posters array (so we don't create a new user object every time) // Initialise the news object - public function __construct($category, $comments = true) + public function __construct($category) { // Get the news posts and assign them to $posts @@ -31,9 +31,13 @@ class News // Attach the poster $post['poster'] = $this->posters[$post['uid']]; + // Load comments + $post['comments'] = $this->comments = new Comments('news-' . $category . '-' . $post['id']); + // Add post to posts array $this->posts[$post['id']] = $post; } + } // Get the amount of posts diff --git a/_sakura/components/Session.php b/_sakura/components/Session.php index 7045745..1acecc0 100644 --- a/_sakura/components/Session.php +++ b/_sakura/components/Session.php @@ -12,7 +12,7 @@ class Session public $sessionId; // Initialise new session - public function ___construct() + public function __construct() { // Check if a PHP session was already started and if not start one diff --git a/_sakura/components/Urls.php b/_sakura/components/Urls.php index a23ac91..19da643 100644 --- a/_sakura/components/Urls.php +++ b/_sakura/components/Urls.php @@ -230,6 +230,24 @@ class Urls '/manage/%s/%s', ], + // Comments urls + 'COMMENT_POST' => [ + '/settings.php?comment-action=true', + '/comments', + ], + 'COMMENT_LIKE' => [ + '/settings.php?comment-action=true&id=%u&mode=like&session=%s', + '/comments?id=%u&mode=like&session=%s', + ], + 'COMMENT_DISLIKE' => [ + '/settings.php?comment-action=true&id=%u&mode=dislike&session=%s', + '/comments?id=%u&mode=dislike&session=%s', + ], + 'COMMENT_DELETE' => [ + '/settings.php?comment-action=true&id=%u&mode=delete&session=%s', + '/comments?id=%u&mode=delete&session=%s', + ], + ]; // Get a formatted url diff --git a/_sakura/sakura.php b/_sakura/sakura.php index f090d2d..c6443a7 100644 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20150916'); +define('SAKURA_VERSION', '20150918'); define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_COLOUR', '#6C3082'); define('SAKURA_STABLE', false); diff --git a/_sakura/templates/yuuno/elements/comment.tpl b/_sakura/templates/yuuno/elements/comment.tpl new file mode 100644 index 0000000..bd97cc8 --- /dev/null +++ b/_sakura/templates/yuuno/elements/comment.tpl @@ -0,0 +1,28 @@ +
  • + + {% if comment.comment_replies %} +
      + {% for comment in comment.comment_replies %} + {% include 'elements/comment.tpl' %} + {% endfor %} +
    + {% endif %} +
  • diff --git a/_sakura/templates/yuuno/elements/comments.tpl b/_sakura/templates/yuuno/elements/comments.tpl index da0c10d..6ccd6fe 100644 --- a/_sakura/templates/yuuno/elements/comments.tpl +++ b/_sakura/templates/yuuno/elements/comments.tpl @@ -1,10 +1,10 @@ -
    +
    {% if session.checkLogin %} -
    - - - + + + +
    @@ -18,133 +18,13 @@
      -
    • -
      -
      -
      -
      -
      -
        -
      • Report
      • -
      • Delete
      • -
      • Reply
      • -
      • 1
      • -
      • 1
      • -
      -
      -
      -
      - aaaaaaaaaa -
      -
      -
      -
        -
      • -
        -
        -
        -
        -
        -
          -
        • Report
        • -
        • Delete
        • -
        • Reply
        • -
        • 1
        • -
        • 1
        • -
        -
        -
        - aaaaaaaaaa -
        -
        -
        -
          -
        • -
          -
          -
          -
          -
          -
            -
          • Report
          • -
          • Delete
          • -
          • Reply
          • -
          • 1
          • -
          • 1
          • -
          -
          -
          - aaaaaaaaaa -
          -
          -
          -
            -
          • -
            -
            -
            -
            -
            -
              -
            • Report
            • -
            • Delete
            • -
            • Reply
            • -
            • 1
            • -
            • 1
            • -
            -
            -
            - aaaaaaaaaa -
            -
            -
            -
          • -
          -
        • -
        • -
          -
          -
          -
          -
          -
            -
          • Report
          • -
          • Delete
          • -
          • Reply
          • -
          • 1
          • -
          • 1
          • -
          -
          -
          - aaaaaaaaaa -
          -
          -
          -
        • -
        -
      • -
      • -
        -
        -
        -
        -
        -
          -
        • Report
        • -
        • Delete
        • -
        • Reply
        • -
        • 1
        • -
        • 1
        • -
        -
        -
        - aaaaaaaaaa -
        -
        -
        -
      • -
      -
    • + {% if post.comments.comments %} + {% for comment in post.comments.comments %} + {% include 'elements/comment.tpl' %} + {% endfor %} + {% else %} +

      There are no comments yet!

      + {% endif %}
    diff --git a/_sakura/templates/yuuno/elements/newsPost.tpl b/_sakura/templates/yuuno/elements/newsPost.tpl index 2974985..4404b05 100644 --- a/_sakura/templates/yuuno/elements/newsPost.tpl +++ b/_sakura/templates/yuuno/elements/newsPost.tpl @@ -12,5 +12,5 @@
    - Posted on {{ post.date|date(sakura.dateFormat) }}{% if not (viewPost and postExists) %} X comments{% endif %} + Posted on {{ post.date|date(sakura.dateFormat) }}{% if not (viewPost and postExists) %} {{ post.comments.count }} comment{% if post.comments.count != 1 %}s{% endif %}{% endif %}
    diff --git a/_sakura/templates/yuuno/main/news.tpl b/_sakura/templates/yuuno/main/news.tpl index b65587c..14ac0cc 100644 --- a/_sakura/templates/yuuno/main/news.tpl +++ b/_sakura/templates/yuuno/main/news.tpl @@ -25,6 +25,9 @@ {% if (viewPost ? postExists : newsPosts|length) %} {% for post in newsPosts %} {% include 'elements/newsPost.tpl' %} + {% if viewPost and postExists %} + {% include 'elements/comments.tpl' %} + {% endif %} {% endfor %} {% if not (viewPost and postExists) and news.getPosts(postsPerPage)|length > 1 %}
    @@ -32,9 +35,6 @@
    {% endif %} - {% if viewPost and postExists %} - {% include 'elements/comments.tpl' %} - {% endif %} {% else %}

    The requested news post does not exist!

    diff --git a/_sakura/templates/yuuno/profile/index.tpl b/_sakura/templates/yuuno/profile/index.tpl index 013adc3..980a8d1 100644 --- a/_sakura/templates/yuuno/profile/index.tpl +++ b/_sakura/templates/yuuno/profile/index.tpl @@ -32,7 +32,7 @@ {% else %} {% if profile.checkFriends(user.data.id) != 0 %}{% endif %} - + {% endif %}
    {% endif %} diff --git a/public/.htaccess b/public/.htaccess index 4560faa..b3856af 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -42,6 +42,7 @@ RewriteRule ^settings/([a-z]+)/([a-z]+)/?$ settings.php?cat=$1&mode=$2 [L,QSA] RewriteRule ^settings/([a-z]+)/([a-z]+)/p([0-9]+)/?$ settings.php?cat=$1&mode=$2&page=$3 [L,QSA] RewriteRule ^friends/?$ settings.php?friend-action=true [L,QSA] RewriteRule ^notifications/?$ settings.php?request-notifications=true [L,QSA] +RewriteRule ^comments/?$ settings.php?comment-action=true [L,QSA] # Members RewriteRule ^members/?$ members.php [L,QSA] diff --git a/public/content/data/yuuno/css/yuuno.css b/public/content/data/yuuno/css/yuuno.css index c72ac07..1b2cee4 100644 --- a/public/content/data/yuuno/css/yuuno.css +++ b/public/content/data/yuuno/css/yuuno.css @@ -2098,21 +2098,18 @@ textarea.inputStyling { /* * Comments */ -.comments { -} - -.comments .comment-input-section { +#comments .comment-input-section { border-top: 1px solid #9475B2; border-bottom: 1px solid #9475B2; } -.comments .comment { +#comments .comment { display: flex; align-items: stretch; margin: 3px 0; } -.comments .comment > .comment-avatar { +#comments .comment > .comment-avatar { height: 60px; width: 60px; background: rgba(0, 0, 0, .2) url("/content/pixel.png") no-repeat scroll left center / contain; @@ -2120,9 +2117,26 @@ textarea.inputStyling { margin-right: 2px; border-radius: 4px; border: 0; + display: block; + text-align: center; + word-wrap: break-word; + transition: .2s; } -.comments .comment > .comment-pointer { +#comments .comment > .comment-avatar:hover { + background-color: transparent; +} + +#comments .comment > .comment-avatar > span { + opacity: 0; + transition: .2s; +} + +#comments .comment > .comment-avatar:hover > span { + opacity: 1; +} + +#comments .comment > .comment-pointer { width: 0px; height: 0px; border-style: solid; @@ -2131,7 +2145,7 @@ textarea.inputStyling { margin-top: 10px; } -.comments .comment > .comment-content { +#comments .comment > .comment-content { border-radius: 5px; border: 0; min-height: 50px; @@ -2142,23 +2156,35 @@ textarea.inputStyling { background: #F6F6F6; } -.comments .comment > .comment-content > .comment-controls { +#comments .comment > .comment-content > .comment-controls { float: right; } -.comments .comment > .comment-content > .comment-controls > ul > li { +#comments .comment > .comment-content > .comment-controls > ul > li { float: left; margin: 0 5px; opacity: 0; transition: .5s; } -.comments .comment > .comment-content:hover > .comment-controls > ul > li, -.comments .comment > .comment-content > .comment-controls > ul > li.shown { +#comments .comment > .comment-content:hover > .comment-controls > ul > li, +#comments .comment > .comment-content > .comment-controls > ul > li.shown { opacity: 1; } -.comments .comment > .comment-submit { +#comments .comment > .comment-content > .comment-controls > ul > li.voting { + font-size: 1.5em; +} + +#comments .comment > .comment-content > .comment-controls > ul > li.like { + color: #0A0; +} + +#comments .comment > .comment-content > .comment-controls > ul > li.dislike { + color: #C00; +} + +#comments .comment > .comment-submit { flex-shrink: 0; font-family: FontAwesome; height: 60px; @@ -2172,28 +2198,30 @@ textarea.inputStyling { cursor: pointer; } -.comments .comment > .comment-submit:hover { +#comments .comment > .comment-submit:hover { background: linear-gradient(0deg, #9475B2 30%, #C2AFFE 70%); } -.comments .comment > .comment-submit:active { +#comments .comment > .comment-submit:active { background: linear-gradient(180deg, #9475B2 30%, #C2AFFE 70%); } -.comments ul { +#comments ul { list-style: none; } -.comments ul > li > ul { +#comments ul > li > ul { margin-left: 40px; } -.comments ul > li > ul .comment > .comment-avatar { +#comments ul > li > ul .comment > .comment-avatar { height: 50px; width: 50px; + font-size: .9em; + line-height: 1.1em; } -.comments ul > li > ul .comment > .comment-content { +#comments ul > li > ul .comment > .comment-content { min-height: 40px; height: 40px; } diff --git a/public/settings.php b/public/settings.php index 9b4cb72..3e70690 100644 --- a/public/settings.php +++ b/public/settings.php @@ -47,6 +47,62 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification // Set header, convert the array to json, print it and exit print json_encode($notifications); exit; +} elseif (isset($_REQUEST['comment-action']) && $_REQUEST['comment-action'] && Users::checkLogin()) { + // Referrer + $redirect = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('SITE_INDEX')); + + // Continue + $continue = true; + + // Match session ids for the same reason + if (!isset($_REQUEST['session']) || $_REQUEST['session'] != session_id()) { + $renderData['page'] = [ + + 'redirect' => $redirect, + 'message' => 'Invalid session, please try again.', + 'success' => 0, + + ]; + + // Prevent + $continue = false; + } + + // Select the right action + if ($continue) { + switch (isset($_REQUEST['mode']) ? $_REQUEST['mode'] : false) { + case 'like': + + break; + + case 'dislike': + + break; + + case 'delete': + + break; + + default: + $renderData['page'] = [ + + 'redirect' => $redirect, + 'message' => 'Did nothing.', + 'success' => 0, + + ]; + } + } + + // Print page contents or if the AJAX request is set only display the render data + print isset($_REQUEST['ajax']) ? + ( + $renderData['page']['message'] . '|' . + $renderData['page']['success'] . '|' . + $renderData['page']['redirect'] + ) : + Templates::render('global/information.tpl', $renderData); + exit; } elseif (isset($_REQUEST['friend-action']) && $_REQUEST['friend-action'] && Users::checkLogin()) { // Friends // Continue