Exemplo n.º 1
0
/**
 * Fetch and parse a named template.
 *
 * @param string $name The name of the template.
 * @param array $vars An associative array of variables to pass to the template.
 *
 * @return string The parsed template output.
 */
function px_get_template($name, $vars = array())
{
    $path = PX_TEMPLATE_DIR . $name . '.php';
    if (!file_exists($path)) {
        $path = PX_COMMON_TEMPLATE_DIR . $name . '.php';
    }
    if (file_exists($path)) {
        ob_start();
        include $path;
        return ob_get_clean();
    } else {
        px_stop_message("Template {$name} not found!");
    }
}
Exemplo n.º 2
0
/**
 * Call the Buyat API.
 *
 * @param string $action The Buyat API function name.
 * @param string $api_key Affiliate's API key.
 * @param array $args An associative array of parameters to pass to the API function.
 * @param boolean $allow_errors Whether or not to pass the response back even if it was an error.
 *
 * @return array The API's response as an associative array.
 */
function px_api_call($action, $api_key, $args, $allow_errors = false)
{
    if (($response = px_perform_post(PX_API_HOST, PX_API_PATH, px_construct_api_request($action, $api_key, $args))) === false) {
        px_stop_message('Unable to contact API');
    }
    $response = unserialize($response);
    if (!is_array($response)) {
        px_stop_message('Invalid response from API');
    }
    if (!$allow_errors && array_key_exists('error_code', $response)) {
        if (array_key_exists('error_message', $response)) {
            px_stop_message("Error from API: {$response['error_message']}");
        } else {
            px_stop_message("Error code from API: {$response['error_code']}");
        }
    }
    return $response;
}
Exemplo n.º 3
0
error_reporting(E_ALL);
define('PX_BASE_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('PX_INCLUDE_DIR', PX_BASE_DIR . 'px-includes' . DIRECTORY_SEPARATOR);
require_once PX_INCLUDE_DIR . 'config.php';
require_once PX_INCLUDE_DIR . 'generic_functions.php';
require_once PX_INCLUDE_DIR . 'api_core.php';
require_once PX_INCLUDE_DIR . 'api_functions.php';
$px_prefs = px_get_preferences();
define('PX_SKIN', $px_prefs['skin_directory']);
define('PX_SKIN_DIR', PX_BASE_DIR . 'px-skins' . DIRECTORY_SEPARATOR . 'skins' . DIRECTORY_SEPARATOR . PX_SKIN . DIRECTORY_SEPARATOR);
define('PX_TEMPLATE_DIR', PX_SKIN_DIR . 'templates' . DIRECTORY_SEPARATOR);
define('PX_COMMON_SKIN_DIR', PX_BASE_DIR . 'px-skins' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR);
define('PX_COMMON_TEMPLATE_DIR', PX_BASE_DIR . 'px-skins' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR);
require_once PX_INCLUDE_DIR . 'skin_functions.php';
if (array_key_exists('error_message', $px_prefs)) {
    px_stop_message($px_prefs['error_message']);
}
if (!array_key_exists('page', $_REQUEST) || strpos('\\', $_REQUEST['page']) || strpos('/', $_REQUEST['page'])) {
    $page = 'main';
} else {
    $page = strtolower(trim($_REQUEST['page']));
}
if (file_exists(PX_SKIN_DIR . $page . '.php')) {
    include PX_SKIN_DIR . $page . '.php';
} else {
    if (file_exists(PX_COMMON_SKIN_DIR . $page . '.php')) {
        include PX_COMMON_SKIN_DIR . $page . '.php';
    } else {
        px_stop_message('Invalid page: ' . $page);
    }
}