Ejemplo n.º 1
0
/**
 * @brief escape text ($str) for XML transport
 *
 * @param string $str
 * @return string Escaped text.
 */
function xmlify($str)
{
    $buffer = '';
    if (is_array($str)) {
        // allow to fall through so we ge a PHP error, as the log statement will
        // probably get lost in the noise unless we're specifically looking for it.
        btlogger('xmlify called with array: ' . print_r($str, true), LOGGER_NORMAL, LOG_WARNING);
    }
    $len = mb_strlen($str);
    for ($x = 0; $x < $len; $x++) {
        $char = mb_substr($str, $x, 1);
        switch ($char) {
            case "\r":
                break;
            case "&":
                $buffer .= '&amp;';
                break;
            case "'":
                $buffer .= '&apos;';
                break;
            case "\"":
                $buffer .= '&quot;';
                break;
            case '<':
                $buffer .= '&lt;';
                break;
            case '>':
                $buffer .= '&gt;';
                break;
            case "\n":
                $buffer .= "\n";
                break;
            default:
                $buffer .= $char;
                break;
        }
    }
    $buffer = trim($buffer);
    return $buffer;
}
Ejemplo n.º 2
0
 /**
  * @brief Sets a configuration value for a channel.
  *
  * Stores a config value ($value) in the category ($family) under the key ($key)
  * for the channel_id $uid.
  *
  * @param string $uid
  *  The channel_id
  * @param string $family
  *  The category of the configuration value
  * @param string $key
  *  The configuration key to set
  * @param string $value
  *  The value to store
  * @return mixed Stored $value or false
  */
 public static function Set($uid, $family, $key, $value)
 {
     // this catches subtle errors where this function has been called
     // with local_channel() when not logged in (which returns false)
     // and throws an error in array_key_exists below.
     // we provide a function backtrace in the logs so that we can find
     // and fix the calling function.
     if (is_null($uid) || $uid === false) {
         btlogger('UID is FALSE!', LOGGER_NORMAL, LOG_ERR);
         return;
     }
     // manage array value
     $dbvalue = is_array($value) ? serialize($value) : $value;
     $dbvalue = is_bool($dbvalue) ? intval($dbvalue) : $dbvalue;
     if (get_pconfig($uid, $family, $key) === false) {
         if (!array_key_exists($uid, \App::$config)) {
             \App::$config[$uid] = array();
         }
         if (!array_key_exists($family, \App::$config[$uid])) {
             \App::$config[$uid][$family] = array();
         }
         $ret = q("INSERT INTO pconfig ( uid, cat, k, v ) VALUES ( %d, '%s', '%s', '%s' ) ", intval($uid), dbesc($family), dbesc($key), dbesc($dbvalue));
     } else {
         $ret = q("UPDATE pconfig SET v = '%s' WHERE uid = %d and cat = '%s' AND k = '%s'", dbesc($dbvalue), intval($uid), dbesc($family), dbesc($key));
     }
     // keep a separate copy for all variables which were
     // set in the life of this page. We need this to
     // synchronise channel clones.
     if (!array_key_exists('transient', \App::$config[$uid])) {
         \App::$config[$uid]['transient'] = array();
     }
     if (!array_key_exists($family, \App::$config[$uid]['transient'])) {
         \App::$config[$uid]['transient'][$family] = array();
     }
     \App::$config[$uid][$family][$key] = $value;
     \App::$config[$uid]['transient'][$family][$key] = $value;
     if ($ret) {
         return $value;
     }
     return $ret;
 }