Permalink
Browse files

Added vaultpress plugin and activated for jquery.com

  • Loading branch information...
1 parent ee92e94 commit 801289681dfd77b38889b5d4dc8c75ba759ee54b @rdworth rdworth committed Feb 12, 2013
@@ -0,0 +1,140 @@
+<?php
+
+class VaultPress_Database {
+
+ var $table = null;
+ var $pks = null;
+
+ function VaultPress_Database() {
+ $this->__construct();
+ }
+
+ function __construct() {
+ }
+
+ function attach( $table ) {
+ $this->table=$table;
+ }
+
+ function get_tables( $filter=null ) {
+ global $wpdb;
+ $rval = $wpdb->get_col( 'SHOW TABLES' );
+ if ( $filter )
+ $rval = preg_grep( $filter, $rval );
+ return $rval;
+ }
+
+ function show_create() {
+ global $wpdb;
+ if ( !$this->table )
+ return false;
+ $table = $wpdb->escape( $this->table );
+ $results = $wpdb->get_row( "SHOW CREATE TABLE `$table`" );
+ $want = 'Create Table';
+ if ( $results )
+ $results = $results->$want;
+ return $results;
+ }
+
+ function explain() {
+ global $wpdb;
+ if ( !$this->table )
+ return false;
+ $table = $wpdb->escape( $this->table );
+ return $wpdb->get_results( "EXPLAIN `$table`" );
+ }
+
+ function diff( $signatures ) {
+ global $wpdb;
+ if ( !is_array( $signatures ) || !count( $signatures ) )
+ return false;
+ if ( !$this->table )
+ return false;
+ $table = $wpdb->escape( $this->table );
+ $diff = array();
+ foreach ( $signatures as $where => $signature ) {
+ $pksig = md5( $where );
+ unset( $wpdb->queries );
+ $row = $wpdb->get_row( "SELECT * FROM `$table` WHERE $where" );
+ if ( !$row ) {
+ $diff[$pksig] = array ( 'change' => 'deleted', 'where' => $where );
+ continue;
+ }
+ $row = serialize( $row );
+ $hash = md5( $row );
+ if ( $hash != $signature )
+ $diff[$pksig] = array( 'change' => 'modified', 'where' => $where, 'signature' => $hash, 'row' => $row );
+ }
+ return $diff;
+ }
+
+ function count( $columns ) {
+ global $wpdb;
+ if ( !is_array( $columns ) || !count( $columns ) )
+ return false;
+ if ( !$this->table )
+ return false;
+ $table = $wpdb->escape( $this->table );
+ $column = $wpdb->escape( array_shift( $columns ) );
+ return $wpdb->get_var( "SELECT COUNT( $column ) FROM `$table`" );
+ }
+
+ function wpdb( $query, $function='get_results' ) {
+ global $wpdb;
+
+ if ( !is_callable( array( $wpdb, $function ) ) )
+ return false;
+
+ $res = $wpdb->$function( $query );
+ if ( !$res )
+ return $res;
+ switch ( $function ) {
+ case 'get_results':
+ foreach ( $res as $idx => $row ) {
+ if ( isset( $row->option_name ) && $row->option_name == 'cron' )
+ $res[$idx]->option_value = serialize( array() );
+ }
+ break;
+ case 'get_row':
+ if ( isset( $res->option_name ) && $res->option_name == 'cron' )
+ $res->option_value = serialize( array() );
+ break;
+ }
+ return $res;
+ }
+
+ function get_cols( $columns, $limit=false, $offset=false, $where=false ) {
+ global $wpdb;
+ if ( !is_array( $columns ) || !count( $columns ) )
+ return false;
+ if ( !$this->table )
+ return false;
+ $table = $wpdb->escape( $this->table );
+ $limitsql = '';
+ $offsetsql = '';
+ $wheresql = '';
+ if ( $limit )
+ $limitsql = ' LIMIT ' . intval( $limit );
+ if ( $offset )
+ $offsetsql = ' OFFSET ' . intval( $offset );
+ if ( $where )
+ $wheresql = ' WHERE ' . base64_decode($where);
+ $rval = array();
+ foreach ( $wpdb->get_results( "SELECT * FROM `$this->table` $wheresql $limitsql $offsetsql" ) as $row ) {
+ // We don't need to actually record a real cron option value, just an empty array
+ if ( isset( $row->option_name ) && $row->option_name == 'cron' )
+ $row->option_value = serialize( array() );
+ $keys = array();
+ $vals = array();
+ foreach ( get_object_vars( $row ) as $i => $v ) {
+ $keys[] = sprintf( "`%s`", $wpdb->escape( $i ) );
+ $vals[] = sprintf( "'%s'", $wpdb->escape( $v ) );
+ if ( !in_array( $i, $columns ) )
+ unset( $row->$i );
+ }
+ $row->hash = md5( sprintf( "(%s) VALUES(%s)", implode( ',',$keys ), implode( ',',$vals ) ) );
+ $rval[]=$row;
+ }
+ return $rval;
+ }
+}
@@ -0,0 +1,217 @@
+<?php
+
+class VaultPress_Filesystem {
+
+ var $type = null;
+ var $dir = null;
+ var $keys = array( 'ino', 'uid', 'gid', 'size', 'mtime', 'blksize', 'blocks' );
+
+ function VaultPress_Filesystem() {
+ $this->__construct();
+ }
+
+ function __construct() {
+ }
+
+ function want( $type ) {
+ $vp = VaultPress::init();
+
+ if ( $type == 'plugins' ) {
+ $this->dir = realpath( $vp->resolve_content_dir() . 'plugins' );
+ $this->type = 'p';
+ return true;
+ }
+ if ( $type == 'themes' ) {
+ $this->dir = realpath( $vp->resolve_content_dir() . 'themes' );
+ $this->type = 't';
+ return true;
+ }
+ if ( $type == 'uploads' ) {
+ $this->dir = realpath( $vp->resolve_upload_path() );
+ $this->type = 'u';
+ return true;
+ }
+ if ( $type == 'content' ) {
+ $this->dir = realpath( $vp->resolve_content_dir() );
+ $this->type = 'c';
+ return true;
+ }
+ if ( $type == 'root' ) {
+ $this->dir = realpath( ABSPATH );
+ $this->type = 'r';
+ return true;
+ }
+ die( 'naughty naughty' );
+ }
+
+ function fdump( $file ) {
+ header("Content-Type: application/octet-stream;");
+ header("Content-Transfer-Encoding: binary");
+ @ob_end_clean();
+ if ( !file_exists( $file ) || !is_readable( $file ) )
+ die( "no such file" );
+ if ( !is_file( $file ) && !is_link( $file ) )
+ die( "can only dump files" );
+ $fp = @fopen( $file, 'rb' );
+ if ( !$fp )
+ die( "could not open file" );
+ while ( !feof( $fp ) )
+ echo @fread( $fp, 8192 );
+ @fclose( $fp );
+ die();
+ }
+
+ function stat( $file, $md5=true, $sha1=true ) {
+ $rval = array();
+ foreach ( stat( $file ) as $i => $v ) {
+ if ( is_numeric( $i ) )
+ continue;
+ $rval[$i] = $v;
+ }
+ $rval['type'] = filetype( $file );
+ if ( $rval['type'] == 'file' ) {
+ if ( $md5 )
+ $rval['md5'] = md5_file( $file );
+ if ( $sha1 )
+ $rval['sha1'] = sha1_file( $file );
+ }
+ $rval['path'] = str_replace( $this->dir, '', $file );
+ return $rval;
+ }
+
+ function ls( $what, $md5=false, $sha1=false, $limit=null, $offset=null ) {
+ clearstatcache();
+ $path = realpath($this->dir . $what);
+ if ( is_file($path) )
+ return $this->stat( $path, $md5, $sha1 );
+ if ( is_dir($path) ) {
+ $entries = array();
+ $current = 0;
+ $offset = (int)$offset;
+ $orig_limit = (int)$limit;
+ $limit = $offset + (int)$limit;
+ foreach ( (array)$this->scan_dir( $path ) as $i ) {
+ $current++;
+ if ( $offset >= $current )
+ continue;
+ if ( $limit && $limit < $current )
+ break;
+
+ // don't sha1 files over 100MB if we are batching due to memory consumption
+ if ( $sha1 && $orig_limit > 1 && is_file( $i ) && (int)@filesize( $i ) > 104857600 )
+ $sha1 = false;
+
+ $entries[] = $this->stat( $i, $md5, $sha1 );
+ }
+ return $entries;
+ }
+ }
+
+ function validate( $file ) {
+ $rpath = realpath( $this->dir.$file );
+ if ( !$rpath )
+ die( serialize( array( 'type' => 'null', 'path' => $file ) ) );
+ if ( is_dir( $rpath ) )
+ $rpath = "$rpath/";
+ if ( strpos( $rpath, $this->dir ) !== 0 )
+ return false;
+ return true;
+ }
+
+ function dir_examine( $subdir='', $recursive=true, $origin=false ) {
+ $res = array();
+ if ( !$subdir )
+ $subdir='/';
+ $dir = $this->dir . $subdir;
+ if ( $origin === false )
+ $origin = $this->dir . $subdir;
+ if ( is_file($dir) ) {
+ if ( $origin == $dir )
+ $name = str_replace( $this->dir, '/', $subdir );
+ else
+ $name = str_replace( $origin, '/', $dir );
+ $res[$name] = $this->stat( $dir.$entry );
+ return $res;
+ }
+ $d = dir( $dir );
+ if ( !$d )
+ return $res;
+ while ( false !== ( $entry = $d->read() ) ) {
+ $rpath = realpath( $dir.$entry );
+ $bname = basename( $rpath );
+ if ( is_link( $dir.$entry ) )
+ continue;
+ if ( $entry == '.' || $entry == '..' || $entry == '...' )
+ continue;
+ if ( !$this->validate( $subdir.$entry ) )
+ continue;
+ $name = str_replace( $origin, '/', $dir.$entry );
+ $res[$name] = $this->stat( $dir.$entry );
+ if ( $recursive && is_dir( $this->dir.$subdir.'/'.$entry ) ) {
+ $res = array_merge( $res, $this->dir_examine( $subdir.$entry.'/', $recursive, $origin ) );
+ }
+ }
+ return $res;
+ }
+
+ function dir_checksum( $base, &$list, $recursive=true ) {
+ if ( $list == null )
+ $list = array();
+
+ if ( 0 !== strpos( $base, $this->dir ) )
+ $base = $this->dir . rtrim( $base, '/' );
+
+ $shortbase = substr( $base, strlen( $this->dir ) );
+ if ( !$shortbase )
+ $shortbase = '/';
+ $stat = stat( $base );
+ $directories = array();
+ $files = (array)$this->scan_dir( $base );
+ array_push( $files, $base );
+ foreach ( $files as $file ) {
+ if ( $file !== $base && @is_dir( $file ) ) {
+ $directories[] = $file;
+ continue;
+ }
+ $stat = @stat( $file );
+ if ( !$stat )
+ continue;
+ $shortstat = array();
+ foreach( $this->keys as $key ) {
+ if ( isset( $stat[$key] ) )
+ $shortstat[$key] = $stat[$key];
+ }
+ $list[$shortbase][basename( $file )] = $shortstat;
+ }
+ $list[$shortbase] = md5( serialize( $list[$shortbase] ) );
+ if ( !$recursive )
+ return $list;
+ foreach ( $directories as $dir ) {
+ $this->dir_checksum( $dir, $list, $recursive );
+ }
+ return $list;
+ }
+
+ function scan_dir( $path ) {
+ $files = array();
+
+ if ( false === is_readable( $path ) ) {
+ return array();
+ }
+
+ $dh = opendir( $path );
+
+ if ( false === $dh ) {
+ return array();
+ }
+
+ while ( false !== ( $file = readdir( $dh ) ) ) {
+ if ( $file == '.' || $file == '..' ) continue;
+ $files[] = "$path/$file";
+ }
+
+ closedir( $dh );
+ sort( $files );
+ return $files;
+ }
+}
Oops, something went wrong.

3 comments on commit 8012896

Owner

scottgonzalez replied Feb 13, 2013

Why do we want to create a backup of jquery.com?

Contributor

rdworth replied Feb 13, 2013

Owner

scottgonzalez replied Feb 13, 2013

That makes sense. Thanks.

Please sign in to comment.