/** * Returns an HTML string of information about a single variable. * * <code> * echo (new \Phalcon\Debug\Dump())->variable($foo, "foo"); * </code> */ PHP_METHOD(Phalcon_Debug_Dump, variable){ zval *variable, *name = NULL, *str, *type, *style = NULL, *output = NULL, *replace_pairs; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &variable, &name); if (!name) { name = PHALCON_GLOBAL(z_null); } PHALCON_INIT_VAR(str); ZVAL_STRING(str, "<pre style=':style'>:output</pre>", 1); PHALCON_INIT_VAR(type); ZVAL_STRING(type, "pre", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_CALL_SELF(&output, "output", variable, name); PHALCON_INIT_VAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":output"), output, PH_COPY); phalcon_strtr_array(return_value, str, replace_pairs TSRMLS_CC); RETURN_MM(); }
/** * Returns an HTML string of debugging information about any number of * variables, each wrapped in a "pre" tag. * * <code> * $foo = "string"; * $bar = ["key" => "value"]; * $baz = new stdClass(); * echo (new \Phalcon\Debug\Dump())->variables($foo, $bar, $baz); *</code> * * @param mixed variable * @param ... */ PHP_METHOD(Phalcon_Debug_Dump, variables){ zval *arg_list = NULL, *name = NULL, *variable = NULL, *output = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); PHALCON_CALL_FUNCTION(&arg_list, "func_get_args"); phalcon_is_iterable(arg_list, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(name, ah0, hp0); PHALCON_GET_HVALUE(variable); PHALCON_CALL_SELF(&output, "variable", variable); PHALCON_SCONCAT(return_value, output); zend_hash_move_forward_ex(ah0, &hp0); } RETURN_MM(); }
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_Url, validate){ zval *validator, *attribute, *value = NULL, *allow_empty, *valid = NULL, *label; zval *pairs, *message_str, *code, *prepared = NULL, *message; zend_class_entry *ce = Z_OBJCE_P(getThis()); PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 1); PHALCON_CALL_METHOD(&value, validator, "getvalue", attribute); PHALCON_OBS_VAR(allow_empty); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &allow_empty, getThis(), ISV(allowEmpty))); if (zend_is_true(allow_empty) && phalcon_validation_validator_isempty_helper(value)) { RETURN_MM_TRUE; } PHALCON_CALL_SELF(&valid, "valid", value); if (PHALCON_IS_FALSE(valid)) { PHALCON_OBS_VAR(label); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &label, getThis(), ISV(label))); if (!zend_is_true(label)) { PHALCON_CALL_METHOD(&label, validator, "getlabel", attribute); if (!zend_is_true(label)) { PHALCON_CPY_WRT(label, attribute); } } PHALCON_ALLOC_INIT_ZVAL(pairs); array_init_size(pairs, 1); Z_TRY_ADDREF_P(label); add_assoc_zval_ex(pairs, SL(":field"), label); PHALCON_OBS_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &message_str, getThis(), ISV(message))); if (!zend_is_true(message_str)) { PHALCON_OBSERVE_OR_NULLIFY_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(Z_OBJCE_P(validator), message_str, validator, "Url")); } PHALCON_OBS_VAR(code); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &code, getThis(), ISV(code))); if (Z_TYPE_P(code) == IS_NULL) { ZVAL_LONG(code, 0); } PHALCON_CALL_FUNCTION(&prepared, "strtr", message_str, pairs); message = phalcon_validation_message_construct_helper(prepared, attribute, "Url", code); Z_TRY_DELREF_P(message); PHALCON_CALL_METHOD(NULL, validator, "appendmessage", message); RETURN_MM_FALSE; } RETURN_MM_TRUE; }
/** * Returns the numeric active version * * <code> * echo Phalcon\Version::getId(); * </code> * * @return int */ PHP_METHOD(Phalcon_Version, getId){ zval *version = NULL, *major, *medium, *minor, *special, *special_number; zval *format, *real_medium = NULL, *real_minor = NULL; PHALCON_MM_GROW(); PHALCON_CALL_SELF(&version, "_getversion"); PHALCON_OBS_VAR(major); phalcon_array_fetch_long(&major, version, 0, PH_NOISY); PHALCON_OBS_VAR(medium); phalcon_array_fetch_long(&medium, version, 1, PH_NOISY); PHALCON_OBS_VAR(minor); phalcon_array_fetch_long(&minor, version, 2, PH_NOISY); PHALCON_OBS_VAR(special); phalcon_array_fetch_long(&special, version, 3, PH_NOISY); PHALCON_OBS_VAR(special_number); phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY); PHALCON_INIT_VAR(format); ZVAL_STRING(format, "%02s", 1); PHALCON_CALL_FUNCTION(&real_medium, "sprintf", format, medium); PHALCON_CALL_FUNCTION(&real_minor, "sprintf", format, minor); PHALCON_CONCAT_VVVVV(return_value, major, real_medium, real_minor, special, special_number); RETURN_MM(); }
PHP_METHOD(Phalcon_Http_Uri, extend){ zval *uri, *self, *parts = NULL, *parts2 = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &uri); PHALCON_CALL_SELF(&parts, "getParts"); if (Z_TYPE_P(uri) != IS_OBJECT || Z_OBJCE_P(uri) != phalcon_http_uri_ce) { PHALCON_INIT_VAR(self); object_init_ex(self, phalcon_http_uri_ce); PHALCON_CALL_METHOD(NULL, self, "__construct", uri); PHALCON_CALL_METHOD(&parts2, self, "getParts"); } else { PHALCON_CALL_METHOD(&parts2, self, "getParts"); } phalcon_array_merge_recursive_n(parts, parts2); phalcon_update_property_this(getThis(), SL("_parts"), parts); RETURN_THIS(); }
PHP_METHOD(Phalcon_Mvc_Collection_GridFS, saveBytes){ zval *bytes, *arr = NULL, *white_list = NULL, *mode = NULL; zval *old_sha1, *old_md5, *sha1 = NULL, *md5 = NULL, *status = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 3, &bytes, &arr, &white_list, &mode); if (!arr) { arr = &PHALCON_GLOBAL(z_null); } if (!white_list) { white_list = &PHALCON_GLOBAL(z_null); } if (!mode) { mode = &PHALCON_GLOBAL(z_null); } if (zend_is_true(bytes)) { old_sha1 = phalcon_read_property(getThis(), SL("sha1"), PH_NOISY); old_md5 = phalcon_read_property(getThis(), SL("md5"), PH_NOISY); PHALCON_CALL_FUNCTION(&sha1, "sha1", bytes); PHALCON_CALL_FUNCTION(&md5, "md5", bytes); phalcon_update_property_this(getThis(), SL("sha1"), sha1); phalcon_update_property_this(getThis(), SL("md5"), md5); } PHALCON_CALL_PARENT(&status, phalcon_mvc_collection_gridfs_ce, getThis(), "save", arr, white_list, mode); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } if (zend_is_true(bytes)) { PHALCON_CALL_SELF(&status, "store", bytes, &PHALCON_GLOBAL(z_null), &PHALCON_GLOBAL(z_null), &PHALCON_GLOBAL(z_true)); if (zend_is_true(old_sha1)) { PHALCON_CALL_SELF(NULL, "remove", old_sha1, old_md5); } } RETURN_CTOR(status); }
/** * Returns the active version (string) * * @return string */ PHP_METHOD(Phalcon_Version, get){ zval *version, *major, *medium, *minor, *special, *special_number; zval *result, *suffix = NULL, *final_version; PHALCON_MM_GROW(); PHALCON_INIT_VAR(version); PHALCON_CALL_SELF(version, this_ptr, "_getversion"); PHALCON_INIT_VAR(major); phalcon_array_fetch_long(&major, version, 0, PH_NOISY_CC); PHALCON_INIT_VAR(medium); phalcon_array_fetch_long(&medium, version, 1, PH_NOISY_CC); PHALCON_INIT_VAR(minor); phalcon_array_fetch_long(&minor, version, 2, PH_NOISY_CC); PHALCON_INIT_VAR(special); phalcon_array_fetch_long(&special, version, 3, PH_NOISY_CC); PHALCON_INIT_VAR(special_number); phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY_CC); PHALCON_INIT_VAR(result); PHALCON_CONCAT_VSVSVS(result, major, ".", medium, ".", minor, " "); if (phalcon_compare_strict_long(special, 1 TSRMLS_CC)) { PHALCON_INIT_VAR(suffix); PHALCON_CONCAT_SV(suffix, "ALPHA ", special_number); goto ph_end_0; } if (phalcon_compare_strict_long(special, 2 TSRMLS_CC)) { PHALCON_INIT_NVAR(suffix); PHALCON_CONCAT_SV(suffix, "BETA ", special_number); goto ph_end_0; } if (phalcon_compare_strict_long(special, 1 TSRMLS_CC)) { PHALCON_INIT_NVAR(suffix); PHALCON_CONCAT_SV(suffix, "RC ", special_number); goto ph_end_0; } PHALCON_INIT_NVAR(suffix); ZVAL_STRING(suffix, "", 1); goto ph_end_0; ph_end_0: phalcon_concat_self(result, suffix TSRMLS_CC); PHALCON_INIT_VAR(final_version); PHALCON_CALL_FUNC_PARAMS_1(final_version, "trim", result); RETURN_CCTOR(final_version); }
/** * Returns the active version (string) * * <code> * echo Phalcon\Version::get(); * </code> * * @return string */ PHP_METHOD(Phalcon_Version, get){ zval *version, *major, *medium, *minor, *special, *special_number; zval *result, *suffix = NULL, *final_version; PHALCON_MM_GROW(); PHALCON_INIT_VAR(version); PHALCON_CALL_SELF(version, this_ptr, "_getversion"); PHALCON_OBS_VAR(major); phalcon_array_fetch_long(&major, version, 0, PH_NOISY_CC); PHALCON_OBS_VAR(medium); phalcon_array_fetch_long(&medium, version, 1, PH_NOISY_CC); PHALCON_OBS_VAR(minor); phalcon_array_fetch_long(&minor, version, 2, PH_NOISY_CC); PHALCON_OBS_VAR(special); phalcon_array_fetch_long(&special, version, 3, PH_NOISY_CC); PHALCON_OBS_VAR(special_number); phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY_CC); PHALCON_INIT_VAR(result); PHALCON_CONCAT_VSVSVS(result, major, ".", medium, ".", minor, " "); switch (phalcon_get_intval(special)) { case 1: PHALCON_INIT_VAR(suffix); PHALCON_CONCAT_SV(suffix, "ALPHA ", special_number); break; case 2: PHALCON_INIT_NVAR(suffix); PHALCON_CONCAT_SV(suffix, "BETA ", special_number); break; case 3: PHALCON_INIT_NVAR(suffix); PHALCON_CONCAT_SV(suffix, "RC ", special_number); break; default: PHALCON_INIT_NVAR(suffix); ZVAL_STRING(suffix, "", 1); break; } phalcon_concat_self(&result, suffix TSRMLS_CC); PHALCON_INIT_VAR(final_version); PHALCON_CALL_FUNC_PARAMS_1(final_version, "trim", result); RETURN_CCTOR(final_version); }
PHP_METHOD(Phalcon_Http_Client_Adapter_Stream, __construct){ zval *uri = NULL, *method = NULL, *upper_method, *header, *stream = NULL, *http, *option, *value; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &uri, &method); PHALCON_CALL_SELF(NULL, "setbaseuri", uri); if (method) { PHALCON_INIT_VAR(upper_method); phalcon_fast_strtoupper(upper_method, method); phalcon_update_property_this(this_ptr, SL("_method"), upper_method TSRMLS_CC); } PHALCON_INIT_VAR(header); object_init_ex(header, phalcon_http_client_header_ce); PHALCON_CALL_METHOD(NULL, header, "__construct"); PHALCON_CALL_FUNCTION(&stream, "stream_context_create"); PHALCON_INIT_VAR(http); ZVAL_STRING(http, "http", 1); PHALCON_INIT_VAR(option); ZVAL_STRING(option, "user_agent", 1); PHALCON_INIT_VAR(value); ZVAL_STRING(value, "Phalcon HTTP Client(Stream)", 1); PHALCON_CALL_METHOD(NULL, header, "set", option, value); phalcon_update_property_this(this_ptr, SL("_header"), header TSRMLS_CC); PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "follow_location", 1); PHALCON_INIT_NVAR(value); ZVAL_LONG(value, 1); PHALCON_CALL_FUNCTION(NULL, "stream_context_set_option", stream, http, option, value); PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "max_redirects", 1); PHALCON_INIT_NVAR(value); ZVAL_LONG(value, 20); PHALCON_CALL_FUNCTION(NULL, "stream_context_set_option", stream, http, option, value); phalcon_update_property_this(this_ptr, SL("_stream"), stream TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Returns the active version (string) * * <code> * echo Phalcon\Version::get(); * </code> * * @return string */ PHP_METHOD(Phalcon_Version, get){ zval *version = NULL, *major, *medium, *minor, *special, *special_number; zval *result, *suffix; PHALCON_MM_GROW(); PHALCON_CALL_SELF(&version, "_getversion"); PHALCON_OBS_VAR(major); phalcon_array_fetch_long(&major, version, 0, PH_NOISY); PHALCON_OBS_VAR(medium); phalcon_array_fetch_long(&medium, version, 1, PH_NOISY); PHALCON_OBS_VAR(minor); phalcon_array_fetch_long(&minor, version, 2, PH_NOISY); PHALCON_OBS_VAR(special); phalcon_array_fetch_long(&special, version, 3, PH_NOISY); PHALCON_OBS_VAR(special_number); phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY); PHALCON_INIT_VAR(result); PHALCON_CONCAT_VSVSVS(result, major, ".", medium, ".", minor, " "); PHALCON_INIT_VAR(suffix); switch (phalcon_get_intval(special)) { case PHALCON_VERSION_ALPHA: PHALCON_CONCAT_SV(suffix, "ALPHA ", special_number); break; case PHALCON_VERSION_BETA: PHALCON_CONCAT_SV(suffix, "BETA ", special_number); break; case PHALCON_VERSION_RC: PHALCON_CONCAT_SV(suffix, "RC ", special_number); break; default: ZVAL_STRING(suffix, "", 1); break; } phalcon_concat_self(&result, suffix TSRMLS_CC); phalcon_fast_trim(return_value, result, PHALCON_TRIM_BOTH TSRMLS_CC); RETURN_MM(); }
/** * Returns the numeric active version * * @return int */ PHP_METHOD(Phalcon_Version, getId){ zval *version = NULL, *major, *medium, *minor, *special, *special_number; zval *format, *real_medium, *real_minor; PHALCON_MM_GROW(); PHALCON_INIT_VAR(version); PHALCON_CALL_SELF(version, this_ptr, "_getversion"); PHALCON_INIT_VAR(major); phalcon_array_fetch_long(&major, version, 0, PH_NOISY_CC); PHALCON_INIT_VAR(medium); phalcon_array_fetch_long(&medium, version, 1, PH_NOISY_CC); PHALCON_INIT_VAR(minor); phalcon_array_fetch_long(&minor, version, 2, PH_NOISY_CC); PHALCON_INIT_VAR(special); phalcon_array_fetch_long(&special, version, 3, PH_NOISY_CC); PHALCON_INIT_VAR(special_number); phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY_CC); PHALCON_INIT_VAR(format); ZVAL_STRING(format, "%02s", 1); PHALCON_INIT_VAR(real_medium); PHALCON_CALL_FUNC_PARAMS_2(real_medium, "sprintf", format, medium); PHALCON_INIT_VAR(real_minor); PHALCON_CALL_FUNC_PARAMS_2(real_minor, "sprintf", format, minor); PHALCON_INIT_NVAR(version); PHALCON_CONCAT_VVVVV(version, major, real_medium, real_minor, special, special_number); RETURN_CCTOR(version); }
/** * Phalcon\Debug\Dump constructor * * @param array styles set styles for vars type * @param boolean detailed debug object's private and protected properties */ PHP_METHOD(Phalcon_Debug_Dump, __construct){ zval *styles = NULL, *detailed = NULL, *default_styles; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &styles, &detailed); PHALCON_INIT_VAR(default_styles); array_init(default_styles); phalcon_array_update_string_string(&default_styles, SL("pre"), SL("background-color:#f3f3f3; font-size:11px; padding:10px; border:1px solid #ccc; text-align:left; color:#333"), PH_COPY); phalcon_array_update_string_string(&default_styles, SL("arr"), SL("color:red"), PH_COPY); phalcon_array_update_string_string(&default_styles, SL("bool"), SL("color:green"), PH_COPY); phalcon_array_update_string_string(&default_styles, SL("float"), SL("color:fuchsia"), PH_COPY); phalcon_array_update_string_string(&default_styles, SL("int"), SL("color:blue"), PH_COPY); phalcon_array_update_string_string(&default_styles, SL("null"), SL("color:black"), PH_COPY); phalcon_array_update_string_string(&default_styles, SL("num"), SL("color:navy"), PH_COPY); phalcon_array_update_string_string(&default_styles, SL("obj"), SL("color:purple"), PH_COPY); phalcon_array_update_string_string(&default_styles, SL("other"), SL("color:maroon"), PH_COPY); phalcon_array_update_string_string(&default_styles, SL("res"), SL("color:lime"), PH_COPY); phalcon_array_update_string_string(&default_styles, SL("str"), SL("color:teal"), PH_COPY); phalcon_update_property_this(this_ptr, SL("_styles"), default_styles TSRMLS_CC); if (styles && Z_TYPE_P(styles) != IS_NULL) { PHALCON_CALL_SELF(NULL, "setstyles", styles); } if (detailed && zend_is_true(detailed)) { phalcon_update_property_bool(this_ptr, SL("_detailed"), 1 TSRMLS_CC); } phalcon_update_property_empty_array(this_ptr, SL("_objects") TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * * @param string $session_id optional, session id * * @return boolean */ PHP_METHOD(Phalcon_Session_Adapter_Memcache, destroy){ zval *sid = NULL; zval *memcache; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &sid); if (!sid) { PHALCON_INIT_VAR(sid); PHALCON_CALL_SELF(&sid, "getid"); } memcache = phalcon_fetch_nproperty_this(this_ptr, SL("_memcache"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(memcache) == IS_OBJECT) { PHALCON_RETURN_CALL_METHOD(memcache, "delete", sid); RETURN_MM(); } else { RETURN_MM_FALSE; } }
/** * Builds a LINK[rel="stylesheet"] tag * * <code> * echo Phalcon\Tag::stylesheetLink("http://fonts.googleapis.com/css?family=Rosario", false); * echo Phalcon\Tag::stylesheetLink("css/style.css"); * </code> * * Volt Syntax: *<code> * {{ stylesheet_link("http://fonts.googleapis.com/css?family=Rosario", false) }} * {{ stylesheet_link("css/style.css") }} *</code> * * @param array $parameters * @param boolean $local * @return string */ PHP_METHOD(Phalcon_Tag, stylesheetLink){ zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; zval *url, *url_href, *href, *code, *value = NULL, *key = NULL, *five; zval *doctype, *eol, *is_xhtml; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, ¶meters, &local); if (!parameters) { PHALCON_INIT_VAR(parameters); } if (!local) { PHALCON_INIT_VAR(local); ZVAL_BOOL(local, 1); } else { PHALCON_SEPARATE_PARAM(local); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 2); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, local, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } if (!phalcon_array_isset_string(params, SS("href"))) { if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(first_param); phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("href"), &first_param, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_string(¶ms, SL("href"), SL(""), PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_NVAR(local); ZVAL_STRING(local, "", 1); if (phalcon_array_isset_long(params, 1)) { PHALCON_OBS_NVAR(local); phalcon_array_fetch_long(&local, params, 1, PH_NOISY_CC); } else { if (phalcon_array_isset_string(params, SS("local"))) { PHALCON_OBS_NVAR(local); phalcon_array_fetch_string(&local, params, SL("local"), PH_NOISY_CC); phalcon_array_unset_string(¶ms, SS("local"), PH_SEPARATE); } } if (!phalcon_array_isset_string(params, SS("type"))) { phalcon_array_update_string_string(¶ms, SL("type"), SL("text/css"), PH_SEPARATE TSRMLS_CC); } if (zend_is_true(local)) { PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_OBS_VAR(url_href); phalcon_array_fetch_string(&url_href, params, SL("href"), PH_NOISY_CC); PHALCON_INIT_VAR(href); PHALCON_CALL_METHOD_PARAMS_1(href, url, "get", url_href); phalcon_array_update_string(¶ms, SL("href"), &href, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<link rel=\"stylesheet\"", 1); if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_VAR(five); ZVAL_LONG(five, 5); PHALCON_OBS_VAR(doctype); phalcon_read_static_property(&doctype, SL("phalcon\\tag"), SL("_documentType") TSRMLS_CC); PHALCON_INIT_VAR(eol); ZVAL_STRING(eol, PHP_EOL, 1); /** * Check if Doctype is XHTML */ PHALCON_INIT_VAR(is_xhtml); is_smaller_function(is_xhtml, five, doctype TSRMLS_CC); if (zend_is_true(is_xhtml)) { PHALCON_SCONCAT_SV(code, " />", eol); } else { PHALCON_SCONCAT_SV(code, ">", eol); } RETURN_CTOR(code); }
/** * Builds a HTML FORM tag * * <code> * echo Phalcon\Tag::form("posts/save"); * echo Phalcon\Tag::form(array("posts/save", "method" => "post")); * </code> * * Volt syntax: * <code> * {{ form("posts/save") }} * {{ form("posts/save", "method": "post") }} * </code> * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, form){ zval *parameters = NULL, *params = NULL, *params_action = NULL, *action = NULL; zval *url, *code, *avalue = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); if (!parameters) { PHALCON_INIT_VAR(parameters); } else { PHALCON_SEPARATE_PARAM(parameters); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 1); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(params_action); phalcon_array_fetch_long(¶ms_action, params, 0, PH_NOISY_CC); } else { if (phalcon_array_isset_string(params, SS("action"))) { PHALCON_OBS_NVAR(params_action); phalcon_array_fetch_string(¶ms_action, params, SL("action"), PH_NOISY_CC); } else { PHALCON_INIT_NVAR(params_action); } } /** * By default the method is POST */ if (!phalcon_array_isset_string(params, SS("method"))) { phalcon_array_update_string_string(¶ms, SL("method"), SL("post"), PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(action); if (Z_TYPE_P(params_action) != IS_NULL) { PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_CALL_METHOD_PARAMS_1(action, url, "get", params_action); } /** * Check for extra parameters */ if (phalcon_array_isset_string(params, SS("parameters"))) { PHALCON_OBS_NVAR(parameters); phalcon_array_fetch_string(¶meters, params, SL("parameters"), PH_NOISY_CC); PHALCON_SCONCAT_SV(action, "?", parameters); } if (Z_TYPE_P(action) != IS_NULL) { phalcon_array_update_string(¶ms, SL("action"), &action, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<form", 1); if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(avalue); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", avalue, "\""); } zend_hash_move_forward_ex(ah0, &hp0); } phalcon_concat_self_str(&code, SL(">") TSRMLS_CC); RETURN_CTOR(code); }
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_InclusionIn, validate){ zval *validator, *attribute, *value = NULL, *allow_empty, *valid = NULL; zval *label, *domain, *joined_domain, *pairs, *message_str, *message, *code; zval *prepared = NULL; zend_class_entry *ce = Z_OBJCE_P(getThis()); PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 1); PHALCON_CALL_METHOD(&value, validator, "getvalue", attribute); PHALCON_OBS_VAR(allow_empty); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &allow_empty, getThis(), phalcon_interned_allowEmpty TSRMLS_CC)); if (zend_is_true(allow_empty) && phalcon_validation_validator_isempty_helper(value)) { RETURN_MM_TRUE; } /* A domain is an array with a list of valid values */ PHALCON_OBS_VAR(domain); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &domain, getThis(), phalcon_interned_domain TSRMLS_CC)); if (Z_TYPE_P(domain) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "Option 'domain' must be an array"); return; } PHALCON_CALL_SELF(&valid, "valid", value, domain); if (PHALCON_IS_FALSE(valid)) { PHALCON_OBS_VAR(label); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &label, getThis(), phalcon_interned_label TSRMLS_CC)); if (!zend_is_true(label)) { PHALCON_CALL_METHOD(&label, validator, "getlabel", attribute); if (!zend_is_true(label)) { PHALCON_CPY_WRT(label, attribute); } } ALLOC_INIT_ZVAL(joined_domain); phalcon_fast_join_str(joined_domain, SL(", "), domain TSRMLS_CC); PHALCON_ALLOC_GHOST_ZVAL(pairs); array_init_size(pairs, 2); Z_ADDREF_P(label); add_assoc_zval_ex(pairs, SS(":field"), label); add_assoc_zval_ex(pairs, SS(":domain"), joined_domain); PHALCON_OBS_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &message_str, getThis(), phalcon_interned_message TSRMLS_CC)); if (!zend_is_true(message_str)) { PHALCON_OBSERVE_OR_NULLIFY_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(Z_OBJCE_P(validator), &message_str, validator, "InclusionIn" TSRMLS_CC)); } PHALCON_OBS_VAR(code); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &code, getThis(), phalcon_interned_code TSRMLS_CC)); if (Z_TYPE_P(code) == IS_NULL) { ZVAL_LONG(code, 0); } PHALCON_CALL_FUNCTION(&prepared, "strtr", message_str, pairs); message = phalcon_validation_message_construct_helper(prepared, attribute, "InclusionIn", code TSRMLS_CC); Z_DELREF_P(message); PHALCON_CALL_METHOD(NULL, validator, "appendmessage", message); RETURN_MM_FALSE; } RETURN_MM_TRUE; }
PHP_METHOD(Phalcon_Http_Client_Adapter_Stream, sendInternal){ zval *stream, *http, *option = NULL, *header, *handler, *base_uri, *url = NULL, *method, *useragent, *timeout; zval *fp = NULL, *meta = NULL, *wrapper_data, *bodystr = NULL, *response; PHALCON_MM_GROW(); stream = phalcon_fetch_nproperty_this(this_ptr, SL("_stream"), PH_NOISY TSRMLS_CC); header = phalcon_fetch_nproperty_this(this_ptr, SL("_header"), PH_NOISY TSRMLS_CC); method = phalcon_fetch_nproperty_this(this_ptr, SL("_method"), PH_NOISY TSRMLS_CC); base_uri = phalcon_fetch_nproperty_this(this_ptr, SL("_base_uri"), PH_NOISY TSRMLS_CC); useragent = phalcon_fetch_nproperty_this(this_ptr, SL("_useragent"), PH_NOISY TSRMLS_CC); timeout = phalcon_fetch_nproperty_this(this_ptr, SL("_timeout"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(http); ZVAL_STRING(http, "http", 1); PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "method", 1); PHALCON_CALL_FUNCTION(NULL, "stream_context_set_option", stream, http, option, method); if (PHALCON_IS_NOT_EMPTY(useragent)) { PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "User-Agent", 1); PHALCON_CALL_METHOD(NULL, header, "set", option, useragent); } PHALCON_CALL_FUNCTION(NULL, "stream_context_set_option", stream, http, option, useragent); PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "timeout", 1); PHALCON_CALL_FUNCTION(NULL, "stream_context_set_option", stream, http, option, timeout); PHALCON_CALL_METHOD(&url, base_uri, "build"); PHALCON_CALL_SELF(NULL, "buildBody"); PHALCON_INIT_VAR(handler); array_init_size(handler, 2); phalcon_array_append(&handler, this_ptr, PH_SEPARATE); add_next_index_stringl(handler, SL("errorHandler"), 1); PHALCON_CALL_FUNCTION(NULL, "set_error_handler", handler); PHALCON_INIT_NVAR(option); ZVAL_STRING(option, "r", 1); PHALCON_CALL_FUNCTION(&fp, "fopen", url, option, PHALCON_GLOBAL(z_false), stream); PHALCON_CALL_FUNCTION(NULL, "restore_error_handler"); PHALCON_CALL_FUNCTION(&meta, "stream_get_meta_data", fp); PHALCON_CALL_FUNCTION(&bodystr, "stream_get_contents", fp); PHALCON_CALL_FUNCTION(NULL, "fclose", fp); PHALCON_INIT_VAR(response); object_init_ex(response, phalcon_http_client_response_ce); PHALCON_CALL_METHOD(NULL, response, "__construct"); if (phalcon_array_isset_string_fetch(&wrapper_data, meta, SS("wrapper_data"))) { PHALCON_CALL_METHOD(NULL, response, "setHeader", wrapper_data); } PHALCON_CALL_METHOD(NULL, response, "setbody", bodystr); RETURN_CTOR(response); }
/** * Builds a HTML FORM tag * * <code> * echo Phalcon\Tag::form("posts/save"); * echo Phalcon\Tag::form(array("posts/save", "method" => "post")); * </code> * * Volt syntax: * <code> * {{ form("posts/save") }} * {{ form("posts/save", "method": "post") }} * </code> * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, form){ zval *parameters = NULL, *params = NULL, *dispatcher, *dispatch_params; zval *action_parameters, *params_action = NULL, *controller_name; zval *action_name, *url, *action = NULL, *form_action; zval *code, *avalue = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!parameters) { PHALCON_INIT_NVAR(parameters); } else { PHALCON_SEPARATE_PARAM(parameters); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(dispatcher); PHALCON_CALL_SELF(dispatcher, this_ptr, "getdispatcherservice"); PHALCON_INIT_VAR(dispatch_params); PHALCON_CALL_METHOD(dispatch_params, dispatcher, "getparams", PH_NO_CHECK); PHALCON_INIT_VAR(action_parameters); phalcon_fast_join_str(action_parameters, SL("/"), dispatch_params TSRMLS_CC); eval_int = phalcon_array_isset_long(params, 0); if (!eval_int) { eval_int = phalcon_array_isset_string(params, SS("action")); if (eval_int) { PHALCON_INIT_VAR(params_action); phalcon_array_fetch_string(¶ms_action, params, SL("action"), PH_NOISY_CC); } else { PHALCON_INIT_VAR(controller_name); PHALCON_CALL_METHOD(controller_name, dispatcher, "getcontrollername", PH_NO_CHECK); PHALCON_INIT_VAR(action_name); PHALCON_CALL_METHOD(action_name, dispatcher, "getactionname", PH_NO_CHECK); PHALCON_INIT_NVAR(params_action); PHALCON_CONCAT_VSV(params_action, controller_name, "/", action_name); } } else { PHALCON_INIT_NVAR(params_action); phalcon_array_fetch_long(¶ms_action, params, 0, PH_NOISY_CC); } eval_int = phalcon_array_isset_string(params, SS("method")); if (!eval_int) { phalcon_array_update_string_string(¶ms, SL("method"), SL("post"), PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); if (zend_is_true(action_parameters)) { PHALCON_INIT_VAR(action); PHALCON_CALL_METHOD_PARAMS_1(action, url, "get", params_action, PH_NO_CHECK); } else { PHALCON_INIT_VAR(form_action); PHALCON_CONCAT_VSV(form_action, params_action, "/", action_parameters); PHALCON_INIT_NVAR(action); PHALCON_CALL_METHOD_PARAMS_1(action, url, "get", form_action, PH_NO_CHECK); } eval_int = phalcon_array_isset_string(params, SS("parameters")); if (eval_int) { PHALCON_INIT_NVAR(parameters); phalcon_array_fetch_string(¶meters, params, SL("parameters"), PH_NOISY_CC); PHALCON_SCONCAT_SV(action, "?", parameters); } PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<form action=\"", action, "\""); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(avalue); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", avalue, "\""); } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: phalcon_concat_self_str(code, SL(">") TSRMLS_CC); RETURN_CTOR(code); }
/** * Builds generic INPUT tags * * @param string $type * @param array $parameters * @param boolean $asValue * @return string */ PHP_METHOD(Phalcon_Tag, _inputField){ zval *type, *parameters, *as_value = NULL, *params = NULL, *value = NULL; zval *id = NULL, *name, *code, *key = NULL, *doctype; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &type, ¶meters, &as_value) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!as_value) { PHALCON_INIT_NVAR(as_value); ZVAL_BOOL(as_value, 0); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(value); if (PHALCON_IS_FALSE(as_value)) { eval_int = phalcon_array_isset_long(params, 0); if (!eval_int) { PHALCON_INIT_VAR(id); phalcon_array_fetch_string(&id, params, SL("id"), PH_NOISY_CC); phalcon_array_update_long(¶ms, 0, &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_NVAR(id); phalcon_array_fetch_long(&id, params, 0, PH_NOISY_CC); eval_int = phalcon_array_isset_string(params, SS("name")); if (!eval_int) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_INIT_VAR(name); phalcon_array_fetch_string(&name, params, SL("name"), PH_NOISY_CC); if (!zend_is_true(name)) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } eval_int = phalcon_array_isset_string(params, SS("id")); if (!eval_int) { phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } eval_int = phalcon_array_isset_string(params, SS("value")); if (!eval_int) { PHALCON_CALL_SELF_PARAMS_1(value, this_ptr, "getvalue", id); phalcon_array_update_string(¶ms, SL("value"), &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } } else { eval_int = phalcon_array_isset_long(params, 0); if (eval_int) { PHALCON_INIT_NVAR(value); phalcon_array_fetch_long(&value, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("value"), &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } } /** * Automatically check inputs */ if (PHALCON_COMPARE_STRING(type, "checkbox")) { if (zend_is_true(value)) { phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<input type=\"", type, "\""); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: /** * Check if Doctype is XHTML */ PHALCON_INIT_VAR(doctype); PHALCON_CALL_SELF(doctype, this_ptr, "getdoctype"); if (phalcon_memnstr_str(doctype, SL("XHTML") TSRMLS_CC)) { phalcon_concat_self_str(code, SL(" />") TSRMLS_CC); } else { phalcon_concat_self_str(code, SL(">") TSRMLS_CC); } RETURN_CTOR(code); }
/** * Builds a HTML A tag using framework conventions * *<code> * echo Phalcon\Tag::linkTo('signup/register', 'Register Here!'); *</code> * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, linkTo){ zval *parameters, *text = NULL, *params = NULL, *action = NULL, *url, *internal_url; zval *code, *value = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", ¶meters, &text) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!text) { PHALCON_INIT_NVAR(text); } else { PHALCON_SEPARATE_PARAM(text); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, text, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(action); ZVAL_STRING(action, "", 1); eval_int = phalcon_array_isset_long(params, 0); if (eval_int) { PHALCON_INIT_NVAR(action); phalcon_array_fetch_long(&action, params, 0, PH_NOISY_CC); } else { eval_int = phalcon_array_isset_string(params, SS("action")); if (eval_int) { PHALCON_INIT_NVAR(action); phalcon_array_fetch_string(&action, params, SL("action"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("action")); } } PHALCON_INIT_NVAR(text); ZVAL_STRING(text, "", 1); eval_int = phalcon_array_isset_long(params, 1); if (eval_int) { PHALCON_INIT_NVAR(text); phalcon_array_fetch_long(&text, params, 1, PH_NOISY_CC); } else { eval_int = phalcon_array_isset_string(params, SS("text")); if (eval_int) { PHALCON_INIT_NVAR(text); phalcon_array_fetch_string(&text, params, SL("text"), PH_NOISY_CC); PHALCON_SEPARATE(params); phalcon_array_unset_string(params, SS("text")); } } PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_INIT_VAR(internal_url); PHALCON_CALL_METHOD_PARAMS_1(internal_url, url, "get", action, PH_NO_CHECK); PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<a href=\"", internal_url, "\""); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: PHALCON_SCONCAT_SVS(code, ">", text, "</a>"); RETURN_CTOR(code); }
/** * Builds HTML IMG tags * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, image){ zval *parameters = NULL, *params = NULL, *first_param, *url, *url_src; zval *src, *code, *value = NULL, *key = NULL, *doctype; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!parameters) { PHALCON_INIT_NVAR(parameters); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } eval_int = phalcon_array_isset_string(params, SS("src")); if (!eval_int) { eval_int = phalcon_array_isset_long(params, 0); if (eval_int) { PHALCON_INIT_VAR(first_param); phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("src"), &first_param, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_INIT_VAR(url_src); phalcon_array_fetch_string(&url_src, params, SL("src"), PH_NOISY_CC); PHALCON_INIT_VAR(src); PHALCON_CALL_METHOD_PARAMS_1(src, url, "get", url_src, PH_NO_CHECK); phalcon_array_update_string(¶ms, SL("src"), &src, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<img", 1); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: PHALCON_INIT_VAR(doctype); PHALCON_CALL_SELF(doctype, this_ptr, "getdoctype"); if (phalcon_memnstr_str(doctype, SL("XHTML") TSRMLS_CC)) { phalcon_concat_self_str(code, SL(" />") TSRMLS_CC); } else { phalcon_concat_self_str(code, SL(">") TSRMLS_CC); } RETURN_CTOR(code); }
/** * Every helper calls this function to check whether a component has a predefined * value using Phalcon\Tag::setDefault or value from $_POST * * @param string $name * @param array $params * @return mixed */ PHP_METHOD(Phalcon_Tag, getValue){ zval *name, *params = NULL, *display_values, *value = NULL, *_POST; zval *autoescape = NULL, *escaper = NULL, *escaped_value = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &name, ¶ms); if (!params) { PHALCON_INIT_VAR(params); } PHALCON_OBS_VAR(display_values); phalcon_read_static_property(&display_values, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); /** * Check if there is a predefined value for it */ if (phalcon_array_isset(display_values, name)) { PHALCON_OBS_VAR(value); phalcon_array_fetch(&value, display_values, name, PH_NOISY_CC); } else { /** * Check if there is a post value for the item */ phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC); if (phalcon_array_isset(_POST, name)) { PHALCON_OBS_NVAR(value); phalcon_array_fetch(&value, _POST, name, PH_NOISY_CC); } else { RETURN_MM_NULL(); } } PHALCON_OBS_VAR(autoescape); phalcon_read_static_property(&autoescape, SL("phalcon\\tag"), SL("_autoEscape") TSRMLS_CC); /** * Escape all values in autoescape mode. Only escaping values */ if (Z_TYPE_P(value) == IS_STRING) { if (zend_is_true(autoescape)) { PHALCON_INIT_VAR(escaper); PHALCON_CALL_SELF(escaper, this_ptr, "getescaperservice"); PHALCON_INIT_VAR(escaped_value); PHALCON_CALL_METHOD_PARAMS_1(escaped_value, escaper, "escapehtmlattr", value); RETURN_CCTOR(escaped_value); } else { if (Z_TYPE_P(params) == IS_ARRAY) { /** * A escape parameter is set? */ if (phalcon_array_isset_string(params, SS("escape"))) { PHALCON_OBS_NVAR(autoescape); phalcon_array_fetch_string(&autoescape, params, SL("escape"), PH_NOISY_CC); if (zend_is_true(autoescape)) { PHALCON_INIT_NVAR(escaper); PHALCON_CALL_SELF(escaper, this_ptr, "getescaperservice"); PHALCON_INIT_NVAR(escaped_value); PHALCON_CALL_METHOD_PARAMS_1(escaped_value, escaper, "escapehtmlattr", value); RETURN_CCTOR(escaped_value); } } } } } RETURN_CCTOR(value); }
/** * Builds a SCRIPT[type="javascript"] tag * * <code> * echo Phalcon\Tag::javascriptInclude("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false); * echo Phalcon\Tag::javascriptInclude("javascript/jquery.js"); * </code> * * Volt syntax: * <code> * {{ javascript_include("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false) }} * {{ javascript_include("javascript/jquery.js") }} * </code> * * @param array $parameters * @param boolean $local * @return string */ PHP_METHOD(Phalcon_Tag, javascriptInclude){ zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; zval *url, *params_src, *src, *eol, *code, *value = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, ¶meters, &local); if (!parameters) { PHALCON_INIT_VAR(parameters); } if (!local) { PHALCON_INIT_VAR(local); ZVAL_BOOL(local, 1); } else { PHALCON_SEPARATE_PARAM(local); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 2); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, local, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } if (!phalcon_array_isset_string(params, SS("src"))) { if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(first_param); phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("src"), &first_param, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_NVAR(local); ZVAL_STRING(local, "", 1); if (phalcon_array_isset_long(params, 1)) { PHALCON_OBS_NVAR(local); phalcon_array_fetch_long(&local, params, 1, PH_NOISY_CC); } else { if (phalcon_array_isset_string(params, SS("local"))) { PHALCON_OBS_NVAR(local); phalcon_array_fetch_string(&local, params, SL("local"), PH_NOISY_CC); phalcon_array_unset_string(¶ms, SS("local"), PH_SEPARATE); } } if (!phalcon_array_isset_string(params, SS("type"))) { phalcon_array_update_string_string(¶ms, SL("type"), SL("text/javascript"), PH_SEPARATE TSRMLS_CC); } if (zend_is_true(local)) { /** * URLs are generated through the 'url' service */ PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_OBS_VAR(params_src); phalcon_array_fetch_string(¶ms_src, params, SL("src"), PH_NOISY_CC); PHALCON_INIT_VAR(src); PHALCON_CALL_METHOD_PARAMS_1(src, url, "get", params_src); phalcon_array_update_string(¶ms, SL("src"), &src, PH_COPY | PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(eol); ZVAL_STRING(eol, PHP_EOL, 1); PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<script", 1); if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_SCONCAT_SV(code, "></script>", eol); RETURN_CTOR(code); }
/** * Prepare an HTML string of information about a single variable. */ PHP_METHOD(Phalcon_Debug_Dump, output){ zval *variable, *name = NULL, *tab = NULL, *space, *tmp = NULL, *new_tab = NULL; zval *output = NULL, *str = NULL, *type = NULL, *style = NULL, *count = NULL, *key = NULL, *value = NULL, *replace_pairs = NULL; zval *class_name = NULL, *objects, *detailed = NULL, *properties = NULL, *methods = NULL, *method = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &variable, &name, &tab); if (!name) { name = PHALCON_GLOBAL(z_null); } else if (!PHALCON_IS_EMPTY(name)) { PHALCON_CONCAT_SVS(return_value, "var ", name, " "); } if (!tab) { tab = PHALCON_GLOBAL(z_one); } PHALCON_INIT_VAR(space); ZVAL_STRING(space, " ", 1); if (Z_TYPE_P(variable) == IS_ARRAY) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style =':style'>Array</b> (<span style =':style'>:count</span>) (\n", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "arr", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(count); ZVAL_LONG(count, phalcon_fast_count_int(variable TSRMLS_CC)); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":count"), count, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); phalcon_concat_self(&return_value, output TSRMLS_CC); phalcon_is_iterable(variable, &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); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); phalcon_concat_self(&return_value, tmp TSRMLS_CC); PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "[<span style=':style'>:key</span>] => ", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "arr", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":key"), key, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); phalcon_concat_self(&return_value, output TSRMLS_CC); if (PHALCON_IS_LONG(tab, 1) && !PHALCON_IS_EMPTY(name) && !phalcon_is_numeric(key) && PHALCON_IS_IDENTICAL(name, key)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } else { PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) + 1); PHALCON_CALL_SELF(&tmp, "output", value, PHALCON_GLOBAL(z_null), new_tab); PHALCON_SCONCAT_VS(return_value, tmp, "\n"); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) - 1); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT(return_value, tmp); } else if (Z_TYPE_P(variable) == IS_OBJECT) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Object</b> :class", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(class_name); phalcon_get_class(class_name, variable, 0 TSRMLS_CC); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":class"), class_name, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); PHALCON_INIT_NVAR(class_name); phalcon_get_parent_class(class_name, variable, 0 TSRMLS_CC); if (zend_is_true(class_name)) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, " <b style=':style'>extends</b> :parent", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":parent"), class_name, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } PHALCON_SCONCAT_STR(return_value, " (\n"); objects = phalcon_fetch_nproperty_this(this_ptr, SL("_objects"), PH_NOISY TSRMLS_CC); if (phalcon_fast_in_array(variable, objects TSRMLS_CC)) { PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT_VS(return_value, tmp, "[already listed]\n"); PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) - 1); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT_VS(return_value, tmp, ")"); RETURN_MM(); } phalcon_update_property_array_append(this_ptr, SL("_objects"), variable TSRMLS_CC); detailed = phalcon_fetch_nproperty_this(this_ptr, SL("_detailed"), PH_NOISY TSRMLS_CC); PHALCON_INIT_NVAR(properties); phalcon_get_object_vars(properties, variable, !zend_is_true(detailed) TSRMLS_CC); phalcon_is_iterable(properties, &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); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT(return_value, tmp); PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "-><span style=':style'>:key</span> (<span style=':style'>:type</span>) = ", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":key"), key, PH_COPY); if (PHALCON_PROPERTY_IS_PUBLIC_ZVAL(variable, key)) { phalcon_array_update_string_string(&replace_pairs, SL(":type"), SL("public"), PH_COPY); } else if (PHALCON_PROPERTY_IS_PRIVATE_ZVAL(variable, key)) { phalcon_array_update_string_string(&replace_pairs, SL(":type"), SL("private"), PH_COPY); } else if (PHALCON_PROPERTY_IS_PROTECTED_ZVAL(variable, key)) { phalcon_array_update_string_string(&replace_pairs, SL(":type"), SL("protected"), PH_COPY); } PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) + 1); PHALCON_CALL_SELF(&tmp, "output", value, PHALCON_GLOBAL(z_null), new_tab); PHALCON_SCONCAT_VS(return_value, tmp, ")\n"); zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_NVAR(methods); phalcon_get_class_methods(methods, variable, !zend_is_true(detailed) TSRMLS_CC); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT(return_value, tmp); PHALCON_INIT_NVAR(str); ZVAL_STRING(str, ":class <b style=':style'>methods</b>: (<span style=':style'>:count</span>) (\n", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(class_name); phalcon_get_class(class_name, variable, 0 TSRMLS_CC); PHALCON_INIT_NVAR(count); ZVAL_LONG(count, phalcon_fast_count_int(methods TSRMLS_CC)); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":class"), class_name, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":count"), count, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); phalcon_is_iterable(methods, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(method); PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) + 1); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, new_tab); PHALCON_SCONCAT(return_value, tmp); PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "-><span style=':style'>:method</span>();\n", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "obj", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":method"), method, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT_VS(return_value, tmp, "\n"); zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_NVAR(new_tab); ZVAL_LONG(new_tab, Z_LVAL_P(tab) - 1); PHALCON_CALL_FUNCTION(&tmp, "str_repeat", space, tab); PHALCON_SCONCAT_VS(return_value, tmp, ")"); } else if (Z_TYPE_P(variable) == IS_LONG) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Integer</b> (<span style=':style'>:var</span>)", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "int", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (Z_TYPE_P(variable) == IS_DOUBLE) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Float</b> (<span style=':style'>:var</span>)", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "float", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (phalcon_is_numeric_ex(variable)) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Numeric string</b> (<span style=':style'>:length</span>) \"<span style=':style'>:var</span>\"", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "num", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string_long(&replace_pairs, SL(":length"), Z_STRLEN_P(variable), PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (Z_TYPE_P(variable) == IS_STRING) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>String</b> (<span style=':style'>:length</span>) \"<span style=':style'>:var</span>\"", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "str", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string_long(&replace_pairs, SL(":length"), Z_STRLEN_P(variable), PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (Z_TYPE_P(variable) == IS_BOOL) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>Boolean</b> (<span style=':style'>:var</span>)", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "bool", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); if (zend_is_true(variable)) { phalcon_array_update_string_string(&replace_pairs, SL(":var"), SL("TRUE") , PH_COPY); } else { phalcon_array_update_string_string(&replace_pairs, SL(":var"), SL("FALSE") , PH_COPY); } PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else if (Z_TYPE_P(variable) == IS_NULL) { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "<b style=':style'>NULL</b>", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "null", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } else { PHALCON_INIT_NVAR(str); ZVAL_STRING(str, "(<span style=':style'>:var</span>)", 1); PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "other", 1); PHALCON_CALL_SELF(&style, "getstyle", type); PHALCON_INIT_NVAR(replace_pairs); array_init(replace_pairs); phalcon_array_update_string(&replace_pairs, SL(":style"), style, PH_COPY); phalcon_array_update_string(&replace_pairs, SL(":var"), variable, PH_COPY); PHALCON_INIT_NVAR(output); phalcon_strtr_array(output, str, replace_pairs TSRMLS_CC); PHALCON_SCONCAT(return_value, output); } RETURN_MM(); }
PHP_METHOD(Phalcon_Http_Client_Adapter_Curl, sendInternal){ zval *uri = NULL, *url = NULL, *method, *useragent, *data, *type, *files, *timeout, *curl, *username, *password, *authtype; zval *file = NULL, *body, *uniqid = NULL, *boundary, *key = NULL, *value = NULL; zval *path_parts = NULL, *filename, *basename, *filedata = NULL; zval *constant, *header, *headers = NULL; zval *content = NULL, *errorno = NULL, *error = NULL, *headersize = NULL, *httpcode = NULL, *headerstr, *bodystr, *response, *tmp = NULL; zend_class_entry *curlfile_ce; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; PHALCON_MM_GROW(); PHALCON_CALL_SELF(&uri, "geturi"); PHALCON_CALL_METHOD(&url, uri, "build"); method = phalcon_fetch_nproperty_this(this_ptr, SL("_method"), PH_NOISY TSRMLS_CC); useragent = phalcon_fetch_nproperty_this(this_ptr, SL("_useragent"), PH_NOISY TSRMLS_CC); data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY TSRMLS_CC); type = phalcon_fetch_nproperty_this(this_ptr, SL("_type"), PH_NOISY TSRMLS_CC); files = phalcon_fetch_nproperty_this(this_ptr, SL("_files"), PH_NOISY TSRMLS_CC); timeout = phalcon_fetch_nproperty_this(this_ptr, SL("_timeout"), PH_NOISY TSRMLS_CC); curl = phalcon_fetch_nproperty_this(this_ptr, SL("_curl"), PH_NOISY TSRMLS_CC); username = phalcon_fetch_nproperty_this(this_ptr, SL("_username"), PH_NOISY TSRMLS_CC); password = phalcon_fetch_nproperty_this(this_ptr, SL("_password"), PH_NOISY TSRMLS_CC); authtype = phalcon_fetch_nproperty_this(this_ptr, SL("_authtype"), PH_NOISY TSRMLS_CC); PHALCON_INIT_VAR(constant); if (!zend_get_constant(SL("CURLOPT_URL"), constant TSRMLS_CC)) { RETURN_MM_FALSE; } PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, url); PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLOPT_CONNECTTIMEOUT"), constant TSRMLS_CC)) { PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, timeout); } PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLOPT_TIMEOUT"), constant TSRMLS_CC)) { PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, timeout); } PHALCON_INIT_NVAR(constant); if (PHALCON_IS_NOT_EMPTY(method) && zend_get_constant(SL("CURLOPT_CUSTOMREQUEST"), constant TSRMLS_CC)) { PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, method); } PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLOPT_USERAGENT"), constant TSRMLS_CC) && PHALCON_IS_NOT_EMPTY(useragent)) { PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, useragent); } header = phalcon_fetch_nproperty_this(this_ptr, SL("_header"), PH_NOISY TSRMLS_CC); if (PHALCON_IS_NOT_EMPTY(username)) { if (PHALCON_IS_STRING(authtype, "any")) { PHALCON_INIT_NVAR(constant); PHALCON_INIT_NVAR(tmp); if (zend_get_constant(SL("CURLOPT_HTTPAUTH"), constant TSRMLS_CC) && zend_get_constant(SL("CURLAUTH_ANY"), tmp TSRMLS_CC)) { PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, tmp); PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLOPT_USERPWD"), constant TSRMLS_CC)) { PHALCON_INIT_NVAR(tmp); PHALCON_CONCAT_VSV(tmp, username, ":", password); PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, tmp); } } } else if (PHALCON_IS_STRING(authtype, "basic")) { PHALCON_INIT_NVAR(constant); PHALCON_INIT_NVAR(tmp); if (zend_get_constant(SL("CURLOPT_HTTPAUTH"), constant TSRMLS_CC) && zend_get_constant(SL("CURLAUTH_BASIC"), tmp TSRMLS_CC)) { PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, tmp); PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLOPT_USERPWD"), constant TSRMLS_CC)) { PHALCON_INIT_NVAR(tmp); PHALCON_CONCAT_VSV(tmp, username, ":", password); PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, tmp); } } } else if (PHALCON_IS_STRING(authtype, "digest")) { PHALCON_INIT_NVAR(constant); PHALCON_INIT_NVAR(tmp); if (zend_get_constant(SL("CURLOPT_HTTPAUTH"), constant TSRMLS_CC) && zend_get_constant(SL("CURLAUTH_DIGEST"), tmp TSRMLS_CC)) { PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, tmp); PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLOPT_USERPWD"), constant TSRMLS_CC)) { PHALCON_INIT_NVAR(tmp); PHALCON_CONCAT_VSV(tmp, username, ":", password); PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, tmp); } } } } PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLOPT_SAFE_UPLOAD"), constant TSRMLS_CC)) { PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, PHALCON_GLOBAL(z_true)); } if (Z_TYPE_P(data) == IS_STRING && PHALCON_IS_NOT_EMPTY(data)) { PHALCON_INIT_NVAR(key); ZVAL_STRING(key, "Content-Type", 1); if (PHALCON_IS_EMPTY(type)) { PHALCON_INIT_NVAR(type); ZVAL_STRING(type, "application/x-www-form-urlencoded", 1); } PHALCON_CALL_METHOD(NULL, header, "set", key, type); PHALCON_INIT_NVAR(constant); zend_get_constant(SL("CURLOPT_POSTFIELDS"), constant TSRMLS_CC); PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, data); } else if (phalcon_class_exists(SL("CURLFile"), 0 TSRMLS_CC)) { if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_INIT_NVAR(data); array_init(data); } if (Z_TYPE_P(files) == IS_ARRAY) { phalcon_is_iterable(files, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HVALUE(file); if (PHALCON_IS_NOT_EMPTY(file)) { curlfile_ce = zend_fetch_class(SL("CURLFile"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); PHALCON_INIT_NVAR(tmp); object_init_ex(tmp, curlfile_ce); PHALCON_CALL_METHOD(NULL, tmp, "__construct", file); phalcon_array_append(&data, tmp, PH_COPY); } zend_hash_move_forward_ex(ah0, &hp0); } } PHALCON_INIT_NVAR(constant); zend_get_constant(SL("CURLOPT_POSTFIELDS"), constant TSRMLS_CC); PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, data); } else { PHALCON_CALL_FUNCTION(&uniqid, "uniqid"); PHALCON_INIT_VAR(boundary); PHALCON_CONCAT_SV(boundary, "--------------", uniqid); PHALCON_INIT_VAR(body); if (Z_TYPE_P(data) == IS_ARRAY) { phalcon_is_iterable(data, &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); PHALCON_SCONCAT_SVS(body, "--", boundary, "\r\n"); PHALCON_SCONCAT_SVSVS(body, "Content-Disposition: form-data; name=\"", key, "\"\r\n\r\n", value, "\r\n"); zend_hash_move_forward_ex(ah0, &hp0); } } if (Z_TYPE_P(files) == IS_ARRAY) { phalcon_is_iterable(files, &ah1, &hp1, 0, 0); while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_HVALUE(file); if (PHALCON_IS_NOT_EMPTY(file)) { PHALCON_CALL_FUNCTION(&path_parts, "pathinfo", file); if (phalcon_array_isset_string_fetch(&filename, path_parts, SS("filename")) && phalcon_array_isset_string_fetch(&basename, path_parts, SS("basename"))) { PHALCON_CALL_FUNCTION(&filedata, "file_get_contents", file); PHALCON_SCONCAT_SVS(body, "--", boundary, "\r\n"); PHALCON_SCONCAT_SVSVS(body, "Content-Disposition: form-data; name=\"", filename, "\"; filename=\"", basename, "\"\r\n"); PHALCON_SCONCAT_SVS(body, "Content-Type: application/octet-stream\r\n\r\n", filedata, "\r\n"); } } zend_hash_move_forward_ex(ah1, &hp1); } } if (!PHALCON_IS_EMPTY(body)) { PHALCON_SCONCAT_SVS(body, "--", boundary, "--\r\n"); PHALCON_INIT_NVAR(key); ZVAL_STRING(key, "Content-Type", 1); PHALCON_INIT_NVAR(value); PHALCON_CONCAT_SV(value, "multipart/form-data; boundary=", boundary); PHALCON_CALL_METHOD(NULL, header, "set", key, value); PHALCON_INIT_NVAR(key); ZVAL_STRING(key, "Content-Length", 1); PHALCON_INIT_NVAR(value); ZVAL_LONG(value, Z_STRLEN_P(body)); PHALCON_CALL_METHOD(NULL, header, "set", key, value); PHALCON_CALL_METHOD(&headers, header, "build"); PHALCON_INIT_NVAR(constant); zend_get_constant(SL("CURLOPT_POSTFIELDS"), constant TSRMLS_CC); PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, body); PHALCON_INIT_NVAR(constant); zend_get_constant(SL("CURLOPT_HTTPHEADER"), constant TSRMLS_CC); PHALCON_CALL_FUNCTION(NULL, "curl_setopt", curl, constant, headers); } } PHALCON_CALL_FUNCTION(&content, "curl_exec", curl); PHALCON_CALL_FUNCTION(&errorno, "curl_errno", curl); if (PHALCON_IS_TRUE(errorno)) { PHALCON_CALL_FUNCTION(&error, "curl_error", curl); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_http_client_exception_ce, error); return; } PHALCON_INIT_VAR(response); object_init_ex(response, phalcon_http_client_response_ce); PHALCON_CALL_METHOD(NULL, response, "__construct"); PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLINFO_HTTP_CODE"), constant TSRMLS_CC)) { PHALCON_CALL_FUNCTION(&httpcode, "curl_getinfo", curl, constant); PHALCON_CALL_METHOD(NULL, response, "setstatuscode", httpcode); } PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLINFO_HEADER_SIZE"), constant TSRMLS_CC)) { PHALCON_CALL_FUNCTION(&headersize, "curl_getinfo", curl, constant); PHALCON_INIT_VAR(headerstr); phalcon_substr(headerstr, content, 0 , Z_LVAL_P(headersize)); PHALCON_INIT_VAR(bodystr); phalcon_substr(bodystr, content, Z_LVAL_P(headersize) , Z_STRLEN_P(content)); PHALCON_CALL_METHOD(NULL, response, "setheader", headerstr); PHALCON_CALL_METHOD(NULL, response, "setbody", bodystr); } RETURN_CTOR(response); }
PHP_METHOD(Phalcon_Http_Client_Adapter_Curl, __construct){ zval *uri = NULL, *method = NULL, *upper_method, *header, *curl = NULL, *options, *constant; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &uri, &method); if (uri) { PHALCON_CALL_SELF(NULL, "setbaseuri", uri); } if (method) { PHALCON_INIT_VAR(upper_method); phalcon_fast_strtoupper(upper_method, method); phalcon_update_property_this(this_ptr, SL("_method"), upper_method TSRMLS_CC); } PHALCON_INIT_VAR(header); object_init_ex(header, phalcon_http_client_header_ce); PHALCON_CALL_METHOD(NULL, header, "__construct"); phalcon_update_property_this(this_ptr, SL("_header"), header TSRMLS_CC); PHALCON_CALL_FUNCTION(&curl, "curl_init"); PHALCON_INIT_VAR(options); array_init(options); PHALCON_INIT_VAR(constant); if (zend_get_constant(SL("CURLOPT_RETURNTRANSFER"), constant TSRMLS_CC)) { phalcon_array_update_zval_bool(&options, constant, 1, PH_COPY); } PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLOPT_AUTOREFERER"), constant TSRMLS_CC)) { phalcon_array_update_zval_bool(&options, constant, 1, PH_COPY); } PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLOPT_FOLLOWLOCATION"), constant TSRMLS_CC)) { phalcon_array_update_zval_bool(&options, constant, 1, PH_COPY); } PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLOPT_MAXREDIRS"), constant TSRMLS_CC)) { phalcon_array_update_zval_long(&options, constant, 20, PH_COPY); } PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLOPT_HEADER"), constant TSRMLS_CC)) { phalcon_array_update_zval_bool(&options, constant, 1, PH_COPY); } PHALCON_INIT_NVAR(constant); if (zend_get_constant(SL("CURLOPT_USERAGENT"), constant TSRMLS_CC)) { phalcon_array_update_zval_string(&options, constant, SL("Phalcon HTTP Client(Curl)"), PH_COPY); } PHALCON_CALL_FUNCTION(NULL, "curl_setopt_array", curl, options); phalcon_update_property_this(this_ptr, SL("_curl"), curl TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Builds HTML IMG tags * * <code> * echo Phalcon\Tag::image("img/bg.png"); * echo Phalcon\Tag::image(array("img/photo.jpg", "alt" => "Some Photo")); * </code> * * Volt Syntax: * <code> * {{ image("img/bg.png") }} * {{ image("img/photo.jpg", "alt": "Some Photo") }} * </code> * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, image){ zval *parameters = NULL, *params = NULL, *first_param, *url, *url_src; zval *src, *code, *value = NULL, *key = NULL, *five, *doctype, *is_xhtml; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); if (!parameters) { PHALCON_INIT_VAR(parameters); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 1); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } if (!phalcon_array_isset_string(params, SS("src"))) { if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(first_param); phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("src"), &first_param, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_OBS_VAR(url_src); phalcon_array_fetch_string(&url_src, params, SL("src"), PH_NOISY_CC); PHALCON_INIT_VAR(src); PHALCON_CALL_METHOD_PARAMS_1(src, url, "get", url_src); phalcon_array_update_string(¶ms, SL("src"), &src, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<img", 1); if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_INIT_VAR(five); ZVAL_LONG(five, 5); PHALCON_OBS_VAR(doctype); phalcon_read_static_property(&doctype, SL("phalcon\\tag"), SL("_documentType") TSRMLS_CC); /** * Check if Doctype is XHTML */ PHALCON_INIT_VAR(is_xhtml); is_smaller_function(is_xhtml, five, doctype TSRMLS_CC); if (zend_is_true(is_xhtml)) { phalcon_concat_self_str(&code, SL(" />") TSRMLS_CC); } else { phalcon_concat_self_str(&code, SL(">") TSRMLS_CC); } RETURN_CTOR(code); }
/** * Builds HTML IMG tags * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, image){ zval *parameters = NULL, *params = NULL, *first_param = NULL, *url = NULL, *src = NULL; zval *code = NULL, *value = NULL, *key = NULL, *attribute = NULL; zval *r0 = NULL; zval *t0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!parameters) { PHALCON_ALLOC_ZVAL_MM(parameters); ZVAL_NULL(parameters); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } eval_int = phalcon_array_isset_string(params, SL("src")+1); if (!eval_int) { eval_int = phalcon_array_isset_long(params, 0); if (eval_int) { PHALCON_INIT_VAR(first_param); phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY_CC); phalcon_array_update_string(¶ms, SL("src"), &first_param, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE TSRMLS_CC); } } PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_ALLOC_ZVAL_MM(r0); phalcon_array_fetch_string(&r0, params, SL("src"), PH_NOISY_CC); PHALCON_INIT_VAR(src); PHALCON_CALL_METHOD_PARAMS_1(src, url, "get", r0, PH_NO_CHECK); phalcon_array_update_string(¶ms, SL("src"), &src, PH_COPY | PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(code); ZVAL_STRING(code, "<img", 1); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_9b93_8: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_9b93_8; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(value); ZVAL_ZVAL(value, *hd, 1, 0); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_INIT_VAR(attribute); PHALCON_CONCAT_SVSVS(attribute, " ", key, "=\"", value, "\""); phalcon_concat_self(&code, attribute TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_9b93_8; fee_9b93_8: PHALCON_INIT_VAR(t0); ZVAL_STRING(t0, "/>", 1); phalcon_concat_self(&code, t0 TSRMLS_CC); RETURN_CTOR(code); }
/** * Builds a HTML A tag using framework conventions * *<code> * echo Phalcon\Tag::linkTo('signup/register', 'Register Here!'); * echo Phalcon\Tag::linkTo(array('signup/register', 'Register Here!')); * echo Phalcon\Tag::linkTo(array('signup/register', 'Register Here!', 'class' => 'btn-primary')); *</code> * * @param array|string $parameters * @param string $text * @return string */ PHP_METHOD(Phalcon_Tag, linkTo){ zval *parameters, *text = NULL, *params = NULL, *action = NULL, *url, *internal_url; zval *code, *value = NULL, *key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, ¶meters, &text); if (!text) { PHALCON_INIT_VAR(text); } else { PHALCON_SEPARATE_PARAM(text); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init_size(params, 2); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); phalcon_array_append(¶ms, text, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(action); ZVAL_STRING(action, "", 1); if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_NVAR(action); phalcon_array_fetch_long(&action, params, 0, PH_NOISY_CC); } else { if (phalcon_array_isset_string(params, SS("action"))) { PHALCON_OBS_NVAR(action); phalcon_array_fetch_string(&action, params, SL("action"), PH_NOISY_CC); phalcon_array_unset_string(¶ms, SS("action"), PH_SEPARATE); } } PHALCON_INIT_NVAR(text); ZVAL_STRING(text, "", 1); if (phalcon_array_isset_long(params, 1)) { PHALCON_OBS_NVAR(text); phalcon_array_fetch_long(&text, params, 1, PH_NOISY_CC); } else { if (phalcon_array_isset_string(params, SS("text"))) { PHALCON_OBS_NVAR(text); phalcon_array_fetch_string(&text, params, SL("text"), PH_NOISY_CC); phalcon_array_unset_string(¶ms, SS("text"), PH_SEPARATE); } } PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); PHALCON_INIT_VAR(internal_url); PHALCON_CALL_METHOD_PARAMS_1(internal_url, url, "get", action); PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<a href=\"", internal_url, "\""); if (!phalcon_is_iterable(params, &ah0, &hp0, 0, 0 TSRMLS_CC)) { return; } while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_GET_FOREACH_VALUE(value); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); } zend_hash_move_forward_ex(ah0, &hp0); } PHALCON_SCONCAT_SVS(code, ">", text, "</a>"); RETURN_CTOR(code); }
/** * Builds a HTML FORM tag * * <code> * echo Phalcon\Tag::form("posts/save"); * echo Phalcon\Tag::form(array("posts/save", "method" => "post")); * </code> * * @param array $parameters * @return string */ PHP_METHOD(Phalcon_Tag, form){ zval *parameters = NULL, *params = NULL, *dispatcher = NULL, *dispatch_params = NULL; zval *slash = NULL, *action_parameters = NULL, *action = NULL, *controller_name = NULL; zval *action_name = NULL, *url = NULL, *form_action = NULL, *query_parameters = NULL; zval *code = NULL, *avalue = NULL, *key = NULL, *attribute = NULL, *final_code = NULL; zval *r0 = NULL; HashTable *ah0; HashPosition hp0; zval **hd; char *hash_index; uint hash_index_len; ulong hash_num; int hash_type; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", ¶meters) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!parameters) { PHALCON_ALLOC_ZVAL_MM(parameters); ZVAL_NULL(parameters); } else { PHALCON_SEPARATE_PARAM(parameters); } if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_INIT_VAR(params); array_init(params); phalcon_array_append(¶ms, parameters, PH_SEPARATE TSRMLS_CC); } else { PHALCON_CPY_WRT(params, parameters); } PHALCON_INIT_VAR(dispatcher); PHALCON_CALL_SELF(dispatcher, this_ptr, "getdispatcherservice"); PHALCON_INIT_VAR(dispatch_params); PHALCON_CALL_METHOD(dispatch_params, dispatcher, "getparams", PH_NO_CHECK); PHALCON_INIT_VAR(slash); ZVAL_STRING(slash, "/", 1); PHALCON_INIT_VAR(action_parameters); phalcon_fast_join(action_parameters, slash, dispatch_params TSRMLS_CC); eval_int = phalcon_array_isset_long(params, 0); if (!eval_int) { eval_int = phalcon_array_isset_string(params, SL("action")+1); if (eval_int) { PHALCON_INIT_VAR(action); phalcon_array_fetch_string(&action, params, SL("action"), PH_NOISY_CC); } else { PHALCON_INIT_VAR(controller_name); PHALCON_CALL_METHOD(controller_name, dispatcher, "getcontrollername", PH_NO_CHECK); PHALCON_INIT_VAR(action_name); PHALCON_CALL_METHOD(action_name, dispatcher, "getactionname", PH_NO_CHECK); PHALCON_INIT_VAR(action); PHALCON_CONCAT_VSV(action, controller_name, "/", action_name); } } else { PHALCON_INIT_VAR(action); phalcon_array_fetch_long(&action, params, 0, PH_NOISY_CC); } eval_int = phalcon_array_isset_string(params, SL("method")+1); if (!eval_int) { phalcon_array_update_string_string(¶ms, SL("method"), SL("post"), PH_SEPARATE TSRMLS_CC); } PHALCON_INIT_VAR(url); PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); if (zend_is_true(action_parameters)) { PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_CALL_METHOD_PARAMS_1(r0, url, "get", action, PH_NO_CHECK); PHALCON_CPY_WRT(action, r0); } else { PHALCON_INIT_VAR(form_action); PHALCON_CONCAT_VSV(form_action, action, "/", action_parameters); PHALCON_INIT_VAR(action); PHALCON_CALL_METHOD_PARAMS_1(action, url, "get", form_action, PH_NO_CHECK); } eval_int = phalcon_array_isset_string(params, SL("parameters")+1); if (eval_int) { PHALCON_INIT_VAR(parameters); phalcon_array_fetch_string(¶meters, params, SL("parameters"), PH_NOISY_CC); PHALCON_INIT_VAR(query_parameters); PHALCON_CONCAT_SV(query_parameters, "?", parameters); phalcon_concat_self(&action, query_parameters TSRMLS_CC); } PHALCON_INIT_VAR(code); PHALCON_CONCAT_SVS(code, "<form action=\"", action, "\" "); if (!phalcon_valid_foreach(params TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(params); zend_hash_internal_pointer_reset_ex(ah0, &hp0); fes_9b93_5: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto fee_9b93_5; } PHALCON_INIT_VAR(key); PHALCON_GET_FOREACH_KEY(key, ah0, hp0); PHALCON_INIT_VAR(avalue); ZVAL_ZVAL(avalue, *hd, 1, 0); if (Z_TYPE_P(key) != IS_LONG) { PHALCON_INIT_VAR(attribute); PHALCON_CONCAT_VSVS(attribute, key, "= \"", avalue, "\" "); phalcon_concat_self(&code, attribute TSRMLS_CC); } zend_hash_move_forward_ex(ah0, &hp0); goto fes_9b93_5; fee_9b93_5: PHALCON_INIT_VAR(final_code); PHALCON_CONCAT_VS(final_code, code, ">"); RETURN_CTOR(final_code); }