Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #44 from flatCore/develop
Browse files Browse the repository at this point in the history
Develop Branch v2.0.5
  • Loading branch information
patkon committed Mar 12, 2021
2 parents 6208dce + fd930fd commit 5760327
Show file tree
Hide file tree
Showing 188 changed files with 9,296 additions and 784 deletions.
2 changes: 1 addition & 1 deletion acp/core/docs.php
Expand Up @@ -127,7 +127,7 @@
}

echo '<hr><a target="_blank" href="'.$helpURL.'" title="'.$helpURL.'" class="btn btn-fc btn-block">'.$icon['question'].' '.$lang['show_help'].'</a>';

echo '<a target="_blank" href="https://github.com/flatCore/flatCore-CMS/discussions" title="Discussions" class="btn btn-primary btn-block">'.$icon['comments'].' Discussions</a>';



Expand Down
73 changes: 53 additions & 20 deletions acp/core/files.browser.php
Expand Up @@ -122,21 +122,34 @@
}


/* DELETE FILE OR IMAGE */
/**
* Delete Files
* or Images and Thumbnails
*/
if(isset($_POST['delete'])) {

$deleteFile = basename($_POST['file']);
$deleteFile = (int) $_POST['delete'];
$get_file_data = fc_get_media_data_by_id($deleteFile);

if(is_file("$disk/$deleteFile")) {
if(unlink("$disk/$deleteFile")) {
fc_delete_media_data("$disk/$deleteFile");
$delete_file = $get_file_data['media_file'];
$delete_thumb = $get_file_data['media_thumb'];

if(is_file($delete_file)) {
if(unlink($delete_file)) {
fc_delete_media_data($delete_file);
if(is_file($delete_thumb)) {
unlink($delete_thumb);
}
echo '<div class="alert alert-success alert-auto-close">'.$lang['msg_file_delete'].'</div>';
} else {
echo '<div class="alert alert-danger"><strong>'.$disk.'/'.$deleteFile.'</strong><br>'.$lang['msg_file_delete_error'].'</div>';
echo '<div class="alert alert-danger"><strong>'.$delete_file.'</strong><br>'.$lang['msg_file_delete_error'].'</div>';
}
} else {
echo '<div class="alert alert-error">File ('.$disk.'/'.$deleteFile.') not found</div>';
echo '<div class="alert alert-error">File ('.$delete_file.') not found</div>';
}



}

/* delete folder */
Expand All @@ -163,6 +176,11 @@ function delete_folder($dir) {
}


if(isset($_POST['clear_tmb'])) {
fc_clear_thumbs_directory();
}


/**
* check if all files stored in media database
* if not, catch up
Expand All @@ -174,7 +192,7 @@ function delete_folder($dir) {
* if yes, fill up
*/

if(isset($_GET['rebuild']) && ($_GET['rebuild'] == 'database')) {
if(isset($_POST['rebuild']) && ($_POST['rebuild'] == 'database')) {

$incomplete = FALSE;
$rebuild_start = time();
Expand Down Expand Up @@ -251,20 +269,25 @@ function delete_folder($dir) {


/* check if thumbnail exists and create missing thumbnail file */
$cnt_created_tmbs = 0;
foreach($storedFiles as $k) {

/* thumbnail directories */
$tmb_dir = '../'.$img_tmb_path;
$tmb_dir_year = $tmb_dir.'/'.date('Y',$k['media_upload_time']);
$tmb_destination = $tmb_dir_year.'/'.date('m',$k['media_upload_time']);

if(!is_dir($tmb_destination)) {
mkdir($tmb_destination, 0777, true);
}

$tmb_name = md5($k['media_file']).'.jpg';

$ckeck_tmb = $tmb_destination.'/'.$tmb_name;

if(!file_exists($ckeck_tmb)) {
fc_create_tmb($k['media_file'], $tmb_name, 250, 250, 60);

$cnt_created_tmbs++;
fc_create_thumbnail($k['media_file'], $tmb_name, $tmb_destination, $fc_preferences['prefs_maxtmbwidth'], $fc_preferences['prefs_maxtmbheight'], 80);
$db_content->update("fc_media", [
"media_thumb" => $ckeck_tmb
],[
Expand Down Expand Up @@ -294,7 +317,7 @@ function delete_folder($dir) {
$tmb_name = md5($image).'.jpg';
$store_tmb_name = $tmb_destination.'/'.$tmb_name;

fc_create_tmb($image, $tmb_name, 250, 250, 60);
fc_create_thumbnail($row['media_file'], $tmb_name, $tmb_destination, $fc_preferences['prefs_maxtmbwidth'], $fc_preferences['prefs_maxtmbheight'], 80);

$db_content->update("fc_media", [
"media_thumb" => $tmb_name
Expand Down Expand Up @@ -343,7 +366,11 @@ function delete_folder($dir) {
}
}

echo '<div class="alert alert-info">Add '.$cnt_files_rebuild.' Files, removed '.$cnt_files_removed.' Files from Database. Completed '.$cnt_infos_completed.' File-Informations</div>';
echo '<div class="alert alert-info">';
echo 'Created Add <strong>'.$cnt_files_rebuild. '</strong> Files, removed <strong>'.$cnt_files_removed.'</strong> Files from Database<br>';
echo 'Completed <strong>'.$cnt_infos_completed. '</strong> File-Informations in Database<br>';
echo 'Created <strong>'.$cnt_created_tmbs. '</strong> Thumbnails.';
echo '</div>';

if($incomplete === TRUE) {
echo '<div class="alert alert-info">Maximum Time reached, <a href="?tn=filebrowser&sub=browse&rebuild=database">start again</a>.</div>';
Expand Down Expand Up @@ -414,9 +441,6 @@ function delete_folder($dir) {

echo '<div class="btn-toolbar float-right">';

echo '<div class="btn-group float-right mr-1">';
echo '<a class="btn btn-sm btn-fc" href="acp.php?tn='.$tn.'&sub=browse&rebuild=database">'.$icon['wrench'].'</a>';
echo '</div>';
echo '<div class="btn-group float-right">';
echo '<a class="btn btn-sm btn-fc '.$check_lastedit.'" href="acp.php?tn='.$tn.'&sub=browse&d='.$disk.'&sort_by=time">'.$lang['date_of_change'].'</a>';
echo '<a class="btn btn-sm btn-fc '.$check_name.'" href="acp.php?tn='.$tn.'&sub=browse&d='.$disk.'&sort_by=name">'.$lang['filename'].'</a>';
Expand Down Expand Up @@ -457,9 +481,9 @@ function delete_folder($dir) {
$_SESSION['media_filter_string'] = $add_keyword_filter;
}

$sql_cnt = "SELECT count(*) AS 'all' FROM fc_media WHERE media_file LIKE '%$disk%' AND (media_lang LIKE '$languagePack' OR media_lang IS NULL) ".$_SESSION['media_filter_string'];

$sql_cnt = "SELECT count(*) AS 'all' FROM fc_media WHERE media_file LIKE '%$disk%' ".$_SESSION['media_filter_string'];
$all_files = $db_content->query($sql_cnt)->fetch();
$all_files = fc_unique_multi_array($all_files,'media_file');
$nbr_of_files = $all_files['all'];


Expand Down Expand Up @@ -494,14 +518,16 @@ function delete_folder($dir) {
$order_sql = 'ORDER BY '.$_SESSION['sort_by'].' '.$_SESSION['sort_direction']. ' ';
$where_sql = 'WHERE media_id IS NOT NULL AND ';
$where_sql .= " (media_file like '%$disk%')";
$where_sql .= " AND (media_lang LIKE '$languagePack' OR media_lang IS NULL)";
//$where_sql .= " AND (media_lang LIKE '$languagePack' OR media_lang IS NULL)";

$limit_sql = "LIMIT $start,$files_per_page ";


$sql = "SELECT * FROM fc_media $where_sql ".$_SESSION['media_filter_string']." $order_sql $limit_sql";
$get_files = $db_content->query($sql)->fetchAll(PDO::FETCH_ASSOC);

$get_files = fc_unique_multi_array($get_files,'media_file');

$cnt_pages = ceil($nbr_of_files/$files_per_page);
$cnt_get_files = count($get_files);

Expand Down Expand Up @@ -551,7 +577,7 @@ function delete_folder($dir) {
for($i=0;$i<$cnt_get_files;$i++) {

$filename = '';

$id = $get_files[$i]['media_id'];
$filename = $get_files[$i]['media_file'];
$filename_thumb = $get_files[$i]['media_thumb'];
$filetime = $get_files[$i]['media_lastedit'];
Expand All @@ -565,7 +591,7 @@ function delete_folder($dir) {
}


$delete_btn = '<button type="submit" onclick="return confirm(\''.$lang['confirm_delete_file'].'\')" class="btn btn-fc btn-sm w-100 text-danger" name="delete" value="'.$lang['delete'].'">'.$icon['trash_alt'].'</button>';
$delete_btn = '<button type="submit" onclick="return confirm(\''.$lang['confirm_delete_file'].'\')" class="btn btn-fc btn-sm w-100 text-danger" name="delete" value="'.$id.'">'.$icon['trash_alt'].'</button>';
$edit_btn = '<a data-fancybox data-type="ajax" data-src="/acp/core/ajax.media.php?file='.$filename.'&folder='.$disk.'" href="javascript:;" class="btn btn-sm btn-fc w-100 text-success">'.$icon['edit'].'</a>';


Expand Down Expand Up @@ -630,6 +656,13 @@ function delete_folder($dir) {
echo '</p></div>'; //EOL PAGINATION


echo '<form action="acp.php?tn=filebrowser&sub=browse" method="POST" class="d-block text-right mt-4">';
echo '<div class="btn-group" role="group">';
echo '<button class="btn btn-sm btn-fc" type="submit" name="rebuild" value="database">Database '.$icon['wrench'].'</button>';
echo '<button class="btn btn-sm btn-fc" type="submit" name="clear_tmb">Thumbnails '.$icon['trash_alt'].'</button>';
echo '</div>';
echo '</form>';



function switch_sort() {
Expand Down
18 changes: 14 additions & 4 deletions acp/core/files.upload-script.php
Expand Up @@ -67,8 +67,18 @@

$max_w = (int) $_REQUEST['w']; // max image width
$max_h = (int) $_REQUEST['h']; // max image height
$max_w_tmb = (int) $_REQUEST['w_tmb']; // max thumbnail width
$max_h_tmb = (int) $_REQUEST['h_tmb']; // max thumbnail height
$max_fz = (int) $_REQUEST['fz']; // max filesize

if($max_w_tmb < 1) {
$max_w_tmb = 250;
}

if($max_h_tmb < 1) {
$max_h_tmb = 250;
}

if(strpos($_REQUEST['upload_destination'],"/images") !== false) {
$destination = '../'.$_REQUEST['upload_destination'];
$upload_type = 'images';
Expand Down Expand Up @@ -99,6 +109,7 @@
$img_name = clean_filename($prefix,$suffix);
$target = "$destination/$img_name";


//$fc_upload_img_types from config.php
if(!in_array($suffix, $fc_upload_img_types)) {
exit;
Expand All @@ -108,9 +119,9 @@
@move_uploaded_file($tmp_name, $target);
} else {
resize_image($tmp_name,$target,$max_w,$max_h,100);
$tmb_name = md5($target).'.jpg';
$tmb_name = md5(substr($target, 3,strlen($target))).'.jpg';
$store_tmb_name = $tmb_destination.'/'.$tmb_name;
fc_create_tmb($tmp_name,$tmb_name,250,250,60);
fc_create_tmb($target,$tmb_name,$max_w_tmb,$max_h_tmb,80);
}

$filetype = mime_content_type(realpath($target));
Expand Down Expand Up @@ -318,7 +329,6 @@ function fc_write_media_data_name($filename,$store_tmb_name,$filesize,$time,$med

$filename = substr($filename, 3,strlen($filename));
$store_tmb_name = substr($store_tmb_name, 3,strlen($store_tmb_name));

$uploader = $_SESSION['user_nick'];

$columns = [
Expand All @@ -329,7 +339,7 @@ function fc_write_media_data_name($filename,$store_tmb_name,$filesize,$time,$med
"media_upload_time" => "$time",
"media_upload_from" => "$uploader",
"media_type" => "$mediatype",
"media_lang" => "$languagePack"
"media_lang" => $_SESSION['lang']
];

$cnt_changes = $db_content->insert("fc_media", $columns);
Expand Down
2 changes: 2 additions & 0 deletions acp/core/files.upload.php
Expand Up @@ -54,7 +54,9 @@
</div>

<input type="hidden" name="w" value="<?php echo $fc_preferences['prefs_maximagewidth']; ?>" />
<input type="hidden" name="w_tmb" value="<?php echo $fc_preferences['prefs_maxtmbwidth']; ?>" />
<input type="hidden" name="h" value="<?php echo $fc_preferences['prefs_maximageheight']; ?>" />
<input type="hidden" name="h_tmb" value="<?php echo $fc_preferences['prefs_maxtmbheight']; ?>" />
<input type="hidden" name="fz" value="<?php echo $fc_preferences['prefs_maxfilesize']; ?>" />
<input type="hidden" name="unchanged" value="<?php echo $fc_preferences['prefs_uploads_remain_unchanged']; ?>" />
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['token']; ?>">
Expand Down
10 changes: 6 additions & 4 deletions acp/core/files.upload_gallery.php
Expand Up @@ -4,8 +4,10 @@
$gallery_id = 'gallery'. (int) $_REQUEST['gal'];
$uploads_dir = '../../content/galleries/'.$year.'/'.$gallery_id;

$max_width = 950;
$max_height = 950;
$max_width = (int) $_REQUEST['w']; // max image width
$max_height = (int) $_REQUEST['h']; // max image height
$max_width_tmb = (int) $_REQUEST['w_tmb']; // max thumbnail width
$max_height_tmb = (int) $_REQUEST['h_tmb']; // max thumbnail height

if(!is_dir($uploads_dir)) {
mkdir($uploads_dir, 0777, true);
Expand All @@ -27,8 +29,8 @@
$tmb_name = $timestring."_tmb.jpg";

if(move_uploaded_file($tmp_name, "$uploads_dir/$org_name")) {
create_thumbs($uploads_dir,$org_name,$img_name, $max_width,$max_height,80);
create_thumbs($uploads_dir,$img_name,$tmb_name, 150,100,100);
create_thumbs($uploads_dir,$org_name,$img_name, $max_width,$max_height,90);
create_thumbs($uploads_dir,$img_name,$tmb_name, $max_width_tmb,$max_height_tmb,80);
unlink("$uploads_dir/$org_name");
print ('Uploaded');
}
Expand Down

0 comments on commit 5760327

Please sign in to comment.