" ; * _ all "TAB" characters (chr(10)) are replaced by "
" ; * _ all spaces are replaced by " ". * * @param * $var : variable to display * @return * string easy to display in Piwigo */ function str_from_var($var) { return '

'. str_replace( chr(10),'
', str_replace(' ',' ', print_r /* var_dump */ ($var,true)) ). '

'; } /* * ec_inspect() * goes through ec_lists['ec_table'] to check errors on (multiple) entries * using the same code. Cannot really be used elsewhere than here in * build_ec_table() . * * @param * * @return * (no return value) */ function ec_inspect($checked_item, $new_action, $check_ec_nok = true) { global $ec_lists; $first = array(); $to_correct = array(); // $to_correct is needed cause following code would not work everywhere : /* foreach ($table as $value) { if ($value == $value_to_check and $value == $problem) { foreach ($table as &$value2) { // key index of $table can be reset if ($value2 == $value_to_check) { $value2 = $better_value; } } } } // It works with WinAmp Server, but not on Apache server of Free (french // Internet provider). */ foreach ($ec_lists['ec_table'] as $ec_entry) { $ec_current_code = $ec_entry['code']; if ( $ec_entry['action'] == 'ec_ok' or ($check_ec_nok and $ec_entry['action'] == 'ec_nok') ) { if (isset($first[$ec_current_code])) { // $first[$ec_current_code] is set <=> code has already been met. // Checked item MUST be equal to the first item (thus all items) for // this code. if ( $first[$ec_current_code] != $ec_entry[$checked_item] or ($new_action == '' and $ec_entry[$checked_item] == 'true') ) $to_correct[$ec_current_code] = true; // value not used in fact // but using $ec_current_code as a key makes a smaller table } // if the error comes back several times else $first[$ec_current_code] = $ec_entry[$checked_item]; } } foreach ($ec_lists['ec_table'] as &$ec_entry) { // & is needed here if (isset($to_correct[$ec_entry['code']])) { if ($new_action == '') { if (!pwg_query(" UPDATE `".EVNTCATS_TABLE."` SET `forced` = 'false' WHERE `id` = ".$ec_entry['id'] )) die('Could not fix a "_f_pb"'); $ec_entry['forced'] = 'false'; } else $ec_entry['action'] = $new_action; } } } // +-----------------------------------------------------------------------+ // | Tables building functions | // +-----------------------------------------------------------------------+ /* * build_ec_categories($dsp) * builds $ec_lists['categories']. * * @param * whether $ec_lists['categories'] must be of type "cat / sub-cat" or * or "cat - sub-cat". * @return * (no return value) */ function build_ec_categories($dsp) { global $template, $ec_lists; $c = array(); display_select_cat_wrapper(" SELECT `id`, `name`, `uppercats`, `global_rank` FROM `".CATEGORIES_TABLE."` ", $c, 'category_options', $dsp); $ec_lists['categories'] = $template->smarty->_tpl_vars['category_options']; } /* * build_ec_table() * builds a table showing the content of the _event_cats database table, * and a table showing the eventual errors. * * @param * no parameters passed ; the main material on which works the function, is * the global array variable $ec_lists. * @return * (no return value) */ function build_ec_table() { global $ec_lists, $conf, $ec_ap_ok; $ec_lists['ec_table'] = array(); $q = pwg_query(" SELECT * FROM `".EVNTCATS_TABLE."` WHERE `code` IS NOT NULL ORDER BY `id` "); while ($r = mysql_fetch_assoc($q)) $ec_lists['ec_table'][intval($r['id'])] = $r; // Construction of behaviour // Multiple action params for a single code check ec_inspect('action', 'ec_nok_action_pb'); // Multiple user_ids for a single code check ec_inspect('user_id', 'ec_nok_userid_pb', false); // Multiple "forced" params for a single code check ec_inspect('forced', ''); // User id and associated page validities checks foreach ($ec_lists['ec_table'] as &$ec_entry) { // Check if associated user_id exists if ( is_in($ec_entry['action'], 'ec_ok') and !array_key_exists($ec_entry['user_id'], $ec_lists['user_ids']) ) $ec_entry['action'] = 'ec_nok_userid_miss'; // Check if associated displayed page exists $a = 0; if ( !empty($ec_entry['arg1']) and // (Only arg2 is significant if action is ec_nok[_xxx] .) is_in($ec_entry['action'], 'ec_ok') ) $a++; if (!empty($ec_entry['arg2'])) $a+= 2; switch ($a) { // case 0 : home, nothing to check case 2: // Additional Page if ( $ec_ap_ok and ( is_in($ec_entry['action'], 'ec_ok') or $ec_entry['action'] == 'ec_nok' ) and !array_key_exists($ec_entry['arg2'], $ec_lists['add_pages']) ) $ec_entry['action'].= '_ap_pb'; break; case 1: // Category case 3: // Image if (is_in($ec_entry['action'], 'ec_ok')) { if (array_key_exists($ec_entry['arg1'], $ec_lists['categories'])) { if ($a == 3) // case 3: // Image if (!ec_image_exists($ec_entry['arg1'], $ec_entry['arg2'])) $ec_entry['action'].= '_img_pb'; } else $ec_entry['action'].= '_cat_pb'; } break; } } } /* * build_ec_lists() * builds the main array variable contaning all informations for the plugin * * @param * no parameter passed, the main material on which works the function, is * the global array variable $ec_lists. * @return * (no return value) */ function build_ec_lists() { global $ec_ap_ok, $template, $ec_lists; $ec_lists = array(); // Construction of $ec_lists['add_pages'] array var $ec_lists['add_pages'] = array(); if ($ec_ap_ok) { $res = pwg_query("SELECT `id`, `title` FROM `".ADD_PAGES_TABLE."`"); while ($r = mysql_fetch_assoc($res)) { $c = (is_in($r['title'], '/user_id=')) ? '/user_id=' : '/group_id='; $a = explode($c ,$r['title']); $ec_lists['add_pages'][$r['id']] = $a[0]; } } // Construction of $ec_lists['categories'] array var build_ec_categories(true); // Construction of $ec_lists['user_ids'] array var $ec_lists['user_ids'] = array(); $q = pwg_query(" SELECT `id`,`username` FROM `".USERS_TABLE."` WHERE `id` > 2 "); while ($r = mysql_fetch_assoc($q)) $ec_lists['user_ids'][$r['id']] = $r['username']; // Construction of $ec_lists['ec_table'] array var build_ec_table(); } ?>