[2488] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2488] | 4 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
---|
[2488] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
| 23 | |
---|
| 24 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 25 | { |
---|
| 26 | die ("Hacking attempt!"); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | function abs_fn_cmp($a, $b) |
---|
| 31 | { |
---|
| 32 | return abs($a)-abs($b); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | function make_consecutive( &$orders, $step=50 ) |
---|
| 36 | { |
---|
| 37 | uasort( $orders, 'abs_fn_cmp' ); |
---|
| 38 | $crt = 1; |
---|
| 39 | foreach( $orders as $id=>$pos) |
---|
| 40 | { |
---|
| 41 | $orders[$id] = $step * ($pos<0 ? -$crt : $crt); |
---|
| 42 | $crt++; |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | global $template; |
---|
| 48 | |
---|
| 49 | include_once(PHPWG_ROOT_PATH.'include/block.class.php'); |
---|
| 50 | |
---|
| 51 | $menu = new BlockManager('menubar'); |
---|
| 52 | $menu->load_registered_blocks(); |
---|
| 53 | $reg_blocks = $menu->get_registered_blocks(); |
---|
| 54 | |
---|
| 55 | $mb_conf = @$conf[ 'blk_'.$menu->get_id() ]; |
---|
| 56 | if ( is_string($mb_conf) ) |
---|
| 57 | $mb_conf = unserialize( $mb_conf ); |
---|
| 58 | if ( !is_array($mb_conf) ) |
---|
| 59 | $mb_conf=array(); |
---|
| 60 | |
---|
| 61 | foreach ($mb_conf as $id => $pos) |
---|
| 62 | { |
---|
| 63 | if (!isset($reg_blocks[$id])) |
---|
| 64 | unset($mb_conf[$id]); |
---|
| 65 | } |
---|
| 66 | |
---|
[8126] | 67 | if ( isset($_POST['reset'])) |
---|
[2488] | 68 | { |
---|
| 69 | $mb_conf = array(); |
---|
| 70 | $query = ' |
---|
| 71 | UPDATE '.CONFIG_TABLE.' |
---|
[4367] | 72 | SET value=\'\' |
---|
| 73 | WHERE param=\'blk_'.addslashes($menu->get_id()).'\' |
---|
[2488] | 74 | LIMIT 1'; |
---|
| 75 | pwg_query($query); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | $idx=1; |
---|
| 80 | foreach ($reg_blocks as $id => $block) |
---|
| 81 | { |
---|
| 82 | if ( !isset($mb_conf[$id]) ) |
---|
| 83 | $mb_conf[$id] = $idx*50; |
---|
| 84 | $idx++; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | |
---|
[8126] | 88 | if ( isset($_POST['submit']) ) |
---|
[2488] | 89 | { |
---|
| 90 | foreach ( $mb_conf as $id => $pos ) |
---|
| 91 | { |
---|
| 92 | $hide = isset($_POST['hide_'.$id]); |
---|
| 93 | $mb_conf[$id] = ($hide ? -1 : +1)*abs($pos); |
---|
| 94 | |
---|
| 95 | $pos = (int)@$_POST['pos_'.$id]; |
---|
| 96 | if ($pos>0) |
---|
| 97 | $mb_conf[$id] = $mb_conf[$id] > 0 ? $pos : -$pos; |
---|
| 98 | } |
---|
| 99 | make_consecutive( $mb_conf ); |
---|
| 100 | |
---|
| 101 | // BEGIN OPTIM - DONT ASK ABOUT THIS ALGO - but optimizes the size of the array we save in DB |
---|
[3711] | 102 | /* !!! OPTIM DISABLED UNTIL IT HAS BEEN FIXED !!! |
---|
[2488] | 103 | $reg_keys = array_keys($reg_blocks); |
---|
| 104 | $cnf_keys = array_keys($mb_conf); |
---|
| 105 | $best_slice = array( 'len'=>0 ); |
---|
| 106 | for ($i=0; $i<count($reg_keys); $i++) |
---|
| 107 | { |
---|
| 108 | for ($j=0; $j<count($cnf_keys); $j++) |
---|
| 109 | { |
---|
| 110 | for ($k=0; max($i,$j)+$k<count($cnf_keys); $k++) |
---|
| 111 | { |
---|
| 112 | if ($cnf_keys[$j+$k] == $reg_keys[$i+$k] ) |
---|
| 113 | { |
---|
| 114 | if ( 1+$k>$best_slice['len']) |
---|
| 115 | { |
---|
| 116 | $best_slice['len'] = 1+$k; |
---|
| 117 | $best_slice['start_cnf'] = $j; |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | else |
---|
| 121 | break; |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | } |
---|
[3711] | 125 | */ |
---|
[2488] | 126 | $mb_conf_db = $mb_conf; |
---|
[3711] | 127 | /* |
---|
[2488] | 128 | if ($best_slice['len']) |
---|
| 129 | { |
---|
| 130 | for ($j=0; $j<$best_slice['start_cnf']; $j++ ) |
---|
| 131 | { |
---|
| 132 | $sign = $mb_conf_db[ $cnf_keys[$j] ] > 0 ? 1 : -1; |
---|
| 133 | $mb_conf_db[ $cnf_keys[$j] ] = $sign * ( ($best_slice['start_cnf'])*50 - ($best_slice['start_cnf']-$j) ); |
---|
| 134 | } |
---|
| 135 | for ($j=$best_slice['start_cnf']; $j<$best_slice['start_cnf']+$best_slice['len']; $j++ ) |
---|
| 136 | { |
---|
| 137 | if ($mb_conf_db[ $cnf_keys[$j] ] > 0) |
---|
| 138 | unset( $mb_conf_db[ $cnf_keys[$j] ] ); |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | //var_export( $best_slice ); var_export($mb_conf); var_export($mb_conf_db); |
---|
| 142 | // END OPTIM |
---|
[3711] | 143 | */ |
---|
[2488] | 144 | $query = ' |
---|
| 145 | UPDATE '.CONFIG_TABLE.' |
---|
[4367] | 146 | SET value=\''.addslashes(serialize($mb_conf_db)).'\' |
---|
| 147 | WHERE param=\'blk_'.addslashes($menu->get_id()).'\' |
---|
| 148 | '; |
---|
[2488] | 149 | pwg_query($query); |
---|
[5853] | 150 | |
---|
| 151 | array_push($page['infos'], l10n('Order of menubar items has been updated successfully.')); |
---|
[2488] | 152 | } |
---|
| 153 | |
---|
| 154 | make_consecutive( $mb_conf ); |
---|
| 155 | |
---|
| 156 | foreach ($mb_conf as $id => $pos ) |
---|
| 157 | { |
---|
| 158 | $template->append( 'blocks', |
---|
| 159 | array( |
---|
| 160 | 'pos' => $pos/5, |
---|
| 161 | 'reg' => $reg_blocks[$id] |
---|
| 162 | ) |
---|
| 163 | ); |
---|
| 164 | } |
---|
[3215] | 165 | |
---|
| 166 | $action = get_root_url().'admin.php?page=menubar'; |
---|
| 167 | $template->assign(array('F_ACTION'=>$action)); |
---|
| 168 | |
---|
[2530] | 169 | $template->set_filename( 'menubar_admin_content', 'menubar.tpl' ); |
---|
[2488] | 170 | $template->assign_var_from_handle( 'ADMIN_CONTENT', 'menubar_admin_content'); |
---|
| 171 | ?> |
---|