From 7300327ae444d4a53c32d029b94245ff389fe5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Fri, 1 Oct 2021 23:03:25 +0300 Subject: [PATCH 1/6] Adding meta description support --- src/bb-modules/News/Api/Admin.php | 40 +++++++++++-------- src/bb-modules/News/Service.php | 17 ++++++++ .../News/html_admin/mod_news_post.phtml | 16 ++++++-- .../News/html_client/mod_news_post.phtml | 5 ++- .../admin_default/html/macro_functions.phtml | 2 +- .../bootstrap/html/mod_news_post.phtml | 6 +-- src/bb-update.php | 4 ++ 7 files changed, 65 insertions(+), 25 deletions(-) diff --git a/src/bb-modules/News/Api/Admin.php b/src/bb-modules/News/Api/Admin.php index ee4739a86..1cc740bc0 100644 --- a/src/bb-modules/News/Api/Admin.php +++ b/src/bb-modules/News/Api/Admin.php @@ -75,6 +75,7 @@ class Admin extends \Api_Abstract * @param int $id - news item ID * * @optional string $title - news item title + * @optional string $description - news item description * @optional string $slug - news item slug * @optional string $content - news item content * @optional string $status - news item status @@ -83,19 +84,24 @@ class Admin extends \Api_Abstract */ public function update($data) { + $service = $this->getService(); $required = array( - 'id' => 'Post id not passed', + 'id' => 'Post ID not passed', ); $this->di['validator']->checkRequiredParamsForArray($required, $data); $model = $this->di['db']->getExistingModelById('Post', $data['id'], 'News item not found'); - $model->content = $this->di['array_get']($data, 'content', $model->content); - $model->title = $this->di['array_get']($data, 'title', $model->title); - $model->slug = $this->di['array_get']($data, 'slug', $model->slug); - $model->image = $this->di['array_get']($data, 'image', $model->image); - $model->section = $this->di['array_get']($data, 'section', $model->section); - $model->status = $this->di['array_get']($data, 'status', $model->status); + $description = $this->di['array_get']($data, 'description', $model->description); + if (empty($description)) $description = $service->generateDescriptionFromContent($this->di['array_get']($data, 'content', $model->content)); + + $model->content = $this->di['array_get']($data, 'content', $model->content); + $model->title = $this->di['array_get']($data, 'title', $model->title); + $model->description = $description; + $model->slug = $this->di['array_get']($data, 'slug', $model->slug); + $model->image = $this->di['array_get']($data, 'image', $model->image); + $model->section = $this->di['array_get']($data, 'section', $model->section); + $model->status = $this->di['array_get']($data, 'status', $model->status); $publish_at = $this->di['array_get']($data, 'publish_at', 0); if ($publish_at) { @@ -130,7 +136,7 @@ class Admin extends \Api_Abstract } /** - * Creat new news item. + * Create new news item. * * @param string $title - news item title * @@ -141,19 +147,21 @@ class Admin extends \Api_Abstract */ public function create($data) { + $service = $this->getService(); $required = array( 'title' => 'Post title not passed', ); $this->di['validator']->checkRequiredParamsForArray($required, $data); - $model = $this->di['db']->dispense('Post'); - $model->admin_id = $this->getIdentity()->id; - $model->title = $data['title']; - $model->slug = $this->di['tools']->slug($data['title']); - $model->status = $this->di['array_get']($data, 'status', NULL); - $model->content = $this->di['array_get']($data, 'content', NULL); - $model->created_at = date('Y-m-d H:i:s'); - $model->updated_at = date('Y-m-d H:i:s'); + $model = $this->di['db']->dispense('Post'); + $model->admin_id = $this->getIdentity()->id; + $model->title = $data['title']; + $model->description = null; + $model->slug = $this->di['tools']->slug($data['title']); + $model->status = $this->di['array_get']($data, 'status', NULL); + $model->content = $this->di['array_get']($data, 'content', NULL); + $model->created_at = date('Y-m-d H:i:s'); + $model->updated_at = date('Y-m-d H:i:s'); $this->di['db']->store($model); $this->di['logger']->info('Created news item #%s', $model->id); diff --git a/src/bb-modules/News/Service.php b/src/bb-modules/News/Service.php index 8a7d39104..1d72db98b 100644 --- a/src/bb-modules/News/Service.php +++ b/src/bb-modules/News/Service.php @@ -35,6 +35,22 @@ class Service return $this->di['db']->findOne('Post', 'slug = :slug AND status = "active"', array('slug'=>$slug)); } + /** + * Generate a placeholder meta description from given string. + * + * @param string $content - string to generate description from + * + * @return string + */ + public function generateDescriptionFromContent($content) + { + $desc = utf8_encode($content); + $desc = strip_tags($desc); + $desc = str_replace(array("\n", "\r", "\t"), ' ', $desc); + $desc = substr($desc, 0, 125); + return $desc; + } + public function getSearchQuery($data) { $sql='SELECT * @@ -71,6 +87,7 @@ class Service $data = array( 'id' => $row->id, 'title' => $row->title, + 'description' => $row->description, 'content' => $row->content, 'slug' => $row->slug, 'image' => $row->image, diff --git a/src/bb-modules/News/html_admin/mod_news_post.phtml b/src/bb-modules/News/html_admin/mod_news_post.phtml index c31373db6..e42536a5b 100644 --- a/src/bb-modules/News/html_admin/mod_news_post.phtml +++ b/src/bb-modules/News/html_admin/mod_news_post.phtml @@ -1,13 +1,13 @@ {% extends "layout_default.phtml" %} {% import "macro_functions.phtml" as mf %} -{% block meta_title %}{{ post.title}}{% endblock %} +{% block meta_title %}{{post.title}}{% endblock %} {% set active_menu = 'support' %} {% block breadcrumbs %} {% endblock %} @@ -15,7 +15,7 @@
-
{{ post.title}}
+
{{post.title}}
@@ -32,7 +32,7 @@
-
{{ post.title}}
+
{{post.title}}
@@ -45,6 +45,14 @@
+
+ +
+ +
+
+
+
diff --git a/src/bb-modules/News/html_client/mod_news_post.phtml b/src/bb-modules/News/html_client/mod_news_post.phtml index fca2db60f..d98e160a0 100644 --- a/src/bb-modules/News/html_client/mod_news_post.phtml +++ b/src/bb-modules/News/html_client/mod_news_post.phtml @@ -1,6 +1,8 @@ {% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %} -{% block meta_title %}{{post.title}}{% endblock %} +{% block meta_title %}{{ post.title }}{% endblock %} +{% block meta_description %}{{ post.description }}{% endblock %} + {% block breadcrumb %}
  • {% trans 'Blog' %}/
  • {{post.title}}
  • @@ -10,6 +12,7 @@ + diff --git a/src/bb-themes/admin_default/html/macro_functions.phtml b/src/bb-themes/admin_default/html/macro_functions.phtml index d1eaead2e..14a280bcf 100644 --- a/src/bb-themes/admin_default/html/macro_functions.phtml +++ b/src/bb-themes/admin_default/html/macro_functions.phtml @@ -130,4 +130,4 @@ {% else %} {% endif %} -{% endmacro %} +{% endmacro %} \ No newline at end of file diff --git a/src/bb-themes/bootstrap/html/mod_news_post.phtml b/src/bb-themes/bootstrap/html/mod_news_post.phtml index eceabcac4..fcf7d993c 100755 --- a/src/bb-themes/bootstrap/html/mod_news_post.phtml +++ b/src/bb-themes/bootstrap/html/mod_news_post.phtml @@ -1,11 +1,13 @@ {% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %} {% block meta_title %}{{post.title}}{% endblock %} +{% block meta_description %}{{ post.description }}{% endblock %} {% block opengraph %} + @@ -43,11 +45,9 @@

    - {{ post.content|bbmd }} + {{ post.content | bbmd }} {# if post.tags %}Tags: {{ post.tags|join(', ') }}{% endif #}

    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ducimus, vero, obcaecati, aut, error quam sapiente nemo saepe quibusdam sit excepturi nam quia corporis eligendi eos magni recusandae laborum minus inventore?

    -

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut, tenetur natus doloremque laborum quos iste ipsum rerum obcaecati impedit odit illo dolorum ab tempora nihil dicta earum fugiat. Temporibus, voluptatibus.


    diff --git a/src/bb-update.php b/src/bb-update.php index 6dee7caa0..f6cef95d6 100644 --- a/src/bb-update.php +++ b/src/bb-update.php @@ -18,6 +18,10 @@ class BBPatch_24 extends BBPatchAbstract { public function patch() { + // Initializing meta description support for announcements + $q = "ALTER TABLE `post` ADD `description` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL AFTER `title`;" + $this->execSql($q); + // Clearing leftovers from deleted payment adapters $q = "DELETE FROM `pay_gateway` WHERE `gateway` = 'AlertPay' OR `gateway` = 'WebToPay' OR `gateway` = 'Payza' OR `gateway` = 'SinglePay'"; $this->execSql($q); From dbc01401610a47afe471421b0bfbcc8ca555dfd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 2 Oct 2021 10:27:28 +0300 Subject: [PATCH 2/6] Fixed bad syntax --- src/bb-update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bb-update.php b/src/bb-update.php index f6cef95d6..6db05b28a 100644 --- a/src/bb-update.php +++ b/src/bb-update.php @@ -19,7 +19,7 @@ class BBPatch_24 extends BBPatchAbstract public function patch() { // Initializing meta description support for announcements - $q = "ALTER TABLE `post` ADD `description` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL AFTER `title`;" + $q = "ALTER TABLE `post` ADD `description` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL AFTER `title`"; $this->execSql($q); // Clearing leftovers from deleted payment adapters From 593faadec798fe30accf8907a76b2cb48ccb7662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 2 Oct 2021 10:34:07 +0300 Subject: [PATCH 3/6] Changed database structure --- src/install/sql/content.sql | 8 ++++---- src/install/sql/structure.sql | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/install/sql/content.sql b/src/install/sql/content.sql index db1a0d856..3ab0893dd 100644 --- a/src/install/sql/content.sql +++ b/src/install/sql/content.sql @@ -245,11 +245,11 @@ UNLOCK TABLES; LOCK TABLES `post` WRITE; /*!40000 ALTER TABLE `post` DISABLE KEYS */; -INSERT INTO `post` (`id`, `admin_id`, `title`, `content`, `slug`, `status`, `image`, `section`, `publish_at`, `published_at`, `expires_at`, `created_at`, `updated_at`) +INSERT INTO `post` (`id`, `admin_id`, `title`, `description`, `content`, `slug`, `status`, `image`, `section`, `publish_at`, `published_at`, `expires_at`, `created_at`, `updated_at`) VALUES - (1,1,'BoxBilling is the most affordable Billing Application Ever!','Just in case you weren''t already aware, BoxBilling is the most affordable client management application ever!\n\nTo learn more about it You can always visit [www.boxbilling.com](http://www.boxbilling.com/)\n','boxbilling-is-affordable-billing-system','active',NULL,NULL,NULL,NULL,NULL,'2020-01-01 12:00:00','2020-01-01 12:00:00'), - (2,1,'Check out great features of BoxBilling','* Supports automated billing, invoicing, product provisioning\n* Automatically create accounts as soon as the payment is received, suspend when account becomes overdue, terminate when a specified amount of time passes.\n* Boxbilling is perfectly created to sell shared and reseller hosting accounts, software licenses and downloadable products.\n* Integrated helpdesk, knowledgebase, news and announcements system.\n','great-features-of-boxbilling','active',NULL,NULL,NULL,NULL,NULL,'2020-01-01 12:00:00','2020-01-01 12:00:00'), - (3,1,'BoxBilling is customizable','* You can create your own simple or advanced hooks on BoxBilling events. For example, send notification via sms when new client signs up.\n* Create custom theme for your client interface\n','boxbilling-is-customizable','active',NULL,NULL,NULL,NULL,NULL,'2020-01-01 12:00:00','2020-01-01 12:00:00'); + (1,1,'BoxBilling is the most affordable Billing Application Ever!','Just in case you weren''t already aware, BoxBilling is the most affordable client management application ever!','Just in case you weren''t already aware, BoxBilling is the most affordable client management application ever!\n\nTo learn more about it You can always visit [www.boxbilling.com](http://www.boxbilling.com/)\n','boxbilling-is-affordable-billing-system','active',NULL,NULL,NULL,NULL,NULL,'2020-01-01 12:00:00','2020-01-01 12:00:00'), + (2,1,'Check out great features of BoxBilling','BoxBilling supports automated billing, invoicing, product provisioning', '* Supports automated billing, invoicing, product provisioning\n* Automatically create accounts as soon as the payment is received, suspend when account becomes overdue, terminate when a specified amount of time passes.\n* Boxbilling is perfectly created to sell shared and reseller hosting accounts, software licenses and downloadable products.\n* Integrated helpdesk, knowledgebase, news and announcements system.\n','great-features-of-boxbilling','active',NULL,NULL,NULL,NULL,NULL,'2020-01-01 12:00:00','2020-01-01 12:00:00'), + (3,1,'BoxBilling is customizable','You can create your own simple or advanced hooks on BoxBilling events.','* You can create your own simple or advanced hooks on BoxBilling events. For example, send notification via sms when new client signs up.\n* Create custom theme for your client interface\n','boxbilling-is-customizable','active',NULL,NULL,NULL,NULL,NULL,'2020-01-01 12:00:00','2020-01-01 12:00:00'); /*!40000 ALTER TABLE `post` ENABLE KEYS */; UNLOCK TABLES; diff --git a/src/install/sql/structure.sql b/src/install/sql/structure.sql index 95b102249..9a7211e79 100644 --- a/src/install/sql/structure.sql +++ b/src/install/sql/structure.sql @@ -775,6 +775,7 @@ CREATE TABLE `post` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `admin_id` bigint(20) DEFAULT NULL, `title` varchar(255) DEFAULT NULL, + `description` text DEFAULT NULL, `content` text, `slug` varchar(255) DEFAULT NULL, `status` varchar(30) DEFAULT 'draft' COMMENT 'active, draft', From 6237e59a6325727f89cf191955220aec9baeac36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 2 Oct 2021 10:53:09 +0300 Subject: [PATCH 4/6] Fix theme files --- src/bb-themes/boxbilling/html/mod_news_post.phtml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bb-themes/boxbilling/html/mod_news_post.phtml b/src/bb-themes/boxbilling/html/mod_news_post.phtml index 7eda6690d..6031c0ac3 100644 --- a/src/bb-themes/boxbilling/html/mod_news_post.phtml +++ b/src/bb-themes/boxbilling/html/mod_news_post.phtml @@ -1,10 +1,12 @@ {% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %} {% block meta_title %}{{post.title}}{% endblock %} +{% block meta_description %}{{post.description}}{% endblock %} {% block opengraph %} + From cb0e4b372d69efc400c0cfb4ef545a8c6661c95b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 2 Oct 2021 11:33:23 +0300 Subject: [PATCH 5/6] Visual adjustment --- src/bb-modules/News/html_admin/mod_news_post.phtml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bb-modules/News/html_admin/mod_news_post.phtml b/src/bb-modules/News/html_admin/mod_news_post.phtml index e42536a5b..4ff07983c 100644 --- a/src/bb-modules/News/html_admin/mod_news_post.phtml +++ b/src/bb-modules/News/html_admin/mod_news_post.phtml @@ -17,11 +17,13 @@
    {{post.title}}
    - +
    +
    Edit post
    +

    If the text is very long you can use <!--more--> tag. Inserting this tag within the post will create and excerpt of text (before the tag) to be displayed in posts list. Users will be able to see whole content when they click on "Read more" button.

    +
    +
    -

    If the text is very long you can use <!--more--> tag. Inserting this tag within the post will create and excerpt of text (before the tag) to be displayed in posts list. Users will be able to see whole content when they click on "Read more" button.

    -
    From 45bf0f880b19b713f74c20189adb5c4e59d459c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 2 Oct 2021 21:57:04 +0300 Subject: [PATCH 6/6] Clarifying --- src/bb-modules/News/html_admin/mod_news_post.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bb-modules/News/html_admin/mod_news_post.phtml b/src/bb-modules/News/html_admin/mod_news_post.phtml index 4ff07983c..b2c088649 100644 --- a/src/bb-modules/News/html_admin/mod_news_post.phtml +++ b/src/bb-modules/News/html_admin/mod_news_post.phtml @@ -48,7 +48,7 @@
    - +
    @@ -101,4 +101,4 @@
    {% endblock %} -{% block head %}{{ mf.bb_editor('.bb-textarea') }}{% endblock %} \ No newline at end of file +{% block head %}{{ mf.bb_editor('.bb-textarea') }}{% endblock %}