/** * Test the JRegistryFormatJSON::objectToString method. * * @return void */ public function testObjectToString() { $class = JRegistryFormat::getInstance('JSON'); $options = null; $object = new stdClass; $object->foo = 'bar'; $object->quoted = '"stringwithquotes"'; $object->booleantrue = true; $object->booleanfalse = false; $object->numericint = 42; $object->numericfloat = 3.1415; // The PHP registry format does not support nested objects $object->section = new stdClass; $object->section->key = 'value'; $object->array = array('nestedarray' => array('test1' => 'value1')); $string = '{"foo":"bar","quoted":"\"stringwithquotes\"",' . '"booleantrue":true,"booleanfalse":false,' . '"numericint":42,"numericfloat":3.1415,' . '"section":{"key":"value"},' . '"array":{"nestedarray":{"test1":"value1"}}' . '}'; // Test basic object to string. $this->assertThat( $class->objectToString($object, $options), $this->equalTo($string) ); }
/** * Test the JRegistryFormat::getInstance method. */ public function testGetInstance() { // Test INI format. $object = JRegistryFormat::getInstance('INI'); $this->assertThat( $object instanceof JRegistryFormatIni, $this->isTrue() ); // Test JSON format. $object = JRegistryFormat::getInstance('JSON'); $this->assertThat( $object instanceof JRegistryFormatJson, $this->isTrue() ); // Test PHP format. $object = JRegistryFormat::getInstance('PHP'); $this->assertThat( $object instanceof JRegistryFormatPHP, $this->isTrue() ); // Test XML format. $object = JRegistryFormat::getInstance('XML'); $this->assertThat( $object instanceof JRegistryFormatXml, $this->isTrue() ); }
/** * Test the JRegistryFormatPHP::stringToObject method. * * @return void */ public function testStringToObject() { $class = JRegistryFormat::getInstance('PHP'); // This method is not implemented in the class. The test is to achieve 100% code coverage $this->assertTrue($class->stringToObject('')); }
/** * Test the JRegistryFormatINI::stringToObject method. * * @return void */ public function testStringToObject() { $class = JRegistryFormat::getInstance('INI'); $string2 = "[section]\nfoo=bar"; $object1 = new stdClass(); $object1->foo = 'bar'; $object2 = new stdClass(); $object2->section = $object1; // Test INI format string without sections. $object = $class->stringToObject($string2, array('processSections' => false)); $this->assertThat($object, $this->equalTo($object1)); // Test INI format string with sections. $object = $class->stringToObject($string2, array('processSections' => true)); $this->assertThat($object, $this->equalTo($object2)); // Test empty string $this->assertThat($class->stringToObject(null), $this->equalTo(new stdClass())); $string3 = "[section]\nfoo=bar\n;Testcomment\nkey=value\n\n/brokenkey=)brokenvalue"; $object2->section->key = 'value'; $this->assertThat($class->stringToObject($string3, array('processSections' => true)), $this->equalTo($object2)); $string4 = "boolfalse=false\nbooltrue=true\nkeywithoutvalue\nnumericfloat=3.1415\nnumericint=42\nkey=\"value\""; $object3 = new stdClass(); $object3->boolfalse = false; $object3->booltrue = true; $object3->numericfloat = 3.1415; $object3->numericint = 42; $object3->key = 'value'; $this->assertThat($class->stringToObject($string4), $this->equalTo($object3)); // Trigger the cache - Doing this only to achieve 100% code coverage. ;-) $this->assertThat($class->stringToObject($string4), $this->equalTo($object3)); }
/** * Logic for the event edit screen * * @access public * @return array * @since 0.9 */ function &getData() { if (empty($this->_data)) { $res = new stdclass(); // original file $source = $this->getSource(); $helper =& JRegistryFormat::getInstance('INI'); $object = $helper->stringToObject(file_get_contents($source)); $res->from = get_object_vars($object); // target file $path = $this->getTarget(); MissingtAdminHelper::checkHistory($path); if (file_exists($path)) { $object = $helper->stringToObject(file_get_contents($path)); $strings = get_object_vars($object); $present = array(); foreach ($res->from as $k => $v) { if (isset($strings[$k]) && !empty($strings[$k])) { $present[$k] = $strings[$k]; } } $res->to = $present; } else { $res->to = array(); } $this->_data = $res; } return $this->_data; }
/** * Test the JRegistryFormatXML::stringToObject method. * * @return void */ public function testStringToObject() { $class = JRegistryFormat::getInstance('XML'); $object = new stdClass; $object->foo = 'bar'; $object->booleantrue = true; $object->booleanfalse = false; $object->numericint = 42; $object->numericfloat = 3.1415; $object->section = new stdClass; $object->section->key = 'value'; $object->array = array('test1' => 'value1'); $string = "<?xml version=\"1.0\"?>\n<registry>" . "<node name=\"foo\" type=\"string\">bar</node>" . "<node name=\"booleantrue\" type=\"boolean\">1</node>" . "<node name=\"booleanfalse\" type=\"boolean\"></node>" . "<node name=\"numericint\" type=\"integer\">42</node>" . "<node name=\"numericfloat\" type=\"double\">3.1415</node>" . "<node name=\"section\" type=\"object\">" . "<node name=\"key\" type=\"string\">value</node>" . "</node>" . "<node name=\"array\" type=\"array\">" . "<node name=\"test1\" type=\"string\">value1</node>" . "</node>" . "</registry>\n"; // Test basic object to string. $this->assertThat( $class->stringToObject($string), $this->equalTo($object) ); }
function stringToObject($data) { $data = JString::trim($data); if (JString::substr($data, 0, 1) != '{' && JString::substr($data, -1, 1) != '}') { $object = JRegistryFormat::getInstance('INI')->stringToObject($data); } else { $object = json_decode($data); } return $object; }
/** * Constructor. * * @param mixed $dispatcher A dispatcher * @param array $config An optional KConfig object with configuration options. * * @return void */ public function __construct($dispatcher = null, $config = array()) { if (isset($config['params'])) { $config = (array) JRegistryFormat::getInstance('ini')->stringToObject($config['params']); } $config = new KConfig($config); parent::__construct($config); $this->_params = $config; KService::set('plg:storage.default', $this); }
/** * Class Constructor * * @param array|object $data The data to be converted to JRegistry format * * @since 1.0.0 */ public function __construct($data = array()) { if ($data instanceof JRegistry) { $data = $data->toArray(); } else { if (is_string($data) && substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') { $data = JRegistryFormat::getInstance('INI')->stringToObject($data); } } parent::__construct($data); }
/** * Parse a JSON formatted string and convert it into an object. * * If the string is not in JSON format, this method will attempt to parse it as INI format. * * @param string $data JSON formatted string to convert. * @param array $options Options used by the formatter. * * @return object Data object. * * @since 11.1 */ public function stringToObject($data, array $options = array('processSections' => false)) { $data = trim($data); if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') { $ini = JRegistryFormat::getInstance('INI'); $obj = $ini->stringToObject($data, $options); } else { $obj = json_decode($data); } return $obj; }
function _convertToIni($array) { $handlerIni =& JRegistryFormat::getInstance('INI'); $object = new StdClass(); foreach ($array as $k => $v) { if (strpos($k, 'KEY_') === 0) { $key = substr($k, 4); $object->{$key} = $v; } } $string = $handlerIni->objectToString($object, null); return $string; }
/** * Sanitize a value * * @param scalar Value to be sanitized * @return string */ protected function _sanitize($value) { $result = null; $handler = JRegistryFormat::getInstance('INI'); if ($value instanceof KConfig) { $value = $value->toArray(); } if (is_string($value)) { $result = $handler->stringToObject($value); } if (is_null($result)) { $result = $handler->objectToString((object) $value, null); } return $result; }
/** * Parse a JSON formatted string and convert it into an object. * * If the string is not in JSON format, this method will attempt to parse it as INI format. * * @param string $data JSON formatted string to convert. * @param array $options Options used by the formatter. * * @return object Data object. * * @since 11.1 */ public function stringToObject($data, $options = array('processSections' => false)) { // Fix legacy API. if (is_bool($options)) { $options = array('processSections' => $options); // Deprecation warning. JLog::add('JRegistryFormatJSON::stringToObject() second argument should not be a boolean.', JLog::WARNING, 'deprecated'); } $data = trim($data); if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') { $ini = JRegistryFormat::getInstance('INI'); $obj = $ini->stringToObject($data, $options); } else { $obj = json_decode($data); } return $obj; }
/** * Test the JRegistryFormat::getInstance method. * * @return void */ public function testGetInstance() { // Test INI format. $object = JRegistryFormat::getInstance('INI'); $this->assertThat( $object instanceof JRegistryFormatIni, $this->isTrue() ); // Test JSON format. $object = JRegistryFormat::getInstance('JSON'); $this->assertThat( $object instanceof JRegistryFormatJson, $this->isTrue() ); // Test PHP format. $object = JRegistryFormat::getInstance('PHP'); $this->assertThat( $object instanceof JRegistryFormatPHP, $this->isTrue() ); // Test XML format. $object = JRegistryFormat::getInstance('XML'); $this->assertThat( $object instanceof JRegistryFormatXml, $this->isTrue() ); // Test non-existing format. try { $object = JRegistryFormat::getInstance('SQL'); } catch (Exception $e) { return; } $this->fail('JRegistryFormat should throw an exception in case of non-existing formats'); }
public static function fwdtofriend($action, $task) { jimport('joomla.html.parameter'); $mainframe = JFactory::getApplication(); JPluginHelper::importPlugin('jnews'); $plugin = JPluginHelper::getPlugin('jnews', 'forwardtofriend'); $registry = new JRegistry(); if (!method_exists($registry, 'loadString')) { $data = trim($plugin->params); $options = array('processSections' => false); if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') { $ini = JRegistryFormat::getInstance('INI'); $obj = $ini->stringToObject($data, $options); } else { $obj = json_decode($data); } $registry->loadObject($obj); } else { $registry->loadString($plugin->params); } $params = $registry; if ($task == 'sendtofriend') { $new = false; $mailingID = JRequest::getInt('mailingid'); $html = JRequest::getInt('html'); $html1 = $html ? 'true' : 'false'; $mailing = new stdClass(); $mailing = jNews_Mailing::getOneMailing('', $mailingID, '', $new, $html1); //&$new $mailing->fromname = JRequest::getVar('fromName'); $mailing->fromemail = JRequest::getVar('fromEmail'); $mailing->frombounce = JRequest::getVar('fromEmail'); $mailing->id = $mailingID; $mailing->issue_nb = 0; $mailing->images = ''; $mailing->attachments = ''; $receiversNames = JRequest::getVar('toName', array(), '', 'array'); $receiversEmails = JRequest::getVar('toEmail', array(), '', 'array'); $message = new stdClass(); $message->dflt = JRequest::getVar('message'); $message->inEmail = JRequest::getVar('inEmailMessage'); //need to get it from the URL/request $list = new stdClass(); $list->id = JRequest::getInt('listid'); $list->html = $html; $botResult = $mainframe->triggerEvent('jnewsbot_sendtofriend', array($mailing, $message, $receiversNames, $receiversEmails, $list)); if (empty($plugin)) { echo '<center><span style="font-size: 1.3em;">The <strong>jNews: Forward to friend</strong> plugin is either not installed or published. Click <a target="_blank" href="administrator/index.php?option=com_plugins&client=site&filter_type=jnews">here</a> to check if it\'s installed or published.</span></center>'; } } else { $botResult = $mainframe->triggerEvent('jnewsbot_fwdtofriend', array($params)); if (empty($plugin)) { echo '<center><span style="font-size: 1.3em;">The <strong>jNews: Forward to friend</strong> plugin is either not installed or published. Click <a target="_blank" href="administrator/index.php?option=com_plugins&client=site&filter_type=jnews">here</a> to check if it\'s installed or published.</span></center>'; } } }
protected static function processLanguageINI($files, $sections = array(), $filter = '') { $data = array(); foreach ((array) $files as $file) { $ini = false; $content = file_get_contents($file); if ($content) { if (function_exists('parse_ini_string')) { $ini = @parse_ini_string($content, true); } else { $registry = JRegistryFormat::getInstance('INI'); $obj = $registry->stringToObject($content, true); $ini = self::object_to_array($obj); } } if ($ini && is_array($ini)) { // only include these keys if (!empty($sections)) { $ini = array_intersect_key($ini, array_flip($sections)); } // filter keys by regular expression if ($filter) { foreach (array_keys($ini) as $key) { if (preg_match('#' . $filter . '#', $key)) { unset($ini[$key]); } } } $data = array_merge($data, $ini); } } $output = ''; if (!empty($data)) { $x = 0; foreach ($data as $key => $strings) { if (is_array($strings)) { $output .= '"' . strtolower($key) . '":{'; $i = 0; foreach ($strings as $k => $v) { if (is_numeric($v)) { $v = (double) $v; } else { $v = '"' . $v . '"'; } // key to lowercase $k = strtolower($k); // get position of the section name in the key if any $pos = strpos($k, $key . '_'); // remove the section name if ($pos === 0) { $k = substr($k, strlen($key) + 1); } // hex colours to uppercase and remove marker if (strpos($k, 'hex_') !== false) { $k = strtoupper(str_replace('hex_', '', $k)); } // create key/value pair as JSON string $output .= '"' . $k . '":' . $v . ','; $i++; } // remove last comma $output = rtrim(trim($output), ','); $output .= "},"; $x++; } } // remove last comma $output = rtrim(trim($output), ','); } return $output; }
/** * Get a namespace in a given string format * * @param string Format to return the string in * @param mixed Parameters used by the formatter, see formatters for more info * @return string Namespace in string format * @since 1.5 */ public function toString($format = 'JSON', $options = array()) { // Return a namespace in a given format $handler = JRegistryFormat::getInstance($format); return $handler->objectToString($this->data, $options); }
/** * Get a namespace in a given string format * * @access public * @param string $format Format to return the string in * @param string $namespace Namespace to return [optional: null returns the default namespace] * @param mixed $params Parameters used by the formatter, see formatters for more info * @return string Namespace in string format * @since 1.5 */ function toString($format = 'INI', $namespace = null, $params = null) { // Return a namespace in a given format $handler =& JRegistryFormat::getInstance($format); // If namespace is not set, get the default namespace if ($namespace == null) { $namespace = $this->_defaultNameSpace; } // Get the namespace $ns =& $this->_registry[$namespace]['data']; return $handler->objectToString($ns, $params); }
function onAfterStoreUser($user, $isnew, $success, $msg) { if ($success === false) { return false; } if (strtolower(substr(JPATH_ROOT, strlen(JPATH_ROOT) - 13)) == 'administrator') { $adminPath = strtolower(substr(JPATH_ROOT, strlen(JPATH_ROOT) - 13)); } else { $adminPath = JPATH_ROOT; } if (!@(include_once $adminPath . DS . 'components' . DS . 'com_jnews' . DS . 'defines.php')) { return; } include_once JNEWSPATH_CLASS . 'class.jnews.php'; require_once JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'classes' . DS . 'class.subscribers.php'; require_once JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'classes' . DS . 'class.listssubscribers.php'; jimport('joomla.html.parameter'); $plugin = JPluginHelper::getPlugin('user', 'jnewssyncuser'); $registry = new JRegistry(); if (!method_exists($registry, 'loadString')) { $data = trim($plugin->params); $options = array('processSections' => false); if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') { $ini = JRegistryFormat::getInstance('INI'); $obj = $ini->stringToObject($data, $options); } else { $obj = json_decode($data); } $registry->loadObject($obj); } else { $registry->loadString($plugin->params); } $params = $registry; $db = JFactory::getDBO(); $subscriber = new stdClass(); $confirmed = 1; if ($user['block']) { $confirmed = 0; } $subscriber->email = trim(strip_tags($user['email'])); if (!empty($user['name'])) { $subscriber->name = trim(strip_tags($user['name'])); } if (empty($user['block'])) { $subscriber->confirmed = 1; } $subscriber->user_id = $user['id']; $subscriber->ip = jNews_Subscribers::getIP(); $subscriber->receive_html = 1; $subscriber->confirmed = $confirmed; $subscriber->subscribe_date = time(); $subscriber->language_iso = 'eng'; $subscriber->timezone = '00:00:00'; $subscriber->blacklist = 0; //check if the version of jnews is pro if ($GLOBALS[JNEWS . 'level'] > 2) { $subscriber->column1 = ''; $subscriber->column2 = ''; $subscriber->column3 = ''; $subscriber->column4 = ''; $subscriber->column5 = ''; } //end if check if the version is pro if (!$isnew and !empty($this->oldUser['email']) and $user['email'] != $this->oldUser['email']) { $d['email'] = $this->oldUser['email']; $infos = jNews_Subscribers::getSubscriberIdFromEmail($this->oldUser); $subscriber->id = $infos['subscriberId']; } if ($isnew) { //new registered user $status = jNews_Subscribers::saveSubscriber($subscriber, $subscriber->user_id, true); if (empty($subscriber->id)) { $subscriber->id = jNews_Subscribers::getSubscriberIdFromUserId($subscriber->user_id); } if (!$status) { return; } $listsToSubscribe = $params->get('lists', ''); if (!empty($listsToSubscribe)) { $condition = ' WHERE `id` IN (' . $listsToSubscribe . ')'; } else { $condition = ' WHERE `auto_add` > 0'; } //get list ids of auto_add lists $query = 'SELECT `id`, `list_type`, `params` from `#__jnews_lists`' . $condition; $db->setQuery($query); $autoListId = $db->loadObjectList(); $error = $db->getErrorMsg(); if (!empty($error)) { echo $error; return false; } else { //use for masterlists $listsA = array(); foreach ($autoListId as $autoId) { if (!empty($autoId->params)) { //use for masterlists $listsA[] = $autoId->id; } else { //for non-masterlists $subscriber->list_id = $autoId->id; jNews_ListsSubs::saveToListSubscribers($subscriber); } if ($autoId->list_type == 2) { $subscribe = array(); $subscribe[] = $autoId->id; if (!empty($subscribe)) { jNews_ListsSubs::subscribeARtoQueue($subscriber->id, $subscribe); } } } //end of foreach } if (!empty($listsA)) { //we check if the social class file exists for the implementation of master lists if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) { if (class_exists('social')) { $listidSubsA = array(); $masterListSubscriber = new stdClass(); //we check if configuration for master lists is enabled if ($GLOBALS[JNEWS . 'use_masterlists']) { if ($GLOBALS[JNEWS . 'level'] > 1) { //we validate if the user can be subscribed to the list then we return the masterlistid //1 - MasterLists for all Potential Users $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 1, $listsA); //2 - MasterLists for all Registered Subscribers $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 2, $listsA); } if ($GLOBALS[JNEWS . 'level'] > 2) { //we validate if the user can be subscribed to the list then we return the masterlistid //3 - MasterLists for all Front-end Subscribers $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 3, $listsA); } } $masterListSubscriber->id = $subscriber->id; $masterListSubscriber->list_id = $listidSubsA; jNews_ListsSubs::saveToListSubscribers($masterListSubscriber); } } } } else { //confirmed registered user // if(!empty($this->oldUser['block']) AND !empty($subscriber->confirmed)){ if (empty($subscriber->id)) { $subscriber->id = jNews_Subscribers::getSubscriberIdFromUserId($subscriber->user_id); } plgUserjNewssyncuser::_confirmUserSubscription($subscriber->id); if ($isnew === false and $success === true) { $status = jNews_Subscribers::saveSubscriber($subscriber, $subscriber->user_id); } // } } //endelse return true; }
function onAfterRoute() { $redirectlink = trim(JRequest::getString('redirectlink')); $fromSubscribe = JRequest::getVar('fromSubscribe', ''); // this is either we have a redirect setup or we come from the module if (empty($fromSubscribe) || empty($redirectlink)) { return ''; } if (strtolower(substr(JPATH_ROOT, strlen(JPATH_ROOT) - 13)) == 'administrator') { $adminPath = strtolower(substr(JPATH_ROOT, strlen(JPATH_ROOT) - 13)); } else { $adminPath = JPATH_ROOT; } if (!@(include_once $adminPath . DS . 'components' . DS . 'com_jnews' . DS . 'defines.php')) { return; } include_once JNEWSPATH_CLASS . 'class.jnews.php'; require_once JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'classes' . DS . 'class.subscribers.php'; require_once JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'administrator' . DS . 'components' . DS . JNEWS_OPTION . DS . 'classes' . DS . 'class.listssubscribers.php'; jimport('joomla.html.parameter'); $db = JFactory::getDBO(); $plugin = JPluginHelper::getPlugin('system', 'vmjnewssubs'); $registry = new JRegistry(); if (!method_exists($registry, 'loadString')) { $data = trim($plugin->params); $options = array('processSections' => false); if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') { $ini = JRegistryFormat::getInstance('INI'); $obj = $ini->stringToObject($data, $options); } else { $obj = json_decode($data); } $registry->loadObject($obj); } else { $registry->loadString($plugin->params); } $params = $registry; $reqfield = $params->get('reqfield', 'user_email'); $email = JRequest::getString('email'); $reqvalue = $reqfield == 'user_email' ? $email : JRequest::get($reqfield); if (is_array($reqvalue)) { //if we find any no we do no if (empty($reqvalue)) { return ''; } foreach ($reqvalue as $resultArVal) { if (empty($resultArVal)) { return ''; } } } else { if (empty($reqvalue) || empty($email) || in_array(strtolower($reqvalue), array('', '0', 'n', 'no', 'none', 'nein', 'non'))) { return; } } $user_id = JRequest::getInt('user_id'); $email = trim(strip_tags($email)); $fname = JRequest::getString('first_name', ''); $mname = JRequest::getString('middle_name', ''); $lname = JRequest::getString('last_name', ''); $name = ''; if (!empty($fname)) { $name .= $fname . ' '; } if (!empty($mname)) { $name .= $mname . ' '; } if (!empty($lname)) { $name .= $lname; } $name = trim($name); if (empty($name)) { $name = JRequest::getVar('username'); } $subscriber = new stdClass(); $subscriber->user_id = $user_id; $subscriber->name = $name; $subscriber->email = $email; $subscriber->ip = jNews_Subscribers::getIP(); $subscriber->receive_html = 1; $subscriber->confirmed = $GLOBALS[JNEWS . 'require_confirmation'] == '1' ? 0 : 1; $subscriber->subscribe_date = time(); $subscriber->language_iso = 'eng'; $subscriber->timezone = '00:00:00'; $subscriber->blacklist = 0; $subscriber->params = ''; $subscriber->admin_id = 62; $status = jNews_Subscribers::saveSubscriber($subscriber, $user_id, true); if (!$status) { return; } $listsToSubscribe = $params->get('lists', ''); $listsToSubscribe = str_replace(' ', '', $listsToSubscribe); if (!empty($listsToSubscribe)) { $condition = ' WHERE `id` IN (' . $listsToSubscribe . ')'; } else { $condition = ''; } $query = 'SELECT `id`, `list_type`,`params` from `#__jnews_lists`' . $condition; $db->setQuery($query); $lsidstoinsert = $db->loadObjectList(); $error = $db->getErrorMsg(); if (!empty($error)) { echo $error; return false; } else { //use for masterlists $listsA = array(); foreach ($lsidstoinsert as $lsid) { $d['email'] = $subscriber->email; //get the subscriber id which is newly inserted jNews_Subscribers::getSubscriberIdFromEmail($d); //subscriber_id from the inserted subscriber if ($d['subscriberId'] > 0) { $subscriber->id = $d['subscriberId']; } else { $subscriber->id = $subscriber->user_id; } if (!empty($lsid->params)) { //use for masterlists $listsA[] = $lsid->id; } else { //for non-masterlists $subscriber->list_id = $lsid->id; jNews_ListsSubs::saveToListSubscribers($subscriber); } if ($lsid->list_type == 2) { $subscribe = array(); $subscribe[] = $lsid->id; if (!empty($subscribe)) { jNews_ListsSubs::subscribeARtoQueue($subscriber->id, $subscribe); } } } //end of foreach if (!empty($listsA)) { //we check if the social class file exists for the implementation of master lists if (@(include_once JNEWSPATH_ADMIN . 'social' . DS . 'class.social.php')) { if (class_exists('jNews_Social')) { $listidSubsA = array(); $masterListSubscriber = new stdClass(); //we check if configuration for master lists is enabled if ($GLOBALS[JNEWS . 'use_masterlists']) { if ($GLOBALS[JNEWS . 'level'] > 1) { //we validate if the user can be subscribed to the list then we return the masterlistid //1 - MasterLists for all Potential Users $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 1, $listsA); //2 - MasterLists for all Registered Subscribers $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 2, $listsA); } if ($GLOBALS[JNEWS . 'level'] > 2) { //we validate if the user can be subscribed to the list then we return the masterlistid //3 - MasterLists for all Front-end Subscribers $listidSubsA[] = jNews_Social::includeMasterListIds($subscriber->id, 3, $listsA); } } //we check first if $listidSubsA and if not empty we do the subscription to the lists if (!empty($listidSubsA)) { $masterListSubscriber->id = $subscriber->id; $masterListSubscriber->list_id = $listidSubsA; jNews_ListsSubs::saveToListSubscribers($masterListSubscriber); } } } } } }
/** * Load a string into the registry * * @param string string to load into the registry * @param string format of the string * @param mixed Options used by the formatter * @return boolean True on success * @since 1.5 */ public function loadString($data, $format = 'JSON', $options = array()) { // Load a string into the given namespace [or default namespace if not given] $handler = JRegistryFormat::getInstance($format); $obj = $handler->stringToObject($data, $options); $this->loadObject($obj); return true; }
/** * public static function to create the view for the Virtuemart Products */ public static function virtuemartproduct($forms = '') { $mainframe = JFactory::getApplication(); JPluginHelper::importPlugin('jnews'); $plugin = JPluginHelper::getPlugin('jnews', 'virtuemartproduct'); if (!empty($plugin)) { $registry = new JRegistry(); if (!method_exists($registry, 'loadString')) { $data = trim($plugin->params); $options = array('processSections' => false); if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') { $ini = JRegistryFormat::getInstance('INI'); $obj = $ini->stringToObject($data, $options); } else { $obj = json_decode($data); } $registry->loadObject($obj); } else { $registry->loadString($plugin->params); } $params = $registry; $botResult = $mainframe->triggerEvent('jnewsbot_virtuemartproduct', array($forms, $params)); } if (empty($plugin)) { echo '<center><span style="font-size: 1.3em;">The <strong>Virtuemart Product</strong> plugin is either not installed or published. Click <a target="_blank" href="administrator/index.php?option=com_plugins&client=site&filter_type=jnews">here</a> to check if it\'s installed or published.</span></center>'; } }
private function fixAssignmentsCorrectOldKeys() { // correct old keys and values $query = $this->db->getQuery(true)->select('a.moduleid,a. params')->from('#__advancedmodules as a'); $this->db->setQuery($query); $rows = $this->db->loadObjectList(); foreach ($rows as $row) { if (empty($row->params)) { continue; } if ($row->params['0'] != '{') { $row->params = str_replace('assignto_secscats', 'assignto_cats', $row->params); $row->params = str_replace('flexicontent', 'fc', $row->params); $params = JRegistryFormat::getInstance('INI')->stringToObject($row->params); } else { $params = json_decode($row->params); if (is_null($params)) { $params = new stdClass(); } } // move tooltip to notes field if (!empty($params->tooltip)) { $query->clear()->update('#__modules as m')->set('m.note = ' . $this->db->quote($params->tooltip))->where('m.id = ' . (int) $row->moduleid); $this->db->setQuery($query); $this->db->execute(); unset($params->tooltip); } // concatenate sef and non-sef url fields if (isset($params->assignto_urls_selection_sef)) { $params->assignto_urls_selection = trim($params->assignto_urls_selection . "\n" . $params->assignto_urls_selection_sef); unset($params->assignto_urls_selection_sef); unset($params->show_url_field); } // set urls_regex value if assignto_urls is used if (!empty($params->assignto_urls) && !isset($params->assignto_urls_regex)) { $params->assignto_urls_regex = 1; } foreach ($params as $k => &$v) { switch ($k) { case 'assignto_php_selection': case 'assignto_urls_selection': case 'assignto_ips_selection': $v = str_replace(array('\\n', '\\|'), array("\n", '|'), $v); break; case 'color': $v = str_replace('#', '', $v); $v = empty($v) || $v == 'none' ? 'none' : $v; if ($v && $v != 'none') { $v = '#' . strtolower($v); } break; case 'assignto_users_selection': if (!is_array($v)) { $v = explode('|', $v); } break; default: if ((substr($k, -10) == '_selection' || substr($k, -4) == '_inc') && !is_array($v)) { // convert | separated strings to arrays $v = explode('|', $v); } break; } } if (!empty($params->assignto_cats_selection)) { foreach ($params->assignto_cats_selection as $key => $val) { if (strpos($val, ':') !== false) { $params->assignto_cats_selection[$key] = substr($val, strpos($val, ':') + 1); } } } $params = json_encode($params); if ($params == $row->params) { continue; } $query->clear()->update('#__advancedmodules as a')->set('a.params = ' . $this->db->quote($params))->where('a.moduleid = ' . (int) $row->moduleid); $this->db->setQuery($query); $this->db->execute(); } }
function processModule($id, $chrome = 'none', $ignores = array(), $overrides = array(), $area = 'articles') { $ignore_access = isset($ignores['ignore_access']) ? $ignores['ignore_access'] : $this->params->ignore_access; $ignore_state = isset($ignores['ignore_state']) ? $ignores['ignore_state'] : $this->params->ignore_state; $ignore_assignments = isset($ignores['ignore_assignments']) ? $ignores['ignore_assignments'] : $this->params->ignore_assignments; $ignore_caching = isset($ignores['ignore_caching']) ? $ignores['ignore_caching'] : $this->params->ignore_caching; $db = JFactory::getDBO(); $query = $db->getQuery(true)->select('m.*')->from('#__modules AS m')->where('m.client_id = 0'); if (is_numeric($id)) { $query->where('m.id = ' . (int) $id); } else { $query->where('m.title = ' . $db->quote(nnText::html_entity_decoder($id))); } if (!$ignore_access) { $query->where('m.access IN (' . implode(',', $this->aid) . ')'); } if (!$ignore_state) { $query->where('m.published = 1')->join('LEFT', '#__extensions AS e ON e.element = m.module AND e.client_id = m.client_id')->where('e.enabled = 1'); } if (!$ignore_assignments) { $date = JFactory::getDate(); $now = $date->toSql(); $nullDate = $db->getNullDate(); $query->where('(m.publish_up = ' . $db->quote($nullDate) . ' OR m.publish_up <= ' . $db->quote($now) . ')')->where('(m.publish_down = ' . $db->quote($nullDate) . ' OR m.publish_down >= ' . $db->quote($now) . ')'); } $query->order('m.ordering'); $db->setQuery($query); $module = $db->loadObject(); if ($module && !$ignore_assignments) { $this->applyAssignments($module); } if (empty($module)) { if ($this->params->place_comments) { return $this->params->message_start . JText::_('MA_OUTPUT_REMOVED_NOT_PUBLISHED') . $this->params->message_end; } return ''; } //determine if this is a custom module $module->user = substr($module->module, 0, 4) == 'mod_' ? 0 : 1; // set style $module->style = $chrome; if ($area == 'articles' && !$ignore_caching || !empty($overrides)) { $json = $module->params && substr(trim($module->params), 0, 1) == '{'; if ($json) { $params = json_decode($module->params); } else { // Old ini style. Needed for crappy old style modules like swMenuPro $params = JRegistryFormat::getInstance('INI')->stringToObject($module->params); } // override module parameters if (!empty($overrides)) { foreach ($overrides as $key => $val) { if (isset($module->{$key})) { $module->{$key} = $val; } else { if ($val && $val['0'] == '[' && $val[strlen($val) - 1] == ']') { $val = json_decode('{"val":' . $val . '}'); $val = $val->val; } else { if (isset($params->{$key}) && is_array($params->{$key})) { $val = explode(',', $val); } } $params->{$key} = $val; } } if ($json) { $module->params = json_encode($params); } else { $registry = new JRegistry(); $registry->loadObject($params); $module->params = $registry->toString('ini'); } } } if (isset($module->access) && !in_array($module->access, $this->aid)) { if ($this->params->place_comments) { return $this->params->message_start . JText::_('MA_OUTPUT_REMOVED_ACCESS') . $this->params->message_end; } return ''; } $document = clone JFactory::getDocument(); $document->_type = 'html'; $renderer = $document->loadRenderer('module'); $html = $renderer->render($module, array('style' => $chrome, 'name' => '')); // don't return html on article level when caching is set if ($area == 'articles' && !$ignore_caching && (isset($params->cache) && !$params->cache || isset($params->owncache) && !$params->owncache)) { return 'MA_IGNORE'; } return $html; }
$showPanel = false; echo '<!-- Beginning : ' . jnews::version() . ' -->' . "\n\r"; //added this line so that if the action show is used the subscribe action will be executed if ($userId <= 0) { if ($action == 'show') { $action = 'subscribe'; } } jimport('joomla.application.module.helper'); $module = JModuleHelper::getModule('jnews'); $moduleParams = new JRegistry(); if (!method_exists($moduleParams, 'loadString')) { $data = trim($module->params); $options = array('processSections' => false); if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') { $ini = JRegistryFormat::getInstance('INI'); $obj = $ini->stringToObject($data, $options); } else { $obj = json_decode($data); } $moduleParams->loadObject($obj); } else { if (empty($module->params)) { if (!is_object($module)) { $module = new stdClass(); } $module->params = '{"enable_captcha":"0","captcha_width":"110","captcha_height":"40"}'; } if (!empty($module->params)) { $moduleParams->loadString($module->params); }
/** * Restores the parameters saved of a given extension in the database * * @access public * @param Array $manifestInformation the infomration identidying the extension * @param String $savedParameters the previously saved parameters */ function restoreParameters($manifestInformation, $savedParameters) { // Load the new settings switch ($manifestInformation["type"]) { case "component": if (version_compare(JVERSION, '1.6.0', 'ge')) { // Joomla! 1.6+ code here $qry_load = "SELECT * FROM #__extensions WHERE `type` = 'component' AND `element` = '" . $manifestInformation["element"] . "'"; } else { // Joomla! 1.5 code here $qry_load = "SELECT * FROM `#__components`" . " WHERE `name` = '" . $this->_db->escape($manifestInformation["element"]) . "'"; } break; case "module": if (version_compare(JVERSION, '1.6.0', 'ge')) { // Joomla! 1.6+ code here $qry_load = "SELECT * FROM #__extensions WHERE `type` = 'module' AND `element` = '" . $manifestInformation["element"] . "'"; } else { // Joomla! 1.5 code here $qry_load = "SELECT * FROM `#__modules`" . " WHERE `module` = '" . $this->_db->escape($manifestInformation["element"]) . "'"; } break; case "plugin": if (version_compare(JVERSION, '1.6.0', 'ge')) { // Joomla! 1.6+ code here $qry_load = "SELECT * FROM #__extensions WHERE `type` = 'plugin' AND `folder` = '" . $manifestInformation["group"] . "' AND `element` = '" . $manifestInformation["element"] . "'"; } else { // Joomla! 1.5 code here $qry_load = "SELECT * FROM `#__plugins`" . " WHERE `folder` = '" . $this->_db->escape($manifestInformation["group"]) . "' && " . "`element` = '" . $this->_db->escape($manifestInformation["element"]) . "'"; } break; default: return; } // Load new parameters from the DB $this->_db->setQuery($qry_load); $obj = $this->_db->loadObject(); // enabled: keep the old parameter // access: keep the old parameter // published: keep the old parameter // params: merge (older is more important than defaut new) // Converting to Object Format $jregistryformat = JRegistryFormat::getInstance('ini'); $new_params = $jregistryformat->stringToObject($obj->params); $old_params = $jregistryformat->stringToObject($savedParameters->params); $old_params = (object) array_merge((array) $new_params, (array) $old_params); // Converting back to INI format $savedParameters->params = $jregistryformat->object__toString($old_params, ''); // Save the merged new / old settings switch ($manifestInformation["type"]) { case "component": if (version_compare(JVERSION, '1.6.0', 'ge')) { // Joomla! 1.6+ code here $qry_save = "UPDATE `#__extensions` SET " . "`enabled` = " . intval($savedParameters->enabled) . ", " . "`params` = '" . $this->_db->escape($savedParameters->params) . "'" . " WHERE `element` = '" . $manifestInformation["element"] . "'" . " AND `type` = 'component'"; } else { // Joomla! 1.5 code here $qry_save = "UPDATE `#__components` SET " . "`enabled`=" . intval($savedParameters->enabled) . ", " . "`params` = '" . $this->_db->escape($savedParameters->params) . "'" . " WHERE `option` = '" . $manifestInformation["element"] . "'"; } break; case "module": if (version_compare(JVERSION, '1.6.0', 'ge')) { // Joomla! 1.6+ code here $qry_save = "UPDATE `#__extensions` SET " . "`access` = " . intval($savedParameters->access) . ", " . "`enabled` = " . intval($savedParameters->enabled) . ", " . "`params` = '" . $this->_db->escape($savedParameters->params) . "'" . " WHERE `element` = '" . $manifestInformation["element"] . "'" . " AND `type` = 'module'"; } else { // Joomla! 1.5 code here $qry_save = "UPDATE `#__modules` SET " . "`access` = " . intval($savedParameters->access) . ", " . "`published` = " . intval($savedParameters->published) . ", " . "`params` = '" . $this->_db->escape($savedParameters->params) . "'" . " WHERE `module` = '" . $this->_db->escape($manifestInformation["element"]) . "'"; } break; case "plugin": if (version_compare(JVERSION, '1.6.0', 'ge')) { // Joomla! 1.6+ code here $qry_save = "UPDATE `#__extensions` SET " . "`access` = " . intval($savedParameters->access) . ", " . "`enabled` = " . intval($savedParameters->enabled) . ", " . "`params` = '" . $this->_db->escape($savedParameters->params) . "'" . " WHERE `element` = '" . $manifestInformation["element"] . "'" . " AND `folder` = '" . $this->_db->escape($manifestInformation["group"]) . "'" . " AND `type` = 'plugin'"; } else { // Joomla! 1.5 code here $qry_save = "UPDATE `#__plugins` SET " . "`access` = " . intval($savedParameters->access) . ", " . "`published` = " . intval($savedParameters->published) . ", " . "`params` = '" . $this->_db->escape($savedParameters->params) . "'" . " WHERE `folder` = '" . $this->_db->escape($manifestInformation["group"]) . "' && " . "`element` = '" . $this->_db->escape($manifestInformation["element"]) . "'"; } break; default: return; } $this->_db->setQuery($qry_save); $this->_db->query(); }
function jnewsbot_content_getitems($contentsearch = '', $setLimit = null, $setSort = null) { if ($setLimit->end < 5) { $setLimit->end = 5; } jimport('joomla.html.parameter'); $db = JFactory::getDBO(); //get the parameters from the plugin $plugin = JPluginHelper::getPlugin('jnews', 'jnewsbot'); $registry = new JRegistry(); if (!method_exists($registry, 'loadString')) { $data = trim($plugin->params); $options = array('processSections' => false); if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') { $ini = JRegistryFormat::getInstance('INI'); $obj = $ini->stringToObject($data, $options); } else { $obj = json_decode($data); } $registry->loadObject($obj); } else { $registry->loadString($plugin->params); } $params = $registry; //get the limit parameter $content_limit = $params->get('content_limit', '5000'); $displaycontent = $params->get('displaycontent', '1'); //sort of categories $sort = JRequest::getVar('filter_category_id', '', 'POST', 'int'); if (isset($sort) && !empty($sort)) { $sort_query = ' AND c.id = "' . $sort . ' "'; } else { $sort_query = ""; } //if($setSort->orderValue == 'c.title_2') { unset($setSort->orderValue); $setSort->orderValue = 'c.title';} if (version_compare(JVERSION, '1.6.0', '<')) { //j15 $query = "SELECT a.id as id, a.title as title, b.title as section, c.title as category FROM #__content as a LEFT JOIN #__sections as b ON a.sectionid = b.id LEFT JOIN #__categories AS c ON a.catid = c.id"; if (!empty($contentsearch)) { $query .= ' WHERE a.title LIKE \'%' . $contentsearch . '%\' AND '; } else { $query .= ' WHERE '; } // $query .= " WHERE "; if (!$displaycontent) { $query .= "a.created > '" . date('Y-m-d H:i:s', time() - 30240000) . "' AND "; } $query .= " a.state=1"; $query .= $sort_query; if (!empty($setSort)) { $val_sort = $setSort->orderValue == 'c.title_2' ? "c.title" : $setSort->orderValue; $query .= " ORDER BY {$val_sort} {$setSort->orderDir}"; } else { $query .= " ORDER BY "; switch ($params->get('content_order', '0')) { case '1': $query .= " a.sectionid, a.catid ASC "; break; case '2': $query .= " a.created DESC "; break; case '3': $query .= " a.title ASC "; break; case '0': default: $query .= " a.id DESC "; // $query .= " a.sectionid, a.catid, a.created DESC "; break; } } //$query .= " LIMIT ".$content_limit; if (!is_null($setLimit) && $setLimit->start != -1 && $setLimit->end) { $query .= ' LIMIT ' . $setLimit->start . ', ' . $setLimit->end; } } else { //j16 $query = "SELECT a.id as id, a.title as title, c.title as category FROM #__content as a LEFT JOIN #__categories AS c ON a.catid = c.id"; if (!empty($contentsearch)) { $query .= ' WHERE a.title LIKE \'%' . $contentsearch . '%\' AND '; } else { $query .= ' WHERE '; } $query .= " c.extension = 'com_content' AND "; if (!$displaycontent) { $query .= " a.created > '" . date('Y-m-d H:i:s', time() - 30240000) . "' AND "; } $query .= " a.state=1"; $query .= $sort_query; if (!empty($setSort)) { $val_sort = $setSort->orderValue == 'c.title_2' ? "c.title" : $setSort->orderValue; $query .= " ORDER BY {$val_sort} {$setSort->orderDir}"; } else { $query .= " ORDER BY "; switch ($params->get('content_order', '0')) { case '1': $query .= " a.catid ASC, c.lft ASC "; break; case '2': $query .= " a.created DESC, c.lft ASC "; break; case '3': case '0': default: $query .= " a.id DESC "; // $query .= " a.title ASC, c.lft ASC "; break; } } //$query .= " LIMIT ".$content_limit; if (!is_null($setLimit) && $setLimit->start != -1 && $setLimit->end) { $query .= ' LIMIT ' . $setLimit->start . ', ' . $setLimit->end; } } $db->setQuery($query); $contentitems = $db->loadObjectList(); return $contentitems; }
/** * get translation stats for the file * @param string full file path * @param string from language code * @param string to language code */ function _auditFile(&$file, $from, $to) { $helper =& JRegistryFormat::getInstance('INI'); $object = $helper->stringToObject(file_get_contents($file->file)); $strings = get_object_vars($object); $strings = array_filter($strings, array($this, '_filterempty')); // filter empty strings for comparison $file->total = count($strings); $target_path = str_replace($from, $to, $file->file); if (!file_exists($target_path)) { $file->translated = 0; } else { $helper =& JRegistryFormat::getInstance('INI'); $object = $helper->stringToObject(file_get_contents($target_path)); $strings_target = get_object_vars($object); $strings_target = array_filter($strings_target, array($this, '_filterempty')); // filter empty strings for comparison $file->translated = count(array_intersect_key($strings, $strings_target)); } }
private static function getModuleParams() { $module = JModuleHelper::getModule('jnews'); $moduleParams = new JRegistry(); if (!method_exists($moduleParams, 'loadString')) { $data = trim($module->params); $options = array('processSections' => false); if (substr($data, 0, 1) != '{' && substr($data, -1, 1) != '}') { $ini = JRegistryFormat::getInstance('INI'); $obj = $ini->stringToObject($data, $options); } else { $obj = json_decode($data); } $moduleParams->loadObject($obj); } else { if (empty($module->params)) { $module->params = '{"enable_captcha":"0","captcha_width":"110","captcha_height":"40"}'; } if (!empty($module->params)) { $moduleParams->loadString($module->params); } } return $moduleParams; }
function save(&$element) { if (!empty($element->params) && is_array($element->params)) { if (version_compare(JVERSION, '1.6', '<')) { $params = ''; foreach ($element->params as $k => $v) { $params .= $k . '=' . $v . "\n"; } $element->params = rtrim($params, "\n"); } else { $handler = JRegistryFormat::getInstance('JSON'); $element->params = $handler->objectToString($element->params); } } $element->id = parent::save($element); if ($element->id && !empty($element->hikashop_params)) { $configClass =& hikashop_config(); $config = new stdClass(); $params_name = 'params_' . $element->id; $config->{$params_name} = $element->hikashop_params; if ($configClass->save($config)) { $configClass->set($params_name, $element->hikashop_params); } if (!HIKASHOP_J30) { return $element->id; } $plugin = JPluginHelper::getPlugin('system', 'cache'); $params = new JRegistry(@$plugin->params); $options = array('defaultgroup' => 'page', 'browsercache' => $params->get('browsercache', false), 'caching' => false); $cache = JCache::getInstance('page', $options); $cache->clean(); } return $element->id; }