/**
  * Takes the given text and converts any URLs into links,
  * returning HTML content.
  *
  * @param string $text
  * @param bool true to sanitize the text before parsing for display security
  * @return string HTML
  */
 static function ConvertUrlToLink($text, $sanitize = false)
 {
     if ($sanitize) {
         $text = VerySimpleStringUtil::Sanitize($text);
     }
     $regex = "/[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]/i";
     return preg_replace($regex, '<a href=\\"\\0\\">\\0</a>', $text);
 }
Beispiel #2
0
 /**
  * Given a URL return an OAuth signed URL.  This will handle creating a timestamp and nonce
  *
  * @param string $url the unsigned url
  * @param string $method request method GET, POST, PUT, DELETE
  * @param string $key oauth key
  * @param string $secret oauth secret
  * @param array $params querystring or post parameters
  * @param string $body the body contents of the request
  * @param string $signature_method method used for signature (default = 'HMAC_SHA1')
  */
 public static function SignUrl($url, $method, $key, $secret, $params = null, $body = null, $signature_method = 'HMAC_SHA1')
 {
     $options = array('consumer_key' => $key, 'consumer_secret' => $secret);
     $params = $params ? $params : array();
     OAuthStore::instance("2Leg", $options);
     // Obtain a request object for the request we want to make
     $request = new OAuthRequester($url, $method, $params, $body);
     $sig = $request->sign($key, null, '');
     $data = $request->signatureBaseString();
     $url = substr(urldecode($data . '&oauth_signature=' . $request->calculateDataSignature($data, $secret, '', $signature_method)), strlen($method) + 1);
     $url = VerySimpleStringUtil::ReplaceFirst('&', '?', $url);
     return $url;
 }
Beispiel #3
0
 /**
  * Renders a datapage as XML for use with a datagrid.  The optional $additionalProps allows
  * retrieval of properties from foreign relationships
  *
  * @param DataPage $page
  * @param Array $additionalProps (In the format Array("GetObjName1"=>"PropName","GetObjName2"=>"PropName1,PropName2")
  * @param Array $supressProps (In the format Array("PropName1","PropName2")
  * @param bool noMap set to true to render this DataPage regardless of whether there is a FieldMap
  */
 protected function RenderXML(DataPage $page, $additionalProps = null, $supressProps = null, $noMap = false)
 {
     if (!is_array($supressProps)) {
         $supressProps = array();
     }
     // never include these props
     $suppressProps[] = "NoCache";
     $suppressProps[] = "CacheLevel";
     $suppressProps[] = "IsLoaded";
     $suppressProps[] = "IsPartiallyLoaded";
     $xml = "";
     $xml .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
     $xml .= "<DataPage>\r\n";
     $xml .= "<ObjectName>" . htmlspecialchars($page->ObjectName) . "</ObjectName>\r\n";
     $xml .= "<ObjectKey>" . htmlspecialchars($page->ObjectKey) . "</ObjectKey>\r\n";
     $xml .= "<TotalRecords>" . htmlspecialchars($page->TotalResults) . "</TotalRecords>\r\n";
     $xml .= "<TotalPages>" . htmlspecialchars($page->TotalPages) . "</TotalPages>\r\n";
     $xml .= "<CurrentPage>" . htmlspecialchars($page->CurrentPage) . "</CurrentPage>\r\n";
     $xml .= "<PageSize>" . htmlspecialchars($page->PageSize) . "</PageSize>\r\n";
     $xml .= "<Records>\r\n";
     // get the fieldmap for this object type unless not specified
     if ($noMap) {
         $fms = array();
     } else {
         try {
             $fms = $this->Phreezer->GetFieldMaps($page->ObjectName);
         } catch (exception $ex) {
             throw new Exception("The objects contained in this DataPage do not have a FieldMap.  Set noMap argument to true to supress this error: " . $ex->getMessage());
         }
     }
     foreach ($page->Rows as $obj) {
         $xml .= "<" . htmlspecialchars($page->ObjectName) . ">\r\n";
         foreach (get_object_vars($obj) as $var => $val) {
             if (!in_array($var, $supressProps)) {
                 // depending on what type of field this is, do some special formatting
                 $fm = isset($fms[$var]) ? $fms[$var]->FieldType : FM_TYPE_UNKNOWN;
                 if ($fm == FM_TYPE_DATETIME) {
                     $val = strtotime($val) ? date("m/d/Y h:i A", strtotime($val)) : $val;
                 } elseif ($fm == FM_TYPE_DATE) {
                     $val = strtotime($val) ? date("m/d/Y", strtotime($val)) : $val;
                 }
                 // if the developer has added a property that is not a simple type
                 // we need to serialize it
                 if (is_array($val) || is_object($val)) {
                     $val = serialize($val);
                 }
                 $val = VerySimpleStringUtil::EncodeSpecialCharacters($val, true, true);
                 $xml .= "<" . htmlspecialchars($var) . ">" . $val . "</" . htmlspecialchars($var) . ">\r\n";
             }
         }
         // Add any properties that we want from child objects
         if ($additionalProps) {
             foreach ($additionalProps as $meth => $propPair) {
                 $props = explode(",", $propPair);
                 foreach ($props as $prop) {
                     $xml .= "<" . htmlspecialchars($meth . $prop) . ">" . htmlspecialchars($obj->{$meth}()->{$prop}) . "</" . htmlspecialchars($meth . $prop) . ">\r\n";
                 }
             }
         }
         $xml .= "</" . htmlspecialchars($page->ObjectName) . ">\r\n";
     }
     $xml .= "</Records>\r\n";
     $xml .= "</DataPage>\r\n";
     // capture output instead of rendering if specified
     if ($this->CaptureOutputMode) {
         $this->DebugOutput = $xml;
     } else {
         header('Content-type: text/xml');
         print $xml;
     }
 }
Beispiel #4
0
 /**
  * Returns true if the given form field has non-ascii characters
  * @param string $fieldname
  * @return bool
  */
 public static function HasNonAsciiChars($fieldname)
 {
     require_once "verysimple/String/VerySimpleStringUtil.php";
     $val = isset($_REQUEST[$fieldname]) ? $_REQUEST[$fieldname] : '';
     return VerySimpleStringUtil::EncodeToHTML($val) != $val;
 }
Beispiel #5
0
 /**
  * Returns true if the given form field has non-ascii characters
  * @param string $fieldname
  * @return bool
  */
 public static function HasNonAsciiChars($fieldname)
 {
     $val = isset($_REQUEST[$fieldname]) ? $_REQUEST[$fieldname] : '';
     return VerySimpleStringUtil::EncodeToHTML($val) != $val;
 }
Beispiel #6
0
 /**
  * Strips any HTML entities from the value using VerySimpleStringUtil
  * @param string $val
  * @return string
  */
 public function DecodeEntities($val)
 {
     return VerySimpleStringUtil::DecodeFromHTML($val, 'ISO-8859-1');
     // return  utf8_decode( VerySimpleStringUtil::DecodeFromHTML($val,) );
 }