This is MOD no like other. Is good after restore backup (or switch server) and see if all images is there in server with
single click.
1 - Is scan for thumbnails and media folder (in media) and match cat ID folder with cat_id CATEGORIES_TABLE and IMAGES_TABLE table.
2 - Is scan for match image filename in all thumbnails and media folder with IMAGES_TABLE table - image_thumb_file and image_media_file field.
If different for 1 or 2, is show error in HTML table and say count of error and show log of no correct or rename data in gallery (data folder - thumbnails and media with inside - sub-folder).
I create plug in file.
If 1 and 2 is show all good in gallery, nothing is show in plug in file page for error.
Note: PHP v5.2+ is need for this. If no get PHP version, ACP - > phpinfo() .Note: Sub cat ID is no include (I try for code).
// Step 1
In admin/plugins folder, create file: images_gallery_diagnostic.php .
Add:
<?php // PLUGIN_TITLE: Images Gallery Diagnostic
$nozip = 1;
define('IN_CP', 1);
define('ROOT_PATH', "./../../");
require(ROOT_PATH.'admin/admin_global.php');
show_admin_header();
if ($action == "") {
$action = "main_menu";
}
if ($action == "main_menu") {
?>
<form>
<?php echo $lang['sql_fields_diagnostic_select_folder']; ?>
<select name="users" onchange="showDirs(this.value)" class="select" />
<option>---</option>
<option value="thumbnails">Thumbnails</option>
<option value="media">Media</option>
</select>
</form>
<table border="0" width="100%" cellpadding="0" cellspacing="0" class="tableborder" />
<tr class="tableseparator">
<td width="100%" class="tableheader"> <?php echo $lang['images_gallery_diagnostic_title']; ?></td>
</tr>
<tr class="tableseparator">
<td width="100%" class="tablerow"> </td>
</tr>
<tr class="tableseparator">
<td width="100%"><div id="dirHint"> </div></td>
</tr>
</table>
<?php
}
if ($action == "get_dirs") {
if (isset($HTTP_GET_VARS['dir_name'])) {
$dir_name = (isset($HTTP_GET_VARS['dir_name'])) ? get_basename(trim(stripslashes($HTTP_GET_VARS['dir_name']))) : "";
} else {
$dir_name = "";
}
if (isset($dir_name) && empty($dir_name) || $dir_name == "---") {
exit;
}
function scanDirectories($rootDir, $allData = array()) {
global $site_db, $site_sess, $lang, $user_table_fields, $config;
$sql = "
SELECT i.cat_id, i.image_date, i.image_thumb_file, i.image_media_file" . get_user_table_field(", u.", "user_id") . get_user_table_field(", u.", "user_name") . "
FROM (" . IMAGES_TABLE . " i, " . CATEGORIES_TABLE . " c)
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = i.user_id)
WHERE i.cat_id = c.cat_id
";
$image_row = $site_db->query_firstrow($sql);
$cat_id = (int)$image_row['cat_id'];
$image_date = (function_exists('get_universal_field_date')) ? get_universal_field_date($image_row['image_date']) : format_date($config['date_format'] . " " . $config['time_format'], $image_row['image_date']);
$image_thumb_file = get_file_name(basename($image_row['image_thumb_file']));
$image_media_file = get_file_name(basename($image_row['image_media_file']));
$user_id = (int)$image_row[$user_table_fields['user_id']];
$user_name = format_text(trim($image_row[$user_table_fields['user_name']]), 2);
// set filenames invisible if you want
$invisibleFileNames = array(".", "..", "index.html", "index.htm", "index.shtml", "default.htm", "default.html", "default.shtml", ".htaccess", ".htpasswd");
// run through content of root directory
$dirContent = @scandir($rootDir);
$error_files_counter = "";
$error_files = "";
$error_folders = "";
foreach ($dirContent as $key => $content) {
// filter all files not accessible
$path = $rootDir.'/'.$content;
if (!in_array($content, $invisibleFileNames)) {
// if content is file & readable, add to array
if (is_file($path) && is_readable($path)) {
// save file name with path
$path = str_replace(ROOT_PATH, "", $path);
$file_source = preg_replace("/([a-z])+\/([a-z])+\/([0-9])+\/+/i", "", $path);
if (preg_match("/(.+)\.(.+)/", get_file_name(basename($file_source)), $regs)) {
$file_name = $regs[1];
$file_extension = $regs[2];
$full_file_name = format_text(trim($regs[1] . "." . $regs[2]), 2);
}
if (isset($full_file_name) && !empty($full_file_name) && preg_match("/([a-z])+\/([a-z])+\/+/", $path, $regs)) {
$path_source = substr(format_text(trim($regs[0]), 2), 0, -1);
$path_source = format_text(trim($path_source), 2);
}
if (isset($path_source) && !empty($path_source) && preg_match("/([a-z])+\/([a-z])+\/([0-9])+\/+/", $path, $regs)) {
$folder_cat_id = preg_replace("/[^0-9]+/i", "", $regs[0]);
$folder_cat_id = format_text(trim($folder_cat_id), 2);
}
if (isset($path_source) && isset($folder_cat_id) && isset($cat_id) && !is_dir(ROOT_PATH . $path_source . "/" . $folder_cat_id) || (is_dir(ROOT_PATH . $path_source . "/" . $folder_cat_id) && $folder_cat_id != $cat_id)) {
if (sizeof($cat_id) > 0) {
$use_cat_id = $cat_id;
$use_text = (str_replace(array("{use_cat_id}"), array($use_cat_id), $lang['images_gallery_diagnostic_use_cat_id']));
} elseif (sizeof($folder_cat_id) > 0) {
$use_cat_id = $folder_cat_id;
$use_text = (str_replace(array("{use_cat_id}"), array($folder_cat_id), $lang['images_gallery_diagnostic_use_folder_cat_id']));
} else {
$use_cat_id = "<>";
}
$error_files_counter = $key - 1;
$error_files .= "
" . (str_replace(array("{use_text}", "{path_source}", "{use_cat_id}", "{images_table}"), array($use_text, $path_source, $use_cat_id, $images_table), $lang['images_gallery_diagnostic_use_no_match_cat_id']))
. ((isset($image_thumb_file) && !empty($image_thumb_file)) ? (str_replace(array("{image_thumb_file}", "{images_table}"), array($image_thumb_file, IMAGES_TABLE), $lang['images_gallery_diagnostic_use_if_thumb_file_found'])) : "")
. (($full_file_name == $image_thumb_file || $full_file_name == $image_media_file) ? (str_replace(array("{user_profile_link}"), array("<a href=\"" . $site_sess->url(ROOT_PATH . "member.php?action=showprofile&" . URL_USER_ID . "=" . $user_id) . "\" target=\"_blank\">" . $user_name . "</a>"), $lang['images_gallery_diagnostic_use_user_profile_link'])) : "")
. ((isset($image_thumb_file) && !empty($image_thumb_file)) ? (str_replace(array("{use_text}", "{image_thumb_file}"), array($use_text, $image_thumb_file), $lang['images_gallery_diagnostic_another_if_thumb_file_found'])) : "")
. ((isset($full_file_name) && isset($image_thumb_file) && isset($folder_cat_id) && isset($path_source) && $full_file_name == $image_thumb_file) ? (str_replace(array("{path_source}", "{folder_cat_id}"), array($path_source, $folder_cat_id), $lang['images_gallery_diagnostic_use_match_filenames'])) : ".") . "<br />";
break;
} elseif (isset($image_thumb_file) && isset($image_media_file) && isset($full_file_name) && isset($folder_cat_id) && $full_file_name != $image_thumb_file || $full_file_name != $image_media_file) {
if (sizeof($full_file_name) > 0) {
$use_file_name = $full_file_name;
} elseif (sizeof($image_thumb_file) > 0) {
$use_file_name = $image_thumb_name;
} elseif (sizeof($image_media_file) > 0) {
$use_file_name = $image_media_name;
}
$error_files_counter = $key - 2;
$error_files .= (str_replace(array("{path_source}", "{folder_cat_id}"), array($path_source, $folder_cat_id), $lang['images_gallery_diagnostic_use_file_name'])) . ((isset($use_file_name) && !empty($use_file_name)) ? (str_replace(array("{use_file_name}", "{images_table}"), array($use_file_name, IMAGES_TABLE), $lang['images_gallery_diagnostic_use_another_file_name'])) : "<>") . "<br />";
}
// if content is a directory and readable, add path and name
} elseif (is_dir($path) && is_readable($path)) {
// recursive callback to open new directory
echo scanDirectories($path, $allData);
}
}
}
if ($error_files_counter > 0) {
?>
<table border="0" width="75%" cellpadding="0" class="tableborder" />
<tr class="tableseparator">
<td width="75%" align="left" class="tableheader" /><?php echo (str_replace(array("{error_files_counter}"), array($error_files_counter), $lang['images_gallery_diagnostic_use_error_title'])); ?></td>
</tr>
<tr>
<td width="75%" align="left" class="tablerow" /><br /><?php echo $error_files; ?><br /></td>
</tr>
</table>
<?php
}
}
// End function.
?>
<table border="0" width="100%" cellpadding="0" cellspacing="0" class="tableborder" />
<tr class="tableseparator">
<td width="100%" class="tablerow" align="center"><?php echo scanDirectories(ROOT_PATH . "data/" . $dir_name); ?></td>
</tr>
</table>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" class="tablerow"> </td>
</tr>
</table>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" class="tableheader"> </td>
</tr>
</table>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" align="center" class="tablerow"><br /><span class=\"smalltext\"><b>Images Gallery Diagnostic MOD</b> - created by <a href="http://www.4homepages.de/forum/index.php?topic=19856.0" target="_blank" />Thunderstrike</a> - 2007-2008<br />Version 1.0</span><br /><br /></td>
</tr>
</table>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="100%" class="tableheader"> </td>
</tr>
</table>
<?php
}
show_admin_footer();
?>
// Step 2
In lang/english/main.php file,
add in top ?>:
//-----------------------------------------------------
//--- Image Gallery Diagnostic ------------------------
//-----------------------------------------------------
$lang['images_gallery_diagnostic_title'] = "Images Gallery Diagnostic";
$lang['sql_fields_diagnostic_select_folder'] = "Select a folder: ";
$lang['images_gallery_diagnostic_use_error_title'] = "Error(s) found: {error_files_counter}";
$lang['images_gallery_diagnostic_use_cat_id'] = "cat ID value: {use_cat_id}";
$lang['images_gallery_diagnostic_use_folder_cat_id'] = "folder cat ID value: {use_cat_id}";
$lang['images_gallery_diagnostic_use_no_match_cat_id'] = "Cannot find <b>{use_text}</b> under FTP folder: {path_source}/<b>{use_cat_id}</b> and / or in <b>{images_table}</b> table";
$lang['images_gallery_diagnostic_use_if_thumb_file_found'] = ". <b>{image_thumb_file}</b> file has been found in <b>{images_table}</b> table";
$lang['images_gallery_diagnostic_use_user_profile_link'] = "<br /> (uploaded by: {user_profile_link}).";
$lang['images_gallery_diagnostic_another_if_thumb_file_found'] = " Matched <b>{use_text}</b> for: <b>{image_thumb_file}</b> file.";
$lang['images_gallery_diagnostic_use_match_filenames'] = " ID matched on FTP: {path_source}/<b><font color=\"red\">{folder_cat_id}</font></b><br />";
$lang['images_gallery_diagnostic_use_file_name'] = " Cannot find file {path_source}/{folder_cat_id}";
$lang['images_gallery_diagnostic_use_another_file_name'] = "/<b>{use_file_name}</b> under FTP and / or in <b>{images_table}</b> table.";
I ask friend for english text, hope is good ...
// Step 3
In admin/admin_functions.php file,
find:
<script type="text/javascript" language="javascript" src="<?php echo ROOT_PATH; ?>admin/calendar.js"></script>
add after:
<?php
// MOD: SQL Fields Diagnostic
if (preg_match("/images_gallery_diagnostic.php/", $self_url)) {
?>
<script src="<?php echo ROOT_PATH; ?>admin/images_gallery_diagnostic.js"></script>
<?php
// End of MOD: SQL Fields Diagnostic
}
?>
// Step 4
In admin, create file:
images_gallery_diagnostic.js ,
add:
var xmlHttp
function showDirs(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="./../../admin/plugins/images_gallery_diagnostic.php"
url=url+"?action=get_dirs&dir_name="+str
//url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("dirHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
Screenshot 1: If rename one cat_id folder in thumbnails folder and is no match for CATEGORIES_TABLE table (cat_id field), is show error message in plug in page. Is say cat ID detect in CATEGORIES_TABLE and IMAGES_TABLE but cat ID folder in FTP is
4 and match is
2.
Screenshot 2: If upload image name in FTP and is no see in IMAGES_TABLE table, error is show in plug in page.
Finish.