refactor all media create to centralise copy of medias and save, etc.
This commit is contained in:
parent
92146ba8e1
commit
04a40049ce
|
@ -12,6 +12,6 @@ descartes/env.php
|
||||||
|
|
||||||
data/test_write_sms.json
|
data/test_write_sms.json
|
||||||
data/test_read_sms.json
|
data/test_read_sms.json
|
||||||
data/medias/
|
data/public/
|
||||||
|
|
||||||
!*.dist
|
!*.dist
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
RewriteEngine on
|
RewriteEngine on
|
||||||
RewriteRule ^assets - [L]
|
RewriteRule ^assets - [L]
|
||||||
RewriteRule ^.well-known - [L]
|
RewriteRule ^.well-known - [L]
|
||||||
RewriteRule ^data/medias - [L]
|
RewriteRule ^data/public/ - [L]
|
||||||
RewriteRule . index.php
|
RewriteRule . index.php
|
||||||
|
|
|
@ -184,6 +184,20 @@ namespace adapters;
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read from a files to simulate sms reception.
|
||||||
|
* In the file we expect a json string representing an array of sms of format :
|
||||||
|
* {
|
||||||
|
* "at" : "2021-03-26 11:21:48",
|
||||||
|
* "medias" : [
|
||||||
|
* "https://unsplash.com/photos/q4DJVtxES0w/download?force=true&w=640",
|
||||||
|
* "/tmp/somelocalfile.jpg"
|
||||||
|
* ],
|
||||||
|
* "mms" : true,
|
||||||
|
* "origin" : "+33612345678",
|
||||||
|
* "text" : "SMS Text"
|
||||||
|
* }
|
||||||
|
*/
|
||||||
public function read(): array
|
public function read(): array
|
||||||
{
|
{
|
||||||
$response = [
|
$response = [
|
||||||
|
@ -223,7 +237,36 @@ namespace adapters;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$response['smss'][] = $decode_sms;
|
$clean_sms = [
|
||||||
|
'at' => $decode_sms['at'],
|
||||||
|
'text' => $decode_sms['text'],
|
||||||
|
'origin' => $decode_sms['origin'],
|
||||||
|
'mms' => $decode_sms['mms'],
|
||||||
|
'medias' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
//In medias we want a media URI or URL
|
||||||
|
foreach ($decode_sms['medias'] ?? [] as $media)
|
||||||
|
{
|
||||||
|
$tempfile = tempnam('/tmp', 'raspisms-media-');
|
||||||
|
if (!$tempfile)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$copy = copy($media, $tempfile);
|
||||||
|
if (!$copy)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$clean_sms['medias'][] = [
|
||||||
|
'filepath' => $tempfile,
|
||||||
|
'extension' => pathinfo($media, PATHINFO_EXTENSION) ?: null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$response['smss'][] = $clean_sms;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
|
|
@ -11,248 +11,281 @@
|
||||||
|
|
||||||
namespace controllers\internals;
|
namespace controllers\internals;
|
||||||
|
|
||||||
class Media extends StandardController
|
class Media extends StandardController
|
||||||
|
{
|
||||||
|
const DEFAULT_CHMOD = 0660;
|
||||||
|
|
||||||
|
protected $model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a media.
|
||||||
|
*
|
||||||
|
* @param int $id_user : Id of the user
|
||||||
|
* @param string $tmpfile_path : Path of the temporary local copy of the media
|
||||||
|
* @param ?string $extension : Extension to use for the media
|
||||||
|
*
|
||||||
|
* @return int : Exception on error, new media id else
|
||||||
|
*/
|
||||||
|
public function create(int $id_user, string $tmpfile_path, ?string $extension = null)
|
||||||
{
|
{
|
||||||
protected $model;
|
$user_path = \controllers\internals\Tool::create_user_public_path($id_user);
|
||||||
|
if (!file_exists($tmpfile_path) || !is_readable($tmpfile_path))
|
||||||
/**
|
|
||||||
* Create a media.
|
|
||||||
*
|
|
||||||
* @param int $id_user : Id of the user
|
|
||||||
* @param string $path : path of the media in data dir
|
|
||||||
*
|
|
||||||
* @return mixed bool|int : false on error, new media id else
|
|
||||||
*/
|
|
||||||
public function create(int $id_user, string $path)
|
|
||||||
{
|
{
|
||||||
$data = [
|
throw new \Exception('File ' . $tmpfile_path . ' is not readable.');
|
||||||
'path' => $path,
|
|
||||||
'id_user' => $id_user,
|
|
||||||
];
|
|
||||||
|
|
||||||
return $this->get_model()->insert($data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
$mimey = new \Mimey\MimeTypes;
|
||||||
* Upload and create a media
|
$extension = $extension ?? $mimey->getExtension(mime_content_type($tmpfile_path));
|
||||||
*
|
|
||||||
* @param int $id_user : Id of the user
|
$new_file_name = \controllers\internals\Tool::random_uuid() . '.' . $extension;
|
||||||
* @param array $file : array representing uploaded file, extracted from $_FILES['yourfile']
|
$new_file_path = $user_path . '/' . $new_file_name;
|
||||||
* @return mixed bool | int : False on error, or new media id on success
|
$new_file_relpath = $id_user . '/' . $new_file_name;
|
||||||
*/
|
|
||||||
public function upload_and_create_for_user(int $id_user, array $file)
|
if (!rename($tmpfile_path, $new_file_path))
|
||||||
{
|
{
|
||||||
$user_media_path = PWD_DATA . '/medias/' . $id_user;
|
throw new \Exception('Cannot create file ' . $new_file_path);
|
||||||
|
|
||||||
//Create user medias dir if not exists
|
|
||||||
if (!file_exists($user_media_path))
|
|
||||||
{
|
|
||||||
if (!mkdir($user_media_path, fileperms(PWD_DATA), true))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$upload_result = \controllers\internals\Tool::save_uploaded_file($file, $user_media_path);
|
|
||||||
if ($upload_result['success'] !== true)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$new_filepath = 'medias/' . $id_user . '/' . $upload_result['content'];
|
|
||||||
return $this->create($id_user, $new_filepath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if (!chown($new_file_path, fileowner($user_path)))
|
||||||
* Link a media to a scheduled, a received or a sended message
|
|
||||||
* @param int $id_media : Id of the media
|
|
||||||
* @param string $resource_type : Type of resource to link the media to ('scheduled', 'received' or 'sended')
|
|
||||||
* @param int $resource_id : Id of the resource to link the media to
|
|
||||||
*
|
|
||||||
* @return mixed bool|int : false on error, the new link id else
|
|
||||||
*/
|
|
||||||
public function link_to(int $id_media, string $resource_type, int $resource_id)
|
|
||||||
{
|
{
|
||||||
switch ($resource_type)
|
throw new \Exception('Cannot give file ' . $new_file_path . ' to user : ' . fileowner($user_path));
|
||||||
{
|
|
||||||
case 'scheduled':
|
|
||||||
return $this->get_model()->insert_media_scheduled($id_media, $resource_id);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'received':
|
|
||||||
return $this->get_model()->insert_media_received($id_media, $resource_id);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'sended':
|
|
||||||
return $this->get_model()->insert_media_sended($id_media, $resource_id);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!chgrp($new_file_path, filegroup($user_path)))
|
||||||
/**
|
|
||||||
* Unlink a media of a scheduled, a received or a sended message
|
|
||||||
* @param int $id_media : Id of the media
|
|
||||||
* @param string $resource_type : Type of resource to unlink the media of ('scheduled', 'received' or 'sended')
|
|
||||||
* @param int $resource_id : Id of the resource to unlink the media of
|
|
||||||
*
|
|
||||||
* @return mixed bool : false on error, true on success
|
|
||||||
*/
|
|
||||||
public function unlink_of(int $id_media, int $resource_type, int $resource_id)
|
|
||||||
{
|
{
|
||||||
switch ($resource_type)
|
throw new \Exception('Cannot give file ' . $new_file_path . ' to group : ' . filegroup($user_path));
|
||||||
{
|
|
||||||
case 'scheduled':
|
|
||||||
return $this->get_model()->delete_media_scheduled($id_media, $resource_id);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'received':
|
|
||||||
return $this->get_model()->delete_media_received($id_media, $resource_id);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'sended':
|
|
||||||
return $this->get_model()->delete_media_sended($id_media, $resource_id);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unlink all medias of a scheduled, a received or a sended message
|
|
||||||
* @param string $resource_type : Type of resource to unlink the media of ('scheduled', 'received' or 'sended')
|
|
||||||
* @param int $resource_id : Id of the resource to unlink the media of
|
|
||||||
*
|
|
||||||
* @return mixed bool : false on error, true on success
|
|
||||||
*/
|
|
||||||
public function unlink_all_of(string $resource_type, int $resource_id)
|
|
||||||
{
|
|
||||||
switch ($resource_type)
|
|
||||||
{
|
|
||||||
case 'scheduled':
|
|
||||||
return $this->get_model()->delete_all_for_scheduled($resource_id);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'received':
|
|
||||||
return $this->get_model()->delete_all_for_received($resource_id);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'sended':
|
|
||||||
return $this->get_model()->delete_all_for_sended($resource_id);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if (!chmod($new_file_path, self::DEFAULT_CHMOD))
|
||||||
* Update a media for a user.
|
|
||||||
*
|
|
||||||
* @param int $id_user : user id
|
|
||||||
* @param int $id_media : Media id
|
|
||||||
* @param string $path : Path of the file
|
|
||||||
*
|
|
||||||
* @return bool : false on error, true on success
|
|
||||||
*/
|
|
||||||
public function update_for_user(int $id_user, int $id_media, string $path): bool
|
|
||||||
{
|
{
|
||||||
$media = [
|
throw new \Exception('Cannot give file ' . $new_file_path . ' rights : ' . self::DEFAULT_CHMOD);
|
||||||
'path' => $path,
|
|
||||||
];
|
|
||||||
|
|
||||||
return (bool) $this->get_model()->update_for_user($id_user, $id_media, $media);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
$data = [
|
||||||
* Delete a media for a user.
|
'path' => $new_file_relpath,
|
||||||
*
|
'id_user' => $id_user,
|
||||||
* @param int $id_user : User id
|
];
|
||||||
* @param int $id : Entry id
|
|
||||||
*
|
$new_media_id = $this->get_model()->insert($data);
|
||||||
* @return mixed bool|int : False on error, else number of removed rows
|
if (!$new_media_id)
|
||||||
*/
|
|
||||||
public function delete_for_user(int $id_user, int $id_media): bool
|
|
||||||
{
|
{
|
||||||
$media = $this->get_model()->get_for_user($id_user, $id_media);
|
throw new \Exception('Cannot insert media in database.');
|
||||||
if (!$media)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Delete file
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$filepath = PWD_DATA . '/' . $media['path'];
|
|
||||||
if (file_exists($filepath))
|
|
||||||
{
|
|
||||||
unlink($filepath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (\Throwable $t)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->get_model()->delete_for_user($id_user, $id_media);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return $new_media_id;
|
||||||
* Find medias for a scheduled.
|
}
|
||||||
*
|
|
||||||
* @param int $id_scheduled : Scheduled id to fin medias for
|
/**
|
||||||
*
|
* Upload and create a media
|
||||||
* @return mixed : Medias || false
|
*
|
||||||
*/
|
* @param int $id_user : Id of the user
|
||||||
public function gets_for_scheduled(int $id_scheduled)
|
* @param array $file : array representing uploaded file, extracted from $_FILES['yourfile']
|
||||||
|
* @return int : Raise exception on error or return new media id on success
|
||||||
|
*/
|
||||||
|
public function create_from_uploaded_file_for_user(int $id_user, array $file)
|
||||||
|
{
|
||||||
|
$upload_result = \controllers\internals\Tool::read_uploaded_file($file);
|
||||||
|
if ($upload_result['success'] !== true)
|
||||||
{
|
{
|
||||||
return $this->get_model()->gets_for_scheduled($id_scheduled);
|
throw new \Exception($upload_result['content']);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find medias for a sended and a user.
|
|
||||||
*
|
|
||||||
* @param int $id_sended : Scheduled id to fin medias for
|
|
||||||
*
|
|
||||||
* @return mixed : Medias || false
|
|
||||||
*/
|
|
||||||
public function gets_for_sended(int $id_sended)
|
|
||||||
{
|
|
||||||
return $this->get_model()->gets_for_sended($id_sended);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find medias for a received and a user.
|
|
||||||
*
|
|
||||||
* @param int $id_received : Scheduled id to fin medias for
|
|
||||||
*
|
|
||||||
* @return mixed : Medias || false
|
|
||||||
*/
|
|
||||||
public function gets_for_received(int $id_received)
|
|
||||||
{
|
|
||||||
return $this->get_model()->gets_for_received($id_received);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return $this->create($id_user, $upload_result['tmp_name'], $upload_result['extension']);
|
||||||
* Find medias that are not used
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function gets_unused()
|
|
||||||
{
|
|
||||||
return $this->get_model()->gets_unused();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$new_filepath = 'medias/' . $id_user . '/' . $upload_result['content'];
|
||||||
* Get the model for the Controller.
|
return $this->create($id_user, $new_filepath);
|
||||||
*/
|
}
|
||||||
protected function get_model(): \descartes\Model
|
|
||||||
{
|
|
||||||
$this->model = $this->model ?? new \models\Media($this->bdd);
|
|
||||||
|
|
||||||
return $this->model;
|
/**
|
||||||
|
* Link a media to a scheduled, a received or a sended message
|
||||||
|
* @param int $id_media : Id of the media
|
||||||
|
* @param string $resource_type : Type of resource to link the media to ('scheduled', 'received' or 'sended')
|
||||||
|
* @param int $resource_id : Id of the resource to link the media to
|
||||||
|
*
|
||||||
|
* @return mixed bool|int : false on error, the new link id else
|
||||||
|
*/
|
||||||
|
public function link_to(int $id_media, string $resource_type, int $resource_id)
|
||||||
|
{
|
||||||
|
switch ($resource_type)
|
||||||
|
{
|
||||||
|
case 'scheduled':
|
||||||
|
return $this->get_model()->insert_media_scheduled($id_media, $resource_id);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'received':
|
||||||
|
return $this->get_model()->insert_media_received($id_media, $resource_id);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'sended':
|
||||||
|
return $this->get_model()->insert_media_sended($id_media, $resource_id);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlink a media of a scheduled, a received or a sended message
|
||||||
|
* @param int $id_media : Id of the media
|
||||||
|
* @param string $resource_type : Type of resource to unlink the media of ('scheduled', 'received' or 'sended')
|
||||||
|
* @param int $resource_id : Id of the resource to unlink the media of
|
||||||
|
*
|
||||||
|
* @return mixed bool : false on error, true on success
|
||||||
|
*/
|
||||||
|
public function unlink_of(int $id_media, int $resource_type, int $resource_id)
|
||||||
|
{
|
||||||
|
switch ($resource_type)
|
||||||
|
{
|
||||||
|
case 'scheduled':
|
||||||
|
return $this->get_model()->delete_media_scheduled($id_media, $resource_id);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'received':
|
||||||
|
return $this->get_model()->delete_media_received($id_media, $resource_id);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'sended':
|
||||||
|
return $this->get_model()->delete_media_sended($id_media, $resource_id);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlink all medias of a scheduled, a received or a sended message
|
||||||
|
* @param string $resource_type : Type of resource to unlink the media of ('scheduled', 'received' or 'sended')
|
||||||
|
* @param int $resource_id : Id of the resource to unlink the media of
|
||||||
|
*
|
||||||
|
* @return mixed bool : false on error, true on success
|
||||||
|
*/
|
||||||
|
public function unlink_all_of(string $resource_type, int $resource_id)
|
||||||
|
{
|
||||||
|
switch ($resource_type)
|
||||||
|
{
|
||||||
|
case 'scheduled':
|
||||||
|
return $this->get_model()->delete_all_for_scheduled($resource_id);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'received':
|
||||||
|
return $this->get_model()->delete_all_for_received($resource_id);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'sended':
|
||||||
|
return $this->get_model()->delete_all_for_sended($resource_id);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a media for a user.
|
||||||
|
*
|
||||||
|
* @param int $id_user : user id
|
||||||
|
* @param int $id_media : Media id
|
||||||
|
* @param string $path : Path of the file
|
||||||
|
*
|
||||||
|
* @return bool : false on error, true on success
|
||||||
|
*/
|
||||||
|
public function update_for_user(int $id_user, int $id_media, string $path): bool
|
||||||
|
{
|
||||||
|
$media = [
|
||||||
|
'path' => $path,
|
||||||
|
];
|
||||||
|
|
||||||
|
return (bool) $this->get_model()->update_for_user($id_user, $id_media, $media);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a media for a user.
|
||||||
|
*
|
||||||
|
* @param int $id_user : User id
|
||||||
|
* @param int $id : Entry id
|
||||||
|
*
|
||||||
|
* @return mixed bool|int : False on error, else number of removed rows
|
||||||
|
*/
|
||||||
|
public function delete_for_user(int $id_user, int $id_media): bool
|
||||||
|
{
|
||||||
|
$media = $this->get_model()->get_for_user($id_user, $id_media);
|
||||||
|
if (!$media)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Delete file
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$filepath = PWD_DATA . '/' . $media['path'];
|
||||||
|
if (file_exists($filepath))
|
||||||
|
{
|
||||||
|
unlink($filepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (\Throwable $t)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->get_model()->delete_for_user($id_user, $id_media);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find medias for a scheduled.
|
||||||
|
*
|
||||||
|
* @param int $id_scheduled : Scheduled id to fin medias for
|
||||||
|
*
|
||||||
|
* @return mixed : Medias || false
|
||||||
|
*/
|
||||||
|
public function gets_for_scheduled(int $id_scheduled)
|
||||||
|
{
|
||||||
|
return $this->get_model()->gets_for_scheduled($id_scheduled);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find medias for a sended and a user.
|
||||||
|
*
|
||||||
|
* @param int $id_sended : Scheduled id to fin medias for
|
||||||
|
*
|
||||||
|
* @return mixed : Medias || false
|
||||||
|
*/
|
||||||
|
public function gets_for_sended(int $id_sended)
|
||||||
|
{
|
||||||
|
return $this->get_model()->gets_for_sended($id_sended);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find medias for a received and a user.
|
||||||
|
*
|
||||||
|
* @param int $id_received : Scheduled id to fin medias for
|
||||||
|
*
|
||||||
|
* @return mixed : Medias || false
|
||||||
|
*/
|
||||||
|
public function gets_for_received(int $id_received)
|
||||||
|
{
|
||||||
|
return $this->get_model()->gets_for_received($id_received);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find medias that are not used
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function gets_unused()
|
||||||
|
{
|
||||||
|
return $this->get_model()->gets_unused();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the model for the Controller.
|
||||||
|
*/
|
||||||
|
protected function get_model(): \descartes\Model
|
||||||
|
{
|
||||||
|
$this->model = $this->model ?? new \models\Media($this->bdd);
|
||||||
|
|
||||||
|
return $this->model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -244,14 +244,17 @@ namespace controllers\internals;
|
||||||
* @param ?string $at : Message reception date, if null use current date
|
* @param ?string $at : Message reception date, if null use current date
|
||||||
* @param string $status : Status of a the sms. By default \models\Received::STATUS_UNREAD
|
* @param string $status : Status of a the sms. By default \models\Received::STATUS_UNREAD
|
||||||
* @param bool $mms : Is the sms a mms
|
* @param bool $mms : Is the sms a mms
|
||||||
* @param array $media_ids : Ids of the medias to link to received
|
* @param array $medias : Empty array if no medias, or medias to create and link to the received message. Format : [[
|
||||||
|
* string 'filepath' => local path to a readable copy of the media,
|
||||||
|
* ?string 'extension' => extension to use for the file or null
|
||||||
|
* ], ...]
|
||||||
*
|
*
|
||||||
* @return array : [
|
* @return array : [
|
||||||
* bool 'error' => false if success, true else
|
* bool 'error' => false if success, true else
|
||||||
* ?string 'error_message' => null if success, error message else
|
* ?string 'error_message' => null if success, error message else
|
||||||
* ]
|
* ]
|
||||||
*/
|
*/
|
||||||
public function receive(int $id_user, int $id_phone, string $text, string $origin, ?string $at = null, string $status = \models\Received::STATUS_UNREAD, bool $mms = false, array $media_ids = []): array
|
public function receive(int $id_user, int $id_phone, string $text, string $origin, ?string $at = null, string $status = \models\Received::STATUS_UNREAD, bool $mms = false, array $medias = []): array
|
||||||
{
|
{
|
||||||
$return = [
|
$return = [
|
||||||
'error' => false,
|
'error' => false,
|
||||||
|
@ -269,6 +272,26 @@ namespace controllers\internals;
|
||||||
$is_command = true;
|
$is_command = true;
|
||||||
$text = $response;
|
$text = $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//We create medias to link to the sms
|
||||||
|
$internal_media = new Media($this->bdd);
|
||||||
|
$media_ids = [];
|
||||||
|
if ($mms)
|
||||||
|
{
|
||||||
|
foreach ($medias as $media)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$new_media_id = $internal_media->create($id_user, $media['filepath'], $media['extension']);
|
||||||
|
$media_ids[] = $new_media_id;
|
||||||
|
}
|
||||||
|
catch (\Throwable $t)
|
||||||
|
{
|
||||||
|
$return['error_message'] = $t->getMessage();
|
||||||
|
continue; //Better loose the media than the message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$received_id = $this->create($id_user, $id_phone, $at, $text, $origin, $status, $is_command, $mms, $media_ids);
|
$received_id = $this->create($id_user, $id_phone, $at, $text, $origin, $status, $is_command, $mms, $media_ids);
|
||||||
if (!$received_id)
|
if (!$received_id)
|
||||||
|
@ -287,7 +310,7 @@ namespace controllers\internals;
|
||||||
'origin' => $origin,
|
'origin' => $origin,
|
||||||
'command' => $is_command,
|
'command' => $is_command,
|
||||||
'mms' => $mms,
|
'mms' => $mms,
|
||||||
'medias' => $this->get_model()->gets_in_for_user($id_user, $media_ids),
|
'medias' => $internal_media->gets_in_for_user($id_user, $media_ids),
|
||||||
];
|
];
|
||||||
|
|
||||||
$internal_webhook = new Webhook($this->bdd);
|
$internal_webhook = new Webhook($this->bdd);
|
||||||
|
|
|
@ -211,8 +211,8 @@ namespace controllers\internals;
|
||||||
foreach ($medias as $media)
|
foreach ($medias as $media)
|
||||||
{
|
{
|
||||||
$media_uris[] = [
|
$media_uris[] = [
|
||||||
'http_url' => HTTP_PWD_DATA . '/' . $media['path'],
|
'http_url' => HTTP_PWD_DATA_PUBLIC . '/' . $media['path'],
|
||||||
'local_uri' => PWD_DATA . '/' . $media['path'],
|
'local_uri' => PWD_DATA_PUBLIC . '/' . $media['path'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -205,7 +205,7 @@ namespace controllers\internals;
|
||||||
*
|
*
|
||||||
* @param array $file : The array extracted from $_FILES['file']
|
* @param array $file : The array extracted from $_FILES['file']
|
||||||
*
|
*
|
||||||
* @return array : ['success' => bool, 'content' => file handler | error message, 'error_code' => $file['error']]
|
* @return array : ['success' => bool, 'content' => file handler | error message, 'error_code' => $file['error'], 'mime_type' => server side calculated mimetype, 'extension' => original extension, 'tmp_name' => name of the tmp_file]
|
||||||
*/
|
*/
|
||||||
public static function read_uploaded_file(array $file)
|
public static function read_uploaded_file(array $file)
|
||||||
{
|
{
|
||||||
|
@ -213,8 +213,9 @@ namespace controllers\internals;
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'content' => 'Une erreur inconnue est survenue.',
|
'content' => 'Une erreur inconnue est survenue.',
|
||||||
'error_code' => $file['error'] ?? 99,
|
'error_code' => $file['error'] ?? 99,
|
||||||
'mime_type' => false,
|
'mime_type' => null,
|
||||||
'extension' => false,
|
'extension' => null,
|
||||||
|
'tmp_name' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (UPLOAD_ERR_OK !== $file['error'])
|
if (UPLOAD_ERR_OK !== $file['error'])
|
||||||
|
@ -277,73 +278,6 @@ namespace controllers\internals;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow to save an uploaded file from the $_FILE['file'] array
|
|
||||||
*
|
|
||||||
* @param array $file : The array extracted from $_FILES['file']
|
|
||||||
* @param string $dirpath : The directory to save the file in
|
|
||||||
* @param bool $override : If true, override the file if another file with this name exists
|
|
||||||
* @param ?string $filename : The name to use for the file, if null use a highly random name
|
|
||||||
* @param ?string $extension : The extension to use for the file, if null try to determine it using original file extension, then mime_type
|
|
||||||
* @param bool $use_mimetype : If true, ignore original file extension to determine final file extension and use file real mimetype instead
|
|
||||||
*
|
|
||||||
* @return array : ['success' => bool, 'content' => new file name | error message, 'error_code' => $file['error']]
|
|
||||||
*/
|
|
||||||
public static function save_uploaded_file(array $file, string $dirpath, bool $override = false, ?string $filename = null, ?string $extension = null, bool $use_mimetype = false)
|
|
||||||
{
|
|
||||||
$result = [
|
|
||||||
'success' => false,
|
|
||||||
'content' => 'Une erreur inconnue est survenue.',
|
|
||||||
'error_code' => $file['error'] ?? 99,
|
|
||||||
];
|
|
||||||
|
|
||||||
$upload_info = self::read_uploaded_file($file);
|
|
||||||
if (!$upload_info['success'])
|
|
||||||
{
|
|
||||||
$result['content'] = $upload_info['content'];
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($extension === null)
|
|
||||||
{
|
|
||||||
$extension = $upload_info['extension'];
|
|
||||||
if ($extension === '' || $use_mimetype)
|
|
||||||
{
|
|
||||||
$mimey = new \Mimey\MimeTypes;
|
|
||||||
$extension = $mimey->getExtension($upload_info['mime_type']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($filename === null)
|
|
||||||
{
|
|
||||||
$filename = self::random_uuid();
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename = $filename . '.' . $extension;
|
|
||||||
$filepath = $dirpath . '/' . $filename;
|
|
||||||
|
|
||||||
if (file_exists($filepath) && !$override)
|
|
||||||
{
|
|
||||||
$result['content'] = 'Le fichier ' . $filepath . ' existe déjà.';
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
$success = move_uploaded_file($upload_info['tmp_name'], $filepath);
|
|
||||||
if (!$success)
|
|
||||||
{
|
|
||||||
$result['content'] = 'Impossible de délplacer le fichier vers ' . $filepath;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result['success'] = true;
|
|
||||||
$result['content'] = $filename;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a highly random uuid based on timestamp and strong cryptographic random
|
* Generate a highly random uuid based on timestamp and strong cryptographic random
|
||||||
*
|
*
|
||||||
|
@ -354,4 +288,39 @@ namespace controllers\internals;
|
||||||
$bytes = random_bytes(16);
|
$bytes = random_bytes(16);
|
||||||
return time() . '-' . bin2hex($bytes);
|
return time() . '-' . bin2hex($bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a user data public path
|
||||||
|
* @param int $id_user : The user id
|
||||||
|
*
|
||||||
|
* @return string : The created path
|
||||||
|
|
||||||
|
* @exception Raise exception on error
|
||||||
|
*/
|
||||||
|
public static function create_user_public_path (int $id_user)
|
||||||
|
{
|
||||||
|
$new_dir = PWD_DATA_PUBLIC . '/' . $id_user;
|
||||||
|
if (file_exists($new_dir))
|
||||||
|
{
|
||||||
|
return $new_dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mkdir($new_dir, fileperms(PWD_DATA_PUBLIC)))
|
||||||
|
{
|
||||||
|
throw new \Exception('Cannot create dir ' . $new_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chown($new_dir, fileowner(PWD_DATA_PUBLIC)))
|
||||||
|
{
|
||||||
|
throw new \Exception('Cannot give dir ' . $new_dir . ' to user : ' . fileowner(PWD_DATA));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chgrp($new_dir, filegroup(PWD_DATA_PUBLIC)))
|
||||||
|
{
|
||||||
|
throw new \Exception('Cannot give dir ' . $new_dir . ' to group : ' . filegroup(PWD_DATA));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $new_dir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,6 +264,7 @@ namespace controllers\internals;
|
||||||
* string 'text' => sms content,
|
* string 'text' => sms content,
|
||||||
* string 'destination' => id of phone the sms was sent to
|
* string 'destination' => id of phone the sms was sent to
|
||||||
* string 'origin' => phone number that sent the sms
|
* string 'origin' => phone number that sent the sms
|
||||||
|
* bool 'mms' => is the sms a mms
|
||||||
* ]
|
* ]
|
||||||
*
|
*
|
||||||
* @return bool : False if no transfer, true else
|
* @return bool : False if no transfer, true else
|
||||||
|
|
|
@ -362,12 +362,15 @@ namespace controllers\publics;
|
||||||
{
|
{
|
||||||
foreach ($files_arrays as $file)
|
foreach ($files_arrays as $file)
|
||||||
{
|
{
|
||||||
$new_media_id = $this->internal_media->upload_and_create_for_user($this->user['id'], $file);
|
try
|
||||||
if (!$new_media_id)
|
{
|
||||||
|
$new_media_id = $this->internal_media->upload_and_create_for_user($this->user['id'], $file);
|
||||||
|
}
|
||||||
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
$return = self::DEFAULT_RETURN;
|
$return = self::DEFAULT_RETURN;
|
||||||
$return['error'] = self::ERROR_CODES['CANNOT_CREATE'];
|
$return['error'] = self::ERROR_CODES['CANNOT_CREATE'];
|
||||||
$return['message'] = self::ERROR_MESSAGES['CANNOT_CREATE'] . ' : Cannot upload and create media file ' . $file['name'];
|
$return['message'] = self::ERROR_MESSAGES['CANNOT_CREATE'] . ' : Cannot upload and create media file ' . $file['name'] . ' : ' . $e->getMessage();
|
||||||
$this->auto_http_code(false);
|
$this->auto_http_code(false);
|
||||||
|
|
||||||
return $this->json($return);
|
return $this->json($return);
|
||||||
|
|
|
@ -183,58 +183,10 @@ use Monolog\Logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sms = $response['sms'];
|
$sms = $response['sms'];
|
||||||
$mms = !empty($sms['mms']);
|
$mms = (bool) $sms['mms'] ?? false;
|
||||||
$medias = empty($sms['medias']) ? [] : $sms['medias'];
|
$medias = empty($sms['medias']) ? [] : $sms['medias'];
|
||||||
$media_ids = [];
|
|
||||||
|
|
||||||
//We create medias to link to the sms
|
$response = $this->internal_received->receive($this->user['id'], $id_phone, $sms['text'], $sms['origin'], $sms['at'], \models\Received::STATUS_UNREAD, $mms, $medias);
|
||||||
if ($mms)
|
|
||||||
{
|
|
||||||
foreach ($medias as $media)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$media['mimetype'] = empty($media['mimetype']) ? mime_content_type($media['filepath']) : $media['mimetype'];
|
|
||||||
|
|
||||||
$mimey = new \Mimey\MimeTypes;
|
|
||||||
$extension = empty($media['extension']) ? $mimey->getExtension($media['mimetype']) : $media['extension'];
|
|
||||||
|
|
||||||
$new_filename = \controllers\internals\Tool::random_uuid() . '.' . $extension;
|
|
||||||
$new_filedir = PWD_DATA . '/medias/' . $this->user['id'];
|
|
||||||
$new_filerelpath = 'medias/' . $this->user['id'] . '/' . $new_filename;
|
|
||||||
$new_filepath = $new_filedir . '/' . $new_filename;
|
|
||||||
|
|
||||||
//Create user dir if not exists
|
|
||||||
if (!file_exists($new_filedir))
|
|
||||||
{
|
|
||||||
if (!mkdir($new_filedir, fileperms(PWD_DATA), true))
|
|
||||||
{
|
|
||||||
throw new \Exception('Cannot create dir ' . $new_filedir . ' to copy media : ' . json_encode($media));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rename($media['filepath'], $new_filepath))
|
|
||||||
{
|
|
||||||
throw new \Exception('Cannot copy media : ' . json_encode($media) . ' to ' . $new_filepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
$new_media_id = $this->internal_media->create($this->user['id'], $new_filerelpath);
|
|
||||||
if (!$new_media_id)
|
|
||||||
{
|
|
||||||
throw new \Exception('Cannot save into db media : ' . json_encode($media));
|
|
||||||
}
|
|
||||||
|
|
||||||
$media_ids[] = $new_media_id;
|
|
||||||
}
|
|
||||||
catch (\Throwable $t)
|
|
||||||
{
|
|
||||||
$this->logger->error($t->getMessage());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = $this->internal_received->receive($this->user['id'], $id_phone, $sms['text'], $sms['origin'], $sms['at'], \models\Received::STATUS_UNREAD, $mms, $media_ids);
|
|
||||||
if ($response['error'])
|
if ($response['error'])
|
||||||
{
|
{
|
||||||
$this->logger->error('Failed receive message : ' . json_encode($sms) . ' with error : ' . $response['error_message']);
|
$this->logger->error('Failed receive message : ' . json_encode($sms) . ' with error : ' . $response['error_message']);
|
||||||
|
|
|
@ -120,7 +120,7 @@ namespace controllers\publics;
|
||||||
$medias = $this->internal_media->gets_for_sended($sended['id']);
|
$medias = $this->internal_media->gets_for_sended($sended['id']);
|
||||||
foreach ($medias as &$media)
|
foreach ($medias as &$media)
|
||||||
{
|
{
|
||||||
$media = HTTP_PWD_DATA . '/' . $media['path'];
|
$media = HTTP_PWD_DATA_PUBLIC . '/' . $media['path'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ namespace controllers\publics;
|
||||||
$medias = $this->internal_media->gets_for_received($received['id']);
|
$medias = $this->internal_media->gets_for_received($received['id']);
|
||||||
foreach ($medias as &$media)
|
foreach ($medias as &$media)
|
||||||
{
|
{
|
||||||
$media = HTTP_PWD_DATA . '/' . $media['path'];
|
$media = HTTP_PWD_DATA_PUBLIC . '/' . $media['path'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ namespace controllers\publics;
|
||||||
$medias = $this->internal_media->gets_for_scheduled($scheduled['id']);
|
$medias = $this->internal_media->gets_for_scheduled($scheduled['id']);
|
||||||
foreach ($medias as &$media)
|
foreach ($medias as &$media)
|
||||||
{
|
{
|
||||||
$media = HTTP_PWD_DATA . '/' . $media['path'];
|
$media = HTTP_PWD_DATA_PUBLIC . '/' . $media['path'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,11 +288,14 @@ namespace controllers\publics;
|
||||||
{
|
{
|
||||||
foreach ($files_arrays as $file)
|
foreach ($files_arrays as $file)
|
||||||
{
|
{
|
||||||
$new_media_id = $this->internal_media->upload_and_create_for_user($_SESSION['user']['id'], $file);
|
try
|
||||||
if (!$new_media_id)
|
{
|
||||||
|
$new_media_id = $this->internal_media->create_from_uploaded_file_for_user($_SESSION['user']['id'], $file);
|
||||||
|
}
|
||||||
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
$return['success'] = false;
|
$return['success'] = false;
|
||||||
$return['message'] = 'Impossible d\'upload et d\'enregistrer le fichier ' . $file['name'];
|
$return['message'] = $e->getMessage();
|
||||||
echo json_encode($return);
|
echo json_encode($return);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -332,10 +332,13 @@ namespace controllers\publics;
|
||||||
{
|
{
|
||||||
foreach ($files_arrays as $file)
|
foreach ($files_arrays as $file)
|
||||||
{
|
{
|
||||||
$new_media_id = $this->internal_media->upload_and_create_for_user($_SESSION['user']['id'], $file);
|
try
|
||||||
if (!$new_media_id)
|
|
||||||
{
|
{
|
||||||
\FlashMessage\FlashMessage::push('danger', 'Impossible d\'upload et d\'enregistrer le fichier ' . $file['name']);
|
$new_media_id = $this->internal_media->create_from_uploaded_file_for_user($_SESSION['user']['id'], $file);
|
||||||
|
}
|
||||||
|
catch (\Exception $e)
|
||||||
|
{
|
||||||
|
\FlashMessage\FlashMessage::push('danger', 'Impossible d\'upload et d\'enregistrer le fichier ' . $file['name'] . ':' . $e->getMessage());
|
||||||
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
|
return $this->redirect(\descartes\Router::url('Scheduled', 'add'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,8 +462,11 @@ namespace controllers\publics;
|
||||||
{
|
{
|
||||||
foreach ($files_arrays as $file)
|
foreach ($files_arrays as $file)
|
||||||
{
|
{
|
||||||
$new_media_id = $this->internal_media->upload_and_create_for_user($_SESSION['user']['id'], $file);
|
try
|
||||||
if (!$new_media_id)
|
{
|
||||||
|
$new_media_id = $this->internal_media->create_from_uploaded_file_for_user($_SESSION['user']['id'], $file);
|
||||||
|
}
|
||||||
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ class Phone extends AbstractDaemon
|
||||||
foreach ($response['smss'] as $sms)
|
foreach ($response['smss'] as $sms)
|
||||||
{
|
{
|
||||||
$this->logger->info('Receive message : ' . json_encode($sms));
|
$this->logger->info('Receive message : ' . json_encode($sms));
|
||||||
$response = $internal_received->receive($this->phone['id_user'], $this->phone['id'], $sms['text'], $sms['origin']);
|
$response = $internal_received->receive($this->phone['id_user'], $this->phone['id'], $sms['text'], $sms['origin'], $sms['at'], \models\Received::STATUS_UNREAD, $sms['mms'] ?? false, $sms['medias'] ?? []);
|
||||||
|
|
||||||
if ($response['error'])
|
if ($response['error'])
|
||||||
{
|
{
|
||||||
|
|
|
@ -87,7 +87,7 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return '<div class="discussion-message-media"><a href="' + mediaUrl + '" target="_blank">Voir le fichier ' + (index + 1) + '</a></div>';
|
return '<div class="discussion-message-media"><a href="' + mediaUrl + '" target="_blank">Voir le fichier ' + ((int)index + 1) + '</a></div>';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var medias_html = '<div class="discussion-message-medias">' + medias.join('') + '</div>';
|
var medias_html = '<div class="discussion-message-medias">' + medias.join('') + '</div>';
|
||||||
|
|
|
@ -110,7 +110,7 @@ jQuery(document).ready(function ()
|
||||||
if (row.mms == 1) {
|
if (row.mms == 1) {
|
||||||
var medias = [];
|
var medias = [];
|
||||||
for (i = 0; i < row.medias.length; i++) {
|
for (i = 0; i < row.medias.length; i++) {
|
||||||
medias.push('<a href="' + HTTP_PWD + '/data/' + jQuery.fn.dataTable.render.text().display(row.medias[i].path) + '" target="_blank">Fichier ' + (i + 1) + '</a>');
|
medias.push('<a href="' + HTTP_PWD + '/data/public/' + jQuery.fn.dataTable.render.text().display(row.medias[i].path) + '" target="_blank">Fichier ' + (i + 1) + '</a>');
|
||||||
}
|
}
|
||||||
html = data + '<br/>' + medias.join(' - ');
|
html = data + '<br/>' + medias.join(' - ');
|
||||||
return html;
|
return html;
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
<?php foreach ($scheduled['medias'] as $key => $media) { ?>
|
<?php foreach ($scheduled['medias'] as $key => $media) { ?>
|
||||||
<p class="current-media">
|
<p class="current-media">
|
||||||
<input type="hidden" name="scheduleds[<?php $this->s($scheduled['id']); ?>][media_ids][]" value="<?php $this->s($media['id']); ?>">
|
<input type="hidden" name="scheduleds[<?php $this->s($scheduled['id']); ?>][media_ids][]" value="<?php $this->s($media['id']); ?>">
|
||||||
<label>Fichier <?= $key + 1 ?> :</label><br/> <a href="<?php $this->s(HTTP_PWD_DATA . '/' . $media['path']); ?>" class="btn btn-info btn-sm" target="_blank">Voir le média</a> <a href="#" class="btn btn-warning btn-delete-media btn-sm">Supprimer le média</a>
|
<label>Fichier <?= $key + 1 ?> :</label><br/> <a href="<?php $this->s(HTTP_PWD_DATA_PUBLIC . '/' . $media['path']); ?>" class="btn btn-info btn-sm" target="_blank">Voir le média</a> <a href="#" class="btn btn-warning btn-delete-media btn-sm">Supprimer le média</a>
|
||||||
</p>
|
</p>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -93,7 +93,7 @@ jQuery(document).ready(function ()
|
||||||
if (row.mms == 1) {
|
if (row.mms == 1) {
|
||||||
var medias = [];
|
var medias = [];
|
||||||
for (i = 0; i < row.medias.length; i++) {
|
for (i = 0; i < row.medias.length; i++) {
|
||||||
medias.push('<a href="' + HTTP_PWD + '/data/' + jQuery.fn.dataTable.render.text().display(row.medias[i].path) + '" target="_blank">Fichier ' + (i + 1) + '</a>');
|
medias.push('<a href="' + HTTP_PWD + '/data/public/' + jQuery.fn.dataTable.render.text().display(row.medias[i].path) + '" target="_blank">Fichier ' + (i + 1) + '</a>');
|
||||||
}
|
}
|
||||||
html = data + '<br/>' + medias.join(' - ');
|
html = data + '<br/>' + medias.join(' - ');
|
||||||
return html;
|
return html;
|
||||||
|
|
|
@ -100,7 +100,7 @@ jQuery(document).ready(function ()
|
||||||
if (row.mms == 1) {
|
if (row.mms == 1) {
|
||||||
var medias = [];
|
var medias = [];
|
||||||
for (i = 0; i < row.medias.length; i++) {
|
for (i = 0; i < row.medias.length; i++) {
|
||||||
medias.push('<a href="' + HTTP_PWD + '/data/' + jQuery.fn.dataTable.render.text().display(row.medias[i].path) + '" target="_blank">Fichier ' + (i + 1) + '</a>');
|
medias.push('<a href="' + HTTP_PWD + '/data/public/' + jQuery.fn.dataTable.render.text().display(row.medias[i].path) + '" target="_blank">Fichier ' + (i + 1) + '</a>');
|
||||||
}
|
}
|
||||||
html = data + '<br/>' + medias.join(' - ');
|
html = data + '<br/>' + medias.join(' - ');
|
||||||
return html;
|
return html;
|
||||||
|
|
Loading…
Reference in New Issue