Skip to content

Commit 8012896

Browse files
committed
Added vaultpress plugin and activated for jquery.com
1 parent ee92e94 commit 8012896

8 files changed

+3620
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?php
2+
3+
class VaultPress_Database {
4+
5+
var $table = null;
6+
var $pks = null;
7+
8+
function VaultPress_Database() {
9+
$this->__construct();
10+
}
11+
12+
function __construct() {
13+
}
14+
15+
function attach( $table ) {
16+
$this->table=$table;
17+
}
18+
19+
function get_tables( $filter=null ) {
20+
global $wpdb;
21+
$rval = $wpdb->get_col( 'SHOW TABLES' );
22+
if ( $filter )
23+
$rval = preg_grep( $filter, $rval );
24+
return $rval;
25+
}
26+
27+
function show_create() {
28+
global $wpdb;
29+
if ( !$this->table )
30+
return false;
31+
$table = $wpdb->escape( $this->table );
32+
$results = $wpdb->get_row( "SHOW CREATE TABLE `$table`" );
33+
$want = 'Create Table';
34+
if ( $results )
35+
$results = $results->$want;
36+
return $results;
37+
}
38+
39+
function explain() {
40+
global $wpdb;
41+
if ( !$this->table )
42+
return false;
43+
$table = $wpdb->escape( $this->table );
44+
return $wpdb->get_results( "EXPLAIN `$table`" );
45+
}
46+
47+
function diff( $signatures ) {
48+
global $wpdb;
49+
if ( !is_array( $signatures ) || !count( $signatures ) )
50+
return false;
51+
if ( !$this->table )
52+
return false;
53+
$table = $wpdb->escape( $this->table );
54+
$diff = array();
55+
foreach ( $signatures as $where => $signature ) {
56+
$pksig = md5( $where );
57+
unset( $wpdb->queries );
58+
$row = $wpdb->get_row( "SELECT * FROM `$table` WHERE $where" );
59+
if ( !$row ) {
60+
$diff[$pksig] = array ( 'change' => 'deleted', 'where' => $where );
61+
continue;
62+
}
63+
$row = serialize( $row );
64+
$hash = md5( $row );
65+
if ( $hash != $signature )
66+
$diff[$pksig] = array( 'change' => 'modified', 'where' => $where, 'signature' => $hash, 'row' => $row );
67+
}
68+
return $diff;
69+
}
70+
71+
function count( $columns ) {
72+
global $wpdb;
73+
if ( !is_array( $columns ) || !count( $columns ) )
74+
return false;
75+
if ( !$this->table )
76+
return false;
77+
$table = $wpdb->escape( $this->table );
78+
$column = $wpdb->escape( array_shift( $columns ) );
79+
return $wpdb->get_var( "SELECT COUNT( $column ) FROM `$table`" );
80+
}
81+
82+
function wpdb( $query, $function='get_results' ) {
83+
global $wpdb;
84+
85+
if ( !is_callable( array( $wpdb, $function ) ) )
86+
return false;
87+
88+
$res = $wpdb->$function( $query );
89+
if ( !$res )
90+
return $res;
91+
switch ( $function ) {
92+
case 'get_results':
93+
foreach ( $res as $idx => $row ) {
94+
if ( isset( $row->option_name ) && $row->option_name == 'cron' )
95+
$res[$idx]->option_value = serialize( array() );
96+
}
97+
break;
98+
case 'get_row':
99+
if ( isset( $res->option_name ) && $res->option_name == 'cron' )
100+
$res->option_value = serialize( array() );
101+
break;
102+
}
103+
return $res;
104+
}
105+
106+
function get_cols( $columns, $limit=false, $offset=false, $where=false ) {
107+
global $wpdb;
108+
if ( !is_array( $columns ) || !count( $columns ) )
109+
return false;
110+
if ( !$this->table )
111+
return false;
112+
$table = $wpdb->escape( $this->table );
113+
$limitsql = '';
114+
$offsetsql = '';
115+
$wheresql = '';
116+
if ( $limit )
117+
$limitsql = ' LIMIT ' . intval( $limit );
118+
if ( $offset )
119+
$offsetsql = ' OFFSET ' . intval( $offset );
120+
if ( $where )
121+
$wheresql = ' WHERE ' . base64_decode($where);
122+
$rval = array();
123+
foreach ( $wpdb->get_results( "SELECT * FROM `$this->table` $wheresql $limitsql $offsetsql" ) as $row ) {
124+
// We don't need to actually record a real cron option value, just an empty array
125+
if ( isset( $row->option_name ) && $row->option_name == 'cron' )
126+
$row->option_value = serialize( array() );
127+
$keys = array();
128+
$vals = array();
129+
foreach ( get_object_vars( $row ) as $i => $v ) {
130+
$keys[] = sprintf( "`%s`", $wpdb->escape( $i ) );
131+
$vals[] = sprintf( "'%s'", $wpdb->escape( $v ) );
132+
if ( !in_array( $i, $columns ) )
133+
unset( $row->$i );
134+
}
135+
$row->hash = md5( sprintf( "(%s) VALUES(%s)", implode( ',',$keys ), implode( ',',$vals ) ) );
136+
$rval[]=$row;
137+
}
138+
return $rval;
139+
}
140+
}
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
<?php
2+
3+
class VaultPress_Filesystem {
4+
5+
var $type = null;
6+
var $dir = null;
7+
var $keys = array( 'ino', 'uid', 'gid', 'size', 'mtime', 'blksize', 'blocks' );
8+
9+
function VaultPress_Filesystem() {
10+
$this->__construct();
11+
}
12+
13+
function __construct() {
14+
}
15+
16+
function want( $type ) {
17+
$vp = VaultPress::init();
18+
19+
if ( $type == 'plugins' ) {
20+
$this->dir = realpath( $vp->resolve_content_dir() . 'plugins' );
21+
$this->type = 'p';
22+
return true;
23+
}
24+
if ( $type == 'themes' ) {
25+
$this->dir = realpath( $vp->resolve_content_dir() . 'themes' );
26+
$this->type = 't';
27+
return true;
28+
}
29+
if ( $type == 'uploads' ) {
30+
$this->dir = realpath( $vp->resolve_upload_path() );
31+
$this->type = 'u';
32+
return true;
33+
}
34+
if ( $type == 'content' ) {
35+
$this->dir = realpath( $vp->resolve_content_dir() );
36+
$this->type = 'c';
37+
return true;
38+
}
39+
if ( $type == 'root' ) {
40+
$this->dir = realpath( ABSPATH );
41+
$this->type = 'r';
42+
return true;
43+
}
44+
die( 'naughty naughty' );
45+
}
46+
47+
function fdump( $file ) {
48+
header("Content-Type: application/octet-stream;");
49+
header("Content-Transfer-Encoding: binary");
50+
@ob_end_clean();
51+
if ( !file_exists( $file ) || !is_readable( $file ) )
52+
die( "no such file" );
53+
if ( !is_file( $file ) && !is_link( $file ) )
54+
die( "can only dump files" );
55+
$fp = @fopen( $file, 'rb' );
56+
if ( !$fp )
57+
die( "could not open file" );
58+
while ( !feof( $fp ) )
59+
echo @fread( $fp, 8192 );
60+
@fclose( $fp );
61+
die();
62+
}
63+
64+
function stat( $file, $md5=true, $sha1=true ) {
65+
$rval = array();
66+
foreach ( stat( $file ) as $i => $v ) {
67+
if ( is_numeric( $i ) )
68+
continue;
69+
$rval[$i] = $v;
70+
}
71+
$rval['type'] = filetype( $file );
72+
if ( $rval['type'] == 'file' ) {
73+
if ( $md5 )
74+
$rval['md5'] = md5_file( $file );
75+
if ( $sha1 )
76+
$rval['sha1'] = sha1_file( $file );
77+
}
78+
$rval['path'] = str_replace( $this->dir, '', $file );
79+
return $rval;
80+
}
81+
82+
function ls( $what, $md5=false, $sha1=false, $limit=null, $offset=null ) {
83+
clearstatcache();
84+
$path = realpath($this->dir . $what);
85+
if ( is_file($path) )
86+
return $this->stat( $path, $md5, $sha1 );
87+
if ( is_dir($path) ) {
88+
$entries = array();
89+
$current = 0;
90+
$offset = (int)$offset;
91+
$orig_limit = (int)$limit;
92+
$limit = $offset + (int)$limit;
93+
foreach ( (array)$this->scan_dir( $path ) as $i ) {
94+
$current++;
95+
if ( $offset >= $current )
96+
continue;
97+
if ( $limit && $limit < $current )
98+
break;
99+
100+
// don't sha1 files over 100MB if we are batching due to memory consumption
101+
if ( $sha1 && $orig_limit > 1 && is_file( $i ) && (int)@filesize( $i ) > 104857600 )
102+
$sha1 = false;
103+
104+
$entries[] = $this->stat( $i, $md5, $sha1 );
105+
}
106+
return $entries;
107+
}
108+
}
109+
110+
function validate( $file ) {
111+
$rpath = realpath( $this->dir.$file );
112+
if ( !$rpath )
113+
die( serialize( array( 'type' => 'null', 'path' => $file ) ) );
114+
if ( is_dir( $rpath ) )
115+
$rpath = "$rpath/";
116+
if ( strpos( $rpath, $this->dir ) !== 0 )
117+
return false;
118+
return true;
119+
}
120+
121+
function dir_examine( $subdir='', $recursive=true, $origin=false ) {
122+
$res = array();
123+
if ( !$subdir )
124+
$subdir='/';
125+
$dir = $this->dir . $subdir;
126+
if ( $origin === false )
127+
$origin = $this->dir . $subdir;
128+
if ( is_file($dir) ) {
129+
if ( $origin == $dir )
130+
$name = str_replace( $this->dir, '/', $subdir );
131+
else
132+
$name = str_replace( $origin, '/', $dir );
133+
$res[$name] = $this->stat( $dir.$entry );
134+
return $res;
135+
}
136+
$d = dir( $dir );
137+
if ( !$d )
138+
return $res;
139+
while ( false !== ( $entry = $d->read() ) ) {
140+
$rpath = realpath( $dir.$entry );
141+
$bname = basename( $rpath );
142+
if ( is_link( $dir.$entry ) )
143+
continue;
144+
if ( $entry == '.' || $entry == '..' || $entry == '...' )
145+
continue;
146+
if ( !$this->validate( $subdir.$entry ) )
147+
continue;
148+
$name = str_replace( $origin, '/', $dir.$entry );
149+
$res[$name] = $this->stat( $dir.$entry );
150+
if ( $recursive && is_dir( $this->dir.$subdir.'/'.$entry ) ) {
151+
$res = array_merge( $res, $this->dir_examine( $subdir.$entry.'/', $recursive, $origin ) );
152+
}
153+
}
154+
return $res;
155+
}
156+
157+
function dir_checksum( $base, &$list, $recursive=true ) {
158+
if ( $list == null )
159+
$list = array();
160+
161+
if ( 0 !== strpos( $base, $this->dir ) )
162+
$base = $this->dir . rtrim( $base, '/' );
163+
164+
$shortbase = substr( $base, strlen( $this->dir ) );
165+
if ( !$shortbase )
166+
$shortbase = '/';
167+
$stat = stat( $base );
168+
$directories = array();
169+
$files = (array)$this->scan_dir( $base );
170+
array_push( $files, $base );
171+
foreach ( $files as $file ) {
172+
if ( $file !== $base && @is_dir( $file ) ) {
173+
$directories[] = $file;
174+
continue;
175+
}
176+
$stat = @stat( $file );
177+
if ( !$stat )
178+
continue;
179+
$shortstat = array();
180+
foreach( $this->keys as $key ) {
181+
if ( isset( $stat[$key] ) )
182+
$shortstat[$key] = $stat[$key];
183+
}
184+
$list[$shortbase][basename( $file )] = $shortstat;
185+
}
186+
$list[$shortbase] = md5( serialize( $list[$shortbase] ) );
187+
if ( !$recursive )
188+
return $list;
189+
foreach ( $directories as $dir ) {
190+
$this->dir_checksum( $dir, $list, $recursive );
191+
}
192+
return $list;
193+
}
194+
195+
function scan_dir( $path ) {
196+
$files = array();
197+
198+
if ( false === is_readable( $path ) ) {
199+
return array();
200+
}
201+
202+
$dh = opendir( $path );
203+
204+
if ( false === $dh ) {
205+
return array();
206+
}
207+
208+
while ( false !== ( $file = readdir( $dh ) ) ) {
209+
if ( $file == '.' || $file == '..' ) continue;
210+
$files[] = "$path/$file";
211+
}
212+
213+
closedir( $dh );
214+
sort( $files );
215+
return $files;
216+
}
217+
}

0 commit comments

Comments
 (0)