Completed
Branch master (3189d6)
by Michael
14:06 queued 10:31
created
admin/customtag.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -12,32 +12,32 @@  discard block
 block discarded – undo
12 12
 
13 13
 function editcustomtag($showmenu = false, $customtagid = 0, $clone = false)
14 14
 {
15
-    global $smartobjectCustomtagHandler;
16
-
17
-    $customtagObj = $smartobjectCustomtagHandler->get($customtagid);
18
-
19
-    if (!$clone && !$customtagObj->isNew()) {
20
-        if ($showmenu) {
21
-            //smart_adminMenu(2, _AM_SOBJECT_CUSTOMTAGS . " > " . _AM_SOBJECT_EDITING);
22
-        }
23
-        smart_collapsableBar('customtagedit', _AM_SOBJECT_CUSTOMTAGS_EDIT, _AM_SOBJECT_CUSTOMTAGS_EDIT_INFO);
24
-
25
-        $sform = $customtagObj->getForm(_AM_SOBJECT_CUSTOMTAGS_EDIT, 'addcustomtag');
26
-        $sform->display();
27
-        smart_close_collapsable('customtagedit');
28
-    } else {
29
-        $customtagObj->setVar('customtagid', 0);
30
-        $customtagObj->setVar('tag', '');
31
-
32
-        if ($showmenu) {
33
-            //smart_adminMenu(2, _AM_SOBJECT_CUSTOMTAGS . " > " . _CO_SOBJECT_CREATINGNEW);
34
-        }
35
-
36
-        smart_collapsableBar('customtagcreate', _AM_SOBJECT_CUSTOMTAGS_CREATE, _AM_SOBJECT_CUSTOMTAGS_CREATE_INFO);
37
-        $sform = $customtagObj->getForm(_AM_SOBJECT_CUSTOMTAGS_CREATE, 'addcustomtag');
38
-        $sform->display();
39
-        smart_close_collapsable('customtagcreate');
40
-    }
15
+	global $smartobjectCustomtagHandler;
16
+
17
+	$customtagObj = $smartobjectCustomtagHandler->get($customtagid);
18
+
19
+	if (!$clone && !$customtagObj->isNew()) {
20
+		if ($showmenu) {
21
+			//smart_adminMenu(2, _AM_SOBJECT_CUSTOMTAGS . " > " . _AM_SOBJECT_EDITING);
22
+		}
23
+		smart_collapsableBar('customtagedit', _AM_SOBJECT_CUSTOMTAGS_EDIT, _AM_SOBJECT_CUSTOMTAGS_EDIT_INFO);
24
+
25
+		$sform = $customtagObj->getForm(_AM_SOBJECT_CUSTOMTAGS_EDIT, 'addcustomtag');
26
+		$sform->display();
27
+		smart_close_collapsable('customtagedit');
28
+	} else {
29
+		$customtagObj->setVar('customtagid', 0);
30
+		$customtagObj->setVar('tag', '');
31
+
32
+		if ($showmenu) {
33
+			//smart_adminMenu(2, _AM_SOBJECT_CUSTOMTAGS . " > " . _CO_SOBJECT_CREATINGNEW);
34
+		}
35
+
36
+		smart_collapsableBar('customtagcreate', _AM_SOBJECT_CUSTOMTAGS_CREATE, _AM_SOBJECT_CUSTOMTAGS_CREATE_INFO);
37
+		$sform = $customtagObj->getForm(_AM_SOBJECT_CUSTOMTAGS_CREATE, 'addcustomtag');
38
+		$sform->display();
39
+		smart_close_collapsable('customtagcreate');
40
+	}
41 41
 }
42 42
 
43 43
 include_once __DIR__ . '/admin_header.php';
@@ -52,70 +52,70 @@  discard block
 block discarded – undo
52 52
 $op = '';
53 53
 
54 54
 if (isset($_GET['op'])) {
55
-    $op = $_GET['op'];
55
+	$op = $_GET['op'];
56 56
 }
57 57
 if (isset($_POST['op'])) {
58
-    $op = $_POST['op'];
58
+	$op = $_POST['op'];
59 59
 }
60 60
 
61 61
 switch ($op) {
62
-    case 'mod':
62
+	case 'mod':
63 63
 
64
-        $customtagid = isset($_GET['customtagid']) ? (int)$_GET['customtagid'] : 0;
64
+		$customtagid = isset($_GET['customtagid']) ? (int)$_GET['customtagid'] : 0;
65 65
 
66
-        smart_xoops_cp_header();
67
-        echo $indexAdmin->addNavigation(basename(__FILE__));
66
+		smart_xoops_cp_header();
67
+		echo $indexAdmin->addNavigation(basename(__FILE__));
68 68
 
69
-        editcustomtag(true, $customtagid);
70
-        break;
69
+		editcustomtag(true, $customtagid);
70
+		break;
71 71
 
72
-    case 'clone':
72
+	case 'clone':
73 73
 
74
-        $customtagid = isset($_GET['customtagid']) ? (int)$_GET['customtagid'] : 0;
74
+		$customtagid = isset($_GET['customtagid']) ? (int)$_GET['customtagid'] : 0;
75 75
 
76
-        smart_xoops_cp_header();
77
-        echo $indexAdmin->addNavigation(basename(__FILE__));
76
+		smart_xoops_cp_header();
77
+		echo $indexAdmin->addNavigation(basename(__FILE__));
78 78
 
79
-        editcustomtag(true, $customtagid, true);
80
-        break;
79
+		editcustomtag(true, $customtagid, true);
80
+		break;
81 81
 
82
-    case 'addcustomtag':
83
-        include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
84
-        $controller = new SmartObjectController($smartobjectCustomtagHandler);
85
-        $controller->storeFromDefaultForm(_AM_SOBJECT_CUSTOMTAGS_CREATED, _AM_SOBJECT_CUSTOMTAGS_MODIFIED);
86
-        break;
82
+	case 'addcustomtag':
83
+		include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
84
+		$controller = new SmartObjectController($smartobjectCustomtagHandler);
85
+		$controller->storeFromDefaultForm(_AM_SOBJECT_CUSTOMTAGS_CREATED, _AM_SOBJECT_CUSTOMTAGS_MODIFIED);
86
+		break;
87 87
 
88
-    case 'del':
88
+	case 'del':
89 89
 
90
-        include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
91
-        $controller = new SmartObjectController($smartobjectCustomtagHandler);
92
-        $controller->handleObjectDeletion();
90
+		include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
91
+		$controller = new SmartObjectController($smartobjectCustomtagHandler);
92
+		$controller->handleObjectDeletion();
93 93
 
94
-        break;
94
+		break;
95 95
 
96
-    default:
96
+	default:
97 97
 
98
-        smart_xoops_cp_header();
99
-        echo $indexAdmin->addNavigation(basename(__FILE__));
100
-        $indexAdmin->addItemButton(_AM_SOBJECT_CUSTOMTAGS_CREATE, 'customtag.php?op=mod', 'add', '');
101
-        echo $indexAdmin->renderButton('left', '');
98
+		smart_xoops_cp_header();
99
+		echo $indexAdmin->addNavigation(basename(__FILE__));
100
+		$indexAdmin->addItemButton(_AM_SOBJECT_CUSTOMTAGS_CREATE, 'customtag.php?op=mod', 'add', '');
101
+		echo $indexAdmin->renderButton('left', '');
102 102
 
103
-        //smart_adminMenu(2, _AM_SOBJECT_CUSTOMTAGS);
103
+		//smart_adminMenu(2, _AM_SOBJECT_CUSTOMTAGS);
104 104
 
105
-        smart_collapsableBar('createdcustomtags', _AM_SOBJECT_CUSTOMTAGS, _AM_SOBJECT_CUSTOMTAGS_DSC);
105
+		smart_collapsableBar('createdcustomtags', _AM_SOBJECT_CUSTOMTAGS, _AM_SOBJECT_CUSTOMTAGS_DSC);
106 106
 
107
-        include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php';
108
-        $objectTable = new SmartObjectTable($smartobjectCustomtagHandler);
109
-        $objectTable->addColumn(new SmartObjectColumn('name', 'left', 150, 'getCustomtagName'));
110
-        $objectTable->addColumn(new SmartObjectColumn('description', 'left'));
111
-        $objectTable->addColumn(new SmartObjectColumn('language', 'center', 150));
107
+		include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php';
108
+		$objectTable = new SmartObjectTable($smartobjectCustomtagHandler);
109
+		$objectTable->addColumn(new SmartObjectColumn('name', 'left', 150, 'getCustomtagName'));
110
+		$objectTable->addColumn(new SmartObjectColumn('description', 'left'));
111
+		$objectTable->addColumn(new SmartObjectColumn('language', 'center', 150));
112 112
 
113
-        //      $objectTable->addCustomAction('getCreateItemLink');
114
-        //      $objectTable->addCustomAction('getCreateAttributLink');
113
+		//      $objectTable->addCustomAction('getCreateItemLink');
114
+		//      $objectTable->addCustomAction('getCreateAttributLink');
115 115
 
116
-        //      $objectTable->addIntroButton('addcustomtag', 'customtag.php?op=mod', _AM_SOBJECT_CUSTOMTAGS_CREATE); //mb button
116
+		//      $objectTable->addIntroButton('addcustomtag', 'customtag.php?op=mod', _AM_SOBJECT_CUSTOMTAGS_CREATE); //mb button
117 117
 
118
-        /*
118
+		/*
119 119
                 $criteria_upcoming = new CriteriaCompo();
120 120
                 $criteria_upcoming->add(new Criteria('start_date', time(), '>'));
121 121
                 $objectTable->addFilter(_AM_SOBJECT_FILTER_UPCOMING, array(
@@ -139,16 +139,16 @@  discard block
 block discarded – undo
139 139
                                             'criteria' => $criteria_last30days
140 140
                 ));
141 141
         */
142
-        $objectTable->addQuickSearch(array('title', 'summary', 'description'));
143
-        $objectTable->addCustomAction('getCloneLink');
142
+		$objectTable->addQuickSearch(array('title', 'summary', 'description'));
143
+		$objectTable->addCustomAction('getCloneLink');
144 144
 
145
-        $objectTable->render();
145
+		$objectTable->render();
146 146
 
147
-        echo '<br />';
148
-        smart_close_collapsable('createdcustomtags');
149
-        echo '<br>';
147
+		echo '<br />';
148
+		smart_close_collapsable('createdcustomtags');
149
+		echo '<br>';
150 150
 
151
-        break;
151
+		break;
152 152
 }
153 153
 
154 154
 //smart_modFooter();
Please login to merge, or discard this patch.
admin/menu.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 $pathLanguage    = $path . $pathModuleAdmin;
20 20
 
21 21
 if (!file_exists($fileinc = $pathLanguage . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/' . 'main.php')) {
22
-    $fileinc = $pathLanguage . '/language/english/main.php';
22
+	$fileinc = $pathLanguage . '/language/english/main.php';
23 23
 }
24 24
 
25 25
 include_once $fileinc;
@@ -60,43 +60,43 @@  discard block
 block discarded – undo
60 60
 //---------------------------------
61 61
 
62 62
 if (!defined('SMARTOBJECT_ROOT_PATH')) {
63
-    include_once XOOPS_ROOT_PATH . '/modules/smartobject/include/functions.php';
63
+	include_once XOOPS_ROOT_PATH . '/modules/smartobject/include/functions.php';
64 64
 }
65 65
 
66 66
 $smartobjectConfig = smart_getModuleConfig('smartobject');
67 67
 
68 68
 if (isset($smartobjectConfig['enable_currencyman']) && $smartobjectConfig['enable_currencyman'] == true) {
69
-    ++$i;
70
-    $adminmenu[$i]['title'] = _MI_SOBJECT_CURRENCIES;
71
-    $adminmenu[$i]['link']  = 'admin/currency.php';
72
-    $adminmenu[$i]['icon']  = $pathIcon32 . '/cash_stack.png';
69
+	++$i;
70
+	$adminmenu[$i]['title'] = _MI_SOBJECT_CURRENCIES;
71
+	$adminmenu[$i]['link']  = 'admin/currency.php';
72
+	$adminmenu[$i]['icon']  = $pathIcon32 . '/cash_stack.png';
73 73
 }
74 74
 
75 75
 global $xoopsModule;
76 76
 if (isset($xoopsModule)) {
77
-    //  $i = -1;
78
-
79
-    // --- for XCL ---
80
-    //  $headermenu[$i]['link'] = '../../system/admin.php?fct=preferences&amp;op=showmod&amp;mod=' . $xoopsModule->getVar('mid');
81
-    $mid = $xoopsModule->getVar('mid');
82
-    if (defined('XOOPS_CUBE_LEGACY')) {
83
-        $link_pref = XOOPS_URL . '/modules/legacy/admin/index.php?action=PreferenceEdit&confmod_id=' . $mid;
84
-    } else {
85
-        $link_pref = XOOPS_URL . '/modules/system/admin.php?fct=preferences&op=showmod&mod=' . $mid;
86
-    }
87
-    $headermenu[$i]['link'] = $link_pref;
88
-    // -----
89
-
90
-    // --- for XCL ---
91
-    //  $headermenu[$i]['link'] = XOOPS_URL . "/modules/system/admin.php?fct=modulesadmin&op=update&module=" . $xoopsModule->getVar('dirname');
92
-    $dirname = $xoopsModule->getVar('dirname');
93
-    if (defined('XOOPS_CUBE_LEGACY')) {
94
-        $link_module = XOOPS_URL . '/modules/legacy/admin/index.php?action=ModuleUpdate&dirname=' . $dirname;
95
-    } else {
96
-        $link_module = XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin&op=update&module=' . $dirname;
97
-    }
98
-    $headermenu[$i]['link'] = $link_module;
99
-    // -----
100
-
101
-    ++$i;
77
+	//  $i = -1;
78
+
79
+	// --- for XCL ---
80
+	//  $headermenu[$i]['link'] = '../../system/admin.php?fct=preferences&amp;op=showmod&amp;mod=' . $xoopsModule->getVar('mid');
81
+	$mid = $xoopsModule->getVar('mid');
82
+	if (defined('XOOPS_CUBE_LEGACY')) {
83
+		$link_pref = XOOPS_URL . '/modules/legacy/admin/index.php?action=PreferenceEdit&confmod_id=' . $mid;
84
+	} else {
85
+		$link_pref = XOOPS_URL . '/modules/system/admin.php?fct=preferences&op=showmod&mod=' . $mid;
86
+	}
87
+	$headermenu[$i]['link'] = $link_pref;
88
+	// -----
89
+
90
+	// --- for XCL ---
91
+	//  $headermenu[$i]['link'] = XOOPS_URL . "/modules/system/admin.php?fct=modulesadmin&op=update&module=" . $xoopsModule->getVar('dirname');
92
+	$dirname = $xoopsModule->getVar('dirname');
93
+	if (defined('XOOPS_CUBE_LEGACY')) {
94
+		$link_module = XOOPS_URL . '/modules/legacy/admin/index.php?action=ModuleUpdate&dirname=' . $dirname;
95
+	} else {
96
+		$link_module = XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin&op=update&module=' . $dirname;
97
+	}
98
+	$headermenu[$i]['link'] = $link_module;
99
+	// -----
100
+
101
+	++$i;
102 102
 }
Please login to merge, or discard this patch.
admin/currency.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -10,29 +10,29 @@  discard block
 block discarded – undo
10 10
 
11 11
 function editclass($showmenu = false, $currencyid = 0)
12 12
 {
13
-    global $smartobjectCurrencyHandler;
14
-
15
-    $currencyObj = $smartobjectCurrencyHandler->get($currencyid);
16
-
17
-    if (!$currencyObj->isNew()) {
18
-        if ($showmenu) {
19
-            //smart_adminMenu(5, _AM_SOBJECT_CURRENCIES . " > " . _AM_SOBJECT_EDITING);
20
-        }
21
-        smart_collapsableBar('currencyedit', _AM_SOBJECT_CURRENCIES_EDIT, _AM_SOBJECT_CURRENCIES_EDIT_INFO);
22
-
23
-        $sform = $currencyObj->getForm(_AM_SOBJECT_CURRENCIES_EDIT, 'addcurrency');
24
-        $sform->display();
25
-        smart_close_collapsable('currencyedit');
26
-    } else {
27
-        if ($showmenu) {
28
-            //smart_adminMenu(5, _AM_SOBJECT_CURRENCIES . " > " . _CO_SOBJECT_CREATINGNEW);
29
-        }
30
-
31
-        smart_collapsableBar('currencycreate', _AM_SOBJECT_CURRENCIES_CREATE, _AM_SOBJECT_CURRENCIES_CREATE_INFO);
32
-        $sform = $currencyObj->getForm(_AM_SOBJECT_CURRENCIES_CREATE, 'addcurrency');
33
-        $sform->display();
34
-        smart_close_collapsable('currencycreate');
35
-    }
13
+	global $smartobjectCurrencyHandler;
14
+
15
+	$currencyObj = $smartobjectCurrencyHandler->get($currencyid);
16
+
17
+	if (!$currencyObj->isNew()) {
18
+		if ($showmenu) {
19
+			//smart_adminMenu(5, _AM_SOBJECT_CURRENCIES . " > " . _AM_SOBJECT_EDITING);
20
+		}
21
+		smart_collapsableBar('currencyedit', _AM_SOBJECT_CURRENCIES_EDIT, _AM_SOBJECT_CURRENCIES_EDIT_INFO);
22
+
23
+		$sform = $currencyObj->getForm(_AM_SOBJECT_CURRENCIES_EDIT, 'addcurrency');
24
+		$sform->display();
25
+		smart_close_collapsable('currencyedit');
26
+	} else {
27
+		if ($showmenu) {
28
+			//smart_adminMenu(5, _AM_SOBJECT_CURRENCIES . " > " . _CO_SOBJECT_CREATINGNEW);
29
+		}
30
+
31
+		smart_collapsableBar('currencycreate', _AM_SOBJECT_CURRENCIES_CREATE, _AM_SOBJECT_CURRENCIES_CREATE_INFO);
32
+		$sform = $currencyObj->getForm(_AM_SOBJECT_CURRENCIES_CREATE, 'addcurrency');
33
+		$sform->display();
34
+		smart_close_collapsable('currencycreate');
35
+	}
36 36
 }
37 37
 
38 38
 include_once __DIR__ . '/admin_header.php';
@@ -43,37 +43,37 @@  discard block
 block discarded – undo
43 43
 $op = '';
44 44
 
45 45
 if (isset($_GET['op'])) {
46
-    $op = $_GET['op'];
46
+	$op = $_GET['op'];
47 47
 }
48 48
 if (isset($_POST['op'])) {
49
-    $op = $_POST['op'];
49
+	$op = $_POST['op'];
50 50
 }
51 51
 
52 52
 switch ($op) {
53
-    case 'mod':
54
-        $currencyid = isset($_GET['currencyid']) ? (int)$_GET['currencyid'] : 0;
53
+	case 'mod':
54
+		$currencyid = isset($_GET['currencyid']) ? (int)$_GET['currencyid'] : 0;
55 55
 
56
-        smart_xoops_cp_header();
56
+		smart_xoops_cp_header();
57 57
 
58
-        editclass(true, $currencyid);
59
-        break;
58
+		editclass(true, $currencyid);
59
+		break;
60 60
 
61
-    case 'updateCurrencies':
61
+	case 'updateCurrencies':
62 62
 
63
-        if (!isset($_POST['SmartobjectCurrency_objects']) || count($_POST['SmartobjectCurrency_objects']) == 0) {
64
-            redirect_header($smart_previous_page, 3, _AM_SOBJECT_NO_RECORDS_TO_UPDATE);
65
-            exit;
66
-        }
63
+		if (!isset($_POST['SmartobjectCurrency_objects']) || count($_POST['SmartobjectCurrency_objects']) == 0) {
64
+			redirect_header($smart_previous_page, 3, _AM_SOBJECT_NO_RECORDS_TO_UPDATE);
65
+			exit;
66
+		}
67 67
 
68
-        if (isset($_POST['default_currency'])) {
69
-            $newDefaultCurrency = $_POST['default_currency'];
70
-            $sql                  = 'UPDATE ' . $smartobjectCurrencyHandler->table . ' SET default_currency=0';
71
-            $smartobjectCurrencyHandler->query($sql);
72
-            $sql = 'UPDATE ' . $smartobjectCurrencyHandler->table . ' SET default_currency=1 WHERE currencyid=' . $newDefaultCurrency;
73
-            $smartobjectCurrencyHandler->query($sql);
74
-        }
68
+		if (isset($_POST['default_currency'])) {
69
+			$newDefaultCurrency = $_POST['default_currency'];
70
+			$sql                  = 'UPDATE ' . $smartobjectCurrencyHandler->table . ' SET default_currency=0';
71
+			$smartobjectCurrencyHandler->query($sql);
72
+			$sql = 'UPDATE ' . $smartobjectCurrencyHandler->table . ' SET default_currency=1 WHERE currencyid=' . $newDefaultCurrency;
73
+			$smartobjectCurrencyHandler->query($sql);
74
+		}
75 75
 
76
-        /*
76
+		/*
77 77
         $criteria = new CriteriaCompo();
78 78
         $criteria->add(new Criteria('currencyid', '(' . implode(', ', $_POST['SmartobjectCurrency_objects']) . ')', 'IN'));
79 79
         $currenciesObj = $smartobjectCurrencyHandler->getObjects($criteria, true);
@@ -83,51 +83,51 @@  discard block
 block discarded – undo
83 83
             $smartobjectCurrencyHandler->insert($currencyObj);
84 84
         }
85 85
         */
86
-        redirect_header($smart_previous_page, 3, _AM_SOBJECT_RECORDS_UPDATED);
87
-        exit;
86
+		redirect_header($smart_previous_page, 3, _AM_SOBJECT_RECORDS_UPDATED);
87
+		exit;
88 88
 
89
-        break;
89
+		break;
90 90
 
91
-    case 'addcurrency':
92
-        include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
93
-        $controller = new SmartObjectController($smartobjectCurrencyHandler);
94
-        $controller->storeFromDefaultForm(_AM_SOBJECT_CURRENCIES_CREATED, _AM_SOBJECT_CURRENCIES_MODIFIED, SMARTOBJECT_URL . 'admin/currency.php');
91
+	case 'addcurrency':
92
+		include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
93
+		$controller = new SmartObjectController($smartobjectCurrencyHandler);
94
+		$controller->storeFromDefaultForm(_AM_SOBJECT_CURRENCIES_CREATED, _AM_SOBJECT_CURRENCIES_MODIFIED, SMARTOBJECT_URL . 'admin/currency.php');
95 95
 
96
-        break;
96
+		break;
97 97
 
98
-    case 'del':
99
-        include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
100
-        $controller = new SmartObjectController($smartobjectCurrencyHandler);
101
-        $controller->handleObjectDeletion();
98
+	case 'del':
99
+		include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
100
+		$controller = new SmartObjectController($smartobjectCurrencyHandler);
101
+		$controller->handleObjectDeletion();
102 102
 
103
-        break;
103
+		break;
104 104
 
105
-    default:
105
+	default:
106 106
 
107
-        smart_xoops_cp_header();
107
+		smart_xoops_cp_header();
108 108
 
109
-        //smart_adminMenu(5, _AM_SOBJECT_CURRENCIES);
109
+		//smart_adminMenu(5, _AM_SOBJECT_CURRENCIES);
110 110
 
111
-        smart_collapsableBar('createdcurrencies', _AM_SOBJECT_CURRENCIES, _AM_SOBJECT_CURRENCIES_DSC);
111
+		smart_collapsableBar('createdcurrencies', _AM_SOBJECT_CURRENCIES, _AM_SOBJECT_CURRENCIES_DSC);
112 112
 
113
-        include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php';
114
-        $objectTable = new SmartObjectTable($smartobjectCurrencyHandler);
115
-        $objectTable->addColumn(new SmartObjectColumn('name', 'left', false, 'getCurrencyLink'));
116
-        $objectTable->addColumn(new SmartObjectColumn('rate', 'center', 150));
117
-        $objectTable->addColumn(new SmartObjectColumn('iso4217', 'center', 150));
118
-        $objectTable->addColumn(new SmartObjectColumn('default_currency', 'center', 150, 'getDefaultCurrencyControl'));
113
+		include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjecttable.php';
114
+		$objectTable = new SmartObjectTable($smartobjectCurrencyHandler);
115
+		$objectTable->addColumn(new SmartObjectColumn('name', 'left', false, 'getCurrencyLink'));
116
+		$objectTable->addColumn(new SmartObjectColumn('rate', 'center', 150));
117
+		$objectTable->addColumn(new SmartObjectColumn('iso4217', 'center', 150));
118
+		$objectTable->addColumn(new SmartObjectColumn('default_currency', 'center', 150, 'getDefaultCurrencyControl'));
119 119
 
120
-        $objectTable->addIntroButton('addcurrency', 'currency.php?op=mod', _AM_SOBJECT_CURRENCIES_CREATE);
120
+		$objectTable->addIntroButton('addcurrency', 'currency.php?op=mod', _AM_SOBJECT_CURRENCIES_CREATE);
121 121
 
122
-        $objectTable->addActionButton('updateCurrencies', _SUBMIT, _AM_SOBJECT_CURRENCY_UPDATE_ALL);
122
+		$objectTable->addActionButton('updateCurrencies', _SUBMIT, _AM_SOBJECT_CURRENCY_UPDATE_ALL);
123 123
 
124
-        $objectTable->render();
124
+		$objectTable->render();
125 125
 
126
-        echo '<br />';
127
-        smart_close_collapsable('createdcurrencies');
128
-        echo '<br>';
126
+		echo '<br />';
127
+		smart_close_collapsable('createdcurrencies');
128
+		echo '<br>';
129 129
 
130
-        break;
130
+		break;
131 131
 }
132 132
 
133 133
 //smart_modFooter();
Please login to merge, or discard this patch.
admin/update.php 1 patch
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -18,180 +18,180 @@  discard block
 block discarded – undo
18 18
 // =========================================================================================
19 19
 function update_tables_to_300()
20 20
 {
21
-    $dbupdater = new WfdownloadsDbupdater();
21
+	$dbupdater = new WfdownloadsDbupdater();
22 22
 
23
-    if (!wfdownloads_TableExists('wfdownloads_meta')) {
24
-        // Create table wfdownloads_meta
25
-        $table = new WfdownloadsTable('wfdownloads_meta');
26
-        $table->setStructure("CREATE TABLE %s (
23
+	if (!wfdownloads_TableExists('wfdownloads_meta')) {
24
+		// Create table wfdownloads_meta
25
+		$table = new WfdownloadsTable('wfdownloads_meta');
26
+		$table->setStructure("CREATE TABLE %s (
27 27
                                 metakey varchar(50) NOT NULL default '',
28 28
                                 metavalue varchar(255) NOT NULL default '',
29 29
                                 PRIMARY KEY (metakey))
30 30
                                 ENGINE=MyISAM;");
31 31
 
32
-        $table->setData(sprintf("'version', %s", round($GLOBALS['xoopsModule']->getVar('version') / 100, 2)));
33
-        if ($dbupdater->updateTable($table)) {
34
-            echo 'wfdownloads_meta table created<br />';
35
-        }
36
-    }
32
+		$table->setData(sprintf("'version', %s", round($GLOBALS['xoopsModule']->getVar('version') / 100, 2)));
33
+		if ($dbupdater->updateTable($table)) {
34
+			echo 'wfdownloads_meta table created<br />';
35
+		}
36
+	}
37 37
 
38
-    $download_fields = array(
39
-        'lid'           => array('Type' => 'int(11) unsigned NOT NULL auto_increment', 'Default' => false),
40
-        'cid'           => array('Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true),
41
-        'title'         => array('Type' => "varchar(100) NOT NULL default ''", 'Default' => true),
42
-        'url'           => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
43
-        'filename'      => array('Type' => "varchar(150) NOT NULL default ''", 'Default' => true),
44
-        'filetype'      => array('Type' => "varchar(100) NOT NULL default ''", 'Default' => true),
45
-        'homepage'      => array('Type' => "varchar(100) NOT NULL default ''", 'Default' => true),
46
-        'version'       => array('Type' => "varchar(20) NOT NULL default ''", 'Default' => true),
47
-        'size'          => array('Type' => "int(8) NOT NULL default '0'", 'Default' => true),
48
-        'platform'      => array('Type' => "varchar(50) NOT NULL default ''", 'Default' => true),
49
-        'screenshot'    => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
50
-        'submitter'     => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
51
-        'publisher'     => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
52
-        'status'        => array('Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true),
53
-        'date'          => array('Type' => "int(10) NOT NULL default '0'", 'Default' => true),
54
-        'hits'          => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
55
-        'rating'        => array('Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true),
56
-        'votes'         => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
57
-        'comments'      => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
58
-        'license'       => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
59
-        'mirror'        => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
60
-        'price'         => array('Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true),
61
-        'paypalemail'   => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
62
-        'features'      => array('Type' => 'text NOT NULL', 'Default' => false),
63
-        'requirements'  => array('Type' => 'text NOT NULL', 'Default' => false),
64
-        'homepagetitle' => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
65
-        'forumid'       => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
66
-        'limitations'   => array('Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true),
67
-        'dhistory'      => array('Type' => 'text NOT NULL', 'Default' => false),
68
-        'published'     => array('Type' => "int(11) NOT NULL default '1089662528'", 'Default' => true),
69
-        'expired'       => array('Type' => "int(10) NOT NULL default '0'", 'Default' => true),
70
-        'updated'       => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
71
-        'offline'       => array('Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true),
72
-        'description'   => array('Type' => 'text NOT NULL', 'Default' => false),
73
-        'ipaddress'     => array('Type' => "varchar(120) NOT NULL default '0'", 'Default' => true),
74
-        'notifypub'     => array('Type' => "int(1) NOT NULL default '0'", 'Default' => true),
75
-        'summary'       => array('Type' => 'text NOT NULL', 'Default' => false)
76
-    );
38
+	$download_fields = array(
39
+		'lid'           => array('Type' => 'int(11) unsigned NOT NULL auto_increment', 'Default' => false),
40
+		'cid'           => array('Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true),
41
+		'title'         => array('Type' => "varchar(100) NOT NULL default ''", 'Default' => true),
42
+		'url'           => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
43
+		'filename'      => array('Type' => "varchar(150) NOT NULL default ''", 'Default' => true),
44
+		'filetype'      => array('Type' => "varchar(100) NOT NULL default ''", 'Default' => true),
45
+		'homepage'      => array('Type' => "varchar(100) NOT NULL default ''", 'Default' => true),
46
+		'version'       => array('Type' => "varchar(20) NOT NULL default ''", 'Default' => true),
47
+		'size'          => array('Type' => "int(8) NOT NULL default '0'", 'Default' => true),
48
+		'platform'      => array('Type' => "varchar(50) NOT NULL default ''", 'Default' => true),
49
+		'screenshot'    => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
50
+		'submitter'     => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
51
+		'publisher'     => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
52
+		'status'        => array('Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true),
53
+		'date'          => array('Type' => "int(10) NOT NULL default '0'", 'Default' => true),
54
+		'hits'          => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
55
+		'rating'        => array('Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true),
56
+		'votes'         => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
57
+		'comments'      => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
58
+		'license'       => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
59
+		'mirror'        => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
60
+		'price'         => array('Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true),
61
+		'paypalemail'   => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
62
+		'features'      => array('Type' => 'text NOT NULL', 'Default' => false),
63
+		'requirements'  => array('Type' => 'text NOT NULL', 'Default' => false),
64
+		'homepagetitle' => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
65
+		'forumid'       => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
66
+		'limitations'   => array('Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true),
67
+		'dhistory'      => array('Type' => 'text NOT NULL', 'Default' => false),
68
+		'published'     => array('Type' => "int(11) NOT NULL default '1089662528'", 'Default' => true),
69
+		'expired'       => array('Type' => "int(10) NOT NULL default '0'", 'Default' => true),
70
+		'updated'       => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
71
+		'offline'       => array('Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true),
72
+		'description'   => array('Type' => 'text NOT NULL', 'Default' => false),
73
+		'ipaddress'     => array('Type' => "varchar(120) NOT NULL default '0'", 'Default' => true),
74
+		'notifypub'     => array('Type' => "int(1) NOT NULL default '0'", 'Default' => true),
75
+		'summary'       => array('Type' => 'text NOT NULL', 'Default' => false)
76
+	);
77 77
 
78
-    $renamed_fields = array(
79
-        'logourl' => 'screenshot'
80
-    );
78
+	$renamed_fields = array(
79
+		'logourl' => 'screenshot'
80
+	);
81 81
 
82
-    echo '<br /><B>Checking Download table</B><br />';
83
-    $downloadHandler = xoops_getModuleHandler('download', 'wfdownloads');
84
-    $download_table   = new WfdownloadsTable('wfdownloads_downloads');
85
-    $fields           = get_table_info($downloadHandler->table, $download_fields);
86
-    // Check for renamed fields
87
-    rename_fields($download_table, $renamed_fields, $fields, $download_fields);
88
-    update_table($download_fields, $fields, $download_table);
89
-    if ($dbupdater->updateTable($download_table)) {
90
-        echo 'Downloads table updated<br />';
91
-    }
92
-    unset($fields);
82
+	echo '<br /><B>Checking Download table</B><br />';
83
+	$downloadHandler = xoops_getModuleHandler('download', 'wfdownloads');
84
+	$download_table   = new WfdownloadsTable('wfdownloads_downloads');
85
+	$fields           = get_table_info($downloadHandler->table, $download_fields);
86
+	// Check for renamed fields
87
+	rename_fields($download_table, $renamed_fields, $fields, $download_fields);
88
+	update_table($download_fields, $fields, $download_table);
89
+	if ($dbupdater->updateTable($download_table)) {
90
+		echo 'Downloads table updated<br />';
91
+	}
92
+	unset($fields);
93 93
 
94
-    $mod_fields = array(
95
-        'requestid'       => array('Type' => 'int(11) NOT NULL auto_increment', 'Default' => false),
96
-        'lid'             => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
97
-        'cid'             => array('Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true),
98
-        'title'           => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
99
-        'url'             => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
100
-        'filename'        => array('Type' => "varchar(150) NOT NULL default ''", 'Default' => true),
101
-        'filetype'        => array('Type' => "varchar(100) NOT NULL default ''", 'Default' => true),
102
-        'homepage'        => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
103
-        'version'         => array('Type' => "varchar(20) NOT NULL default ''", 'Default' => true),
104
-        'size'            => array('Type' => "int(8) NOT NULL default '0'", 'Default' => true),
105
-        'platform'        => array('Type' => "varchar(50) NOT NULL default ''", 'Default' => true),
106
-        'screenshot'      => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
107
-        'submitter'       => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
108
-        'publisher'       => array('Type' => 'text NOT NULL', 'Default' => false),
109
-        'status'          => array('Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true),
110
-        'date'            => array('Type' => "int(10) NOT NULL default '0'", 'Default' => true),
111
-        'hits'            => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
112
-        'rating'          => array('Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true),
113
-        'votes'           => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
114
-        'comments'        => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
115
-        'license'         => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
116
-        'mirror'          => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
117
-        'price'           => array('Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true),
118
-        'paypalemail'     => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
119
-        'features'        => array('Type' => 'text NOT NULL', 'Default' => false),
120
-        'requirements'    => array('Type' => 'text NOT NULL', 'Default' => false),
121
-        'homepagetitle'   => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
122
-        'forumid'         => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
123
-        'limitations'     => array('Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true),
124
-        'dhistory'        => array('Type' => 'text NOT NULL', 'Default' => false),
125
-        'published'       => array('Type' => "int(10) NOT NULL default '0'", 'Default' => true),
126
-        'expired'         => array('Type' => "int(10) NOT NULL default '0'", 'Default' => true),
127
-        'updated'         => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
128
-        'offline'         => array('Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true),
129
-        'summary'         => array('Type' => 'text NOT NULL', 'Default' => false),
130
-        'description'     => array('Type' => 'text NOT NULL', 'Default' => false),
131
-        'modifysubmitter' => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
132
-        'requestdate'     => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true)
133
-    );
94
+	$mod_fields = array(
95
+		'requestid'       => array('Type' => 'int(11) NOT NULL auto_increment', 'Default' => false),
96
+		'lid'             => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
97
+		'cid'             => array('Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true),
98
+		'title'           => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
99
+		'url'             => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
100
+		'filename'        => array('Type' => "varchar(150) NOT NULL default ''", 'Default' => true),
101
+		'filetype'        => array('Type' => "varchar(100) NOT NULL default ''", 'Default' => true),
102
+		'homepage'        => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
103
+		'version'         => array('Type' => "varchar(20) NOT NULL default ''", 'Default' => true),
104
+		'size'            => array('Type' => "int(8) NOT NULL default '0'", 'Default' => true),
105
+		'platform'        => array('Type' => "varchar(50) NOT NULL default ''", 'Default' => true),
106
+		'screenshot'      => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
107
+		'submitter'       => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
108
+		'publisher'       => array('Type' => 'text NOT NULL', 'Default' => false),
109
+		'status'          => array('Type' => "tinyint(2) NOT NULL default '0'", 'Default' => true),
110
+		'date'            => array('Type' => "int(10) NOT NULL default '0'", 'Default' => true),
111
+		'hits'            => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
112
+		'rating'          => array('Type' => "double(6,4) NOT NULL default '0.0000'", 'Default' => true),
113
+		'votes'           => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
114
+		'comments'        => array('Type' => "int(11) unsigned NOT NULL default '0'", 'Default' => true),
115
+		'license'         => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
116
+		'mirror'          => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
117
+		'price'           => array('Type' => "varchar(10) NOT NULL default 'Free'", 'Default' => true),
118
+		'paypalemail'     => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
119
+		'features'        => array('Type' => 'text NOT NULL', 'Default' => false),
120
+		'requirements'    => array('Type' => 'text NOT NULL', 'Default' => false),
121
+		'homepagetitle'   => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
122
+		'forumid'         => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
123
+		'limitations'     => array('Type' => "varchar(255) NOT NULL default '30 day trial'", 'Default' => true),
124
+		'dhistory'        => array('Type' => 'text NOT NULL', 'Default' => false),
125
+		'published'       => array('Type' => "int(10) NOT NULL default '0'", 'Default' => true),
126
+		'expired'         => array('Type' => "int(10) NOT NULL default '0'", 'Default' => true),
127
+		'updated'         => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
128
+		'offline'         => array('Type' => "tinyint(1) NOT NULL default '0'", 'Default' => true),
129
+		'summary'         => array('Type' => 'text NOT NULL', 'Default' => false),
130
+		'description'     => array('Type' => 'text NOT NULL', 'Default' => false),
131
+		'modifysubmitter' => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
132
+		'requestdate'     => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true)
133
+	);
134 134
 
135
-    $renamed_fields = array(
136
-        'logourl' => 'screenshot'
137
-    );
135
+	$renamed_fields = array(
136
+		'logourl' => 'screenshot'
137
+	);
138 138
 
139
-    echo '<br /><B>Checking Modified Downloads table</B><br />';
140
-    $modHandler = xoops_getModuleHandler('modification', 'wfdownloads');
141
-    $mod_table   = new WfdownloadsTable('wfdownloads_mod');
142
-    $fields      = get_table_info($modHandler->table, $mod_fields);
143
-    rename_fields($mod_table, $renamed_fields, $fields, $mod_fields);
144
-    update_table($mod_fields, $fields, $mod_table);
145
-    if ($dbupdater->updateTable($mod_table)) {
146
-        echo 'Modified Downloads table updated <br />';
147
-    }
148
-    unset($fields);
139
+	echo '<br /><B>Checking Modified Downloads table</B><br />';
140
+	$modHandler = xoops_getModuleHandler('modification', 'wfdownloads');
141
+	$mod_table   = new WfdownloadsTable('wfdownloads_mod');
142
+	$fields      = get_table_info($modHandler->table, $mod_fields);
143
+	rename_fields($mod_table, $renamed_fields, $fields, $mod_fields);
144
+	update_table($mod_fields, $fields, $mod_table);
145
+	if ($dbupdater->updateTable($mod_table)) {
146
+		echo 'Modified Downloads table updated <br />';
147
+	}
148
+	unset($fields);
149 149
 
150
-    $cat_fields = array(
151
-        'cid'          => array('Type' => 'int(5) unsigned NOT NULL auto_increment', 'Default' => false),
152
-        'pid'          => array('Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true),
153
-        'title'        => array('Type' => "varchar(50) NOT NULL default ''", 'Default' => true),
154
-        'imgurl'       => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
155
-        'description'  => array('Type' => "text NOT NULL default ''", 'Default' => true),
156
-        'total'        => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
157
-        'summary'      => array('Type' => 'text NOT NULL', 'Default' => false),
158
-        'spotlighttop' => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
159
-        'spotlighthis' => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
160
-        'dohtml'       => array('Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true),
161
-        'dosmiley'     => array('Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true),
162
-        'doxcode'      => array('Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true),
163
-        'doimage'      => array('Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true),
164
-        'dobr'         => array('Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true),
165
-        'weight'       => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true)
166
-    );
167
-    echo '<br /><B>Checking Category table</B><br />';
168
-    $catHandler = xoops_getModuleHandler('category', 'wfdownloads');
169
-    $cat_table   = new WfdownloadsTable('wfdownloads_cat');
170
-    $fields      = get_table_info($catHandler->table, $cat_fields);
171
-    update_table($cat_fields, $fields, $cat_table);
172
-    if ($dbupdater->updateTable($cat_table)) {
173
-        echo 'Category table updated<br />';
174
-    }
175
-    unset($fields);
150
+	$cat_fields = array(
151
+		'cid'          => array('Type' => 'int(5) unsigned NOT NULL auto_increment', 'Default' => false),
152
+		'pid'          => array('Type' => "int(5) unsigned NOT NULL default '0'", 'Default' => true),
153
+		'title'        => array('Type' => "varchar(50) NOT NULL default ''", 'Default' => true),
154
+		'imgurl'       => array('Type' => "varchar(255) NOT NULL default ''", 'Default' => true),
155
+		'description'  => array('Type' => "text NOT NULL default ''", 'Default' => true),
156
+		'total'        => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
157
+		'summary'      => array('Type' => 'text NOT NULL', 'Default' => false),
158
+		'spotlighttop' => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
159
+		'spotlighthis' => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
160
+		'dohtml'       => array('Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true),
161
+		'dosmiley'     => array('Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true),
162
+		'doxcode'      => array('Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true),
163
+		'doimage'      => array('Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true),
164
+		'dobr'         => array('Type' => "tinyint(1) NOT NULL default '1'", 'Default' => true),
165
+		'weight'       => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true)
166
+	);
167
+	echo '<br /><B>Checking Category table</B><br />';
168
+	$catHandler = xoops_getModuleHandler('category', 'wfdownloads');
169
+	$cat_table   = new WfdownloadsTable('wfdownloads_cat');
170
+	$fields      = get_table_info($catHandler->table, $cat_fields);
171
+	update_table($cat_fields, $fields, $cat_table);
172
+	if ($dbupdater->updateTable($cat_table)) {
173
+		echo 'Category table updated<br />';
174
+	}
175
+	unset($fields);
176 176
 
177
-    $broken_fields = array(
178
-        'reportid'     => array('Type' => 'int(5) NOT NULL auto_increment', 'Default' => false),
179
-        'lid'          => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
180
-        'sender'       => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
181
-        'ip'           => array('Type' => "varchar(20) NOT NULL default ''", 'Default' => true),
182
-        'date'         => array('Type' => "varchar(11) NOT NULL default '0'", 'Default' => true),
183
-        'confirmed'    => array('Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true),
184
-        'acknowledged' => array('Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true)
185
-    );
186
-    echo '<br /><B>Checking Broken Report table</B><br />';
187
-    $brokenHandler = xoops_getModuleHandler('report', 'wfdownloads');
188
-    $broken_table   = new WfdownloadsTable('wfdownloads_broken');
189
-    $fields         = get_table_info($brokenHandler->table, $broken_fields);
190
-    update_table($broken_fields, $fields, $broken_table);
191
-    if ($dbupdater->updateTable($broken_table)) {
192
-        echo 'Broken Reports table updated<br />';
193
-    }
194
-    unset($fields);
177
+	$broken_fields = array(
178
+		'reportid'     => array('Type' => 'int(5) NOT NULL auto_increment', 'Default' => false),
179
+		'lid'          => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
180
+		'sender'       => array('Type' => "int(11) NOT NULL default '0'", 'Default' => true),
181
+		'ip'           => array('Type' => "varchar(20) NOT NULL default ''", 'Default' => true),
182
+		'date'         => array('Type' => "varchar(11) NOT NULL default '0'", 'Default' => true),
183
+		'confirmed'    => array('Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true),
184
+		'acknowledged' => array('Type' => "enum('0','1') NOT NULL default '0'", 'Default' => true)
185
+	);
186
+	echo '<br /><B>Checking Broken Report table</B><br />';
187
+	$brokenHandler = xoops_getModuleHandler('report', 'wfdownloads');
188
+	$broken_table   = new WfdownloadsTable('wfdownloads_broken');
189
+	$fields         = get_table_info($brokenHandler->table, $broken_fields);
190
+	update_table($broken_fields, $fields, $broken_table);
191
+	if ($dbupdater->updateTable($broken_table)) {
192
+		echo 'Broken Reports table updated<br />';
193
+	}
194
+	unset($fields);
195 195
 }
196 196
 
197 197
 // =========================================================================================
@@ -204,48 +204,48 @@  discard block
 block discarded – undo
204 204
  */
205 205
 function invert_nohtm_dohtml_values()
206 206
 {
207
-    $ret = array();
208
-    global $xoopsDB;
209
-    $catHandler = xoops_getModuleHandler('category', 'wfdownloads');
210
-    $result      = $xoopsDB->query('SHOW COLUMNS FROM ' . $catHandler->table);
211
-    while ($existing_field = $xoopsDB->fetchArray($result)) {
212
-        $fields[$existing_field['field']] = $existing_field['type'];
213
-    }
214
-    if (in_array('nohtml', array_keys($fields))) {
215
-        $dbupdater = new WfdownloadsDbupdater();
216
-        //Invert column values
217
-        // alter options in wfdownloads_cat
218
-        $table = new WfdownloadsTable('wfdownloads_cat');
219
-        $table->addAlteredField('nohtml', "dohtml tinyint(1) NOT NULL DEFAULT '1'");
220
-        $table->addAlteredField('nosmiley', "dosmiley tinyint(1) NOT NULL DEFAULT '1'");
221
-        $table->addAlteredField('noxcodes', "doxcode tinyint(1) NOT NULL DEFAULT '1'");
222
-        $table->addAlteredField('noimages', "doimage tinyint(1) NOT NULL DEFAULT '1'");
223
-        $table->addAlteredField('nobreak', "dobr tinyint(1) NOT NULL DEFAULT '1'");
207
+	$ret = array();
208
+	global $xoopsDB;
209
+	$catHandler = xoops_getModuleHandler('category', 'wfdownloads');
210
+	$result      = $xoopsDB->query('SHOW COLUMNS FROM ' . $catHandler->table);
211
+	while ($existing_field = $xoopsDB->fetchArray($result)) {
212
+		$fields[$existing_field['field']] = $existing_field['type'];
213
+	}
214
+	if (in_array('nohtml', array_keys($fields))) {
215
+		$dbupdater = new WfdownloadsDbupdater();
216
+		//Invert column values
217
+		// alter options in wfdownloads_cat
218
+		$table = new WfdownloadsTable('wfdownloads_cat');
219
+		$table->addAlteredField('nohtml', "dohtml tinyint(1) NOT NULL DEFAULT '1'");
220
+		$table->addAlteredField('nosmiley', "dosmiley tinyint(1) NOT NULL DEFAULT '1'");
221
+		$table->addAlteredField('noxcodes', "doxcode tinyint(1) NOT NULL DEFAULT '1'");
222
+		$table->addAlteredField('noimages', "doimage tinyint(1) NOT NULL DEFAULT '1'");
223
+		$table->addAlteredField('nobreak', "dobr tinyint(1) NOT NULL DEFAULT '1'");
224 224
 
225
-        //inverting values no=1 <=> do=0
226
-        // have to store teporarly as value = 2 to
227
-        // avoid putting everithing to same value
228
-        // if you change 1 to 0, then 0 to one,
229
-        // every value will be 1, follow me?
230
-        $table->addUpdatedWhere('dohtml', 2, '=1');
231
-        $table->addUpdatedWhere('dohtml', 1, '=0');
232
-        $table->addUpdatedWhere('dohtml', 0, '=2');
225
+		//inverting values no=1 <=> do=0
226
+		// have to store teporarly as value = 2 to
227
+		// avoid putting everithing to same value
228
+		// if you change 1 to 0, then 0 to one,
229
+		// every value will be 1, follow me?
230
+		$table->addUpdatedWhere('dohtml', 2, '=1');
231
+		$table->addUpdatedWhere('dohtml', 1, '=0');
232
+		$table->addUpdatedWhere('dohtml', 0, '=2');
233 233
 
234
-        $table->addUpdatedWhere('dosmiley', 2, '=1');
235
-        $table->addUpdatedWhere('dosmiley', 1, '=0');
236
-        $table->addUpdatedWhere('dosmiley', 0, '=2');
234
+		$table->addUpdatedWhere('dosmiley', 2, '=1');
235
+		$table->addUpdatedWhere('dosmiley', 1, '=0');
236
+		$table->addUpdatedWhere('dosmiley', 0, '=2');
237 237
 
238
-        $table->addUpdatedWhere('doxcode', 2, '=1');
239
-        $table->addUpdatedWhere('doxcode', 1, '=0');
240
-        $table->addUpdatedWhere('doxcode', 0, '=2');
238
+		$table->addUpdatedWhere('doxcode', 2, '=1');
239
+		$table->addUpdatedWhere('doxcode', 1, '=0');
240
+		$table->addUpdatedWhere('doxcode', 0, '=2');
241 241
 
242
-        $table->addUpdatedWhere('doimage', 2, '=1');
243
-        $table->addUpdatedWhere('doimage', 1, '=0');
244
-        $table->addUpdatedWhere('doimage', 0, '=2');
245
-        $ret = $dbupdater->updateTable($table);
246
-    }
242
+		$table->addUpdatedWhere('doimage', 2, '=1');
243
+		$table->addUpdatedWhere('doimage', 1, '=0');
244
+		$table->addUpdatedWhere('doimage', 0, '=2');
245
+		$ret = $dbupdater->updateTable($table);
246
+	}
247 247
 
248
-    return $ret;
248
+	return $ret;
249 249
 }
250 250
 
251 251
 /**
@@ -258,22 +258,22 @@  discard block
 block discarded – undo
258 258
  */
259 259
 function update_table($new_fields, $existing_fields, &$table)
260 260
 {
261
-    foreach ($new_fields as $field => $fieldinfo) {
262
-        $type = $fieldinfo['Type'];
263
-        if (!in_array($field, array_keys($existing_fields))) {
264
-            //Add field as it is missing
265
-            $table->addNewField($field, $type);
266
-            //$xoopsDB->query("ALTER TABLE ".$table." ADD ".$field." ".$type);
267
-            //echo $field."(".$type.") <FONT COLOR='##22DD51'>Added</FONT><br />";
268
-        } elseif ($existing_fields[$field] != $type) {
269
-            $table->addAlteredField($field, $field . ' ' . $type);
270
-            // check $fields[$field]['type'] for things like "int(10) unsigned"
271
-            //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$field." ".$type);
272
-            //echo $field." <FONT COLOR='#FF6600'>Changed to</FONT> ".$type."<br />";
273
-        } else {
274
-            //echo $field." <FONT COLOR='#0033FF'>Uptodate</FONT><br />";
275
-        }
276
-    }
261
+	foreach ($new_fields as $field => $fieldinfo) {
262
+		$type = $fieldinfo['Type'];
263
+		if (!in_array($field, array_keys($existing_fields))) {
264
+			//Add field as it is missing
265
+			$table->addNewField($field, $type);
266
+			//$xoopsDB->query("ALTER TABLE ".$table." ADD ".$field." ".$type);
267
+			//echo $field."(".$type.") <FONT COLOR='##22DD51'>Added</FONT><br />";
268
+		} elseif ($existing_fields[$field] != $type) {
269
+			$table->addAlteredField($field, $field . ' ' . $type);
270
+			// check $fields[$field]['type'] for things like "int(10) unsigned"
271
+			//$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$field." ".$type);
272
+			//echo $field." <FONT COLOR='#FF6600'>Changed to</FONT> ".$type."<br />";
273
+		} else {
274
+			//echo $field." <FONT COLOR='#0033FF'>Uptodate</FONT><br />";
275
+		}
276
+	}
277 277
 }
278 278
 
279 279
 /**
@@ -286,22 +286,22 @@  discard block
 block discarded – undo
286 286
  */
287 287
 function get_table_info($table, $default_fields)
288 288
 {
289
-    global $xoopsDB;
290
-    $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $table);
291
-    while ($existing_field = $xoopsDB->fetchArray($result)) {
292
-        $fields[$existing_field['Field']] = $existing_field['Type'];
293
-        if ($existing_field['Null'] !== 'YES') {
294
-            $fields[$existing_field['Field']] .= ' NOT NULL';
295
-        }
296
-        if ($existing_field['Extra']) {
297
-            $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
298
-        }
299
-        if ($default_fields[$existing_field['Field']]['Default']) {
300
-            $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
301
-        }
302
-    }
289
+	global $xoopsDB;
290
+	$result = $xoopsDB->query('SHOW COLUMNS FROM ' . $table);
291
+	while ($existing_field = $xoopsDB->fetchArray($result)) {
292
+		$fields[$existing_field['Field']] = $existing_field['Type'];
293
+		if ($existing_field['Null'] !== 'YES') {
294
+			$fields[$existing_field['Field']] .= ' NOT NULL';
295
+		}
296
+		if ($existing_field['Extra']) {
297
+			$fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
298
+		}
299
+		if ($default_fields[$existing_field['Field']]['Default']) {
300
+			$fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
301
+		}
302
+	}
303 303
 
304
-    return $fields;
304
+	return $fields;
305 305
 }
306 306
 
307 307
 /**
@@ -315,59 +315,59 @@  discard block
 block discarded – undo
315 315
  */
316 316
 function rename_fields(&$table, $renamed_fields, &$fields, $new_fields)
317 317
 {
318
-    foreach (array_keys($fields) as $field) {
319
-        if (in_array($field, array_keys($renamed_fields))) {
320
-            $new_field_name = $renamed_fields[$field];
321
-            $new_field_type = $new_fields[$new_field_name]['Type'];
322
-            $table->addAltered($field, $new_field_name . ' ' . $new_field_type);
323
-            //$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$new_field_name." ".$new_field_type);
324
-            //echo $field." Renamed to ".$new_field_name."<br />";
325
-            $fields[$new_field_name] = $new_field_type;
326
-        }
327
-    }
328
-    //return $fields;
318
+	foreach (array_keys($fields) as $field) {
319
+		if (in_array($field, array_keys($renamed_fields))) {
320
+			$new_field_name = $renamed_fields[$field];
321
+			$new_field_type = $new_fields[$new_field_name]['Type'];
322
+			$table->addAltered($field, $new_field_name . ' ' . $new_field_type);
323
+			//$xoopsDB->query("ALTER TABLE ".$table." CHANGE ".$field." ".$new_field_name." ".$new_field_type);
324
+			//echo $field." Renamed to ".$new_field_name."<br />";
325
+			$fields[$new_field_name] = $new_field_type;
326
+		}
327
+	}
328
+	//return $fields;
329 329
 }
330 330
 
331 331
 $op = isset($_REQUEST['op']) ? (int)$_REQUEST['op'] : 0;
332 332
 switch ($op) {
333
-    case 1:
334
-        // Make sure that nohtml is properly changed to dohtml
335
-        invert_nohtm_dohtml_values();
336
-        // Ensure that the proper tables are present
337
-        update_tables_to_300();
338
-        // Import data from MyDownloads
339
-        import_mydownloads_to_wfdownloads();
340
-        break;
333
+	case 1:
334
+		// Make sure that nohtml is properly changed to dohtml
335
+		invert_nohtm_dohtml_values();
336
+		// Ensure that the proper tables are present
337
+		update_tables_to_300();
338
+		// Import data from MyDownloads
339
+		import_mydownloads_to_wfdownloads();
340
+		break;
341 341
 
342
-    case 2:
343
-        // Update WF-Downloads
344
-        $log = invert_nohtm_dohtml_values();
345
-        update_tables_to_300();
346
-        break;
342
+	case 2:
343
+		// Update WF-Downloads
344
+		$log = invert_nohtm_dohtml_values();
345
+		update_tables_to_300();
346
+		break;
347 347
 
348
-    default:
349
-        //ask what to do
350
-        include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
351
-        $form = new XoopsThemeForm('Upgrade WF-Downloads', 'form', $_SERVER['REQUEST_URI']);
348
+	default:
349
+		//ask what to do
350
+		include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
351
+		$form = new XoopsThemeForm('Upgrade WF-Downloads', 'form', $_SERVER['REQUEST_URI']);
352 352
 
353
-        //Is MyDownloads installed?
354
-        $moduleHandler    = xoops_getHandler('module');
355
-        $mydownloadsModule = $moduleHandler->getByDirname('mydownloads');
356
-        if (is_object($mydownloadsModule)) {
357
-            $mydownloadsButton = new XoopsFormButton('Import data from MyDownloads', 'myd_button', 'Import', 'submit');
358
-            $mydownloadsButton->setExtra("onclick='document.forms.form.op.value=\"1\"'");
359
-            $form->addElement($mydownloadsButton);
360
-        }
353
+		//Is MyDownloads installed?
354
+		$moduleHandler    = xoops_getHandler('module');
355
+		$mydownloadsModule = $moduleHandler->getByDirname('mydownloads');
356
+		if (is_object($mydownloadsModule)) {
357
+			$mydownloadsButton = new XoopsFormButton('Import data from MyDownloads', 'myd_button', 'Import', 'submit');
358
+			$mydownloadsButton->setExtra("onclick='document.forms.form.op.value=\"1\"'");
359
+			$form->addElement($mydownloadsButton);
360
+		}
361 361
 
362
-        if (!wfdownloads_TableExists('wfdownloads_meta')) {
363
-            $updateButton = new XoopsFormButton('Update WF-Downloads', 'upd_button', 'Update', 'submit');
364
-            $updateButton->setExtra("onclick='document.forms.form.op.value=\"2\"'");
365
-            $form->addElement($updateButton);
366
-        }
362
+		if (!wfdownloads_TableExists('wfdownloads_meta')) {
363
+			$updateButton = new XoopsFormButton('Update WF-Downloads', 'upd_button', 'Update', 'submit');
364
+			$updateButton->setExtra("onclick='document.forms.form.op.value=\"2\"'");
365
+			$form->addElement($updateButton);
366
+		}
367 367
 
368
-        $form->addElement(new XoopsFormHidden('op', 0));
369
-        $form->display();
370
-        break;
368
+		$form->addElement(new XoopsFormHidden('op', 0));
369
+		$form->display();
370
+		break;
371 371
 }
372 372
 //wfdownloads_modFooter();
373 373
 //xoops_cp_footer();
Please login to merge, or discard this patch.
class/smartobjecthandler.php 1 patch
Indentation   +966 added lines, -966 removed lines patch added patch discarded remove patch
@@ -25,970 +25,970 @@
 block discarded – undo
25 25
  */
26 26
 class SmartPersistableObjectHandler extends XoopsObjectHandler
27 27
 {
28
-    public $_itemname;
29
-
30
-    /**
31
-     * Name of the table use to store this {@link SmartObject}
32
-     *
33
-     * Note that the name of the table needs to be free of the database prefix.
34
-     * For example "smartsection_categories"
35
-     * @var string
36
-     */
37
-    public $table;
38
-
39
-    /**
40
-     * Name of the table key that uniquely identify each {@link SmartObject}
41
-     *
42
-     * For example: "categoryid"
43
-     * @var string
44
-     */
45
-    public $keyName;
46
-
47
-    /**
48
-     * Name of the class derived from {@link SmartObject} and which this handler is handling
49
-     *
50
-     * Note that this string needs to be lowercase
51
-     *
52
-     * For example: "smartsectioncategory"
53
-     * @var string
54
-     */
55
-    public $className;
56
-
57
-    /**
58
-     * Name of the field which properly identify the {@link SmartObject}
59
-     *
60
-     * For example: "name" (this will be the category's name)
61
-     * @var string
62
-     */
63
-    public $identifierName;
64
-
65
-    /**
66
-     * Name of the field which will be use as a summary for the object
67
-     *
68
-     * For example: "summary"
69
-     * @var string
70
-     */
71
-    public $summaryName;
72
-
73
-    /**
74
-     * Page name use to basically manage and display the {@link SmartObject}
75
-     *
76
-     * This page needs to be the same in user side and admin side
77
-     *
78
-     * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php
79
-     * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page
80
-     * @var string
81
-     */
82
-    public $_page;
83
-
84
-    /**
85
-     * Full path of the module using this {@link SmartObject}
86
-     *
87
-     * <code>XOOPS_URL . "/modules/smartsection/"</code>
88
-     * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name
89
-     * @var string
90
-     */
91
-    public $_modulePath;
92
-
93
-    public $_moduleUrl;
94
-
95
-    public $_moduleName;
96
-
97
-    public $_uploadUrl;
98
-
99
-    public $_uploadPath;
100
-
101
-    public $_allowedMimeTypes = 0;
102
-
103
-    public $_maxFileSize = 1000000;
104
-
105
-    public $_maxWidth = 500;
106
-
107
-    public $_maxHeight = 500;
108
-
109
-    public $highlightFields = array();
110
-
111
-    /**
112
-     * Array containing the events name and functions
113
-     *
114
-     * @var array
115
-     */
116
-    public $eventArray = array();
117
-
118
-    /**
119
-     * Array containing the permissions that this handler will manage on the objects
120
-     *
121
-     * @var array
122
-     */
123
-    public $permissionsArray = false;
124
-
125
-    public $generalSQL = false;
126
-
127
-    public $_eventHooks     = array();
128
-    public $_disabledEvents = array();
129
-
130
-    /**
131
-     * Constructor - called from child classes
132
-     *
133
-     * @param object|XoopsDatabase $db           {@link XoopsDatabase}
134
-     *                                           object
135
-     * @param                      $itemname
136
-     * @param string               $keyname      Name of the table key that uniquely identify each {@link SmartObject}
137
-     * @param string               $idenfierName Name of the field which properly identify the {@link SmartObject}
138
-     * @param                      $summaryName
139
-     * @param                      $modulename
140
-     * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a>
141
-     * @internal param Name $string of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling
142
-     * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a>
143
-     * @internal param string $moduleName name of the module
144
-     */
145
-    public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename)
146
-    {
147
-        parent::__construct($db);
148
-
149
-        $this->_itemname      = $itemname;
150
-        $this->_moduleName    = $modulename;
151
-        $this->table          = $db->prefix($modulename . '_' . $itemname);
152
-        $this->keyName        = $keyname;
153
-        $this->className      = ucfirst($modulename) . ucfirst($itemname);
154
-        $this->identifierName = $idenfierName;
155
-        $this->summaryName    = $summaryName;
156
-        $this->_page          = $itemname . '.php';
157
-        $this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
158
-        $this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
159
-        $this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
160
-        $this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
161
-    }
162
-
163
-    /**
164
-     * @param $event
165
-     * @param $method
166
-     */
167
-    public function addEventHook($event, $method)
168
-    {
169
-        $this->_eventHooks[$event] = $method;
170
-    }
171
-
172
-    /**
173
-     * Add a permission that this handler will manage for its objects
174
-     *
175
-     * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC);
176
-     *
177
-     * @param string      $perm_name   name of the permission
178
-     * @param string      $caption     caption of the control that will be displayed in the form
179
-     * @param bool|string $description description of the control that will be displayed in the form
180
-     */
181
-    public function addPermission($perm_name, $caption, $description = false)
182
-    {
183
-        include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php');
184
-
185
-        $this->permissionsArray[] = array(
186
-            'perm_name'   => $perm_name,
187
-            'caption'     => $caption,
188
-            'description' => $description
189
-        );
190
-    }
191
-
192
-    /**
193
-     * @param $criteria
194
-     * @param $perm_name
195
-     * @return bool
196
-     */
197
-    public function setGrantedObjectsCriteria(&$criteria, $perm_name)
198
-    {
199
-        $smartPermissionsHandler = new SmartobjectPermissionHandler($this);
200
-        $grantedItems             = $smartPermissionsHandler->getGrantedItems($perm_name);
201
-        if (count($grantedItems) > 0) {
202
-            $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
203
-
204
-            return true;
205
-        } else {
206
-            return false;
207
-        }
208
-    }
209
-
210
-    /**
211
-     * @param bool $_uploadPath
212
-     * @param bool $_allowedMimeTypes
213
-     * @param bool $_maxFileSize
214
-     * @param bool $_maxWidth
215
-     * @param bool $_maxHeight
216
-     */
217
-    public function setUploaderConfig($_uploadPath = false, $_allowedMimeTypes = false, $_maxFileSize = false, $_maxWidth = false, $_maxHeight = false)
218
-    {
219
-        $this->_uploadPath       = $_uploadPath ?: $this->_uploadPath;
220
-        $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes;
221
-        $this->_maxFileSize      = $_maxFileSize ?: $this->_maxFileSize;
222
-        $this->_maxWidth         = $_maxWidth ?: $this->_maxWidth;
223
-        $this->_maxHeight        = $_maxHeight ?: $this->_maxHeight;
224
-    }
225
-
226
-    /**
227
-     * create a new {@link SmartObject}
228
-     *
229
-     * @param bool $isNew Flag the new objects as "new"?
230
-     *
231
-     * @return object {@link SmartObject}
232
-     */
233
-    public function &create($isNew = true)
234
-    {
235
-        $obj = new $this->className($this);
236
-        $obj->setImageDir($this->getImageUrl(), $this->getImagePath());
237
-        if (!$obj->handler) {
238
-            $obj->handler =& $this;
239
-        }
240
-
241
-        if ($isNew === true) {
242
-            $obj->setNew();
243
-        }
244
-
245
-        return $obj;
246
-    }
247
-
248
-    /**
249
-     * @return string
250
-     */
251
-    public function getImageUrl()
252
-    {
253
-        return $this->_uploadUrl . $this->_itemname . '/';
254
-    }
255
-
256
-    /**
257
-     * @return string
258
-     */
259
-    public function getImagePath()
260
-    {
261
-        $dir = $this->_uploadPath . $this->_itemname;
262
-        if (!file_exists($dir)) {
263
-            smart_admin_mkdir($dir);
264
-        }
265
-
266
-        return $dir . '/';
267
-    }
268
-
269
-    /**
270
-     * retrieve a {@link SmartObject}
271
-     *
272
-     * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
273
-     * @param  bool  $as_object whether to return an object or an array
274
-     * @param  bool  $debug
275
-     * @param  bool  $criteria
276
-     * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed
277
-     *                          FALSE if failed
278
-     */
279
-    public function get($id, $as_object = true, $debug = false, $criteria = false)
280
-    {
281
-        if (!$criteria) {
282
-            $criteria = new CriteriaCompo();
283
-        }
284
-        if (is_array($this->keyName)) {
285
-            for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
286
-                /**
287
-                 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
288
-                 * Is the fact that we removed the (int)() represents a security risk ?
289
-                 */
290
-                //$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname));
291
-                $criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname));
292
-            }
293
-        } else {
294
-            //$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname);
295
-            /**
296
-             * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
297
-             * Is the fact that we removed the (int)() represents a security risk ?
298
-             */
299
-            $criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname));
300
-        }
301
-        $criteria->setLimit(1);
302
-        if ($debug) {
303
-            $obj_array = $this->getObjectsD($criteria, false, $as_object);
304
-        } else {
305
-            $obj_array = $this->getObjects($criteria, false, $as_object);
306
-            //patch: weird bug of indexing by id even if id_as_key = false;
307
-            if (!isset($obj_array[0]) && is_object($obj_array[$id])) {
308
-                $obj_array[0] = $obj_array[$id];
309
-                unset($obj_array[$id]);
310
-                $obj_array[0]->unsetNew();
311
-            }
312
-        }
313
-
314
-        if (count($obj_array) != 1) {
315
-            $obj =& $this->create();
316
-
317
-            return $obj;
318
-        }
319
-
320
-        return $obj_array[0];
321
-    }
322
-
323
-    /**
324
-     * retrieve a {@link SmartObject}
325
-     *
326
-     * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
327
-     * @param  bool  $as_object whether to return an object or an array
328
-     * @return mixed reference to the {@link SmartObject}, FALSE if failed
329
-     */
330
-    public function &getD($id, $as_object = true)
331
-    {
332
-        return $this->get($id, $as_object, true);
333
-    }
334
-
335
-    /**
336
-     * retrieve objects from the database
337
-     *
338
-     * @param object $criteria  {@link CriteriaElement} conditions to be met
339
-     * @param bool   $id_as_key use the ID as key for the array?
340
-     * @param bool   $as_object return an array of objects?
341
-     *
342
-     * @param  bool  $sql
343
-     * @param  bool  $debug
344
-     * @return array
345
-     */
346
-    public function getObjects($criteria = null, $id_as_key = false, $as_object = true, $sql = false, $debug = false)
347
-    {
348
-        $ret   = array();
349
-        $limit = $start = 0;
350
-
351
-        if ($this->generalSQL) {
352
-            $sql = $this->generalSQL;
353
-        } elseif (!$sql) {
354
-            $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
355
-        }
356
-
357
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
358
-            $sql .= ' ' . $criteria->renderWhere();
359
-            if ($criteria->getSort() != '') {
360
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
361
-            }
362
-            $limit = $criteria->getLimit();
363
-            $start = $criteria->getStart();
364
-        }
365
-        if ($debug) {
366
-            xoops_debug($sql);
367
-        }
368
-
369
-        $result = $this->db->query($sql, $limit, $start);
370
-        if (!$result) {
371
-            return $ret;
372
-        }
373
-
374
-        return $this->convertResultSet($result, $id_as_key, $as_object);
375
-    }
376
-
377
-    /**
378
-     * @param       $sql
379
-     * @param       $criteria
380
-     * @param  bool $force
381
-     * @param  bool $debug
382
-     * @return array
383
-     */
384
-    public function query($sql, $criteria, $force = false, $debug = false)
385
-    {
386
-        $ret = array();
387
-
388
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
389
-            $sql .= ' ' . $criteria->renderWhere();
390
-            if ($criteria->groupby) {
391
-                $sql .= $criteria->getGroupby();
392
-            }
393
-            if ($criteria->getSort() != '') {
394
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
395
-            }
396
-        }
397
-        if ($debug) {
398
-            xoops_debug($sql);
399
-        }
400
-
401
-        if ($force) {
402
-            $result = $this->db->queryF($sql);
403
-        } else {
404
-            $result = $this->db->query($sql);
405
-        }
406
-
407
-        if (!$result) {
408
-            return $ret;
409
-        }
410
-
411
-        while ($myrow = $this->db->fetchArray($result)) {
412
-            $ret[] = $myrow;
413
-        }
414
-
415
-        return $ret;
416
-    }
417
-
418
-    /**
419
-     * retrieve objects with debug mode - so will show the query
420
-     *
421
-     * @param object $criteria  {@link CriteriaElement} conditions to be met
422
-     * @param bool   $id_as_key use the ID as key for the array?
423
-     * @param bool   $as_object return an array of objects?
424
-     *
425
-     * @param  bool  $sql
426
-     * @return array
427
-     */
428
-    public function getObjectsD($criteria = null, $id_as_key = false, $as_object = true, $sql = false)
429
-    {
430
-        return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true);
431
-    }
432
-
433
-    /**
434
-     * @param $arrayObjects
435
-     * @return array|bool
436
-     */
437
-    public function getObjectsAsArray($arrayObjects)
438
-    {
439
-        $ret = array();
440
-        foreach ($arrayObjects as $key => $object) {
441
-            $ret[$key] = $object->toArray();
442
-        }
443
-        if (count($ret > 0)) {
444
-            return $ret;
445
-        } else {
446
-            return false;
447
-        }
448
-    }
449
-
450
-    /**
451
-     * Convert a database resultset to a returnable array
452
-     *
453
-     * @param object $result    database resultset
454
-     * @param bool   $id_as_key - should NOT be used with joint keys
455
-     * @param bool   $as_object
456
-     *
457
-     * @return array
458
-     */
459
-    public function convertResultSet($result, $id_as_key = false, $as_object = true)
460
-    {
461
-        $ret = array();
462
-        while ($myrow = $this->db->fetchArray($result)) {
463
-            $obj =& $this->create(false);
464
-            $obj->assignVars($myrow);
465
-            if (!$id_as_key) {
466
-                if ($as_object) {
467
-                    $ret[] =& $obj;
468
-                } else {
469
-                    $ret[] = $obj->toArray();
470
-                }
471
-            } else {
472
-                if ($as_object) {
473
-                    $value =& $obj;
474
-                } else {
475
-                    $value = $obj->toArray();
476
-                }
477
-                if ($id_as_key === 'parentid') {
478
-                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
479
-                } else {
480
-                    $ret[$obj->getVar($this->keyName)] = $value;
481
-                }
482
-            }
483
-            unset($obj);
484
-        }
485
-
486
-        return $ret;
487
-    }
488
-
489
-    /**
490
-     * @param  null $criteria
491
-     * @param  int  $limit
492
-     * @param  int  $start
493
-     * @return array
494
-     */
495
-    public function getListD($criteria = null, $limit = 0, $start = 0)
496
-    {
497
-        return $this->getList($criteria, $limit, $start, true);
498
-    }
499
-
500
-    /**
501
-     * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
502
-     *
503
-     * @param object $criteria {@link CriteriaElement} conditions to be met
504
-     * @param int    $limit    Max number of objects to fetch
505
-     * @param int    $start    Which record to start at
506
-     *
507
-     * @param  bool  $debug
508
-     * @return array
509
-     */
510
-    public function getList($criteria = null, $limit = 0, $start = 0, $debug = false)
511
-    {
512
-        $ret = array();
513
-        if ($criteria == null) {
514
-            $criteria = new CriteriaCompo();
515
-        }
516
-
517
-        if ($criteria->getSort() == '') {
518
-            $criteria->setSort($this->getIdentifierName());
519
-        }
520
-
521
-        $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
522
-        if (!empty($this->identifierName)) {
523
-            $sql .= ', ' . $this->getIdentifierName();
524
-        }
525
-        $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
526
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
527
-            $sql .= ' ' . $criteria->renderWhere();
528
-            if ($criteria->getSort() != '') {
529
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
530
-            }
531
-            $limit = $criteria->getLimit();
532
-            $start = $criteria->getStart();
533
-        }
534
-
535
-        if ($debug) {
536
-            xoops_debug($sql);
537
-        }
538
-
539
-        $result = $this->db->query($sql, $limit, $start);
540
-        if (!$result) {
541
-            return $ret;
542
-        }
543
-
544
-        $myts = MyTextSanitizer::getInstance();
545
-        while ($myrow = $this->db->fetchArray($result)) {
546
-            //identifiers should be textboxes, so sanitize them like that
547
-            $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]);
548
-        }
549
-
550
-        return $ret;
551
-    }
552
-
553
-    /**
554
-     * count objects matching a condition
555
-     *
556
-     * @param  object $criteria {@link CriteriaElement} to match
557
-     * @return int    count of objects
558
-     */
559
-    public function getCount($criteria = null)
560
-    {
561
-        $field   = '';
562
-        $groupby = false;
563
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
564
-            if ($criteria->groupby != '') {
565
-                $groupby = true;
566
-                $field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
567
-            }
568
-        }
569
-        /**
570
-         * if we have a generalSQL, lets used this one.
571
-         * This needs to be improved...
572
-         */
573
-        if ($this->generalSQL) {
574
-            $sql = $this->generalSQL;
575
-            $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
576
-        } else {
577
-            $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
578
-        }
579
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
580
-            $sql .= ' ' . $criteria->renderWhere();
581
-            if ($criteria->groupby != '') {
582
-                $sql .= $criteria->getGroupby();
583
-            }
584
-        }
585
-
586
-        $result = $this->db->query($sql);
587
-        if (!$result) {
588
-            return 0;
589
-        }
590
-        if ($groupby == false) {
591
-            list($count) = $this->db->fetchRow($result);
592
-
593
-            return $count;
594
-        } else {
595
-            $ret = array();
596
-            while (list($id, $count) = $this->db->fetchRow($result)) {
597
-                $ret[$id] = $count;
598
-            }
599
-
600
-            return $ret;
601
-        }
602
-    }
603
-
604
-    /**
605
-     * delete an object from the database
606
-     *
607
-     * @param  XoopsObject $obj reference to the object to delete
608
-     * @param  bool        $force
609
-     * @return bool        FALSE if failed.
610
-     */
611
-    public function delete(XoopsObject $obj, $force = false)
612
-    {
613
-        $eventResult = $this->executeEvent('beforeDelete', $obj);
614
-        if (!$eventResult) {
615
-            $obj->setErrors('An error occured during the BeforeDelete event');
616
-
617
-            return false;
618
-        }
619
-
620
-        if (is_array($this->keyName)) {
621
-            $clause = array();
622
-            for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
623
-                $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
624
-            }
625
-            $whereclause = implode(' AND ', $clause);
626
-        } else {
627
-            $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
628
-        }
629
-        $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
630
-        if (false != $force) {
631
-            $result = $this->db->queryF($sql);
632
-        } else {
633
-            $result = $this->db->query($sql);
634
-        }
635
-        if (!$result) {
636
-            return false;
637
-        }
638
-
639
-        $eventResult = $this->executeEvent('afterDelete', $obj);
640
-        if (!$eventResult) {
641
-            $obj->setErrors('An error occured during the AfterDelete event');
642
-
643
-            return false;
644
-        }
645
-
646
-        return true;
647
-    }
648
-
649
-    /**
650
-     * @param $event
651
-     */
652
-    public function disableEvent($event)
653
-    {
654
-        if (is_array($event)) {
655
-            foreach ($event as $v) {
656
-                $this->_disabledEvents[] = $v;
657
-            }
658
-        } else {
659
-            $this->_disabledEvents[] = $event;
660
-        }
661
-    }
662
-
663
-    /**
664
-     * @return array
665
-     */
666
-    public function getPermissions()
667
-    {
668
-        return $this->permissionsArray;
669
-    }
670
-
671
-    /**
672
-     * insert a new object in the database
673
-     *
674
-     * @param  XoopsObject $obj         reference to the object
675
-     * @param  bool        $force       whether to force the query execution despite security settings
676
-     * @param  bool        $checkObject check if the object is dirty and clean the attributes
677
-     * @param  bool        $debug
678
-     * @return bool        FALSE if failed, TRUE if already present and unchanged or successful
679
-     */
680
-    public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false)
681
-    {
682
-        if ($checkObject != false) {
683
-            if (!is_object($obj)) {
684
-                return false;
685
-            }
686
-            /**
687
-             * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
688
-             */
689
-            if (!is_a($obj, $this->className)) {
690
-                $obj->setError(get_class($obj) . ' Differs from ' . $this->className);
691
-
692
-                return false;
693
-            }
694
-            if (!$obj->isDirty()) {
695
-                $obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith
696
-
697
-                return true;
698
-            }
699
-        }
700
-
701
-        if ($obj->seoEnabled) {
702
-            // Auto create meta tags if empty
703
-            $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary());
704
-
705
-            if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) {
706
-                if (!$obj->meta_keywords()) {
707
-                    $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords);
708
-                }
709
-
710
-                if (!$obj->meta_description()) {
711
-                    $obj->setVar('meta_description', $smartobjectMetagen->_meta_description);
712
-                }
713
-            }
714
-
715
-            // Auto create short_url if empty
716
-            if (!$obj->short_url()) {
717
-                $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false));
718
-            }
719
-        }
720
-
721
-        $eventResult = $this->executeEvent('beforeSave', $obj);
722
-        if (!$eventResult) {
723
-            $obj->setErrors('An error occured during the BeforeSave event');
724
-
725
-            return false;
726
-        }
727
-
728
-        if ($obj->isNew()) {
729
-            $eventResult = $this->executeEvent('beforeInsert', $obj);
730
-            if (!$eventResult) {
731
-                $obj->setErrors('An error occured during the BeforeInsert event');
732
-
733
-                return false;
734
-            }
735
-        } else {
736
-            $eventResult = $this->executeEvent('beforeUpdate', $obj);
737
-            if (!$eventResult) {
738
-                $obj->setErrors('An error occured during the BeforeUpdate event');
739
-
740
-                return false;
741
-            }
742
-        }
743
-        if (!$obj->cleanVars()) {
744
-            $obj->setErrors('Variables were not cleaned properly.');
745
-
746
-            return false;
747
-        }
748
-        $fieldsToStoreInDB = array();
749
-        foreach ($obj->cleanVars as $k => $v) {
750
-            if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
751
-                $cleanvars[$k] = (int)$v;
752
-            } elseif (is_array($v)) {
753
-                $cleanvars[$k] = $this->db->quoteString(implode(',', $v));
754
-            } else {
755
-                $cleanvars[$k] = $this->db->quoteString($v);
756
-            }
757
-            if ($obj->vars[$k]['persistent']) {
758
-                $fieldsToStoreInDB[$k] = $cleanvars[$k];
759
-            }
760
-        }
761
-        if ($obj->isNew()) {
762
-            if (!is_array($this->keyName)) {
763
-                if ($cleanvars[$this->keyName] < 1) {
764
-                    $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
765
-                }
766
-            }
767
-
768
-            $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
769
-        } else {
770
-            $sql = 'UPDATE ' . $this->table . ' SET';
771
-            foreach ($fieldsToStoreInDB as $key => $value) {
772
-                if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) {
773
-                    continue;
774
-                }
775
-                if (isset($notfirst)) {
776
-                    $sql .= ',';
777
-                }
778
-                $sql .= ' ' . $key . ' = ' . $value;
779
-                $notfirst = true;
780
-            }
781
-            if (is_array($this->keyName)) {
782
-                $whereclause = '';
783
-                for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
784
-                    if ($i > 0) {
785
-                        $whereclause .= ' AND ';
786
-                    }
787
-                    $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
788
-                }
789
-            } else {
790
-                $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
791
-            }
792
-            $sql .= ' WHERE ' . $whereclause;
793
-        }
794
-
795
-        if ($debug) {
796
-            xoops_debug($sql);
797
-        }
798
-
799
-        if (false != $force) {
800
-            $result = $this->db->queryF($sql);
801
-        } else {
802
-            $result = $this->db->query($sql);
803
-        }
804
-
805
-        if (!$result) {
806
-            $obj->setErrors($this->db->error());
807
-
808
-            return false;
809
-        }
810
-
811
-        if ($obj->isNew() && !is_array($this->keyName)) {
812
-            $obj->assignVar($this->keyName, $this->db->getInsertId());
813
-        }
814
-        $eventResult = $this->executeEvent('afterSave', $obj);
815
-        if (!$eventResult) {
816
-            $obj->setErrors('An error occured during the AfterSave event');
817
-
818
-            return false;
819
-        }
820
-
821
-        if ($obj->isNew()) {
822
-            $obj->unsetNew();
823
-            $eventResult = $this->executeEvent('afterInsert', $obj);
824
-            if (!$eventResult) {
825
-                $obj->setErrors('An error occured during the AfterInsert event');
826
-
827
-                return false;
828
-            }
829
-        } else {
830
-            $eventResult = $this->executeEvent('afterUpdate', $obj);
831
-            if (!$eventResult) {
832
-                $obj->setErrors('An error occured during the AfterUpdate event');
833
-
834
-                return false;
835
-            }
836
-        }
837
-
838
-        return true;
839
-    }
840
-
841
-    /**
842
-     * @param       $obj
843
-     * @param  bool $force
844
-     * @param  bool $checkObject
845
-     * @param  bool $debug
846
-     * @return bool
847
-     */
848
-    public function insertD(&$obj, $force = false, $checkObject = true, $debug = false)
849
-    {
850
-        return $this->insert($obj, $force, $checkObject, true);
851
-    }
852
-
853
-    /**
854
-     * Change a value for objects with a certain criteria
855
-     *
856
-     * @param string $fieldname  Name of the field
857
-     * @param string $fieldvalue Value to write
858
-     * @param object $criteria   {@link CriteriaElement}
859
-     *
860
-     * @param  bool  $force
861
-     * @return bool
862
-     */
863
-    public function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false)
864
-    {
865
-        $set_clause = $fieldname . ' = ';
866
-        if (is_numeric($fieldvalue)) {
867
-            $set_clause .= $fieldvalue;
868
-        } elseif (is_array($fieldvalue)) {
869
-            $set_clause .= $this->db->quoteString(implode(',', $fieldvalue));
870
-        } else {
871
-            $set_clause .= $this->db->quoteString($fieldvalue);
872
-        }
873
-        $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
874
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
875
-            $sql .= ' ' . $criteria->renderWhere();
876
-        }
877
-        if (false != $force) {
878
-            $result = $this->db->queryF($sql);
879
-        } else {
880
-            $result = $this->db->query($sql);
881
-        }
882
-        if (!$result) {
883
-            return false;
884
-        }
885
-
886
-        return true;
887
-    }
888
-
889
-    /**
890
-     * delete all objects meeting the conditions
891
-     *
892
-     * @param  object $criteria {@link CriteriaElement} with conditions to meet
893
-     * @return bool
894
-     */
895
-
896
-    public function deleteAll($criteria = null)
897
-    {
898
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
899
-            $sql = 'DELETE FROM ' . $this->table;
900
-            $sql .= ' ' . $criteria->renderWhere();
901
-            if (!$this->db->query($sql)) {
902
-                return false;
903
-            }
904
-            $rows = $this->db->getAffectedRows();
905
-
906
-            return $rows > 0 ? $rows : true;
907
-        }
908
-
909
-        return false;
910
-    }
911
-
912
-    /**
913
-     * @return mixed
914
-     */
915
-    public function getModuleInfo()
916
-    {
917
-        return smart_getModuleInfo($this->_moduleName);
918
-    }
919
-
920
-    /**
921
-     * @return bool
922
-     */
923
-    public function getModuleConfig()
924
-    {
925
-        return smart_getModuleConfig($this->_moduleName);
926
-    }
927
-
928
-    /**
929
-     * @return string
930
-     */
931
-    public function getModuleItemString()
932
-    {
933
-        $ret = $this->_moduleName . '_' . $this->_itemname;
934
-
935
-        return $ret;
936
-    }
937
-
938
-    /**
939
-     * @param $object
940
-     */
941
-    public function updateCounter($object)
942
-    {
943
-        if (isset($object->vars['counter'])) {
944
-            $new_counter = $object->getVar('counter') + 1;
945
-            $sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
946
-            $this->query($sql, null, true);
947
-        }
948
-    }
949
-
950
-    /**
951
-     * Execute the function associated with an event
952
-     * This method will check if the function is available
953
-     *
954
-     * @param string $event name of the event
955
-     * @param        $executeEventObj
956
-     * @return mixed result of the execution of the function or FALSE if the function was not executed
957
-     * @internal param object $obj $object on which is performed the event
958
-     */
959
-    public function executeEvent($event, &$executeEventObj)
960
-    {
961
-        if (!in_array($event, $this->_disabledEvents)) {
962
-            if (method_exists($this, $event)) {
963
-                $ret = $this->$event($executeEventObj);
964
-            } else {
965
-                // check to see if there is a hook for this event
966
-                if (isset($this->_eventHooks[$event])) {
967
-                    $method = $this->_eventHooks[$event];
968
-                    // check to see if the method specified by this hook exists
969
-                    if (method_exists($this, $method)) {
970
-                        $ret = $this->$method($executeEventObj);
971
-                    }
972
-                }
973
-                $ret = true;
974
-            }
975
-
976
-            return $ret;
977
-        }
978
-
979
-        return true;
980
-    }
981
-
982
-    /**
983
-     * @param  bool $withprefix
984
-     * @return string
985
-     */
986
-    public function getIdentifierName($withprefix = true)
987
-    {
988
-        if ($withprefix) {
989
-            return $this->_itemname . '.' . $this->identifierName;
990
-        } else {
991
-            return $this->identifierName;
992
-        }
993
-    }
28
+	public $_itemname;
29
+
30
+	/**
31
+	 * Name of the table use to store this {@link SmartObject}
32
+	 *
33
+	 * Note that the name of the table needs to be free of the database prefix.
34
+	 * For example "smartsection_categories"
35
+	 * @var string
36
+	 */
37
+	public $table;
38
+
39
+	/**
40
+	 * Name of the table key that uniquely identify each {@link SmartObject}
41
+	 *
42
+	 * For example: "categoryid"
43
+	 * @var string
44
+	 */
45
+	public $keyName;
46
+
47
+	/**
48
+	 * Name of the class derived from {@link SmartObject} and which this handler is handling
49
+	 *
50
+	 * Note that this string needs to be lowercase
51
+	 *
52
+	 * For example: "smartsectioncategory"
53
+	 * @var string
54
+	 */
55
+	public $className;
56
+
57
+	/**
58
+	 * Name of the field which properly identify the {@link SmartObject}
59
+	 *
60
+	 * For example: "name" (this will be the category's name)
61
+	 * @var string
62
+	 */
63
+	public $identifierName;
64
+
65
+	/**
66
+	 * Name of the field which will be use as a summary for the object
67
+	 *
68
+	 * For example: "summary"
69
+	 * @var string
70
+	 */
71
+	public $summaryName;
72
+
73
+	/**
74
+	 * Page name use to basically manage and display the {@link SmartObject}
75
+	 *
76
+	 * This page needs to be the same in user side and admin side
77
+	 *
78
+	 * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php
79
+	 * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page
80
+	 * @var string
81
+	 */
82
+	public $_page;
83
+
84
+	/**
85
+	 * Full path of the module using this {@link SmartObject}
86
+	 *
87
+	 * <code>XOOPS_URL . "/modules/smartsection/"</code>
88
+	 * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name
89
+	 * @var string
90
+	 */
91
+	public $_modulePath;
92
+
93
+	public $_moduleUrl;
94
+
95
+	public $_moduleName;
96
+
97
+	public $_uploadUrl;
98
+
99
+	public $_uploadPath;
100
+
101
+	public $_allowedMimeTypes = 0;
102
+
103
+	public $_maxFileSize = 1000000;
104
+
105
+	public $_maxWidth = 500;
106
+
107
+	public $_maxHeight = 500;
108
+
109
+	public $highlightFields = array();
110
+
111
+	/**
112
+	 * Array containing the events name and functions
113
+	 *
114
+	 * @var array
115
+	 */
116
+	public $eventArray = array();
117
+
118
+	/**
119
+	 * Array containing the permissions that this handler will manage on the objects
120
+	 *
121
+	 * @var array
122
+	 */
123
+	public $permissionsArray = false;
124
+
125
+	public $generalSQL = false;
126
+
127
+	public $_eventHooks     = array();
128
+	public $_disabledEvents = array();
129
+
130
+	/**
131
+	 * Constructor - called from child classes
132
+	 *
133
+	 * @param object|XoopsDatabase $db           {@link XoopsDatabase}
134
+	 *                                           object
135
+	 * @param                      $itemname
136
+	 * @param string               $keyname      Name of the table key that uniquely identify each {@link SmartObject}
137
+	 * @param string               $idenfierName Name of the field which properly identify the {@link SmartObject}
138
+	 * @param                      $summaryName
139
+	 * @param                      $modulename
140
+	 * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a>
141
+	 * @internal param Name $string of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling
142
+	 * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a>
143
+	 * @internal param string $moduleName name of the module
144
+	 */
145
+	public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename)
146
+	{
147
+		parent::__construct($db);
148
+
149
+		$this->_itemname      = $itemname;
150
+		$this->_moduleName    = $modulename;
151
+		$this->table          = $db->prefix($modulename . '_' . $itemname);
152
+		$this->keyName        = $keyname;
153
+		$this->className      = ucfirst($modulename) . ucfirst($itemname);
154
+		$this->identifierName = $idenfierName;
155
+		$this->summaryName    = $summaryName;
156
+		$this->_page          = $itemname . '.php';
157
+		$this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
158
+		$this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
159
+		$this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
160
+		$this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
161
+	}
162
+
163
+	/**
164
+	 * @param $event
165
+	 * @param $method
166
+	 */
167
+	public function addEventHook($event, $method)
168
+	{
169
+		$this->_eventHooks[$event] = $method;
170
+	}
171
+
172
+	/**
173
+	 * Add a permission that this handler will manage for its objects
174
+	 *
175
+	 * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC);
176
+	 *
177
+	 * @param string      $perm_name   name of the permission
178
+	 * @param string      $caption     caption of the control that will be displayed in the form
179
+	 * @param bool|string $description description of the control that will be displayed in the form
180
+	 */
181
+	public function addPermission($perm_name, $caption, $description = false)
182
+	{
183
+		include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php');
184
+
185
+		$this->permissionsArray[] = array(
186
+			'perm_name'   => $perm_name,
187
+			'caption'     => $caption,
188
+			'description' => $description
189
+		);
190
+	}
191
+
192
+	/**
193
+	 * @param $criteria
194
+	 * @param $perm_name
195
+	 * @return bool
196
+	 */
197
+	public function setGrantedObjectsCriteria(&$criteria, $perm_name)
198
+	{
199
+		$smartPermissionsHandler = new SmartobjectPermissionHandler($this);
200
+		$grantedItems             = $smartPermissionsHandler->getGrantedItems($perm_name);
201
+		if (count($grantedItems) > 0) {
202
+			$criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
203
+
204
+			return true;
205
+		} else {
206
+			return false;
207
+		}
208
+	}
209
+
210
+	/**
211
+	 * @param bool $_uploadPath
212
+	 * @param bool $_allowedMimeTypes
213
+	 * @param bool $_maxFileSize
214
+	 * @param bool $_maxWidth
215
+	 * @param bool $_maxHeight
216
+	 */
217
+	public function setUploaderConfig($_uploadPath = false, $_allowedMimeTypes = false, $_maxFileSize = false, $_maxWidth = false, $_maxHeight = false)
218
+	{
219
+		$this->_uploadPath       = $_uploadPath ?: $this->_uploadPath;
220
+		$this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes;
221
+		$this->_maxFileSize      = $_maxFileSize ?: $this->_maxFileSize;
222
+		$this->_maxWidth         = $_maxWidth ?: $this->_maxWidth;
223
+		$this->_maxHeight        = $_maxHeight ?: $this->_maxHeight;
224
+	}
225
+
226
+	/**
227
+	 * create a new {@link SmartObject}
228
+	 *
229
+	 * @param bool $isNew Flag the new objects as "new"?
230
+	 *
231
+	 * @return object {@link SmartObject}
232
+	 */
233
+	public function &create($isNew = true)
234
+	{
235
+		$obj = new $this->className($this);
236
+		$obj->setImageDir($this->getImageUrl(), $this->getImagePath());
237
+		if (!$obj->handler) {
238
+			$obj->handler =& $this;
239
+		}
240
+
241
+		if ($isNew === true) {
242
+			$obj->setNew();
243
+		}
244
+
245
+		return $obj;
246
+	}
247
+
248
+	/**
249
+	 * @return string
250
+	 */
251
+	public function getImageUrl()
252
+	{
253
+		return $this->_uploadUrl . $this->_itemname . '/';
254
+	}
255
+
256
+	/**
257
+	 * @return string
258
+	 */
259
+	public function getImagePath()
260
+	{
261
+		$dir = $this->_uploadPath . $this->_itemname;
262
+		if (!file_exists($dir)) {
263
+			smart_admin_mkdir($dir);
264
+		}
265
+
266
+		return $dir . '/';
267
+	}
268
+
269
+	/**
270
+	 * retrieve a {@link SmartObject}
271
+	 *
272
+	 * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
273
+	 * @param  bool  $as_object whether to return an object or an array
274
+	 * @param  bool  $debug
275
+	 * @param  bool  $criteria
276
+	 * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed
277
+	 *                          FALSE if failed
278
+	 */
279
+	public function get($id, $as_object = true, $debug = false, $criteria = false)
280
+	{
281
+		if (!$criteria) {
282
+			$criteria = new CriteriaCompo();
283
+		}
284
+		if (is_array($this->keyName)) {
285
+			for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
286
+				/**
287
+				 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
288
+				 * Is the fact that we removed the (int)() represents a security risk ?
289
+				 */
290
+				//$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname));
291
+				$criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname));
292
+			}
293
+		} else {
294
+			//$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname);
295
+			/**
296
+			 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
297
+			 * Is the fact that we removed the (int)() represents a security risk ?
298
+			 */
299
+			$criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname));
300
+		}
301
+		$criteria->setLimit(1);
302
+		if ($debug) {
303
+			$obj_array = $this->getObjectsD($criteria, false, $as_object);
304
+		} else {
305
+			$obj_array = $this->getObjects($criteria, false, $as_object);
306
+			//patch: weird bug of indexing by id even if id_as_key = false;
307
+			if (!isset($obj_array[0]) && is_object($obj_array[$id])) {
308
+				$obj_array[0] = $obj_array[$id];
309
+				unset($obj_array[$id]);
310
+				$obj_array[0]->unsetNew();
311
+			}
312
+		}
313
+
314
+		if (count($obj_array) != 1) {
315
+			$obj =& $this->create();
316
+
317
+			return $obj;
318
+		}
319
+
320
+		return $obj_array[0];
321
+	}
322
+
323
+	/**
324
+	 * retrieve a {@link SmartObject}
325
+	 *
326
+	 * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
327
+	 * @param  bool  $as_object whether to return an object or an array
328
+	 * @return mixed reference to the {@link SmartObject}, FALSE if failed
329
+	 */
330
+	public function &getD($id, $as_object = true)
331
+	{
332
+		return $this->get($id, $as_object, true);
333
+	}
334
+
335
+	/**
336
+	 * retrieve objects from the database
337
+	 *
338
+	 * @param object $criteria  {@link CriteriaElement} conditions to be met
339
+	 * @param bool   $id_as_key use the ID as key for the array?
340
+	 * @param bool   $as_object return an array of objects?
341
+	 *
342
+	 * @param  bool  $sql
343
+	 * @param  bool  $debug
344
+	 * @return array
345
+	 */
346
+	public function getObjects($criteria = null, $id_as_key = false, $as_object = true, $sql = false, $debug = false)
347
+	{
348
+		$ret   = array();
349
+		$limit = $start = 0;
350
+
351
+		if ($this->generalSQL) {
352
+			$sql = $this->generalSQL;
353
+		} elseif (!$sql) {
354
+			$sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
355
+		}
356
+
357
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
358
+			$sql .= ' ' . $criteria->renderWhere();
359
+			if ($criteria->getSort() != '') {
360
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
361
+			}
362
+			$limit = $criteria->getLimit();
363
+			$start = $criteria->getStart();
364
+		}
365
+		if ($debug) {
366
+			xoops_debug($sql);
367
+		}
368
+
369
+		$result = $this->db->query($sql, $limit, $start);
370
+		if (!$result) {
371
+			return $ret;
372
+		}
373
+
374
+		return $this->convertResultSet($result, $id_as_key, $as_object);
375
+	}
376
+
377
+	/**
378
+	 * @param       $sql
379
+	 * @param       $criteria
380
+	 * @param  bool $force
381
+	 * @param  bool $debug
382
+	 * @return array
383
+	 */
384
+	public function query($sql, $criteria, $force = false, $debug = false)
385
+	{
386
+		$ret = array();
387
+
388
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
389
+			$sql .= ' ' . $criteria->renderWhere();
390
+			if ($criteria->groupby) {
391
+				$sql .= $criteria->getGroupby();
392
+			}
393
+			if ($criteria->getSort() != '') {
394
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
395
+			}
396
+		}
397
+		if ($debug) {
398
+			xoops_debug($sql);
399
+		}
400
+
401
+		if ($force) {
402
+			$result = $this->db->queryF($sql);
403
+		} else {
404
+			$result = $this->db->query($sql);
405
+		}
406
+
407
+		if (!$result) {
408
+			return $ret;
409
+		}
410
+
411
+		while ($myrow = $this->db->fetchArray($result)) {
412
+			$ret[] = $myrow;
413
+		}
414
+
415
+		return $ret;
416
+	}
417
+
418
+	/**
419
+	 * retrieve objects with debug mode - so will show the query
420
+	 *
421
+	 * @param object $criteria  {@link CriteriaElement} conditions to be met
422
+	 * @param bool   $id_as_key use the ID as key for the array?
423
+	 * @param bool   $as_object return an array of objects?
424
+	 *
425
+	 * @param  bool  $sql
426
+	 * @return array
427
+	 */
428
+	public function getObjectsD($criteria = null, $id_as_key = false, $as_object = true, $sql = false)
429
+	{
430
+		return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true);
431
+	}
432
+
433
+	/**
434
+	 * @param $arrayObjects
435
+	 * @return array|bool
436
+	 */
437
+	public function getObjectsAsArray($arrayObjects)
438
+	{
439
+		$ret = array();
440
+		foreach ($arrayObjects as $key => $object) {
441
+			$ret[$key] = $object->toArray();
442
+		}
443
+		if (count($ret > 0)) {
444
+			return $ret;
445
+		} else {
446
+			return false;
447
+		}
448
+	}
449
+
450
+	/**
451
+	 * Convert a database resultset to a returnable array
452
+	 *
453
+	 * @param object $result    database resultset
454
+	 * @param bool   $id_as_key - should NOT be used with joint keys
455
+	 * @param bool   $as_object
456
+	 *
457
+	 * @return array
458
+	 */
459
+	public function convertResultSet($result, $id_as_key = false, $as_object = true)
460
+	{
461
+		$ret = array();
462
+		while ($myrow = $this->db->fetchArray($result)) {
463
+			$obj =& $this->create(false);
464
+			$obj->assignVars($myrow);
465
+			if (!$id_as_key) {
466
+				if ($as_object) {
467
+					$ret[] =& $obj;
468
+				} else {
469
+					$ret[] = $obj->toArray();
470
+				}
471
+			} else {
472
+				if ($as_object) {
473
+					$value =& $obj;
474
+				} else {
475
+					$value = $obj->toArray();
476
+				}
477
+				if ($id_as_key === 'parentid') {
478
+					$ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
479
+				} else {
480
+					$ret[$obj->getVar($this->keyName)] = $value;
481
+				}
482
+			}
483
+			unset($obj);
484
+		}
485
+
486
+		return $ret;
487
+	}
488
+
489
+	/**
490
+	 * @param  null $criteria
491
+	 * @param  int  $limit
492
+	 * @param  int  $start
493
+	 * @return array
494
+	 */
495
+	public function getListD($criteria = null, $limit = 0, $start = 0)
496
+	{
497
+		return $this->getList($criteria, $limit, $start, true);
498
+	}
499
+
500
+	/**
501
+	 * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
502
+	 *
503
+	 * @param object $criteria {@link CriteriaElement} conditions to be met
504
+	 * @param int    $limit    Max number of objects to fetch
505
+	 * @param int    $start    Which record to start at
506
+	 *
507
+	 * @param  bool  $debug
508
+	 * @return array
509
+	 */
510
+	public function getList($criteria = null, $limit = 0, $start = 0, $debug = false)
511
+	{
512
+		$ret = array();
513
+		if ($criteria == null) {
514
+			$criteria = new CriteriaCompo();
515
+		}
516
+
517
+		if ($criteria->getSort() == '') {
518
+			$criteria->setSort($this->getIdentifierName());
519
+		}
520
+
521
+		$sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
522
+		if (!empty($this->identifierName)) {
523
+			$sql .= ', ' . $this->getIdentifierName();
524
+		}
525
+		$sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
526
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
527
+			$sql .= ' ' . $criteria->renderWhere();
528
+			if ($criteria->getSort() != '') {
529
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
530
+			}
531
+			$limit = $criteria->getLimit();
532
+			$start = $criteria->getStart();
533
+		}
534
+
535
+		if ($debug) {
536
+			xoops_debug($sql);
537
+		}
538
+
539
+		$result = $this->db->query($sql, $limit, $start);
540
+		if (!$result) {
541
+			return $ret;
542
+		}
543
+
544
+		$myts = MyTextSanitizer::getInstance();
545
+		while ($myrow = $this->db->fetchArray($result)) {
546
+			//identifiers should be textboxes, so sanitize them like that
547
+			$ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]);
548
+		}
549
+
550
+		return $ret;
551
+	}
552
+
553
+	/**
554
+	 * count objects matching a condition
555
+	 *
556
+	 * @param  object $criteria {@link CriteriaElement} to match
557
+	 * @return int    count of objects
558
+	 */
559
+	public function getCount($criteria = null)
560
+	{
561
+		$field   = '';
562
+		$groupby = false;
563
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
564
+			if ($criteria->groupby != '') {
565
+				$groupby = true;
566
+				$field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
567
+			}
568
+		}
569
+		/**
570
+		 * if we have a generalSQL, lets used this one.
571
+		 * This needs to be improved...
572
+		 */
573
+		if ($this->generalSQL) {
574
+			$sql = $this->generalSQL;
575
+			$sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
576
+		} else {
577
+			$sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
578
+		}
579
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
580
+			$sql .= ' ' . $criteria->renderWhere();
581
+			if ($criteria->groupby != '') {
582
+				$sql .= $criteria->getGroupby();
583
+			}
584
+		}
585
+
586
+		$result = $this->db->query($sql);
587
+		if (!$result) {
588
+			return 0;
589
+		}
590
+		if ($groupby == false) {
591
+			list($count) = $this->db->fetchRow($result);
592
+
593
+			return $count;
594
+		} else {
595
+			$ret = array();
596
+			while (list($id, $count) = $this->db->fetchRow($result)) {
597
+				$ret[$id] = $count;
598
+			}
599
+
600
+			return $ret;
601
+		}
602
+	}
603
+
604
+	/**
605
+	 * delete an object from the database
606
+	 *
607
+	 * @param  XoopsObject $obj reference to the object to delete
608
+	 * @param  bool        $force
609
+	 * @return bool        FALSE if failed.
610
+	 */
611
+	public function delete(XoopsObject $obj, $force = false)
612
+	{
613
+		$eventResult = $this->executeEvent('beforeDelete', $obj);
614
+		if (!$eventResult) {
615
+			$obj->setErrors('An error occured during the BeforeDelete event');
616
+
617
+			return false;
618
+		}
619
+
620
+		if (is_array($this->keyName)) {
621
+			$clause = array();
622
+			for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
623
+				$clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
624
+			}
625
+			$whereclause = implode(' AND ', $clause);
626
+		} else {
627
+			$whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
628
+		}
629
+		$sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
630
+		if (false != $force) {
631
+			$result = $this->db->queryF($sql);
632
+		} else {
633
+			$result = $this->db->query($sql);
634
+		}
635
+		if (!$result) {
636
+			return false;
637
+		}
638
+
639
+		$eventResult = $this->executeEvent('afterDelete', $obj);
640
+		if (!$eventResult) {
641
+			$obj->setErrors('An error occured during the AfterDelete event');
642
+
643
+			return false;
644
+		}
645
+
646
+		return true;
647
+	}
648
+
649
+	/**
650
+	 * @param $event
651
+	 */
652
+	public function disableEvent($event)
653
+	{
654
+		if (is_array($event)) {
655
+			foreach ($event as $v) {
656
+				$this->_disabledEvents[] = $v;
657
+			}
658
+		} else {
659
+			$this->_disabledEvents[] = $event;
660
+		}
661
+	}
662
+
663
+	/**
664
+	 * @return array
665
+	 */
666
+	public function getPermissions()
667
+	{
668
+		return $this->permissionsArray;
669
+	}
670
+
671
+	/**
672
+	 * insert a new object in the database
673
+	 *
674
+	 * @param  XoopsObject $obj         reference to the object
675
+	 * @param  bool        $force       whether to force the query execution despite security settings
676
+	 * @param  bool        $checkObject check if the object is dirty and clean the attributes
677
+	 * @param  bool        $debug
678
+	 * @return bool        FALSE if failed, TRUE if already present and unchanged or successful
679
+	 */
680
+	public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false)
681
+	{
682
+		if ($checkObject != false) {
683
+			if (!is_object($obj)) {
684
+				return false;
685
+			}
686
+			/**
687
+			 * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
688
+			 */
689
+			if (!is_a($obj, $this->className)) {
690
+				$obj->setError(get_class($obj) . ' Differs from ' . $this->className);
691
+
692
+				return false;
693
+			}
694
+			if (!$obj->isDirty()) {
695
+				$obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith
696
+
697
+				return true;
698
+			}
699
+		}
700
+
701
+		if ($obj->seoEnabled) {
702
+			// Auto create meta tags if empty
703
+			$smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary());
704
+
705
+			if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) {
706
+				if (!$obj->meta_keywords()) {
707
+					$obj->setVar('meta_keywords', $smartobjectMetagen->_keywords);
708
+				}
709
+
710
+				if (!$obj->meta_description()) {
711
+					$obj->setVar('meta_description', $smartobjectMetagen->_meta_description);
712
+				}
713
+			}
714
+
715
+			// Auto create short_url if empty
716
+			if (!$obj->short_url()) {
717
+				$obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false));
718
+			}
719
+		}
720
+
721
+		$eventResult = $this->executeEvent('beforeSave', $obj);
722
+		if (!$eventResult) {
723
+			$obj->setErrors('An error occured during the BeforeSave event');
724
+
725
+			return false;
726
+		}
727
+
728
+		if ($obj->isNew()) {
729
+			$eventResult = $this->executeEvent('beforeInsert', $obj);
730
+			if (!$eventResult) {
731
+				$obj->setErrors('An error occured during the BeforeInsert event');
732
+
733
+				return false;
734
+			}
735
+		} else {
736
+			$eventResult = $this->executeEvent('beforeUpdate', $obj);
737
+			if (!$eventResult) {
738
+				$obj->setErrors('An error occured during the BeforeUpdate event');
739
+
740
+				return false;
741
+			}
742
+		}
743
+		if (!$obj->cleanVars()) {
744
+			$obj->setErrors('Variables were not cleaned properly.');
745
+
746
+			return false;
747
+		}
748
+		$fieldsToStoreInDB = array();
749
+		foreach ($obj->cleanVars as $k => $v) {
750
+			if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
751
+				$cleanvars[$k] = (int)$v;
752
+			} elseif (is_array($v)) {
753
+				$cleanvars[$k] = $this->db->quoteString(implode(',', $v));
754
+			} else {
755
+				$cleanvars[$k] = $this->db->quoteString($v);
756
+			}
757
+			if ($obj->vars[$k]['persistent']) {
758
+				$fieldsToStoreInDB[$k] = $cleanvars[$k];
759
+			}
760
+		}
761
+		if ($obj->isNew()) {
762
+			if (!is_array($this->keyName)) {
763
+				if ($cleanvars[$this->keyName] < 1) {
764
+					$cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
765
+				}
766
+			}
767
+
768
+			$sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
769
+		} else {
770
+			$sql = 'UPDATE ' . $this->table . ' SET';
771
+			foreach ($fieldsToStoreInDB as $key => $value) {
772
+				if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) {
773
+					continue;
774
+				}
775
+				if (isset($notfirst)) {
776
+					$sql .= ',';
777
+				}
778
+				$sql .= ' ' . $key . ' = ' . $value;
779
+				$notfirst = true;
780
+			}
781
+			if (is_array($this->keyName)) {
782
+				$whereclause = '';
783
+				for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
784
+					if ($i > 0) {
785
+						$whereclause .= ' AND ';
786
+					}
787
+					$whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
788
+				}
789
+			} else {
790
+				$whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
791
+			}
792
+			$sql .= ' WHERE ' . $whereclause;
793
+		}
794
+
795
+		if ($debug) {
796
+			xoops_debug($sql);
797
+		}
798
+
799
+		if (false != $force) {
800
+			$result = $this->db->queryF($sql);
801
+		} else {
802
+			$result = $this->db->query($sql);
803
+		}
804
+
805
+		if (!$result) {
806
+			$obj->setErrors($this->db->error());
807
+
808
+			return false;
809
+		}
810
+
811
+		if ($obj->isNew() && !is_array($this->keyName)) {
812
+			$obj->assignVar($this->keyName, $this->db->getInsertId());
813
+		}
814
+		$eventResult = $this->executeEvent('afterSave', $obj);
815
+		if (!$eventResult) {
816
+			$obj->setErrors('An error occured during the AfterSave event');
817
+
818
+			return false;
819
+		}
820
+
821
+		if ($obj->isNew()) {
822
+			$obj->unsetNew();
823
+			$eventResult = $this->executeEvent('afterInsert', $obj);
824
+			if (!$eventResult) {
825
+				$obj->setErrors('An error occured during the AfterInsert event');
826
+
827
+				return false;
828
+			}
829
+		} else {
830
+			$eventResult = $this->executeEvent('afterUpdate', $obj);
831
+			if (!$eventResult) {
832
+				$obj->setErrors('An error occured during the AfterUpdate event');
833
+
834
+				return false;
835
+			}
836
+		}
837
+
838
+		return true;
839
+	}
840
+
841
+	/**
842
+	 * @param       $obj
843
+	 * @param  bool $force
844
+	 * @param  bool $checkObject
845
+	 * @param  bool $debug
846
+	 * @return bool
847
+	 */
848
+	public function insertD(&$obj, $force = false, $checkObject = true, $debug = false)
849
+	{
850
+		return $this->insert($obj, $force, $checkObject, true);
851
+	}
852
+
853
+	/**
854
+	 * Change a value for objects with a certain criteria
855
+	 *
856
+	 * @param string $fieldname  Name of the field
857
+	 * @param string $fieldvalue Value to write
858
+	 * @param object $criteria   {@link CriteriaElement}
859
+	 *
860
+	 * @param  bool  $force
861
+	 * @return bool
862
+	 */
863
+	public function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false)
864
+	{
865
+		$set_clause = $fieldname . ' = ';
866
+		if (is_numeric($fieldvalue)) {
867
+			$set_clause .= $fieldvalue;
868
+		} elseif (is_array($fieldvalue)) {
869
+			$set_clause .= $this->db->quoteString(implode(',', $fieldvalue));
870
+		} else {
871
+			$set_clause .= $this->db->quoteString($fieldvalue);
872
+		}
873
+		$sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
874
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
875
+			$sql .= ' ' . $criteria->renderWhere();
876
+		}
877
+		if (false != $force) {
878
+			$result = $this->db->queryF($sql);
879
+		} else {
880
+			$result = $this->db->query($sql);
881
+		}
882
+		if (!$result) {
883
+			return false;
884
+		}
885
+
886
+		return true;
887
+	}
888
+
889
+	/**
890
+	 * delete all objects meeting the conditions
891
+	 *
892
+	 * @param  object $criteria {@link CriteriaElement} with conditions to meet
893
+	 * @return bool
894
+	 */
895
+
896
+	public function deleteAll($criteria = null)
897
+	{
898
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
899
+			$sql = 'DELETE FROM ' . $this->table;
900
+			$sql .= ' ' . $criteria->renderWhere();
901
+			if (!$this->db->query($sql)) {
902
+				return false;
903
+			}
904
+			$rows = $this->db->getAffectedRows();
905
+
906
+			return $rows > 0 ? $rows : true;
907
+		}
908
+
909
+		return false;
910
+	}
911
+
912
+	/**
913
+	 * @return mixed
914
+	 */
915
+	public function getModuleInfo()
916
+	{
917
+		return smart_getModuleInfo($this->_moduleName);
918
+	}
919
+
920
+	/**
921
+	 * @return bool
922
+	 */
923
+	public function getModuleConfig()
924
+	{
925
+		return smart_getModuleConfig($this->_moduleName);
926
+	}
927
+
928
+	/**
929
+	 * @return string
930
+	 */
931
+	public function getModuleItemString()
932
+	{
933
+		$ret = $this->_moduleName . '_' . $this->_itemname;
934
+
935
+		return $ret;
936
+	}
937
+
938
+	/**
939
+	 * @param $object
940
+	 */
941
+	public function updateCounter($object)
942
+	{
943
+		if (isset($object->vars['counter'])) {
944
+			$new_counter = $object->getVar('counter') + 1;
945
+			$sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
946
+			$this->query($sql, null, true);
947
+		}
948
+	}
949
+
950
+	/**
951
+	 * Execute the function associated with an event
952
+	 * This method will check if the function is available
953
+	 *
954
+	 * @param string $event name of the event
955
+	 * @param        $executeEventObj
956
+	 * @return mixed result of the execution of the function or FALSE if the function was not executed
957
+	 * @internal param object $obj $object on which is performed the event
958
+	 */
959
+	public function executeEvent($event, &$executeEventObj)
960
+	{
961
+		if (!in_array($event, $this->_disabledEvents)) {
962
+			if (method_exists($this, $event)) {
963
+				$ret = $this->$event($executeEventObj);
964
+			} else {
965
+				// check to see if there is a hook for this event
966
+				if (isset($this->_eventHooks[$event])) {
967
+					$method = $this->_eventHooks[$event];
968
+					// check to see if the method specified by this hook exists
969
+					if (method_exists($this, $method)) {
970
+						$ret = $this->$method($executeEventObj);
971
+					}
972
+				}
973
+				$ret = true;
974
+			}
975
+
976
+			return $ret;
977
+		}
978
+
979
+		return true;
980
+	}
981
+
982
+	/**
983
+	 * @param  bool $withprefix
984
+	 * @return string
985
+	 */
986
+	public function getIdentifierName($withprefix = true)
987
+	{
988
+		if ($withprefix) {
989
+			return $this->_itemname . '.' . $this->identifierName;
990
+		} else {
991
+			return $this->identifierName;
992
+		}
993
+	}
994 994
 }
Please login to merge, or discard this patch.
class/rating.php 1 patch
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -37,125 +37,125 @@  discard block
 block discarded – undo
37 37
  */
38 38
 class SmartobjectRating extends SmartObject
39 39
 {
40
-    public $_modulePlugin = false;
41
-
42
-    /**
43
-     * SmartobjectRating constructor.
44
-     */
45
-    public function __construct()
46
-    {
47
-        $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true);
48
-        $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME);
49
-        $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM);
50
-        $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID);
51
-        $this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID);
52
-        $this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE);
53
-        $this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE);
54
-
55
-        $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME);
56
-
57
-        $this->setControl('dirname', array(
58
-            'handler'  => 'rating',
59
-            'method'   => 'getModuleList',
60
-            'onSelect' => 'submit'
61
-        ));
62
-
63
-        $this->setControl('item', array(
64
-            'object' => &$this,
65
-            'method' => 'getItemList'
66
-        ));
67
-
68
-        $this->setControl('uid', 'user');
69
-
70
-        $this->setControl('rate', array(
71
-            'handler' => 'rating',
72
-            'method'  => 'getRateList'
73
-        ));
74
-    }
75
-
76
-    /**
77
-     * @param  string $key
78
-     * @param  string $format
79
-     * @return mixed
80
-     */
81
-    public function getVar($key, $format = 's')
82
-    {
83
-        if ($format === 's' && in_array($key, array('name', 'dirname'))) {
84
-            //            return call_user_func(array($this, $key));
85
-            return $this->{$key}();
86
-        }
87
-
88
-        return parent::getVar($key, $format);
89
-    }
90
-
91
-    /**
92
-     * @return string
93
-     */
94
-    public function name()
95
-    {
96
-        $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, array());
97
-
98
-        return $ret;
99
-    }
100
-
101
-    /**
102
-     * @return mixed
103
-     */
104
-    public function dirname()
105
-    {
106
-        global $smartobjectRatingHandler;
107
-        $moduleArray = $smartobjectRatingHandler->getModuleList();
108
-
109
-        return $moduleArray[$this->getVar('dirname', 'n')];
110
-    }
111
-
112
-    /**
113
-     * @return mixed
114
-     */
115
-    public function getItemList()
116
-    {
117
-        $plugin = $this->getModulePlugin();
118
-
119
-        return $plugin->getItemList();
120
-    }
121
-
122
-    /**
123
-     * @return string
124
-     */
125
-    public function getItemValue()
126
-    {
127
-        $moduleUrl      = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/';
128
-        $plugin         = $this->getModulePlugin();
129
-        $pluginItemInfo = $plugin->getItemInfo($this->getVar('item'));
130
-        if (!$pluginItemInfo) {
131
-            return '';
132
-        }
133
-        $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid'));
134
-        $ret      = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>';
135
-
136
-        return $ret;
137
-    }
138
-
139
-    /**
140
-     * @return mixed
141
-     */
142
-    public function getRateValue()
143
-    {
144
-        return $this->getVar('rate');
145
-    }
146
-
147
-    /**
148
-     * @return bool
149
-     */
150
-    public function getModulePlugin()
151
-    {
152
-        if (!$this->_modulePlugin) {
153
-            global $smartobjectRatingHandler;
154
-            $this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n'));
155
-        }
156
-
157
-        return $this->_modulePlugin;
158
-    }
40
+	public $_modulePlugin = false;
41
+
42
+	/**
43
+	 * SmartobjectRating constructor.
44
+	 */
45
+	public function __construct()
46
+	{
47
+		$this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true);
48
+		$this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME);
49
+		$this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM);
50
+		$this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID);
51
+		$this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID);
52
+		$this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE);
53
+		$this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE);
54
+
55
+		$this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME);
56
+
57
+		$this->setControl('dirname', array(
58
+			'handler'  => 'rating',
59
+			'method'   => 'getModuleList',
60
+			'onSelect' => 'submit'
61
+		));
62
+
63
+		$this->setControl('item', array(
64
+			'object' => &$this,
65
+			'method' => 'getItemList'
66
+		));
67
+
68
+		$this->setControl('uid', 'user');
69
+
70
+		$this->setControl('rate', array(
71
+			'handler' => 'rating',
72
+			'method'  => 'getRateList'
73
+		));
74
+	}
75
+
76
+	/**
77
+	 * @param  string $key
78
+	 * @param  string $format
79
+	 * @return mixed
80
+	 */
81
+	public function getVar($key, $format = 's')
82
+	{
83
+		if ($format === 's' && in_array($key, array('name', 'dirname'))) {
84
+			//            return call_user_func(array($this, $key));
85
+			return $this->{$key}();
86
+		}
87
+
88
+		return parent::getVar($key, $format);
89
+	}
90
+
91
+	/**
92
+	 * @return string
93
+	 */
94
+	public function name()
95
+	{
96
+		$ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, array());
97
+
98
+		return $ret;
99
+	}
100
+
101
+	/**
102
+	 * @return mixed
103
+	 */
104
+	public function dirname()
105
+	{
106
+		global $smartobjectRatingHandler;
107
+		$moduleArray = $smartobjectRatingHandler->getModuleList();
108
+
109
+		return $moduleArray[$this->getVar('dirname', 'n')];
110
+	}
111
+
112
+	/**
113
+	 * @return mixed
114
+	 */
115
+	public function getItemList()
116
+	{
117
+		$plugin = $this->getModulePlugin();
118
+
119
+		return $plugin->getItemList();
120
+	}
121
+
122
+	/**
123
+	 * @return string
124
+	 */
125
+	public function getItemValue()
126
+	{
127
+		$moduleUrl      = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/';
128
+		$plugin         = $this->getModulePlugin();
129
+		$pluginItemInfo = $plugin->getItemInfo($this->getVar('item'));
130
+		if (!$pluginItemInfo) {
131
+			return '';
132
+		}
133
+		$itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid'));
134
+		$ret      = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>';
135
+
136
+		return $ret;
137
+	}
138
+
139
+	/**
140
+	 * @return mixed
141
+	 */
142
+	public function getRateValue()
143
+	{
144
+		return $this->getVar('rate');
145
+	}
146
+
147
+	/**
148
+	 * @return bool
149
+	 */
150
+	public function getModulePlugin()
151
+	{
152
+		if (!$this->_modulePlugin) {
153
+			global $smartobjectRatingHandler;
154
+			$this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n'));
155
+		}
156
+
157
+		return $this->_modulePlugin;
158
+	}
159 159
 }
160 160
 
161 161
 /**
@@ -163,93 +163,93 @@  discard block
 block discarded – undo
163 163
  */
164 164
 class SmartobjectRatingHandler extends SmartPersistableObjectHandler
165 165
 {
166
-    public $_rateOptions = array();
167
-    public $_moduleList  = false;
168
-    public $pluginsObject;
169
-
170
-    /**
171
-     * SmartobjectRatingHandler constructor.
172
-     * @param XoopsDatabase $db
173
-     */
174
-    public function __construct($db)
175
-    {
176
-        parent::__construct($db, 'rating', 'ratingid', 'rate', '', 'smartobject');
177
-        $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid';
178
-
179
-        $this->_rateOptions[1] = 1;
180
-        $this->_rateOptions[2] = 2;
181
-        $this->_rateOptions[3] = 3;
182
-        $this->_rateOptions[4] = 4;
183
-        $this->_rateOptions[5] = 5;
184
-
185
-        $this->pluginsObject = new SmartPluginHandler();
186
-    }
187
-
188
-    /**
189
-     * @return bool
190
-     */
191
-    public function getModuleList()
192
-    {
193
-        if (!$this->_moduleList) {
194
-            $moduleArray          = $this->pluginsObject->getPluginsArray();
195
-            $this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION;
196
-            foreach ($moduleArray as $k => $v) {
197
-                $this->_moduleList[$k] = $v;
198
-            }
199
-        }
200
-
201
-        return $this->_moduleList;
202
-    }
203
-
204
-    /**
205
-     * @return array
206
-     */
207
-    public function getRateList()
208
-    {
209
-        return $this->_rateOptions;
210
-    }
211
-
212
-    /**
213
-     * @param $itemid
214
-     * @param $dirname
215
-     * @param $item
216
-     * @return int
217
-     */
218
-    public function getRatingAverageByItemId($itemid, $dirname, $item)
219
-    {
220
-        $sql    = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid";
221
-        $result = $this->db->query($sql);
222
-        if (!$result) {
223
-            return 0;
224
-        }
225
-        list($average, $sum) = $this->db->fetchRow($result);
226
-        $ret['average'] = isset($average) ? $average : 0;
227
-        $ret['sum']     = isset($sum) ? $sum : 0;
228
-
229
-        return $ret;
230
-    }
231
-
232
-    /**
233
-     * @param $item
234
-     * @param $itemid
235
-     * @param $dirname
236
-     * @param $uid
237
-     * @return bool
238
-     */
239
-    public function already_rated($item, $itemid, $dirname, $uid)
240
-    {
241
-        $criteria = new CriteriaCompo();
242
-        $criteria->add(new Criteria('item', $item));
243
-        $criteria->add(new Criteria('itemid', $itemid));
244
-        $criteria->add(new Criteria('dirname', $dirname));
245
-        $criteria->add(new Criteria('user.uid', $uid));
246
-
247
-        $ret = $this->getObjects($criteria);
248
-
249
-        if (!$ret) {
250
-            return false;
251
-        } else {
252
-            return $ret[0];
253
-        }
254
-    }
166
+	public $_rateOptions = array();
167
+	public $_moduleList  = false;
168
+	public $pluginsObject;
169
+
170
+	/**
171
+	 * SmartobjectRatingHandler constructor.
172
+	 * @param XoopsDatabase $db
173
+	 */
174
+	public function __construct($db)
175
+	{
176
+		parent::__construct($db, 'rating', 'ratingid', 'rate', '', 'smartobject');
177
+		$this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid';
178
+
179
+		$this->_rateOptions[1] = 1;
180
+		$this->_rateOptions[2] = 2;
181
+		$this->_rateOptions[3] = 3;
182
+		$this->_rateOptions[4] = 4;
183
+		$this->_rateOptions[5] = 5;
184
+
185
+		$this->pluginsObject = new SmartPluginHandler();
186
+	}
187
+
188
+	/**
189
+	 * @return bool
190
+	 */
191
+	public function getModuleList()
192
+	{
193
+		if (!$this->_moduleList) {
194
+			$moduleArray          = $this->pluginsObject->getPluginsArray();
195
+			$this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION;
196
+			foreach ($moduleArray as $k => $v) {
197
+				$this->_moduleList[$k] = $v;
198
+			}
199
+		}
200
+
201
+		return $this->_moduleList;
202
+	}
203
+
204
+	/**
205
+	 * @return array
206
+	 */
207
+	public function getRateList()
208
+	{
209
+		return $this->_rateOptions;
210
+	}
211
+
212
+	/**
213
+	 * @param $itemid
214
+	 * @param $dirname
215
+	 * @param $item
216
+	 * @return int
217
+	 */
218
+	public function getRatingAverageByItemId($itemid, $dirname, $item)
219
+	{
220
+		$sql    = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid";
221
+		$result = $this->db->query($sql);
222
+		if (!$result) {
223
+			return 0;
224
+		}
225
+		list($average, $sum) = $this->db->fetchRow($result);
226
+		$ret['average'] = isset($average) ? $average : 0;
227
+		$ret['sum']     = isset($sum) ? $sum : 0;
228
+
229
+		return $ret;
230
+	}
231
+
232
+	/**
233
+	 * @param $item
234
+	 * @param $itemid
235
+	 * @param $dirname
236
+	 * @param $uid
237
+	 * @return bool
238
+	 */
239
+	public function already_rated($item, $itemid, $dirname, $uid)
240
+	{
241
+		$criteria = new CriteriaCompo();
242
+		$criteria->add(new Criteria('item', $item));
243
+		$criteria->add(new Criteria('itemid', $itemid));
244
+		$criteria->add(new Criteria('dirname', $dirname));
245
+		$criteria->add(new Criteria('user.uid', $uid));
246
+
247
+		$ret = $this->getObjects($criteria);
248
+
249
+		if (!$ret) {
250
+			return false;
251
+		} else {
252
+			return $ret[0];
253
+		}
254
+	}
255 255
 }
Please login to merge, or discard this patch.
class/smartaddto.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -9,66 +9,66 @@
 block discarded – undo
9 9
 
10 10
 class SmartAddto
11 11
 {
12
-    public $_layout;
13
-    public $_method;
12
+	public $_layout;
13
+	public $_method;
14 14
 
15
-    /**
16
-     * Constructor of SmartAddTo
17
-     *
18
-     * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons
19
-     * @param int $method 0=directpage, 1=popup
20
-     */
21
-    public function __construct($layout = 0, $method = 1)
22
-    {
23
-        $layout = (int)$layout;
24
-        if ($layout < 0 || $layout > 3) {
25
-            $layout = 0;
26
-        }
27
-        $this->_layout = $layout;
15
+	/**
16
+	 * Constructor of SmartAddTo
17
+	 *
18
+	 * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons
19
+	 * @param int $method 0=directpage, 1=popup
20
+	 */
21
+	public function __construct($layout = 0, $method = 1)
22
+	{
23
+		$layout = (int)$layout;
24
+		if ($layout < 0 || $layout > 3) {
25
+			$layout = 0;
26
+		}
27
+		$this->_layout = $layout;
28 28
 
29
-        $method = (int)$method;
30
-        if ($method < 0 || $method > 1) {
31
-            $method = 1;
32
-        }
33
-        $this->_method = $method;
34
-    }
29
+		$method = (int)$method;
30
+		if ($method < 0 || $method > 1) {
31
+			$method = 1;
32
+		}
33
+		$this->_method = $method;
34
+	}
35 35
 
36
-    /**
37
-     * @param  bool $fetchOnly
38
-     * @return mixed|string|void
39
-     */
40
-    public function render($fetchOnly = false)
41
-    {
42
-        global $xoTheme, $xoopsTpl;
36
+	/**
37
+	 * @param  bool $fetchOnly
38
+	 * @return mixed|string|void
39
+	 */
40
+	public function render($fetchOnly = false)
41
+	{
42
+		global $xoTheme, $xoopsTpl;
43 43
 
44
-        $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css');
44
+		$xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css');
45 45
 
46
-        $xoopsTpl->assign('smartobject_addto_method', $this->_method);
47
-        $xoopsTpl->assign('smartobject_addto_layout', $this->_layout);
46
+		$xoopsTpl->assign('smartobject_addto_method', $this->_method);
47
+		$xoopsTpl->assign('smartobject_addto_layout', $this->_layout);
48 48
 
49
-        $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/');
49
+		$xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/');
50 50
 
51
-        if ($fetchOnly) {
52
-            return $xoopsTpl->fetch('db:smartobject_addto.tpl');
53
-        } else {
54
-            $xoopsTpl->display('db:smartobject_addto.tpl');
55
-        }
56
-    }
51
+		if ($fetchOnly) {
52
+			return $xoopsTpl->fetch('db:smartobject_addto.tpl');
53
+		} else {
54
+			$xoopsTpl->display('db:smartobject_addto.tpl');
55
+		}
56
+	}
57 57
 
58
-    /**
59
-     * @return array
60
-     */
61
-    public function renderForBlock()
62
-    {
63
-        global $xoTheme;
58
+	/**
59
+	 * @return array
60
+	 */
61
+	public function renderForBlock()
62
+	{
63
+		global $xoTheme;
64 64
 
65
-        $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css');
65
+		$xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css');
66 66
 
67
-        $block                             = array();
68
-        $block['smartobject_addto_method'] = $this->_method;
69
-        $block['smartobject_addto_layout'] = $this->_layout;
70
-        $block['smartobject_addto_url']    = SMARTOBJECT_URL . 'include/addto/';
67
+		$block                             = array();
68
+		$block['smartobject_addto_method'] = $this->_method;
69
+		$block['smartobject_addto_layout'] = $this->_layout;
70
+		$block['smartobject_addto_url']    = SMARTOBJECT_URL . 'include/addto/';
71 71
 
72
-        return $block;
73
-    }
72
+		return $block;
73
+	}
74 74
 }
Please login to merge, or discard this patch.
class/file.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -8,14 +8,14 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class SmartobjectFile extends SmartobjectBasedUrl
10 10
 {
11
-    /**
12
-     * SmartobjectFile constructor.
13
-     */
14
-    public function __construct()
15
-    {
16
-        parent::__construct();
17
-        $this->quickInitVar('fileid', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME);
18
-    }
11
+	/**
12
+	 * SmartobjectFile constructor.
13
+	 */
14
+	public function __construct()
15
+	{
16
+		parent::__construct();
17
+		$this->quickInitVar('fileid', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME);
18
+	}
19 19
 }
20 20
 
21 21
 /**
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class SmartobjectFileHandler extends SmartPersistableObjectHandler
25 25
 {
26
-    /**
27
-     * SmartobjectFileHandler constructor.
28
-     * @param object|XoopsDatabase $db
29
-     */
30
-    public function __construct($db)
31
-    {
32
-        parent::__construct($db, 'file', 'fileid', 'caption', 'desc', 'smartobject');
33
-    }
26
+	/**
27
+	 * SmartobjectFileHandler constructor.
28
+	 * @param object|XoopsDatabase $db
29
+	 */
30
+	public function __construct($db)
31
+	{
32
+		parent::__construct($db, 'file', 'fileid', 'caption', 'desc', 'smartobject');
33
+	}
34 34
 }
Please login to merge, or discard this patch.
class/smartobjectcontroller.php 1 patch
Indentation   +474 added lines, -474 removed lines patch added patch discarded remove patch
@@ -31,478 +31,478 @@
 block discarded – undo
31 31
  */
32 32
 class SmartObjectController
33 33
 {
34
-    public $handler;
35
-
36
-    /**
37
-     * SmartObjectController constructor.
38
-     * @param $handler
39
-     */
40
-    public function __construct($handler)
41
-    {
42
-        $this->handler = $handler;
43
-    }
44
-
45
-    /**
46
-     * @param $smartObj
47
-     */
48
-    public function postDataToObject(&$smartObj)
49
-    {
50
-        foreach (array_keys($smartObj->vars) as $key) {
51
-            switch ($smartObj->vars[$key]['data_type']) {
52
-                case XOBJ_DTYPE_IMAGE:
53
-                    if (isset($_POST['url_' . $key]) && $_POST['url_' . $key] != '') {
54
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
55
-                        $smartObj->setVar($key, $_POST['url_' . $key]);
56
-                        if (file_exists($oldFile)) {
57
-                            unlink($oldFile);
58
-                        }
59
-                    }
60
-                    if (isset($_POST['delete_' . $key]) && $_POST['delete_' . $key] == '1') {
61
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
62
-                        $smartObj->setVar($key, '');
63
-                        if (file_exists($oldFile)) {
64
-                            unlink($oldFile);
65
-                        }
66
-                    }
67
-                    break;
68
-
69
-                case XOBJ_DTYPE_URLLINK:
70
-                    $linkObj = $smartObj->getUrlLinkObj($key);
71
-                    $linkObj->setVar('caption', $_POST['caption_' . $key]);
72
-                    $linkObj->setVar('description', $_POST['desc_' . $key]);
73
-                    $linkObj->setVar('target', $_POST['target_' . $key]);
74
-                    $linkObj->setVar('url', $_POST['url_' . $key]);
75
-                    if ($linkObj->getVar('url') != '') {
76
-                        $smartObj->storeUrlLinkObj($linkObj);
77
-                    }
78
-                    //todo: catch errors
79
-                    $smartObj->setVar($key, $linkObj->getVar('urllinkid'));
80
-                    break;
81
-
82
-                case XOBJ_DTYPE_FILE:
83
-                    if (!isset($_FILES['upload_' . $key]['name']) || $_FILES['upload_' . $key]['name'] == '') {
84
-                        $fileObj = $smartObj->getFileObj($key);
85
-                        $fileObj->setVar('caption', $_POST['caption_' . $key]);
86
-                        $fileObj->setVar('description', $_POST['desc_' . $key]);
87
-                        $fileObj->setVar('url', $_POST['url_' . $key]);
88
-                        if (!($fileObj->getVar('url') == '' && $fileObj->getVar('url') == '' && $fileObj->getVar('url') == '')) {
89
-                            $res = $smartObj->storeFileObj($fileObj);
90
-                            if ($res) {
91
-                                $smartObj->setVar($key, $fileObj->getVar('fileid'));
92
-                            } else {
93
-                                //error setted, but no error message (to be improved)
94
-                                $smartObj->setErrors($fileObj->getErrors());
95
-                            }
96
-                        }
97
-                    }
98
-                    break;
99
-
100
-                case XOBJ_DTYPE_STIME:
101
-                case XOBJ_DTYPE_MTIME:
102
-                case XOBJ_DTYPE_LTIME:
103
-                    // check if this field's value is available in the POST array
104
-                    if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) {
105
-                        $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time'];
106
-                    } else {
107
-                        $value = strtotime($_POST[$key]);
108
-                        //if strtotime returns false, the value is already a time stamp
109
-                        if (!$value) {
110
-                            $value = (int)$_POST[$key];
111
-                        }
112
-                    }
113
-                    $smartObj->setVar($key, $value);
114
-
115
-                    break;
116
-
117
-                default:
118
-                    $smartObj->setVar($key, $_POST[$key]);
119
-                    break;
120
-            }
121
-        }
122
-    }
123
-
124
-    /**
125
-     * @param       $smartObj
126
-     * @param       $objectid
127
-     * @param       $created_success_msg
128
-     * @param       $modified_success_msg
129
-     * @param  bool $redirect_page
130
-     * @param  bool $debug
131
-     * @return mixed
132
-     */
133
-    public function doStoreFromDefaultForm(&$smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false)
134
-    {
135
-        global $smart_previous_page;
136
-
137
-        $this->postDataToObject($smartObj);
138
-
139
-        if ($smartObj->isNew()) {
140
-            $redirect_msg = $created_success_msg;
141
-        } else {
142
-            $redirect_msg = $modified_success_msg;
143
-        }
144
-
145
-        // Check if there were uploaded files
146
-        if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) {
147
-            include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php';
148
-            $uploaderObj = new SmartUploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight);
149
-            foreach ($_FILES as $name => $file_array) {
150
-                if (isset($file_array['name']) && $file_array['name'] != '' && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
151
-                    if ($uploaderObj->fetchMedia($name)) {
152
-                        $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
153
-                        if ($uploaderObj->upload()) {
154
-                            // Find the related field in the SmartObject
155
-                            $related_field   = str_replace('upload_', '', $name);
156
-                            $uploadedArray[] = $related_field;
157
-                            //si c'est un fichier Rich
158
-                            if ($smartObj->vars[$related_field]['data_type'] === XOBJ_DTYPE_FILE) {
159
-                                $object_fileurl = $smartObj->getUploadDir();
160
-                                $fileObj        = $smartObj->getFileObj($related_field);
161
-                                $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName());
162
-                                $fileObj->setVar('caption', $_POST['caption_' . $related_field]);
163
-                                $fileObj->setVar('description', $_POST['desc_' . $related_field]);
164
-                                $smartObj->storeFileObj($fileObj);
165
-                                //todo: catch errors
166
-                                $smartObj->setVar($related_field, $fileObj->getVar('fileid'));
167
-                            } else {
168
-                                $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
169
-                                unlink($old_file);
170
-                                $smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
171
-                            }
172
-                        } else {
173
-                            $smartObj->setErrors($uploaderObj->getErrors(false));
174
-                        }
175
-                    } else {
176
-                        $smartObj->setErrors($uploaderObj->getErrors(false));
177
-                    }
178
-                }
179
-            }
180
-        }
181
-
182
-        if ($debug) {
183
-            $storeResult = $this->handler->insertD($smartObj);
184
-        } else {
185
-            $storeResult = $this->handler->insert($smartObj);
186
-        }
187
-
188
-        if ($storeResult) {
189
-            if ($this->handler->getPermissions()) {
190
-                $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
191
-                $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id());
192
-            }
193
-        }
194
-
195
-        if ($redirect_page === null) {
196
-            return $smartObj;
197
-        } else {
198
-            if (!$storeResult) {
199
-                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
200
-            }
201
-
202
-            $redirect_page = $redirect_page ?: smart_get_page_before_form();
203
-
204
-            redirect_header($redirect_page, 2, $redirect_msg);
205
-        }
206
-    }
207
-
208
-    /**
209
-     * Store the object in the database autmatically from a form sending POST data
210
-     *
211
-     * @param  string      $created_success_msg  message to display if new object was created
212
-     * @param  string      $modified_success_msg message to display if object was successfully edited
213
-     * @param  bool|string $redirect_page        redirect page, if not set, then we backup once
214
-     * @param  bool        $debug
215
-     * @param  bool        $x_param
216
-     * @return bool
217
-     * @internal param string $created_redir_page redirect page after creating the object
218
-     * @internal param string $modified_redir_page redirect page after editing the object
219
-     * @internal param bool $exit if set to TRUE then the script ends
220
-     */
221
-    public function storeFromDefaultForm($created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false, $x_param = false)
222
-    {
223
-        $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
224
-        if ($debug) {
225
-            if ($x_param) {
226
-                $smartObj = $this->handler->getD($objectid, true, $x_param);
227
-            } else {
228
-                $smartObj = $this->handler->getD($objectid);
229
-            }
230
-        } else {
231
-            if ($x_param) {
232
-                $smartObj = $this->handler->get($objectid, true, false, false, $x_param);
233
-            } else {
234
-                $smartObj = $this->handler->get($objectid);
235
-            }
236
-        }
237
-
238
-        // if handler is the Multilanguage handler, we will need to treat this for multilanguage
239
-        if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) {
240
-            if ($smartObj->isNew()) {
241
-                // This is a new object. We need to store the meta data and then the language data
242
-                // First, we will get rid of the multilanguage data to only store the meta data
243
-                $smartObj->stripMultilanguageFields();
244
-                $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
245
-                /**
246
-                 * @todo we need to trap potential errors here
247
-                 */
248
-
249
-                // ok, the meta daa is stored. Let's recreate the object and then
250
-                // get rid of anything not multilanguage
251
-                unset($smartObj);
252
-                $smartObj = $this->handler->get($objectid);
253
-                $smartObj->stripNonMultilanguageFields();
254
-
255
-                $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName));
256
-                $this->handler->changeTableNameForML();
257
-                $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
258
-
259
-                return $ret;
260
-            }
261
-        } else {
262
-            return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
263
-        }
264
-    }
265
-
266
-    /**
267
-     * @return bool
268
-     */
269
-    public function storeSmartObjectD()
270
-    {
271
-        return $this->storeSmartObject(true);
272
-    }
273
-
274
-    /**
275
-     * @param  bool $debug
276
-     * @param  bool $xparam
277
-     * @return bool
278
-     */
279
-    public function storeSmartObject($debug = false, $xparam = false)
280
-    {
281
-        $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam);
282
-
283
-        return $ret;
284
-    }
285
-
286
-    /**
287
-     * Handles deletion of an object which keyid is passed as a GET param
288
-     *
289
-     * @param  bool   $confirm_msg
290
-     * @param  string $op
291
-     * @param  bool   $userSide
292
-     * @return bool
293
-     * @internal param string $redir_page redirect page after deleting the object
294
-     */
295
-    public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false)
296
-    {
297
-        global $smart_previous_page;
298
-
299
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
300
-        $smartObj = $this->handler->get($objectid);
301
-
302
-        if ($smartObj->isNew()) {
303
-            redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
304
-        }
305
-
306
-        $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
307
-        if ($confirm) {
308
-            if (!$this->handler->delete($smartObj)) {
309
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
310
-                exit;
311
-            }
312
-
313
-            redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
314
-        } else {
315
-            // no confirm: show deletion condition
316
-
317
-            xoops_cp_header();
318
-
319
-            if (!$confirm_msg) {
320
-                $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
321
-            }
322
-
323
-            xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
324
-
325
-            xoops_cp_footer();
326
-        }
327
-        exit();
328
-    }
329
-
330
-    /**
331
-     * @param bool   $confirm_msg
332
-     * @param string $op
333
-     */
334
-    public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del')
335
-    {
336
-        global $smart_previous_page, $xoopsTpl;
337
-
338
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
339
-        $smartObj = $this->handler->get($objectid);
340
-
341
-        if ($smartObj->isNew()) {
342
-            redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
343
-        }
344
-
345
-        $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
346
-        if ($confirm) {
347
-            if (!$this->handler->delete($smartObj)) {
348
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
349
-                exit;
350
-            }
351
-
352
-            redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
353
-        } else {
354
-            // no confirm: show deletion condition
355
-            if (!$confirm_msg) {
356
-                $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
357
-            }
358
-
359
-            ob_start();
360
-            xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
361
-            $smartobjectDeleteConfirm = ob_get_clean();
362
-            $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm);
363
-        }
364
-    }
365
-
366
-    /**
367
-     * Retreive the object admin side link for a {@link SmartObjectSingleView} page
368
-     *
369
-     * @param  object $smartObj reference to the object from which we want the user side link
370
-     * @param  bool   $onlyUrl  wether or not to return a simple URL or a full <a> link
371
-     * @param  bool   $withimage
372
-     * @return string admin side link to the object
373
-     */
374
-    public function getAdminViewItemLink($smartObj, $onlyUrl = false, $withimage = false)
375
-    {
376
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
377
-        if ($onlyUrl) {
378
-            return $ret;
379
-        } elseif ($withimage) {
380
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "'  title='" . _CO_SOBJECT_ADMIN_VIEW . "'/></a>";
381
-        }
382
-
383
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
384
-    }
385
-
386
-    /**
387
-     * Retreive the object user side link
388
-     *
389
-     * @param  object $smartObj reference to the object from which we want the user side link
390
-     * @param  bool   $onlyUrl  wether or not to return a simple URL or a full <a> link
391
-     * @return string user side link to the object
392
-     */
393
-    public function getItemLink(&$smartObj, $onlyUrl = false)
394
-    {
395
-        $seoMode       = smart_getModuleModeSEO($this->handler->_moduleName);
396
-        $seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName);
397
-
398
-        /**
399
-         * $seoIncludeId feature is not finished yet, so let's put it always to true
400
-         */
401
-        //$seoIncludeId = smart_getModuleIncludeIdSEO($this->handler->_moduleName);
402
-        $seoIncludeId = true;
403
-
404
-        if ($seoMode === 'rewrite') {
405
-            $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
406
-        } elseif ($seoMode === 'pathinfo') {
407
-            $ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
408
-        } else {
409
-            $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
410
-        }
411
-
412
-        if (!$onlyUrl) {
413
-            $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
414
-        }
415
-
416
-        return $ret;
417
-    }
418
-
419
-    /**
420
-     * @param       $smartObj
421
-     * @param  bool $onlyUrl
422
-     * @param  bool $withimage
423
-     * @return string
424
-     */
425
-    public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
426
-    {
427
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language');
428
-        if ($onlyUrl) {
429
-            return $ret;
430
-        } elseif ($withimage) {
431
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'  title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'/></a>";
432
-        }
433
-
434
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
435
-    }
436
-
437
-    /**
438
-     * @param       $smartObj
439
-     * @param  bool $onlyUrl
440
-     * @param  bool $withimage
441
-     * @param  bool $userSide
442
-     * @return string
443
-     */
444
-    public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
445
-    {
446
-        $admin_side = $userSide ? '' : 'admin/';
447
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
448
-        if ($onlyUrl) {
449
-            return $ret;
450
-        } elseif ($withimage) {
451
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "'  title='" . _CO_SOBJECT_MODIFY . "'/></a>";
452
-        }
453
-
454
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
455
-    }
456
-
457
-    /**
458
-     * @param       $smartObj
459
-     * @param  bool $onlyUrl
460
-     * @param  bool $withimage
461
-     * @param  bool $userSide
462
-     * @return string
463
-     */
464
-    public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
465
-    {
466
-        $admin_side = $userSide ? '' : 'admin/';
467
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
468
-        if ($onlyUrl) {
469
-            return $ret;
470
-        } elseif ($withimage) {
471
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "'  title='" . _CO_SOBJECT_DELETE . "'/></a>";
472
-        }
473
-
474
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
475
-    }
476
-
477
-    /**
478
-     * @param $smartObj
479
-     * @return string
480
-     */
481
-    public function getPrintAndMailLink($smartObj)
482
-    {
483
-        global $xoopsConfig;
484
-
485
-        $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
486
-        $js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
487
-        $printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"/></a>';
488
-
489
-        $smartModule = smart_getModuleInfo($smartObj->handler->_moduleName);
490
-        $link        = smart_getCurrentPage();
491
-        $mid         = $smartModule->getVar('mid');
492
-        $friendlink  = "<a href=\"javascript:openWithSelfMain('" . SMARTOBJECT_URL . 'sendlink.php?link=' . $link . '&amp;mid=' . $mid . "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" . SMARTOBJECT_IMAGES_ACTIONS_URL . "mail_send.png\"  alt=\"" . _CO_SOBJECT_EMAIL . "\" title=\"" . _CO_SOBJECT_EMAIL . "\" style=\"vertical-align: middle;\"/></a>";
493
-
494
-        $ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
495
-
496
-        return $ret;
497
-    }
498
-
499
-    /**
500
-     * @return string
501
-     */
502
-    public function getModuleItemString()
503
-    {
504
-        $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
505
-
506
-        return $ret;
507
-    }
34
+	public $handler;
35
+
36
+	/**
37
+	 * SmartObjectController constructor.
38
+	 * @param $handler
39
+	 */
40
+	public function __construct($handler)
41
+	{
42
+		$this->handler = $handler;
43
+	}
44
+
45
+	/**
46
+	 * @param $smartObj
47
+	 */
48
+	public function postDataToObject(&$smartObj)
49
+	{
50
+		foreach (array_keys($smartObj->vars) as $key) {
51
+			switch ($smartObj->vars[$key]['data_type']) {
52
+				case XOBJ_DTYPE_IMAGE:
53
+					if (isset($_POST['url_' . $key]) && $_POST['url_' . $key] != '') {
54
+						$oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
55
+						$smartObj->setVar($key, $_POST['url_' . $key]);
56
+						if (file_exists($oldFile)) {
57
+							unlink($oldFile);
58
+						}
59
+					}
60
+					if (isset($_POST['delete_' . $key]) && $_POST['delete_' . $key] == '1') {
61
+						$oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
62
+						$smartObj->setVar($key, '');
63
+						if (file_exists($oldFile)) {
64
+							unlink($oldFile);
65
+						}
66
+					}
67
+					break;
68
+
69
+				case XOBJ_DTYPE_URLLINK:
70
+					$linkObj = $smartObj->getUrlLinkObj($key);
71
+					$linkObj->setVar('caption', $_POST['caption_' . $key]);
72
+					$linkObj->setVar('description', $_POST['desc_' . $key]);
73
+					$linkObj->setVar('target', $_POST['target_' . $key]);
74
+					$linkObj->setVar('url', $_POST['url_' . $key]);
75
+					if ($linkObj->getVar('url') != '') {
76
+						$smartObj->storeUrlLinkObj($linkObj);
77
+					}
78
+					//todo: catch errors
79
+					$smartObj->setVar($key, $linkObj->getVar('urllinkid'));
80
+					break;
81
+
82
+				case XOBJ_DTYPE_FILE:
83
+					if (!isset($_FILES['upload_' . $key]['name']) || $_FILES['upload_' . $key]['name'] == '') {
84
+						$fileObj = $smartObj->getFileObj($key);
85
+						$fileObj->setVar('caption', $_POST['caption_' . $key]);
86
+						$fileObj->setVar('description', $_POST['desc_' . $key]);
87
+						$fileObj->setVar('url', $_POST['url_' . $key]);
88
+						if (!($fileObj->getVar('url') == '' && $fileObj->getVar('url') == '' && $fileObj->getVar('url') == '')) {
89
+							$res = $smartObj->storeFileObj($fileObj);
90
+							if ($res) {
91
+								$smartObj->setVar($key, $fileObj->getVar('fileid'));
92
+							} else {
93
+								//error setted, but no error message (to be improved)
94
+								$smartObj->setErrors($fileObj->getErrors());
95
+							}
96
+						}
97
+					}
98
+					break;
99
+
100
+				case XOBJ_DTYPE_STIME:
101
+				case XOBJ_DTYPE_MTIME:
102
+				case XOBJ_DTYPE_LTIME:
103
+					// check if this field's value is available in the POST array
104
+					if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) {
105
+						$value = strtotime($_POST[$key]['date']) + $_POST[$key]['time'];
106
+					} else {
107
+						$value = strtotime($_POST[$key]);
108
+						//if strtotime returns false, the value is already a time stamp
109
+						if (!$value) {
110
+							$value = (int)$_POST[$key];
111
+						}
112
+					}
113
+					$smartObj->setVar($key, $value);
114
+
115
+					break;
116
+
117
+				default:
118
+					$smartObj->setVar($key, $_POST[$key]);
119
+					break;
120
+			}
121
+		}
122
+	}
123
+
124
+	/**
125
+	 * @param       $smartObj
126
+	 * @param       $objectid
127
+	 * @param       $created_success_msg
128
+	 * @param       $modified_success_msg
129
+	 * @param  bool $redirect_page
130
+	 * @param  bool $debug
131
+	 * @return mixed
132
+	 */
133
+	public function doStoreFromDefaultForm(&$smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false)
134
+	{
135
+		global $smart_previous_page;
136
+
137
+		$this->postDataToObject($smartObj);
138
+
139
+		if ($smartObj->isNew()) {
140
+			$redirect_msg = $created_success_msg;
141
+		} else {
142
+			$redirect_msg = $modified_success_msg;
143
+		}
144
+
145
+		// Check if there were uploaded files
146
+		if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) {
147
+			include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php';
148
+			$uploaderObj = new SmartUploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight);
149
+			foreach ($_FILES as $name => $file_array) {
150
+				if (isset($file_array['name']) && $file_array['name'] != '' && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
151
+					if ($uploaderObj->fetchMedia($name)) {
152
+						$uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
153
+						if ($uploaderObj->upload()) {
154
+							// Find the related field in the SmartObject
155
+							$related_field   = str_replace('upload_', '', $name);
156
+							$uploadedArray[] = $related_field;
157
+							//si c'est un fichier Rich
158
+							if ($smartObj->vars[$related_field]['data_type'] === XOBJ_DTYPE_FILE) {
159
+								$object_fileurl = $smartObj->getUploadDir();
160
+								$fileObj        = $smartObj->getFileObj($related_field);
161
+								$fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName());
162
+								$fileObj->setVar('caption', $_POST['caption_' . $related_field]);
163
+								$fileObj->setVar('description', $_POST['desc_' . $related_field]);
164
+								$smartObj->storeFileObj($fileObj);
165
+								//todo: catch errors
166
+								$smartObj->setVar($related_field, $fileObj->getVar('fileid'));
167
+							} else {
168
+								$old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
169
+								unlink($old_file);
170
+								$smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
171
+							}
172
+						} else {
173
+							$smartObj->setErrors($uploaderObj->getErrors(false));
174
+						}
175
+					} else {
176
+						$smartObj->setErrors($uploaderObj->getErrors(false));
177
+					}
178
+				}
179
+			}
180
+		}
181
+
182
+		if ($debug) {
183
+			$storeResult = $this->handler->insertD($smartObj);
184
+		} else {
185
+			$storeResult = $this->handler->insert($smartObj);
186
+		}
187
+
188
+		if ($storeResult) {
189
+			if ($this->handler->getPermissions()) {
190
+				$smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
191
+				$smartPermissionsHandler->storeAllPermissionsForId($smartObj->id());
192
+			}
193
+		}
194
+
195
+		if ($redirect_page === null) {
196
+			return $smartObj;
197
+		} else {
198
+			if (!$storeResult) {
199
+				redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
200
+			}
201
+
202
+			$redirect_page = $redirect_page ?: smart_get_page_before_form();
203
+
204
+			redirect_header($redirect_page, 2, $redirect_msg);
205
+		}
206
+	}
207
+
208
+	/**
209
+	 * Store the object in the database autmatically from a form sending POST data
210
+	 *
211
+	 * @param  string      $created_success_msg  message to display if new object was created
212
+	 * @param  string      $modified_success_msg message to display if object was successfully edited
213
+	 * @param  bool|string $redirect_page        redirect page, if not set, then we backup once
214
+	 * @param  bool        $debug
215
+	 * @param  bool        $x_param
216
+	 * @return bool
217
+	 * @internal param string $created_redir_page redirect page after creating the object
218
+	 * @internal param string $modified_redir_page redirect page after editing the object
219
+	 * @internal param bool $exit if set to TRUE then the script ends
220
+	 */
221
+	public function storeFromDefaultForm($created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false, $x_param = false)
222
+	{
223
+		$objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
224
+		if ($debug) {
225
+			if ($x_param) {
226
+				$smartObj = $this->handler->getD($objectid, true, $x_param);
227
+			} else {
228
+				$smartObj = $this->handler->getD($objectid);
229
+			}
230
+		} else {
231
+			if ($x_param) {
232
+				$smartObj = $this->handler->get($objectid, true, false, false, $x_param);
233
+			} else {
234
+				$smartObj = $this->handler->get($objectid);
235
+			}
236
+		}
237
+
238
+		// if handler is the Multilanguage handler, we will need to treat this for multilanguage
239
+		if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) {
240
+			if ($smartObj->isNew()) {
241
+				// This is a new object. We need to store the meta data and then the language data
242
+				// First, we will get rid of the multilanguage data to only store the meta data
243
+				$smartObj->stripMultilanguageFields();
244
+				$newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
245
+				/**
246
+				 * @todo we need to trap potential errors here
247
+				 */
248
+
249
+				// ok, the meta daa is stored. Let's recreate the object and then
250
+				// get rid of anything not multilanguage
251
+				unset($smartObj);
252
+				$smartObj = $this->handler->get($objectid);
253
+				$smartObj->stripNonMultilanguageFields();
254
+
255
+				$smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName));
256
+				$this->handler->changeTableNameForML();
257
+				$ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
258
+
259
+				return $ret;
260
+			}
261
+		} else {
262
+			return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
263
+		}
264
+	}
265
+
266
+	/**
267
+	 * @return bool
268
+	 */
269
+	public function storeSmartObjectD()
270
+	{
271
+		return $this->storeSmartObject(true);
272
+	}
273
+
274
+	/**
275
+	 * @param  bool $debug
276
+	 * @param  bool $xparam
277
+	 * @return bool
278
+	 */
279
+	public function storeSmartObject($debug = false, $xparam = false)
280
+	{
281
+		$ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam);
282
+
283
+		return $ret;
284
+	}
285
+
286
+	/**
287
+	 * Handles deletion of an object which keyid is passed as a GET param
288
+	 *
289
+	 * @param  bool   $confirm_msg
290
+	 * @param  string $op
291
+	 * @param  bool   $userSide
292
+	 * @return bool
293
+	 * @internal param string $redir_page redirect page after deleting the object
294
+	 */
295
+	public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false)
296
+	{
297
+		global $smart_previous_page;
298
+
299
+		$objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
300
+		$smartObj = $this->handler->get($objectid);
301
+
302
+		if ($smartObj->isNew()) {
303
+			redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
304
+		}
305
+
306
+		$confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
307
+		if ($confirm) {
308
+			if (!$this->handler->delete($smartObj)) {
309
+				redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
310
+				exit;
311
+			}
312
+
313
+			redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
314
+		} else {
315
+			// no confirm: show deletion condition
316
+
317
+			xoops_cp_header();
318
+
319
+			if (!$confirm_msg) {
320
+				$confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
321
+			}
322
+
323
+			xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
324
+
325
+			xoops_cp_footer();
326
+		}
327
+		exit();
328
+	}
329
+
330
+	/**
331
+	 * @param bool   $confirm_msg
332
+	 * @param string $op
333
+	 */
334
+	public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del')
335
+	{
336
+		global $smart_previous_page, $xoopsTpl;
337
+
338
+		$objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
339
+		$smartObj = $this->handler->get($objectid);
340
+
341
+		if ($smartObj->isNew()) {
342
+			redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
343
+		}
344
+
345
+		$confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
346
+		if ($confirm) {
347
+			if (!$this->handler->delete($smartObj)) {
348
+				redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
349
+				exit;
350
+			}
351
+
352
+			redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
353
+		} else {
354
+			// no confirm: show deletion condition
355
+			if (!$confirm_msg) {
356
+				$confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
357
+			}
358
+
359
+			ob_start();
360
+			xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
361
+			$smartobjectDeleteConfirm = ob_get_clean();
362
+			$xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm);
363
+		}
364
+	}
365
+
366
+	/**
367
+	 * Retreive the object admin side link for a {@link SmartObjectSingleView} page
368
+	 *
369
+	 * @param  object $smartObj reference to the object from which we want the user side link
370
+	 * @param  bool   $onlyUrl  wether or not to return a simple URL or a full <a> link
371
+	 * @param  bool   $withimage
372
+	 * @return string admin side link to the object
373
+	 */
374
+	public function getAdminViewItemLink($smartObj, $onlyUrl = false, $withimage = false)
375
+	{
376
+		$ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
377
+		if ($onlyUrl) {
378
+			return $ret;
379
+		} elseif ($withimage) {
380
+			return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "'  title='" . _CO_SOBJECT_ADMIN_VIEW . "'/></a>";
381
+		}
382
+
383
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
384
+	}
385
+
386
+	/**
387
+	 * Retreive the object user side link
388
+	 *
389
+	 * @param  object $smartObj reference to the object from which we want the user side link
390
+	 * @param  bool   $onlyUrl  wether or not to return a simple URL or a full <a> link
391
+	 * @return string user side link to the object
392
+	 */
393
+	public function getItemLink(&$smartObj, $onlyUrl = false)
394
+	{
395
+		$seoMode       = smart_getModuleModeSEO($this->handler->_moduleName);
396
+		$seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName);
397
+
398
+		/**
399
+		 * $seoIncludeId feature is not finished yet, so let's put it always to true
400
+		 */
401
+		//$seoIncludeId = smart_getModuleIncludeIdSEO($this->handler->_moduleName);
402
+		$seoIncludeId = true;
403
+
404
+		if ($seoMode === 'rewrite') {
405
+			$ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
406
+		} elseif ($seoMode === 'pathinfo') {
407
+			$ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
408
+		} else {
409
+			$ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
410
+		}
411
+
412
+		if (!$onlyUrl) {
413
+			$ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
414
+		}
415
+
416
+		return $ret;
417
+	}
418
+
419
+	/**
420
+	 * @param       $smartObj
421
+	 * @param  bool $onlyUrl
422
+	 * @param  bool $withimage
423
+	 * @return string
424
+	 */
425
+	public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
426
+	{
427
+		$ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language');
428
+		if ($onlyUrl) {
429
+			return $ret;
430
+		} elseif ($withimage) {
431
+			return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'  title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'/></a>";
432
+		}
433
+
434
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
435
+	}
436
+
437
+	/**
438
+	 * @param       $smartObj
439
+	 * @param  bool $onlyUrl
440
+	 * @param  bool $withimage
441
+	 * @param  bool $userSide
442
+	 * @return string
443
+	 */
444
+	public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
445
+	{
446
+		$admin_side = $userSide ? '' : 'admin/';
447
+		$ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
448
+		if ($onlyUrl) {
449
+			return $ret;
450
+		} elseif ($withimage) {
451
+			return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "'  title='" . _CO_SOBJECT_MODIFY . "'/></a>";
452
+		}
453
+
454
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
455
+	}
456
+
457
+	/**
458
+	 * @param       $smartObj
459
+	 * @param  bool $onlyUrl
460
+	 * @param  bool $withimage
461
+	 * @param  bool $userSide
462
+	 * @return string
463
+	 */
464
+	public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
465
+	{
466
+		$admin_side = $userSide ? '' : 'admin/';
467
+		$ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
468
+		if ($onlyUrl) {
469
+			return $ret;
470
+		} elseif ($withimage) {
471
+			return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "'  title='" . _CO_SOBJECT_DELETE . "'/></a>";
472
+		}
473
+
474
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
475
+	}
476
+
477
+	/**
478
+	 * @param $smartObj
479
+	 * @return string
480
+	 */
481
+	public function getPrintAndMailLink($smartObj)
482
+	{
483
+		global $xoopsConfig;
484
+
485
+		$printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
486
+		$js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
487
+		$printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"/></a>';
488
+
489
+		$smartModule = smart_getModuleInfo($smartObj->handler->_moduleName);
490
+		$link        = smart_getCurrentPage();
491
+		$mid         = $smartModule->getVar('mid');
492
+		$friendlink  = "<a href=\"javascript:openWithSelfMain('" . SMARTOBJECT_URL . 'sendlink.php?link=' . $link . '&amp;mid=' . $mid . "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" . SMARTOBJECT_IMAGES_ACTIONS_URL . "mail_send.png\"  alt=\"" . _CO_SOBJECT_EMAIL . "\" title=\"" . _CO_SOBJECT_EMAIL . "\" style=\"vertical-align: middle;\"/></a>";
493
+
494
+		$ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
495
+
496
+		return $ret;
497
+	}
498
+
499
+	/**
500
+	 * @return string
501
+	 */
502
+	public function getModuleItemString()
503
+	{
504
+		$ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
505
+
506
+		return $ret;
507
+	}
508 508
 }
Please login to merge, or discard this patch.