Exemple #1
0
 public function send($type, $url, $request = null, $options = array())
 {
     if (is_string($options['header'])) {
         $headers = preg_split('\\r\\n', $options['header']);
     } else {
         $headers = (array) $options['header'];
     }
     switch ($type) {
         case 'GET':
             $type = OAUTH_HTTP_METHOD_GET;
             break;
         case 'POST':
             $type = OAUTH_HTTP_METHOD_POST;
             break;
         case 'PUT':
             $type = OAUTH_HTTP_METHOD_PUT;
             break;
         case 'DELETE':
             $type = OAUTH_HTTP_METHOD_DELETE;
             break;
     }
     try {
         if ($this->wrapped->fetch((string) $url, $request, $type, $headers)) {
             return $this->wrapped->getLastResponse();
         } else {
             return ar_error::raiseError('OAuth fetch failed', ar_exceptions::UNKNOWN_ERROR);
         }
     } catch (Exception $e) {
         return ar_error::raiseError($e->getMessage(), $e->getCode());
     }
 }
Exemple #2
0
 function create($filename)
 {
     ini_set('memory_limit', '512M');
     $this->_filename = $filename;
     $resCreate = $this->open($this->_filename, ZipArchive::CREATE);
     if ($resCreate !== true) {
         return ar_error::raiseError("System-error creating temporary zip archive '" . $this->filename . "'", $resCreate);
     }
     return $this;
 }
Exemple #3
0
 public static function create($prefix = null, $timeout = 7200)
 {
     // this method is used by pinp scripts to create a specific cache
     // so it must be more restrictive than the constructor of the cacheStore
     // which must be able to clear any and all caches
     if (!$prefix) {
         // make sure you have a default prefix, so you won't clear other prefixes unintended
         $prefix = 'default';
     }
     $prefix = 'pinp/' . $prefix;
     // make sure the pinp scripts have their own top level
     $prefix = $prefix . ar::context()->getPath();
     // make sure the cache store is limited to the current path in the context stack
     try {
         return new ar_cacheStore($prefix, $timeout);
     } catch (Exception $e) {
         return ar_error::raiseError($e->getMessage(), $e->getCode());
     }
 }
Exemple #4
0
 public function generateFromURL($url)
 {
     if (!preg_match('|^https?://|', $url)) {
         return ar_error::raiseError("wkhtmltopdf: '{$url}' is not a valid URL", 201);
     }
     $url = escapeshellarg($url);
     $tempFile = tempnam($this->config['temp'], 'pdf');
     if (!$tempFile) {
         return ar_error::raiseError("wkhtmltopdf: could not create a temporary file", 202);
     }
     $execString = $this->config['cmd'];
     foreach ($this->options as $name => $value) {
         if (is_bool($value)) {
             $execString .= " --{$name}";
         } else {
             $execString .= " --{$name} " . escapeshellarg($value);
         }
     }
     foreach ($this->cookies as $name => $value) {
         $execString .= " --cookie " . escapeshellarg($name) . " " . escapeshellarg($value);
     }
     foreach ($this->headers as $name => $value) {
         $execString .= " --custom-header " . escapeshellarg($name) . " " . escapeshellarg($value);
     }
     if ($this->cover) {
         $execString .= " cover " . escapeshellarg($this->cover);
     }
     $execString .= " {$url} {$tempFile}";
     $execOutput = array();
     $execResult = 0;
     exec($execString, $execOutput, $execResult);
     if ($execResult != 0 && $execResult != 2) {
         // code 2 is for 404's encountered
         @unlink($tempFile);
         return ar_error::raiseError("wkhtmltopdf: error ({$execResult}) while trying to generate PDF: " . implode("\n", (array) $execOutput), 203);
     }
     readfile($tempFile);
     unlink($tempFile);
 }
Exemple #5
0
 public static function _raiseError($message, $error)
 {
     return ar_error::raiseError($message, $error);
 }
Exemple #6
0
 public static function friendlyDate($date, $nls = null, $now = null)
 {
     if (!$nls) {
         $nls = array('lastyear' => 'last year', 'yearsago' => '%d years ago', 'lastmonth' => 'last month', 'monthsago' => '%d months ago', 'lastweek' => 'last week', 'weeksago' => '%d weeks ago', 'yesterday' => 'yesterday', 'daysago' => '%d days ago', 'hourago' => '1 hour ago', 'hoursago' => '%d hours ago', 'minuteago' => '1 minute ago', 'minutesago' => '%d minutes ago', 'justnow' => 'just now');
     }
     if (!isset($now)) {
         $now = time();
     }
     if (is_string($date)) {
         $date = strtotime($date, $now);
     }
     if (is_string($now)) {
         $now = strtotime($now);
     }
     if (is_int($date) && is_int($now)) {
         $interval = getdate($now - $date);
         if ($interval['year'] > 1971) {
             return sprintf($nls['yearsago'], $interval['year'] - 1970);
         } else {
             if ($interval['year'] > 1970 || $interval['mon'] > 11) {
                 return $nls['lastyear'];
             } else {
                 if ($interval['mon'] > 2) {
                     return sprintf($nls['monthsago'], $interval['mon']);
                 } else {
                     if ($interval['mon'] > 1) {
                         return $nls['lastmonth'];
                     } else {
                         if ($interval['mday'] > 2) {
                             return sprintf($nls['daysago'], $interval['mday']);
                         } else {
                             if ($interval['mday'] > 1) {
                                 return $nls['yesterday'];
                             } else {
                                 if ($interval['hours'] > 2) {
                                     return sprintf($nls['hoursago'], $interval['hours']);
                                 } else {
                                     if ($interval['hours'] > 1) {
                                         return $nls['hourago'];
                                     } else {
                                         if ($interval['minutes'] > 1) {
                                             return sprintf($nls['minutesago'], $interval['minutes']);
                                         } else {
                                             if ($interval['minutes'] > 0) {
                                                 return $nls['minuteago'];
                                             } else {
                                                 return $nls['justnow'];
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         return ar_error::raiseError('Illegal date argument', ar_exceptions::ILLEGAL_ARGUMENT);
     }
 }
Exemple #7
0
 public static function parse($xml, $encoding = null)
 {
     // important: parse must never return results with simple string values, but must always
     // wrap them in an ar_xmlNode, or tryToParse may get called, which will call parse, which
     // will... etc.
     $dom = new DOMDocument();
     if ($encoding) {
         $xml = '<?xml encoding="' . $encoding . '">' . $xml;
     }
     $prevErrorSetting = libxml_use_internal_errors(true);
     if ($dom->loadXML($xml)) {
         if ($encoding) {
             foreach ($dom->childNodes as $item) {
                 if ($item->nodeType == XML_PI_NODE) {
                     $dom->removeChild($item);
                     break;
                 }
             }
             $dom->encoding = $encoding;
         }
         $domroot = $dom->documentElement;
         if ($domroot) {
             $result = self::parseHead($dom);
             $root = self::el($domroot->tagName, self::parseAttributes($domroot), self::parseChildren($domroot));
             $s = simplexml_import_dom($dom);
             $n = $s->getDocNamespaces();
             foreach ($n as $prefix => $ns) {
                 if ($prefix) {
                     $prefix = ':' . $prefix;
                 }
                 $root->setAttribute('xmlns' . $prefix, $ns);
             }
             $result[] = $root;
             return $result;
         }
     }
     $errors = libxml_get_errors();
     libxml_clear_errors();
     libxml_use_internal_errors($prevErrorSetting);
     return ar_error::raiseError('Incorrect xml passed', ar_exceptions::ILLEGAL_ARGUMENT, $errors);
 }
Exemple #8
0
 public static function error($message, $code, $previous = null)
 {
     return ar_error::raiseError($message, $code, $previous);
 }
Exemple #9
0
 public function __call($function, $args)
 {
     if ($function[0] === '_') {
         // variable called as a function
         $function = substr($function, 1);
         if (isset($this->{$function}) && $this->{$function} instanceof \Closure) {
             return call_user_func_array($this->{$function}, $args);
         } else {
             return ar_error::raiseError("Function is not a closure", 500);
         }
     } else {
         //function not in whitelist
         switch ($function) {
             // first arg must be a closure
             case 'array_map':
                 if ($this->isSafeCallable($args[0])) {
                     return call_user_func_array($function, $args);
                 }
                 break;
                 // second arg must be a closure
             // second arg must be a closure
             case 'array_filter':
             case 'array_reduce':
             case 'preg_replace_callback':
                 if ($this->isSafeCallable($args[1])) {
                     return call_user_func_array($function, $args);
                 }
                 break;
                 // last arg must be a closure
             // last arg must be a closure
             case 'array_diff_uassoc':
             case 'array_diff_ukey':
             case 'array_intersect_uassoc':
             case 'array_intersect_ukey':
             case 'array_udiff':
             case 'array_udiff_assoc':
                 $l = count($args);
                 if ($this->isSafeCallable($args[$l - 1])) {
                     return call_user_func_array($function, $args);
                 }
                 break;
                 // last two args must be a closure
             // last two args must be a closure
             case 'array_udiff_uassoc':
             case 'array_uintersect_uassoc':
                 $l = count($args);
                 if ($this->isSafeCallable($args[$l - 1]) && $this->isSafeCallable($args[$l - 2])) {
                     return call_user_func_array($function, $args);
                 }
                 break;
         }
         $function = '_' . $function;
         if (is_callable([$this->this, $function])) {
             return call_user_func_array([$this->this, $function], $args);
         }
         return ar_error::raiseError("Function is not a method", 500);
     }
 }
Exemple #10
0
 public function exifToLatLong($exif)
 {
     if ($exif['GPS'] && is_array($exif['GPS']['GPSLatitude']) && is_array($exif['GPS']['GPSLongitude'])) {
         $lat_degree = (double) self::parseNumber($exif["GPS"]["GPSLatitude"][0]);
         $lat_mins = (double) self::parseNumber($exif["GPS"]["GPSLatitude"][1]);
         $lat_secs = (double) self::parseNumber($exif["GPS"]["GPSLatitude"][2]);
         $result = array();
         $result['lat'] = $lat_degree + $lat_mins / 60 + $lat_secs / 3600;
         if ($exif['GPS']['GPSLatitudeRef'] == 'S') {
             $result['lat'] = -1 * $result['lat'];
         }
         $lng_degree = (double) self::parseNumber($exif["GPS"]["GPSLongitude"][0]);
         $lng_mins = (double) self::parseNumber($exif["GPS"]["GPSLongitude"][1]);
         $lng_secs = (double) self::parseNumber($exif["GPS"]["GPSLongitude"][2]);
         $result['lng'] = $lng_degree + $lng_mins / 60 + $lng_secs / 3600;
         if ($exif['GPS']['GPSLongitudeRef'] == 'W') {
             $result['lng'] = -1 * $result['lng'];
         }
         return $result;
     } else {
         return ar_error::raiseError('MOD_GEO: No EXIF GPS block given', 'geo_6');
     }
 }
Exemple #11
0
 public static function temp($contents = null)
 {
     list($ob, $fstore) = static::getStore();
     $tmpsrc = tempnam($ob->store->get_config("files") . "temp", "tmp");
     if (!$tmpsrc) {
         // FIXME: nlsstrings
         return ar_error::raiseError('Could not create temp file', 501);
     }
     $fp = fopen($tmpsrc, 'w+');
     if (is_resource($fp)) {
         $res = new ar_content_filesFile($fp);
         if ($contents instanceof ar_content_filesFile) {
             // FIXME: create an more efficient way for copying with a stream_copy_to_stream call or wrapping t in an CopyFrom/CopyTo api
             // or even an temp function on a ar_content_filesFile object which creates an temp file from the ar_content_filesFile
             $contents = $contents->getContents();
             fwrite($fp, $contents);
             rewind($fp);
         } else {
             if (is_resource($contents) && get_resource_type($contents) === 'stream') {
                 stream_copy_to_stream($contents, $fp);
                 rewind($fp);
             } else {
                 if (isset($contents)) {
                     fwrite($fp, $contents);
                     rewind($fp);
                 }
             }
         }
         return $res;
     } else {
         // FIXME: nlsstrings
         return ar_error::raiseError('Could not create temp file', 502);
     }
 }
Exemple #12
0
 public function quoteValues($values, $settings = array())
 {
     $settings = array_merge($this->settings, $settings);
     if (!is_array($values)) {
         return ar_error::raiseError('mod_csv: quoteValues: values argument is not an array', 2);
     }
     $result = '';
     if ($settings['keySelection']) {
         foreach ($settings['keySelection'] as $key) {
             $result .= $this->quoteValue($values[$key], $settings) . $settings['seperator'];
         }
     } else {
         foreach ($values as $value) {
             $result .= $this->quoteValue($value, $settings) . $settings['seperator'];
         }
     }
     $result = substr($result, 0, -strlen($settings['seperator'])) . $settings['lineEnd'];
     return $result;
 }
Exemple #13
0
 public function call($method, $args = array())
 {
     if (is_string($method)) {
         $method = ar_pinp::getCallback($method, array_keys($args));
     }
     if (!$method instanceof \Closure) {
         return ar_error::raiseError('Illegal event listener method', 500);
     }
     return ar_events::addListener($this->path, $this->eventName, $this->objectType, $method, $args, $this->capture, $this->filters);
 }