-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy patherrors.class.php
82 lines (70 loc) · 2.77 KB
/
errors.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if(!class_exists('samErrors')) {
class samErrors {
public $errorString;
public function __construct($rows = null) {
$this->errorString = self::checkShell($rows);
}
public function getErrors($rows = array(), $dir = '') {
global $wpdb;
$errors = array(
'dir' => false,
'tables' => array(
'places' => 0,
'ads' => 0,
'zones' => 0,
'blocks' => 0
),
'prefix' => $wpdb->prefix
);
if(is_null($dir)) $dir = SAM_AD_IMG;
if(!is_dir($dir)) $errors['dir'] = true;
foreach($rows as $key => $value) {
$table = $wpdb->prefix . 'sam_' . $key;
if($wpdb->get_var("SHOW TABLES LIKE '$table'") != $table) $errors['tables'][$key] = 1;
if($errors['tables'][$key] != 1) {
$result = $wpdb->get_results("DESCRIBE $table", ARRAY_A);
if($rows[$key] != count($result)) $errors['tables'][$key] = 2;
}
}
return $errors;
}
public function checkShell($rows = null) {
global $sam_tables_defs;
$dirError = '';
$oError = '';
$output = '';
if(is_null($rows))
$rows = array(
'places' => count($sam_tables_defs['places']),
'ads' => count($sam_tables_defs['ads']),
'zones' => count($sam_tables_defs['zones']),
'blocks' => count($sam_tables_defs['blocks'])
);
$errors = self::getErrors($rows, SAM_AD_IMG);
if($errors['dir']) {
$dirError = '<p><strong>'.__("Simple Ads Manager Images Folder hasn't been created!", SAM_DOMAIN).'</strong></p>';
$dirError .= '<p>'.__("Try to reactivate plugin or create folder manually.", SAM_DOMAIN).'<br/>'.__("Manually creation: Create folder 'sam-images' in 'wp-content/plugins' folder. Don't forget to set folder's permissions to 777.", SAM_DOMAIN).'</p>';
}
foreach($errors['tables'] as $key => $value) {
$table = $errors['prefix'].'sam_'.$key;
switch($value) {
case 1:
$oError .= '<p><strong>'.sprintf(__("Database table %s hasn't been created!", SAM_DOMAIN), $table).'</strong></p>';
break;
case 2:
$oError .= '<p><strong>'.sprintf(__("Database table %s hasn't been upgraded!", SAM_DOMAIN), $table).'</strong></p>';
break;
default:
$oError .= '';
break;
}
}
if(!empty($oError) || !empty($dirError))
$output = '<div class="error below-h2">'.$dirError.$oError.'</div>';
return $output;
}
}
}
?>