Pastie: A paste-bin-like application for Horde.
authorBen Klang <ben@alkaloid.net>
Tue, 18 May 2010 01:00:23 +0000 (21:00 -0400)
committerBen Klang <ben@alkaloid.net>
Tue, 18 May 2010 01:01:27 +0000 (21:01 -0400)
Supporting the Text_Highlighter and GeSHi highlighters, this simple pastebin facilitates secure sharing of code samples and other text within the context of a Horde session.

34 files changed:
pastie/COPYING [new file with mode: 0644]
pastie/LICENSE.ASL [new file with mode: 0644]
pastie/LICENSE.BSDL [new file with mode: 0644]
pastie/README [new file with mode: 0644]
pastie/config/conf.xml [new file with mode: 0644]
pastie/config/horde.local.php.dist [new file with mode: 0644]
pastie/config/prefs.php.dist [new file with mode: 0644]
pastie/docs/CHANGES [new file with mode: 0644]
pastie/docs/CREDITS [new file with mode: 0644]
pastie/docs/INSTALL [new file with mode: 0644]
pastie/docs/RELEASE_NOTES [new file with mode: 0644]
pastie/index.php [new file with mode: 0644]
pastie/lib/Api.php [new file with mode: 0644]
pastie/lib/Application.php [new file with mode: 0644]
pastie/lib/Block/example.php [new file with mode: 0644]
pastie/lib/Driver.php [new file with mode: 0644]
pastie/lib/Driver/Sql.php [new file with mode: 0644]
pastie/lib/Exception.php [new file with mode: 0644]
pastie/lib/Forms/Paste.php [new file with mode: 0644]
pastie/lib/Highlighter.php [new file with mode: 0644]
pastie/lib/Highlighter/LibGeshi.php [new file with mode: 0644]
pastie/lib/Highlighter/TextHighlighter.php [new file with mode: 0644]
pastie/lib/Pastie.php [new file with mode: 0644]
pastie/lib/Test.php [new file with mode: 0644]
pastie/locale/en_US/help.xml [new file with mode: 0644]
pastie/paste.php [new file with mode: 0644]
pastie/po/README [new file with mode: 0644]
pastie/scripts/sql/pastie.sql [new file with mode: 0644]
pastie/templates/common-header.inc [new file with mode: 0644]
pastie/templates/menu.inc [new file with mode: 0644]
pastie/templates/view.inc [new file with mode: 0644]
pastie/themes/graphics/pastie.png [new file with mode: 0644]
pastie/themes/screen.css [new file with mode: 0644]
pastie/view.php [new file with mode: 0644]

diff --git a/pastie/COPYING b/pastie/COPYING
new file mode 100644 (file)
index 0000000..a6b6756
--- /dev/null
@@ -0,0 +1,280 @@
+                   GNU GENERAL PUBLIC LICENSE
+                      Version 2, June 1991
+
+ Copyright 1989, 1991 Free Software Foundation, Inc.
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                           Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+\f
+                   GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+\f
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+\f
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+\f
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                           NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                    END OF TERMS AND CONDITIONS
diff --git a/pastie/LICENSE.ASL b/pastie/LICENSE.ASL
new file mode 100644 (file)
index 0000000..3f99def
--- /dev/null
@@ -0,0 +1,48 @@
+Version 1.0
+
+Copyright 2006-2010 The Horde Project. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+1. Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+3. The end-user documentation included with the redistribution, if
+any, must include the following acknowledgment:
+
+   "This product includes software developed by the Horde Project
+    (http://www.horde.org/)."
+
+Alternately, this acknowledgment may appear in the software itself, if
+and wherever such third-party acknowledgments normally appear.
+
+4. The names "Horde", "The Horde Project", and "Pastie" must not be
+used to endorse or promote products derived from this software without
+prior written permission. For written permission, please contact
+core@horde.org.
+
+5. Products derived from this software may not be called "Horde" or
+"Pastie", nor may "Horde" or "Pastie" appear in their name, without
+prior written permission of the Horde Project.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE HORDE PROJECT OR ITS CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+This software consists of voluntary contributions made by many
+individuals on behalf of the Horde Project. For more information on
+the Horde Project, please see <http://www.horde.org/>.
diff --git a/pastie/LICENSE.BSDL b/pastie/LICENSE.BSDL
new file mode 100644 (file)
index 0000000..ea2f0d1
--- /dev/null
@@ -0,0 +1,24 @@
+Copyright 2006-2010 The Horde Project.  All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE HORDE PROJECT
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/pastie/README b/pastie/README
new file mode 100644 (file)
index 0000000..7fd0b33
--- /dev/null
@@ -0,0 +1,86 @@
+What is Pastie?
+=================
+
+:Contact: foo@example.com
+
+.. contents:: Contents
+.. section-numbering::
+
+Pastie is ...
+
+This software is OSI Certified Open Source Software. OSI Certified is a
+certification mark of the `Open Source Initiative`_.
+
+.. _`Open Source Initiative`: http://www.opensource.org/
+
+
+Obtaining Pastie
+------------------
+
+Further information on Pastie and the latest version can be obtained at
+
+  http://www.horde.org/pastie/
+
+
+Documentation
+-------------
+
+The following documentation is available in the Pastie distribution:
+
+:README_:            This file
+:COPYING_:           Copyright and license information
+:LICENSE_:           Copyright and license information
+:`docs/CHANGES`_:    Changes by release
+:`docs/CREDITS`_:    Project developers
+:`docs/INSTALL`_:    Installation instructions and notes
+:`docs/TODO`_:       Development TODO list
+:`docs/UPGRADING`_:  Pointers on upgrading from previous Pastie versions
+
+
+Installation
+------------
+
+Instructions for installing Pastie can be found in the file INSTALL_ in the
+``docs/`` directory of the Pastie distribution.
+
+
+Assistance
+----------
+
+If you encounter problems with Pastie, help is available!
+
+The Horde Frequently Asked Questions List (FAQ), available on the Web at
+
+  http://www.horde.org/faq/
+
+The Horde Project runs a number of mailing lists, for individual applications
+and for issues relating to the project as a whole. Information, archives, and
+subscription information can be found at
+
+  http://www.horde.org/mail/
+
+Lastly, Horde developers, contributors and users also make occasional
+appearances on IRC, on the channel #horde on the freenode Network
+(irc.freenode.net).
+
+
+Licensing
+---------
+
+For licensing and copyright information, please see the file COPYING_/LICENSE_
+[pick one] in the Pastie distribution.
+
+Thanks,
+
+The Pastie team
+
+
+.. _README: ?f=README.html
+.. _COPYING: http://www.horde.org/licenses/gpl.php
+.. _LICENSE: http://www.horde.org/licenses/asl.php
+.. _docs/CHANGES: ?f=CHANGES.html
+.. _docs/CREDITS: ?f=CREDITS.html
+.. _INSTALL:
+.. _docs/INSTALL: ?f=INSTALL.html
+.. _docs/TODO: ?f=TODO.html
+.. _docs/UPGRADING: ?f=UPGRADING.html
diff --git a/pastie/config/conf.xml b/pastie/config/conf.xml
new file mode 100644 (file)
index 0000000..63d3c0c
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!-- $Id$ -->
+<configuration>
+ <configsection name="storage">
+  <configheader>Storage System Settings</configheader>
+  <configswitch name="driver" desc="What storage driver should we use?">sql
+   <case name="sql" desc="SQL">
+    <configsection name="params">
+     <configsql switchname="driverconfig">
+     </configsql>
+    </configsection>
+   </case>
+  </configswitch>
+ </configsection>
+ <configsection name="highlighter">
+  <configheader>Text Highlighting Engine</configheader>
+  <configswitch name="engine" desc="Which highlighting engine should we use?">Text_Highlighter
+   <case name="TextHighlighter" desc="PEAR Text_Highlighter"/>
+   <case name="Geshi" desc="GeSHi - Generic Syntax Highlighter"/>
+  </configswitch>
+ </configsection>
+
+ <configsection name="menu">
+  <configheader>Menu Settings</configheader>
+  <configmultienum name="apps" desc="Select any applications that should be
+  linked in Pastie's menu">
+   <values>
+    <configspecial name="list-horde-apps" />
+   </values>
+  </configmultienum>
+ </configsection>
+</configuration>
diff --git a/pastie/config/horde.local.php.dist b/pastie/config/horde.local.php.dist
new file mode 100644 (file)
index 0000000..9793ac3
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+/* Defines the location of the Horde base directory, if it is not in its
+ * default location (TODO: where is default). */
+define('HORDE_BASE', '/path/to/horde');
diff --git a/pastie/config/prefs.php.dist b/pastie/config/prefs.php.dist
new file mode 100644 (file)
index 0000000..e32cd2b
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+/**
+ * See horde/config/prefs.php for documentation on the structure of this file.
+ *
+ * $Id$
+ */
+
+$prefGroups['Sample'] = array(
+    'column' => _("Sample Prefs"),
+    'label' => _("Sample Pref"),
+    'desc' => _("Set your sample preference."),
+    'members' => array('sample')
+);
+
+$_prefs['sample'] = array(
+    'value' => '',
+    'locked' => false,
+    'shared' => false,
+    'type' => 'text',
+    'desc' => _("This is your sample preference.")
+);
diff --git a/pastie/docs/CHANGES b/pastie/docs/CHANGES
new file mode 100644 (file)
index 0000000..3743cae
--- /dev/null
@@ -0,0 +1,5 @@
+-------
+0.1-git
+-------
+
+[xyz] Initial Release.
diff --git a/pastie/docs/CREDITS b/pastie/docs/CREDITS
new file mode 100644 (file)
index 0000000..eb85d5f
--- /dev/null
@@ -0,0 +1,24 @@
+===========================
+ Pastie Development Team
+===========================
+
+
+Core Developers
+===============
+
+
+
+Drivers
+=======
+
+
+
+Localization
+============
+
+=====================   ======================================================
+=====================   ======================================================
+
+
+Contributions
+=============
diff --git a/pastie/docs/INSTALL b/pastie/docs/INSTALL
new file mode 100644 (file)
index 0000000..065697e
--- /dev/null
@@ -0,0 +1,238 @@
+=====================
+ Installing Pastie
+=====================
+
+:Contact: foo@example.com
+
+.. contents:: Contents
+.. section-numbering::
+
+This document contains instructions for installing the Pastie ...
+
+For information on the capabilities and features of Pastie, see the file
+README_ in the top-level directory of the Pastie distribution.
+
+
+Obtaining Pastie
+==================
+
+Pastie can be obtained from the Horde website and FTP server, at
+
+   http://www.horde.org/pastie/
+
+   ftp://ftp.horde.org/pub/pastie/
+
+Or use the mirror closest to you:
+
+   http://www.horde.org/mirrors.php
+
+Bleeding-edge development versions of Pastie are available via Git; see the
+file `horde/docs/HACKING`_ in the Horde distribution, or the website
+http://www.horde.org/source/, for information on accessing the Horde Git
+repository.
+
+
+Prerequisites
+=============
+
+To function properly, Pastie **requires** the following:
+
+1. A working Horde installation.
+
+   Pastie runs within the `Horde Application Framework`_, a set of common
+   tools for Web applications written in PHP. You must install Horde before
+   installing Pastie.
+
+   .. Important:: Pastie 1.0 requires version 4.0+ of the Horde Framework -
+                  earlier versions of Horde will **not** work.
+
+   .. _`Horde Application Framework`: http://www.horde.org/horde/
+
+   The Horde Framework can be obtained from the Horde website and FTP server,
+   at
+
+      http://www.horde.org/horde/
+
+      ftp://ftp.horde.org/pub/horde/
+
+   .. Important:: Be sure to have completed all of the steps in the
+                  `horde/docs/INSTALL`_ file for the Horde Framework before
+                  installing Pastie. Many of Pastie's prerequisites are
+                  also Horde prerequisites. Additionally, many of Pastie's
+                  optional features are configured via the Horde install.
+
+2. The following PHP capabilities:
+
+   a. FOO support ``--with-foo`` [OPTIONAL]
+
+      Description of Foo and what it is used for.
+
+3. The following PEAR packages:
+   (See `horde/docs/INSTALL`_ for instructions on installing PEAR packages)
+
+   a. PEAR_Package x.x.x [OPTIONAL]
+
+      Pastie uses the Foo_Bar class for...
+
+4. The following PECL modules:
+   (See `horde/docs/INSTALL`_ for instructions on installing PECL modules)
+
+   a. pecl_package x.x.x [OPTIONAL]
+
+      pecl_package is required to...
+
+
+The following items are not required, but are strongly **RECOMMENDED**:
+
+1. Yet something else.
+
+
+Installing Pastie
+===================
+
+Pastie is written in PHP, and must be installed in a web-accessible
+directory. The precise location of this directory will differ from system to
+system. Conventionally, Pastie is installed directly underneath Horde in the
+web server's document tree.
+
+Since Pastie is written in PHP, there is no compilation necessary; simply
+expand the distribution where you want it to reside and rename the root
+directory of the distribution to whatever you wish to appear in the URL. For
+example, with the Apache web server's default document root of
+``/usr/local/apache/htdocs``, you would type::
+
+   cd /usr/local/apache/htdocs/horde
+   tar zxvf /path/to/pastie-h3-x.y.z.tar.gz
+   mv pastie-h3-x.y.z pastie
+
+and would then find Pastie at the URL::
+
+   http://your-server/horde/pastie/
+
+
+Configuring Pastie
+====================
+
+1. Configuring Horde for Pastie
+
+   a. Register the application
+
+      In ``horde/config/registry.php``, find the ``applications['pastie']``
+      stanza. The default settings here should be okay, but you can change
+      them if desired. If you have changed the location of Pastie relative
+      to Horde, either in the URL, in the filesystem or both, you must update
+      the ``fileroot`` and ``webroot`` settings to their correct values.
+
+2. Creating the database tables
+
+   The specific steps to create Pastie's database tables depend on which
+   database you've chosen to use.
+
+   First, look in ``scripts/sql/`` to see if a script already exists for your
+   database type. If so, you should be able to simply execute that script as
+   superuser in your database. (Note that executing the script as the "horde"
+   user will probably fail when granting privileges.)
+
+   If such a script does not exist, you'll need to build your own, using the
+   file ``pastie.sql`` as a starting point.  If you need assistance in
+   creating database tables, you may wish to let us know on the Pastie
+   mailing list.
+
+   You will also need to make sure that the "horde" user in your database has
+   table-creation privileges, so that the tables that `PEAR DB`_ uses to
+   provide portable sequences can be created.
+
+   .. _`PEAR DB`: http://pear.php.net/DB
+
+3. Configuring Pastie
+
+   To configure Pastie, change to the ``config/`` directory of the installed
+   distribution, and make copies of all of the configuration ``dist`` files
+   without the ``dist`` suffix::
+
+      cd config/
+      for foo in *.dist; do cp $foo `basename $foo .dist`; done
+
+   Or on Windows::
+
+      copy *.dist *.
+
+   Documentation on the format and purpose of those files can be found in each
+   file. You may edit these files if you wish to customize Pastie's
+   appearance and behavior. With one exception (``foo.php``) the defaults will
+   be correct for most sites.
+
+   You must login to Horde as a Horde Administrator to finish the
+   configuration of Pastie. Use the Horde ``Administration`` menu item to
+   get to the administration page, and then click on the ``Configuration``
+   icon to get the configuration page. Select ``Pastie Name`` from the
+   selection list of applications. Fill in or change any configuration values
+   as needed. When done click on ``Generate Pastie Name Configuration`` to
+   generate the ``conf.php`` file. If your web server doesn't have write
+   permissions to the Pastie configuration directory or file, it will not be
+   able to write the file. In this case, go back to ``Configuration`` and
+   choose one of the other methods to create the configuration file
+   ``pastie/config/conf.php``.
+
+   Note for international users: Pastie uses GNU gettext to provide local
+   translations of text displayed by applications; the translations are found
+   in the ``po/`` directory. If a translation is not yet available for your
+   locale (and you wish to create one), see the ``horde/po/README`` file, or
+   if you're having trouble using a provided translation, please see the
+   `horde/docs/TRANSLATIONS`_ file for instructions.
+
+4. More instructions, upgrading, securing, etc.
+
+5. Testing Pastie
+
+   Once you have configured Pastie, bring up the included test page in your
+   Web browser to ensure that all necessary prerequisites have been met. See
+   the `horde/docs/INSTALL`_ document for further details on the Horde test
+   script.
+
+   The test script will also allow you to test...
+
+   Next, use Pastie to.... Test at least the following:
+
+   - Foo
+   - Bar
+
+
+Known Problems
+==============
+
+...
+
+
+Obtaining Support
+=================
+
+If you encounter problems with Pastie, help is available!
+
+The Horde Frequently Asked Questions List (FAQ), available on the Web at
+
+  http://www.horde.org/faq/
+
+The Horde Project runs a number of mailing lists, for individual applications
+and for issues relating to the project as a whole. Information, archives, and
+subscription information can be found at
+
+  http://www.horde.org/mail/
+
+Lastly, Horde developers, contributors and users may also be found on IRC,
+on the channel #horde on the Freenode Network (irc.freenode.net).
+
+Please keep in mind that Pastie is free software written by volunteers.
+For information on reasonable support expectations, please read
+
+  http://www.horde.org/support.php
+
+Thanks for using Pastie!
+
+The Pastie team
+
+
+.. _README: ?f=README.html
+.. _`horde/docs/HACKING`: ../../horde/docs/?f=HACKING.html
+.. _`horde/docs/INSTALL`: ../../horde/docs/?f=INSTALL.html
+.. _`horde/docs/TRANSLATIONS`: ../../horde/docs/?f=TRANSLATIONS.html
diff --git a/pastie/docs/RELEASE_NOTES b/pastie/docs/RELEASE_NOTES
new file mode 100644 (file)
index 0000000..66a4346
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Release focus. Possible values:
+ * 0 - N/A
+ * 1 - Initial freshmeat announcement
+ * 2 - Documentation
+ * 3 - Code cleanup
+ * 4 - Minor feature enhancements
+ * 5 - Major feature enhancements
+ * 6 - Minor bugfixes
+ * 7 - Major bugfixes
+ * 8 - Minor security fixes
+ * 9 - Major security fixes
+ */
+$this->notes['fm']['focus'] = 4;
+
+/* Mailing list release notes. */
+$this->notes['ml']['changes'] = <<<ML
+The Horde Team is pleased to announce the [first release candidate|final
+release] of the Pastie Foo Bar Application version H3 (x.x).
+
+The Pastie Foo Bar Application is a...
+
+[For alpha/beta releases:
+This is a preview version that should not be used on production systems.  This
+version is considered feature complete but there might still be a few bugs.
+You should not use this preview version over existing production data.
+
+We encourage widespread testing and feedback via the mailing lists or our bug
+tracking system.  Updated translations are very welcome, though some strings
+might still change before the final release.]
+
+[For release candidates:
+Barring any problems, this code will be released as Pastie H3 (x.x).
+Testing is requested and comments are encouraged.
+Updated translations would also be great.]
+
+The major changes compared to the Pastie version H3 (x.x) are:
+[or: Pastie version H3 (x.y) is a major upgrade in the x.x release series,
+including these enhancements:]
+    * ...
+ML;
+
+/* Freshmeat release notes, not more than 600 characters. */
+$this->notes['fm']['changes'] = <<<FM
+FM;
+
+$this->notes['name'] = 'Pastie';
+$this->notes['fm']['project'] = 'pastie';
+$this->notes['fm']['branch'] = 'Default';
diff --git a/pastie/index.php b/pastie/index.php
new file mode 100644 (file)
index 0000000..9b55883
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+/**
+ * Pastie index script.
+ *
+ * Copyright 2007-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Your Name <you@example.com>
+ */
+
+require dirname(__FILE__) . '/paste.php';
diff --git a/pastie/lib/Api.php b/pastie/lib/Api.php
new file mode 100644 (file)
index 0000000..cd4b6e7
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+class Pastie_Api extends Horde_Registry_Api
+{
+}
diff --git a/pastie/lib/Application.php b/pastie/lib/Application.php
new file mode 100644 (file)
index 0000000..4535448
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/**
+ * Pastie application API.
+ *
+ * This file defines Horde's core API interface. Other core Horde libraries
+ * can interact with Pastie through this API.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Pastie
+ */
+
+/* Determine the base directories. */
+if (!defined('PASTIE_BASE')) {
+    define('PASTIE_BASE', dirname(__FILE__) . '/..');
+}
+
+if (!defined('HORDE_BASE')) {
+    /* If Horde does not live directly under the app directory, the HORDE_BASE
+     * constant should be defined in config/horde.local.php. */
+    if (file_exists(PASTIE_BASE . '/config/horde.local.php')) {
+        include PASTIE_BASE . '/config/horde.local.php';
+    } else {
+        define('HORDE_BASE', PASTIE_BASE . '/..');
+    }
+}
+
+/* Load the Horde Framework core (needed to autoload
+ * Horde_Registry_Application::). */
+require_once HORDE_BASE . '/lib/core.php';
+
+class Pastie_Application extends Horde_Registry_Application
+{
+    /**
+     * The application's version.
+     *
+     * @var string
+     */
+    public $version = 'H4 (0.1-git)';
+
+    protected function _init()
+    {
+        try {
+            $this->driver = Pastie_Driver::factory();
+        } catch (Pastie_Exception $e) {
+            $GLOBALS['notification']->notify($e);
+            return false;
+        }
+    }
+
+    /**
+     * Generate the menu to use on the prefs page.
+     *
+     * @return Horde_Menu  A Horde_Menu object.
+     */
+    public function prefsMenu()
+    {
+        return Pastie::getMenu();
+    }
+
+}
diff --git a/pastie/lib/Block/example.php b/pastie/lib/Block/example.php
new file mode 100644 (file)
index 0000000..c3cdc84
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+$block_name = _("Example Block");
+
+/**
+ * @package Horde_Block
+ */
+class Horde_Block_Pastie_example extends Horde_Block
+{
+    protected $_app = 'pastie';
+
+    protected function _params()
+    {
+        return array('color' => array('type' => 'text',
+                                      'name' => _("Color"),
+                                      'default' => '#ff0000'));
+    }
+
+    /**
+     * The title to go in this block.
+     *
+     * @return string   The title text.
+     */
+    protected function _title()
+    {
+        return _("Color");
+    }
+
+    /**
+     * The content to go in this block.
+     *
+     * @return string   The content
+     */
+    protected function _content()
+    {
+        $html  = '<table width="100" height="100" bgcolor="%s">';
+        $html .= '<tr><td>&nbsp;</td></tr>';
+        $html .= '</table>';
+
+        return sprintf($html, $this->_params['color']);
+    }
+
+}
diff --git a/pastie/lib/Driver.php b/pastie/lib/Driver.php
new file mode 100644 (file)
index 0000000..b8b702c
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Pastie_Driver:: defines an API for implementing storage backends for
+ * Pastie.
+ *
+ * Copyright 2007-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Your Name <you@example.com>
+ * @package Pastie
+ */
+class Pastie_Driver
+{
+    /**
+     * Array holding the current foo list. Each array entry is a hash
+     * describing a foo. The array is indexed by the IDs.
+     *
+     * @var array
+     */
+    protected $_foos = array();
+
+    /**
+     * Attempts to return a concrete instance based on $driver.
+     *
+     * @param string $driver  The type of the concrete subclass to return.
+     *                        The class name is based on the storage driver
+     *                        ($driver).  The code is dynamically included.
+     *
+     * @param array $params   A hash containing any additional configuration
+     *                        or connection parameters a subclass might need.
+     *
+     * @return Pastie_Driver  The newly created concrete instance.
+     * @throws Horde_Exception
+     */
+    static public function factory($driver = null, $params = null)
+    {
+        if (is_null($driver)) {
+            $driver = $GLOBALS['conf']['storage']['driver'];
+        }
+        $driver = ucfirst(basename($driver));
+
+        if (is_null($params)) {
+            $params = Horde::getDriverConfig('storage', $driver);
+        }
+
+        $class = 'Pastie_Driver_' . $driver;
+        if (class_exists($class)) {
+            return new $class($params);
+        }
+
+        throw new Horde_Exception('Could not find driver ' . $class);
+    }
+
+    /**
+     * Lists all foos.
+     *
+     * @return array  Returns a list of all foos.
+     */
+    public function listFoos()
+    {
+        return $this->_foos;
+    }
+
+}
diff --git a/pastie/lib/Driver/Sql.php b/pastie/lib/Driver/Sql.php
new file mode 100644 (file)
index 0000000..6723abb
--- /dev/null
@@ -0,0 +1,260 @@
+<?php
+/**
+ * Pastie storage implementation for PHP's PEAR database abstraction layer.
+ *
+ * Required values for $params:
+ * <pre>
+ * 'phptype' - The database type (e.g. 'pgsql', 'mysql', etc.).
+ * 'table' - The name of the foo table in 'database'.
+ * 'charset' - The database's internal charset.
+ * </pre>
+ *
+ * Required by some database implementations:
+ * <pre>
+ * 'database' - The name of the database.
+ * 'hostspec' - The hostname of the database server.
+ * 'protocol' - The communication protocol ('tcp', 'unix', etc.).
+ * 'username' - The username with which to connect to the database.
+ * 'password' - The password associated with 'username'.
+ * 'options' - Additional options to pass to the database.
+ * 'tty' - The TTY on which to connect to the database.
+ * 'port' - The port on which to connect to the database.
+ * </pre>
+ *
+ * The table structure can be created by the scripts/sql/pastie_foo.sql
+ * script.
+ *
+ * Copyright 2007-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (BSD). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/bsd.html.
+ *
+ * @author  Ben Klang <ben@alkaloid.net>
+ * @package Pastie
+ */
+class Pastie_Driver_Sql extends Pastie_Driver
+{
+    /**
+     * Hash containing connection parameters.
+     *
+     * @var array
+     */
+    protected $_params = array();
+
+    /**
+     * Handle for the current database connection.
+     *
+     * @var DB
+     */
+    protected $_db;
+
+    /**
+     * Handle for the current database connection, used for writing. Defaults
+     * to the same handle as $_db if a separate write database is not required.
+     *
+     * @var DB
+     */
+    protected $_write_db;
+
+    /**
+     * Boolean indicating whether or not we're connected to the SQL server.
+     *
+     * @var boolean
+     */
+    protected $_connected = false;
+
+    /**
+     * Constructs a new SQL storage object.
+     *
+     * @param array $params  A hash containing connection parameters.
+     */
+    public function __construct($params = array())
+    {
+        $this->_params = $params;
+    }
+
+    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);
+        }
+
+        $uuid = new Horde_Support_Uuid();
+
+        $bin = 'default'; // FIXME: Allow bins to be Horde_Shares
+
+        $query = 'INSERT INTO pastie_pastes (paste_id, paste_uuid, ' .
+                 'paste_bin, paste_title, paste_syntax, paste_content, ' .
+                 'paste_owner, paste_timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?)';
+        $values = array(
+                      $id,
+                      $uuid,
+                      $bin,
+                      $title,
+                      $syntax,
+                      $paste,
+                      Horde_Auth::getAuth(),
+                      time()
+        );
+
+        Horde::logMessage(sprintf('Pastie_Driver_Sql#savePaste(): %s', $query), 'DEBUG');
+        Horde::logMessage(print_r($values, true), 'DEBUG');
+
+        $result = $this->_write_db->query($query, $values);
+        if ($result instanceof PEAR_Error) {
+            Horde::logMessage($result, 'err');
+            throw new Horde_Exception_Prior($result);
+        }
+
+        return $uuid;
+    }
+
+    /**
+     * Retrieves the paste from the database.
+     * 
+     * @param array $params  Array of selectors to find the paste.
+     *
+     * @return array  Array of paste information
+     */
+    public function getPaste($params)
+    {
+        // Right now we will accept 'id' or 'uuid'
+        if (!isset($params['id']) && !isset($params['uuid'])) {
+            Horde::logMessage('Error: must specify some kind of unique id.', 'err');
+            throw new Pastie_Exception(_("Internal error.  Details have been logged for the administrator."));
+        }
+
+        $query = 'SELECT paste_id, paste_uuid, paste_title, paste_syntax, '.
+                 'paste_content, paste_owner, paste_timestamp ' .
+                 'FROM pastie_pastes ';
+        $values = array();
+        if (isset($params['id'])) {
+            $query .= 'WHERE paste_id = ? ';
+            $values[] = $params['id'];
+        } elseif (isset($params['uuid'])) {
+            $query .= 'WHERE paste_uuid = ? ';
+            $values[] = $params['uuid'];
+        }
+
+        $query .= 'AND paste_bin = ?';
+        $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#getPaste(): %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);
+        }
+        $result->free();
+
+        if ($row) {
+            return 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'])
+            );
+        } else {
+            throw new Pastie_Exception(_("Invalid paste ID."));
+        }
+    }
+
+    /**
+     * Attempts to open a persistent connection to the SQL server.
+     *
+     * @throws Horde_Exception
+     */
+    protected function _connect()
+    {
+        if ($this->_connected) {
+            return;
+        }
+
+        Horde::assertDriverConfig($this->_params, 'storage',
+                                  array('phptype', 'charset'));
+
+        if (!isset($this->_params['database'])) {
+            $this->_params['database'] = '';
+        }
+        if (!isset($this->_params['username'])) {
+            $this->_params['username'] = '';
+        }
+        if (!isset($this->_params['hostspec'])) {
+            $this->_params['hostspec'] = '';
+        }
+
+        /* Connect to the SQL server using the supplied parameters. */
+        $this->_write_db = DB::connect($this->_params,
+                                       array('persistent' => !empty($this->_params['persistent'])));
+        if ($this->_write_db instanceof PEAR_Error) {
+            throw new Horde_Exception_Prior($this->_write_db);
+        }
+
+        // Set DB portability options.
+        switch ($this->_write_db->phptype) {
+        case 'mssql':
+            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
+            break;
+
+        default:
+            $this->_write_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+        }
+
+        /* Check if we need to set up the read DB connection seperately. */
+        if (!empty($this->_params['splitread'])) {
+            $params = array_merge($this->_params, $this->_params['read']);
+            $this->_db = DB::connect($params,
+                                     array('persistent' => !empty($params['persistent'])));
+            if ($this->_db instanceof PEAR_Error) {
+                throw new Horde_Exception_Prior($this->_db);
+            }
+
+            // Set DB portability options.
+            switch ($this->_db->phptype) {
+            case 'mssql':
+                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS | DB_PORTABILITY_RTRIM);
+                break;
+
+            default:
+                $this->_db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
+            }
+
+        } else {
+            /* Default to the same DB handle for the writer too. */
+            $this->_db = $this->_write_db;
+        }
+
+        $this->_connected = true;
+    }
+
+    /**
+     * Disconnects from the SQL server and cleans up the connection.
+     */
+    protected function _disconnect()
+    {
+        if ($this->_connected) {
+            $this->_connected = false;
+            $this->_db->disconnect();
+            $this->_write_db->disconnect();
+        }
+    }
+
+}
diff --git a/pastie/lib/Exception.php b/pastie/lib/Exception.php
new file mode 100644 (file)
index 0000000..ef4d84a
--- /dev/null
@@ -0,0 +1 @@
+<?php class Pastie_Exception extends Horde_Exception {}
diff --git a/pastie/lib/Forms/Paste.php b/pastie/lib/Forms/Paste.php
new file mode 100644 (file)
index 0000000..4a4fdbe
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Copyright 2010 Alkaloid Networks LLC <http://www.alkaloid.net>
+ *
+ * See the enclosed file LICENSE for license information (GPL). If you
+ * did not receive this file, see http://www.horde.org/licenses/gpl.php.
+ *
+ * @author Ben Klang <ben@alkaloid.net>
+ * @package Pastie
+ */
+class PasteForm extends Horde_Form
+{
+    /**
+     */
+    function PasteForm(&$vars)
+    {
+        parent::Horde_Form($vars, _("New Paste"));
+
+        $types = array('none', 'php');
+
+        $this->addVariable(_("Title"), 'title', 'text', false);
+
+        $this->addVariable(_("Syntax"), 'syntax', 'enum', true,
+                          false, null, array($types, false));
+
+        $this->addVariable(_("Paste"), 'paste', 'longtext', true, false, null,
+                           array('rows' => 20, 'cols' => 100));
+
+        return true;
+    }
+}
diff --git a/pastie/lib/Highlighter.php b/pastie/lib/Highlighter.php
new file mode 100644 (file)
index 0000000..43cff64
--- /dev/null
@@ -0,0 +1,2 @@
+<?php
+class Pastie_Highlighter {}
diff --git a/pastie/lib/Highlighter/LibGeshi.php b/pastie/lib/Highlighter/LibGeshi.php
new file mode 100644 (file)
index 0000000..da368ca
--- /dev/null
@@ -0,0 +1,182 @@
+<?php
+/**
+ * 
+ * @package Pastie
+ */
+require_once 'geshi.php';
+
+// This file is named LibGeshi to avoid recursive includes/requires.
+class Pastie_Highlighter_LibGeshi extends Pastie_Highlighter {
+    public static function output($text, $syntax = 'none') {
+        if ($syntax == 'none') {
+            return '<pre>' . $text . '</pre>';
+        } else {
+            $geshi = new GeSHi($text, $syntax);
+        }
+        $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
+        return $geshi->parse_code();
+    }
+
+    public static function getSyntaxes()
+    {
+        return array(
+            "4cs",
+            "abap",
+            "actionscript",
+            "actionscript3",
+            "ada",
+            "apache",
+            "applescript",
+            "apt_sources",
+            "asm",
+            "asp",
+            "autohotkey",
+            "autoit",
+            "avisynth",
+            "awk",
+            "bash",
+            "basic4gl",
+            "bf",
+            "bibtex",
+            "blitzbasic",
+            "bnf",
+            "boo",
+            "c",
+            "c_mac",
+            "caddcl",
+            "cadlisp",
+            "cfdg",
+            "cfm",
+            "cil",
+            "clojure",
+            "cmake",
+            "cobol",
+            "cpp-qt",
+            "cpp",
+            "csharp",
+            "css",
+            "cuesheet",
+            "d",
+            "dcs",
+            "delphi",
+            "diff",
+            "div",
+            "dos",
+            "dot",
+            "eiffel",
+            "email",
+            "erlang",
+            "fo",
+            "fortran",
+            "freebasic",
+            "fsharp",
+            "gambas",
+            "gdb",
+            "genero",
+            "gettext",
+            "glsl",
+            "gml",
+            "gnuplot",
+            "groovy",
+            "haskell",
+            "hq9plus",
+            "html4strict",
+            "idl",
+            "ini",
+            "inno",
+            "intercal",
+            "io",
+            "java",
+            "java5",
+            "javascript",
+            "jquery",
+            "kixtart",
+            "klonec",
+            "klonecpp",
+            "latex",
+            "lisp",
+            "locobasic",
+            "logtalk",
+            "lolcode",
+            "lotusformulas",
+            "lotusscript",
+            "lscript",
+            "lsl2",
+            "lua",
+            "m68k",
+            "make",
+            "mapbasic",
+            "matlab",
+            "mirc",
+            "mmix",
+            "modula3",
+            "mpasm",
+            "mxml",
+            "mysql",
+            "newlisp",
+            "nsis",
+            "oberon2",
+            "objc",
+            "ocaml-brief",
+            "ocaml",
+            "oobas",
+            "oracle11",
+            "oracle8",
+            "pascal",
+            "per",
+            "perl",
+            "perl6",
+            "php-brief",
+            "php",
+            "pic16",
+            "pike",
+            "pixelbender",
+            "plsql",
+            "povray",
+            "powerbuilder",
+            "powershell",
+            "progress",
+            "prolog",
+            "properties",
+            "providex",
+            "purebasic",
+            "python",
+            "qbasic",
+            "rails",
+            "rebol",
+            "reg",
+            "robots",
+            "rsplus",
+            "ruby",
+            "sas",
+            "scala",
+            "scheme",
+            "scilab",
+            "sdlbasic",
+            "smalltalk",
+            "smarty",
+            "sql",
+            "systemverilog",
+            "tcl",
+            "teraterm",
+            "text",
+            "thinbasic",
+            "tsql",
+            "typoscript",
+            "vb",
+            "vbnet",
+            "verilog",
+            "vhdl",
+            "vim",
+            "visualfoxpro",
+            "visualprolog",
+            "whitespace",
+            "whois",
+            "winbatch",
+            "xml",
+            "xorg_conf",
+            "xpp",
+            "z80"
+        );
+    }
+}
diff --git a/pastie/lib/Highlighter/TextHighlighter.php b/pastie/lib/Highlighter/TextHighlighter.php
new file mode 100644 (file)
index 0000000..72beada
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/**
+ *
+ * @package Pastie
+ */
+
+// This file is named LibGeshi to avoid recursive includes/requires.
+class Pastie_Highlighter_TextHighlighter extends Pastie_Highlighter {
+    public static function output($text, $syntax = 'none') {
+        if ($syntax == 'none') {
+            return '<pre>' . $text . '</pre>';
+        } else {
+            // Since we may be coming from another syntax highlighter,
+            // we'll try upcasing the syntax name and hope we get lucky.
+            $syntax = strtoupper($syntax);
+            $highlighter = Text_Highlighter::factory($syntax);
+            if ($highlighter instanceof PEAR_Error) {
+                throw new Horde_Exception_Prior($highlighter);
+            }
+            $renderer = new Text_Highlighter_Renderer_Html(array(
+                "numbers" => HL_NUMBERS_LI
+            ));
+            if ($renderer instanceof PEAR_Error) {
+                throw new Horde_Exception_Prior($renderer);
+            }
+            $highlighter->setRenderer($renderer);
+            return $highlighter->highlight($text);
+        }
+    }
+
+    public static function getSyntaxes()
+    {
+        return array(
+            "ABAP",
+            "CPP",
+            "CSS",
+            "DIFF",
+            "DTD",
+            "Generator",
+            "HTML",
+            "JAVA",
+            "JAVASCRIPT",
+            "MYSQL",
+            "PERL",
+            "PHP",
+            "PYTHON",
+            "RUBY",
+            "SH",
+            "SQL",
+            "VBSCRIPT",
+            "XML"
+        );
+    }
+}
\ No newline at end of file
diff --git a/pastie/lib/Pastie.php b/pastie/lib/Pastie.php
new file mode 100644 (file)
index 0000000..246fd7a
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Pastie Base Class.
+ *
+ * Copyright 2007-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Your Name <you@example.com>
+ * @package Pastie
+ */
+class Pastie
+{
+    /**
+     * Build Pastie's list of menu items.
+     */
+    static public function getMenu()
+    {
+        $menu = new Horde_Menu(Horde_Menu::MASK_ALL);
+        $menu->add(Horde::applicationUrl('paste.php'), _("Paste"), 'pastie.png', Horde_Themes::img(null, 'horde'));
+
+        return $menu;
+    }
+
+}
diff --git a/pastie/lib/Test.php b/pastie/lib/Test.php
new file mode 100644 (file)
index 0000000..c7103e2
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * This class provides the application configuration for the test script.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ */
+class Pastie_Test extends Horde_Test
+{
+    /**
+     * The module list
+     *
+     * @var array
+     */
+    protected $_moduleList = array();
+
+    /**
+     * PHP settings list.
+     *
+     * @var array
+     */
+    protected $_settingsList = array();
+
+    /**
+     * PEAR modules list.
+     *
+     * @var array
+     */
+    protected $_pearList = array();
+
+    /**
+     * Required configuration files.
+     *
+     * @var array
+     */
+    protected $_fileList = array();
+
+    /**
+     * Inter-Horde application dependencies.
+     *
+     * @var array
+     */
+    protected $_appList = array();
+
+    /**
+     * Any application specific tests that need to be done.
+     *
+     * @return string  HTML output.
+     */
+    public function appTests()
+    {
+    }
+
+}
diff --git a/pastie/locale/en_US/help.xml b/pastie/locale/en_US/help.xml
new file mode 100644 (file)
index 0000000..1c27044
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version='1.0'?>
+<help>
+
+<entry id="pastie-overview">
+    <title>Pastie Overview</title>
+
+    <heading>What is Pastie?</heading>
+    <para>Use this module as a blank base for Horde appliations. All of the
+    files in this module are to be used as examples. Please customize them
+    for your own application's requirements.</para>
+</entry>
+
+</help>
diff --git a/pastie/paste.php b/pastie/paste.php
new file mode 100644 (file)
index 0000000..b8e15d8
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Add a new paste to the current pastebin.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (BSD). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/bsd.html.
+ *
+ * @author Ben Klang <ben@alkaloid.net>
+ */
+
+require_once dirname(__FILE__) . '/lib/Application.php';
+$pastie = Horde_Registry::appInit('pastie');
+
+require_once PASTIE_BASE . '/lib/Forms/Paste.php';
+
+$vars = Horde_Variables::getDefaultVariables();
+$url = Horde::applicationUrl('paste.php');
+
+$form = new PasteForm($vars);
+
+if ($form->validate($vars)) {
+    $form->getInfo($vars, $info);
+
+    try {
+        $uuid = $pastie->driver->savePaste('default', $info['paste'], $info['syntax']);
+
+        $notification->push(sprintf('Paste saved. %s', $uuid), 'horde.success');
+
+        $url = Horde::applicationUrl('view/' . $uuid, true);
+        header('Location: ' . $url);
+        exit;
+    } catch (Exception $e) {
+        $notification->push($e->getMessage(), 'horde.error');
+    }
+}
+
+$title = $form->getTitle();
+
+require PASTIE_TEMPLATES . '/common-header.inc';
+require PASTIE_TEMPLATES . '/menu.inc';
+
+$form->renderActive(null, null, $url, 'post');
+
+require $registry->get('templates', 'horde') . '/common-footer.inc';
diff --git a/pastie/po/README b/pastie/po/README
new file mode 100644 (file)
index 0000000..a985e94
--- /dev/null
@@ -0,0 +1 @@
+see horde/po/README
diff --git a/pastie/scripts/sql/pastie.sql b/pastie/scripts/sql/pastie.sql
new file mode 100644 (file)
index 0000000..4ff8281
--- /dev/null
@@ -0,0 +1,22 @@
+--
+-- Copyright 2001-2005 Robert E. Coyle <robertecoyle@hotmail.com>
+--
+-- See the enclosed file LICENSE for license information (BSD). If you
+-- did not receive this file, see http://www.horde.org/licenses/bsdl.php.
+--
+-- Database definitions for Whups
+
+CREATE TABLE pastie_pastes (
+    paste_id           INT NOT NULL,           -- sequential id
+    paste_uuid         VARCHAR(40) NOT NULL,   -- UUID
+    paste_bin          VARCHAR(64) NOT NULL,   -- associated bin (FIXME)
+    paste_title         VARCHAR(255),           -- optional title
+    paste_syntax       VARCHAR(16) NOT NULL,   -- syntax for highlighting
+    paste_content      TEXT,                   -- paste content
+    paste_owner                VARCHAR(255),           -- paster name
+    paste_timestamp    INT NOT NULL,           -- date/time, Unix epoch
+    PRIMARY KEY (paste_id),
+    UNIQUE paste_id (paste_id),
+    UNIQUE paste_uuid (paste_uuid)
+);
+    
diff --git a/pastie/templates/common-header.inc b/pastie/templates/common-header.inc
new file mode 100644 (file)
index 0000000..255429b
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+if (isset($language)) {
+    header('Content-type: text/html; charset=' . Horde_Nls::getCharset());
+    header('Vary: Accept-Language');
+}
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
+<?php echo !empty($language) ? '<html lang="' . strtr($language, '_', '-') . '">' : '<html>' ?>
+<head>
+<?php
+
+$page_title = $registry->get('name');
+if (!empty($title)) $page_title .= ' :: ' . $title;
+if (!empty($refresh_time) && ($refresh_time > 0) && !empty($refresh_url)) {
+    echo "<meta http-equiv=\"refresh\" content=\"$refresh_time;url=$refresh_url\">\n";
+}
+
+Horde::includeScriptFiles();
+
+?>
+<title><?php echo htmlspecialchars($page_title) ?></title>
+<link href="<?php echo Horde_Themes::img('favicon.ico', array('nohorde' => true)) ?>" rel="SHORTCUT ICON" />
+<?php echo Horde_Themes::includeStylesheetFiles() ?>
+</head>
+
+<body>
diff --git a/pastie/templates/menu.inc b/pastie/templates/menu.inc
new file mode 100644 (file)
index 0000000..e1c0d66
--- /dev/null
@@ -0,0 +1,4 @@
+<div id="menu">
+ <?php echo Pastie::getMenu()->render() ?>
+</div>
+<?php $GLOBALS['notification']->notify(array('listeners' => 'status')) ?>
diff --git a/pastie/templates/view.inc b/pastie/templates/view.inc
new file mode 100644 (file)
index 0000000..d491fab
--- /dev/null
@@ -0,0 +1,10 @@
+<div id="showpaste">
+    <div class="pasteHeader">
+        <h2 class="pasteTitle"><?php echo $paste['title']; ?></h2>
+        By <span class="pasteOwner"><?php echo $paste['owner']; ?></span>
+        on <span class="pasteDate"><?php echo $paste['timestamp']; ?></span>
+    </div>
+    <div class="pasteContents">
+    <?php echo $output; ?>
+    </div>
+</div>
\ No newline at end of file
diff --git a/pastie/themes/graphics/pastie.png b/pastie/themes/graphics/pastie.png
new file mode 100644 (file)
index 0000000..73f6687
Binary files /dev/null and b/pastie/themes/graphics/pastie.png differ
diff --git a/pastie/themes/screen.css b/pastie/themes/screen.css
new file mode 100644 (file)
index 0000000..acf7cdc
--- /dev/null
@@ -0,0 +1,25 @@
+/* Insert CSS definitions here. */
+#showpaste {
+    margin: 35px;
+}
+
+.pasteTitle {
+    font-size: 1.3em;
+}
+
+.pasteOwner {
+    font-style: italic;
+    font-weight: bold;
+}
+
+.pasteDate {
+    font-style: italic;
+    font-weight: bold;
+}
+
+.pasteContents {
+    padding: 10px;
+    border: 1px solid #c00;
+    background-color: #ddd;
+    list-style-position: inside;
+}
\ No newline at end of file
diff --git a/pastie/view.php b/pastie/view.php
new file mode 100644 (file)
index 0000000..4bb5afc
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/**
+ * View a paste.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (BSD). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/bsd.html.
+ *
+ * @author Ben Klang <ben@alkaloid.net>
+ */
+
+require_once dirname(__FILE__) . '/lib/Application.php';
+$pastie = Horde_Registry::appInit('pastie');
+
+require_once PASTIE_BASE . '/lib/Forms/Paste.php';
+$uuid = trim(Horde_Util::getPathInfo(), '/');
+
+if (!empty($uuid)) {
+    try {
+        $paste = $pastie->driver->getPaste(array('uuid' => $uuid));
+    } catch (Horde_Exception $e) {
+        $notification->push($e);
+        $paste = null;
+    }
+}
+
+$pasteurl = Horde::applicationUrl('paste.php');
+$vars = new Horde_Variables($paste);
+$form = new PasteForm($vars);
+
+try {
+    $engine = 'Pastie_Highlighter_' . $GLOBALS['conf']['highlighter']['engine'];
+    $output = $engine::output($paste['paste'], $paste['syntax']);
+} catch (Pastie_Exception $e) {
+    $output = _("Error parsing the paste.");
+}
+
+$title = _("View Paste");
+
+require PASTIE_TEMPLATES . '/common-header.inc';
+require PASTIE_TEMPLATES . '/menu.inc';
+
+require PASTIE_TEMPLATES . '/view.inc';
+
+$form->renderActive(null, null, $pasteurl, 'post');
+
+require $registry->get('templates', 'horde') . '/common-footer.inc';