Search.php
play.php
{% *Copyright: Lorenzo D. Alipio* %} {% *file: web/themes/default/play.tpl* %} {% extends file="web/themes/default/main.tpl" %} {% block name=title %}Playing {% $content.title %}{% /block %} {% block name=meta %}{% /block %} {% block name=metad %}{% /block %} {% block name=general %} <div class="span8"> <h4>Playing {% $content.title %}</h4> <iframe id="youtube" width="100%" height="480" src="//www.youtube.com/embed/{% $content.v_id %}" frameborder="0" allowfullscreen></iframe> <br/> <!-- Related Videos --> <div id="related"> <h3 class="title">Related Videos</h3> <ul> {% section name=item loop=$content.related %} <li> <a href="javascript:loadThisVideo('youtube','http://www.youtube.com/embed/{% $content.related[item].v_id %}?rel=0&hd=1')"><img src="{% $content.related[item].thumb %}" title="{% $content.related[item].title %}"/></a> </li> {% /section %} </ul> </div> <!-- end of related --> </div> <div class="span4"> <h5 class="title">Recommended Videos</h5> <div id = "thumb3"> <ul> {% section name=item loop=$content.video %} <li> <a href="javascript:loadThisVideo('youtube','http://www.youtube.com/embed/{% $content.video[item].v_id %}?rel=0&hd=1')"><img src="{% $content.video[item].thumb %}"/></a> <br/> {% $content.video[item].title %} <br/> </li> {% /section %} </ul> </div> </div> {% /block %}
{% *Copyright: Lorenzo D. Alipio* %} {% extends file="web/themes/default/main.tpl" %} {% block name=title %}About Us{% /block %} {% block name=meta %}{% /block %} {% block name=metad %}{% /block %} {% block name=general %} {% $content.about %} {% $content.name %} {% $content.email %} {% /block %}
{% extends file="web/themes/green/main.tpl" %} {% block name=title %}Music Video Categories{% /block %} {% block name=meta %}{% /block %} {% block name=metad %}{% /block %} {% block name=general %} <h1 class="title" >{% $content.categoryHeader %}</h1>{% /block %}{% foreach from=$content.cat item=cat %}
- {% $cat|strip %}
{% /foreach %}
{% *2013 Copyright Lorenzo D. Alipio <ldalipio@msn.com>* %} {% extends file="web/themes/default/main.tpl" %} {% block name=title %}About Us{% /block %} {% block name=meta %}{% /block %} {% block name=metad %}{% /block %} {% block name=general %} <div class="span8"> <h4 class="title" >About this Demo Script</h1> {% $content.content['first_p'] %} <ul> {% foreach $content.content['lists'] as $item %} <li>{% $item %}</li> {% /foreach %} </ul> <h5 class="title">Additional Information</h5> <br/> {% $content.content['more_info'] %} <br/> </div> <div class="span4"> <h4 class="title">Demo Map</h5> <ul> <li><a href="categories.php"><h5 class="title">Categories</h5></a></li> <li><a href="toprated.php"><h5 class="title">Top Rated</h5></a></li> <li><a href="mostviewed.php"><h5 class="title">Most Viewed</h5></a></li> <li><a href="latest.php"><h5 class="title">Latest Video</h5></a></li> </ul> </div> {% /block %}
{% extends file="web/themes/green/main.tpl" %} {% block name=title %}{% /block %} {% block name=meta %}{% /block %} {% block name=metad %}{% /block %} {% block name=title %}{% /block %} {% block name=thumb %} <h3 class="title">Video Count {% $content.count %}</h3> <div id = "thumb2"> <ul> {% section name=item loop=$content.video %} <li> <a href="play.php?vid={% $content.video[item].v_id %}&title={% $content.video[item].title|escape:'htmlall' %}&cat={% $content.cat %}"><img src="{% $content.video[item].thumb %}"/></a> <br/> {% $content.video[item].title %} <br/> {% $content.video[item].desc %} <br/> </li> {% /section %} </ul> </div> {% /block %} {% block name=paginate %}{% $content.pagination %}{% /block %}
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <!-- page title block --> <title>{% block name=title %}{% /block %}</title> <!-- /end of page title block --> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> <!-- robots block --> {% block name=robots %}{% /block %} <!-- /end of robots block --> <meta name="keywords" content="{% block name=meta %}{% /block %}"> <meta name="robots" content="all"> <meta name="revisit" content="1 day"> <!-- additional css block --> {% block name=style %} <style> #player { margin:0 auto; float:none; } </style> {% /block %} <!-- end of additional css block --> <!-- Optional javascript block --> {% block name=jscript %}{% /block %} <!-- /end of optional javascript block --> <link href="http://{% $content.sitepath %}themes/default/css/bootstrap.css" rel="stylesheet"> <link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet"> <link href="http://{% $content.sitepath %}themes/default/css/bootstrap-responsive.css" rel="stylesheet"> <!-- HTML5 shim, for IE6-8 support of HTML5 elements --> <!--[if lt IE 9]> <script src="../assets/js/html5shiv.js"></script> <![endif]--> <!-- Fav and touch icons --> <link rel="apple-touch-icon-precomposed" sizes="144x144" href="http://{% $content.sitepath %}themes/default/ico/apple-touch-icon-144-precomposed.png"> <link rel="apple-touch-icon-precomposed" sizes="114x114" href="http://{% $content.sitepath %}themes/default/ico/apple-touch-icon-114-precomposed.png"> <link rel="apple-touch-icon-precomposed" sizes="72x72" href="http://{% $content.sitepath %}themes/default/ico/apple-touch-icon-72-precomposed.png"> <link rel="apple-touch-icon-precomposed" href="http://{% $content.sitepath %}themes/default/ico/apple-touch-icon-57-precomposed.png"> <link rel="shortcut icon" href="http://{% $content.sitepath %}themes/default/ico/favicon.png"> <!-- /end of Fav and touch icons --> <!-- link to the theme style css file --> <link href="http://{% $content.sitepath %}themes/default/css/green.css" rel="stylesheet"> <!-- /end of theme style css file --> <!--[if gte IE 9]> <style type="text/css"> .gradient { filter: none; } </style> <![endif]--> {% block name=style %}{% /block %} <!-- jquery code block --> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <!-- /end of jquery code block --> <script> $(function() { $( "#videos" ).tabs(); }); </script> <script> function resizeCaller(){var a=new Array;for(i=0;i<iframeids.length;i++){if(document.getElementById)resizeIframe(iframeids[i]);if((document.all||document.getElementById)&&iframehide=="no"){var b=document.all?document.all[iframeids[i]]:document.getElementById(iframeids[i]);b.style.display="block"}}}function resizeIframe(a){var b=document.getElementById(a);if(b&&!window.opera){b.style.display="block";if(b.contentDocument&&b.contentDocument.body.offsetHeight)b.height=b.contentDocument.body.offsetHeight+FFextraHeight;else if(b.Document&&b.Document.body.scrollHeight)b.height=b.Document.body.scrollHeight;if(b.addEventListener)b.addEventListener("load",readjustIframe,false);else if(b.attachEvent){b.detachEvent("onload",readjustIframe);b.attachEvent("onload",readjustIframe)}}}function readjustIframe(a){var b=window.event?event:a;var c=b.currentTarget?b.currentTarget:b.srcElement;if(c)resizeIframe(c.id)}function loadThisVideo(a,b){if(document.getElementById)document.getElementById(a).src=b}var iframeids=["myframe"];var iframehide="yes";var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];var FFextraHeight=parseFloat(getFFVersion)>=.1?16:0;if(window.addEventListener)window.addEventListener("load",resizeCaller,false);else if(window.attachEvent)window.attachEvent("onload",resizeCaller);else window.onload=resizeCaller </script> </head> <body> <div class="navbar navbar-inverse navbar-fixed-top"> <div class="navbar-inner-green"> <div class="container"> <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="brand" href="#">Lorenzo Alipio Demo Script</a> <div class="nav-collapse collapse"> <ul class="nav"> <li class="active"><a href="index.php"><i class="icon-home icon-large" ></i> Main</a></li> <li><a href="#about">About</a></li> <li><a href="#contact">Contact</a></li> <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Media<b class="caret"></b></a> <ul class="dropdown-menu"> <li class="dropdown-submenu"> <a tabindex="-1" href="#">Video</a> <ul class="dropdown-menu"> <li><a href="latest.php">Latest</a></li> <li><a href="toprated.php">Top Rated</a></li> <li><a href="mostviewed.php">Most Viewed</a></li> <li><a href="categories.php">Categories</a></li> </ul> </li> <li class="dropdown-submenu"> <a tabindex="-1" href="#">Audio</a> <ul class="dropdown-menu"> <li><a href="#">Latest</a></li> </ul> </li> <li class="dropdown-submenu"> <a tabindex="-1" href="#">Photos</a> <ul class="dropdown-menu"> <li><a href="#">Latest Photos</a></li> </ul> </li> <li class="dropdown-submenu"> <a tabindex="-1" href="#">Blog</a> <ul class="dropdown-menu"> <li><a href="#">Latest Entries</a></li> </ul> </li> </ul> </li> {% block name=accountmenu %}{% /block %} </ul> <form class="navbar-search pull-right" method="get" action="video.php"> <input type="text" name="q" class="search-query span2" placeholder="Search"> </form> </div><!--/.nav-collapse --> </div> </div> </div> <div class="container"> {% block name=mtitle %}{% /block %} <div class="row"> <div id="videos"> {% block name=page_tabmenu %} <!-- page tab menu block --> {% /block %} <!-- featured begins --> <div id="featured" class="span12 row-fluid"> {% block name=featured %}{% /block %} </div> <!-- latest begins --> <div id="latest" class="span12 row-fluid"> {% block name=latest %}{% /block %} </div> <!-- mostviewed begins --> <div id="mostviewed" class="span12 row-fluid"> {% block name=mostviewed %}{% /block %} </div> </div> </div> <!-- /end of tab content blocks --> <!-- content blocks of all types --> <div class="span12 row-fluid"> {% block name=thumb %}{% /block %} </div> <div class="span12 row-fluid"> {% block name=login %}{% /block %} </div> <div class="span12 row-fluid"> {% block name=general %}{% /block %} </div> <!-- show pagination here if needed --> <div class="row"> <div class="span12 row-fluid"> <table width = "100%" ALIGN="center"> <tr> <td align="center" ><div class='paginate'> {% block name=paginate %}{% /block %} </div> </td></tr></table> <!-- EOF pagination section --> </div> </div> <div id="push"></div> </div> <div id="footer"> <div class="container"> <div class="row"> <div class="span12 row-fluid pagination-centered"> <div class="span6"><div class="bottombox text-left"><h1 class="footer">Lorenzo D. Alipio</h1> © All rights reserved. Powered by Lorenzo D. Alipio Framework. </div></div> <div class="span3"><div class="bottombox"><h5 class="footer">Archives</h5></div></div> <div class="span3"><div class="bottombox"><h5 class="footer">Social</h5> <div class="social_icons"> <ul> <li><a href="#"><img src="http://{% $content.sitepath %}themes/default/social/blogger.png"></a></li> <li><a href="#"><img src="http://{% $content.sitepath %}themes/default/social/facebook.png"></a></li> <li><a href="#"><img src="http://{% $content.sitepath %}themes/default/social/youtube.png"></a></li> <li><a href="#"><img src="http://{% $content.sitepath %}themes/default/social/twitter.png"></a></li> <li><a href="#"><img src="http://{% $content.sitepath %}themes/default/social/digg.png"></a></li> <li><a href="#"><img src="http://{% $content.sitepath %}themes/default/social/stumbleupon.png"></a></li> <li><a href="#"><img src="http://{% $content.sitepath %}themes/default/social/vimeo.png"></a></li> <li><a href="#"><img src="http://{% $content.sitepath %}themes/default/social/rss.png"></a></li> </ul></div> </div></div> <div class="spane12 row fluid"> <footer> <!-- display copyright --> {% block name=copyright %}{% /block %} </footer> </div> </div> </div> </div> </div> </div> <!-- can use this block for much needed javascript on page --> {% block name=jscript1 %}{% /block %} <script src="http://{% $content.sitepath %}themes/default/js/bootstrap-transition.js"></script> <script src="http://{% $content.sitepath %}themes/default/js/bootstrap-alert.js"></script> <script src="http://{% $content.sitepath %}themes/default/js/bootstrap-modal.js"></script> <script src="http://{% $content.sitepath %}themes/default/js/bootstrap-dropdown.js"></script> <script src="http://{% $content.sitepath %}themes/default/js/bootstrap-scrollspy.js"></script> <script src="http://{% $content.sitepath %}themes/default/js/bootstrap-tab.js"></script> <script src="http://{% $content.sitepath %}themes/default/js/bootstrap-tooltip.js"></script> <script src="http://{% $content.sitepath %}themes/default/js/bootstrap-popover.js"></script> <script src="http://{% $content.sitepath %}themes/default/js/bootstrap-button.js"></script> <script src="http://{% $content.sitepath %}themes/default/js/bootstrap-collapse.js"></script> <script src="http://{% $content.sitepath %}themes/default/js/bootstrap-carousel.js"></script> <script src="http://{% $content.sitepath %}themes/default/js/bootstrap-typeahead.js"></script> <!-- 2nd javascript block for javascript that needs to be written on the page --> {% block name=jscript2 %}{% /block %} </body> </html>
<?php /* * * Copyright Lorenzo D. Alipio* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * MostviewedController.php */ class MostviewedController extends Controller { public $q = "funnies"; public $index = '1'; public $orderby = "published"; public $i = 48; public $count =''; function __construct() { parent::__construct(); Use_Class::autoload(YOUTUBE); } public function index(){ if(isset($_GET['q'])){ $q = $_GET['q']; $q = preg_replace('/[[:space:]]+/', '/', trim($q)); $q = str_replace('/', '+', $q); $index = $_GET['start-index']; $orderby = $_GET['orderby']; $i = 25; } else{ $q = "Metallica"; $index = "1"; $orderby = "published"; $i = 25; } $object = new YoutubeVideo($q,$index,$orderby,$i); $video = array( 'count'=> $object->getCount(), 'video'=> $object->getVideo(), 'sitepath'=>SITEPATH, 'cat' => $q, 'pagination'=>$object->pagenate('mostviewed.php') ); return $this->view->set_content($video,'latest.tpl'); } }
<?php /* * * Copyright Lorenzo D. Alipio* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * PlayController.php */ class PlayController extends Controller { public $v_id; public $title; public $description ; public $q = "funnies"; public $index = '1'; public $orderby = "viewCount"; public $i = 10; public $count =''; public function __construct() { parent::__construct(); Use_Class::autoload(YOUTUBE); if(isset($_GET['vid'])){ $this->v_id = filter_var($_GET['vid'], FILTER_SANITIZE_STRIPPED); $this->title = filter_var($_GET['title'], FILTER_SANITIZE_STRIPPED); $this->category = filter_var($_GET['cat'], FILTER_SANITIZE_STRIPPED); $this->q = $this->category; // set video data feed URL } } public function index(){ $object = new YoutubeVideo($this->q,$this->index,$this->orderby,$this->i); $relatedObject = new YoutubeVideo($this->q, 2 ,$this->orderby,15); $video = array( 'v_id' => $this->v_id, 'title' => $this->title, 'video'=> $object->getVideo(), 'related'=>$relatedObject->getVideo(), 'sitepath' => SITEPATH, 'cat' =>$this->category ); return $this->view->set_content($video,'play.tpl'); } }
<?php /* * Copyright Lorenzo D. Alipio* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * File: application/controller/TopratedController.php */ class TopratedController extends Controller { public $q = "toprated"; public $index = '1'; public $orderby = "published"; public $i = 48; public $count =''; function __construct() { parent::__construct(); Use_Class::autoload(YOUTUBE); } public function index(){ //$object = Ini_object::instance('YoutubeVideo'); if(isset($_GET['q'])){ $q = $_GET['q']; $q = preg_replace('/[[:space:]]+/', '/', trim($q)); $q = str_replace('/', '+', $q); $index = $_GET['start-index']; $orderby = $_GET['orderby']; $i = 25; } else{ $q = "Aerosmith"; $index = "1"; $orderby = "published"; $i = 25; } $object = new YoutubeVideo($q,$index,$orderby,$i); $video = array( 'count'=> $object->getCount(), 'video'=> $object->getVideo(), 'sitepath'=>SITEPATH, 'cat' => $q, 'pagination'=>$object->pagenate('toprated.php') ); return $this->view->set_content($video,'latest.tpl'); } }
<?php /* * Copyright Lorenzo D. AlipioNotice, how the ViewClass.php was coded, we are setting our own delimiters for our smarty template engine. We will be using {% and %} because I am trying to build this framework to be able to use twig template engine. This conclude the Part 6B. Next time we will be writing the parent template file, the child template files. Hopefully, we can test our simple MVC implementing youtube API v2.* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * File: application/view/ViewClass.php */ Class View{ public function __construct(){ if(TPL === 'Smarty'){ Ini_object::instance('Smarty'); $this->tpl = Ini_object::instance('Smarty'); $this->tpl->left_delimiter = '{% '; $this->tpl->right_delimiter = ' %}'; $this->tpl->template_dir = ( THEME_DIR ); $this->tpl->compile_dir = ( THEME_COMPILE ); $this->tpl->caching = 0; $this->tpl->setCompileCheck(true); $this->tpl->cache_dir = ( THEME_CACHE ); $this->tpl->config_dir = ( THEME_CONFIG ); } else if(TPL ==='Twig'){ Use_Class::useFile(TWIG_LOADER); Twig_Autoloader::register(); ## define our template directory location $loader = new Twig_Loader_Filesystem('templates'); ## initialize Twig environment with cache enabled $twig = new Twig_Environment($loader, array( 'cache' => TWIG_CACHE, 'auto_reload' => true )); } } /* * TO DO integrate TWIG * */ public function set_content($content=array(),$templateName = null){ $this->tpl->assign('content', $content); return $this->tpl->display(THEME .$templateName); } }
<?php /* * Copyright Lorenzo D. Alipio* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * AboutController.php */ class AboutController extends Controller{ public function __construct(){ parent::__construct(); } private function aboutContent(){ return array( 'about'=> 'Created with L.D.Alipio light MVC, twitter bootstrap, smarty template engine.', 'email' => 'YourEmail@domain.com', 'name' => 'Lorenzo Alipio', 'motto' => 'You can do it (not like the Nike though.)', 'sitepath'=>SITEPATH ); } public function index(){ return $this->view->set_content(self::aboutContent(),'about.tpl'); } }
class AboutController extends Controller{
public function __construct(){
parent::__construct();
}
public function __construct(){ $this->model = Ini_object::instance('ModelClass'); $this->view = Ini_object::instance('View'); }
<?php /* * Copyright Lorenzo D. Alipio* This file is for demonstration purposes only and NOT authorize for distribution. * NO License will be granted for any purposes NON-profit or for profit. * However, the instance of smarty within the constructor of which this class instantiated is covered * by GNU license. * * filename: application/ViewClass.php * Update Date: 8-20-2013 * Previous Version: 1.4 * CategoriesController.php */ class CategoriesController extends Controller{ public function __construct(){ parent::__construct(); } public function index(){ $cat = array( 'Charice','The Beatles','Elvis Presley', 'Nora Jones', 'James Brown','Rolling Stones','Bob Dylan','Chuck Berry','The Who','Led Zeppelin','Stevie Wonder','Jimi Hendrix','Ray Charles','The Beach Boys','Pink Floyd','Aretha Franklin','Little Richard','Marvin Gaye','Bruce Springsteen','David Bowie','Fats Domino','Black Sabbath','Queen','Buddy Holly','Bob Marley','Sam Cooke','Elton John','Neil Young','U2','Run-D.M.C.','Bo Diddley','Jerry Lee Lewis','B.B. King','Sly & The Family Stone','The Clash','Prince','The Grateful Dead','The Velvet Underground','Nirvana','Michael Jackson','The Supremes','The Temptations','Madonna','Public Enemy','The Kinks','Otis Redding','The Everly Brothers','Van Halen','Elvis Costello','Simon & Garfunkel','Cream','Frank Zappa','Roy Orbison','Eric Clapton','George Clinton & Parliament/Funkadelic','The Allman Brothers Band','Janis Joplin','The Ramones','Crosby, Stills, & Nash & Young','Fleetwood Mac','AC+DC','The Byrds','Joni Mitchell','The Eagles','Smokey Robinson & The Miracles','R.E.M.','Creedence Clearwater Revival','Johnny Cash','Van Morrison','Aerosmith','Curtis Mayfield & The Impressions','The Drifters','The Police','Metallica','Pearl Jam','Deep Purple','Bill Haley & His Comets','The Band','Santana','Yes','Jefferson Airplane','King Crimson','Al Green','The Isley Brothers','The Moody Blues','The Sex Pistols','N.W.A','Talking Heads','Tom Petty & The Heartbreakers','Billy Joel','The Bee Gees','The Yardbirds','The Four Tops','Radiohead','Patti Smith','Guns N Roses','Chicago','Rush','Bob Seger & The Silver Bullet Band','Rick Nelson','Earth Wind & Fire' ); sort($cat); $content = array( 'sitepath'=>SITEPATH, 'categoryHeader' => 'Music Video Categories', 'cat' => $cat ); return $this->view->set_content($content,'categories.tpl'); } }
<?php /* * * Copyright Lorenzo D. Alipio* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * IndexController.php */ class IndexController extends Controller{ public function __construct(){ parent::__construct(); } public function index(){ $content = array( 'sitepath'=>SITEPATH, 'content' =>self::article() ); ## this model content is for database //return $this->view->set_content($this->model->Content(),'index.tpl'); return $this->view->set_content($content,((TPL === 'Smarty')? 'index.tpl' : 'index.html')); } private function article(){ $article =array( 'first_p'=> 'This demo application script demonstrate the power of MVC methodologies in web development. This demo application also demonstrate the implementation of the capabilities of the following:', 'lists' => array('Smarty templating engine','Twitter Bootstrap Front-end framework,Smarty template inheritance','Youtube API version 2,Clean extensible PHP script,Pure OOP as written in Model View Controller design Pattern','Request routing to web or public directory only','Auto redirect to the index, if the page request does not exist','Pages have their own controller to better manage the content delivery','No HTML tags in the business logic pages','Written in PHP 5.5.1 > standards'), 'more_info'=>'This template may appear to be simple in its form, but it demonstrated the advance implementation of Object Oriented PHP.', 'copyright'=> 'Property of Lorenzo D. Alipio'); return $article; } }
<?php /* * * Copyright Lorenzo D. Alipio* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * LatestController.php */ class LatestController extends Controller { public $q = "most_recent"; public $index = '1'; public $orderby = "published"; public $i = 48; public $count =''; function __construct() { parent::__construct(); Use_Class::autoload(YOUTUBE); } public function index(){ //$object = Ini_object::instance('YoutubeVideo'); if(isset($_GET['q'])){ $q = $_GET['q']; $q = preg_replace('/[[:space:]]+/', '/', trim($q)); $q = str_replace('/', '+', $q); $index = $_GET['start-index']; $orderby = $_GET['orderby']; $i = 25; } else{ $q = "AC+DC"; $index = "1"; $orderby = "published"; $i = 25; } $object = new YoutubeVideo($q,$index,$orderby,$i); $video = array( 'count'=> $object->getCount(), 'video'=> $object->getVideo(), 'sitepath'=>SITEPATH, 'cat' => $q, 'pagination'=>$object->pagenate('latest.php') ); return $this->view->set_content($video,'latest.tpl'); } }
<? /* * Copyright Lorenzo D. Alipio* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * Controller.php * namespace application\controller\; */ Abstract Class Controller { /* * * @model use model * @view use view * */ protected $model; protected $view; function __construct() { $this->model = Ini_object::instance('ModelClass'); $this->view = Ini_object::instance('View'); } /** * set contract between main controller and the application controllers. Must have */ abstract function index(); } ?>
<? /* * * Copyright Lorenzo D. Alipio* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * BaseModel.php */ //Use_Class::autoload(PDO); Abstract Class BaseModel{ public function __construct(){} Abstract function Content(); } ?>
<?php /* * * Copyright Lorenzo D. Alipio * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * Bootstrap.php */ if(!isset($_SESSION)){session_start();} define('TPL','Smarty'); /* * * file constants definition file or bootstrap * */ define( 'SITEPATH', $_SERVER['SERVER_NAME'] . str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_FILENAME'])) .'/'); define ('EXT', '.php'); define ('DS', DIRECTORY_SEPARATOR); define ('ROOT',(dirname(__DIR__))); define ('TEMP',ROOT.DS .'temp'. DS ); define ('BASE_CONTROLLER', ROOT .'\vendor\core\controller_Controller'); define ('VENDOR', ROOT .'/vendor/'); /* *Define Base model for the application *@BASE holds database connection e.g. PDO, MYSQLI *@MODEL application model e.g. IndexModel, YoutubeModel, the same convention as the controllers */ define ('BASE_MODEL',ROOT .'\vendor\core\model_Model'); define ('MODEL',ROOT .'\application\model_ModelClass'); define ('VIEW', ROOT .'\application\view_ViewClass'); /* libraries for the application */ define ('LIBS', ROOT.DS .'vendor\applib'. DS); define ('TPL_ENG', LIBS .'template_engine'. DS); define ('SMARTY_LOAD', LIBS .'\template_engine\smarty_Smarty.class'); /* Template engine configuration and directories */ ## define public directory, accessable only to users define ('WEB_DIR', ROOT. DS .'web'.DS); ## Theme Directory define( 'THEME_DIR', WEB_DIR .'themes'. DS ); define( 'THEME_COMPILE', THEME_DIR .'themes_compile'); define( 'THEME_CACHE', TEMP .'theme_cache'. DS); define( 'THEME_CONFIG', THEME_DIR .'theme_configs'); define( 'THEME' , THEME_DIR .'green'. DS );The function of the bootstrap.php above is to keep all of the files in our application. This is the page where we define our constants. I am planning to write another tutorial similar to this, but it will be more advance than this. It will beutilizing the composer autoloader, and symfony class loader. Since this article is entitled as "simple MVC", I need to stay focus on that purpose.
<?php /* * * Copyright Lorenzo D. Alipio * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * AutoLoad.php */ require_once ('Bootstrap.file.php'); class Use_Class{ /* * @autoload autoload class file. * * @param [in] $className class file constant name * @return require_once the file */ public static function autoload($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strrpos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require_once $fileName; } /* *@loadController *@controller takes pathinfo *@return PagecontrollerController or default IndexController */ public static function loadController($controller,$array=array()){ return((is_array($array) && ((!empty($controller) || ($controller != null) )))? array('\application\controller_'.ucfirst($controller).'Controller' , array_search($controller, $array)) : array('\application\controller_IndexController' ,'IndexController')); } public static function useFile($file){ include_once($file); } } /* * *@ini_Object initialize objects by singleton *return objects */ final class Ini_object{ /** * Maintains collection of instantiated classes */ private static $instances = array(); /** * Overload constructor */ private function __construct(){} /** * Manages instantiation of classes * * @param $class * * @return self instance of the class */ public static function instance($class) { //instantiate class as necessary self::create($class); //return instance return self::$instances[$class]; } /** * Creates the instances * * @param $class * * @return none */ private static function create($class) { //check if an instance of requested class exists if (!array_key_exists($class , self::$instances)) { self::$instances[$class] = new $class; } } } /* *@auto load base controller model, view and smarty */ Use_Class::autoload(BASE_CONTROLLER); /* *@auto load application model.. this is not the base model *@auto load application view .. this is not the base view class */ Use_Class::autoload(MODEL); Use_Class::autoload(VIEW); Use_Class::autoload(SMARTY_LOAD);
<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ web/ [L] RewriteRule (.*) web/$1 [L] </IfModule>
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond $1 !\.(gif|jpg|png|ico|css|js|swf|wav|mp3|less|cur) [OR] RewriteCond %{REQUEST_URI} ^/web/.*\.css$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?url=$1 [L,QSA] </IfModule>We need to test if these .htaccess are working as intended. Create a php file called index.php, and save it to the root directory of out application.
<?php echo 'Hello from the root index.php'; ?>
<?php echo 'Hello from the Web directory index.php'; ?>
"Hello from the Web directory index.php".
<?php /* * * Copyright Lorenzo D. Alipio* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * projectcreator.php */ class CreateProject{ private $controller = '/application/controller/'; private $model = '/application/model/'; private $view = '/application/view/'; private $default_theme = '/web/themes/default/'; private $theme_compile = '/web/themes/themes_compile/'; private $temp = '/temp/'; private $theme_configs= '/web/themes/themes_configs/'; private $smartyUrl = 'http://www.smarty.net/files/Smarty-3.1.14.zip'; private $dir; private $projectName ; public function __construct(){ $this->dir = array($this->controller, $this->model, $this->view, $this->default_theme, $this->theme_compile, $this->temp,$this->theme_configs); $this->projectName = 'mvcproject'; } public function createDir(){ foreach($this->dir as $item){ if(!file_exists($this->projectName.$item)){ $this->setProject($this->projectName.$item); } else{ echo $this->projectName.$item.' already exists '; } } } public function setProject($project){ if(!file_exists($project)){ mkdir($project, 0, true); echo ' '. $project .' Created'; } if(!file_exists($this->projectName.'/smarty.zip')){ $this->downloadSmarty($this->smartyUrl); echo '<br/> Smarty Downloaded'; } } public function unZipfile(){ $file = $this->projectName.'/smarty.zip'; if(file_exists($this->projectName.'/temp')){ if(!file_exists($this->projectName.'/temp/smarty/')){ mkdir($this->projectName.'/temp/smarty/', 0, true); } if (is_resource($file)) { while ($zip_entry = zip_read($file)) { $fp = fopen($this->projectName.'/temp/smarty/'.zip_entry_name($zip_entry), "w"); if (zip_entry_open($file, $zip_entry, "r")) { $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); fwrite($fp,"$buf"); zip_entry_close($zip_entry); fclose($fp); } } zip_close($file); } } } public function downloadSmarty($url){ $fp = fopen($this->projectName.'/smarty.zip', 'w'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FILE, $fp); $data = curl_exec($ch); curl_close($ch); fclose($fp); } public function createJson(){ $json ='{'; $json .= "\n\n\t"; //$json .= "\t"; $json .= '"require": {'; $json .= "\n\t\t"; $json .= '"symfony/class-loader": "2.4.*@dev",'; $json .= "\n\t\t"; $json .= '"symfony/http-foundation": "2.3.*@dev",'; $json .= "\n\t\t"; $json .= '"phpunit/phpunit": "3.7.*",'; $json .= "\n\t\t"; $json .= '"swiftmailer/swiftmailer": ">=4.2.0,<4 data-blogger-escaped-.3-dev="" data-blogger-escaped-.="}" data-blogger-escaped-file_exists="" data-blogger-escaped-if="" data-blogger-escaped-json="" data-blogger-escaped-this-="">projectName.'/composer.json')){ $writeJsonFile = fopen($this->projectName.'/composer.json',"w"); fwrite($writeJsonFile,$json); fclose($writeJsonFile); } } } $object = new CreateProject(); $object->createDir(); //$object->createJson(); //$object->unZipfile(); ?>
<?php $this->projectName = 'mvcproject'; ?>
$this->downloadSmarty($this->smartyUrl); echo 'Smarty Downloaded';
//$this->downloadSmarty($this->smartyUrl); //echo 'Smarty Downloaded';