Esempio n. 1
0
/**
 * Execute a render.
 *
 * @param string $type
 * @param int $quality
 * @return string
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, _render) {

	zval *extension, *quality = NULL, *interlacing = NULL, ret = {}, type = {}, mime = {}, image = {}, tmp = {};
	const char *func_name = "imagegif";
	char *ext;

	phalcon_fetch_params(0, 1, 2, &extension, &quality, &interlacing);

	phalcon_fast_strtolower(&ret, extension);

	ext = Z_STRVAL(ret);

	if (strcmp(ext, "gif") == 0) {
		ZVAL_LONG(&type, 1);
		func_name = "imagegif";
	} else if (strcmp(ext, "jpg") == 0 || strcmp(ext, "jpeg") == 0) {
		ZVAL_LONG(&type, 2);
		func_name = "imagejpeg";
	} else if (strcmp(ext, "png") == 0) {
		ZVAL_LONG(&type, 3);
		func_name = "imagepng";
	} else {
		zend_throw_exception_ex(phalcon_image_exception_ce, 0, "Installed GD does not support '%s' images", Z_STRVAL_P(extension));
		return;
	}

	phalcon_return_property(&image, getThis(), SL("_image"));

	if (interlacing && Z_TYPE_P(interlacing) >= IS_NULL && Z_LVAL(type) > 1) {
		if (zend_is_true(interlacing)) {
			PHALCON_CALL_FUNCTIONW(NULL, "imageinterlace", &image, &PHALCON_GLOBAL(z_one));
		} else {
			PHALCON_CALL_FUNCTIONW(NULL, "imageinterlace", &image, &PHALCON_GLOBAL(z_zero));
		}
	}
	phalcon_ob_start();

	if (Z_LVAL(type) == 1 || !quality || Z_TYPE_P(quality) == IS_NULL) {
		PHALCON_CALL_FUNCTIONW(&ret, func_name, &image);
	} else {
		if (Z_LVAL(type) == 3) {
			ZVAL_LONG(&tmp, ceil(Z_LVAL_P(quality)/100*9));
			PHALCON_CALL_FUNCTIONW(&ret, func_name, &image, &PHALCON_GLOBAL(z_null), &tmp);
		} else {
			PHALCON_CALL_FUNCTIONW(&ret, func_name, &image, &PHALCON_GLOBAL(z_null), quality);
		}
	}

	phalcon_ob_get_contents(return_value);
	phalcon_ob_end_clean();

	if (zend_is_true(&ret)) {
		phalcon_update_property_zval(getThis(), SL("_type"), &type);

		PHALCON_CALL_FUNCTIONW(&mime, "image_type_to_mime_type", &type);
		phalcon_update_property_zval(getThis(), SL("_mime"), &mime);
	}

	return;
}
Esempio n. 2
0
/**
 * Renders a view using the template engine
 *
 * @param string $path
 * @param array $params
 * @param boolean $mustClean
 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Php, render) {

    zval *path, *params, *must_clean = NULL, *value = NULL, *key = NULL, *contents;
    zval *view;
    HashTable *ah0;
    HashPosition hp0;
    zval **hd;

    PHALCON_MM_GROW();

    phalcon_fetch_params(1, 2, 1, &path, &params, &must_clean);

    if (!must_clean) {
        PHALCON_INIT_VAR(must_clean);
        ZVAL_BOOL(must_clean, 0);
    }

    if (PHALCON_IS_TRUE(must_clean)) {
        phalcon_ob_clean(TSRMLS_C);
    }

    /**
     * Create the variables in local symbol table
     */
    if (Z_TYPE_P(params) == IS_ARRAY) {

        phalcon_is_iterable(params, &ah0, &hp0, 0, 0);

        while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) {

            PHALCON_GET_HKEY(key, ah0, hp0);
            PHALCON_GET_HVALUE(value);

            if (phalcon_set_symbol(key, value TSRMLS_CC) == FAILURE) {
                return;
            }

            zend_hash_move_forward_ex(ah0, &hp0);
        }

    }

    /**
     * Require the file
     */
    if (phalcon_require(path TSRMLS_CC) == FAILURE) {
        return;
    }
    if (PHALCON_IS_TRUE(must_clean)) {
        PHALCON_INIT_VAR(contents);
        phalcon_ob_get_contents(contents TSRMLS_CC);

        PHALCON_OBS_VAR(view);
        phalcon_read_property_this(&view, this_ptr, SL("_view"), PH_NOISY_CC);
        phalcon_call_method_p1_noret(view, "setcontent", contents);
    }

    PHALCON_MM_RESTORE();
}
Esempio n. 3
0
/**
 * Returns output cached content
 *
 * @return string
 */
PHP_METHOD(Phalcon_Cache_Frontend_Output, getContent){

	zval *buffering;

	buffering = phalcon_read_property(getThis(), SL("_buffering"), PH_NOISY);
	if (zend_is_true(buffering)) {
		phalcon_ob_get_contents(return_value);
	}
}