From f574fe1a877396f5a2e9daf84395947b17023858 Mon Sep 17 00:00:00 2001
From: Anatoliy Belsky <ab@php.net>
Date: Wed, 28 Nov 2012 08:39:10 +0100
Subject: [PATCH] Support port config for postgres db connection

Upport from master
---
 include/db/pdo-postgres.inc.php | 13 ++++++++++++-
 include/db/postgres.inc.php     | 14 +++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/include/db/pdo-postgres.inc.php b/include/db/pdo-postgres.inc.php
index 07158a1d..c413fbc0 100644
--- a/include/db/pdo-postgres.inc.php
+++ b/include/db/pdo-postgres.inc.php
@@ -49,10 +49,21 @@ function serendipity_db_in_sql($col, &$search_ids, $type = ' OR ') {
 function serendipity_db_connect() {
     global $serendipity;
 
+    $host = port = '';
+    if (strlen($serendipity['dbHost'])) {
+        if (false !== strstr($serendipity['dbHost'], ':')) {
+            $tmp = explode(':', $serendipity['dbHost']);
+            $host = "host={$tmp[0]};";
+            $port = "port={$tmp[1]};";
+        } else {
+            $host = "host={$serendipity['dbHost']};";
+        }
+    }
+
     $serendipity['dbConn'] = new PDO(
                                sprintf(
                                  'pgsql:%sdbname=%s',
-                                 strlen($serendipity['dbHost']) ? ('host=' . $serendipity['dbHost'] . ';') : '',
+                                 "$host$port",
                                  $serendipity['dbName']
                                ),
                                $serendipity['dbUser'],
diff --git a/include/db/postgres.inc.php b/include/db/postgres.inc.php
index 310400af..da922706 100644
--- a/include/db/postgres.inc.php
+++ b/include/db/postgres.inc.php
@@ -53,10 +53,22 @@ function serendipity_db_connect() {
         $function = 'pg_connect';
     }
 
+    $host = port = '';
+    if (strlen($serendipity['dbHost'])) {
+        if (false !== strstr($serendipity['dbHost'], ':')) {
+            $tmp = explode(':', $serendipity['dbHost']);
+            $host = "host={$tmp[0]} ";
+            $port = "port={$tmp[1]} ";
+        } else {
+            $host = "host={$serendipity['dbHost']} ";
+        }
+    }
+
+
     $serendipity['dbConn'] = $function(
                                sprintf(
                                  '%sdbname=%s user=%s password=%s',
-                                 strlen($serendipity['dbHost']) ? ('host=' . $serendipity['dbHost'] . ' ') : '',
+                                 "$host$port",
                                  $serendipity['dbName'],
                                  $serendipity['dbUser'],
                                  $serendipity['dbPass']