/**
  * Function to convert a static time into a relative measurement
  *
  * @param   string  $date  The date to convert
  * @param   string  $unit  The optional unit of measurement to return
  *                         if the value of the diff is greater than one
  * @param   string  $time  An optional time to compare to, defaults to now
  *
  * @return  string  The converted time string
  *
  * @since   11.3
  */
 public static function relative($date, $unit = null, $time = null)
 {
     if (is_null($time)) {
         // Get now
         $time = Factory::getDate('now');
     }
     // Get the difference in seconds between now and the time
     $diff = strtotime($time) - strtotime($date);
     // Less than a minute
     if ($diff < 60) {
         return Text::_('JLIB_HTML_DATE_RELATIVE_LESSTHANAMINUTE');
     }
     // Round to minutes
     $diff = round($diff / 60);
     // 1 to 59 minutes
     if ($diff < 60 || $unit == 'minute') {
         return Text::plural('JLIB_HTML_DATE_RELATIVE_MINUTES', $diff);
     }
     // Round to hours
     $diff = round($diff / 60);
     // 1 to 23 hours
     if ($diff < 24 || $unit == 'hour') {
         return Text::plural('JLIB_HTML_DATE_RELATIVE_HOURS', $diff);
     }
     // Round to days
     $diff = round($diff / 24);
     // 1 to 6 days
     if ($diff < 7 || $unit == 'day') {
         return Text::plural('JLIB_HTML_DATE_RELATIVE_DAYS', $diff);
     }
     // Round to weeks
     $diff = round($diff / 7);
     // 1 to 4 weeks
     if ($diff <= 4 || $unit == 'week') {
         return Text::plural('JLIB_HTML_DATE_RELATIVE_WEEKS', $diff);
     }
     // Over a month, return the absolute time
     return Html::_('date', $date);
 }
 /**
  * Render the feed.
  *
  * @param   string  $name     The name of the element to render
  * @param   array   $params   Array of values
  * @param   string  $content  Override the output of the renderer
  *
  * @return  string  The output of the script
  *
  * @see JDocumentRenderer::render()
  * @since   11.1
  */
 public function render($name = '', $params = null, $content = null)
 {
     $app = Factory::getApplication();
     // Gets and sets timezone offset from site configuration
     $tz = new DateTimeZone($app->getCfg('offset'));
     $now = Factory::getDate();
     $now->setTimeZone($tz);
     $data = $this->_doc;
     $uri = Uri::getInstance();
     $url = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
     $syndicationURL = Route::_('&format=feed&type=atom');
     if ($app->getCfg('sitename_pagetitles', 0) == 1) {
         $title = Text::sprintf('JPAGETITLE', $app->getCfg('sitename'), $data->title);
     } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
         $title = Text::sprintf('JPAGETITLE', $data->title, $app->getCfg('sitename'));
     } else {
         $title = $data->title;
     }
     $feed_title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
     $feed = "<feed xmlns=\"http://www.w3.org/2005/Atom\" ";
     if ($data->language != "") {
         $feed .= " xml:lang=\"" . $data->language . "\"";
     }
     $feed .= ">\n";
     $feed .= "\t<title type=\"text\">" . $feed_title . "</title>\n";
     $feed .= "\t<subtitle type=\"text\">" . htmlspecialchars($data->description, ENT_COMPAT, 'UTF-8') . "</subtitle>\n";
     if (empty($data->category) === false) {
         if (is_array($data->category)) {
             foreach ($data->category as $cat) {
                 $feed .= "\t<category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n";
             }
         } else {
             $feed .= "\t<category term=\"" . htmlspecialchars($data->category, ENT_COMPAT, 'UTF-8') . "\" />\n";
         }
     }
     $feed .= "\t<link rel=\"alternate\" type=\"text/html\" href=\"" . $url . "\"/>\n";
     $feed .= "\t<id>" . str_replace(' ', '%20', $data->getBase()) . "</id>\n";
     $feed .= "\t<updated>" . htmlspecialchars($now->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n";
     if ($data->editor != "") {
         $feed .= "\t<author>\n";
         $feed .= "\t\t<name>" . $data->editor . "</name>\n";
         if ($data->editorEmail != "") {
             $feed .= "\t\t<email>" . htmlspecialchars($data->editorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n";
         }
         $feed .= "\t</author>\n";
     }
     $feed .= "\t<generator uri=\"http://joomla.org\" version=\"1.6\">" . $data->getGenerator() . "</generator>\n";
     $feed .= '	<link rel="self" type="application/atom+xml" href="' . str_replace(' ', '%20', $url . $syndicationURL) . "\"/>\n";
     for ($i = 0, $count = count($data->items); $i < $count; $i++) {
         $feed .= "\t<entry>\n";
         $feed .= "\t\t<title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n";
         $feed .= '		<link rel="alternate" type="text/html" href="' . $url . $data->items[$i]->link . "\"/>\n";
         if ($data->items[$i]->date == "") {
             $data->items[$i]->date = $now->toUnix();
         }
         $itemDate = Factory::getDate($data->items[$i]->date);
         $itemDate->setTimeZone($tz);
         $feed .= "\t\t<published>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</published>\n";
         $feed .= "\t\t<updated>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n";
         if (empty($data->items[$i]->guid) === true) {
             $feed .= "\t\t<id>" . str_replace(' ', '%20', $url . $data->items[$i]->link) . "</id>\n";
         } else {
             $feed .= "\t\t<id>" . htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8') . "</id>\n";
         }
         if ($data->items[$i]->author != "") {
             $feed .= "\t\t<author>\n";
             $feed .= "\t\t\t<name>" . htmlspecialchars($data->items[$i]->author, ENT_COMPAT, 'UTF-8') . "</name>\n";
             if ($data->items[$i]->authorEmail != "") {
                 $feed .= "\t\t\t<email>" . htmlspecialchars($data->items[$i]->authorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n";
             }
             $feed .= "\t\t</author>\n";
         }
         if ($data->items[$i]->description != "") {
             $feed .= "\t\t<summary type=\"html\">" . htmlspecialchars($data->items[$i]->description, ENT_COMPAT, 'UTF-8') . "</summary>\n";
             $feed .= "\t\t<content type=\"html\">" . htmlspecialchars($data->items[$i]->description, ENT_COMPAT, 'UTF-8') . "</content>\n";
         }
         if (empty($data->items[$i]->category) === false) {
             if (is_array($data->items[$i]->category)) {
                 foreach ($data->items[$i]->category as $cat) {
                     $feed .= "\t\t<category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n";
                 }
             } else {
                 $feed .= "\t\t<category term=\"" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8') . "\" />\n";
             }
         }
         if ($data->items[$i]->enclosure != null) {
             $feed .= "\t\t<link rel=\"enclosure\" href=\"" . $data->items[$i]->enclosure->url . "\" type=\"" . $data->items[$i]->enclosure->type . "\"  length=\"" . $data->items[$i]->enclosure->length . "\" />\n";
         }
         $feed .= "\t</entry>\n";
     }
     $feed .= "</feed>\n";
     return $feed;
 }
 /**
  * Updates last visit time of user
  *
  * @param   integer  $timeStamp  The timestamp, defaults to 'now'.
  * @param   integer  $userId     The user id (optional).
  *
  * @return  boolean  False if an error occurs
  *
  * @since   11.1
  */
 public function setLastVisit($timeStamp = null, $userId = null)
 {
     // Check for User ID
     if (is_null($userId)) {
         if (isset($this)) {
             $userId = $this->id;
         } else {
             jexit('No userid in setLastVisit');
         }
     }
     // If no timestamp value is passed to function, than current time is used.
     $date = Factory::getDate($timeStamp);
     // Update the database row for the user.
     $db = $this->_db;
     $query = $db->getQuery(true);
     $query->update($db->quoteName($this->_tbl));
     $query->set($db->quoteName('lastvisitDate') . '=' . $db->quote($date->toSql()));
     $query->where($db->quoteName('id') . '=' . (int) $userId);
     $db->setQuery($query);
     $db->execute();
     return true;
 }
 /**
  * Returns formated date according to a given format and time zone.
  *
  * @param   string   $input      String in a format accepted by date(), defaults to "now".
  * @param   string   $format     The date format specification string (see {@link PHP_MANUAL#date})
  * @param   mixed    $tz         Time zone to be used for the date.  Special cases: boolean true for user
  *                               setting, boolean false for server setting.
  * @param   boolean  $gregorian  True to use Gregorian calenar
  *
  * @return  string    A date translated by the given format and time zone.
  *
  * @see     strftime
  * @since   11.1
  */
 public static function date($input = 'now', $format = null, $tz = true, $gregorian = false)
 {
     // Get some system objects.
     $config = Factory::getConfig();
     $user = Factory::getUser();
     // UTC date converted to user time zone.
     if ($tz === true) {
         // Get a date object based on UTC.
         $date = Factory::getDate($input, 'UTC');
         // Set the correct time zone based on the user configuration.
         $date->setTimeZone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
     } elseif ($tz === false) {
         // Get a date object based on UTC.
         $date = Factory::getDate($input, 'UTC');
         // Set the correct time zone based on the server configuration.
         $date->setTimeZone(new DateTimeZone($config->get('offset')));
     } elseif ($tz === null) {
         $date = Factory::getDate($input);
     } else {
         // Get a date object based on UTC.
         $date = Factory::getDate($input, 'UTC');
         // Set the correct time zone based on the server configuration.
         $date->setTimeZone(new DateTimeZone($tz));
     }
     // If no format is given use the default locale based format.
     if (!$format) {
         $format = Text::_('DATE_FORMAT_LC1');
     } elseif (Factory::getLanguage()->hasKey($format)) {
         $format = Text::_($format);
     }
     if ($gregorian) {
         return $date->format($format, true);
     } else {
         return $date->calendar($format, true);
     }
 }
 /**
  * Method to apply an input filter to a value based on field data.
  *
  * @param   string  $element  The XML element object representation of the form field.
  * @param   mixed   $value    The value to filter for the field.
  *
  * @return  mixed   The filtered value.
  *
  * @since   11.1
  */
 protected function filterField($element, $value)
 {
     // Make sure there is a valid SimpleXMLElement.
     if (!$element instanceof SimpleXMLElement) {
         return false;
     }
     // Get the field filter type.
     $filter = (string) $element['filter'];
     // Process the input value based on the filter.
     $return = null;
     switch (strtoupper($filter)) {
         // Access Control Rules.
         case 'RULES':
             $return = array();
             foreach ((array) $value as $action => $ids) {
                 // Build the rules array.
                 $return[$action] = array();
                 foreach ($ids as $id => $p) {
                     if ($p !== '') {
                         $return[$action][$id] = $p == '1' || $p == 'true' ? true : false;
                     }
                 }
             }
             break;
             // Do nothing, thus leaving the return value as null.
         // Do nothing, thus leaving the return value as null.
         case 'UNSET':
             break;
             // No Filter.
         // No Filter.
         case 'RAW':
             $return = $value;
             break;
             // Filter the input as an array of integers.
         // Filter the input as an array of integers.
         case 'INT_ARRAY':
             // Make sure the input is an array.
             if (is_object($value)) {
                 $value = get_object_vars($value);
             }
             $value = is_array($value) ? $value : array($value);
             ArrayHelper::toInteger($value);
             $return = $value;
             break;
             // Filter safe HTML.
         // Filter safe HTML.
         case 'SAFEHTML':
             $return = Input::getInstance(null, null, 1, 1)->clean($value, 'string');
             break;
             // Convert a date to UTC based on the server timezone offset.
         // Convert a date to UTC based on the server timezone offset.
         case 'SERVER_UTC':
             if ((int) $value > 0) {
                 // Get the server timezone setting.
                 $offset = Factory::getConfig()->get('offset');
                 // Return an SQL formatted datetime string in UTC.
                 $return = Factory::getDate($value, $offset)->toSql();
             } else {
                 $return = '';
             }
             break;
             // Convert a date to UTC based on the user timezone offset.
         // Convert a date to UTC based on the user timezone offset.
         case 'USER_UTC':
             if ((int) $value > 0) {
                 // Get the user timezone setting defaulting to the server timezone setting.
                 $offset = Factory::getUser()->getParam('timezone', Factory::getConfig()->get('offset'));
                 // Return a MySQL formatted datetime string in UTC.
                 $return = Factory::getDate($value, $offset)->toSql();
             } else {
                 $return = '';
             }
             break;
             // Ensures a protocol is present in the saved field. Only use when
             // the only permitted protocols requre '://'. See JFormRuleUrl for list of these.
         // Ensures a protocol is present in the saved field. Only use when
         // the only permitted protocols requre '://'. See JFormRuleUrl for list of these.
         case 'URL':
             if (empty($value)) {
                 return;
             }
             $value = Input::getInstance()->clean($value, 'html');
             $value = trim($value);
             // Check for a protocol
             $protocol = parse_url($value, PHP_URL_SCHEME);
             // If there is no protocol and the relative option is not specified,
             // we assume that it is an external URL and prepend http://.
             if ($element['type'] == 'url' && !$protocol && !$element['relative'] || !$element['type'] == 'url' && !$protocol) {
                 $protocol = 'http';
                 // If it looks like an internal link, then add the root.
                 if (substr($value, 0) == 'index.php') {
                     $value = Uri::root() . $value;
                 }
                 // Otherwise we treat it is an external link.
                 // Put the url back together.
                 $value = $protocol . '://' . $value;
             } elseif (!$protocol && $element['relative']) {
                 $host = Uri::getInstance('SERVER')->gethost();
                 // If it starts with the host string, just prepend the protocol.
                 if (substr($value, 0) == $host) {
                     $value = 'http://' . $value;
                 } else {
                     $value = Uri::root() . $value;
                 }
             }
             $return = $value;
             break;
         case 'TEL':
             $value = trim($value);
             // Does it match the NANP pattern?
             if (preg_match('/^(?:\\+?1[-. ]?)?\\(?([2-9][0-8][0-9])\\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) {
                 $number = (string) preg_replace('/[^\\d]/', '', $value);
                 if (substr($number, 0, 1) == 1) {
                     $number = substr($number, 1);
                 }
                 if (substr($number, 0, 2) == '+1') {
                     $number = substr($number, 2);
                 }
                 $result = '1.' . $number;
             } elseif (preg_match('/^\\+(?:[0-9] ?){6,14}[0-9]$/', $value) == 1) {
                 $countrycode = substr($value, 0, strpos($value, ' '));
                 $countrycode = (string) preg_replace('/[^\\d]/', '', $countrycode);
                 $number = strstr($value, ' ');
                 $number = (string) preg_replace('/[^\\d]/', '', $number);
                 $result = $countrycode . '.' . $number;
             } elseif (preg_match('/^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$/', $value) == 1) {
                 if (strstr($value, 'x')) {
                     $xpos = strpos($value, 'x');
                     $value = substr($value, 0, $xpos);
                 }
                 $result = str_replace('+', '', $value);
             } elseif (preg_match('/[0-9]{1,3}\\.[0-9]{4,14}$/', $value) == 1) {
                 $result = $value;
             } else {
                 $value = (string) preg_replace('/[^\\d]/', '', $value);
                 if ($value != null && strlen($value) <= 15) {
                     $length = strlen($value);
                     // If it is fewer than 13 digits assume it is a local number
                     if ($length <= 12) {
                         $result = '.' . $value;
                     } else {
                         // If it has 13 or more digits let's make a country code.
                         $cclen = $length - 12;
                         $result = substr($value, 0, $cclen) . '.' . substr($value, $cclen);
                     }
                 } else {
                     $result = '';
                 }
             }
             $return = $result;
             break;
         default:
             // Check for a callback filter.
             if (strpos($filter, '::') !== false && is_callable(explode('::', $filter))) {
                 $return = call_user_func(explode('::', $filter), $value);
             } elseif (function_exists($filter)) {
                 $return = call_user_func($filter, $value);
             } else {
                 $return = Input::getInstance()->clean($value, $filter);
             }
             break;
     }
     return $return;
 }
 /**
  * Method to bind an associative array of data to a user object
  *
  * @param   array  &$array  The associative array to bind to the object
  *
  * @return  boolean  True on success
  *
  * @since   11.1
  */
 public function bind(&$array)
 {
     // Let's check to see if the user is new or not
     if (empty($this->id)) {
         // Check the password and create the crypted password
         if (empty($array['password'])) {
             $array['password'] = Helper::genRandomPassword();
             $array['password2'] = $array['password'];
         }
         // Not all controllers check the password, although they should.
         // Hence this code is required:
         if (isset($array['password2']) && $array['password'] != $array['password2']) {
             $this->setError(Text::_('JLIB_USER_ERROR_PASSWORD_NOT_MATCH'));
             return false;
         }
         $this->password_clear = ArrayHelper::getValue($array, 'password', '', 'string');
         $salt = Helper::genRandomPassword(32);
         $crypt = Helper::getCryptedPassword($array['password'], $salt);
         $array['password'] = $crypt . ':' . $salt;
         // Set the registration timestamp
         $this->set('registerDate', Factory::getDate()->toSql());
     } else {
         // Updating an existing user
         if (!empty($array['password'])) {
             if ($array['password'] != $array['password2']) {
                 $this->setError(Text::_('JLIB_USER_ERROR_PASSWORD_NOT_MATCH'));
                 return false;
             }
             $this->password_clear = ArrayHelper::getValue($array, 'password', '', 'string');
             $salt = Helper::genRandomPassword(32);
             $crypt = Helper::getCryptedPassword($array['password'], $salt);
             $array['password'] = $crypt . ':' . $salt;
         } else {
             $array['password'] = $this->password;
         }
     }
     if (array_key_exists('params', $array)) {
         $params = '';
         $this->_params->loadArray($array['params']);
         if (is_array($array['params'])) {
             $params = (string) $this->_params;
         } else {
             $params = $array['params'];
         }
         $this->params = $params;
     }
     // Bind the array
     if (!$this->setProperties($array)) {
         $this->setError(Text::_('JLIB_USER_ERROR_BIND_ARRAY'));
         return false;
     }
     // Check that username is not greater than 150 characters
     $username = $this->get('username');
     if (strlen($username) > 150) {
         $username = substr($username, 0, 150);
         $this->set('username', $username);
     }
     // Check that password is not greater than 100 characters
     $password = $this->get('password');
     if (strlen($password) > 100) {
         $password = substr($password, 0, 100);
         $this->set('password', $password);
     }
     // Make sure its an integer
     $this->id = (int) $this->id;
     return true;
 }
 /**
  * Render the feed.
  *
  * @param   string  $name     The name of the element to render
  * @param   array   $params   Array of values
  * @param   string  $content  Override the output of the renderer
  *
  * @return  string  The output of the script
  *
  * @see JDocumentRenderer::render()
  * @since   11.1
  */
 public function render($name = '', $params = null, $content = null)
 {
     $app = Factory::getApplication();
     // Gets and sets timezone offset from site configuration
     $tz = new DateTimeZone($app->getCfg('offset'));
     $now = Factory::getDate();
     $now->setTimeZone($tz);
     $data = $this->_doc;
     $uri = Uri::getInstance();
     $url = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
     $syndicationURL = Route::_('&format=feed&type=rss');
     if ($app->getCfg('sitename_pagetitles', 0) == 1) {
         $title = Text::sprintf('JPAGETITLE', $app->getCfg('sitename'), $data->title);
     } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
         $title = Text::sprintf('JPAGETITLE', $data->title, $app->getCfg('sitename'));
     } else {
         $title = $data->title;
     }
     $feed_title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
     $feed = "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
     $feed .= "\t<channel>\n";
     $feed .= "\t\t<title>" . $feed_title . "</title>\n";
     $feed .= "\t\t<description><![CDATA[" . $data->description . "]]></description>\n";
     $feed .= "\t\t<link>" . str_replace(' ', '%20', $url . $data->link) . "</link>\n";
     $feed .= "\t\t<lastBuildDate>" . htmlspecialchars($now->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</lastBuildDate>\n";
     $feed .= "\t\t<generator>" . $data->getGenerator() . "</generator>\n";
     $feed .= '		<atom:link rel="self" type="application/rss+xml" href="' . str_replace(' ', '%20', $url . $syndicationURL) . "\"/>\n";
     if ($data->image != null) {
         $feed .= "\t\t<image>\n";
         $feed .= "\t\t\t<url>" . $data->image->url . "</url>\n";
         $feed .= "\t\t\t<title>" . htmlspecialchars($data->image->title, ENT_COMPAT, 'UTF-8') . "</title>\n";
         $feed .= "\t\t\t<link>" . str_replace(' ', '%20', $data->image->link) . "</link>\n";
         if ($data->image->width != "") {
             $feed .= "\t\t\t<width>" . $data->image->width . "</width>\n";
         }
         if ($data->image->height != "") {
             $feed .= "\t\t\t<height>" . $data->image->height . "</height>\n";
         }
         if ($data->image->description != "") {
             $feed .= "\t\t\t<description><![CDATA[" . $data->image->description . "]]></description>\n";
         }
         $feed .= "\t\t</image>\n";
     }
     if ($data->language != "") {
         $feed .= "\t\t<language>" . $data->language . "</language>\n";
     }
     if ($data->copyright != "") {
         $feed .= "\t\t<copyright>" . htmlspecialchars($data->copyright, ENT_COMPAT, 'UTF-8') . "</copyright>\n";
     }
     if ($data->editorEmail != "") {
         $feed .= "\t\t<managingEditor>" . htmlspecialchars($data->editorEmail, ENT_COMPAT, 'UTF-8') . ' (' . htmlspecialchars($data->editor, ENT_COMPAT, 'UTF-8') . ")</managingEditor>\n";
     }
     if ($data->webmaster != "") {
         $feed .= "\t\t<webMaster>" . htmlspecialchars($data->webmaster, ENT_COMPAT, 'UTF-8') . "</webMaster>\n";
     }
     if ($data->pubDate != "") {
         $pubDate = JFactory::getDate($data->pubDate);
         $pubDate->setTimeZone($tz);
         $feed .= "\t\t<pubDate>" . htmlspecialchars($pubDate->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</pubDate>\n";
     }
     if (empty($data->category) === false) {
         if (is_array($data->category)) {
             foreach ($data->category as $cat) {
                 $feed .= "\t\t<category>" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "</category>\n";
             }
         } else {
             $feed .= "\t\t<category>" . htmlspecialchars($data->category, ENT_COMPAT, 'UTF-8') . "</category>\n";
         }
     }
     if ($data->docs != "") {
         $feed .= "\t\t<docs>" . htmlspecialchars($data->docs, ENT_COMPAT, 'UTF-8') . "</docs>\n";
     }
     if ($data->ttl != "") {
         $feed .= "\t\t<ttl>" . htmlspecialchars($data->ttl, ENT_COMPAT, 'UTF-8') . "</ttl>\n";
     }
     if ($data->rating != "") {
         $feed .= "\t\t<rating>" . htmlspecialchars($data->rating, ENT_COMPAT, 'UTF-8') . "</rating>\n";
     }
     if ($data->skipHours != "") {
         $feed .= "\t\t<skipHours>" . htmlspecialchars($data->skipHours, ENT_COMPAT, 'UTF-8') . "</skipHours>\n";
     }
     if ($data->skipDays != "") {
         $feed .= "\t\t<skipDays>" . htmlspecialchars($data->skipDays, ENT_COMPAT, 'UTF-8') . "</skipDays>\n";
     }
     for ($i = 0, $count = count($data->items); $i < $count; $i++) {
         if (strpos($data->items[$i]->link, 'http://') === false && strpos($data->items[$i]->link, 'https://') === false) {
             $data->items[$i]->link = str_replace(' ', '%20', $url . $data->items[$i]->link);
         }
         $feed .= "\t\t<item>\n";
         $feed .= "\t\t\t<title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n";
         $feed .= "\t\t\t<link>" . str_replace(' ', '%20', $data->items[$i]->link) . "</link>\n";
         if (empty($data->items[$i]->guid) === true) {
             $feed .= "\t\t\t<guid isPermaLink=\"true\">" . str_replace(' ', '%20', $data->items[$i]->link) . "</guid>\n";
         } else {
             $feed .= "\t\t\t<guid isPermaLink=\"false\">" . htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8') . "</guid>\n";
         }
         $feed .= "\t\t\t<description><![CDATA[" . $this->_relToAbs($data->items[$i]->description) . "]]></description>\n";
         if ($data->items[$i]->authorEmail != "") {
             $feed .= "\t\t\t<author>" . htmlspecialchars($data->items[$i]->authorEmail . ' (' . $data->items[$i]->author . ')', ENT_COMPAT, 'UTF-8') . "</author>\n";
         }
         /*
          * @todo: On hold
          * if ($data->items[$i]->source!="") {
          *   $data.= "			<source>".htmlspecialchars($data->items[$i]->source, ENT_COMPAT, 'UTF-8')."</source>\n";
          * }
          */
         if (empty($data->items[$i]->category) === false) {
             if (is_array($data->items[$i]->category)) {
                 foreach ($data->items[$i]->category as $cat) {
                     $feed .= "\t\t\t<category>" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "</category>\n";
                 }
             } else {
                 $feed .= "\t\t\t<category>" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8') . "</category>\n";
             }
         }
         if ($data->items[$i]->comments != "") {
             $feed .= "\t\t\t<comments>" . htmlspecialchars($data->items[$i]->comments, ENT_COMPAT, 'UTF-8') . "</comments>\n";
         }
         if ($data->items[$i]->date != "") {
             $itemDate = Factory::getDate($data->items[$i]->date);
             $itemDate->setTimeZone($tz);
             $feed .= "\t\t\t<pubDate>" . htmlspecialchars($itemDate->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</pubDate>\n";
         }
         if ($data->items[$i]->enclosure != null) {
             $feed .= "\t\t\t<enclosure url=\"";
             $feed .= $data->items[$i]->enclosure->url;
             $feed .= "\" length=\"";
             $feed .= $data->items[$i]->enclosure->length;
             $feed .= "\" type=\"";
             $feed .= $data->items[$i]->enclosure->type;
             $feed .= "\"/>\n";
         }
         $feed .= "\t\t</item>\n";
     }
     $feed .= "\t</channel>\n";
     $feed .= "</rss>\n";
     return $feed;
 }
 /**
  * Method to check a row out if the necessary properties/fields exist.  To
  * prevent race conditions while editing rows in a database, a row can be
  * checked out if the fields 'checked_out' and 'checked_out_time' are available.
  * While a row is checked out, any attempt to store the row by a user other
  * than the one who checked the row out should be held until the row is checked
  * in again.
  *
  * @param   integer  $userId  The Id of the user checking out the row.
  * @param   mixed    $pk      An optional primary key value to check out.  If not set
  *                            the instance property value is used.
  *
  * @return  boolean  True on success.
  *
  * @link    http://docs.joomla.org/JTable/checkOut
  * @since   11.1
  */
 public function checkOut($userId, $pk = null)
 {
     // If there is no checked_out or checked_out_time field, just return true.
     if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time')) {
         return true;
     }
     if (is_null($pk)) {
         $pk = array();
         foreach ($this->_tbl_keys as $key) {
             $pk[$key] = $this->{$key};
         }
     } elseif (!is_array($pk)) {
         $pk = array($this->_tbl_key => $pk);
     }
     foreach ($this->_tbl_keys as $key) {
         $pk[$key] = is_null($pk[$key]) ? $this->{$key} : $pk[$key];
         if ($pk[$key] === null) {
             throw new UnexpectedValueException('Null primary key not allowed.');
         }
     }
     // Get the current time in MySQL format.
     $time = Factory::getDate()->toSql();
     // Check the row out by primary key.
     $query = $this->_db->getQuery(true);
     $query->update($this->_tbl);
     $query->set($this->_db->quoteName('checked_out') . ' = ' . (int) $userId);
     $query->set($this->_db->quoteName('checked_out_time') . ' = ' . $this->_db->quote($time));
     $this->appendPrimaryKeys($query, $pk);
     $this->_db->setQuery($query);
     $this->_db->execute();
     // Set table values in the object.
     $this->checked_out = (int) $userId;
     $this->checked_out_time = $time;
     return true;
 }
 /**
  * Method to get the field input markup.
  *
  * @return  string   The field input markup.
  *
  * @since   11.1
  */
 protected function getInput()
 {
     // Initialize some field attributes.
     $format = $this->element['format'] ? (string) $this->element['format'] : '%Y-%m-%d';
     // Build the attributes array.
     $attributes = array();
     if ($this->element['size']) {
         $attributes['size'] = (int) $this->element['size'];
     }
     if ($this->element['maxlength']) {
         $attributes['maxlength'] = (int) $this->element['maxlength'];
     }
     if ($this->element['class']) {
         $attributes['class'] = (string) $this->element['class'];
     }
     if ((string) $this->element['readonly'] == 'true') {
         $attributes['readonly'] = 'readonly';
     }
     if ((string) $this->element['disabled'] == 'true') {
         $attributes['disabled'] = 'disabled';
     }
     if ($this->element['onchange']) {
         $attributes['onchange'] = (string) $this->element['onchange'];
     }
     // Handle the special case for "now".
     if (strtoupper($this->value) == 'NOW') {
         $this->value = strftime($format);
     }
     // Get some system objects.
     $config = Factory::getConfig();
     $user = Factory::getUser();
     // If a known filter is given use it.
     switch (strtoupper((string) $this->element['filter'])) {
         case 'SERVER_UTC':
             // Convert a date to UTC based on the server timezone.
             if ((int) $this->value) {
                 // Get a date object based on the correct timezone.
                 $date = Factory::getDate($this->value, 'UTC');
                 $date->setTimezone(new DateTimeZone($config->get('offset')));
                 // Transform the date string.
                 $this->value = $date->format('Y-m-d H:i:s', true, false);
             }
             break;
         case 'USER_UTC':
             // Convert a date to UTC based on the user timezone.
             if ((int) $this->value) {
                 // Get a date object based on the correct timezone.
                 $date = Factory::getDate($this->value, 'UTC');
                 $date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset'))));
                 // Transform the date string.
                 $this->value = $date->format('Y-m-d H:i:s', true, false);
             }
             break;
     }
     return Html::_('calendar', $this->value, $this->name, $this->id, $format, $attributes);
 }
 /**
  * Returns a published state on a grid
  *
  * @param   integer       $value         The state value.
  * @param   integer       $i             The row index
  * @param   string|array  $prefix        An optional task prefix or an array of options
  * @param   boolean       $enabled       An optional setting for access control on the action.
  * @param   string        $checkbox      An optional prefix for checkboxes.
  * @param   string        $publish_up    An optional start publishing date.
  * @param   string        $publish_down  An optional finish publishing date.
  *
  * @return  string  The Html code
  *
  * @see     JHtmlJGrid::state
  * @since   11.1
  */
 public static function published($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb', $publish_up = null, $publish_down = null)
 {
     if (is_array($prefix)) {
         $options = $prefix;
         $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
         $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
         $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
     }
     $states = array(1 => array('unpublish', 'JPUBLISHED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JPUBLISHED', false, 'publish', 'publish'), 0 => array('publish', 'JUNPUBLISHED', 'JLIB_HTML_PUBLISH_ITEM', 'JUNPUBLISHED', false, 'unpublish', 'unpublish'), 2 => array('unpublish', 'JARCHIVED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JARCHIVED', false, 'archive', 'archive'), -2 => array('publish', 'JTRASHED', 'JLIB_HTML_PUBLISH_ITEM', 'JTRASHED', false, 'trash', 'trash'));
     // Special state for dates
     if ($publish_up || $publish_down) {
         $nullDate = Factory::getDBO()->getNullDate();
         $nowDate = Factory::getDate()->toUnix();
         $tz = new DateTimeZone(Factory::getUser()->getParam('timezone', Factory::getConfig()->get('offset')));
         $publish_up = $publish_up != $nullDate ? Factory::getDate($publish_up, 'UTC')->setTimeZone($tz) : false;
         $publish_down = $publish_down != $nullDate ? Factory::getDate($publish_down, 'UTC')->setTimeZone($tz) : false;
         // Create tip text, only we have publish up or down settings
         $tips = array();
         if ($publish_up) {
             $tips[] = Text::sprintf('JLIB_HTML_PUBLISHED_START', $publish_up->format(Date::$format, true));
         }
         if ($publish_down) {
             $tips[] = Text::sprintf('JLIB_HTML_PUBLISHED_FINISHED', $publish_down->format(Date::$format, true));
         }
         $tip = empty($tips) ? false : implode('<br/>', $tips);
         // Add tips and special titles
         foreach ($states as $key => $state) {
             // Create special titles for published items
             if ($key == 1) {
                 $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_ITEM';
                 if ($publish_up > $nullDate && $nowDate < $publish_up->toUnix()) {
                     $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_PENDING_ITEM';
                     $states[$key][5] = $states[$key][6] = 'pending';
                 }
                 if ($publish_down > $nullDate && $nowDate > $publish_down->toUnix()) {
                     $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_EXPIRED_ITEM';
                     $states[$key][5] = $states[$key][6] = 'expired';
                 }
             }
             // Add tips to titles
             if ($tip) {
                 $states[$key][1] = Text::_($states[$key][1]);
                 $states[$key][2] = Text::_($states[$key][2]) . '::' . $tip;
                 $states[$key][3] = Text::_($states[$key][3]) . '::' . $tip;
                 $states[$key][4] = true;
             }
         }
         return self::state($states, $value, $i, array('prefix' => $prefix, 'translate' => !$tip), $enabled, true, $checkbox);
     }
     return self::state($states, $value, $i, $prefix, $enabled, true, $checkbox);
 }