1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 13:47:31 +02:00

Batch Import can now read an .xml file of a matching name and use it's info during import for title and description. Batch XMLs will come later.

This commit is contained in:
CaMer0n
2012-07-12 01:43:38 +00:00
parent c59b733023
commit 90d3ecadcc
3 changed files with 83 additions and 8 deletions

View File

@@ -606,6 +606,8 @@ define('SITEADMIN', $pref['siteadmin']);
define('SITEADMINEMAIL', $pref['siteadminemail']); define('SITEADMINEMAIL', $pref['siteadminemail']);
define('SITEDISCLAIMER', $tp->toHTML($pref['sitedisclaimer'], '', 'emotes_off,defs')); define('SITEDISCLAIMER', $tp->toHTML($pref['sitedisclaimer'], '', 'emotes_off,defs'));
define('SITECONTACTINFO', $tp->toHTML($pref['sitecontactinfo'], true, 'emotes_off,defs')); define('SITECONTACTINFO', $tp->toHTML($pref['sitecontactinfo'], true, 'emotes_off,defs'));
define('SITEEMAIL', vartrue($pref['replyto_email'],$pref['siteadminemail']));
/* Withdrawn 0.8 /* Withdrawn 0.8
// legacy module.php file loading. // legacy module.php file loading.

View File

@@ -1082,7 +1082,7 @@ class media_admin_ui extends e_admin_ui
$f = e107::getFile()->get_file_info($oldpath,TRUE); $f = e107::getFile()->get_file_info($oldpath,TRUE);
// $mes->addDebug("checkDupe(): newpath=".$newpath."<br />oldpath=".$oldpath."<br />".print_r($upload,TRUE)); // $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") ) if(file_exists($newpath) || e107::getDb()->db_Select("core_media","*","media_url = '".$tp->createConstants($newpath,'rel')."' LIMIT 1") )
{ {
// $mes->addWarning($newpath." already exists and was renamed during import."); // $mes->addWarning($newpath." already exists and was renamed during import.");
$file = $f['pathinfo']['filename']."_.".$f['pathinfo']['extension']; $file = $f['pathinfo']['filename']."_.".$f['pathinfo']['extension'];
@@ -1135,9 +1135,11 @@ class media_admin_ui extends e_admin_ui
$fl = e107::getFile(); $fl = e107::getFile();
$fl->setFileInfo('all'); $fl->setFileInfo('all');
$files = $fl->get_files(e_MEDIA."temp/"); $rejectArray = array('^\.ftpquota$','^index\.html$','^null\.txt$','\.bak$','^.tmp','.*\.xml$','^\.$','^\.\.$','^\/$','^CVS$','thumbs\.db','.*\._$','^\.htaccess$','index\.html','null\.txt');
$files = $fl->get_files(e_MEDIA."temp/",'',$rejectArray);
e107::js('core','core/admin.js','prototype'); e107::js('core','core/admin.js','prototype');
// e107::getJs()->requireCoreLib('core/admin.js');
//TODO Detect XML file, and if found - read that instead of the directory. //TODO Detect XML file, and if found - read that instead of the directory.
@@ -1170,6 +1172,7 @@ class media_admin_ui extends e_admin_ui
<th class='center'>".LAN_FILE."</th> <th class='center'>".LAN_FILE."</th>
<th >Title</th> <th >Title</th>
<th >Caption</th> <th >Caption</th>
<th >Author</th>
<th>Mime Type</th> <th>Mime Type</th>
<th>File Size</th> <th>File Size</th>
<th>".LAN_DATESTAMP."</th> <th>".LAN_DATESTAMP."</th>
@@ -1181,6 +1184,7 @@ class media_admin_ui extends e_admin_ui
$c = 0; $c = 0;
foreach($files as $f) foreach($files as $f)
{ {
$default = $this->getFileXml($f['fname']);
$text .= " $text .= "
@@ -1188,8 +1192,10 @@ class media_admin_ui extends e_admin_ui
<td class='center'>".$frm->checkbox("batch_selected[".$c."]",$f['fname'])."</td> <td class='center'>".$frm->checkbox("batch_selected[".$c."]",$f['fname'])."</td>
<td class='center'>".$this->preview($f)."</td> <td class='center'>".$this->preview($f)."</td>
<td>".$f['fname']."</td> <td>".$f['fname']."</td>
<td>".$frm->text('batch_import_name['.$c.']', ($_POST['batch_import_name'][$c] ? $_POST['batch_import_name'][$c] : $f['fname']))."</td> <td>".$frm->text('batch_import_name['.$c.']', ($_POST['batch_import_name'][$c] ? $_POST['batch_import_name'][$c] : $default['title']))."</td>
<td>".$frm->textarea('batch_import_diz['.$c.']', $_POST['batch_import_diz'][$c])."</td> <td><textarea name='batch_import_diz['.$c.']' rows='3' cols='50'>". ($_POST['batch_import_diz'][$c] ? $_POST['batch_import_diz'][$c] : $default['description'])."</textarea></td>
<td><a href='mailto:".$default['authorEmail']."'>".$default['authorName']."</a></td>
<td>".$f['mime']."</td> <td>".$f['mime']."</td>
<td>".$f['fsize']."</td> <td>".$f['fsize']."</td>
<td>".e107::getDateConvert()->convert_date($f['modified'])."</td> <td>".e107::getDateConvert()->convert_date($f['modified'])."</td>
@@ -1201,7 +1207,7 @@ class media_admin_ui extends e_admin_ui
$c++; $c++;
} }
// <td>".$frm->textarea('batch_import_diz['.$c.']', ($_POST['batch_import_diz'][$c] ? $_POST['batch_import_diz'][$c] : $default['description']))."</td>
$text .= " $text .= "
</tbody> </tbody>
@@ -1237,6 +1243,65 @@ class media_admin_ui extends e_admin_ui
} }
// Check for matching XML file name and if found, return data from it during import.
function getFileXml($imgFile)
{
list($file,$ext) = explode(".",$imgFile);
$xmlFile = e_UPLOAD.$file.".xml";
if(is_readable($xmlFile))
{
$data = file_get_contents($xmlFile);
$tmp = preg_match("/<author name=(?:'|\")([^'\"]*)/i",$data,$authorName);
$tmp = preg_match("/email=(?:'|\")([^'\"]*)/i",$data,$authorEmail);
$tmp = preg_match("/<title>(.*)<\/title>/i",$data,$title);
$tmp = preg_match("/<description>(.*)<\/description>/i",$data,$diz);
return array(
'title' => $title[1],
'description' => $diz[1],
'authorName' => $authorName[1],
'authorEmail' => $authorEmail[1]
);
}
return array('title'=>basename($file),'description'=>'','authorName'=>'','authorEmail'=>'');
/*
Example: matchingfilename.xml (ie. same name as jpg|.gif|.png etc)
<?xml version='1.0' encoding='utf-8' ?>
<e107Media>
<item file='filename.jpg' date='2012-10-25'>
<author name='MyName' url='http://mysite.com' email='email@email.com' />
<title>Title of File</title>
<description>Description of File</description>
<category></category>
</item>
</e107Media>
*/
}
function deleteFileXml($imgFile)
{
list($file,$ext) = explode(".",$imgFile);
$xmlFile = e_UPLOAD.$file.".xml";
if(file_exists($xmlFile))
{
unlink($xmlFile);
}
}
function batchImport() function batchImport()
{ {
$fl = e107::getFile(); $fl = e107::getFile();
@@ -1353,6 +1418,7 @@ class media_admin_ui extends e_admin_ui
if($sql->db_Insert("core_media",$insert)) if($sql->db_Insert("core_media",$insert))
{ {
$mes->add("Importing Media: ".$f['fname'], E_MESSAGE_SUCCESS); $mes->add("Importing Media: ".$f['fname'], E_MESSAGE_SUCCESS);
$this->deleteFileXml($f['fname']);
} }
else else
{ {
@@ -1371,8 +1437,9 @@ class media_admin_ui extends e_admin_ui
if($type == 'image') if($type == 'image')
{ {
$url = e107::getParser()->thumbUrl($f['path'].$f['fname'], 'w=100', true); $url = e107::getParser()->thumbUrl($f['path'].$f['fname'], 'w=100', true);
$large = e107::getParser()->thumbUrl($f['path'].$f['fname'], 'w=800', true);
//echo $url; //echo $url;
return "<img src='".$url."' alt=\"".$f['name']."\" width='50px' />"; return "<a class='e-dialog' href='".$large."'><img src='".$url."' alt=\"".$f['name']."\" width='100px' /></a>";
} }
else else
{ {

View File

@@ -158,7 +158,13 @@ class e_file
{ {
$omit = array($omit); $omit = array($omit);
} }
if(count($omit))
{
$this->fileFilter = $omit;
} }
}
while (false !== ($file = readdir($handle))) while (false !== ($file = readdir($handle)))
{ {
if(is_dir($path.'/'.$file)) if(is_dir($path.'/'.$file))