Example #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());
     }
 }
Example #2
0
File: rss.php Project: poef/ariadne
 public function get($url, $request = null, $options = array())
 {
     $xml = $this->httpClient->get($url, $request, $options);
     if ($xml && !ar_error::isError($xml)) {
         return $this->parse($xml);
     } else {
         return $xml;
     }
 }
Example #3
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;
 }
Example #4
0
 public function testSaveAndGet()
 {
     global $AR;
     $me = $this;
     ar::context()->callAtPath(TESTBASE . 'file-nls/', function () use($me) {
         $content = "file contents";
         $result = ar_store_files::save('test', $content, 'nl');
         $me->assertEquals($result, strlen($content));
         $result = ar_store_files::get('test', 'nl');
         if (!ar_error::isError($result)) {
             $result = $result->getContents();
         }
         $me->assertEquals($content, $result);
     });
 }
Example #5
0
File: ftp.php Project: poef/ariadne
 public static function put($url, $contents, $options = array())
 {
     $path = parse_url($url, PHP_URL_PATH);
     if ($path !== false) {
         $fileName = basename($path);
         $client = new ar_connect_ftpClient($url, $options);
         if (!ar_error::isError($client)) {
             return $client->put($contents, $fileName);
         } else {
             return $client;
         }
     } else {
         return ar::error("Could not parse url " . (string) $url, 11);
     }
 }
Example #6
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());
     }
 }
Example #7
0
 public static function http($options, $ariadne = null, $session = null, $nls = null)
 {
     ar_error::$throwExceptions = true;
     if (!isset($ariadne)) {
         $ariadne = ar_core_ariadne::create($options['AR']);
     }
     if (!isset($session)) {
         if (!isset($options['session']['hideSessionIDFromURL'])) {
             $options['session']['hideSessionIDFromURL'] = $options['AR']->hideSessionIDFromURL;
         }
         $session = new ar_core_session($options['session']);
     }
     if (!isset($nls)) {
         $nlsOptions = $options['AR']->nls;
         $nlsOptions->root = $options['AR']->dir->install . 'lib/nls/';
         $nls = new ar_core_nls($nlsOptions);
     }
     return new ar_core_loader_http($options, $ariadne, $session, $nls);
 }
Example #8
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);
 }
Example #9
0
function importTemplate($cpath, $args)
{
    global $store, $axstore;
    $templatesrc = current($axstore->call('system.get.template.php', $args, $axstore->get($cpath)));
    $templatedst = current($store->call('system.get.template.php', $args, $store->get($cpath)));
    if (!$store->exists($cpath)) {
        // cannot install config on non-existing path
        print "{$cpath} doesn't exists, skipping\n";
    }
    if (!ar_error::isError($templatesrc)) {
        if (ar_error::isError($templatedst)) {
            // error means no template found
            // save template
            $args['template'] = $templatesrc;
            ar::get($cpath)->call('system.save.layout.phtml', $args);
        } else {
            print "Already a configfile defined on {$cpath}, please merge the following in your configfile " . $args['function'] . "\n";
            print $templatesrc . "\n";
        }
    } else {
        print "Error src template not found on {$cpath} \n";
    }
}
Example #10
0
 public static function tryToParse($html)
 {
     $result = $html;
     if (!$html instanceof ar_xmlNodeInterface) {
         // ar_xmlNodeInterface is correct, there is no ar_htmlNodeInterface
         if ($html && strpos($html, '<') !== false) {
             try {
                 $result = self::parse($html, 'UTF-8');
                 if (ar_error::isError($result)) {
                     $result = new ar_htmlNode((string) $html);
                 } else {
                     $check = trim($html);
                     /*
                     	DOMDocument::loadHTML always generates a full html document
                     	so the next bit of magic tries to remove the added elements
                     */
                     if (stripos($check, '<p') === 0) {
                         $result = $result->html->body[0]->childNodes;
                     } else {
                         $result = $result->html->body[0];
                         if ($result->firstChild->tagName == 'p') {
                             $result = $result->firstChild;
                         }
                         $result = $result->childNodes;
                     }
                 }
             } catch (Exception $e) {
                 $result = new ar_htmlNode((string) $html);
             }
         } else {
             $result = new ar_htmlNode((string) $html);
         }
     }
     return $result;
 }
Example #11
0
 public function post($path, $options = array())
 {
     $url = ar::url($this->rootURL . $path . '.json');
     $json = $this->client->post($url, $options);
     if ($json && !ar_error::isError($json)) {
         return json_decode($json);
     } else {
         return $json;
     }
 }
<?php

if ($this->CheckLogin("layout") && $this->CheckConfig()) {
    $args = array("type" => $this->getvar("newtype"), "function" => $this->getvar("newfunction"), "language" => $this->getvar("newlanguage"), "default" => $this->getvar("default"), "template" => $this->getvar("template"), "private" => $this->getvar("private"));
    if ($args['function'] == 'config.ini' && $this instanceof $args['type']) {
        $result = $this->call('system.template.test.phtml', $args);
        if (!$result) {
            $this->error = 'Unknown error in template ' . $args['function'];
        } else {
            if (ar_error::isError($result)) {
                $this->error = $result->getMessage();
            }
        }
    }
    if (!$this->error) {
        $this->call("system.save.layout.phtml", $args);
    }
    if (!$this->error) {
        $this->call("window.opener.objectadded.js");
        $formArgs = array();
    } else {
        $formArgs = array('error' => $this->error);
    }
    $this->call("dialog.templates.edit.form.php", $formArgs);
}
Example #13
0
         $deleted_templates[] = $item['name'];
         break;
     case "E":
         // existing template, no need for recompile
         break;
     case "Skipped":
     case "C":
         break;
         // Don't try to recompile conflicted templates
     // Don't try to recompile conflicted templates
     default:
         $updated_templates[] = $item['name'];
         break;
 }
 $props = $fstore->svn_get_ariadne_props($svn, $item['name']);
 if (ar_error::isError($props)) {
     echo "<span>" . $props->getMessage() . "</span>";
 } else {
     if ($item["filestate"] == "A") {
         echo "<span class='svn_addtemplateline'>Added " . $this->path . $props["ar:function"] . " (" . $props["ar:type"] . ") [" . $props["ar:language"] . "] " . ($props["ar:default"] == '1' ? $ARnls["default"] : "") . "</span>\n";
     } elseif ($item["filestate"] == "U") {
         // substr to work around bugs in SVN.php
         echo "<span class='svn_revisionline'>Updated " . $this->path . $props["ar:function"] . " (" . $props["ar:type"] . ") [" . $props["ar:language"] . "] " . ($props["ar:default"] == '1' ? $ARnls["default"] : "") . "</span>\n";
     } elseif ($item["filestate"] == "M" || $item["filestate"] == "G") {
         echo "<span class='svn_revisionline'>Merged " . $this->path . $props["ar:function"] . " (" . $props["ar:type"] . ") [" . $props["ar:language"] . "] " . ($props["ar:default"] == '1' ? $ARnls["default"] : "") . "</span>\n";
     } elseif ($item["filestate"] == "E") {
         echo "<span class='svn_revisionline'>Existing " . $this->path . $props["ar:function"] . " (" . $props["ar:type"] . ") [" . $props["ar:language"] . "] " . ($props["ar:default"] == '1' ? $ARnls["default"] : "") . "</span>\n";
     } elseif ($item["filestate"] == "C") {
         echo "<span class='svn_revisionline'>Conflict " . $this->path . $props["ar:function"] . " (" . $props["ar:type"] . ") [" . $props["ar:language"] . "] " . ($props["ar:default"] == '1' ? $ARnls["default"] : "") . "</span>\n";
     } elseif ($item["filestate"] == "D") {
         // system.svn.delete.templates.php will report that this template has been deleted
Example #14
0
File: xml.php Project: poef/ariadne
 public static function tryToParse($xml)
 {
     $result = $xml;
     if (!$xml instanceof ar_xmlNodeInterface) {
         if ($xml && strpos($xml, '<') !== false) {
             try {
                 $result = self::parse('<root>' . $xml . '</root>');
                 if (ar_error::isError($result)) {
                     $result = new ar_xmlNode((string) $xml);
                 } else {
                     $result = $result->firstChild->childNodes;
                 }
             } catch (Exception $e) {
                 $result = new ar_xmlNode((string) $xml);
             }
         } else {
             $result = new ar_xmlNode((string) $xml);
         }
     }
     return $result;
 }
Example #15
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;
 }
Example #16
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);
     }
 }
Example #17
0
 public function _init($config)
 {
     $geo = new pinp_geo();
     $result = $geo->init($config);
     if (!ar_error::isError($result)) {
         return $geo;
     } else {
         return $result;
     }
 }
Example #18
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);
     }
 }
Example #19
0
     $status .= "<span class='svndiff_headline'>" . htmlspecialchars($line) . "</span>\n";
     $line = $linebased[++$i];
     $firstspace = strpos($line, " ") + 1;
     $nextspace = strpos($line, "\t", $firstspace);
     $template = substr($line, $firstspace, $nextspace - $firstspace);
     $props = $fstore->svn_get_ariadne_props($svn, $template);
     if (!ar_error::isError($props) && count($props)) {
         $line = str_replace($template, $this->path . $props["ar:function"] . " (" . $props["ar:type"] . ") [" . $props["ar:language"] . "] " . ($props["ar:default"] == '1' ? $ARnls["default"] : ""), $line);
     }
     $status .= "<span class='svndiff_headline'>" . htmlspecialchars($line) . "</span>\n";
     $line = $linebased[++$i];
     $firstspace = strpos($line, " ") + 1;
     $nextspace = strpos($line, "\t", $firstspace);
     $template = substr($line, $firstspace, $nextspace - $firstspace);
     $props = $fstore->svn_get_ariadne_props($svn, $template);
     if (!ar_error::isError($props) && count($props)) {
         $line = str_replace($template, $this->path . $props["ar:function"] . " (" . $props["ar:type"] . ") [" . $props["ar:language"] . "] " . ($props["ar:default"] == '1' ? $ARnls["default"] : ""), $line);
     }
     $status .= "<span class='svndiff_headline'>" . htmlspecialchars($line) . "</span>\n";
     break;
 case "@":
     // @@
     $status .= "<span class='svndiff_offsetline'>" . htmlspecialchars($line) . "</span>\n";
     break;
 case "-":
     // --- file -diff
     $status .= "<span class='svndiff_removeline'>" . htmlspecialchars($line) . "</span>\n";
     break;
 case "+":
     // +++ file +diff
     $status .= "<span class='svndiff_addline'>" . htmlspecialchars($line) . "</span>\n";
Example #20
0
File: ar.php Project: poef/ariadne
 public static function configure($option, $value)
 {
     switch ($option) {
         case 'throwExceptions':
             self::$throwExceptions = $value;
             break;
     }
 }
Example #21
0
 public static function _isError($ob)
 {
     return ar_error::isError($ob);
 }
Example #22
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);
 }