aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2015-01-26 18:24:37 +0100
committerChristian Weiske <cweiske@cweiske.de>2015-01-26 18:24:37 +0100
commitc9e9855eb649e5b9237a81a6076ddd7fb30fe9e3 (patch)
tree2c9eba86ce182d5c150af8382c4dec2a91ef7fd6
parent66170c339bbcd8b87e23c47daa11359a99e0d02d (diff)
downloadphorkie-c9e9855eb649e5b9237a81a6076ddd7fb30fe9e3.tar.gz
phorkie-c9e9855eb649e5b9237a81a6076ddd7fb30fe9e3.zip
javascript embedding support
-rw-r--r--data/templates/display-head.htm21
-rw-r--r--data/templates/display-sidebar-urls.htm12
-rw-r--r--data/templates/display.htm1
-rw-r--r--data/templates/embed-file.htm7
-rw-r--r--data/templates/embed-part-file.htm9
-rw-r--r--data/templates/embed.htm9
-rw-r--r--src/phorkie/File.php20
-rw-r--r--src/phorkie/Renderer/Geshi.php8
-rw-r--r--src/phorkie/Repository.php3
-rw-r--r--www/.htaccess2
-rw-r--r--www/css/embed.css42
-rw-r--r--www/css/phorkie.css29
-rw-r--r--www/embed-file.php27
-rw-r--r--www/embed.php21
-rw-r--r--www/js/phorkie.js3
15 files changed, 185 insertions, 29 deletions
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 @@
</form>
</div>
</div>
-
-{% if repo.getCloneURL(true) or repo.getCloneURL(false) %}
-<div class="urlinfo well well-small">
- {% if repo.getCloneURL(true) %}
- <div class="row-fluid">
- <div class="span3">Public clone URL</div>
- <div class="span9">
- <a href="{{repo.getCloneURL(true)}}">{{repo.getCloneURL(true)}}</a>
- </div>
- </div>
- {% endif %}
- {% if repo.getCloneURL(false) %}
- <div class="row-fluid">
- <div class="span3">Private clone URL</div>
- <div class="span9">
- <a href="{{repo.getCloneURL(false)}}">{{repo.getCloneURL(false)}}</a>
- </div>
- </div>
- {% endif %}
-</div>
-{% 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 @@
+<label id="url-embed" for="url-embed-input"><b>Embed</b> HTML code</label>
+<input id="url-embed-input" type="text" class="fullwidthtext" value='&lt;script src="{{repo.getLink('embed', null, true)}}" type="text/javascript"&gt;&lt;/script&gt;'/>
+
+{% if repo.getCloneURL(true) %}
+<label id="url-public" for="url-public-input"><b>Public</b> clone URL</label>
+<input id="url-public-input" type="text" class="fullwidthtext" value="{{repo.getCloneURL(true)}}"/>
+{% endif %}
+
+{% if repo.getCloneURL(false) %}
+<label id="url-private" for="url-private-input"><b>Private</b> clone URL</label>
+<input id="url-private-input" type="text" class="fullwidthtext" value="{{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('<link rel="stylesheet" href="{{htmlhelper.fullUrl('css/embed.css')}}"/>');
+document.write(
+ '<div class="phork" id="{{repo.id}}">'
+ + {% filter json_encode(constant('JSON_UNESCAPED_SLASHES'))|raw -%}{% include 'embed-part-file.htm' %}{%- endfilter %}
+ + '</div>'
+);
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 @@
+<div class="phork-file">
+ <div class="phork-content">
+ {{file.getRenderedContent(toolres)|raw}}
+ </div>
+ <div class="phork-meta">
+ <a href="{{file.getLink('raw', null, true)}}" style="float: right">view raw source</a>
+ <a href="{{file.getLink('display', null, true)}}">{{file.getFilename()}}</a>
+ </div>
+</div>
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('<link rel="stylesheet" href="{{htmlhelper.fullUrl('css/embed.css')}}"/>');
+document.write(
+ '<div class="phork" id="{{repo.id}}">'
+{% for file in repo.getFiles %}
+ + {% filter json_encode(constant('JSON_UNESCAPED_SLASHES'))|raw -%}{% include 'embed-part-file.htm' %}{%- endfilter %}
+{% endfor %}
+ + '</div>'
+);
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 '<div class="code">'
+ return '<style type="text/css">'
+ . $geshi->get_stylesheet() . '</style>'
+ . '<div class="code">'
. str_replace('&nbsp;', '&#160;', $geshi->parse_code())
. '</div>';
}
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 @@
+<?php
+namespace phorkie;
+/**
+ * Embed a file of a paste into a HTML site.
+ * We deliver javascript for that.
+ */
+$reqWritePermissions = false;
+require_once 'www-header.php';
+
+$repo = new Repository();
+$repo->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 @@
+<?php
+namespace phorkie;
+/**
+ * Embed a file of a paste into a HTML site.
+ * We deliver javascript for that.
+ */
+$reqWritePermissions = false;
+require_once 'www-header.php';
+
+$repo = new Repository();
+$repo->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);
}