Skip to content

Commit

Permalink
v3.9.0
Browse files Browse the repository at this point in the history
Medium style image zoom
  • Loading branch information
dimobelov authored Jul 31, 2019
1 parent 0d16c37 commit b5861a2
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 6 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ BlThemes - Themes for [Bludit](https://github.com/bludit/bludit) CMS version 3+

## Changelog

v3.9.0

* Added Medium style Image Zoom to Article images. [Demo](https://blthemes.pp.ua/blekathlon/medium-style-zoom)
* Search results are cached for one hour only.
* Downloads moved to [Gumroad](https://blthemes.pp.ua/blekathlon/blekathlon-info).
* Fixed issues with [search](https://github.com/blthemes/Blekathlon/issues/8).

v3.8.1

* IMPORTANT: Due to some user complaints, the use of CDN for images and image resizing has been disabled. If you want to use it again in `init.php` change this line:
Expand Down
2 changes: 1 addition & 1 deletion css/style.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/bundle.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"author": "BlThemes",
"email": "",
"website": "https://blthemes.pp.ua",
"version": "3.8.1",
"releaseDate": "2019-02-27",
"version": "3.9.0",
"releaseDate": "2019-07-31",
"license": "MIT",
"compatible": "3.0",
"compatible": "3.9",
"notes": ""
}
2 changes: 1 addition & 1 deletion php/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
</div>
</footer>
<script>
var uploadsFolder = '<?php echo HTML_PATH_UPLOADS; ?>';
var uploadsFolder = '<?php echo HTML_PATH_UPLOADS; ?>', siteRoot = '<?php echo rtrim($site->url(), '/') . '/'; //site url with trailing slash ?>';
</script>
237 changes: 237 additions & 0 deletions php/lib/helper.php.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
<?php
class Helper
{
private $useCDN = false;

function __construct($useCDN=false)
{
$this->useCDN = $useCDN;
}

public function cdn_that_image($image, $width)
{
if( ! $this->useCDN) return $image;
if ( 0 === strpos( $image, '//' ) ) {
$image = 'https:' . $image;
}
$image_url_parts = @parse_url( $image );

if ( ! is_array( $image_url_parts ) || empty( $image_url_parts['host'] ) || empty( $image_url_parts['path'] ) ) return $image;
if( strpos( $image_url_parts['host'], 'localhost') !== false || strpos( $image_url_parts['host'], '127.0.0.1') !== false) return $image;

$image_host_path = $image_url_parts['host'] . $image_url_parts['path'];

$cdn_url = "https://i.meln.top/";
$cdn_url .= 'width/' . $width . '/n/'. $image_host_path; //resize image, keep proportions

return $cdn_url;
}

public function cdn_cover_image($image, $width, $height)
{
if( ! $this->useCDN) return $image;
if ( 0 === strpos( $image, '//' ) ) {
$image = 'https:' . $image;
}
$image_url_parts = @parse_url( $image );

if ( !is_array( $image_url_parts ) || empty( $image_url_parts['host'] ) || empty( $image_url_parts['path'] ) ) return $image;
if( strpos( $image_url_parts['host'], 'localhost') !== false || strpos( $image_url_parts['host'], '127.0.0.1') !== false) return $image;

$image_host_path = $image_url_parts['host'] . $image_url_parts['path'];

$cdn_url = "https://i.meln.top";
$cdn_url .= '/cover/' . $width .'x'.$height. '/n/'. $image_host_path; //resize image, keep proportions

return $cdn_url;
}

public static function get_thumb()
{
global $page;
$first_img = $page->thumbCoverImage();
if (empty($first_img)) {
preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $page->content(), $matches);
if (isset($matches[1][0])) {
$first_img = $matches[1][0];
}
}
return $first_img;
}


public function previousKey()
{
global $page;
global $pages;
if($page->isStatic()) return false;
$currentKey = $page->key();
$keys = $pages->getPublishedDB(true);
$position = array_search($currentKey, $keys) + 1;
if (isset($keys[$position])) {
return $keys[$position];
}
return false;
}

public function nextKey()
{
global $page;
global $pages;
if($page->isStatic()) return false;
$currentKey = $page->key();
$keys = $pages->getPublishedDB(true);
$position = array_search($currentKey, $keys) - 1;
if (isset($keys[$position])) {
return $keys[$position];
}
return false;
}

public function head_description()
{
global $site;
global $WHERE_AM_I;
global $page;
global $url;

$description = $site->description();

if ($WHERE_AM_I == 'page') {
$description = $page->description();
if (empty($description)) {
$cont = str_replace('<', ' <', $page->content(false));
$cont = html_entity_decode($cont);
$description = Text::truncate(Text::removeHTMLTags($cont), 250);
$description = trim($description);
}
} elseif ($WHERE_AM_I == 'category') {
try {
$categoryKey = $url->slug();
$category = new Category($categoryKey);
$description = $category->description();
}
catch (Exception $e) {
// description from the site
}
}
return '<meta name="description" content="' . $description . '">' . PHP_EOL;
}

public function description()
{
global $site;
global $WHERE_AM_I;
global $url;

$description = $site->description();

if ($WHERE_AM_I == 'category') {
try {
$categoryKey = $url->slug();
$category = new Category($categoryKey);
$description = $category->description();
}
catch (Exception $e) {
// description from the site
}
}
return $description;
}

public function slogan()
{
global $site;
global $WHERE_AM_I;
global $url;
$slogan = $site->slogan();
if ($WHERE_AM_I == 'category') {
try {
$categoryKey = $url->slug();
$category = new Category($categoryKey);
$slogan = $category->name();
}
catch (Exception $e) {
// slogan from the site
}
}
return $slogan;
}


public static function content2excerpt($cont)
{
$cont = str_replace('<', ' <', $cont);
$cont = html_entity_decode($cont);
$description = Text::truncate(Text::removeHTMLTags($cont), 250);
$description = trim( $description);
return $description;
}

/**
* Summary of getRelated
* @param mixed $max
* @param mixed $similar
* @return array[]|string
*/
public static function getRelated($max = 3, $similar = true)
{
global $WHERE_AM_I;
global $page;
if ($WHERE_AM_I == 'page') {
$currentKey = $page->key();
if (!$page->category()) return false;
$currentCategory = getCategory($page->categoryKey());
if (count($currentCategory->pages()) >= $max + 1) {
$allCatPages = $currentCategory->pages();
//remove curent page
$allCatPages = array_diff($allCatPages, array($currentKey));

//sort rest pages by similarity O(N**3)
if ($similar) {
usort($allCatPages, function ($a, $b) use ($currentKey) {
similar_text($currentKey, $a, $percentA);
similar_text($currentKey, $b, $percentB);
return $percentA === $percentB ? 0 : ($percentA > $percentB ? -1 : 1);
});
}
//or just randomize
else {
shuffle($allCatPages);
}
$related = array();
for ($i = 0; $i < $max; $i++) {
$item = new Page($allCatPages[$i]);
if ($item->published()) {
$related[] = array(
'title' => $item->title(),
'link' => $item->permalink(),
'image' => $item->coverImage(),
'thumb' => $item->thumbCoverImage()
);
}
}
return $related;
}

}
return false;
}

/**
* Limit text to number of words
* @param string $text The input string
* @param int $limit Number of words to return
* @param string $ending Text to add at end
* @return string
*/
public function limit_text_words($text, $limit, $ending = '...') {
if (str_word_count($text, 0) > $limit) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$limit]) . $ending;
}
return $text;
}

}

0 comments on commit b5861a2

Please sign in to comment.