Use Wordpress authentication in ZenPhoto

I wrote a post here a few days ago explaining how I'd integrated ZenPhoto into my Wordpress blog. Now I´ve gone a bit further and tweaked it so ZenPhoto uses my Wordpress authentication, all Wordpress users (except Subscribers) can now access the ZenPhoto administration with their WP user/pass. If anyone is interested, a short tutorial on how to do this can be found at:

http://tech.einaregilsson.com/2007/08/08/using-wordpress-authentication-in-zenphoto/

Comments

  • acrylian Administrator, Developer
    Although for me the separate installations are not that big problem, this is great. If I knew that earlier I could have used it recently on a page.

    Maybe you should write a real wp plugin...:-)
  • Yes, a proper plugin would be excellent.... although, probably require a very different approach, since this mod doesn't touch WP, but rather edits the authenication in ZenPhoto itself...

    For now though, this works like a charm. Thanks!
  • einaregilsson,

    I'm wondering if you know how to get a tab for my gallery to show up in the main WordPress site navigation? I've been looking around, and there doesn't seem to be an easy way, but maybe i'm missing something. Thanks!
  • Found a solution: I made a new empty page in Wordpress called "gallery," which makes the tab in the main navigation. The Zenphoto mod_rewrite rules ensure that the slug for the new page goes to my zenphoto page, which is at /gallery/

    Now if I could just get that tab to stay highlighted when I click through into zenphoto albums and image pages...
  • Yeah, a WP plugin can't really do this since these are all ZenPhoto files I had to change. ZenPhoto itself doesn't have a plugin architecture yet as far as I know.

    @dspnorman: The only thing I can think of to highlight the current page is to figure out what WP uses to determine whether to highlight it, and possible alter $_GET[] or something so WP thinks it's on that page.

    Something like $_GET['p'] = 123; //where 123 is the postID of the empty gallery page

    is all I can think of. If you tell me what theme you're using I might be able to figure it out :)
  • I'm using K2, and the logic for marking the current page is pretty obscure... there's an if statement which calls several functions in turn to check on ... something, not quite sure what yet. Basically if any return true, it adds a class to the link in the menu. That class is the CSS creates the "you are here" tab.

    I've hacked it for now by adding a rule to the zen-style.css which uses an attribute selector to get the "gallery" tab, and then if the link in that tab is visited (i.e. if I'm on a gallery page) it applies the same styling to mark the tab as current. Only problem is, that means the CSS is in two places.

    It works though, and I have no idea how to hack the WP theme to make it add that extra class when on a gallery sub page, since it's all done in the WP header.
  • As far as I can see, the return value of $wp_query->get_queried_object_id() determines which page you're on and is used in the list_pages function. If you're willing to hack your WP files then I think your best bet would be to add something like this at the top of the function:

    if (substr($_SERVER['REQUEST_URI'],0, 9) == '/gallery/) {
    return 123; //where 123 is the post id of your gallery page
    }

    I think that would work, although I haven't tested it. Otherwise if you want this function to return the correct value you'll have to load the post somehow and I have no idea how to do that. But if your css thing works then thats probably the easiest way to do it.
  • I just set up fresh Wordpress and Zenphoto installs on a Media Temple Grid Server, and I can't get this integration working. I've followed the steps exactly as I did on my other server, where it's working fine.

    However, on the (mt) server, I get an error when trying to view or login to the gallery pages:

    `Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /mnt/xx/xx/xx/domains/xxx/html/pictures/zen/auth_zp.php on line 14`

    Here's what's on the that line in my file: `return is_user_logged_in() && wp_get_current_user()->user_level >= 2;`

    As I said, there's no difference between this file and one that's working on another server, and even the directory structure is the same... anyone know of pickiness with Media Temple's PHP implementation?
  • That should work on any normal php setup I think. But you could try breaking it down, like:

    $is_logged_in = is_user_logged_in();
    if (!$is_user_logged_in)
    {
    return false;
    }

    $user = wp_get_current_user();
    $level = $user->user_level;
    return $level >= 2;

    Havent tested it, but this should at least give you a clearer picture of what's not working.
  • Will try this, thanks.
  • Hi thanks for the integration tips. i also use Ruzee's method and it is working great as you can see on my test pag www.bertsimons.nl/zenphoto.

    To highlight the current page I did this:

    my wordpress is in www.bertsimons.nl/wordpress
    my zenphoto is in www.bertsimons.nl/zenphoto

    following:

    $page = $_SERVER['REQUEST_URI'];
    $page = str_replace("/","",$page);

    will in my case now return: ' zenphoto' or 'wordpress'

    in my wordpress header I now put:

    <?php //highlight wordpress pages or zenphoto

    $page = $_SERVER['REQUEST_URI'];
    $page = str_replace("/","",$page);
    if ($page == "wordpress") {
    $page = "zenphotouit";
    $highlight = "wordpress";

    } else {

    $highlight = "wordpressuit";
    $page = "zenphoto";

    }

    if (is_page()) {
    $page = "zenphotouit";
    $highlight = "wordpressuit";

    }

    if (is_single()) {
    $page = "zenphotouit";
    $highlight = "wordpress";

    }

    if (is_category()) {
    $page = "zenphotouit";
    $highlight = "wordpress";

    }

    if (is_archive()) {
    $page = "zenphotouit";
    $highlight = "wordpress";

    }

    ?>

    and the string $higlight and $page are classes to put in my navigation bar which I also define in my wordpress header.php

    <div>

    <ul id="supernav">

    <li class="<?php echo $page; ?>">Portfolio</class>
    <li class="<?php echo $highlight; ?>">">Blog</class>

    <?php wp_list_pages('title_li='); ?>

    </div>

    the classes I defined in my wordpress style.css
    ('uit' is dutch for 'off')

    #supernav a {
    color:#858585;}

    #supernav .zenphoto a {color:#fff;}

    #supernav .zenphotouit a {color:#858585;}

    #supernav .wordpress a {color:#fff;}

    #supernav .wordpressuit a {color:#858585;}

    #supernav page_item a {color:#858585;}

    #supernav .current_page_item a {color:#fff;}

    note; the .current_page_item a and page_item a class are classe defined by the <?php wp_list_pages('title_li='); ?> tag.

    hope this is usefull.
  • and something I can't get working....

    In my blog I use Zenpress to insert a photo from an zenphoto album in wordpress.
    clicking the image takes me to the corresponding album.
    In the zenphoto image description I would like to see the cooresponding wordpress post text..

    I manage to get all posts in there when using

    <?php while (have_posts()) : the_post(); ?><?php the_excerpt(); ?><?php endwhile; ?>

    but not the single post I was on in wordpress..

    any ideas?
  • I'm not sure I understand what you're trying to do. Do you want to see the wordpress post text while you're viewing the image in the actual zenphoto album? If so, you'll somehow need to know which post the image appeared in. Maybe something like:

    $url = 'your image url here';
    $rs = $wpdb->get_results("select post_content from posts where post_content like '%$url%', ARRAY_A);

    $text = $rs['post_content'];

    Something like that maybe. Haven't tested it. Or am I completely misunderstanding what you're asking for?
  • Yes Eina, that's exactly what I wanted...

    and thanks alot for pointing me in the right direction! I got it working!

    for now I made something like this, I could get it working with getFullImageUrl() probably because of my lack of php writing skills to properly add quuotes, ots etc in teh right place...

    <?php

    $url = getImageTitle();
    $sql = "select post_content, post_title from wp_posts WHERE post_content REGEXP '".$url."'";
    $zen_wpcontent = array();
    $zen_wpcontent2 = array();
    $results = $wpdb->get_results($sql );
    foreach( $results as $result )
    $zen_wpcontent[] = $result->post_title;
    $zen_wpcontent2[] = $result->post_content;

    for($x=0;$x<count($zen_wpcontent);$x++)
    {
    echo $zen_wpcontent[$x]; echo "<br><br>";
    echo $zen_wpcontent2[$x];
    echo " ";
    }

    ?>

    and to hide image from the original post_content I just added a class image: display none; to the css

    thanks a lot!
  • and a variation. $zen_wptitle ,$zen_wpcontent, $zen_wpguid respectivily put the title, the content and a link back to the wordpress post in zenphoto

    <?php
    $url = getImageTitle();
    $sql = "select post_content, ID, guid, post_title from wp_posts WHERE post_content REGEXP '".$url."'";
    $results = $wpdb->get_results($sql );
    foreach( $results as $result ){
    $zen_wpID[] = $result->ID;}
    for($x=0;$x<count($zen_wpID);$x++){
    $post_id = get_post($zen_wpID[$x]);
    $zen_wptitle = $post_id->post_title;
    $zen_wpcontent = $post_id->post_content;
    $zen_wpguid = $post_id->guid;}
    ?>
  • and finally discovered how to use the etgFullImageUrl...

    <?php
    $url = getFullimageurl() ;
    $url = str_replace('/albums','',$url);
    $sql = "select post_content, ID, guid, post_title from wp_posts WHERE post_content LIKE '%".$url."%'";
    $results = $wpdb->get_results($sql );
    foreach( $results as $result )
    {
    $zen_wpID[] = $result->ID;
    }
    for($x=0;$x<count($zen_wpID);$x++)
    {
    $post_id = get_post($zen_wpID[$x]);
    $zen_wptitle = $post_id->post_title;
    $zen_wpcontent = $post_id->post_content;
    $zen_wpguid = $post_id->guid;
    }
Sign In or Register to comment.