/*
get the boleto pdf url from order
499836
public function getUrlBoletoPDF()
    {
        $result = "";

        // if isBoletoPayment is not called first load the order
        if ($this->order == null) {
            $this->order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
        }

        if ($this->order->getPayment()->getMethod() == "adyen_boleto") {
            $result = $this->order->getAdyenBoletoPdf();
        }

        return $result;
    }
488438
function (pdf_file, cb) {
            var quality = 300;
            if (options.hasOwnProperty('quality') && options.quality) {
              quality = options.quality;
            }
            convert(pdf_file.file_path, quality, function (err, tif_path) {
              var zeroBasedNumPages = num_pages-1;
              self.emit('log', 'converted page to intermediate tiff file, page '+ index+ ' (0-based indexing) of '+ zeroBasedNumPages);
              if (err) { return cb(err); }
              var ocr_flags = [
                '-psm 6'
              ];
              if (options.ocr_flags) {
                ocr_flags = options.ocr_flags;
              }
              ocr(tif_path, ocr_flags, function (err, extract) {
                fs.unlink(tif_path, function (tif_cleanup_err, reply) {
                  if (tif_cleanup_err) {
                    err += ', error removing temporary tif file: "'+tif_cleanup_err+'"';
                  }
                  if (err) { return cb(err); }
                  var page_number = index+1
                  self.emit('log', 'raw ocr: page ' + index + ' (0-based indexing) of ' +zeroBasedNumPages + ' complete');
                  single_page_pdf_file_paths.push(pdf_file.file_path);
                  self.emit('page', { hash: hash, text: extract, index: index, num_pages: num_pages, pdf_path: pdf_path, single_page_pdf_path: pdf_file.file_path});
                  text_pages.push(extract);
                  index++;
                  cb();
                });
              });
            });
          }
227622
public function url($url, $title, $order = 0, $attributes = array())
    {
        if (func_num_args() == 3) {
            $arguments = func_get_args();

            return $this->add([
                'url' => $this->formatUrl(array_get($arguments, 0)),
                'title' => array_get($arguments, 1),
                'attributes' => array_get($arguments, 2)
            ]);
        }

        $url = $this->formatUrl($url);
        
        $item = MenuItem::make(compact('url', 'title', 'order', 'attributes'));

        $this->items[] = $item;

        return $item;
    }
1142440
function getDownloadUrl() {
		$inputs = self::remoteXpathQuery($this->videoUrl, '/html/body/div[3]/div[2]/div[2]/div[7]/form/input[@name]');
		
		$postFields = [];
		foreach ($inputs as $input) {
			$postFields[$input->getAttribute('name')] = $input->getAttribute('value');
		}
		
		sleep(11);	//10 sek wait-time is required
		$scriptElements = self::remoteXpathQuery($this->videoUrl, '/html/body/div[3]/div[2]/div[2]/div[1]/script[3]', $postFields);
		
		$textContent = $scriptElements->item(0)->textContent;
		preg_match('/file: ".*\..*"/U', $textContent, $matches);
		$url = substr(reset($matches), 6);
		return trim($url, '"');
	}
65171
protected function _getSortUrl($field = '')
    {
        $url = $this->_getFilterUrl();

        if ($field === '' && empty($this->activeSort)) {
            return $url;
        }

        if (!isset($url['?'])) {
            $url['?'] = [];
        }

        if ($field !== '') {
            $url['?']['s'] = $field;
            $dir = 'asc';
            if (isset($this->activeSort[$field])) {
                if ($this->activeSort[$field] === 'asc') {
                    $url['?']['d'] = 'desc';
                    $dir = 'desc';
                }
            }
            if ($field === $this->defaultSort['field'] && $dir === $this->defaultSort['dir']) {
                unset($url['?']['s']);
                if (isset($url['?']['d'])) {
                    unset($url['?']['d']);
                }
            }

            return $url;
        }

        if (!empty($this->activeSort)) {
            $field = array_keys($this->activeSort)[0];
            $dir = $this->activeSort[$field];
            if (($field === $this->defaultSort['field'] && $dir !== $this->defaultSort['dir']) ||
                $field !== $this->defaultSort['field']
            ) {
                $url['?']['s'] = $field;
                if ($this->activeSort[$field] !== 'asc') {
                    $url['?']['d'] = 'desc';
                }
            }
        }

        return $url;
    }
1173604
public function getBoleto()
    {
        if (isset($this->data['object']) && 'transaction' === $this->data['object']) {
            if ( $this->data['boleto_url'] ) {
                $data = array(
                    'boleto_url' => $this->data['boleto_url'], 
                    'boleto_barcode' => $this->data['boleto_barcode'],
                    'boleto_expiration_date' => $this->data['boleto_expiration_date'],
                );
                return $data;
            } else {
                return null;
            }
        }
        
        return null;
    }
112085
public function getDocument($attributes = [], $onlyUrl = false, $modelSlug = null, $relation = null)
    {
        $this->setAttributes($modelSlug,'file');
        $file = $this->getFile();

        if (is_null($file)) {
            return '';
        }
        $src = $this->getFileDownloadSrc($file, $relation);
        $attr = $this->getHTMLAttributes($attributes);
        return $onlyUrl ? asset($src) : '<a href="'.asset($src).'" '.$attr.'> ' . $file . '</a>';
    }
148553
public function sortByUrl()
    {
        $params = $_GET;
        $isDesc = isset($params['sort_order']) && $params['sort_order'] != 'asc';
        if ($this->isCurrentSortField() && $isDesc) {
            $params['sort_order'] = 'asc';
        } else {
            $params['sort_order'] = 'desc';
        }
        $params['order_by'] = $this->field;

        return url()->current().'?'.http_build_query($params);
    }
197569
public function getOrdered()
    {
        if (!$this->sort) {
            return $this->content;
        }

        $unordered = [];
        foreach ($this->content as $content) {
            $unordered[$content->getId()] = $content;
        }

        $ordered = [];
        $sort = json_decode($this->sort, true);
        $order = $sort['order'];
        foreach ($order as $id) {
            if (isset($unordered[$id])) {
                $ordered[] = $unordered[$id];
            }
        }

        return $ordered;
    }
803496
public function getPageUrl($page=NULL) {
	
		// save current order val
		$tmp = $this->page;
	
		// build url with order value in param
		$this->page = (int)$page;
		$url = $this->getUrl();
		$this->page = $tmp;
	
		return $url;
	
	}
881997
function igets($fid=0,$order = 'id')
	{
		$gets['fid'] = $fid;
		$gets['order'] = $order;
		return $this->gets($gets);
	}
564553
function stream($filename = "document.pdf", $options = array())
    {
        if (headers_sent()) {
            die("Unable to stream pdf: headers already sent");
        }

        if (!isset($options["compress"])) $options["compress"] = true;
        if (!isset($options["Attachment"])) $options["Attachment"] = true;

        $debug = !$options['compress'];
        $tmp = ltrim($this->output($debug));

        header("Cache-Control: private");
        header("Content-Type: application/pdf");
        header("Content-Length: " . mb_strlen($tmp, "8bit"));

        $filename = str_replace(array("\n", "'"), "", basename($filename, ".pdf")) . ".pdf";
        $attachment = $options["Attachment"] ? "attachment" : "inline";

        $encoding = mb_detect_encoding($filename);
        $fallbackfilename = mb_convert_encoding($filename, "ISO-8859-1", $encoding);
        $fallbackfilename = str_replace("\"", "", $fallbackfilename);
        $encodedfilename = rawurlencode($filename);

        $contentDisposition = "Content-Disposition: $attachment; filename=\"$fallbackfilename\"";
        if ($fallbackfilename !== $filename) {
            $contentDisposition .= "; filename*=UTF-8''$encodedfilename";
        }
        header($contentDisposition);

        echo $tmp;
        flush();
    }
917383
public function toResource()
    {
        $protocol = $this->collection->database->connection->registerFileStreamWrapper();

        $context = stream_context_create([
            $protocol => [
                'download' => $this,
            ]
        ]);

        $document = $this->getDocument();
        $url = "{$protocol}://{$this->collection->database->name}.{$this->collection->prefix}?_id={$document['_id']}";
        return fopen($url, 'r', false, $context);
    }
1169901
function getdata($page = 1, $length = 10, $ano = false, $mes = false, $dia = false)
    {
        
        $dt = [];
        $where = '';
        
        if ($ano !== false) {
            $where .= ' AND YEAR(data) = :ano ';
            $dt[':ano'] = $ano;
        }
        
        if ($mes !== false) {
            $where .= ' AND MONTH(data) = :mes ';
            $dt[':mes'] = $mes;
        }

        if ($dia !== false) {
            $where .= ' AND DAY(data) = :dia ';
            $dt[':dia'] = $dia;
        }

        //Calculando a página
        $data = $this->calculate($page, $length,
                                'SELECT id								 
								 FROM access								 
								 WHERE (uri LIKE "/a/%" 
								 OR uri = "/")
								 '.$where.'								 
								 GROUP BY uri, MONTH(data), DAY(data)', $dt);

        return $this->execute($data,
                                'SELECT data, COUNT(id)qt, uri AS Link 
								 FROM access
     							 WHERE (uri LIKE "/a/%" 
								 OR uri = "/")
								 '.$where.'
								 GROUP BY uri, MONTH(data), DAY(data)
								 ORDER BY DAY(data), uri
								 LIMIT '.$data['init'].', '.$data['length'], $dt);
    }
853074
function (ordered) {
    var self = this;
    if (ordered) {
      return self.fetch();
    } else {
      var results = new LocalCollection._IdMap;
      self.forEach(function (doc) {
        results.set(doc._id, doc);
      });
      return results;
    }
  }
341986
public static function get_request_document() {
        $uri = $_SERVER['REQUEST_URI'];     // /tsugi/lti/some/cool/stuff
        $pieces = explode('/',$uri);
        if ( count($pieces) > 1 ) {
            $local_path = $pieces[count($pieces)-1];
            $pos = strpos($local_path,'?');
            if ( $pos > 0 ) $local_path = substr($local_path,0,$pos);
            return $local_path;
        }
        return false;
    }
292822
public function URLToPDF($url, GrabzItPDFOptions $options = null)
	{
		if ($options == null)
		{
			$options = new GrabzItPDFOptions();			
		}		

		$this->request = new GrabzItRequest($this->getRootUrl(false) . GrabzItClient::TakePDF, false, $options, $url);
	}