From 8b728425bf3eec7b806ea70ae20450e58b3910d5 Mon Sep 17 00:00:00 2001 From: "Mark (ilosuna)" Date: Sat, 12 Apr 2014 16:56:32 +0200 Subject: [PATCH] Add WYSIWYG editor, minor code improvements --- cms/config/definitions.conf.php | 20 ++++++++ cms/data/content.sqlite | Bin 393216 -> 393216 bytes cms/data/entries.sqlite | Bin 19456 -> 19456 bytes cms/data/userdata.sqlite | Bin 4096 -> 4096 bytes cms/includes/classes/Comment.class.php | 20 ++++++-- cms/includes/page_types/commentable_page.php | 4 +- cms/includes/settings.inc.php | 8 ++-- cms/includes/users.inc.php | 3 +- cms/index.php | 12 ++--- cms/lang/bulgarian.admin.lang.php | 4 +- cms/lang/english.admin.lang.php | 4 +- cms/lang/german.admin.lang.php | 4 +- cms/lang/russian.admin.lang.php | 4 +- cms/lang/spanish.admin.lang.php | 4 +- cms/templates/admin/main.tpl | 13 +++-- cms/templates/admin/subtemplates/edit.inc.tpl | 45 +++++++++--------- .../admin/subtemplates/settings.inc.tpl | 2 - cms/templates/default.tpl | 6 +-- index.php | 12 ++--- static/css/style_admin.css | 2 + static/css/wysiwyg.css | 1 + static/js/admin_backend.js | 5 ++ static/js/wysiwyg_init.js | 14 ++++++ 23 files changed, 117 insertions(+), 70 deletions(-) create mode 100644 cms/config/definitions.conf.php create mode 100644 static/css/wysiwyg.css create mode 100644 static/js/wysiwyg_init.js diff --git a/cms/config/definitions.conf.php b/cms/config/definitions.conf.php new file mode 100644 index 0000000..c9a96bd --- /dev/null +++ b/cms/config/definitions.conf.php @@ -0,0 +1,20 @@ + diff --git a/cms/data/content.sqlite b/cms/data/content.sqlite index 6ddaf8fe945ba94d0e0cd84f08186cd01cabd055..d8faf9f9f9e9e7c004a4c0ba3f6990ce54046dde 100644 GIT binary patch delta 1108 zcmY+DYiJx*6vyw(*|bTT?PRmfnl!s9F|m)N+0G`L*b*zmfVC2AsaVtxo$TW#J7jlf zJ2TsP&+I}W+JH3B=0foSO7YPWU82s1QY7R{RS1fL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8Rok_3f&6MO|&y?~xRB zb+i7li+`u|Zuin})E?;sl|P9yiV@QPvKm&|8B@M-{Kk&?z5S~7wt3$oey?{jw3VUb1?%U3J#nHMh-+rePJzoonShGOVt{hWS6D{Dv2YSUU+{YBkXx77>khPtLQ&L_HRUv%Da zB<+%OM;%g0Yf;%&@@>`SE}T~&F`sw}CI_+wj^&w3mM>PbMTGcbg_TN!DHuqtAyHxl zKAoJQQ<)^4Nv39!sZ=sOkGBE0xh@QunHYyK>Mg&;`?B(XZ0 z%g_gBVJe&#cp33Bvr^^rvPX|TFbzZP234^V%)m%ks;~tll>~(jr(rCd6H&I17pvTO zPMS5MB#g#czJOE@u!u?mhk`@ir#1?sYAQZ$z+l8|5RrW%o{X{qMy0DNSR+2BtsW1*!jpuLy$73!Vcrc-Mx3 z{=PV*!mA}g79{2oscg>k<*p596Ma6F~Y-`(XuJ;%e==zS6tyyXL=qtl2o$<^J@He}WD?|Ho41SubMjm@wroD*iixX8lvz c-Fx4EKe>7SbyvRaAMa^4HYj&|&wnfOFYB*(aR2}S diff --git a/cms/data/entries.sqlite b/cms/data/entries.sqlite index 645c5e88e7d6703feae243141c2d92bda034041d..698744c938f95fd58c1f4258bcf5318af8de4e6a 100644 GIT binary patch delta 75 zcmZpe!Pqc^ae@>R3+F@`Cm^{oVKp=RX~x-%C5#@M1vwNMCmXX$Fse^%RAbX;U_8zM cVofa6VP#=pV9=P@sIvJpD-Ro^)gm4T0NisD-2eap delta 56 zcmZpe!Pqc^ae@>R^WTXwPC#;F!fIyr%giNANlZzb1vwNMCmXX$Oq|fos4&q{X7guO L9yUg!MLZ4w1%nY1 diff --git a/cms/data/userdata.sqlite b/cms/data/userdata.sqlite index 5baaef391d709b9b91890d0eba7e7611d3592ae3..fa94fc96dac58aefa154383255a33c0fcde4489a 100644 GIT binary patch delta 45 zcmZorXi%6S#l&nnQN{^KZcJFs&0NN8xLJ@zfqAkXzc-`H#72k7yZD`%gPj=w3405d delta 48 zcmZorXi%6S#l$paqKp%e+?cSMo4JzNaI+wb0`p`&es2~A1_sB8jkc3_@jEkf<}&~Q DJHHGy diff --git a/cms/includes/classes/Comment.class.php b/cms/includes/classes/Comment.class.php index 770fcde..fede2d1 100644 --- a/cms/includes/classes/Comment.class.php +++ b/cms/includes/classes/Comment.class.php @@ -2,7 +2,7 @@ class Comment { public $comments_per_page = 10; - public $comment_order = 1; + public $comment_order = 0; public $name_maxlength = 100; public $email_hp_maxlength = 100; public $word_maxlength = 50; @@ -81,8 +81,10 @@ class Comment if($this->total_comments > 0) { + if($this->comment_order) $order = 'DESC'; + else $order = 'ASC'; if($rss) $dbr = Database::$entries->prepare("SELECT id, time, name, email_hp, comment, ip FROM ".Database::$db_settings['comment_table']." WHERE type=:type AND comment_id=:comment_id AND comment!='' ORDER BY id ASC LIMIT ".$this->comments_per_page); - else $dbr = Database::$entries->prepare("SELECT id, time, name, email_hp, comment, ip FROM ".Database::$db_settings['comment_table']." WHERE type=:type AND comment_id=:comment_id AND comment!='' ORDER BY id DESC LIMIT ".$this->comments_per_page." OFFSET ".(intval($this->current_page)-1)*$this->comments_per_page); + else $dbr = Database::$entries->prepare("SELECT id, time, name, email_hp, comment, ip FROM ".Database::$db_settings['comment_table']." WHERE type=:type AND comment_id=:comment_id AND comment!='' ORDER BY id ".$order." LIMIT ".$this->comments_per_page." OFFSET ".(intval($this->current_page)-1)*$this->comments_per_page); $dbr->bindParam(':type', $this->type, PDO::PARAM_INT); $dbr->bindParam(':comment_id', $this->comment_id, PDO::PARAM_INT); $dbr->execute(); @@ -108,7 +110,8 @@ class Comment } } $comments[$i]['id'] = $data['id']; - $comments[$i]['nr'] = $this->total_comments + 1 - ($nr + ($this->current_page-1) * $this->comments_per_page); + if($this->comment_order) $comments[$i]['nr'] = $this->total_comments + 1 - ($nr + ($this->current_page-1) * $this->comments_per_page); + else $comments[$i]['nr'] = ($nr + ($this->current_page-1) * $this->comments_per_page); $comments[$i]['name'] = htmlspecialchars($data['name']); $comments[$i]['time'] = $data['time']; #$comments[$i]['formated_time'] = format_time(TIME_FORMAT_FULL,$data['time']); @@ -123,7 +126,7 @@ class Comment } // end foreach // reverse array for ascending order: - if($this->comment_order == 1) $comments = array_reverse($comments); + #if($this->comment_order == 1) $comments = array_reverse($comments); $this->_localization->replacePlaceholder('total_comments', $this->total_comments, 'comments_pagination_info'); $this->_localization->replacePlaceholder('current_page', $this->current_page, 'comments_pagination_info'); @@ -172,7 +175,7 @@ class Comment } // end foreach // reverse array for ascending order: - if($this->comment_order == 1 && isset($pingbacks)) $pingbacks = array_reverse($pingbacks); + #if($this->comment_order == 1 && isset($pingbacks)) $pingbacks = array_reverse($pingbacks); #$this->form_values = $this->get_form_values(); @@ -233,6 +236,13 @@ class Comment $mail->set_charset(CHARSET); $mail->send($this->settings['email'], $this->settings['email'], Localization::$lang['comment_notification_subject'], Localization::$lang['comment_notification_message'], $this->settings['mail_parameter']); } + + // count comments: + $this->total_comments = $this->count_comments($this->comment_id); + + $this->total_pages = ceil($this->total_comments / $this->comments_per_page); + if($this->current_page>$this->total_pages) $this->current_page = $this->total_pages; + return true; } } diff --git a/cms/includes/page_types/commentable_page.php b/cms/includes/page_types/commentable_page.php index 096082f..887574e 100644 --- a/cms/includes/page_types/commentable_page.php +++ b/cms/includes/page_types/commentable_page.php @@ -100,7 +100,9 @@ elseif(isset($_POST['save'])) $cache->clear(PAGE); $cache->clearRelated(PAGE); } - header('Location: '.BASE_URL.PAGE.'#comments'); + if(!$settings['comment_order'] && $comment->total_pages>1) $comment_page_addition = ','.$comment->total_pages; + else $comment_page_addition = ''; + header('Location: '.BASE_URL.PAGE.$comment_page_addition.'#comments'); exit; } } diff --git a/cms/includes/settings.inc.php b/cms/includes/settings.inc.php index a0d3dd3..a5d8715 100644 --- a/cms/includes/settings.inc.php +++ b/cms/includes/settings.inc.php @@ -96,10 +96,10 @@ if(isset($_SESSION[$settings['session_prefix'].'user_type']) && $_SESSION[$setti $template->assign('subtemplate', 'settings.inc.tpl'); // WYSIWYG editor available? - if(file_exists(BASE_PATH.WYSIWYG_EDITOR)) - { - $template->assign('wysiwyg_editor_available', true); - } + #if(file_exists(BASE_PATH.WYSIWYG_EDITOR)) + # { + # $template->assign('wysiwyg_editor_available', true); + # } break; case 'advanced_settings'; diff --git a/cms/includes/users.inc.php b/cms/includes/users.inc.php index 4f72410..c7ee898 100644 --- a/cms/includes/users.inc.php +++ b/cms/includes/users.inc.php @@ -33,8 +33,9 @@ if(isset($_SESSION[$settings['session_prefix'].'user_id'])) if(empty($errors)) { $pw_hash = generate_pw_hash($_POST['pw']); - $dbr = Database::$userdata->prepare("INSERT INTO ".Database::$db_settings['userdata_table']." (name,type,pw,last_login) VALUES (:name,0,:pw,0)"); + $dbr = Database::$userdata->prepare("INSERT INTO ".Database::$db_settings['userdata_table']." (name, type, wysiwyg, pw, last_login) VALUES (:name, 0, :wysiwyg, :pw, 0)"); $dbr->bindValue(':name', trim($_POST['name']), PDO::PARAM_STR); + $dbr->bindParam(':wysiwyg', $settings['wysiwyg_editor'], PDO::PARAM_INT); $dbr->bindParam(':pw', $pw_hash, PDO::PARAM_STR); $dbr->execute(); header('Location: '.BASE_URL.ADMIN_DIR.'index.php?mode=users'); diff --git a/cms/index.php b/cms/index.php index ba4e909..ea33e6b 100644 --- a/cms/index.php +++ b/cms/index.php @@ -46,17 +46,13 @@ try if(is_access_denied()) raise_error('403'); } - define('VALID_URL_CHARACTERS', '/^[a-zA-Z0-9._\-\/]+$/'); define('ADMIN_DIR', 'cms/'); - define('MEDIA_DIR', 'static/media/'); define('CACHE_DIR', 'cms/cache/'); - define('IMAGE_IDENTIFIER', 'photo'); - define('BASE_URL',get_base_url(ADMIN_DIR)); + define('BASE_URL',get_base_url('cms/')); define('STATIC_URL', BASE_URL.'static/'); - define('BASE_PATH',get_base_path(ADMIN_DIR)); - - define('WYSIWYG_EDITOR', 'cms/modules/tiny_mce/tiny_mce.js'); - define('WYSIWYG_EDITOR_INIT', 'js/wysiwyg_init.js'); + define('BASE_PATH',get_base_path('cms/')); + + require(BASE_PATH.'cms/config/definitions.conf.php'); if($settings['caching']) { diff --git a/cms/lang/bulgarian.admin.lang.php b/cms/lang/bulgarian.admin.lang.php index 1936fc7..bca0b94 100644 --- a/cms/lang/bulgarian.admin.lang.php +++ b/cms/lang/bulgarian.admin.lang.php @@ -58,8 +58,8 @@ $lang['login_password'] = 'Парола:'; $lang['login_submit'] = 'Вход'; # content -$lang['edit_wysiwyg_mode'] = 'WYSIWYG режим'; -$lang['edit_non_wysiwyg_mode'] = 'Text режим'; +$lang['enable_wysiwyg_editor'] = 'WYSIWYG режим'; +$lang['disable_wysiwyg_editor'] = 'Text режим'; $lang['change_edit_mode_notice'] = 'Внимание! Настоящите промени няма да бъдат съхранени при смяна на режима на редактиране!'; $lang['values_comma_separated'] = 'разделени със запетая'; $lang['page_overview'] = 'Страници'; diff --git a/cms/lang/english.admin.lang.php b/cms/lang/english.admin.lang.php index 52c7bf0..e21fad4 100644 --- a/cms/lang/english.admin.lang.php +++ b/cms/lang/english.admin.lang.php @@ -53,8 +53,8 @@ $lang['login_password'] = 'Password:'; $lang['login_submit'] = 'Log in'; # content -$lang['edit_wysiwyg_mode'] = 'WYSIWYG mode'; -$lang['edit_non_wysiwyg_mode'] = 'Text mode'; +$lang['enable_wysiwyg_editor'] = 'WYSIWYG editor'; +$lang['disable_wysiwyg_editor'] = 'Source code'; $lang['change_edit_mode_notice'] = 'Caution! Current changes will not be saved when switching edit mode!'; $lang['values_comma_separated'] = 'several values separated by comma'; $lang['page_overview'] = 'Page overview'; diff --git a/cms/lang/german.admin.lang.php b/cms/lang/german.admin.lang.php index 2af636f..f2dd68b 100644 --- a/cms/lang/german.admin.lang.php +++ b/cms/lang/german.admin.lang.php @@ -53,8 +53,8 @@ $lang['login_password'] = 'Passwort:'; $lang['login_submit'] = 'Login'; # content -$lang['edit_wysiwyg_mode'] = 'WYSIWYG mode'; -$lang['edit_non_wysiwyg_mode'] = 'Textmodus'; +$lang['enable_wysiwyg_editor'] = 'WYSIWYG-Editor'; +$lang['disable_wysiwyg_editor'] = 'Quelltext'; $lang['change_edit_mode_notice'] = 'Achtung! Aktuelle Änderungen werden beim Umschalten nicht übernommen!'; $lang['values_comma_separated'] = 'mehrere Werte durch Komma getrennt'; $lang['page_overview'] = 'Seitenübersicht'; diff --git a/cms/lang/russian.admin.lang.php b/cms/lang/russian.admin.lang.php index bbbd77d..adf29d2 100644 --- a/cms/lang/russian.admin.lang.php +++ b/cms/lang/russian.admin.lang.php @@ -57,8 +57,8 @@ $lang['login_password'] = 'Пароль:'; $lang['login_submit'] = 'Войти'; # content -$lang['edit_wysiwyg_mode'] = 'WYSIWYG'; -$lang['edit_non_wysiwyg_mode'] = 'Text'; +$lang['enable_wysiwyg_editor'] = 'WYSIWYG'; +$lang['disable_wysiwyg_editor'] = 'Text'; $lang['change_edit_mode_notice'] = 'Внимание! При смене режима все несохранённые изменения будут потеряны!'; $lang['values_comma_separated'] = 'Перечислите значения через запятую'; $lang['page_overview'] = 'Страницы'; diff --git a/cms/lang/spanish.admin.lang.php b/cms/lang/spanish.admin.lang.php index 7136a70..60385f9 100644 --- a/cms/lang/spanish.admin.lang.php +++ b/cms/lang/spanish.admin.lang.php @@ -55,8 +55,8 @@ $lang['login_password'] = 'Contraseña:'; $lang['login_submit'] = 'iniciar sesión'; # content -$lang['edit_wysiwyg_mode'] = 'Modo WYSIWYG'; -$lang['edit_non_wysiwyg_mode'] = 'Modo texto'; +$lang['enable_wysiwyg_editor'] = 'Modo WYSIWYG'; +$lang['disable_wysiwyg_editor'] = 'Modo texto'; $lang['change_edit_mode_notice'] = '¡Atención! ¡Los cambios actuales no se grabarán al cambiar el modo de edición!'; $lang['values_comma_separated'] = 'varios valores separados por comas'; $lang['page_overview'] = 'Relación de páginas'; diff --git a/cms/templates/admin/main.tpl b/cms/templates/admin/main.tpl index 76d0f16..d3a46f3 100644 --- a/cms/templates/admin/main.tpl +++ b/cms/templates/admin/main.tpl @@ -5,7 +5,7 @@ <?php echo $settings['website_title']; ?> - <?php echo $lang['administration']; if(isset($subtitle)) echo ' - ' . $subtitle; ?> - + @@ -43,13 +43,16 @@ - - - + + + + + + + - diff --git a/cms/templates/admin/subtemplates/edit.inc.tpl b/cms/templates/admin/subtemplates/edit.inc.tpl index 73956bb..882970f 100644 --- a/cms/templates/admin/subtemplates/edit.inc.tpl +++ b/cms/templates/admin/subtemplates/edit.inc.tpl @@ -19,7 +19,7 @@

-
+
@@ -64,29 +64,28 @@
- - - - -
adline" value="" /> + + + + -
- -
- + + + + +
+
- - - + + +
- +
@@ -216,7 +215,7 @@
+
@@ -407,7 +406,7 @@
- +
@@ -442,10 +441,12 @@ checked="checked" />

- -
+ + +
+ diff --git a/cms/templates/admin/subtemplates/settings.inc.tpl b/cms/templates/admin/subtemplates/settings.inc.tpl index 62077f5..093e89a 100644 --- a/cms/templates/admin/subtemplates/settings.inc.tpl +++ b/cms/templates/admin/subtemplates/settings.inc.tpl @@ -85,11 +85,9 @@
- -
diff --git a/cms/templates/default.tpl b/cms/templates/default.tpl index 34b59a1..00131d1 100644 --- a/cms/templates/default.tpl +++ b/cms/templates/default.tpl @@ -7,7 +7,7 @@ - + @@ -98,8 +98,8 @@
- - + + diff --git a/index.php b/index.php index 567fc79..f2cc4a1 100644 --- a/index.php +++ b/index.php @@ -91,15 +91,9 @@ try define('BASE_URL', get_base_url()); define('STATIC_URL', BASE_URL.'static/'); define('BASE_PATH', get_base_path()); - define('MEDIA_DIR', 'static/media/'); - define('SMILIES_DIR', 'static/media/smilies/'); - define('IMAGE_IDENTIFIER', 'photo'); - define('CATEGORY_IDENTIFIER', 'category:'); - define('AMPERSAND_REPLACEMENT', ':AMP:'); - - define('WYSIWYG_EDITOR', 'cms/modules/tiny_mce/tiny_mce.js'); - define('WYSIWYG_EDITOR_INIT', 'js/wysiwyg_init_frontend.js'); - + + require(BASE_PATH.'cms/config/definitions.conf.php'); + if($settings['content_functions']==1) require(BASE_PATH.'cms/includes/functions.content.inc.php'); require('./cms/includes/classes/Template.class.php'); diff --git a/static/css/style_admin.css b/static/css/style_admin.css index f6c5508..e013451 100644 --- a/static/css/style_admin.css +++ b/static/css/style_admin.css @@ -11,6 +11,8 @@ body { padding-top:70px; padding-bottom:50px; } .nav-tabs li.active a:hover { background:#fafafa; } .tab-content { padding:20px; margin-bottom:20px; border:1px solid #ddd; border-top:none; background:#fafafa; } +#wysiwyg-toggle { } + .label-block { font-size:14px; line-height:20px; display:block; } .form-control-inline { display:inline; width:inherit; } diff --git a/static/css/wysiwyg.css b/static/css/wysiwyg.css new file mode 100644 index 0000000..8e903cd --- /dev/null +++ b/static/css/wysiwyg.css @@ -0,0 +1 @@ +p { font-size:13px; line-height:150%; } diff --git a/static/js/admin_backend.js b/static/js/admin_backend.js index 4dd26e9..d46eb1d 100644 --- a/static/js/admin_backend.js +++ b/static/js/admin_backend.js @@ -16,6 +16,11 @@ obj.scrollTop = scrollTop; $(function() { +$("a[data-confirm-link]").click(function(e) { e.preventDefault(); + message = $(this).data('confirm-link') ? decodeURIComponent($(this).data('confirm-link')) : 'Are you sure?'; + var confirmed = confirm(decodeURIComponent(message)); + if(confirmed) window.location.href = $(this).attr("href"); }); + $("a[data-delete-confirm]").click(function(e) { e.preventDefault(); message = $(this).data('delete-confirm') ? decodeURIComponent($(this).data('delete-confirm')) : 'Delete?'; $(this).parents("tr").addClass('danger'); diff --git a/static/js/wysiwyg_init.js b/static/js/wysiwyg_init.js new file mode 100644 index 0000000..7e80cbd --- /dev/null +++ b/static/js/wysiwyg_init.js @@ -0,0 +1,14 @@ +tinymce.init({ + selector: "#content", + menubar:false, + statusbar: false, + entity_encoding : "raw", + plugins: [ + "advlist autolink lists link image anchor code" + ], + target_list:false, + + toolbar: "undo redo | styleselect | bold italic | bullist numlist | link unlink | image | code", + content_css : "../static/css/wysiwyg.css" + +});