From c9e9855eb649e5b9237a81a6076ddd7fb30fe9e3 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 26 Jan 2015 18:24:37 +0100 Subject: javascript embedding support --- data/templates/display-head.htm | 21 ----------------- data/templates/display-sidebar-urls.htm | 12 ++++++++++ data/templates/display.htm | 1 + data/templates/embed-file.htm | 7 ++++++ data/templates/embed-part-file.htm | 9 +++++++ data/templates/embed.htm | 9 +++++++ src/phorkie/File.php | 20 ++++++++++++---- src/phorkie/Renderer/Geshi.php | 8 +++++-- src/phorkie/Repository.php | 3 +++ www/.htaccess | 2 ++ www/css/embed.css | 42 +++++++++++++++++++++++++++++++++ www/css/phorkie.css | 29 +++++++++++++++++++++++ www/embed-file.php | 27 +++++++++++++++++++++ www/embed.php | 21 +++++++++++++++++ www/js/phorkie.js | 3 ++- 15 files changed, 185 insertions(+), 29 deletions(-) create mode 100644 data/templates/display-sidebar-urls.htm create mode 100644 data/templates/embed-file.htm create mode 100644 data/templates/embed-part-file.htm create mode 100644 data/templates/embed.htm create mode 100644 www/css/embed.css create mode 100644 www/embed-file.php create mode 100644 www/embed.php diff --git a/data/templates/display-head.htm b/data/templates/display-head.htm index aa7daec..8c16908 100644 --- a/data/templates/display-head.htm +++ b/data/templates/display-head.htm @@ -27,24 +27,3 @@ - -{% if repo.getCloneURL(true) or repo.getCloneURL(false) %} -
- {% if repo.getCloneURL(true) %} -
-
Public clone URL
- -
- {% endif %} - {% if repo.getCloneURL(false) %} -
-
Private clone URL
- -
- {% endif %} -
-{% endif %} diff --git a/data/templates/display-sidebar-urls.htm b/data/templates/display-sidebar-urls.htm new file mode 100644 index 0000000..446810c --- /dev/null +++ b/data/templates/display-sidebar-urls.htm @@ -0,0 +1,12 @@ + + + +{% if repo.getCloneURL(true) %} + + +{% endif %} + +{% if repo.getCloneURL(false) %} + + +{% endif %} diff --git a/data/templates/display.htm b/data/templates/display.htm index d6fd646..59db9f8 100644 --- a/data/templates/display.htm +++ b/data/templates/display.htm @@ -23,6 +23,7 @@ {% block sidebar %} {% include 'display-sidebar-owner.htm' %} + {% include 'display-sidebar-urls.htm' %} {% include 'display-sidebar-fork.htm' %} {% include 'display-sidebar-history.htm' %} {% endblock %} diff --git a/data/templates/embed-file.htm b/data/templates/embed-file.htm new file mode 100644 index 0000000..46075de --- /dev/null +++ b/data/templates/embed-file.htm @@ -0,0 +1,7 @@ +/* embedding {{file.getFilename()}} of {{repo.getLink('display', null, true)}} */ +document.write(''); +document.write( + '
' + + {% filter json_encode(constant('JSON_UNESCAPED_SLASHES'))|raw -%}{% include 'embed-part-file.htm' %}{%- endfilter %} + + '
' +); diff --git a/data/templates/embed-part-file.htm b/data/templates/embed-part-file.htm new file mode 100644 index 0000000..cdfd132 --- /dev/null +++ b/data/templates/embed-part-file.htm @@ -0,0 +1,9 @@ +
+
+ {{file.getRenderedContent(toolres)|raw}} +
+ +
diff --git a/data/templates/embed.htm b/data/templates/embed.htm new file mode 100644 index 0000000..0334c22 --- /dev/null +++ b/data/templates/embed.htm @@ -0,0 +1,9 @@ +/* embedding all files of {{repo.getLink('display', null, true)}} */ +document.write(''); +document.write( + '
' +{% for file in repo.getFiles %} + + {% filter json_encode(constant('JSON_UNESCAPED_SLASHES'))|raw -%}{% include 'embed-part-file.htm' %}{%- endfilter %} +{% endfor %} + + '
' +); diff --git a/src/phorkie/File.php b/src/phorkie/File.php index 2aa1d19..9eb7fa7 100644 --- a/src/phorkie/File.php +++ b/src/phorkie/File.php @@ -96,27 +96,37 @@ class File * Get a link to the file * * @param string $type Link type. Supported are: + * - "display" * - "raw" * - "tool" * @param string $option Additional option, e.g. tool name + * @param boolean $full Return full URL or normal relative * * @return string */ - public function getLink($type, $option = null) + public function getLink($type, $option = null, $full = false) { if ($type == 'raw') { if ($this->repo->hash === null) { - return $this->repo->id . '/raw/' . $this->getFilename(); + $link = $this->repo->id . '/raw/' . $this->getFilename(); } else { - return $this->repo->id . '/rev-raw/' . $this->repo->hash + $link = $this->repo->id . '/rev-raw/' . $this->repo->hash . '/' . $this->getFilename(); } } else if ($type == 'tool') { - return $this->repo->id + $link = $this->repo->id . '/tool/' . $option . '/' . $this->getFilename(); + } else if ($type == 'display') { + $link = $this->repo->id . '#' . $this->getFilename(); + } else { + throw new Exception('Unknown type'); } - throw new Exception('Unknown type'); + + if ($full) { + $link = Tools::fullUrl($link); + } + return $link; } /** diff --git a/src/phorkie/Renderer/Geshi.php b/src/phorkie/Renderer/Geshi.php index 0c545ed..2b3854a 100644 --- a/src/phorkie/Renderer/Geshi.php +++ b/src/phorkie/Renderer/Geshi.php @@ -22,14 +22,18 @@ class Renderer_Geshi } $geshi = new \geshi($file->getContent(), $this->getType($file)); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); - $geshi->set_header_type(GESHI_HEADER_DIV); + $geshi->set_header_type(GESHI_HEADER_PRE_TABLE); + $geshi->enable_classes(); + $geshi->set_line_style('color: #DDD;'); if ($res !== null) { $geshi->highlight_lines_extra(array_keys($res->annotations)); $geshi->set_highlight_lines_extra_style('background-color: #F2DEDE'); } - return '
' + return '' + . '
' . str_replace(' ', ' ', $geshi->parse_code()) . '
'; } diff --git a/src/phorkie/Repository.php b/src/phorkie/Repository.php index 467456b..f9b248d 100644 --- a/src/phorkie/Repository.php +++ b/src/phorkie/Repository.php @@ -310,6 +310,7 @@ class Repository * - "delete" * - "delete-confirm" * - "display" + * - "embed" * - "fork" * - "revision" * @param string $option Additional link option, e.g. revision number @@ -334,6 +335,8 @@ class Repository $link = $this->id . '/delete'; } else if ($type == 'delete-confirm') { $link = $this->id . '/delete/confirm'; + } else if ($type == 'embed') { + $link = $this->id . '/embed'; } else if ($type == 'remotefork') { return 'web+fork:' . $this->getLink('display', null, true); } else if ($type == 'revision') { diff --git a/www/.htaccess b/www/.htaccess index 566d27c..cda57f9 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -11,6 +11,8 @@ RewriteRule ^([0-9]+)/delete/confirm$ delete.php?id=$1&confirm=1 RewriteRule ^([0-9]+)/doap$ doap.php?id=$1 RewriteRule ^([0-9]+)/edit$ edit.php?id=$1 RewriteRule ^([0-9]+)/edit/(.+)$ edit.php?id=$1&file=$2 +RewriteRule ^([0-9]+)/embed$ embed.php?id=$1 +RewriteRule ^([0-9]+)/embed/(.+)$ embed-file.php?id=$1&file=$2 RewriteRule ^([0-9]+)/fork$ fork.php?id=$1 RewriteRule ^([0-9]+)/linkback$ linkback.php?id=$1 RewriteRule ^([0-9]+)/raw/(.+)$ raw.php?id=$1&file=$2 diff --git a/www/css/embed.css b/www/css/embed.css new file mode 100644 index 0000000..4d5c050 --- /dev/null +++ b/www/css/embed.css @@ -0,0 +1,42 @@ +.phork-file { + border: 1px solid #DDD; + border-bottom: 1px solid #CCC; + border-radius: 3px; + padding: 0px; + background-color: white; + margin-bottom: 2ex; + margin-top: 2ex; +} +.phork-content { + padding: 0.6ex; +} +.phork-file > .code { + overflow-x: auto; +} +.phork-file .code pre { + border: none; + background-color: inherit; + word-break: normal; + word-wrap: normal; + white-space: pre; + color: black; + font: normal normal 1em/1.2em monospace; + padding: 0px; + margin: 0px; +} +.phork-file .code .ln pre { + margin-right: 1ex; + color: #DDD; +} +.phork-meta { + background-color: #EEE; + font-size: 75%; + padding: 0.5ex 1ex; + margin: none; +} +.phork-meta a { + font-family: sans-serif; + text-decoration: none; + color: #888; + font-weight: bold; +} \ No newline at end of file diff --git a/www/css/phorkie.css b/www/css/phorkie.css index edebe1c..d2b05c4 100644 --- a/www/css/phorkie.css +++ b/www/css/phorkie.css @@ -91,6 +91,29 @@ h1 { .file .image { margin-bottom: 2ex; } +.file > .document { + margin-left: 1em; +} + +.code pre { + border: none; + background-color: inherit; + word-break: normal; + word-wrap: normal; + white-space: pre; + color: black; + font: normal normal 1em/1.2em monospace; + padding: 0px; + margin: 0px; + margin-bottom: 2ex; +} +.code { + overflow-x: auto; +} +.code .ln pre { + margin-right: 1ex; + color: #DDD; +} div.annotations div.alert { margin-bottom: 1ex; @@ -156,6 +179,12 @@ form label.inline { margin-left: 8em; } +input.fullwidthtext { + width: 100%; + box-sizing: border-box; + height: auto; +} + .btn [class^="icon-"], .btn [class*=" icon-"] { line-height: 1.1em; } diff --git a/www/embed-file.php b/www/embed-file.php new file mode 100644 index 0000000..0ece1b9 --- /dev/null +++ b/www/embed-file.php @@ -0,0 +1,27 @@ +loadFromRequest(); + +if (!isset($_GET['file']) || $_GET['file'] == '') { + throw new Exception_Input('File name missing'); +} + +$file = $repo->getFileByName($_GET['file']); +header('Content-Type: text/javascript'); +header('Expires: ' . date('r', time() + 3600)); +render( + 'embed-file', + array( + 'repo' => $repo, + 'file' => $file, + ) +); +?> diff --git a/www/embed.php b/www/embed.php new file mode 100644 index 0000000..660e1f2 --- /dev/null +++ b/www/embed.php @@ -0,0 +1,21 @@ +loadFromRequest(); + +header('Content-Type: text/javascript'); +header('Expires: ' . date('r', time() + 3600)); +render( + 'embed', + array( + 'repo' => $repo, + ) +); +?> diff --git a/www/js/phorkie.js b/www/js/phorkie.js index 7078e8f..5d96575 100644 --- a/www/js/phorkie.js +++ b/www/js/phorkie.js @@ -49,5 +49,6 @@ function toggleAdditional(elem, time) var jt = jQuery(elem); jt.children('i').toggleClass('icon-chevron-down') .toggleClass('icon-chevron-up'); - jt.parents('.row-fluid').children('.additional').toggle(time); + //jt.parents('.row-fluid').children('.additional').toggle(time); + jt.parents('.row-fluid').children('.additional').animate(time); } -- cgit v1.2.3