A simple php website which displays quotes on pictures of pandas.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

296 lines
34 KiB

  1. /*!
  2. * @mekwall's .vangogh() for Syntax Highlighting
  3. *
  4. * All code is open source and dual licensed under GPL and MIT.
  5. * Check the individual licenses for more information.
  6. * https://github.com/mekwall/jquery-vangogh/blob/master/GPL-LICENSE.txt
  7. * https://github.com/mekwall/jquery-vangogh/blob/master/MIT-LICENSE.txt
  8. */
  9. (function($,a,b){var c=1,d=!1,e=!1,f={get:function(b){var c=a.location.hash;if(c.length>0){var d=c.match(new RegExp(b+":{([a-zA-Z0-9,-]*)}"));if(d)return d[1].split(",")}return[]},set:function(b,c){var d=a.location.hash,e,f=b+":{"+c.join(",")+"}",g=d.indexOf(b+":{");if(c.length===0)return this.remove(b);g!==-1?e=d.replace(new RegExp("("+b+":{[a-zA-Z0-9,-]*})"),f):e=d.length>0?d+","+f:f,a.location.hash=e},remove:function(b){a.location.hash=a.location.hash.replace(new RegExp("([,]?"+b+":{[a-zA-Z0-9,-]*}[,]?)"),"")}},g={numberRange:/^([0-9]+)-([0-9]+)$/,pageNumber:/-([0-9]+)$/,multilineBegin:/<span class="([\w-_][^"]+)">(?:.[^<]*(?!<\/span>)|)$/ig,multilineEnd:/(<span class="([\w-_][^"]+)">)?(?:.[^<]*)?(<\/span>)/ig};$.fn.vanGogh=function(h){function n(){if(d||e)setTimeout(n,100);else{k++;if(k>=10)return;if(h.source&&!l){e=!0,$.ajax({url:h.source,crossDomain:!0,dataType:"text",success:function(a){l=a},error:function(a,b){l="ERROR: "+b},complete:function(){e=!1,n()}});return}b=b||a.hljs;if(!b){d=!0,$.getScript(h.autoload,function(){d=!1,n()});return}j.filter("pre,code").each(function(){function r(b,c,e){var h=!1,i=a.find(".vg-line");c&&(a.find(".vg-highlight").removeClass("vg-highlight"),f.remove(d),k=[]),b=$.type(b)==="array"?b:[b],$.each(b,function(b,c){if(k.indexOf(c)<=-1){!isNaN(parseFloat(c,10))&&isFinite(c)&&(c=parseInt(c,10));if($.type(c)==="string"){var e=g.numberRange.exec(c);if(e){var f=e[1],h=e[2],j="";for(var b=f;b<=h;b++)j+=",#"+d+"-"+b,k.push(b);i.filter(j.substring(1)).addClass("vg-highlight")}else a.find(".vg-line:contains("+c+")").each(function(){var a=$(this).addClass("vg-highlight");a.html(a.html().replace(c,'<span class="vg-highlight">'+c+"</span>"))}),k.push(c)}else{var l=d+"-"+this,m=i.filter("#"+l);m.length&&(m.addClass("vg-highlight"),k.push(c))}}}),!e&&f.set(d,k)}var a=$(this).addClass("vg-container").attr("id",this.id||"vg-"+c++),d=this.id,e=a.find("code"),i=!1,j=!1,k=[];e.length||(e=a,i=!0),h.source&&l&&e.text(l);var n=e.text();b.highlightBlock(e[0],h.tab);var o=e.html().split("\n"),p="",q="";if(!i){var s={},t=0;$.each(o,function(a,b){var c=a+h.firstLine,e=d+"-"+c,f=b;h.numbers&&(p+='<a class="vg-number" rel="#'+e+'">'+c+"</a>");if(s[t]){var i=g.multilineEnd.exec(b);i&&!i[1]?(f='<span class="'+s[t]+'">'+f,delete s[t],t--):f='<span class="'+s[t]+'">'+f+"</span>"}var j=g.multilineBegin.exec(b);j&&(t++,s[t]=j[1]),q+='<div class="vg-line" id="'+e+'">'+f+"</div>"}),q='<code class="vg-code">'+q+"</code>",h.numbers&&(q='<div class="vg-gutter">'+p+"</div>"+q),a.html(q),e=a.find("code"),a.find(".vg-number").click(function(b){var c=$(this),e=c.attr("rel"),h=a.find(e);if(h.hasClass("vg-highlight")){h.removeClass("vg-highlight"),k.splice(k.indexOf(c.text()),1),f.set(d,k),j=!1;return!1}var i=j;j=parseInt(g.pageNumber.exec(e)[1],10),b.shiftKey&&j?r(i<j?i+"-"+j:j+"-"+i,!0):r(j,b.ctrlKey?!1:!0);return!1});var u=a.find(".vg-gutter"),v=u.outerWidth(),w=0,x=!1;h.animateGutter&&a.scroll(function(a){if(this.scrollLeft!==w)if(this.scrollLeft>v){if(this.scrollLeft<w)w=this.scrollLeft,u.hide();else if(this.scrollLeft!==w){if(x)return;var b=this;w=this.scrollLeft,x=setTimeout(function(){x=!1;var a=b.scrollLeft;e.css("marginLeft",v),u.css({"float":"none",position:"absolute",left:a-v}).show().stop().animate({left:a})},500)}}else w=this.scrollLeft,clearTimeout(x),x=!1,u.css({"float":"",position:"",left:""}).show()})}else i&&a.addClass("vg-code");e.dblclick(function(){m(e[0]);return!1});if(h.maxLines>0){var y=a.find(".vg-line").height(),z=parseInt(e.css("paddingTop")),A=y*(h.maxLines+1)+z;a.css({minHeight:y+z,maxHeight:A})}h.highlight&&r(h.highlight,!0,!0);var B=f.get(d);B.length&&r(B,!1,!0)})}}function m(b){var c=a,d=a.document;if(d.body.createTextRange){var e=d.body.createTextRange();e.moveToElementText(b),e.select()}else if(d.createRange){var f=c.getSelection(),e=d.createRange();e.selectNodeContents(b),f.removeAllRanges(),f.addRange(e)}}var i={language:"auto",firstLine:1,maxLines:0,numbers:!0,highlight:null,animateGutter:!0,autoload:"http://softwaremaniacs.org/media/soft/highlight/highlight.pack.js",tab:" "};h=$.extend(
  10. /*!
  11. * Repo.js
  12. * @author Darcy Clarke
  13. *
  14. * Copyright (c) 2012 Darcy Clarke
  15. * Dual licensed under the MIT and GPL licenses.
  16. * http://darcyclarke.me/
  17. */
  18. (function($){
  19. // Github repo
  20. $.fn.repo = function( options ){
  21. // Context and Base64 methods
  22. var _this = this,
  23. keyStr64 = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv" + "wxyz0123456789+/" + "=",
  24. encode64 = function(a){a=escape(a);var b="";var c,d,e="";var f,g,h,i="";var j=0;do{c=a.charCodeAt(j++);d=a.charCodeAt(j++);e=a.charCodeAt(j++);f=c>>2;g=(c&3)<<4|d>>4;h=(d&15)<<2|e>>6;i=e&63;if(isNaN(d)){h=i=64}else if(isNaN(e)){i=64}b=b+keyStr64.charAt(f)+keyStr64.charAt(g)+keyStr64.charAt(h)+keyStr64.charAt(i);c=d=e="";f=g=h=i=""}while(j<a.length);return b},
  25. decode64 = function(a){var b="";var c,d,e="";var f,g,h,i="";var j=0;var k=/[^A-Za-z0-9\+\/\=]/g;if(k.exec(a)){}a=a.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{f=keyStr64.indexOf(a.charAt(j++));g=keyStr64.indexOf(a.charAt(j++));h=keyStr64.indexOf(a.charAt(j++));i=keyStr64.indexOf(a.charAt(j++));c=f<<2|g>>4;d=(g&15)<<4|h>>2;e=(h&3)<<6|i;b=b+String.fromCharCode(c);if(h!=64){b=b+String.fromCharCode(d)}if(i!=64){b=b+String.fromCharCode(e)}c=d=e="";f=g=h=i=""}while(j<a.length);return unescape(b)},
  26. transition = function(el, direction, init){
  27. var opposite = (direction === 'left') ? '' : 'left';
  28. if(init){
  29. el.addClass('active');
  30. _this.container.css({'height' : calculateHeight(el) + 'px'});
  31. } else {
  32. _this.container
  33. .find('.page.active')
  34. .css('position','absolute')
  35. .addClass(direction)
  36. .removeClass('active')
  37. .end()
  38. .css({'height' : calculateHeight(el) + 'px'});
  39. el.addClass('active')
  40. .removeClass(opposite)
  41. .delay(250)
  42. .queue(function(){
  43. $(this).css('position','relative').dequeue();
  44. });
  45. }
  46. },
  47. calculateHeight = function(el){
  48. // This calculates the height of the bounding box for the repo display.
  49. // clientHeight is element containing fetched results, plus the h1 tag, plus
  50. // the div repo margin has of 15 pixels.
  51. return (el[0].clientHeight + _this.container.find('h1').outerHeight(true) + 15);
  52. },
  53. getMimeTypeByExtension = function(extension){
  54. var mimeTypes = {
  55. // images
  56. 'png': 'image/png',
  57. 'gif': 'image/gif',
  58. 'jpg': 'image/jpeg',
  59. 'jpeg': 'image/jpeg',
  60. 'ico': 'image/x-icon'
  61. };
  62. return mimeTypes[extension] ? mimeTypes[extension] : 'text/plain';
  63. };
  64. // Settings
  65. _this.settings = $.extend({
  66. user : '',
  67. name : '',
  68. branch : 'master',
  69. css : '@font-face{font-family:"Octicons Regular";src:url("https://a248.e.akamai.net/assets.github.com/fonts/octicons/octicons-regular-webfont.eot?639c50d4");src:url("https://a248.e.akamai.net/assets.github.com/fonts/octicons/octicons-regular-webfont.eot?639c50d4#iefix") format("embedded-opentype"),url("https://a248.e.akamai.net/assets.github.com/fonts/octicons/octicons-regular-webfont.woff?0605b255") format("woff"),url("https://a248.e.akamai.net/assets.github.com/fonts/octicons/octicons-regular-webfont.ttf?f82fcba7") format("truetype"),url("https://a248.e.akamai.net/assets.github.com/fonts/octicons/octicons-regular-webfont.svg?1f7afa21#newFontRegular") format("svg");font-weight:normal;font-style:normal}@font-face{font-family:"repo-icons";src:url("https://raw.github.com/darcyclarke/Repo.js/master/fonts/repo.eot");src:url("https://raw.github.com/darcyclarke/Repo.js/master/fonts/repo.eot#iefix") format("embedded-opentype"),url("https://raw.github.com/darcyclarke/Repo.js/master/fonts/repo.woff") format("woff"),url("https://raw.github.com/darcyclarke/Repo.js/master/fonts/repo.ttf") format("truetype"),url("https://raw.github.com/darcyclarke/Repo.js/master/fonts/repo.svg") format("svg");font-weight:normal;font-style:normal}.repo,.repo *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;box-sizing:border-box}.repo ul *{display:block;font-family:sans-serif;font-size:13px;line-height:18px}.repo{width:100%;margin:0 0 15px 0;position:relative;padding-bottom:1px;color:#555;overflow:hidden;height:300px;-webkit-transition:height .25s;-moz-transition:height .25s;-o-transition:height .25s;-ms-transition:height .25s;transition:height .25s}.repo .page{background:#f8f8f8;border:4px solid rgba(0,0,0,0.08);border-radius:3px;-ms-filter:"alpha(opacity=0)";filter:alpha(opacity=0);opacity:0;left:100%;width:98%;position:absolute;-webkit-transition:all .25s;-moz-transition:all .25s;-o-transition:all .25s;-ms-transition:all .25s;transition:all .25s}.repo .page.active{left:1%!important;-ms-filter:"alpha(opacity=100)";filter:alpha(opacity=100);opacity:1;display:block}.repo .page.left{left:-100%}.repo .loader{position:absolute;display:block;width:100%;height:300px;top:0;left:0;background:url(data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U0MDExRTE5OEVFRTYxNzRDQjUwREVEIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+Af/+/fz7+vn49/b19PPy8fDv7u3s6+rp6Ofm5eTj4uHg397d3Nva2djX1tXU09LR0M/OzczLysnIx8bFxMPCwcC/vr28u7q5uLe2tbSzsrGwr66trKuqqainpqWko6KhoJ+enZybmpmYl5aVlJOSkZCPjo2Mi4qJiIeGhYSDgoGAf359fHt6eXh3dnV0c3JxcG9ubWxramloZ2ZlZGNiYWBfXl1cW1pZWFdWVVRTUlFQT05NTEtKSUhHRkVEQ0JBQD8+PTw7Ojk4NzY1NDMyMTAvLi0sKyopKCcmJSQjIiEgHx4dHBsaGRgXFhUUExIREA8ODQwLCgkIBwYFBAMCAQAAIfkECQYACAAsAAAAAEAAQAAABJwQyUmrvXaAEbD/YPgdZAl0YqqKxtG+JECsdC2VOCygdv/BLVxJMPMZK0KgqzQ4OhEwYUlXePqmy2iSZ10FpdklidtNhbW5A7ksAp9La3ZI+cXG5aEAwPDV3vEqe31qgE8BX3+FNXyJio6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/shEAIfkECQYACAAsAAAAAEAAQAAABOwQyUmrvXaAEbD/YPgdZAl0YqqKxtG+JECsdC2VOCygdv/BL
  70. }, options);
  71. // Extension Hashes
  72. _this.extensions = {
  73. as : 'actionscript',
  74. coffee : 'coffeescript',
  75. css : 'css',
  76. html : 'html',
  77. js : 'javascript',
  78. md : 'markdown',
  79. php : 'php',
  80. py : 'python',
  81. rb : 'ruby'
  82. };
  83. // Repo
  84. _this.repo = {
  85. name : 'default',
  86. folders : [],
  87. files : []
  88. };
  89. // Namespace - strip out characters that would have to be escaped to be used in selectors
  90. _this.namespace = _this.settings.name.toLowerCase().replace(/[^a-z0-9_-]/g, '');
  91. // Check if this namespace is already in use
  92. var usedNamespaces = $('[data-id^='+ _this.namespace +']');
  93. if(usedNamespaces.length){
  94. _this.namespace += String(usedNamespaces.length);
  95. }
  96. // Insert CSS
  97. if(typeof _this.settings.css != 'undefined' && _this.settings.css !== '' && $('#repojs_css').length <= 0)
  98. $('body').prepend($('<style id="repojs_css">').html(_this.settings.css));
  99. // Query Github Tree API
  100. $.ajax({
  101. url: 'https://api.github.com/repos/' + _this.settings.user + '/' + _this.settings.name + '/git/trees/' + _this.settings.branch + '?recursive=1',
  102. type: 'GET',
  103. data: {},
  104. dataType: 'jsonp',
  105. success: function(response){
  106. var treeLength = response.data.tree.length;
  107. $.each(response.data.tree, function(i){
  108. // Setup if last element
  109. if(!--treeLength){
  110. _this.container.addClass('loaded');
  111. // Add 10ms timeout here as some browsers require a bit of time before calculating height.
  112. setTimeout( function(){
  113. transition(_this.container.find('.page').first(), 'left', true);
  114. }, 10 );
  115. }
  116. // Return if data is not a file
  117. if(this.type != 'blob')
  118. return;
  119. // Setup defaults
  120. var first = _this.container.find('.page').first()
  121. ctx = _this.repo,
  122. output = first,
  123. path = this.path,
  124. arr = path.split('/'),
  125. file = arr[(arr.length - 1)],
  126. id = '';
  127. // Remove file from array
  128. arr = arr.slice(0,-1);
  129. id = _this.namespace;
  130. // Loop through folders
  131. $.each(arr, function(i){
  132. var name = String(this),
  133. index = 0,
  134. exists = false;
  135. id = id + '_split_' + name.replace('.','_dot_');
  136. // Loop through folders and check names
  137. $.each(ctx.folders, function(i){
  138. if(this.name == name){
  139. index = i;
  140. exists = true;
  141. }
  142. });
  143. // Create folder if it doesn't exist
  144. if(!exists){
  145. // Append folder to DOM
  146. if(output !== first){
  147. output.find('ul li.back').after($('<li class="dir"><a href="#" data-id="' + id + '">' + name +'</a></li>'));
  148. } else {
  149. output.find('ul li').first().after($('<li class="dir"><a href="#" data-id="' + id + '">' + name +'</a></li>'));
  150. }
  151. // Add folder to repo object
  152. ctx.folders.push({
  153. name : name,
  154. folders : [],
  155. files : [],
  156. element : $('<div class="page" id="' + id + '"><ul><li class="titles"><span>name</span></li><li class="back"><a href="#">..</a></li></ul></page>').appendTo(_this.container)[0]
  157. });
  158. index = ctx.folders.length-1;
  159. }
  160. // Change context & output to the proper folder
  161. output = $(ctx.folders[index].element);
  162. ctx = ctx.folders[index];
  163. });
  164. // Append file to DOM
  165. output.find('ul').append($('<li class="file"><a href="#" data-path="' + path + '" data-id="' + id + '">' + file +'</a></li>'));
  166. // Add file to the repo object
  167. ctx.files.push(file);
  168. });
  169. // Bind to page links
  170. _this.container.on('click', 'a', function(e){
  171. e.preventDefault();
  172. var link = $(this),
  173. parent = link.parents('li'),
  174. page = link.parents('.page'),
  175. repo = link.parents('.repo'),
  176. el = $('#' + link.data('id'));
  177. // Is link a file
  178. if(parent.hasClass('file')){
  179. el = $('#' + link.data('id'));
  180. if(el.legnth > 0){
  181. el.addClass('active');
  182. } else {
  183. $.ajax({
  184. url: 'https://api.github.com/repos/' + _this.settings.user + '/' + _this.settings.name + '/contents/' + link.data('path') + '?ref=' + _this.settings.branch,
  185. type: 'GET',
  186. data: {},
  187. dataType: 'jsonp',
  188. success: function(response){
  189. var fileContainer = $('<div class="file page" id="' + link.data('id') + '"></div>'),
  190. extension = response.data.name.split('.').pop().toLowerCase(),
  191. mimeType = getMimeTypeByExtension(extension);
  192. if('image' === mimeType.split('/').shift()){
  193. el = fileContainer.append($('<div class="image"><span class="border-wrap"><img src="" /></span></div>')).appendTo(repo);
  194. el.find('img')
  195. .attr('src', 'data:' + mimeType + ';base64,' + response.data.content)
  196. .attr('alt', response.data.name);
  197. }
  198. else {
  199. el = fileContainer.append($('<pre><code></code></pre>')).appendTo(repo);
  200. if(typeof _this.extensions[extension] != 'undefined')
  201. el.find('code').addClass(_this.extensions[extension]);
  202. el.find('code').html(String(decode64(response.data.content)).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'));
  203. el.find('pre').vanGogh();
  204. }
  205. transition(el, 'left');
  206. },
  207. error: function(response){
  208. if(console && console.log)
  209. console.log('Request Error:', e);
  210. }
  211. });
  212. }
  213. // Is link a folder
  214. } else if(parent.hasClass('dir')) {
  215. _this.container
  216. .find('h1')
  217. .find('.active')
  218. .removeClass('active')
  219. .end()
  220. .append('<a href="#" data-id="' + link.data('id') + '" class="active">' + link.text() + '</a>');
  221. transition(el, 'left');
  222. // Is link a back link
  223. } else if(parent.hasClass('back')){
  224. _this.container.find('h1 a').last().remove();
  225. el = page[0].id.split('_split_').slice(0,-1).join('_split_');
  226. el = (el == _this.namespace) ? _this.container.find('.page').first() : $('#' + el);
  227. transition(el, 'right');
  228. // Is nav link
  229. } else {
  230. el = el.length ? el : _this.container.find('.page').eq(link.index());
  231. if(link[0] !== _this.container.find('h1 a')[0])
  232. link.addClass('active');
  233. _this.container.find('h1 a').slice((link.index()+1),_this.container.find('h1 a').length).remove();
  234. transition(el, 'right');
  235. }
  236. });
  237. },
  238. error : function(response){
  239. if(console && console.log)
  240. console.log('Request Error:', response);
  241. }
  242. });
  243. // Setup repo container
  244. return this.each(function(){
  245. _this.container = $('<div class="repo"><h1><a href="#" data-id="' + _this.namespace + '_split_default">' + _this.settings.name + '</a></h1><div class="loader"></div><div class="page" id="' + _this.namespace + '_split_default"><ul><li class="titles"><span>name</span></li></ul></div></div>').appendTo($(this));
  246. });
  247. };
  248. })(jQuery);