Your forum has been Ipsum-ified. Please consider doing a full recount, and remember to re-activate all of your plugins!', 'bbipsum' ), bb_get_uri( 'bb-admin/tools-recount.php', null, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN ) ) ); } if ( !empty( $_GET['deleted'] ) ) { bb_admin_notice( sprintf( __( 'Your forum has been cleaned of gibberish. Please consider doing a full recount.', 'bbipsum' ), bb_get_uri( 'bb-admin/tools-recount.php', null, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN ) ) ); } require_once dirname( __FILE__ ) . '/LoremIpsum.class.php'; $lipsum = new LoremIpsumGenerator(); ?>
' . __( 'Go back', 'bbipsum' ) . '
'; } else { bb_safe_redirect( $goback ); } exit; } if ( $_POST['action'] == 'delete' ) { bb_check_admin_referer( 'bbipsum-delete' ); if ( empty( $_POST['delete'] ) ) { bb_safe_redirect( wp_get_referer() ); exit; } global $bbdb; $bbdb->query( "DELETE FROM `$bbdb->users` WHERE `ID` IN ( SELECT `t`.* FROM ( SELECT `user_id` FROM `$bbdb->usermeta` WHERE `meta_key` = 'bbipsum' ) AS `t` )" ); $bbdb->query( "DELETE FROM `$bbdb->usermeta` WHERE `user_id` IN ( SELECT `t`.* FROM ( SELECT `user_id` FROM `$bbdb->usermeta` WHERE `meta_key` = 'bbipsum' ) AS `t` )" ); $bbdb->query( "DELETE FROM `$bbdb->topics` WHERE `topic_id` IN ( SELECT `t`.* FROM ( SELECT `object_id` FROM `$bbdb->meta` WHERE `meta_key` = 'bbipsum' AND `object_type` = 'bb_topic' ) AS `t` )" ); $bbdb->query( "DELETE FROM `$bbdb->meta` WHERE `object_id` IN ( SELECT `t`.* FROM ( SELECT `object_id` FROM `$bbdb->meta` WHERE `meta_key` = 'bbipsum' AND `object_type` = 'bb_topic' ) AS `t` ) AND `object_type` = 'bb_topic'" ); $bbdb->query( "DELETE FROM `$bbdb->posts` WHERE `post_id` IN ( SELECT `t`.* FROM ( SELECT `object_id` FROM `$bbdb->meta` WHERE `meta_key` = 'bbipsum' AND `object_type` = 'bb_post' ) AS `t` )" ); $bbdb->query( "DELETE FROM `$bbdb->meta` WHERE `object_id` IN ( SELECT `t`.* FROM ( SELECT `object_id` FROM `$bbdb->meta` WHERE `meta_key` = 'bbipsum' AND `object_type` = 'bb_post' ) AS `t` ) AND `object_type` = 'bb_post'" ); $goback = add_query_arg( 'deleted', 'true', remove_query_arg( 'updated', wp_get_referer() ) ); bb_safe_redirect( $goback ); exit; } } } add_action( 'bbipsum_pre_head', 'bbipsum_admin_parse' ); function bbipsum_admin_add() { bb_admin_add_submenu( 'bbIpsum', 'use_keys', 'bbipsum', 'tools-recount.php' ); } add_action( 'bb_admin_menu_generator', 'bbipsum_admin_add' ); /** * The same as WP_Pass::rand() except that this one allows a constant seed. */ function bbipsum_rand( $min = 0, $max = 4294967295 ) { global $bbipsum_seed, $bbipsum_rand, $_bbipsum_rand; if ( !isset( $bbipsum_seed ) ) { $bbipsum_seed = bb_generate_password(); } // Reset $bbipsum_rand after 14 uses // 16(md5) + 20(sha1) + 20(sha1) / 4 = 14 random numbers from $bbipsum_rand if ( empty( $bbipsum_rand ) || strlen( $bbipsum_rand ) < 8 ) { $bbipsum_rand = md5( $_bbipsum_rand . $bbipsum_seed, true ); $bbipsum_rand .= sha1( $bbipsum_rand, true ); $bbipsum_rand .= sha1( $bbipsum_rand . $bbipsum_seed, true ); $bbipsum_seed = md5( $bbipsum_seed . $bbipsum_rand ); $_bbipsum_rand = $bbipsum_rand; } // Take the first 4 digits for our value $value = substr( $bbipsum_rand, 0, 4 ); // Strip the first eight, leaving the remainder for the next call to wp_rand(). $bbipsum_rand = substr( $bbipsum_rand, 4 ); $value = current( unpack( 'Nvalue', $value ) ); // Reduce the value to be within the min - max range // 4294967295 = 0xffffffff = max random number if ( $max != 4294967295 ) $value = $min + ( ( $max - $min + 1 ) * ( $value / ( 4294967295 + 1 ) ) ); return absint( $value ); } function bbipsum_get_gibberish_name( $ipsum_type ) { switch ( $ipsum_type ) { case 1: return bbipsum_asdfjkl_generate( bbipsum_rand( 5, 20 ) ); case 2: return bbipsum_aroodles_generate( bbipsum_rand( 10, 30 ) ); case 3: return bbipsum_pikachu_generate( bbipsum_rand( 10, 30 ) ); case 0: default: require_once dirname( __FILE__ ) . '/LoremIpsum.class.php'; $lipsum = new LoremIpsumGenerator(); return ucfirst( str_replace( ',', '', trim( $lipsum->getContent( bbipsum_rand( 2, 4 ), 'plain', false ), " \t\n\r." ) ) ); } } function bbipsum_get_gibberish( $ipsum_type ) { switch ( $ipsum_type ) { case 1: return bbipsum_asdfjkl_generate( bbipsum_rand( 5, 40 ) ); case 2: return bbipsum_aroodles_generate( bbipsum_rand( 10, 60 ) ); case 3: return bbipsum_pikachu_generate( bbipsum_rand( 10, 60 ) ); case 0: default: require_once dirname( __FILE__ ) . '/LoremIpsum.class.php'; $lipsum = new LoremIpsumGenerator(); return ucfirst( str_replace( ',', '', trim( $lipsum->getContent( bbipsum_rand( 2, 8 ), 'plain', false ), " \t\n\r." ) ) ); } } function bbipsum_get_gibberish_html( $ipsum_type, $html = true ) { switch ( $ipsum_type ) { case 1: return bbipsum_filter( bbipsum_asdfjkl_generate( bbipsum_rand( 500, 5000 ) ), $html ); case 2: return bbipsum_filter( bbipsum_aroodles_generate( bbipsum_rand( 500, 5000 ), true ), $html ); case 3: return bbipsum_filter( bbipsum_pikachu_generate( bbipsum_rand( 500, 5000 ), true ), $html ); case 0: default: require_once dirname( __FILE__ ) . '/LoremIpsum.class.php'; $lipsum = new LoremIpsumGenerator(); return bbipsum_filter( $lipsum->getContent( bbipsum_rand( 100, 1000 ), 'txt' ), $html ); } } function bbipsum_split( $str ) { $ret = array(); for ( $i = 0, $l = function_exists( 'mb_strlen' ) ? mb_strlen( $str ) : strlen( $str ); $i < $l; $i++ ) { $ret[] = function_exists( 'mb_substr' ) ? mb_substr( $str, $i, 1) : substr( $str, $i, 1 ); } return $ret; } function bbipsum_asdfjkl_generate( $len ) { $asdfjkl = bbipsum_split( __( 'abcdefghijklmnopqrstuvwxyz0123456789 ', 'bbipsum' ) ); $ret = ''; for ( $i = 0; $i < $len; $i++ ) { $ret .= $asdfjkl[bbipsum_rand( 0, count( $asdfjkl ) - 1 )]; } return $ret; } function bbipsum_pikachu_expand( $word ) { if ( is_array( $word ) ) $word = $word[1]; $ret = ''; $i = bbipsum_rand( 1, 3 ); while ( $i-- ) { $ret .= $word; } return $ret; } function bbipsum_pikachu_generate( $len, $punctuate = false ) { $words = array( 'Pikachu', 'Ch(u)', '(Pika)', '(Pi)', 'Pi(ka)', 'kachu', '(Chu)' ); $w = count( $words ) - 1; $separators = array( ' ', '-' ); if ( $punctuate ) $separators = array_merge( $separators, array( '. ', '? ', '! ' ) ); $s = count( $separators ) - 1; $ret = ''; while ( strlen( $ret ) < $len ) { $word = $words[bbipsum_rand( 0, $w )]; if ( $word == 'kachu' && !$ret ) continue; $ret .= $separators[bbipsum_rand( 0, $s )] . preg_replace_callback( '/\(([^\)]*)\)/', 'bbipsum_pikachu_expand', $word ); } return trim( $ret, implode( '', $separators ) ); } // Algorithm by Sam P. function bbipsum_aroodles_generate( $len, $punctuate = false ) { $consonants = bbipsum_split( _c( 'bcdfghjklmnpstvwxyz|consonants', 'bbipsum' ) ); $c = count( $consonants ) - 1; $vowels = bbipsum_split( _c( 'aeiou|vowels', 'bbipsum' ) ); $v = count( $vowels ) - 1; $separators = array( ' ', '-' ); if ( $punctuate ) $separators = array_merge( $separators, array( '. ', '? ', '! ' ) ); $s = count( $separators ) - 1; $ret = ''; while ( strlen( $ret ) < $len ) { $ret .= $separators[bbipsum_rand( 0, $s )]; // Two consonants $ret .= bbipsum_rand( 0, 1 ) ? $consonants[bbipsum_rand( 0, $c )] : strtoupper( $consonants[bbipsum_rand( 0, $c )] ); $ret .= $consonants[bbipsum_rand( 0, $c )]; // Two to ten vowel [sic] $ret .= str_repeat( $vowels[bbipsum_rand( 0, $v )], bbipsum_rand( 2, 10 ) ); // One consonant $ret .= $consonants[bbipsum_rand( 0, $c )]; } return ucfirst( ltrim( $ret, implode( '', $separators ) ) ); } function bbipsum_rand_punctuation( $allow_none = false ) { if ( $allow_none && !bbipsum_rand( 0, 2 ) ) return ''; if ( bbipsum_rand( 0, 3 ) ) return '.'; if ( bbipsum_rand( 0, 1 ) ) return '?'; return '!'; } function bbipsum_rand_formatting( $sentence ) { $words = explode( ' ', $sentence ); $tags = array( 'strong', 'em', 'a href="#"' ); $opened = array(); $ret = ''; for ( $i = 0, $l = count( $words ); $i < $l; $i++ ) { switch ( bbipsum_rand( 0, 10 ) ) { case 0: if ( $opened ) { $ret .= ' ' . $words[$i] . '' . array_pop( $opened ) . '>'; break; } case 1: $tag = $tags[bbipsum_rand( 0, count( $tags ) - 1 )]; $ret .= ' <' . $tag . '>' . $words[$i] . '' . reset( explode( ' ', $tag ) ) . '>'; break; case 2: $tag = $tags[bbipsum_rand( 0, count( $tags ) - 1 )]; $ret .= ' <' . $tag . '>' . $words[$i]; $opened[] = reset( explode( ' ', $tag ) ); break; default: $ret .= ' ' . $words[$i]; } } while ( $opened ) { $ret .= '' . array_pop( $opened ) . '>'; } return trim( $ret ); } function bbipsum_filter( $_ipsum, $full_html = false ) { if ( $full_html ) { $sentences = array_values( array_filter( explode( '. ', strip_tags( str_replace( '', ' ', bbipsum_filter( $_ipsum . "\n" ) ) ) . ' ' ) ) ); $sentences = array_map( 'bbipsum_rand_formatting', $sentences ); $ret = ''; for ( $i = 0, $l = count( $sentences ); $i < $l; $i++ ) { $list_type = 'o'; switch ( bbipsum_rand( 0, 5 ) ) { case 0: $ret .= '
'; $_i = bbipsum_rand( 1, min( $l - $i, 5 ) ); $ret .= bbipsum_filter( strip_tags( implode( '. ', array_slice( $sentences, $i, $_i ) ) ), true ); $i += $_i; $ret .= ''; break; case 1: $ret .= "\n\n`\n"; $ret .= $sentences[$i] . "\n"; $ret .= $sentences[$i + 1]; $ret .= "\n`\n\n"; $i++; break; case 2: case 3: $ret .= "\n\n"; for ( $j = min( $l, $i + bbipsum_rand( 1, 5 ) ); $i < $j; $i++ ) { $ret .= $sentences[$i] . bbipsum_rand_punctuation() . ' '; } $ret .= "\n\n"; break; case 4: $list_type = 'u'; case 5: $ret .= '<' . $list_type . 'l>'; for ( $j = min( $l, $i + bbipsum_rand( 1, 5 ) ); $i < $j; $i++ ) { $ret .= '
' . implode( '
', array_map( 'bbipsum_filter', array_filter( explode( "\n", $_ipsum ), 'trim' ) ) ) . '
'; } $ipsum = explode( '.', $_ipsum ); $ret = ''; foreach ( $ipsum as $i ) { if ( trim( $i ) ) $ret .= ucfirst( trim( $i ) ) . '. '; } return trim( $ret ); }