From 439a3c03a5ecdc8cd095dd34bb299d94a5babcf4 Mon Sep 17 00:00:00 2001 From: lucha <lucha@paranoici.org> Date: Wed, 23 Nov 2016 15:53:28 +0100 Subject: [PATCH] replace http with https in siteurl and home options --- bin/noblogs.in | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/bin/noblogs.in b/bin/noblogs.in index d7e9e41..13302a8 100755 --- a/bin/noblogs.in +++ b/bin/noblogs.in @@ -72,6 +72,9 @@ Known commands: Convert Next Gen Gallery (NGG) photo galleries to stardard Wordpress galleries, and then notify (via email) admins of the fact. + https-siteurl BLOG + Adds https (instead of http) to siteurl and home options. + <?php exit(1); } @@ -435,6 +438,36 @@ function do_ngg_convert($args) { } } +// replaces http with https, and removes ending slash +function add_https_to_uri($uri){ + $re = "http[s]?:\/\/([^.]+\.noblogs\.org)[/]?/i"; + $subst = "https://$1"; + return preg_replace($re,$subst,$uri); +} + +// adds https to siteurl and home options +function do_https_siteurl($args){ + foreach ($args as $arg) { + $blog = noblogs_get_blog($arg); + if (!$blog) { + echo "Blog {$arg} not found.\n"; + continue; + } + switch_to_blog($blog->blog_id); + + $siteurl = get_option('siteurl'); + $home = get_option('home'); + + $siteurl = add_https_to_uri($siteurl); + $home = add_https_to_uri($home); + + update_option('siteurl', $siteurl); + update_option('home', $home); + + echo "{$arg}: ${siteurl} | ${home}\n"; + restore_current_blog(); + } +} // Command-line parsing. $cmd = $argv[1]; @@ -448,4 +481,3 @@ if (!function_exists($cmd_func)) { help(); } call_user_func($cmd_func, array_slice($argv, 2)); - -- GitLab