Is myBB parsing &hash=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#31
(2015-10-17, 02:03 AM)Destroy666 Wrote:
(2015-10-16, 09:10 PM)SentoWeb Wrote: Please note that doing so will result in a big performance issue.

A big performance issue caused by running one additional regex in the already messy parser...? It shouldn't matter unless you're on a very very slow, most likely free hosting and your forum is on the verge of exceeding limits.

Anyways, it'd be better if you discussed this in the Plugin Development forum, not in a rejected bug report which has been proven invalid: http://community.mybb.com/thread-185099-...pid1193073

From what I understand the OP wants to load URLs without actually wrapping them in an IMG tag which would mean that this is executed every time the post is parsed (so basically a MyCode which looks for links). I argued for a PHP solution which just wraps the url in an image tag after the content is posted which is way more efficient and also results in more efficient MyCode parsing. This solution can be used by a forum of any size. The "it doesn't hurt me now" argument is a bad excuse for creating future problems.

(2015-10-16, 09:44 PM)Thomas131 Wrote: I would say that my Regex is about as cpu/memory-using as the default URL-Tag-Parser. (Maybe even less because I used ?: a lot of time to not save match-patterns) I really don't think that he will run into performance issues. There is definitly a reason, why MyCodes are Regexes ...

Yes, never argued with that. The solution you provided is the easiest to set up and it is as efficient as anything else using regex. I suggested a different approach because long-term the OP will want more efficient way of doing this, and perhaps even check if the URL actually returns image headers and whatnot.
[Image: axolis.png]

Project, Portfolio and Product management for freelancers.
Reply
#32
(2015-10-16, 08:10 PM)SentoWeb Wrote: Its a bit more complicated but still possible. Basically you want to make use of the content creation hooks and parse the content. Something like this is a good starting point:

<?php
$content = 'My content http://site.com/image.png?querystring=12 yes, this contains an image';

$imageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'bmp'];

foreach (explode(" ", $content) as $word) {
    // strlen($word) is there so that we don't even bother checking short strings
    if (strlen($word) >= 12 && filter_var($word, FILTER_VALIDATE_URL)) {
        foreach ($imageExtensions as $extension) {
            $pos = strpos(strtolower($word), ".".$extension);
            if ($pos) {
                $url = substr($word, $pos+strlen($extension)+1, 1);
                if ($url == '' || $url = '?') {
                    str_replace($word, '[img]'.$word.'[/img]', $content);
                }
            }
        }
    }
}

Make sure to define image extensions in lowercase.

Its never too late to learn BUT if you can get one working sample and where i would call it, i be happy to give it a shot Toungue

By the way,  why wrap it in a IMG tag when you cannot use PHP there?
Reply
#33
Moved this to plugin development - makes more sense here
Reply
#34
(2015-10-17, 09:07 AM)expat Wrote:
(2015-10-16, 08:10 PM)SentoWeb Wrote: Its a bit more complicated but still possible. Basically you want to make use of the content creation hooks and parse the content. Something like this is a good starting point:

<?php
$content = 'My content http://site.com/image.png?querystring=12 yes, this contains an image';

$imageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'bmp'];

foreach (explode(" ", $content) as $word) {
    // strlen($word) is there so that we don't even bother checking short strings
    if (strlen($word) >= 12 && filter_var($word, FILTER_VALIDATE_URL)) {
        foreach ($imageExtensions as $extension) {
            $pos = strpos(strtolower($word), ".".$extension);
            if ($pos) {
                $url = substr($word, $pos+strlen($extension)+1, 1);
                if ($url == '' || $url = '?') {
                    str_replace($word, '[img]'.$word.'[/img]', $content);
                }
            }
        }
    }
}

Make sure to define image extensions in lowercase.

Its never too late to learn BUT if you can get one working sample and where i would call it, i be happy to give it a shot Toungue

By the way,  why wrap it in a IMG tag when you cannot use PHP there?

The idea is to use PHP to wrap it in IMG tags after the content was posted. You can do additional checks there, like check the headers and make sure that this is indeed an image file. You could additionally put a class there to give images a different treatment. The idea is to identify images after the content was posted instead of running a regex (mycode) every time the post content is parsed. If you want a solution which is quick to set up the regex one posted by Thomas131 is the way to go though.
[Image: axolis.png]

Project, Portfolio and Product management for freelancers.
Reply
#35
I will say goodbye from this thread. I have posted a solution, but I don't have additional time.

God Bless you!
Thomas131
Reply
#36
thanks all for your help, some new concepts I still grasping with.

DIDnt someone say the posted content is cached? So when you post something, regex runs thru the post and its cached....

How can i then change it on the fly and cache again? Very nice concept

PS. I think I know what you are trying to do, is changing the [ URL ] into the [ IMAGE ] ?? Question is why? when you can skip the clunky REGEX and display the image anyway you wished, since you already located the image link
Reply
#37
I'm just locating image-URLs and displaying this images with my Regex. No Link to [img]link[/img] converting.
Reply
#38
(2015-10-17, 02:11 PM)Thomas131 Wrote: I'm just locating image-URLs and displaying this images with my Regex. No Link to [img]link[/img] converting.

yeah, i mean the other chap.

If i went your way I would prefer to hack the parser and do an IF clause there and output the image as i wished, rather call it back to myCode again, coz you are search for URL and Image separately twice, rather in the same search
Reply
#39
Parsed posts are not cached in 1.x. They are in 2.0.
Reply
#40
(2015-10-17, 08:00 AM)SentoWeb Wrote: From what I understand the OP wants to load URLs without actually wrapping them in an IMG tag which would mean that this is executed every time the post is parsed (so basically a MyCode which looks for links). I argued for a PHP solution which just wraps the url in an image tag after the content is posted which is way more efficient and also results in more efficient MyCode parsing. This solution can be used by a forum of any size. The "it doesn't hurt me now" argument is a bad excuse for creating future problems.

http://bradt.ca/blog/stop-avoiding-regul...s-damn-it/

Using several string functions won't make it much faster, if any. Try it yourself and run both code samples 100 times. There won't be any significiant difference.
Reply


Forum Jump:


Users browsing this thread: 13 Guest(s)