array('function name','title for main page','description/options for main page')
$tasks = array(
'update_thumbs' => array('update_thumbs', $lang_util_php['update'],'
'.$lang_util_php['update_what'].' (2):
'.$lang_util_php['update_thumb'].'
'.$lang_util_php['update_pic'].'
'.$lang_util_php['update_both'].' '.$lang_util_php['update_number'].'
'.$lang_util_php['update_option'].' '),
'filename_to_title' => array('filename_to_title', $lang_util_php['filename_title'],'
'.$lang_util_php['filename_how'].' (2):
' . $lang_util_php['filename_remove'] . '
'.$lang_util_php['filename_euro'].'
'.$lang_util_php['filename_us'].'
'.$lang_util_php['filename_time'].' '),
'del_titles' => array('del_titles', $lang_util_php['delete_title'], $lang_util_php['delete_title_explanation']),
'del_orig' => array('del_orig', $lang_util_php['delete_original'], $lang_util_php['delete_original_explanation']),
'del_norm' => array('del_norm', $lang_util_php['delete_intermediate'], $lang_util_php['delete_intermediate_explanation']),
'del_orphans' => array('del_orphans', $lang_util_php['delete_orphans'], $lang_util_php['delete_orphans_explanation']),
'refresh_db' => array('refresh_db', $lang_util_php['refresh_db'], $lang_util_php['refresh_db'].' ' . $lang_util_php['update_number'].'
'.$lang_util_php['update_option']),
'reset_views' => array('reset_views', $lang_util_php['reset_views'], $lang_util_php['reset_views_explanation']),
'php_info' => array('', '' . $lang_util_php['phpinfo'] . ' ', $lang_util_php['phpinfo_explanation']),
'upd_db' => array('', '' . $lang_util_php['update_db'].' ',$lang_util_php['update_db_explanation']),
'view_log' => array('', '' . $lang_util_php['view_log'] . ' ', $lang_util_php['view_log_explanation']),
'versioncheck' => array('', '' . $lang_util_php['versioncheck'] . ' ', $lang_util_php['versioncheck_explanation']),
'bridgemgr' => array('', '' . $lang_util_php['bridgemanager'] . ' ', $lang_util_php['bridgemanager_explanation']),
);
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
if (array_key_exists($action, $tasks)){
call_user_func($action);
echo "{$lang_util_php['back']} ";
} else {
$help = ' '.cpg_display_help('f=index.htm&as=admin_tools&ae=admin_tools_end&top=1', '600', '400');
starttable('100%', $lang_util_php['title'].$help, 2);
echo '
'.$lang_util_php['what_it_does'] . ' :
';
foreach($lang_util_desc_php as $value) {
echo "$value \n";
}
echo '
' . $lang_util_php['instruction'] . ' :
(1) ' . $lang_util_php['instruction_action'] . '
(2) ' . $lang_util_php['instruction_parameter'] . '
(3) ' . $lang_util_php['instruction_album'] . '
(4) ' . sprintf($lang_util_php['instruction_press'], $lang_util_php['submit_form']).'
';
endtable();
echo ' ';
}
function my_flush()
{
print str_repeat(" ", 4096); // force a flush;
}
function del_titles()
{
global $CONFIG, $lang_util_php;
$albumid = (isset($_POST['albumid'])) ? $_POST['albumid'] : 0;
$albstr = ($albumid) ? "WHERE aid = $albumid" : '';
echo "{$lang_util_php['delete_wait']} ";
$query = cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET title = '' $albstr");
if ($query) {
echo $lang_util_php['titles_deleted']." ";
}
}
function filename_to_title()
{
global $CONFIG, $lang_util_php;
$albumid = (isset($_POST['albumid'])) ? $_POST['albumid'] : 0;
$albstr = ($albumid) ? " WHERE aid = $albumid" : '';
$parsemode = $_POST['parsemode'];
$result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_PICTURES']} $albstr");
echo "{$lang_util_php['titles_wait']} ";
while ($row = mysql_fetch_assoc($result)){
$filename = $row['filename'];
$pid = $row['pid'];
// //////////////////////////////////////////
// ADD YOUR OWN PARSEMODES HERE //
// /////////////////////////////////////////
$pattern = "/(\d+)(.)(\d+)(.)(\d+)(.)(\d+)(.)(\d+)(.)(\d+)(.+)/";
switch ($parsemode){
case 0: // REMOVE .JPG AND REPLACE _ WITH [ ]
$filename = substr($filename, 0, -4);
$newtitle = str_replace("_", " ", $filename);
break;
case 1: // CHANGE 2003_11_23_13_20_20.jpg TO 23/11/2003 13:20
$newtitle = str_replace("%20", " ", $filename);
$replacement = "$5/$3/$1 $7:$9";
$newtitle = preg_replace($pattern, $replacement, $filename);
break;
case 2: // CHANGE 2003_11_23_13_20_20.jpg TO 11/23/2003 13:20
$newtitle = str_replace("%20", " ", $filename);
$replacement = "$3/$5/$1 $7:$9";
$newtitle = preg_replace($pattern, $replacement, $filename);
break;
case 3: // CHANGE 2003_11_23_13_20_20.jpg TO 13:20
$newtitle = str_replace("%20", " ", $filename);
$replacement = "$7:$9";
$newtitle = preg_replace($pattern, $replacement, $filename);
break;
}
$query = cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET title = '$newtitle' WHERE pid = '$pid'");
if ($query){
echo "{$lang_util_php['file']} : $filename {$lang_util_php['title_set_to']} : $newtitle ";
}
my_flush();
}
}
function filloptions()
{
global $CONFIG, $lang_util_php;
$result = cpg_db_query("SELECT aid, category, IF(user_name IS NOT NULL, CONCAT('(', user_name, ') ',title), CONCAT(' - ', title)) AS title " . "FROM {$CONFIG['TABLE_ALBUMS']} AS a " . "LEFT JOIN {$CONFIG['TABLE_USERS']} AS u ON category = (" . FIRST_USER_CAT . " + user_id) " . "ORDER BY category, title");
echo ' All Albums ';
while ($row = mysql_fetch_array($result)){
$result2 = cpg_db_query("SELECT name FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = {$row['category']}");
$row2 = mysql_fetch_assoc($result2);
echo "{$row2['name']} {$row['title']} ";
}
echo ' (3) (4)';
}
function update_thumbs()
{
global $CONFIG, $lang_util_php;
$albumid = (isset($_POST['albumid'])) ? $_POST['albumid'] : 0;
$albstr = ($albumid) ? "WHERE aid = $albumid" : '';
$updatetype = $_POST['updatetype'];
$numpics = $_POST['numpics'];
$startpic = (isset($_POST['startpic'])) ? $_POST['startpic'] : 0;
echo "{$lang_util_php['thumbs_wait']} ";
$result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_PICTURES']} $albstr LIMIT $startpic, $numpics");
$count = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)){
$image = $CONFIG['fullpath'] . $row['filepath'] . $row['filename'];
$normal = $CONFIG['fullpath'] . $row['filepath'] . $CONFIG['normal_pfx'] . $row['filename'];
$thumb = $CONFIG['fullpath'] . $row['filepath'] . $CONFIG['thumb_pfx'] . $row['filename'];
if ($updatetype == 0 || $updatetype == 2){
if (resize_image($image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'])){
echo "$thumb {$lang_util_php['updated_succesfully']} ! ";
my_flush();
} else {
echo "{$lang_util_php['error_create']} : $thumb ";
my_flush();
}
}
if ($updatetype == 1 || $updatetype == 2){
$imagesize = getimagesize($image);
if (max($imagesize[0], $imagesize[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate']){
if (resize_image($image, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'])){
echo "$normal {$lang_util_php['updated_succesfully']} ! ";
my_flush();
} else {
echo "{$lang_util_php['error_create']} : $normal ";
my_flush();
}
}
}
}
if ($count == $numpics){
$startpic += $numpics;
echo <<< EOT
EOT;
}
}
function del_orig()
{
global $CONFIG, $lang_util_php;
$albumid = (isset($_POST['albumid'])) ? $_POST['albumid'] : 0;
$albstr = ($albumid) ? "WHERE aid = $albumid" : '';
$result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_PICTURES']} $albstr");
$num = mysql_num_rows($result);
echo "{$lang_util_php['replace_wait']} ";
while ($row = mysql_fetch_assoc($result)) {
$pid = $row['pid'];
$image = $CONFIG['fullpath'] . $row['filepath'] . $row['filename'];
$normal = $CONFIG['fullpath'] . $row['filepath'] . $CONFIG['normal_pfx'] . $row['filename'];
$thumb = $CONFIG['fullpath'] . $row['filepath'] . $CONFIG['thumb_pfx'] . $row['filename'];
if (file_exists($normal)) {
$deleted = unlink($image);
$renamed = rename($normal, $image);
if ($deleted AND $renamed){
$imagesize = getimagesize($image); // dimensions
$image_filesize = filesize($image); // bytes
$total_filesize = $image_filesize + filesize($thumb);
cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET filesize='$image_filesize', total_filesize='$total_filesize', pwidth='{$imagesize[0]}', pheight='{$imagesize[1]}' WHERE pid='$pid' ");
printf($lang_util_php['main_success'], $normal);
} else {
echo (!$renamed) ? sprintf($lang_util_php['error_rename'], $normal, $image) : sprintf($lang_util_php['error_deleting'], $image);
}
} else {
printf($lang_util_php['error_not_found'], $normal);
}
echo ' ';
}
}
function del_norm()
{
global $CONFIG, $lang_util_php;
$albumid = (isset($_POST['albumid'])) ? $_POST['albumid'] : 0;
$albstr = ($albumid) ? "WHERE aid = $albumid" : '';
$result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_PICTURES']} $albstr");
$num = mysql_num_rows($result);
echo "".$lang_util_php['deleting_intermediates']." ";
while ($row = mysql_fetch_assoc($result)){
$pid = $row['pid'];
$image = $CONFIG['fullpath'] . $row['filepath'] . $row['filename'];
$normal = $CONFIG['fullpath'] . $row['filepath'] . $CONFIG['normal_pfx'] . $row['filename'];
$thumb = $CONFIG['fullpath'] . $row['filepath'] . $CONFIG['thumb_pfx'] . $row['filename'];
if (file_exists($normal)){
$test = unlink($normal);
if ($test){
$total_filesize = filesize($image) + filesize($thumb);
cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET total_filesize='$total_filesize' WHERE pid='$pid'");
printf('The intermediate pic %s was successfully deleted', $normal);
print ' ';
} else {
printf('Error deleting %s !', $normal);
}
} else {
printf($lang_util_php['error_not_found'], $normal);
print ' ';
}
}
}
function del_orphans()
{
global $CONFIG, $lang_util_php;
$count = 0;
echo "".$lang_util_php['searching_orphans']." ";
my_flush();
if (isset($_GET['single'])){
$delone = cpg_db_query("DELETE FROM {$CONFIG['TABLE_COMMENTS']} WHERE msg_id= '{$_GET['single']}' LIMIT 1");
}
$result = cpg_db_query("SELECT pid FROM {$CONFIG['TABLE_PICTURES']}");
while ($row = mysql_fetch_assoc($result)){
$ok_array[] = $row['pid'];
}
$check_str = '(' . implode(',',$ok_array) . ')';
$result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_COMMENTS']} WHERE pid NOT IN $check_str");
while ($row = mysql_fetch_array($result)){
$pid = $row['pid'];
$msg_id = $row['msg_id'];
$msg_body = $row['msg_body'];
if (isset($_POST['del'])){
cpg_db_query("DELETE FROM {$CONFIG['TABLE_COMMENTS']} WHERE msg_id= $msg_id");
echo "{$lang_util_php['comment']} $msg_body {$lang_util_php['nonexist']} $pid - {$lang_util_php['delete']} ";
}
$count = mysql_num_rows($result);
echo " $count {$lang_util_php['orphan_comment']} ";
if ($count > 1){
echo <<< EOT
EOT;
}
}
}
function reset_views()
{
global $CONFIG, $lang_util_php;
$albumid = (isset($_POST['albumid'])) ? $_POST['albumid'] : 0;
$albstr = ($albumid) ? "WHERE aid = $albumid" : '';
if (cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET hits ='0' $albstr")) echo 'Reset successful';
}
function refresh_db()
{
global $CONFIG, $lang_util_php;
$albumid = (isset($_POST['albumid'])) ? $_POST['albumid'] : 0;
$albstr = ($albumid) ? "WHERE aid = $albumid" : '';
$numpics = $_POST['refresh_numpics'];
$startpic = (isset($_POST['refresh_startpic'])) ? $_POST['refresh_startpic'] : 0;
starttable('100%', "Update results", 3);
echo "{$lang_util_php['file']} {$lang_util_php['problem']} {$lang_util_php['status']} ";
$outcome = 'none';
$result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_PICTURES']} $albstr ORDER BY pid ASC LIMIT $startpic, $numpics");
$count = mysql_num_rows($result);
$found = 0;
while ($row = mysql_fetch_assoc($result)){
extract($row, EXTR_PREFIX_ALL, "db");
unset($prob);
$full_pic_url = $CONFIG['fullpath'] . $db_filepath . $db_filename;
$thumb_url = $CONFIG['fullpath'] . $db_filepath . $CONFIG['thumb_pfx'] . $db_filename;
$normal_url = $CONFIG['fullpath'] . $db_filepath . $CONFIG['normal_pfx'] . $db_filename;
$url = '' . "$db_title ($db_pid)" . ' ';
if (@file_exists($full_pic_url)){
$filesize = @filesize($full_pic_url);
$dimensions = @getimagesize($full_pic_url);
if ($filesize){
$thumb_filesize = @filesize($thumb_url);
$normal_filesize = @filesize($normal_url);
$total_filesize = $filesize + $thumb_filesize + $normal_filesize;
if ($total_filesize <> $db_total_filesize){
$prob .= "Total filesize is incorrect Database: {$db_total_filesize} bytes Actual: {$total_filesize} bytes ";
$fs1_upd = @cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET total_filesize = '$total_filesize' WHERE pid = '$db_pid' LIMIT 1");
$outcome = ($fs1_upd) ? 'Updated' : 'Update failed.';
}
if ($filesize <> $db_filesize){
$prob .= "Total filesize is incorrect Database: {$db_filesize} bytes Actual: {$filesize} bytes ";
$fs2_upd = @cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET filesize = '$filesize' WHERE pid = '$db_pid' LIMIT 1");
$outcome = ($fs2_upd) ? 'Updated' : 'Update failed.';
}
} else {
$prob .= "Could not obtain file size (may be invalid file), skipping.... ";
$outcome = "Skipped";
}
if ($dimensions){
if (($dimensions[0] <> $db_pwidth) || ($dimensions[1] <> $db_pheight)){
$prob .= "Dimensions are incorrect Database: {$db_pwidth}x{$db_pheight} Actual:{$dimensions[0]}x{$dimensions[1]} ";
$dim_upd = @cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET `pwidth` = '{$dimensions[0]}', `pheight` = '{$dimensions[1]}' WHERE `pid` = '$db_pid' LIMIT 1");
$outcome = ($dim_upd) ? 'Updated' : 'Update failed - '.mysql_error();
}
} else {
$prob .= "Could not obtain dimension info, skipping.... ";
$outcome = "Skipped";
}
} else {
$prob .= "File $full_pic_url does not exist ! ";
$outcome = "Cannot fix";
}
if ($prob){
$found++;
echo "$url $prob $outcome ";
} else {
echo "$url No problems detected OK ";
}
my_flush();
}
endtable();
if ($outcome == 'none') echo 'No problems were found.';
if ($count == $numpics){
$startpic += $numpics;
echo <<< EOT
EOT;
}
}
pagefooter();
ob_end_flush();
?>