| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikWP - Libraries |
| 4 |
* @subpackage adapter.factory |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2023 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
/** |
| 15 |
* Abstract Factory pattern. |
| 16 |
* |
| 17 |
* @since 10.0 |
| 18 |
*/ |
| 19 |
abstract class JFactory |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Application CMS adapter instance. |
| 23 |
* |
| 24 |
* @var JApplication |
| 25 |
*/ |
| 26 |
private static $application = null; |
| 27 |
|
| 28 |
/** |
| 29 |
* Language adapter instance. |
| 30 |
* |
| 31 |
* @var JLanguage |
| 32 |
*/ |
| 33 |
private static $language = null; |
| 34 |
|
| 35 |
/** |
| 36 |
* Document adapter instance. |
| 37 |
* |
| 38 |
* @var JDocument |
| 39 |
*/ |
| 40 |
private static $document = null; |
| 41 |
|
| 42 |
/** |
| 43 |
* Access point to retrieve the current database instance. |
| 44 |
* |
| 45 |
* @return JDatabase Global database adapter. |
| 46 |
*/ |
| 47 |
public static function getDbo() |
| 48 |
{ |
| 49 |
JLoader::import('adapter.database.database'); |
| 50 |
|
| 51 |
global $wpdb; |
| 52 |
|
| 53 |
return JDatabase::getInstance($wpdb); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Get an application object. |
| 58 |
* Returns the global application object, only creating it if it doesn't already exist. |
| 59 |
* |
| 60 |
* @return JApplication The application adapter. |
| 61 |
*/ |
| 62 |
public static function getApplication() |
| 63 |
{ |
| 64 |
if (static::$application === null) |
| 65 |
{ |
| 66 |
JLoader::import('adapter.application.application'); |
| 67 |
|
| 68 |
static::$application = new JApplication(); |
| 69 |
} |
| 70 |
|
| 71 |
return static::$application; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Get a language object. |
| 76 |
* Returns the global language object, only creating it if it doesn't already exist. |
| 77 |
* |
| 78 |
* @return JLanguage The language adapter. |
| 79 |
*/ |
| 80 |
public static function getLanguage() |
| 81 |
{ |
| 82 |
if (static::$language === null) |
| 83 |
{ |
| 84 |
JLoader::import('adapter.language.language'); |
| 85 |
|
| 86 |
static::$language = JLanguage::getInstance(); |
| 87 |
} |
| 88 |
|
| 89 |
return static::$language; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Get a session object. |
| 94 |
* Returns the global session object, only creating it if it doesn't already exist. |
| 95 |
* |
| 96 |
* @param array $options An array containing session options (@unused). |
| 97 |
* |
| 98 |
* @return JSession The session adapter. |
| 99 |
*/ |
| 100 |
public static function getSession(array $options = array()) |
| 101 |
{ |
| 102 |
JLoader::import('adapter.session.session'); |
| 103 |
|
| 104 |
return JSession::getInstance(); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Get a document object. |
| 109 |
* Returns the global document object, only creating it if it doesn't already exist. |
| 110 |
* |
| 111 |
* @return JDocument The document adapter. |
| 112 |
*/ |
| 113 |
public static function getDocument() |
| 114 |
{ |
| 115 |
if (static::$document === null) |
| 116 |
{ |
| 117 |
JLoader::import('adapter.application.document'); |
| 118 |
|
| 119 |
static::$document = new JDocument(); |
| 120 |
} |
| 121 |
|
| 122 |
return static::$document; |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Get a user object. |
| 127 |
* Returns the global user object, only creating it if it doesn't already exist. |
| 128 |
* |
| 129 |
* @param integer $id The primary key value of the user to load. |
| 130 |
* |
| 131 |
* @return JUser The user adapter. |
| 132 |
*/ |
| 133 |
public static function getUser($id = null) |
| 134 |
{ |
| 135 |
JLoader::import('adapter.user.user'); |
| 136 |
|
| 137 |
return JUser::getInstance($id); |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Creates a new instance of the specified editor. |
| 142 |
* |
| 143 |
* @param string $name The editor name type. |
| 144 |
* |
| 145 |
* @return JEditor The instance of the editor. |
| 146 |
*/ |
| 147 |
public static function getEditor($name = null) |
| 148 |
{ |
| 149 |
JLoader::import('adapter.editor.editor'); |
| 150 |
|
| 151 |
if (is_null($name)) |
| 152 |
{ |
| 153 |
$name = JFactory::getApplication()->get('editor'); |
| 154 |
} |
| 155 |
|
| 156 |
return JEditor::getInstance($name); |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Return the JDate object. |
| 161 |
* |
| 162 |
* @param mixed $time The initial time for the JDate object |
| 163 |
* @param mixed $tzOffset The timezone offset. |
| 164 |
* |
| 165 |
* @return JDate The date object. |
| 166 |
*/ |
| 167 |
public static function getDate($time = 'now', $tzOffset = null) |
| 168 |
{ |
| 169 |
JLoader::import('adapter.date.date'); |
| 170 |
|
| 171 |
return JDate::getInstance($time, $tzOffset); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Get a mailer object. |
| 176 |
* |
| 177 |
* Returns the global JMail object, only creating it if it doesn't already exist. |
| 178 |
* |
| 179 |
* @return JMail The mail object. |
| 180 |
*/ |
| 181 |
public static function getMailer() |
| 182 |
{ |
| 183 |
JLoader::import('adapter.mail.mail'); |
| 184 |
|
| 185 |
/** |
| 186 |
* Always return a new instance of JMail without caching it. |
| 187 |
* This avoids having a JMail instance already filled-in when |
| 188 |
* this method is called more than once. |
| 189 |
* |
| 190 |
* @since 10.1.10 |
| 191 |
*/ |
| 192 |
return new JMail; |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Returns the configuration registry. |
| 197 |
* |
| 198 |
* @return JConfig The configuration object. |
| 199 |
* |
| 200 |
* @since 10.1.4 |
| 201 |
*/ |
| 202 |
public static function getConfig() |
| 203 |
{ |
| 204 |
JLoader::import('adapter.config.config'); |
| 205 |
|
| 206 |
return new JConfig; |
| 207 |
} |
| 208 |
} |
| 209 |
|