Skip to content

Commit f3a35c2

Browse files
committed
Broken URLs on profiles/channels without post id
1 parent ceee9fb commit f3a35c2

File tree

9 files changed

+64
-48
lines changed

9 files changed

+64
-48
lines changed

BbCode/Helper/Telegram.php

+29-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
<?php
2+
3+
/**
4+
* This file is a part of add-on "[Telegram] BB Code - Media Post".
5+
*
6+
* Developed by CrazyHackGUT aka Kruzya.
7+
* (c) 2018-2021
8+
*/
9+
210
namespace Kruzya\TelegramBbMedia\BbCode\Helper;
3-
// Kruzya/Telegram/BbCode/Helper
4-
5-
class Telegram {
6-
public static function matchCallback($url, $matchedId, \XF\Entity\BbCodeMediaSite $site, $siteId) {
7-
if (preg_match('#t\.me\/(?P<channel>.{1,})\/(?P<postId>.{1,})#si', $url, $matches))
8-
$matchedId = $matches['channel'] . '/' . $matches['postId'];
9-
return $matchedId;
10-
}
11+
12+
13+
use XF\Entity\BbCodeMediaSite;
14+
15+
class Telegram
16+
{
17+
/**
18+
* @param string $url
19+
* @param string $matchedId
20+
* @param BbCodeMediaSite $site
21+
* @param string $siteId
22+
* @return false|string
23+
*/
24+
public static function onMatch($url, $matchedId, BbCodeMediaSite $site, $siteId)
25+
{
26+
$matchedId = false;
27+
if (preg_match('#t\.me\/(?P<channel>.{1,})\/(?P<postId>.{1,})#si', $url, $matches))
28+
$matchedId = $matches['channel'] . '/' . $matches['postId'];
29+
30+
return $matchedId;
31+
}
1132
}

_files/js/Kruzya/TelegramBbMedia/post-widget.js

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* This file is a part of add-on "[Telegram] BB Code - Media Post".
3+
*
4+
* Developed by CrazyHackGUT aka Kruzya.
5+
* (c) 2018-2021
6+
*/
7+
8+
window.addEventListener('message', function(message)
9+
{
10+
if (message.origin !== 'https://t.me') {
11+
return;
12+
}
13+
14+
let iframes = [].slice.call(document.getElementsByTagName('iframe'))
15+
.filter(iframe => iframe.contentWindow === message.source);
16+
17+
let data = JSON.parse(message.data);
18+
if (data.event !== 'resize') {
19+
return;
20+
}
21+
22+
if (iframes.length < 1) {
23+
return;
24+
}
25+
26+
iframes[0].style.height = data.height + 'px';
27+
}, false);
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"telegram.json": {
3-
"hash": "7497fd286a7013c1b4444458fc4dfeb4"
3+
"hash": "33117d2b21a350747241cac78a90fc99"
44
}
55
}

_output/bb_code_media_sites/telegram.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"match_urls": "t.me/{$id}",
55
"match_is_regex": false,
66
"match_callback_class": "Kruzya\\TelegramBbMedia\\BbCode\\Helper\\Telegram",
7-
"match_callback_method": "matchCallback",
8-
"embed_html": "<iframe src=\"https://t.me/{$id}?embed=1\"\n scrolling=\"no\"\n style=\"border: medium none; overflow: hidden; min-width: 320px; height: 0px;\"\n width=\"100%\"\n height=\"\"\n frameborder=\"0\">\n</iframe>",
7+
"match_callback_method": "onMatch",
8+
"embed_html": "<iframe src=\"https://t.me/{$id}?embed=1\" scrolling=\"no\" width=\"100%\" height=\"\" frameborder=\"0\"\n\t\tstyle=\"border: medium none; overflow: hidden; min-width: 320px; height: 0px;\">\n</iframe>\n\n<xf:js src=\"kruzya/telegram-bb-media/post-widget.js\"\n\t min=\"1\" addon=\"Kruzya/TelegramBbMedia\" />",
99
"embed_html_callback_class": "",
1010
"embed_html_callback_method": "",
1111
"oembed_enabled": false,

_output/template_modifications/_metadata.json

-5
This file was deleted.

_output/template_modifications/public/kruzya_telegram_script_media.json

-9
This file was deleted.

addon.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"legacy_addon_id": "",
33
"title": "[Telegram] BB Code - Media Post",
44
"description": "Adds a new Media Post Type for embedding posts from Telegram Chats/Channels",
5-
"version_id": 1000070,
6-
"version_string": "1.0.0",
5+
"version_id": 1000170,
6+
"version_string": "1.0.1",
77
"dev": "CrazyHackGUT aka Kruzya",
88
"dev_url": "https://kruzya.me/",
99
"faq_url": "https://xenforo.info/resources/6733/field?field=faq",
1010
"support_url": "https://xenforo.info/resources/6733/",
1111
"extra_urls": [],
1212
"require": [],
1313
"icon": "fa-telegram"
14-
}
14+
}

build.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"additional_files": [
3-
"js/Kruzya/TelegramBbMedia/post-widget.js"
3+
"js/kruzya/telegram-bb-media/post-widget.js"
44
],
55
"minify": [
6-
"js/Kruzya/TelegramBbMedia/post-widget.js"
6+
"js/kruzya/telegram-bb-media/post-widget.js"
77
]
88
}

0 commit comments

Comments
 (0)