diff --git a/e107_admin/image.php b/e107_admin/image.php
index 098167ffc..987bcdd50 100644
--- a/e107_admin/image.php
+++ b/e107_admin/image.php
@@ -37,10 +37,8 @@ include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
$e_sub_cat = 'image';
-// require_once("auth.php");
-// require_once(e_HANDLER."form_handler.php");
-//require_once(e_HANDLER."userclass_class.php");
-//require_once(e_HANDLER."message_handler.php");
+
+
// $frm = new e_form(); //new form handler
$emessage = eMessage::getInstance();
@@ -329,7 +327,7 @@ class media_admin_ui extends e_admin_ui
$this->cats[$cat] = $row['media_cat_title'];
}
asort($this->cats);
-
+
if(varset($_POST['batch_import_selected']))
{
@@ -342,20 +340,96 @@ class media_admin_ui extends e_admin_ui
}
if($this->getQuery('iframe'))
- {
- $this->getResponse()->setIframeMod();
- }
-
- if($this->getQuery('for') && $this->getMediaCategory($this->getQuery('for')))
- {
- $this->setPosted('media_category', $this->getQuery('for'));
- if(!$this->getId())
+ {
+ $this->getResponse()->setIframeMod(); // disable header/footer menus etc.
+ if(!$this->getQuery('for'))
{
- $this->getModel()->set('media_category', $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()
+ {
+ $text = "
+
+
+
+
+
+
+ ";
+
+ return $text;
+ }
+
+
+
+
+
+
function importPage()
{
$this->batchImportForm();
@@ -384,6 +458,7 @@ class media_admin_ui extends e_admin_ui
*/
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();
@@ -430,7 +505,7 @@ class media_admin_ui extends e_admin_ui
$mes = e107::getMessage();
- if(vartrue($_FILES['file_userfile']))
+ if(vartrue($_FILES['file_userfile'])) // CREATE
{
$pref['upload_storagetype'] = "1";
@@ -439,49 +514,46 @@ class media_admin_ui extends e_admin_ui
$upload = array_shift($uploaded);
if(vartrue($upload['error']))
{
- $mes->add($upload['message'], E_MESSAGE_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 = 'temp/'.$upload['name'];
- $newpath = $typePath.'/'.$upload['name'];
+ $oldpath = e_MEDIA."temp/".$upload['name'];
+ $newpath = $this->checkDupe($oldpath,$typePath.'/'.$upload['name']);
- //$info = $fl->get_file_info(e_MEDIA.$oldpath);
-
- /*$upload_data = array( // not saved if 'noedit' is active.
- 'media_type' => $upload['type'],
- 'media_datestamp' => time(),
- 'media_url' => "{e_MEDIA}".$newpath,
- 'media_size' => $upload['size'],
- 'media_author' => USERID,
- 'media_usedby' => '',
- 'media_tags' => '',
- 'media_dimensions' => $info['img-width']." x ".$info['img-height']
- );*/
-
- // only one upload? Not sure what's the idea here
- // we are currently creating one media item
- if(!rename(e_MEDIA.$oldpath, e_MEDIA.$newpath))
+ 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);
- if(!varset($new_data['media_name']))
+ $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
+ else // Update Only ?
{
$img_data = $this->mediaData($new_data['media_url']);
@@ -500,7 +572,9 @@ class media_admin_ui extends e_admin_ui
{
$tp = e107::getParser();
$oldpath = $tp->replaceConstants($new_data['media_url']);
- $newpath = $typePath.'/'.$fname;
+ $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);
@@ -513,11 +587,33 @@ class media_admin_ui extends e_admin_ui
{
$img_data['media_name'] = basename($new_data['media_url']);
}
+
+
+ return $img_data;
}
- 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;
@@ -730,22 +826,21 @@ class media_admin_ui extends e_admin_ui
$mes->add("Couldn't get file info from : ".$oldpath, E_MESSAGE_ERROR);
}
- $newpath = $this->getPath($f['mime']).'/'.$file;
+ $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]);
- // echo "oldpath=".$file;
-//
- // echo "
newpath=".$tp->createConstants($newpath,'rel');
- // continue;
$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(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;
+ }
+ */
diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php
index 821fee365..1bed225f9 100644
--- a/e107_admin/newspost.php
+++ b/e107_admin/newspost.php
@@ -1509,25 +1509,32 @@ class admin_newspost
".$frm->bbarea('news_extended', $val, 'extended', 'helpc')."
-
-
- ".NWSLAN_66.": |
- ";
-
- $text .= $frm->mediaUrl('news', NWSLAN_69);
-
- $text .= "
- |
-
-
- ".NWSLAN_67.": |
-
- ";
-
+ |
";
+ /*
+
+ $text .= "
+
+ ".NWSLAN_66.": |
+ ";
+
+ $text .= $frm->mediaUrl('news', NWSLAN_69);
+
+ $text .= "
+ |
+
";
+ */
+ $text .= "
+
+
+ ".NWSLAN_67.":
+ ".$frm->help(LAN_NEWS_23)." |
+
+ ";
+
+
$text .= $frm->imagepicker('news_thumbnail', $_POST['news_thumbnail'],'','news');
$text .= "
- ".LAN_NEWS_23."
|
diff --git a/e107_admin/prefs.php b/e107_admin/prefs.php
index 5f8258ff8..afdfca3bb 100644
--- a/e107_admin/prefs.php
+++ b/e107_admin/prefs.php
@@ -249,7 +249,7 @@ $text .= "
".PRFLAN_214." |
- ".$frm->imagepicker('sitelogo',$pref['sitelogo'],'-- No Image --')." |
+ ".$frm->imagepicker('sitelogo',$pref['sitelogo'],'_common')." |
".PRFLAN_5." |
diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php
index 3e54929f1..713b87c9e 100644
--- a/e107_handlers/form_handler.php
+++ b/e107_handlers/form_handler.php
@@ -145,12 +145,20 @@ class e_form
}
// FIXME - Dialog JS no more working, investigate
- public function mediaUrl($category = '', $label = '')
+ public function mediaUrl($category = '', $label = '', $tagid='', $tabs=TRUE)
{
if($category) $category = '&for='.$category;
if(!$label) $label = ' Upload an image or file';
- $ret = "".$label."";
+ if($tagid) $category .= '&tagid='.$tagid;
+
+ // $tabs // TODO - option to choose which tabs to display.
+
+ //TODO Parse selection data back to parent form.
+ $url = e_ADMIN_ABS."image.php?mode=main&action=dialog".$category;
+
+ $ret = "".$label."";
+
if(!e107::getRegistry('core/form/mediaurl'))
{
e107::getJs()->requireCoreLib('core/admin.js')
@@ -165,7 +173,8 @@ class e_form
new e107Widgets.URLDialog(element.href + "&iframe=1", {
id: element["id"] || "e-dialog",
width: 900,
- height: 550
+ height: 600
+
}).center().activate().show();
});
');
@@ -194,8 +203,50 @@ class e_form
*/
function imagepicker($name, $default, $label = '', $sc_parameters = '')
{
- $sql = e107::getDb();
$tp = e107::getParser();
+ $name_id = $this->name2id($name);
+ if(is_string($sc_parameters))
+ {
+ if(strpos($sc_parameters, '=') === false) $sc_parameters = 'media='.$sc_parameters;
+ parse_str($sc_parameters, $sc_parameters);
+ }
+
+ $default_thumb = $default;
+ if($default)
+ {
+ if('{' != $default[0])
+ {
+ // convert to sc path
+ $default_thumb = $tp->createConstants($default, 'nice');
+ $default = $tp->createConstants($default, 'mix');
+ }
+ $default_url = $tp->replaceConstants($default, 'abs');
+ }
+ else
+ {
+ $default = $default_url = e_IMAGE_ABS."generic/blank.gif";
+ }
+
+ //$width = intval(vartrue($sc_parameters['width'], 150));
+
+ $ret = "";
+ $att = 'aw=120&ah=100';
+ $thpath = isset($sc_parameters['nothumb']) || $hide ? $default : $tp->thumbUrl($default_thumb, $att, true);
+ $label = "

";
+
+ $cat = $tp->toDB($sc_parameters['media']);
+ $ret .= $this->mediaUrl($cat, $label,$name_id);
+ $ret .= "
\n";
+ $ret .= ""; // to be hidden eventually.
+ // $ret .= $this->text($name,$default); // to be hidden eventually.
+ return $ret;
+
+
+ // ---------------- OLD DROPDOWN METHOD BELOW -----------------------------
+
+ $tp = e107::getParser();
+ $sql = e107::getDb();
+
if(is_string($sc_parameters))
{
diff --git a/e107_handlers/media_class.php b/e107_handlers/media_class.php
index 9aa717239..1cf4534a7 100644
--- a/e107_handlers/media_class.php
+++ b/e107_handlers/media_class.php
@@ -247,6 +247,7 @@ class e_media
/**
* Return the total number of Images in a particular category
+ *
*/
public function countImages($cat)
{
@@ -257,14 +258,26 @@ class e_media
/**
* Return an array of Images in a particular category
+ * @param string $cat : category name. use + to include _common eg. 'news+'
*/
- public function getImages($cat, $from=0, $amount=null)
+ public function getImages($cat='', $from=0, $amount=null)
{
- if(!$cat) return;
+ $inc = array();
+
+ if(strpos($cat,"+") || !$cat)
+ {
+ $cat = str_replace("+","",$cat);
+ $inc[] = "media_category = '_common' ";
+ }
+ if($cat)
+ {
+ $inc[] = "media_category = '".$cat."' ";
+ }
// TODO check the category is valid.
- // TODO check userclasses.
+
$ret = array();
- $query = "SELECT * FROM #core_media WHERE media_category = '".$cat."' ORDER BY media_name";
+ $query = "SELECT * FROM #core_media WHERE media_userclass IN (".USERCLASS_LIST.") AND ( ".implode(" OR ",$inc) ;
+ $query .= " ) ORDER BY media_datestamp DESC";
if($amount)
{
@@ -318,5 +331,38 @@ class e_media
return $text;
}
+
+ public function mediaSelect($cat='',$tagid=null,$att=null)
+ {
+
+ $cat = ($cat) ? $cat."+" : "";
+ $images = $this->getImages($cat);
+ $att = 'aw=120&ah=100';
+
+ $name = $tagid;
+ $prevId = $name."_prev";
+
+
+ foreach($images as $im)
+ {
+ $realPath = e107::getParser()->thumbUrl($im['media_url'], $att);
+ $diz = e107::getParser()->toAttribute($im['media_title']);
+
+ $onclick = "onclick =\"
+ parent.document.getElementById('{$tagid}').value = '{$im['media_url']}';
+ parent.document.getElementById('".$prevId."').src = '{$realPath}';
+ parent.window.close();
+ return false; \"";
+
+ //FIXME Make Window Close automatically when selection is made.
+
+ $text .= "";
+ $text .= "
";
+ $text .= "";
+ }
+
+ return $text;
+ }
+
}