Pastie: Fix list of valid syntaxes when calling highlighters
authorBen Klang <ben@alkaloid.net>
Tue, 18 May 2010 02:02:59 +0000 (22:02 -0400)
committerBen Klang <ben@alkaloid.net>
Tue, 18 May 2010 02:02:59 +0000 (22:02 -0400)
pastie/lib/Forms/Paste.php
pastie/paste.php
pastie/view.php

index 4a4fdbe..b13db18 100644 (file)
@@ -16,7 +16,19 @@ class PasteForm extends Horde_Form
     {
         parent::Horde_Form($vars, _("New Paste"));
 
-        $types = array('none', 'php');
+        $engine = 'Pastie_Highlighter_' . $GLOBALS['conf']['highlighter']['engine'];
+        $tmp = call_user_func(array($engine, 'getSyntaxes'));
+        $types = array();
+        foreach ($tmp as $type) {
+            $types[$type] = $type;
+        }
+
+        // Some highlighters have a long list of supported languages.
+        // Default to PHP if one is not already specified
+        $curtype = $vars->get('syntax');
+        if (empty($curtype)) {
+            $vars->set('syntax', 'php');
+        }
 
         $this->addVariable(_("Title"), 'title', 'text', false);
 
index b8e15d8..a7baa73 100644 (file)
@@ -28,7 +28,7 @@ if ($form->validate($vars)) {
 
         $notification->push(sprintf('Paste saved. %s', $uuid), 'horde.success');
 
-        $url = Horde::applicationUrl('view/' . $uuid, true);
+        $url = Horde::applicationUrl('uuid/' . $uuid, true);
         header('Location: ' . $url);
         exit;
     } catch (Exception $e) {
index 4bb5afc..ab2be4c 100644 (file)
@@ -14,7 +14,7 @@ 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(), '/');
+$uuid = Horde_Util::getFormData('uuid');
 
 if (!empty($uuid)) {
     try {
@@ -31,7 +31,7 @@ $form = new PasteForm($vars);
 
 try {
     $engine = 'Pastie_Highlighter_' . $GLOBALS['conf']['highlighter']['engine'];
-    $output = $engine::output($paste['paste'], $paste['syntax']);
+    $output = call_user_func_array(array($engine, 'output'), array($paste['paste'], $paste['syntax']));
 } catch (Pastie_Exception $e) {
     $output = _("Error parsing the paste.");
 }