www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Thread: Don't laugh! But this may be a stupid wordpress/php question...

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Posts
    86

    Don't laugh! But this may be a stupid wordpress/php question...

    I'm wanting to pull my nav bar and footer etc from my custom wordpress theme to display in my Invision Power Board. The two really don't play nicely with each-other but who wants to separately code and edit two nav bars etc every time there is a link change etc?

    My question which is likely stupid and outrageous...

    Rather then plugging the wordpress environment into my forum is there a simpler way to maybe output the rendered SOURCE code (meaning the code that you would see if you viewed the source in the browser window) to a file, then use a php code inside the forum skin template to import that code so that it's not containing all the wordpress stuff? Then the forum won't be choking on the wp-load and wp-header files etc. Does that make sense? I know it likely isn't possible but hopefully what I'm asking is being understood. Feel free to ask me any questions and thank you for any input on this...

  2. #2
    Join Date
    Jul 2013
    Posts
    29
    You may put the desired WP code into separate files, put include statement to the place the code was before, and then include these files from your IPB. In case you want to include rendered output you will have to do this also, but this time you will use SSI or file_get_contents() from url to fetch the data.

  3. #3
    Join Date
    Feb 2010
    Posts
    86
    Quote Originally Posted by tishetsky View Post
    You may put the desired WP code into separate files, put include statement to the place the code was before, and then include these files from your IPB. In case you want to include rendered output you will have to do this also, but this time you will use SSI or file_get_contents() from url to fetch the data.
    Ok, so what we had working to get the wordpress nav bar to work in the forum before I posted this thread here is:

    In the forums index.php file that we really shouldn't touch we had to put:

    Code:
    require_once('/this-is-our-absolute-path.com/wp-load.php');
    (wp load then gets the wp-config file sorted out etc)

    Then in the forum skin global template we put this with their parse instructions for a file:

    Code:
    {parse include="/this-is-our-absolute-path.com/wp-content/themes/our-theme/footer.php"}
    The footer code file above has this in it:

    Code:
    <div id="footer" class="col-full">
      <?php wp_nav_menu( array( 'theme_location' => 'footer-menu', 'container_class' => 'footer-navigation', ) ); ?>
      <div class="clear"></div>
    </div>
    <div class="contact-info">
        <p><?php echo eh_get_option('eh_site_address'); ?> <br/>
          <a href="mailto:<?php echo eh_get_option('eh_site_email'); ?>"><?php echo eh_get_option('eh_site_email'); ?></a> </p>
      </div>
    </div>
    <!--/wrapper-->
    <?php wp_footer(); ?>
    </body></html>
    (doesn't look like much but it's a footer with a fair amount of links)

    So that all works but as I said it's requiring us to load the wordpress environment into the forum which doesn't play nice. So I know it's asking alot but could you possibly give me an example code of some sort as to what you're saying is a possibility for us to try? I'm thinking the very first part of what you're saying is kinda what we already did but then the ssi or includes I'm not sure how to work with such a thing.

    I would be more then happy to PayPal you a little cash for any help with an example if it produces something that works for us here....

    Thanks!

  4. #4
    Join Date
    Jul 2013
    Posts
    29
    You may consider dumping a part of WP output to separate static file and include it as plain text. You will have to modify WP template to grab a part of rendered output and write it to a file
    PHP Code:
    <? ob_start(); ?>
    <div id="footer" class="col-full">
      <?php wp_nav_menu( array( 'theme_location' => 'footer-menu''container_class' => 'footer-navigation', ) ); ?>
      <div class="clear"></div>
    </div>
    <div class="contact-info">
        <p><?php echo eh_get_option('eh_site_address'); ?> <br/>
          <a href="mailto:<?php echo eh_get_option('eh_site_email'); ?>"><?php echo eh_get_option('eh_site_email'); ?></a> </p>
      </div>
    </div>
    <!--/wrapper-->
    <?php wp_footer(); ?>
    <? 
        $page_content 
    ob_get_flush(); 
        
    file_put_contents('/some/file/to/include/from/ipb.txt'$page_content);
    ?>
    Then include it from ipb preferrably with file_get_contents() to avoid code parsing attempt which will be done if using include() or require(). This file will be renewed every time the WP is requested, but the request to IPB will not launch WP scripts. Pay attention to ob_* functions (ob stands for Output Buffering), read their manual for better understanding. Also check write permissions of the target file's folder. Hope my explanation is clear enough.

  5. #5
    Join Date
    Feb 2010
    Posts
    86
    Ok, I got this to work and it seems like the perfect solution. I've got my developer taking a peak at it now just to be sure I'm not missing anything that he can think of.

    I did have to parse include it though otherwise I couldn't get it to work in IPB's templates. When I look at the documentation though it seems as though their parse include may be the same thing as get_contents possibly? Or maybe I'm an idiot...LOL but here is their documentation for the parse command:

    include
    {parse include="file_location.html"}This will retrieve the contents of the file specified and insert it into the template.
    Useful if you have a html header or other content outside of IP.Board that you want to include.

    http://community.invisionpower.com/r...arse-tags-r157
    Is there any reason using their parse contents could be a bad thing? I'm not having to load the wordpress environment or anything so it seems like it's simply reading that file the same as the normal get_contents command would do?

    Lastly, is this method just as safe from hacking as any other method would be? I'm not familiar with the export function that's writing to the php but could someone from another domain use the export function to our txt file and infect it with malicious code? Or does it only work if it's from my same FTP account to write to that file?

    Thank you so much! This is awesome!

  6. #6
    Join Date
    Feb 2010
    Posts
    86
    I'm also wondering if it's ok that it's writing to these files this much. I mean, if it's writing to that file every time a user refreshes a page in our forum then could that cause an issue with my hosting company or anything? Or is it common and a no-issue?

  7. #7
    Join Date
    Jul 2013
    Posts
    29
    I know nothing about IPB inner working, but from this piece of documentation the "parse include" looks acceptable.

    Considering security, I didn't quite understand the question, but if you mean that somebody on another server can write to a file on your server, no he cannot. Somebody on the same server (if u are on shared hosting) possibly can write to this file, but setting correct write permissions will prevent him from doing it, also shared hosting setup usually does not allow a user to write to another user's folders.

    Considering performance, yes, it is not too good to write the file on each and every reload at least because it is totally useless. Since you only need to write to this file when some changes are made I can recommend to check if file exists and write to it only if it does not exist. In this case you may delete the file after making changes, the script will detect that file is missing and create it filled with fresh data. On another hand this will require reading filesystem on each WP request to check if the file presents, but this is not as resource consuming as frequent writes.

    You also may add checking of some GET parameter and write the file only if it is set to certain value or is set at all, though I am not quite sure if it is easyly done within WP. But if you manage to do it you will get maximum efficiency possible for this task. In this case you will manually force file write by requesting your WP with some url that normally is accessible but not publicly visible.

  8. #8
    Join Date
    Feb 2010
    Posts
    86
    I would really appreciate you PM'ing me an email address I can PayPal you a few bucks too for all you've helped us with here...

  9. #9
    Join Date
    Feb 2010
    Posts
    86
    Hopefully you got my PayPal yesterday...

    Quote Originally Posted by tishetsky View Post
    Considering performance, yes, it is not too good to write the file on each and every reload at least because it is totally useless. Since you only need to write to this file when some changes are made I can recommend to check if file exists and write to it only if it does not exist. In this case you may delete the file after making changes, the script will detect that file is missing and create it filled with fresh data. On another hand this will require reading filesystem on each WP request to check if the file presents, but this is not as resource consuming as frequent writes.
    Any chance of getting a code example? I've been searching around and see different solutions but I'm not sure how or what best works with what we've got working already with the code above?

  10. #10
    Join Date
    Feb 2010
    Posts
    86
    If anyone can get me the additional code example needed below with the checking if the file exists then I'll be glad to shoot you $20 or so for your time via PayPal as soon as it's posted and confirmed works. Thanks!

    PHP Code:
    <? ob_start(); ?> 
    <div id="footer" class="col-full"> 
      <?php wp_nav_menu( array( 'theme_location' => 'footer-menu''container_class' => 'footer-navigation', ) ); ?> 
      <div class="clear"></div> 
    </div> 
    <div class="contact-info"> 
        <p><?php echo eh_get_option('eh_site_address'); ?> <br/> 
          <a href="mailto:<?php echo eh_get_option('eh_site_email'); ?>"><?php echo eh_get_option('eh_site_email'); ?></a> </p> 
      </div> 
    </div> 
    <!--/wrapper--> 
    <?php wp_footer(); ?> 
    <?  
        $page_content 
    ob_get_flush();  
        
    file_put_contents('/some/file/to/include/from/ipb.txt'$page_content); 
    ?>
    Quote Originally Posted by tishetsky View Post
    Considering performance, yes, it is not too good to write the file on each and every reload at least because it is totally useless. Since you only need to write to this file when some changes are made I can recommend to check if file exists and write to it only if it does not exist. In this case you may delete the file after making changes, the script will detect that file is missing and create it filled with fresh data. On another hand this will require reading filesystem on each WP request to check if the file presents, but this is not as resource consuming as frequent writes.

    You also may add checking of some GET parameter and write the file only if it is set to certain value or is set at all, though I am not quite sure if it is easyly done within WP. But if you manage to do it you will get maximum efficiency possible for this task. In this case you will manually force file write by requesting your WP with some url that normally is accessible but not publicly visible.

  11. #11
    Join Date
    Jul 2013
    Posts
    29
    I would like to, but I do not see a PM button anywhere. Maybe that's because I am recently registered and cannot send PMs yet. PM me if you can, I will reply.

  12. #12
    Join Date
    Feb 2010
    Posts
    86
    Yeah, it won't let me send you a PM. Says that you've either opted out of PM's or that you're not allowed to have them.

    If it's not that you opted out of PM's in your settings then shoot me a quick email with your paypal address to blue_vision@mac.com. It's 2am here and I'm heading off to bed but I'll get it in the morning.

    Thanks!

  13. #13
    Join Date
    Jul 2013
    Posts
    29
    Hello again, yes I did receive your money, thank you.

    Checking the file existance is pretty straightforward. Add the following around file_put_contents():
    PHP Code:
    $ipb_txt_file "/some/file/to/include/from/ipb.txt";
    if (!
    is_file($ipb_txt_file)) {
       
    file_put_contents($ipb_txt_file$page_content);

    Now when you add something that requires text file updating you just delete this text file over ftp or ssh or whatever else you use and on the very first request to WP it will be written again populated with current data. Another way I was talking about was to request the WP with some additional $_GET parameter. e.g. wordpress.url/?renew_ipb and change the check accordingly. In this case it would be
    PHP Code:
    if (isset($_GET['renew_ipb'])) 
    instead of
    PHP Code:
    if (!is_file(...)) 
    Though it may require you to add changes to htaccess if for some reason the default one does not pass all request parameters wrom apache to the script.

  14. #14
    Join Date
    Feb 2010
    Posts
    86
    Awesome! Thanks! Haven't tried it yet but will in the morning (it's 1am here)...

    Now, I understand the checking for the files existence one but I'm having a hard time understanding the GET one.

    How does it know when the txt file needs to be updated? Do I have to delete it (like the GET) or manually do something to the file if we add anything to the footer etc? I'm just kinda confused on how this works...

  15. #15
    Join Date
    Jul 2013
    Posts
    29
    The logic is quite simple: every time the WP script is called it grabs a piece of rendered output into buffer before sending it to client. After that it checks for some condition and if that condition is true it writes the grabbed data to a file. Grabbing data into a buffer does not cost you a thing, so it is possible to be performed on every request. The condition to be checked may be:
    1) absence of a file
    or
    2) presence of a GET parameter in request
    From the script's point of view GET parameters are just an array created by php engine according to what the apache passed to php engine, which in its turn depends on how the certain URL was requested. I don't know how to explain it any simplier. In most general case when you request a script by URL "your.domain/?renew_ipb" which most probably will be rewriten to "your.domain/index.php?renew_ipb" the index.php script will see an Array variable named $_GET with one of its fields named 'renew_ipb' and its existance can be checked by "if (isset($_GET['renew_ipb']))". In this case after you add some info to your WP footer you need to request your WP by such an URL (you may type it in browser address bar or add a bookmark) and only if you add this certain GET parameter to an URL the text file will be written to disk. If no certain GET parameter is present (since we only check its presence, not its value) the piece of rendered output will be grabbed to buffer but not will be written to disk thus not generating unneccessary load.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles