Database refactoring and improving blog comments, blog post history and more
This commit is contained in:
@@ -16,101 +16,215 @@
|
||||
$this->load->model('UserModel', '', TRUE);
|
||||
}
|
||||
|
||||
function transfer() {
|
||||
$data = $this->db->query('SELECT * FROM kingofdog.blog_posts')->result_array();
|
||||
foreach ($data as $item) {
|
||||
extract($item);
|
||||
// $this->db->query('INSERT INTO kingofdog_new.blog_post_versions (postID, lang, active, title, description, content, contentWordsCount, authorID, changes, edited) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
|
||||
// $postID, $language, $isActive, "", "", $content, $wordCount, $contentAuthorID, $versionMessage, $contentDate
|
||||
// ]);
|
||||
// $this->db->query('UPDATE kingofdog_new.blog_post_versions SET title = ?, description = ? WHERE postID = ? AND lang = ?', [
|
||||
// $postTitle, $postDesc, $postID, $language
|
||||
// ]);
|
||||
// $this->db->query('UPDATE kingofdog_new.blog_post_versions SET url = ? WHERE postID = ?', [$postUrl, $postID]);
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostIDByUrl($url) {
|
||||
$data = $this->db->query('SELECT postID FROM blog_post_versions WHERE url = ? AND lang = ? AND active ORDER BY edited DESC LIMIT 1', [$url, $_SESSION['site_lang']])->result_array();
|
||||
return !empty($data) ? $data[0]['postID'] : NULL;
|
||||
}
|
||||
|
||||
function getAllPosts($search, $amount, $offset = 0)
|
||||
{
|
||||
$offset *= $amount;
|
||||
if ($search !== '') {
|
||||
$search = strtolower($search);
|
||||
$posts = $this->db->query('
|
||||
SELECT
|
||||
p.*,
|
||||
ca.name categoryName,
|
||||
ca.display_name categoryDisplayName,
|
||||
(SELECT count(*)
|
||||
FROM blog_comments
|
||||
WHERE post_id = p.postID) commentCount,
|
||||
(SELECT count(*)
|
||||
FROM blog_post_likes
|
||||
WHERE post_id = p.postID) likeCount,
|
||||
(SELECT wordCount FROM blog_content c WHERE c.postID = p.postID AND isActive = TRUE AND c.language = ? ORDER BY c.contentDate DESC LIMIT 1) wordCount
|
||||
FROM blog_posts p, blog_categories ca
|
||||
WHERE ca.id = p.postCategoryID
|
||||
AND (CONCAT((SELECT t.postTitle FROM blog_translations t WHERE t.postID = p.postID AND language = ?), postUrl, (SELECT t.postDesc FROM blog_translations t WHERE t.postID = p.postID AND language = ?)) RLIKE ?
|
||||
OR (SELECT content
|
||||
FROM blog_content
|
||||
WHERE blog_content.postID = p.postID AND isActive = TRUE
|
||||
LIMIT 1) RLIKE ?)
|
||||
AND postState = 1
|
||||
ORDER BY postPublishDate DESC
|
||||
LIMIT ? OFFSET ?', [$_SESSION['site_lang'], $_SESSION['site_lang'], $_SESSION['site_lang'], $search, $search, $amount, $offset])->result_array();
|
||||
SELECT
|
||||
p.*
|
||||
FROM blog_post p
|
||||
WHERE ((SELECT LOWER(title) RLIKE ? OR LOWER(description) RLIKE ? OR LOWER(content) RLIKE ? FROM blog_post_versions WHERE postID = p.ID AND lang = ?)
|
||||
OR (SELECT LOWER(displayname) RLIKE ? FROM blog_categories c WHERE c.lang = ? AND c.categoryID IN (SELECT categoryID FROM blog_post_categories pc WHERE pc.postID = p.ID)))
|
||||
AND state = 1
|
||||
ORDER BY initialRelease DESC
|
||||
LIMIT ? OFFSET ?', [$search, $search, $search, $_SESSION['site_lang'], $search, $_SESSION['site_lang'], $amount, $offset])->result_array();
|
||||
} else {
|
||||
$posts = $this->db->query('
|
||||
SELECT p.*,
|
||||
ca.name categoryName,
|
||||
ca.display_name categoryDisplayName,
|
||||
(SELECT count(*) FROM blog_comments WHERE post_id = p.postID) commentCount,
|
||||
(SELECT count(*) FROM blog_post_likes WHERE post_id = p.postID) likeCount,
|
||||
(SELECT wordCount FROM blog_content c WHERE c.postID = p.postID AND isActive = TRUE AND c.language = ? ORDER BY c.contentDate DESC LIMIT 1) wordCount
|
||||
FROM blog_posts p, blog_categories ca
|
||||
WHERE ca.id = p.postCategoryID
|
||||
AND postState = 1
|
||||
ORDER BY postPublishDate DESC
|
||||
LIMIT ? OFFSET ?', [$_SESSION['site_lang'], $amount, $offset])->result_array();
|
||||
SELECT *
|
||||
FROM blog_post
|
||||
WHERE state = 1
|
||||
ORDER BY initialRelease DESC
|
||||
LIMIT ? OFFSET ?', [$amount, $offset])->result_array();
|
||||
}
|
||||
$posts = $this->mergePostTitleDesc($posts);
|
||||
$posts = $this->mergePostTranslation($posts);
|
||||
$posts = $this->mergePostCategories($posts);
|
||||
$posts = $this->mergePostStats($posts);
|
||||
$posts = $this->mergePostAuthorData($posts);
|
||||
return $posts;
|
||||
}
|
||||
|
||||
public function mergePostTranslation($posts, $content = FALSE, $language = NULL, $indexID = 'ID')
|
||||
{
|
||||
$language = ($language == NULL ? $_SESSION['site_lang'] : $language);
|
||||
foreach ($posts as $i => $post) {
|
||||
$translationData = $this->getPostTranslation($post[$indexID], $content, $language);
|
||||
if(isset($translationData['error']) && $translationData['error']) {
|
||||
unset($posts[$i]);
|
||||
continue;
|
||||
}
|
||||
$posts[$i] += $translationData;
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
private function mergePostCategories($posts, $language = NULL)
|
||||
{
|
||||
$language = $language == NULL ? $_SESSION['site_lang'] : $language;
|
||||
foreach ($posts as $i => $post) {
|
||||
$categories = $this->getPostCategories($post['ID'], $language);
|
||||
$posts[$i]['categories'] = $categories;
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
private function getPostCategories($postID, $language)
|
||||
{
|
||||
$data = $this->db->query('SELECT ID, name, displayname FROM blog_categories WHERE categoryID IN (SELECT categoryID FROM blog_post_categories WHERE postID = ?) AND lang = ?', [$postID, $language])->result_array();
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function mergePostStats($posts, $language = NULL)
|
||||
{
|
||||
$language = $language == NULL ? $_SESSION['site_lang'] : $language;
|
||||
foreach ($posts as $i => $post) {
|
||||
$stats = $this->getPostStats($post['ID'], $language);
|
||||
$posts[$i] += $stats;
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
private function mergePostState($posts) {
|
||||
$states = [
|
||||
1 => "Veröffentlicht",
|
||||
2 => "Entwurf",
|
||||
3 => "Geplant",
|
||||
4 => "Im Papierkorb",
|
||||
];
|
||||
foreach ($posts as $i => $post) {
|
||||
$posts[$i]['stateName'] = $states[$post['state']];
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
private function getPostStats($postID, $language)
|
||||
{
|
||||
$comments = $this->db->query('SELECT COUNT(*) count FROM blog_post_comments WHERE postID = ?', [$postID])->result_array()[0]['count'];
|
||||
$likes = $this->db->query('SELECT COUNT(*) count FROM blog_post_likes WHERE postID = ?', [$postID])->result_array()[0]['count'];
|
||||
$words = $this->db->query('SELECT contentWordsCount count FROM blog_post_versions WHERE postID = ? AND active AND lang = ?', [$postID, $language])->result_array();
|
||||
|
||||
$words = empty($words) ? 0 : $words[0]['count'];
|
||||
|
||||
return [
|
||||
'commentCount' => $comments,
|
||||
'likeCount' => $likes,
|
||||
'wordCount' => $words,
|
||||
];
|
||||
}
|
||||
|
||||
private function mergePostAuthorData($posts)
|
||||
{
|
||||
foreach ($posts as $i => $post) {
|
||||
$authorData = $this->getAuthorData($post['authorID']);
|
||||
$posts[$i]['author'] = $authorData;
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
public function getAuthorData($authorID)
|
||||
{
|
||||
$author = $this->db->query('SELECT u.ID, u.username, u.displayname, u.rank, s.profilePicture, s.headerImage, s.about FROM users u LEFT JOIN user_settings s ON u.ID = s.ID WHERE u.ID = ?', [$authorID])->result_array();
|
||||
|
||||
$author = $this->UserModel->setDefaultImages($author);
|
||||
|
||||
if (empty($author)) {
|
||||
return null;
|
||||
}
|
||||
return $author[0];
|
||||
}
|
||||
|
||||
public function getPostPageCount($search, $postsPerPage)
|
||||
{
|
||||
if ($search !== '') {
|
||||
$search = strtolower($search);
|
||||
$data = $this->db->query('
|
||||
SELECT COUNT(*) pageCount
|
||||
FROM blog_posts p, blog_categories ca
|
||||
WHERE ca.id = p.postCategoryID
|
||||
AND (CONCAT((SELECT t.postTitle FROM blog_translations t WHERE t.postID = p.postID AND language = ?), postUrl, (SELECT t.postDesc FROM blog_translations t WHERE t.postID = p.postID AND language = ?)) RLIKE ?
|
||||
OR (SELECT content FROM blog_content WHERE blog_content.postID = p.postID AND isActive = TRUE LIMIT 1) RLIKE ?)
|
||||
AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $search])->result_array();
|
||||
SELECT COUNT(*) pageCount
|
||||
FROM blog_post p
|
||||
WHERE ((SELECT LOWER(title) RLIKE ? OR LOWER(description) RLIKE ? OR LOWER(content) RLIKE ? FROM blog_post_versions v WHERE v.postID = p.ID AND v.lang = ? AND active)
|
||||
OR (SELECT LOWER(displayname) RLIKE ? FROM blog_categories c WHERE c.lang = ? AND c.categoryID IN (SELECT categoryID FROM blog_post_categories pc WHERE pc.postID = p.ID)))
|
||||
AND state = 1', [$search, $search, $_SESSION['site_lang'], $search, $_SESSION['site_lang']])->result_array();
|
||||
} else {
|
||||
$data = $this->db->query('SELECT COUNT(*) pageCount FROM blog_posts')->result_array();
|
||||
$data = $this->db->query('SELECT COUNT(*) pageCount FROM blog_post')->result_array();
|
||||
}
|
||||
return ($data[0]['pageCount']) / $postsPerPage;
|
||||
}
|
||||
|
||||
function getCategoryPosts($category, $amount, $offset = 0)
|
||||
{
|
||||
$category = $this->db->query('SELECT ID FROM blog_categories WHERE name = ? AND lang = ?', [$category, $_SESSION['site_lang']])->result_array();
|
||||
|
||||
if(empty($category)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$offset *= $amount;
|
||||
$posts = $this->db->query('
|
||||
SELECT p.*, ca.name categoryName, ca.display_name categoryDisplayName, (SELECT count(*) FROM blog_comments WHERE post_id = p.postID) commentCount, (SELECT count(*) FROM blog_post_likes WHERE post_id = p.postID) likeCount
|
||||
FROM blog_posts p, blog_categories ca
|
||||
WHERE ca.id = p.postCategoryID
|
||||
AND postState = 1
|
||||
AND ca.name = ?
|
||||
ORDER BY postPublishDate DESC
|
||||
LIMIT ? OFFSET ?', [$category, $amount, $offset])->result_array();
|
||||
$posts = $this->mergePostTitleDesc($posts);
|
||||
$posts = $this->db->query('SELECT * FROM blog_post p WHERE ID IN (SELECT postID FROM blog_post_categories pc WHERE pc.categoryID = ?) LIMIT ? OFFSET ?', [$category[0]['ID'], $amount, $offset])->result_array();
|
||||
$posts = $this->mergePostTranslation($posts);
|
||||
$posts = $this->mergePostCategories($posts);
|
||||
$posts = $this->mergePostStats($posts);
|
||||
$posts = $this->mergePostAuthorData($posts);
|
||||
return $posts;
|
||||
}
|
||||
|
||||
public function getCategoryPostsByID($categoryID, $amount = 3, $postID = NULL)
|
||||
public function getCategoryPostsByID($categories, $amount = 3, $postID = NULL)
|
||||
{
|
||||
$posts = $this->db->query('SELECT * FROM blog_posts WHERE postCategoryID = ? AND postID != ? AND blog_posts.postState = 1 ORDER BY postPublishDate DESC LIMIT ?', [$categoryID, $postID, $amount])->result_array();
|
||||
return $this->mergePostTitleDesc($posts);
|
||||
function getIDs($val) {
|
||||
return $val['ID'];
|
||||
}
|
||||
|
||||
if(empty($categories)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$categories = array_map('getIDs', $categories);
|
||||
|
||||
$posts = $this->db->query('SELECT * FROM blog_post WHERE ID IN (SELECT postID FROM blog_post_categories WHERE categoryID IN ?) AND ID != ? AND state = 1 ORDER BY initialRelease DESC LIMIT ?', [$categories, $postID, $amount])->result_array();
|
||||
$posts = $this->mergePostTranslation($posts);
|
||||
return $posts;
|
||||
}
|
||||
|
||||
public function getTagPosts($tag, $amount, $offset = 0) {
|
||||
public function getTagPosts($tag, $amount, $offset = 0)
|
||||
{
|
||||
$offset *= $amount;
|
||||
$posts = $this->db->query('SELECT p.*, ca.name categoryName, ca.display_name categoryDisplayName, (SELECT count(*) FROM blog_comments WHERE post_id = p.postID) commentCount, (SELECT count(*) FROM blog_post_likes WHERE post_id = p.postID) likeCount FROM blog_posts p LEFT JOIN blog_categories ca ON ca.ID = p.postCategoryID WHERE postState = 1 AND EXISTS(SELECT post_id FROM blog_post_tags WHERE tag_id = (SELECT ID FROM blog_tags t WHERE t.name = ?) AND post_id = p.postID) ORDER BY postPublishDate DESC LIMIT ? OFFSET ?', [$tag, $amount, $offset])->result_array();
|
||||
$posts = $this->mergePostTitleDesc($posts);
|
||||
$tag = strtolower($tag);
|
||||
$tagID = $this->db->query('SELECT ID FROM blog_tags WHERE name = ? AND lang = ?', [$tag, $_SESSION['site_lang']])->result_array();
|
||||
|
||||
if(empty($tagID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$posts = $this->db->query('SELECT * FROM blog_post p WHERE state = 1 AND ID IN (SELECT postID FROM blog_post_tags WHERE tagID = ?) ORDER BY initialRelease DESC LIMIT ? OFFSET ?', [$tagID[0]['ID'], $amount, $offset])->result_array();
|
||||
$posts = $this->mergePostTranslation($posts);
|
||||
$posts = $this->mergePostCategories($posts);
|
||||
$posts = $this->mergePostStats($posts);
|
||||
$posts = $this->mergePostAuthorData($posts);
|
||||
return $posts;
|
||||
}
|
||||
|
||||
function getCategoryIDAfterInsert($name, $display_name)
|
||||
{
|
||||
if (!$this->db->simple_query('INSERT INTO blog_categories (name, display_name) VALUES (?, ?)', [$name, $display_name])) {
|
||||
$return = $this->db->query('SELECT ID FROM blog_categories WHERE name = ? AND display_name = ? LIMIT 1', [$name, $display_name])->result_array()[0];
|
||||
if (!$this->db->simple_query('INSERT INTO blog_categories (name, displayname) VALUES (?, ?)', [$name, $display_name])) {
|
||||
$return = $this->db->query('SELECT ID FROM blog_categories WHERE name = ? AND displayname = ? LIMIT 1', [$name, $display_name])->result_array()[0];
|
||||
$return = $return['ID'];
|
||||
} else {
|
||||
$return = $this->db->query('SELECT LAST_INSERT_ID() ID')->result_array()[0]['ID'];
|
||||
@@ -120,7 +234,9 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
|
||||
function incrementViews($id)
|
||||
{
|
||||
$this->db->query('UPDATE blog_posts SET postViews = postViews+1 WHERE postID = ?', [$id]);
|
||||
$this->db->query('INSERT IGNORE INTO blog_post_stats (ID) VALUES (?)', [$id]);
|
||||
|
||||
$this->db->query('UPDATE blog_post_stats SET views = views + 1 WHERE ID = ?', [$id]);
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
}
|
||||
|
||||
@@ -135,172 +251,157 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
public function getPost($postUrl)
|
||||
{
|
||||
$content = $this->db->query('
|
||||
SELECT p.*,
|
||||
ca.name categoryName,
|
||||
ca.display_name categoryDisplayName,
|
||||
COUNT(co.comment) commentCount,
|
||||
(SELECT count(*) FROM blog_post_likes l WHERE l.post_id = p.postID) likeCount
|
||||
FROM blog_posts p
|
||||
LEFT JOIN blog_categories ca ON p.postCategoryID = ca.ID
|
||||
LEFT JOIN blog_comments co ON p.postID = co.post_id
|
||||
LEFT JOIN blog_post_likes l ON p.postID = l.post_id
|
||||
WHERE postUrl = ? AND postState = 1
|
||||
GROUP BY p.postID', [$postUrl])->result_array(); //TODO: language integration
|
||||
SELECT p.*
|
||||
FROM blog_post p
|
||||
WHERE (SELECT postID FROM blog_post_versions v WHERE v.postID = p.ID AND (v.lang = ? OR v.lang = "de") AND active AND url = ? ORDER BY edited DESC LIMIT 1) = p.ID AND state = 1
|
||||
GROUP BY ID', [$_SESSION['site_lang'], $postUrl])->result_array(); //TODO: language integration
|
||||
|
||||
$content = $this->mergePostTitleDesc($content);
|
||||
$content = $this->mergePostTranslation($content, true);
|
||||
$content = $this->mergePostStats($content);
|
||||
$content = $this->mergePostCategories($content);
|
||||
$content = $this->mergePostAuthorData($content);
|
||||
$content = $this->mergePostContent($content, $_SESSION['site_lang']);
|
||||
return $content[0];
|
||||
}
|
||||
|
||||
public function getPostDataByID($postID)
|
||||
{
|
||||
$data = $this->db->query('
|
||||
SELECT p.*,
|
||||
ca.name AS categoryName,
|
||||
ca.display_name AS categoryDisplayName,
|
||||
COUNT(co.comment) AS commentCount,
|
||||
COUNT(l.post_id) AS likeCount
|
||||
FROM blog_posts p
|
||||
LEFT JOIN blog_categories ca ON p.postCategoryID = ca.ID
|
||||
LEFT JOIN blog_comments co ON p.postID = co.post_id
|
||||
LEFT JOIN blog_post_likes l ON p.postID = l.post_id
|
||||
WHERE postID = ?
|
||||
GROUP BY p.postID', [$postID])->result_array();
|
||||
SELECT *
|
||||
FROM blog_post
|
||||
WHERE ID = ?', [$postID])->result_array();
|
||||
|
||||
$data = $this->mergePostCategories($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getContentDataByID($postID, $contentID, $lang)
|
||||
{
|
||||
$data = $this->db->query('SELECT * FROM blog_content WHERE postID = ? AND contentID = ? AND language = ?', [$postID, $contentID, $lang])->result_array();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getTranslationDataByID($postID, $translationID, $lang)
|
||||
{
|
||||
$data = $this->db->query('SELECT * FROM blog_translations WHERE postID = ? AND postTranslationID = ? AND language = ?', [$postID, $translationID, $lang])->result_array();
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getPostContentByID($postID, $language)
|
||||
{
|
||||
$content = $this->db->query('SELECT * FROM blog_content WHERE postID = ? AND isActive = TRUE AND language = ? ORDER BY contentDate DESC LIMIT 1', [$postID, $language])->result_array();
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function getRandomPosts($postID)
|
||||
{
|
||||
$posts = $this->db->query('SELECT * FROM blog_posts WHERE postID <> ? AND postState = 1 ORDER BY RAND() LIMIT 3', [$postID])->result_array();
|
||||
$posts = $this->mergePostTitleDesc($posts);
|
||||
$posts = $this->db->query('SELECT * FROM blog_post WHERE ID <> ? AND state = 1 ORDER BY RAND() LIMIT 3', [$postID])->result_array();
|
||||
$posts = $this->mergePostTranslation($posts);
|
||||
$posts = $this->mergePostAuthorData($posts);
|
||||
return $posts;
|
||||
}
|
||||
|
||||
public function mergePostTitleDesc($posts, $language = NULL)
|
||||
public function getPostTranslation($postID, $showContent, $language)
|
||||
{
|
||||
$language = ($language == NULL ? $_SESSION['site_lang'] : $language);
|
||||
foreach ($posts as $i => $post) {
|
||||
$titleDesc = $this->getPostTitleDesc($post['postID'], $language);
|
||||
$posts[$i]['postTitle'] = $titleDesc['title'];
|
||||
$posts[$i]['postDesc'] = $titleDesc['desc'];
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
$data = $this->db->query('SELECT * FROM blog_post_versions WHERE postID = ? AND active ORDER BY lang ASC', [$postID])->result_array();
|
||||
|
||||
private function mergePostAuthorData($posts)
|
||||
{
|
||||
foreach ($posts as $i => $post) {
|
||||
$authorData = $this->getAuthorData($post['postAuthorID']);
|
||||
$posts[$i]['postAuthorDisplayname'] = $authorData['displayname'];
|
||||
$posts[$i]['postAuthorUsername'] = $authorData['username'];
|
||||
$posts[$i]['postAuthorProfilePicture'] = $authorData['profile_picture'];
|
||||
$posts[$i]['postAuthorHeaderImage'] = $authorData['header_image'];
|
||||
$posts[$i]['postAuthorRank'] = $authorData['rank'];
|
||||
$posts[$i]['postAuthorAbout'] = $authorData['about'];
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
private function mergePostContent($posts, $language)
|
||||
{
|
||||
$language = ($language == NULL ? $_SESSION['site_lang'] : $language);
|
||||
foreach ($posts as $i => $post) {
|
||||
$content = $this->getPostContentByID($post['postID'], $language);
|
||||
if (empty($content) && $_SESSION['site_lang'] !== 'de') {
|
||||
$content = $this->getPostContentByID($post['postID'], 'de');
|
||||
}
|
||||
if (!empty($content)) {
|
||||
$content = $content[0];
|
||||
$posts[$i]['postContent'] = $content['content'];
|
||||
$posts[$i]['postWordCount'] = $content['wordCount'];
|
||||
}
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
public function getPostTitleDesc($postID, $language)
|
||||
{
|
||||
$data = $this->db->query('SELECT * FROM blog_translations WHERE postID = ? ORDER BY blog_translations.language ASC', [$postID])->result_array();
|
||||
if (empty($data)) {
|
||||
return ['title' => 'Nicht vorhandener Post', 'desc' => 'Aus unbekannten Gründen ist dieser Blog-Post nicht vorhanden. Bitte versuche es später erneut oder kontaktiere das Support-Team'];
|
||||
return ['error' => true, 'title' => 'Nicht vorhandener Post', 'description' => 'Aus unbekannten Gründen ist dieser Blog-Post nicht vorhanden. Bitte versuche es später erneut oder kontaktiere das Support-Team'];
|
||||
}
|
||||
$postTitle = $data[0]['postTitle'];
|
||||
$postDesc = $data[0]['postDesc'];
|
||||
|
||||
$url = $data[0]['url'];
|
||||
$title = $data[0]['title'];
|
||||
$description = $data[0]['description'];
|
||||
$content = $data[0]['content'];
|
||||
foreach ($data as $row) {
|
||||
if ($row['language'] == $language) {
|
||||
$postTitle = $row['postTitle'];
|
||||
$postDesc = $row['postDesc'];
|
||||
if ($row['lang'] == $language) {
|
||||
$url = $row['url'];
|
||||
$title = $row['title'];
|
||||
$description = $row['description'];
|
||||
$content = $row['content'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ['title' => $postTitle, 'desc' => $postDesc];
|
||||
|
||||
$return = [
|
||||
'url' => $url,
|
||||
'title' => $title,
|
||||
'description' => $description,
|
||||
];
|
||||
if($showContent) {
|
||||
$return['content'] = $content;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function getAuthorData($authorID)
|
||||
{
|
||||
$author = $this->db->query('SELECT ID, username, displayname, rank, profile_picture, header_image, about FROM users WHERE ID = ?', [$authorID])->result_array();
|
||||
public function getPostTranslationByID($postID, $versionID, $lang) {
|
||||
$data = $this->db->query('SELECT * FROM blog_post_versions WHERE postID = ? AND ID = ? AND lang = ?', [$postID, $versionID, $lang])->result_array();
|
||||
return $data;
|
||||
}
|
||||
|
||||
$author = $this->UserModel->setDefaultImages($author);
|
||||
|
||||
if(empty($author)) {
|
||||
return null;
|
||||
}
|
||||
return $author[0];
|
||||
public function getPostTranslationByHashID($versionID) {
|
||||
$data = $this->db->query('SELECT * FROM blog_post_versions WHERE MD5(ID) = ?', [$versionID])->result_array();
|
||||
return !empty($data) ? $data[0] : NULL;
|
||||
}
|
||||
|
||||
public function getComments($postID)
|
||||
{
|
||||
$comments = $this->db->query('SELECT * FROM blog_comments WHERE post_id = ? ORDER BY date_created DESC', [$postID])->result_array();
|
||||
$comments = $this->db->query('SELECT * FROM blog_post_comments WHERE postID = ? ORDER BY date DESC', [$postID])->result_array();
|
||||
return $comments;
|
||||
}
|
||||
|
||||
public function getCommentsByUrl($postUrl)
|
||||
{
|
||||
return $this->db->query('SELECT * FROM blog_comments WHERE post_id = (SELECT postID FROM blog_posts WHERE postUrl = ?) ORDER BY date_created DESC', [$postUrl])->result_array();
|
||||
$ID = $this->getPostIDByUrl($postUrl);
|
||||
if($ID !== NULL) {
|
||||
return $this->getComments($ID);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
public function addComment($postID, $userID, $comment, $reply, $replyTo)
|
||||
{
|
||||
$this->db->query('INSERT INTO blog_comments (post_id, user_id, comment, reply, replyTo_id) VALUES (?, ?, ?, ?, ?)', [$postID, $userID, $comment, $reply, $replyTo]);
|
||||
public function getComment($commentID) {
|
||||
$comment = $this->db->query('SELECT * FROM blog_post_comments WHERE ID = ?', [$commentID])->result_array();
|
||||
return !empty($comment) ? $comment[0] : NULL;
|
||||
}
|
||||
|
||||
public function isCommentIDValid($commentID) {
|
||||
$comment = $this->db->query('SELECT ID FROM blog_post_comments WHERE ID = ?', [$commentID])->result_array();
|
||||
return !empty($comment);
|
||||
}
|
||||
|
||||
public function addCommentByUrl($postUrl, $userID, $comment, $replyTo)
|
||||
{
|
||||
$postID = $this->getPostIDByUrl($postUrl);
|
||||
|
||||
if($postID == NULL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->addComment($postID, $userID, $comment, $replyTo);
|
||||
|
||||
return $this->db->query('SELECT * FROM blog_post_comments WHERE postID = ? AND userID = ? ORDER BY ID DESC LIMIT 1', [$postID, $userID])->result_array()[0];
|
||||
}
|
||||
|
||||
public function addComment($postID, $userID, $comment, $replyTo)
|
||||
{
|
||||
$this->db->query('INSERT INTO blog_post_comments (postID, userID, comment, replyToID) VALUES (?, ?, ?, ?)', [$postID, $userID, $comment, $replyTo]);
|
||||
|
||||
$this->db->cache_delete('user', 'getComments');
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
$this->db->cache_delete('blog', 'comment');
|
||||
$this->db->cache_delete('blog', 'getComments');
|
||||
$this->db->cache_delete('blog', 'getReportModal');
|
||||
$this->db->cache_delete('blog', 'reportModal');
|
||||
$this->db->cache_delete('blog', 'getDeleteModal');
|
||||
$this->db->cache_delete('blog', 'deleteComment');
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
}
|
||||
|
||||
public function addCommentByUrl($postUrl, $userID, $comment, $reply, $replyTo)
|
||||
{
|
||||
$postID = $this->db->query('SELECT postID FROM blog_posts WHERE postUrl = ?', [$postUrl])->result_array();
|
||||
if(empty($postID)) {
|
||||
return null;
|
||||
}
|
||||
public function reportComment($commentID, $reason, $reasonText) {
|
||||
$this->db->query('INSERT INTO blog_post_comments_reports (commentID, reason, reasonText) VALUES (?, ?, ?)', [$commentID, $reason, $reasonText]);
|
||||
|
||||
$this->addComment($postID[0]['postID'], $userID, $comment, $reply, $replyTo);
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
}
|
||||
|
||||
return $this->db->query('SELECT * FROM blog_comments WHERE post_id = ? AND user_id = ? ORDER BY ID DESC LIMIT 1', [$postID[0]['postID'], $userID])->result_array()[0];
|
||||
public function deleteComment($userID, $commentID) {
|
||||
$this->db->query('DELETE FROM blog_post_comments WHERE replyToID = ?', [$commentID]);
|
||||
$this->db->query('DELETE FROM blog_post_comments WHERE userID = ? AND ID = ?', [$userID, $commentID]);
|
||||
|
||||
$this->db->cache_delete('user', 'getComments');
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
$this->db->cache_delete('blog', 'comment');
|
||||
$this->db->cache_delete('blog', 'getComments');
|
||||
$this->db->cache_delete('blog', 'getReportModal');
|
||||
$this->db->cache_delete('blog', 'reportModal');
|
||||
$this->db->cache_delete('blog', 'getDeleteModal');
|
||||
$this->db->cache_delete('blog', 'deleteComment');
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
}
|
||||
|
||||
public function getAllTags()
|
||||
@@ -310,13 +411,14 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
|
||||
public function getTags($postID)
|
||||
{
|
||||
$tags = $this->db->query('SELECT t.* FROM blog_tags t WHERE ID IN (SELECT tag_id FROM blog_post_tags WHERE post_id = ?)', [$postID])->result_array();
|
||||
$tags = $this->db->query('SELECT t.* FROM blog_tags t WHERE ID IN (SELECT tagID FROM blog_post_tags WHERE postID = ?)', [$postID])->result_array();
|
||||
return $tags;
|
||||
}
|
||||
|
||||
public function mergeTagInfo($tags) {
|
||||
public function mergeTagInfo($tags)
|
||||
{
|
||||
foreach ($tags as $i => $tag) {
|
||||
$data = $this->db->query('SELECT count(*) countUsed, SUM(postViews) totalViews FROM blog_posts WHERE postID = (SELECT post_id FROM blog_post_tags WHERE tag_id = ? AND post_id = postID)', [$tag['ID']])->result_array();
|
||||
$data = $this->db->query('SELECT count(*) countUsed, SUM(postViews) totalViews FROM blog_posts WHERE postID = (SELECT postID FROM blog_post_tags WHERE tag_id = ? AND postID = postID)', [$tag['ID']])->result_array();
|
||||
$data = $data[0];
|
||||
$tags[$i]['countUsed'] = $data['countUsed'];
|
||||
$tags[$i]['totalViews'] = $data['totalViews'] != '' ? $data['totalViews'] : 0;
|
||||
@@ -326,7 +428,7 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
|
||||
public function hasAlreadyLiked($postID, $userID)
|
||||
{
|
||||
$getLikes = $this->db->query('SELECT * FROM blog_post_likes WHERE post_id = ? AND user_id = ?', [$postID, $userID])->result_array();
|
||||
$getLikes = $this->db->query('SELECT * FROM blog_post_likes WHERE postID = ? AND userID = ?', [$postID, $userID])->result_array();
|
||||
if (empty($getLikes)) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -336,53 +438,49 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
|
||||
public function addLike($postID, $userID)
|
||||
{
|
||||
$this->db->query('INSERT INTO blog_post_likes (post_id, user_id) VALUES (?, ?)', [$postID, $userID]);
|
||||
$this->db->query('INSERT INTO blog_post_likes (postID, userID) VALUES (?, ?)', [$postID, $userID]);
|
||||
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
$this->db->cache_delete('blog', 'like');
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
|
||||
return $this->db->query('SELECT count(*) likeCount FROM blog_post_likes WHERE post_id = ?', [$postID])->result_array()[0];
|
||||
return $this->db->query('SELECT count(*) likeCount FROM blog_post_likes WHERE postID = ?', [$postID])->result_array()[0];
|
||||
}
|
||||
|
||||
public function removeLike($postID, $userID)
|
||||
{
|
||||
$this->db->query('DELETE FROM blog_post_likes WHERE post_id = ? AND user_id = ?', [$postID, $userID]);
|
||||
$this->db->query('DELETE FROM blog_post_likes WHERE postID = ? AND userID = ?', [$postID, $userID]);
|
||||
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
$this->db->cache_delete('blog', 'like');
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
|
||||
return $this->db->query('SELECT count(*) likeCount FROM blog_post_likes WHERE post_id = ?', [$postID])->result_array()[0];
|
||||
return $this->db->query('SELECT count(*) likeCount FROM blog_post_likes WHERE postID = ?', [$postID])->result_array()[0];
|
||||
}
|
||||
|
||||
public function getPostList($onlyTrash)
|
||||
{
|
||||
$posts = $this->db->query('SELECT p.*,
|
||||
ca.name categoryName,
|
||||
ca.display_name categoryDisplayName,
|
||||
(SELECT count(*)
|
||||
FROM blog_comments
|
||||
WHERE post_id = p.postID) commentCount,
|
||||
(SELECT count(*)
|
||||
FROM blog_post_likes
|
||||
WHERE post_id = p.postID) likeCount,
|
||||
(SELECT display_name
|
||||
FROM blog_states
|
||||
WHERE ID = p.postState) postStateDisplay
|
||||
FROM blog_posts p
|
||||
LEFT JOIN blog_categories ca ON ca.ID = p.postCategoryID
|
||||
WHERE postIsDeleted = ?', [$onlyTrash])->result_array();
|
||||
$posts = $this->mergePostTitleDesc($posts);
|
||||
if($onlyTrash) {
|
||||
$posts = $this->db->query('SELECT p.*, s.views
|
||||
FROM blog_trash p LEFT JOIN blog_post_stats s ON s.ID = p.ID')->result_array();
|
||||
} else {
|
||||
$posts = $this->db->query('SELECT p.*, s.views
|
||||
FROM blog_post p LEFT JOIN blog_post_stats s ON s.ID = p.ID')->result_array();
|
||||
}
|
||||
|
||||
$posts = $this->mergePostTranslation($posts);
|
||||
$posts = $this->mergePostCategories($posts);
|
||||
$posts = $this->mergePostStats($posts);
|
||||
$posts = $this->mergePostAuthorData($posts);
|
||||
$posts = $this->mergePostState($posts);
|
||||
return $posts;
|
||||
}
|
||||
|
||||
public function getAllContentVersions($postID, $lang)
|
||||
public function getAllPostVersions($postID, $lang)
|
||||
{
|
||||
$content = $this->db->query('SELECT * FROM blog_content WHERE postID = ? AND language = ? ORDER BY contentDate DESC', [$postID, $lang])->result_array();
|
||||
$content = $this->db->query('SELECT *, MD5(ID) hashID FROM blog_post_versions WHERE postID = ? AND lang = ? ORDER BY edited DESC', [$postID, $lang])->result_array();
|
||||
return $content;
|
||||
}
|
||||
|
||||
@@ -391,7 +489,7 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
$this->db->cache_off();
|
||||
$tagData = $this->db->query('SELECT ID FROM blog_tags WHERE name = ?', [strtolower($tag)])->result_array();
|
||||
if (empty($tagData)) {
|
||||
$this->db->query('INSERT INTO blog_tags (name, display_name) VALUES (?, ?)', [strtolower($tag), $tag]);
|
||||
$this->db->query('INSERT INTO blog_tags (name, displayname) VALUES (?, ?)', [strtolower($tag), $tag]);
|
||||
$tagData = $this->db->query('SELECT ID FROM blog_tags WHERE name = ?', [strtolower($tag)])->result_array();
|
||||
}
|
||||
$this->db->cache_on();
|
||||
@@ -401,7 +499,7 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
|
||||
public function addPostTagByID($postID, $tagID)
|
||||
{
|
||||
$this->db->query('INSERT INTO blog_post_tags (post_id, tag_id) VALUES (?, ?) ON DUPLICATE KEY UPDATE post_id = post_id', [$postID, $tagID]);
|
||||
$this->db->query('INSERT INTO blog_post_tags (postID, tagID) VALUES (?, ?) ON DUPLICATE KEY UPDATE postID = postID', [$postID, $tagID]);
|
||||
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
@@ -411,7 +509,7 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
|
||||
public function deleteAllPostTags($postID)
|
||||
{
|
||||
$this->db->query('DELETE FROM blog_post_tags WHERE post_id = ?', [$postID]);
|
||||
$this->db->query('DELETE FROM blog_post_tags WHERE postID = ?', [$postID]);
|
||||
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
@@ -419,6 +517,25 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
}
|
||||
|
||||
public function addPostCategoryByID($postID, $categoryID)
|
||||
{
|
||||
$this->db->query('INSERT INTO blog_post_categories (postID, categoryID) VALUES (?, ?) ON DUPLICATE KEY UPDATE postID = postID', [$postID, $categoryID]);
|
||||
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
$this->db->cache_delete('blog', 'like');
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
}
|
||||
|
||||
public function deleteAllPostCategories($postID)
|
||||
{
|
||||
$this->db->query('DELETE FROM blog_post_categories WHERE postID = ?', [$postID]);
|
||||
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
$this->db->cache_delete('blog', 'category');
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
}
|
||||
// TODO: Update
|
||||
public function prepareContentForRelease($content)
|
||||
{
|
||||
@@ -469,7 +586,8 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
|
||||
public function deletePost($id)
|
||||
{
|
||||
$this->db->query('UPDATE blog_posts SET postIsDeleted = TRUE, postDeletedDate = NOW(), postState = 4 WHERE postID = ? LIMIT 1', [$id]);
|
||||
$this->db->query('INSERT INTO blog_trash SELECT * FROM blog_post WHERE ID = ?', [$id]);
|
||||
$this->db->query('DELETE FROM blog_post WHERE ID = ?', [$id]);
|
||||
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
@@ -481,7 +599,8 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
|
||||
public function restorePost($id)
|
||||
{
|
||||
$this->db->query('UPDATE blog_posts SET postIsDeleted = FALSE, postDeletedDate = NULL, postState = 1 WHERE postID = ? LIMIT 1', [$id]);
|
||||
$this->db->query('INSERT INTO blog_post SELECT * FROM blog_trash WHERE ID = ?', [$id]);
|
||||
$this->db->query('DELETE FROM blog_trash WHERE ID = ?', [$id]);
|
||||
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
@@ -493,11 +612,19 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
|
||||
public function deletePostFinally($id)
|
||||
{
|
||||
$this->db->query('DELETE FROM blog_content WHERE postID = ? AND (SELECT postIsDeleted FROM blog_posts WHERE postID = ?) = TRUE', [$id, $id]);
|
||||
$this->db->query('DELETE FROM blog_post_likes WHERE post_id = ? AND (SELECT postIsDeleted FROM blog_posts WHERE postID = ?) = TRUE', [$id, $id]);
|
||||
$this->db->query('DELETE FROM blog_post_tags WHERE post_id = ? AND (SELECT postIsDeleted FROM blog_posts WHERE postID = ?) = TRUE', [$id, $id]);
|
||||
$this->db->query('DELETE FROM blog_comments WHERE post_id = ? AND (SELECT postIsDeleted FROM blog_posts WHERE postID = ?) = TRUE', [$id, $id]);
|
||||
$this->db->query('DELETE FROM blog_posts WHERE postID = ? AND postIsDeleted = TRUE LIMIT 1', [$id]);
|
||||
$data = $this->db->query('SELECT ID FROM blog_trash WHERE ID = ?', [$id])->result_array();
|
||||
|
||||
if(empty($data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->db->query('DELETE FROM blog_post_categories WHERE postID = ?', [$id]);
|
||||
$this->db->query('DELETE FROM blog_post_comments WHERE postID = ?', [$id]);
|
||||
$this->db->query('DELETE FROM blog_post_likes WHERE postID = ?', [$id]);
|
||||
$this->db->query('DELETE FROM blog_post_stats WHERE ID = ?', [$id]);
|
||||
$this->db->query('DELETE FROM blog_post_tags WHERE postID = ?', [$id]);
|
||||
$this->db->query('DELETE FROM blog_post_versions WHERE postID = ?', [$id]);
|
||||
$this->db->query('DELETE FROM blog_trash WHERE ID = ? LIMIT 1', [$id]);
|
||||
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
@@ -507,47 +634,29 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
}
|
||||
|
||||
public function getPrevPost($id)
|
||||
public function getPrevPost($initialRelease)
|
||||
{
|
||||
$posts = $this->db->query('SELECT postID, postUrl, postImage FROM blog_posts WHERE postPublishDate < (SELECT postPublishDate FROM blog_posts WHERE postID = ?) AND postState = 1 ORDER BY postPublishDate DESC LIMIT 1', [$id])->result_array();
|
||||
return $this->mergePostTitleDesc($posts);
|
||||
$posts = $this->db->query('SELECT ID, image FROM blog_post WHERE initialRelease < ? AND state = 1 ORDER BY initialRelease DESC LIMIT 1', [$initialRelease])->result_array();
|
||||
$posts = $this->mergePostTranslation($posts);
|
||||
return $posts;
|
||||
}
|
||||
|
||||
public function getNextPost($id)
|
||||
public function getNextPost($initialRelease)
|
||||
{
|
||||
$posts = $this->db->query('SELECT postID, postUrl, postImage FROM blog_posts WHERE postPublishDate > (SELECT postPublishDate FROM blog_posts WHERE postID = ?) AND postState = 1 ORDER BY postPublishDate ASC LIMIT 1', [$id])->result_array();
|
||||
return $this->mergePostTitleDesc($posts);
|
||||
$posts = $this->db->query('SELECT ID, image FROM blog_post WHERE initialRelease > ? AND state = 1 ORDER BY initialRelease ASC LIMIT 1', [$initialRelease])->result_array();
|
||||
$posts = $this->mergePostTranslation($posts);
|
||||
return $posts;
|
||||
}
|
||||
|
||||
public function getMostRecentPosts($count)
|
||||
{
|
||||
$posts = $this->db->query('SELECT postID, postImage, postUrl, postPublishDate FROM blog_posts WHERE postState = 1 ORDER BY postPublishDate DESC LIMIT ?', [$count])->result_array();
|
||||
return $this->mergePostTitleDesc($posts);
|
||||
$posts = $this->db->query('SELECT ID, image, initialRelease FROM blog_post WHERE state = 1 ORDER BY initialRelease DESC LIMIT ?', [$count])->result_array();
|
||||
$posts = $this->mergePostTranslation($posts);
|
||||
return $posts;
|
||||
}
|
||||
|
||||
private function countWords($text)
|
||||
public function getReadingTime($wordCount)
|
||||
{
|
||||
$text = preg_replace("/<[a-zA-Z0-9\/ .,:;\-_+!?&%=\"]+>/", '', $text);
|
||||
return str_word_count($text);
|
||||
}
|
||||
|
||||
public function getReadingTime($postID)
|
||||
{
|
||||
$data = $this->db->query('SELECT wordCount, language FROM blog_content c WHERE postID = ? AND isActive = TRUE AND (c.language = ? OR c.language = "de") ORDER BY contentDate DESC', [$postID, $_SESSION['site_lang']])->result_array();
|
||||
|
||||
if (empty($data)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$wordCount = $data[0]['wordCount'];
|
||||
|
||||
foreach ($data as $entry) {
|
||||
if ($entry['language'] == $_SESSION['site_lang']) {
|
||||
$wordCount = $entry['wordCount'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$wordsPerSecond = 3;
|
||||
$duration = $wordCount / $wordsPerSecond;
|
||||
$duration /= 60;
|
||||
@@ -557,53 +666,46 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
|
||||
public function createNewPostDraft($authorID)
|
||||
{
|
||||
$this->db->query('INSERT INTO blog_posts (postAuthorID, postState) VALUE (?, 2)', [$authorID]);
|
||||
$data = $this->db->query('SELECT postID FROM blog_posts WHERE postState = 2 ORDER BY postID DESC LIMIT 1')->result_array();
|
||||
$this->db->query('INSERT INTO blog_post (authorID, state) VALUE (?, 2)', [$authorID]);
|
||||
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
$data = $this->db->query('SELECT ID FROM blog_post WHERE state = 2 ORDER BY ID DESC LIMIT 1')->result_array();
|
||||
|
||||
return intval($data[0]['postID']);
|
||||
}
|
||||
|
||||
public function createNewContentDraft($postID)
|
||||
{
|
||||
$this->db->query('INSERT INTO blog_content (postID, isActive) VALUES (?, 0)', [$postID]);
|
||||
public function createNewTranslationDraft($postID, $authorID, $lang) {
|
||||
$this->db->query('INSERT INTO blog_post_versions (postID, authorID, active, lang) VALUES (?, ?, 0, ?)', [$postID, $authorID, $lang]);
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
$data = $this->db->query('SELECT contentID FROM blog_content WHERE postID = ? ORDER BY contentID DESC LIMIT 1', [$postID])->result_array();
|
||||
return intval($data[0]['contentID']);
|
||||
|
||||
$data = $this->db->query('SELECT ID FROM blog_post_versions WHERE postID = ? ORDER BY ID DESC LIMIT 1', [$postID])->result_array();
|
||||
|
||||
return intval($data[0]['ID']);
|
||||
}
|
||||
|
||||
public function createNewTranslation($postID, $language)
|
||||
public function updatePostDraft($postID, $initialRelease, $postImage)
|
||||
{
|
||||
$data = $this->db->query('SELECT postTranslationID FROM blog_translations WHERE postID = ? AND language = ?', [$postID, $language])->result_array();
|
||||
|
||||
if (empty($data)) {
|
||||
$this->db->query('INSERT INTO blog_translations (postID, language) VALUES (?, ?)', [$postID, $language]);
|
||||
$data = $this->db->query('SELECT postTranslationID FROM blog_translations WHERE postID = ? AND language = ? ORDER BY postTranslationID DESC', [$postID, $language])->result_array();
|
||||
}
|
||||
|
||||
return intval($data[0]['postTranslationID']);
|
||||
}
|
||||
|
||||
public function updatePostDraft($postID, $postUrl, $postCategory, $postPublishDate, $postImage)
|
||||
{
|
||||
$this->db->query('UPDATE blog_posts SET postUrl = ?, postCategoryID = ?, postPublishDate = ?, postImage = ? WHERE postID = ?', [$postUrl, $postCategory, $postPublishDate, $postImage, $postID]);
|
||||
$this->db->cache_delete('admin', 'edit');
|
||||
}
|
||||
|
||||
public function updateContentDraft($contentID, $postContent, $postLang)
|
||||
{
|
||||
$wordCount = $this->countWords($postContent);
|
||||
$this->db->query('UPDATE blog_content SET content = ?, language = ?, contentDate = NOW(), wordCount = ? WHERE contentID = ?', [$postContent, $postLang, $wordCount, $contentID]);
|
||||
$this->db->query('UPDATE blog_post SET initialRelease = ?, image = ? WHERE ID = ?', [$initialRelease, $postImage, $postID]);
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
}
|
||||
|
||||
public function updateTranslation($translationID, $postTitle, $postDesc)
|
||||
public function updateTranslationDraft($versionID, $url, $title, $description, $content, $lang)
|
||||
{
|
||||
$this->db->query('UPDATE blog_translations SET postTitle = ?, postDesc = ? WHERE postTranslationID = ?', [$postTitle, $postDesc, $translationID]);
|
||||
$wordCount = $this->countWords($content);
|
||||
$this->db->query('UPDATE blog_post_versions SET lang = ?, url = ?, title = ?, description = ?, content = ?, contentWordsCount = ?, edited = NOW() WHERE ID = ?', [$lang, $url, $title, $description, $content, $wordCount, $versionID]);
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
}
|
||||
|
||||
private function countWords($text)
|
||||
{
|
||||
$text = preg_replace("/<[a-zA-Z0-9\/ .,:;\-_+!?&%=\"]+>/", '', $text);
|
||||
return str_word_count($text);
|
||||
}
|
||||
|
||||
public function publishPostDraft($postID)
|
||||
{
|
||||
$this->db->query('UPDATE blog_posts SET postPublishDate = NOW(), postLastEdit = NOW(), postState = 1 WHERE postID = ?', [$postID]);
|
||||
$this->db->query('UPDATE blog_post SET initialRelease = NOW(), lastEdit = NOW(), state = 1 WHERE ID = ?', [$postID]);
|
||||
$this->db->query('INSERT INTO blog_post_stats (ID) VALUES (?)', [$postID]);
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
$this->db->cache_delete('blog', 'tag');
|
||||
@@ -612,54 +714,65 @@ AND postState = 1', [$_SESSION['site_lang'], $_SESSION['site_lang'], $search, $s
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
}
|
||||
|
||||
public function publishContentDraft($authorID, $contentID, $postID, $lang)
|
||||
public function publishTranslationDraft($postID, $versionID, $authorID, $lang)
|
||||
{
|
||||
$firstContent = $this->db->query('SELECT contentID FROM blog_content WHERE postID = ? AND contentID != ? AND language = ?', [$postID, $contentID, $lang])->result_array();
|
||||
$isNative = TRUE;
|
||||
if(!empty($firstContent)) {
|
||||
$isNative = FALSE;
|
||||
$this->db->query('UPDATE blog_post_versions SET active = FALSE WHERE postID = ? AND lang = ?', [$postID, $lang]);
|
||||
$this->db->query('UPDATE blog_post_versions SET active = TRUE, edited = NOW(), authorID = ? WHERE postID = ? AND ID = ?', [$authorID, $postID, $versionID]);
|
||||
}
|
||||
|
||||
public function getPostVersionIDs($postID) {
|
||||
$data = $this->db->query('SELECT ID, lang FROM blog_post_versions WHERE postID = ? GROUP BY lang ORDER BY active DESC, edited DESC, ID DESC', [$postID])->result_array();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getPostVersions($postID) {
|
||||
function getIDs($val) {
|
||||
return $val['ID'];
|
||||
}
|
||||
|
||||
$this->db->query('UPDATE blog_content SET isActive = FALSE WHERE postID = ?', [$postID]);
|
||||
$this->db->query('UPDATE blog_content SET isActive = TRUE, isNativePost = ?, contentDate = NOW(), contentAuthorID = ? WHERE contentID = ?', [$isNative, $authorID, $contentID]);
|
||||
}
|
||||
$versionIDs = $this->getPostVersionIDs($postID);
|
||||
$versionIDs = array_map("getIDs", $versionIDs);
|
||||
$data = $this->db->query('SELECT * FROM blog_post_versions WHERE ID IN ?', [$versionIDs])->result_array();
|
||||
|
||||
public function getPostTranslationIDs($postID) {
|
||||
$data = $this->db->query('SELECT postTranslationID, language FROM blog_translations WHERE postID = ?', [$postID])->result_array();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getPostContentIDs($postID) {
|
||||
$data = $this->db->query('SELECT (SELECT contentID FROM blog_content WHERE language = c.language ORDER BY contentID DESC LIMIT 1) contentID, language FROM blog_content c WHERE postID = ? AND language IS NOT NULL GROUP BY language ORDER BY contentID DESC', [$postID])->result_array();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getPostTranslations($postID)
|
||||
{
|
||||
$data = $this->db->query('SELECT * FROM blog_translations t LEFT JOIN blog_content c ON c.postID = t.postID AND c.language = t.language WHERE t.postID = ?', [$postID])->result_array();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function postIDExisting($postID)
|
||||
{
|
||||
$data = $this->db->query('SELECT postID FROM blog_posts WHERE postID = ?', [$postID])->result_array();
|
||||
$data = $this->db->query('SELECT ID FROM blog_post WHERE ID = ?', [$postID])->result_array();
|
||||
return !empty($data);
|
||||
}
|
||||
|
||||
public function contentIDExisting($postID, $contentID)
|
||||
public function versionIDExisting($postID, $versionID)
|
||||
{
|
||||
$data = $this->db->query('SELECT contentID FROM blog_content WHERE postID = ? AND contentID = ?', [$postID, $contentID])->result_array();
|
||||
$data = $this->db->query('SELECT ID FROM blog_post_versions WHERE postID = ? AND ID = ?', [$postID, $versionID])->result_array();
|
||||
return !empty($data);
|
||||
}
|
||||
|
||||
public function translationIDExisting($postID, $translationID)
|
||||
public function postUrlExisting($postUrl)
|
||||
{
|
||||
$data = $this->db->query('SELECT postTranslationID FROM blog_translations WHERE postID = ? AND postTranslationID = ?', [$postID, $translationID])->result_array();
|
||||
$data = $this->db->query('SELECT url FROM blog_post_versions WHERE url = ?', [$postUrl])->result_array();
|
||||
return !empty($data);
|
||||
}
|
||||
|
||||
public function postUrlExisting($postUrl) {
|
||||
$data = $this->db->query('SELECT postUrl FROM blog_posts WHERE postUrl = ?', [$postUrl])->result_array();
|
||||
return !empty($data);
|
||||
public function createCategory($name, $displayname, $lang, $categoryID = null) {
|
||||
$sameName = $this->db->query('SELECT categoryID FROM blog_categories WHERE name = ? AND displayname = ? AND lang = ?', [$name, $displayname, $lang])->result_array();
|
||||
if(!empty($sameName)) {
|
||||
return $sameName[0]['categoryID'];
|
||||
}
|
||||
|
||||
if($categoryID == null) {
|
||||
$highestCategoryID = $this->db->query('SELECT categoryID FROM blog_categories ORDER BY categoryID DESC LIMIT 1')->result_array();
|
||||
$categoryID = !empty($highestCategoryID) ? $highestCategoryID[0]['categoryID'] + 1 : 1;
|
||||
}
|
||||
$this->db->query('INSERT INTO blog_categories (categoryID, lang, name, displayname) VALUES (?, ?, ?, ?)', [$categoryID, $lang, $name, $displayname]);
|
||||
$this->db->cache_delete('admin', 'blog');
|
||||
$this->db->cache_delete('blog', 'index');
|
||||
$this->db->cache_delete('blog', 'category');
|
||||
$this->db->cache_delete('blog', 'tag');
|
||||
$this->db->cache_delete('blog', 'search');
|
||||
$this->db->cache_delete('blog', 'post');
|
||||
|
||||
return $categoryID;
|
||||
}
|
||||
}
|
@@ -12,15 +12,16 @@ class DatabaseModel extends CI_Model
|
||||
public function createMissingDatabases()
|
||||
{
|
||||
//$this->createDatabases();
|
||||
$this->createTables();
|
||||
// TODO: Update data base generation
|
||||
// $this->createTables();
|
||||
//$this->addIndices();
|
||||
//$this->addAutoIncrements();
|
||||
//$this->addConstraints();
|
||||
|
||||
$this->fillBlogTables();
|
||||
$this->fillFeedbackTable();
|
||||
$this->fillMainTable();
|
||||
$this->fillProjectsTable();
|
||||
//$this->fillBlogTables();
|
||||
//$this->fillFeedbackTable();
|
||||
//$this->fillMainTable();
|
||||
//$this->fillProjectsTable();
|
||||
}
|
||||
|
||||
private function createDatabases()
|
||||
|
@@ -10,6 +10,10 @@
|
||||
}
|
||||
|
||||
function sendMail($recipient, $subject, $template, $templateData) {
|
||||
if(base_url() == 'http://192.168.178.39/') {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load->library('email');
|
||||
|
||||
$config['mailtype'] = 'html';
|
||||
|
@@ -26,7 +26,7 @@ class FileModel extends CI_Model
|
||||
$userID = $user;
|
||||
}
|
||||
|
||||
$this->db->query('INSERT INTO files (name, original_name, type, size, path, user) VALUES (?, ?, ?, ?, ?, ?)', [$name, $originalName, $type, $size, $path, $userID]);
|
||||
$this->db->query('INSERT INTO files (name, originalName, type, size, path, user) VALUES (?, ?, ?, ?, ?, ?)', [$name, $originalName, $type, $size, $path, $userID]);
|
||||
|
||||
$this->db->cache_delete('admin', 'files');
|
||||
}
|
||||
|
@@ -19,15 +19,15 @@
|
||||
|
||||
$return = '';
|
||||
foreach ($posts as $result) {
|
||||
$date = strtotime($result['postPublishDate']);
|
||||
$date = strtotime($result['initialRelease']);
|
||||
$return .= '<div class="media">';
|
||||
|
||||
if ($result['postImage'] != '') {
|
||||
$return .= '<img src="' . $result['postImage'] . '?w=100" style="width:75px" class="img-fluid mr-3">';
|
||||
if ($result['image'] != '') {
|
||||
$return .= '<img src="' . $result['image'] . '?w=100" style="width:75px" class="img-fluid mr-3">';
|
||||
}
|
||||
|
||||
$return .= '<div class="media-body">
|
||||
<h6 class="my-0"><a href="#">' . $result['postTitle'] . '</a></h6>
|
||||
<h6 class="my-0"><a href="#">' . $result['title'] . '</a></h6>
|
||||
<small class="text-white-50">' . lang('footer_published') . ' ' . DateTimeHumanizer::difference(new \DateTime(), new \DateTime("@$date"), $_SESSION['site_lang']) . '</small>
|
||||
</div>
|
||||
</div>';
|
||||
|
@@ -28,7 +28,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
$encryptedPassword = $this->getPasswordHash($password, $logindata['original_name']);
|
||||
$encryptedPassword = $this->getPasswordHash($password, $logindata['originalName']);
|
||||
|
||||
if ($encryptedPassword == $logindata['password']) {
|
||||
$this->startLoginSession($logindata, $rememberMe);
|
||||
@@ -40,15 +40,15 @@
|
||||
public function getLoginData($username)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$return = $this->db->query('SELECT * FROM users WHERE (username = lower(?) OR email = lower(?)) AND is_activated = TRUE LIMIT 1',
|
||||
$return = $this->db->query('SELECT u.ID, u.username, u.displayname, u.originalName, u.email, u.rank, u.loginMethod, u.password, u.isDeleted, s.profilePicture, s.showAds FROM users u INNER JOIN user_settings s ON s.ID = u.ID WHERE (username = lower(?) OR email = lower(?)) AND activated = TRUE LIMIT 1',
|
||||
[htmlspecialchars($username, ENT_QUOTES), $username])->result_array();
|
||||
$this->db->cache_on();
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function getPasswordHash($password, $original_name)
|
||||
public function getPasswordHash($password, $originalName)
|
||||
{
|
||||
$salt = md5($original_name);
|
||||
$salt = md5($originalName);
|
||||
$passwordHash = hash('sha256', $salt . $password . $salt);
|
||||
return $passwordHash;
|
||||
}
|
||||
@@ -80,7 +80,7 @@
|
||||
'displayname' => $displayname,
|
||||
'rank' => $rank,
|
||||
'showAds' => $ads,
|
||||
'profile_picture' => $avatar,
|
||||
'profilePicture' => $avatar,
|
||||
) = $logindata;
|
||||
|
||||
$this->session->set_userdata('user', [
|
||||
@@ -131,7 +131,7 @@
|
||||
|
||||
public function isAvailable($username)
|
||||
{
|
||||
$registered = $this->db->query('SELECT * FROM users WHERE username = lower(?) OR original_name = lower(?)', [$username, $username])->result_array();
|
||||
$registered = $this->db->query('SELECT * FROM users WHERE username = lower(?) OR originalName = lower(?)', [$username, $username])->result_array();
|
||||
|
||||
if (empty($registered)) {
|
||||
return '';
|
||||
@@ -144,7 +144,7 @@
|
||||
{
|
||||
$encryptedPassword = $this->LoginModel->getPasswordHash($password, strtolower($username));
|
||||
$activation_key = hash("sha512", uniqid(rand(), true)) . hash("sha512", uniqid(rand(), true));
|
||||
$this->db->query('INSERT INTO users (original_name, username, displayname, login_method, password, email, rank, is_activated, activation_key) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', [strtolower($username), strtolower($username), $username, $login_method, $encryptedPassword, $email, 1, false, $activation_key]);
|
||||
$this->db->query('INSERT INTO users (originalName, username, displayname, login_method, password, email, rank, activated, activation_key) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', [strtolower($username), strtolower($username), $username, $login_method, $encryptedPassword, $email, 1, false, $activation_key]);
|
||||
|
||||
$this->db->cache_delete('admin', 'users');
|
||||
|
||||
@@ -178,7 +178,7 @@
|
||||
|
||||
public function hashMailExists($emailHash, $activation_key)
|
||||
{
|
||||
$results = $this->db->query('SELECT ID FROM users WHERE MD5(email) = ? AND is_activated = 0 AND activation_key = ?', [$emailHash, $activation_key])->result_array();
|
||||
$results = $this->db->query('SELECT ID FROM users WHERE MD5(email) = ? AND activated = 0 AND activation_key = ?', [$emailHash, $activation_key])->result_array();
|
||||
if (!empty($results)) {
|
||||
return $results[0]['ID'];
|
||||
} else {
|
||||
@@ -188,7 +188,7 @@
|
||||
|
||||
public function activateMail($id)
|
||||
{
|
||||
$this->db->query('UPDATE users SET is_activated = 1, activation_key = NULL WHERE ID = ? LIMIT 1', [$id]);
|
||||
$this->db->query('UPDATE users SET activated = 1, activation_key = NULL WHERE ID = ? LIMIT 1', [$id]);
|
||||
|
||||
// Clear cached queries
|
||||
$username = $this->db->query('SELECT username FROM users WHERE ID = ?', [$id])->result_array();
|
||||
@@ -199,14 +199,14 @@
|
||||
public function changeMailAddress($email, $username)
|
||||
{
|
||||
$activation_key = hash("sha512", uniqid(rand(), true)) . hash("sha512", uniqid(rand(), true));
|
||||
$this->db->query('UPDATE users SET email = lower(?), is_activated = FALSE, activation_key = ? WHERE username = ?', [$email, $activation_key, $username]);
|
||||
$this->db->query('UPDATE users SET email = lower(?), activated = FALSE, activation_key = ? WHERE username = ?', [$email, $activation_key, $username]);
|
||||
$this->db->cache_delete('admin', 'users');
|
||||
}
|
||||
|
||||
public function changePassword($newPassword, $original_name)
|
||||
public function changePassword($newPassword, $originalName)
|
||||
{
|
||||
$encryptedPassword = $this->getPasswordHash($newPassword, $original_name);
|
||||
$this->db->query('UPDATE users SET password = ? WHERE original_name = ?', [$encryptedPassword, $original_name]);
|
||||
$encryptedPassword = $this->getPasswordHash($newPassword, $originalName);
|
||||
$this->db->query('UPDATE users SET password = ? WHERE originalName = ?', [$encryptedPassword, $originalName]);
|
||||
}
|
||||
|
||||
public function checkPassword($password)
|
||||
|
@@ -27,7 +27,14 @@
|
||||
public function getUserNotificationsRaw($userID, $limit = 20, $offset = 0)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$rawData = $this->db->query('SELECT n.*, count(*) count, s.username senderName, s.displayname senderDisplayname, s.profile_picture senderPicture, r.username recipientName, r.displayName recipientDisplayname FROM notifications n LEFT JOIN users s ON n.senderID = s.ID LEFT JOIN users r ON n.recipientID = r.ID WHERE recipientID = ? GROUP BY type, referenceID ORDER BY createdAt DESC, unread DESC LIMIT ? OFFSET ?', [$userID, $limit, $offset])->result_array();
|
||||
$rawData = $this->db->query('SELECT n.*, count(*) count, s.username senderName, s.displayname senderDisplayname, ss.profilePicture senderPicture, r.username recipientName, r.displayName recipientDisplayname
|
||||
FROM notifications n
|
||||
LEFT JOIN users s ON n.senderID = s.ID
|
||||
LEFT JOIN user_settings ss ON s.ID = ss.ID
|
||||
LEFT JOIN users r ON n.recipientID = r.ID
|
||||
WHERE recipientID = ?
|
||||
GROUP BY type, referenceID
|
||||
ORDER BY createdAt DESC, unread DESC LIMIT ? OFFSET ?', [$userID, $limit, $offset])->result_array();
|
||||
|
||||
$notifications = [];
|
||||
foreach ($rawData as $notification) {
|
||||
@@ -36,7 +43,13 @@
|
||||
if ($notificationGroup['count'] == 1) {
|
||||
$notificationGroup['items'] = [$notification];
|
||||
} else {
|
||||
$notificationGroup['items'] = $this->db->query('SELECT n.*, s.username senderName, s.displayname senderDisplayname, s.profile_picture senderPicture, r.username recipientName, r.displayName recipientDisplayname FROM notifications n LEFT JOIN users s ON n.senderID = s.ID LEFT JOIN users r ON n.recipientID = r.ID WHERE recipientID = ? AND type = ? AND referenceID = ? LIMIT 5', [$userID, $notification['type'], $notification['referenceID']])->result_array();
|
||||
$notificationGroup['items'] = $this->db->query('SELECT n.*, s.username senderName, s.displayname senderDisplayname, ss.profilePicture senderPicture, r.username recipientName, r.displayName recipientDisplayname
|
||||
FROM notifications n
|
||||
LEFT JOIN users s ON n.senderID = s.ID
|
||||
LEFT JOIN user_settings ss ON s.ID = ss.ID
|
||||
LEFT JOIN users r ON n.recipientID = r.ID
|
||||
WHERE recipientID = ? AND type = ? AND referenceID = ?
|
||||
LIMIT 5', [$userID, $notification['type'], $notification['referenceID']])->result_array();
|
||||
}
|
||||
|
||||
$notifications[] = $notificationGroup;
|
||||
|
@@ -15,43 +15,30 @@
|
||||
return $this->addReply($userID, $content, NULL);
|
||||
}
|
||||
|
||||
public function addReply($userID, $content, $replyToUUID)
|
||||
public function addReply($userID, $content, $replyToHashID)
|
||||
{
|
||||
$content = $this->preparePostContent($content);
|
||||
$uuid = $this->generatePostUUID($userID, $content);
|
||||
$hashID = $this->generatePostHashID($userID, $content);
|
||||
$replyTo = NULL;
|
||||
if ($replyToUUID !== NULL) {
|
||||
$replyToID = $this->db->query('SELECT ID FROM user_posts WHERE uuid = ?', [$replyToUUID])->result_array();
|
||||
if ($replyToHashID !== NULL) {
|
||||
$replyToID = $this->db->query('SELECT ID FROM user_posts WHERE hashID = ?', [$replyToHashID])->result_array();
|
||||
$replyTo = !empty($replyToID) ? $replyToID[0]['ID'] : NULL;
|
||||
}
|
||||
$this->db->query('INSERT INTO user_posts (user_id, content, uuid, reply_to) VALUES (?, ?, ?, ?)', [$userID, $content, $uuid, $replyTo]);
|
||||
$this->db->query('INSERT INTO user_posts (userID, content, hashID, replyToPostID) VALUES (?, ?, ?, ?)', [$userID, $content, $hashID, $replyTo]);
|
||||
|
||||
|
||||
$insertedPost = $this->db->query('SELECT ID, user_id FROM user_posts WHERE uuid = ?', [$uuid])->result_array();
|
||||
$this->addPostMentions($insertedPost[0]['ID'], $content, $uuid);
|
||||
$insertedPost = $this->db->query('SELECT ID, userID FROM user_posts WHERE hashID = ?', [$hashID])->result_array();
|
||||
$this->addPostMentions($insertedPost[0]['ID'], $content, $hashID);
|
||||
$this->addPostHashtags($insertedPost[0]['ID'], $content);
|
||||
|
||||
// Send notification to user whose post was replied to
|
||||
if ($userID != $insertedPost[0]['user_id']) {
|
||||
$this->NotificationModel->userNotificationPostReply($userID, $insertedPost[0]['user_id'], $insertedPost[0]['ID'], $uuid);
|
||||
if ($userID != $insertedPost[0]['userID']) {
|
||||
$this->NotificationModel->userNotificationPostReply($userID, $insertedPost[0]['userID'], $insertedPost[0]['ID'], $hashID);
|
||||
}
|
||||
|
||||
return $insertedPost[0]['ID'];
|
||||
}
|
||||
|
||||
public function deletePost($userID, $uuid) {
|
||||
$postID = $this->db->query('SELECT ID FROM user_posts WHERE user_id = ? AND uuid = ?', [$userID, $uuid])->result_array()[0]['ID'];
|
||||
$this->db->query('DELETE FROM user_posts WHERE user_id = ? AND uuid = ?', [$userID, $uuid]);
|
||||
$this->db->query('DELETE FROM user_posts_hashtags WHERE postID = ?', [$postID]);
|
||||
$this->db->query('DELETE FROM user_posts_mentions WHERE postID = ?', [$postID]);
|
||||
$this->db->query('DELETE FROM user_posts_likes WHERE postID = ?', [$postID]);
|
||||
$this->db->query('DELETE FROM user_posts_media WHERE postID = ?', [$postID]);
|
||||
}
|
||||
|
||||
public function addMediaToPost($postID, $type, $fileID) {
|
||||
$this->db->query('INSERT INTO user_posts_media (postID, mediaType, fileID) VALUES (?, ?, ?)', [$postID, $type, $fileID]);
|
||||
}
|
||||
|
||||
public function preparePostContent($content)
|
||||
{
|
||||
if ($this->endsWith($content, '<br> ')) {
|
||||
@@ -69,12 +56,7 @@
|
||||
(substr($haystack, -$length) === $needle);
|
||||
}
|
||||
|
||||
function generatePostUUID($userID, $content)
|
||||
{
|
||||
return md5($userID . $content . date("Y-m-d H:i:s"));
|
||||
}
|
||||
|
||||
public function addPostMentions($postID, $content, $postUUID)
|
||||
public function addPostMentions($postID, $content, $postHashID)
|
||||
{
|
||||
preg_match_all('/@([A-Za-z0-9._]+)/', $content, $mentions, PREG_OFFSET_CAPTURE);
|
||||
foreach ($mentions[1] as $mention) {
|
||||
@@ -83,16 +65,16 @@
|
||||
continue;
|
||||
}
|
||||
$mentionedUser = $mentionedUser[0];
|
||||
$this->addMention($postID, $_SESSION['user']['ID'], $mentionedUser['ID'], $mention[1], $postUUID);
|
||||
$this->addMention($postID, $_SESSION['user']['ID'], $mentionedUser['ID'], $mention[1], $postHashID);
|
||||
}
|
||||
}
|
||||
|
||||
public function addMention($postID, $userID, $mentionedUserID, $position, $postUUID)
|
||||
public function addMention($postID, $userID, $mentionedUserID, $position, $postHashID)
|
||||
{
|
||||
$this->db->query('INSERT INTO user_posts_mentions (userID, postID, mentionedUserID, position) VALUES (?, ?, ?, ?)', [$userID, $postID, $mentionedUserID, $position]);
|
||||
|
||||
// Send notification
|
||||
$this->NotificationModel->userNotificationPostMentioned($userID, $mentionedUserID, $postID, $postUUID);
|
||||
$this->NotificationModel->userNotificationPostMentioned($userID, $mentionedUserID, $postID, $postHashID);
|
||||
}
|
||||
|
||||
public function addPostHashtags($postID, $content)
|
||||
@@ -108,10 +90,30 @@
|
||||
$this->db->query('INSERT INTO user_posts_hashtags (userID, postID, hashtag, position) VALUES (?, ?, ?, ?)', [$userID, $postID, $hashtag, $position]);
|
||||
}
|
||||
|
||||
public function deletePost($userID, $hashID)
|
||||
{
|
||||
$postID = $this->db->query('SELECT ID FROM user_posts WHERE userID = ? AND hashID = ?', [$userID, $hashID])->result_array()[0]['ID'];
|
||||
$this->db->query('DELETE FROM user_posts WHERE userID = ? AND hashID = ?', [$userID, $hashID]);
|
||||
$this->db->query('DELETE FROM user_posts_hashtags WHERE postID = ?', [$postID]);
|
||||
$this->db->query('DELETE FROM user_posts_mentions WHERE postID = ?', [$postID]);
|
||||
$this->db->query('DELETE FROM user_posts_likes WHERE postID = ?', [$postID]);
|
||||
$this->db->query('DELETE FROM user_posts_media WHERE postID = ?', [$postID]);
|
||||
}
|
||||
|
||||
public function addMediaToPost($postID, $type, $fileID)
|
||||
{
|
||||
$this->db->query('INSERT INTO user_posts_media (postID, mediaType, fileID) VALUES (?, ?, ?)', [$postID, $type, $fileID]);
|
||||
}
|
||||
|
||||
function generatePostHashID($userID, $content)
|
||||
{
|
||||
return md5($userID . $content . date("Y-m-d H:i:s"));
|
||||
}
|
||||
|
||||
function getUserPosts($id, $count, $offset, $maxLength = 250)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$posts = $this->db->query('SELECT * FROM user_posts p WHERE user_id = ? ORDER BY date DESC LIMIT ? OFFSET ?', [$id, $count, $offset])->result_array();
|
||||
$posts = $this->db->query('SELECT * FROM user_posts p WHERE userID = ? ORDER BY date DESC LIMIT ? OFFSET ?', [$id, $count, $offset])->result_array();
|
||||
$this->db->cache_on();
|
||||
|
||||
$posts = $this->preparePostList($posts, $maxLength);
|
||||
@@ -136,38 +138,32 @@
|
||||
$post = $this->mergeUserHasLiked($post, $_SESSION['user']['ID']);
|
||||
}
|
||||
|
||||
if($post['reply_to'] != NULL) {
|
||||
if ($post['replyToPostID'] != NULL) {
|
||||
$post = $this->mergeReplyData($post);
|
||||
}
|
||||
|
||||
$postList[$i] = $post;
|
||||
}
|
||||
|
||||
$postList = $this->UserModel->setDefaultImages($postList);
|
||||
|
||||
return $postList;
|
||||
}
|
||||
|
||||
public function getPostMedia($postID) {
|
||||
$result = $this->db->query('SELECT m.mediaType type, f.name name FROM user_posts_media m LEFT JOIN files f ON f.ID = m.fileID WHERE postID = ?', [$postID])->result_array();
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function mergePostUserData($post)
|
||||
{
|
||||
$user = $this->UserModel->getUserByID($post['user_id']);
|
||||
$user = $this->UserModel->getUserByID($post['userID']);
|
||||
$user = $user[0];
|
||||
|
||||
$post['username'] = $user['username'];
|
||||
$post['displayname'] = $user['displayname'];
|
||||
$post['profile_picture'] = $user['profile_picture'];
|
||||
$post['profilePicture'] = $user['profilePicture'];
|
||||
return $post;
|
||||
}
|
||||
|
||||
public function getPostReplyCountByID($postID)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$data = $this->db->query('SELECT count(*) replyCount FROM user_posts WHERE reply_to = ?', [$postID])->result_array();
|
||||
$data = $this->db->query('SELECT count(*) replyCount FROM user_posts WHERE replyToPostID = ?', [$postID])->result_array();
|
||||
$this->db->cache_on();
|
||||
|
||||
return $data[0]['replyCount'];
|
||||
@@ -214,10 +210,16 @@
|
||||
return $finalContent;
|
||||
}
|
||||
|
||||
public function getPostMedia($postID)
|
||||
{
|
||||
$result = $this->db->query('SELECT m.mediaType type, f.name name FROM user_posts_media m LEFT JOIN files f ON f.ID = m.fileID WHERE postID = ?', [$postID])->result_array();
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function mergeUserHasLiked($post, $userID)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$data = $this->db->query('SELECT * FROM user_posts_likes WHERE postID = (SELECT ID FROM user_posts WHERE uuid = ?) AND likerUserID = ?', [$post['uuid'], $userID])->result_array();
|
||||
$data = $this->db->query('SELECT * FROM user_posts_likes WHERE postID = (SELECT ID FROM user_posts WHERE hashID = ?) AND likerUserID = ?', [$post['hashID'], $userID])->result_array();
|
||||
$this->db->cache_on();
|
||||
|
||||
if (empty($data)) {
|
||||
@@ -228,10 +230,11 @@
|
||||
return $post;
|
||||
}
|
||||
|
||||
private function mergeReplyData($post) {
|
||||
$data = $this->db->query('SELECT p.*, username, displayname FROM user_posts p LEFT JOIN users ON users.ID = p.user_id WHERE p.ID = ?', [$post['reply_to']])->result_array();
|
||||
private function mergeReplyData($post)
|
||||
{
|
||||
$data = $this->db->query('SELECT p.* FROM user_posts p WHERE p.ID = ?', [$post['replyToPostID']])->result_array();
|
||||
$data = $this->preparePostList($data);
|
||||
if(!empty($data)) {
|
||||
if (!empty($data)) {
|
||||
$post['replyToPost'] = $data[0];
|
||||
} else {
|
||||
$post['replyToPost'] = [
|
||||
@@ -259,7 +262,7 @@
|
||||
public function getFeedPosts($userID, $amount, $offset)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$data = $this->db->query('SELECT * FROM user_posts WHERE user_id IN (SELECT followedUserID FROM user_followers WHERE followerUserID = ?) OR ID IN(SELECT postID FROM user_posts_mentions WHERE mentionedUserID = ?) OR ID IN (SELECT postID FROM user_posts_likes WHERE likedUserID = ?) OR user_id = ? ORDER BY date DESC LIMIT ? OFFSET ?', [$userID, $userID, $userID, $userID, $amount, $offset])->result_array();
|
||||
$data = $this->db->query('SELECT * FROM user_posts WHERE userID IN (SELECT followedUserID FROM user_followers WHERE followerUserID = ?) OR ID IN(SELECT postID FROM user_posts_mentions WHERE mentionedUserID = ?) OR ID IN (SELECT postID FROM user_posts_likes WHERE likedUserID = ?) OR userID = ? ORDER BY date DESC LIMIT ? OFFSET ?', [$userID, $userID, $userID, $userID, $amount, $offset])->result_array();
|
||||
$this->db->cache_on();
|
||||
|
||||
$data = $this->preparePostList($data);
|
||||
@@ -270,7 +273,7 @@
|
||||
public function getPopularPosts($amount, $offset)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$data = $this->db->query('SELECT * FROM user_posts p ORDER BY ((SELECT count(*) FROM user_posts_likes WHERE postID = p.ID) + (SELECT count(*) FROM user_posts WHERE reply_to = p.ID)) DESC, date DESC LIMIT ? OFFSET ?', [$amount, $offset])->result_array();
|
||||
$data = $this->db->query('SELECT * FROM user_posts p ORDER BY ((SELECT count(*) FROM user_posts_likes WHERE postID = p.ID) + (SELECT count(*) FROM user_posts WHERE replyToPostID = p.ID)) DESC, date DESC LIMIT ? OFFSET ?', [$amount, $offset])->result_array();
|
||||
$this->db->cache_on();
|
||||
|
||||
$data = $this->preparePostList($data);
|
||||
@@ -278,10 +281,10 @@
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getPostDetails($userID, $uuid)
|
||||
public function getPostDetails($userID, $hashID)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$data = $this->db->query('SELECT * FROM user_posts WHERE user_id = ? AND uuid = ?', [$userID, $uuid])->result_array();
|
||||
$data = $this->db->query('SELECT * FROM user_posts WHERE userID = ? AND hashID = ?', [$userID, $hashID])->result_array();
|
||||
$this->db->cache_on();
|
||||
|
||||
$data = $this->preparePostList($data, -1);
|
||||
@@ -292,7 +295,7 @@
|
||||
public function getPostReplies($postID)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$replies = $this->db->query('SELECT * FROM user_posts WHERE reply_to = ? ORDER BY date', [$postID])->result_array();
|
||||
$replies = $this->db->query('SELECT * FROM user_posts WHERE replyToPostID = ? ORDER BY date', [$postID])->result_array();
|
||||
$this->db->cache_on();
|
||||
|
||||
$replies = $this->preparePostList($replies);
|
||||
@@ -300,33 +303,34 @@
|
||||
return $replies;
|
||||
}
|
||||
|
||||
public function getPostByUUID($uuid) {
|
||||
public function getPostByHashID($hashID)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$result = $this->db->query('SELECT * FROM user_posts WHERE uuid = ?', [$uuid])->result_array();
|
||||
$result = $this->db->query('SELECT * FROM user_posts WHERE hashID = ?', [$hashID])->result_array();
|
||||
$this->db->cache_on();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function addPostLikeByUUID($uuid, $userID)
|
||||
public function addPostLikeByHashID($hashID, $userID)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$data = $this->db->query('SELECT * FROM user_posts_likes WHERE postID = (SELECT ID FROM user_posts WHERE uuid = ?) AND likerUserID = ?', [$uuid, $userID])->result_array();
|
||||
$data = $this->db->query('SELECT * FROM user_posts_likes WHERE postID = (SELECT ID FROM user_posts WHERE hashID = ?) AND likerUserID = ?', [$hashID, $userID])->result_array();
|
||||
$this->db->cache_on();
|
||||
|
||||
// IDs needed for handling notifications later
|
||||
$postUser = $this->db->query('SELECT ID FROM users WHERE ID = (SELECT user_id FROM user_posts WHERE uuid = ?)', [$uuid])->result_array();
|
||||
$postID = $this->db->query('SELECT ID FROM user_posts WHERE uuid = ?', [$uuid])->result_array();
|
||||
$postUser = $this->db->query('SELECT ID FROM users WHERE ID = (SELECT userID FROM user_posts WHERE hashID = ?)', [$hashID])->result_array();
|
||||
$postID = $this->db->query('SELECT ID FROM user_posts WHERE hashID = ?', [$hashID])->result_array();
|
||||
if (empty($data)) {
|
||||
$this->db->query('INSERT INTO user_posts_likes (postID, likedUserID, likerUserID) VALUES ((SELECT ID FROM user_posts WHERE uuid = ?), (SELECT user_id FROM user_posts WHERE uuid = ?), ?)', [$uuid, $uuid, $userID]);
|
||||
$this->db->query('INSERT INTO user_posts_likes (postID, likedUserID, likerUserID) VALUES ((SELECT ID FROM user_posts WHERE hashID = ?), (SELECT userID FROM user_posts WHERE hashID = ?), ?)', [$hashID, $hashID, $userID]);
|
||||
|
||||
// Send like notification
|
||||
if ($postUser[0]['ID'] != $userID) {
|
||||
$this->NotificationModel->userNotificationPostLike($userID, $postUser[0]['ID'], $postID[0]['ID'], $uuid);
|
||||
$this->NotificationModel->userNotificationPostLike($userID, $postUser[0]['ID'], $postID[0]['ID'], $hashID);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
$this->db->query('DELETE FROM user_posts_likes WHERE postID = (SELECT ID FROM user_posts WHERE uuid = ?) AND likerUserID = ?', [$uuid, $userID]);
|
||||
$this->db->query('DELETE FROM user_posts_likes WHERE postID = (SELECT ID FROM user_posts WHERE hashID = ?) AND likerUserID = ?', [$hashID, $userID]);
|
||||
|
||||
// Remove existing notification
|
||||
$this->NotificationModel->removeNotification($userID, $postUser[0]['ID'], $postID[0]['ID'], 'users.likedPost');
|
||||
@@ -336,18 +340,18 @@
|
||||
|
||||
}
|
||||
|
||||
public function getPostLikeCountByUUID($uuid)
|
||||
public function getPostLikeCountByHashID($hashID)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$data = $this->db->query('SELECT count(*) likeCount FROM user_posts_likes WHERE postID = (SELECT ID FROM user_posts WHERE uuid = ?)', [$uuid])->result_array();
|
||||
$data = $this->db->query('SELECT count(*) likeCount FROM user_posts_likes WHERE postID = (SELECT ID FROM user_posts WHERE hashID = ?)', [$hashID])->result_array();
|
||||
$this->db->cache_on();
|
||||
return $data[0]['likeCount'];
|
||||
}
|
||||
|
||||
public function isUUIDValid($uuid)
|
||||
public function isHashIDValid($hashID)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$data = $this->db->query('SELECT ID FROM user_posts WHERE uuid = ?', [$uuid])->result_array();
|
||||
$data = $this->db->query('SELECT ID FROM user_posts WHERE hashID = ?', [$hashID])->result_array();
|
||||
$this->db->cache_on();
|
||||
return !empty($data);
|
||||
}
|
||||
@@ -376,7 +380,7 @@
|
||||
public function searchPosts($query, $limit = 20, $offset = 0)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$results = $this->db->query('SELECT * FROM user_posts WHERE content RLIKE ? OR (SELECT username FROM users WHERE ID = user_id) RLIKE ? ORDER BY (SELECT count(*) FROM user_posts_likes WHERE postID = ID) DESC, (SELECT count(*) FROM user_posts WHERE user_posts.reply_to = ID) DESC, date DESC LIMIT ? OFFSET ?', [$query, $query, $limit, $offset])->result_array();
|
||||
$results = $this->db->query('SELECT * FROM user_posts WHERE content RLIKE ? OR (SELECT username FROM users WHERE ID = userID) RLIKE ? ORDER BY (SELECT count(*) FROM user_posts_likes WHERE postID = ID) DESC, (SELECT count(*) FROM user_posts WHERE replyToPostID = ID) DESC, date DESC LIMIT ? OFFSET ?', [$query, $query, $limit, $offset])->result_array();
|
||||
$this->db->cache_on();
|
||||
|
||||
$results = $this->preparePostList($results);
|
||||
@@ -384,14 +388,15 @@
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function reportPost($uuid, $reason, $reasonText) {
|
||||
$this->db->query('INSERT INTO user_posts_reports (postID, reason, reasonText) VALUES ((SELECT ID FROM user_posts WHERE uuid = ?), ?, ?)', [$uuid, $reason, $reasonText]);
|
||||
public function reportPost($hashID, $reason, $reasonText)
|
||||
{
|
||||
$this->db->query('INSERT INTO user_posts_reports (postID, reason, reasonText) VALUES ((SELECT ID FROM user_posts WHERE hashID = ?), ?, ?)', [$hashID, $reason, $reasonText]);
|
||||
$this->db->cache_delete('admin', 'reports');
|
||||
|
||||
// Send notification
|
||||
$postID = $this->db->query('SELECT ID FROM user_posts WHERE uuid = ?', [$uuid])->result_array();
|
||||
$postID = $this->db->query('SELECT ID FROM user_posts WHERE hashID = ?', [$hashID])->result_array();
|
||||
$this->NotificationModel->rankNotificationPostReport(
|
||||
isset($_SESSION['user']) ? $_SESSION['user']['ID'] : -1,
|
||||
8, $postID[0]['ID'], $uuid);
|
||||
8, $postID[0]['ID'], $hashID);
|
||||
}
|
||||
}
|
@@ -26,18 +26,38 @@
|
||||
public function mergeTranslationData($postList, $lang = 'de')
|
||||
{
|
||||
foreach ($postList as $i => $post) {
|
||||
$data = $this->db->query('SELECT * FROM projects_translations WHERE projectID = ? AND (lang = ? OR lang = ?) ORDER BY lang', [$post['ID'], 'de', $lang])->result_array();
|
||||
if (sizeof($data) == 1) {
|
||||
$postList[$i] = array_merge($post, $data[0]);
|
||||
$data = $this->db->query('SELECT title, description, content, downloadName, openSourceName, customLinkName FROM projects_translations WHERE projectID = ? AND lang = ? ORDER BY lang', [$post['ID'], 'de'])->result_array();
|
||||
|
||||
if(empty($data)) {
|
||||
$postList[$i] = array_merge($post, [
|
||||
'title' => 'Not found',
|
||||
'description' => 'Not found',
|
||||
'content' => 'Not found',
|
||||
]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$data = $data[0];
|
||||
if($lang == 'de') {
|
||||
$postList[$i] = array_merge($post, $data);
|
||||
continue;
|
||||
}
|
||||
|
||||
$dataLang = $this->db->query('SELECT title, description, content, downloadName, openSourceName, customLinkName FROM projects_translations WHERE projectID = ? AND lang = ? ORDER BY lang', [$post['ID'], $lang])->result_array();
|
||||
|
||||
if (empty($dataLang)) {
|
||||
$postList[$i] = array_merge($post, $data);
|
||||
continue;
|
||||
}
|
||||
|
||||
$dataLang = $dataLang[0];
|
||||
|
||||
$merged = [];
|
||||
foreach ($data[0] as $key => $value) {
|
||||
if (($value == NULL && $data[1][$key] == NULL) || ($value != NULL && $data[1][$key] == NULL)) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (($value == NULL && $dataLang[$key] == NULL) || ($value != NULL && $dataLang[$key] == NULL)) {
|
||||
$merged[$key] = $value;
|
||||
} else {
|
||||
$merged[$key] = $data[1][$key];
|
||||
$merged[$key] = $dataLang[$key];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,10 +68,29 @@
|
||||
|
||||
public function getCategories()
|
||||
{
|
||||
$collections = $this->db->query('SELECT c.*, count(p.projectID) count FROM projects_categories c LEFT JOIN projects_entry_categories p ON c.ID = p.categoryID GROUP BY c.ID ORDER BY c.collection')->result_array();
|
||||
$collections = $this->db->query('SELECT c.*, count(p.projectID) count FROM projects_categories c LEFT JOIN projects_entry_categories p ON c.categoryID = p.categoryID GROUP BY c.categoryID ORDER BY c.name')->result_array();
|
||||
|
||||
if($_SESSION['site_lang'] !== 'de') {
|
||||
$collectionsLang = $this->db->query('SELECT categoryID, name, displayname FROM projects_categories WHERE lang = ?', [$_SESSION['site_lang']])->result_array();
|
||||
|
||||
$categoryIDs = array_column($collections, 'categoryID');
|
||||
foreach ($collectionsLang as $item) {
|
||||
$key = array_search($item['categoryID'], $categoryIDs);
|
||||
$collections[$key] = array_merge($collections[$key], $item);
|
||||
}
|
||||
}
|
||||
|
||||
return $collections;
|
||||
}
|
||||
|
||||
public function getCategoriesRaw() {
|
||||
$categories = $this->db->query('SELECT ID, GROUP_CONCAT(c.name) name, GROUP_CONCAT(c.displayname) displayname, (SELECT COUNT(*) FROM projects_entry_categories p WHERE c.categoryID = p.categoryID) count
|
||||
FROM projects_categories c
|
||||
GROUP BY c.categoryID
|
||||
ORDER BY ID')->result_array();
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public function editEntry($data, $id)
|
||||
{
|
||||
$this->db->update('projects', $data, ['id' => $id]);
|
||||
@@ -120,7 +159,19 @@
|
||||
|
||||
public function getEntryCategories($id)
|
||||
{
|
||||
return $this->db->query('SELECT * FROM projects_categories WHERE ID IN (SELECT categoryID FROM projects_entry_categories WHERE projectID = ?)', [$id])->result_array();
|
||||
$categories = $this->db->query('SELECT * FROM projects_categories WHERE ID IN (SELECT categoryID FROM projects_entry_categories WHERE projectID = ?) AND lang = "de"', [$id])->result_array();
|
||||
|
||||
if($_SESSION['site_lang'] != 'de') {
|
||||
$categoriesLang = $this->db->query('SELECT categoryID, name, displayname FROM projects_categories WHERE lang = ?', [$_SESSION['site_lang']])->result_array();
|
||||
|
||||
$categoryIDs = array_column($categories, 'categoryID');
|
||||
foreach ($categoriesLang as $item) {
|
||||
$key = array_search($item['categoryID'], $categoryIDs);
|
||||
$categories[$key] = array_merge($categories[$key], $item);
|
||||
}
|
||||
}
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public function updateCategories($postID, $categories)
|
||||
|
@@ -50,44 +50,44 @@
|
||||
|
||||
$possibilities = [
|
||||
'blogPost' => [
|
||||
'sql' => 'SELECT "blogPost" type, bp.postUrl url, bp.postAuthorID author, bp.postImage image, bt.postTitle title, bt.postDesc content, bp.postPublishDate date
|
||||
FROM blog_posts bp
|
||||
INNER JOIN blog_translations bt ON bt.postID = bp.postID AND bt.language = ?
|
||||
LEFT JOIN blog_content bc ON bc.postID = bp.postID AND bc.isActive = TRUE AND bc.language = ?
|
||||
WHERE (LOWER(bt.postTitle) RLIKE ?
|
||||
OR LOWER(bt.postDesc) RLIKE ?
|
||||
OR LOWER(bc.content) RLIKE ?
|
||||
OR bp.postID IN (SELECT bpt.post_id FROM blog_post_tags bpt WHERE bpt.tag_id IN(SELECT bt.ID FROM blog_tags bt WHERE bt.name RLIKE ? OR LOWER(bt.display_name) RLIKE ?))
|
||||
OR (SELECT username FROM users WHERE ID = bp.postAuthorID) RLIKE ?
|
||||
OR (SELECT display_name FROM blog_categories WHERE ID = bp.postCategoryID) RLIKE ?)
|
||||
AND postState = 1 AND postIsDeleted = FALSE',
|
||||
'attributes' => 'llqqqqqqq'
|
||||
'sql' => 'SELECT "blogPost" type, v.url url, bp.authorID author, bp.image image, v.title title, v.description content, bp.initialRelease date
|
||||
FROM blog_post bp
|
||||
INNER JOIN blog_post_versions v ON v.postID = bp.ID AND v.lang = ? AND active
|
||||
WHERE (LOWER(v.title) RLIKE ?
|
||||
OR LOWER(v.description) RLIKE ?
|
||||
OR LOWER(v.content) RLIKE ?
|
||||
OR bp.ID IN (SELECT bpt.postID FROM blog_post_tags bpt WHERE bpt.tagID IN (SELECT bt.tagID FROM blog_tags bt WHERE (bt.name RLIKE ? OR LOWER(bt.displayname) RLIKE ?) AND lang = ?))
|
||||
OR bp.ID IN (SELECT bpc.postID FROM blog_post_categories bpc WHERE bpc.categoryID IN (SELECT bc.categoryID FROM blog_categories bc WHERE (bc.name RLIKE ? OR LOWER(bc.displayname) RLIKE ?) AND lang = ?))
|
||||
OR (SELECT username FROM users WHERE ID = bp.authorID) RLIKE ?)
|
||||
AND state = 1',
|
||||
'attributes' => 'lqqqqqlqqlq'
|
||||
],
|
||||
'blogCategory' => [
|
||||
'sql' => 'SELECT "blogCategory" type, c.name url, 1 author, null image, c.display_name title, null content, null date
|
||||
'sql' => 'SELECT "blogCategory" type, c.name url, 1 author, null image, c.displayname title, null content, null date
|
||||
FROM blog_categories c
|
||||
WHERE c.name RLIKE ? OR LOWER(c.display_name) RLIKE ?',
|
||||
'attributes' => 'qq'
|
||||
WHERE (c.name RLIKE ? OR LOWER(c.displayname) RLIKE ?) AND lang = ?',
|
||||
'attributes' => 'qql'
|
||||
],
|
||||
'blogTag' => [
|
||||
'sql' => 'SELECT "blogTag" type, t.name url, 1 author, null image, t.display_name title, null content, null date
|
||||
'sql' => 'SELECT "blogTag" type, t.name url, 1 author, null image, t.displayname title, null content, null date
|
||||
FROM blog_tags t
|
||||
WHERE t.name RLIKE ? OR LOWER(t.display_name) RLIKE ?',
|
||||
'attributes' => 'qq'
|
||||
WHERE (t.name RLIKE ? OR LOWER(t.displayname) RLIKE ?) AND lang = ?',
|
||||
'attributes' => 'qql'
|
||||
],
|
||||
'user' => [
|
||||
'sql' => 'SELECT "user" type, u.username url, u.ID author, u.header_image image, u.displayname title, u.about content, u.date_created date
|
||||
'sql' => 'SELECT "user" type, u.username url, u.ID author, s.headerImage image, u.displayname title, s.about content, u.dateCreated date
|
||||
FROM users u
|
||||
INNER JOIN user_settings s ON u.ID = s.ID
|
||||
WHERE (username RLIKE ?
|
||||
OR lower(about) RLIKE ?)
|
||||
AND is_activated AND isDeleted = FALSE',
|
||||
AND activated AND isDeleted = FALSE',
|
||||
'attributes' => 'qq',
|
||||
],
|
||||
'userPost' => [
|
||||
'sql' => 'SELECT "userPost" type, p.uuid url, p.user_id author, null image, p.content title, null content, p.date date
|
||||
'sql' => 'SELECT "userPost" type, p.hashID url, p.userID author, null image, p.content title, null content, p.date date
|
||||
FROM user_posts p
|
||||
WHERE LOWER(p.content) RLIKE ?
|
||||
OR (SELECT username FROM users WHERE ID = p.user_id) RLIKE ?',
|
||||
OR (SELECT username FROM users WHERE ID = p.userID) RLIKE ?',
|
||||
'attributes' => 'qq',
|
||||
],
|
||||
'project' => [
|
||||
@@ -100,9 +100,9 @@
|
||||
'attributes' => 'lqqq',
|
||||
],
|
||||
'projectCategory' => [
|
||||
'sql' => 'SELECT "projectCategory" type, c.collection url, 1 author, null image, c.displayname title, c.displayname content, null date
|
||||
'sql' => 'SELECT "projectCategory" type, c.name url, 1 author, null image, c.displayname title, c.displayname content, null date
|
||||
FROM projects_categories c
|
||||
WHERE lower(collection) RLIKE ?
|
||||
WHERE name RLIKE ?
|
||||
OR lower(displayname) RLIKE ?',
|
||||
'attributes' => 'qq'
|
||||
],
|
||||
@@ -136,7 +136,6 @@
|
||||
{
|
||||
foreach ($results as $i => $result) {
|
||||
list(
|
||||
'author' => $author,
|
||||
'authorDisplayname' => $displayname,
|
||||
'authorName' => $username,
|
||||
'content' => $content,
|
||||
|
@@ -1,113 +1,126 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class SocialMediaModel extends CI_Model
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
class SocialMediaModel extends CI_Model
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private function getSslPage($url) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_REFERER, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getYouTubeVideos()
|
||||
{
|
||||
$apiUrl = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=20&playlistId=UUEDHiXaIhm2VFu-hi6CcOWw&key=AIzaSyDAZ_TwVMZeiKDQxgWM2OYRq3YskEpY9yw';
|
||||
$apiResult = json_decode($this->getSslPage($apiUrl));
|
||||
$items = $apiResult->items;
|
||||
foreach ($items as $item) {
|
||||
$snippet = $item->snippet;
|
||||
$published = $snippet->publishedAt;
|
||||
$author = $snippet->channelTitle;
|
||||
$author_url = "https://youtube.com/channel/" . $snippet->channelId;
|
||||
$title = $snippet->title;
|
||||
if (isset($snippet->thumbnails->maxres->url)) $thumbnail = $snippet->thumbnails->maxres->url;
|
||||
else $thumbnail = $snippet->thumbnails->standard->url;
|
||||
$url = "http://youtu.be/" . $snippet->resourceId->videoId;
|
||||
|
||||
$this->db->query('INSERT INTO social_posts (post_plattform, post_content, post_url, post_author, post_author_url, post_date, post_img_source) VALUES (?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE post_content = ?, post_img_source = ?;', ["YouTube", $title, $url, $author, $author_url, strtotime($published), $thumbnail, $title, $thumbnail]);
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
|
||||
public function getTwitterPosts()
|
||||
{
|
||||
$consumer_key = 'TsUzd4stukv9Ix7TGG7RdYq4k';
|
||||
$consumer_key_secret = 'sTRq4WcELJZuciTrkNUttGgWhEiGaUkuqNhISgaG4uHRFgzm0B';
|
||||
$access_token = '1880071790-Nij2RaBDVRGVWoWW2PSJUwAvuLAOaQFAAr5tAtC';
|
||||
$access_token_secret = 'ldhLg0SP3ycrrdIqhNcddj0042pdGY9vmZMKQJRClmDkD';
|
||||
|
||||
$oauth_hash = 'count=20&oauth_consumer_key=' . $consumer_key . '&oauth_nonce=' . time() . '&oauth_signature_method=HMAC-SHA1&oauth_timestamp=' . time() . '&oauth_token=' . $access_token . '&oauth_version=1.0';
|
||||
$base = 'GET&' . urlencode('https://api.twitter.com/1.1/statuses/user_timeline.json') . '&' . rawurlencode($oauth_hash);
|
||||
$key = rawurlencode($consumer_key_secret) . '&' . rawurlencode($access_token_secret);
|
||||
$signature = base64_encode(hash_hmac('sha1', $base, $key, true));
|
||||
$signature = rawurlencode($signature);
|
||||
|
||||
$oauth_header = 'oauth_consumer_key="' . $consumer_key . '", oauth_nonce="' . time() . '", oauth_signature="' . $signature . '", oauth_signature_method="HMAC-SHA1", oauth_timestamp="' . time() . '", oauth_token="' . $access_token . '", oauth_version="1.0", ';
|
||||
$curl_header = array("Authorization: Oauth {$oauth_header}", 'Expect:');
|
||||
|
||||
$curl_request = curl_init();
|
||||
curl_setopt($curl_request, CURLOPT_HTTPHEADER, $curl_header);
|
||||
curl_setopt($curl_request, CURLOPT_HEADER, false);
|
||||
curl_setopt($curl_request, CURLOPT_URL, 'https://api.twitter.com/1.1/statuses/user_timeline.json?count=20');
|
||||
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
|
||||
$json = curl_exec($curl_request);
|
||||
curl_close($curl_request);
|
||||
|
||||
$posts = json_decode($json);
|
||||
// private function getSslPage($url) {
|
||||
// $ch = curl_init();
|
||||
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
// curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
// curl_setopt($ch, CURLOPT_URL, $url);
|
||||
// curl_setopt($ch, CURLOPT_REFERER, $url);
|
||||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
// $result = curl_exec($ch);
|
||||
// curl_close($ch);
|
||||
// return $result;
|
||||
// }
|
||||
//
|
||||
// public function getYouTubeVideos()
|
||||
// {
|
||||
// $apiUrl = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=20&playlistId=UUEDHiXaIhm2VFu-hi6CcOWw&key=AIzaSyDAZ_TwVMZeiKDQxgWM2OYRq3YskEpY9yw';
|
||||
// $apiResult = json_decode($this->getSslPage($apiUrl));
|
||||
// $items = $apiResult->items;
|
||||
// foreach ($items as $item) {
|
||||
// $snippet = $item->snippet;
|
||||
// $published = $snippet->publishedAt;
|
||||
// $author = $snippet->channelTitle;
|
||||
// $author_url = "https://youtube.com/channel/" . $snippet->channelId;
|
||||
// $title = $snippet->title;
|
||||
// if (isset($snippet->thumbnails->maxres->url)) $thumbnail = $snippet->thumbnails->maxres->url;
|
||||
// else $thumbnail = $snippet->thumbnails->standard->url;
|
||||
// $url = "http://youtu.be/" . $snippet->resourceId->videoId;
|
||||
//
|
||||
// $this->db->query('INSERT INTO social_posts (origin, post_content, post_url, post_author, post_author_url, date, post_img_source) VALUES (?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE post_content = ?, post_img_source = ?;', ["YouTube", $title, $url, $author, $author_url, strtotime($published), $thumbnail, $title, $thumbnail]);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public function getTwitterPosts()
|
||||
// {
|
||||
// $consumer_key = 'TsUzd4stukv9Ix7TGG7RdYq4k';
|
||||
// $consumer_key_secret = 'sTRq4WcELJZuciTrkNUttGgWhEiGaUkuqNhISgaG4uHRFgzm0B';
|
||||
// $access_token = '1880071790-Nij2RaBDVRGVWoWW2PSJUwAvuLAOaQFAAr5tAtC';
|
||||
// $access_token_secret = 'ldhLg0SP3ycrrdIqhNcddj0042pdGY9vmZMKQJRClmDkD';
|
||||
//
|
||||
// $oauth_hash = 'count=20&oauth_consumer_key=' . $consumer_key . '&oauth_nonce=' . time() . '&oauth_signature_method=HMAC-SHA1&oauth_timestamp=' . time() . '&oauth_token=' . $access_token . '&oauth_version=1.0';
|
||||
// $base = 'GET&' . urlencode('https://api.twitter.com/1.1/statuses/user_timeline.json') . '&' . rawurlencode($oauth_hash);
|
||||
// $key = rawurlencode($consumer_key_secret) . '&' . rawurlencode($access_token_secret);
|
||||
// $signature = base64_encode(hash_hmac('sha1', $base, $key, true));
|
||||
// $signature = rawurlencode($signature);
|
||||
//
|
||||
// $oauth_header = 'oauth_consumer_key="' . $consumer_key . '", oauth_nonce="' . time() . '", oauth_signature="' . $signature . '", oauth_signature_method="HMAC-SHA1", oauth_timestamp="' . time() . '", oauth_token="' . $access_token . '", oauth_version="1.0", ';
|
||||
// $curl_header = array("Authorization: Oauth {$oauth_header}", 'Expect:');
|
||||
//
|
||||
// $curl_request = curl_init();
|
||||
// curl_setopt($curl_request, CURLOPT_HTTPHEADER, $curl_header);
|
||||
// curl_setopt($curl_request, CURLOPT_HEADER, false);
|
||||
// curl_setopt($curl_request, CURLOPT_URL, 'https://api.twitter.com/1.1/statuses/user_timeline.json?count=20');
|
||||
// curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, true);
|
||||
// curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
|
||||
// $json = curl_exec($curl_request);
|
||||
// curl_close($curl_request);
|
||||
//
|
||||
// $posts = json_decode($json);
|
||||
//
|
||||
//
|
||||
// foreach ($posts as $post) {
|
||||
// $content = str_replace("\n", "<br>", $post->text);
|
||||
// $author = $post->user->screen_name;
|
||||
// $author_url = 'https://twitter.com/' . $author;
|
||||
// $url = $author_url . '/status/' . $post->id_str;
|
||||
// $published = strtotime($post->created_at);
|
||||
// $original_id = $post->id_str;
|
||||
// if (isset($post->extended_entities->media[0]->media_url)) {
|
||||
// $image = $post->extended_entities->media[0]->media_url;
|
||||
// } else {
|
||||
// $image = '';
|
||||
// }
|
||||
// $this->db->query('INSERT INTO social_posts (origin, post_content, post_url, post_author, post_author_url, date, post_img_source, post_original_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE post_content = ?, post_author_url = ?, post_original_id = ?;', ["Twitter", $content, $url, $author, $author_url, $published, $image, $original_id, $content, $author_url, $original_id]);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
foreach ($posts as $post) {
|
||||
$content = str_replace("\n", "<br>", $post->text);
|
||||
$author = $post->user->screen_name;
|
||||
$author_url = 'https://twitter.com/' . $author;
|
||||
$url = $author_url . '/status/' . $post->id_str;
|
||||
$published = strtotime($post->created_at);
|
||||
$original_id = $post->id_str;
|
||||
if (isset($post->extended_entities->media[0]->media_url)) {
|
||||
$image = $post->extended_entities->media[0]->media_url;
|
||||
public function newestVids($vidCount)
|
||||
{
|
||||
$data = $this->db->query('SELECT * FROM social_posts WHERE origin = "YouTube" ORDER BY date DESC LIMIT ?', [$vidCount])->result_array();
|
||||
|
||||
if (!empty($data)) {
|
||||
return $data;
|
||||
} else {
|
||||
$image = '';
|
||||
return null;
|
||||
}
|
||||
$this->db->query('INSERT INTO social_posts (post_plattform, post_content, post_url, post_author, post_author_url, post_date, post_img_source, post_original_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE post_content = ?, post_author_url = ?, post_original_id = ?;', ["Twitter", $content, $url, $author, $author_url, $published, $image, $original_id, $content, $author_url, $original_id]);
|
||||
}
|
||||
|
||||
public function getAllPosts()
|
||||
{
|
||||
$this->getTwitterPosts();
|
||||
$items = $this->db->query('SELECT * FROM social_posts ORDER BY date DESC')->result_array();
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function getPosts($amount, $offset)
|
||||
{
|
||||
if ($offset == 0) {
|
||||
$items = $this->db->query('SELECT * FROM social_posts ORDER BY date DESC LIMIT ?', [$amount])->result_array();
|
||||
} else {
|
||||
$items = $this->db->query('SELECT * FROM social_posts ORDER BY date DESC LIMIT ? OFFSET ?', [$amount, $offset])->result_array();
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function getPostsOfCategory($amount, $offset, $category)
|
||||
{
|
||||
if ($offset == 0) {
|
||||
$items = $this->db->query('SELECT * FROM social_posts WHERE origin LIKE ? ORDER BY date DESC LIMIT ?', [$category, $amount])->result_array();
|
||||
} else {
|
||||
$items = $this->db->query('SELECT * FROM social_posts WHERE origin LIKE ? ORDER BY date DESC LIMIT ? OFFSET ?', [$category, $amount, $offset])->result_array();
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllPosts()
|
||||
{
|
||||
$this->getTwitterPosts();
|
||||
$items = $this->db->query('SELECT * FROM social_posts ORDER BY post_date DESC')->result_array();
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function getPosts($amount, $offset)
|
||||
{
|
||||
if($offset == 0) {
|
||||
$items = $this->db->query('SELECT * FROM social_posts ORDER BY post_date DESC LIMIT ?', [$amount])->result_array();
|
||||
} else {
|
||||
$items = $this->db->query('SELECT * FROM social_posts ORDER BY post_date DESC LIMIT ? OFFSET ?', [$amount, $offset])->result_array();
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function getPostsOfCategory($amount, $offset, $category) {
|
||||
if($offset == 0) {
|
||||
$items = $this->db->query('SELECT * FROM social_posts WHERE post_plattform LIKE ? ORDER BY post_date DESC LIMIT ?', [$category, $amount])->result_array();
|
||||
} else {
|
||||
$items = $this->db->query('SELECT * FROM social_posts WHERE post_plattform LIKE ? ORDER BY post_date DESC LIMIT ? OFFSET ?', [$category, $amount, $offset])->result_array();
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@
|
||||
|
||||
function getUser($username)
|
||||
{
|
||||
$result = $this->db->query('SELECT ID, username, displayname, email, rank, profile_picture, header_image, about, social_networks, showAds, date_created, gender, language, country, birthdate, birthyear, receiveEmails, receiveNewsletter FROM users WHERE username = ? AND is_activated = TRUE AND isDeleted = FALSE LIMIT 1', [$username])->result_array();
|
||||
$result = $this->db->query('SELECT u.ID, u.username, u.displayname, u.email, u.rank, u.dateCreated, s.profilePicture, s.headerImage, s.about, s.socialNetworks, s.showAds, s.gender, s.language, s.country, s.birthdate, s.birthyear, s.receiveEmails, s.receiveNewsletter FROM users u INNER JOIN user_settings s ON s.ID = u.ID WHERE username = ? AND activated = TRUE AND isDeleted = FALSE LIMIT 1', [strtolower($username)])->result_array();
|
||||
if (empty($result)) {
|
||||
return null;
|
||||
}
|
||||
@@ -25,11 +25,11 @@
|
||||
public function setDefaultImages($userList)
|
||||
{
|
||||
for ($i = 0; $i < sizeof($userList); $i++) {
|
||||
if ((isset($userList[$i]['header_image']) && ($userList[$i]['header_image'] == '' || $userList[$i]['header_image'] == NULL)) || !isset($userList[$i]['header_image'])) {
|
||||
$userList[$i]['header_image'] = 'https://cdn.kinogofdog.eu' . '/' . $userList[$i]['displayname'];
|
||||
if ((isset($userList[$i]['headerImage']) && ($userList[$i]['headerImage'] == '' || $userList[$i]['headerImage'] == NULL)) || !isset($userList[$i]['headerImage'])) {
|
||||
$userList[$i]['headerImage'] = 'https://cdn.kinogofdog.eu' . '/' . $userList[$i]['displayname'];
|
||||
}
|
||||
if (isset($userList[$i]['profile_picture']) && $userList[$i]['profile_picture'] == '') {
|
||||
$userList[$i]['profile_picture'] = base_url('/f/8d204712d8132b36d765640ce775ce15');
|
||||
if (isset($userList[$i]['profilePicture']) && $userList[$i]['profilePicture'] == '') {
|
||||
$userList[$i]['profilePicture'] = base_url('/f/8d204712d8132b36d765640ce775ce15');
|
||||
}
|
||||
}
|
||||
return $userList;
|
||||
@@ -51,7 +51,18 @@
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function mergeFollowerCount($users) {
|
||||
public function getFollowers($id)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$followers = $this->db->query('SELECT u.ID, followedSince, username, displayname, profilePicture, headerImage FROM user_followers LEFT JOIN users u ON u.ID = followerUserID LEFT JOIN user_settings s ON s.ID = followerUserID WHERE followedUserID = ? AND u.activated = TRUE AND u.isDeleted = FALSE ORDER BY followedSince DESC', [$id])->result_array();
|
||||
$this->db->cache_on();
|
||||
$followers = $this->setDefaultImages($followers);
|
||||
$followers = $this->mergeFollowerCount($followers);
|
||||
return $followers;
|
||||
}
|
||||
|
||||
public function mergeFollowerCount($users)
|
||||
{
|
||||
foreach ($users as $i => $user) {
|
||||
$this->db->cache_off();
|
||||
$followerCount = $this->db->query('SELECT count(*) followerCount FROM user_followers WHERE followedUserID = ?', [$user['ID']])->result_array();
|
||||
@@ -61,19 +72,9 @@
|
||||
return $users;
|
||||
}
|
||||
|
||||
public function getFollowers($id)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$followers = $this->db->query('SELECT ID, followedSince, username, displayname, profile_picture, header_image FROM user_followers LEFT JOIN users ON ID = followerUserID WHERE followedUserID = ? AND is_activated = TRUE AND isDeleted = FALSE ORDER BY followedSince DESC', [$id])->result_array();
|
||||
$this->db->cache_on();
|
||||
$followers = $this->setDefaultImages($followers);
|
||||
$followers = $this->mergeFollowerCount($followers);
|
||||
return $followers;
|
||||
}
|
||||
|
||||
function getUserByID($id)
|
||||
{
|
||||
$result = $this->db->query('SELECT ID, original_name, username, displayname, email, rank, profile_picture, header_image, is_activated, about, lastLogin, social_networks, showAds, date_created, gender, language, country, birthdate, birthyear, receiveEmails, receiveNewsletter FROM users WHERE ID = ? AND is_activated = TRUE AND isDeleted = FALSE LIMIT 1', [$id])->result_array();
|
||||
$result = $this->db->query('SELECT u.ID, originalName, username, displayname, email, rank, profilePicture, headerImage, activated, about, lastLogin, socialNetworks, showAds, dateCreated, gender, language, country, birthdate, birthyear, receiveEmails, receiveNewsletter FROM users u LEFT JOIN user_settings s ON s.ID = u.ID WHERE u.ID = ? AND activated = TRUE AND isDeleted = FALSE LIMIT 1', [$id])->result_array();
|
||||
if (empty($result)) {
|
||||
return null;
|
||||
}
|
||||
@@ -82,15 +83,16 @@
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getUserEmailByID($id) {
|
||||
$result = $this->db->query('SELECT email FROM users WHERE ID = ? AND is_activated = TRUE AND isDeleted = TRUE', [$id])->result_array();
|
||||
function getUserEmailByID($id)
|
||||
{
|
||||
$result = $this->db->query('SELECT email FROM users WHERE ID = ? AND activated = TRUE AND isDeleted = TRUE', [$id])->result_array();
|
||||
return !empty($result) ? $result[0]['email'] : '';
|
||||
}
|
||||
|
||||
public function getFollowing($id)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$following = $this->db->query('SELECT ID, followedSince, username, displayname, profile_picture, header_image FROM user_followers LEFT JOIN users ON ID = followedUserID WHERE followerUserID = ? AND isDeleted = FALSE ORDER BY followedSince DESC', [$id])->result_array();
|
||||
$following = $this->db->query('SELECT u.ID, followedSince, username, displayname, profilePicture, headerImage FROM user_followers LEFT JOIN users u ON u.ID = followedUserID LEFT JOIN user_settings s ON s.ID = followedUserID WHERE followerUserID = ? AND isDeleted = FALSE ORDER BY followedSince DESC', [$id])->result_array();
|
||||
$this->db->cache_on();
|
||||
$following = $this->setDefaultImages($following);
|
||||
$following = $this->mergeFollowerCount($following);
|
||||
@@ -99,15 +101,15 @@
|
||||
|
||||
function getUserComments($id, $count, $offset)
|
||||
{
|
||||
$comments = $this->db->query('SELECT *, p.postUrl FROM blog_comments c LEFT JOIN blog_posts p ON p.postID = c.post_id WHERE user_id = ? ORDER BY date_created DESC LIMIT ? OFFSET ?', [$id, $count, $offset])->result_array();
|
||||
$comments = $this->BlogModel->mergePostTitleDesc($comments);
|
||||
$comments = $this->db->query('SELECT c.* FROM blog_post_comments c WHERE userID = ? ORDER BY date DESC LIMIT ? OFFSET ?', [$id, $count, $offset])->result_array();
|
||||
$comments = $this->BlogModel->mergePostTranslation($comments, false, null, 'postID');
|
||||
return $comments;
|
||||
}
|
||||
|
||||
function getUserBlogPosts($id, $count, $offset)
|
||||
{
|
||||
$posts = $this->db->query('SELECT * FROM blog_posts WHERE postIsDeleted = FALSE AND postState = 1 AND postAuthorID = ? ORDER BY postPublishDate DESC LIMIT ? OFFSET ?', [$id, $count, $offset])->result_array();
|
||||
$posts = $this->BlogModel->mergePostTitleDesc($posts);
|
||||
$posts = $this->db->query('SELECT * FROM blog_post WHERE state = 1 AND authorID = ? ORDER BY initialRelease DESC LIMIT ? OFFSET ?', [$id, $count, $offset])->result_array();
|
||||
$posts = $this->BlogModel->mergePostTranslation($posts);
|
||||
return $posts;
|
||||
}
|
||||
|
||||
@@ -125,11 +127,11 @@
|
||||
FROM user_followers
|
||||
WHERE followerUserID = ?) followedCount
|
||||
FROM user_posts
|
||||
WHERE user_id = ?', [$userID, $userID, $userID])->result_array()[0];
|
||||
WHERE userID = ?', [$userID, $userID, $userID])->result_array()[0];
|
||||
$result['postCount'] = $user['postCount'];
|
||||
$result['followerCount'] = $user['followerCount'];
|
||||
$result['followedCount'] = $user['followedCount'];
|
||||
$blogResults = $this->db->query('SELECT COUNT(*) blogCount, (SELECT COUNT(*) FROM blog_comments WHERE user_id = ?) commentCount FROM blog_posts WHERE postIsDeleted = FALSE AND postState = 1 AND postAuthorID = ?', [$userID, $userID])->result_array()[0];
|
||||
$blogResults = $this->db->query('SELECT COUNT(*) blogCount, (SELECT COUNT(*) FROM blog_post_comments WHERE userID = ?) commentCount FROM blog_post WHERE state = 1 AND authorID = ?', [$userID, $userID])->result_array()[0];
|
||||
$result['blogCount'] = $blogResults['blogCount'];
|
||||
$result['commentCount'] = $blogResults['commentCount'];
|
||||
$this->db->cache_on();
|
||||
@@ -162,19 +164,39 @@ WHERE user_id = ?', [$userID, $userID, $userID])->result_array()[0];
|
||||
|
||||
function updateProfile($data, $id)
|
||||
{
|
||||
$this->db->where('ID', $id);
|
||||
$this->db->update('users', $data);
|
||||
function in_data1($val) {
|
||||
return in_array($val, ['username', 'displayname', 'email', 'password']);
|
||||
}
|
||||
|
||||
$data1 = array_filter($data, "in_data1");
|
||||
if(!empty($data1)) {
|
||||
$this->db->where('ID', $id);
|
||||
$this->db->update('users', $data1);
|
||||
}
|
||||
|
||||
$data2 = array_diff($data, $data1);
|
||||
if(!empty($data2)) {
|
||||
$this->db->where('ID', $id);
|
||||
$this->db->update('user_settings', $data2);
|
||||
}
|
||||
}
|
||||
|
||||
function insertIntoHistory($data)
|
||||
{
|
||||
unset($data['date_created']);
|
||||
$this->db->insert('users_history', $data);
|
||||
if(isset($data['password'])) {
|
||||
unset($data['password']);
|
||||
$data['passwordChanged'] = true;
|
||||
}
|
||||
|
||||
$this->db->insert('user_settings_history', $data);
|
||||
}
|
||||
|
||||
function getUserList($amount, $offset)
|
||||
{
|
||||
$data = $this->db->query('SELECT ID, username, displayname, rank, profile_picture, header_image, is_activated, showAds, receiveEmails, receiveNewsletter, date_created, isCurrentlyOnline, lastLogin, login_method, language, country, gender FROM users LIMIT ? OFFSET ?', [$amount, $offset])->result_array();
|
||||
$data = $this->db->query('SELECT u.ID, username, displayname, rank, profilePicture, headerImage, activated, showAds, receiveEmails, receiveNewsletter, dateCreated, isCurrentlyOnline, lastLogin, loginMethod, language, country, gender
|
||||
FROM users u
|
||||
LEFT JOIN user_settings s ON u.ID = s.ID
|
||||
LIMIT ? OFFSET ?', [$amount, $offset])->result_array();
|
||||
$data = $this->setDefaultImages($data);
|
||||
$data = $this->setRankname($data);
|
||||
return $data;
|
||||
@@ -187,34 +209,35 @@ WHERE user_id = ?', [$userID, $userID, $userID])->result_array()[0];
|
||||
|
||||
function getActiveUsers($count)
|
||||
{
|
||||
$data = $this->db->query('SELECT username, displayname, profile_picture, lastLogin, (SELECT COUNT(*) FROM user_followers WHERE followedUserID = users.ID) follower_count FROM users WHERE isCurrentlyOnline = TRUE AND is_activated = TRUE AND isDeleted = FALSE ORDER BY lastLogin DESC LIMIT ?', [$count])->result_array();
|
||||
$data = $this->db->query('SELECT username, displayname, profilePicture, lastLogin, (SELECT COUNT(*) FROM user_followers WHERE followedUserID = u.ID) follower_count FROM users u LEFT JOIN user_settings s ON s.ID = u.ID WHERE isCurrentlyOnline = TRUE AND activated = TRUE AND isDeleted = FALSE ORDER BY lastLogin DESC LIMIT ?', [$count])->result_array();
|
||||
$data = $this->setDefaultImages($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getNewestUsers($count)
|
||||
{
|
||||
$data = $this->db->query('SELECT username, displayname, profile_picture, date_created, (SELECT COUNT(*) FROM user_followers WHERE followedUserID = users.ID) follower_count FROM users WHERE is_activated = TRUE AND isDeleted = FALSE ORDER BY date_created DESC LIMIT ?', [$count])->result_array();
|
||||
$data = $this->db->query('SELECT username, displayname, profilePicture, dateCreated, (SELECT COUNT(*) FROM user_followers WHERE followedUserID = u.ID) follower_count FROM users u LEFT JOIN user_settings s ON s.ID = u.ID WHERE activated = TRUE AND isDeleted = FALSE ORDER BY dateCreated DESC LIMIT ?', [$count])->result_array();
|
||||
$data = $this->setDefaultImages($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function searchUsers($query, $rank = '', $region = '', $lang = '', $amount = 3, $offset = 0) {
|
||||
public function searchUsers($query, $rank = '', $region = '', $lang = '', $amount = 3, $offset = 0)
|
||||
{
|
||||
$conditions = [];
|
||||
$inputs = [];
|
||||
if($query !== '') {
|
||||
if ($query !== '') {
|
||||
$conditions[] = 'username RLIKE ?';
|
||||
$inputs[] = $query;
|
||||
}
|
||||
if($rank !== '') {
|
||||
if ($rank !== '') {
|
||||
$conditions[] = 'rank = ?';
|
||||
$inputs[] = $rank;
|
||||
}
|
||||
if($region !== '') {
|
||||
if ($region !== '') {
|
||||
$conditions[] = 'country = ?';
|
||||
$inputs[] = $region;
|
||||
}
|
||||
if($lang !== '') {
|
||||
if ($lang !== '') {
|
||||
$conditions[] = 'language = ?';
|
||||
$inputs[] = $lang;
|
||||
}
|
||||
@@ -222,7 +245,7 @@ WHERE user_id = ?', [$userID, $userID, $userID])->result_array()[0];
|
||||
$dbClause = join(' AND ', $conditions);
|
||||
$inputs[] = $amount;
|
||||
$inputs[] = $offset;
|
||||
$data = $this->db->query('SELECT username, displayname, profile_picture, header_image, about, rank FROM users WHERE is_activated = TRUE AND isDeleted = FALSE AND ' . $dbClause . ' LIMIT ? OFFSET ?', $inputs)->result_array();
|
||||
$data = $this->db->query('SELECT username, displayname, profilePicture, headerImage, about, rank FROM users u LEFT JOIN user_settings s ON s.ID = u.ID WHERE activated = TRUE AND isDeleted = FALSE AND ' . $dbClause . ' LIMIT ? OFFSET ?', $inputs)->result_array();
|
||||
|
||||
$data = $this->setDefaultImages($data);
|
||||
$data = $this->setRankname($data);
|
||||
@@ -230,19 +253,23 @@ WHERE user_id = ?', [$userID, $userID, $userID])->result_array()[0];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getAvailableCountries() {
|
||||
return $this->db->query('SELECT country, count(*) countryUserCount FROM users WHERE country IS NOT NULL AND country != "" GROUP BY country ORDER BY country')->result_array();
|
||||
public function getAvailableCountries()
|
||||
{
|
||||
return $this->db->query('SELECT country, count(*) countryUserCount FROM user_settings WHERE country IS NOT NULL AND country != "" GROUP BY country ORDER BY country')->result_array();
|
||||
}
|
||||
|
||||
public function getAvailableLanguages() {
|
||||
return $this->db->query('SELECT language, count(*) langUserCount FROM users GROUP BY language ORDER BY language')->result_array();
|
||||
public function getAvailableLanguages()
|
||||
{
|
||||
return $this->db->query('SELECT language, count(*) langUserCount FROM user_settings GROUP BY language ORDER BY language')->result_array();
|
||||
}
|
||||
|
||||
public function deleteUser($id) {
|
||||
public function deleteUser($id)
|
||||
{
|
||||
$this->db->query('UPDATE users SET isDeleted = TRUE, isCurrentlyOnline = FALSE, lastOnlineUpdate = NULL WHERE ID = ?', [$id])->result_array();
|
||||
}
|
||||
|
||||
public function getPermissions($userID) {
|
||||
public function getPermissions($userID)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$result = $this->db->query('SELECT * FROM user_permissions WHERE userID = ?', [$userID])->result_array();
|
||||
$this->db->cache_on();
|
||||
@@ -256,18 +283,21 @@ WHERE user_id = ?', [$userID, $userID, $userID])->result_array()[0];
|
||||
return $perms;
|
||||
}
|
||||
|
||||
public function hasPermission($userID, $permType, $permName) {
|
||||
public function hasPermission($userID, $permType, $permName)
|
||||
{
|
||||
$this->db->cache_off();
|
||||
$result = $this->db->query('SELECT ID FROM user_permissions WHERE userID = ? AND permissionType = ? AND permissionName = ?', [$userID, $permType, $permName])->result_array();
|
||||
$this->db->cache_on();
|
||||
return !empty($result);
|
||||
}
|
||||
|
||||
public function addPermission($userID, $permissionGroup, $permissionName, $givenBy) {
|
||||
public function addPermission($userID, $permissionGroup, $permissionName, $givenBy)
|
||||
{
|
||||
$this->db->query('INSERT INTO user_permissions (userID, permissionType, permissionName, givenBy) VALUES (?, ?, ?, ?)', [$userID, $permissionGroup, $permissionName, $givenBy]);
|
||||
}
|
||||
|
||||
public function revokePermission($userID, $permissionGroup, $permissionName) {
|
||||
public function revokePermission($userID, $permissionGroup, $permissionName)
|
||||
{
|
||||
$this->db->query('DELETE FROM user_permissions WHERE userID = ? AND permissionType = ? AND permissionName = ?', [$userID, $permissionGroup, $permissionName]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user