Merge pull request #1051 from boxbilling/metadesc

Added meta description support on announcement pages
This commit is contained in:
Yağızhan authored and GitHub committed 2021-10-02 22:49:07 +03:00
commit 0f9763374a
10 files changed
+78 -33

No files matched your search

+24 -16
View File
@@ -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);
+17
View File
@@ -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,
@@ -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 %}
<ul>
<li class="firstB"><a href="{{ '/'|alink }}">{% trans 'Home' %}</a></li>
<li><a href="{{ 'news'|alink }}">{% trans 'News' %}</a></li>
<li class="lastB">{{ post.title}}</li>
<li class="lastB">{{post.title}}</li>
</ul>
{% endblock %}
@@ -15,13 +15,15 @@
<div class="widget">
<div class="head">
<h5>{{ post.title}}</h5>
<h5>{{post.title}}</h5>
</div>
<div class="help">
<h5>Edit post</h5>
<p>If the text is very long you can use <strong>&lt;!--more--&gt;</strong> 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.</p>
</div>
<form method="post" action="{{ 'api/admin/news/update'|link }}" class="mainForm save api-form" data-api-msg="{% trans 'Post updated' %}">
<fieldset>
<p>If the text is very long you can use <strong>&lt;!--more--&gt;</strong> 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.</p>
<br/>
<textarea name="content" cols="5" rows="20" class="bb-textarea">{{ post.content }}</textarea>
<input type="submit" value="{% trans 'Update' %}" class="greyishBtn submitForm" />
<input type="hidden" name="id" value="{{ post.id }}"/>
@@ -32,7 +34,7 @@
<div class="widget">
<div class="head">
<h5>{{ post.title}}</h5>
<h5>{{post.title}}</h5>
</div>
<form method="post" action="{{ 'api/admin/news/update'|link }}" class="mainForm save api-form" data-api-msg="{% trans 'Post updated' %}">
@@ -45,6 +47,14 @@
<div class="fix"></div>
</div>
<div class="rowElem noborder">
<label>{% trans 'Meta description' %}</label>
<div class="formRight">
<textarea name="description" rows="5" cols="40" placeholder="{{ post.description }}">{{ post.description }}</textarea>
</div>
<div class="fix"></div>
</div>
<div class="rowElem">
<label>{% trans 'Slug' %}</label>
<div class="formRight">
@@ -91,4 +101,4 @@
</div>
{% endblock %}
{% block head %}{{ mf.bb_editor('.bb-textarea') }}{% endblock %}
{% block head %}{{ mf.bb_editor('.bb-textarea') }}{% endblock %}
@@ -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 %}
<li><a href="{{ 'news' | link}}">{% trans 'Blog' %}</a><span class="divider">/</span></li>
<li class="active">{{post.title}}</li>
@@ -10,6 +12,7 @@
<meta property="og:title" content="{{ post.title }}" />
<meta property="og:type" content="article" />
<meta property="og:description" content="{{ post.description }}" />
<meta property="og:url" content="{{ guest.system_current_url }}" />
<meta property="og:image" content="{{post.image}}" />
<meta property="article:author" content="{{ post.author.name }}" />
@@ -130,4 +130,4 @@
{% else %}
<!-- No WYSIWYG, no fancy stuff. Enable the WYSIWYG extension for a better management experience. -->
{% endif %}
{% endmacro %}
{% endmacro %}
@@ -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 %}
<meta property="og:title" content="{{ post.title }}" />
<meta property="og:type" content="article" />
<meta property="og:description" content="{{ post.description }}" />
<meta property="og:url" content="{{ guest.system_current_url }}" />
<meta property="og:image" content="{{post.image}}" />
<meta property="article:author" content="{{ post.author.name }}" />
@@ -43,11 +45,9 @@
<!-- Post Content -->
<p>
{{ post.content|bbmd }}
{{ post.content | bbmd }}
{# if post.tags %}Tags: {{ post.tags|join(', ') }}{% endif #}
</p>
<p class="lead">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?</p>
<p>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.</p>
<hr>
@@ -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 %}
<meta property="og:title" content="{{ post.title }}" />
<meta property="og:description" content="{{ post.description }}" />
<meta property="og:type" content="article" />
<meta property="og:url" content="{{ guest.system_current_url }}" />
<meta property="og:image" content="{{post.image}}" />
+4
View File
@@ -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);
+4 -4
View File
@@ -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;
+1
View File
@@ -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',