public final function render() { $this->lf = $this->layout !== null ? get::mvc_file('layout', $this->layout) : false; if ($this->lf === false && $this->layout != 'default') { $this->lf = get::mvc_file('layout', 'default'); } $this->vf = $this->view !== null ? get::mvc_file('view', $this->view) : false; if ($this->lf === false) { throw new Exception('Unable to find layout: ' . $this->layout); } if ($this->vf === false) { throw new Exception('Unable to find view: ' . $this->view); } if (isset($this->params) && is_array($this->params) && is::assoc_array($this->params)) { extract($this->params); } $this->helpers = get::helpers('template'); extract($this->helpers); ob_start(); require $this->vf; $munla_view_data = ob_get_contents(); ob_end_clean(); if (!isset($page_title)) { $page_title = config::TITLE_DEFAULT; } if (!isset($page_class)) { $page_class = preg_replace('[^a-zA-Z0-9-_]', '', str_replace('/', '-', $this->view)); } require $this->lf; }
/** * Autoload includes class files as they are needed. * * @param string $name The name of the class to load. */ public static function autoload($name) { $fileToRequire = false; if ($name == 'stdClassModel') { $fileToRequire = sprintf('%s%s.php', MUNLA_CORE_DIR, $name); } if ($fileToRequire === false && strlen($name) > 3 && substr($name, 0, 3) == 'xml') { $fileToRequire = sprintf('%sxml/%s.php', MUNLA_CORE_DIR, strtolower(substr($name, 3))); } if ($fileToRequire === false && in_array($name, self::$appDef)) { if (file_exists(sprintf('%s%s.php', MUNLA_APP_DIR, $name))) { $fileToRequire = sprintf('%s%s.php', MUNLA_APP_DIR, $name); } elseif (file_exists(sprintf('%s_%s.php', MUNLA_CORE_DIR, $name))) { $fileToRequire = sprintf('%s_%s.php', MUNLA_CORE_DIR, $name); } } if (is_string($fileToRequire)) { if (file_exists($fileToRequire)) { require $fileToRequire; } return; } if (file_exists(sprintf('%s%s.php', MUNLA_CORE_DIR, $name))) { require sprintf('%s%s.php', MUNLA_CORE_DIR, $name); return; } foreach (self::$types as $type) { if (substr($name, 0 - strlen($type)) == $type) { $file = get::mvc_file($type, substr($name, 0, 0 - strlen($type))); if ($file === false) { return; } require $file; return; } } }
/** * Gets the named view file given a route. * * @param array $route The route to find the view for. * * @return string|bool The name of the view for the route, or FALSE on failure. */ private static function route_view(array $route) { $file = get::mvc_file('view', sprintf('%s/%s', $route['controller'], $route['action'])); if ($file !== false) { return sprintf('%s/%s', $route['controller'], $route['action']); } $file = get::mvc_file('view', sprintf('%s/index', $route['controller'])); if ($file !== false) { return sprintf('%s/index', $route['controller']); } $file = get::mvc_file('view', $route['controller']); if ($file !== false) { return $route['controller']; } if ($route['controller'] == 'index' && $route['action'] != 'index') { $file = get::mvc_file('view', $route['action']); if ($file !== false) { return $route['action']; } } if (isset($route['params']) && is_array($route['params']) && count($route['params']) > 0) { $filename = sprintf('%s/%s/%s', $route['controller'], $route['action'], implode('/', $route['params'])); $file = get::mvc_file('view', $filename); if ($file !== false) { return $filename; } } return false; }
private function generateEmail(array $args) { if (count($args) < 1 || count($args) > 8) { throw new Exception('Wrong parameter count'); } $ord = array(1 => 'First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth'); $params = array('template' => null, 'to' => null, 'cc' => null, 'bcc' => null, 'subject' => null, 'message' => null, 'params' => null, 'prefix' => null, 'suffix' => null); $pkeys = array_keys($params); $argsC = $args; while (count($pkeys) > 0 && count($argsC) > 0) { $param = array_shift($pkeys); $arg = array_shift($argsC); if ($param == 'template') { if (!is_string($arg) || is::email($arg, true)) { $param = array_shift($pkeys); } elseif (is_string($arg)) { $params['template'] = $arg; } else { throw new InvalidArgumentException('First parameter expected to be a template or email address.'); } } if (in_array($param, array('to', 'cc', 'bcc'))) { if (isset($arg) && is_string($arg) && $arg != '') { if ($eml = is::email($arg, true)) { $params[$param] = $eml; } elseif ($param == 'to') { throw new InvalidArgumentException(sprintf('%s parameter expected to be the recipients email address (1).', $this->ord($pkeys, $params['template']))); } else { while ($param != 'subject') { $param = array_shift($pkeys); } } } elseif (is_array($arg)) { if ($eml = $this->getEmailAddressArray($arg)) { $params[$param] = $eml; } elseif ($param == 'to') { throw new InvalidArgumentException(sprintf('%s parameter expected to be the recipients email address (2).', $this->ord($pkeys, $params['template']))); } else { throw new InvalidArgumentException(sprintf('%s parameter expected to be the subject or an email address.', $this->ord($pkeys, $params['template']))); } } elseif (is::of_class($arg, 'emailAddressList')) { $params[$param] = $arg; } } if ($param == 'subject') { if (is_string($arg)) { $params[$param] = $arg; } else { throw new InvalidArgumentException(sprintf('%s parameter expected to be the subject.', $this->ord($pkeys, $params['template']))); } } if ($params['template']) { if ($param == 'message') { $param = array_shift($pkeys); } if ($param == 'params') { if (is_array($arg)) { $params[$param] = $arg; } else { throw new InvalidArgumentException(sprintf('%s parameter expected to be an array of values for the template.', $this->ord($pkeys, $params['template']))); } } elseif (in_array($param, array('prefix', 'suffix'))) { if (!isset($arg)) { $params[$param] = ''; } elseif (is_string($arg)) { $params[$param] = $arg; } else { throw new InvalidArgumentException(sprintf('%s parameter expected to be a %s string.', $this->ord($pkeys, $params['template']) . $param)); } } } elseif ($param == 'message') { if (is_string($arg)) { $params[$param] = $arg; } else { throw new InvalidArgumentException(sprintf('%s parameter expected to be the %s string.', $this->ord($pkeys, $params['template']) . $param)); } } } if ($params['template'] && (!isset($params['subject']) || !isset($params['params'])) || !isset($params['template']) && $params['subject'] && !isset($params['message']) && (!isset($this->mail) || !isset($this->mail['message']))) { throw new BadFunctionCallException('Unable to build a new message, missing parameters.'); } $emlKeys = array('to', 'cc', 'bcc'); $emailSet = false; $otherSet = false; foreach ($params as $k => $v) { if (isset($v)) { if (in_array($k, $emlKeys)) { $emailSet = true; } else { $otherSet = true; } } } if ($emailSet && !$otherSet && !isset($this->mail)) { throw new BadFunctionCallException('Unable to build a new message, only emails passed.'); } $mail = null; if (!isset($this->mail)) { //to, [cc], [bcc], [subject, message] //template, to, [cc], [bcc], [subject, params], [prefix], [suffix] $from = isset(config::$emailFrom) ? config::$emailFrom : 'noreply@' . get::domain(); if (is_string($from)) { if ($eml = is::email($from, false)) { $from = (string) $eml; } else { throw new DomainException('From address is not a valid email - see config.1'); } } elseif (is_array($from)) { if ($eml = $this->getEmailAddressArray($from)) { $from = $eml; } else { throw new DomainException('From address is not a valid email - see config'); } } else { throw new DomainException('From address is not a valid email - see config'); } $this->mail = array('from' => $from, 'images' => array()); $mail =& $this->mail; } else { $mail =& $this->mail; } $mail['to'] = $this->emlAddrArray($params['to']); $mail['cc'] = isset($params['cc']) ? $this->emlAddrArray($params['cc']) : null; $mail['bcc'] = isset($params['bcc']) ? $this->emlAddrArray($params['bcc']) : null; if (isset($params['subject'])) { $mail['subject'] = $params['subject']; } if (!isset($params['template']) && $params['message']) { $mail['message'] = $params['message']; $mail['images'] = array(); } elseif ($params['template']) { $file = get::mvc_file('email', $params['template']); if ($file === false) { throw new DomainException('Unable to find email template.'); } $mail['images'] = array(); if (array_key_exists('images', $params['params']) && is_array($params['params']['images'])) { $kill = array(); $imgs = array(); foreach ($params['params']['images'] as $img => $path) { $un = uniqid('PDP-CID-'); $localpath = get::file_path($path); if ($localpath === false) { $kill[] = $img; continue; } $size = getimagesize($localpath); if ($size === false) { $kill[] = $img; continue; } $imgs[$un]['data'] = chunk_split(base64_encode(file_get_contents($localpath))); $imgs[$un]['size'] = $size; $imgs[$un]['name'] = basename($localpath); $imgs[$un]['id'] = $un; $params['params']['images'][$img] = $un; } foreach ($kill as $k) { unset($params['params']['images'][$k]); } $mail['images'] = $imgs; $params['params']['images'] = new emailImageList($params['params']['images']); foreach ($params['params']['images'] as $img => $un) { if ($params['prefix']) { $params['prefix'] = str_replace('cid:' . $img, 'cid:' . $un, $params['prefix']); } if ($params['suffix']) { $params['suffix'] = str_replace('cid:' . $img, 'cid:' . $un, $params['suffix']); } } } $v = new emailView($file, $params['params']); $p = $params['prefix'] ? $params['prefix'] : ''; $s = $params['suffix'] ? $params['suffix'] : ''; $mail['message'] = $p . $v . $s; if (count($mail['images']) > 0 && array_key_exists('images', $params['params']) && is_object($params['params']['images'])) { $lst = $params['params']['images']; $imgs = $lst->toArray(); foreach ($lst->getKeys() as $k) { if (!$lst->wasAccessed($k) && array_key_exists($imgs[$k], $mail['images'])) { unset($mail['images'][$imgs[$k]]); } } } } return $this->mail; }