Welcome, Guest. Please login or register.
March 28, 2024, 03:34:21 am

ballp.it is the community forum for The F Plus.

You're only seeing part of the forum conversation. To see more, register for an account. This will give you read-only access to nearly all the forums.

Topic: [REQUEST] Fix this stupid PHP.  (Read 10088 times)

Lemon

  • Whatever happened to Freedom of Speech?
  • Administrator
  • ...IT'S NOW THE MASH!
  • 4,127
  • 421
[REQUEST] Fix this stupid PHP.
Hi! I am not good at PHP.

So, when you're looking at the thread view of ballp.it (like this page), the HTML rendered, in order, for the Subject/Started By cell is...

  • a useless div
  • a useless span
  • a link to the actual thread
  • a link to the new posts in that thread (if there are any)
  • Thread creator
  • Thread pagination

So, in HTML terms, what I get is...
HTML
<td class="subject windowbg2">
<div>
<span id="msg_50194"><a href="http://ballp.it/index.php?topic=1703.0">First times watching classic movies</a></span>
<a href="http://ballp.it/index.php?topic=1703.msg50303#new" class="jump-to-new subject-level" id="newicon50194">
<svg viewBox="0 0 32 32"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#PostNewOnes"></use></svg>
</a>
<p>Started by <a href="http://ballp.it/index.php?action=profile;u=19" title="View the profile of jack chick">jack chick</a>
<small id="pages50194">« <a class="navPages" href="http://ballp.it/index.php?topic=1703.0">1</a> <a class="navPages" href="http://ballp.it/index.php?topic=1703.15">2</a>  »</small>
</p>
</div>
</td>

While this isn't the worst thing in the world, it really isn't the best. Most  importantly, I really want that "jump to new" link to come first, so I can float it appropriately. Perfect world, the markup looks like this...
HTML
<td class="subject-and-creator">
<div class="title">
<a href="http://ballp.it/index.php?topic=1703.msg50303#new" class="jump-to-new subject-level" id="newicon50194">
<svg viewBox="0 0 32 32"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#PostNewOnes"></use></svg>
</a>
<a class="thread-title" href="http://ballp.it/index.php?topic=1703.0">First times watching classic movies</a>
</div>
<div class="creator-and-pagination">
<span class="creator">
Started by <a href="http://ballp.it/index.php?action=profile;u=19" title="View the profile of jack chick">jack chick</a>
</span>
<span class="pagination">
« <a class="navPages" href="http://ballp.it/index.php?topic=1703.0">1</a> <a class="navPages" href="http://ballp.it/index.php?topic=1703.15">2</a>  »
</span>
</div>
</td>

With a lot of these ballpit changes, these changes are pretty easy. However, in this particular case, the code is a fucking mess...
PHP
<td class="subject ', $alternate_class, '">
<div ', (!empty($topic['quick_mod']['modify']) ? 'id="topic_' . $topic['first_post']['id'] . '" onmouseout="mouse_on_div = 0;" onmouseover="mouse_on_div = 1;" ondblclick="modify_topic(\'' . $topic['id'] . '\', \'' . $topic['first_post']['id'] . '\');"' : ''), '>
', $topic['is_sticky'] ? '<strong>' : '', '<span id="msg_' . $topic['first_post']['id'] . '">', $topic['first_post']['link'], (!$context['can_approve_posts'] && !$topic['approved'] ? '&nbsp;<em>(' . $txt['awaiting_approval'] . ')</em>' : ''), '</span>', $topic['is_sticky'] ? '</strong>' : '';

// Is this topic new? (assuming they are logged in!)
if ($topic['new'] && $context['user']['is_logged'])
echo '
<a href="', $topic['new_href'], '" class="jump-to-new subject-level" id="newicon' . $topic['first_post']['id'] . '">
                                     <svg viewBox="0 0 32 32" ><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#PostNewOnes"></use></svg>
                                   </a>';
echo '
<p>', $txt['started_by'], ' ', $topic['first_post']['member']['link'], '
<small id="pages' . $topic['first_post']['id'] . '">', $topic['pages'], '</small>
</p>
</div>
</td>

If somebody has the chops and wants to simplify that crap, I'd appreciate it. If you're interested, I have all of this up in a GitHub repo, the file in question here is Themes/Giggle/MessageIndex.template.php

Otherwise, no big deal, but I'll probably never address that float issue.

Lemon

  • Whatever happened to Freedom of Speech?
  • Administrator
  • ...IT'S NOW THE MASH!
  • 4,127
  • 421
[REQUEST] Fix this stupid PHP. #1
Just turned this into a GitHub issue.

duz

  • Paid
  • 659
  • 19
[REQUEST] Fix this stupid PHP. #2
What messy code. So basically this?

PHP
echo "<td class='subject {$alternate_class}'>
    <div class='title' ", (!empty($topic["quick_mod"]["modify"])
        ? "id='topic_" . $topic["first_post"]["id"] . "' onmouseout='mouse_on_div = 0;' onmouseover='mouse_on_div = 1;' ondblclick='modify_topic(\"" . $topic["id"] . "\", \"" . $topic["first_post"]["id"] . "\");'"
        : ""),
    ">";

// Is this topic new? (assuming they are logged in!)
if ($topic["new"] && $context["user"]["is_logged"]) {
    echo "
        <a href='{$topic["new_href"]}' class='jump-to-new subject-level' id='newicon{$topic["first_post"]["id"]}'>
            <svg viewBox='0 0 32 32' ><use xmlns:xlink='http://www.w3.org/1999/xlink' xlink:href='#PostNewOnes'></use></svg>
        </a>";
}

echo ($topic["is_sticky"]
    ? "<strong>"
        : ""),
    "{$topic["first_post"]["link"]}",
    (!$context["can_approve_posts"]
        && !$topic["approved"]
    ? "&nbsp;<em>({$txt["awaiting_approval"]})</em>"
        : ""),
    "",
    ($topic["is_sticky"]
    ? "</strong>"
        : "");

echo "</div><div class='creator-and-pagination'>";
echo "  <span class='creator'>
            {$txt["started_by"]} {$topic["first_post"]["member"]["link"]}
        </span>
        <span class='pagination'>
            {$topic["pages"]}
        </span>
    </div>
</td>";

Lemon

  • Whatever happened to Freedom of Speech?
  • Administrator
  • ...IT'S NOW THE MASH!
  • 4,127
  • 421
[REQUEST] Fix this stupid PHP. #3
Hmmmm, unfortunately no I'm not having luck with that. I'm editing this template, placing your bit at the parts between 268 - 283, and then providing a couple of extra apostrophes and echo commands to compensate, but when I upload the results, pages like this are completely blank.

duz

  • Paid
  • 659
  • 19
[REQUEST] Fix this stupid PHP. #4
Oh, woops, here's a pastebin of the full thing merged now that I'm sober and can do a proper diff.  If it's still not working I'll get git installed and tweak some more.
Lemon

Lemon

  • Whatever happened to Freedom of Speech?
  • Administrator
  • ...IT'S NOW THE MASH!
  • 4,127
  • 421
[REQUEST] Fix this stupid PHP. #5
Yaaaaaay! Thanks, duz. That worked.

Bodark

  • Joan Ocean's #1 Fansquatch
  • Paid
  • I'm real and I tried to suck your dick.
  • 850
  • 55
[REQUEST] Fix this stupid PHP. #6
I really hate to burst your bubble, but it made things very messy on mobile.

Running Chrome on Android, fwiw.
Vinny Possum

Frank West

  • Have you ever astraled and kicked it with satan
  • Ridiculist
  • Marky Mk 2
    • 1,325
    • 165
[REQUEST] Fix this stupid PHP. #7
What Bodark said but if I said it instead.

Nifty Nif

  • Big Dumb Slimy Monster
  • Paid
  • powerful and can be dangreous
  • 809
  • 51
[REQUEST] Fix this stupid PHP. #8
Confirmed on Chrome, iOS 9. :(

Lemon

  • Whatever happened to Freedom of Speech?
  • Administrator
  • ...IT'S NOW THE MASH!
  • 4,127
  • 421
[REQUEST] Fix this stupid PHP. #9
Confirmed on Chrome, iOS 9. :(
Nifty Nif, June 08, 2016, 06:52:03 pm

Shiiit.

Okay, on it.
Vinny Possum

Vinny Possum

  • Garfield's cosmic love katana.
  • Paid
  • 1,236
  • -16
[REQUEST] Fix this stupid PHP. #10
I really hate to burst your bubble, but it made things very messy on mobile.

Running Chrome on Android, fwiw.
Bodark, June 08, 2016, 06:38:44 pm
I'm having the same problem, so it isn't an isolated thing.

Lemon

  • Whatever happened to Freedom of Speech?
  • Administrator
  • ...IT'S NOW THE MASH!
  • 4,127
  • 421
[REQUEST] Fix this stupid PHP. #11
Yeah, I can duplicate it.

Though at the moment, I don't understand why this is happening, but I'll figure it out.

Nifty Nif

  • Big Dumb Slimy Monster
  • Paid
  • powerful and can be dangreous
  • 809
  • 51
[REQUEST] Fix this stupid PHP. #12
Yeah, I can duplicate it.

Though at the moment, I don't understand why this is happening, but I'll figure it out.
Lemon, June 08, 2016, 08:47:33 pm

Did it happen in the 3.5 hours between your deploy and Bodark's post?  Not to be that guy, I know you know how to do your job, but it could be a sneaky browser update or some bullshit.  It probably wasn't.  :(  Just ruling things out, picking the low-hanging fruit.  I'll get my nose out of here.

Edit: it actually looks fine on mobile Safari, might be a Chrome thing.  And while I was trying to cross-check it on Firefox, I decided to double-check Chrome...and I think you either rolled it back or fixed it.  You're fast!  Nice job!
« Last Edit: June 08, 2016, 09:14:30 pm by Nifty Nif »

Vinny Possum

  • Garfield's cosmic love katana.
  • Paid
  • 1,236
  • -16
[REQUEST] Fix this stupid PHP. #13
Seems to be fixed. Thanks Lemon!
Bodark

Nifty Nif

  • Big Dumb Slimy Monster
  • Paid
  • powerful and can be dangreous
  • 809
  • 51
[REQUEST] Fix this stupid PHP. #14
I saw the tiniest blip while I was bulbing something, and that was probably when you fixed it.  Hot damn!  Shows what I know.  Thank you Lemon!!!  [yay][lemon]
Lemon Bodark