plugins/gallery/functions.php
changeset 18 c1c398349651
parent 0 7caf561c50ee
child 38 512951548faa
equal deleted inserted replaced
15:ac7d3dedcc44 18:c1c398349651
   312   }
   312   }
   313   closedir($dir_handle);
   313   closedir($dir_handle);
   314   return $entries;
   314   return $entries;
   315 }
   315 }
   316 
   316 
       
   317 /**
       
   318  * Wrapper for JSON decoding that works on Enano 1.0.x and 1.1.x
       
   319  * @param string JSON datastream...
       
   320  * @return mixed
       
   321  */
       
   322 
       
   323 function snapr_json_decode($data)
       
   324 {
       
   325   if ( defined('ENANO_ATLEAST_1_1') )
       
   326   {
       
   327     try
       
   328     {
       
   329       $decoded = enano_json_decode($data);
       
   330     }
       
   331     catch ( Exception $e )
       
   332     {
       
   333       $response = array(
       
   334         'mode' => 'error',
       
   335         'error' => 'Exception in JSON parser.'
       
   336       );
       
   337       die(enano_json_encode($response));
       
   338     }
       
   339   }
       
   340   else
       
   341   {
       
   342     $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
       
   343     $decoded = $json->decode($data);
       
   344   }
       
   345   return ( isset($decoded) ) ? $decoded : false;
       
   346 }
       
   347 
       
   348 /**
       
   349  * Wrapper for JSON encoding that works on Enano 1.0.x and 1.1.x
       
   350  * @param mixed Data to encode
       
   351  * @return string
       
   352  */
       
   353 
       
   354 function snapr_json_encode($data)
       
   355 {
       
   356   if ( defined('ENANO_ATLEAST_1_1') )
       
   357   {
       
   358     try
       
   359     {
       
   360       $encoded = enano_json_encode($data);
       
   361     }
       
   362     catch ( Exception $e )
       
   363     {
       
   364       $response = array(
       
   365         'mode' => 'error',
       
   366         'error' => 'Exception in JSON encoder.'
       
   367       );
       
   368       die(enano_json_encode($response));
       
   369     }
       
   370   }
       
   371   else
       
   372   {
       
   373     $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
       
   374     $encoded = $json->encode($data);
       
   375   }
       
   376   return ( isset($encoded) ) ? $encoded : false;
       
   377 }
       
   378 
   317 ?>
   379 ?>