From: Marcus C. <ma...@br...> - 2007-06-16 18:17:00
|
Hi All, One of the areas of our site is a set of 'Learning Paths' which is euro education jargon for 'Tutorial'. These are mini websites which have been created by external webbers. I had to think of a way of them making them independently of cchost. Each page is just a stub which includes a template which includes the content and a common nav file. This way i can ignore everything but the content and nav when I come to integrate in the main system. What I need to do is to integrate the content files into cchost with the minimum of fuss, editing etc. This is my approach - feel free to offer better suggestions! There's a root directory for the mini sites: {mycchost}/learning_paths each mini site is in it's own directory according to topic and language eg. {mycchost}/learning_paths/production_en A tab set provides navigation to the mini sites The URL learning_path/{lp_name} is handled by a function which determines the language and then sends the browser to {mycchost}/learning_paths/{lp_name}_{lang}/{file} These URLs are handled by another function which displays the contents of a nav file and specific content files according to the {file} parameter. This all works fine and relative URLs for hrefs work which means less editing of the source supplied to me. However relative image src attributes don't work (cos there's no real directory named after the virtual root). Maybe I've just got to make them do fully qualified src's for images (which is a shame for future portability of these mini sites). If you want to see this working: http://ccdev18.dreamhosters.com/media/view/modem/learning_paths - choose 'production'. If you want to see it in Italian you'll have to register and change the language in your profile. Here's the class that does the business: CCEvents::AddHandler( CC_EVENT_MAP_URLS, array( 'MOLearningPaths', 'OnMapUrls' ) ); // This class is for displaying Learning_Path mini sites within cchost class MOLearningPaths { //The user selects a path from the tabs or menus function OnMapUrls() { CCEvents::MapUrl( ccp('learning_path'), array ( 'MOLearningPaths', 'learningPathLang' ), CC_DONT_CARE_LOGGED_IN, '{lp}' ); CCEvents::MapUrl( ccp('learning_paths', 'production_it'), array ( 'MOLearningPaths', 'showLearningPath' ), CC_DONT_CARE_LOGGED_IN, '{lpfile}' ); CCEvents::MapUrl( ccp('learning_paths', 'production_en'), array ( 'MOLearningPaths', 'showLearningPath' ), CC_DONT_CARE_LOGGED_IN, '{lpfile}' ); } //determine which language the learning path should be displayed in function learningPathLang ( $lp ) { //cchost probably already has a 'getLang' in CCLanguage... $lang = getLang(); if (empty($lp)) $url .= ccp('learning_paths','index.html'); else { $url = ccl('learning_paths', $lp.'_'.$lang); } //send the browser to the new URL so that relative links work CCDebug::Log('Learning paths lang - sending browser to:'.$url); CCUtil::SendBrowserTo($url); } function showLearningPath( $lpfile = '') { CCDebug::Log(cc_current_url()); //find out which learning path we're in $dir_array = explode('/', cc_current_url()); $learning_path = array_pop($dir_array); //if there's a file in the url we need the second last token if ($lpfile != '') $learning_path = array_pop($dir_array); //still nothing? bale out... if (empty($learning_path)) CCUtil::SendBrowserTo(ccl('view','home')); if (empty($lpfile)) CCUtil::SendBrowserTo(ccl('learning_paths', $learning_path, 'index.php')); else if (strpos($lpfile, '.php') === false) CCUtil::SendBrowserTo(ccl('learning_paths', $learning_paths, 'index.php')); $lproot = $_SERVER['DOCUMENT_ROOT']."/learning_paths/".$learning_path."/"; $contentFile = $lproot.substr($lpfile, 0, strrpos($lpfile, '.php'))."_content.php"; $navFile = $lproot."learning_path_nav.php"; CCDebug::Log($contentFile); $page = CCPage::GetPage(); $html = ""; $html .= '<div style="padding-top:20px; width:30%; float:right; padding-left:10px;">'.file_get_contents($navFile).'</div>'; $html .= '<div style="width:65%;">'.file_get_contents($contentFile).'</div>'; CCPage::PageArg('body_html',$html,'show_body_html'); } } cheers Marcus -- Marcus Clements www.brightonart.org www.rocketfestival.com www.innerfield.co.uk |
From: Victor S. <fou...@gm...> - 2007-06-20 07:49:13
|
On 6/16/07, Marcus Clements <ma...@br...> wrote: > One of the areas of our site is a set of 'Learning Paths' which is euro > education jargon for 'Tutorial' <snip> > > This is my approach - feel free to offer better suggestions! OPTION 1: I probably would have started with javascript <div id="target1"></div> <script> function get_file(url) { new Ajax.Updater( $('target1'), url, { method: 'get' } ); } </script> <a href="javascript://show this file" onclick="get_file(' http://mysite/somepath');">Part 4: Audio Stuff</a> I haven't tested the code above but I think you get the idea... OPTION 2: I'm not 100% sure but I think the blog-integration code may do what you want already (It's how I merged WordPress and ccHost at http://fourstones.net ) With this method you put <script> call outs into your html/php file. Say Part2_Overview.php: <html> <head> <!-- IN THE HEAD SECTION: --> <script src="http://your_install/media/skin/head"></script> .. your head section ... </head> <body> <!-- RIGHT AFTER BODY TAG --> <script src="http://your_install/media/skin/body_begin"></script> ... your page.... <!-- RIGHT BEFORE /BODY TAG --> <script src="http://your_install/media/skin/body_end"></script> </body> </html> VS |