includes/functions.php
changeset 334 c72b545f1304
parent 328 dc838fd61a06
child 335 67bd3121a12e
equal deleted inserted replaced
333:32429702305e 334:c72b545f1304
  3804     return 'jpg';
  3804     return 'jpg';
  3805   
  3805   
  3806   return false;
  3806   return false;
  3807 }
  3807 }
  3808 
  3808 
       
  3809 /**
       
  3810  * Generates a JSON encoder/decoder singleton.
       
  3811  * @return object
       
  3812  */
       
  3813 
       
  3814 function enano_json_singleton()
       
  3815 {
       
  3816   static $json_obj;
       
  3817   if ( !is_object($json_obj) )
       
  3818     $json_obj = new Services_JSON(SERVICES_JSON_LOOSE_TYPE | SERVICES_JSON_SUPPRESS_ERRORS);
       
  3819   
       
  3820   return $json_obj;
       
  3821 }
       
  3822 
       
  3823 /**
       
  3824  * Wrapper for JSON encoding.
       
  3825  * @param mixed Variable to encode
       
  3826  * @return string JSON-encoded string
       
  3827  */
       
  3828 
       
  3829 function enano_json_encode($data)
       
  3830 {
       
  3831   /*
       
  3832   if ( function_exists('json_encode') )
       
  3833   {
       
  3834     // using PHP5 with JSON support
       
  3835     return json_encode($data);
       
  3836   }
       
  3837   */
       
  3838   
       
  3839   return Zend_Json::encode($data, true);
       
  3840 }
       
  3841 
       
  3842 /**
       
  3843  * Wrapper for JSON decoding.
       
  3844  * @param string JSON-encoded string
       
  3845  * @return mixed Decoded value
       
  3846  */
       
  3847 
       
  3848 function enano_json_decode($data)
       
  3849 {
       
  3850   /*
       
  3851   if ( function_exists('json_decode') )
       
  3852   {
       
  3853     // using PHP5 with JSON support
       
  3854     return json_decode($data);
       
  3855   }
       
  3856   */
       
  3857   
       
  3858   return Zend_Json::decode($data, Zend_Json::TYPE_ARRAY);
       
  3859 }
       
  3860 
  3809 //die('<pre>Original:  01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'</pre>');
  3861 //die('<pre>Original:  01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'</pre>');
  3810 
  3862 
  3811 ?>
  3863 ?>