array(
'controller' => 'media_admin_ui',
'path' => null,
'ui' => 'media_form_ui',
'uipath' => null
),
'cat' => array(
'controller' => 'media_cat_ui',
'path' => null,
'ui' => 'media_cat_form_ui',
'uipath' => null
)
);
protected $adminMenu = array(
'main/list' => array('caption'=> 'Media Library', 'perm' => 'A'),
'main/create' => array('caption'=> "Add New Media", 'perm' => 'A'), // Should be handled in Media-Import.
'main/import' => array('caption'=> "Media Import", 'perm' => 'A|A2'),
'cat/list' => array('caption'=> 'Media Categories', 'perm' => 'A'),
'cat/create' => array('caption'=> "Create Category", 'perm' => 'A'), // is automatic.
// 'main/icons' => array('caption'=> IMALAN_71, 'perm' => 'A'),
'main/settings' => array('caption'=> LAN_PREFS, 'perm' => 'A'),
'main/avatar' => array('caption'=> IMALAN_23, 'perm' => 'A')
);
/*
$var['main']['text'] = IMALAN_7;
$var['main']['link'] = e_SELF;
$var['icons']['text'] = IMALAN_71;
$var['icons']['link'] = e_SELF."?icons";
$var['avatars']['text'] = IMALAN_23;
$var['avatars']['link'] = e_SELF."?avatars";
$var['editor']['text'] = "Image Manipulation (future release)";
$var['editor']['link'] = e_SELF."?editor";*/
protected $adminMenuAliases = array(
'main/edit' => 'main/list'
);
protected $menuTitle = LAN_MEDIAMANAGER;
}
class media_cat_ui extends e_admin_ui
{
protected $pluginTitle = 'Media Categories';
protected $pluginName = 'core';
protected $table = "core_media_cat";
protected $pid = "media_cat_id";
protected $perPage = 0; //no limit
protected $batchDelete = false;
public $ownerCount = array();
// protected $listQry = "SELECT * FROM #faq_info"; // without any Order or Limit.
// protected $editQry = "SELECT * FROM #faq_info WHERE faq_info_id = {ID}";
protected $fields = array(
//'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'media_cat_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE, 'readonly'=>TRUE),
'media_cat_image' => array('title'=> LAN_IMAGE, 'type' => 'image', 'data' => 'str', 'width' => '100px', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>FALSE, 'batch' => FALSE, 'filter'=>FALSE),
'media_cat_owner' => array('title'=> "Owner", 'type' => 'dropdown', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE),
'media_cat_category' => array('title'=> LAN_CATEGORY, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>TRUE),
'media_cat_title' => array('title'=> LAN_TITLE, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE),
'media_cat_diz' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=150&bb=1','readonly'=>FALSE), // Display name
'media_cat_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int'),
'media_cat_order' => array('title'=> LAN_ORDER, 'type' => 'text', 'width' => '5%', 'thclass' => 'right', 'class'=> 'right' ),
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center')
);
function init()
{
$this->fields['media_cat_owner']['writeParms'] = array(
"_common" => "_common",
"_icon" => "_icon",
"news" => "news",
"page" => "page",
"gallery" => "gallery",
"download" => "download"
);
$sql = e107::getDb();
$sql->db_Select_gen("SELECT media_cat_owner, count(media_cat_id) as number FROM `#core_media_cat` GROUP BY media_cat_owner");
while($row = $sql->db_Fetch())
{
$this->ownerCount[$row['media_cat_owner']] = $row['number'];
}
}
public function beforeCreate($new_data)
{
//$replace = array("_"," ","'",'"',"."); //FIXME Improve
//$new_data['media_cat_category'] = str_replace($replace,"-",$new_data['media_cat_category']);
$increment = ($this->ownerCount[$new_data['media_cat_owner']] +1);
$new_data['media_cat_category'] = $new_data['media_cat_owner']."_".$increment;
return $new_data;
}
public function beforeUpdate($new_data, $old_data, $id)
{
$mes = e107::getMessage();
if($new_data['media_cat_owner'] != "gallery")
{
$mes->addError("Modification is not permitted");
return FALSE;
}
return $new_data;
}
}
class media_cat_form_ui extends e_admin_form_ui
{
}
class media_form_ui extends e_admin_form_ui
{
function init()
{
/*$sql = e107::getDb();
// $sql->db_Select_gen("SELECT media_cat_title, media_title_nick FROM #core_media as m LEFT JOIN #core_media_cat as c ON m.media_category = c.media_cat_owner GROUP BY m.media_category");
$sql->db_Select_gen("SELECT media_cat_title, media_cat_owner FROM #core_media_cat");
while($row = $sql->db_Fetch())
{
$cat = $row['media_cat_owner'];
$this->cats[$cat] = $row['media_cat_title'];
}
asort($this->cats);*/
}
function media_category($curVal,$mode) // not really necessary since we can use 'dropdown' - but just an example of a custom function.
{
if($mode == 'read')
{
return $this->getController()->getMediaCategory($curVal);
//return $this->cats[$curVal];
}
if($mode == 'batch') // Custom Batch List for release_type
{
return $this->getController()->getMediaCategory();
}
if($mode == 'filter') // Custom Filter List for release_type
{
return $this->getController()->getMediaCategory();
}
$text = "";
$cats = $this->getController()->getMediaCategory();
foreach($cats as $key => $val)
{
$selected = ($curVal == $key) ? "selected='selected'" : "";
$text .= "".$val." \n";
}
$text .= " ";
return $text;
}
}
class media_admin_ui extends e_admin_ui
{
protected $pluginTitle = LAN_MEDIAMANAGER;
protected $pluginName = 'core';
protected $table = "core_media";
protected $listQry = "SELECT m.*,u.user_id,u.user_name FROM #core_media AS m LEFT JOIN #user AS u ON m.media_author = u.user_id "; // without any Order or Limit.
// //protected $editQry = "SELECT * FROM #comments WHERE comment_id = {ID}";
// protected $tableJoin = array(
// 'u.user' => array('leftField' => 'media_author', 'rightField' => 'user_id', 'fields' => 'user_id,user_loginname,user_name')
// );
protected $pid = "media_id";
protected $perPage = 10;
protected $batchDelete = true;
// protected $defaultOrder = 'desc';
protected $listOrder = 'm.media_id desc'; // show newest images first.
//TODO - finish 'user' type, set 'data' to all editable fields, set 'noedit' for all non-editable fields
/*
* We need a column with a preview that is generated from the path of another field.
* ie. the preview column should show a thumbnail which is generated from the media_url column.
* It needs to also take into consideration the type of media (image, video etc) which comes from another field.
*/
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'data'=> null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'media_id' => array('title'=> LAN_ID, 'type' => 'number', 'data'=> 'int', 'width' =>'5%', 'forced'=> TRUE, 'nolist'=>TRUE),
'media_url' => array('title'=> 'Preview', 'type' => 'image', 'data'=> 'str', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>TRUE, 'writeParams' => 'path={e_MEDIA}', 'width' => '110px'),
'media_category' => array('title'=> LAN_CATEGORY, 'type' => 'method', 'data'=> 'str', 'width' => 'auto', 'filter' => true, 'batch' => true,),
// Upload should be managed completely separately via upload-handler.
'media_upload' => array('title'=> "Upload File", 'type' => 'upload', 'data'=> false, 'readParms' => 'hidden', 'writeParms' => 'disable_button=1', 'width' => '10%', 'nolist' => true),
'media_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'data'=> 'str', 'width' => 'auto'),
'media_caption' => array('title'=> "Caption", 'type' => 'text', 'data'=> 'str', 'width' => 'auto'),
// media_description is type = textarea until bbarea can be reduced to not include youtube etc
'media_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'textarea', 'data'=> 'str', 'width' => 'auto', 'thclass' => 'left first', 'readParms' => 'truncate=100', 'writeParms' => 'counter=0'),
'media_type' => array('title'=> "Mime Type", 'type' => 'text', 'data'=> 'str', 'width' => 'auto', 'noedit'=>TRUE),
'media_author' => array('title'=> LAN_USER, 'type' => 'user', 'data'=> 'int', 'width' => 'auto', 'thclass' => 'center', 'class'=>'center','readParms' => 'link=1', 'filter' => true, 'batch' => true, 'noedit'=>TRUE ),
'media_datestamp' => array('title'=> LAN_DATESTAMP, 'type' => 'datestamp', 'data'=> 'int', 'width' => '10%', 'noedit'=>TRUE), // User date
'media_size' => array('title'=> "Size", 'type' => 'number', 'data'=> 'int', 'width' => 'auto', 'noedit'=>TRUE),
'media_dimensions' => array('title'=> "Dimensions", 'type' => 'text', 'data'=> 'str', 'width' => '5%', 'readonly'=>TRUE, 'class'=>'nowrap','noedit'=>TRUE),
'media_userclass' => array('title'=> LAN_USERCLASS, 'type' => 'userclass', 'data'=> 'str', 'width' => '10%', 'thclass' => 'center','filter'=>TRUE,'batch'=>TRUE ),
'media_tags' => array('title'=> "Tags/Keywords", 'type' => 'text', 'data'=> 'str', 'width' => '10%', 'filter'=>TRUE,'batch'=>TRUE ),
'media_usedby' => array('title'=> '', 'type' => 'text', 'data'=> 'text', 'width' => 'auto', 'thclass' => 'center', 'class'=>'center', 'nolist'=>true, 'readonly'=>TRUE ),
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'data'=> null, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center')
);
protected $mimePaths = array(
'text' => e_MEDIA_FILE,
'multipart' => e_MEDIA_FILE,
'application' => e_MEDIA_FILE,
'audio' => e_MEDIA_AUDIO,
'image' => e_MEDIA_IMAGE,
'video' => e_MEDIA_VIDEO,
'other' => e_MEDIA_FILE
);
// protected $fieldpref = array('checkboxes','media_url', 'media_id', 'media_thumb', 'media_title', 'media_caption', 'media_description', 'media_category', 'media_datestamp','media_userclass', 'options');
/*
protected $prefs = array(
'pref_type' => array('title'=> 'type', 'type'=>'text'),
'pref_folder' => array('title'=> 'folder', 'type' => 'boolean'),
'pref_name' => array('title'=> 'name', 'type' => 'text')
);*/
protected $cats = array();
protected $owner = array();
protected $ownercats = array();
function init()
{
$sql = e107::getDb();
// $sql->db_Select_gen("SELECT media_cat_title, media_title_nick FROM #core_media as m LEFT JOIN #core_media_cat as c ON m.media_category = c.media_cat_owner GROUP BY m.media_category");
$sql->db_Select_gen("SELECT media_cat_title, media_cat_owner, media_cat_category FROM #core_media_cat");
while($row = $sql->db_Fetch())
{
$cat = $row['media_cat_category'];
$owner = $row['media_cat_owner'];
$this->owner[$owner] = $owner;
$this->ownercats[$owner.'|'.$cat] = $row['media_cat_title'];
$this->cats[$cat] = $row['media_cat_title'];
}
asort($this->cats);
if(varset($_POST['batch_import_selected']))
{
$this->batchImport();
}
if(varset($_POST['update_options']))
{
$this->updateSettings();
}
if($this->getQuery('iframe'))
{
if($this->getQuery('bbcode'))
{
e107::getJs()->headerFile(e_PLUGIN_ABS.'tinymce/tiny_mce_popup.js',2);
e107::getJS()->headerInline("
/* Send the generated IMG bbcode back to the textarea/window */
function saveBB()
{
var add = document.getElementById('bbcode_holder').value;
var html = document.getElementById('html_holder').value;
// tinyMCE.execCommand('mceInsertContent',false,add);
tinyMCE.execCommand('mceInsertRawHTML',false,html);
tinyMCEPopup.close();
//addtext(add);
//parent.e107Widgets.DialogManagerDefault.getWindow('e-dialog').close();
return false;
}
");
}
$this->getResponse()->setIframeMod(); // disable header/footer menus etc.
if(!$this->getQuery('for'))
{
$this->setPosted('media_category', "_common");
$this->getModel()->set('media_category', "_common");
}
elseif($this->getMediaCategory($this->getQuery('for')))
{
$this->setPosted('media_category', $this->getQuery('for'));
if(!$this->getId())
{
$this->getModel()->set('media_category', $this->getQuery('for'));
}
}
}
//
// if($this->getQuery('for') && $this->getMediaCategory($this->getQuery('for')))
// {
//
// $this->setPosted('media_category', $this->getQuery('for'));
// if(!$this->getId())
// {
// $this->getModel()->set('media_category', $this->getQuery('for'));
// }
// }
//
}
function dialogPage() // Popup dialogPage for Image Selection.
{
// $this->getModel()->setAction('create');
// $this->getUI()->getController()->getRequest()->setAction('create');
//$this->setAction('create');;
if($_POST['etrigger_submit'])
{
$data = $this->beforeCreate($_POST);
e107::getDb()->db_Insert('core_media',$data); // Replace with Generic (needs parm sent)
}
echo $this->imageSelectUpload();
}
function imageSelectUpload()
{
$frm = e107::getForm();
$bbcodeMode = ($this->getQuery('bbcode')==1) ? 'bbcode=1' : FALSE;
$text = "
Library
";
$text .= e107::getMedia()->mediaSelect($this->getQuery('for'),$this->getQuery('tagid'),$bbcodeMode); // eg. news, news-thumbnail
$text .= "
Upload ";
$this->fields['media_category']['readonly'] = TRUE;
$this->fields['media_url']['noedit'] = TRUE;
$this->fields['media_userclass']['noedit'] = TRUE;
$text .= $this->CreatePage();
$text .= "
";
/* In BBCODE-Mode this dialog rerturns an [img] bbcode to the 'tagid' container with the appropriate parms generated.
* eg. [img style=float:left;margin-right:3px]{e_MEDIA_IMAGE}someimage.jpg[/img]
* Then the dialog may be used as a bbcode img popup and within TinyMce also.
*
*/
if($bbcodeMode)
{
$text .= "
Appearance
Preview
";
}
$text .= "
";
// For BBCODE mode. //TODO image-float.
if($bbcodeMode)
{
$text .= "To be Hidden
bbcode:
html:
src:
";
$text .= "
Save
Cancel
";
e107::getJs()->footerInline("
/* Generate an IMG bbcode based on input by user */
function updateBB()
{
var style = '';
var bb = '';
var src = document.getElementById('src').value;
var width = document.getElementById('width').value;
var height = document.getElementById('height').value;
var margin_top = document.getElementById('margin-top').value;
var margin_bottom = document.getElementById('margin-bottom').value;
var margin_right = document.getElementById('margin-right').value;
var margin_left = document.getElementById('margin-left').value;
if(width !='')
{
// style = style + 'width:' + width + 'px;';
}
if(height !='')
{
// style = style + 'height:' + height + 'px;';
}
if(margin_right !='')
{
style = style + 'margin-right:' + margin_right + 'px;';
}
if(margin_left !='')
{
style = style + 'margin-left:' + margin_left + 'px;';
}
if(margin_top !='')
{
style = style + 'margin-top:' + margin_top + 'px;';
}
if(margin_bottom !='')
{
style = style + 'margin-bottom:' + margin_bottom + 'px;';
}
bb = '[img';
if(style !='')
{
bb = bb + ' style='+style;
}
bb = bb + ']';
bb = bb + src;
bb = bb + '[/img]';
document.getElementById('bbcode_holder').value = bb;
// var html = ' ';
var html = ' ';
document.getElementById('html_holder').value = html;
}
");
}
return $text;
}
function importPage()
{
$this->batchImportForm();
}
function settingsPage()
{
main_config();
}
function avatarPage()
{
show_avatars();
}
function iconsPage()
{
// $this->icon_editor();
}
/**
* Invoked just before item create event
* @return array
*/
public function beforeCreate($new_data)
{
// print_a($_POST);
// return data to be merged with posted model data
$this->getRequest()->setPosted('media_upload', null);
//$dataFields = $this->getModel()->getDataFields();
//unset($dataFields['media_upload']);
//$this->getModel()->setDataFields($dataFields);
if($this->getQuery('for') && $this->getMediaCategory($this->getQuery('for')))
{
$new_data['media_category'] = $this->getQuery('for');
}
return $this->observeUploaded($new_data);
}
/**
* Same as beforeCreate() but invoked on edit
* @return TBD
*/
public function beforeUpdate($new_data, $old_data, $id)
{
// return data to be merged with posted model data
return $this->observeUploaded($new_data);
}
public function mediaData($sc_path)
{
if(!$sc_path) return array();
$path = e107::getParser()->replaceConstants($sc_path);
$info = e107::getFile()->get_file_info($path);
return array(
'media_type' => $info['mime'],
'media_datestamp' => time(),
'media_url' => e107::getParser()->createConstants($path, 'rel'),
'media_size' => filesize($path),
'media_author' => USERID,
'media_usedby' => '',
'media_tags' => '',
'media_dimensions' => $info['img-width']." x ".$info['img-height']
);
}
// XXX - strict mysql error on Create without UPLOAD!
function observeUploaded($new_data)
{
$fl = e107::getFile();
$mes = e107::getMessage();
if(vartrue($_FILES['file_userfile'])) // CREATE
{
$pref['upload_storagetype'] = "1";
require_once(e_HANDLER."upload_handler.php"); //TODO - still not a class!
$uploaded = process_uploaded_files(e_MEDIA.'temp/'); //FIXME doesn't handle xxx.JPG (uppercase)
$upload = array_shift($uploaded);
if(vartrue($upload['error']))
{
$mes->addError($upload['message']);
return FALSE;
}
if(!$typePath = $this->getPath($upload['type']))
{
$mes->addError("Couldn't generated path from upload data");
return FALSE;
}
$mes->addDebug(print_a($upload,TRUE));
$oldpath = e_MEDIA."temp/".$upload['name'];
$newpath = $this->checkDupe($oldpath,$typePath.'/'.$upload['name']);
if(!rename($oldpath, e_MEDIA.$newpath))
{
$mes->add("Couldn't move file from ".$oldpath." to ".$newpath, E_MESSAGE_ERROR);
return FALSE;
};
$img_data = $this->mediaData($newpath); // Basic File Info only
$img_data['media_name'] = $new_data['name'];
$img_data['media_caption'] = $new_data['media_caption'];
$img_data['media_category'] = $new_data['media_category'];
$img_data['media_description'] = $new_data['media_description'];
$img_data['media_tags'] = $new_data['media_tags'];
$img_data['media_userclass'] = 0;
$img_data['media_author'] = USERID;
if(!varset($img_data['media_name']))
{
$img_data['media_name'] = $upload['name'];
}
$mes->addDebug(print_a($img_data,TRUE));
return $img_data;
}
else // Update Only ?
{
$img_data = $this->mediaData($new_data['media_url']);
if(!($typePath = $this->getPath($img_data['media_type'])))
{
$mes->addError("Couldn't get path ".$typePath);
return FALSE;
}
$fname = basename($new_data['media_url']);
// move to the required place
if(strpos($new_data['media_url'], '{e_MEDIA}temp/') !== FALSE)
{
$tp = e107::getParser();
$oldpath = $tp->replaceConstants($new_data['media_url']);
$newpath = $this->checkDupe($oldpath,$typePath.'/'.$fname);
if(!rename($oldpath, $newpath))
{
$mes->add("Couldn't move file from ".$oldpath." to ".str_replace('../', '', $newpath), E_MESSAGE_ERROR);
return FALSE;
}
$img_data['media_url'] = $tp->createConstants($newpath, 'rel');
}
if(!varset($new_data['media_name']))
{
$img_data['media_name'] = basename($new_data['media_url']);
}
return $img_data;
}
}
// Check for existing image path in db and rename if found.
function checkDupe($oldpath,$newpath)
{
$mes = e107::getMessage();
$tp = e107::getParser();
$f = e107::getFile()->get_file_info($oldpath,TRUE);
// $mes->addDebug("checkDupe(): newpath=".$newpath." oldpath=".$oldpath." ".print_r($upload,TRUE));
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.");
$file = $f['pathinfo']['filename']."_.".$f['pathinfo']['extension'];
$newpath = $this->getPath($f['mime']).'/'.$file;
}
return $newpath;
}
function beforeDelete($data, $id) // call before 'delete' is executed. - return false to prevent delete execution (e.g. some dependencies check)
{
return true;
}
function afterDelete($deleted_data, $id) // call after 'delete' is successfully executed. - delete the file with the db record (optional pref)
{
}
function getPath($mime)
{
$mes = e107::getMessage();
list($pmime,$tmp) = explode('/',$mime);
if(!vartrue($this->mimePaths[$pmime]))
{
$mes->add("Couldn't detect mime-type($mime). Upload failed.", E_MESSAGE_ERROR);
return FALSE;
}
$dir = $this->mimePaths[$pmime].date("Y-m");
if(!is_dir($dir))
{
if(!mkdir($dir, 0755))
{
$mes->add("Couldn't create folder ($dir).", E_MESSAGE_ERROR);
return FALSE;
};
}
return $dir;
}
function batchImportForm()
{
$frm = e107::getForm();
$mes = e107::getMessage();
$fl = e107::getFile();
$fl->setFileInfo('all');
$files = $fl->get_files(e_MEDIA."temp/");
e107::getJs()->requireCoreLib('core/admin.js');
//TODO Detect XML file, and if found - read that instead of the directory.
if(!vartrue($_POST['batch_import_selected']))
{
$mes->add("Scanning for new media (images, videos, files) in folder: ".e_MEDIA."temp/", E_MESSAGE_INFO);
}
if(!count($files))
{
$mes->add("No media Found! Please upload some files and then refresh this page.", E_MESSAGE_INFO);
return;
}
$text = "
";
echo $mes->render().$text;
}
function batchImport()
{
$fl = e107::getFile();
$mes = e107::getMessage();
$sql = e107::getDb();
$tp = e107::getParser();
if(!count($_POST['batch_selected']))
{
$mes->addError("Please check at least one image.");
return;
}
require(e_HANDLER.'phpthumb/ThumbLib.inc.php'); // For resizing on import.
list($img_import_w,$img_import_h) = explode("x",e107::getPref('img_import_resize'));
if(vartrue($_POST['batch_import_watermark']))
{
$WM = TRUE;
$watermarkPath = e_THEME.e107::getPref('sitetheme')."/images/watermark.png";
$watermark = PhpThumbFactory::create($watermarkPath);
}
else
{
$WM = FALSE;
}
foreach($_POST['batch_selected'] as $key=>$file)
{
$oldpath = e_MEDIA."temp/".$file;
// Resize on Import Routine ------------------------
if(vartrue($img_import_w) && vartrue($img_import_h))
{
try
{
$thumb = PhpThumbFactory::create($oldpath);
$thumb->setOptions(array('correctPermissions' => true));
}
catch (Exception $e)
{
$mes->addError($e->getMessage());
continue;
// return $this;
}
if($WM) // TODO Add watermark prefs for alpha and position.
{
$thumb->resize($img_import_w,$img_import_h)->addWatermark($watermark, 'rightBottom', 30, 0, 0)->save($oldpath);
}
else
{
$thumb->resize($img_import_w,$img_import_h)->save($oldpath);
}
}
// End Resize routine. ---------------------
$f = $fl->get_file_info($oldpath);
if(!$f['mime'])
{
$mes->add("Couldn't get file info from : ".$oldpath, E_MESSAGE_ERROR);
}
$newpath = $this->checkDupe($oldpath,$this->getPath($f['mime']).'/'.$file);
$newname = $tp->toDB($_POST['batch_import_name'][$key]);
$newdiz = $tp->toDB($_POST['batch_import_diz'][$key]);
$f['fname'] = $file;
/*
if(file_exists($newpath) || $sql->db_Select("core_media","media_url = '".$tp->createConstants($newpath,'rel')."' LIMIT 1") )
{
$mes->addWarning($newpath." already exists and was renamed during import.");
$file = $f['pathinfo']['filename']."_.".$f['pathinfo']['extension'];
$newpath = $this->getPath($f['mime']).'/'.$file;
}
*/
if(rename($oldpath,$newpath))
{
$insert = array(
'media_caption' => $newdiz,
'media_description' => '',
'media_category' => $_POST['batch_category'],
'media_datestamp' => $f['modified'],
'media_url' => $tp->createConstants($newpath,'rel'),
'media_userclass' => 0,
'media_name' => $newname,
'media_author' => USERID,
'media_size' => $f['fsize'],
'media_dimensions' => $f['img-width']." x ".$f['img-height'],
'media_usedby' => '',
'media_tags' => '',
'media_type' => $f['mime']
);
if($sql->db_Insert("core_media",$insert))
{
$mes->add("Importing Media: ".$f['fname'], E_MESSAGE_SUCCESS);
}
else
{
rename($newpath,$oldpath); //move it back.
}
}
}
}
function preview($f)
{
list($type,$tmp) = explode("/",$f['mime']);
if($type == 'image')
{
$url = e107::getParser()->thumbUrl($f['path'].$f['fname'], 'w=100', true);
//echo $url;
return " ";
}
else
{
return; //TODO generic icon/image for no preview.
}
}
public function getMediaCategory($id = false)
{
if($id) return (isset($this->cats[$id]) ? $this->cats[$id] : 0);
return $this->cats;
}
/*
* UPDATE IMAGE OPTIONS - MAIN SCREEN
*/
function updateSettings()
{
global $pref,$admin_log,$tp;
$mes = e107::getMessage();
$tmp = array();
$tmp['image_post'] = intval($_POST['image_post']);
$tmp['resize_method'] = $tp->toDB($_POST['resize_method']);
$tmp['im_path'] = trim($tp->toDB($_POST['im_path']));
$tmp['image_post_class'] = intval($_POST['image_post_class']);
$tmp['image_post_disabled_method'] = intval($_POST['image_post_disabled_method']);
$tmp['enable_png_image_fix'] = intval($_POST['enable_png_image_fix']);
if($_POST['img_import_resize_w'] && $_POST['img_import_resize_h'])
{
$tmp['img_import_resize'] = intval($_POST['img_import_resize_w'])."x".intval($_POST['img_import_resize_h']);
}
if ($admin_log->logArrayDiffs($tmp, $pref, 'IMALAN_04'))
{
save_prefs(); // Only save if changes
$mes->add(IMALAN_9, E_MESSAGE_SUCCESS);
}
else
{
$mes->add(IMALAN_20, E_MESSAGE_INFO);
}
}
}
new media_admin();
require_once(e_ADMIN."auth.php");
e107::getAdminUI()->runPage();
// -----------------------------------------------------------------------
$action = e_QUERY;
if(varset($_GET['action']) == "icons")
{
// icon_editor();
}
if(varset($_GET['action']) == "avatars")
{
// show_avatars();
}
if(varset($_GET['action']) == 'settings')
{
// main_config();
}
/*
* DELETE CHECKED AVATARS - SHOW AVATAR SCREEN
*/
if (isset($_POST['submit_show_delete_multi']))
{
if(varset($_POST['multiaction']))
{
$tmp = array(); $tmp1 = array(); $message = array();
foreach ($_POST['multiaction'] as $todel)
{
$todel = explode('#', $todel);
$todel[1] = basename($todel[1]);
$image_type = 2;
if(strpos($todel[1], '-upload-') === 0)
{
$image_type = 1;
$todel[1] = substr($todel[1], strlen('-upload-'));
}
//delete it from server
@unlink(e_UPLOAD."avatars/".$todel[1]);
//admin log & sysmessage
$message[] = $todel[1];
//It's owned by an user
if($todel[0])
{
switch ($image_type)
{
case 1: //avatar
$tmp[] = intval($todel[0]);
break;
case 2: //photo
$tmp1[] = intval($todel[0]);
break;
}
}
}
//Reset all deleted user avatars with one query
if(!empty($tmp))
{
$sql->db_Update("user", "user_image='' WHERE user_id IN (".implode(',', $tmp).")");
}
//Reset all deleted user photos with one query
if(!empty($tmp1))
{
$sql->db_Update("user", "user_sess='' WHERE user_id IN (".implode(',', $tmp1).")");
}
unset($tmp, $tmp1);
//Format system message
if(!empty($message))
{
$admin_log->log_event('IMALAN_01', implode('[!br!]', $message), E_LOG_INFORMATIVE, '');
$emessage->add(implode(', ', $message).' '.IMALAN_28, E_MESSAGE_SUCCESS);
}
}
}
/*
* DELETE ALL UNUSED IMAGES - SHOW AVATAR SCREEN
*/
if (isset($_POST['submit_show_deleteall']))
{
$handle = opendir(e_UPLOAD."avatars/");
$dirlist = array();
while ($file = readdir($handle)) {
if (!is_dir(e_UPLOAD."avatars/{$file}") && $file != '.' && $file != '..' && $file != "index.html" && $file != "null.txt" && $file != '/' && $file != 'CVS' && $file != 'Thumbs.db') {
$dirlist[] = $file;
}
}
closedir($handle);
if(!empty($dirlist))
{
$imgList = '';
$count = 0;
foreach ($dirlist as $image_name)
{
$image_name = basename($image_name);
$image_todb = $tp->toDB($image_name);
if (!$sql->db_Count('user', '(*)', "WHERE user_image='-upload-{$image_todb}' OR user_sess='{$image_todb}'")) {
unlink(e_UPLOAD."avatars/".$image_name);
$imgList .= '[!br!]'.$image_name;
$count++;
}
}
$message = $count." ".IMALAN_26;
$emessage->add($message, E_MESSAGE_SUCCESS);
$admin_log->log_event('IMALAN_02', $message.$imgList,E_LOG_INFORMATIVE, '');
unset($imgList);
}
}
/*
* DELETE ALL CHECKED BAD IMAGES - VALIDATE SCREEN
*/
if (isset($_POST['submit_avdelete_multi']))
{
require_once(e_HANDLER."avatar_handler.php");
$avList = array();
$tmp = array();
$uids = array();
//Sanitize
$_POST['multiaction'] = $tp->toDB($_POST['multiaction']);
//sql queries significant reduced
if(!empty($_POST['multiaction']) && $sql->db_Select("user", 'user_id, user_name, user_image', "user_id IN (".implode(',', $_POST['multiaction']).")"))
{
$search_users = $sql->db_getList('ALL', FALSE, FALSE, 'user_id');
foreach($_POST['multiaction'] as $uid)
{
if (varsettrue($search_users[$uid]))
{
$avname = avatar($search_users[$uid]['user_image']);
if (strpos($avname, "http://") === FALSE)
{ // Internal file, so unlink it
@unlink($avname);
}
$uids[] = $uid;
$tmp[] = $search_users[$uid]['user_name'];
$avList[] = $uid.':'.$search_users[$uid]['user_name'].':'.$search_users[$uid]['user_image'];
}
}
//sql queries significant reduced
if(!empty($uids))
{
$sql->db_Update("user", "user_image='' WHERE user_id IN (".implode(',', $uids).")");
}
$emessage->add(IMALAN_51.''.implode(', ', $tmp).' '.IMALAN_28, E_MESSAGE_SUCCESS);
$admin_log->log_event('IMALAN_03', implode('[!br!]', $avList), E_LOG_INFORMATIVE, '');
unset($search_users);
}
unset($avList, $tmp, $uids);
}
/*
* SHOW AVATARS SCREEN
*/
function show_avatars()
{
global $e107, $pref;
$ns = e107::getRender();
$sql = e107::getDb();
$frm = e107::getForm();
$tp = e107::getParser();
$mes = e107::getMessage();
$handle = opendir(e_UPLOAD."avatars/"); //TODO replace with $fl
$dirlist = array();
while ($file = readdir($handle))
{
if ($file != '.' && $file != '..' && $file != "index.html" && $file != "null.txt" && $file != '/' && $file != 'CVS' && $file != 'Thumbs.db' && !is_dir($file))
{
$dirlist[] = $file;
}
}
closedir($handle);
$text = '';
if (empty($dirlist))
{
$text .= IMALAN_29;
}
else
{
$text = "
";
}
echo $mes->render().$text;
return;
// $ns->tablerender(LAN_MEDIAMANAGER." :: ".IMALAN_18, $mes->render().$text);
}
/*
* CHECK AVATARS SCREEN
*/
if (isset($_POST['check_avatar_sizes']))
{
// Set up to track what we've done
//
$iUserCount = 0;
$iAVinternal = 0;
$iAVexternal = 0;
$iAVnotfound = 0;
$iAVtoobig = 0;
require_once(e_HANDLER."avatar_handler.php");
$text = "
";
$ns->tablerender(IMALAN_37, $emessage->render().$text);
}
/*
* MAIN CONFIG SCREEN
*/
function main_config()
{
global $pref;
$frm = e107::getForm();
$tp = e107::getParser();
$sql = e107::getDb();
$ns = e107::getRender();
$mes = e107::getMessage();
if(function_exists('gd_info'))
{
$gd_info = gd_info();
$gd_version = $gd_info['GD Version'];
}
else
{
$gd_version = " ".IMALAN_55." ";
}
$IM_NOTE = "";
if($pref['im_path'] != "")
{
$im_file = $pref['im_path'].'convert';
if(!file_exists($im_file))
{
$IM_NOTE = "".IMALAN_52." ";
}
else
{
$cmd = "{$im_file} -version";
$tmp = `$cmd`;
if(strpos($tmp, "ImageMagick") === FALSE)
{
$IM_NOTE = "".IMALAN_53." ";
}
}
}
$text = "
";
echo $mes->render().$text;
return;
$ns->tablerender(LAN_MEDIAMANAGER." :: ".IMALAN_7, $mes->render().$text);
}
//Just in case...
if(!e_AJAX_REQUEST) require_once("footer.php");
/**
* Handle page DOM within the page header
*
* @return string JS source
*/
//function headerjs()
//{
// require_once(e_HANDLER.'js_helper.php');
// //FIXME - how exactly to auto-call JS lan? This and more should be solved in Stage II.
// $ret = "
//
//
// ";
//
// return $ret;
//}
?>