3v4l.org

run code in 300+ PHP versions simultaneously
<?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'] ]); } } ?>
Output for 5.4.0 - 5.4.31
Parse error: syntax error, unexpected ';' in /in/iDolJ on line 119
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/iDolJ on line 16
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/iDolJ on line 16
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/iDolJ on line 11
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/iDolJ on line 11
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/iDolJ on line 11
Process exited with code 255.

preferences:
213.04 ms | 1399 KiB | 122 Q