We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Wow. I was expecting to have to redo it a few times before it worked, since it was completely off the top of my head and untested. I guess we got lucky.

    Did I mention that I accept donations at http://bobsguides.com/support-this-site.html wink



    ------------------------------------------------------------------------------------------
    PLEASE, PLEASE specify the version of MODX you are using.
    MODX info for everyone: http://bobsguides.com/modx.html
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 16899
      • 284 Posts
      LOL!!! smiley Yes, it was a bit of lucky and experience!!! wink
        • 16899
        • 284 Posts
        Hello again!!!
        I was testing the split snippet and happened a little thing :

        Output Code

        <h3>Partner Name Here</h3>
        <h6>Partner Area/Business</h6>
        <p>Lorem ipsum dolor sit amet, consectetur... <!-- No End Tag -->
        					<div class="toggle">
        						<h3>Read More</h3>
        						<div>
        				<!-- No Start Tag -->		ing elit. Nullam laoreet enim luctus sapien ornare at viverra ante hendrerit. Aliquam erat volutpat. Proin vel tellus neque, a convallis nisi. Suspendisse et ante at ligula luctus rhoncus. Sed condimentum magna id dui congue eget placerat elit fermentum. Praesent facilisis dui congue lectus iaculis sit amet tristique nibh molestie.</p>
        
        <p>Aliquam erat volutpat. Mauris tristique euismod auctor. Etiam venenatis volutpat mauris quis suscipit. Etiam risus dui, pulvinar egestas commodo fermentum, ornare eget quam. Donec sit amet justo eros, sit amet adipiscing tortor. </p>
        						</div>
        					</div>


        To solve this end/close tag bug i did this on the snippet (close p tag after hellip) :

            $output = substr($input, 0, strrpos(substr($input, 0, $options), ' ')).'...</p>';


        and this on the output Tpl:

        			<div class="partners-wrapper [[+_last:isnot=``:then=`last`:else=``]]">
        				<div class="grid-2 first"><img src="[[+partner-logotype]]" alt="[[+partner-name]]" class="fx3"/></div>
        				<div class="grid-7 last">
        					<h3>[[+partner-name]]</h3>
        					<h6>[[+area]]</h6>
        					[[+description:split=`50`]]
        					<div class="toggle">
        						<h3>Read More</h3>
        						<div>
        <!- And open the p tag here -->	<p>... [[+extra]]
        						</div>
        					</div>
        				</div>
                            
        			<div class="clear"> </div>
        			</div>


        Ok, it solves the problem, but is this an ideal solution?

        Many thanks in advance!! [ed. note: legues last edited this post 14 years, 4 months ago.]
          • 3749
          • 24,544 Posts
          I'm afraid not. The missing closing tag could be for bold, italics, or the end of a list, among other things. That would mess up the rest of your code.

          If you look at the code of the ellipsis filter in the current version of Revo, it has a solution using regular expression matching.

          Here is a version of it modified to set the placeholder for you. The problem is that the hidden part will then have a closing tag for an element that is not open. In addition, in the hidden div you may have list items that are no longer in the list, bold and italic text that's not bold or italic, etc. It will usually work, but it won't be valid HTML. It would be possible to remove the orphaned closing tags, but that wouldn't solve the problem of the misformatting in the hidden div.

          <?php
          $limit= intval($m_val) ? intval($m_val) : 100;
                                      $pad = $this->modx->getOption('ellipsis_filter_pad',null,'…');
          
                                      /* ensure that filter correctly counts special chars */
                                      $output = html_entity_decode($output,ENT_COMPAT,$encoding);
                                      $len = $usemb ? mb_strlen($output) : strlen($output);
                                      if ($limit > $len) $limit = $len;
                                      $breakpoint = $usemb ? mb_strpos($output," ",$limit,$encoding) : strpos($output, " ", $limit);
                                      if (false !== $breakpoint) {
                                          if ($breakpoint < $len - 1) {
                                              $partial = $usemb ? mb_substr($output, 0, $breakpoint,$encoding) : substr($output, 0, $breakpoint);
                                              $output = $partial . $pad;
                                          }
                                      }
          
                                      $opened = array();
                                      if (preg_match_all("/<(\/?[a-z]+)>?/i", $output, $matches)) {
                                          foreach ($matches[1] as $tag) {
                                              if (preg_match("/^[a-z]+$/i", $tag, $regs)) {
                                                  $strLower = $usemb ? mb_strtolower($regs[0],$encoding) : strtolower($regs[0]);
                                                  if ($strLower != 'br' || $strLower != 'hr') {
                                                      $opened[] = $regs[0];
                                                  }
                                              } elseif (preg_match("/^\/([a-z]+)$/i", $tag, $regs)) {
                                                  unset($opened[array_pop(array_keys($opened, $regs[1]))]);
                                              }
                                          }
                                      }
                                      if ($opened) {
                                          $tagstoclose = array_reverse($opened);
                                          foreach ($tagstoclose as $tag) $output .= "</$tag>";
                                      }
          /* I added this part */
                $modx->setPlaceholder('extra', substr($input, strlen($output)));
          




          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 16899
            • 284 Posts
            Thanks again for the feedback! Much appreciated!! smiley I think this could be a nice point to develop a MODX plugin based on this situation, don´t you think? wink
              • 3749
              • 24,544 Posts
              The problem is that there's no robust solution to the problem other than extending the visible "teaser" part until all tags are closed, which would be slow and could make it very long, potentially messing up the page layout.

              My inelegant method would be to just make sure the summary (introtext) field for every document was filled and contained valid HTML and then use that for the teaser. Then *replace* it (and the "see more" message) with the entire page content using JS.


              ------------------------------------------------------------------------------------------
              PLEASE, PLEASE specify the version of MODX you are using.
              MODX info for everyone: http://bobsguides.com/modx.html
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting