Beispiel #1
0
/**
 * Returns the complete location where the joined/filtered collection must be written
 *
 * @param string $basePath
 * @return string
 */
PHP_METHOD(Phalcon_Assets_Collection, getRealTargetPath){

	zval *base_path = NULL, *target_path, complete_path = {};

	phalcon_fetch_params(0, 0, 1, &base_path);

	if (!base_path) {
		base_path = &PHALCON_GLOBAL(z_null);
	}

	target_path = phalcon_read_property(getThis(), SL("_targetPath"), PH_NOISY);

	/** 
	 * A base path for resources can be set in the assets manager
	 */
	PHALCON_CONCAT_VV(&complete_path, base_path, target_path);

	/** 
	 * Get the real template path, the target path can optionally don't exist
	 */
	if (phalcon_file_exists(&complete_path) == SUCCESS) {
		phalcon_file_realpath(return_value, &complete_path);
		return;
	}

	RETURN_CTORW(&complete_path);
}
Beispiel #2
0
/**
 * Phalcon\Image\GD constructor
 *
 * @param string $file
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, __construct){

	zval *file, *width = NULL, *height = NULL, exception_message = {}, checked = {}, realpath = {}, img_width = {}, img_height = {}, type = {}, mime = {}, format = {}, image = {}, imageinfo = {}, saveflag = {}, blendmode = {};

	phalcon_fetch_params(0, 1, 2, &file, &width, &height);

	if (Z_TYPE_P(file) != IS_STRING) {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_image_exception_ce, "file parameter should be a string");
		return;
	}

	phalcon_return_static_property_ce(&checked, phalcon_image_adapter_gd_ce, SL("_checked"));

	if (!zend_is_true(&checked)) {
		PHALCON_CALL_CE_STATICW(NULL, phalcon_image_adapter_gd_ce, "check");
	}

	phalcon_update_property_zval(getThis(), SL("_file"), file);

	if (phalcon_file_exists(file) != FAILURE) {
		phalcon_file_realpath(&realpath, file);
		if (unlikely(Z_TYPE(realpath) != IS_STRING)) {
			convert_to_string(&realpath);
		}

		phalcon_update_property_zval(getThis(), SL("_realpath"), &realpath);

		PHALCON_CALL_FUNCTIONW(&imageinfo, "getimagesize", &realpath);

		if (phalcon_array_isset_fetch_long(&img_width, &imageinfo, 0)) {
			phalcon_update_property_zval(getThis(), SL("_width"), &img_width);
		}

		if (phalcon_array_isset_fetch_long(&img_height, &imageinfo, 1)) {
			phalcon_update_property_zval(getThis(), SL("_height"), &img_height);
		}

		if (phalcon_array_isset_fetch_long(&type, &imageinfo, 2)) {
			convert_to_long(&type);
			phalcon_update_property_zval(getThis(), SL("_type"), &type);
		} else {
			ZVAL_LONG(&type, -1);
		}

		if (phalcon_array_isset_fetch_str(&mime, &imageinfo, SL("mime"))) {
			convert_to_string(&mime);
			phalcon_update_property_zval(getThis(), SL("_mime"), &mime);
		}

		assert(Z_TYPE(type) == IS_LONG);

		switch (Z_LVAL(type)) {
			case 1: // GIF
				ZVAL_STRING(&format, "gif");
				PHALCON_CALL_FUNCTIONW(&image, "imagecreatefromgif", &realpath);
				break;

			case 2: // JPEG
				ZVAL_STRING(&format, "jpg");
				PHALCON_CALL_FUNCTIONW(&image, "imagecreatefromjpeg", &realpath);
				break;

			case 3: // PNG
				ZVAL_STRING(&format, "png");
				PHALCON_CALL_FUNCTIONW(&image, "imagecreatefrompng", &realpath);
				break;

			default:
				if (PHALCON_IS_NOT_EMPTY(&mime)) {
					zend_throw_exception_ex(phalcon_image_exception_ce, 0, "Installed GD does not support '%s' images", Z_STRVAL(mime));
				} else {
					zend_throw_exception_ex(phalcon_image_exception_ce, 0, "Installed GD does not support such images");
				}
				return;
		}

		if (Z_TYPE(image) != IS_RESOURCE) {
			assert(Z_TYPE(realpath) == IS_STRING);
			zend_throw_exception_ex(phalcon_image_exception_ce, 0, "Failed to create image from file '%s'", Z_STRVAL(realpath));
			return;
		}

		phalcon_update_property_zval(getThis(), SL("_format"), &format);

		ZVAL_TRUE(&saveflag);

		PHALCON_CALL_FUNCTIONW(NULL, "imagesavealpha", &image, &saveflag);
	} else if (width && height) {
		PHALCON_CALL_FUNCTIONW(&image, "imagecreatetruecolor", width, height);

		if (Z_TYPE(image) != IS_RESOURCE) {
			PHALCON_THROW_EXCEPTION_STRW(phalcon_image_exception_ce, "imagecreatetruecolor() failed");
			return;
		}

		ZVAL_TRUE(&blendmode);
		ZVAL_TRUE(&saveflag);

		PHALCON_CALL_FUNCTIONW(NULL, "imagealphablending", &image, &blendmode);
		PHALCON_CALL_FUNCTIONW(NULL, "imagesavealpha", &image, &saveflag);

		phalcon_update_property_zval(getThis(), SL("_realpath"), file);
		phalcon_update_property_zval(getThis(), SL("_width"), width);
		phalcon_update_property_zval(getThis(), SL("_height"), height);

		ZVAL_LONG(&type, 3);

		phalcon_update_property_zval(getThis(), SL("_type"), &type);

		ZVAL_STRING(&format, "png");

		phalcon_update_property_zval(getThis(), SL("_format"), &format);

		ZVAL_STRING(&mime, "image/png");

		phalcon_update_property_zval(getThis(), SL("_mime"), &mime);
	} else {
		PHALCON_CONCAT_SVS(&exception_message, "Failed to create image from file '", file, "'");
		PHALCON_THROW_EXCEPTION_ZVALW(phalcon_image_exception_ce, &exception_message);
		return;
	}

	phalcon_update_property_zval(getThis(), SL("_image"), &image);
}