diff --git a/app/post.class.php b/app/post.class.php index 058c24c..d768e76 100644 --- a/app/post.class.php +++ b/app/post.class.php @@ -13,8 +13,8 @@ private static function parse_content($c){ // Highlight if(Config::get("highlight")){ - $c = preg_replace_callback('/\[code(?:=([^\[]+))?\](.+?)(?:(?=\[\/code\]))\[\/code\]/m', function($m){ - return ''.htmlentities($m[2]).''; + $c = preg_replace_callback('/\[code(?:=([^\[]+))?\]((.|\s)+?)(?:(?=\[\/code\]))\[\/code\]/m', function($m){ + return ''.htmlentities(trim($m[2])).''; }, $c); } else { // Links @@ -41,6 +41,7 @@ private static function parse_content($c){ private static function raw_data($raw_input){ $default_input = [ "text" => '', + "plain_text" => '', "feeling" => '', "persons" => '', "location" => '', @@ -121,7 +122,7 @@ public static function delete($r){ public static function edit_data($r){ self::login_protected(); - return DB::get_instance()->query("SELECT `plain_text` AS `text`, `feeling`, `persons`, `location`, `privacy`, `content_type`, `content` FROM `posts` WHERE `id` = ? AND `status` = 1", $r["id"])->first(); + return DB::get_instance()->query("SELECT `plain_text`, `feeling`, `persons`, `location`, `privacy`, `content_type`, `content` FROM `posts` WHERE `id` = ? AND `status` = 1", $r["id"])->first(); } public static function get_date($r){ diff --git a/config.ini b/config.ini index 93c1845..2278d68 100644 --- a/config.ini +++ b/config.ini @@ -10,7 +10,7 @@ title = Blog name = Max Musermann pic_small = static/images/profile.jpg pic_big = static/images/profile_big.jpg -cover = static/images/cover.jpg +;cover = static/images/cover.jpg [language] lang = en @@ -24,6 +24,6 @@ pass = demo [system] system_name = blog -version = 1.03 +version = 1.04 debug = true logs = false \ No newline at end of file diff --git a/index.php b/index.php index c3459e3..5e58286 100644 --- a/index.php +++ b/index.php @@ -31,7 +31,7 @@ } $hours = ''; -for($h=0;$h<=60;$h++){ +for($h=0;$h<=24;$h++){ $hours .= sprintf('', $h, $h); } @@ -153,7 +153,10 @@ @@ -272,7 +275,7 @@
- "> + ' : (empty($header) ? '
' : '')); ?>
">
@@ -296,6 +299,7 @@ + ' : ''; ?> diff --git a/static/scripts/app.js b/static/scripts/app.js index cbf22dc..269907b 100644 --- a/static/scripts/app.js +++ b/static/scripts/app.js @@ -299,7 +299,8 @@ var new_post = { url: "ajax.php", data: { action: "insert", - text: new_post.obj.find(".e_text").text(), + text: new_post.obj.find(".e_text").val(), + //text: new_post.obj.find(".e_text").text(), feeling: new_post.obj.find(".i_feeling").val(), persons: new_post.obj.find(".i_persons").val(), location: new_post.obj.find(".i_location").val(), @@ -448,7 +449,9 @@ $.fn.apply_edit = function(data){ }; // Set data and key listeners for text div - modal.find(".e_text").text(data.text).keydown(function(e) { + //modal.find(".e_text").html(data.plain_text) + modal.find(".e_text").val(data.plain_text) + /*.keydown(function(e) { if(e.keyCode === 13){ document.execCommand('insertHTML', false, "\n"); return false; @@ -475,7 +478,10 @@ $.fn.apply_edit = function(data){ document.execCommand('paste', false, text); } }); - + + autosize($(modal.find(".e_text"))); + //autosize.update(ta); + var file_data = modal.find(".photo_upload"); $(file_data).change(function(){ var form_data = new FormData(); @@ -626,7 +632,8 @@ $.fn.post_fill = function(data){ }); post.find(".b_date").attr("href", "#id="+data.id); - + + /* var chars = 380; if(data.text.length > chars){ var b_more = []; @@ -642,6 +649,18 @@ $.fn.post_fill = function(data){ }); }); } + */ + + var height = 200; + if(data.text.length > 400){ + post.find(".b_text").css("max-height", height+"px"); + var show_more = $('#prepared .show_more').clone(); + show_more.insertAfter(post.find(".b_text")); + show_more.click(function(){ + $(this).remove(); + post.find(".b_text").css("max-height", ''); + }); + } // Highlight if(typeof hljs !== "undefined"){ @@ -754,7 +773,8 @@ $.fn.apply_post = function(){ data: { action: "update", id: post_id, - text: modal.find(".e_text").text(), + text: modal.find(".e_text").val(), + //text: modal.find(".e_text").text(), feeling: modal.find(".i_feeling").val(), persons: modal.find(".i_persons").val(), location: modal.find(".i_location").val(), diff --git a/static/scripts/autosize.js b/static/scripts/autosize.js new file mode 100644 index 0000000..e0a21c7 --- /dev/null +++ b/static/scripts/autosize.js @@ -0,0 +1,292 @@ +/*! + Autosize 4.0.0 + license: MIT + http://www.jacklmoore.com/autosize +*/ +(function (global, factory) { + if (typeof define === 'function' && define.amd) { + define(['exports', 'module'], factory); + } else if (typeof exports !== 'undefined' && typeof module !== 'undefined') { + factory(exports, module); + } else { + var mod = { + exports: {} + }; + factory(mod.exports, mod); + global.autosize = mod.exports; + } +})(this, function (exports, module) { + 'use strict'; + + var map = typeof Map === "function" ? new Map() : (function () { + var keys = []; + var values = []; + + return { + has: function has(key) { + return keys.indexOf(key) > -1; + }, + get: function get(key) { + return values[keys.indexOf(key)]; + }, + set: function set(key, value) { + if (keys.indexOf(key) === -1) { + keys.push(key); + values.push(value); + } + }, + 'delete': function _delete(key) { + var index = keys.indexOf(key); + if (index > -1) { + keys.splice(index, 1); + values.splice(index, 1); + } + } + }; + })(); + + var createEvent = function createEvent(name) { + return new Event(name, { bubbles: true }); + }; + try { + new Event('test'); + } catch (e) { + // IE does not support `new Event()` + createEvent = function (name) { + var evt = document.createEvent('Event'); + evt.initEvent(name, true, false); + return evt; + }; + } + + function assign(ta) { + if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || map.has(ta)) return; + + var heightOffset = null; + var clientWidth = ta.clientWidth; + var cachedHeight = null; + + function init() { + var style = window.getComputedStyle(ta, null); + + if (style.resize === 'vertical') { + ta.style.resize = 'none'; + } else if (style.resize === 'both') { + ta.style.resize = 'horizontal'; + } + + if (style.boxSizing === 'content-box') { + heightOffset = -(parseFloat(style.paddingTop) + parseFloat(style.paddingBottom)); + } else { + heightOffset = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth); + } + // Fix when a textarea is not on document body and heightOffset is Not a Number + if (isNaN(heightOffset)) { + heightOffset = 0; + } + + update(); + } + + function changeOverflow(value) { + { + // Chrome/Safari-specific fix: + // When the textarea y-overflow is hidden, Chrome/Safari do not reflow the text to account for the space + // made available by removing the scrollbar. The following forces the necessary text reflow. + var width = ta.style.width; + ta.style.width = '0px'; + // Force reflow: + /* jshint ignore:start */ + ta.offsetWidth; + /* jshint ignore:end */ + ta.style.width = width; + } + + ta.style.overflowY = value; + } + + function getParentOverflows(el) { + var arr = []; + + while (el && el.parentNode && el.parentNode instanceof Element) { + if (el.parentNode.scrollTop) { + arr.push({ + node: el.parentNode, + scrollTop: el.parentNode.scrollTop + }); + } + el = el.parentNode; + } + + return arr; + } + + function resize() { + var originalHeight = ta.style.height; + var overflows = getParentOverflows(ta); + var docTop = document.documentElement && document.documentElement.scrollTop; // Needed for Mobile IE (ticket #240) + + ta.style.height = ''; + + var endHeight = ta.scrollHeight + heightOffset; + + if (ta.scrollHeight === 0) { + // If the scrollHeight is 0, then the element probably has display:none or is detached from the DOM. + ta.style.height = originalHeight; + return; + } + + ta.style.height = endHeight + 'px'; + + // used to check if an update is actually necessary on window.resize + clientWidth = ta.clientWidth; + + // prevents scroll-position jumping + overflows.forEach(function (el) { + el.node.scrollTop = el.scrollTop; + }); + + if (docTop) { + document.documentElement.scrollTop = docTop; + } + } + + function update() { + resize(); + + var styleHeight = Math.round(parseFloat(ta.style.height)); + var computed = window.getComputedStyle(ta, null); + + // Using offsetHeight as a replacement for computed.height in IE, because IE does not account use of border-box + var actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(computed.height)) : ta.offsetHeight; + + // The actual height not matching the style height (set via the resize method) indicates that + // the max-height has been exceeded, in which case the overflow should be allowed. + if (actualHeight !== styleHeight) { + if (computed.overflowY === 'hidden') { + changeOverflow('scroll'); + resize(); + actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(window.getComputedStyle(ta, null).height)) : ta.offsetHeight; + } + } else { + // Normally keep overflow set to hidden, to avoid flash of scrollbar as the textarea expands. + if (computed.overflowY !== 'hidden') { + changeOverflow('hidden'); + resize(); + actualHeight = computed.boxSizing === 'content-box' ? Math.round(parseFloat(window.getComputedStyle(ta, null).height)) : ta.offsetHeight; + } + } + + if (cachedHeight !== actualHeight) { + cachedHeight = actualHeight; + var evt = createEvent('autosize:resized'); + try { + ta.dispatchEvent(evt); + } catch (err) { + // Firefox will throw an error on dispatchEvent for a detached element + // https://bugzilla.mozilla.org/show_bug.cgi?id=889376 + } + } + } + + var pageResize = function pageResize() { + if (ta.clientWidth !== clientWidth) { + update(); + } + }; + + var destroy = (function (style) { + window.removeEventListener('resize', pageResize, false); + ta.removeEventListener('input', update, false); + ta.removeEventListener('keyup', update, false); + ta.removeEventListener('autosize:destroy', destroy, false); + ta.removeEventListener('autosize:update', update, false); + + Object.keys(style).forEach(function (key) { + ta.style[key] = style[key]; + }); + + map['delete'](ta); + }).bind(ta, { + height: ta.style.height, + resize: ta.style.resize, + overflowY: ta.style.overflowY, + overflowX: ta.style.overflowX, + wordWrap: ta.style.wordWrap + }); + + ta.addEventListener('autosize:destroy', destroy, false); + + // IE9 does not fire onpropertychange or oninput for deletions, + // so binding to onkeyup to catch most of those events. + // There is no way that I know of to detect something like 'cut' in IE9. + if ('onpropertychange' in ta && 'oninput' in ta) { + ta.addEventListener('keyup', update, false); + } + + window.addEventListener('resize', pageResize, false); + ta.addEventListener('input', update, false); + ta.addEventListener('autosize:update', update, false); + ta.style.overflowX = 'hidden'; + ta.style.wordWrap = 'break-word'; + + map.set(ta, { + destroy: destroy, + update: update + }); + + init(); + } + + function destroy(ta) { + var methods = map.get(ta); + if (methods) { + methods.destroy(); + } + } + + function update(ta) { + var methods = map.get(ta); + if (methods) { + methods.update(); + } + } + + var autosize = null; + + // Do nothing in Node.js environment and IE8 (or lower) + if (typeof window === 'undefined' || typeof window.getComputedStyle !== 'function') { + autosize = function (el) { + return el; + }; + autosize.destroy = function (el) { + return el; + }; + autosize.update = function (el) { + return el; + }; + } else { + autosize = function (el, options) { + if (el) { + Array.prototype.forEach.call(el.length ? el : [el], function (x) { + return assign(x, options); + }); + } + return el; + }; + autosize.destroy = function (el) { + if (el) { + Array.prototype.forEach.call(el.length ? el : [el], destroy); + } + return el; + }; + autosize.update = function (el) { + if (el) { + Array.prototype.forEach.call(el.length ? el : [el], update); + } + return el; + }; + } + + module.exports = autosize; +}); \ No newline at end of file diff --git a/static/styles/design.css b/static/styles/design.css index 150887a..ce18bcb 100644 --- a/static/styles/design.css +++ b/static/styles/design.css @@ -36,7 +36,7 @@ body { .cover { font-size: 0; position: relative; - min-height: 315px; + /*min-height: 315px;*/ } .cover .overlay { background: url(../images/UgNUNkKQar6.png) bottom left repeat-x; @@ -114,6 +114,21 @@ body { text-transform: uppercase; } +.show_more { + height: 40px; + line-height: 40px; + position: relative; + margin-top: -40px; + display: block; + text-align: center; + background: -moz-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 75%, rgba(255,255,255,1) 100%); + background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 75%,rgba(255,255,255,1) 100%); + background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 75%,rgba(255,255,255,1) 100%); + filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=0 ); + cursor: pointer; + vertical-align: bottom; +} + .b_post { border: 1px solid; border-color: #e5e6e9 #dfe0e4 #d0d1d5; @@ -246,6 +261,7 @@ body { word-wrap: break-word; font-size: 14px; padding-top: 10px; + overflow: hidden; } .b_text a, @@ -603,14 +619,25 @@ body { .e_text { margin-left: 50px; -} - -.e_text { outline: 0; white-space: pre-line; min-height: 50px; } +.t_area { + overflow: hidden; + padding: 0 16px 0 0; + margin: 0; + box-sizing: border-box; +} + +.t_area .e_text { + margin: 0 0 0 10px; + min-height: 88px; + max-width: 100%; + min-width: 100%; +} + .options { text-align: left; float: left;