javascript embedding support
authorChristian Weiske <cweiske@cweiske.de>
Mon, 26 Jan 2015 17:24:37 +0000 (18:24 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 26 Jan 2015 17:24:37 +0000 (18:24 +0100)
15 files changed:
data/templates/display-head.htm
data/templates/display-sidebar-urls.htm [new file with mode: 0644]
data/templates/display.htm
data/templates/embed-file.htm [new file with mode: 0644]
data/templates/embed-part-file.htm [new file with mode: 0644]
data/templates/embed.htm [new file with mode: 0644]
src/phorkie/File.php
src/phorkie/Renderer/Geshi.php
src/phorkie/Repository.php
www/.htaccess
www/css/embed.css [new file with mode: 0644]
www/css/phorkie.css
www/embed-file.php [new file with mode: 0644]
www/embed.php [new file with mode: 0644]
www/js/phorkie.js

index aa7daecdd91006cdacf501ea605ebbe7a7b58b2f..8c1690866c0429ff5b81a9890a9e0f73073f9c03 100644 (file)
   </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 (file)
index 0000000..446810c
--- /dev/null
@@ -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 %}
index d6fd6469c78d6b30e9f7a0f21a7990dd2b2069bf..59db9f8fcb54e7447cc99844846c20da6ae6448a 100644 (file)
@@ -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 (file)
index 0000000..46075de
--- /dev/null
@@ -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 (file)
index 0000000..cdfd132
--- /dev/null
@@ -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 (file)
index 0000000..0334c22
--- /dev/null
@@ -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>'
+);
index 2aa1d194c48d2c3e87ccbf7876ff1aa1988446c6..9eb7fa7002be4463442c1a4c81b596352b5ec895 100644 (file)
@@ -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;
     }
 
     /**
index 0c545ed5dff3e9d674959eb9e2f07566a991a99c..2b3854a59d60f746ee5ebe0148ba1be209b7322d 100644 (file)
@@ -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>';
     }
index 467456b96821e81cd919927c734f098e2212bdb0..f9b248dcf91ea2b1c5a8bf572879bbd1a0f5b85e 100644 (file)
@@ -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') {
index 566d27c0ba38def12564fee2d4a2368c9256f85e..cda57f991215f3d418918d906b00ed8d4235e461 100644 (file)
@@ -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 (file)
index 0000000..4d5c050
--- /dev/null
@@ -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
index edebe1c69443d3c4403569515b5388044b5548ca..d2b05c4d55d282bb7ed4b71483bc1208b997bb83 100644 (file)
@@ -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 (file)
index 0000000..0ece1b9
--- /dev/null
@@ -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 (file)
index 0000000..660e1f2
--- /dev/null
@@ -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,
+    )
+);
+?>
index 7078e8fe9173bc8a17b9ac9facb0a8985189b5d0..5d965751cd54d723b049f66657a0fd8270fead0b 100644 (file)
@@ -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);
 }