public function __construct($viewData = array()) { // Get class-specific options $this->_config = Z::getConfig(__CLASS__); $this->_viewData = $viewData; $core = Z_Application::getInstance(); $this->_response =& $core->getResponse(); $this->_request =& $core->getRequest(); }
function smarty_function_currenturl($params, &$smarty) { $zcore = Z_Application::getInstance(); $url = $zcore->generateUrl(null, null, null, $_GET); $assign = empty($params['assign']); if (!$assign) { $smarty->assign($params['assign'], $url); } else { return $url; } }
function smarty_function_url($params, &$smarty) { $zcore = Z_Application::getInstance(); if (isset($params['controller'])) { $c = $params['controller']; } else { $c = 'index'; } if (isset($params['action'])) { $a = $params['action']; } else { $a = 'index'; } if (isset($params['module'])) { $m = $params['module']; } else { $m = 'default'; } if (isset($params['data'])) { $data = $params['data']; } else { $data = array(); } $assign = empty($params['assign']); unset($params['assign']); unset($params['module']); unset($params['action']); unset($params['data']); unset($params['controller']); $url = $zcore->generateUrl($a, $c, $m, $params); if (!$assign) { $smarty->assign($params['assign'], $url); } else { return $url; } }
<?php /** * Get an instance of our application */ $application = Z_Application::getInstance(); /** * Basic router */ $router = new Z_Router(); $router->addRoute('/:controller:', array()); $router->addRoute('/:controller:/:action:', array()); $router->addRoute('/:module:/:controller:/:action:', array()); $application->addRouter($router); /** * Configure Z_Asset (for usage of the publish smarty plugin) */ Z_Asset::getInstance(realpath(dirname(__FILE__) . '/../assets/') . Z_DS, realpath(dirname(__FILE__) . '/views/') . Z_DS, Z_Asset::$BIT_CHECK_DATETIME | Z_Asset::$BIT_CHECK_SIZE, 0755, $application->getWebRoot('/assets/')); /** * Hack for GoDaddy PHP hosting */ // $_SERVER["REQUEST_URI"] = str_replace($_SERVER["SCRIPT_NAME"], "", $_SERVER["REQUEST_URI"]);
public function generateUrl($action = 'index', $controller = 'index', $module = 'default', $data = array()) { if ($data == array()) { $data[''] = ''; } $application = Z_Application::getInstance(); $request = $application->GetRequest(); if ($action == null) { $action = $request->GetAction(); } if ($controller == null) { $controller = $request->GetController(); } if ($module == null) { $module = $request->GetModule(); } $url = false; $application = array('action', 'controller', 'module'); $coredata = array($action, $controller, $module); foreach ($this->_routes as $route) { $url = false; if (is_array($route)) { $mvc = $route[1]; $route = $route[0]; } else { $mvc = array(); $mvc['module'] = 'default'; } if (!isset($mvc['module'])) { $mvc['module'] = 'default'; } $data = array_merge($mvc, $data); $troute = $route; $cnt = 0; foreach ($application as $cpart) { $route = $troute; $dat = $coredata[$cnt]; $cnt++; $troute = str_replace(":{$cpart}:", $dat, $troute); if ($troute == $route && (!isset($mvc[$cpart]) || $mvc[$cpart] != $dat)) { $urlx = false; break; } $urlx = $troute; } if ($urlx == false) { continue; } $index = 0; foreach ($data as $k => $v) { $index++; $route = $troute; //if (in_array($k,array('controller', 'action', 'module'))) // continue; $routeOld = $troute; $troute = str_replace(":{$k}:", $v, $troute); if (count($mvc) != 3) { if ($troute == $route && !isset($mvc[$k]) || isset($mvc[$k]) && $mvc[$k] != $v) { $url = $troute; break; } } else { if ($routeOld == $troute) { continue; } if ($troute == $route && !isset($mvc[$k])) { $url = $troute; unset($data[$k]); break; } if ($index == count($data)) { $url = $troute; unset($data[$k]); break; } } /*if ($index == count($data)) { $url = $troute; die($troute); break; }*/ /*if ((($troute == $route) && (!isset($mvc[$k]))) || ((isset($mvc[$k]) && ($mvc[$k] != $v)))) { }*/ $url = false; } if ($url) { $pref = $_SERVER['SCRIPT_NAME']; $pref = dirname($pref); $pref = str_replace('\\', '/', $pref); if ($pref == '/') { $pref = ''; } $url = $pref . $url; } $url .= '?'; foreach ($data as $k => $v) { if (in_array($k, array('controller', 'action', 'module'))) { continue; } $url .= "{$k}=" . urlencode($v) . '&'; } if (substr($url, -1) == '&') { $url = substr($url, 0, strlen($url) - 1); } return $url; } $pref = $_SERVER['SCRIPT_NAME']; $pref = dirname($pref); if ($url) { $url = $pref . $url; } $url .= '?'; foreach ($data as $k => $v) { if (in_array($k, array('controller', 'action', 'module'))) { continue; } $url .= "{$k}=" . urlencode($v) . '&'; } if (substr($url, -1) == '&') { $url = substr($url, 0, strlen($url) - 1); } return $url; }