Re: Sidebar and Dynamic News
| From: | Paul Dragoonis | Date: | Thu, 25 Aug 2011 12:15:20 +0000 |
| Subject: | Re: Sidebar and Dynamic News | ||
| References: | 1 2 3 4 5 6 | Groups: | php.webmaster |
| Request: | Send a blank email to php-webmaster+get-12041@lists.php.net to get a copy of this message | ||
On Thu, Aug 25, 2011 at 1:14 PM, Paul Dragoonis <dragoonis@gmail.com> wrote:
>
>
> On Fri, Aug 19, 2011 at 12:39 PM, Paul Dragoonis <dragoonis@gmail.com>wrote:
>
>>
>>
>> On Fri, Aug 19, 2011 at 12:29 PM, Hannes Magnusson <
>> hannes.magnusson@gmail.com> wrote:
>>
>>> On Fri, Aug 19, 2011 at 13:24, Paul Dragoonis <dragoonis@gmail.com>
>>> wrote:
>>> >
>>> >
>>> > On Fri, Aug 19, 2011 at 11:20 AM, Hannes Magnusson
>>> > <hannes.magnusson@gmail.com> wrote:
>>> >>
>>> >> On Thu, Aug 18, 2011 at 12:56, Paul Dragoonis <dragoonis@gmail.com>
>>> wrote:
>>> >> > Hey Stewart + all,
>>> >> > As discussed previously I'd get back into the new prototype
>>> again. Here
>>> >> > is
>>> >> > my first patch in a while with more to come.
>>> >> > I have attached my patch here for review before i commit it to SVN.
>>> >> > I've also attached a screenshot for those who want to see visual
>>> changes
>>> >> > without importing a patch.
>>> >>
>>> >>
>>> >> - Your editor seems to be messing with trailing whitespace
>>> >
>>> > I'll look at my editor settings
>>> >
>>> >>
>>> >> - That print_view() function is useless
>>> >
>>> > It's not useless, we need it to stop horrible code like heredocs
>>> everywhere,
>>> > and we're isolating our app data from the UI so that we're doing PHP
>>> inside
>>> > HTML rather than HTML inside PHP.
>>>
>>> How does splitting every little area into chunkloads of files help with
>>> things?
>>> All that function essentially does is include, with a twist of
>>> extract().. I really don't see the use.
>>>
>>
>> Splitting our app code up with our "views" code will make code chunks more
>> maintainable and readable.
>> Having all the app logic and UI logic mixed in is a very painful codebase
>> to work with.
>>
>> We could merge the four view files into just 'sidebar.php' that is a good
>> compromise, I feel that the split approach on the sidebar view files was a
>> bit "too" organised.
>>
>> Lets get this wrapped up, move on from debating and start pumping out
>> features, we can refactor a bit later :-)
>>
>> Thanks for your feedback thus far, appreciated.
>>
>
>
> I'm back, I've fixed my editor to show whitespace and tab/spaces. I
> converted all my added code to spaces for indentation instead of tabs.
>
> I've taken Hannes' feedback into consideration and fixed up the view files
> so instead of 5 there is only 1, which I do like more now.
>
> My patch is attached, if anyone has no problems with it i'm happy to commit
> and move onto something else.
>
>
Forgot the attachment, duh! - here it is now.
> Cheers,
> Paul.
>
>
>>
>> Cheers,
>> Paul.
>>
>>
>>>
>>> -Hannes
>>>
>>
>>
>
Index: styles/home.css =================================================================== --- styles/home.css (revision 315477) +++ styles/home.css (working copy) @@ -60,7 +60,7 @@ } -/* We have to override these because theme.css has a generic style for 'ul' +/* We have to override these because theme.css has a generic style for 'ul' and that doesn't apply here on the downloads area */ #mega-drop-down div.download ul { @@ -268,12 +268,12 @@ } div.home-sidebar h2 { - border-top: 6px solid #c3add9; + border-bottom: 6px solid #c3add9; font-size: 1.5em; line-height: 100%; - padding: 5px 0 10px 0; + padding: 5px 0 5px 0; font-weight: normal; - margin: 0; + margin: 20px 0 5px 0; } div.home-sidebar h2:first-child { @@ -281,7 +281,7 @@ } div.home-sidebar ul { - margin: 0 0 30px 0; + margin: 0 0 0 0; list-style-type: none; padding: 0; } \ No newline at end of file Index: include/layout.inc =================================================================== --- include/layout.inc (revision 315477) +++ include/layout.inc (working copy) @@ -350,8 +350,8 @@ </div> </div> <!--[if IE 6]> -<script type="text/javascript"> - /*Load jQuery if not already loaded*/ if(typeof jQuery == 'undefined'){ document.write("<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></"+"script>"); var __noconflict = true; } +<script type="text/javascript"> + /*Load jQuery if not already loaded*/ if(typeof jQuery == 'undefined'){ document.write("<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></"+"script>"); var __noconflict = true; } var IE6UPDATE_OPTIONS = { icons_path: "/ie6update/images/" } @@ -674,6 +674,25 @@ <?php } +/** + * Print a view + * + * @param string $templateName + * @param array $params + * @return void + */ +function print_view($templateName, array $params = array()) { + $path = $_SERVER['DOCUMENT_ROOT'] . '/views/' . $templateName; + if(file_exists($path)) { + if(!empty($params)) { + foreach($params as $key => $param) { + $$key = $param; + } + } + include_once $path; + } +} + // Print news links for archives function news_archive_sidebar() { Index: views/homepage/sidebar.php =================================================================== --- views/homepage/sidebar.php (revision 0) +++ views/homepage/sidebar.php (revision 0) @@ -0,0 +1,51 @@ +<div class=home-sidebar> + + <h2>Recent News</h2> + <ul> + <?php + $i = 0; + foreach (print_news($news, "frontpage", 5, null, true) as $entry): + $escaped_title = htmlentities($entry['title'], ENT_QUOTES, 'UTF-8'); + ?> + <li><a target="_blank" title="<?php echo $escaped_title; ?>" href="<?php echo $entry['permlink']; ?>"><?php echo $escaped_title; ?></a></li> + <?php + endforeach; + ?> + </ul> + <p class="center"><a href="/archive/index.php" title="News Archive">News Archive</a></p> + + <h2>Conferences</h2> + <ul> + <li>Lorem ipsum dolor sit amet</li> + <li>Lorem ipsum dolor sit amet</li> + <li>Lorem ipsum dolor sit amet</li> + </ul> + + <h2>User Group Events</h2> + <ul> + <li>Lorem ipsum dolor sit amet</li> + <li>Lorem ipsum dolor sit amet</li> + <li>Lorem ipsum dolor sit amet</li> + </ul> + + <h2>Thanks To</h2> + <ul> + <li><a target="_blank" href="http://www.easydns.com/?V=698570efeb62a6e2" title="DNS Hosting provided by easyDNS">easyDNS</a></li> + <li><a target="_blank" href="http://www.directi.com/">Directi</a></li> + <li><a target="_blank" href="http://promote.pair.com/direct.pl?php.net">pair Networks</a></li> + <li><a target="_blank" href="http://www.servercentral.net/">Server Central</a></li> + <li><a target="_blank" href="http://www.hostedsolutions.com/">Hosted Solutions</a></li> + <li><a target="_blank" href="http://www.spry.com/">Spry VPS Hosting</a></li> + <li><a target="_blank" href="http://ez.no/">eZ Systems</a> / <a href="http://www.hit.no/">HiT</a></li> + <li><a target="_blank" href="http://www.osuosl.org">OSU Open Source Lab</a></li> + <li><a target="_blank" href="http://www.yahoo.com/">Yahoo! Inc.</a></li> + <li><a target="_blank" href="http://www.binarysec.com/">BinarySEC</a></li> + <li><a target="_blank" href="http://www.nexcess.net/">NEXCESS.NET</a></li> + <li><a target="_blank" href="http://www.rackspace.com/">Rackspace</a></li> + <li><a target="_blank" href="http://www.eukhost.com/">EUKhost</a></li> + <li><a target="_blank" href="http://www.micfo.com/">micfo</a></li> + <li><a target="_blank" href="http://www.redpill-linpro.com">Redpill Linpro</a></li> + <li><a target="_blank" href="http://www.facebook.com">Facebook</a></li> + </ul> + +</div> \ No newline at end of file Index: index-beta.php =================================================================== --- index-beta.php (revision 315477) +++ index-beta.php (working copy) @@ -49,62 +49,6 @@ include_once $_SERVER['DOCUMENT_ROOT'] . '/include/pregen-news.inc'; include_once $_SERVER['DOCUMENT_ROOT'] . '/include/version.inc'; -// Prepare news headings. -$news = "<ul>"; -foreach (print_news($NEWS_ENTRIES, "frontpage", 5, null, true) as $entry) { - $news .= <<< EOT -<li>[{$entry["date"]}] <a href="{$entry["permlink"]}">{$entry["title"]}</a></li> -EOT; -} -$news .= "</ul>"; -$news .= '<p class="center"><a href="/archive/index.php">News Archive</a></p>'; - -// Prepare sidebar. -$sidebar = <<< EOT -<div class=home-sidebar> - <h2>Recent News</h2> - <ul> - <li>PHP 5.3.5 and 5.2.17 Released!</li> - <li>PHP 5.2.16 Released!</li> - <li>PHP 5.3.4 Released!</li> - </ul> - - <h2>Conferences</h2> - <ul> - <li>Lorem ipsum dolor sit amet</li> - <li>Lorem ipsum dolor sit amet</li> - <li>Lorem ipsum dolor sit amet</li> - </ul> - - <h2>User Group Events</h2> - <ul> - <li>Lorem ipsum dolor sit amet</li> - <li>Lorem ipsum dolor sit amet</li> - <li>Lorem ipsum dolor sit amet</li> - </ul> - - <h2>Thanks To</h2> - <ul> - <li><a href="http://www.easydns.com/?V=698570efeb62a6e2" title="DNS Hosting provided by easyDNS">easyDNS</a></li> - <li><a href="http://www.directi.com/">Directi</a></li> - <li><a href="http://promote.pair.com/direct.pl?php.net">pair Networks</a></li> - <li><a href="http://www.servercentral.net/">Server Central</a></li> - <li><a href="http://www.hostedsolutions.com/">Hosted Solutions</a></li> - <li><a href="http://www.spry.com/">Spry VPS Hosting</a></li> - <li><a href="http://ez.no/">eZ Systems</a> / <a href="http://www.hit.no/">HiT</a></li> - <li><a href="http://www.osuosl.org">OSU Open Source Lab</a></li> - <li><a href="http://www.yahoo.com/">Yahoo! Inc.</a></li> - <li><a href="http://www.binarysec.com/">BinarySEC</a></li> - <li><a href="http://www.nexcess.net/">NEXCESS.NET</a></li> - <li><a href="http://www.rackspace.com/">Rackspace</a></li> - <li><a href="http://www.eukhost.com/">EUKhost</a></li> - <li><a href="http://www.micfo.com/">micfo</a></li> - <li><a href="http://www.redpill-linpro.com">Redpill Linpro</a></li> - <li><a href="http://www.facebook.com">Facebook</a></li> - </ul> -</div> -EOT; - // Prepare announcements. $announcements = " <div class='announcements'> @@ -120,8 +64,8 @@ <h2>Get Involved!</h2> <p> Getting involved with PHP is easier than you think. - Are you interested in helping to improve one of the world's most - widely used scripting languages? We are looking for all sorts + Are you interested in helping to improve one of the world's most + widely used scripting languages? We are looking for all sorts of people, not only developers. <a href='/get-involved.php' class='readmore'>Read more...</a> </p> @@ -130,8 +74,8 @@ <span class=graphic></span> <h2>Need Help?</h2> <p> - Everyone needs a little help from time to time, and finding it - isn't always easy. Thankfully, PHP has one of the best support + Everyone needs a little help from time to time, and finding it + isn't always easy. Thankfully, PHP has one of the best support communities out there. <a href='/support.php' class='readmore'>Read more...</a> </p> @@ -177,7 +121,7 @@ 'onload' => 'boldEvents();', 'headtags' => array( '<link rel="alternate" type="application/atom+xml" title="PHP: Hypertext Preprocessor" href="' . $MYSITE . 'feed.atom" />', - '<script type="text/javascript">', + '<script type="text/javascript">', "function okc(f){var c=[38,38,40,40,37,39,37,39,66,65,13],x=function(){x.c=x.c||Array.apply({},c);x.r=function(){x.c=null};return x.c},h=function(e){if(x()[0]==(e||window.event).keyCode){x().shift();if(!x().length){x.r();f()}}else{x.r()}};window.addEventListener?window.addEventListener('keydown',h,false):document.attachEvent('onkeydown',h)}", "okc(function(){if(document.getElementById){i=document.getElementById('phplogo');i.src='".$_SERVER['STATIC_ROOT']."/images/php_konami.gif'}});", '</script>' @@ -202,7 +146,7 @@ ); // Print body of home page. -print $sidebar; +print_view('homepage/sidebar.php', array('news' => $NEWS_ENTRIES)); print $content; // Print the common footer.
Index: styles/home.css =================================================================== --- styles/home.css (revision 315477) +++ styles/home.css (working copy) @@ -60,7 +60,7 @@ } -/* We have to override these because theme.css has a generic style for 'ul' +/* We have to override these because theme.css has a generic style for 'ul' and that doesn't apply here on the downloads area */ #mega-drop-down div.download ul { @@ -268,12 +268,12 @@ } div.home-sidebar h2 { - border-top: 6px solid #c3add9; + border-bottom: 6px solid #c3add9; font-size: 1.5em; line-height: 100%; - padding: 5px 0 10px 0; + padding: 5px 0 5px 0; font-weight: normal; - margin: 0; + margin: 20px 0 5px 0; } div.home-sidebar h2:first-child { @@ -281,7 +281,7 @@ } div.home-sidebar ul { - margin: 0 0 30px 0; + margin: 0 0 0 0; list-style-type: none; padding: 0; } \ No newline at end of file Index: include/layout.inc =================================================================== --- include/layout.inc (revision 315477) +++ include/layout.inc (working copy) @@ -350,8 +350,8 @@ </div> </div> <!--[if IE 6]> -<script type="text/javascript"> - /*Load jQuery if not already loaded*/ if(typeof jQuery == 'undefined'){ document.write("<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></"+"script>"); var __noconflict = true; } +<script type="text/javascript"> + /*Load jQuery if not already loaded*/ if(typeof jQuery == 'undefined'){ document.write("<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></"+"script>"); var __noconflict = true; } var IE6UPDATE_OPTIONS = { icons_path: "/ie6update/images/" } @@ -674,6 +674,25 @@ <?php } +/** + * Print a view + * + * @param string $templateName + * @param array $params + * @return void + */ +function print_view($templateName, array $params = array()) { + $path = $_SERVER['DOCUMENT_ROOT'] . '/views/' . $templateName; + if(file_exists($path)) { + if(!empty($params)) { + foreach($params as $key => $param) { + $$key = $param; + } + } + include_once $path; + } +} + // Print news links for archives function news_archive_sidebar() { Index: views/homepage/sidebar.php =================================================================== --- views/homepage/sidebar.php (revision 0) +++ views/homepage/sidebar.php (revision 0) @@ -0,0 +1,51 @@ +<div class=home-sidebar> + + <h2>Recent News</h2> + <ul> + <?php + $i = 0; + foreach (print_news($news, "frontpage", 5, null, true) as $entry): + $escaped_title = htmlentities($entry['title'], ENT_QUOTES, 'UTF-8'); + ?> + <li><a target="_blank" title="<?php echo $escaped_title; ?>" href="<?php echo $entry['permlink']; ?>"><?php echo $escaped_title; ?></a></li> + <?php + endforeach; + ?> + </ul> + <p class="center"><a href="/archive/index.php" title="News Archive">News Archive</a></p> + + <h2>Conferences</h2> + <ul> + <li>Lorem ipsum dolor sit amet</li> + <li>Lorem ipsum dolor sit amet</li> + <li>Lorem ipsum dolor sit amet</li> + </ul> + + <h2>User Group Events</h2> + <ul> + <li>Lorem ipsum dolor sit amet</li> + <li>Lorem ipsum dolor sit amet</li> + <li>Lorem ipsum dolor sit amet</li> + </ul> + + <h2>Thanks To</h2> + <ul> + <li><a target="_blank" href="http://www.easydns.com/?V=698570efeb62a6e2" title="DNS Hosting provided by easyDNS">easyDNS</a></li> + <li><a target="_blank" href="http://www.directi.com/">Directi</a></li> + <li><a target="_blank" href="http://promote.pair.com/direct.pl?php.net">pair Networks</a></li> + <li><a target="_blank" href="http://www.servercentral.net/">Server Central</a></li> + <li><a target="_blank" href="http://www.hostedsolutions.com/">Hosted Solutions</a></li> + <li><a target="_blank" href="http://www.spry.com/">Spry VPS Hosting</a></li> + <li><a target="_blank" href="http://ez.no/">eZ Systems</a> / <a href="http://www.hit.no/">HiT</a></li> + <li><a target="_blank" href="http://www.osuosl.org">OSU Open Source Lab</a></li> + <li><a target="_blank" href="http://www.yahoo.com/">Yahoo! Inc.</a></li> + <li><a target="_blank" href="http://www.binarysec.com/">BinarySEC</a></li> + <li><a target="_blank" href="http://www.nexcess.net/">NEXCESS.NET</a></li> + <li><a target="_blank" href="http://www.rackspace.com/">Rackspace</a></li> + <li><a target="_blank" href="http://www.eukhost.com/">EUKhost</a></li> + <li><a target="_blank" href="http://www.micfo.com/">micfo</a></li> + <li><a target="_blank" href="http://www.redpill-linpro.com">Redpill Linpro</a></li> + <li><a target="_blank" href="http://www.facebook.com">Facebook</a></li> + </ul> + +</div> \ No newline at end of file Index: index-beta.php =================================================================== --- index-beta.php (revision 315477) +++ index-beta.php (working copy) @@ -49,62 +49,6 @@ include_once $_SERVER['DOCUMENT_ROOT'] . '/include/pregen-news.inc'; include_once $_SERVER['DOCUMENT_ROOT'] . '/include/version.inc'; -// Prepare news headings. -$news = "<ul>"; -foreach (print_news($NEWS_ENTRIES, "frontpage", 5, null, true) as $entry) { - $news .= <<< EOT -<li>[{$entry["date"]}] <a href="{$entry["permlink"]}">{$entry["title"]}</a></li> -EOT; -} -$news .= "</ul>"; -$news .= '<p class="center"><a href="/archive/index.php">News Archive</a></p>'; - -// Prepare sidebar. -$sidebar = <<< EOT -<div class=home-sidebar> - <h2>Recent News</h2> - <ul> - <li>PHP 5.3.5 and 5.2.17 Released!</li> - <li>PHP 5.2.16 Released!</li> - <li>PHP 5.3.4 Released!</li> - </ul> - - <h2>Conferences</h2> - <ul> - <li>Lorem ipsum dolor sit amet</li> - <li>Lorem ipsum dolor sit amet</li> - <li>Lorem ipsum dolor sit amet</li> - </ul> - - <h2>User Group Events</h2> - <ul> - <li>Lorem ipsum dolor sit amet</li> - <li>Lorem ipsum dolor sit amet</li> - <li>Lorem ipsum dolor sit amet</li> - </ul> - - <h2>Thanks To</h2> - <ul> - <li><a href="http://www.easydns.com/?V=698570efeb62a6e2" title="DNS Hosting provided by easyDNS">easyDNS</a></li> - <li><a href="http://www.directi.com/">Directi</a></li> - <li><a href="http://promote.pair.com/direct.pl?php.net">pair Networks</a></li> - <li><a href="http://www.servercentral.net/">Server Central</a></li> - <li><a href="http://www.hostedsolutions.com/">Hosted Solutions</a></li> - <li><a href="http://www.spry.com/">Spry VPS Hosting</a></li> - <li><a href="http://ez.no/">eZ Systems</a> / <a href="http://www.hit.no/">HiT</a></li> - <li><a href="http://www.osuosl.org">OSU Open Source Lab</a></li> - <li><a href="http://www.yahoo.com/">Yahoo! Inc.</a></li> - <li><a href="http://www.binarysec.com/">BinarySEC</a></li> - <li><a href="http://www.nexcess.net/">NEXCESS.NET</a></li> - <li><a href="http://www.rackspace.com/">Rackspace</a></li> - <li><a href="http://www.eukhost.com/">EUKhost</a></li> - <li><a href="http://www.micfo.com/">micfo</a></li> - <li><a href="http://www.redpill-linpro.com">Redpill Linpro</a></li> - <li><a href="http://www.facebook.com">Facebook</a></li> - </ul> -</div> -EOT; - // Prepare announcements. $announcements = " <div class='announcements'> @@ -120,8 +64,8 @@ <h2>Get Involved!</h2> <p> Getting involved with PHP is easier than you think. - Are you interested in helping to improve one of the world's most - widely used scripting languages? We are looking for all sorts + Are you interested in helping to improve one of the world's most + widely used scripting languages? We are looking for all sorts of people, not only developers. <a href='/get-involved.php' class='readmore'>Read more...</a> </p> @@ -130,8 +74,8 @@ <span class=graphic></span> <h2>Need Help?</h2> <p> - Everyone needs a little help from time to time, and finding it - isn't always easy. Thankfully, PHP has one of the best support + Everyone needs a little help from time to time, and finding it + isn't always easy. Thankfully, PHP has one of the best support communities out there. <a href='/support.php' class='readmore'>Read more...</a> </p> @@ -177,7 +121,7 @@ 'onload' => 'boldEvents();', 'headtags' => array( '<link rel="alternate" type="application/atom+xml" title="PHP: Hypertext Preprocessor" href="' . $MYSITE . 'feed.atom" />', - '<script type="text/javascript">', + '<script type="text/javascript">', "function okc(f){var c=[38,38,40,40,37,39,37,39,66,65,13],x=function(){x.c=x.c||Array.apply({},c);x.r=function(){x.c=null};return x.c},h=function(e){if(x()[0]==(e||window.event).keyCode){x().shift();if(!x().length){x.r();f()}}else{x.r()}};window.addEventListener?window.addEventListener('keydown',h,false):document.attachEvent('onkeydown',h)}", "okc(function(){if(document.getElementById){i=document.getElementById('phplogo');i.src='".$_SERVER['STATIC_ROOT']."/images/php_konami.gif'}});", '</script>' @@ -202,7 +146,7 @@ ); // Print body of home page. -print $sidebar; +print_view('homepage/sidebar.php', array('news' => $NEWS_ENTRIES)); print $content; // Print the common footer.