pub / rememori

Simple file-based bookmarking and notes application
git clone https://src.jayvii.de/pub/rememori.git
Home | Log | Files | Exports | Refs | README | RSS

rss.php (3179B)


      1 <?php
      2 
      3     /* Load library functions */
      4     $libs = array("api.php", "users.php", "helpers.php", "read.php");
      5     foreach ($libs as $lib) {
      6         include($_SERVER["DOCUMENT_ROOT"] . "/lib/" . $lib);
      7     }
      8 
      9     /* Load configurations */
     10     foreach (glob($_SERVER["DOCUMENT_ROOT"] . "/config/*.php") as $conf) {
     11         include($conf);
     12     }
     13 
     14     /* Gather POST input and validate if necessary */
     15     $category = validate_input_string(gather_post("category"));
     16     $user = validate_input_string(gather_post("user"));
     17     $token = validate_input_string(gather_post("token"));
     18     $return = validate_input_string(gather_post("return"));
     19 
     20     /* Fallback to GET request, if no POST was found */
     21     if (empty($category)) {
     22         $category = validate_input_string(gather_get("category"));
     23     }
     24     if (empty($user)) {
     25         $user = validate_input_string(gather_get("user"));
     26     }
     27     if (empty($token)) {
     28         $token = validate_input_string(gather_get("token"));
     29     }
     30     if (empty($return)) {
     31         $return = validate_input_string(gather_get("return"));
     32     }
     33 
     34     /* run authentification method. exit immediately if it fails */
     35     $auth = auth_user($user, $token, -1);
     36     if ($auth !== true) {
     37         http_response_code(401); // unauthorized
     38         api_error($return, $GLOBALS["i18n_noauth"]);
     39         exit(1);
     40     }
     41 
     42     /* fetch notes in the given category */
     43     $notes = gather_notes($user, $category);
     44 
     45     /* Sort filenames by edit timestamp */
     46     usort($notes, "sort_by_time");
     47 
     48     /* construct RSS URL */
     49     $rssurl = htmlspecialchars(
     50         "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]
     51     );
     52 
     53     /* construct icons URL */
     54     $icnurl = htmlspecialchars(
     55         "https://" . $_SERVER["SERVER_NAME"] . "/assets/img/favicon"
     56     );
     57 
     58     /* write RSS XML */
     59     http_response_code(200); // success
     60     header('Content-Type: text/xml');
     61 
     62 ?>
     63 
     64 <!-- XML header -->
     65 <rss
     66     version="2.0"
     67     xmlns:atom="http://www.w3.org/2005/Atom"
     68     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     69 >
     70 <channel>
     71 <title><?php echo $user . "/" . $category; ?></title>
     72 <icon><?php echo $icnurl . "_32.png"; ?></icon>
     73 <logo><?php echo $icnurl . ".png"; ?></logo> 
     74 <link><?php echo "https://" . $_SERVER["SERVER_NAME"] . "/"; ?></link>
     75 <description>
     76     Rememori notes in <?php echo $user . "/" . $category; ?>
     77 </description>
     78 <generator>rememori</generator>
     79 <lastBuildDate><?php echo date(DATE_ATOM, time()); ?></lastBuildDate>
     80 <atom:link href="<?php echo $rssurl; ?>" rel="self" type="application/rss+xml"/>
     81 
     82 <?php
     83 
     84     /* cycle through items in gather notes and list them */
     85     foreach ($notes as $note) {
     86 
     87         /* If the entry does not contain a link, skip it! */
     88         if (empty($note["link"])) {
     89             continue;
     90         }
     91 
     92 ?>
     93 
     94 <!-- item: <?php echo $note["name"]; ?> -->
     95 <item>
     96 <title><?php echo $note["name"]; ?></title>
     97 <link><?php echo $note["link"]; ?></link>
     98 <pubDate><?php echo date(DATE_ATOM, $note["time"]); ?></pubDate>
     99 <guid><?php echo $note["link"]; ?></guid>
    100 <description>
    101 <?php echo read_note($user, $note["category"], $note["name"] . ".txt"); ?>
    102 </description>
    103 </item>
    104 
    105 <?php
    106 
    107     } // foreach
    108 
    109 ?>
    110 
    111 </channel>
    112 </rss>