Advertisement
Poetro

blog.php

May 28th, 2011
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.42 KB | None | 0 0
  1. <?php
  2. /*****esetleges hibak(?) kijelzese*****///hozzaadott kezdete
  3. error_reporting(E_NOTICE);
  4. /*****forras megjelenitese, ekkor: ?forras*****/
  5. if(isset($_GET['forras'])){highlight_file(__FILE__);exit;}
  6. /***********************************************///hozzaadott vege
  7. function getItems() {
  8.   $db = file('db.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); //allomany tombbe olvasasa, ures sorok kihagyasaval
  9.   $entries = array(); //tombbe rendezes?
  10.   foreach ($db as $line) { //sorokra bontas?
  11.     $entry = new stdClass();
  12.     list($entry->azonosito, $entry->cim, $entry->tartalom, $entry->kulcsszavak, $entry->cimkek, $entry->bekuldo, $entry->idopont) =
  13.       explode('||', $line); //sorbol az elkulonitett reszek valtozova alakitasa //bekuldo es idopont hozzaadott
  14.     $entry->cimkek = array_map('trim', explode(', ', $entry->cimkek)); //cimkék szetvalogatasa vesszo utani szokoz szerint
  15.     $entries[] = $entry;
  16.   }
  17.   return $entries;
  18. }
  19.  
  20. function showAll() {
  21.   $teasers = array();
  22.   $entries = getItems();
  23.   foreach ($entries as $entry) {
  24.     $teasers[] = showTeaser($entry);
  25.   }
  26.   return showTeasers($teasers);
  27. }
  28.  
  29. function showTeasers($teasers) {
  30.   $teasers = implode("\n", $teasers);
  31.   return <<<__HTML__
  32.   <div class="hfeed">
  33.     $teasers
  34.   </div>
  35. __HTML__;
  36. }
  37.  
  38. function showTag($tag) {
  39.   $teasers = array();
  40.   $entries = getItems();
  41.   foreach ($entries as $entry) {
  42.     if (in_array($tag, $entry->cimkek)) {
  43.       $teasers[] = showTeaser($entry);
  44.     }
  45.   }
  46.   return showTeasers($teasers);
  47. }
  48.  
  49. function showItem($entry) {
  50.   $cimkek = array_map('checkPlain', $entry->cimkek);
  51.   $felho = '';
  52.   foreach ($cimkek as $cimke) {
  53.     $ecimke = urlencode($cimke);
  54.     $felho .= <<<__HTML__
  55.     <li>
  56.       <a href="?tag=$ecimke" rel="tag">$cimke</a>
  57.     </li>
  58. __HTML__;
  59.   }
  60.   $cim = checkPlain($entry->cim);
  61.   return <<<__HTML__
  62.   <div class="hentry">
  63.     <h2 class="entry-title">
  64.       <a href="?view={$entry->azonosito}">$cim</a>
  65.     </h2>
  66.     <div class="entry-content">
  67.       {$entry->tartalom}
  68.     </div>
  69.     <ul class="tags">
  70.       $felho
  71.     </ul>
  72.  
  73.   </div>
  74. __HTML__;
  75. }
  76.  
  77. function getItem($azonosito) {
  78.   $teasers = array();
  79.   $entries = getItems();
  80.   foreach ($entries as $entry) {
  81.     $teasers[] = showTeaser($entry);
  82.     if ($entry->azonosito == $azonosito) {
  83.       return $entry;
  84.     }
  85.   }
  86. }
  87.  
  88. function showTeaser($entry) {
  89.   $cimkek = array_map('checkPlain', $entry->cimkek);
  90.   $felho = array();
  91.   foreach ($cimkek as $cimke) {
  92.     $ecimke = urlencode($cimke);
  93.     $felho[] = <<<__HTML__
  94.         <li>
  95.           <a href="?tag=$ecimke" rel="tag">$cimke</a>
  96.         </li>
  97. __HTML__;
  98.   }
  99.   $felho = "\n" . implode("\n", $felho);
  100.   $cim = checkPlain($entry->cim);
  101.   $tartalom = nl2br(checkPlain(truncate(strip_tags($entry->tartalom), 240, TRUE, TRUE)), TRUE);
  102.   return <<<__HTML__
  103.     <div class="hentry">
  104.       <h2 class="entry-title">
  105.  
  106.         <a href="?view={$entry->azonosito}">$cim</a>
  107.       </h2>
  108.       <div class="entry-summary">
  109.         <p>$tartalom</p>
  110.  
  111.       </div>
  112.       <ul class="tags">$felho
  113.       </ul>
  114.     </div>
  115. __HTML__;
  116. }
  117.  
  118. function truncate($text, $len, $wordSafe, $dots) {
  119.   if (mb_strlen($text) < $len) {
  120.     return $text;
  121.   }
  122.   if ($dots) {
  123.     $len -= 1;
  124.   }
  125.   if ($wordSafe) {
  126.     $text = mb_substr($text, 0, $len + 1);
  127.     if ($lastSpace = strrpos($text, ' ')) {
  128.       $text = substr($text, 0, $lastSpace);
  129.     }
  130.     else {
  131.       $text = mb_substr($text, 0, $len);
  132.     }
  133.   }
  134.   else {
  135.     $text = mb_substr($text, 0, $len);
  136.   }
  137.  
  138.   if ($dots) {
  139.     $text .= '…';
  140.   }
  141.  
  142.   return $text;
  143. }
  144.  
  145. function checkPlain($text) {
  146.   return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
  147. }
  148.  
  149. $meta = array(
  150.   'title'       => 'Oldalam címe',
  151.   'description' => 'Oldalam leírása',
  152.   'keywords'    => 'kulcsszó',
  153.   'tags'        => 'tagok',
  154.   'author'      => 'Mórocz Tamás',
  155.   'copyright'   => 'Mórocz Tamás, Poetro',
  156. );
  157.  
  158. if (isset($_GET['view'])) {     //ha a $_GET['view'] valtozo van
  159.   $entry = getItem($_GET['view']); //akkor az ertekevel megegyezo azonositoju bejegyzes megjelenitese
  160.   $meta = array(
  161.     'title'       => $entry->cim,
  162.     'description' => truncate($entry->tartalom, 240, TRUE, TRUE),
  163.     'keywords'    => $entry->kulcsszavak,
  164.     'tags'        => implode(', ', $entry->cimkek),
  165.     'author'      => 'Mórocz Tamás' . ($entry->bekuldo != 'Mórocz Tamás' ? ', ' . $entry->bekuldo : ''),
  166.     'copyright'   => 'Mórocz Tamás, Poetro',
  167.   );
  168.   $title = $entry->cim;
  169.   $output = showItem($entry);
  170. }
  171. else if (isset($_GET['tag'])) { //ha a $_GET['tag'] valtozo van
  172.   $title = $_GET['tag'];
  173.   $output = showTag($_GET['tag']);   //akkor az ertekevel megegyezo cimkeju bejegyzesek felsorolodnak
  174. }
  175. else {
  176.   $title = 'Címlap';
  177.   $output = showAll(); //osszes felsorolasa
  178. }
  179. ?>
  180. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  181. <html xmlns='http://www.w3.org/1999/xhtml' lang='hu'>
  182.   <head>
  183.     <title><?php echo checkPlain($title)?> | Valós játékleírások blog</title>
  184.     <meta http-equiv="content-type" content="text/html;charset=utf-8" />
  185.     <?php foreach ($meta as $name => $content): ?>
  186.     <meta name="<?php echo checkPlain($name); ?>" content="<?php echo checkPlain($content); ?>" />
  187.     <?php endforeach; ?>
  188.     <link rel="stylesheet" href="http://blog.realgameguides.com/style.css" type="text/css" />
  189.     <link rel="shortcut icon" href="http://blog.realgameguides.com/favicon.ico" type="image/x-icon" />
  190.   </head>
  191.   <body>
  192.     <div id="container">
  193.       <div id="header">
  194.         <div id="mainnav">
  195.           <a href="http://blog.realgameguides.com/">Főoldal</a>
  196.           <a href="http://blog.realgameguides.com/?view=kapcsolat">Kapcsolat</a>
  197.         </div>
  198.       </div>
  199.       <div id="content">
  200.         <?php echo $output; ?>
  201.         <div class="ad468x60">
  202.           <script type="text/javascript">
  203.             document.write('<a href="http:\/\/ubuntu.hu\/ismerteto\/"><img src="http:\/\/ad.realgameguides.com\/ubuntuhu.png" alt="Ubuntu" \/><\/a>');
  204.           </script>
  205.           <noscript>
  206.             <div>
  207.               <a href="http://realgameguides.com/" title="Valós Játék Leírások">
  208.                 <img class="banner468x60" src="http://realgameguides.com/img/banner.png" alt="Valós Játék Leírások" />
  209.               </a>
  210.             </div>
  211.           </noscript>
  212.         </div>
  213.       <?php if(isset($_GET['view'])): ?>
  214.         <iframe id="fbb" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fblog.realgameguides.com%2F%3Fview%3D<?php echo $_GET['view']; ?>&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;font&amp;colorscheme=light&amp;height=80"></iframe>
  215.       <?php endif; ?>
  216.       </div>
  217.       <div id="footer">
  218.         <a href="http://blog.realgameguides.com/">Nyitólap</a> &#124;
  219.         <a href="http://blog.realgameguides.com/?view=kapcsolat">Kapcsolat</a> &#124;
  220.         <a href="http://realgameguides.com/">Valós Játék Leírások</a> &#124;
  221.         <a href="http://validator.w3.org/check?uri=referer">
  222.           Érvényes
  223.           <abbr title="eXtensible HyperText Markup Language">XHTML</abbr>
  224.         </a> &#124;
  225.         <a href="http://jigsaw.w3.org/css-validator/check/referer">
  226.           Érvényes <abbr title="Cascading Style Sheets">CSS</abbr>
  227.         </a>
  228.         &#124; &copy; 2011 Mórocz Tamás, Poetro - Minden jog fenntartva!
  229.       </div>
  230.     </div>
  231.   </body>
  232. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement