Advertisement
Guest User

functions.inc.php

a guest
Sep 18th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. <?php
  2. function retrieveEntries($db, $id=NULL)
  3. {
  4.     /*
  5.     * If an entry ID was supplied, load the associated entry
  6.     */
  7.     if(isset($id))
  8.     {
  9.         $sql = "SELECT title, entry
  10.         FROM entries
  11.         WHERE id=?
  12.         LIMIT 1";
  13.         $stmt = $db->prepare($sql);
  14.         $stmt->execute(array($_GET['id']));
  15.         // Save the returned entry array
  16.         $e = $stmt->fetch();
  17.         // Set the fulldisp flag for a single entry
  18.         $fulldisp = 1;
  19.     }
  20.     /*
  21.     * If no entry ID was supplied, load all entry titles
  22.     */
  23.     else
  24.     {
  25.         $sql = "SELECT id, title
  26.         FROM entries
  27.         ORDER BY created DESC";
  28.         // Loop through returned results and store as an array
  29.         foreach($db->query($sql) as $row)
  30.         {
  31.         $e[] = array(
  32.         'id' => $row['id'],
  33.         'title' => $row['title']
  34.         );
  35.         }
  36.         // Set the fulldisp flag for multiple entries
  37.         $fulldisp = 0;
  38.         /*
  39.         * If no entries were returned, display a default
  40.         * message and set the fulldisp flag to display a
  41.         * single entry
  42.         */
  43.         if(!is_array($e))
  44.         {
  45.             $fulldisp = 1;
  46.             $e = array(
  47.             'title' => 'No Entries Yet',
  48.             'entry' => '<a href="/admin.php">Post an entry!</a>'
  49.             );
  50.         }
  51.     }
  52.         // Add the $fulldisp flag to the end of the array
  53.         array_push($e, $fulldisp);
  54.         return $e;
  55. }
  56.  
  57. function sanitizeData($data)
  58. {
  59.     // If $data is not an array, run strip_tags()
  60.     if(!is_array($data))
  61.     {
  62.         // Remove all tags except <a> tags
  63.         return strip_tags($data, "<a>");
  64.     }
  65.     // If $data is an array, process each element
  66.     else
  67.     {
  68.         // Call sanitizeData recursively for each array element
  69.         return array_map('sanitizeData', $data);
  70.     }
  71. }
  72.  
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement