Skip to content

Commit

Permalink
Adding mobile support.
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Mar 8, 2013
1 parent 5d0c2e8 commit 49b6b4a
Show file tree
Hide file tree
Showing 18 changed files with 232 additions and 27 deletions.
39 changes: 39 additions & 0 deletions application/classes/Controller/Mobile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/* This file is part of the MuMVC Project (http://alex.413x31.com/Projects/MuMVC)
* Copyright (c) 2013 MuMVC Team (http://alex.413x31.com/Projects/MuMVC/Team)
* Full copyright and license information can be found in the file license.txt or
at http://alex.413x31.com/Projects/MuMVC/licence.txt */

namespace Application\Controller;

use MuMVC\ActionController;
use MuMVC\Registry;

class Mobile extends ActionController {
public function before() {
$this->layout = 'layout_mobile.tpl';
parent::before();
$this->addCrumb('Mobile', '/mobile/');
}
public function indexAction() { }
public function error($code, $message) {
$this->action = 'error' . $code;
$this->before();
if ($message) {
$this->template->asigna('MESSAGE', $message);
}
}

public function after() {
$this->getBreadcrumbs();
return parent::after();
}

public function getBreadcrumbs() {
foreach(self::$crumbs as $crumb) {
$this->layout->asigna('description', $crumb[0]);
$this->layout->asigna('link', $crumb[1]);
$this->layout->parse('crumb');
}
}
}
26 changes: 26 additions & 0 deletions application/classes/Controller/Mobile/Mumvc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/* This file is part of the MuMVC Project (http://alex.413x31.com/Projects/MuMVC)
* Copyright (c) 2013 MuMVC Team (http://alex.413x31.com/Projects/MuMVC/Team)
* Full copyright and license information can be found in the file license.txt or
at http://alex.413x31.com/Projects/MuMVC/licence.txt */

namespace Application\Controller\Mobile;

use Application\Controller\Mobile;

class Mumvc extends Mobile {
public function __construct() {
$this->controller = 'Mobile/Mumvc';
parent::__construct();
}
public function before() {
parent::before();
$this->addCrumb('MuMVC', '/mobile/MuMVC/');
}
public function index() { }
public function error($code, $message) {
$this->controller = 'Mobile';
$this->action = 'error' . $code;
parent::error($code, $message);
}
}
1 change: 1 addition & 0 deletions application/views/layout.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<li><a href="/assets/pdf/CV_en.pdf">&otimes; English C.V</a></li>
<li><a href="/assets/pdf/CV_es.pdf">&otimes; Spanish C.V</a></li>
<li><a href="/MuMVC/">&otimes; &mu;MVC</a></li>
<li style="float: right;"><a href="/mobile/">Mobile version</a></li>
</ul>
</div>
<div class="box">
Expand Down
50 changes: 50 additions & 0 deletions application/views/layout_mobile.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Alexey Serikov Kompaniets Online</title>
<link rel="stylesheet" href="/assets/css/jquery.mobile.custom.min.css" />
<link rel="stylesheet" href="/assets/css/jquery.mobile.custom.structure.css" />
<link rel="stylesheet" href="/assets/css/jquery.mobile.custom.theme.css" />
<script src="/assets/js/jquery.js"></script>
<script src="/assets/js/jquery.mobile.custom.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div data-role="page" data-theme="a">
<div data-role="header" data-divider-theme="b">
<h1>Alexey Serikov Kompaniets Online</h1>
</div>
<div data-role="navbar" position="fixed">
<ul>
<li><a href="/mobile/">Home</a>
<li><a href="/old/">Old site</a></li>
<li><a href="/mobile/MuMVC/">MuMVC</a>
<li><a href="/assets/pdf/CV_es.pdf">Spanish C.V.</a></li>
<li><a href="/assets/pdf/CV_en.pdf">English C.V.</a></li>
</ul>

<ul data-role="navbar" data-inset="true" data-divider-theme="b">
{block name="crumb"}
<li data-theme="a"><a href="{$link}">{$description}</a></li>
{/block}
</ul>


</div>

<div data-role="content">

{$CONTENT}
<ul data-role="listview" data-inset="true" data-divider-theme="b">
</ul>
<ul data-role="listview" data-inset="true" data-divider-theme="d">
<li data-role="list-divider">Projects</li>
<li><a href="/mobile/MuMVC/">MuMVC</a></li>
</ul>
</div>
<div data-role="footer" data-position="fixed">
</div>
</div>
</body>
</html>
2 changes: 2 additions & 0 deletions application/views/mobile/error404.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>HTTP/404: Page not found</h1>
<p>Action {$MESSAGE} you were looking for couldn't be found on this server.</p>
Empty file.
21 changes: 21 additions & 0 deletions application/views/mobile/mumvc/index.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<h1>About &mu;MVC</h1>
<p>&mu;MVC as it is at the moment
<h3>Features</h3>
<ul>
<li>Fully fledged (rh)MVC system, whatever that means.<a href="/mobile/MuMVC/rhMVC/">*</a></li>
<li>8 bits template system</li>
</ul>
<h3>Missing features</h3>
<p>Features that won't be missed.</p>
<ul>
<li>Dependency Injection</li>
<li>ASCII art and console commands</li>
</ul>
<h3><strike>Filosophy</strike> Methodology</h3>
<h3>Code</h3>
<ul>
<li>Repository: <a href="http://git.413x31.com/gitweb/?p=mumvc.git;a=summary">gitweb</a></li>
<li>Conventions:</li>
</ul>
<h3>Team</h3>
<p>Please see <a href="team">team page</a>.</p>
Empty file.
2 changes: 2 additions & 0 deletions application/views/mobile/mumvc/team.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h3><i>&mu;</i>MVC Team</h3>
<p>Project leader: </p><b>Alexey Serikov Kompaniets</b> &lt; [email protected] &gt;</b>
16 changes: 13 additions & 3 deletions application/views/mumvc/index.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<h1>About &mu;MVC
<h3>Methodology</h3>
<h3>Filosophy</h3>
<h1>About &mu;MVC</h1>
<p>&mu;MVC as it is at the moment
<h3>Features</h3>
<ul>
</ul>
<h3>Missing features</h3>
<p>Features that won't be missed.</p>
<ul>
<li>Dependency Injection</li>
<li>ASCII art and console commands</li>
</ul>
<p>The following is a shortlist of features that
<h3><strike>Filosophy</strike> Methodology</h3>
<h3>Code</h3>
<ul>
<li>Repository: <a href="http://git.413x31.com/gitweb/?p=mumvc.git;a=summary">gitweb</a></li>
Expand Down
2 changes: 2 additions & 0 deletions htdocs/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ h1 {
}
.box {
padding: 10px; border-radius: 10px; margin: auto; margin-top: 10px; width: 800px; height: 500px; background-color: white;
overflow-y: auto;
overflow-x: hidden;
}
.footer {
padding: 10px; border-radius: 10px; margin: auto; margin-top: 10px; width: 800px; background-color: #ffe;
Expand Down
17 changes: 11 additions & 6 deletions htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
$mt1 = microtime(true);

require_once __DIR__ . '/../modules/MuMVC/Root.php';
# require_once __DIR__ . '/../modules/MuCMS/autoload.php';

use MuMVC\Route;
use MuMVC\Cache;
use MuMVC\Controller;
use MuMVC\Registry;
use MuCMS\Cms;

Registry::instance()->set('caching', true);
Registry::instance()->set('caching_routes', true);
Registry::instance()->set('caching', false);
Registry::instance()->set('caching_routes', false);

try {
Controller::instance()->dispatch();
Expand All @@ -18,7 +20,10 @@
echo "<p>{$e->getMessage()}</p>";
}

echo '<div class="footer">' .
'Executed in ' . ( microtime(true) - $mt1 ) . '<br>' .
'Memory peak usage: ' . memory_get_peak_usage() .
'</div>';
if (! (Controller::instance()->getController() instanceof \Application\Controller\Mobile)) {
echo '<div class="footer">';
var_dump(Controller::instance()->getRoute()->getCurrent());
echo '<br>Executed in ' . ( microtime(true) - $mt1 ) . '<br>' .
'Memory peak usage: ' . memory_get_peak_usage() .
'</div>';
}
39 changes: 28 additions & 11 deletions modules/MuMVC/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,36 @@
namespace MuMVC;

abstract class ActionController {
/**
* Controller alias that's used to find propper view etc
* @var unknown
*/
protected $controller;
protected $action;
protected $template;
protected $layout;
protected $params;
protected $auto_render = TRUE;
protected static $crumbs = array();

public function __construct($action='default', $params=array(), $controller=FALSE) {
$this->controller = $controller ? $controller : get_class($this);
public function __construct($action='index', $params=array(), $controller=FALSE) {
if (!isset($this->controller)) {
$controller = $controller ? $controller : get_class($this);
$controller = str_replace(APP_NAMESPACE . '\Controller\\', '', $controller);
$this->controller = $controller;
}
$this->action = $action;
$this->params = $params;
}

protected function findTemplate($templatePath=null) {
if ($templatePath == null) {
$controllerName = $this->controller;
if (($pos = strrpos($controllerName, '\\')) !== false) {
$controllerName = substr($controllerName, $pos+1);
}
$controllerName = str_replace('\\', '/', $controllerName);
$controllerName = strtolower($controllerName);
$templatePath = APP_PATH . '/views/' . $controllerName . '/' . $this->action . '.tpl';
$templatePath = $controllerName . '/' . $this->action . '.tpl';
}
if (file_exists($templatePath)) {
if (file_exists(APP_VIEW . '/' . $templatePath)) {
return $templatePath;
}
return FALSE;
Expand All @@ -38,15 +45,25 @@ public function before() {
if ($this->auto_render) {
$templateFile = $this->findTemplate();
if ($templateFile) {
$this->template = new Template($this->findTemplate());
$this->template = new Template($templateFile);
}
if ($this->layout) {
$this->layout = new Template($this->layout);
}
else {
$this->layout = new Template( APP_DEFAULT_LAYOUT);
}
$this->layout = TPL_DEFAULT_LAYOUT;
}
}
public function addCrumb( $string, $link) {
array_push(ActionController::$crumbs, array($string, $link));
}
public function after() {
if ($this->auto_render) {
$tpl_layout = new Template($this->layout);
$tpl_layout->asigna('CONTENT', $this->template->render());
$tpl_layout = $this->layout;
if (is_object($this->template)) {
$tpl_layout->asigna('CONTENT', $this->template->render());
}
return $tpl_layout->render();
}
}
Expand Down
16 changes: 15 additions & 1 deletion modules/MuMVC/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,24 @@ public function cacheSave() {
public function cacheLoad($data) {
$this->_output = $data;
}
public function getRoute() {
return $this->route;
}
public function dispatch() {
$route = $this->route->parse();

if (strpos($route['controller'], '\\') === FALSE) {
$controller = ucfirst($route['controller']);
}
else {
$spacesIn = explode('\\', $route['controller']);
$spacesOut= array();
foreach($spacesIn as $key => $space) { $spacesOut[] = ucfirst($space); }
$controller = implode('\\', $spacesOut);
}

try {
$actionControllerString = 'Application\\Controller\\' . ucfirst($route['controller']);
$actionControllerString = 'Application\\Controller\\' . $controller;
$actionController = new $actionControllerString( $route['action'] );
} catch ( AutoloadException $e) {
$actionDefaultControllerString = 'Application\\Controller\\' . ucfirst($this->route->getDefault('controller'));
Expand Down
4 changes: 4 additions & 0 deletions modules/MuMVC/Db/MysqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

use MuMVC\Root;
use Exception;
use mysql_connect;
use mysql_query;
use mysql_fetch_assoc;
use mysql_free_result;

class MysqlDriver extends Root implements IDbDriver {
private $connection;
Expand Down
3 changes: 3 additions & 0 deletions modules/MuMVC/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
define('APP_ROOT', realpath( __DIR__ . '/../../application' ));
define('APP_PATH', realpath( __DIR__ . '/../../application' ));
define('APP_DEFAULT_TPL', realpath( APP_PATH . '/views/default/default.tpl' ));
define('APP_VIEW', realpath( __DIR__ . '/../../application/views'));
define('APP_DEFAULT_LAYOUT', 'layout.tpl');
define('APP_NAMESPACE', 'Application');

require_once(__DIR__ . '/Cache.php');
require_once(__DIR__ . '/Db.php');
Expand Down
10 changes: 8 additions & 2 deletions modules/MuMVC/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Route {
protected $routePatterns = array(
'mumvc' => array(
'/^\/MuMVC(\/(?P<action>[a-z]+))*/', array('controller' => 'mumvc')),
'mobile_mumvc' => array(
'/^\/mobile\/MuMVC(\/(?P<action>[a-z]+))*/', array('controller' => 'mobile\mumvc')),

'default' => array(
'/^\/(?P<controller>[a-z]+)(\/(?P<action>[a-z]+)){0,1}(\/(?<id>[0-9]+)){0,1}/',
//default controller and action
Expand Down Expand Up @@ -53,7 +56,7 @@ public function parse($path=null) {
$path = preg_replace('/[^a-zA-Z0-9_\/]/', '', $path);

if (isset(Route::$parsedRoutes[$path])) {
return Route::$parsedRoutes[$path];
return $this->currentRoute = Route::$parsedRoutes[$path];
}

$this->currentPath = $path;
Expand Down Expand Up @@ -106,4 +109,7 @@ public function persist() {
Cache::instance()->store( MUMVC_ROUTES_CACHE_KEY, Route::$parsedRoutes);
}
}
}
public function getCurrent() {
return $this->currentRoute;
}
}
11 changes: 7 additions & 4 deletions modules/MuMVC/Template.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?php
namespace MuMVC;

define('TPL_DEFAULT_LAYOUT', APP_PATH . '/views/layout.tpl');

class Template {
var $vars, $blocks, $raw_blocks, $raw;
var $vars, $blocks, $raw_blocks, $raw, $file;

// Construtor
function __construct ($file) {
$this->setFile($file);
}
public function setFile($file) {
if (is_readable($file)) {
$file = str_replace('\\', '/', $file);
if (!is_file($file)) {
$file = APP_VIEW . '/' . $file;
}
if (is_file($file)) {
$fh = fopen($file, 'r');
$this->init($fh);
$this->file = $file;
}
else {
throw new \Exception("Template file < $file > couldn't be found.");
Expand Down

0 comments on commit 49b6b4a

Please sign in to comment.