Skip to content

Commit

Permalink
Bugs, textarea and new show more
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k1o committed Sep 23, 2017
1 parent 4b3f10e commit 8dc8b75
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 17 deletions.
7 changes: 4 additions & 3 deletions app/post.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<code'.($m[1] ? ' class="'.$m[1].'"' : '').'>'.htmlentities($m[2]).'</code>';
$c = preg_replace_callback('/\[code(?:=([^\[]+))?\]((.|\s)+?)(?:(?=\[\/code\]))\[\/code\]/m', function($m){
return '<code'.($m[1] ? ' class="'.$m[1].'"' : '').'>'.htmlentities(trim($m[2])).'</code>';
}, $c);
} else {
// Links
Expand All @@ -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" => '',
Expand Down Expand Up @@ -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){
Expand Down
4 changes: 2 additions & 2 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +24,6 @@ pass = demo

[system]
system_name = blog
version = 1.03
version = 1.04
debug = true
logs = false
10 changes: 7 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}

$hours = '';
for($h=0;$h<=60;$h++){
for($h=0;$h<=24;$h++){
$hours .= sprintf('<option value="%d">%02d</option>', $h, $h);
}

Expand Down Expand Up @@ -153,7 +153,10 @@
<div class="modal-body drop_space">
<div class="e_drag"><span><?php echo __("Drag photos here"); ?></span></div>
<img src="<?php echo Config::get("pic_small"); ?>" width="40" height="40" class="e_profile">
<div class="e_text" contenteditable="true" placeholder="<?php echo __("What\'s on your mind?"); ?>"></div>
<!--<div class="e_text" contenteditable="true"></div>-->
<div class="t_area">
<textarea class="e_text" placeholder="<?php echo __("What's on your mind?"); ?>"></textarea>
</div>
</div>
<input type="hidden" class="i_content_type">
<input type="hidden" class="i_content">
Expand Down Expand Up @@ -272,7 +275,7 @@
<div class="cover">
<?php echo $header; ?>
<div class="overlay"></div>
<img src="<?php echo Config::get("cover"); ?>">
<?php echo (Config::get_safe("cover", false) ? '<img src="'.Config::get("cover").'">' : (empty($header) ? '<div style="padding-bottom: 37%;"></div>' : '')); ?>
<div class="profile">
<img src="<?php echo Config::get("pic_big"); ?>">
</div>
Expand All @@ -296,6 +299,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<!--<script src="static/scripts/jquery.min.js"></script>-->
<script>$["\x61\x6A\x61\x78\x53\x65\x74\x75\x70"]({"\x68\x65\x61\x64\x65\x72\x73":{"\x43\x73\x72\x66-\x54\x6F\x6B\x65\x6E":"<?php echo $_SESSION['token'];?>"}});</script>
<script src="static/scripts/autosize.js"></script>
<?php echo Config::get("highlight") ? '<script src="static/scripts/highlight.js"></script><script>hljs.initHighlightingOnLoad();</script>' : ''; ?>
<script src="static/scripts/app.js?v=<?php echo Config::get("version"); ?>"></script>
</body>
Expand Down
30 changes: 25 additions & 5 deletions static/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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"){
Expand Down Expand Up @@ -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(),
Expand Down
Loading

0 comments on commit 8dc8b75

Please sign in to comment.