1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-19 04:02:28 +02:00

More fixes and Media Manager work - esp. file upload.

This commit is contained in:
CaMer0n 2012-05-22 13:32:49 +00:00
parent ca25aa7997
commit 629f7db1ab
6 changed files with 185 additions and 15 deletions

View File

@ -24,6 +24,7 @@ if (!getperms("A"))
exit;
}
/*
* CLOSE - GO TO MAIN SCREEN
*/
@ -407,6 +408,15 @@ class media_admin_ui extends e_admin_ui
}
echo $this->imageSelectUpload();
}
function uploadPage()
{
$text = '<div id="uploader" rel="'.e_FILE.'jslib/plupload/upload.php">
<p>No HTML5 support.</p>
</div>';
return $text;
}
function imageSelectUpload()
@ -451,7 +461,8 @@ class media_admin_ui extends e_admin_ui
$this->fields['media_url']['noedit'] = TRUE;
$this->fields['media_userclass']['noedit'] = TRUE;
$text .= $this->CreatePage();
//$text .= $this->uploadPage(); // To test upload script with plupload
$text .= $this->CreatePage(); // comment me out to test plupload
$text .= "
</fieldset>";

View File

@ -725,7 +725,7 @@ class admin_newspost
global $user_pref;
$qry = "";
$this->parseRequest($qry);
require_once(e_HANDLER."cache_handler.php");
@ -795,7 +795,7 @@ class admin_newspost
if ($this->_sort_order != 'asc') $this->_sort_order = 'desc';
$this->_sort_link = ($this->_sort_order) == 'asc' ? 'desc' : 'asc';
$sort_order = 'desc';
$this->_request = array($action, $sub_action, $id, $sort_order, $from);
}

View File

@ -1020,7 +1020,7 @@ function update_706_to_800($type='')
if($count ==1)
{
if ($just_check) return update_needed('Media-Manager Categories needs to be updated.');
$sql->db_Update('core_media_cat', "media_cat_owner = media_cat_nick, media_cat_category = media_cat_nick WHERE media_cat_nick REGEXP '_common|news|page|_icon_16|_icon_32|_icon_48|_icon_64' ");
$sql->db_Update('core_media_cat', "media_cat_owner = media_cat_nick, media_cat_category = media_cat_nick WHERE media_cat_nick REGEXP '_common|news|page|_icon_16|_icon_32|_icon_48|_icon_64' ");
$sql->db_Update('core_media_cat', "media_cat_owner = '_icon', media_cat_category = media_cat_nick WHERE media_cat_nick REGEXP '_icon_16|_icon_32|_icon_48|_icon_64' ");
$sql->db_Update('core_media_cat', "media_cat_owner = 'download', media_cat_category='download_image' WHERE media_cat_nick = 'download' ");
$sql->db_Update('core_media_cat', "media_cat_owner = 'download', media_cat_category='download_thumb' WHERE media_cat_nick = 'downloadthumb' ");
@ -1053,23 +1053,52 @@ function update_706_to_800($type='')
$sql->db_Update('core_media', "media_category='news_thumb' WHERE media_category = 'newsthumb' ");
e107::getMessage()->addDebug("core-media Category names updated");
}
// Media Update - core media and core-file.
$count = $sql->db_Select_gen("SELECT * FROM `#core_media` WHERE media_category = '_common' LIMIT 1 ");
if($count ==1)
{
if ($just_check) return update_needed('Media-Manager Category Data needs to be updated.');
$sql->db_Update('core_media', "media_category='_common_image' WHERE media_category = '_common' ");
e107::getMessage()->addDebug("core-media _common Category updated");
}
// Media Update - core media and core-file. CATEGORY
$count = $sql->db_Select_gen("SELECT * FROM `#core_media_cat` WHERE media_cat_category = '_common' LIMIT 1 ");
if($count ==1)
{
if ($just_check) return update_needed('Media-Manager Category Data needs to be updated.');
$sql->db_Update('core_media_cat', "media_cat_category='_common_image' WHERE media_cat_category = '_common' ");
mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_file', '(Common Area)', 'Media in this category will be available in all areas of admin. ', 253, '', 0);");
mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_file', 'Download Files', '', 253, '', 0);");
e107::getMessage()->addDebug("core-media-cat _common Category updated");
}
$count = $sql->db_Select_gen("SELECT * FROM `#core_media_cat` WHERE `media_cat_owner` = '_common' ");
$count = $sql->db_Select_gen("SELECT * FROM `#core_media_cat` WHERE `media_cat_owner` = '_common' LIMIT 1 ");
if($count != 1)
{
if ($just_check) return update_needed('Add Media-Manager Categories and Import existing images.');
mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common', '(Common Area)', 'Media in this category will be available in all areas of admin. ', 253, '', 0);");
mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_image', '(Common Images)', 'Media in this category will be available in all areas of admin. ', 253, '', 0);");
mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_file', '(Common Files)', 'Media in this category will be available in all areas of admin. ', 253, '', 0);");
mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'news', 'news', 'News', 'Will be available in the news area. ', 253, '', 1);");
mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'page', 'page', 'Custom Pages', 'Will be available in the custom pages area of admin. ', 253, '', 0);");
mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_image', 'Download Images', '', 253, '', 0);");
mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_thumb', 'Download Thumbnails', '', 253, '', 0);");
mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'download', 'download_file', 'Download Files', '', 253, '', 0);");
mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'gallery', 'gallery_1', 'Gallery', 'Visible to the public at /gallery.php', 0, '', 0);");
mysql_query("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, 'news', 'news_thumb', 'News Thumbnails (Legacy)', 'Legacy news thumbnails. ', 253, '', 1);");
$med->import('news_thumb', e_IMAGE.'newspost_images',"^thumb_");

View File

@ -43,6 +43,7 @@ class db_verify
'mismatch_index' => '', // TODO
);
var $errors = array();
/**
* Setup
*/
@ -213,7 +214,7 @@ class db_verify
// $debugA = $this->tables[$selection]['data'][$key]; // Extracted Raw Field Text
// $debugB = $sqlDataArr['data'][0]; // Extracted Raw Field Text
if($debugA)
if(isset($debugA))
{
$debug = "<table border='1'>
@ -316,8 +317,8 @@ class db_verify
{
foreach($this->results as $tabs => $field)
{
$file = $this->results[$tabs]['_file'];
if($this->errors[$tabs]['_status'] == 'missing_table') // Missing Table
$file = varset($this->results[$tabs]['_file']);
if(varset($this->errors[$tabs]['_status']) == 'missing_table') // Missing Table
{
$this->fixList[$file][$tabs]['all'][] = 'create';
}

View File

@ -23,6 +23,8 @@ class e_media
{
protected $imagelist = array();
protected $logging = true;
protected $mimePaths = array(
'text' => e_MEDIA_FILE,
'multipart' => e_MEDIA_FILE,
@ -278,7 +280,7 @@ class e_media
if(strpos($cat,"+") || !$cat)
{
$cat = str_replace("+","",$cat);
$inc[] = "media_category = '_common' ";
$inc[] = "media_category = '_common_image' ";
}
if($cat)
{
@ -481,6 +483,7 @@ class e_media
// $mes->addDebug("checkDupe(): newpath=".$newpath."<br />oldpath=".$oldpath."<br />".print_r($upload,TRUE));
if(file_exists($newpath) || e107::getDb()->db_Select("core_media","*","media_url = '".$tp->createConstants($newpath,'rel')."' LIMIT 1") )
{
$this->log($newpath." already exists and will be renamed during import.");
$mes->addWarning($newpath." already exists and was renamed during import.");
$file = $f['pathinfo']['filename']."_.".$f['pathinfo']['extension'];
$newpath = $this->getPath($f['mime']).'/'.$file;
@ -545,16 +548,30 @@ class e_media
}
public function importFile($file='',$category='_common')
public function log($message)
{
if($this->logging == false) return;
$insert = "\n".$message;
file_put_contents(e_UPLOAD."upload.log",$insert,FILE_APPEND | LOCK_EX);
}
public function importFile($file='',$category='_common_image')
{
$mes = e107::getMessage();
$tp = e107::getParser();
$sql = e107::getDb();
$oldpath = e_MEDIA."temp/".$file;
$oldpath = e_UPLOAD.$file;
if(!file_exists($oldpath))
{
$this->log("Couldn't find the file: ".$oldpath);
$mes->add("Couldn't find the file: ".$oldpath, E_MESSAGE_ERROR);
return;
}
@ -563,14 +580,17 @@ class e_media
if(!$typePath = $this->getPath($img_data['media_type']))
{
$this->log("Couldn't generated path from file info:".$oldpath);
$mes->addError("Couldn't generated path from file info:".$oldpath);
return FALSE;
}
$newpath = $this->checkDupe($oldpath,$typePath.'/'.$file);
if(!rename($oldpath, e_MEDIA.$newpath))
if(!rename($oldpath, $newpath)) // e_MEDIA.$newpath was working before.
{
$this->log("Couldn't move file from ".realpath($oldpath)." to ".e_MEDIA.$newpath);
$mes->add("Couldn't move file from ".$oldpath." to ".$newpath, E_MESSAGE_ERROR);
return FALSE;
};
@ -585,10 +605,12 @@ class e_media
if($sql->db_Insert("core_media",$img_data))
{
$mes->add("Importing Media: ".$file, E_MESSAGE_SUCCESS);
$this->log("Importing Media: ".$file." successful");
return $img_data['media_url'];
}
else
{
$this->log("Db Insert Failed ");
rename($newpath,$oldpath); //move it back.
return FALSE;
}

View File

@ -99,6 +99,30 @@ e107::js('core', 'core/colorbox/jquery.colorbox-min.js', 'jquery', 2);
e107::css('core', 'core/colorbox/colorbox.css', 'jquery');
e107::js('core', 'core/jquery.elastic.source.js', 'jquery', 2);
// e107::js('url', 'http://bp.yahooapis.com/2.4.21/browserplus-min.js', 'jquery', 2);
//e107::css('core', 'plupload/jquery.ui.plupload/css/jquery.ui.plupload.css', 'jquery');
e107::js('core', 'plupload/plupload.full.js', 'jquery', 2);
//e107::js('core', 'plupload/jquery.ui.plupload/jquery.ui.plupload.js','jquery',2);
e107::css('core', 'plupload/jquery.plupload.queue/css/jquery.plupload.queue.css', 'jquery');
e107::js('core', 'plupload/jquery.plupload.queue/jquery.plupload.queue.js', 'jquery', 2);
//
e107::js('inline','
$(document).ready(function()
@ -121,6 +145,11 @@ e107::js('inline','
$( "#tab-container" ).tabs();
});
// Tabs
$(function() {
$( ".e-tabs" ).tabs();
});
// Decorate
$(".adminlist tr:even").addClass("even");
$(".adminlist tr:odd").addClass("odd");
@ -276,17 +305,95 @@ e107::js('inline','
});
// Upload Handling
$(function() {
var path = $("#uploader").attr("rel");
$("#uploader").pluploadQueue({
// General settings
runtimes : "html5,html4",
url : path,
max_file_size : "10mb",
chunk_size : "1mb",
unique_names : false,
// Resize images on clientside if we can
resize : {width : 320, height : 240, quality : 90},
// Specify what files to browse for
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip,gz"}
]
,
// Error reporting etc
preinit: attachError,
setup: attachCallbacks
});
});
// Attach widget callbacks
function attachError(Uploader) {
Uploader.bind("FileUploaded", function(up, file, response) {
var data = $.parseJSON(response.response);
console.log("[FileUploaded] Response - " + response.response);
if (data.error == 1) {
up.trigger("Error", {message: "\'" + data.message + "\'", file: file});
console.log("[Error] " + file.id + " : " + data.message);
return false;
}
});
}
function attachCallbacks(Uploader) {
Uploader.bind("Init", function(up) {
up.settings.multipart_params = {
"upload_type" : $("#uploadQueue").attr("data-uploadType"),
"xref_id" : $("#uploadQueue").attr("data-xrefID"),
"image_category" : $("#uploadQueue").attr("data-imageCategory")
};
});
Uploader.bind("UploadComplete", function(up, files) {
console.log("[UploadComplete]");
$(".plupload_buttons").css("display", "inline");
$(".plupload_upload_status").css("display", "inline");
$(".plupload_start").addClass("plupload_disabled");
alert("it worked");
});
}
})
// BC Expandit() function
function expandit(e) {
var id = "#" + e; // TODO detect new "div" when e = "";
$(id).toggle("slow");
var href = $(e).attr("href");
if(href === "#" || href == "")
{
idt = $(e).next("div");
$(idt).toggle("slow");
return false;;
}
var id = "#" + e;
$(id).toggle("slow");
return false;
};