Skip to content

Instantly share code, notes, and snippets.

@garvinhicking
Created January 29, 2015 12:44
Show Gist options
  • Save garvinhicking/5aa581920139f4847d59 to your computer and use it in GitHub Desktop.
Save garvinhicking/5aa581920139f4847d59 to your computer and use it in GitHub Desktop.
Serendipity iframe-less preview patch
diff --git a/include/functions_config.inc.php b/include/functions_config.inc.php
index ca0dfb6..e6a615e 100644
--- a/include/functions_config.inc.php
+++ b/include/functions_config.inc.php
@@ -826,7 +826,12 @@ function serendipity_iframe(&$entry, $mode = null) {
case 'preview':
$serendipity['smarty_preview'] = true;
- $data['preview'] = serendipity_printEntries(array($entry), ($entry['extended'] != '' ? 1 : 0), true);
+
+ if ($serendipity['iframe_preview']) {
+ $data['preview'] = serendipity_printEntries(array($entry), ($entry['extended'] != '' ? 1 : 0), true);
+ } else {
+ return '<html><body><script type="text/javascript">preview_window = window.open("' . $serendipity['baseURL'] . $serendipity['indexFile'] . '?serendipity[action]=entrypreview", "blogpreview' . md5($serendipity['baseURL']) . '"); preview_window.focus();</script></body></html>';
+ }
break;
}
return serendipity_smarty_show('preview_iframe.tpl', $data);
@@ -864,7 +869,11 @@ function serendipity_iframe_create($mode, &$entry) {
break;
case 'preview':
- $attr = ' height="300" ';
+ if ($serendipity['preview_iframe']) {
+ $attr = ' height="300" ';
+ } else {
+ $attr = ' height="0" ';
+ }
break;
}
diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php
index f04c556..a74a7ba 100644
--- a/include/functions_entries.inc.php
+++ b/include/functions_entries.inc.php
@@ -981,6 +981,10 @@ function serendipity_printEntryFooter($suffix = '.html', $totalEntries = null) {
function serendipity_getTotalEntries() {
global $serendipity;
+ if (empty($serendipity['fullCountQuery'])) {
+ return 0;
+ }
+
// The unique query condition was built previously in serendipity_fetchEntries()
if ($serendipity['dbType'] == 'sqlite' || $serendipity['dbType'] == 'sqlite3' || $serendipity['dbType'] == 'pdo-sqlite' || $serendipity['dbType'] == 'sqlite3oo') {
$querystring = "SELECT count(e.id) {$serendipity['fullCountQuery']} GROUP BY e.id";
diff --git a/include/genpage.inc.php b/include/genpage.inc.php
index 3ca97fc..9e5308a 100644
--- a/include/genpage.inc.php
+++ b/include/genpage.inc.php
@@ -31,6 +31,12 @@ $serendipity['smarty']->assignByRef('leftSidebarElements', $leftSidebarElements)
$serendipity['smarty']->assignByRef('rightSidebarElements', $rightSidebarElements);
switch ($serendipity['GET']['action']) {
+ case 'entrypreview':
+ if (isset($_SESSION['save_entry']) && serendipity_userLoggedIn()) {
+ serendipity_printEntries(array($_SESSION['save_entry']), 1);
+ }
+ break;
+
// User wants to read the diary
case 'read':
if (isset($serendipity['GET']['id'])) {
diff --git a/serendipity_config.inc.php b/serendipity_config.inc.php
index fa01e36..933a709 100644
--- a/serendipity_config.inc.php
+++ b/serendipity_config.inc.php
@@ -131,6 +131,14 @@ if (!isset($serendipity['template_backend'])) {
$serendipity['template_backend'] = '2k11';
}
+// iframe preview
+if (!isset($serendipity['iframe_preview'])) {
+ // Can currently be set to TRUE in serendipity_config_local.inc.php to force iframe previews
+ // But with time, this iframe preview will be removed eventually.
+ $serendipity['iframe_preview'] = false;
+}
+
+
// Available languages
if (!isset($serendipity['languages'])) {
$serendipity['languages'] = array('en' => 'English',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment