Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
1 result

Target

Select target project
  • noblogs/noblogs-cli
1 result
Select Git revision
  • master
1 result
Show changes
Commits on Source (3)
......@@ -12,9 +12,6 @@ Known commands:
info BLOG [...]
Print some basic information about one or more blogs.
connectdb BLOG
Connect to the MySQL instance that has the blog db.
get-option OPTION_NAME BLOG [...]
Print the value of an option for the specified blogs.
......@@ -47,9 +44,6 @@ Known commands:
for a blog that is not local is dangerous! Use the 'on-local-blogs'
wrapper.
fix-rewrites BLOG [...]
Fix broken rewrite rules for the specified blogs. NOTE: dangerous!!!!
close-comments-if-inactive BLOG [...]
Closes old posts for comments on non-active blogs.
......@@ -57,9 +51,6 @@ Known commands:
Remove the 'network upgrade' message when all the blogs have
been upgraded individually.
update-friend-domains
Update the list of 'friend' email domains.
check-updates
Check for updates of core, plugins and themes.
Options:
......@@ -67,14 +58,6 @@ Known commands:
-mail sends email to ai-changes@investici.org
-json print JSON output
set-readonly on|off
Set read-only mode for the local noblogs installation. The argument
must be either the literal 'on' or 'off'.
ngg-convert BLOG
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.
......@@ -123,22 +106,6 @@ function do_info($args) {
}
}
// 'connectdb': Connect to the database hosting a specific blog.
function do_connectdb($args) {
$blog = noblogs_get_blog($args[0]);
if (!$blog) {
die("Blog not found.\n");
}
$backend = noblogs_get_backend_for_blog($blog->blog_id);
echo "ID: {$blog->blog_id}\n";
$cmd = "mysql -A -h {$backend['host']} -P {$backend['port']} -u{$backend['user']} -p{$backend['password']} {$backend['db']}";
echo "$cmd\n";
//system($cmd);
}
// 'get-option': Print the value of a blog option.
function do_get_option($args) {
$option = $args[0];
......@@ -227,7 +194,6 @@ function do_dump_shards($args) {
echo "\n";
}
// 'print-all-blogs': List all blog IDs.
function do_print_all_blogs($args) {
$blogs = noblogs_get_blogs();
......@@ -236,7 +202,6 @@ function do_print_all_blogs($args) {
}
}
// 'print-local-blogs': List the blog IDs that are local to this machine.
function do_print_local_blogs($args) {
$local_blogs = noblogs_get_local_blogs();
......@@ -245,7 +210,6 @@ function do_print_local_blogs($args) {
}
}
// 'remove-network-upgrade-message': Remove the annoying "network
// upgrade necessary" banner from the dashboard.
function do_remove_network_upgrade_message($args) {
......@@ -253,7 +217,6 @@ function do_remove_network_upgrade_message($args) {
update_site_option('wpmu_upgrade_site', $wp_db_version);
}
// 'check-upgrade': Check if a blog needs to be upgraded.
function do_check_upgrade($args) {
global $wp_db_version;
......@@ -274,7 +237,6 @@ function do_check_upgrade($args) {
}
}
// 'upgrade': Upgrade a blog.
function do_upgrade($args) {
//include(NOBLOGS_ROOT . "/wp-admin/includes/upgrade.php");
......@@ -292,7 +254,6 @@ function do_upgrade($args) {
}
}
// 'run-cron': Run cron jobs.
function do_run_cron($args) {
foreach ($args as $arg) {
......@@ -308,31 +269,6 @@ function do_run_cron($args) {
}
}
// 'fix-rewrites': Fix rewrite rules
function do_fix_rewrites($args) {
global $wp_rewrite;
foreach ($args as $arg) {
$blog = noblogs_get_blog($arg);
if (!$blog) {
echo "Blog {$arg} not found.\n";
continue;
}
switch_to_blog($blog->blog_id);
$wp_rewrite->init();
create_initial_taxonomies();
$wp_rewrite->flush_rules();
echo "{$arg}: ok\n";
restore_current_blog();
}
}
function do_update_friend_domains($args) {
$domains = noblogs_list_friend_domains();
update_site_option('limited_email_domains', $domains);
echo "Update done.\n";
}
function do_check_spam($args) {
global $wpdb;
$spamcount = 0;
......@@ -450,35 +386,6 @@ function do_check_updates($args) {
}
// 'set-readonly': toggle readonly mode by modifying .htaccess
function do_set_readonly($args) {
$htaccess = NOBLOGS_ROOT . '/.htaccess';
if ($args[0] == "on") {
comment_with_markers($htaccess, 'readonly', false);
} elseif ($args[0] == "off") {
comment_with_markers($htaccess, 'readonly', true);
} else {
print "Argument must be either 'on' or 'off'.";
}
}
function do_ngg_convert($args) {
require_once(dirname(__FILE__) . '/ngg.php');
foreach ($args as $arg) {
$blog = noblogs_get_blog($arg);
if (!$blog) {
echo "Blog {$arg} not found.\n";
continue;
}
switch_to_blog($blog->blog_id);
echo "Converting blog ${arg}: \n";
$post_ids = ngg_convert();
ngg_alert_admin($post_ids);
restore_current_blog();
}
}
// replaces http with https, and removes ending slash
function add_https_to_uri($uri){
$re = "#^http[s]?://([^.]+\.noblogs\.org)[/]?$#i";
......
<?php
function _is_domain($x) {
return ($x != "" && $x[0] != "#");
}
function noblogs_list_friend_domains() {
exec("ldapsearch -LLL -u -x '(&(status=active)(acceptMail=true))' cn | awk '/^cn:/ {print $2}'", $ldap_domains);
$ext_domains = explode("\n", file_get_contents("/etc/noblogs/friend_domains"));
$all_domains = array_filter(array_merge($ldap_domains, $ext_domains),
"_is_domain");
sort($all_domains);
return $all_domains;
}
<?php
require_once(NOBLOGS_ROOT . '/wp-admin/includes/media.php');
require_once(NOBLOGS_ROOT . '/wp-admin/includes/file.php');
require_once(NOBLOGS_ROOT . '/wp-admin/includes/image.php');
function ngg_get_post_ids( $limit = -1 ) {
$args = array(
's' => '[nggallery',
'post_type' => array( 'post', 'page' ),
'post_status' => 'any',
'nopaging' => true,
'fields' => 'ids',
'posts_per_page' => $limit
);
$query = new WP_Query( $args );
return $query->posts;
}
function do_ngg_count($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);
$post_ids = ngg_get_post_ids();
$count = count($post_ids);
echo "${arg} : ${count} \n";
foreach ( $post_ids as $post_id ) {
$post = get_post( $post_id );
$gallery_count = count(ngg_find_gallery_shortcodes($post));
echo "\t ${post_id}: ${gallery_count} \n";
}
restore_current_blog();
}
}
function ngg_upload_image($post, $path, $image){
$url = home_url( trailingslashit( $path ) . $image->filename );
// Let's use a hash trick here to find our attachment post after it's been sideloaded.
$hash = md5( 'attachment-hash' . $url . $image->description . time() . rand( 1, 999 ) );
$result = media_sideload_image( $url, $post->ID, $hash );
if ( is_wp_error( $result ) ) {
echo sprintf( "Error loading %s: %s\n", $url, $result->get_error_message() );
return;
} else {
$attachments = get_posts( array(
'post_parent' => $post->ID,
's' => $hash,
'post_type' => 'attachment',
'posts_per_page' => -1,
) );
if ( ! $attachments || ! is_array( $attachments ) || count( $attachments ) != 1 ) {
echo sprintf( "Error: Could not insert attachment for %d\n", $post->ID );
return;
}
}
return $attachments[0];
}
function ngg_upload_gallery($post,$gallery_id){
global $wpdb;
$path = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}ngg_gallery WHERE gid = ". intval( $gallery_id ), ARRAY_A );
$images = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}ngg_pictures WHERE galleryid = ". intval( $gallery_id ) . " ORDER BY sortorder, pid ASC" );
if ( ! $path || ! $images ) {
echo sprintf( "Warning: Could not find images for nggallery %d\n", $gallery_id );
return;
}
$attached_images = [];
foreach ( $images as $image ) {
$attachment = ngg_upload_image($post, $path['path'], $image);
// Titles should fallback to the filename.
if ( ! trim( $image->alttext ) ) {
$image->alttext = $image->filename;
}
$attachment->post_title = $image->alttext;
$attachment->post_content = $image->description;
$attachment->menu_order = $image->sortorder;
update_post_meta( $attachment->ID, '_wp_attachment_image_alt', $image->alttext );
wp_update_post( $attachment );
$attached_images[] = $attachment->ID;
echo sprintf( "Log: Added attachment %d for post %d \n", $attachment->ID, $post->ID );
}
return array( $images, $attached_images );
}
// If there are existing images attached the post,
// let's remember to exclude them from our new gallery.
function ngg_exclude_existing_attachments($post_ID){
$existing_attachments_ids = get_posts( array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'post_parent' => $post_ID,
'post_mime_type' => 'image',
'fields' => 'ids',
) );
$attr = array();
if ( $existing_attachments_ids )
$attr['exclude'] = implode( ',', $existing_attachments_ids );
return $attr;
}
function ngg_find_gallery_shortcodes($post){
$matches = null;
preg_match_all( '/\[nggallery.*?\]/si', $post->post_content, $matches );
return $matches[0];
}
function ngg_parse_shortcode($shortcode){
$atts = shortcode_parse_atts($shortcode);
return intval( $atts['id'] );
}
function ngg_convert() {
global $wpdb;
$uploads = wp_upload_dir();
$baseurl = $uploads['baseurl'];
$posts_count = 0;
$gallery_count = 0;
$images_count = 0;
$blog_id = get_current_blog_id();
$post_ids = ngg_get_post_ids();
foreach ( $post_ids as $post_id ) {
$post = get_post( $post_id );
$matches = null;
// If there are existing images attached the post,
// let's remember to exclude them from our new gallery.
$code_attr = ngg_exclude_existing_attachments($post->ID);
foreach ( ngg_find_gallery_shortcodes($post) as $shortcode ){
$gallery_id = ngg_parse_shortcode($shortcode);
list ($gallery_images, $attached_images) = ngg_upload_gallery($post, $gallery_id);
if ( count($gallery_images) != count($attached_images) ) {
echo "Not replacing ${shortcode}. ";
echo sprintf("%d of %d images converted.\n", count($attached_images), count($gallery_images));
continue;
}
// Construct the [gallery] shortcode
$code_attr['ids'] = implode(',', $attached_images);
$new_shortcode = '[gallery';
foreach ( $code_attr as $key => $value )
$new_shortcode .= sprintf( ' %s="%s"', esc_attr( $key ), esc_attr( $value ) );
$new_shortcode .= ']';
$post->post_content = str_replace( $shortcode, $new_shortcode, $post->post_content );
echo sprintf( "Log: Blog id %d. Updated gallery id %d of post %d \n", $blog_id, $gallery_id, $post->ID );
$images_count += count($attached_images);
$gallery_count++;
}
// Booyaga!
wp_update_post( $post );
$posts_count++;
}
echo "Log: Converted ${posts_count} posts, ${gallery_count} galleries and ${images_count} images \n";
return $post_ids;
}
function ngg_alert_admin($post_ids = null) {
if (!$post_ids){
$post_ids = ngg_get_post_ids();
}
$posts_count = count($post_ids);
$blog_id = get_current_blog_id();
$blog_name = get_bloginfo('name');
if (!$blog_name){
$blog_name = home_url();
}
$blog_url = site_url();
$admin_email = get_bloginfo('admin_email');
$admin_user = get_user_by( 'email', $admin_email);
$admin_name = $admin_user->user_nicename;
if (!$admin_name){
$admin_name = $admin_email;
}
$post_list = "";
foreach ( $post_ids as $post_id ) {
$post_title = get_post($post_id)->post_title;
$post_url = get_permalink($post_id);
$post_list = $post_list . "${post_title}: ${post_url} \n";
}
$mail_body = <<<EOT
Dear ${admin_name},
you are receiving this message because your are the admin of the blog "${blog_name}"
${blog_url}
We are in the process of removing the NextGen Gallery Plugin and converting all existing
image galleries to the standard Wordpress media manager.
In your blog, we have found that the following posts include NextGen Galleries that should
have been converted:
${post_list}
If everything went well, you do not have to do anything at all.
Please check that the images are showing correctly, and let us know if something went wrong.
with love and +kaos
Autistici/Inventati
-------------------
Caro ${admin_name},
ricevi questa email perché sei l'amministratore del blog "${blog_name}"
${blog_url}
Stiamo per rimuovere il plugin NextGen Gallery e abbiamo trasferito tutte le gallerie
di immagini al gestore di media di Wordpress.
Nel tuo blog, ci sono i seguenti posts che includevano gallerie di NextGen e che sono
state convertite:
${post_list}
Se è andato tutto a buon fine, non devi fare nient'altro.
Controlla che le immagini si visualizzano correttamente, e facci sapere se c'è qualcosa
che non va.
con amore e +kaos
Autistici/Inventati
EOT;
echo "Sending email to ${admin_email} \n";
wp_mail($admin_email, "[Noblogs] Removing NextGen Gallery Plugin",
$mail_body, 'From: Autistici/Inventati <info@autistici.org>' . "\r\n");
}
......@@ -8,7 +8,6 @@ define('AI_CRON_SCRIPT', true);
// Load our includes.
require_once(dirname(__FILE__) . '/blogs.php');
require_once(dirname(__FILE__) . '/cron.php');
require_once(dirname(__FILE__) . '/friends.php');
require_once(dirname(__FILE__) . '/editfiles.php');
require_once(dirname(__FILE__) . '/wp-piwik.php');
......