Ver Fonte

Changes from who knows how long ago

Billy Barrow há 10 meses atrás
pai
commit
021894a470
4 ficheiros alterados com 72 adições e 10 exclusões
  1. 6 7
      index.php
  2. 34 0
      navigation.php
  3. 31 2
      pprf.php
  4. 1 1
      ppub.php

+ 6 - 7
index.php

@@ -7,13 +7,6 @@ define("INDEX_TYPE_MAIN", 0);
 define("INDEX_TYPE_TAG", 1);
 define("INDEX_TYPE_SEARCH", 2);
 
-$ppcl = null;
-if(USE_PPCL) {
-    include_once("ppcl.php");
-    $ppcl = new Ppcl();
-    $ppcl->from_string(file_get_contents(PUBLICATION_DIR . "/collection.ppcl"));
-}
-
 function get_ppub_file_list() {
     if(USE_PPIX) {
         include_once("ppix.php");
@@ -50,6 +43,9 @@ function get_ppub_file_list() {
         }
     }
     else if(USE_PPCL) {
+        include_once("ppcl.php");
+        $ppcl = new Ppcl();
+        $ppcl->from_string(file_get_contents(PUBLICATION_DIR . "/collection.ppcl"));
         $list = array();
         foreach($ppcl->publications as $pub) {
             array_push($list, $pub->name);
@@ -148,6 +144,9 @@ $file_name = $file;
 $file = PUBLICATION_DIR . "/" . $file;
 $ppcl_pub = null;
 if(USE_PPCL) {
+    include_once("ppcl.php");
+    $ppcl = new Ppcl();
+    $ppcl->from_string(file_get_contents(PUBLICATION_DIR . "/collection.ppcl"));
     $ppcl_pub = $ppcl->get_publication($file_name);
 }
 

+ 34 - 0
navigation.php

@@ -0,0 +1,34 @@
+<?php
+
+function baseline_navigation() {
+    ?>
+    <ul class="compressed">
+        <li><a href="<?php echo(SITE_URL);?>/"><span class="icon">🗞️</span>Latest</a></li>
+        <li><a href="<?php echo(SITE_URL);?>/feed.rss"><span class="icon">📡</span>RSS Feed</a></li>
+    </ul>
+    <?php
+}
+
+function baseline_banner_css() {
+    if(SITE_BANNER != null) { ?>
+        header[role="banner"] {
+            background:
+                url("<?php echo(SITE_BANNER); ?>");
+            background-position: center;
+            background-size: cover;
+        }
+        @media (prefers-color-scheme: dark) {
+            header[role="banner"] {
+                background:
+                    linear-gradient(
+                        rgba(43, 54, 65, 0.6),
+                        rgba(43, 54, 65, 0.6)
+                    ),
+                    url("<?php echo(SITE_BANNER); ?>");
+                background-position: center;
+                background-size: cover;
+            }
+        }
+        <?php 
+    }
+}

+ 31 - 2
pprf.php

@@ -101,6 +101,28 @@ function read_authenticated_message($handle, $ppcl) {
     return $data;
 }
 
+function get_ppub_length_after_truncation($ppub_name, $truncation_level) {
+    include_once("ppub.php");
+
+    $ppub = new Ppub();
+    $ppub->read_file(PUBLICATION_DIR . "/" . $ppub_name);
+    
+    if($truncation_level == 3) {
+        // TRUNCATE_AFTER_HEADER
+        return $ppub->blob_start;
+    }
+    else if($truncation_level == 2) {
+        // send_failure(1, "Truncation level " . $truncation_level . " on publication " . PUBLICATION_DIR . "/" . $ppub_name);
+        // TRUNCATE_AFTER_METADATA
+        return $ppub->asset_list[0]->end_location + $ppub->blob_start;
+    }
+    else {
+        // TRUNCATE_AFTER_DEFAULT_ASSET
+        return $ppub->asset_list[1]->end_location + $ppub->blob_start;
+    }
+
+}
+
 if(!ENABLE_PPRF) {
     send_failure(1, "PPRF has been disabled on this server");
 }
@@ -418,9 +440,16 @@ if($message_info["type"] == 4) {
     $path = PUBLICATION_DIR . "/" . $name;
     $size = filesize($path);
 
+    // Truncation level is derived from the first two flags of the request, 3 = 0b11
+    $truncation_level = ($flags & 3);
+    if($truncation_level > 0) {
+        $size = get_ppub_length_after_truncation($name, $truncation_level);
+    }
+    
     $ppub = fopen($path, 'rb');
-
-    $message = "\x00\x00";
+    
+    // Flags (currently only truncation flags supported)
+    $message = pack("v", $truncation_level);
     $message .= pack("P", $size);
 
     send_partial_message(133, $message);

+ 1 - 1
ppub.php

@@ -21,9 +21,9 @@ class Ppub {
     public $asset_index = array();
     public $asset_list = array();
     public $default_asset = null;
+    public $blob_start = 0;
 
     private $handle = null;
-    private $blob_start = 0;
 
     public function read_file($file_path) {
         $handle = fopen($file_path, "rb");