function smarty_block_app($params, $body, &$smarty) { if (empty($body)) { return; } if (!array_key_exists('name', $params)) { Error::info('Tag param error:', 'app标签必须有参数name!'); return; } if (array_key_exists('func', $params)) { $func = $params['func']; unset($params['func']); } else { $func = 'getList'; } $fields = implode(',', SwooleTemplate::get_fields($body)); global $php; $php->createModel($model); if (array_key_exists('titlelen', $params)) { $titlelen = $params['titlelen']; unset($params['titlelen']); $php->model->{$model}->select = str_replace('title', "substring( title, 1, {$titlelen} ) AS title", $fields); } else { $php->model->{$model}->select = $fields; } $data = call_user_func(array($php->model->{$model}, $func), $params); return SwooleTemplate::parse_loop($data, $body, $fields); }
function smarty_block_select($params, $body, &$smarty) { if (is_null($body)) { return; } global $php; $select = new Swoole\SelectDB($php->db); $select->put($params); return SwooleTemplate::parse_loop($select->getall(), $body); }
function smarty_block_app($params, $body, &$smarty) { if (empty($body)) { return; } global $php; $app = $php->createModel('App'); if (array_key_exists('name', $params)) { $app_config = $app->getConfig($params['name']); $app_instance = $app->getInstance(); unset($params['name']); } elseif (array_key_exists('typeid', $params)) { $cate = $php->createModel('Category'); $category = $cate->get($params['typeid']); $app_config = $app->getConfig($category['modelname']); $app_instance = $app->getInstance(); } else { return; } if (array_key_exists('func', $params)) { $func = $params['func']; unset($params['func']); } else { $func = 'getList'; } $stpl = new SwooleTemplate($php->db); $fields = implode(',', $stpl->get_fields($body)); if (empty($fields)) { return; } if (array_key_exists('titlelen', $params)) { $titlelen = $params['titlelen']; unset($params['titlelen']); $app_instance->select = str_replace('title', "substring( title, 1, {$titlelen} ) AS title,title as title_full", $fields); } if (strpos($fields, 'url') === false) { $fields .= ',url'; } $app_instance->select = $fields; $data = call_user_func(array($app_instance, $func), $params); return $stpl->parse_loop($data, $body, $fields); }
function smarty_block_category($params, $body, &$smarty) { if (empty($body)) { return; } global $php; $category_ins = $php->createModel('Category'); if (array_key_exists('app', $params)) { $app = $php->createModel('App'); $app_config = $app->getConfig($params['app']); $params['fid'] = $app_config['category']; unset($params['app']); } if (array_key_exists('func', $params)) { $func = $params['func']; unset($params['func']); } else { $func = 'getChild'; } $stpl = new SwooleTemplate($php->db); $data = call_user_func_array(array($category_ins, $func), $params); return $stpl->parse_loop($data, $body, $fields); }