1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-28 10:20:45 +02:00

EONE-36 (Improvement): Added media class. Icons are now imported and removed during plugin install/uninstall.

This commit is contained in:
CaMer0n
2010-03-14 02:11:23 +00:00
parent 637cf91009
commit ab53f91431
9 changed files with 241 additions and 299 deletions

View File

@@ -442,8 +442,6 @@ $pref = e107::getPref();
//DEPRECATED, BC, call e107::getConfig('menu')->get('pref_name') only when needed //DEPRECATED, BC, call e107::getConfig('menu')->get('pref_name') only when needed
$menu_pref = e107::getConfig('menu')->getPref(); //extract menu prefs $menu_pref = e107::getConfig('menu')->getPref(); //extract menu prefs
//DEPRECATED, BC, call e107::getConfig('ipool')->get('pref_name') only when needed
$iconpool = e107::getConfig('ipool')->getPref(); //extract iconpool
$sql->db_Mark_Time('(Extracting Core Prefs Done)'); $sql->db_Mark_Time('(Extracting Core Prefs Done)');
@@ -1438,7 +1436,7 @@ function get_user_data($uid, $extra = '')
//SO MUCH DEPRECATED - use e107::getConfig(alias)->save() instead //SO MUCH DEPRECATED - use e107::getConfig(alias)->save() instead
function save_prefs($table = 'core', $uid = USERID, $row_val = '') function save_prefs($table = 'core', $uid = USERID, $row_val = '')
{ {
global $pref, $user_pref, $tp, $PrefCache, $sql, $eArrayStorage, $theme_pref, $iconpool; global $pref, $user_pref, $tp, $PrefCache, $sql, $eArrayStorage, $theme_pref;
switch($table) switch($table)
{ {
@@ -1447,11 +1445,6 @@ function save_prefs($table = 'core', $uid = USERID, $row_val = '')
return e107::getConfig()->loadData($pref, false)->save(false, true); return e107::getConfig()->loadData($pref, false)->save(false, true);
break; break;
case 'iconpool':
//brute load, force update
return e107::getConfig('ipool')->loadData($iconpool, true)->save(false, true);
break;
case 'theme': case 'theme':
//brute load, force update //brute load, force update
return e107::getConfig()->set('sitetheme_pref', $theme_pref)->save(false, true); return e107::getConfig()->set('sitetheme_pref', $theme_pref)->save(false, true);
@@ -1486,21 +1479,6 @@ function save_prefs($table = 'core', $uid = USERID, $row_val = '')
} }
} }
} }
elseif($table == "iconpool")
{
// $sql->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('IconPool_Backup', '".addslashes($PrefCache)."') ");
$_iconpool = $tp->toDB($iconpool, true, true);
if($sql->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('IconPool', '".$eArrayStorage->WriteArray($_iconpool)."') "))
{
ecache::clear_sys('Config_ipool');
return true;
}
else
{
return false;
}
}
elseif($table == "theme") elseif($table == "theme")
{ {
$pref['sitetheme_pref'] = $theme_pref; $pref['sitetheme_pref'] = $theme_pref;

View File

@@ -317,7 +317,7 @@ class media_admin_ui extends e_admin_ui
function iconsPage() function iconsPage()
{ {
$this->icon_editor(); // $this->icon_editor();
} }
@@ -584,92 +584,7 @@ class media_admin_ui extends e_admin_ui
} }
function icon_editor()
{
global $iconpool, $e107;
$ns = e107::getRender();
$tp = e107::getParser();
$frm = e107::getForm();
$mes = e107::getMessage();
ksort($iconpool);
$text = "
<form method='post' action='".e_SELF."?".e_QUERY."' id='icon_edit'>
<fieldset id='core-imagemanager-icons'>
<legend class='e-hideme'>".DBLAN_20."</legend>
<table cellpadding='0' cellspacing='0' class='adminlist'>
<colgroup span='4'>
<col style='width: 5%'></col>
<col style='width: 20%'></col>
<col style='width: 70%'></col>
<col style='width: 5%'></col>
</colgroup>
<thead>
<tr>
<th class='center'>".LAN_DELETE."</th>
<th>".LAN_CATEGORY."</th>
<th>".IMALAN_72."</th>
<th class='center last'>".LAN_OPTIONS."</th>
</tr>
</thead>
<tbody>
";
$tmp = array(16, 32, 48, 64, 128);
foreach($iconpool as $key => $val)
{
$tmp1 = array();
foreach($val as $icon)
{
$filepath = $icon;
$filepath_abs = $tp->replaceConstants($icon);
$icon_file = basename($filepath_abs);
$str = "<img class='icon picker list%%size%%' src='{$filepath_abs}' alt='{$icon_file}' />";
foreach ($tmp as $isize)
{
if(strpos($icon_file, '_'.$isize.'.') !== false)
{
$tmp1[$isize] = varset($tmp1[$isize]).str_replace('%%size%%', ' S'.$isize, $str);
continue 2;
}
}
$tmp1['other'] = varset($tmp1['other']).$str;//other
}
$ptext = "<div class='field-spacer iconeditor'>".str_replace('%%size%%', '', implode('</div><div class="field-spacer iconeditor">', $tmp1))."</div>";
// $ptext = (is_array($val)) ? "<pre>".print_r($val, TRUE)."</pre>" : htmlspecialchars($val, ENT_QUOTES, CHARSET);
// $ptext = $e107->tp->textclean($ptext, 80);
$text .= "
<tr>
<td class='center autocheck e-pointer'>".$frm->checkbox("delpref2[$key]", 1)."</td>
<td>{$key}</td>
<td>{$ptext}</td>
<td class='center'>".$frm->submit_image("delpref[$key]", LAN_DELETE, 'delete', LAN_CONFIRMDEL." [$key]")."</td>
</tr>
";
}
$text .= "
</tbody>
</table>
<div class='buttons-bar center'>
".$frm->admin_button('delpref_checked', LAN_DELCHECKED, 'delete')."
</div>
</fieldset>
</form>
";
//$text .= "<div style='text-align:center'><a href='".e_SELF."'>".DBLAN_13."</a></div>\n";
// $ns->tablerender(LAN_MEDIAMANAGER." :: ".IMALAN_71, $mes->render().$text);
echo $mes->render().$text;
}
} }
@@ -698,11 +613,6 @@ e107::getAdminUI()->runPage();
$action = e_QUERY; $action = e_QUERY;
if(isset($_POST['delpref']) || (isset($_POST['delpref_checked']) && isset($_POST['delpref2'])))
{
del_pref_val();
}
if(varset($_GET['action']) == "icons") if(varset($_GET['action']) == "icons")
{ {
// icon_editor(); // icon_editor();
@@ -1330,38 +1240,6 @@ if(!e_AJAX_REQUEST) require_once("footer.php");
function del_pref_val()
{
global $iconpool, $e107cache, $emessage;
$del = array_keys($_POST['delpref']);
$delpref = key($_POST['delpref']);
if($delpref)
{
unset($iconpool[$delpref]);
$deleted_list .= "<li>".$delpref."</li>";
}
if($_POST['delpref2'])
{
foreach($_POST['delpref2'] as $k => $v)
{
$deleted_list .= "<li>".$k."</li>";
unset($iconpool[$k]);
}
}
if(save_prefs('iconpool'))
{
$emessage->add(LAN_DELETED."<ul>".$deleted_list."</ul>");
$e107cache->clear();
}
//$e107->ns->tablerender(LAN_DELETED,$message);
}

View File

@@ -992,7 +992,10 @@ class pluginManager{
); );
} }
if(count($icons = e107::getConfig('ipool')->getPref('plugin-'.$plug['plugin_path']))>1) $med = e107::getMedia();
$icons = $med->listIcons(e_PLUGIN.$plug['plugin_path']);
if(count($icons)>0)
{ {
foreach($icons as $key=>$val) foreach($icons as $key=>$val)
{ {
@@ -1000,7 +1003,7 @@ class pluginManager{
} }
$opts['delete_ipool'] = array( $opts['delete_ipool'] = array(
'label' =>'Remove icons from icon-pool', 'label' =>'Remove icons from Media-Manager',
'preview' => $iconText, 'preview' => $iconText,
'helpText' => EPL_ADLAN_79, 'helpText' => EPL_ADLAN_79,
'itemList' => array(1=>LAN_YES,0=>LAN_NO), 'itemList' => array(1=>LAN_YES,0=>LAN_NO),

View File

@@ -888,6 +888,9 @@ function update_706_to_800($type='')
//-- Media-manger import -------------------------------------------------- //-- Media-manger import --------------------------------------------------
$med = e107::getMedia();
$count = $sql->db_Select('core_media_cat'); $count = $sql->db_Select('core_media_cat');
if($count < 5) if($count < 5)
{ {
@@ -901,14 +904,16 @@ function update_706_to_800($type='')
mysql_query($query); mysql_query($query);
} }
core_media_import('news',e_IMAGE.'newspost_images'); $med->import('news',e_IMAGE.'newspost_images');
core_media_import('page',e_IMAGE.'custom'); $med->import('page',e_IMAGE.'custom');
core_media_import('download',e_FILE.'downloadimages'); $med->import('download',e_FILE.'downloadimages');
core_media_import('downloadthumb',e_IMAGE.'downloadthumbs'); $med->import('downloadthumb',e_IMAGE.'downloadthumbs');
$count = $sql->db_Select_gen("SELECT * FROM `#core_media_cat` WHERE media_cat_nick='_icon_16' OR media_cat_nick='_icon_32' "); $count = $sql->db_Select_gen("SELECT * FROM `#core_media_cat` WHERE media_cat_nick='_icon_16' OR media_cat_nick='_icon_32' ");
if(!$count) if($count < 2)
{ {
if ($just_check) return update_needed('Add icons to media-manager'); if ($just_check) return update_needed('Add icons to media-manager');
@@ -927,18 +932,12 @@ function update_706_to_800($type='')
$mes = e107::getMessage(); $mes = e107::getMessage();
$mes->add("Icon category added", E_MESSAGE_DEBUG); $mes->add("Icon category added", E_MESSAGE_DEBUG);
$iconsrch = array(16,32,48,64); $med->importIcons(e_PLUGIN);
$med->importIcons(e_IMAGE."icons/");
foreach($iconsrch as $size) $med->importIcons(e_THEME.$pref['sitetheme']."/images/");
{
$types = "_".$size.".png|_".$size.".PNG";
core_media_import('_icon_'.$size,e_PLUGIN, $types);
core_media_import('_icon_'.$size,e_IMAGE."icons/", $types);
core_media_import('_icon_'.$size,e_THEME.$pref['sitetheme']."/images/", $types);
}
} }
// Any other images should be imported manually via Media Manager batch-import. // Any other images should be imported manually via Media Manager batch-import.
// ------------------------------------------------------------------ // ------------------------------------------------------------------
@@ -958,58 +957,6 @@ function update_706_to_800($type='')
return $just_check; return $just_check;
} }
function core_media_import($cat,$epath,$fmask='')
{
if(!vartrue($cat)){ return;}
if(!is_readable($epath))
{
return;
}
$fl = e107::getFile();
$tp = e107::getParser();
$sql = e107::getDb();
$mes = e107::getMessage();
$fl->setFileInfo('all');
$img_array = $fl->get_files($epath,$fmask,'',2);
if(!count($img_array)){ return;}
//print_a($img_array);
//return;
foreach($img_array as $f)
{
$fullpath = $tp->createConstants($f['path'].$f['fname'],1);
$insert = array(
'media_caption' => $f['fname'],
'media_description' => '',
'media_category' => $cat,
'media_datestamp' => $f['modified'],
'media_url' => $fullpath,
'media_userclass' => 0,
'media_name' => $f['fname'],
'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_Select('core_media','media_url',"media_url = '".$fullpath."' LIMIT 1"))
{
if($sql->db_Insert("core_media",$insert))
{
$mes->add("Importing Media: ".$f['fname'], E_MESSAGE_SUCCESS);
}
}
}
}
function update_70x_to_706($type='') function update_70x_to_706($type='')
{ {

View File

@@ -26,7 +26,7 @@ function iconpicker_shortcode($parm)
$str = ""; $str = "";
$size_section = array(); $size_section = array();
$lastsize = ""; $lastsize = "16";
if($sql->db_Select_gen($qry)) if($sql->db_Select_gen($qry))
{ {
@@ -35,16 +35,16 @@ function iconpicker_shortcode($parm)
list($tmp,$tmp2,$size) = explode("_",$row['media_category']); list($tmp,$tmp2,$size) = explode("_",$row['media_category']);
if($lastsize!='' && ($size != $lastsize)) if($str !='' && ($size != $lastsize))
{ {
$size_section[] = $str; $size_section[] = $str;
$str = ""; $str = "";
} }
$str .= "<a href='#".$row['media_url']."' title='{$filepath}' onclick=\"e107Helper.insertText('{$row['media_url']}','{$name}','{$name}-iconpicker'); return false; \"><img class='icon picker list%%size%%' src='".$tp->replaceConstants($row['media_url'])."' alt='{$row['media_name']}' /></a>"; $str .= "<a href='#".$row['media_url']."' title='{$filepath}' onclick=\"e107Helper.insertText('{$row['media_url']}','{$name}','{$name}-iconpicker'); return false; \"><img class='icon picker list%%size%%' src='".$tp->replaceConstants($row['media_url'])."' alt='{$row['media_name']}' /></a>";
$lastsize = $size; $lastsize = $size;
} }
return '<div id="'.$name.'-iconpicker-ajax"><div class="field-spacer iconpicker">'.str_replace('%%size%%', '', implode('</div><div class="field-spacer iconpicker">', $size_section)).'</div></div>'; return '<div id="'.$name.'-iconpicker-ajax"><div class="field-spacer iconpicker">'.str_replace('%%size%%', '', implode('</div><div class="field-spacer iconpicker">', $size_section)).'</div></div>';

View File

@@ -168,6 +168,7 @@ class e107
'themeHandler' => '{e_HANDLER}theme_handler.php', 'themeHandler' => '{e_HANDLER}theme_handler.php',
'user_class' => '{e_HANDLER}userclass_class.php', 'user_class' => '{e_HANDLER}userclass_class.php',
'xmlClass' => '{e_HANDLER}xml_class.php', 'xmlClass' => '{e_HANDLER}xml_class.php',
'e_media' => '{e_HANDLER}media_class.php',
); );
/** /**
@@ -1106,6 +1107,15 @@ class e107
return self::getSingleton('comment', true); return self::getSingleton('comment', true);
} }
/**
* Retrieve Media handler singleton object
* @return comment
*/
public static function getMedia()
{
return self::getSingleton('e_media', true);
}
/** /**
* Retrieve message handler singleton * Retrieve message handler singleton
* @return eMessage * @return eMessage

View File

@@ -0,0 +1,184 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2010 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Administration - Media Management Class
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/plugin_class.php,v $
* $Revision: 11315 $
* $Date: 2010-02-10 10:18:01 -0800 (Wed, 10 Feb 2010) $
* $Author: secretr $
*
*/
if (!defined('e107_INIT')) { exit; }
class e_media
{
/**
* Import files from specified path into media database.
* @param string $cat Category nickname
* @param string $epath path to file.
* @param string $fmask [optional] filetypes eg. .jpg|.gif
* @return
*/
public function import($cat,$epath,$fmask='')
{
if(!vartrue($cat)){ return;}
if(!is_readable($epath))
{
return;
}
$fl = e107::getFile();
$tp = e107::getParser();
$sql = e107::getDb();
$mes = e107::getMessage();
$fl->setFileInfo('all');
$img_array = $fl->get_files($epath,$fmask,'',2);
if(!count($img_array)){ return;}
//print_a($img_array);
//return;
foreach($img_array as $f)
{
$fullpath = $tp->createConstants($f['path'].$f['fname'],1);
$insert = array(
'media_caption' => $f['fname'],
'media_description' => '',
'media_category' => $cat,
'media_datestamp' => $f['modified'],
'media_url' => $fullpath,
'media_userclass' => 0,
'media_name' => $f['fname'],
'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_Select('core_media','media_url',"media_url = '".$fullpath."' LIMIT 1"))
{
if($sql->db_Insert("core_media",$insert))
{
$mes->add("Importing Media: ".$f['fname'], E_MESSAGE_SUCCESS);
}
else
{
$mes->add("Importing Media: ".$f['fname'], E_MESSAGE_ERROR);
}
}
}
}
/**
* Import icons into media-manager from specified path.
* @param string $path
* @return
*/
public function importIcons($path)
{
$iconsrch = array(16,32,48,64);
foreach($iconsrch as $size)
{
$types = "_".$size.".png|_".$size.".PNG";
$this->import('_icon_'.$size, $path, $types);
}
}
/**
* Remove Media from media table
* @param string $cat [optional] remove a full category of media
* @return
*/
function removeCat($cat)
{
$tp = e107::getParser();
$sql = e107::getDb();
$mes = e107::getMessage();
if(vartrue($cat))
{
$status = ($sql->db_Delete('core_media',"media_cat = '".$cat."'")) ? TRUE : FALSE;
$mes->add("Removing Media in Category: ".$cat, E_MESSAGE_DEBUG);
return $status;
}
}
/**
* Remove Media from media table
* @param string $epath remove media in the specified path.
* @param string $type [optional] image|icon
* @return
*/
function removePath($epath, $type='image')
{
$tp = e107::getParser();
$sql = e107::getDb();
$mes = e107::getMessage();
$qry = ($type == 'icon') ? " AND media_category REGEXP '_icon_16|_icon_32|_icon_48|_icon_64' " : " AND NOT media_category REGEXP '_icon_16|_icon_32|_icon_48|_icon_64' ";
if(vartrue($epath))
{
$path = $tp->createConstants($epath, 'rel');
$status = ($sql->db_Delete('core_media',"media_url LIKE '".$path."%'".$qry)) ? TRUE : FALSE;
$message = ($type == 'image') ? "Removing Media with path: ".$path : "Removing Icons with path: ".$path;
$mes->add($message, E_MESSAGE_DEBUG);
return $status;
}
}
/**
* Return a list if icons in the specified path
* @param string $epath
* @return array
*/
function listIcons($epath)
{
if(!$epath) return;
$ret = array();
$sql = e107::getDb();
$tp = e107::getParser();
$path = $tp->createConstants($epath, 'rel');
$status = ($sql->db_Select_gen("SELECT * FROM `#core_media` WHERE `media_url` LIKE '".$path."%' AND media_category REGEXP '_icon_16|_icon_32|_icon_48|_icon_64' ")) ? TRUE : FALSE;
while ($row = $sql->db_Fetch())
{
$ret[] = $row['media_url'];
}
return $ret;
}
}
?>

View File

@@ -301,91 +301,34 @@ class e107plugin
function manage_icons($plugin='',$function='') function manage_icons($plugin='',$function='')
{ {
global $iconpool,$pref;
if($plugin == '')
{
return;
}
$mes = eMessage::getInstance(); $mes = eMessage::getInstance();
$sql = e107::getDb(); $sql = e107::getDb();
$tp = e107::getParser(); $tp = e107::getParser();
$fl = e107::getFile(); $med = e107::getMedia();
if($plugin && ($function == 'uninstall') ) if($function == 'install' || $function == 'upgrade')
{ {
if(vartrue($this->unInstallOpts['delete_ipool'], FALSE)) $med->importIcons(e_PLUGIN.$plugin);
{
$ipool_entry = 'plugin-'.$plugin;
e107::getConfig('ipool')->remove($ipool_entry); // FIXME - ipool removal issue.
$status = (e107::getConfig('ipool')->save(FALSE)) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add('Removing Icon-Pool entry: '.$ipool_entry, $status);
}
return; return;
} }
if($function == 'uninstall')
$query = "SELECT * FROM #plugin WHERE plugin_installflag =0 ORDER BY plugin_path ASC";
$sql->db_Select_gen($query);
$list = $sql->db_getList();
$reject_core = array('$.','$..','/','CVS','thumbs.db','*._$', 'index', 'null*');
$reject_plugin = $reject_core;
foreach($list as $val) // reject uninstalled plugin folders.
{ {
$reject_plugin[] = $val['plugin_path']."/images"; if(vartrue($this->unInstallOpts['delete_ipool'], FALSE))
}
$filesrch = implode("|",array("_16.png","_16.PNG","_32.png","_32.PNG","_48.png","_48.PNG","_64.png","_64.PNG","_128.png","_128.png"));
if($plugin_icons = $fl->get_files(e_PLUGIN,$filesrch,$reject_plugin,2))
{ {
sort($plugin_icons); $status = ($med->removePath(e_PLUGIN.$plugin,'icon')) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add('Removing Icons from Media-Manager', $status);
} }
return;
if($core_icons = $fl->get_files(e_IMAGE."icons/",$filesrch,$reject_core,2))
{
sort($core_icons);
} }
if($theme_icons = $fl->get_files(e_THEME.$pref['sitetheme']."/images/",$filesrch,$reject_core,2))
{
sort($theme_icons);
}
$srch = array(e_IMAGE,"/");
$repl = array("","-");
$iconpool = array();
foreach($core_icons as $file)
{
$path = str_replace($srch,$repl,$file['path']);
$key = substr("core-".$path,0,-1);
$iconpool[$key][] = $tp->createConstants($file['path'],1).$file['fname'];
}
$srch = array(e_PLUGIN,"/images/","/icons/","/icon/");
$repl = array("","","");
foreach($plugin_icons as $file)
{
$path = str_replace($srch,$repl,$file['path']);
$key = "plugin-".$path;
$iconpool[$key][] = $tp->createConstants($file['path'],1).$file['fname'];
}
$srch = array(e_THEME,"/images/","/icons/","/demo/");
$repl = array("","","");
foreach($theme_icons as $file)
{
$path = str_replace($srch,$repl,$file['path']);
$key = "theme-".$path;
$iconpool[$key][] = $tp->createConstants($file['path'],1).$file['fname'];
}
e107::getConfig('ipool')->setPref($iconpool);
return (e107::getConfig('ipool')->save(FALSE)) ? TRUE : FALSE;
} }
/** /**

View File

@@ -721,8 +721,7 @@ final class e_core_pref extends e_pref
'emote' => 'emote_default', //TODO include other emote packs of the user. 'emote' => 'emote_default', //TODO include other emote packs of the user.
'menu' => 'menu_pref', 'menu' => 'menu_pref',
'search' => 'search_prefs', 'search' => 'search_prefs',
'notify' => 'notify_prefs', 'notify' => 'notify_prefs'
'ipool' => 'IconPool'
); );
/** /**