Archived
1
0

Implement video upload to posts

This commit is contained in:
Marcel
2018-12-30 18:52:30 +01:00
parent 1f3e0243cf
commit ebb5c473f6
11 changed files with 1063 additions and 571 deletions

View File

@@ -63,6 +63,8 @@
$route['user/getComments'] = 'user/getComments';
$route['user/getBlogPosts'] = 'user/getBlogPosts';
$route['user/publishPost'] = 'user/publishPost';
$route['user/uploadPostMedia'] = 'user/uploadPostMedia';
$route['user/deletePostMedia'] = 'user/deletePostMedia';
$route['user/switchFollowing'] = 'user/switchFollowing';
$route['user/getReportModal'] = 'user/getReportModal';
$route['user/(:any)'] = 'user/index/$1';

File diff suppressed because it is too large Load Diff

View File

@@ -52,5 +52,5 @@
$lang['header_post'] = 'Post';
$lang['header_post_title'] = 'Post verfassen';
$lang['header_post_content'] = 'Inhalt';
$lang['header_post_notice'] = 'Es wird an einer Funktion zum Uploaden von Fotos, Videos und anderen Medien gearbeitet. In hoffentlich naher Zukunft wirst du auch die Möglichkeit haben, diese zu deinen Posts hinzuzufügen!';
$lang['header_post_notice'] = 'Derzeit arbeiten wir intensiv daran, dir die Möglichkeit zu bieten, neben Bildern und Videos auch Audio-Aufnahmen hinzuzufügen und vor allem mithilfe von unter anderem einer direkten Kamera-Integration das Nutzererlebnis deutlich besser zu gestalten. Auch möchten wir die Text-Eingabe deutlich komfortabler gestalten. Also, stay tuned!';
$lang['header_post_publish'] = 'Veröffentlichen';

View File

@@ -61,3 +61,27 @@
$lang['post_copy_link'] = 'Link zum Post kopieren';
$lang['post_report'] = 'Post melden';
$lang['post_delete'] = 'Post löschen';
$lang['post_error_login_title'] = 'Veröffentlichung des Posts nicht möglich!';
$lang['post_error_login_lines'] = [
'Du musst in deinen Account eingeloggt sein, um Posts erstellen zu können.',
'Bitte erstelle dir entweder <a href="' . base_url('login') . '">kostenlos einen neuen Account</a> oder <a href="' . base_url('login') . '">melde dich an</a>.'
];
$lang['post_error_too_long_title'] = 'Veröffentlichung des Posts fehlgeschlagen!';
$lang['post_error_too_long_lines'] = [
'Dein Post ist leider zu lang. Er darf maximal 10.000 Zeichen umfassen.',
];
$lang['post_error_reply_title'] = 'Veröffentlichung des Posts fehlgeschlagen!';
$lang['post_error_reply_lines'] = [
'Der Post, an den du deine Antwort richten willst, existiert nicht (mehr).',
'Solltest du dies für einen Fehler halten, versuche es später erneut oder kontaktiere uns.',
];
$lang['post_error_no_conent_title'] = 'Veröffentlichung des Posts nicht möglich!';
$lang['post_error_no_conent_lines'] = [
'Du hast uns leider keinen Inhalt angegeben, den wir veröffentlichen können.',
'Sollte es sich dabei um ein Irrtum handeln, so kontaktiere uns bitte über das Kontakt-Formular.',
];
$lang['post_success_title'] = '';
$lang['post_success_lines'] = [
'',
];

View File

@@ -11,8 +11,24 @@ class FileModel extends CI_Model
parent::__construct();
}
private function getPath($fileName, $userContent) {
return 'files/' . ($userContent ? 'userContent/' : '') . $fileName;
private function getPath($fileName, $user) {
return 'files/' . ($user != null ? 'userContent/' . $user . '/' : '') . $fileName;
}
private function addToDatabase($name, $originalName, $type, $size, $path, $user) {
$userID = NULL;
if(is_string($user)) {
$user = $this->db->query('SELECT ID FROM users WHERE username = lower(?)', [$user])->result_array();
if(!empty($user)) {
$userID = $user[0]['ID'];
}
} else if(is_integer($user)) {
$userID = $user;
}
$this->db->query('INSERT INTO files (name, original_name, type, size, path, user) VALUES (?, ?, ?, ?, ?, ?)', [$name, $originalName, $type, $size, $path, $userID]);
$this->db->cache_delete('admin', 'files');
}
public function uploadFile($original_name, $tmpname, $size, $type, $userContent = true)
@@ -28,20 +44,51 @@ class FileModel extends CI_Model
$target_file = str_replace('\\', '/', $target_file);
$this->db->query('INSERT INTO files (name, original_name, type, size, path, isUserData) VALUES (?, ?, ?, ?, ?, ?)', [$name, $original_name, $type, $size, $target_file, $userContent]);
$this->db->cache_delete('admin', 'files');
$this->addToDatabase($name, $original_name, $type, $size, $target_file, $userContent);
echo shell_exec('python /var/www/codeigniter/duplicates.py');
return "/f/" . $name;
}
public function uploadImage($name, $max_size, $originalname, $max_width, $userContent = true) {
$config['upload_path'] = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . ($userContent ? 'userContent' . DIRECTORY_SEPARATOR : '');
public function uploadVideo($name, $max_size, $originalName, $max_width, $user = null) {
$path = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
if($user !== null) {
$path .= 'userContent' . DIRECTORY_SEPARATOR . $user . DIRECTORY_SEPARATOR;
}
$config['upload_path'] = $path;
if(!file_exists($path)) {
mkdir($path, 0777);
}
$config['allowed_types'] = 'mp4';
$config['max_size'] = $max_size;
$config['file_name'] = $this->generateName() . '.' . pathinfo(basename($originalName), PATHINFO_EXTENSION);
$this->load->library('upload', $config);
if(!$this->upload->do_upload($name)) {
return null;
} else {
$data = $this->upload->data();
$this->upload->display_errors();
$this->addToDatabase($data['raw_name'], $originalName, $data['file_type'], $data['file_size'] * 1024, $this->getPath($data['file_name'], $user), $user);
return '/f/' . $data['raw_name'];
}
}
public function uploadImage($name, $max_size, $originalName, $max_width, $user = null) {
$config['upload_path'] = '.' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
if($user != null) {
$config['upload_path'] .= 'userContent' . DIRECTORY_SEPARATOR . $user . DIRECTORY_SEPARATOR;
}
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = $max_size;
$config['file_name'] = $this->generateName() . "." . pathinfo(basename($originalname), PATHINFO_EXTENSION);
$config['file_name'] = $this->generateName() . "." . pathinfo(basename($originalName), PATHINFO_EXTENSION);
$this->load->library('upload', $config);
@@ -60,9 +107,7 @@ class FileModel extends CI_Model
$this->image_lib->resize();
$this->db->query('INSERT INTO files (name, original_name, type, size, path, isUserData) VALUES (?, ?, ?, ?, ?, ?)', [$data['raw_name'], $originalname, $data['file_type'], $data['file_size'] * 1024, $this->getPath($data['file_name'], $userContent), $userContent]);
$this->db->cache_delete('admin', 'files');
$this->addToDatabase($data['raw_name'], $originalName, $data['file_type'], $data['file_size'] * 1024, $this->getPath($data['file_name'], $user), $user);
echo shell_exec('python /var/www/codeigniter/duplicates.py');
@@ -164,6 +209,16 @@ class FileModel extends CI_Model
return $result;
}
public function getFileID($name, $userID = null) {
$result = $this->db->query('SELECT ID FROM files WHERE name = ? AND user = ?', [$name, $userID])->result_array();
return $result;
}
public function getFilePath($name, $userID = null) {
$result = $this->db->query('SELECT path FROM files WHERE name = ? AND user = ?', [$name, $userID])->result_array();
return !empty($result) ? $result[0]['path'] : null;
}
public function delete($id) {
$filePath = $this->db->query('SELECT path FROM files WHERE ID = ? LIMIT 1', [$id])->result_array()[0];
unlink($filePath['path']);

View File

@@ -48,8 +48,8 @@
$this->db->query('DELETE FROM user_posts_media WHERE postID = ?', [$postID]);
}
public function addImageToPost($postID, $imageUrl) {
$this->db->query('INSERT INTO user_posts_media (postID, mediaType, mediaUrl) VALUES (?, ?, ?)', [$postID, 'image', $imageUrl]);
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)
@@ -149,7 +149,7 @@
}
public function getPostMedia($postID) {
$result = $this->db->query('SELECT * FROM user_posts_media WHERE postID = ?', [$postID])->result_array();
$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;
}

View File

@@ -110,7 +110,8 @@
'lib/jquery.PageScroll2id.min.js',
'lib/jquery.mobile.custom.min.js',
'post-create.js',
'post-item.js'
'post-item.js',
'video-controls.js',
];
if (isset($additionalScripts)) {
$scripts = array_merge($scripts, $additionalScripts);

View File

@@ -35,11 +35,46 @@
<?php if (!empty($media)): ?>
<div class="post-media-list row">
<?php foreach ($media as $item): ?>
<div class="col">
<div class="post-media" data-full-image="<?= $item['mediaUrl'] ?>" style="background-image: url(<?= $item['mediaUrl'] ?>?w=500"></div>
</div>
<?php endforeach; ?>
<?php foreach ($media as $item) {
$url = '/f/' . $item['name'];
switch ($item['type']) {
case 'image':
?>
<div class="col">
<div class="post-media post-image" data-full-image="<?= $url ?>" style="background-image: url('<?= $url ?>?w=500')"></div>
</div>
<?php
break;
case 'video':
?>
<div class="col">
<div class="video-container">
<video class="video" src="<?= $url ?>" muted></video>
<div class="video-controls">
<button type="button" class="video-control-btn video-toggle-play">
<i class="fa fa-play"></i>
</button>
<div class="video-volume-container">
<button type="button" class="video-control-btn video-mute">
<i class="fa fa-volume-muted"></i>
</button>
<input type="range" class="video-volume" min="0" max="1" step="0.1" value="1">
</div>
<output class="video-time">0:00</output>
<input type="range" class="video-seek-bar" value="0">
<output class="video-length">0:00</output>
<button type="button" class="video-control-btn video-fullscreen">
<i class="fa fa-expand"></i>
</button>
</div>
</div>
</div>
<?php
break;
case 'audio':
break;
}
} ?>
</div>
<?php endif; ?>
</div>