Example #1
0
/**
 * Phalcon\Http\Uri constructor
 *
 * @param mixed $uri
 */
PHP_METHOD(Phalcon_Http_Uri, __construct)
{
	zval *uri = NULL, parts = {}, query = {}, params = {};

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

	if (!uri || PHALCON_IS_EMPTY(uri)) {
		phalcon_update_property_empty_array(getThis(), SL("_parts"));
	} else if (Z_TYPE_P(uri) == IS_STRING) {
		PHALCON_CALL_FUNCTIONW(&parts, "parse_url", uri);
		if (phalcon_array_isset_fetch_str(&query, &parts, SL("query"))) {
			ZVAL_MAKE_REF(&params);
			PHALCON_CALL_FUNCTIONW(NULL, "parse_str", &query, &params);
			ZVAL_UNREF(&params);
			phalcon_array_update_str(&parts, SL("query"), &params, PH_COPY);
		}

		phalcon_update_property_zval(getThis(), SL("_parts"), &parts);
	} else if (Z_TYPE_P(uri) == IS_ARRAY) {
		phalcon_update_property_zval(getThis(), SL("_parts"), uri);
	} else if (Z_TYPE_P(uri) == IS_OBJECT && Z_OBJCE_P(uri) == phalcon_http_uri_ce) {
		phalcon_return_property(&parts, uri, SL("_parts"));
		phalcon_update_property_zval(getThis(), SL("_parts"), &parts);
	} else {
		phalcon_update_property_empty_array(getThis(), SL("_parts"));
	}
}
Example #2
0
/**
 * Gets the ouput
 *
 * @return int
 */
PHP_METHOD(Phalcon_Binary_Writer, getContent){

	zval output = {}, position = {};

	phalcon_read_property(&output, getThis(), SL("_output"), PH_NOISY);
	phalcon_read_property(&position, getThis(), SL("_position"), PH_NOISY);

	PHALCON_CALL_FUNCTIONW(NULL, "rewind", &output);
	PHALCON_CALL_FUNCTIONW(return_value, "fread", &output, &position);
}
Example #3
0
/**
 * Execute a watermarking.
 *
 * @param Phalcon\Image\Adapter $watermark
 * @param int $offset_x
 * @param int $offset_y
 * @param int $opacity
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, _watermark) {

	zval *watermark, *offset_x = NULL, *offset_y = NULL, *opacity = NULL, op = {}, image = {}, overlay = {}, blob = {}, saveflag = {}, width = {}, height = {}, color = {}, tmp = {}, effect = {}, blendmode = {}, ret = {};
	int int_opacity;
	double num;

	phalcon_fetch_params(0, 4, 0, &watermark, &offset_x, &offset_y, &opacity);

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

	PHALCON_CALL_METHODW(&blob, watermark, "render");
	PHALCON_CALL_FUNCTIONW(&overlay, "imagecreatefromstring", &blob);

	ZVAL_TRUE(&saveflag);

	PHALCON_CALL_FUNCTIONW(NULL, "imagesavealpha", &overlay, &saveflag);
	PHALCON_CALL_FUNCTIONW(&width, "imagesx", &overlay);
	PHALCON_CALL_FUNCTIONW(&height, "imagesy", &overlay);

	int_opacity = Z_LVAL_P(opacity);
	if (int_opacity < 100) {
		num = (int_opacity * 127.0 / 100) - 127;

		if (num < 0) {
			num = -num;
		}

		int_opacity = (int)num;

		ZVAL_LONG(&op, int_opacity);
		ZVAL_LONG(&tmp, 127);

		PHALCON_CALL_FUNCTIONW(&color, "imagecolorallocatealpha", &overlay, &tmp, &tmp, &tmp, &op);

		if (!phalcon_get_constant(&effect, SL("IMG_EFFECT_OVERLAY"))) {
			return;
		}

		PHALCON_CALL_FUNCTIONW(NULL, "imagelayereffect", &overlay, &effect);

		ZVAL_LONG(&tmp, 0);

		PHALCON_CALL_FUNCTIONW(NULL, "imagefilledrectangle", &overlay, &tmp, &tmp, &width, &height, &color);
	}

	ZVAL_LONG(&blendmode, 1);
	PHALCON_CALL_FUNCTIONW(NULL, "imagealphablending", &image, &blendmode);

	ZVAL_LONG(&tmp, 0);

	PHALCON_CALL_FUNCTIONW(&ret, "imagecopy", &image, &overlay, offset_x, offset_y, &tmp, &tmp, &width, &height);

	RETVAL_BOOL(zend_is_true(&ret));
}
Example #4
0
/**
 * Load config file
 *
 * @param string $filePath
 */
PHP_METHOD(Phalcon_Config_Adapter_Yaml, read){

	zval *file_path, *absolute_path = NULL, config_dir_path = {}, *base_path = NULL, config = {};

	phalcon_fetch_params(0, 1, 1, &file_path, &absolute_path);
	PHALCON_ENSURE_IS_STRING(file_path);

	if (absolute_path == NULL) {
		absolute_path = &PHALCON_GLOBAL(z_false);
	}

	if (zend_is_true(absolute_path)) {
		PHALCON_CPY_WRT_CTOR(&config_dir_path, file_path);
	} else {
		base_path = phalcon_read_static_property_ce(phalcon_config_adapter_ce, SL("_basePath"));

		PHALCON_CONCAT_VV(&config_dir_path, base_path, file_path);
	}

	PHALCON_CALL_FUNCTIONW(&config, "yaml_parse_file", &config_dir_path);

	if (Z_TYPE(config) == IS_ARRAY) {
		PHALCON_CALL_METHODW(NULL, getThis(), "val", &config);
	}

	RETURN_THISW();
}
Example #5
0
/**
 * Phalcon\Logger\Adapter\Stream constructor
 *
 * @param string $name
 * @param array $options
 */
PHP_METHOD(Phalcon_Logger_Adapter_Stream, __construct){

	zval *name, *options = NULL, mode = {}, stream = {};

	phalcon_fetch_params(0, 1, 1, &name, &options);
	PHALCON_ENSURE_IS_STRING(name);

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

	if (phalcon_array_isset_fetch_str(&mode, options, SL("mode"))) {
		if (phalcon_memnstr_str(&mode, SL("r"))) {
			PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "Stream must be opened in append or write mode");
			return;
		}
	} else {
		ZVAL_STRING(&mode, "ab");
	}

	/** 
	 * We use 'fopen' to respect to open-basedir directive
	 */
	PHALCON_CALL_FUNCTIONW(&stream, "fopen", name, &mode);
	if (Z_TYPE(stream) != IS_RESOURCE) {
		zend_throw_exception_ex(phalcon_logger_exception_ce, 0, "Cannot open stream '%s'", Z_STRVAL_P(name));
	} else {
		phalcon_update_property_this(getThis(), SL("_stream"), &stream);
	}
}
Example #6
0
/**
 * Gets the column name in MySQL
 *
 * @param Phalcon\Db\ColumnInterface $column
 * @return string
 */
PHP_METHOD(Phalcon_Db_Dialect_Mysql, getColumnDefinition){

	zval *column, size = {}, column_type = {}, column_sql = {}, type_values = {}, slash = {}, *value, value_cslashes = {}, is_unsigned = {}, scale = {}, name = {};
	int c, i = 0;

	phalcon_fetch_params(0, 1, 0, &column);
	PHALCON_VERIFY_INTERFACE_EX(column, phalcon_db_columninterface_ce, phalcon_db_exception_ce, 0);

	PHALCON_CALL_METHODW(&size, column, "getsize");
	PHALCON_CALL_METHODW(&column_type, column, "gettype");

	if (Z_TYPE(column_type) == IS_STRING) {
		PHALCON_CPY_WRT(&column_sql, &column_type);
		PHALCON_CALL_METHODW(&type_values, column, "gettypevalues");
		if (PHALCON_IS_NOT_EMPTY(&type_values)) {
			ZVAL_STRING(&slash, "\"");
			if (Z_TYPE(type_values) == IS_ARRAY) {
				c = phalcon_fast_count_int(&type_values);
				phalcon_concat_self_str(&column_sql, SL("("));
				ZEND_HASH_FOREACH_VAL(Z_ARRVAL(type_values), value) {
					i++;
					PHALCON_CALL_FUNCTIONW(&value_cslashes, "addcslashes", value, &slash);
					if (i < c) {
						PHALCON_SCONCAT_SVS(&column_sql, "\"", &value_cslashes, "\", ");
					} else {
						PHALCON_SCONCAT_SVS(&column_sql, "\"", &value_cslashes, "\"");
					}
				} ZEND_HASH_FOREACH_END();
Example #7
0
/**
 * Write hex string to the current position in the file pointer
 * 
 * @return Phalcon\Binary\Writer
 */
PHP_METHOD(Phalcon_Binary_Writer, writeHexString){

	zval *str, *length = NULL, *low_nibble = NULL, len = {}, format = {}, result = {};

	phalcon_fetch_params(0, 1, 2, &str, &length, &low_nibble);

	if (length && Z_TYPE_P(length) != IS_NULL) {
		if (low_nibble && zend_is_true(low_nibble)) {
			PHALCON_CONCAT_SV(&format, "h", length);
		} else {
			PHALCON_CONCAT_SV(&format, "H", length);
		}
	} else {
		if (low_nibble && zend_is_true(low_nibble)) {
			ZVAL_STRING(&format, "h*");
		} else {
			ZVAL_STRING(&format, "H*");
		}
	}
	PHALCON_CALL_FUNCTIONW(&result, "pack", &format, str);

	ZVAL_LONG(&len, Z_STRLEN(result));

	PHALCON_CALL_METHODW(NULL, getThis(), "write", &result, &len);
	RETURN_THISW();
}
Example #8
0
/**
 * Decrement of a given key, by number $value
 * 
 * @param  string $keyName
 * @param  long $value
 * @return mixed
 */
PHP_METHOD(Phalcon_Cache_Backend_Apc, decrement){

	zval *key_name, *value = NULL, prefix = {}, prefixed_key = {}, cached_content = {};

	phalcon_fetch_params(0, 1, 1, &key_name, &value);

	if (!value || Z_TYPE_P(value) == IS_NULL) {
		value = &PHALCON_GLOBAL(z_one);
	} else {
		PHALCON_ENSURE_IS_LONG(value);
	}

	phalcon_read_property(&prefix, getThis(), SL("_prefix"), PH_NOISY);

	PHALCON_CONCAT_SVV(&prefixed_key, "_PHCA", &prefix, key_name);
	phalcon_update_property_zval(getThis(), SL("_lastKey"), &prefixed_key);

	if (SUCCESS == phalcon_function_exists_ex(SL("apc_dec"))) {
		PHALCON_RETURN_CALL_FUNCTIONW("apc_dec", &prefixed_key, value);
	} else {
		PHALCON_CALL_FUNCTIONW(&cached_content, "apc_fetch", &prefixed_key);

		if (Z_TYPE(cached_content) == IS_LONG) {
			phalcon_sub_function(return_value, &cached_content, value);
			PHALCON_CALL_METHODW(NULL, getThis(), "save", key_name, return_value);
		} else {
			RETURN_FALSE;
		}
	}
}
Example #9
0
/**
 * Starts the profile of a SQL sentence
 *
 * @param string $sqlStatement
 * @param $sqlVariables
 * @param $sqlBindTypes
 * @return Phalcon\Db\Profiler
 */
PHP_METHOD(Phalcon_Db_Profiler, startProfile){

	zval *sql_statement, *sql_variables = NULL, *sql_bindtypes = NULL, active_profile = {}, time = {};

	phalcon_fetch_params(0, 1, 2, &sql_statement, &sql_variables, &sql_bindtypes);

	object_init_ex(&active_profile, phalcon_db_profiler_item_ce);
	PHALCON_CALL_METHODW(NULL, &active_profile, "setsqlstatement", sql_statement);

	if (sql_variables) {
	    PHALCON_CALL_METHODW(NULL, &active_profile, "setsqlvariables", sql_variables);
	}

	if (sql_bindtypes) {
	    PHALCON_CALL_METHODW(NULL, &active_profile, "setsqlbindtypes", sql_bindtypes);
	}

	PHALCON_CALL_FUNCTIONW(&time, "microtime", &PHALCON_GLOBAL(z_true));
	PHALCON_CALL_METHODW(NULL, &active_profile, "setinitialtime", &time);

	if (phalcon_method_exists_ex(getThis(), SL("beforestartprofile")) == SUCCESS) {
		PHALCON_CALL_METHODW(NULL, getThis(), "beforestartprofile", &active_profile);
	}

	phalcon_update_property_zval(getThis(), SL("_activeProfile"), &active_profile);

	RETURN_THISW();
}
Example #10
0
/**
 * Stops the active profile
 *
 * @return Phalcon\Db\Profiler
 */
PHP_METHOD(Phalcon_Db_Profiler, stopProfile){

	zval active_profile = {}, final_time = {}, initial_time = {}, difference = {}, total_seconds = {}, new_total_seconds = {};

	phalcon_read_property(&active_profile, getThis(), SL("_activeProfile"), PH_NOISY);

	PHALCON_CALL_FUNCTIONW(&final_time, "microtime", &PHALCON_GLOBAL(z_true));
	PHALCON_CALL_METHODW(NULL, &active_profile, "setfinaltime", &final_time);

	PHALCON_CALL_METHODW(&initial_time, &active_profile, "getinitialtime");

	phalcon_sub_function(&difference, &final_time, &initial_time);

	phalcon_read_property(&total_seconds, getThis(), SL("_totalSeconds"), PH_NOISY);

	phalcon_add_function(&new_total_seconds, &total_seconds, &difference);

	phalcon_update_property_zval(getThis(), SL("_totalSeconds"), &new_total_seconds);
	phalcon_update_property_array_append(getThis(), SL("_allProfiles"), &active_profile);

	if (phalcon_method_exists_ex(getThis(), SL("afterendprofile")) == SUCCESS) {
		PHALCON_CALL_METHODW(NULL, getThis(), "afterendprofile", &active_profile);
	}

	RETURN_THISW();
}
Example #11
0
/**
 * Gets the value of an environment variable
 *
 * @param string $name
 * @return string|boolean
 */
PHP_METHOD(Phalcon_Http_Request, getEnv){

	zval *name;

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

	PHALCON_CALL_FUNCTIONW(return_value, "getenv", name);
}
Example #12
0
/**
 * Execute a resize.
 *
 * @param int $width
 * @param int $height
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, _resize) {

	zval *width, *height, image = {}, tmp_image = {};

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

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

	PHALCON_CALL_FUNCTIONW(&tmp_image, "imagescale", &image, width, height);

	if (Z_TYPE(tmp_image) == IS_RESOURCE) {
		PHALCON_CALL_FUNCTIONW(NULL, "imagedestroy", &image);
		phalcon_update_property_zval(getThis(), SL("_image"), &tmp_image);

		phalcon_update_property_zval(getThis(), SL("_width"), width);
		phalcon_update_property_zval(getThis(), SL("_height"), height);
	}
}
Example #13
0
/**
 * Destroys the loaded image to free up resources.
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, __destruct){

	zval image = {};

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

	if (Z_TYPE(image) == IS_RESOURCE) {
		PHALCON_CALL_FUNCTIONW(NULL, "imagedestroy", &image);
	}
}
Example #14
0
/**
 * Executes the validation
 *
 * @param Phalcon\Validation $validator
 * @param string $attribute
 * @return boolean
 */
PHP_METHOD(Phalcon_Validation_Validator_Between, validate){

	zval *validator, *attribute, value = {}, allow_empty = {}, minimum = {}, maximum = {}, label = {}, pairs = {}, valid = {}, message_str = {}, code = {}, prepared = {}, message = {};
	zend_class_entry *ce = Z_OBJCE_P(getThis());

	phalcon_fetch_params(0, 2, 0, &validator, &attribute);

	PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 0);

	PHALCON_CALL_METHODW(&value, validator, "getvalue", attribute);

	RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&allow_empty, ce, getThis(), ISV(allowEmpty)));
	if (zend_is_true(&allow_empty) && phalcon_validation_validator_isempty_helper(&value)) {
		RETURN_TRUE;
	}

	RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minimum, ce, getThis(), "minimum"));
	RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maximum, ce, getThis(), "maximum"));

	PHALCON_CALL_SELFW(&valid, "valid", &value, &minimum, &maximum);

	if (PHALCON_IS_FALSE(&valid)) {
		RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&label, ce, getThis(), ISV(label)));
		if (!zend_is_true(&label)) {
			PHALCON_CALL_METHODW(&label, validator, "getlabel", attribute);
			if (!zend_is_true(&label)) {
				PHALCON_CPY_WRT_CTOR(&label, attribute);
			}
		}

		array_init_size(&pairs, 3);
		phalcon_array_update_str(&pairs, SL(":field"), &label, PH_COPY);
		phalcon_array_update_str(&pairs, SL(":min"), &minimum, PH_COPY);
		phalcon_array_update_str(&pairs, SL(":max"), &maximum, PH_COPY);

		RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message)));
		if (!zend_is_true(&message_str)) {
			RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "Between"));
		}

		RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&code, ce, getThis(), ISV(code)));
		if (Z_TYPE_P(&code) == IS_NULL) {
			ZVAL_LONG(&code, 0);
		}

		PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs);

		phalcon_validation_message_construct_helper(&message, &prepared, attribute, "Between", &code);

		PHALCON_CALL_METHODW(NULL, validator, "appendmessage", &message);
		RETURN_FALSE;
	}

	RETURN_TRUE;
}
Example #15
0
/**
 * Execute a background.
 *
 * @param int $r
 * @param int $g
 * @param int $b
 * @param int $opacity
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, _background) {

	zval *r, *g, *b, *opacity, op = {}, image = {}, background = {}, width = {}, height = {}, color = {}, tmp = {}, blendmode = {}, ret = {};
	int int_opacity;
	double num;

	phalcon_fetch_params(0, 4, 0, &r, &g, &b, &opacity);

	phalcon_return_property(&image, getThis(), SL("_image"));
	phalcon_return_property(&width, getThis(), SL("_width"));
	phalcon_return_property(&height, getThis(), SL("_height"));

	int_opacity = Z_LVAL_P(opacity);

	num = (int_opacity * 127.0 / 100) - 127;

	if (num < 0) {
		num = -num;
	}

	int_opacity = (int)num;

	PHALCON_CALL_METHODW(&background, getThis(), "_create", &width, &height);

	ZVAL_LONG(&op, int_opacity);

	PHALCON_CALL_FUNCTIONW(&color, "imagecolorallocatealpha", &background, r, g, b, &op);

	ZVAL_LONG(&tmp, 0);

	PHALCON_CALL_FUNCTIONW(NULL, "imagefilledrectangle", &background, &tmp, &tmp, &width, &height, &color);

	ZVAL_TRUE(&blendmode);

	PHALCON_CALL_FUNCTIONW(NULL, "imagealphablending", &background, &blendmode);
	PHALCON_CALL_FUNCTIONW(&ret, "imagecopy", &background, &image, &tmp, &tmp, &tmp, &tmp, &width, &height);

	if (zend_is_true(&ret)) {
		PHALCON_CALL_FUNCTIONW(NULL, "imagedestroy", &image);
		phalcon_update_property_zval(getThis(), SL("_image"), &background);
	}
}
Example #16
0
/**
 * Closes the logger
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Logger_Adapter_Syslog, close){

	zval *opened;

	opened = phalcon_read_property(getThis(), SL("_opened"), PH_NOISY);
	if (zend_is_true(opened)) {
		PHALCON_CALL_FUNCTIONW(NULL, "closelog");
	}

	RETURN_TRUE;
}
Example #17
0
/**
 * Create an empty image with the given width and height.
 *
 * @param int $width
 * @param int $height
 * @return resource
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, _create) {

	zval *width, *height, image = {}, blendmode = {}, saveflag = {};

	phalcon_fetch_params(0, 2, 0, &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_FALSE(&blendmode);
	ZVAL_TRUE(&saveflag);

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

	RETURN_CTORW(&image);
}
Example #18
0
/**
 * Reads meta-data from APC
 *
 * @param  string $key
 * @return array
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, read){

	zval *key, prefix = {}, apc_key = {};

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

	phalcon_read_property(&prefix, getThis(), SL("_prefix"), PH_NOISY);

	PHALCON_CONCAT_SVV(&apc_key, "$PMM$", &prefix, key);

	PHALCON_CALL_FUNCTIONW(return_value, "apc_fetch", &apc_key);
}
Example #19
0
/**
 * Phalcon\Binary\Writer constructor
 *
 * @param  string|resource $data
 * @param  int $endian
 * @throws \InvalidArgumentException
 */
PHP_METHOD(Phalcon_Binary_Writer, __construct){

	zval *data = NULL, *endian = NULL, filename = {}, mode = {}, handler = {}, fstat = {}, size = {};

	phalcon_fetch_params(0, 0, 2, &data, &endian);

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

	if (Z_TYPE_P(data) == IS_STRING || Z_TYPE_P(data) == IS_NULL) {
		ZVAL_STRING(&filename, "php://memory");
		ZVAL_STRING(&mode, "br+");
		PHALCON_CALL_FUNCTIONW(&handler, "fopen", &filename, &mode);
		PHALCON_CALL_FUNCTIONW(NULL, "fwrite", &handler, data);

		PHALCON_CALL_FUNCTIONW(&fstat, "fstat", &handler);
		if (phalcon_array_isset_fetch_str(&size, &fstat, SL("size"))) {
			phalcon_update_property_zval(getThis(), SL("_position"), &size);
		}
		phalcon_update_property_zval(getThis(), SL("_output"), &handler);
	} else if (Z_TYPE_P(data) == IS_RESOURCE) {
		phalcon_update_property_zval(getThis(), SL("_output"), data);

		PHALCON_CALL_FUNCTIONW(&fstat, "fstat", data);
		if (phalcon_array_isset_fetch_str(&size, &fstat, SL("size"))) {
			phalcon_update_property_zval(getThis(), SL("_position"), &size);
		}
	} else {
		PHALCON_THROW_EXCEPTION_STRW(phalcon_binary_exception_ce, "Data must be set as string or resource");
		return;
	}

	if (endian && Z_TYPE_P(endian) != IS_NULL) {
		if (Z_TYPE_P(endian) != IS_LONG || Z_LVAL_P(endian) < 0 || Z_LVAL_P(endian) > 2) {
			PHALCON_THROW_EXCEPTION_STRW(phalcon_binary_exception_ce, "Endian must be set as big or little");
		}
		phalcon_update_property_zval(getThis(), SL("_endian"), endian);
	}
}
Example #20
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;
}
Example #21
0
/**
 * Execute a rotation.
 *
 * @param int $degrees
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, _rotate) {

	zval *_degrees, degrees = {}, image = {}, tmp_image = {}, color = {}, alpha = {}, transparent = {}, ignore_transparent = {}, saveflag = {}, w = {}, h = {};
	int tmp_degrees;

	phalcon_fetch_params(0, 1, 0, &_degrees);
	PHALCON_CPY_WRT_CTOR(&degrees, _degrees);

	ZVAL_LONG(&color, 0);
	ZVAL_LONG(&alpha, 127);

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

	PHALCON_CALL_FUNCTIONW(&transparent, "imagecolorallocatealpha", &image, &color, &color, &color, &alpha);

	tmp_degrees = phalcon_get_intval(&degrees);

	ZVAL_LONG(&degrees, 360 - tmp_degrees);
	ZVAL_LONG(&ignore_transparent, 1);

	PHALCON_CALL_FUNCTIONW(&tmp_image, "imagerotate", &image, &degrees, &transparent, &ignore_transparent);

	ZVAL_TRUE(&saveflag);

	PHALCON_CALL_FUNCTIONW(NULL, "imagesavealpha", &tmp_image, &saveflag);
	PHALCON_CALL_FUNCTIONW(&w, "imagesx", &tmp_image);
	PHALCON_CALL_FUNCTIONW(&h, "imagesy", &tmp_image);
	PHALCON_CALL_FUNCTIONW(NULL, "imagedestroy", &image);
	phalcon_update_property_zval(getThis(), SL("_image"), &tmp_image);
	phalcon_update_property_zval(getThis(), SL("_width"), &w);
	phalcon_update_property_zval(getThis(), SL("_height"), &h);
}
Example #22
0
/**
 * Write bytes to the current position in the file pointer
 * 
 * @return Phalcon\Binary\Writer
 */
PHP_METHOD(Phalcon_Binary_Writer, write){

	zval *data, *length, position = {}, result = {}, output = {};

	phalcon_fetch_params(0, 2, 0, &data, &length);

	phalcon_read_property(&position, getThis(), SL("_position"), PH_NOISY);
	phalcon_add_function(&result, &position, length);

	phalcon_read_property(&output, getThis(), SL("_output"), PH_NOISY);
	PHALCON_CALL_FUNCTIONW(return_value, "fwrite", &output, data, length);
	phalcon_update_property_zval(getThis(), SL("_position"), &result);
}
Example #23
0
/**
 * Writes the meta-data to APC
 *
 * @param string $key
 * @param array $data
 */
PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, write){

	zval *key, *data, prefix = {}, apc_key = {}, ttl = {};

	phalcon_fetch_params(0, 2, 0, &key, &data);

	phalcon_read_property(&prefix, getThis(), SL("_prefix"), PH_NOISY);

	PHALCON_CONCAT_SVV(&apc_key, "$PMM$", &prefix, key);

	phalcon_read_property(&ttl, getThis(), SL("_ttl"), PH_NOISY);
	PHALCON_CALL_FUNCTIONW(NULL, "apc_store", &apc_key, data, &ttl);
}
Example #24
0
/**
 * Executes the validation
 *
 * @param string $value
 * @return boolean
 */
PHP_METHOD(Phalcon_Validation_Validator_Alnum, valid){

	zval *value, valid = {};

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

	PHALCON_CALL_FUNCTIONW(&valid, "ctype_alnum", value);
	if (!zend_is_true(&valid)) {
		RETURN_FALSE;
	}

	RETURN_TRUE;
}
Example #25
0
/**
 * Pixelate image
 *
 * @param int $amount amount to pixelate
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, _pixelate){

	zval *amount, image = {}, width = {}, height = {}, color = {};
	int a, x, y, x1, y1, w, h;

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

	phalcon_return_property(&image, getThis(), SL("_image"));
	phalcon_return_property(&width, getThis(), SL("_width"));
	phalcon_return_property(&height, getThis(), SL("_height"));

	a = phalcon_get_intval(amount);
	w = phalcon_get_intval(&width);
	h = phalcon_get_intval(&height);

	for(x = 0; x < w; x += a) {
		for (y = 0; y < h; y += a) {
			zval tmp1 = {}, tmp2 = {}, tmp3 = {}, tmp4 = {};
			x1 = (int)(x + a/2 + 0.5);
			y1 = (int)(y + a/2 + 0.5);

			ZVAL_LONG(&tmp1, x1)
			ZVAL_LONG(&tmp2, y1)

			PHALCON_CALL_FUNCTIONW(&color, "imagecolorat", &image, &tmp1, &tmp2);

			ZVAL_LONG(&tmp1, x)
			ZVAL_LONG(&tmp2, y)

			x1 = x + a;
			y1 = y + a;

			ZVAL_LONG(&tmp3, x1)
			ZVAL_LONG(&tmp4, y1)

			PHALCON_CALL_FUNCTIONW(NULL, "imagefilledrectangle", &image, &tmp1, &tmp2, &tmp3, &tmp4, &color);
		}
	}
}
Example #26
0
/**
 * Executes the validation
 *
 * @param string $value
 * @return boolean
 */
PHP_METHOD(Phalcon_Validation_Validator_Json, valid){

	zval *value, assoc = {}, valid = {}, json = {}, *constant, ret = {}, option = {}, keys = {};

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

	ZVAL_TRUE(&valid);
	ZVAL_TRUE(&assoc);

	PHALCON_CALL_FUNCTIONW(&json, "json_decode", value, &assoc);

	if (Z_TYPE(json) == IS_NULL) {
		if ((constant = zend_get_constant_str(SL("JSON_ERROR_NONE"))) != NULL) {
			PHALCON_CALL_FUNCTIONW(&ret, "json_last_error");

			if (!PHALCON_IS_EQUAL(&ret, constant)) {
				ZVAL_FALSE(&valid);
			}
		}
	}

	if (!zend_is_true(&valid)) {
		RETURN_FALSE;
	}

	ZVAL_STRING(&option, "keys");

	PHALCON_CALL_METHODW(&keys, getThis(), "getoption", &option);

	if (Z_TYPE(keys) != IS_NULL) {
		PHALCON_CALL_FUNCTIONW(&ret, "array_key_exists", &keys, &json);
		if (!zend_is_true(&ret)) {
			RETURN_FALSE;
		}
	}

	RETURN_TRUE;
}
Example #27
0
/**
 * Write a unsigned char to the current position in the file pointer
 * 
 * @return Phalcon\Binary\Writer
 */
PHP_METHOD(Phalcon_Binary_Writer, writeUnsignedChar){

	zval *byte, length = {}, format = {}, result = {};

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

	ZVAL_LONG(&length, 1);

	ZVAL_STRING(&format, "C");
	PHALCON_CALL_FUNCTIONW(&result, "pack", &format, byte);

	PHALCON_CALL_METHODW(NULL, getThis(), "write", &result, &length);
	RETURN_THISW();
}
Example #28
0
/**
 * Write a double to the current position in the file pointer
 * 
 * @return Phalcon\Binary\Writer
 */
PHP_METHOD(Phalcon_Binary_Writer, writeDouble){

	zval *num, length = {}, format = {}, result = {};

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

	ZVAL_LONG(&length, sizeof(double));

	ZVAL_STRING(&format, "d");
	PHALCON_CALL_FUNCTIONW(&result, "pack", &format, num);

	PHALCON_CALL_METHODW(NULL, getThis(), "write", &result, &length);
	RETURN_THISW();
}
Example #29
0
/**
 * Draws a line
 *
 * @param int $sx
 * @param int $sy
 * @param int $ex
 * @param int $ey
 * @param string $color
 * @return Phalcon\Image\Adapter\GD
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, line){

	zval *sx, *sy, *ex, *ey, *color = NULL, image = {}, rgb = {}, r = {}, g = {}, b = {}, imagecolor = {};

	phalcon_fetch_params(0, 4, 1, &sx, &sy, &ex, &ey, &color);

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

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

	if (Z_TYPE(image) == IS_RESOURCE) {
		PHALCON_CALL_METHODW(&rgb, getThis(), "getcolorrbg", color);
		phalcon_array_fetch_long(&r, &rgb, 0, PH_NOISY);
		phalcon_array_fetch_long(&g, &rgb, 1, PH_NOISY);
		phalcon_array_fetch_long(&b, &rgb, 2, PH_NOISY);

		PHALCON_CALL_FUNCTIONW(&imagecolor, "imagecolorallocate", &image, &r, &g, &b);
		PHALCON_CALL_FUNCTIONW(NULL, "imageline", &image, sy, sx, ey, ex, &imagecolor);
	}
	RETURN_THISW();
}
Example #30
0
/**
 * Execute a crop.
 *
 * @param int $width
 * @param int $height
 * @param int $offset_x
 * @param int $offset_y
 */
PHP_METHOD(Phalcon_Image_Adapter_GD, _crop)
{
	zval *width, *height, *offset_x, *offset_y, image = {}, tmp_image = {}, rect = {};

	phalcon_fetch_params(0, 4, 0, &width, &height, &offset_x, &offset_y);

	phalcon_read_property(&image, getThis(), SL("_image"), 0);

	array_init_size(&rect, 4);
	phalcon_array_update_str(&rect, SL("x"), offset_x, 0);
	phalcon_array_update_str(&rect, SL("y"), offset_y, 0);
	phalcon_array_update_str(&rect, SL("width"), width, 0);
	phalcon_array_update_str(&rect, SL("height"), height, 0);

	PHALCON_CALL_FUNCTIONW(&tmp_image, "imagecrop", &image, &rect);

	if (Z_TYPE(tmp_image) == IS_RESOURCE) {
		PHALCON_CALL_FUNCTIONW(NULL, "imagedestroy", &image);
		phalcon_update_property_zval(getThis(), SL("_image"), &tmp_image);
		phalcon_update_property_zval(getThis(), SL("_width"), width);
		phalcon_update_property_zval(getThis(), SL("_height"), height);
	}
}