From 7ac8142fc637c546ee72d15f50f65394496d0e03 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Wed, 12 Mar 2014 21:30:54 -0500 Subject: [PATCH] Adding feature to allow users to choose a syntaxhighlighter theme per project --- indefero/src/IDF/FileUtil.php | 13 ++++++- indefero/src/IDF/Form/ProjectConf.php | 22 +++++++++++- indefero/src/IDF/Migrations/29EnableAds.php | 36 +++++++++++++++++++ .../IDF/Migrations/30SyntaxHighlightTheme.php | 36 +++++++++++++++++++ indefero/src/IDF/Project.php | 9 +++++ indefero/src/IDF/conf/urls.php | 7 ++++ .../src/IDF/templates/idf/admin/summary.html | 7 ++++ indefero/src/IDF/templates/idf/base.html | 11 +++++- 8 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 indefero/src/IDF/Migrations/29EnableAds.php create mode 100644 indefero/src/IDF/Migrations/30SyntaxHighlightTheme.php diff --git a/indefero/src/IDF/FileUtil.php b/indefero/src/IDF/FileUtil.php index 94fdcbd..2a6256d 100644 --- a/indefero/src/IDF/FileUtil.php +++ b/indefero/src/IDF/FileUtil.php @@ -38,6 +38,10 @@ class IDF_FileUtil 'skin', 'sln', 'svc', 'vala', 'vb', 'vbproj', 'vbs', 'wsdl', 'xhtml', 'xml', 'xsd', 'xsl', 'xslt'); + public static $map = array("h" => "cpp", "hpp" => "cpp", "rc"=>"text", "sh"=>"bash", "cs"=>"csharp"); + + public static $syntaxhighlightext = array("as3", "cf", "cpp", "c", "css", "pas", "diff", "patch", "erl", "java", "jfx", "js", "pl", "php", "py", "rb", "sass", "scss", "scala", "sql", "vb", ); + /** * Test if an extension is supported by the syntax highlighter. * @@ -72,7 +76,14 @@ class IDF_FileUtil } return Pluf_Template::markSafe(implode("\n", $table));*/ //var_dump($fileinfo); - $content = ''; + $ext = ""; + if (in_array($fileinfo[2], self::$syntaxhighlightext)) + $ext = $fileinfo[2]; + elseif (array_key_exists($fileinfo[2], self::$map)) + $ext = self::$map[$fileinfo[2]]; + else + $ext = "text"; + $content = ''; return Pluf_Template::markSafe($content); } diff --git a/indefero/src/IDF/Form/ProjectConf.php b/indefero/src/IDF/Form/ProjectConf.php index 6f1901a..4663c0a 100644 --- a/indefero/src/IDF/Form/ProjectConf.php +++ b/indefero/src/IDF/Form/ProjectConf.php @@ -33,7 +33,17 @@ class IDF_Form_ProjectConf extends Pluf_Form { $this->project = $extra['project']; $this->user = $extra["user"]; - $conf = $this->project->getConf(); + $conf = $this->project->getConf(); + $options = array( + 'Default' => __('Default'), + 'Django' => __('Django'), + 'Eclipse' => __('Eclipse'), + 'Emacs' => __('Emacs'), + 'FadeToGrey' => __('FadeToGrey'), + 'MDUltra' => __('MDUltra'), + 'Midnight' => __('Midnight'), + 'RDark' => __('RDark'), + ); // Basic part $this->fields['name'] = new Pluf_Form_Field_Varchar(array('required' => true, @@ -59,6 +69,15 @@ class IDF_Form_ProjectConf extends Pluf_Form 'initial' => $conf->getVal('external_project_url'), )); + + $this->fields['syntaxtheme'] = new Pluf_Form_Field_Varchar( + array('required' => true, + 'label' => __('Syntax Highlight Theme'), + 'initial' => ($this->project->syntaxtheme) ? $this->project->syntaxtheme : "Default", + 'widget_attrs' => array('choices' => $options), + 'widget' => 'Pluf_Form_Widget_SelectInput', + )); + if ($this->user->administrator) { $this->fields['enableads'] = new Pluf_Form_Field_Boolean( @@ -208,6 +227,7 @@ class IDF_Form_ProjectConf extends Pluf_Form $this->project->shortdesc = $this->cleaned_data['shortdesc']; $this->project->description = $this->cleaned_data['description']; $this->project->batchAssoc('IDF_Tag', $tagids); + $this->project->syntaxtheme = $this->cleaned_data["syntaxtheme"]; if ($this->user->administrator) $this->project->enableads = $this->cleaned_data['enableads']; $this->project->update(); diff --git a/indefero/src/IDF/Migrations/29EnableAds.php b/indefero/src/IDF/Migrations/29EnableAds.php new file mode 100644 index 0000000..a0d4101 --- /dev/null +++ b/indefero/src/IDF/Migrations/29EnableAds.php @@ -0,0 +1,36 @@ +getSqlTable(); + + $sql = array(); + + $sql["MySQL"] = "ALTER TABLE " . $table . " ADD COLUMN `enableads` int(11) NULL AFTER `current_activity`;"; + + $db = Pluf::db(); + $engine = Pluf::f('db_engine'); + if (!isset($sql[$engine])) { + throw new Exception('SQLite complex migration not supported.'); + } + + $db->execute($sql[$engine]); + +} + +function IDF_Migrations_28OTPKey_down() +{ + $table = Pluf::factory('IDF_Project')->getSqlTable(); + + $sql = array(); + + $sql["MySQL"] = "ALTER TABLE " . $table . " DROP COLUMN `enableads`;"; + + $db = Pluf::db(); + $engine = Pluf::f('db_engine'); + if (!isset($sql[$engine])) { + throw new Exception('SQLite complex migration not supported.'); + } + + $db->execute($sql[$engine]); +} \ No newline at end of file diff --git a/indefero/src/IDF/Migrations/30SyntaxHighlightTheme.php b/indefero/src/IDF/Migrations/30SyntaxHighlightTheme.php new file mode 100644 index 0000000..211ca0f --- /dev/null +++ b/indefero/src/IDF/Migrations/30SyntaxHighlightTheme.php @@ -0,0 +1,36 @@ +getSqlTable(); + + $sql = array(); + + $sql["MySQL"] = "ALTER TABLE " . $table . " ADD COLUMN `syntaxtheme` VARCHAR(50) NULL AFTER `enableads`;"; + + $db = Pluf::db(); + $engine = Pluf::f('db_engine'); + if (!isset($sql[$engine])) { + throw new Exception('SQLite complex migration not supported.'); + } + + $db->execute($sql[$engine]); + +} + +function IDF_Migrations_28OTPKey_down() +{ + $table = Pluf::factory('IDF_Project')->getSqlTable(); + + $sql = array(); + + $sql["MySQL"] = "ALTER TABLE " . $table . " DROP COLUMN `syntaxtheme`;"; + + $db = Pluf::db(); + $engine = Pluf::f('db_engine'); + if (!isset($sql[$engine])) { + throw new Exception('SQLite complex migration not supported.'); + } + + $db->execute($sql[$engine]); +} \ No newline at end of file diff --git a/indefero/src/IDF/Project.php b/indefero/src/IDF/Project.php index e2232c1..6f4845b 100644 --- a/indefero/src/IDF/Project.php +++ b/indefero/src/IDF/Project.php @@ -116,6 +116,15 @@ class IDF_Project extends Pluf_Model 'verbose' => __('enableads'), 'default' => 1, ), + + 'syntaxtheme' => + array( + 'type' => 'Pluf_DB_Field_Text', + 'blank' => false, + 'verbose' => __('syntaxtheme'), + 'default' => "Default", + "size" => 50 + ) ); $activityTable = $this->_con->pfx.'idf_projectactivities'; $tagTable = $this->_con->pfx.'idf_project_idf_tag_assoc'; diff --git a/indefero/src/IDF/conf/urls.php b/indefero/src/IDF/conf/urls.php index 000723e..8773ac2 100644 --- a/indefero/src/IDF/conf/urls.php +++ b/indefero/src/IDF/conf/urls.php @@ -29,6 +29,13 @@ $ctl[] = array('regex' => '#^/$#', 'model' => 'IDF_Views', 'method' => 'index'); +$ctl[] = array('regex' => '#^/u/(.*)/$#', + 'base' => $base, + 'model' => 'IDF_Views_User', + 'method' => 'view', + 'name' => 'idf_user_view'); + + $ctl[] = array('regex' => '#^/projects/$#', 'base' => $base, 'model' => 'IDF_Views', diff --git a/indefero/src/IDF/templates/idf/admin/summary.html b/indefero/src/IDF/templates/idf/admin/summary.html index 16b3922..da344f3 100644 --- a/indefero/src/IDF/templates/idf/admin/summary.html +++ b/indefero/src/IDF/templates/idf/admin/summary.html @@ -76,6 +76,13 @@ {if $form.f.enableads.errors}{$form.f.enableads.fieldErrors}{/if} {$form.f.enableads|unsafe} + + + {$form.f.syntaxtheme.labelTag}: + {if $form.f.syntaxtheme.errors}{$form.f.syntaxtheme.fieldErrors}{/if} + {$form.f.syntaxtheme|unsafe} + +   diff --git a/indefero/src/IDF/templates/idf/base.html b/indefero/src/IDF/templates/idf/base.html index 4c53683..6ce3805 100644 --- a/indefero/src/IDF/templates/idf/base.html +++ b/indefero/src/IDF/templates/idf/base.html @@ -40,7 +40,16 @@ - + {if $project} + {if $project.syntaxtheme} + + {else} + + {/if} + {else} + + {/if} + {appversion}