@ 2014-08-18T14:49:04Z <?php
/**
* Remote Negotiation Class, JSON Based
*
* @author Michael Telatynski <postmaster@t3chguy.co.uk>
* @copyright 2014 Web Development Guru
* @version 1.0
*/
class Remote extends AuthenticatedMySQLi {
private $site, $content, $zip;
private function selMiddle($a, $b, $s) { return (strpos($s, $a) === FALSE) ?FALSE:strstr(substr($s, strpos($s, $a) + strlen($a)), $b, TRUE); }
private function fitData($id, $name) {
if(count($rows = $this -> query('SELECT field, data FROM data WHERE uid=? AND file=?', 'is', [$id, $name])) > 0) {
foreach ($rows as $curr) { $this -> content = str_ireplace('{{DATA_' . $curr['field'] . '}}', (new Parsedown)->parse($curr['data']), $this -> content); }
}
}
private function fitIncludes() {
if (preg_match_all('/{{INCLUDE_([a-zA-Z1-9_].+?)}}/', $this -> content, $m, PREG_SET_ORDER) > 0) {
foreach ($m as $c) { if (file_exists($file = $c[1] . '.inc')) { $this -> content = str_ireplace($c[0], @file_get_contents($file), $this -> content); } }
}
return $this;
}
private function fitTestimonials($uid) {
$lot = $this -> query('SELECT author, content FROM testimonials WHERE uid=? ORDER BY RAND()', 'i', [$uid]);
$lot = array_map(function ($val) { return '<li><p class="text">' . $val['content'] . '</p><p class="author">' . $val['author'] . '</p></li>'; }, $lot);
$this -> content = str_replace('{{TESTIMONIAL_ARRAY}}', '<ul id="testimonials">' . implode($lot) . '</ul>', $this -> content);
return $this;
}
private function fitDynamics($css='') {
foreach(glob('*.css') as $file) { $css .= '/* ' . basename($file) . " */\n" . @file_get_contents($file) . "\n\n"; }
$replacements = [
'{{APIKEY}}' => $_GET['db'],
'{{CSS_FILE}}' => $css,
'{{REMOTE_URL}}' => $this -> site,
'{{BLOG_TTL_1}}' => '',
'{{BLOG_PRE_1}}' => '',
'{{BLOG_TTL_2}}' => '',
'{{BLOG_PRE_2}}' => '',
'{{BLOG_TTL_3}}' => '',
'{{BLOG_PRE_3}}' => '',
];
$this -> content = str_replace(array_keys($replacements), array_values($replacements), $this -> content);
return $this;
}
private function fitStatics() {
global $remoteTestimonial;
$replacements = [
'{{HOME_URL}}' => 'webdevguru.co.uk',
'{{DEFAULT_CSS}}' => '@import url("cms.{{HOME_URL}}/css/{{APIKEY}}/"); a[disabled] { pointer-events: none; }',
'{{WEBDEVGURU_LINK}}' => 'Design by: <a href="http://www.webdevguru.co.uk" target="_blank">www.WebDevGuru.co.uk</a>',
'{{COPYRIGHT_SNIPPET}}' => date('Y'),
'{{TESTIMONIAL_SCRIPT}}' => $remoteTestimonial,
"\n" => '',
"\r" => '',
"\t" => '',
];
$this -> content = str_replace(array_keys($replacements), array_values($replacements), $this -> content);
return $this;
}
private function padBlogging($blogs) {
$cframe = $this -> fitStatics() -> fitDynamics() -> selMiddle('{{COMMENTS_START}}', '{{COMMENTS_FINAL}}', $this -> content);
foreach ($blogs as $num => $blog) {
$replacements = [
'{{BLOG_REFNUM}}' => $num,
'{{BLOG_IDNUM}}' => $blog['id'],
'{{BLOG_TITLE}}' => $blog['title'],
'{{BLOG_IMAGE}}' => $blog['img'],
'{{BLOG_CONTENT}}' => $blog['content'],
'{{BLOG_PREV_HREF}}' => (in_array($num-1, array_keys($blogs))) ? 'href="page_' . $num-1 . '.buf.html"':'disabled="disabled"',
'{{BLOG_NEXT_HREF}}' => (in_array($num+1, array_keys($blogs))) ? 'href="page_' . $num+1 . '.buf.html"':'disabled="disabled"',
'{{COMMENTS_START}}' => '',
'{{COMMENTS_FINAL}}' => '',
];
if ($cframe !== FALSE) {
if (count($comments = $this -> query('SELECT name, data, date FROM blogging_c WHERE live=1 AND blog_uid=? ORDER BY date', 'i', [ $blog['id'] ])) > 0) {
$parsedcomments = '';
$commplacements = [
'{{COMMENT_NAME}}' => $comment['name'],
'{{COMMENT_DATA}}' => $comment['date'],
'{{COMMENT_DATA}}' => $comment['data'],
];
foreach ($comments as $comment) { $parsedcomments .= str_replace(array_keys($commplacements), array_values($commplacements), $cframe); }
$iter[$num] = str_replace([array_keys($replacements), $cframe], [array_values($replacements), $parsedcomments], $this -> content);
} else { $iter[$num]= str_replace([array_keys($replacements), $cframe], [array_values($replacements)], $this -> content); }
}
}
return $iter;
}
public function getID($id) { return count($x = $this -> query('SELECT id, name, enabled FROM sites WHERE password(id)=? LIMIT 1', 's', [$id])) ? $x:['enabled' => 'UNKNOWN APIKEY!']; }
private function recuriveZipAdd($pattern='') {
$this -> zip -> addGlob($pattern . '*.{css,js,png,jpeg,gif,ico,woff,ttf,svg,eot}', GLOB_BRACE);
foreach (glob($pattern . '*', GLOB_ONLYDIR | GLOB_MARK) as $file) { $this -> recuriveZipAdd($file); }
return $this;
}
public function createManifest() {
if (@chdir('site-data/' . $_GET['db'])) {
$this -> zip = new ZipArchive;
if (file_exists('manifest.zip')) { unlink('manifest.zip'); }
if ($this -> zip -> open('manifest.zip', ZipArchive::CREATE) === TRUE) { $this -> recuriveZipAdd() -> zip -> close(); }
die('{"Result":"OK","Message":"Successfully Generated New ZIP Assets Archive!"}');
} else { die('{"Result":"ERROR","Message":"Error Navigating to Directory"}'); }
}
public function sync() {
phpinfo();
var_dump(($id = $this -> getID(
$_GET['db']
));
/*$return = (
($id = $this -> getID(
$_GET['db']
)
)['enabled'] === '1899-11-30')
?: $id['enabled'];*/
if ($return === TRUE) {
chdir('site-data/' . $id['name']);
$this -> site = $id['name'];
$output = ['id' => $id['id'], 'name' => $id['name'], 'href' => 'http://cms.webdevguru.co.uk/site-data/' . $id['name'] . '/manifest.zip'];
foreach(glob('*.suf') as $file) {
if (file_exists($file) && !empty($this -> content = @file_get_contents($file))) {
$this -> fitIncludes() -> fitStatics() -> fitTestimonials($id['id']) -> fitDynamics() -> fitData($id['id'], basename($file));
$output['suf'][pathinfo($file, PATHINFO_FILENAME)] = preg_replace(['/<!--(.|\s)*?-->/', '/ {2,}/'], '', $this -> content);
}
}
if (file_exists('blog.buf')) {
$blogs = $this -> query('SELECT id, title, img, content FROM blogging_posts WHERE uid=?', 'i', [ $id['id'] ]);
if (count($blogs) > 0 && ($this -> content = @file_get_contents('blog.buf'))) { $output['buf'] = $this -> padBlogging($blogs); }
}
echo json_encode($output);
} else { die($return); }
}
public function conn() {
if (@file_get_contents('http://' . $_GET['db'] . '/GuruCMS_Remote.php')) { die('{"Message":"Sync Has Been Completed!"}'); }
die('{"Message":"' . $_GET['db'] . ' isn\'t Responding!"}'); }
}
public function addto() {
if (isset($_POST['name'], $_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { echo '{"Result":"OK"}'; } else { die('{"Result":"ERROR"}'); }
$this -> query('INSERT INTO mailinglists (uid, name, email) VALUES (?, ?, ?)', 'iss', [$this -> getID($_GET['db'])['id'], $_POST['name'], $_POST['email'] ]);
}
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.31 0.007 0.073 19.20 5.4.30 0.003 0.043 19.13 5.4.29 0.003 0.070 19.31 5.4.28 0.007 0.070 18.94 5.4.27 0.007 0.070 19.20 5.4.26 0.003 0.067 18.97 5.4.25 0.003 0.073 19.19 5.4.24 0.000 0.070 18.85 5.4.23 0.000 0.073 19.05 5.4.22 0.013 0.037 18.86 5.4.21 0.017 0.040 18.96 5.4.20 0.000 0.040 18.84 5.4.19 0.000 0.077 19.23 5.4.18 0.007 0.073 18.84 5.4.17 0.007 0.077 19.30 5.4.16 0.000 0.047 19.21 5.4.15 0.010 0.057 18.93 5.4.14 0.003 0.063 16.51 5.4.13 0.000 0.073 16.51 5.4.12 0.003 0.073 16.40 5.4.11 0.007 0.043 16.63 5.4.10 0.007 0.070 16.61 5.4.9 0.007 0.067 16.64 5.4.8 0.007 0.067 16.42 5.4.7 0.000 0.080 16.49 5.4.6 0.010 0.043 16.45 5.4.5 0.007 0.063 16.50 5.4.4 0.007 0.067 16.60 5.4.3 0.003 0.070 16.23 5.4.2 0.010 0.040 16.56 5.4.1 0.003 0.070 16.47 5.4.0 0.010 0.053 15.83 5.3.29 0.007 0.043 14.79 5.3.28 0.003 0.057 14.52 5.3.27 0.007 0.073 14.64 5.3.26 0.007 0.043 14.58 5.3.25 0.003 0.067 14.60 5.3.24 0.000 0.047 14.54 5.3.23 0.007 0.060 14.52 5.3.22 0.007 0.070 14.49 5.3.21 0.003 0.050 14.48 5.3.20 0.003 0.043 14.55 5.3.19 0.000 0.073 14.70 5.3.18 0.003 0.043 14.58 5.3.17 0.007 0.057 14.55 5.3.16 0.003 0.077 14.80 5.3.15 0.000 0.077 14.57 5.3.14 0.003 0.073 14.48 5.3.13 0.003 0.073 14.61 5.3.12 0.003 0.050 14.56 5.3.11 0.003 0.073 14.57 5.3.10 0.007 0.070 13.97 5.3.9 0.010 0.070 13.93 5.3.8 0.010 0.063 13.99 5.3.7 0.003 0.040 13.95 5.3.6 0.007 0.040 14.12 5.3.5 0.003 0.063 14.01 5.3.4 0.000 0.047 14.08 5.3.3 0.010 0.040 13.83 5.3.2 0.003 0.050 13.80 5.3.1 0.000 0.070 13.80 5.3.0 0.007 0.037 13.80 5.2.17 0.000 0.040 13.80 5.2.16 0.000 0.050 13.80 5.2.15 0.000 0.067 13.80 5.2.14 0.003 0.057 13.80 5.2.13 0.007 0.060 13.80 5.2.12 0.007 0.027 13.80 5.2.11 0.003 0.033 13.80 5.2.10 0.010 0.057 13.80 5.2.9 0.010 0.050 13.80 5.2.8 0.003 0.063 13.80 5.2.7 0.003 0.060 13.80 5.2.6 0.003 0.047 13.80 5.2.5 0.003 0.057 13.80 5.2.4 0.007 0.063 13.80 5.2.3 0.000 0.037 13.80 5.2.2 0.003 0.060 13.80 5.2.1 0.000 0.057 13.80 5.2.0 0.007 0.043 13.80 5.1.6 0.000 0.057 13.80 5.1.5 0.007 0.020 13.80 5.1.4 0.000 0.053 13.80 5.1.3 0.003 0.033 13.80 5.1.2 0.000 0.060 13.80 5.1.1 0.007 0.040 13.80 5.1.0 0.003 0.053 13.80 5.0.5 0.000 0.040 13.80 5.0.4 0.003 0.043 13.80 5.0.3 0.007 0.060 13.80 5.0.2 0.007 0.033 13.80 5.0.1 0.003 0.027 13.80 5.0.0 0.003 0.033 13.80 4.4.9 0.000 0.037 13.80 4.4.8 0.000 0.020 13.80 4.4.7 0.007 0.027 13.80 4.4.6 0.000 0.017 13.80 4.4.5 0.003 0.030 13.80 4.4.4 0.000 0.027 13.80 4.4.3 0.003 0.033 13.80 4.4.2 0.003 0.027 13.80 4.4.1 0.000 0.037 13.80 4.4.0 0.007 0.030 13.80 4.3.11 0.000 0.037 13.80 4.3.10 0.000 0.037 13.80 4.3.9 0.000 0.030 13.80 4.3.8 0.007 0.023 13.80 4.3.7 0.000 0.037 13.80 4.3.6 0.000 0.030 13.80 4.3.5 0.003 0.030 13.80 4.3.4 0.000 0.057 13.80 4.3.3 0.007 0.033 13.80 4.3.2 0.000 0.040 13.80 4.3.1 0.000 0.037 13.80 4.3.0 0.000 0.017 13.80
preferences:dark mode live preview
139.55 ms | 1394 KiB | 7 Q