pub / kontra

Der linke Newsaggregator.
git clone src.jayvii.de/pub/kontra.git
Home | Log | Files | Exports | Refs | README | RSS

gen_opml.php (1775B)


      1 <?php
      2 
      3 function gen_opml($config) {
      4 
      5     /* Gather news sources from selection */
      6     $input_keys = preg_grep(
      7         "/^source-[0-9]+$/",
      8         array_keys($_POST)
      9     );
     10     $sources = array();
     11     foreach ($input_keys as $key) {
     12         $sources[$_POST[$key]] = $config["sources"][$_POST[$key]];
     13     }
     14 
     15     $exp_hash = md5(serialize($sources));
     16     $file_name = "kontra_" . date("Y-m-d") . "_" . $exp_hash . ".opml";
     17 
     18     /* Set Download and content type headers */
     19     header('Content-Type: application/xml; charset=UTF-8');
     20     header('Content-Disposition: Attachment;filename="' . $file_name . '"');
     21 
     22     /* Build OPML file */
     23 ?>
     24 
     25 <opml version="2.0">
     26 <head>
     27     <title>
     28         Nachrichten-Export von Kontra -
     29         <?php echo "https://" . $_SERVER["SERVER_NAME"] . PHP_EOL; ?>
     30     </title>
     31 </head>
     32 <body>
     33 
     34 <?php
     35 
     36     /* Cycle through each source and write source entry */
     37     $indexes = array(
     38         "regions", "languages", "access", "medium", "topics"
     39     );
     40     foreach ($sources as $source) {
     41 
     42         /* Construct title */
     43         $title = $config["publisher"][$source["publisher"][0]]["name"] .
     44             ": " . $source["title"];
     45 
     46         /* Create category list */
     47         $categories = array();
     48         foreach ($indexes as $index) {
     49             foreach ($source[$index] as $category) {
     50                 array_push(
     51                     $categories,
     52                     $config[$index][$category]["name"]
     53                 );
     54             }
     55         }
     56 
     57 ?>
     58 
     59 <outline
     60     title="<?php echo $title; ?>"
     61     text="<?php echo $title; ?>"
     62     category="<?php echo implode(",", $categories); ?>"
     63     xmlUrl="<?php echo $source["rss"]; ?>"
     64     htmlUrl="<?php echo $source["web"]; ?>"
     65 />
     66 
     67 <?php
     68 
     69     } // foreach-source
     70 
     71 ?>
     72 
     73 </body>
     74 </opml>
     75 
     76 <?php
     77 
     78 } // function
     79 
     80 ?>