From 96971be9d529279733a3751aa94ae93c70e1157e Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Mon, 17 May 2010 23:12:22 -0400 Subject: [PATCH] Pastie: Add recent pastes sidebar --- pastie/lib/Driver/Sql.php | 51 +++++++++++++++++++++++++++++++++++-- pastie/lib/Highlighter/LibGeshi.php | 3 +++ pastie/paste.php | 9 ++++++- pastie/templates/paste.inc | 4 +++ pastie/templates/recent.inc | 16 ++++++++++++ pastie/templates/view.inc | 6 ++++- pastie/themes/screen.css | 18 ++++++++++++- pastie/view.php | 1 + 8 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 pastie/templates/paste.inc create mode 100644 pastie/templates/recent.inc diff --git a/pastie/lib/Driver/Sql.php b/pastie/lib/Driver/Sql.php index 6723abb16..933b1a80b 100644 --- a/pastie/lib/Driver/Sql.php +++ b/pastie/lib/Driver/Sql.php @@ -76,7 +76,7 @@ class Pastie_Driver_Sql extends Pastie_Driver public function savePaste($bin, $paste, $syntax = 'none', $title = '') { $this->_connect(); - + $id = $this->_db->nextId('mySequence'); if (PEAR::isError($id)) { throw new Horde_Exception_Prior($id); @@ -114,7 +114,7 @@ class Pastie_Driver_Sql extends Pastie_Driver /** * Retrieves the paste from the database. - * + * * @param array $params Array of selectors to find the paste. * * @return array Array of paste information @@ -177,6 +177,53 @@ class Pastie_Driver_Sql extends Pastie_Driver } } + public function getPastes($bin) + { + $query = 'SELECT paste_id, paste_uuid, paste_title, paste_syntax, '. + 'paste_content, paste_owner, paste_timestamp ' . + 'FROM pastie_pastes WHERE paste_bin = ? ' . + 'ORDER BY paste_timestamp DESC'; + $values[] = 'default'; // FIXME: Horde_Share + + /* Make sure we have a valid database connection. */ + $this->_connect(); + + /* Log the query at a DEBUG log level. */ + Horde::logMessage(sprintf('Pastie_Driver_Sql#getPastes(): %s', $query), 'DEBUG'); + + /* Execute the query. */ + $result = $this->_db->query($query, $values); + + if ($result instanceof PEAR_Error) { + throw new Horde_Exception_Prior($result); + } + + $row = $result->fetchRow(DB_FETCHMODE_ASSOC); + if ($row instanceof PEAR_Error) { + throw new Horde_Exception_Prior($row); + } + + $pastes = array(); + while ($row && !($row instanceof PEAR_Error)) { + $pastes[$row['paste_uuid']] = array( + 'id' => $row['paste_id'], + 'uuid' => $row['paste_uuid'], + 'bin' => $row['paste_bin'], + 'title' => $row['paste_title'], + 'syntax' => $row['paste_syntax'], + 'paste' => $row['paste_content'], + 'owner' => $row['paste_owner'], + 'timestamp' => new Horde_Date($row['paste_timestamp']) + ); + + /* Advance to the new row in the result set. */ + $row = $result->fetchRow(DB_FETCHMODE_ASSOC); + } + $result->free(); + + return $pastes; + } + /** * Attempts to open a persistent connection to the SQL server. * diff --git a/pastie/lib/Highlighter/LibGeshi.php b/pastie/lib/Highlighter/LibGeshi.php index da368caad..f1830d794 100644 --- a/pastie/lib/Highlighter/LibGeshi.php +++ b/pastie/lib/Highlighter/LibGeshi.php @@ -11,6 +11,9 @@ class Pastie_Highlighter_LibGeshi extends Pastie_Highlighter { if ($syntax == 'none') { return '
' . $text . '
'; } else { + // Since we may be coming from another syntax highlighter, + // we'll try downcasing the syntax name and hope we get lucky. + $syntax = strtolower($syntax); $geshi = new GeSHi($text, $syntax); } $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS); diff --git a/pastie/paste.php b/pastie/paste.php index 8458391cc..395b7a140 100644 --- a/pastie/paste.php +++ b/pastie/paste.php @@ -36,11 +36,18 @@ if ($form->validate($vars)) { } } +try { + $recent = $pastie->driver->getPastes('default'); //FIXME: Horde_Share +} catch (Horde_Exception $e) { + $notification->push($e); +} + + $title = $form->getTitle(); require PASTIE_TEMPLATES . '/common-header.inc'; require PASTIE_TEMPLATES . '/menu.inc'; -$form->renderActive(null, null, $url, 'post'); +require PASTIE_TEMPLATES . '/paste.inc'; require $registry->get('templates', 'horde') . '/common-footer.inc'; diff --git a/pastie/templates/paste.inc b/pastie/templates/paste.inc new file mode 100644 index 000000000..2097b1c01 --- /dev/null +++ b/pastie/templates/paste.inc @@ -0,0 +1,4 @@ +'; +$form->renderActive(null, null, $url, 'post'); \ No newline at end of file diff --git a/pastie/templates/recent.inc b/pastie/templates/recent.inc new file mode 100644 index 000000000..a220e778a --- /dev/null +++ b/pastie/templates/recent.inc @@ -0,0 +1,16 @@ + +
+

Recent Pastings

+
+ +
+
+ | + | + +
+
+ +
\ No newline at end of file diff --git a/pastie/templates/view.inc b/pastie/templates/view.inc index d491fabf0..c4e8e9f43 100644 --- a/pastie/templates/view.inc +++ b/pastie/templates/view.inc @@ -1,3 +1,6 @@ +

@@ -7,4 +10,5 @@
-
\ No newline at end of file +
+
\ No newline at end of file diff --git a/pastie/themes/screen.css b/pastie/themes/screen.css index acf7cdc5c..f993e98d0 100644 --- a/pastie/themes/screen.css +++ b/pastie/themes/screen.css @@ -1,6 +1,22 @@ /* Insert CSS definitions here. */ +#recentPastes { + float: left; + width: 20%; + height: 100%; + border: 1px solid #c00; + padding: 2px; + overflow: hidden; + margin: 50px 15px 10px 15px; +} + +.recentPaste { + margin-top: 3px; +} + #showpaste { - margin: 35px; + margin: 10px 35px 10px 35px; + float: right; + width: 70%; } .pasteTitle { diff --git a/pastie/view.php b/pastie/view.php index ab2be4c36..d7735e6d4 100644 --- a/pastie/view.php +++ b/pastie/view.php @@ -19,6 +19,7 @@ $uuid = Horde_Util::getFormData('uuid'); if (!empty($uuid)) { try { $paste = $pastie->driver->getPaste(array('uuid' => $uuid)); + $recent = $pastie->driver->getPastes('default'); //FIXME: Horde_Share } catch (Horde_Exception $e) { $notification->push($e); $paste = null; -- 2.11.0