Instead of using $post = JRequest::get('post')
to get all $_POST, you should use $post = JFactory::getApplication()->input->getArray(array())
in Joomla 3.X.
Category / Joomla3.X
Post regarding Joomla3.X versions will be posted under this category.
Get Super users in Joomla
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
/** * Returns the Super Users email information. If you provide a comma separated $email list * we will check that these emails do belong to Super Users and that they have not blocked * system emails. * * @param null|string $email A list of Super Users to email * * @return array The list of Super User emails * * @since 3.5 */ private function getSuperUsers($email = null) { // Get a reference to the database object $db = JFactory::getDBO(); // Convert the email list to an array if (!empty($email)) { $temp = explode(',', $email); $emails = array(); foreach ($temp as $entry) { $entry = trim($entry); $emails[] = $db->q($entry); } $emails = array_unique($emails); } else { $emails = array(); } // Get a list of groups which have Super User privileges $ret = array(); try { $query = $db->getQuery(true) ->select($db->qn('rules')) ->from($db->qn('#__assets')) ->where($db->qn('parent_id') . ' = ' . $db->q(0)); $db->setQuery($query, 0, 1); $rulesJSON = $db->loadResult(); $rules = json_decode($rulesJSON, true); $rawGroups = $rules['core.admin']; $groups = array(); if (empty($rawGroups)) { return $ret; } foreach ($rawGroups as $g => $enabled) { if ($enabled) { $groups[] = $db->q($g); } } if (empty($groups)) { return $ret; } } catch (Exception $exc) { return $ret; } // Get the user IDs of users belonging to the SA groups try { $query = $db->getQuery(true) ->select($db->qn('user_id')) ->from($db->qn('#__user_usergroup_map')) ->where($db->qn('group_id') . ' IN(' . implode(',', $groups) . ')'); $db->setQuery($query); $rawUserIDs = $db->loadColumn(0); if (empty($rawUserIDs)) { return $ret; } $userIDs = array(); foreach ($rawUserIDs as $id) { $userIDs[] = $db->q($id); } } catch (Exception $exc) { return $ret; } // Get the user information for the Super Administrator users try { $query = $db->getQuery(true) ->select( array( $db->qn('id'), $db->qn('username'), $db->qn('email'), ) )->from($db->qn('#__users')) ->where($db->qn('id') . ' IN(' . implode(',', $userIDs) . ')') ->where($db->qn('sendEmail') . ' = ' . $db->q('1')); if (!empty($emails)) { $query->where($db->qn('email') . 'IN(' . implode(',', $emails) . ')'); } $db->setQuery($query); $ret = $db->loadObjectList(); } catch (Exception $exc) { return $ret; } return $ret; } |
Joomla Get the full current URI
1 2 3 4 5 6 |
// Get the full current URI. $uri = JUri::getInstance(); $current = rawurldecode($uri->toString(array('scheme', 'host', 'port', 'path', 'query', 'fragment'))); // the server-relative URL $currRel = rawurldecode($uri->toString(array('path', 'query', 'fragment'))); |
Joomla Cookie API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// Get input cookie object $inputCookie = JFactory::getApplication()->input->cookie; // Get cookie data $value = $inputCookie->get($name = 'myCookie', $defaultValue = null); // Check that cookie exists $cookieExists = ($value === null); // Set cookie data $inputCookie->set($name = 'myCookie', $value = '123', $expire = 0); // Remove cookie $inputCookie->set('myCookie', null, time() - 1); |
Some rules about $expire value
its a Unix tinestamp in seconds, like return value of time().
$expire == 0: cookie lifetime is of browser session.
$expire < time(): cookie is being deleted (expire set to past). You could remove cookie by setting it's value to null, but apparently IE fails to do so.
Notes
Keep in mind that cookies should be set before headers are sent (usually before output is echoed).
Cookie key and value should be properly escaped
Non-string values
When serializing the value on set (like json_encode($dataNode)), remember to use proper filter to retrieve it later on. Default is cmd, which filters out pretty much anything but a-Z, 0-9 and cracks JSON structure.
1 2 3 4 5 6 7 8 |
// Get cookie data $encodedString = $inputCookie->get('myCookie', null, $filter = 'string'); // Decode $values = json_decode($encodedString); // Encode and Set $inputCookie->set('myCookie', json_encode($values)); |
Rererences
Joomla CMS github repository: JInputCookie::set (very well documented)
php docs: php.net/setcookie (developer experiences)
Wikipedia: HTTP Cookies (theory)
Joomla Date/Timezone
JFactory::getDate()
will always stay in UTC. This is good for storing dates into the database and other calculations.
For displaying a date to a user, it is recommended to use JHtml::date()
. This will automatically use your timezone setting.
JHtml::date('now', 'Y-m-d H:i:s');
For more information and to see the code behind this function: http://docs.joomla.org/API16:JHtml/date
Add Additional Parameters in Pagination
We have to initialize JPagination object first
1 2 |
$pagination = new JPagination; $pagination->setAdditionalUrlParam('name','ronniee'); |
Add New Parameter in URL
1 2 3 |
$url =& JURI::getInstance(); $url->setVar( 'test', 1); print $url; |