category OSS
package OSS_Utils
copyright Copyright (c) 2007 - 2012, Open Source Solutions Limited, Dublin, Ireland
license New BSD License

 Methods

Converts a HTML file to PDF using htmldoc.

HtmlToPdf(string $html, string $pdf, bool $embedFonts) : bool
Static

Please note that the current stable version of htmldoc (v1.8.27) does not support CSS. Make sure PHP has write permission in the output directory. Also don't forget that relative paths are relative to the currently executing PHP script (include() and require() doesn't count in that). Using command line OpenOffice might be a better solution (a necessary macro and a tiny, one line shell script are available on the internet), as it supports everything in the HTML, CSS, images, etc, while the htmldoc 1.9.x is still in "developer snapshot" state.

Parameters

$html

string

the input HTML file name

$pdf

string

the output PDF file name

$embedFonts

bool

default false embed the used fonts to the genereated PDF or not - can save 100's of kBytes even in a plain PDF (think of email sending)

Returns

bool

A function to generate a URL with the given parameters.

genUrl(string | bool $controller, string | bool $action, string | bool $module, array $params, string $host) : string
Static

This is a useful function as no knowledge of the application's path is required.

It is also configurable (via Zend_Application config and assuming 'options' is available in Zend_Registry as it would be from OSS_Controller_Action).

You can configure the hostname by setting config: utils.genurl.host_mode

  • Default (no config / invalid config): ''$_SERVER['HTTP_HOST']''
  • ''HTTP_X_FORWARDED_HOST'': Use ''$_SERVER['HTTP_X_FORWARDED_HOST']''
  • ''REPLEACE'': set with value from utils.genurl.host_replace

Parameters

$controller

stringbool

default false The controller to call.

$action

stringbool

default false The action to call (controller must be set if setting action)

$module

stringbool

default false The module to use. Set to false to ignore.

$params

array

default array() An array of key value pairs to add to the URL.

$host

string

Defaults to null. Hostname (including http[s]://) to override url with

Returns

string

A generally available function to retrieve options from the application.ini, anywhere in the program.

getIniOption(string $option) : mixed
Static

Don't need to use this in the controllers, the $this->_options array is available there, this is useful in models, forms and other places.

todo : this method is rarely called, but a way to speed it up is to store the key and value in session, and then look for it when called

Parameters

$option

string

Returns

mixed

Returns with the resource object.

getResource(string $resource) : object
Static

Use if Zend_Registry::get() doesn't work. (And in the OSS framework it doesn't.)

Parameters

$resource

string

Returns

object

Returns with the temporary directory set in the application.ini, or if it is not set, then with the result of sys_get_temp_dir().

getTempDir() : string
Static
todo : this method is rarely called, but a way to speed it up is to store the path in session, and then look for it when called

Returns

string

Returns number with ordinal postfix.

ordinal(int $number) : string
Static

Parameters

$number

int

Returns

string

Parses an XML using SimpleXML and returns with the result object, or false on error.

parseXML(string $XML) : array | bool
Static

Parameters

$XML

string

Returns

arraybool

Creates a uniformly distributed directory path from given numeric id.

uniformDistHash(int $id, int $length) : string
Static

First it turn given id to hex. Then it appends new hex with leading zeros to reach given length ( 3 by default ) if necessary. And then new string is reversed. From reversed string function takes as many characters as defined in length.

e.g. uniformDistHash( 216 ) returns 8/d/0/216/ uniformDistHash( 7 ) returns 7/0/0/7/ uniformDistHash( 5057 ) returns 1/c/3/5057/

Parameters

$id

int

Id for making file structure

$length

int

How many levels should be created

Returns

string

Converts a HTML file to PDF using wkhtmltopdf

wkhtmltopdf(string $html, string $pdf) : bool
Static

Parameters

$html

string

the input HTML file name

$pdf

string

the output PDF file name

Returns

bool