return $diff . " week" . plural($diff) . " ago"; } if (date('Y', $time) != date('Y', time())) { return date("j-M Y", $time); } return date("j-M", $time); } $last = null; list($dummy, $defhtml, $defjs, $defcss) = defaultCode(); $formatted = array(); arsort($order); foreach ($order as $key => $value) { $template_bin = array(); foreach ($bins[$key] as $bin) { $url = formatURL($bin['url'], $bin['revision']); $title = getTitleFromCode($bin); $firstTime = $bin['url'] != $last; // attempt to get the modified panels - note that this won't detect // if they're using their own template $args = array('?live'); $js = trim($bin['javascript']); $html = trim($bin['html']); $css = trim($bin['css']); if ($js && $js !== $defjs) { $args[] = 'javascript'; } if ($html && $html !== $defhtml) { $args[] = 'html'; } if ($css && $css !== $defcss) { $args[] = 'css';
exit; } } } // If they're saving via an XHR request, then second back JSON or JSONP response if ($ajax) { // supports plugins making use of JS Bin via ajax calls and callbacks if (array_key_exists('callback', $_REQUEST)) { echo $_REQUEST['callback'] . '("'; } $url = ROOT . '/' . $code_id . '/' . $revision; if (isset($_REQUEST['format']) && strtolower($_REQUEST['format']) == 'plain') { echo $url; } else { // FIXME - why *am* I sending "js" and "html" with the url to the bin? $data = array(code => $code_id, root => PATH, created => date('c', time()), revision => $revision, url => $url, edit => $url . '/edit', html => $url . '/edit', js => $url . '/edit', title => getTitleFromCode(array(html => $html, javascript => $javascript)), allowUpdate => $allowUpdate === false ? false : true, checksum => $allowUpdate); echo json_encode($data); // echo '{ "code": "' . $code_id . '", "root": "' . PATH . '", "created": "' . date('c', time()) . '", "revision": ' . $revision . ', "url" : "' . $url . '", "edit" : "' . $url . '/edit", "html" : "' . $url . '/edit", "js" : "' . $url . '/edit", "title": "' . .'" }'; } if (array_key_exists('callback', $_REQUEST)) { echo '")'; } } else { // code was saved, so lets do a location redirect to the newly saved code $edit_mode = false; if ($revision == 1) { header('Location: ' . ROOT . $code_id . '/edit'); } else { header('Location: ' . ROOT . $code_id . '/' . $revision . '/edit'); } }