[www-doc] [Git][VideoLAN.org/websites][master] 3 commits: set developer mode when served through php cli-server

Jean-Baptiste Kempf gitlab at videolan.org
Tue May 18 17:06:02 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN organization / websites


Commits:
3e026637 by Francois Cartegnie at 2021-05-12T16:36:19+02:00
set developer mode when served through php cli-server

- - - - -
22f97037 by Francois Cartegnie at 2021-05-18T15:29:45+02:00
allow rss to fail

- - - - -
6c557239 by Francois Cartegnie at 2021-05-18T15:29:49+02:00
allow to skip database

- - - - -


4 changed files:

- www.videolan.org/Makefile
- www.videolan.org/include/developer.php
- www.videolan.org/index.php
- www.videolan.org/vlc/skins.php


Changes:

=====================================
www.videolan.org/Makefile
=====================================
@@ -28,6 +28,10 @@ ifneq ($(PHP_IGNORES),)
   PHP_FILES := $(filter-out $(PHP_IGNORES:%=%.php), $(PHP_FILES))
 endif
 
+ifneq (${SKIP_DB},)
+  SKIP_DB := 1
+endif
+
 TARGETS := $(PHP_FILES:%.php=%.html) $(ROOT)/news-rss.html $(ROOT)/style/style.min.css \
 	$(ROOT)/style/bootstrap.min.css \
 	$(ROOT)/style/slick.min.css \
@@ -49,7 +53,7 @@ clean: clean-recursive
 	@echo "Preprocessing $@ ..."
 	@rm -f $@.tmp
 	@cd $(ROOT) || exit 1 ; \
-	if ! REQUEST_URI=$(ROOT)$(HERE) DOCUMENT_ROOT=$(ROOT) $(HERE)$(PHPCGI) $(HERE)$< > $(HERE)$@.tmp; then \
+	if ! REQUEST_URI=$(ROOT)$(HERE) DOCUMENT_ROOT=$(ROOT) SKIP_DATABASE=$(SKIP_DB) $(HERE)$(PHPCGI) $(HERE)$< > $(HERE)$@.tmp; then \
 		cat $(HERE)$@.tmp | tail -1 ; \
 		rm -f $(HERE)$@.tmp ; \
 		exit 1 ; \


=====================================
www.videolan.org/include/developer.php
=====================================
@@ -1,8 +1,12 @@
 <?php
 function isDeveloper() {
-    //comment the first one to be in developer mode
-    return false;
+    return (php_sapi_name() == 'cli-server');
+    //comment previous entry to be in developer mode
     return true;
 }
 
+function skipDatabase() {
+    return isset($_ENV['SKIP_DATABASE']) || isset($_SERVER['SKIP_DATABASE']);
+}
+
 ?>


=====================================
www.videolan.org/index.php
=====================================
@@ -264,19 +264,23 @@ include($_SERVER["DOCUMENT_ROOT"] . "/include/magpierss/rss_fetch.inc");
                 </h1>
                 <div lang=""><!-- tweets are often english, but some are french and we even retweeted arabic or similar, so the empty lang is intentional -->
                 <?php
-                $rss = fetch_rss("http://www.videolan.org/_twitter/userrss.php?xrt=0&xrp=1&c=40");
-                $i = 0;
-                $chars_per_entry = 240;
-                $entries_per_column = 5;
-                $columns = 1;
-                foreach ($rss->items as $item) {
-                    echo '<p dir="ltr" style="border-bottom: 1px dashed #CCC;padding-bottom:5px;margin-bottom:5px; text-align: left;">';
-                    echo preg_replace(array('^(http://\S+)^is', '^(https://\S+)^is'), '<a href="$1">$1</a>', str_replace("videolan:", "<b>" . date("Y-m-d h:i", strtotime($item['pubdate'])) . "</b>", $item['title']));
-                    echo "</p>";
-                    $i++;
-                    if ($i >= $columns * $entries_per_column) break;
-                    if ($i % $entries_per_column == 0) echo "</td><td>";
+                $rss = @fetch_rss("http://www.videolan.org/_twitter/userrss.php?xrt=0&xrp=1&c=40");
+                if( is_object($rss) )
+                {
+                    $i = 0;
+                    $chars_per_entry = 240;
+                    $entries_per_column = 5;
+                    $columns = 1;
+                    foreach ($rss->items as $item) {
+                        echo '<p dir="ltr" style="border-bottom: 1px dashed #CCC;padding-bottom:5px;margin-bottom:5px; text-align: left;">';
+                        echo preg_replace(array('^(http://\S+)^is', '^(https://\S+)^is'), '<a href="$1">$1</a>', str_replace("videolan:", "<b>" . date("Y-m-d h:i", strtotime($item['pubdate'])) . "</b>", $item['title']));
+                        echo "</p>";
+                        $i++;
+                        if ($i >= $columns * $entries_per_column) break;
+                        if ($i % $entries_per_column == 0) echo "</td><td>";
+                    }
                 }
+                else echo "<p>Could not load RSS feed</p>";
                 ?>
                 </div>
             </div>


=====================================
www.videolan.org/vlc/skins.php
=====================================
@@ -1,9 +1,15 @@
 <?php
-require_once '/home/videolan/etc/db-www.php';
-if( !($connect = pg_connect( $connect_string )) )
-  die( "connection to database failed" );
+require_once($_SERVER["DOCUMENT_ROOT"]."/include/developer.php");
 
-if( isset( $_POST["skin_id"] ) && isset( $_POST["rating"] ) )
+if( !skipDatabase() )
+{
+    require_once '/home/videolan/etc/db-www.php';
+    if( !($connect = pg_connect( $connect_string )) )
+        die( "connection to database failed" . empty($connect) );
+}
+else $connect = false;
+
+if( $connect != false && isset( $_POST["skin_id"] ) && isset( $_POST["rating"] ) )
 {
   if( $_COOKIE["skinrated_{$_POST["skin_id"]}"] != $_POST["skin_id"] )
   {
@@ -49,11 +55,19 @@ function AddSkin( $id, $name, $author, $img, $url, $dl, $date, $date_mod, $ratin
   echo "</div>\n";
 }
 
-$query = 'SELECT downloads, size FROM skins_pack WHERE id=0';
-$q = pg_query( $connect, $query );
-$r = pg_fetch_array( $q );
-$sp_dl = $r['downloads'];
-$sp_size = FormatSize( $r['size'] );
+if ( $connect != false )
+{
+    $query = 'SELECT downloads, size FROM skins_pack WHERE id=0';
+    $q = pg_query( $connect, $query );
+    $r = pg_fetch_array( $q );
+    $sp_dl = $r['downloads'];
+    $sp_size = FormatSize( $r['size'] );
+}
+else
+{
+    $sp_dl = 0;
+    $sp_size = 0;
+}
 
 ?>
 <script type='text/javascript'>
@@ -121,15 +135,19 @@ switch( $sort )
     break;
 }
 
-$q = pg_query( $connect, $query );
-while( $r = pg_fetch_array( $q ) )
+if( $connect != false )
 {
-  AddSkin( $r['id'], htmlspecialchars($r['name']), htmlspecialchars($r['author']), $r['image'],
-           $r['url'], $r['downloads'], $r['date_added'], $r['date_modified'],
-           $r['avg'], $r['count'], /*$r['avg_old'], $r['count_old'],*/
-           0/*$r['sign']*/, $r['min_version'], $r['size'] );
+    $q = pg_query( $connect, $query );
+    while( $r = pg_fetch_array( $q ) )
+    {
+      AddSkin( $r['id'], htmlspecialchars($r['name']), htmlspecialchars($r['author']), $r['image'],
+               $r['url'], $r['downloads'], $r['date_added'], $r['date_modified'],
+               $r['avg'], $r['count'], /*$r['avg_old'], $r['count_old'],*/
+               0/*$r['sign']*/, $r['min_version'], $r['size'] );
+    }
+    pg_close( $connect );
 }
-pg_close( $connect );
+else echo "<p><b>Failed to connect to database</b></p>";
 ?>
 
 



View it on GitLab: https://code.videolan.org/VideoLAN.org/websites/-/compare/748c67eb8f207d411e0f3a38185ba79e925ef612...6c557239d38b04122679b7432abfb330ab53c757

-- 
View it on GitLab: https://code.videolan.org/VideoLAN.org/websites/-/compare/748c67eb8f207d411e0f3a38185ba79e925ef612...6c557239d38b04122679b7432abfb330ab53c757
You're receiving this email because of your account on code.videolan.org.




More information about the www-doc mailing list