Advertisement:

Author Topic: [FIX] How to fix "function_show_flash_message"  (Read 6567 times)

volunteer

  • Full Member
  • ***
  • Posts: 241
[FIX] How to fix "function_show_flash_message"
« on: March 15, 2014, 10:45:06 pm »
If u make a mistake filling a form or if u successfully publish and Item u dont get any confirmation message

function twitter_show_flash_message

itemp-post.php

Code: [Select]
<body>
        <?php osc_current_web_theme_path('header.php') ; ?>
        <div class="container margin-top-10">
            <?php twitter_show_flash_message() ; ?>
        </div>

repurpose is based on twitter theme, found lot of bugs before due to that "adaptation", is this one one more?? what should I do?

Thanks!
« Last Edit: March 17, 2014, 12:52:44 pm by volunteer »


volunteer

  • Full Member
  • ***
  • Posts: 241
Re: "function twitter_show_flash_message" not working
« Reply #2 on: March 17, 2014, 12:51:48 pm »
thanks a lot! I will place a quote for your msg in this thread and mark it as solved

I got it working like this:

Went into every PHP form of the template and replaced:
Code: [Select]
<?php twitter_show_flash_message() ; ?>
with
Code: [Select]
<?php osc_show_flash_message() ; ?>
So what's happening now is that we are using the OS Class built in messaging system instead of the twitter theme's implementation.

Now we have to apply the CSS (because the OS Class' message CSS isn't something to write home about)

So go into your oc-includes\osclass\helpers\hMessages.php
and replace line 103 with this:
Code: [Select]
echo '<div id="' . $id . '" class="alert-message ' . strtolower($class) . ' ' . strtolower($class) . '-' .$message['type'] . '"><a class="close" href="#">×</a>';

Here we are just adding the Twitter classes to the messages so that it looks good.

The only disadvantage to this is that the error messages aren't that nice.
For instance: "Title too short (en_US). Email invalid."

volunteer

  • Full Member
  • ***
  • Posts: 241
Re: [FIX] How to fix "function_show_flash_message"
« Reply #3 on: March 17, 2014, 04:24:43 pm »
it messes up with the flash messages in admin panel although :(

ikrougovoi

  • Newbie
  • *
  • Posts: 15
Re: [FIX] How to fix "function_show_flash_message"
« Reply #4 on: March 17, 2014, 06:12:56 pm »
It only messes up if you forgot to put the osc_show_flash_message on one of the PHP pages.

The reason being:
1. You fill out a form and if there are any errors the form populates a variable with all of the warnings/errors
2. The errors/warnings are then displayed in the next page where a call to osc_show_flash_message is called and then it clears out the variables
So if you don't call osc_show_flash_message in every page, then some of the error messages will stay in the variable until it runs into the next osc_show_flash_message call

This happened to be me because I forgot to put osc_show_flash_message in the user_login/user_signup forms.
So I was trying to login and was putting in the wrong password, when I went to the item_post form I saw "invalid password" 3 times at the top.
(It took the invalid password messages from the login form and displayed them in the next form it found osc_show_flash_message)

I hope this helps, my admin panel works fine.
When I create a category, or delete a category, etc...
You can't "Close" some of the messages in the Admin panel though, that is broken, but when you go to another page they go away.
(The reason you can't close is because we changed the <a class="close" href="#">x</a> in the hMessage file..)

This is why OSCLASS does NOT want you to change the "CORE" code (such as the hMessage.php file)
But to me, I'd rather my users see a nice error message than me in the Admin Panel...
I'll look into getting the Admin panel "X" working at some point and post the changes..
« Last Edit: March 17, 2014, 06:39:42 pm by ikrougovoi »

volunteer

  • Full Member
  • ***
  • Posts: 241
Re: [FIX] How to fix "function_show_flash_message"
« Reply #5 on: March 17, 2014, 06:38:31 pm »
the X (close) works in my admin panel.. just the style (css) got uglier than before

ikrougovoi

  • Newbie
  • *
  • Posts: 15
Re: [FIX] How to fix "function_show_flash_message"
« Reply #6 on: March 17, 2014, 06:41:02 pm »
Yes.. It depends on which place in the Admin panel.

So.. Making changes to the categories it works you can click X.
(This is because it echos different HTML for Category messages, so NOT line 103 of the hMessage.php file we modified)

Making changes to the locations/emails it does not :(

This is because we set the "X" link (this is supposed to close the flash message) to the class of "close", where as the original hMessage close is a <button> tag (I think, I cannot remember now).
« Last Edit: March 17, 2014, 06:57:41 pm by ikrougovoi »

volunteer

  • Full Member
  • ***
  • Posts: 241
Re: [FIX] How to fix "function_show_flash_message"
« Reply #7 on: March 17, 2014, 07:55:04 pm »
what about importing the error msg system from twitter theme to repurpose?

or u have this problem with twitter and the reason is the last version of OSCLASS?

ikrougovoi

  • Newbie
  • *
  • Posts: 15
Re: [FIX] How to fix "function_show_flash_message"
« Reply #8 on: March 17, 2014, 08:27:57 pm »
Yes, the twitter theme has the same problem.

I'm thinking the BEST solution here would be inside the
twitter_show_flash_message
change it to call the OSC_Show_Flash_message
and then alter the HTML that the OSC_Show_Flash_message function returns..
so replace the original close HTML with the twitter close, and add the Twitter flash-message css class to it
Pseudo-code:
Code: [Select]
function twitter_show_flash_message
$message = osc_show_flash_message()
// replace <button class="close"> with twitter <a class="close" href="#">x</a> inside our $message variable
// replace <div class="message'> with the twitter class="flash-message" inside our $message
echo $message

This will mean that we won't have to modify the hMessage.php file
Which is A LOT better.
The admin panel calls the regular osc_show_flash_message which means we won't mess that up..

The Twitter _getMessage('pubMessage') function is currently what's broken (from what I can see).
There is nothing to "GET" from the 'pubMessage' variable..

DISCLAIMER: I am NOT a web developer..
I'm just trying to figure this all out by reverse engineering....
« Last Edit: March 17, 2014, 08:36:12 pm by ikrougovoi »

volunteer

  • Full Member
  • ***
  • Posts: 241
Re: [FIX] How to fix "function_show_flash_message"
« Reply #9 on: March 17, 2014, 08:50:11 pm »
u lost me there.. in which files?

ikrougovoi

  • Newbie
  • *
  • Posts: 15
Re: [FIX] How to fix "function_show_flash_message"
« Reply #10 on: March 17, 2014, 08:53:58 pm »
So inside twitter(or repurpose)\functions.php

line 85
Code: [Select]
    if( !function_exists('twitter_show_flash_message') ) {
        function twitter_show_flash_message() {
            $message = Session::newInstance()->_getMessage('pubMessages') ;

            if (isset($message['msg']) && $message['msg'] != '') {
                if( $message['type'] == 'ok' ) $message['type'] = 'success' ;
                echo '<div class="alert-message ' . $message['type'] . '">' ;
                echo '<a class="close" href="#">×</a>';
                echo '<p>' . $message['msg'] . '</p>';
                echo '</div>' ;

                Session::newInstance()->_dropMessage('pubMessages') ;
            }
        }
    }

In there, instead of the
Code: [Select]
$message = Session::newInstance()->_getMessage('pubMessages') ;
We should try

Code: [Select]
$message = osc_show_flash_message() ;
Now our $message variable contains what the OSClass messaging system returns.

Now we can do some string replacement inside the $message variable to replace the close tag, and add the twitter CSS.
(we will have to revert our PHP files to call twitter_show_flash_message)
But at least this way we are not messing around with the core hMessage.php file so outside of the template the osc_show_flash_message function works as it should.. (Such as inside the admin console pages)
« Last Edit: March 17, 2014, 08:58:36 pm by ikrougovoi »

ikrougovoi

  • Newbie
  • *
  • Posts: 15
Re: [FIX] How to fix "function_show_flash_message"
« Reply #11 on: March 17, 2014, 09:33:04 pm »
Except I'm an idiot and osc_show_flash_message doesn't actually return anything..
It just "echo"s the html back to your page...
(echo = "print", meaning it just prints <div id="flashmessage" class="flashmessage", etc. to your HTML page)

So another way we can do this is to change the CSS :)

So... Look for the CSS that styles the "alert-message" and apply it to "flashmessage"

osc_show_flash_message applies "flashmessage" style to it's messages.
We can just make the CSS apply the styling to "flashmessage" instead of "alert-message"
And something similar for the "close" button.

This should work as custom.css is only called on the end-user pages, not the Admin pages.

I will work on this tonight and post the fix here :)

volunteer

  • Full Member
  • ***
  • Posts: 241
Re: [FIX] How to fix "function_show_flash_message"
« Reply #12 on: March 17, 2014, 10:05:23 pm »
thanks! I will be waiting for your next post

ikrougovoi

  • Newbie
  • *
  • Posts: 15
Re: [FIX] How to fix "function_show_flash_message"
« Reply #13 on: March 18, 2014, 03:12:45 am »
Alright.. Final fix:
ensure all of your PHP pages are calling:
twitter_show_flash_message()

ensure your osc_show_flash_message function inside the helpers\hMessage.php file is the original (if you've changed it as per our discussion above)

now inside your theme\functions.php file look for the following lines (85 for Twitter, 86 for Repurpose)
Code: [Select]
    if( !function_exists('twitter_show_flash_message') ) {
        function twitter_show_flash_message() {
            $message = Session::newInstance()->_getMessage('pubMessages') ;

            if (isset($message['msg']) && $message['msg'] != '') {
                if( $message['type'] == 'ok' ) $message['type'] = 'success' ;
                echo '<div class="alert-message ' . $message['type'] . '">' ;
                echo '<a class="close" href="#">×</a>';
                echo '<p>' . $message['msg'] . '</p>';
                echo '</div>' ;

                Session::newInstance()->_dropMessage('pubMessages') ;
            }
        }
    }

and replace it with:
Code: [Select]
    if( !function_exists('twitter_show_flash_message') ) {
    function twitter_show_flash_message($section = 'pubMessages', $class = "alert-message", $id = "alert-message") {
        $messages = Session::newInstance()->_getMessage($section);
        if (is_array($messages)) {

            foreach ($messages as $message) {

                echo '<div id="flash_js"></div>';
       
                if (isset($message['msg']) && $message['msg'] != '') {
                    echo '<div id="' . $id . '" class="' . strtolower($class) . ' ' .$message['type'] . '"><a class="close">x</a>';
                    echo osc_apply_filter('flash_message_text', $message['msg']);
                    echo '</div>';
                } else if($message!='') {
                    echo '<div id="' . $id . '" class="' . $class . '">';
                    echo osc_apply_filter('flash_message_text', $message);
                    echo '</div>';
                } else {
                    echo '<div id="' . $id . '" class="' . $class . '" style="display:none;">';
                    echo osc_apply_filter('flash_message_text', '');
                    echo '</div>';
                }
            }
        } 
        Session::newInstance()->_dropMessage($section);
}
}

What we're doing here is essentially re-using the built in OS Class messaging function, but setting the class and close button for the alert to the Twitter CSS classes.
Now this is not best practice as we now have duplicate code in our application.. But hey it works!
I'm pretty sure the twitter one does NOT work because:
Code: [Select]
$message = Session::newInstance()->_getMessage('pubMessages') ;returns an Array, where as the twitter function is expecting ONE message....

Your Admin pages should all still be using osc_show_flash_messages which we have set back to the original one.
Now everything works :)

volunteer

  • Full Member
  • ***
  • Posts: 241
Re: [FIX] How to fix "function_show_flash_message"
« Reply #14 on: March 18, 2014, 04:25:08 am »
that's great! I appreciate all your work I will try it as soon as I manage to make my site work again, just moved to a new server but can't login as Admin anymore :(