Announcement

Collapse
No announcement yet.

Converting case-sensitive tags with Cleaner

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Converting case-sensitive tags with Cleaner

    I have these situations after import:

    <font color="0000ff">yadda yadda yadda ya</font>, and
    <font size="+2">yadda yadda yadda ya</font>,

    where both color and size end with the same </font>.

    How do I substitute </font> with either [ /SIZE ] or [ /COLOR ] in the correct context?

    The best idea I could come up with is both the /size /color vB tags in there together, and then find a way to strip out the surplus one later.....?

  • #2
    On line 98 of cleaner is this line :

    PHP Code:
    #$text = preg_replace('##siU', '', $text); 
    A commented out place holder for a regular expression.

    To match depending on context and content we'll have to use that to to get the cleaning done.

    For ease, we can replace that with two simple lines opposed to one complicated one for each case :

    PHP Code:
    $text preg_replace('#<font color="(.*)">(.*)</font>#siU''[COLOR="$1"]$2[/COLOR]'$text);
    $text preg_replace('#<font size="\+(.*)">(.*)</font>#siU''[SIZE="$1"]$2[/SIZE]'$text); 
    I wrote ImpEx.

    Blog | Me

    Comment


    • #3
      All the quote marks, 'singles' & "doubles", are driving my aging eyes to tears!

      Here is an example of a post that needs cleaning:
      Imported vB forum: http://www.mechmate.com/forums/showthread.php?t=254
      Old Discus forum: http://www.mechmate.com/Forum/show.cgi?tpc=15&post=1041#POST1041

      This is my work list of expressions that still need replacement:

      <font size="-2"> [ SIZE="1" ]
      <font size="-1"> [ SIZE="1" ]
      <font size="+1"> [ SIZE="4" ]
      <font size="+2"> [ SIZE="6" ]
      </font> [ /SIZE ]

      <font color="ff0000"> [ COLOR="Red" ]
      <font color="ffff00"> [ COLOR="Yellow" ]
      <font color="00aa00"> [ COLOR="green" ]
      <font color="ff6000"> [ COLOR="orange" ]
      <font color="00aaaa"> [ COLOR="Cyan" ]
      <font color="0000ff"> [ COLOR="Blue" ]
      <font color="aa00aa"> [ COLOR="purple" ]
      <font color="ffffff"> [ COLOR="White" ]
      <font color="c0c0c0"> [ COLOR="gray" ]
      </font> [ /COLOR ]

      Jerry, I suspect the single line approach will work okay for the colors, but that there would be a large size discrepancy because of the mismatched numbers used by Discus.

      If I get colors done first, then I can fight with sizes line by line . . . . . . .

      Thanks for all the help so far!

      Comment


      • #4
        Okay, have just done color cleaning with the single line
        $text = preg_replace('#<font color="(.*)">(.*)</font>#siU',.........


        That worked mostly okay, except where there were colors inside other colors. I will manually go and fix those rare cases.

        Now to tackle sizes . . . . . . . .

        Comment


        • #5
          Hold the horses!

          That color clean didn't work on all the threads???? (yes, I have cleared cache/alt-refeshed)

          Checked a couple of threads at random and they were all nice and pretty in their correct colours, but the thread I linked to above is unchanged??

          Earlier I had copied some posts from that thread to my test board, and there the cleaner worked fine. The same cleaner.php on the live board goes and cleans all (I think, still checking) the threads except the one I had tested? Now I am wondering if any other threads may have been missed......?

          Comment


          • #6
            Then the font code must be diffrent in the other threads, as cleaner does all the posts it can find. I would double check the code in the posts that it ignored.

            The codes in your second post should be fine.
            I wrote ImpEx.

            Blog | Me

            Comment


            • #7
              Jerry this one is very weird. You know how to get into my test board at:
              http://www.mechmate.com/testvb/showthread.php?t=639

              I pasted the same post (repeatedly off one clipboard) as edits over two old posts in that thread, and twice more as new posts. The cleaner only cleaned the first 2 out of the 4 posts. (those inserted via edits)

              I have double-checked. You can also see it at Post No. #3 in this thread.

              Comment


              • #8
                Are you rebuilding the post cache in the admincp ?
                I wrote ImpEx.

                Blog | Me

                Comment


                • #9
                  Have heard of it, but never looked for it, nor found it, nor touched it...promise!

                  Should I be?

                  Comment


                  • #10
                    Originally posted by Gerald_D View Post
                    Have heard of it, but never looked for it, nor found it, nor touched it...promise!

                    Should I be?
                    Yes !

                    Run cleaner, then update the post cache.

                    AdminCP > Maintenance > Update Counters > Rebuild Post Cache
                    I wrote ImpEx.

                    Blog | Me

                    Comment


                    • #11
                      Deleted cross-post

                      Comment


                      • #12
                        Well, that worked - but you knew it was going to!

                        Now for the last lap.....

                        These size expressions still need to be converted:

                        <font size="-2"> [ SIZE="1" ]
                        <font size="-1"> [ SIZE="1" ]
                        <font size="+1"> [ SIZE="4" ]
                        <font size="+2"> [ SIZE="6" ]
                        </font> [ /SIZE ]

                        Would this work okay:

                        $replacer = array(
                        "<font size=\"-2\">" => "[ SIZE=\"1\" ]",
                        "<font size=\"-1\">" => "[ SIZE=\"1\" ]",
                        "<font size=\"+1\">" => "[ SIZE=\"4\" ]",
                        "<font size=\"+2\">" => "[ SIZE=\"6\" ]",
                        "</font>" => "[ /SIZE ]",
                        "" => "",
                        "" => "",
                        "" => ""
                        );

                        Are my "escapes" correct?

                        Comment


                        • #13
                          That will work, or just put the strings in single quotes.

                          PHP Code:
                          $replacer = array(
                          '<font size="-2">' => '[ SIZE="1" ]',
                          '<font size="-1">' => '[ SIZE="1" ]',
                          '<font size="+1">' => '[ SIZE="4" ]',
                          '<font size="+2">' => '[ SIZE="6" ]',
                          '</font>' => "[ /SIZE ]"
                          ); 
                          I wrote ImpEx.

                          Blog | Me

                          Comment


                          • #14
                            Thanks Jerry. I chickened out and used your single quote method.

                            Last (big) job with this board conversion is to find all the links (except pics) that still go back to the old board.

                            Comment

                            Related Topics

                            Collapse

                            Working...
                            X