|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Xoosocialnetwork; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Xoosocialnetwork module |
|
7
|
|
|
* |
|
8
|
|
|
* You may not change or alter any portion of this comment or credits |
|
9
|
|
|
* of supporting developers from this source code or any supporting source code |
|
10
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
16
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* @package Xoosocialnetwork |
|
18
|
|
|
* @since 2.6.0 |
|
19
|
|
|
* @author Laurent JEN (Aka DuGris) |
|
20
|
|
|
|
|
21
|
|
|
*/ |
|
22
|
|
|
use Xoops\Core\Database\Connection; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class SocialnetworkHandler |
|
26
|
|
|
*/ |
|
27
|
|
|
class SocialnetworkHandler extends \XoopsPersistableObjectHandler |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @param null|\Xoops\Core\Database\Connection $db |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(Connection $db = null) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->configPath = \XoopsBaseConfig::get('var-path') . '/configs/xoosocialnetwork/'; |
|
|
|
|
|
|
35
|
|
|
$this->configFile = 'xoosocialnetwork'; |
|
|
|
|
|
|
36
|
|
|
$this->configFileExt = '.php'; |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
parent::__construct($db, 'xoosocialnetwork', Socialnetwork::class, 'xoosocialnetwork_id', 'xoosocialnetwork_title'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return array |
|
43
|
|
|
*/ |
|
44
|
|
|
public function renderAdminList() |
|
45
|
|
|
{ |
|
46
|
|
|
$criteria = new \CriteriaCompo(); |
|
47
|
|
|
$criteria->setSort('xoosocialnetwork_order'); |
|
48
|
|
|
$criteria->setOrder('asc'); |
|
49
|
|
|
|
|
50
|
|
|
return $this->getObjects($criteria, true, false); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return array |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getDisplayed() |
|
57
|
|
|
{ |
|
58
|
|
|
$criteria = new \CriteriaCompo(); |
|
59
|
|
|
$criteria->add(new \Criteria('xoosocialnetwork_display', 1)); |
|
60
|
|
|
$criteria->setSort('xoosocialnetwork_order'); |
|
61
|
|
|
$criteria->setOrder('asc'); |
|
62
|
|
|
|
|
63
|
|
|
return $this->getObjects($criteria, true, false); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return bool|mixed |
|
68
|
|
|
*/ |
|
69
|
|
|
public function loadConfig() |
|
70
|
|
|
{ |
|
71
|
|
|
$cached_config = $this->readConfig(); |
|
72
|
|
|
if (empty($cached_config)) { |
|
73
|
|
|
$cached_config = $this->createConfig(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $cached_config; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return mixed |
|
81
|
|
|
*/ |
|
82
|
|
|
public function readConfig() |
|
83
|
|
|
{ |
|
84
|
|
|
$path_file = $this->configPath . $this->configFile . $this->configFileExt; |
|
85
|
|
|
\XoopsLoad::load('XoopsFile'); |
|
86
|
|
|
$file = \XoopsFile::getHandler('file', $path_file); |
|
87
|
|
|
|
|
88
|
|
|
return eval(@$file->read()); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return bool |
|
93
|
|
|
*/ |
|
94
|
|
|
public function createConfig() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->writeConfig($this->getDisplayed()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param $data |
|
101
|
|
|
* @return bool |
|
102
|
|
|
*/ |
|
103
|
|
|
public function writeConfig($data) |
|
104
|
|
|
{ |
|
105
|
|
|
$path_file = $this->configPath . $this->configFile . $this->configFileExt; |
|
106
|
|
|
\XoopsLoad::load('XoopsFile'); |
|
107
|
|
|
$file = \XoopsFile::getHandler('file', $path_file); |
|
108
|
|
|
|
|
109
|
|
|
return $file->write('return ' . var_export($data, true) . ';'); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|