From ab53f914314198f5e57ed69633eaa19ecee96cc2 Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Sun, 14 Mar 2010 02:11:23 +0000 Subject: [PATCH] EONE-36 (Improvement): Added media class. Icons are now imported and removed during plugin install/uninstall. --- class2.php | 24 +-- e107_admin/image.php | 126 +------------- e107_admin/plugin.php | 7 +- e107_admin/update_routines.php | 81 ++------- e107_core/shortcodes/single/iconpicker.php | 12 +- e107_handlers/e107_class.php | 10 ++ e107_handlers/media_class.php | 184 +++++++++++++++++++++ e107_handlers/plugin_class.php | 93 ++--------- e107_handlers/pref_class.php | 3 +- 9 files changed, 241 insertions(+), 299 deletions(-) create mode 100644 e107_handlers/media_class.php diff --git a/class2.php b/class2.php index 0c4402c4a..6933ab3cf 100644 --- a/class2.php +++ b/class2.php @@ -442,8 +442,6 @@ $pref = e107::getPref(); //DEPRECATED, BC, call e107::getConfig('menu')->get('pref_name') only when needed $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)'); @@ -1438,7 +1436,7 @@ function get_user_data($uid, $extra = '') //SO MUCH DEPRECATED - use e107::getConfig(alias)->save() instead 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) { @@ -1447,11 +1445,6 @@ function save_prefs($table = 'core', $uid = USERID, $row_val = '') return e107::getConfig()->loadData($pref, false)->save(false, true); break; - case 'iconpool': - //brute load, force update - return e107::getConfig('ipool')->loadData($iconpool, true)->save(false, true); - break; - case 'theme': //brute load, force update 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") { $pref['sitetheme_pref'] = $theme_pref; diff --git a/e107_admin/image.php b/e107_admin/image.php index 65a7ba827..84ea95da2 100644 --- a/e107_admin/image.php +++ b/e107_admin/image.php @@ -317,7 +317,7 @@ class media_admin_ui extends e_admin_ui 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 = " -
-
- ".DBLAN_20." - - - - - - - - - - - - - - - - - "; - $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 = "{$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 = "
".str_replace('%%size%%', '', implode('
', $tmp1))."
"; - - // $ptext = (is_array($val)) ? "
".print_r($val, TRUE)."
" : htmlspecialchars($val, ENT_QUOTES, CHARSET); - // $ptext = $e107->tp->textclean($ptext, 80); - - $text .= " - - - - - - - "; - } - - $text .= " - -
".LAN_DELETE."".LAN_CATEGORY."".IMALAN_72."".LAN_OPTIONS."
".$frm->checkbox("delpref2[$key]", 1)."{$key}{$ptext}".$frm->submit_image("delpref[$key]", LAN_DELETE, 'delete', LAN_CONFIRMDEL." [$key]")."
-
- ".$frm->admin_button('delpref_checked', LAN_DELCHECKED, 'delete')." -
-
-
- - - "; - //$text .= "
".DBLAN_13."
\n"; - // $ns->tablerender(LAN_MEDIAMANAGER." :: ".IMALAN_71, $mes->render().$text); - - echo $mes->render().$text; - } + } @@ -698,11 +613,6 @@ e107::getAdminUI()->runPage(); $action = e_QUERY; -if(isset($_POST['delpref']) || (isset($_POST['delpref_checked']) && isset($_POST['delpref2']))) -{ - del_pref_val(); -} - if(varset($_GET['action']) == "icons") { // 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 .= "
  • ".$delpref."
  • "; - } - - if($_POST['delpref2']) - { - - foreach($_POST['delpref2'] as $k => $v) - { - $deleted_list .= "
  • ".$k."
  • "; - unset($iconpool[$k]); - } - } - - if(save_prefs('iconpool')) - { - $emessage->add(LAN_DELETED.""); - $e107cache->clear(); - } - //$e107->ns->tablerender(LAN_DELETED,$message); - - -} - diff --git a/e107_admin/plugin.php b/e107_admin/plugin.php index f064afd64..84a26773a 100644 --- a/e107_admin/plugin.php +++ b/e107_admin/plugin.php @@ -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) { @@ -1000,7 +1003,7 @@ class pluginManager{ } $opts['delete_ipool'] = array( - 'label' =>'Remove icons from icon-pool', + 'label' =>'Remove icons from Media-Manager', 'preview' => $iconText, 'helpText' => EPL_ADLAN_79, 'itemList' => array(1=>LAN_YES,0=>LAN_NO), diff --git a/e107_admin/update_routines.php b/e107_admin/update_routines.php index d0f956c26..1f79c56fb 100644 --- a/e107_admin/update_routines.php +++ b/e107_admin/update_routines.php @@ -888,6 +888,9 @@ function update_706_to_800($type='') //-- Media-manger import -------------------------------------------------- + + $med = e107::getMedia(); + $count = $sql->db_Select('core_media_cat'); if($count < 5) { @@ -901,14 +904,16 @@ function update_706_to_800($type='') mysql_query($query); } - core_media_import('news',e_IMAGE.'newspost_images'); - core_media_import('page',e_IMAGE.'custom'); - core_media_import('download',e_FILE.'downloadimages'); - core_media_import('downloadthumb',e_IMAGE.'downloadthumbs'); + $med->import('news',e_IMAGE.'newspost_images'); + $med->import('page',e_IMAGE.'custom'); + $med->import('download',e_FILE.'downloadimages'); + $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' "); - if(!$count) + if($count < 2) { 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->add("Icon category added", E_MESSAGE_DEBUG); - $iconsrch = array(16,32,48,64); - - foreach($iconsrch as $size) - { - $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); - } + $med->importIcons(e_PLUGIN); + $med->importIcons(e_IMAGE."icons/"); + $med->importIcons(e_THEME.$pref['sitetheme']."/images/"); } + // 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; } -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='') { diff --git a/e107_core/shortcodes/single/iconpicker.php b/e107_core/shortcodes/single/iconpicker.php index 13015a893..a955cb8f4 100644 --- a/e107_core/shortcodes/single/iconpicker.php +++ b/e107_core/shortcodes/single/iconpicker.php @@ -26,7 +26,7 @@ function iconpicker_shortcode($parm) $str = ""; $size_section = array(); - $lastsize = ""; + $lastsize = "16"; if($sql->db_Select_gen($qry)) { @@ -34,17 +34,17 @@ function iconpicker_shortcode($parm) { list($tmp,$tmp2,$size) = explode("_",$row['media_category']); - - if($lastsize!='' && ($size != $lastsize)) + + if($str !='' && ($size != $lastsize)) { $size_section[] = $str; - $str = ""; + $str = ""; } - $str .= "{$row["; - + $lastsize = $size; + } return '
    '.str_replace('%%size%%', '', implode('
    ', $size_section)).'
    '; diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 6786a3adc..98d4610da 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -168,6 +168,7 @@ class e107 'themeHandler' => '{e_HANDLER}theme_handler.php', 'user_class' => '{e_HANDLER}userclass_class.php', 'xmlClass' => '{e_HANDLER}xml_class.php', + 'e_media' => '{e_HANDLER}media_class.php', ); /** @@ -1105,6 +1106,15 @@ class e107 { 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 diff --git a/e107_handlers/media_class.php b/e107_handlers/media_class.php new file mode 100644 index 000000000..817723a37 --- /dev/null +++ b/e107_handlers/media_class.php @@ -0,0 +1,184 @@ +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; + } + + + +} + + + +?> \ No newline at end of file diff --git a/e107_handlers/plugin_class.php b/e107_handlers/plugin_class.php index e8bf5dec0..b581b806b 100644 --- a/e107_handlers/plugin_class.php +++ b/e107_handlers/plugin_class.php @@ -301,90 +301,33 @@ class e107plugin function manage_icons($plugin='',$function='') { - global $iconpool,$pref; + + if($plugin == '') + { + return; + } $mes = eMessage::getInstance(); $sql = e107::getDb(); $tp = e107::getParser(); - $fl = e107::getFile(); - - if($plugin && ($function == 'uninstall') ) + $med = e107::getMedia(); + + if($function == 'install' || $function == 'upgrade') { - if(vartrue($this->unInstallOpts['delete_ipool'], FALSE)) - { - $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); - } + $med->importIcons(e_PLUGIN.$plugin); return; } + - - - $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. + if($function == 'uninstall') { - $reject_plugin[] = $val['plugin_path']."/images"; - } - - $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); - } - - 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; + if(vartrue($this->unInstallOpts['delete_ipool'], FALSE)) + { + $status = ($med->removePath(e_PLUGIN.$plugin,'icon')) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; + $mes->add('Removing Icons from Media-Manager', $status); + } + return; + } } diff --git a/e107_handlers/pref_class.php b/e107_handlers/pref_class.php index 903d96400..e1cc41b12 100644 --- a/e107_handlers/pref_class.php +++ b/e107_handlers/pref_class.php @@ -721,8 +721,7 @@ final class e_core_pref extends e_pref 'emote' => 'emote_default', //TODO include other emote packs of the user. 'menu' => 'menu_pref', 'search' => 'search_prefs', - 'notify' => 'notify_prefs', - 'ipool' => 'IconPool' + 'notify' => 'notify_prefs' ); /**