Skip to content

Commit

Permalink
correct cropping description
Browse files Browse the repository at this point in the history
  • Loading branch information
mediafoks committed Oct 6, 2024
1 parent bf43194 commit 255e7da
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ksopengraph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<copyright>Copyright (C) 2024 Sergey Kuznetsov</copyright>
<license>MIT</license>
<authorEmail>mediafoks@google.com</authorEmail>
<version>1.1.7</version>
<version>1.2.0</version>
<description>PLG_CONTENT_KS_OPEN_GRAPH_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Content\KsOpenGraph</namespace>
<files>
Expand Down
2 changes: 1 addition & 1 deletion services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @return void
*
* @since 1.1.7
* @since 1.2.0
*/
public function register(Container $container)
{
Expand Down
20 changes: 18 additions & 2 deletions src/Extension/KsOpenGraph.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @version 1.1.4
* @version 1.2.0
* @package ksopengraph (plugin)
* @author Sergey Kuznetsov - mediafoks@google.com
* @copyright Copyright (c) 2024 Sergey Kuznetsov
Expand Down Expand Up @@ -81,6 +81,22 @@ public function setImage($image)
return $linkImg;
}

public function catStr($str, $length = 300)
{
$str_clean = trim(strip_tags($str)); // удаляем HTML символы и пробелы в начале и конце строки

if (mb_strlen($str_clean, 'utf-8') <= $length) {
return $str_clean;
} else {
$str_cat = mb_substr($str_clean, 0, $length, 'utf-8'); // обрезаем строку до нужной длины
$space_pos = mb_strrpos($str_cat, ' ', 0, 'utf-8'); // находим позицию последнего пробела
$str_cat_space = mb_substr($str_cat, 0, $space_pos, 'utf-8'); // обрезаем строку до пробела
$new_str = $str_cat_space . '...'; // добавляем троеточие в конец строки

return $new_str;
}
}

public function renderTag($name, $value, $type = 1)
{
$app = $this->getApplication();
Expand Down Expand Up @@ -210,7 +226,7 @@ public function onContentAfterDisplay(AfterDisplayEvent $event): void

$this->renderTag('og:site_name', $config->get('sitename'), $type);
$this->renderTag('og:title', $thisTitle, $type);
$this->renderTag('og:description', mb_strimwidth(strip_tags($thisDescription), 0, 300, "..."), $type);
$this->renderTag('og:description', $this->catStr($thisDescription), $type);
$this->renderTag('og:url', Uri::current(), $type);
$this->renderTag('og:image', $this->setImage($this->realCleanImageURL($thisImage)), $type);
$this->renderTag('og:type', $thisOgType, $type);
Expand Down
4 changes: 2 additions & 2 deletions update.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<element>ksopengraph</element>
<type>plugin</type>
<folder>content</folder>
<version>1.1.7</version>
<version>1.2.0</version>
<downloads>
<downloadurl type="full" format="zip">https://github.com/mediafoks/plg_content_ksopengraph/archive/refs/tags/v1.1.7.zip</downloadurl>
<downloadurl type="full" format="zip">https://github.com/mediafoks/plg_content_ksopengraph/archive/refs/tags/v1.2.0.zip</downloadurl>
</downloads>
<tags>
<tag>stable</tag>
Expand Down

0 comments on commit 255e7da

Please sign in to comment.