/** * Return a URL service from the DI * * @return Phalcon\Mvc\UrlInterface */ PHP_METHOD(Phalcon_Tag, getUrlService){ zval *url = NULL, *dependency_injector = NULL, *service; PHALCON_MM_GROW(); PHALCON_OBSERVE_VAR(url); phalcon_read_static_property(&url, SL("phalcon\\tag"), SL("_urlService") TSRMLS_CC); if (Z_TYPE_P(url) == IS_NULL) { PHALCON_OBSERVE_VAR(dependency_injector); phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_INIT_NVAR(dependency_injector); PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); } if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "A dependency injector container is required to obtain the \"url\" service"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "url", 1); PHALCON_INIT_NVAR(url); PHALCON_CALL_METHOD_PARAMS_1(url, dependency_injector, "getshared", service, PH_NO_CHECK); phalcon_update_static_property(SL("phalcon\\tag"), SL("_urlService"), url TSRMLS_CC); } RETURN_CCTOR(url); }
/** * Returns an Escaper service from the default DI * * @return Phalcon\EscaperInterface */ PHP_METHOD(Phalcon_Tag, getEscaperService){ zval *escaper = NULL, *dependency_injector = NULL, *service; PHALCON_MM_GROW(); PHALCON_OBS_VAR(escaper); phalcon_read_static_property(&escaper, SL("phalcon\\tag"), SL("_escaperService") TSRMLS_CC); if (Z_TYPE_P(escaper) != IS_OBJECT) { PHALCON_OBS_VAR(dependency_injector); phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_INIT_NVAR(dependency_injector); PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); } if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "A dependency injector container is required to obtain the \"dispatcher\" service"); return; } PHALCON_INIT_VAR(service); ZVAL_STRING(service, "escaper", 1); PHALCON_INIT_NVAR(escaper); PHALCON_CALL_METHOD_PARAMS_1(escaper, dependency_injector, "getshared", service); phalcon_update_static_property(SL("phalcon\\tag"), SL("_escaperService"), escaper TSRMLS_CC); } RETURN_CCTOR(escaper); }
/** * Gets the current document title * * <code> * echo Phalcon\Tag::getTitle(); * </code> * * <code> * {{ get_title() }} * </code> * * @return string */ PHP_METHOD(Phalcon_Tag, getTitle){ zval *tags = NULL, *document_title, *eol, *title_html; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &tags); if (!tags) { PHALCON_INIT_VAR(tags); ZVAL_BOOL(tags, 1); } PHALCON_OBS_VAR(document_title); phalcon_read_static_property(&document_title, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); if (PHALCON_IS_TRUE(tags)) { PHALCON_INIT_VAR(eol); ZVAL_STRING(eol, PHP_EOL, 1); PHALCON_INIT_VAR(title_html); PHALCON_CONCAT_SVSV(title_html, "<title>", document_title, "</title>", eol); RETURN_CTOR(title_html); } RETURN_CCTOR(document_title); }
/** * Assigns default values to generated tags by helpers * * <code> * //Assigning "peter" to "name" component * Phalcon\Tag::setDefault("name", "peter"); * * //Later in the view * echo Phalcon\Tag::textField("name"); //Will have the value "peter" by default * </code> * * @param string $id * @param string $value */ PHP_METHOD(Phalcon_Tag, setDefault){ zval *id, *value, *is_scalar; zval *t0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &id, &value) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (zend_is_true(value)) { PHALCON_INIT_VAR(is_scalar); PHALCON_CALL_FUNC_PARAMS_1(is_scalar, "is_scalar", value); if (PHALCON_IS_FALSE(is_scalar)) { PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "Only scalar values can be assigned to UI components"); return; } } PHALCON_OBSERVE_VAR(t0); phalcon_read_static_property(&t0, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); if (Z_TYPE_P(t0) != IS_ARRAY) { convert_to_array(t0); } phalcon_array_update_zval(&t0, id, &value, PH_COPY TSRMLS_CC); phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), t0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Check if a helper has a default value set using Phalcon\Tag::setDefault or value from $_POST * * @param string $name * @return boolean */ PHP_METHOD(Phalcon_Tag, hasValue){ zval *name, *display_values, *_POST; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &name); 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)) { RETURN_MM_TRUE; } 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)) { RETURN_MM_TRUE; } } RETURN_MM_FALSE; }
/** * Assigns default values to generated tags by helpers * * <code> * //Assigning "peter" to "name" component * Phalcon\Tag::setDefault("name", "peter"); * * //Later in the view * echo Phalcon\Tag::textField("name"); //Will have the value "peter" by default * </code> * * @param string $id * @param string $value */ PHP_METHOD(Phalcon_Tag, setDefault){ zval *id, *value; zval *t0 = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &id, &value); if (Z_TYPE_P(value) != IS_NULL) { if (PHALCON_IS_SCALAR(value)) { PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "Only scalar values can be assigned to UI components"); return; } } PHALCON_OBSERVE_VAR(t0); phalcon_read_static_property(&t0, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); if (Z_TYPE_P(t0) != IS_ARRAY) { convert_to_array(t0); } phalcon_array_update_zval(&t0, id, &value, PH_COPY TSRMLS_CC); phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), t0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Returns a Dispatcher service from the DI * * @return Phalcon\Mvc\Dispatcher */ PHP_METHOD(Phalcon_Tag, getDispatcherService){ zval *dependency_injector = NULL, *dispatcher = NULL; zval *c0 = NULL; PHALCON_MM_GROW(); PHALCON_OBSERVE_VAR(dependency_injector); phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_CC); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_INIT_VAR(dependency_injector); PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); } if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "A dependency injector container is required to obtain the \"dispatcher\" service"); return; } PHALCON_INIT_VAR(c0); ZVAL_STRING(c0, "dispatcher", 1); PHALCON_INIT_VAR(dispatcher); PHALCON_CALL_METHOD_PARAMS_1(dispatcher, dependency_injector, "getshared", c0, PH_NO_CHECK); RETURN_CCTOR(dispatcher); }
/** * Phalcon\Db constructor * * @param stdClass $descriptor */ PHP_METHOD(Phalcon_Db, __construct){ zval *descriptor = NULL; zval *t0 = NULL, *t1 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &descriptor) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } phalcon_update_property_zval(this_ptr, SL("_descriptor"), descriptor TSRMLS_CC); PHALCON_OBSERVE_VAR(t0); phalcon_read_static_property(&t0, SL("phalcon\\db"), SL("_connectionConsecutive") TSRMLS_CC); PHALCON_SEPARATE_NMO(t0); PHALCON_ALLOC_ZVAL_MM(t1); ZVAL_ZVAL(t1, t0, 1, 0); increment_function(t0); phalcon_update_static_property(SL("phalcon\\db"), SL("_connectionConsecutive"), t0 TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_connectionId"), t1 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Get the document type declaration of content * * @return string */ PHP_METHOD(Phalcon_Tag, getDocType){ zval *doctype = NULL, *declaration, *eol, *doctype_html; PHALCON_MM_GROW(); PHALCON_OBSERVE_VAR(doctype); phalcon_read_static_property(&doctype, SL("phalcon\\tag"), SL("_documentType") TSRMLS_CC); PHALCON_INIT_VAR(eol); ZVAL_STRING(eol, PHP_EOL, 1); PHALCON_INIT_VAR(declaration); if (phalcon_compare_strict_long(doctype, 1 TSRMLS_CC)) { ZVAL_STRING(declaration, " PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\"", 1); goto ph_end_0; } if (phalcon_compare_strict_long(doctype, 2 TSRMLS_CC)) { PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD HTML 4.01//EN\"", eol, "\t\"http://www.w3.org/TR/html4/strict.dtd\""); goto ph_end_0; } if (phalcon_compare_strict_long(doctype, 3 TSRMLS_CC)) { PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"", eol, "\t\"http://www.w3.org/TR/html4/loose.dtd\""); goto ph_end_0; } if (phalcon_compare_strict_long(doctype, 4 TSRMLS_CC)) { PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"", eol, "\t\"http://www.w3.org/TR/html4/frameset.dtd\""); goto ph_end_0; } if (phalcon_compare_strict_long(doctype, 6 TSRMLS_CC)) { PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""); goto ph_end_0; } if (phalcon_compare_strict_long(doctype, 7 TSRMLS_CC)) { PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\""); goto ph_end_0; } if (phalcon_compare_strict_long(doctype, 8 TSRMLS_CC)) { PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\""); goto ph_end_0; } if (phalcon_compare_strict_long(doctype, 9 TSRMLS_CC)) { PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\""); goto ph_end_0; } if (phalcon_compare_strict_long(doctype, 10 TSRMLS_CC)) { PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 2.0//EN\"", eol, "\t\"http://www.w3.org/MarkUp/DTD/xhtml2.dtd\""); goto ph_end_0; } ph_end_0: PHALCON_INIT_VAR(doctype_html); PHALCON_CONCAT_SVSV(doctype_html, "<!DOCTYPE html", declaration, ">", eol); RETURN_CTOR(doctype_html); }
/** * Internally gets the request dispatcher * * @return Phalcon\DiInterface */ PHP_METHOD(Phalcon_Tag, getDI){ zval *dependency_injector; PHALCON_MM_GROW(); PHALCON_OBS_VAR(dependency_injector); phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_CC); RETURN_CCTOR(dependency_injector); }
/** * Return the lastest DI created * * @return Phalcon\DiInterface */ PHP_METHOD(Phalcon_DI, getDefault){ zval *default_di; PHALCON_MM_GROW(); PHALCON_OBS_VAR(default_di); phalcon_read_static_property(&default_di, SL("phalcon\\di"), SL("_default") TSRMLS_CC); RETURN_CCTOR(default_di); }
/** * Gets the singleton instance of Phalcon_Request * * @return Phalcon_Request */ PHP_METHOD(Phalcon_Request, getInstance){ zval *t0 = NULL, *t1 = NULL; zval *i0 = NULL; PHALCON_MM_GROW(); PHALCON_OBSERVE_VAR(t0); phalcon_read_static_property(&t0, phalcon_request_ce, "_instance", sizeof("_instance")-1 TSRMLS_CC); if (!zend_is_true(t0)) { PHALCON_ALLOC_ZVAL_MM(i0); object_init_ex(i0, phalcon_request_ce); PHALCON_CALL_METHOD_NORETURN(i0, "__construct", PHALCON_CHECK); zend_update_static_property(phalcon_request_ce, "_instance", sizeof("_instance")-1, i0 TSRMLS_CC); } PHALCON_OBSERVE_VAR(t1); phalcon_read_static_property(&t1, phalcon_request_ce, "_instance", sizeof("_instance")-1 TSRMLS_CC); PHALCON_RETURN_CHECK_CTOR(t1); }
/** * Phalcon\Mvc\Router\Route constructor * * @param string $pattern * @param array $paths * @param array|string $httpMethods */ PHP_METHOD(Phalcon_Mvc_Router_Route, __construct){ zval *pattern, *paths = NULL, *http_methods = NULL, *unique_id = NULL; zval *route_id = NULL, *one, *next_id; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); if (!paths) { PHALCON_INIT_VAR(paths); } if (!http_methods) { PHALCON_INIT_VAR(http_methods); } /** * Configure the route (extract parameters, paths, etc) */ phalcon_call_method_p2_noret(this_ptr, "reconfigure", pattern, paths); /** * Update the HTTP method constraints */ phalcon_update_property_this(this_ptr, SL("_methods"), http_methods TSRMLS_CC); /** * Get the unique Id from the static member _uniqueId */ PHALCON_OBS_VAR(unique_id); phalcon_read_static_property(&unique_id, SL("phalcon\\mvc\\router\\route"), SL("_uniqueId") TSRMLS_CC); if (Z_TYPE_P(unique_id) == IS_NULL) { PHALCON_INIT_NVAR(unique_id); ZVAL_LONG(unique_id, 0); } /** * TODO: Add a function that increase static members */ PHALCON_CPY_WRT(route_id, unique_id); phalcon_update_property_this(this_ptr, SL("_id"), route_id TSRMLS_CC); PHALCON_INIT_VAR(one); ZVAL_LONG(one, 1); PHALCON_INIT_VAR(next_id); phalcon_add_function(next_id, unique_id, one TSRMLS_CC); phalcon_update_static_property(SL("phalcon\\mvc\\router\\route"), SL("_uniqueId"), next_id TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Phalcon\DI constructor * */ PHP_METHOD(Phalcon_DI, __construct){ zval *default_di; PHALCON_MM_GROW(); PHALCON_OBS_VAR(default_di); phalcon_read_static_property(&default_di, SL("phalcon\\di"), SL("_default") TSRMLS_CC); if (!zend_is_true(default_di)) { phalcon_update_static_property(SL("phalcon\\di"), SL("_default"), this_ptr TSRMLS_CC); } PHALCON_MM_RESTORE(); }
/** * Check if a default descriptor has already defined * * @return boolean */ PHP_METHOD(Phalcon_Db_Pool, hasDefaultDescriptor){ zval *t0 = NULL, *t1 = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); PHALCON_OBSERVE_VAR(t0); phalcon_read_static_property(&t0, SL("Phalcon_Db_Pool"), SL("_defaultDescriptor") TSRMLS_CC); PHALCON_INIT_VAR(t1); ZVAL_NULL(t1); PHALCON_INIT_VAR(r0); is_not_identical_function(r0, t1, t0 TSRMLS_CC); RETURN_NCTOR(r0); }
/** * 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 * @return mixed */ PHP_METHOD(Phalcon_Tag, getValue){ zval *name = NULL, *display_values = NULL, *default_value = NULL; zval *post = NULL, *le_post_name = NULL, *have_magic_quotes = NULL; zval *post_name = NULL, *striped = NULL; zval *g0 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_OBSERVE_VAR(display_values); phalcon_read_static_property(&display_values, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); eval_int = phalcon_array_isset(display_values, name); if (eval_int) { PHALCON_INIT_VAR(default_value); phalcon_array_fetch(&default_value, display_values, name, PH_NOISY_CC); RETURN_CCTOR(default_value); } else { phalcon_get_global(&g0, SL("_POST")+1 TSRMLS_CC); PHALCON_CPY_WRT(post, g0); eval_int = phalcon_array_isset(post, name); if (eval_int) { PHALCON_INIT_VAR(le_post_name); phalcon_array_fetch(&le_post_name, post, name, PH_NOISY_CC); PHALCON_INIT_VAR(have_magic_quotes); PHALCON_CALL_FUNC(have_magic_quotes, "get_magic_quotes_gpc"); if (!zend_is_true(have_magic_quotes)) { PHALCON_CPY_WRT(post_name, le_post_name); RETURN_CCTOR(post_name); } else { PHALCON_INIT_VAR(striped); PHALCON_CALL_FUNC_PARAMS_1(striped, "stripslashes", le_post_name); RETURN_CCTOR(striped); } } } PHALCON_MM_RESTORE(); }
/** * Phalcon\Db constructor * * @param stdClass $descriptor */ PHP_METHOD(Phalcon_Db, __construct){ zval *descriptor = NULL, *connection_consecutive = NULL; zval *next_consecutive = NULL, *dialect_type = NULL, *dialect_class = NULL; zval *dialect_object = NULL; zval *t0 = NULL; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &descriptor) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_OBSERVE_VAR(connection_consecutive); phalcon_read_static_property(&connection_consecutive, SL("phalcon\\db"), SL("_connectionConsecutive") TSRMLS_CC); PHALCON_INIT_VAR(t0); ZVAL_LONG(t0, 1); PHALCON_INIT_VAR(next_consecutive); phalcon_add_function(next_consecutive, connection_consecutive, t0 TSRMLS_CC); phalcon_update_static_property(SL("phalcon\\db"), SL("_connectionConsecutive"), next_consecutive TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_connectionId"), connection_consecutive TSRMLS_CC); eval_int = phalcon_array_isset_string(descriptor, SL("dialectClass")+1); if (!eval_int) { PHALCON_INIT_VAR(dialect_type); phalcon_read_property(&dialect_type, this_ptr, SL("_dialectType"), PH_NOISY_CC); PHALCON_INIT_VAR(dialect_class); PHALCON_CONCAT_SV(dialect_class, "phalcon\\db\\dialect\\", dialect_type); } else { PHALCON_INIT_VAR(dialect_class); phalcon_array_fetch_string(&dialect_class, descriptor, SL("dialectClass"), PH_NOISY_CC); } ce0 = phalcon_fetch_class(dialect_class TSRMLS_CC); PHALCON_INIT_VAR(dialect_object); object_init_ex(dialect_object, ce0); PHALCON_CALL_METHOD_NORETURN(dialect_object, "__construct", PH_CHECK); phalcon_update_property_zval(this_ptr, SL("_dialect"), dialect_object TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_descriptor"), descriptor TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Get the title of view content * * @return string */ PHP_METHOD(Phalcon_Tag, getTitle){ zval *document_title = NULL, *eol = NULL, *title_html = NULL; PHALCON_MM_GROW(); PHALCON_OBSERVE_VAR(document_title); phalcon_read_static_property(&document_title, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); PHALCON_INIT_VAR(eol); zend_get_constant(SL("PHP_EOL"), eol TSRMLS_CC); PHALCON_INIT_VAR(title_html); PHALCON_CONCAT_SVSV(title_html, "<title>", document_title, "</title>", eol); RETURN_CTOR(title_html); }
/** * Gets Phalcon_Controller_Front singleton instance * * @return Phalcon_Controller_Front */ PHP_METHOD(Phalcon_Controller_Front, getInstance){ zval *instance = NULL; PHALCON_MM_GROW(); PHALCON_OBSERVE_VAR(instance); phalcon_read_static_property(&instance, SL("phalcon\\controller\\front"), SL("_instance") TSRMLS_CC); if (!zend_is_true(instance)) { PHALCON_INIT_VAR(instance); object_init_ex(instance, phalcon_controller_front_ce); PHALCON_CALL_METHOD_NORETURN(instance, "__construct", PH_CHECK); phalcon_update_static_property(SL("phalcon\\controller\\front"), SL("_instance"), instance TSRMLS_CC); } RETURN_CCTOR(instance); }
/** * Appends a text to current document title * * @param string $title */ PHP_METHOD(Phalcon_Tag, appendTitle){ zval *title; zval *t0 = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &title); PHALCON_OBS_VAR(t0); phalcon_read_static_property(&t0, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r0); concat_function(r0, t0, title TSRMLS_CC); phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), r0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Prepends a text to current document title * * @param string $title */ PHP_METHOD(Phalcon_Tag, prependTitle){ zval *title, *document_title; zval *r0 = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &title); PHALCON_OBS_VAR(document_title); phalcon_read_static_property(&document_title, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); PHALCON_INIT_VAR(r0); PHALCON_CONCAT_VV(r0, title, document_title); phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), r0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Add to title of view content * * @param string $title */ PHP_METHOD(Phalcon_Tag, appendTitle){ zval *title; zval *t0 = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &title) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_OBSERVE_VAR(t0); phalcon_read_static_property(&t0, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(r0); concat_function(r0, t0, title TSRMLS_CC); phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), r0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * Add before the title of view content * * @param string $title */ PHP_METHOD(Phalcon_Tag, prependTitle){ zval *title, *document_title = NULL; zval *r0 = NULL; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &title) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_OBSERVE_VAR(document_title); phalcon_read_static_property(&document_title, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); PHALCON_INIT_VAR(r0); PHALCON_CONCAT_VV(r0, title, document_title); phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), r0 TSRMLS_CC); PHALCON_MM_RESTORE(); }
/** * 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 * @return mixed */ PHP_METHOD(Phalcon_Tag, getValue){ zval *name, *display_values = NULL, *default_value; zval *post = NULL, *post_name; zval *g0 = NULL; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_OBSERVE_VAR(display_values); phalcon_read_static_property(&display_values, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); eval_int = phalcon_array_isset(display_values, name); if (eval_int) { PHALCON_INIT_VAR(default_value); phalcon_array_fetch(&default_value, display_values, name, PH_NOISY_CC); RETURN_CCTOR(default_value); } else { phalcon_get_global(&g0, SL("_POST")+1 TSRMLS_CC); PHALCON_CPY_WRT(post, g0); eval_int = phalcon_array_isset(post, name); if (eval_int) { PHALCON_INIT_VAR(post_name); phalcon_array_fetch(&post_name, post, name, PH_NOISY_CC); RETURN_CCTOR(post_name); } } PHALCON_MM_RESTORE(); }
/** * Handles uncaught exceptions * * @param \Exception $exception * @return boolean */ PHP_METHOD(Phalcon_Debug, onUncaughtException){ zval *exception, *is_active = NULL, *message = NULL; zval *class_name, *css_sources, *escaped_message = NULL; zval *html, *version, *file, *line, *show_back_trace; zval *data_vars, *trace, *trace_item = NULL, *n = NULL, *html_item = NULL; zval *_REQUEST, *value = NULL, *key_request = NULL, *_SERVER; zval *key_server = NULL, *files, *key_file = NULL; zval *memory, *data_var = NULL, *key_var = NULL, *variable = NULL, *dumped_argument = NULL; zval *js_sources; HashTable *ah0, *ah1, *ah2, *ah3, *ah4; HashPosition hp0, hp1, hp2, hp3, hp4; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &exception); /** * Cancel the output buffer if active */ if (phalcon_ob_get_level(TSRMLS_C) > 0) { phalcon_ob_end_clean(TSRMLS_C); } PHALCON_OBS_VAR(is_active); phalcon_read_static_property(&is_active, SL("phalcon\\debug"), SL("_isActive") TSRMLS_CC); /** * Avoid that multiple exceptions being showed */ if (zend_is_true(is_active)) { PHALCON_INIT_VAR(message); phalcon_call_method(message, exception, "getmessage"); zend_print_zval(message, 0); } PHALCON_INIT_NVAR(is_active); ZVAL_BOOL(is_active, 1); /** * Globally block the debug component to avoid other exceptions must be shown */ phalcon_update_static_property(SL("phalcon\\debug"), SL("_isActive"), is_active TSRMLS_CC); PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, exception, 0 TSRMLS_CC); PHALCON_INIT_NVAR(message); phalcon_call_method(message, exception, "getmessage"); /** * CSS static sources to style the error presentation */ PHALCON_INIT_VAR(css_sources); phalcon_call_method(css_sources, this_ptr, "getcsssources"); /** * Escape the exception's message avoiding possible XSS injections? */ PHALCON_CPY_WRT(escaped_message, message); /** * Use the exception info as document's title */ PHALCON_INIT_VAR(html); PHALCON_CONCAT_SVSVS(html, "<html><head><title>", class_name, ": ", escaped_message, "</title>"); PHALCON_SCONCAT_VS(html, css_sources, "</head><body>"); /** * Get the version link */ PHALCON_INIT_VAR(version); phalcon_call_method(version, this_ptr, "getversion"); phalcon_concat_self(&html, version TSRMLS_CC); PHALCON_INIT_VAR(file); phalcon_call_method(file, exception, "getfile"); PHALCON_INIT_VAR(line); phalcon_call_method(line, exception, "getline"); /** * Main exception info */ phalcon_concat_self_str(&html, SL("<div align=\"center\"><div class=\"error-main\">") TSRMLS_CC); PHALCON_SCONCAT_SVSVS(html, "<h1>", class_name, ": ", escaped_message, "</h1>"); PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-file\">", file, " (", line, ")</span>"); phalcon_concat_self_str(&html, SL("</div>") TSRMLS_CC); PHALCON_OBS_VAR(show_back_trace); phalcon_read_property_this(&show_back_trace, this_ptr, SL("_showBackTrace"), PH_NOISY_CC); /** * Check if the developer wants to show the backtrace or not */ if (zend_is_true(show_back_trace)) { PHALCON_OBS_VAR(data_vars); phalcon_read_property_this(&data_vars, this_ptr, SL("_data"), PH_NOISY_CC); /** * Create the tabs in the page */ phalcon_concat_self_str(&html, SL("<div class=\"error-info\"><div id=\"tabs\"><ul>") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-1\">Backtrace</a></li>") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-2\">Request</a></li>") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-3\">Server</a></li>") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-4\">Included Files</a></li>") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-5\">Memory</a></li>") TSRMLS_CC); if (Z_TYPE_P(data_vars) == IS_ARRAY) { phalcon_concat_self_str(&html, SL("<li><a href=\"#error-tabs-6\">Variables</a></li>") TSRMLS_CC); } phalcon_concat_self_str(&html, SL("</ul>") TSRMLS_CC); /** * Print backtrace */ phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-1\"><table cellspacing=\"0\" align=\"center\" width=\"100%\">") TSRMLS_CC); PHALCON_INIT_VAR(trace); phalcon_call_method(trace, exception, "gettrace"); phalcon_is_iterable(trace, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { PHALCON_GET_HKEY(n, ah0, hp0); PHALCON_GET_HVALUE(trace_item); /** * Every line in the trace is rendered using 'showTraceItem' */ PHALCON_INIT_NVAR(html_item); phalcon_call_method_p2(html_item, this_ptr, "showtraceitem", n, trace_item); phalcon_concat_self(&html, html_item TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); } phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); /** * Print _REQUEST superglobal */ phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-2\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<tr><th>Key</th><th>Value</th></tr>") TSRMLS_CC); phalcon_get_global(&_REQUEST, SS("_REQUEST") TSRMLS_CC); phalcon_is_iterable(_REQUEST, &ah1, &hp1, 0, 0); while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { PHALCON_GET_HKEY(key_request, ah1, hp1); PHALCON_GET_HVALUE(value); PHALCON_SCONCAT_SVSVS(html, "<tr><td class=\"key\">", key_request, "</td><td>", value, "</td></tr>"); zend_hash_move_forward_ex(ah1, &hp1); } phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); /** * Print _SERVER superglobal */ phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-3\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<tr><th>Key</th><th>Value</th></tr>") TSRMLS_CC); phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); phalcon_is_iterable(_SERVER, &ah2, &hp2, 0, 0); while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { PHALCON_GET_HKEY(key_server, ah2, hp2); PHALCON_GET_HVALUE(value); PHALCON_SCONCAT_SVSVS(html, "<tr><td class=\"key\">", key_server, "</td><td>", value, "</td></tr>"); zend_hash_move_forward_ex(ah2, &hp2); } phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); /** * Show included files */ PHALCON_INIT_VAR(files); phalcon_call_func(files, "get_included_files"); phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-4\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<tr><th>#</th><th>Path</th></tr>") TSRMLS_CC); phalcon_is_iterable(files, &ah3, &hp3, 0, 0); while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { PHALCON_GET_HKEY(key_file, ah3, hp3); PHALCON_GET_HVALUE(value); PHALCON_SCONCAT_SVSVS(html, "<tr><td>", key_file, "</th><td>", value, "</td></tr>"); zend_hash_move_forward_ex(ah3, &hp3); } phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); /** * Memory usage */ PHALCON_INIT_VAR(memory); ZVAL_LONG(memory, zend_memory_usage(1 TSRMLS_CC)); phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-5\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC); PHALCON_SCONCAT_SVS(html, "<tr><th colspan=\"2\">Memory</th></tr><tr><td>Usage</td><td>", memory, "</td></tr>"); phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); /** * Print extra variables passed to the component */ if (Z_TYPE_P(data_vars) == IS_ARRAY) { phalcon_concat_self_str(&html, SL("<div id=\"error-tabs-6\"><table cellspacing=\"0\" align=\"center\" class=\"superglobal-detail\">") TSRMLS_CC); phalcon_concat_self_str(&html, SL("<tr><th>Key</th><th>Value</th></tr>") TSRMLS_CC); phalcon_is_iterable(data_vars, &ah4, &hp4, 0, 0); while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { PHALCON_GET_HKEY(key_var, ah4, hp4); PHALCON_GET_HVALUE(data_var); PHALCON_OBS_NVAR(variable); phalcon_array_fetch_long(&variable, data_var, 0, PH_NOISY); PHALCON_INIT_NVAR(dumped_argument); phalcon_call_method_p1(dumped_argument, this_ptr, "_getvardump", variable); PHALCON_SCONCAT_SVSVS(html, "<tr><td class=\"key\">", key_var, "</td><td>", dumped_argument, "</td></tr>"); zend_hash_move_forward_ex(ah4, &hp4); } phalcon_concat_self_str(&html, SL("</table></div>") TSRMLS_CC); } phalcon_concat_self_str(&html, SL("</div>") TSRMLS_CC); } /** * Get Javascript sources */ PHALCON_INIT_VAR(js_sources); phalcon_call_method(js_sources, this_ptr, "getjssources"); PHALCON_SCONCAT_VS(html, js_sources, "</div></body></html>"); /** * Print the HTML, @TODO, add an option to store the html */ zend_print_zval(html, 0); PHALCON_INIT_NVAR(is_active); ZVAL_BOOL(is_active, 0); /** * Unlock the exception renderer */ phalcon_update_static_property(SL("phalcon\\debug"), SL("_isActive"), is_active TSRMLS_CC); RETURN_MM_TRUE; }
/** * 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, *five, *doctype, *is_xhtml; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &type, ¶meters, &as_value); if (!as_value) { PHALCON_INIT_VAR(as_value); ZVAL_BOOL(as_value, 0); } 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); } PHALCON_INIT_VAR(value); if (PHALCON_IS_FALSE(as_value)) { if (!phalcon_array_isset_long(params, 0)) { PHALCON_OBS_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_OBS_NVAR(id); phalcon_array_fetch_long(&id, params, 0, PH_NOISY_CC); if (!phalcon_array_isset_string(params, SS("name"))) { phalcon_array_update_string(¶ms, SL("name"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } else { PHALCON_OBS_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); } } /** * Automatically assign the id if the name is not an array */ if (!phalcon_memnstr_str(id, SL("[") TSRMLS_CC)) { if (!phalcon_array_isset_string(params, SS("id"))) { phalcon_array_update_string(¶ms, SL("id"), &id, PH_COPY | PH_SEPARATE TSRMLS_CC); } } if (!phalcon_array_isset_string(params, SS("value"))) { PHALCON_CALL_SELF_PARAMS_2(value, this_ptr, "getvalue", id, params); phalcon_array_update_string(¶ms, SL("value"), &value, PH_COPY | PH_SEPARATE TSRMLS_CC); } } else { if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_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_IS_STRING(type, "checkbox")) { if (zend_is_true(value)) { phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE TSRMLS_CC); } } else { if (PHALCON_IS_STRING(type, "radio")) { 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_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); }
/** * 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 HTML tag * *<code> * echo Phalcon\Tag::tagHtml($name, $parameters, $selfClose, $onlyStart, $eol); *</code> * * @param string $tagName * @param array $parameters * @param boolean $selfClose * @param boolean $onlyStart * @param boolean $useEol * @return string */ PHP_METHOD(Phalcon_Tag, tagHtml){ zval *tag_name, *parameters = NULL, *self_close = NULL, *only_start = NULL; zval *use_eol = NULL, *params = NULL, *local_code, *value = NULL, *key = NULL; zval *five, *doctype, *is_xhtml, *eol; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 4, &tag_name, ¶meters, &self_close, &only_start, &use_eol); if (!parameters) { PHALCON_INIT_VAR(parameters); } if (!self_close) { PHALCON_INIT_VAR(self_close); ZVAL_BOOL(self_close, 0); } if (!only_start) { PHALCON_INIT_VAR(only_start); ZVAL_BOOL(only_start, 0); } if (!use_eol) { PHALCON_INIT_VAR(use_eol); ZVAL_BOOL(use_eol, 0); } 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); } PHALCON_INIT_VAR(local_code); PHALCON_CONCAT_SV(local_code, "<", tag_name); 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(local_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)) { if (zend_is_true(self_close)) { phalcon_concat_self_str(&local_code, SL(" />") TSRMLS_CC); } else { phalcon_concat_self_str(&local_code, SL(">") TSRMLS_CC); } } else { if (zend_is_true(only_start)) { phalcon_concat_self_str(&local_code, SL(">") TSRMLS_CC); } else { PHALCON_SCONCAT_SVS(local_code, "></", tag_name, ">"); } } if (zend_is_true(use_eol)) { PHALCON_INIT_VAR(eol); ZVAL_STRING(eol, PHP_EOL, 1); phalcon_concat_self(&local_code, eol TSRMLS_CC); } RETURN_CTOR(local_code); }
/** * 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 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); }