Ejemplo 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;
}
Ejemplo n.º 2
0
/**
 * Renders a partial view
 *
 * <code>
 * 	//Show a partial inside another view
 * 	$this->partial('shared/footer');
 * </code>
 *
 * <code>
 * 	//Show a partial inside another view with parameters
 * 	$this->partial('shared/footer', array('content' => $html));
 * </code>
 *
 * @param string $partialPath
 * @param array $params
 */
PHP_METHOD(Phalcon_Mvc_View_Simple, partial){

	zval *partial_path, *params = NULL, *view_params = NULL, *merged_params = NULL;
	zval *content;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &partial_path, &params);
	
	if (!params) {
		PHALCON_INIT_VAR(params);
	}
	
	/** 
	 * Start ouput buffering
	 */
	phalcon_ob_start(TSRMLS_C);
	
	/** 
	 * If the developer pass an array of variables we create a new virtual symbol table
	 */
	if (Z_TYPE_P(params) == IS_ARRAY) { 
	
		PHALCON_OBS_VAR(view_params);
		phalcon_read_property_this(&view_params, this_ptr, SL("_viewParams"), PH_NOISY_CC);
	
		/** 
		 * Merge or assign the new params as parameters
		 */
		if (Z_TYPE_P(view_params) == IS_ARRAY) { 
			PHALCON_INIT_VAR(merged_params);
			phalcon_fast_array_merge(merged_params, &view_params, &params TSRMLS_CC);
		} else {
			PHALCON_CPY_WRT(merged_params, params);
		}
	
		/** 
		 * Create a virtual symbol table
		 */
		phalcon_create_symbol_table(TSRMLS_C);
	
	} else {
		PHALCON_CPY_WRT(merged_params, params);
	}
	
	/** 
	 * Call engine render, this checks in every registered engine for the partial
	 */
	phalcon_call_method_p2_noret(this_ptr, "_internalrender", partial_path, merged_params);
	
	/** 
	 * Now we need to restore the original view parameters
	 */
	if (view_params != NULL) {
		/** 
		 * Restore the original view params
		 */
		phalcon_update_property_this(this_ptr, SL("_viewParams"), view_params TSRMLS_CC);
	}
	
	phalcon_ob_end_clean(TSRMLS_C);
	
	PHALCON_OBS_VAR(content);
	phalcon_read_property_this(&content, this_ptr, SL("_content"), PH_NOISY_CC);
	
	/** 
	 * Content is output to the parent view
	 */
	zend_print_zval(content, 0);
	
	PHALCON_MM_RESTORE();
}
Ejemplo n.º 3
0
/**
 * Renders a view
 *
 * @param string $path
 * @param array $params
 * @return string
 */
PHP_METHOD(Phalcon_Mvc_View_Simple, render){

	zval *path, *params = NULL, *cache, *is_started = NULL, *key = NULL, *lifetime = NULL;
	zval *cache_options, *content = NULL, *view_params;
	zval *merged_params = NULL, *is_fresh;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &path, &params);
	
	if (!params) {
		PHALCON_INIT_VAR(params);
	}
	
	/** 
	 * Create/Get a cache
	 */
	PHALCON_INIT_VAR(cache);
	phalcon_call_method(cache, this_ptr, "getcache");
	if (Z_TYPE_P(cache) == IS_OBJECT) {
	
		/** 
		 * Check if the cache is started, the first time a cache is started we start the
		 * cache
		 */
		PHALCON_INIT_VAR(is_started);
		phalcon_call_method(is_started, cache, "isstarted");
		if (PHALCON_IS_FALSE(is_started)) {
	
			PHALCON_INIT_VAR(key);
	
			PHALCON_INIT_VAR(lifetime);
	
			PHALCON_OBS_VAR(cache_options);
			phalcon_read_property_this(&cache_options, this_ptr, SL("_cacheOptions"), PH_NOISY_CC);
	
			/** 
			 * Check if the user has defined a different options to the default
			 */
			if (Z_TYPE_P(cache_options) == IS_ARRAY) { 
				if (phalcon_array_isset_string(cache_options, SS("key"))) {
					PHALCON_OBS_NVAR(key);
					phalcon_array_fetch_string(&key, cache_options, SL("key"), PH_NOISY);
				}
				if (phalcon_array_isset_string(cache_options, SS("lifetime"))) {
					PHALCON_OBS_NVAR(lifetime);
					phalcon_array_fetch_string(&lifetime, cache_options, SL("lifetime"), PH_NOISY);
				}
			}
	
			/** 
			 * If a cache key is not set we create one using a md5
			 */
			if (Z_TYPE_P(key) == IS_NULL) {
				PHALCON_INIT_NVAR(key);
				phalcon_md5(key, path);
			}
	
			/** 
			 * We start the cache using the key set
			 */
			PHALCON_INIT_VAR(content);
			phalcon_call_method_p2(content, cache, "start", key, lifetime);
			if (Z_TYPE_P(content) != IS_NULL) {
				phalcon_update_property_this(this_ptr, SL("_content"), content TSRMLS_CC);
				RETURN_CCTOR(content);
			}
		}
	}
	
	/** 
	 * Create a virtual symbol table
	 */
	phalcon_create_symbol_table(TSRMLS_C);
	
	phalcon_ob_start(TSRMLS_C);
	
	PHALCON_OBS_VAR(view_params);
	phalcon_read_property_this(&view_params, this_ptr, SL("_viewParams"), PH_NOISY_CC);
	
	/** 
	 * Merge parameters
	 */
	if (Z_TYPE_P(params) == IS_ARRAY) { 
		if (Z_TYPE_P(view_params) == IS_ARRAY) { 
			PHALCON_INIT_VAR(merged_params);
			phalcon_fast_array_merge(merged_params, &view_params, &params TSRMLS_CC);
		} else {
			PHALCON_CPY_WRT(merged_params, params);
		}
	} else {
		PHALCON_CPY_WRT(merged_params, view_params);
	}
	
	/** 
	 * internalRender is also reused by partials
	 */
	phalcon_call_method_p2_noret(this_ptr, "_internalrender", path, merged_params);
	
	/** 
	 * Store the data in output into the cache
	 */
	if (Z_TYPE_P(cache) == IS_OBJECT) {
	
		PHALCON_INIT_NVAR(is_started);
		phalcon_call_method(is_started, cache, "isstarted");
		if (PHALCON_IS_TRUE(is_started)) {
	
			PHALCON_INIT_VAR(is_fresh);
			phalcon_call_method(is_fresh, cache, "isfresh");
			if (PHALCON_IS_TRUE(is_fresh)) {
				phalcon_call_method_noret(cache, "save");
			} else {
				phalcon_call_method_noret(cache, "stop");
			}
		} else {
			phalcon_call_method_noret(cache, "stop");
		}
	}
	
	phalcon_ob_end_clean(TSRMLS_C);
	
	PHALCON_OBS_NVAR(content);
	phalcon_read_property_this(&content, this_ptr, SL("_content"), PH_NOISY_CC);
	
	RETURN_CCTOR(content);
}
Ejemplo n.º 4
0
/**
 * Starts output frontend
 */
PHP_METHOD(Phalcon_Cache_Frontend_Output, start){

	phalcon_update_property_bool(getThis(), SL("_buffering"), 1);
	phalcon_ob_start();
}