Completed
Push — master ( 248a3a...c5aa4f )
by Michael
05:44 queued 02:41
created
class/form/elements/smartformyesnoelement.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@
 block discarded – undo
11 11
  */
12 12
 class SmartFormYesnoElement extends XoopsFormRadioYN
13 13
 {
14
-    /**
15
-     * SmartFormYesnoElement constructor.
16
-     * @param string $object
17
-     * @param string $key
18
-     */
19
-    public function __construct($object, $key)
20
-    {
21
-        parent::__construct($object->vars[$key]['form_caption'], $key, $object->getVar($key, 'e'));
22
-    }
14
+	/**
15
+	 * SmartFormYesnoElement constructor.
16
+	 * @param string $object
17
+	 * @param string $key
18
+	 */
19
+	public function __construct($object, $key)
20
+	{
21
+		parent::__construct($object->vars[$key]['form_caption'], $key, $object->getVar($key, 'e'));
22
+	}
23 23
 }
Please login to merge, or discard this patch.
class/basedurl.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -36,29 +36,29 @@
 block discarded – undo
36 36
  */
37 37
 class SmartobjectBasedUrl extends SmartObject
38 38
 {
39
-    /**
40
-     * SmartobjectBasedUrl constructor.
41
-     */
42
-    public function __construct()
43
-    {
44
-        $this->quickInitVar('caption', XOBJ_DTYPE_TXTBOX, false);
45
-        $this->quickInitVar('description', XOBJ_DTYPE_TXTBOX, false);
46
-        $this->quickInitVar('url', XOBJ_DTYPE_TXTBOX, false);
47
-    }
39
+	/**
40
+	 * SmartobjectBasedUrl constructor.
41
+	 */
42
+	public function __construct()
43
+	{
44
+		$this->quickInitVar('caption', XOBJ_DTYPE_TXTBOX, false);
45
+		$this->quickInitVar('description', XOBJ_DTYPE_TXTBOX, false);
46
+		$this->quickInitVar('url', XOBJ_DTYPE_TXTBOX, false);
47
+	}
48 48
 
49
-    /**
50
-     * @param  string $key
51
-     * @param  string $format
52
-     * @return mixed
53
-     */
54
-    public function getVar($key, $format = 'e')
55
-    {
56
-        if (0 === strpos($key, 'url_')) {
57
-            return parent::getVar('url', $format);
58
-        } elseif (0 === strpos($key, 'caption_')) {
59
-            return parent::getVar('caption', $format);
60
-        } else {
61
-            return parent::getVar($key, $format);
62
-        }
63
-    }
49
+	/**
50
+	 * @param  string $key
51
+	 * @param  string $format
52
+	 * @return mixed
53
+	 */
54
+	public function getVar($key, $format = 'e')
55
+	{
56
+		if (0 === strpos($key, 'url_')) {
57
+			return parent::getVar('url', $format);
58
+		} elseif (0 === strpos($key, 'caption_')) {
59
+			return parent::getVar('caption', $format);
60
+		} else {
61
+			return parent::getVar($key, $format);
62
+		}
63
+	}
64 64
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
 
30 30
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
31 31
 
32
-include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
32
+include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php';
33 33
 
34 34
 /**
35 35
  * Class SmartobjectBasedUrl
Please login to merge, or discard this patch.
class/smartprinterfriendly.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -15,65 +15,65 @@
 block discarded – undo
15 15
  */
16 16
 class SmartPrinterFriendly
17 17
 {
18
-    public $_title;
19
-    public $_dsc;
20
-    public $_content;
21
-    public $_tpl;
22
-    public $_pageTitle = false;
23
-    public $_width     = 680;
18
+	public $_title;
19
+	public $_dsc;
20
+	public $_content;
21
+	public $_tpl;
22
+	public $_pageTitle = false;
23
+	public $_width     = 680;
24 24
 
25
-    /**
26
-     * SmartPrinterFriendly constructor.
27
-     * @param      $content
28
-     * @param bool $title
29
-     * @param bool $dsc
30
-     */
31
-    public function __construct($content, $title = false, $dsc = false)
32
-    {
33
-        $this->_title   = $title;
34
-        $this->_dsc     = $dsc;
35
-        $this->_content = $content;
36
-    }
25
+	/**
26
+	 * SmartPrinterFriendly constructor.
27
+	 * @param      $content
28
+	 * @param bool $title
29
+	 * @param bool $dsc
30
+	 */
31
+	public function __construct($content, $title = false, $dsc = false)
32
+	{
33
+		$this->_title   = $title;
34
+		$this->_dsc     = $dsc;
35
+		$this->_content = $content;
36
+	}
37 37
 
38
-    public function render()
39
-    {
40
-        /**
41
-         * @todo move the output to a template
42
-         * @todo make the output XHTML compliant
43
-         */
38
+	public function render()
39
+	{
40
+		/**
41
+		 * @todo move the output to a template
42
+		 * @todo make the output XHTML compliant
43
+		 */
44 44
 
45
-        include_once XOOPS_ROOT_PATH . '/class/template.php';
45
+		include_once XOOPS_ROOT_PATH . '/class/template.php';
46 46
 
47
-        $this->_tpl = new XoopsTpl();
47
+		$this->_tpl = new XoopsTpl();
48 48
 
49
-        $this->_tpl->assign('smartobject_print_pageTitle', $this->_pageTitle ?: $this->_title);
50
-        $this->_tpl->assign('smartobject_print_title', $this->_title);
51
-        $this->_tpl->assign('smartobject_print_dsc', $this->_dsc);
52
-        $this->_tpl->assign('smartobject_print_content', $this->_content);
53
-        $this->_tpl->assign('smartobject_print_width', $this->_width);
49
+		$this->_tpl->assign('smartobject_print_pageTitle', $this->_pageTitle ?: $this->_title);
50
+		$this->_tpl->assign('smartobject_print_title', $this->_title);
51
+		$this->_tpl->assign('smartobject_print_dsc', $this->_dsc);
52
+		$this->_tpl->assign('smartobject_print_content', $this->_content);
53
+		$this->_tpl->assign('smartobject_print_width', $this->_width);
54 54
 
55
-        $current_urls = smart_getCurrentUrls();
56
-        $current_url  = $current_urls['full'];
55
+		$current_urls = smart_getCurrentUrls();
56
+		$current_url  = $current_urls['full'];
57 57
 
58
-        $this->_tpl->assign('smartobject_print_currenturl', $current_url);
59
-        $this->_tpl->assign('smartobject_print_url', $this->url);
58
+		$this->_tpl->assign('smartobject_print_currenturl', $current_url);
59
+		$this->_tpl->assign('smartobject_print_url', $this->url);
60 60
 
61
-        $this->_tpl->display('db:smartobject_print.tpl');
62
-    }
61
+		$this->_tpl->display('db:smartobject_print.tpl');
62
+	}
63 63
 
64
-    /**
65
-     * @param $text
66
-     */
67
-    public function setPageTitle($text)
68
-    {
69
-        $this->_pageTitle = $text;
70
-    }
64
+	/**
65
+	 * @param $text
66
+	 */
67
+	public function setPageTitle($text)
68
+	{
69
+		$this->_pageTitle = $text;
70
+	}
71 71
 
72
-    /**
73
-     * @param $width
74
-     */
75
-    public function setWidth($width)
76
-    {
77
-        $this->_width = $width;
78
-    }
72
+	/**
73
+	 * @param $width
74
+	 */
75
+	public function setWidth($width)
76
+	{
77
+		$this->_width = $width;
78
+	}
79 79
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
          * @todo make the output XHTML compliant
43 43
          */
44 44
 
45
-        include_once XOOPS_ROOT_PATH . '/class/template.php';
45
+        include_once XOOPS_ROOT_PATH.'/class/template.php';
46 46
 
47 47
         $this->_tpl = new XoopsTpl();
48 48
 
Please login to merge, or discard this patch.
class/smartplugins.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -5,68 +5,68 @@  discard block
 block discarded – undo
5 5
  */
6 6
 class SmartPlugin
7 7
 {
8
-    public $_infoArray;
9
-
10
-    /**
11
-     * SmartPlugin constructor.
12
-     * @param $array
13
-     */
14
-    public function __construct($array)
15
-    {
16
-        $this->_infoArray = $array;
17
-    }
18
-
19
-    /**
20
-     * @param $item
21
-     * @return bool
22
-     */
23
-    public function getItemInfo($item)
24
-    {
25
-        if (isset($this->_infoArray['items'][$item])) {
26
-            return $this->_infoArray['items'][$item];
27
-        } else {
28
-            return false;
29
-        }
30
-    }
31
-
32
-    /**
33
-     * @return mixed
34
-     */
35
-    public function getItemList()
36
-    {
37
-        $itemsArray = $this->_infoArray['items'];
38
-        foreach ($itemsArray as $k => $v) {
39
-            $ret[$k] = $v['caption'];
40
-        }
41
-
42
-        return $ret;
43
-    }
44
-
45
-    /**
46
-     * @return bool|int|string
47
-     */
48
-    public function getItem()
49
-    {
50
-        $ret = false;
51
-        foreach ($this->_infoArray['items'] as $k => $v) {
52
-            $search_str = str_replace('%u', '', $v['url']);
53
-            if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) {
54
-                $ret = $k;
55
-                break;
56
-            }
57
-        }
58
-
59
-        return $ret;
60
-    }
61
-
62
-    /**
63
-     * @param $item
64
-     * @return mixed
65
-     */
66
-    public function getItemIdForItem($item)
67
-    {
68
-        return $_REQUEST[$this->_infoArray['items'][$item]['request']];
69
-    }
8
+	public $_infoArray;
9
+
10
+	/**
11
+	 * SmartPlugin constructor.
12
+	 * @param $array
13
+	 */
14
+	public function __construct($array)
15
+	{
16
+		$this->_infoArray = $array;
17
+	}
18
+
19
+	/**
20
+	 * @param $item
21
+	 * @return bool
22
+	 */
23
+	public function getItemInfo($item)
24
+	{
25
+		if (isset($this->_infoArray['items'][$item])) {
26
+			return $this->_infoArray['items'][$item];
27
+		} else {
28
+			return false;
29
+		}
30
+	}
31
+
32
+	/**
33
+	 * @return mixed
34
+	 */
35
+	public function getItemList()
36
+	{
37
+		$itemsArray = $this->_infoArray['items'];
38
+		foreach ($itemsArray as $k => $v) {
39
+			$ret[$k] = $v['caption'];
40
+		}
41
+
42
+		return $ret;
43
+	}
44
+
45
+	/**
46
+	 * @return bool|int|string
47
+	 */
48
+	public function getItem()
49
+	{
50
+		$ret = false;
51
+		foreach ($this->_infoArray['items'] as $k => $v) {
52
+			$search_str = str_replace('%u', '', $v['url']);
53
+			if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) {
54
+				$ret = $k;
55
+				break;
56
+			}
57
+		}
58
+
59
+		return $ret;
60
+	}
61
+
62
+	/**
63
+	 * @param $item
64
+	 * @return mixed
65
+	 */
66
+	public function getItemIdForItem($item)
67
+	{
68
+		return $_REQUEST[$this->_infoArray['items'][$item]['request']];
69
+	}
70 70
 }
71 71
 
72 72
 /**
@@ -74,57 +74,57 @@  discard block
 block discarded – undo
74 74
  */
75 75
 class SmartPluginHandler
76 76
 {
77
-    public $pluginPatterns = false;
78
-
79
-    /**
80
-     * @param $dirname
81
-     * @return bool|SmartPlugin
82
-     */
83
-    public function getPlugin($dirname)
84
-    {
85
-        $pluginName = SMARTOBJECT_ROOT_PATH . 'plugins/' . $dirname . '.php';
86
-        if (file_exists($pluginName)) {
87
-            include_once($pluginName);
88
-            $function = 'smartobject_plugin_' . $dirname;
89
-            if (function_exists($function)) {
90
-                $array = $function();
91
-                $ret   = new SmartPlugin($array);
92
-
93
-                return $ret;
94
-            }
95
-        }
96
-
97
-        return false;
98
-    }
99
-
100
-    /**
101
-     * @return array
102
-     */
103
-    public function getPluginsArray()
104
-    {
105
-        include_once(XOOPS_ROOT_PATH . '/class/xoopslists.php');
106
-
107
-        $moduleHandler = xoops_getHandler('module');
108
-        $criteria       = new CriteriaCompo();
109
-        $criteria->add(new Criteria('isactive', 1));
110
-        $tempModulesObj = $moduleHandler->getObjects($criteria);
111
-        $modulesObj     = array();
112
-        foreach ($tempModulesObj as $moduleObj) {
113
-            $modulesObj[$moduleObj->getVar('dirname')] = $moduleObj;
114
-        }
115
-
116
-        $aFiles = XoopsLists::getFileListAsArray(SMARTOBJECT_ROOT_PATH . 'plugins/');
117
-        $ret    = array();
118
-        foreach ($aFiles as $file) {
119
-            if (substr($file, strlen($file) - 4, 4) === '.php') {
120
-                $pluginName                = str_replace('.php', '', $file);
121
-                $module_xoops_version_file = XOOPS_ROOT_PATH . "/modules/$pluginName/xoops_version.php";
122
-                if (file_exists($module_xoops_version_file) && isset($modulesObj[$pluginName])) {
123
-                    $ret[$pluginName] = $modulesObj[$pluginName]->getVar('name');
124
-                }
125
-            }
126
-        }
127
-
128
-        return $ret;
129
-    }
77
+	public $pluginPatterns = false;
78
+
79
+	/**
80
+	 * @param $dirname
81
+	 * @return bool|SmartPlugin
82
+	 */
83
+	public function getPlugin($dirname)
84
+	{
85
+		$pluginName = SMARTOBJECT_ROOT_PATH . 'plugins/' . $dirname . '.php';
86
+		if (file_exists($pluginName)) {
87
+			include_once($pluginName);
88
+			$function = 'smartobject_plugin_' . $dirname;
89
+			if (function_exists($function)) {
90
+				$array = $function();
91
+				$ret   = new SmartPlugin($array);
92
+
93
+				return $ret;
94
+			}
95
+		}
96
+
97
+		return false;
98
+	}
99
+
100
+	/**
101
+	 * @return array
102
+	 */
103
+	public function getPluginsArray()
104
+	{
105
+		include_once(XOOPS_ROOT_PATH . '/class/xoopslists.php');
106
+
107
+		$moduleHandler = xoops_getHandler('module');
108
+		$criteria       = new CriteriaCompo();
109
+		$criteria->add(new Criteria('isactive', 1));
110
+		$tempModulesObj = $moduleHandler->getObjects($criteria);
111
+		$modulesObj     = array();
112
+		foreach ($tempModulesObj as $moduleObj) {
113
+			$modulesObj[$moduleObj->getVar('dirname')] = $moduleObj;
114
+		}
115
+
116
+		$aFiles = XoopsLists::getFileListAsArray(SMARTOBJECT_ROOT_PATH . 'plugins/');
117
+		$ret    = array();
118
+		foreach ($aFiles as $file) {
119
+			if (substr($file, strlen($file) - 4, 4) === '.php') {
120
+				$pluginName                = str_replace('.php', '', $file);
121
+				$module_xoops_version_file = XOOPS_ROOT_PATH . "/modules/$pluginName/xoops_version.php";
122
+				if (file_exists($module_xoops_version_file) && isset($modulesObj[$pluginName])) {
123
+					$ret[$pluginName] = $modulesObj[$pluginName]->getVar('name');
124
+				}
125
+			}
126
+		}
127
+
128
+		return $ret;
129
+	}
130 130
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
         $ret = false;
51 51
         foreach ($this->_infoArray['items'] as $k => $v) {
52 52
             $search_str = str_replace('%u', '', $v['url']);
53
-            if (strpos($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'], $search_str) > 0) {
53
+            if (strpos($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], $search_str) > 0) {
54 54
                 $ret = $k;
55 55
                 break;
56 56
             }
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function getPlugin($dirname)
84 84
     {
85
-        $pluginName = SMARTOBJECT_ROOT_PATH . 'plugins/' . $dirname . '.php';
85
+        $pluginName = SMARTOBJECT_ROOT_PATH.'plugins/'.$dirname.'.php';
86 86
         if (file_exists($pluginName)) {
87 87
             include_once($pluginName);
88
-            $function = 'smartobject_plugin_' . $dirname;
88
+            $function = 'smartobject_plugin_'.$dirname;
89 89
             if (function_exists($function)) {
90 90
                 $array = $function();
91 91
                 $ret   = new SmartPlugin($array);
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      */
103 103
     public function getPluginsArray()
104 104
     {
105
-        include_once(XOOPS_ROOT_PATH . '/class/xoopslists.php');
105
+        include_once(XOOPS_ROOT_PATH.'/class/xoopslists.php');
106 106
 
107 107
         $moduleHandler = xoops_getHandler('module');
108 108
         $criteria       = new CriteriaCompo();
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
             $modulesObj[$moduleObj->getVar('dirname')] = $moduleObj;
114 114
         }
115 115
 
116
-        $aFiles = XoopsLists::getFileListAsArray(SMARTOBJECT_ROOT_PATH . 'plugins/');
116
+        $aFiles = XoopsLists::getFileListAsArray(SMARTOBJECT_ROOT_PATH.'plugins/');
117 117
         $ret    = array();
118 118
         foreach ($aFiles as $file) {
119 119
             if (substr($file, strlen($file) - 4, 4) === '.php') {
120 120
                 $pluginName                = str_replace('.php', '', $file);
121
-                $module_xoops_version_file = XOOPS_ROOT_PATH . "/modules/$pluginName/xoops_version.php";
121
+                $module_xoops_version_file = XOOPS_ROOT_PATH."/modules/$pluginName/xoops_version.php";
122 122
                 if (file_exists($module_xoops_version_file) && isset($modulesObj[$pluginName])) {
123 123
                     $ret[$pluginName] = $modulesObj[$pluginName]->getVar('name');
124 124
                 }
Please login to merge, or discard this patch.
xoops_version.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 $modversion['min_xoops']           = '2.5.8';
44 44
 $modversion['min_admin']           = '1.1';
45 45
 $modversion['min_db']              = array(
46
-    'mysql'  => '5.0.7',
47
-    'mysqli' => '5.0.7'
46
+	'mysql'  => '5.0.7',
47
+	'mysqli' => '5.0.7'
48 48
 );
49 49
 
50 50
 // ---
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 global $xoopsConfig;
75 75
 $common_file = XOOPS_ROOT_PATH . '/modules/smartobject/language/' . $xoopsConfig['language'] . '/common.php';
76 76
 if (file_exists($common_file)) {
77
-    $flag_common = true;
78
-    include_once $common_file;
77
+	$flag_common = true;
78
+	include_once $common_file;
79 79
 } else {
80
-    include_once(XOOPS_ROOT_PATH . '/modules/smartobject/language/english/common.php');
80
+	include_once(XOOPS_ROOT_PATH . '/modules/smartobject/language/english/common.php');
81 81
 }
82 82
 // -----
83 83
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 //about
37 37
 $modversion['module_status']       = 'RC 1';
38 38
 $modversion['release_date']        = '2016/03/28';
39
-$modversion['release_file']        = XOOPS_URL . '/modules/' . $modversion['dirname'] . '/docs/changelog.txt';
39
+$modversion['release_file']        = XOOPS_URL.'/modules/'.$modversion['dirname'].'/docs/changelog.txt';
40 40
 $modversion['module_website_url']  = 'www.xoops.org';
41 41
 $modversion['module_website_name'] = 'XOOPS';
42 42
 $modversion['min_php']             = '5.5';
@@ -72,12 +72,12 @@  discard block
 block discarded – undo
72 72
 // ----- BUG: not read other language file -----
73 73
 //include_once(XOOPS_ROOT_PATH.'/modules/smartobject/language/english/common.php');
74 74
 global $xoopsConfig;
75
-$common_file = XOOPS_ROOT_PATH . '/modules/smartobject/language/' . $xoopsConfig['language'] . '/common.php';
75
+$common_file = XOOPS_ROOT_PATH.'/modules/smartobject/language/'.$xoopsConfig['language'].'/common.php';
76 76
 if (file_exists($common_file)) {
77 77
     $flag_common = true;
78 78
     include_once $common_file;
79 79
 } else {
80
-    include_once(XOOPS_ROOT_PATH . '/modules/smartobject/language/english/common.php');
80
+    include_once(XOOPS_ROOT_PATH.'/modules/smartobject/language/english/common.php');
81 81
 }
82 82
 // -----
83 83
 
Please login to merge, or discard this patch.
include/captcha/config.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -12,29 +12,29 @@
 block discarded – undo
12 12
  */
13 13
 
14 14
 $config = array(
15
-    'mode'       => 'image',
16
-    'name'       => 'xoopscaptcha',
17
-    'skipmember' => true,                    // Skip CAPTCHA check for members
18
-    'maxattempt' => 100,                    // Maximum attempts for each session
15
+	'mode'       => 'image',
16
+	'name'       => 'xoopscaptcha',
17
+	'skipmember' => true,                    // Skip CAPTCHA check for members
18
+	'maxattempt' => 100,                    // Maximum attempts for each session
19 19
 
20
-    'num_chars'       => 4,                        // Maximum characters
20
+	'num_chars'       => 4,                        // Maximum characters
21 21
 
22
-    // For image mode, based on DuGris' SecurityImage
23
-    'rootpath'        => __DIR__,        // __Absolute__ Path to the root of fonts and backgrounds
24
-    'imagepath'       => 'uploads/captcha',        // Path to temporary image files, __relative__ to XOOPS_ROOT_PATH
25
-    'imageurl'        => 'modules/smartobject/include/captcha/scripts/img.php',        // Path to the script for creating image, __relative__ to XOOPS_ROOT_PATH
26
-    'casesensitive'   => false,                    // Characters in image mode is case-sensitive
27
-    'fontsize_min'    => 12,                    // Minimum font-size
28
-    'fontsize_max'    => 12,                    // Maximum font-size
29
-    'background_type' => 0,                        // Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files
30
-    'background_num'  => 50,                        // Number of background images to generate
31
-    'polygon_point'   => 3
22
+	// For image mode, based on DuGris' SecurityImage
23
+	'rootpath'        => __DIR__,        // __Absolute__ Path to the root of fonts and backgrounds
24
+	'imagepath'       => 'uploads/captcha',        // Path to temporary image files, __relative__ to XOOPS_ROOT_PATH
25
+	'imageurl'        => 'modules/smartobject/include/captcha/scripts/img.php',        // Path to the script for creating image, __relative__ to XOOPS_ROOT_PATH
26
+	'casesensitive'   => false,                    // Characters in image mode is case-sensitive
27
+	'fontsize_min'    => 12,                    // Minimum font-size
28
+	'fontsize_max'    => 12,                    // Maximum font-size
29
+	'background_type' => 0,                        // Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files
30
+	'background_num'  => 50,                        // Number of background images to generate
31
+	'polygon_point'   => 3
32 32
 );
33 33
 
34 34
 $language = preg_replace("/[^a-z0-9_\-]/i", '', $GLOBALS['xoopsConfig']['language']);
35 35
 
36 36
 if (!@include_once __DIR__ . "/language/{$language}.php") {
37
-    require_once __DIR__ . '/language/english.php';
37
+	require_once __DIR__ . '/language/english.php';
38 38
 }
39 39
 
40 40
 return $config;
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,27 +14,27 @@
 block discarded – undo
14 14
 $config = array(
15 15
     'mode'       => 'image',
16 16
     'name'       => 'xoopscaptcha',
17
-    'skipmember' => true,                    // Skip CAPTCHA check for members
18
-    'maxattempt' => 100,                    // Maximum attempts for each session
17
+    'skipmember' => true, // Skip CAPTCHA check for members
18
+    'maxattempt' => 100, // Maximum attempts for each session
19 19
 
20
-    'num_chars'       => 4,                        // Maximum characters
20
+    'num_chars'       => 4, // Maximum characters
21 21
 
22 22
     // For image mode, based on DuGris' SecurityImage
23
-    'rootpath'        => __DIR__,        // __Absolute__ Path to the root of fonts and backgrounds
24
-    'imagepath'       => 'uploads/captcha',        // Path to temporary image files, __relative__ to XOOPS_ROOT_PATH
25
-    'imageurl'        => 'modules/smartobject/include/captcha/scripts/img.php',        // Path to the script for creating image, __relative__ to XOOPS_ROOT_PATH
26
-    'casesensitive'   => false,                    // Characters in image mode is case-sensitive
27
-    'fontsize_min'    => 12,                    // Minimum font-size
28
-    'fontsize_max'    => 12,                    // Maximum font-size
29
-    'background_type' => 0,                        // Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files
30
-    'background_num'  => 50,                        // Number of background images to generate
23
+    'rootpath'        => __DIR__, // __Absolute__ Path to the root of fonts and backgrounds
24
+    'imagepath'       => 'uploads/captcha', // Path to temporary image files, __relative__ to XOOPS_ROOT_PATH
25
+    'imageurl'        => 'modules/smartobject/include/captcha/scripts/img.php', // Path to the script for creating image, __relative__ to XOOPS_ROOT_PATH
26
+    'casesensitive'   => false, // Characters in image mode is case-sensitive
27
+    'fontsize_min'    => 12, // Minimum font-size
28
+    'fontsize_max'    => 12, // Maximum font-size
29
+    'background_type' => 0, // Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files
30
+    'background_num'  => 50, // Number of background images to generate
31 31
     'polygon_point'   => 3
32 32
 );
33 33
 
34 34
 $language = preg_replace("/[^a-z0-9_\-]/i", '', $GLOBALS['xoopsConfig']['language']);
35 35
 
36
-if (!@include_once __DIR__ . "/language/{$language}.php") {
37
-    require_once __DIR__ . '/language/english.php';
36
+if (!@include_once __DIR__."/language/{$language}.php") {
37
+    require_once __DIR__.'/language/english.php';
38 38
 }
39 39
 
40 40
 return $config;
Please login to merge, or discard this patch.
class/smartobject.php 3 patches
Doc Comments   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
     }
166 166
 
167 167
     /**
168
-     * @param        $key
168
+     * @param        string $key
169 169
      * @param        $data_type
170 170
      * @param bool   $itemName
171 171
      * @param string $form_caption
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
194 194
      * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
195 195
      * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
196
-     * @param mixed  $value        default value of this variable
196
+     * @param string|false  $value        default value of this variable
197 197
      */
198 198
     public function quickInitVar($key, $data_type, $required = false, $form_caption = '', $form_dsc = '', $value = null)
199 199
     {
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     }
203 203
 
204 204
     /**
205
-     * @param        $varname
205
+     * @param        string $varname
206 206
      * @param bool   $displayOnForm
207 207
      * @param string $default
208 208
      */
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
     /**
459 459
      * add an error
460 460
      *
461
-     * @param      $err_str
461
+     * @param      string $err_str
462 462
      * @param bool $prefix
463 463
      * @internal param string $value error to add
464 464
      * @access   public
@@ -720,8 +720,8 @@  discard block
 block discarded – undo
720 720
 
721 721
     /**
722 722
      * @param $key
723
-     * @param $info
724
-     * @param $value
723
+     * @param string $info
724
+     * @param boolean $value
725 725
      */
726 726
     public function setVarInfo($key, $info, $value)
727 727
     {
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
     }
730 730
 
731 731
     /**
732
-     * @param         $key
732
+     * @param         string $key
733 733
      * @param  bool   $editor
734 734
      * @return string
735 735
      */
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
      * @access public
907 907
      * @param  string $key    key of the object's variable to be returned
908 908
      * @param  string $format format to use for the output
909
-     * @return mixed  formatted value of the variable
909
+     * @return string  formatted value of the variable
910 910
      */
911 911
     public function getVar($key, $format = 's')
912 912
     {
@@ -1209,7 +1209,7 @@  discard block
 block discarded – undo
1209 1209
     }
1210 1210
 
1211 1211
     /**
1212
-     * @param $key
1212
+     * @param string $key
1213 1213
      */
1214 1214
     public function hideFieldFromForm($key)
1215 1215
     {
Please login to merge, or discard this patch.
Indentation   +1360 added lines, -1360 removed lines patch added patch discarded remove patch
@@ -17,31 +17,31 @@  discard block
 block discarded – undo
17 17
 include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
18 18
 
19 19
 if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) {
20
-    define('XOBJ_DTYPE_SIMPLE_ARRAY', 101);
20
+	define('XOBJ_DTYPE_SIMPLE_ARRAY', 101);
21 21
 }
22 22
 if (!defined('XOBJ_DTYPE_CURRENCY')) {
23
-    define('XOBJ_DTYPE_CURRENCY', 200);
23
+	define('XOBJ_DTYPE_CURRENCY', 200);
24 24
 }
25 25
 if (!defined('XOBJ_DTYPE_FLOAT')) {
26
-    define('XOBJ_DTYPE_FLOAT', 201);
26
+	define('XOBJ_DTYPE_FLOAT', 201);
27 27
 }
28 28
 if (!defined('XOBJ_DTYPE_TIME_ONLY')) {
29
-    define('XOBJ_DTYPE_TIME_ONLY', 202);
29
+	define('XOBJ_DTYPE_TIME_ONLY', 202);
30 30
 }
31 31
 if (!defined('XOBJ_DTYPE_URLLINK')) {
32
-    define('XOBJ_DTYPE_URLLINK', 203);
32
+	define('XOBJ_DTYPE_URLLINK', 203);
33 33
 }
34 34
 if (!defined('XOBJ_DTYPE_FILE')) {
35
-    define('XOBJ_DTYPE_FILE', 204);
35
+	define('XOBJ_DTYPE_FILE', 204);
36 36
 }
37 37
 if (!defined('XOBJ_DTYPE_IMAGE')) {
38
-    define('XOBJ_DTYPE_IMAGE', 205);
38
+	define('XOBJ_DTYPE_IMAGE', 205);
39 39
 }
40 40
 if (!defined('XOBJ_DTYPE_FORM_SECTION')) {
41
-    define('XOBJ_DTYPE_FORM_SECTION', 210);
41
+	define('XOBJ_DTYPE_FORM_SECTION', 210);
42 42
 }
43 43
 if (!defined('XOBJ_DTYPE_FORM_SECTION_CLOSE')) {
44
-    define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211);
44
+	define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211);
45 45
 }
46 46
 
47 47
 /**
@@ -55,1355 +55,1355 @@  discard block
 block discarded – undo
55 55
  */
56 56
 class SmartObject extends XoopsObject
57 57
 {
58
-    public $_image_path;
59
-    public $_image_url;
60
-
61
-    public $seoEnabled   = false;
62
-    public $titleField;
63
-    public $summaryField = false;
64
-
65
-    /**
66
-     * Reference to the handler managing this object
67
-     *
68
-     * @var SmartPersistableObjectHandler reference to {@link SmartPersistableObjectHandler}
69
-     */
70
-    public $handler;
71
-
72
-    /**
73
-     * References to control objects, managing the form fields of this object
74
-     */
75
-    public $controls = array();
76
-
77
-    /**
78
-     * SmartObject constructor.
79
-     * @param $handler
80
-     */
81
-    public function __construct($handler)
82
-    {
83
-        $this->handler = $handler;
84
-    }
85
-
86
-    /**
87
-     * Checks if the user has a specific access on this object
88
-     *
89
-     * @param $perm_name
90
-     * @return bool: TRUE if user has access, false if not
91
-     * @internal param string $gperm_name name of the permission to test
92
-     */
93
-    public function accessGranted($perm_name)
94
-    {
95
-        $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
96
-
97
-        return $smartPermissionsHandler->accessGranted($perm_name, $this->id());
98
-    }
99
-
100
-    /**
101
-     * @param      $section_name
102
-     * @param bool $value
103
-     * @param bool $hide
104
-     */
105
-    public function addFormSection($section_name, $value = false, $hide = false)
106
-    {
107
-        $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true);
108
-        $this->vars[$section_name]['hide'] = $hide;
109
-    }
110
-
111
-    /**
112
-     * @param $section_name
113
-     */
114
-    public function closeSection($section_name)
115
-    {
116
-        $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
117
-    }
118
-
119
-    /**
120
-     *
121
-     * @param string $key           key of this field. This needs to be the name of the field in the related database table
122
-     * @param int    $data_type     set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
123
-     * @param mixed  $value         default value of this variable
124
-     * @param bool   $required      set to TRUE if this variable needs to have a value set before storing the object in the table
125
-     * @param int    $maxlength     maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only
126
-     * @param string $options       does this data have any select options?
127
-     * @param bool   $multilingual  is this field needs to support multilingual features (NOT YET IMPLEMENTED...)
128
-     * @param string $form_caption  caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
129
-     * @param string $form_dsc      description of this variable in a {@link SmartobjectForm}
130
-     * @param bool   $sortby        set to TRUE to make this field used to sort objects in SmartObjectTable
131
-     * @param bool   $persistent    set to FALSE if this field is not to be saved in the database
132
-     * @param bool   $displayOnForm
133
-     */
134
-    public function initVar($key, $data_type, $value = null, $required = false, $maxlength = null, $options = '', $multilingual = false, $form_caption = '', $form_dsc = '', $sortby = false,
135
-                            $persistent = true, $displayOnForm = true
136
-    ) {
137
-        //url_ is reserved for files.
138
-        if (0 === strpos($key, 'url_')) {
139
-            trigger_error("Cannot use variable starting with 'url_'.");
140
-        }
141
-        parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
142
-        if ($this->handler && (!$form_caption || $form_caption === '')) {
143
-            $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
144
-            if (defined($dyn_form_caption)) {
145
-                $form_caption = constant($dyn_form_caption);
146
-            }
147
-        }
148
-        if ($this->handler && (!$form_dsc || $form_dsc === '')) {
149
-            $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
150
-            if (defined($dyn_form_dsc)) {
151
-                $form_dsc = constant($dyn_form_dsc);
152
-            }
153
-        }
154
-
155
-        $this->vars[$key] = array_merge($this->vars[$key], array(
156
-            'multilingual'        => $multilingual,
157
-            'form_caption'        => $form_caption,
158
-            'form_dsc'            => $form_dsc,
159
-            'sortby'              => $sortby,
160
-            'persistent'          => $persistent,
161
-            'displayOnForm'       => $displayOnForm,
162
-            'displayOnSingleView' => true,
163
-            'readonly'            => false
164
-        ));
165
-    }
166
-
167
-    /**
168
-     * @param        $key
169
-     * @param        $data_type
170
-     * @param bool   $itemName
171
-     * @param string $form_caption
172
-     * @param bool   $sortby
173
-     * @param string $value
174
-     * @param bool   $displayOnForm
175
-     * @param bool   $required
176
-     */
177
-    public function initNonPersistableVar($key, $data_type, $itemName = false, $form_caption = '', $sortby = false, $value = '', $displayOnForm = false, $required = false)
178
-    {
179
-        $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm);
180
-        $this->vars[$key]['itemName'] = $itemName;
181
-    }
182
-
183
-    /**
184
-     * Quickly initiate a var
185
-     *
186
-     * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-)
187
-     *
188
-     * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255
189
-     * - all other vars are NULL or '' depending of the parameter
190
-     *
191
-     * @param string $key          key of this field. This needs to be the name of the field in the related database table
192
-     * @param int    $data_type    set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
193
-     * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
194
-     * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
195
-     * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
196
-     * @param mixed  $value        default value of this variable
197
-     */
198
-    public function quickInitVar($key, $data_type, $required = false, $form_caption = '', $form_dsc = '', $value = null)
199
-    {
200
-        $maxlength = $data_type === 'XOBJ_DTYPE_TXTBOX' ? 255 : null;
201
-        $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true);
202
-    }
203
-
204
-    /**
205
-     * @param        $varname
206
-     * @param bool   $displayOnForm
207
-     * @param string $default
208
-     */
209
-    public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined')
210
-    {
211
-        switch ($varname) {
212
-            case 'dohtml':
213
-                $value = $default !== 'notdefined' ? $default : true;
214
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm);
215
-                $this->setControl($varname, 'yesno');
216
-                break;
217
-
218
-            case 'dobr':
219
-                $value = ($default === 'notdefined') ? true : $default;
220
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm);
221
-                $this->setControl($varname, 'yesno');
222
-                break;
223
-
224
-            case 'doimage':
225
-                $value = $default !== 'notdefined' ? $default : true;
226
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm);
227
-                $this->setControl($varname, 'yesno');
228
-                break;
229
-
230
-            case 'dosmiley':
231
-                $value = $default !== 'notdefined' ? $default : true;
232
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm);
233
-                $this->setControl($varname, 'yesno');
234
-                break;
235
-
236
-            case 'doxcode':
237
-                $value = $default !== 'notdefined' ? $default : true;
238
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm);
239
-                $this->setControl($varname, 'yesno');
240
-                break;
241
-
242
-            case 'meta_keywords':
243
-                $value = $default !== 'notdefined' ? $default : '';
244
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm);
245
-                $this->setControl('meta_keywords', array(
246
-                    'name'        => 'textarea',
247
-                    'form_editor' => 'textarea'
248
-                ));
249
-                break;
250
-
251
-            case 'meta_description':
252
-                $value = $default !== 'notdefined' ? $default : '';
253
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm);
254
-                $this->setControl('meta_description', array(
255
-                    'name'        => 'textarea',
256
-                    'form_editor' => 'textarea'
257
-                ));
258
-                break;
259
-
260
-            case 'short_url':
261
-                $value = $default !== 'notdefined' ? $default : '';
262
-                $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm);
263
-                break;
264
-
265
-            case 'hierarchy_path':
266
-                $value = $default !== 'notdefined' ? $default : '';
267
-                $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm);
268
-                break;
269
-
270
-            case 'counter':
271
-                $value = $default !== 'notdefined' ? $default : 0;
272
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm);
273
-                break;
274
-
275
-            case 'weight':
276
-                $value = $default !== 'notdefined' ? $default : 0;
277
-                $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm);
278
-                break;
279
-            case 'custom_css':
280
-                $value = $default !== 'notdefined' ? $default : '';
281
-                $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm);
282
-                $this->setControl('custom_css', array(
283
-                    'name'        => 'textarea',
284
-                    'form_editor' => 'textarea'
285
-                ));
286
-                break;
287
-        }
288
-        $this->hideFieldFromSingleView($varname);
289
-    }
290
-
291
-    /**
292
-     * Set control information for an instance variable
293
-     *
294
-     * The $options parameter can be a string or an array. Using a string
295
-     * is the quickest way:
296
-     *
297
-     * $this->setControl('date', 'date_time');
298
-     *
299
-     * This will create a date and time selectbox for the 'date' var on the
300
-     * form to edit or create this item.
301
-     *
302
-     * Here are the currently supported controls:
303
-     *
304
-     *      - color
305
-     *      - country
306
-     *      - date_time
307
-     *      - date
308
-     *      - email
309
-     *      - group
310
-     *      - group_multi
311
-     *      - image
312
-     *      - imageupload
313
-     *      - label
314
-     *      - language
315
-     *      - parentcategory
316
-     *      - password
317
-     *      - select_multi
318
-     *      - select
319
-     *      - text
320
-     *      - textarea
321
-     *      - theme
322
-     *      - theme_multi
323
-     *      - timezone
324
-     *      - user
325
-     *      - user_multi
326
-     *      - yesno
327
-     *
328
-     * Now, using an array as $options, you can customize what information to
329
-     * use in the control. For example, if one needs to display a select box for
330
-     * the user to choose the status of an item. We only need to tell SmartObject
331
-     * what method to execute within what handler to retreive the options of the
332
-     * selectbox.
333
-     *
334
-     * $this->setControl('status', array('name' => false,
335
-     *                                   'itemHandler' => 'item',
336
-     *                                   'method' => 'getStatus',
337
-     *                                   'module' => 'smartshop'));
338
-     *
339
-     * In this example, the array elements are the following:
340
-     *      - name: false, as we don't need to set a special control here.
341
-     *               we will use the default control related to the object type (defined in initVar)
342
-     *      - itemHandler: name of the object for which we will use the handler
343
-     *      - method: name of the method of this handler that we will execute
344
-     *      - module: name of the module from wich the handler is
345
-     *
346
-     * So in this example, SmartObject will create a selectbox for the variable 'status' and it will
347
-     * populate this selectbox with the result from SmartshopItemHandler::getStatus()
348
-     *
349
-     * Another example of the use of $options as an array is for TextArea:
350
-     *
351
-     * $this->setControl('body', array('name' => 'textarea',
352
-     *                                   'form_editor' => 'default'));
353
-     *
354
-     * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use
355
-     * the 'default' editor, providing it is defined in the module
356
-     * preferences: $xoopsModuleConfig['default_editor']
357
-     *
358
-     * Of course, you can force the use of a specific editor:
359
-     *
360
-     * $this->setControl('body', array('name' => 'textarea',
361
-     *                                   'form_editor' => 'koivi'));
362
-     *
363
-     * Here is a list of supported editor:
364
-     *      - tiny: TinyEditor
365
-     *      - dhtmltextarea: XOOPS DHTML Area
366
-     *      - fckeditor: FCKEditor
367
-     *      - inbetween: InBetween
368
-     *      - koivi: Koivi
369
-     *      - spaw: Spaw WYSIWYG Editor
370
-     *      - htmlarea: HTMLArea
371
-     *      - textarea: basic textarea with no options
372
-     *
373
-     * @param string $var     name of the variable for which we want to set a control
374
-     * @param array  $options
375
-     */
376
-    public function setControl($var, $options = array())
377
-    {
378
-        if (isset($this->controls[$var])) {
379
-            unset($this->controls[$var]);
380
-        }
381
-        if (is_string($options)) {
382
-            $options = array('name' => $options);
383
-        }
384
-        $this->controls[$var] = $options;
385
-    }
386
-
387
-    /**
388
-     * Get control information for an instance variable
389
-     *
390
-     * @param  string     $var
391
-     * @return bool|mixed
392
-     */
393
-    public function getControl($var)
394
-    {
395
-        return isset($this->controls[$var]) ? $this->controls[$var] : false;
396
-    }
397
-
398
-    /**
399
-     * Create the form for this object
400
-     *
401
-     * @param         $form_caption
402
-     * @param         $form_name
403
-     * @param  bool   $form_action
404
-     * @param  string $submit_button_caption
405
-     * @param  bool   $cancel_js_action
406
-     * @param  bool   $captcha
407
-     * @return a      <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object
408
-     *                                      object for this object
409
-     * @see SmartObjectForm::SmartObjectForm()
410
-     */
411
-    public function getForm($form_caption, $form_name, $form_action = false, $submit_button_caption = _CO_SOBJECT_SUBMIT, $cancel_js_action = false, $captcha = false)
412
-    {
413
-        include_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php';
414
-        $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha);
415
-
416
-        return $form;
417
-    }
418
-
419
-    /**
420
-     * @return array
421
-     */
422
-    public function toArray()
423
-    {
424
-        $ret  = array();
425
-        $vars =& $this->getVars();
426
-        foreach ($vars as $key => $var) {
427
-            $value     = $this->getVar($key);
428
-            $ret[$key] = $value;
429
-        }
430
-        if ($this->handler->identifierName !== '') {
431
-            $controller = new SmartObjectController($this->handler);
432
-            /**
433
-             * Addition of some automatic value
434
-             */
435
-            $ret['itemLink']         = $controller->getItemLink($this);
436
-            $ret['itemUrl']          = $controller->getItemLink($this, true);
437
-            $ret['editItemLink']     = $controller->getEditItemLink($this, false, true);
438
-            $ret['deleteItemLink']   = $controller->getDeleteItemLink($this, false, true);
439
-            $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this);
440
-        }
441
-
442
-        // Hightlighting searched words
443
-        include_once(SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php');
444
-        $highlight = smart_getConfig('module_search_highlighter', false, true);
445
-
446
-        if ($highlight && isset($_GET['keywords'])) {
447
-            $myts     = MyTextSanitizer::getInstance();
448
-            $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords'])));
449
-            $h        = new SmartHighlighter($keywords, true, 'smart_highlighter');
450
-            foreach ($this->handler->highlightFields as $field) {
451
-                $ret[$field] = $h->highlight($ret[$field]);
452
-            }
453
-        }
454
-
455
-        return $ret;
456
-    }
457
-
458
-    /**
459
-     * add an error
460
-     *
461
-     * @param      $err_str
462
-     * @param bool $prefix
463
-     * @internal param string $value error to add
464
-     * @access   public
465
-     */
466
-    public function setErrors($err_str, $prefix = false)
467
-    {
468
-        if (is_array($err_str)) {
469
-            foreach ($err_str as $str) {
470
-                $this->setErrors($str, $prefix);
471
-            }
472
-        } else {
473
-            if ($prefix) {
474
-                $err_str = '[' . $prefix . '] ' . $err_str;
475
-            }
476
-            parent::setErrors($err_str);
477
-        }
478
-    }
479
-
480
-    /**
481
-     * @param      $field
482
-     * @param bool $required
483
-     */
484
-    public function setFieldAsRequired($field, $required = true)
485
-    {
486
-        if (is_array($field)) {
487
-            foreach ($field as $v) {
488
-                $this->doSetFieldAsRequired($v, $required);
489
-            }
490
-        } else {
491
-            $this->doSetFieldAsRequired($field, $required);
492
-        }
493
-    }
494
-
495
-    /**
496
-     * @param $field
497
-     */
498
-    public function setFieldForSorting($field)
499
-    {
500
-        if (is_array($field)) {
501
-            foreach ($field as $v) {
502
-                $this->doSetFieldForSorting($v);
503
-            }
504
-        } else {
505
-            $this->doSetFieldForSorting($field);
506
-        }
507
-    }
508
-
509
-    /**
510
-     * @return bool
511
-     */
512
-    public function hasError()
513
-    {
514
-        return count($this->_errors) > 0;
515
-    }
516
-
517
-    /**
518
-     * @param $url
519
-     * @param $path
520
-     */
521
-    public function setImageDir($url, $path)
522
-    {
523
-        $this->_image_url  = $url;
524
-        $this->_image_path = $path;
525
-    }
526
-
527
-    /**
528
-     * Retreive the group that have been granted access to a specific permission for this object
529
-     *
530
-     * @param $group_perm
531
-     * @return string $group_perm name of the permission
532
-     */
533
-    public function getGroupPerm($group_perm)
534
-    {
535
-        if (!$this->handler->getPermissions()) {
536
-            $this->setError("Trying to access a permission that does not exists for thisobject's handler");
537
-
538
-            return false;
539
-        }
540
-
541
-        $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
542
-        $ret                     = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id());
543
-
544
-        if (count($ret) == 0) {
545
-            return false;
546
-        } else {
547
-            return $ret;
548
-        }
549
-    }
550
-
551
-    /**
552
-     * @param  bool  $path
553
-     * @return mixed
554
-     */
555
-    public function getImageDir($path = false)
556
-    {
557
-        if ($path) {
558
-            return $this->_image_path;
559
-        } else {
560
-            return $this->_image_url;
561
-        }
562
-    }
563
-
564
-    /**
565
-     * @param  bool  $path
566
-     * @return mixed
567
-     */
568
-    public function getUploadDir($path = false)
569
-    {
570
-        if ($path) {
571
-            return $this->_image_path;
572
-        } else {
573
-            return $this->_image_url;
574
-        }
575
-    }
576
-
577
-    /**
578
-     * @param  string $key
579
-     * @param  string $info
580
-     * @return array
581
-     */
582
-    public function getVarInfo($key = '', $info = '')
583
-    {
584
-        if (isset($this->vars[$key][$info])) {
585
-            return $this->vars[$key][$info];
586
-        } elseif ($info === '' && isset($this->vars[$key])) {
587
-            return $this->vars[$key];
588
-        } else {
589
-            return $this->vars;
590
-        }
591
-    }
592
-
593
-    /**
594
-     * Get the id of the object
595
-     *
596
-     * @return int id of this object
597
-     */
598
-    public function id()
599
-    {
600
-        return $this->getVar($this->handler->keyName, 'e');
601
-    }
602
-
603
-    /**
604
-     * Return the value of the title field of this object
605
-     *
606
-     * @param  string $format
607
-     * @return string
608
-     */
609
-    public function title($format = 's')
610
-    {
611
-        return $this->getVar($this->handler->identifierName, $format);
612
-    }
613
-
614
-    /**
615
-     * Return the value of the title field of this object
616
-     *
617
-     * @return string
618
-     */
619
-    public function summary()
620
-    {
621
-        if ($this->handler->summaryName) {
622
-            return $this->getVar($this->handler->summaryName);
623
-        } else {
624
-            return false;
625
-        }
626
-    }
627
-
628
-    /**
629
-     * Retreive the object admin side link, displayijng a SingleView page
630
-     *
631
-     * @param  bool   $onlyUrl wether or not to return a simple URL or a full <a> link
632
-     * @return string user side link to the object
633
-     */
634
-    public function getAdminViewItemLink($onlyUrl = false)
635
-    {
636
-        $controller = new SmartObjectController($this->handler);
637
-
638
-        return $controller->getAdminViewItemLink($this, $onlyUrl);
639
-    }
640
-
641
-    /**
642
-     * Retreive the object user side link
643
-     *
644
-     * @param  bool   $onlyUrl wether or not to return a simple URL or a full <a> link
645
-     * @return string user side link to the object
646
-     */
647
-    public function getItemLink($onlyUrl = false)
648
-    {
649
-        $controller = new SmartObjectController($this->handler);
650
-
651
-        return $controller->getItemLink($this, $onlyUrl);
652
-    }
653
-
654
-    /**
655
-     * @param  bool   $onlyUrl
656
-     * @param  bool   $withimage
657
-     * @param  bool   $userSide
658
-     * @return string
659
-     */
660
-    public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false)
661
-    {
662
-        $controller = new SmartObjectController($this->handler);
663
-
664
-        return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide);
665
-    }
666
-
667
-    /**
668
-     * @param  bool   $onlyUrl
669
-     * @param  bool   $withimage
670
-     * @param  bool   $userSide
671
-     * @return string
672
-     */
673
-    public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false)
674
-    {
675
-        $controller = new SmartObjectController($this->handler);
676
-
677
-        return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide);
678
-    }
679
-
680
-    /**
681
-     * @return string
682
-     */
683
-    public function getPrintAndMailLink()
684
-    {
685
-        $controller = new SmartObjectController($this->handler);
686
-
687
-        return $controller->getPrintAndMailLink($this);
688
-    }
689
-
690
-    /**
691
-     * @param $sortsel
692
-     * @return array|bool
693
-     */
694
-    public function getFieldsForSorting($sortsel)
695
-    {
696
-        $ret = array();
697
-
698
-        foreach ($this->vars as $key => $field_info) {
699
-            if ($field_info['sortby']) {
700
-                $ret[$key]['caption']  = $field_info['form_caption'];
701
-                $ret[$key]['selected'] = $key == $sortsel ? "selected='selected'" : '';
702
-            }
703
-        }
704
-
705
-        if (count($ret) > 0) {
706
-            return $ret;
707
-        } else {
708
-            return false;
709
-        }
710
-    }
711
-
712
-    /**
713
-     * @param $key
714
-     * @param $newType
715
-     */
716
-    public function setType($key, $newType)
717
-    {
718
-        $this->vars[$key]['data_type'] = $newType;
719
-    }
720
-
721
-    /**
722
-     * @param $key
723
-     * @param $info
724
-     * @param $value
725
-     */
726
-    public function setVarInfo($key, $info, $value)
727
-    {
728
-        $this->vars[$key][$info] = $value;
729
-    }
730
-
731
-    /**
732
-     * @param         $key
733
-     * @param  bool   $editor
734
-     * @return string
735
-     */
736
-    public function getValueFor($key, $editor = true)
737
-    {
738
-        global $xoopsModuleConfig;
739
-
740
-        $ret  = $this->getVar($key, 'n');
741
-        $myts = MyTextSanitizer::getInstance();
742
-
743
-        $control     = isset($this->controls[$key]) ? $this->controls[$key] : false;
744
-        $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
745
-
746
-        $html     = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true;
747
-        $smiley   = true;
748
-        $xcode    = true;
749
-        $image    = true;
750
-        $br       = isset($this->vars['dobr']) ? $this->getVar('dobr') : true;
751
-        $formatML = true;
752
-
753
-        if ($form_editor === 'default') {
754
-            global $xoopsModuleConfig;
755
-            $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea';
756
-        }
757
-
758
-        if ($editor) {
759
-            if (defined('XOOPS_EDITOR_IS_HTML') && !in_array($form_editor, array('formtextarea', 'textarea', 'dhtmltextarea'))) {
760
-                $br       = false;
761
-                $formatML = !$editor;
762
-            } else {
763
-                return htmlspecialchars($ret, ENT_QUOTES);
764
-            }
765
-        }
766
-
767
-        if (method_exists($myts, 'formatForML')) {
768
-            return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML);
769
-        } else {
770
-            return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
771
-        }
772
-    }
773
-
774
-    /**
775
-     * clean values of all variables of the object for storage.
776
-     * also add slashes whereever needed
777
-     *
778
-     * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
779
-     * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
780
-     * as a string separated by |
781
-     *
782
-     * @return bool true if successful
783
-     * @access public
784
-     */
785
-    public function cleanVars()
786
-    {
787
-        $ts              = MyTextSanitizer::getInstance();
788
-        $existing_errors = $this->getErrors();
789
-        $this->_errors   = array();
790
-        foreach ($this->vars as $k => $v) {
791
-            $cleanv = $v['value'];
792
-            if (!$v['changed']) {
793
-            } else {
794
-                $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv;
795
-                switch ($v['data_type']) {
796
-                    case XOBJ_DTYPE_TXTBOX:
797
-                        if ($v['required'] && $cleanv != '0' && $cleanv == '') {
798
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
799
-                            continue 2;
800
-                        }
801
-                        if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) {
802
-                            $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength']));
803
-                            continue 2;
804
-                        }
805
-                        if (!$v['not_gpc']) {
806
-                            $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
807
-                        } else {
808
-                            $cleanv = $ts->censorString($cleanv);
809
-                        }
810
-                        break;
811
-                    case XOBJ_DTYPE_TXTAREA:
812
-                        if ($v['required'] && $cleanv != '0' && $cleanv == '') {
813
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
814
-                            continue 2;
815
-                        }
816
-                        if (!$v['not_gpc']) {
817
-                            $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
818
-                        } else {
819
-                            $cleanv = $ts->censorString($cleanv);
820
-                        }
821
-                        break;
822
-                    case XOBJ_DTYPE_SOURCE:
823
-                        if (!$v['not_gpc']) {
824
-                            $cleanv = $ts->stripSlashesGPC($cleanv);
825
-                        } else {
826
-                            $cleanv = $cleanv;
827
-                        }
828
-                        break;
829
-                    case XOBJ_DTYPE_INT:
830
-                    case XOBJ_DTYPE_TIME_ONLY:
831
-                        $cleanv = (int)$cleanv;
832
-                        break;
833
-
834
-                    case XOBJ_DTYPE_CURRENCY:
835
-                        $cleanv = smart_currency($cleanv);
836
-                        break;
837
-
838
-                    case XOBJ_DTYPE_FLOAT:
839
-                        $cleanv = smart_float($cleanv);
840
-                        break;
841
-
842
-                    case XOBJ_DTYPE_EMAIL:
843
-                        if ($v['required'] && $cleanv === '') {
844
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
845
-                            continue 2;
846
-                        }
847
-                        if ($cleanv !== '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) {
848
-                            $this->setErrors('Invalid Email');
849
-                            continue 2;
850
-                        }
851
-                        if (!$v['not_gpc']) {
852
-                            $cleanv = $ts->stripSlashesGPC($cleanv);
853
-                        }
854
-                        break;
855
-                    case XOBJ_DTYPE_URL:
856
-                        if ($v['required'] && $cleanv === '') {
857
-                            $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
858
-                            continue 2;
859
-                        }
860
-                        if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
861
-                            $cleanv = 'http://' . $cleanv;
862
-                        }
863
-                        if (!$v['not_gpc']) {
864
-                            $cleanv =& $ts->stripSlashesGPC($cleanv);
865
-                        }
866
-                        break;
867
-                    case XOBJ_DTYPE_SIMPLE_ARRAY:
868
-                        $cleanv = implode('|', $cleanv);
869
-                        break;
870
-                    case XOBJ_DTYPE_ARRAY:
871
-                        $cleanv = serialize($cleanv);
872
-                        break;
873
-                    case XOBJ_DTYPE_STIME:
874
-                    case XOBJ_DTYPE_MTIME:
875
-                    case XOBJ_DTYPE_LTIME:
876
-                        $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
877
-                        if (!($cleanv > 0)) {
878
-                            $cleanv = strtotime($cleanv);
879
-                        }
880
-                        break;
881
-                    default:
882
-                        break;
883
-                }
884
-            }
885
-            $this->cleanVars[$k] =& $cleanv;
886
-            unset($cleanv);
887
-        }
888
-        if (count($this->_errors) > 0) {
889
-            $this->_errors = array_merge($existing_errors, $this->_errors);
890
-
891
-            return false;
892
-        }
893
-        $this->_errors = array_merge($existing_errors, $this->_errors);
894
-        $this->unsetDirty();
895
-
896
-        return true;
897
-    }
898
-
899
-    /**
900
-     * returns a specific variable for the object in a proper format
901
-     *
902
-     * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
903
-     * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
904
-     * as a string separated by |
905
-     *
906
-     * @access public
907
-     * @param  string $key    key of the object's variable to be returned
908
-     * @param  string $format format to use for the output
909
-     * @return mixed  formatted value of the variable
910
-     */
911
-    public function getVar($key, $format = 's')
912
-    {
913
-        global $myts;
914
-
915
-        $ret = $this->vars[$key]['value'];
916
-
917
-        switch ($this->vars[$key]['data_type']) {
918
-
919
-            case XOBJ_DTYPE_TXTBOX:
920
-                switch (strtolower($format)) {
921
-                    case 's':
922
-                    case 'show':
923
-                        // ML Hack by marcan
924
-                        $ts  = MyTextSanitizer::getInstance();
925
-                        $ret = $ts->htmlSpecialChars($ret);
926
-
927
-                        if (method_exists($myts, 'formatForML')) {
928
-                            return $ts->formatForML($ret);
929
-                        } else {
930
-                            return $ret;
931
-                        }
932
-                        break 1;
933
-                    // End of ML Hack by marcan
934
-
935
-                    case 'clean':
936
-                        $ts = MyTextSanitizer::getInstance();
937
-
938
-                        $ret = smart_html2text($ret);
939
-                        $ret = smart_purifyText($ret);
940
-
941
-                        if (method_exists($myts, 'formatForML')) {
942
-                            return $ts->formatForML($ret);
943
-                        } else {
944
-                            return $ret;
945
-                        }
946
-                        break 1;
947
-                    // End of ML Hack by marcan
948
-
949
-                    case 'e':
950
-                    case 'edit':
951
-                        $ts = MyTextSanitizer::getInstance();
952
-
953
-                        return $ts->htmlSpecialChars($ret);
954
-                        break 1;
955
-                    case 'p':
956
-                    case 'preview':
957
-                    case 'f':
958
-                    case 'formpreview':
959
-                        $ts = MyTextSanitizer::getInstance();
960
-
961
-                        return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret));
962
-                        break 1;
963
-                    case 'n':
964
-                    case 'none':
965
-                    default:
966
-                        break 1;
967
-                }
968
-                break;
969
-            case XOBJ_DTYPE_LTIME:
970
-                switch (strtolower($format)) {
971
-                    case 's':
972
-                    case 'show':
973
-                    case 'p':
974
-                    case 'preview':
975
-                    case 'f':
976
-                    case 'formpreview':
977
-                        $ret = formatTimestamp($ret, _DATESTRING);
978
-
979
-                        return $ret;
980
-                        break 1;
981
-                    case 'n':
982
-                    case 'none':
983
-                    case 'e':
984
-                    case 'edit':
985
-                        break 1;
986
-                    default:
987
-                        break 1;
988
-                }
989
-                break;
990
-            case XOBJ_DTYPE_STIME:
991
-                switch (strtolower($format)) {
992
-                    case 's':
993
-                    case 'show':
994
-                    case 'p':
995
-                    case 'preview':
996
-                    case 'f':
997
-                    case 'formpreview':
998
-                        $ret = formatTimestamp($ret, _SHORTDATESTRING);
999
-
1000
-                        return $ret;
1001
-                        break 1;
1002
-                    case 'n':
1003
-                    case 'none':
1004
-                    case 'e':
1005
-                    case 'edit':
1006
-                        break 1;
1007
-                    default:
1008
-                        break 1;
1009
-                }
1010
-                break;
1011
-            case XOBJ_DTYPE_TIME_ONLY:
1012
-                switch (strtolower($format)) {
1013
-                    case 's':
1014
-                    case 'show':
1015
-                    case 'p':
1016
-                    case 'preview':
1017
-                    case 'f':
1018
-                    case 'formpreview':
1019
-                        $ret = formatTimestamp($ret, 'G:i');
1020
-
1021
-                        return $ret;
1022
-                        break 1;
1023
-                    case 'n':
1024
-                    case 'none':
1025
-                    case 'e':
1026
-                    case 'edit':
1027
-                        break 1;
1028
-                    default:
1029
-                        break 1;
1030
-                }
1031
-                break;
1032
-
1033
-            case XOBJ_DTYPE_CURRENCY:
1034
-                $decimal_section_original = strstr($ret, '.');
1035
-                $decimal_section          = $decimal_section_original;
1036
-                if ($decimal_section) {
1037
-                    if (strlen($decimal_section) == 1) {
1038
-                        $decimal_section = '.00';
1039
-                    } elseif (strlen($decimal_section) == 2) {
1040
-                        $decimal_section .= '0';
1041
-                    }
1042
-                    $ret = str_replace($decimal_section_original, $decimal_section, $ret);
1043
-                } else {
1044
-                    $ret .= '.00';
1045
-                }
1046
-                break;
1047
-
1048
-            case XOBJ_DTYPE_TXTAREA:
1049
-                switch (strtolower($format)) {
1050
-                    case 's':
1051
-                    case 'show':
1052
-                        $ts   = MyTextSanitizer::getInstance();
1053
-                        $html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1054
-
1055
-                        $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
1056
-
1057
-                        $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
1058
-                        $image  = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
1059
-                        $br     = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
1060
-
1061
-                        /**
1062
-                         * Hack by marcan <INBOX> for SCSPRO
1063
-                         * Setting mastop as the main editor
1064
-                         */
1065
-                        if (defined('XOOPS_EDITOR_IS_HTML')) {
1066
-                            $br = false;
1067
-                        }
1068
-                        /**
1069
-                         * Hack by marcan <INBOX> for SCSPRO
1070
-                         * Setting mastop as the main editor
1071
-                         */
1072
-
1073
-                        return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
1074
-                        break 1;
1075
-                    case 'e':
1076
-                    case 'edit':
1077
-                        return htmlspecialchars($ret, ENT_QUOTES);
1078
-                        break 1;
1079
-                    case 'p':
1080
-                    case 'preview':
1081
-                        $ts     = MyTextSanitizer::getInstance();
1082
-                        $html   = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1083
-                        $xcode  = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
1084
-                        $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
1085
-                        $image  = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
1086
-                        $br     = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
1087
-
1088
-                        return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br);
1089
-                        break 1;
1090
-                    case 'f':
1091
-                    case 'formpreview':
1092
-                        $ts = MyTextSanitizer::getInstance();
1093
-
1094
-                        return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1095
-                        break 1;
1096
-                    case 'n':
1097
-                    case 'none':
1098
-                    default:
1099
-                        break 1;
1100
-                }
1101
-                break;
1102
-            case XOBJ_DTYPE_SIMPLE_ARRAY:
1103
-                $ret =& explode('|', $ret);
1104
-                break;
1105
-            case XOBJ_DTYPE_ARRAY:
1106
-                $ret =& unserialize($ret);
1107
-                break;
1108
-            case XOBJ_DTYPE_SOURCE:
1109
-                switch (strtolower($format)) {
1110
-                    case 's':
1111
-                    case 'show':
1112
-                        break 1;
1113
-                    case 'e':
1114
-                    case 'edit':
1115
-                        return htmlspecialchars($ret, ENT_QUOTES);
1116
-                        break 1;
1117
-                    case 'p':
1118
-                    case 'preview':
1119
-                        $ts = MyTextSanitizer::getInstance();
1120
-
1121
-                        return $ts->stripSlashesGPC($ret);
1122
-                        break 1;
1123
-                    case 'f':
1124
-                    case 'formpreview':
1125
-                        $ts = MyTextSanitizer::getInstance();
1126
-
1127
-                        return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1128
-                        break 1;
1129
-                    case 'n':
1130
-                    case 'none':
1131
-                    default:
1132
-                        break 1;
1133
-                }
1134
-                break;
1135
-            default:
1136
-                if ($this->vars[$key]['options'] !== '' && $ret != '') {
1137
-                    switch (strtolower($format)) {
1138
-                        case 's':
1139
-                        case 'show':
1140
-                            $selected = explode('|', $ret);
1141
-                            $options  = explode('|', $this->vars[$key]['options']);
1142
-                            $i        = 1;
1143
-                            $ret      = array();
1144
-                            foreach ($options as $op) {
1145
-                                if (in_array($i, $selected)) {
1146
-                                    $ret[] = $op;
1147
-                                }
1148
-                                ++$i;
1149
-                            }
1150
-
1151
-                            return implode(', ', $ret);
1152
-                        case 'e':
1153
-                        case 'edit':
1154
-                            $ret = explode('|', $ret);
1155
-                            break 1;
1156
-                        default:
1157
-                            break 1;
1158
-                    }
1159
-                }
1160
-                break;
1161
-        }
1162
-
1163
-        return $ret;
1164
-    }
1165
-
1166
-    /**
1167
-     * @param $key
1168
-     */
1169
-    public function doMakeFieldreadOnly($key)
1170
-    {
1171
-        if (isset($this->vars[$key])) {
1172
-            $this->vars[$key]['readonly']      = true;
1173
-            $this->vars[$key]['displayOnForm'] = true;
1174
-        }
1175
-    }
1176
-
1177
-    /**
1178
-     * @param $key
1179
-     */
1180
-    public function makeFieldReadOnly($key)
1181
-    {
1182
-        if (is_array($key)) {
1183
-            foreach ($key as $v) {
1184
-                $this->doMakeFieldreadOnly($v);
1185
-            }
1186
-        } else {
1187
-            $this->doMakeFieldreadOnly($key);
1188
-        }
1189
-    }
1190
-
1191
-    /**
1192
-     * @param $key
1193
-     */
1194
-    public function doHideFieldFromForm($key)
1195
-    {
1196
-        if (isset($this->vars[$key])) {
1197
-            $this->vars[$key]['displayOnForm'] = false;
1198
-        }
1199
-    }
1200
-
1201
-    /**
1202
-     * @param $key
1203
-     */
1204
-    public function doHideFieldFromSingleView($key)
1205
-    {
1206
-        if (isset($this->vars[$key])) {
1207
-            $this->vars[$key]['displayOnSingleView'] = false;
1208
-        }
1209
-    }
1210
-
1211
-    /**
1212
-     * @param $key
1213
-     */
1214
-    public function hideFieldFromForm($key)
1215
-    {
1216
-        if (is_array($key)) {
1217
-            foreach ($key as $v) {
1218
-                $this->doHideFieldFromForm($v);
1219
-            }
1220
-        } else {
1221
-            $this->doHideFieldFromForm($key);
1222
-        }
1223
-    }
1224
-
1225
-    /**
1226
-     * @param $key
1227
-     */
1228
-    public function hideFieldFromSingleView($key)
1229
-    {
1230
-        if (is_array($key)) {
1231
-            foreach ($key as $v) {
1232
-                $this->doHideFieldFromSingleView($v);
1233
-            }
1234
-        } else {
1235
-            $this->doHideFieldFromSingleView($key);
1236
-        }
1237
-    }
1238
-
1239
-    /**
1240
-     * @param $key
1241
-     */
1242
-    public function doShowFieldOnForm($key)
1243
-    {
1244
-        if (isset($this->vars[$key])) {
1245
-            $this->vars[$key]['displayOnForm'] = true;
1246
-        }
1247
-    }
1248
-
1249
-    /**
1250
-     * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars
1251
-     *
1252
-     * @param  bool    $fetchOnly   if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed
1253
-     * @param  bool    $userSide    for futur use, to do something different on the user side
1254
-     * @param  array   $actions
1255
-     * @param  bool    $headerAsRow
1256
-     * @return content of the template if $fetchOnly or nothing if !$fetchOnly
1257
-     */
1258
-    public function displaySingleObject($fetchOnly = false, $userSide = false, $actions = array(), $headerAsRow = true)
1259
-    {
1260
-        include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php';
1261
-        $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow);
1262
-        // add all fields mark as displayOnSingleView except the keyid
1263
-        foreach ($this->vars as $key => $var) {
1264
-            if ($key != $this->handler->keyName && $var['displayOnSingleView']) {
1265
-                $is_header = ($key == $this->handler->identifierName);
1266
-                $singleview->addRow(new SmartObjectRow($key, false, $is_header));
1267
-            }
1268
-        }
1269
-
1270
-        if ($fetchOnly) {
1271
-            $ret = $singleview->render($fetchOnly);
1272
-
1273
-            return $ret;
1274
-        } else {
1275
-            $singleview->render($fetchOnly);
1276
-        }
1277
-    }
1278
-
1279
-    /**
1280
-     * @param $key
1281
-     */
1282
-    public function doDisplayFieldOnSingleView($key)
1283
-    {
1284
-        if (isset($this->vars[$key])) {
1285
-            $this->vars[$key]['displayOnSingleView'] = true;
1286
-        }
1287
-    }
1288
-
1289
-    /**
1290
-     * @param      $field
1291
-     * @param bool $required
1292
-     */
1293
-    public function doSetFieldAsRequired($field, $required = true)
1294
-    {
1295
-        $this->setVarInfo($field, 'required', $required);
1296
-    }
1297
-
1298
-    /**
1299
-     * @param $field
1300
-     */
1301
-    public function doSetFieldForSorting($field)
1302
-    {
1303
-        $this->setVarInfo($field, 'sortby', true);
1304
-    }
1305
-
1306
-    /**
1307
-     * @param $key
1308
-     */
1309
-    public function showFieldOnForm($key)
1310
-    {
1311
-        if (is_array($key)) {
1312
-            foreach ($key as $v) {
1313
-                $this->doShowFieldOnForm($v);
1314
-            }
1315
-        } else {
1316
-            $this->doShowFieldOnForm($key);
1317
-        }
1318
-    }
1319
-
1320
-    /**
1321
-     * @param $key
1322
-     */
1323
-    public function displayFieldOnSingleView($key)
1324
-    {
1325
-        if (is_array($key)) {
1326
-            foreach ($key as $v) {
1327
-                $this->doDisplayFieldOnSingleView($v);
1328
-            }
1329
-        } else {
1330
-            $this->doDisplayFieldOnSingleView($key);
1331
-        }
1332
-    }
1333
-
1334
-    /**
1335
-     * @param $key
1336
-     */
1337
-    public function doSetAdvancedFormFields($key)
1338
-    {
1339
-        if (isset($this->vars[$key])) {
1340
-            $this->vars[$key]['advancedform'] = true;
1341
-        }
1342
-    }
1343
-
1344
-    /**
1345
-     * @param $key
1346
-     */
1347
-    public function setAdvancedFormFields($key)
1348
-    {
1349
-        if (is_array($key)) {
1350
-            foreach ($key as $v) {
1351
-                $this->doSetAdvancedFormFields($v);
1352
-            }
1353
-        } else {
1354
-            $this->doSetAdvancedFormFields($key);
1355
-        }
1356
-    }
1357
-
1358
-    /**
1359
-     * @param $key
1360
-     * @return mixed
1361
-     */
1362
-    public function getUrlLinkObj($key)
1363
-    {
1364
-        $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject');
1365
-        $urllinkid                 = $this->getVar($key) !== null ? $this->getVar($key) : 0;
1366
-        if ($urllinkid != 0) {
1367
-            return $smartobjectLinkurlHandler->get($urllinkid);
1368
-        } else {
1369
-            return $smartobjectLinkurlHandler->create();
1370
-        }
1371
-    }
1372
-
1373
-    /**
1374
-     * @param $urlLinkObj
1375
-     * @return mixed
1376
-     */
1377
-    public function &storeUrlLinkObj($urlLinkObj)
1378
-    {
1379
-        $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject');
1380
-
1381
-        return $smartobjectLinkurlHandler->insert($urlLinkObj);
1382
-    }
1383
-
1384
-    /**
1385
-     * @param $key
1386
-     * @return mixed
1387
-     */
1388
-    public function getFileObj($key)
1389
-    {
1390
-        $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject');
1391
-        $fileid                 = $this->getVar($key) !== null ? $this->getVar($key) : 0;
1392
-        if ($fileid != 0) {
1393
-            return $smartobjectFileHandler->get($fileid);
1394
-        } else {
1395
-            return $smartobjectFileHandler->create();
1396
-        }
1397
-    }
1398
-
1399
-    /**
1400
-     * @param $fileObj
1401
-     * @return mixed
1402
-     */
1403
-    public function &storeFileObj($fileObj)
1404
-    {
1405
-        $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject');
1406
-
1407
-        return $smartobjectFileHandler->insert($fileObj);
1408
-    }
58
+	public $_image_path;
59
+	public $_image_url;
60
+
61
+	public $seoEnabled   = false;
62
+	public $titleField;
63
+	public $summaryField = false;
64
+
65
+	/**
66
+	 * Reference to the handler managing this object
67
+	 *
68
+	 * @var SmartPersistableObjectHandler reference to {@link SmartPersistableObjectHandler}
69
+	 */
70
+	public $handler;
71
+
72
+	/**
73
+	 * References to control objects, managing the form fields of this object
74
+	 */
75
+	public $controls = array();
76
+
77
+	/**
78
+	 * SmartObject constructor.
79
+	 * @param $handler
80
+	 */
81
+	public function __construct($handler)
82
+	{
83
+		$this->handler = $handler;
84
+	}
85
+
86
+	/**
87
+	 * Checks if the user has a specific access on this object
88
+	 *
89
+	 * @param $perm_name
90
+	 * @return bool: TRUE if user has access, false if not
91
+	 * @internal param string $gperm_name name of the permission to test
92
+	 */
93
+	public function accessGranted($perm_name)
94
+	{
95
+		$smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
96
+
97
+		return $smartPermissionsHandler->accessGranted($perm_name, $this->id());
98
+	}
99
+
100
+	/**
101
+	 * @param      $section_name
102
+	 * @param bool $value
103
+	 * @param bool $hide
104
+	 */
105
+	public function addFormSection($section_name, $value = false, $hide = false)
106
+	{
107
+		$this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true);
108
+		$this->vars[$section_name]['hide'] = $hide;
109
+	}
110
+
111
+	/**
112
+	 * @param $section_name
113
+	 */
114
+	public function closeSection($section_name)
115
+	{
116
+		$this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
117
+	}
118
+
119
+	/**
120
+	 *
121
+	 * @param string $key           key of this field. This needs to be the name of the field in the related database table
122
+	 * @param int    $data_type     set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
123
+	 * @param mixed  $value         default value of this variable
124
+	 * @param bool   $required      set to TRUE if this variable needs to have a value set before storing the object in the table
125
+	 * @param int    $maxlength     maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only
126
+	 * @param string $options       does this data have any select options?
127
+	 * @param bool   $multilingual  is this field needs to support multilingual features (NOT YET IMPLEMENTED...)
128
+	 * @param string $form_caption  caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
129
+	 * @param string $form_dsc      description of this variable in a {@link SmartobjectForm}
130
+	 * @param bool   $sortby        set to TRUE to make this field used to sort objects in SmartObjectTable
131
+	 * @param bool   $persistent    set to FALSE if this field is not to be saved in the database
132
+	 * @param bool   $displayOnForm
133
+	 */
134
+	public function initVar($key, $data_type, $value = null, $required = false, $maxlength = null, $options = '', $multilingual = false, $form_caption = '', $form_dsc = '', $sortby = false,
135
+							$persistent = true, $displayOnForm = true
136
+	) {
137
+		//url_ is reserved for files.
138
+		if (0 === strpos($key, 'url_')) {
139
+			trigger_error("Cannot use variable starting with 'url_'.");
140
+		}
141
+		parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
142
+		if ($this->handler && (!$form_caption || $form_caption === '')) {
143
+			$dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
144
+			if (defined($dyn_form_caption)) {
145
+				$form_caption = constant($dyn_form_caption);
146
+			}
147
+		}
148
+		if ($this->handler && (!$form_dsc || $form_dsc === '')) {
149
+			$dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
150
+			if (defined($dyn_form_dsc)) {
151
+				$form_dsc = constant($dyn_form_dsc);
152
+			}
153
+		}
154
+
155
+		$this->vars[$key] = array_merge($this->vars[$key], array(
156
+			'multilingual'        => $multilingual,
157
+			'form_caption'        => $form_caption,
158
+			'form_dsc'            => $form_dsc,
159
+			'sortby'              => $sortby,
160
+			'persistent'          => $persistent,
161
+			'displayOnForm'       => $displayOnForm,
162
+			'displayOnSingleView' => true,
163
+			'readonly'            => false
164
+		));
165
+	}
166
+
167
+	/**
168
+	 * @param        $key
169
+	 * @param        $data_type
170
+	 * @param bool   $itemName
171
+	 * @param string $form_caption
172
+	 * @param bool   $sortby
173
+	 * @param string $value
174
+	 * @param bool   $displayOnForm
175
+	 * @param bool   $required
176
+	 */
177
+	public function initNonPersistableVar($key, $data_type, $itemName = false, $form_caption = '', $sortby = false, $value = '', $displayOnForm = false, $required = false)
178
+	{
179
+		$this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm);
180
+		$this->vars[$key]['itemName'] = $itemName;
181
+	}
182
+
183
+	/**
184
+	 * Quickly initiate a var
185
+	 *
186
+	 * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-)
187
+	 *
188
+	 * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255
189
+	 * - all other vars are NULL or '' depending of the parameter
190
+	 *
191
+	 * @param string $key          key of this field. This needs to be the name of the field in the related database table
192
+	 * @param int    $data_type    set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required)
193
+	 * @param bool   $required     set to TRUE if this variable needs to have a value set before storing the object in the table
194
+	 * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a  {@link SmartObjectTable}
195
+	 * @param string $form_dsc     description of this variable in a {@link SmartobjectForm}
196
+	 * @param mixed  $value        default value of this variable
197
+	 */
198
+	public function quickInitVar($key, $data_type, $required = false, $form_caption = '', $form_dsc = '', $value = null)
199
+	{
200
+		$maxlength = $data_type === 'XOBJ_DTYPE_TXTBOX' ? 255 : null;
201
+		$this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true);
202
+	}
203
+
204
+	/**
205
+	 * @param        $varname
206
+	 * @param bool   $displayOnForm
207
+	 * @param string $default
208
+	 */
209
+	public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined')
210
+	{
211
+		switch ($varname) {
212
+			case 'dohtml':
213
+				$value = $default !== 'notdefined' ? $default : true;
214
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm);
215
+				$this->setControl($varname, 'yesno');
216
+				break;
217
+
218
+			case 'dobr':
219
+				$value = ($default === 'notdefined') ? true : $default;
220
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm);
221
+				$this->setControl($varname, 'yesno');
222
+				break;
223
+
224
+			case 'doimage':
225
+				$value = $default !== 'notdefined' ? $default : true;
226
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm);
227
+				$this->setControl($varname, 'yesno');
228
+				break;
229
+
230
+			case 'dosmiley':
231
+				$value = $default !== 'notdefined' ? $default : true;
232
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm);
233
+				$this->setControl($varname, 'yesno');
234
+				break;
235
+
236
+			case 'doxcode':
237
+				$value = $default !== 'notdefined' ? $default : true;
238
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm);
239
+				$this->setControl($varname, 'yesno');
240
+				break;
241
+
242
+			case 'meta_keywords':
243
+				$value = $default !== 'notdefined' ? $default : '';
244
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm);
245
+				$this->setControl('meta_keywords', array(
246
+					'name'        => 'textarea',
247
+					'form_editor' => 'textarea'
248
+				));
249
+				break;
250
+
251
+			case 'meta_description':
252
+				$value = $default !== 'notdefined' ? $default : '';
253
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm);
254
+				$this->setControl('meta_description', array(
255
+					'name'        => 'textarea',
256
+					'form_editor' => 'textarea'
257
+				));
258
+				break;
259
+
260
+			case 'short_url':
261
+				$value = $default !== 'notdefined' ? $default : '';
262
+				$this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm);
263
+				break;
264
+
265
+			case 'hierarchy_path':
266
+				$value = $default !== 'notdefined' ? $default : '';
267
+				$this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm);
268
+				break;
269
+
270
+			case 'counter':
271
+				$value = $default !== 'notdefined' ? $default : 0;
272
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm);
273
+				break;
274
+
275
+			case 'weight':
276
+				$value = $default !== 'notdefined' ? $default : 0;
277
+				$this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm);
278
+				break;
279
+			case 'custom_css':
280
+				$value = $default !== 'notdefined' ? $default : '';
281
+				$this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm);
282
+				$this->setControl('custom_css', array(
283
+					'name'        => 'textarea',
284
+					'form_editor' => 'textarea'
285
+				));
286
+				break;
287
+		}
288
+		$this->hideFieldFromSingleView($varname);
289
+	}
290
+
291
+	/**
292
+	 * Set control information for an instance variable
293
+	 *
294
+	 * The $options parameter can be a string or an array. Using a string
295
+	 * is the quickest way:
296
+	 *
297
+	 * $this->setControl('date', 'date_time');
298
+	 *
299
+	 * This will create a date and time selectbox for the 'date' var on the
300
+	 * form to edit or create this item.
301
+	 *
302
+	 * Here are the currently supported controls:
303
+	 *
304
+	 *      - color
305
+	 *      - country
306
+	 *      - date_time
307
+	 *      - date
308
+	 *      - email
309
+	 *      - group
310
+	 *      - group_multi
311
+	 *      - image
312
+	 *      - imageupload
313
+	 *      - label
314
+	 *      - language
315
+	 *      - parentcategory
316
+	 *      - password
317
+	 *      - select_multi
318
+	 *      - select
319
+	 *      - text
320
+	 *      - textarea
321
+	 *      - theme
322
+	 *      - theme_multi
323
+	 *      - timezone
324
+	 *      - user
325
+	 *      - user_multi
326
+	 *      - yesno
327
+	 *
328
+	 * Now, using an array as $options, you can customize what information to
329
+	 * use in the control. For example, if one needs to display a select box for
330
+	 * the user to choose the status of an item. We only need to tell SmartObject
331
+	 * what method to execute within what handler to retreive the options of the
332
+	 * selectbox.
333
+	 *
334
+	 * $this->setControl('status', array('name' => false,
335
+	 *                                   'itemHandler' => 'item',
336
+	 *                                   'method' => 'getStatus',
337
+	 *                                   'module' => 'smartshop'));
338
+	 *
339
+	 * In this example, the array elements are the following:
340
+	 *      - name: false, as we don't need to set a special control here.
341
+	 *               we will use the default control related to the object type (defined in initVar)
342
+	 *      - itemHandler: name of the object for which we will use the handler
343
+	 *      - method: name of the method of this handler that we will execute
344
+	 *      - module: name of the module from wich the handler is
345
+	 *
346
+	 * So in this example, SmartObject will create a selectbox for the variable 'status' and it will
347
+	 * populate this selectbox with the result from SmartshopItemHandler::getStatus()
348
+	 *
349
+	 * Another example of the use of $options as an array is for TextArea:
350
+	 *
351
+	 * $this->setControl('body', array('name' => 'textarea',
352
+	 *                                   'form_editor' => 'default'));
353
+	 *
354
+	 * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use
355
+	 * the 'default' editor, providing it is defined in the module
356
+	 * preferences: $xoopsModuleConfig['default_editor']
357
+	 *
358
+	 * Of course, you can force the use of a specific editor:
359
+	 *
360
+	 * $this->setControl('body', array('name' => 'textarea',
361
+	 *                                   'form_editor' => 'koivi'));
362
+	 *
363
+	 * Here is a list of supported editor:
364
+	 *      - tiny: TinyEditor
365
+	 *      - dhtmltextarea: XOOPS DHTML Area
366
+	 *      - fckeditor: FCKEditor
367
+	 *      - inbetween: InBetween
368
+	 *      - koivi: Koivi
369
+	 *      - spaw: Spaw WYSIWYG Editor
370
+	 *      - htmlarea: HTMLArea
371
+	 *      - textarea: basic textarea with no options
372
+	 *
373
+	 * @param string $var     name of the variable for which we want to set a control
374
+	 * @param array  $options
375
+	 */
376
+	public function setControl($var, $options = array())
377
+	{
378
+		if (isset($this->controls[$var])) {
379
+			unset($this->controls[$var]);
380
+		}
381
+		if (is_string($options)) {
382
+			$options = array('name' => $options);
383
+		}
384
+		$this->controls[$var] = $options;
385
+	}
386
+
387
+	/**
388
+	 * Get control information for an instance variable
389
+	 *
390
+	 * @param  string     $var
391
+	 * @return bool|mixed
392
+	 */
393
+	public function getControl($var)
394
+	{
395
+		return isset($this->controls[$var]) ? $this->controls[$var] : false;
396
+	}
397
+
398
+	/**
399
+	 * Create the form for this object
400
+	 *
401
+	 * @param         $form_caption
402
+	 * @param         $form_name
403
+	 * @param  bool   $form_action
404
+	 * @param  string $submit_button_caption
405
+	 * @param  bool   $cancel_js_action
406
+	 * @param  bool   $captcha
407
+	 * @return a      <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object
408
+	 *                                      object for this object
409
+	 * @see SmartObjectForm::SmartObjectForm()
410
+	 */
411
+	public function getForm($form_caption, $form_name, $form_action = false, $submit_button_caption = _CO_SOBJECT_SUBMIT, $cancel_js_action = false, $captcha = false)
412
+	{
413
+		include_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php';
414
+		$form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha);
415
+
416
+		return $form;
417
+	}
418
+
419
+	/**
420
+	 * @return array
421
+	 */
422
+	public function toArray()
423
+	{
424
+		$ret  = array();
425
+		$vars =& $this->getVars();
426
+		foreach ($vars as $key => $var) {
427
+			$value     = $this->getVar($key);
428
+			$ret[$key] = $value;
429
+		}
430
+		if ($this->handler->identifierName !== '') {
431
+			$controller = new SmartObjectController($this->handler);
432
+			/**
433
+			 * Addition of some automatic value
434
+			 */
435
+			$ret['itemLink']         = $controller->getItemLink($this);
436
+			$ret['itemUrl']          = $controller->getItemLink($this, true);
437
+			$ret['editItemLink']     = $controller->getEditItemLink($this, false, true);
438
+			$ret['deleteItemLink']   = $controller->getDeleteItemLink($this, false, true);
439
+			$ret['printAndMailLink'] = $controller->getPrintAndMailLink($this);
440
+		}
441
+
442
+		// Hightlighting searched words
443
+		include_once(SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php');
444
+		$highlight = smart_getConfig('module_search_highlighter', false, true);
445
+
446
+		if ($highlight && isset($_GET['keywords'])) {
447
+			$myts     = MyTextSanitizer::getInstance();
448
+			$keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords'])));
449
+			$h        = new SmartHighlighter($keywords, true, 'smart_highlighter');
450
+			foreach ($this->handler->highlightFields as $field) {
451
+				$ret[$field] = $h->highlight($ret[$field]);
452
+			}
453
+		}
454
+
455
+		return $ret;
456
+	}
457
+
458
+	/**
459
+	 * add an error
460
+	 *
461
+	 * @param      $err_str
462
+	 * @param bool $prefix
463
+	 * @internal param string $value error to add
464
+	 * @access   public
465
+	 */
466
+	public function setErrors($err_str, $prefix = false)
467
+	{
468
+		if (is_array($err_str)) {
469
+			foreach ($err_str as $str) {
470
+				$this->setErrors($str, $prefix);
471
+			}
472
+		} else {
473
+			if ($prefix) {
474
+				$err_str = '[' . $prefix . '] ' . $err_str;
475
+			}
476
+			parent::setErrors($err_str);
477
+		}
478
+	}
479
+
480
+	/**
481
+	 * @param      $field
482
+	 * @param bool $required
483
+	 */
484
+	public function setFieldAsRequired($field, $required = true)
485
+	{
486
+		if (is_array($field)) {
487
+			foreach ($field as $v) {
488
+				$this->doSetFieldAsRequired($v, $required);
489
+			}
490
+		} else {
491
+			$this->doSetFieldAsRequired($field, $required);
492
+		}
493
+	}
494
+
495
+	/**
496
+	 * @param $field
497
+	 */
498
+	public function setFieldForSorting($field)
499
+	{
500
+		if (is_array($field)) {
501
+			foreach ($field as $v) {
502
+				$this->doSetFieldForSorting($v);
503
+			}
504
+		} else {
505
+			$this->doSetFieldForSorting($field);
506
+		}
507
+	}
508
+
509
+	/**
510
+	 * @return bool
511
+	 */
512
+	public function hasError()
513
+	{
514
+		return count($this->_errors) > 0;
515
+	}
516
+
517
+	/**
518
+	 * @param $url
519
+	 * @param $path
520
+	 */
521
+	public function setImageDir($url, $path)
522
+	{
523
+		$this->_image_url  = $url;
524
+		$this->_image_path = $path;
525
+	}
526
+
527
+	/**
528
+	 * Retreive the group that have been granted access to a specific permission for this object
529
+	 *
530
+	 * @param $group_perm
531
+	 * @return string $group_perm name of the permission
532
+	 */
533
+	public function getGroupPerm($group_perm)
534
+	{
535
+		if (!$this->handler->getPermissions()) {
536
+			$this->setError("Trying to access a permission that does not exists for thisobject's handler");
537
+
538
+			return false;
539
+		}
540
+
541
+		$smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
542
+		$ret                     = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id());
543
+
544
+		if (count($ret) == 0) {
545
+			return false;
546
+		} else {
547
+			return $ret;
548
+		}
549
+	}
550
+
551
+	/**
552
+	 * @param  bool  $path
553
+	 * @return mixed
554
+	 */
555
+	public function getImageDir($path = false)
556
+	{
557
+		if ($path) {
558
+			return $this->_image_path;
559
+		} else {
560
+			return $this->_image_url;
561
+		}
562
+	}
563
+
564
+	/**
565
+	 * @param  bool  $path
566
+	 * @return mixed
567
+	 */
568
+	public function getUploadDir($path = false)
569
+	{
570
+		if ($path) {
571
+			return $this->_image_path;
572
+		} else {
573
+			return $this->_image_url;
574
+		}
575
+	}
576
+
577
+	/**
578
+	 * @param  string $key
579
+	 * @param  string $info
580
+	 * @return array
581
+	 */
582
+	public function getVarInfo($key = '', $info = '')
583
+	{
584
+		if (isset($this->vars[$key][$info])) {
585
+			return $this->vars[$key][$info];
586
+		} elseif ($info === '' && isset($this->vars[$key])) {
587
+			return $this->vars[$key];
588
+		} else {
589
+			return $this->vars;
590
+		}
591
+	}
592
+
593
+	/**
594
+	 * Get the id of the object
595
+	 *
596
+	 * @return int id of this object
597
+	 */
598
+	public function id()
599
+	{
600
+		return $this->getVar($this->handler->keyName, 'e');
601
+	}
602
+
603
+	/**
604
+	 * Return the value of the title field of this object
605
+	 *
606
+	 * @param  string $format
607
+	 * @return string
608
+	 */
609
+	public function title($format = 's')
610
+	{
611
+		return $this->getVar($this->handler->identifierName, $format);
612
+	}
613
+
614
+	/**
615
+	 * Return the value of the title field of this object
616
+	 *
617
+	 * @return string
618
+	 */
619
+	public function summary()
620
+	{
621
+		if ($this->handler->summaryName) {
622
+			return $this->getVar($this->handler->summaryName);
623
+		} else {
624
+			return false;
625
+		}
626
+	}
627
+
628
+	/**
629
+	 * Retreive the object admin side link, displayijng a SingleView page
630
+	 *
631
+	 * @param  bool   $onlyUrl wether or not to return a simple URL or a full <a> link
632
+	 * @return string user side link to the object
633
+	 */
634
+	public function getAdminViewItemLink($onlyUrl = false)
635
+	{
636
+		$controller = new SmartObjectController($this->handler);
637
+
638
+		return $controller->getAdminViewItemLink($this, $onlyUrl);
639
+	}
640
+
641
+	/**
642
+	 * Retreive the object user side link
643
+	 *
644
+	 * @param  bool   $onlyUrl wether or not to return a simple URL or a full <a> link
645
+	 * @return string user side link to the object
646
+	 */
647
+	public function getItemLink($onlyUrl = false)
648
+	{
649
+		$controller = new SmartObjectController($this->handler);
650
+
651
+		return $controller->getItemLink($this, $onlyUrl);
652
+	}
653
+
654
+	/**
655
+	 * @param  bool   $onlyUrl
656
+	 * @param  bool   $withimage
657
+	 * @param  bool   $userSide
658
+	 * @return string
659
+	 */
660
+	public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false)
661
+	{
662
+		$controller = new SmartObjectController($this->handler);
663
+
664
+		return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide);
665
+	}
666
+
667
+	/**
668
+	 * @param  bool   $onlyUrl
669
+	 * @param  bool   $withimage
670
+	 * @param  bool   $userSide
671
+	 * @return string
672
+	 */
673
+	public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false)
674
+	{
675
+		$controller = new SmartObjectController($this->handler);
676
+
677
+		return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide);
678
+	}
679
+
680
+	/**
681
+	 * @return string
682
+	 */
683
+	public function getPrintAndMailLink()
684
+	{
685
+		$controller = new SmartObjectController($this->handler);
686
+
687
+		return $controller->getPrintAndMailLink($this);
688
+	}
689
+
690
+	/**
691
+	 * @param $sortsel
692
+	 * @return array|bool
693
+	 */
694
+	public function getFieldsForSorting($sortsel)
695
+	{
696
+		$ret = array();
697
+
698
+		foreach ($this->vars as $key => $field_info) {
699
+			if ($field_info['sortby']) {
700
+				$ret[$key]['caption']  = $field_info['form_caption'];
701
+				$ret[$key]['selected'] = $key == $sortsel ? "selected='selected'" : '';
702
+			}
703
+		}
704
+
705
+		if (count($ret) > 0) {
706
+			return $ret;
707
+		} else {
708
+			return false;
709
+		}
710
+	}
711
+
712
+	/**
713
+	 * @param $key
714
+	 * @param $newType
715
+	 */
716
+	public function setType($key, $newType)
717
+	{
718
+		$this->vars[$key]['data_type'] = $newType;
719
+	}
720
+
721
+	/**
722
+	 * @param $key
723
+	 * @param $info
724
+	 * @param $value
725
+	 */
726
+	public function setVarInfo($key, $info, $value)
727
+	{
728
+		$this->vars[$key][$info] = $value;
729
+	}
730
+
731
+	/**
732
+	 * @param         $key
733
+	 * @param  bool   $editor
734
+	 * @return string
735
+	 */
736
+	public function getValueFor($key, $editor = true)
737
+	{
738
+		global $xoopsModuleConfig;
739
+
740
+		$ret  = $this->getVar($key, 'n');
741
+		$myts = MyTextSanitizer::getInstance();
742
+
743
+		$control     = isset($this->controls[$key]) ? $this->controls[$key] : false;
744
+		$form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
745
+
746
+		$html     = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true;
747
+		$smiley   = true;
748
+		$xcode    = true;
749
+		$image    = true;
750
+		$br       = isset($this->vars['dobr']) ? $this->getVar('dobr') : true;
751
+		$formatML = true;
752
+
753
+		if ($form_editor === 'default') {
754
+			global $xoopsModuleConfig;
755
+			$form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea';
756
+		}
757
+
758
+		if ($editor) {
759
+			if (defined('XOOPS_EDITOR_IS_HTML') && !in_array($form_editor, array('formtextarea', 'textarea', 'dhtmltextarea'))) {
760
+				$br       = false;
761
+				$formatML = !$editor;
762
+			} else {
763
+				return htmlspecialchars($ret, ENT_QUOTES);
764
+			}
765
+		}
766
+
767
+		if (method_exists($myts, 'formatForML')) {
768
+			return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML);
769
+		} else {
770
+			return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
771
+		}
772
+	}
773
+
774
+	/**
775
+	 * clean values of all variables of the object for storage.
776
+	 * also add slashes whereever needed
777
+	 *
778
+	 * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
779
+	 * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
780
+	 * as a string separated by |
781
+	 *
782
+	 * @return bool true if successful
783
+	 * @access public
784
+	 */
785
+	public function cleanVars()
786
+	{
787
+		$ts              = MyTextSanitizer::getInstance();
788
+		$existing_errors = $this->getErrors();
789
+		$this->_errors   = array();
790
+		foreach ($this->vars as $k => $v) {
791
+			$cleanv = $v['value'];
792
+			if (!$v['changed']) {
793
+			} else {
794
+				$cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv;
795
+				switch ($v['data_type']) {
796
+					case XOBJ_DTYPE_TXTBOX:
797
+						if ($v['required'] && $cleanv != '0' && $cleanv == '') {
798
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
799
+							continue 2;
800
+						}
801
+						if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) {
802
+							$this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength']));
803
+							continue 2;
804
+						}
805
+						if (!$v['not_gpc']) {
806
+							$cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
807
+						} else {
808
+							$cleanv = $ts->censorString($cleanv);
809
+						}
810
+						break;
811
+					case XOBJ_DTYPE_TXTAREA:
812
+						if ($v['required'] && $cleanv != '0' && $cleanv == '') {
813
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
814
+							continue 2;
815
+						}
816
+						if (!$v['not_gpc']) {
817
+							$cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv));
818
+						} else {
819
+							$cleanv = $ts->censorString($cleanv);
820
+						}
821
+						break;
822
+					case XOBJ_DTYPE_SOURCE:
823
+						if (!$v['not_gpc']) {
824
+							$cleanv = $ts->stripSlashesGPC($cleanv);
825
+						} else {
826
+							$cleanv = $cleanv;
827
+						}
828
+						break;
829
+					case XOBJ_DTYPE_INT:
830
+					case XOBJ_DTYPE_TIME_ONLY:
831
+						$cleanv = (int)$cleanv;
832
+						break;
833
+
834
+					case XOBJ_DTYPE_CURRENCY:
835
+						$cleanv = smart_currency($cleanv);
836
+						break;
837
+
838
+					case XOBJ_DTYPE_FLOAT:
839
+						$cleanv = smart_float($cleanv);
840
+						break;
841
+
842
+					case XOBJ_DTYPE_EMAIL:
843
+						if ($v['required'] && $cleanv === '') {
844
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
845
+							continue 2;
846
+						}
847
+						if ($cleanv !== '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) {
848
+							$this->setErrors('Invalid Email');
849
+							continue 2;
850
+						}
851
+						if (!$v['not_gpc']) {
852
+							$cleanv = $ts->stripSlashesGPC($cleanv);
853
+						}
854
+						break;
855
+					case XOBJ_DTYPE_URL:
856
+						if ($v['required'] && $cleanv === '') {
857
+							$this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
858
+							continue 2;
859
+						}
860
+						if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
861
+							$cleanv = 'http://' . $cleanv;
862
+						}
863
+						if (!$v['not_gpc']) {
864
+							$cleanv =& $ts->stripSlashesGPC($cleanv);
865
+						}
866
+						break;
867
+					case XOBJ_DTYPE_SIMPLE_ARRAY:
868
+						$cleanv = implode('|', $cleanv);
869
+						break;
870
+					case XOBJ_DTYPE_ARRAY:
871
+						$cleanv = serialize($cleanv);
872
+						break;
873
+					case XOBJ_DTYPE_STIME:
874
+					case XOBJ_DTYPE_MTIME:
875
+					case XOBJ_DTYPE_LTIME:
876
+						$cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
877
+						if (!($cleanv > 0)) {
878
+							$cleanv = strtotime($cleanv);
879
+						}
880
+						break;
881
+					default:
882
+						break;
883
+				}
884
+			}
885
+			$this->cleanVars[$k] =& $cleanv;
886
+			unset($cleanv);
887
+		}
888
+		if (count($this->_errors) > 0) {
889
+			$this->_errors = array_merge($existing_errors, $this->_errors);
890
+
891
+			return false;
892
+		}
893
+		$this->_errors = array_merge($existing_errors, $this->_errors);
894
+		$this->unsetDirty();
895
+
896
+		return true;
897
+	}
898
+
899
+	/**
900
+	 * returns a specific variable for the object in a proper format
901
+	 *
902
+	 * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly
903
+	 * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array
904
+	 * as a string separated by |
905
+	 *
906
+	 * @access public
907
+	 * @param  string $key    key of the object's variable to be returned
908
+	 * @param  string $format format to use for the output
909
+	 * @return mixed  formatted value of the variable
910
+	 */
911
+	public function getVar($key, $format = 's')
912
+	{
913
+		global $myts;
914
+
915
+		$ret = $this->vars[$key]['value'];
916
+
917
+		switch ($this->vars[$key]['data_type']) {
918
+
919
+			case XOBJ_DTYPE_TXTBOX:
920
+				switch (strtolower($format)) {
921
+					case 's':
922
+					case 'show':
923
+						// ML Hack by marcan
924
+						$ts  = MyTextSanitizer::getInstance();
925
+						$ret = $ts->htmlSpecialChars($ret);
926
+
927
+						if (method_exists($myts, 'formatForML')) {
928
+							return $ts->formatForML($ret);
929
+						} else {
930
+							return $ret;
931
+						}
932
+						break 1;
933
+					// End of ML Hack by marcan
934
+
935
+					case 'clean':
936
+						$ts = MyTextSanitizer::getInstance();
937
+
938
+						$ret = smart_html2text($ret);
939
+						$ret = smart_purifyText($ret);
940
+
941
+						if (method_exists($myts, 'formatForML')) {
942
+							return $ts->formatForML($ret);
943
+						} else {
944
+							return $ret;
945
+						}
946
+						break 1;
947
+					// End of ML Hack by marcan
948
+
949
+					case 'e':
950
+					case 'edit':
951
+						$ts = MyTextSanitizer::getInstance();
952
+
953
+						return $ts->htmlSpecialChars($ret);
954
+						break 1;
955
+					case 'p':
956
+					case 'preview':
957
+					case 'f':
958
+					case 'formpreview':
959
+						$ts = MyTextSanitizer::getInstance();
960
+
961
+						return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret));
962
+						break 1;
963
+					case 'n':
964
+					case 'none':
965
+					default:
966
+						break 1;
967
+				}
968
+				break;
969
+			case XOBJ_DTYPE_LTIME:
970
+				switch (strtolower($format)) {
971
+					case 's':
972
+					case 'show':
973
+					case 'p':
974
+					case 'preview':
975
+					case 'f':
976
+					case 'formpreview':
977
+						$ret = formatTimestamp($ret, _DATESTRING);
978
+
979
+						return $ret;
980
+						break 1;
981
+					case 'n':
982
+					case 'none':
983
+					case 'e':
984
+					case 'edit':
985
+						break 1;
986
+					default:
987
+						break 1;
988
+				}
989
+				break;
990
+			case XOBJ_DTYPE_STIME:
991
+				switch (strtolower($format)) {
992
+					case 's':
993
+					case 'show':
994
+					case 'p':
995
+					case 'preview':
996
+					case 'f':
997
+					case 'formpreview':
998
+						$ret = formatTimestamp($ret, _SHORTDATESTRING);
999
+
1000
+						return $ret;
1001
+						break 1;
1002
+					case 'n':
1003
+					case 'none':
1004
+					case 'e':
1005
+					case 'edit':
1006
+						break 1;
1007
+					default:
1008
+						break 1;
1009
+				}
1010
+				break;
1011
+			case XOBJ_DTYPE_TIME_ONLY:
1012
+				switch (strtolower($format)) {
1013
+					case 's':
1014
+					case 'show':
1015
+					case 'p':
1016
+					case 'preview':
1017
+					case 'f':
1018
+					case 'formpreview':
1019
+						$ret = formatTimestamp($ret, 'G:i');
1020
+
1021
+						return $ret;
1022
+						break 1;
1023
+					case 'n':
1024
+					case 'none':
1025
+					case 'e':
1026
+					case 'edit':
1027
+						break 1;
1028
+					default:
1029
+						break 1;
1030
+				}
1031
+				break;
1032
+
1033
+			case XOBJ_DTYPE_CURRENCY:
1034
+				$decimal_section_original = strstr($ret, '.');
1035
+				$decimal_section          = $decimal_section_original;
1036
+				if ($decimal_section) {
1037
+					if (strlen($decimal_section) == 1) {
1038
+						$decimal_section = '.00';
1039
+					} elseif (strlen($decimal_section) == 2) {
1040
+						$decimal_section .= '0';
1041
+					}
1042
+					$ret = str_replace($decimal_section_original, $decimal_section, $ret);
1043
+				} else {
1044
+					$ret .= '.00';
1045
+				}
1046
+				break;
1047
+
1048
+			case XOBJ_DTYPE_TXTAREA:
1049
+				switch (strtolower($format)) {
1050
+					case 's':
1051
+					case 'show':
1052
+						$ts   = MyTextSanitizer::getInstance();
1053
+						$html = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1054
+
1055
+						$xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
1056
+
1057
+						$smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
1058
+						$image  = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
1059
+						$br     = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
1060
+
1061
+						/**
1062
+						 * Hack by marcan <INBOX> for SCSPRO
1063
+						 * Setting mastop as the main editor
1064
+						 */
1065
+						if (defined('XOOPS_EDITOR_IS_HTML')) {
1066
+							$br = false;
1067
+						}
1068
+						/**
1069
+						 * Hack by marcan <INBOX> for SCSPRO
1070
+						 * Setting mastop as the main editor
1071
+						 */
1072
+
1073
+						return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br);
1074
+						break 1;
1075
+					case 'e':
1076
+					case 'edit':
1077
+						return htmlspecialchars($ret, ENT_QUOTES);
1078
+						break 1;
1079
+					case 'p':
1080
+					case 'preview':
1081
+						$ts     = MyTextSanitizer::getInstance();
1082
+						$html   = !empty($this->vars['dohtml']['value']) ? 1 : 0;
1083
+						$xcode  = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0;
1084
+						$smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0;
1085
+						$image  = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0;
1086
+						$br     = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0;
1087
+
1088
+						return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br);
1089
+						break 1;
1090
+					case 'f':
1091
+					case 'formpreview':
1092
+						$ts = MyTextSanitizer::getInstance();
1093
+
1094
+						return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1095
+						break 1;
1096
+					case 'n':
1097
+					case 'none':
1098
+					default:
1099
+						break 1;
1100
+				}
1101
+				break;
1102
+			case XOBJ_DTYPE_SIMPLE_ARRAY:
1103
+				$ret =& explode('|', $ret);
1104
+				break;
1105
+			case XOBJ_DTYPE_ARRAY:
1106
+				$ret =& unserialize($ret);
1107
+				break;
1108
+			case XOBJ_DTYPE_SOURCE:
1109
+				switch (strtolower($format)) {
1110
+					case 's':
1111
+					case 'show':
1112
+						break 1;
1113
+					case 'e':
1114
+					case 'edit':
1115
+						return htmlspecialchars($ret, ENT_QUOTES);
1116
+						break 1;
1117
+					case 'p':
1118
+					case 'preview':
1119
+						$ts = MyTextSanitizer::getInstance();
1120
+
1121
+						return $ts->stripSlashesGPC($ret);
1122
+						break 1;
1123
+					case 'f':
1124
+					case 'formpreview':
1125
+						$ts = MyTextSanitizer::getInstance();
1126
+
1127
+						return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES);
1128
+						break 1;
1129
+					case 'n':
1130
+					case 'none':
1131
+					default:
1132
+						break 1;
1133
+				}
1134
+				break;
1135
+			default:
1136
+				if ($this->vars[$key]['options'] !== '' && $ret != '') {
1137
+					switch (strtolower($format)) {
1138
+						case 's':
1139
+						case 'show':
1140
+							$selected = explode('|', $ret);
1141
+							$options  = explode('|', $this->vars[$key]['options']);
1142
+							$i        = 1;
1143
+							$ret      = array();
1144
+							foreach ($options as $op) {
1145
+								if (in_array($i, $selected)) {
1146
+									$ret[] = $op;
1147
+								}
1148
+								++$i;
1149
+							}
1150
+
1151
+							return implode(', ', $ret);
1152
+						case 'e':
1153
+						case 'edit':
1154
+							$ret = explode('|', $ret);
1155
+							break 1;
1156
+						default:
1157
+							break 1;
1158
+					}
1159
+				}
1160
+				break;
1161
+		}
1162
+
1163
+		return $ret;
1164
+	}
1165
+
1166
+	/**
1167
+	 * @param $key
1168
+	 */
1169
+	public function doMakeFieldreadOnly($key)
1170
+	{
1171
+		if (isset($this->vars[$key])) {
1172
+			$this->vars[$key]['readonly']      = true;
1173
+			$this->vars[$key]['displayOnForm'] = true;
1174
+		}
1175
+	}
1176
+
1177
+	/**
1178
+	 * @param $key
1179
+	 */
1180
+	public function makeFieldReadOnly($key)
1181
+	{
1182
+		if (is_array($key)) {
1183
+			foreach ($key as $v) {
1184
+				$this->doMakeFieldreadOnly($v);
1185
+			}
1186
+		} else {
1187
+			$this->doMakeFieldreadOnly($key);
1188
+		}
1189
+	}
1190
+
1191
+	/**
1192
+	 * @param $key
1193
+	 */
1194
+	public function doHideFieldFromForm($key)
1195
+	{
1196
+		if (isset($this->vars[$key])) {
1197
+			$this->vars[$key]['displayOnForm'] = false;
1198
+		}
1199
+	}
1200
+
1201
+	/**
1202
+	 * @param $key
1203
+	 */
1204
+	public function doHideFieldFromSingleView($key)
1205
+	{
1206
+		if (isset($this->vars[$key])) {
1207
+			$this->vars[$key]['displayOnSingleView'] = false;
1208
+		}
1209
+	}
1210
+
1211
+	/**
1212
+	 * @param $key
1213
+	 */
1214
+	public function hideFieldFromForm($key)
1215
+	{
1216
+		if (is_array($key)) {
1217
+			foreach ($key as $v) {
1218
+				$this->doHideFieldFromForm($v);
1219
+			}
1220
+		} else {
1221
+			$this->doHideFieldFromForm($key);
1222
+		}
1223
+	}
1224
+
1225
+	/**
1226
+	 * @param $key
1227
+	 */
1228
+	public function hideFieldFromSingleView($key)
1229
+	{
1230
+		if (is_array($key)) {
1231
+			foreach ($key as $v) {
1232
+				$this->doHideFieldFromSingleView($v);
1233
+			}
1234
+		} else {
1235
+			$this->doHideFieldFromSingleView($key);
1236
+		}
1237
+	}
1238
+
1239
+	/**
1240
+	 * @param $key
1241
+	 */
1242
+	public function doShowFieldOnForm($key)
1243
+	{
1244
+		if (isset($this->vars[$key])) {
1245
+			$this->vars[$key]['displayOnForm'] = true;
1246
+		}
1247
+	}
1248
+
1249
+	/**
1250
+	 * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars
1251
+	 *
1252
+	 * @param  bool    $fetchOnly   if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed
1253
+	 * @param  bool    $userSide    for futur use, to do something different on the user side
1254
+	 * @param  array   $actions
1255
+	 * @param  bool    $headerAsRow
1256
+	 * @return content of the template if $fetchOnly or nothing if !$fetchOnly
1257
+	 */
1258
+	public function displaySingleObject($fetchOnly = false, $userSide = false, $actions = array(), $headerAsRow = true)
1259
+	{
1260
+		include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php';
1261
+		$singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow);
1262
+		// add all fields mark as displayOnSingleView except the keyid
1263
+		foreach ($this->vars as $key => $var) {
1264
+			if ($key != $this->handler->keyName && $var['displayOnSingleView']) {
1265
+				$is_header = ($key == $this->handler->identifierName);
1266
+				$singleview->addRow(new SmartObjectRow($key, false, $is_header));
1267
+			}
1268
+		}
1269
+
1270
+		if ($fetchOnly) {
1271
+			$ret = $singleview->render($fetchOnly);
1272
+
1273
+			return $ret;
1274
+		} else {
1275
+			$singleview->render($fetchOnly);
1276
+		}
1277
+	}
1278
+
1279
+	/**
1280
+	 * @param $key
1281
+	 */
1282
+	public function doDisplayFieldOnSingleView($key)
1283
+	{
1284
+		if (isset($this->vars[$key])) {
1285
+			$this->vars[$key]['displayOnSingleView'] = true;
1286
+		}
1287
+	}
1288
+
1289
+	/**
1290
+	 * @param      $field
1291
+	 * @param bool $required
1292
+	 */
1293
+	public function doSetFieldAsRequired($field, $required = true)
1294
+	{
1295
+		$this->setVarInfo($field, 'required', $required);
1296
+	}
1297
+
1298
+	/**
1299
+	 * @param $field
1300
+	 */
1301
+	public function doSetFieldForSorting($field)
1302
+	{
1303
+		$this->setVarInfo($field, 'sortby', true);
1304
+	}
1305
+
1306
+	/**
1307
+	 * @param $key
1308
+	 */
1309
+	public function showFieldOnForm($key)
1310
+	{
1311
+		if (is_array($key)) {
1312
+			foreach ($key as $v) {
1313
+				$this->doShowFieldOnForm($v);
1314
+			}
1315
+		} else {
1316
+			$this->doShowFieldOnForm($key);
1317
+		}
1318
+	}
1319
+
1320
+	/**
1321
+	 * @param $key
1322
+	 */
1323
+	public function displayFieldOnSingleView($key)
1324
+	{
1325
+		if (is_array($key)) {
1326
+			foreach ($key as $v) {
1327
+				$this->doDisplayFieldOnSingleView($v);
1328
+			}
1329
+		} else {
1330
+			$this->doDisplayFieldOnSingleView($key);
1331
+		}
1332
+	}
1333
+
1334
+	/**
1335
+	 * @param $key
1336
+	 */
1337
+	public function doSetAdvancedFormFields($key)
1338
+	{
1339
+		if (isset($this->vars[$key])) {
1340
+			$this->vars[$key]['advancedform'] = true;
1341
+		}
1342
+	}
1343
+
1344
+	/**
1345
+	 * @param $key
1346
+	 */
1347
+	public function setAdvancedFormFields($key)
1348
+	{
1349
+		if (is_array($key)) {
1350
+			foreach ($key as $v) {
1351
+				$this->doSetAdvancedFormFields($v);
1352
+			}
1353
+		} else {
1354
+			$this->doSetAdvancedFormFields($key);
1355
+		}
1356
+	}
1357
+
1358
+	/**
1359
+	 * @param $key
1360
+	 * @return mixed
1361
+	 */
1362
+	public function getUrlLinkObj($key)
1363
+	{
1364
+		$smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject');
1365
+		$urllinkid                 = $this->getVar($key) !== null ? $this->getVar($key) : 0;
1366
+		if ($urllinkid != 0) {
1367
+			return $smartobjectLinkurlHandler->get($urllinkid);
1368
+		} else {
1369
+			return $smartobjectLinkurlHandler->create();
1370
+		}
1371
+	}
1372
+
1373
+	/**
1374
+	 * @param $urlLinkObj
1375
+	 * @return mixed
1376
+	 */
1377
+	public function &storeUrlLinkObj($urlLinkObj)
1378
+	{
1379
+		$smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject');
1380
+
1381
+		return $smartobjectLinkurlHandler->insert($urlLinkObj);
1382
+	}
1383
+
1384
+	/**
1385
+	 * @param $key
1386
+	 * @return mixed
1387
+	 */
1388
+	public function getFileObj($key)
1389
+	{
1390
+		$smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject');
1391
+		$fileid                 = $this->getVar($key) !== null ? $this->getVar($key) : 0;
1392
+		if ($fileid != 0) {
1393
+			return $smartobjectFileHandler->get($fileid);
1394
+		} else {
1395
+			return $smartobjectFileHandler->create();
1396
+		}
1397
+	}
1398
+
1399
+	/**
1400
+	 * @param $fileObj
1401
+	 * @return mixed
1402
+	 */
1403
+	public function &storeFileObj($fileObj)
1404
+	{
1405
+		$smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject');
1406
+
1407
+		return $smartobjectFileHandler->insert($fileObj);
1408
+	}
1409 1409
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
 
13 13
 // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
14 14
 
15
-include_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
15
+include_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php';
16 16
 
17
-include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
17
+include_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php';
18 18
 
19 19
 if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) {
20 20
     define('XOBJ_DTYPE_SIMPLE_ARRAY', 101);
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public function closeSection($section_name)
115 115
     {
116
-        $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
116
+        $this->initVar('close_section_'.$section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true);
117 117
     }
118 118
 
119 119
     /**
@@ -140,13 +140,13 @@  discard block
 block discarded – undo
140 140
         }
141 141
         parent::initVar($key, $data_type, $value, $required, $maxlength, $options);
142 142
         if ($this->handler && (!$form_caption || $form_caption === '')) {
143
-            $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key);
143
+            $dyn_form_caption = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key);
144 144
             if (defined($dyn_form_caption)) {
145 145
                 $form_caption = constant($dyn_form_caption);
146 146
             }
147 147
         }
148 148
         if ($this->handler && (!$form_dsc || $form_dsc === '')) {
149
-            $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC');
149
+            $dyn_form_dsc = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key.'_DSC');
150 150
             if (defined($dyn_form_dsc)) {
151 151
                 $form_dsc = constant($dyn_form_dsc);
152 152
             }
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
      */
411 411
     public function getForm($form_caption, $form_name, $form_action = false, $submit_button_caption = _CO_SOBJECT_SUBMIT, $cancel_js_action = false, $captcha = false)
412 412
     {
413
-        include_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php';
413
+        include_once SMARTOBJECT_ROOT_PATH.'class/form/smartobjectform.php';
414 414
         $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha);
415 415
 
416 416
         return $form;
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
     public function toArray()
423 423
     {
424 424
         $ret  = array();
425
-        $vars =& $this->getVars();
425
+        $vars = & $this->getVars();
426 426
         foreach ($vars as $key => $var) {
427 427
             $value     = $this->getVar($key);
428 428
             $ret[$key] = $value;
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
         }
441 441
 
442 442
         // Hightlighting searched words
443
-        include_once(SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php');
443
+        include_once(SMARTOBJECT_ROOT_PATH.'class/smarthighlighter.php');
444 444
         $highlight = smart_getConfig('module_search_highlighter', false, true);
445 445
 
446 446
         if ($highlight && isset($_GET['keywords'])) {
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
             }
472 472
         } else {
473 473
             if ($prefix) {
474
-                $err_str = '[' . $prefix . '] ' . $err_str;
474
+                $err_str = '['.$prefix.'] '.$err_str;
475 475
             }
476 476
             parent::setErrors($err_str);
477 477
         }
@@ -798,8 +798,8 @@  discard block
 block discarded – undo
798 798
                             $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k));
799 799
                             continue 2;
800 800
                         }
801
-                        if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) {
802
-                            $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength']));
801
+                        if (isset($v['maxlength']) && strlen($cleanv) > (int) $v['maxlength']) {
802
+                            $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int) $v['maxlength']));
803 803
                             continue 2;
804 804
                         }
805 805
                         if (!$v['not_gpc']) {
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
                         break;
829 829
                     case XOBJ_DTYPE_INT:
830 830
                     case XOBJ_DTYPE_TIME_ONLY:
831
-                        $cleanv = (int)$cleanv;
831
+                        $cleanv = (int) $cleanv;
832 832
                         break;
833 833
 
834 834
                     case XOBJ_DTYPE_CURRENCY:
@@ -858,10 +858,10 @@  discard block
 block discarded – undo
858 858
                             continue 2;
859 859
                         }
860 860
                         if ($cleanv !== '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) {
861
-                            $cleanv = 'http://' . $cleanv;
861
+                            $cleanv = 'http://'.$cleanv;
862 862
                         }
863 863
                         if (!$v['not_gpc']) {
864
-                            $cleanv =& $ts->stripSlashesGPC($cleanv);
864
+                            $cleanv = & $ts->stripSlashesGPC($cleanv);
865 865
                         }
866 866
                         break;
867 867
                     case XOBJ_DTYPE_SIMPLE_ARRAY:
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
                     case XOBJ_DTYPE_STIME:
874 874
                     case XOBJ_DTYPE_MTIME:
875 875
                     case XOBJ_DTYPE_LTIME:
876
-                        $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv);
876
+                        $cleanv = !is_string($cleanv) ? (int) $cleanv : strtotime($cleanv);
877 877
                         if (!($cleanv > 0)) {
878 878
                             $cleanv = strtotime($cleanv);
879 879
                         }
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
                         break;
883 883
                 }
884 884
             }
885
-            $this->cleanVars[$k] =& $cleanv;
885
+            $this->cleanVars[$k] = & $cleanv;
886 886
             unset($cleanv);
887 887
         }
888 888
         if (count($this->_errors) > 0) {
@@ -1100,10 +1100,10 @@  discard block
 block discarded – undo
1100 1100
                 }
1101 1101
                 break;
1102 1102
             case XOBJ_DTYPE_SIMPLE_ARRAY:
1103
-                $ret =& explode('|', $ret);
1103
+                $ret = & explode('|', $ret);
1104 1104
                 break;
1105 1105
             case XOBJ_DTYPE_ARRAY:
1106
-                $ret =& unserialize($ret);
1106
+                $ret = & unserialize($ret);
1107 1107
                 break;
1108 1108
             case XOBJ_DTYPE_SOURCE:
1109 1109
                 switch (strtolower($format)) {
@@ -1257,7 +1257,7 @@  discard block
 block discarded – undo
1257 1257
      */
1258 1258
     public function displaySingleObject($fetchOnly = false, $userSide = false, $actions = array(), $headerAsRow = true)
1259 1259
     {
1260
-        include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php';
1260
+        include_once SMARTOBJECT_ROOT_PATH.'class/smartobjectsingleview.php';
1261 1261
         $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow);
1262 1262
         // add all fields mark as displayOnSingleView except the keyid
1263 1263
         foreach ($this->vars as $key => $var) {
Please login to merge, or discard this patch.
class/smartobjectcontroller.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 
124 124
     /**
125 125
      * @param        $smartObj
126
-     * @param        $objectid
127
-     * @param        $created_success_msg
128
-     * @param        $modified_success_msg
126
+     * @param        integer $objectid
127
+     * @param        string $created_success_msg
128
+     * @param        string $modified_success_msg
129 129
      * @param  bool  $redirect_page
130 130
      * @param  bool  $debug
131 131
      * @return mixed
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      * @param  bool   $confirm_msg
290 290
      * @param  string $op
291 291
      * @param  bool   $userSide
292
-     * @return bool
292
+     * @return boolean|null
293 293
      * @internal param string $redir_page redirect page after deleting the object
294 294
      */
295 295
     public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false)
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
     }
444 444
 
445 445
     /**
446
-     * @param         $smartObj
446
+     * @param         SmartMlObject $smartObj
447 447
      * @param  bool   $onlyUrl
448 448
      * @param  bool   $withimage
449 449
      * @return string
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
     }
534 534
 
535 535
     /**
536
-     * @param $smartObj
536
+     * @param SmartObject $smartObj
537 537
      * @return string
538 538
      */
539 539
     public function getPrintAndMailLink($smartObj)
Please login to merge, or discard this patch.
Indentation   +544 added lines, -544 removed lines patch added patch discarded remove patch
@@ -31,548 +31,548 @@
 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'),
324
-                          sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
325
-
326
-            xoops_cp_footer();
327
-        }
328
-        exit();
329
-    }
330
-
331
-    /**
332
-     * @param bool   $confirm_msg
333
-     * @param string $op
334
-     */
335
-    public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del')
336
-    {
337
-        global $smart_previous_page, $xoopsTpl;
338
-
339
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
340
-        $smartObj = $this->handler->get($objectid);
341
-
342
-        if ($smartObj->isNew()) {
343
-            redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
344
-        }
345
-
346
-        $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
347
-        if ($confirm) {
348
-            if (!$this->handler->delete($smartObj)) {
349
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
350
-                exit;
351
-            }
352
-
353
-            redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
354
-        } else {
355
-            // no confirm: show deletion condition
356
-            if (!$confirm_msg) {
357
-                $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
358
-            }
359
-
360
-            ob_start();
361
-            xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'),
362
-                          sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
363
-            $smartobjectDeleteConfirm = ob_get_clean();
364
-            $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm);
365
-        }
366
-    }
367
-
368
-    /**
369
-     * Retreive the object admin side link for a {@link SmartObjectSingleView} page
370
-     *
371
-     * @param  SmartObject $smartObj  reference to the object from which we want the user side link
372
-     * @param  bool   $onlyUrl   wether or not to return a simple URL or a full <a> link
373
-     * @param  bool   $withimage
374
-     * @return string admin side link to the object
375
-     */
376
-    public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
377
-    {
378
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
379
-        if ($onlyUrl) {
380
-            return $ret;
381
-        } elseif ($withimage) {
382
-            return "<a href='" .
383
-                   $ret .
384
-                   "'><img src='" .
385
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
386
-                   "viewmag.png' style='vertical-align: middle;' alt='" .
387
-                   _CO_SOBJECT_ADMIN_VIEW .
388
-                   "'  title='" .
389
-                   _CO_SOBJECT_ADMIN_VIEW .
390
-                   "'/></a>";
391
-        }
392
-
393
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
394
-    }
395
-
396
-    /**
397
-     * Retreive the object user side link
398
-     *
399
-     * @param  SmartObject $smartObj reference to the object from which we want the user side link
400
-     * @param  bool   $onlyUrl  wether or not to return a simple URL or a full <a> link
401
-     * @return string user side link to the object
402
-     */
403
-    public function getItemLink(SmartObject $smartObj, $onlyUrl = false)
404
-    {
405
-        $seoMode       = smart_getModuleModeSEO($this->handler->_moduleName);
406
-        $seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName);
407
-
408
-        /**
409
-         * $seoIncludeId feature is not finished yet, so let's put it always to true
410
-         */
411
-        //$seoIncludeId = smart_getModuleIncludeIdSEO($this->handler->_moduleName);
412
-        $seoIncludeId = true;
413
-
414
-        if ($seoMode === 'rewrite') {
415
-            $ret = XOOPS_URL .
416
-                   '/' .
417
-                   $seoModuleName .
418
-                   '.' .
419
-                   $this->handler->_itemname .
420
-                   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
421
-                   '/' .
422
-                   $smartObj->getVar('short_url') .
423
-                   '.html';
424
-        } elseif ($seoMode === 'pathinfo') {
425
-            $ret = SMARTOBJECT_URL .
426
-                   'seo.php/' .
427
-                   $seoModuleName .
428
-                   '.' .
429
-                   $this->handler->_itemname .
430
-                   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
431
-                   '/' .
432
-                   $smartObj->getVar('short_url') .
433
-                   '.html';
434
-        } else {
435
-            $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
436
-        }
437
-
438
-        if (!$onlyUrl) {
439
-            $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
440
-        }
441
-
442
-        return $ret;
443
-    }
444
-
445
-    /**
446
-     * @param         $smartObj
447
-     * @param  bool   $onlyUrl
448
-     * @param  bool   $withimage
449
-     * @return string
450
-     */
451
-    public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
452
-    {
453
-        $ret = $this->handler->_moduleUrl .
454
-               'admin/' .
455
-               $this->handler->_page .
456
-               '?op=mod&' .
457
-               $this->handler->keyName .
458
-               '=' .
459
-               $smartObj->getVar($this->handler->keyName) .
460
-               '&language=' .
461
-               $smartObj->getVar('language');
462
-        if ($onlyUrl) {
463
-            return $ret;
464
-        } elseif ($withimage) {
465
-            return "<a href='" .
466
-                   $ret .
467
-                   "'><img src='" .
468
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
469
-                   "wizard.png' style='vertical-align: middle;' alt='" .
470
-                   _CO_SOBJECT_LANGUAGE_MODIFY .
471
-                   "'  title='" .
472
-                   _CO_SOBJECT_LANGUAGE_MODIFY .
473
-                   "'/></a>";
474
-        }
475
-
476
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
477
-    }
478
-
479
-    /**
480
-     * @param         $smartObj
481
-     * @param  bool   $onlyUrl
482
-     * @param  bool   $withimage
483
-     * @param  bool   $userSide
484
-     * @return string
485
-     */
486
-    public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
487
-    {
488
-        $admin_side = $userSide ? '' : 'admin/';
489
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
490
-        if ($onlyUrl) {
491
-            return $ret;
492
-        } elseif ($withimage) {
493
-            return "<a href='" .
494
-                   $ret .
495
-                   "'><img src='" .
496
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
497
-                   "edit.png' style='vertical-align: middle;' alt='" .
498
-                   _CO_SOBJECT_MODIFY .
499
-                   "'  title='" .
500
-                   _CO_SOBJECT_MODIFY .
501
-                   "'/></a>";
502
-        }
503
-
504
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
505
-    }
506
-
507
-    /**
508
-     * @param         $smartObj
509
-     * @param  bool   $onlyUrl
510
-     * @param  bool   $withimage
511
-     * @param  bool   $userSide
512
-     * @return string
513
-     */
514
-    public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
515
-    {
516
-        $admin_side = $userSide ? '' : 'admin/';
517
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
518
-        if ($onlyUrl) {
519
-            return $ret;
520
-        } elseif ($withimage) {
521
-            return "<a href='" .
522
-                   $ret .
523
-                   "'><img src='" .
524
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
525
-                   "editdelete.png' style='vertical-align: middle;' alt='" .
526
-                   _CO_SOBJECT_DELETE .
527
-                   "'  title='" .
528
-                   _CO_SOBJECT_DELETE .
529
-                   "'/></a>";
530
-        }
531
-
532
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
533
-    }
534
-
535
-    /**
536
-     * @param $smartObj
537
-     * @return string
538
-     */
539
-    public function getPrintAndMailLink($smartObj)
540
-    {
541
-        global $xoopsConfig;
542
-
543
-        $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
544
-        $js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
545
-        $printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"/></a>';
546
-
547
-        $smartModule = smart_getModuleInfo($smartObj->handler->_moduleName);
548
-        $link        = smart_getCurrentPage();
549
-        $mid         = $smartModule->getVar('mid');
550
-        $friendlink  = "<a href=\"javascript:openWithSelfMain('" .
551
-                       SMARTOBJECT_URL .
552
-                       'sendlink.php?link=' .
553
-                       $link .
554
-                       '&amp;mid=' .
555
-                       $mid .
556
-                       "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" .
557
-                       SMARTOBJECT_IMAGES_ACTIONS_URL .
558
-                       "mail_send.png\"  alt=\"" .
559
-                       _CO_SOBJECT_EMAIL .
560
-                       "\" title=\"" .
561
-                       _CO_SOBJECT_EMAIL .
562
-                       "\" style=\"vertical-align: middle;\"/></a>";
563
-
564
-        $ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
565
-
566
-        return $ret;
567
-    }
568
-
569
-    /**
570
-     * @return string
571
-     */
572
-    public function getModuleItemString()
573
-    {
574
-        $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
575
-
576
-        return $ret;
577
-    }
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'),
324
+						  sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
325
+
326
+			xoops_cp_footer();
327
+		}
328
+		exit();
329
+	}
330
+
331
+	/**
332
+	 * @param bool   $confirm_msg
333
+	 * @param string $op
334
+	 */
335
+	public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del')
336
+	{
337
+		global $smart_previous_page, $xoopsTpl;
338
+
339
+		$objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
340
+		$smartObj = $this->handler->get($objectid);
341
+
342
+		if ($smartObj->isNew()) {
343
+			redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
344
+		}
345
+
346
+		$confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
347
+		if ($confirm) {
348
+			if (!$this->handler->delete($smartObj)) {
349
+				redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
350
+				exit;
351
+			}
352
+
353
+			redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
354
+		} else {
355
+			// no confirm: show deletion condition
356
+			if (!$confirm_msg) {
357
+				$confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
358
+			}
359
+
360
+			ob_start();
361
+			xoops_confirm(array('op' => $op, $this->handler->keyName => $smartObj->getVar($this->handler->keyName), 'confirm' => 1, 'redirect_page' => $smart_previous_page), xoops_getenv('PHP_SELF'),
362
+						  sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
363
+			$smartobjectDeleteConfirm = ob_get_clean();
364
+			$xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm);
365
+		}
366
+	}
367
+
368
+	/**
369
+	 * Retreive the object admin side link for a {@link SmartObjectSingleView} page
370
+	 *
371
+	 * @param  SmartObject $smartObj  reference to the object from which we want the user side link
372
+	 * @param  bool   $onlyUrl   wether or not to return a simple URL or a full <a> link
373
+	 * @param  bool   $withimage
374
+	 * @return string admin side link to the object
375
+	 */
376
+	public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
377
+	{
378
+		$ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
379
+		if ($onlyUrl) {
380
+			return $ret;
381
+		} elseif ($withimage) {
382
+			return "<a href='" .
383
+				   $ret .
384
+				   "'><img src='" .
385
+				   SMARTOBJECT_IMAGES_ACTIONS_URL .
386
+				   "viewmag.png' style='vertical-align: middle;' alt='" .
387
+				   _CO_SOBJECT_ADMIN_VIEW .
388
+				   "'  title='" .
389
+				   _CO_SOBJECT_ADMIN_VIEW .
390
+				   "'/></a>";
391
+		}
392
+
393
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
394
+	}
395
+
396
+	/**
397
+	 * Retreive the object user side link
398
+	 *
399
+	 * @param  SmartObject $smartObj reference to the object from which we want the user side link
400
+	 * @param  bool   $onlyUrl  wether or not to return a simple URL or a full <a> link
401
+	 * @return string user side link to the object
402
+	 */
403
+	public function getItemLink(SmartObject $smartObj, $onlyUrl = false)
404
+	{
405
+		$seoMode       = smart_getModuleModeSEO($this->handler->_moduleName);
406
+		$seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName);
407
+
408
+		/**
409
+		 * $seoIncludeId feature is not finished yet, so let's put it always to true
410
+		 */
411
+		//$seoIncludeId = smart_getModuleIncludeIdSEO($this->handler->_moduleName);
412
+		$seoIncludeId = true;
413
+
414
+		if ($seoMode === 'rewrite') {
415
+			$ret = XOOPS_URL .
416
+				   '/' .
417
+				   $seoModuleName .
418
+				   '.' .
419
+				   $this->handler->_itemname .
420
+				   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
421
+				   '/' .
422
+				   $smartObj->getVar('short_url') .
423
+				   '.html';
424
+		} elseif ($seoMode === 'pathinfo') {
425
+			$ret = SMARTOBJECT_URL .
426
+				   'seo.php/' .
427
+				   $seoModuleName .
428
+				   '.' .
429
+				   $this->handler->_itemname .
430
+				   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
431
+				   '/' .
432
+				   $smartObj->getVar('short_url') .
433
+				   '.html';
434
+		} else {
435
+			$ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
436
+		}
437
+
438
+		if (!$onlyUrl) {
439
+			$ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
440
+		}
441
+
442
+		return $ret;
443
+	}
444
+
445
+	/**
446
+	 * @param         $smartObj
447
+	 * @param  bool   $onlyUrl
448
+	 * @param  bool   $withimage
449
+	 * @return string
450
+	 */
451
+	public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
452
+	{
453
+		$ret = $this->handler->_moduleUrl .
454
+			   'admin/' .
455
+			   $this->handler->_page .
456
+			   '?op=mod&' .
457
+			   $this->handler->keyName .
458
+			   '=' .
459
+			   $smartObj->getVar($this->handler->keyName) .
460
+			   '&language=' .
461
+			   $smartObj->getVar('language');
462
+		if ($onlyUrl) {
463
+			return $ret;
464
+		} elseif ($withimage) {
465
+			return "<a href='" .
466
+				   $ret .
467
+				   "'><img src='" .
468
+				   SMARTOBJECT_IMAGES_ACTIONS_URL .
469
+				   "wizard.png' style='vertical-align: middle;' alt='" .
470
+				   _CO_SOBJECT_LANGUAGE_MODIFY .
471
+				   "'  title='" .
472
+				   _CO_SOBJECT_LANGUAGE_MODIFY .
473
+				   "'/></a>";
474
+		}
475
+
476
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
477
+	}
478
+
479
+	/**
480
+	 * @param         $smartObj
481
+	 * @param  bool   $onlyUrl
482
+	 * @param  bool   $withimage
483
+	 * @param  bool   $userSide
484
+	 * @return string
485
+	 */
486
+	public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
487
+	{
488
+		$admin_side = $userSide ? '' : 'admin/';
489
+		$ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
490
+		if ($onlyUrl) {
491
+			return $ret;
492
+		} elseif ($withimage) {
493
+			return "<a href='" .
494
+				   $ret .
495
+				   "'><img src='" .
496
+				   SMARTOBJECT_IMAGES_ACTIONS_URL .
497
+				   "edit.png' style='vertical-align: middle;' alt='" .
498
+				   _CO_SOBJECT_MODIFY .
499
+				   "'  title='" .
500
+				   _CO_SOBJECT_MODIFY .
501
+				   "'/></a>";
502
+		}
503
+
504
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
505
+	}
506
+
507
+	/**
508
+	 * @param         $smartObj
509
+	 * @param  bool   $onlyUrl
510
+	 * @param  bool   $withimage
511
+	 * @param  bool   $userSide
512
+	 * @return string
513
+	 */
514
+	public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
515
+	{
516
+		$admin_side = $userSide ? '' : 'admin/';
517
+		$ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
518
+		if ($onlyUrl) {
519
+			return $ret;
520
+		} elseif ($withimage) {
521
+			return "<a href='" .
522
+				   $ret .
523
+				   "'><img src='" .
524
+				   SMARTOBJECT_IMAGES_ACTIONS_URL .
525
+				   "editdelete.png' style='vertical-align: middle;' alt='" .
526
+				   _CO_SOBJECT_DELETE .
527
+				   "'  title='" .
528
+				   _CO_SOBJECT_DELETE .
529
+				   "'/></a>";
530
+		}
531
+
532
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
533
+	}
534
+
535
+	/**
536
+	 * @param $smartObj
537
+	 * @return string
538
+	 */
539
+	public function getPrintAndMailLink($smartObj)
540
+	{
541
+		global $xoopsConfig;
542
+
543
+		$printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
544
+		$js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
545
+		$printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"/></a>';
546
+
547
+		$smartModule = smart_getModuleInfo($smartObj->handler->_moduleName);
548
+		$link        = smart_getCurrentPage();
549
+		$mid         = $smartModule->getVar('mid');
550
+		$friendlink  = "<a href=\"javascript:openWithSelfMain('" .
551
+					   SMARTOBJECT_URL .
552
+					   'sendlink.php?link=' .
553
+					   $link .
554
+					   '&amp;mid=' .
555
+					   $mid .
556
+					   "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" .
557
+					   SMARTOBJECT_IMAGES_ACTIONS_URL .
558
+					   "mail_send.png\"  alt=\"" .
559
+					   _CO_SOBJECT_EMAIL .
560
+					   "\" title=\"" .
561
+					   _CO_SOBJECT_EMAIL .
562
+					   "\" style=\"vertical-align: middle;\"/></a>";
563
+
564
+		$ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
565
+
566
+		return $ret;
567
+	}
568
+
569
+	/**
570
+	 * @return string
571
+	 */
572
+	public function getModuleItemString()
573
+	{
574
+		$ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
575
+
576
+		return $ret;
577
+	}
578 578
 }
Please login to merge, or discard this patch.
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
  * @credit  Jan Keller Pedersen <[email protected]> - IDG Danmark A/S <www.idg.dk>
24 24
  * @link    http://smartfactory.ca The SmartFactory
25 25
  */
26
-include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
27
-include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjecthandler.php';
26
+include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php';
27
+include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobjecthandler.php';
28 28
 
29 29
 /**
30 30
  * Class SmartObjectController
@@ -50,15 +50,15 @@  discard block
 block discarded – undo
50 50
         foreach (array_keys($smartObj->vars) as $key) {
51 51
             switch ($smartObj->vars[$key]['data_type']) {
52 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]);
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 56
                         if (file_exists($oldFile)) {
57 57
                             unlink($oldFile);
58 58
                         }
59 59
                     }
60
-                    if (isset($_POST['delete_' . $key]) && $_POST['delete_' . $key] == '1') {
61
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
60
+                    if (isset($_POST['delete_'.$key]) && $_POST['delete_'.$key] == '1') {
61
+                        $oldFile = $smartObj->getUploadDir(true).$smartObj->getVar($key, 'e');
62 62
                         $smartObj->setVar($key, '');
63 63
                         if (file_exists($oldFile)) {
64 64
                             unlink($oldFile);
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
 
69 69
                 case XOBJ_DTYPE_URLLINK:
70 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]);
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 75
                     if ($linkObj->getVar('url') !== '') {
76 76
                         $smartObj->storeUrlLinkObj($linkObj);
77 77
                     }
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
                     break;
81 81
 
82 82
                 case XOBJ_DTYPE_FILE:
83
-                    if (!isset($_FILES['upload_' . $key]['name']) || $_FILES['upload_' . $key]['name'] === '') {
83
+                    if (!isset($_FILES['upload_'.$key]['name']) || $_FILES['upload_'.$key]['name'] === '') {
84 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]);
85
+                        $fileObj->setVar('caption', $_POST['caption_'.$key]);
86
+                        $fileObj->setVar('description', $_POST['desc_'.$key]);
87
+                        $fileObj->setVar('url', $_POST['url_'.$key]);
88 88
                         if (!($fileObj->getVar('url') === '' && $fileObj->getVar('url') === '' && $fileObj->getVar('url') === '')) {
89 89
                             $res = $smartObj->storeFileObj($fileObj);
90 90
                             if ($res) {
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
                         $value = strtotime($_POST[$key]);
108 108
                         //if strtotime returns false, the value is already a time stamp
109 109
                         if (!$value) {
110
-                            $value = (int)$_POST[$key];
110
+                            $value = (int) $_POST[$key];
111 111
                         }
112 112
                     }
113 113
                     $smartObj->setVar($key, $value);
@@ -144,12 +144,12 @@  discard block
 block discarded – undo
144 144
 
145 145
         // Check if there were uploaded files
146 146
         if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) {
147
-            include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php';
147
+            include_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartuploader.php';
148 148
             $uploaderObj = new SmartUploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight);
149 149
             foreach ($_FILES as $name => $file_array) {
150 150
                 if (isset($file_array['name']) && $file_array['name'] !== '' && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
151 151
                     if ($uploaderObj->fetchMedia($name)) {
152
-                        $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
152
+                        $uploaderObj->setTargetFileName(time().'_'.$uploaderObj->getMediaName());
153 153
                         if ($uploaderObj->upload()) {
154 154
                             // Find the related field in the SmartObject
155 155
                             $related_field   = str_replace('upload_', '', $name);
@@ -158,14 +158,14 @@  discard block
 block discarded – undo
158 158
                             if ($smartObj->vars[$related_field]['data_type'] === XOBJ_DTYPE_FILE) {
159 159
                                 $object_fileurl = $smartObj->getUploadDir();
160 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]);
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 164
                                 $smartObj->storeFileObj($fileObj);
165 165
                                 //todo: catch errors
166 166
                                 $smartObj->setVar($related_field, $fileObj->getVar('fileid'));
167 167
                             } else {
168
-                                $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
168
+                                $old_file = $smartObj->getUploadDir(true).$smartObj->getVar($related_field);
169 169
                                 unlink($old_file);
170 170
                                 $smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
171 171
                             }
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
             return $smartObj;
197 197
         } else {
198 198
             if (!$storeResult) {
199
-                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
199
+                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR.$smartObj->getHtmlErrors());
200 200
             }
201 201
 
202 202
             $redirect_page = $redirect_page ?: smart_get_page_before_form();
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
      */
221 221
     public function storeFromDefaultForm($created_success_msg, $modified_success_msg, $redirect_page = false, $debug = false, $x_param = false)
222 222
     {
223
-        $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
223
+        $objectid = isset($_POST[$this->handler->keyName]) ? (int) $_POST[$this->handler->keyName] : 0;
224 224
         if ($debug) {
225 225
             if ($x_param) {
226 226
                 $smartObj = $this->handler->getD($objectid, true, $x_param);
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
     {
297 297
         global $smart_previous_page;
298 298
 
299
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
299
+        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0;
300 300
         $smartObj = $this->handler->get($objectid);
301 301
 
302 302
         if ($smartObj->isNew()) {
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
         $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
307 307
         if ($confirm) {
308 308
             if (!$this->handler->delete($smartObj)) {
309
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
309
+                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors());
310 310
                 exit;
311 311
             }
312 312
 
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
     {
337 337
         global $smart_previous_page, $xoopsTpl;
338 338
 
339
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
339
+        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0;
340 340
         $smartObj = $this->handler->get($objectid);
341 341
 
342 342
         if ($smartObj->isNew()) {
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
         $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
347 347
         if ($confirm) {
348 348
             if (!$this->handler->delete($smartObj)) {
349
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
349
+                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors());
350 350
                 exit;
351 351
             }
352 352
 
@@ -375,22 +375,22 @@  discard block
 block discarded – undo
375 375
      */
376 376
     public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
377 377
     {
378
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
378
+        $ret = $this->handler->_moduleUrl.'admin/'.$this->handler->_page.'?op=view&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
379 379
         if ($onlyUrl) {
380 380
             return $ret;
381 381
         } elseif ($withimage) {
382
-            return "<a href='" .
383
-                   $ret .
384
-                   "'><img src='" .
385
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
386
-                   "viewmag.png' style='vertical-align: middle;' alt='" .
387
-                   _CO_SOBJECT_ADMIN_VIEW .
388
-                   "'  title='" .
389
-                   _CO_SOBJECT_ADMIN_VIEW .
382
+            return "<a href='".
383
+                   $ret.
384
+                   "'><img src='".
385
+                   SMARTOBJECT_IMAGES_ACTIONS_URL.
386
+                   "viewmag.png' style='vertical-align: middle;' alt='".
387
+                   _CO_SOBJECT_ADMIN_VIEW.
388
+                   "'  title='".
389
+                   _CO_SOBJECT_ADMIN_VIEW.
390 390
                    "'/></a>";
391 391
         }
392 392
 
393
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
393
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
394 394
     }
395 395
 
396 396
     /**
@@ -412,31 +412,31 @@  discard block
 block discarded – undo
412 412
         $seoIncludeId = true;
413 413
 
414 414
         if ($seoMode === 'rewrite') {
415
-            $ret = XOOPS_URL .
416
-                   '/' .
417
-                   $seoModuleName .
418
-                   '.' .
419
-                   $this->handler->_itemname .
420
-                   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
421
-                   '/' .
422
-                   $smartObj->getVar('short_url') .
415
+            $ret = XOOPS_URL.
416
+                   '/'.
417
+                   $seoModuleName.
418
+                   '.'.
419
+                   $this->handler->_itemname.
420
+                   ($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').
421
+                   '/'.
422
+                   $smartObj->getVar('short_url').
423 423
                    '.html';
424 424
         } elseif ($seoMode === 'pathinfo') {
425
-            $ret = SMARTOBJECT_URL .
426
-                   'seo.php/' .
427
-                   $seoModuleName .
428
-                   '.' .
429
-                   $this->handler->_itemname .
430
-                   ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') .
431
-                   '/' .
432
-                   $smartObj->getVar('short_url') .
425
+            $ret = SMARTOBJECT_URL.
426
+                   'seo.php/'.
427
+                   $seoModuleName.
428
+                   '.'.
429
+                   $this->handler->_itemname.
430
+                   ($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').
431
+                   '/'.
432
+                   $smartObj->getVar('short_url').
433 433
                    '.html';
434 434
         } else {
435
-            $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
435
+            $ret = $this->handler->_moduleUrl.$this->handler->_page.'?'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
436 436
         }
437 437
 
438 438
         if (!$onlyUrl) {
439
-            $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
439
+            $ret = "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
440 440
         }
441 441
 
442 442
         return $ret;
@@ -450,30 +450,30 @@  discard block
 block discarded – undo
450 450
      */
451 451
     public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
452 452
     {
453
-        $ret = $this->handler->_moduleUrl .
454
-               'admin/' .
455
-               $this->handler->_page .
456
-               '?op=mod&' .
457
-               $this->handler->keyName .
458
-               '=' .
459
-               $smartObj->getVar($this->handler->keyName) .
460
-               '&language=' .
453
+        $ret = $this->handler->_moduleUrl.
454
+               'admin/'.
455
+               $this->handler->_page.
456
+               '?op=mod&'.
457
+               $this->handler->keyName.
458
+               '='.
459
+               $smartObj->getVar($this->handler->keyName).
460
+               '&language='.
461 461
                $smartObj->getVar('language');
462 462
         if ($onlyUrl) {
463 463
             return $ret;
464 464
         } elseif ($withimage) {
465
-            return "<a href='" .
466
-                   $ret .
467
-                   "'><img src='" .
468
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
469
-                   "wizard.png' style='vertical-align: middle;' alt='" .
470
-                   _CO_SOBJECT_LANGUAGE_MODIFY .
471
-                   "'  title='" .
472
-                   _CO_SOBJECT_LANGUAGE_MODIFY .
465
+            return "<a href='".
466
+                   $ret.
467
+                   "'><img src='".
468
+                   SMARTOBJECT_IMAGES_ACTIONS_URL.
469
+                   "wizard.png' style='vertical-align: middle;' alt='".
470
+                   _CO_SOBJECT_LANGUAGE_MODIFY.
471
+                   "'  title='".
472
+                   _CO_SOBJECT_LANGUAGE_MODIFY.
473 473
                    "'/></a>";
474 474
         }
475 475
 
476
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
476
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
477 477
     }
478 478
 
479 479
     /**
@@ -486,22 +486,22 @@  discard block
 block discarded – undo
486 486
     public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
487 487
     {
488 488
         $admin_side = $userSide ? '' : 'admin/';
489
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
489
+        $ret        = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=mod&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
490 490
         if ($onlyUrl) {
491 491
             return $ret;
492 492
         } elseif ($withimage) {
493
-            return "<a href='" .
494
-                   $ret .
495
-                   "'><img src='" .
496
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
497
-                   "edit.png' style='vertical-align: middle;' alt='" .
498
-                   _CO_SOBJECT_MODIFY .
499
-                   "'  title='" .
500
-                   _CO_SOBJECT_MODIFY .
493
+            return "<a href='".
494
+                   $ret.
495
+                   "'><img src='".
496
+                   SMARTOBJECT_IMAGES_ACTIONS_URL.
497
+                   "edit.png' style='vertical-align: middle;' alt='".
498
+                   _CO_SOBJECT_MODIFY.
499
+                   "'  title='".
500
+                   _CO_SOBJECT_MODIFY.
501 501
                    "'/></a>";
502 502
         }
503 503
 
504
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
504
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
505 505
     }
506 506
 
507 507
     /**
@@ -514,22 +514,22 @@  discard block
 block discarded – undo
514 514
     public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
515 515
     {
516 516
         $admin_side = $userSide ? '' : 'admin/';
517
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
517
+        $ret        = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=del&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
518 518
         if ($onlyUrl) {
519 519
             return $ret;
520 520
         } elseif ($withimage) {
521
-            return "<a href='" .
522
-                   $ret .
523
-                   "'><img src='" .
524
-                   SMARTOBJECT_IMAGES_ACTIONS_URL .
525
-                   "editdelete.png' style='vertical-align: middle;' alt='" .
526
-                   _CO_SOBJECT_DELETE .
527
-                   "'  title='" .
528
-                   _CO_SOBJECT_DELETE .
521
+            return "<a href='".
522
+                   $ret.
523
+                   "'><img src='".
524
+                   SMARTOBJECT_IMAGES_ACTIONS_URL.
525
+                   "editdelete.png' style='vertical-align: middle;' alt='".
526
+                   _CO_SOBJECT_DELETE.
527
+                   "'  title='".
528
+                   _CO_SOBJECT_DELETE.
529 529
                    "'/></a>";
530 530
         }
531 531
 
532
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
532
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
533 533
     }
534 534
 
535 535
     /**
@@ -540,28 +540,28 @@  discard block
 block discarded – undo
540 540
     {
541 541
         global $xoopsConfig;
542 542
 
543
-        $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
544
-        $js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
545
-        $printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"/></a>';
543
+        $printlink = $this->handler->_moduleUrl.'print.php?'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
544
+        $js        = "javascript:openWithSelfMain('".$printlink."', 'smartpopup', 700, 519);";
545
+        $printlink = '<a href="'.$js.'"><img  src="'.SMARTOBJECT_IMAGES_ACTIONS_URL.'fileprint.png" alt="" style="vertical-align: middle;"/></a>';
546 546
 
547 547
         $smartModule = smart_getModuleInfo($smartObj->handler->_moduleName);
548 548
         $link        = smart_getCurrentPage();
549 549
         $mid         = $smartModule->getVar('mid');
550
-        $friendlink  = "<a href=\"javascript:openWithSelfMain('" .
551
-                       SMARTOBJECT_URL .
552
-                       'sendlink.php?link=' .
553
-                       $link .
554
-                       '&amp;mid=' .
555
-                       $mid .
556
-                       "', ',',',',',','sendmessage', 674, 500);\"><img src=\"" .
557
-                       SMARTOBJECT_IMAGES_ACTIONS_URL .
558
-                       "mail_send.png\"  alt=\"" .
559
-                       _CO_SOBJECT_EMAIL .
560
-                       "\" title=\"" .
561
-                       _CO_SOBJECT_EMAIL .
550
+        $friendlink  = "<a href=\"javascript:openWithSelfMain('".
551
+                       SMARTOBJECT_URL.
552
+                       'sendlink.php?link='.
553
+                       $link.
554
+                       '&amp;mid='.
555
+                       $mid.
556
+                       "', ',',',',',','sendmessage', 674, 500);\"><img src=\"".
557
+                       SMARTOBJECT_IMAGES_ACTIONS_URL.
558
+                       "mail_send.png\"  alt=\"".
559
+                       _CO_SOBJECT_EMAIL.
560
+                       "\" title=\"".
561
+                       _CO_SOBJECT_EMAIL.
562 562
                        "\" style=\"vertical-align: middle;\"/></a>";
563 563
 
564
-        $ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
564
+        $ret = '<span id="smartobject_print_button">'.$printlink.'&nbsp;</span>'.'<span id="smartobject_mail_button">'.$friendlink.'</span>';
565 565
 
566 566
         return $ret;
567 567
     }
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
      */
572 572
     public function getModuleItemString()
573 573
     {
574
-        $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
574
+        $ret = $this->handler->_moduleName.'_'.$this->handler->_itemname;
575 575
 
576 576
         return $ret;
577 577
     }
Please login to merge, or discard this patch.
class/smartobjecthandler.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
      *
133 133
      * @param XoopsDatabase $db           {@link XoopsDatabase}
134 134
      *                                           object
135
-     * @param                      $itemname
135
+     * @param                      string $itemname
136 136
      * @param string               $keyname      Name of the table key that uniquely identify each {@link SmartObject}
137 137
      * @param string               $idenfierName Name of the field which properly identify the {@link SmartObject}
138
-     * @param                      $summaryName
138
+     * @param                      string $summaryName
139 139
      * @param                      $modulename
140 140
      * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a>
141 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
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
     /**
193 193
      * @param $criteria
194
-     * @param $perm_name
194
+     * @param boolean $perm_name
195 195
      * @return bool
196 196
      */
197 197
     public function setGrantedObjectsCriteria(&$criteria, $perm_name)
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
     }
376 376
 
377 377
     /**
378
-     * @param        $sql
378
+     * @param        string $sql
379 379
      * @param        $criteria
380 380
      * @param  bool  $force
381 381
      * @param  bool  $debug
Please login to merge, or discard this 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 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 SmartObject {@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 CriteriaElement $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(CriteriaElement $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 (false !== ($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 CriteriaElement $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(CriteriaElement $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 (false !== ($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 CriteriaElement $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(CriteriaElement $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 (false !== ($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  CriteriaElement $criteria {@link CriteriaElement} to match
557
-     * @return int    count of objects
558
-     */
559
-    public function getCount(CriteriaElement $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 (false !== (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 CriteriaElement $criteria   {@link CriteriaElement}
859
-     *
860
-     * @param  bool $force
861
-     * @return bool
862
-     */
863
-    public function updateAll($fieldname, $fieldvalue, CriteriaElement $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  CriteriaElement $criteria {@link CriteriaElement} with conditions to meet
893
-     * @return bool
894
-     */
895
-
896
-    public function deleteAll(CriteriaElement $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 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 SmartObject {@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 CriteriaElement $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(CriteriaElement $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 (false !== ($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 CriteriaElement $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(CriteriaElement $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 (false !== ($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 CriteriaElement $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(CriteriaElement $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 (false !== ($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  CriteriaElement $criteria {@link CriteriaElement} to match
557
+	 * @return int    count of objects
558
+	 */
559
+	public function getCount(CriteriaElement $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 (false !== (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 CriteriaElement $criteria   {@link CriteriaElement}
859
+	 *
860
+	 * @param  bool $force
861
+	 * @return bool
862
+	 */
863
+	public function updateAll($fieldname, $fieldvalue, CriteriaElement $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  CriteriaElement $criteria {@link CriteriaElement} with conditions to meet
893
+	 * @return bool
894
+	 */
895
+
896
+	public function deleteAll(CriteriaElement $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.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -148,16 +148,16 @@  discard block
 block discarded – undo
148 148
 
149 149
         $this->_itemname      = $itemname;
150 150
         $this->_moduleName    = $modulename;
151
-        $this->table          = $db->prefix($modulename . '_' . $itemname);
151
+        $this->table          = $db->prefix($modulename.'_'.$itemname);
152 152
         $this->keyName        = $keyname;
153
-        $this->className      = ucfirst($modulename) . ucfirst($itemname);
153
+        $this->className      = ucfirst($modulename).ucfirst($itemname);
154 154
         $this->identifierName = $idenfierName;
155 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 . '/';
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 161
     }
162 162
 
163 163
     /**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function addPermission($perm_name, $caption, $description = false)
182 182
     {
183
-        include_once(SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php');
183
+        include_once(SMARTOBJECT_ROOT_PATH.'class/smartobjectpermission.php');
184 184
 
185 185
         $this->permissionsArray[] = array(
186 186
             'perm_name'   => $perm_name,
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
         $smartPermissionsHandler = new SmartobjectPermissionHandler($this);
200 200
         $grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
201 201
         if (count($grantedItems) > 0) {
202
-            $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
202
+            $criteria->add(new Criteria($this->keyName, '('.implode(', ', $grantedItems).')', 'IN'));
203 203
 
204 204
             return true;
205 205
         } else {
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
         $obj = new $this->className($this);
236 236
         $obj->setImageDir($this->getImageUrl(), $this->getImagePath());
237 237
         if (!$obj->handler) {
238
-            $obj->handler =& $this;
238
+            $obj->handler = & $this;
239 239
         }
240 240
 
241 241
         if ($isNew === true) {
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
      */
251 251
     public function getImageUrl()
252 252
     {
253
-        return $this->_uploadUrl . $this->_itemname . '/';
253
+        return $this->_uploadUrl.$this->_itemname.'/';
254 254
     }
255 255
 
256 256
     /**
@@ -258,12 +258,12 @@  discard block
 block discarded – undo
258 258
      */
259 259
     public function getImagePath()
260 260
     {
261
-        $dir = $this->_uploadPath . $this->_itemname;
261
+        $dir = $this->_uploadPath.$this->_itemname;
262 262
         if (!file_exists($dir)) {
263 263
             smart_admin_mkdir($dir);
264 264
         }
265 265
 
266
-        return $dir . '/';
266
+        return $dir.'/';
267 267
     }
268 268
 
269 269
     /**
@@ -351,13 +351,13 @@  discard block
 block discarded – undo
351 351
         if ($this->generalSQL) {
352 352
             $sql = $this->generalSQL;
353 353
         } elseif (!$sql) {
354
-            $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
354
+            $sql = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname;
355 355
         }
356 356
 
357 357
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
358
-            $sql .= ' ' . $criteria->renderWhere();
358
+            $sql .= ' '.$criteria->renderWhere();
359 359
             if ($criteria->getSort() !== '') {
360
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
360
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
361 361
             }
362 362
             $limit = $criteria->getLimit();
363 363
             $start = $criteria->getStart();
@@ -386,12 +386,12 @@  discard block
 block discarded – undo
386 386
         $ret = array();
387 387
 
388 388
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
389
-            $sql .= ' ' . $criteria->renderWhere();
389
+            $sql .= ' '.$criteria->renderWhere();
390 390
             if ($criteria->groupby) {
391 391
                 $sql .= $criteria->getGroupby();
392 392
             }
393 393
             if ($criteria->getSort() !== '') {
394
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
394
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
395 395
             }
396 396
         }
397 397
         if ($debug) {
@@ -464,18 +464,18 @@  discard block
 block discarded – undo
464 464
             $obj->assignVars($myrow);
465 465
             if (!$id_as_key) {
466 466
                 if ($as_object) {
467
-                    $ret[] =& $obj;
467
+                    $ret[] = & $obj;
468 468
                 } else {
469 469
                     $ret[] = $obj->toArray();
470 470
                 }
471 471
             } else {
472 472
                 if ($as_object) {
473
-                    $value =& $obj;
473
+                    $value = & $obj;
474 474
                 } else {
475 475
                     $value = $obj->toArray();
476 476
                 }
477 477
                 if ($id_as_key === 'parentid') {
478
-                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
478
+                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] = & $value;
479 479
                 } else {
480 480
                     $ret[$obj->getVar($this->keyName)] = $value;
481 481
                 }
@@ -518,15 +518,15 @@  discard block
 block discarded – undo
518 518
             $criteria->setSort($this->getIdentifierName());
519 519
         }
520 520
 
521
-        $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
521
+        $sql = 'SELECT '.(is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
522 522
         if (!empty($this->identifierName)) {
523
-            $sql .= ', ' . $this->getIdentifierName();
523
+            $sql .= ', '.$this->getIdentifierName();
524 524
         }
525
-        $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
525
+        $sql .= ' FROM '.$this->table.' AS '.$this->_itemname;
526 526
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
527
-            $sql .= ' ' . $criteria->renderWhere();
527
+            $sql .= ' '.$criteria->renderWhere();
528 528
             if ($criteria->getSort() !== '') {
529
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
529
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
530 530
             }
531 531
             $limit = $criteria->getLimit();
532 532
             $start = $criteria->getStart();
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
564 564
             if ($criteria->groupby !== '') {
565 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
566
+                $field   = $criteria->groupby.', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
567 567
             }
568 568
         }
569 569
         /**
@@ -574,10 +574,10 @@  discard block
 block discarded – undo
574 574
             $sql = $this->generalSQL;
575 575
             $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
576 576
         } else {
577
-            $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
577
+            $sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table.' AS '.$this->_itemname;
578 578
         }
579 579
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
580
-            $sql .= ' ' . $criteria->renderWhere();
580
+            $sql .= ' '.$criteria->renderWhere();
581 581
             if ($criteria->groupby !== '') {
582 582
                 $sql .= $criteria->getGroupby();
583 583
             }
@@ -620,13 +620,13 @@  discard block
 block discarded – undo
620 620
         if (is_array($this->keyName)) {
621 621
             $clause = array();
622 622
             for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
623
-                $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
623
+                $clause[] = $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]);
624 624
             }
625 625
             $whereclause = implode(' AND ', $clause);
626 626
         } else {
627
-            $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
627
+            $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName);
628 628
         }
629
-        $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
629
+        $sql = 'DELETE FROM '.$this->table.' WHERE '.$whereclause;
630 630
         if (false !== $force) {
631 631
             $result = $this->db->queryF($sql);
632 632
         } else {
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
              * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
688 688
              */
689 689
             if (!is_a($obj, $this->className)) {
690
-                $obj->setError(get_class($obj) . ' Differs from ' . $this->className);
690
+                $obj->setError(get_class($obj).' Differs from '.$this->className);
691 691
 
692 692
                 return false;
693 693
             }
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
         $fieldsToStoreInDB = array();
749 749
         foreach ($obj->cleanVars as $k => $v) {
750 750
             if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
751
-                $cleanvars[$k] = (int)$v;
751
+                $cleanvars[$k] = (int) $v;
752 752
             } elseif (is_array($v)) {
753 753
                 $cleanvars[$k] = $this->db->quoteString(implode(',', $v));
754 754
             } else {
@@ -761,13 +761,13 @@  discard block
 block discarded – undo
761 761
         if ($obj->isNew()) {
762 762
             if (!is_array($this->keyName)) {
763 763
                 if ($cleanvars[$this->keyName] < 1) {
764
-                    $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
764
+                    $cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq');
765 765
                 }
766 766
             }
767 767
 
768
-            $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
768
+            $sql = 'INSERT INTO '.$this->table.' ('.implode(',', array_keys($fieldsToStoreInDB)).') VALUES ('.implode(',', array_values($fieldsToStoreInDB)).')';
769 769
         } else {
770
-            $sql = 'UPDATE ' . $this->table . ' SET';
770
+            $sql = 'UPDATE '.$this->table.' SET';
771 771
             foreach ($fieldsToStoreInDB as $key => $value) {
772 772
                 if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) {
773 773
                     continue;
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
                 if (isset($notfirst)) {
776 776
                     $sql .= ',';
777 777
                 }
778
-                $sql .= ' ' . $key . ' = ' . $value;
778
+                $sql .= ' '.$key.' = '.$value;
779 779
                 $notfirst = true;
780 780
             }
781 781
             if (is_array($this->keyName)) {
@@ -784,12 +784,12 @@  discard block
 block discarded – undo
784 784
                     if ($i > 0) {
785 785
                         $whereclause .= ' AND ';
786 786
                     }
787
-                    $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
787
+                    $whereclause .= $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]);
788 788
                 }
789 789
             } else {
790
-                $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
790
+                $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName);
791 791
             }
792
-            $sql .= ' WHERE ' . $whereclause;
792
+            $sql .= ' WHERE '.$whereclause;
793 793
         }
794 794
 
795 795
         if ($debug) {
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
      */
863 863
     public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
864 864
     {
865
-        $set_clause = $fieldname . ' = ';
865
+        $set_clause = $fieldname.' = ';
866 866
         if (is_numeric($fieldvalue)) {
867 867
             $set_clause .= $fieldvalue;
868 868
         } elseif (is_array($fieldvalue)) {
@@ -870,9 +870,9 @@  discard block
 block discarded – undo
870 870
         } else {
871 871
             $set_clause .= $this->db->quoteString($fieldvalue);
872 872
         }
873
-        $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
873
+        $sql = 'UPDATE '.$this->table.' SET '.$set_clause;
874 874
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
875
-            $sql .= ' ' . $criteria->renderWhere();
875
+            $sql .= ' '.$criteria->renderWhere();
876 876
         }
877 877
         if (false != $force) {
878 878
             $result = $this->db->queryF($sql);
@@ -896,8 +896,8 @@  discard block
 block discarded – undo
896 896
     public function deleteAll(CriteriaElement $criteria = null)
897 897
     {
898 898
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
899
-            $sql = 'DELETE FROM ' . $this->table;
900
-            $sql .= ' ' . $criteria->renderWhere();
899
+            $sql = 'DELETE FROM '.$this->table;
900
+            $sql .= ' '.$criteria->renderWhere();
901 901
             if (!$this->db->query($sql)) {
902 902
                 return false;
903 903
             }
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
      */
931 931
     public function getModuleItemString()
932 932
     {
933
-        $ret = $this->_moduleName . '_' . $this->_itemname;
933
+        $ret = $this->_moduleName.'_'.$this->_itemname;
934 934
 
935 935
         return $ret;
936 936
     }
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
     {
943 943
         if (isset($object->vars['counter'])) {
944 944
             $new_counter = $object->getVar('counter') + 1;
945
-            $sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
945
+            $sql         = 'UPDATE '.$this->table.' SET counter='.$new_counter.' WHERE '.$this->keyName.'='.$object->id();
946 946
             $this->query($sql, null, true);
947 947
         }
948 948
     }
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
     public function getIdentifierName($withprefix = true)
987 987
     {
988 988
         if ($withprefix) {
989
-            return $this->_itemname . '.' . $this->identifierName;
989
+            return $this->_itemname.'.'.$this->identifierName;
990 990
         } else {
991 991
             return $this->identifierName;
992 992
         }
Please login to merge, or discard this patch.