// All rights reserved. This script is part of PHPWCMS. The PHPWCMS web content management system is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html A copy is found in the textfile GPL.txt and important notices to the license from the author is found in LICENSE.txt distributed with these scripts. This script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. This copyright notice MUST APPEAR in all copies of the script! *************************************************************************************/ /** * Sept. 2009 * enhancement to enable phpwcms filebrowser support in FCK Editor * based on concept and work of Markus Köhl * * April 2011 * - enhancement to enable phpwcms filebrowser support in CKEditor * based on concept and work of Markus Köhl * - Issue 265 based on TB's post */ session_start(); $phpwcms = array(); $phpwcms_root = dirname(__FILE__); $js_files_all = array(); $js_files_select = array(); require($phpwcms_root.'/config/phpwcms/conf.inc.php'); require($phpwcms_root.'/include/inc_lib/default.inc.php'); if( empty($_SESSION["wcs_user_lang"]) ) { session_destroy(); headerRedirect( PHPWCMS_URL ); } else { require(PHPWCMS_ROOT.'/include/inc_lang/backend/en/lang.ext.inc.php'); $cust_lang = PHPWCMS_ROOT.'/include/inc_lang/backend/' . strtolower(substr($_SESSION["wcs_user_lang"], 0, 2)) . '/lang.ext.inc.php'; if(is_file($cust_lang)) { include($cust_lang); } } // set target for article summary/list image if(isset($_GET['target'])) { switch($_GET['target']) { case 'list': $_SESSION['filebrowser_image_target'] = '_list_'; break; default: $_SESSION['filebrowser_image_target'] = '_'; } } elseif(empty($_SESSION['filebrowser_image_target'])) { $_SESSION['filebrowser_image_target'] = '_'; } if(isset($_GET['entry_id'])) { $_SESSION['filebrowser_image_entry_id'] = preg_replace('/[^a-z0-9_]/', '', $_GET['entry_id']); } require_once (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php'); require_once (PHPWCMS_ROOT.'/include/inc_lib/general.inc.php'); checkLogin(); require_once (PHPWCMS_ROOT.'/include/inc_lib/backend.functions.inc.php'); require_once (PHPWCMS_ROOT.'/include/inc_lib/imagick.convert.inc.php'); $phpwcms_filestorage = PHPWCMS_FILES; $js_aktion = (isset($_GET["opt"])) ? intval($_GET["opt"]) : 0; switch($js_aktion) { case 0: case 1: case 3: case 7: case 8: case 5: case 11: case 17: $titel = $BL['IMAGE_TITLE']; $filetype = $BL['IMAGE_FILES']; break; case 4: case 9: case 10: case 16: case 15: case 18: $titel = $BL['FILE_TITLE']; $filetype = $BL['FILES']; break; case 2: case 6: case 12: case 13: case 14: $titel = $BL['MEDIA_TITLE']; $filetype = $BL['MEDIA_FILES']; break; } if(isset($folder)) unset($folder); if(isset($_SESSION["folder"])) $folder = $_SESSION["folder"]; if(isset($_GET["folder"])) { list($folder_id, $folder_value) = explode('|', $_GET["folder"]); $folder[$folder_id] = intval($folder_value); $_SESSION["folder"] = $folder; //Rückgabe des Aktuellen Array mit Aufolderwerten in die Session } $_SESSION["list_zaehler"] = 0; //Zähler für die Public-Listenfunktion setzen //Checken, welcher Ordner aktiv if(isset($_GET["files"])) { $_SESSION["imgdir"] = intval($_GET["files"]); } elseif(!isset($_SESSION["imgdir"])) { $_SESSION["imgdir"] = 0; } else { $_SESSION["imgdir"] = intval($_SESSION["imgdir"]); } //Does user have files and folders that can be used $sql = "SELECT COUNT(f_id) FROM ".DB_PREPEND."phpwcms_file WHERE f_aktiv=1 AND (f_public=1 OR f_uid=".$_SESSION["wcs_user_id"].") AND f_trash=0 LIMIT 1"; if($result = mysql_query($sql, $db) or die ("error while counting private files")) { if($row = mysql_fetch_row($result)) $count_user_files = $row[0]; mysql_free_result($result); } ?> <?php echo $titel ?> '.LF; //Abstand vor echo ''.LF; //Aufbau trennende Tabellen-Zeile echo ''.LF; //Abstand nach echo ''.LF; //Wenn überhaupt Ordner für User vorhanden, dann Listing if(!$folder_status && $count_wert) { folder_list(0, $db, 18, "filebrowser.php?opt=".$js_aktion."&"); } echo '
     
'.LF; //Anzeige des Festplattensymbols $dirname = $BL['ROOT_DIR']; if(!isset($folder[0])) { $folder[0] = 0; } $folder_status = true_false($folder[0]); // Change based on Issue 265 by TB to allow file's uploader to select own items $count_sql = "SELECT COUNT(f_id) FROM ".DB_PREPEND."phpwcms_file WHERE f_pid=0 AND f_aktiv=1 AND f_trash=0 AND (f_public=1 OR f_uid=".$_SESSION["wcs_user_id"].") LIMIT 1"; if($count_result = mysql_query($count_sql, $db)) { if($count_row = mysql_fetch_row($count_result)) { $count = ''.on_off($folder_status, $dirname, 0).''; $count_wert = $count_row[0]; } mysql_free_result($count_result); } // define current directory name $current_dirname = $dirname; $dirname = "".$dirname.""; $bgcol = (isset($row["f_id"]) && $row["f_id"] == $_SESSION["imgdir"]) ? ' bgcolor="#FED83F"' : ''; echo '
'; echo $count.''; //Zellinhalt 1. Spalte echo ''.$dirname.'
'; } else { echo "no files available"; } ?> '.LF; $file_sql = "SELECT * FROM ".DB_PREPEND."phpwcms_file WHERE f_pid=".$_SESSION["imgdir"]." AND "; switch($js_aktion) { case 6: $file_sql .= "f_ext IN ('swf', 'mp3', 'flv', 'mp4', 'm4v', 'f4v', 'jpg', 'jpeg', 'png', 'gif') AND "; break; // H.264 case 12: $file_sql .= "f_ext IN ('mp4', 'm4p', 'mov', 'm4p', 'm4a', 'm4v') AND "; break; // WebM case 13: $file_sql .= "f_ext IN ('webm') AND "; break; // Ogg case 14: $file_sql .= "f_ext IN ('ogg', 'ogv', 'oga', 'ogx') AND "; break; // Typical Doc files case 18: $file_sql .= "f_ext IN ('pdf', 'doc', 'docx', 'txt', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp', 'pages', 'key', 'numbers') AND "; case 15: $entry_id = empty($_SESSION['filebrowser_image_entry_id']) ? '' : $_SESSION['filebrowser_image_entry_id']; break; case 11: case 17: case 8: $entry_id = empty($_SESSION['filebrowser_image_entry_id']) ? '' : $_SESSION['filebrowser_image_entry_id']; case 7: $file_sql .= "f_ext IN ('jpeg', 'jpg', 'png', 'gif') AND "; break; case 2: $default_ext = "f_ext IN ('aif', 'aiff', 'mov', 'movie', 'mp3', 'mpeg', 'mpeg4', "; $default_ext .= "'mpeg2', 'wav', 'swf', 'ram', 'ra', 'wma', 'wmv', "; $default_ext .= "'avi', 'au', 'midi', 'moov', 'rm', 'rpm', 'mid', 'midi')"; if(!empty($phpwcms["multimedia_ext"])) { $allowed_ext = convertStringToArray(strtolower($phpwcms["multimedia_ext"])); if(count($allowed_ext)) { $default_ext = "f_ext IN ('".implode("', '", $allowed_ext) . "')"; } } $file_sql .= $default_ext." AND "; break; } $file_sql .= "f_aktiv=1 AND f_kid=1 AND f_trash=0 AND "; $file_sql .= "(f_public=1 OR f_uid=".$_SESSION["wcs_user_id"].") "; $file_sql .= "ORDER BY f_sort, f_name"; if($file_result = mysql_query($file_sql, $db) or die ("error while listing files
".html_entities($file_sql))) { $file_durchlauf = 0; if(empty($_SESSION['image_browser_article'])) { $target_form = 'articlecontent'; } else { $target_form = 'article'; } while($file_row = mysql_fetch_array($file_result)) { $filename = html_specialchars($file_row["f_name"]); $thumb_image = true; if( !in_array($js_aktion, array(2, 4, 9, 10, 16, 18)) ) { // check if file can have thumbnail - if so it can be choosen for usage $thumb_image = get_cached_image( array( "target_ext" => $file_row["f_ext"], "image_name" => $file_row["f_hash"] . '.' . $file_row["f_ext"], "thumb_name" => md5($file_row["f_hash"].$phpwcms["img_list_width"].$phpwcms["img_list_height"].$phpwcms["sharpen_level"]) ) ); } if($thumb_image != false || in_array($js_aktion, array(6, 10, 12, 13, 14, 16, 18))) { $js_files_select[$file_durchlauf] = ' [' . $file_durchlauf .', ' . $file_row["f_id"] . ', "' . $filename . '"]'; $add_all = false; switch($js_aktion) { case 0: $jst = empty($_SESSION['filebrowser_image_target']) ? '_' : $_SESSION['filebrowser_image_target']; $js = "window.opener.document.".$target_form.".cimage".$jst."name.value='".$filename."';"; $js .= "window.opener.document.".$target_form.".cimage".$jst."id.value='".$file_row["f_id"]."';"; break; case 2: $js = "window.opener.document.articlecontent.cmedia_name.value='".$filename."';"; $js .= "window.opener.document.articlecontent.cmedia_id.value='".$file_row["f_id"]."';"; break; case 6: case 12: case 13: case 14: $js = "window.opener.setIdName('".$file_row["f_id"]."', '".$filename."', ".$js_aktion.");"; break; case 18: case 15: $js = "window.opener.setIdName('".$entry_id."', '".$file_row["f_id"]."', '".$filename."');"; break; case 7: $js = "window.opener.setImgIdName('".$file_row["f_id"]."', '".$filename."');"; break; case 8: $js = "window.opener.setImgIdName('".$entry_id."', '".$file_row["f_id"]."', '".$filename."');"; break; case 4: $js = "addFile(window.opener.document.articlecontent.cfile_list,'".$filename."','".$file_row["f_id"]."');"; $js_files_all[] = $js; $add_all = true; break; case 9: $js = "window.opener.addFile('".$file_row["f_id"]."', '".$filename."');"; $js_files_all[] = $js; $add_all = true; break; case 5: $js = "addFile(window.opener.img_field,'".$filename."','".$file_row["f_id"]."');"; $js_files_all[] = $js; $add_all = true; break; //mod case 10: $js = "window.opener.SetUrl('download.php?f=".$file_row["f_hash"] . "&target=0');"; break; case 11: $js = "window.opener.SetUrl('image_resized.php?format=" . $file_row["f_ext"]. "&q=85&imgfile=".$phpwcms_filestorage.$file_row["f_hash"] . '.' . $file_row["f_ext"]. "');"; break; //CKEditor case 16: $js = "window.opener.CKEDITOR.tools.callFunction(2, 'download.php?f=".$file_row["f_hash"] . "&target=0');"; break; case 17: $js = "window.opener.CKEDITOR.tools.callFunction(2,'image_resized.php?format=" . $file_row["f_ext"]. "&q=85&imgfile=".$phpwcms_filestorage.$file_row["f_hash"] . '.' . $file_row["f_ext"]. "');"; break; default: $js = "addFile(window.opener.document.articlecontent.cimage_list,'".$filename."','".$file_row["f_id"]."');"; $js_files_all[] = $js; $add_all = true; } // show "add all files" if($file_durchlauf === 0 && $add_all) { echo ' ' . $BL['ADD_ALL_FILES'] . ' '; } echo ''.LF; echo "\n\"\"\n"; if($js_aktion != 4 && $js_aktion != 10 && $js_aktion != 16) { echo "".$filename."\n\"\""; } else { echo "".$filename."\n"; } echo ""; echo "\"\"\n"; echo "\"\"\n\n"; echo "\"\"\n"; if(!empty($thumb_image[0]) && in_array( $js_aktion, array(0, 1, 3, 5, 6, 7, 8, 10, 11, 17, 18) ) ) { echo " \n"; echo ''; echo "\n\n"; } echo "\"\"\n"; echo "\"\"\n"; $file_durchlauf++; } } if(!$file_durchlauf) { //Abschluss der Filelisten-Tabelle echo "\"\"\n"; echo " ".$BL['NO_FILE']."  \n"; echo "\"\"\n"; } } //Ende Liste Dateien echo ""; if( count($js_files_select) ) { echo LF . '' . LF; } ?> '.on_off($folder_status, $dirname, 0).''; $count_wert = $count_row[0]; } mysql_free_result($count_result); } $dirname = ''. $dirname . ''; if($row["f_id"] == $_SESSION["imgdir"]) { $bgcol = ' bgcolor="#FED83F"'; $current_dirname = $row["f_name"]; } else { $bgcol = ''; } //Aufbau der Zeile echo "\"\"\n"; //Abstand vor echo ""; echo $count."\"\"\"\""; //Zellinhalt 1. Spalte echo "\"\"".$dirname."\"\"\n"; //Aufbau trennende Tabellen-Zeile echo "\"\"\n"; //Abstand nach echo "\"\"\n"; //Trennlinie //Weiter, wenn Unterstruktur if(!$folder_status && $count_wert) { folder_list($row["f_id"], $dbcon, $vor+18, $zieldatei); //, $userID } //Zaehler mitführen $_SESSION["list_zaehler"]++; } mysql_free_result($result); } function on_off($wert, $string, $art = 1) { //Erzeugt das Status-Zeichen für Klapp-Auf/Zu //Wenn Art = 1 dann als Zeichen, ansonsten als Bild if($wert) { if($art == 1) { return "+"; } else { return "\"\""; } } else { if($art == 1) { return "-"; } else { return "\"\""; } } } function true_false($wert) { //Wechselt den Wahr/Falsch wert zum Gegenteil: 1=>0 und 0=>1 if(intval($wert)) { return 0; } else { return 1; } } ?>