Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening DOM on discussion pageload to find images #4186

Closed
linc opened this issue Jul 12, 2016 · 2 comments
Closed

Opening DOM on discussion pageload to find images #4186

linc opened this issue Jul 12, 2016 · 2 comments

Comments

@linc
Copy link
Contributor

linc commented Jul 12, 2016

DiscussionController::index() has this gem:

        include_once(PATH_LIBRARY.'/vendors/simplehtmldom/simple_html_dom.php');
        if ($PageNumber == 1) {
            $this->description(sliceParagraph(Gdn_Format::plainText($this->Discussion->Body, $this->Discussion->Format), 160));
            // Add images to head for open graph
            $Dom = str_get_html(Gdn_Format::to($this->Discussion->Body, $this->Discussion->Format));
        } else {
            $this->Data['Title'] .= sprintf(t(' - Page %s'), PageNumber($this->Offset, $Limit));

            $FirstComment = $this->data('Comments')->firstRow();
            $FirstBody = val('Body', $FirstComment);
            $FirstFormat = val('Format', $FirstComment);
            $this->description(sliceParagraph(Gdn_Format::plainText($FirstBody, $FirstFormat), 160));
            // Add images to head for open graph
            $Dom = str_get_html(Gdn_Format::to($FirstBody, $FirstFormat));
        }

        if ($Dom) {
            foreach ($Dom->find('img') as $img) {
                if (isset($img->src)) {
                    $this->image($img->src);
                }
            }
        }

So we're opening the DOM on EVERY load to find images in the OP. Presumably it'd make a helluva lot more sense to store this open graph image information as a separate DB field to avoid doing this. I'd suggest the existing Gdn_Discussion.Attributes.

@DaazKu
Copy link
Contributor

DaazKu commented Jul 12, 2016

Do not forget that "storing" means "caching" here.
The new attribute's field should be deleted on edit so that it can be updated.

@linc
Copy link
Contributor Author

linc commented Dec 26, 2017

We removed simplehtmldom.

@linc linc closed this as completed Dec 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants