├── README.md
├── custom-view
├── README.md
├── application
│ ├── Bootstrap.php
│ ├── controllers
│ │ └── Index.php
│ ├── library
│ │ └── Smarty
│ │ │ ├── Adapter.php
│ │ │ ├── Config_File.class.php
│ │ │ ├── Smarty.class.php
│ │ │ ├── Smarty_Compiler.class.php
│ │ │ ├── debug.tpl
│ │ │ ├── internals
│ │ │ ├── core.assemble_plugin_filepath.php
│ │ │ ├── core.assign_smarty_interface.php
│ │ │ ├── core.create_dir_structure.php
│ │ │ ├── core.display_debug_console.php
│ │ │ ├── core.get_include_path.php
│ │ │ ├── core.get_microtime.php
│ │ │ ├── core.get_php_resource.php
│ │ │ ├── core.is_secure.php
│ │ │ ├── core.is_trusted.php
│ │ │ ├── core.load_plugins.php
│ │ │ ├── core.load_resource_plugin.php
│ │ │ ├── core.process_cached_inserts.php
│ │ │ ├── core.process_compiled_include.php
│ │ │ ├── core.read_cache_file.php
│ │ │ ├── core.rm_auto.php
│ │ │ ├── core.rmdir.php
│ │ │ ├── core.run_insert_handler.php
│ │ │ ├── core.smarty_include_php.php
│ │ │ ├── core.write_cache_file.php
│ │ │ ├── core.write_compiled_include.php
│ │ │ ├── core.write_compiled_resource.php
│ │ │ └── core.write_file.php
│ │ │ └── plugins
│ │ │ ├── block.privilege.php
│ │ │ ├── block.textformat.php
│ │ │ ├── compiler.assign.php
│ │ │ ├── function.assign_debug_info.php
│ │ │ ├── function.config_load.php
│ │ │ ├── function.counter.php
│ │ │ ├── function.cycle.php
│ │ │ ├── function.debug.php
│ │ │ ├── function.eval.php
│ │ │ ├── function.fetch.php
│ │ │ ├── function.html_checkboxes.php
│ │ │ ├── function.html_image.php
│ │ │ ├── function.html_options.php
│ │ │ ├── function.html_radios.php
│ │ │ ├── function.html_select_date.php
│ │ │ ├── function.html_select_time.php
│ │ │ ├── function.html_table.php
│ │ │ ├── function.mailto.php
│ │ │ ├── function.math.php
│ │ │ ├── function.popup.php
│ │ │ ├── function.popup_init.php
│ │ │ ├── modifier.capitalize.php
│ │ │ ├── modifier.cat.php
│ │ │ ├── modifier.count_characters.php
│ │ │ ├── modifier.count_paragraphs.php
│ │ │ ├── modifier.count_sentences.php
│ │ │ ├── modifier.count_words.php
│ │ │ ├── modifier.date_format.php
│ │ │ ├── modifier.debug_print_var.php
│ │ │ ├── modifier.default.php
│ │ │ ├── modifier.escape.php
│ │ │ ├── modifier.indent.php
│ │ │ ├── modifier.lower.php
│ │ │ ├── modifier.nl2br.php
│ │ │ ├── modifier.regex_replace.php
│ │ │ ├── modifier.replace.php
│ │ │ ├── modifier.spacify.php
│ │ │ ├── modifier.string_format.php
│ │ │ ├── modifier.strip.php
│ │ │ ├── modifier.strip_tags.php
│ │ │ ├── modifier.truncate.php
│ │ │ ├── modifier.upper.php
│ │ │ ├── modifier.wordwrap.php
│ │ │ ├── outputfilter.trimwhitespace.php
│ │ │ ├── shared.escape_special_chars.php
│ │ │ └── shared.make_timestamp.php
│ └── views
│ │ └── index
│ │ └── index.tpl
├── conf
│ └── application.ini
└── index.php
└── yaf-light-frame
├── README.md
├── application
├── Bootstrap.php
├── controllers
│ ├── Base.php
│ ├── Error.php
│ └── Index.php
├── library
│ ├── Common
│ │ ├── Logger
│ │ │ └── Helper.php
│ │ ├── Request
│ │ │ └── Helper.php
│ │ ├── Template.php
│ │ └── Util.php
│ └── Db
│ │ ├── DbInterface.php
│ │ ├── Factory.php
│ │ └── Mysql.php
├── models
│ ├── BaseModel.php
│ └── IndexModel.php
└── views
│ ├── error
│ └── error.phtml
│ └── index
│ └── index.phtml
├── conf
├── application.ini
└── auto.php
├── index.php
└── log
├── Yaf_Log
└── yaf.log
/README.md:
--------------------------------------------------------------------------------
1 | yaf-examples
2 | ============
3 |
4 | examples for php-yaf usage
--------------------------------------------------------------------------------
/custom-view/README.md:
--------------------------------------------------------------------------------
1 | Custom view engine example
2 | ============
3 |
4 | examples for using a custom view engine(smarty) with yaf
5 |
--------------------------------------------------------------------------------
/custom-view/application/Bootstrap.php:
--------------------------------------------------------------------------------
1 | registerLocalNamespace(array(
7 | 'Smarty',
8 | ));
9 | }
10 |
11 | public function _initSmarty(Yaf_Dispatcher $dispatcher) {
12 | /* init smarty view engine */
13 | Yaf_Loader::import("Smarty/Adapter.php");
14 | $smarty = new Smarty_Adapter(null, Yaf_Application::app()->getConfig()->smarty);
15 | $dispatcher->setView($smarty);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/custom-view/application/controllers/Index.php:
--------------------------------------------------------------------------------
1 | getView()->assign("body", "Hello Wrold
");
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/custom-view/application/library/Smarty/Adapter.php:
--------------------------------------------------------------------------------
1 | _smarty = new Smarty;
29 |
30 | if (null !== $tmplPath) {
31 | $this->setScriptPath($tmplPath);
32 | }
33 |
34 | foreach ($extraParams as $key => $value) {
35 | $this->_smarty->$key = $value;
36 | }
37 | }
38 |
39 | /**
40 | * Return the template engine object
41 | *
42 | * @return Smarty
43 | */
44 | public function getEngine() {
45 | return $this->_smarty;
46 | }
47 |
48 | /**
49 | * Set the path to the templates
50 | *
51 | * @param string $path The directory to set as the path.
52 | * @return void
53 | */
54 | public function setScriptPath($path)
55 | {
56 | if (is_readable($path)) {
57 | $this->_smarty->template_dir = $path;
58 | return;
59 | }
60 |
61 | throw new Exception('Invalid path provided');
62 | }
63 |
64 | /**
65 | * Retrieve the current template directory
66 | *
67 | * @return string
68 | */
69 | public function getScriptPath()
70 | {
71 | return $this->_smarty->template_dir;
72 | }
73 |
74 | /**
75 | * Alias for setScriptPath
76 | *
77 | * @param string $path
78 | * @param string $prefix Unused
79 | * @return void
80 | */
81 | public function setBasePath($path, $prefix = 'Zend_View')
82 | {
83 | return $this->setScriptPath($path);
84 | }
85 |
86 | /**
87 | * Alias for setScriptPath
88 | *
89 | * @param string $path
90 | * @param string $prefix Unused
91 | * @return void
92 | */
93 | public function addBasePath($path, $prefix = 'Zend_View')
94 | {
95 | return $this->setScriptPath($path);
96 | }
97 |
98 | /**
99 | * Assign a variable to the template
100 | *
101 | * @param string $key The variable name.
102 | * @param mixed $val The variable value.
103 | * @return void
104 | */
105 | public function __set($key, $val)
106 | {
107 | $this->_smarty->assign($key, $val);
108 | }
109 |
110 | /**
111 | * Allows testing with empty() and isset() to work
112 | *
113 | * @param string $key
114 | * @return boolean
115 | */
116 | public function __isset($key)
117 | {
118 | return (null !== $this->_smarty->get_template_vars($key));
119 | }
120 |
121 | /**
122 | * Allows unset() on object properties to work
123 | *
124 | * @param string $key
125 | * @return void
126 | */
127 | public function __unset($key)
128 | {
129 | $this->_smarty->clear_assign($key);
130 | }
131 |
132 | /**
133 | * Assign variables to the template
134 | *
135 | * Allows setting a specific key to the specified value, OR passing
136 | * an array of key => value pairs to set en masse.
137 | *
138 | * @see __set()
139 | * @param string|array $spec The assignment strategy to use (key or
140 | * array of key => value pairs)
141 | * @param mixed $value (Optional) If assigning a named variable,
142 | * use this as the value.
143 | * @return void
144 | */
145 | public function assign($spec, $value = null) {
146 | if (is_array($spec)) {
147 | $this->_smarty->assign($spec);
148 | return;
149 | }
150 |
151 | $this->_smarty->assign($spec, $value);
152 | }
153 |
154 | /**
155 | * Clear all assigned variables
156 | *
157 | * Clears all variables assigned to Zend_View either via
158 | * {@link assign()} or property overloading
159 | * ({@link __get()}/{@link __set()}).
160 | *
161 | * @return void
162 | */
163 | public function clearVars() {
164 | $this->_smarty->clear_all_assign();
165 | }
166 |
167 | /**
168 | * Processes a template and returns the output.
169 | *
170 | * @param string $name The template to process.
171 | * @return string The output.
172 | */
173 | public function render($name, $value = NULL) {
174 | return $this->_smarty->fetch($name);
175 | }
176 |
177 | public function display($name, $value = NULL) {
178 | echo $this->_smarty->fetch($name);
179 | }
180 |
181 | }
182 |
183 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
184 | ?>
185 |
--------------------------------------------------------------------------------
/custom-view/application/library/Smarty/debug.tpl:
--------------------------------------------------------------------------------
1 | {* Smarty *}
2 | {* debug.tpl, last updated version 2.1.0 *}
3 | {assign_debug_info}
4 | {capture assign=debug_output}
5 |
6 |
7 |
no templates included
112 | {/section} 113 |{ldelim}${$_debug_keys[vars]|escape:'html'}{rdelim} | 121 |{$_debug_vals[vars]|@debug_print_var} |
---|---|
no template variables assigned |
{ldelim}#{$_debug_config_keys[config_vars]|escape:'html'}#{rdelim} | 133 |{$_debug_config_vals[config_vars]|@debug_print_var} |
---|---|
no config vars assigned |
19 | * Params: style: string (email) 20 | * indent: integer (0) 21 | * wrap: integer (80) 22 | * wrap_char string ("\n") 23 | * indent_char: string (" ") 24 | * wrap_boundary: boolean (true) 25 | *26 | * @author Monte Ohrt
20 | * array('file' => required config file name, 21 | * 'section' => optional config file section to load 22 | * 'scope' => local/parent/global 23 | * 'global' => overrides scope, setting to parent if true) 24 | *25 | * @param Smarty 26 | */ 27 | function smarty_function_config_load($params, &$smarty) 28 | { 29 | if ($smarty->debugging) { 30 | $_params = array(); 31 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 32 | $_debug_start_time = smarty_core_get_microtime($_params, $smarty); 33 | } 34 | 35 | $_file = isset($params['file']) ? $smarty->_dequote($params['file']) : null; 36 | $_section = isset($params['section']) ? $smarty->_dequote($params['section']) : null; 37 | $_scope = isset($params['scope']) ? $smarty->_dequote($params['scope']) : 'global'; 38 | $_global = isset($params['global']) ? $smarty->_dequote($params['global']) : false; 39 | 40 | if (!isset($_file) || strlen($_file) == 0) { 41 | $smarty->trigger_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__); 42 | } 43 | 44 | if (isset($_scope)) { 45 | if ($_scope != 'local' && 46 | $_scope != 'parent' && 47 | $_scope != 'global') { 48 | $smarty->trigger_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__); 49 | } 50 | } else { 51 | if ($_global) { 52 | $_scope = 'parent'; 53 | } else { 54 | $_scope = 'local'; 55 | } 56 | } 57 | 58 | $_params = array('resource_name' => $_file, 59 | 'resource_base_path' => $smarty->config_dir, 60 | 'get_source' => false); 61 | $smarty->_parse_resource_name($_params); 62 | $_file_path = $_params['resource_type'] . ':' . $_params['resource_name']; 63 | if (isset($_section)) 64 | $_compile_file = $smarty->_get_compile_path($_file_path.'|'.$_section); 65 | else 66 | $_compile_file = $smarty->_get_compile_path($_file_path); 67 | 68 | if($smarty->force_compile || !file_exists($_compile_file)) { 69 | $_compile = true; 70 | } elseif ($smarty->compile_check) { 71 | $_params = array('resource_name' => $_file, 72 | 'resource_base_path' => $smarty->config_dir, 73 | 'get_source' => false); 74 | $_compile = $smarty->_fetch_resource_info($_params) && 75 | $_params['resource_timestamp'] > filemtime($_compile_file); 76 | } else { 77 | $_compile = false; 78 | } 79 | 80 | if($_compile) { 81 | // compile config file 82 | if(!is_object($smarty->_conf_obj)) { 83 | require_once SMARTY_DIR . $smarty->config_class . '.class.php'; 84 | $smarty->_conf_obj = new $smarty->config_class(); 85 | $smarty->_conf_obj->overwrite = $smarty->config_overwrite; 86 | $smarty->_conf_obj->booleanize = $smarty->config_booleanize; 87 | $smarty->_conf_obj->read_hidden = $smarty->config_read_hidden; 88 | $smarty->_conf_obj->fix_newlines = $smarty->config_fix_newlines; 89 | } 90 | 91 | $_params = array('resource_name' => $_file, 92 | 'resource_base_path' => $smarty->config_dir, 93 | $_params['get_source'] = true); 94 | if (!$smarty->_fetch_resource_info($_params)) { 95 | return; 96 | } 97 | $smarty->_conf_obj->set_file_contents($_file, $_params['source_content']); 98 | $_config_vars = array_merge($smarty->_conf_obj->get($_file), 99 | $smarty->_conf_obj->get($_file, $_section)); 100 | if(function_exists('var_export')) { 101 | $_output = ''; 102 | } else { 103 | $_output = ''\\\'', '\\'=>'\\\\')) . '\'); ?>'; 104 | } 105 | $_params = (array('compile_path' => $_compile_file, 'compiled_content' => $_output, 'resource_timestamp' => $_params['resource_timestamp'])); 106 | require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php'); 107 | smarty_core_write_compiled_resource($_params, $smarty); 108 | } else { 109 | include($_compile_file); 110 | } 111 | 112 | if ($smarty->caching) { 113 | $smarty->_cache_info['config'][$_file] = true; 114 | } 115 | 116 | $smarty->_config[0]['vars'] = @array_merge($smarty->_config[0]['vars'], $_config_vars); 117 | $smarty->_config[0]['files'][$_file] = true; 118 | 119 | if ($_scope == 'parent') { 120 | $smarty->_config[1]['vars'] = @array_merge($smarty->_config[1]['vars'], $_config_vars); 121 | $smarty->_config[1]['files'][$_file] = true; 122 | } else if ($_scope == 'global') { 123 | for ($i = 1, $for_max = count($smarty->_config); $i < $for_max; $i++) { 124 | $smarty->_config[$i]['vars'] = @array_merge($smarty->_config[$i]['vars'], $_config_vars); 125 | $smarty->_config[$i]['files'][$_file] = true; 126 | } 127 | } 128 | 129 | if ($smarty->debugging) { 130 | $_params = array(); 131 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 132 | $smarty->_smarty_debug_info[] = array('type' => 'config', 133 | 'filename' => $_file.' ['.$_section.'] '.$_scope, 134 | 'depth' => $smarty->_inclusion_depth, 135 | 'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time); 136 | } 137 | 138 | } 139 | 140 | /* vim: set expandtab: */ 141 | 142 | ?> 143 | -------------------------------------------------------------------------------- /custom-view/application/library/Smarty/plugins/function.counter.php: -------------------------------------------------------------------------------- 1 | 13 | * Name: counter
29 | * {cycle values="#eeeeee,#d0d0d0d"} 30 | * {cycle name=row values="one,two,three" reset=true} 31 | * {cycle name=row} 32 | *33 | * @link http://smarty.php.net/manual/en/language.function.cycle.php {cycle} 34 | * (Smarty online manual) 35 | * @author Monte Ohrt
27 | * {html_checkboxes values=$ids output=$names} 28 | * {html_checkboxes values=$ids name='box' separator='31 | * @link http://smarty.php.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} 32 | * (Smarty online manual) 33 | * @author Christopher Kvarme
' output=$names} 29 | * {html_checkboxes values=$ids checked=$checked separator='
' output=$names} 30 | *