read_more fix

Gravatar xgenvn

  • Posts: 4
  • Topic Created: Thu Apr 5 11:11:47 2012 +0200
  • Topic Updated: Thu Apr 5 16:47:17 2012 +0200

I've experienced one error when using read_more modules on a quote feathers. It would just output:

Read more>> (((more

I was willing to take a quick look to the quote.twig and I saw that it was a little bit different with other feathers template.

<div class="source">${ ("— " ~ post.source_unfiltered) | markup_post_text(post) | markup_text(post) | read_more }</div>

After looking to the code, I changed it to:

<div class="source">${ post.source | read_more | add_dash}</div>

In the read_more module: read_more.php, add the following static function

``
static function add_dash($text) { return preg_replace("/(<p(\s+[^>]+)?>|^)/si", "\1— ", $text, 1); }

`` And you're now good to go. add_dash function is in the feather/quote.php. I just didnt know how to access it, so I just copy it to read_more function and set it to static function.

Gravatar PolarLava

  • Posts: 11
  • Created: Fri Apr 6 00:14:10 2012 +0200
  • Permalink: read_more fix

I'll have to give this a try. I've been battling this read more issue on and off for ages now. When I get a chance to try it I'll let you know how it worked out.

Gravatar xgenvn

  • Posts: 4
  • Created: Fri Apr 6 14:24:20 2012 +0200
  • Permalink: read_more fix

Hi PolarLava, I've seen you online on the IRC channel before. If you feel hard to fix, then here the package for you to override yours.

Attachments

Gravatar PolarLava

  • Posts: 11
  • Created: Sun Apr 8 19:11:28 2012 +0200
  • Permalink: read_more fix

Grabbed you fix, but then realized it doesn't address my problem anyway. Yours is related to using the Quote Feather. Mine is actually an issue that manifests itself in a similar manner [Read more>> (((more))) ], but is caused by HTML and entities in posts. Your fix actually incorporates part of my previous attempt at fixing this issue. If you diff against git you'll see your static method, but also my change:

  • preg_match_all("/e51b2b9a58824dd068d8777ec6e97e4d((((more(((.+)))?))))/", preg_replace("/<[^>]+>/", "", $text), $more, PREG_OFFSET_CAPTURE);
  • preg_match_all("/e51b2b9a58824dd068d8777ec6e97e4d((((more(((.+)))?))))/", preg_replace("/<[^>]+>/", "", html_entity_decode($text, ENT_QUOTES)), $more, PREG_OFFSET_CAPTURE);

Basically it decodes the entities, but I still seem to be having issues unfortunately. This seemed to solve a lot of my issues that were cause by my imported data that contains HTML & entities. But I'm currently having issues I believe related to Textile, although I'm not certain that's the cause. I had discussed this fairly extensively, but it was lost when the project/site changed hands as it was in the old Development discussion area. :(

I know the problem is still in that area because of what I'm seeing when I dump the $more variable:

Array ( [0] => Array ( [0] => Array ( [0] => e51b2b9a58824dd068d8777ec6e97e4d(((more))) [1] => 570 )

    )

[1] => Array
    (
        [0] => Array
            (
                [0] => (((more)))
                [1] => 602
            )

    )

[2] => Array
    (
        [0] => 
    )

[3] => Array
    (
        [0] => 
    )

)

(Somebody want to remind me what the format tag is for that and I'll fix it so it's readable. :)

You'll note that the difference in the replace offset is 32, the length of the hash, but it's not picking up the (((more))) which in turn gets dumped out as part of the display along with 18 characters of the "more" section. How much gets displayed depend on the text of the entry. It could be as little as something like "(", "(((mo", etc. Much like the last time I looked into this I find this implementation overly complex for what it does. I guess this is because it's replacing the actual Read More link at this point and not just the comment tag. That's easy and works fine if you edit the entry via Admin.

Gravatar PolarLava

  • Posts: 11
  • Created: Sun Apr 8 23:13:07 2012 +0200
  • Updated: Mon Apr 9 03:29:53 2012 +0200
  • Permalink: read_more fix

So stripping things down I believe I know what's happening. There are entities that aren't being translated because they aren't handled by html_entity_decode(). For example I stripped my test entry to simply read:

So it's <!--more--> And then the rest is here.

This strips the entry to only contain one entity, the single quote. But the single quote there really is a "close single quote", which can be either &rsquo; or &#8217; as it turns out in this case. The solution as I see it is to use the stupefyEntities() method from the SmartyPants module.

So I've figure out how to detect if that is there, but being I've never done anything that needed to call a module, at the moment I'm a bit stuck. I'm not sure how to call it yet, but I have gotten as far as finding it as an object in Modules::$instances. Continuing to pursue, but wanted to update before I need to stop and don't get the opportunity.

xgenvn, this would also handle your quote feather issue as it processes em-dash's as well.


So I've modified modules/smartypants/smartypants.php (see attached) to add aliases for "unmarkup_text" (what's needed here) and "unmarkup_title" (for consistency). These both call a new stupify() static function which in turn will initiate the stupefyEntities() method of SmartyPants. (I've worked with and contributed to this previously so I know this fairly well.) And if I dump Trigger::current() I can see that this appears to be setup correctly.

So now I'm down to "How do I call this function?" I've been mucking around in modules/read_more/read_more.php trying to figure out how to call this within read_more(). But digging around some more, I'm wondering this should be called from feathers/text.twig...if you can daisy chain calls. I'm out of time for today, but wondering if I can't do so here:

${ post.body | read_more("Read more…") }

Don't believe that would work. I still think it needs to be done inside that read_more() call. Help? :)

Attachments

Gravatar xgenvn

  • Posts: 4
  • Created: Mon Apr 9 18:41:13 2012 +0200
  • Permalink: read_more fix

I've read your long posts about this issue. I'm not really figured out this why such a #$% matter. I think using tag wisely will help decrease the error caused by the markup text. I mean, just use it when you finish a paragraph and make sure other nested tags are closed too. I dont use sophisticated content when using markdown/textile on the head-excerpt so it'll be fine for me. But it's kinda an immature plugin to handle complex context. I've investigated to some feathers tpl, post.body/description/etc was almost used html_entities_decode before using readmore function, which that means markup text has been already processed and ready to output. However, I'm using the markdown plugin to write post. Not so sure if it's different to yours (smartypant or textile). Otherwise, I think you can try using 2 static function (stupidify) directly in your feather tpl, and check your posts again, like so: <div class="source">${ ("&mdash; " ~ post.source_unfiltered) | stupidify(post) | read_more }</div>