Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

xml export of post gallery WordPress

  • SOLVED

Hi,
Default Wordpress post gallery system is good. But couldnt find a solution for safety xml export of post gallery.

For example there can be a feed type xml export for a 120 id post like "?galleryxml=120". i will use this for flash gallery solution in this example:
http://www.simpleviewer.net/simpleviewer/pro/examples/minimal/

I would like to import this to post with hook, not need shortcode.

Answers (3)

2010-02-22

Dan Fraticiu answers:

<?php
/*
Plugin Name: Simple Viewer Gallery
Plugin URI: none
Description: Simple Viewer Gallery allows you to easely insert simple viewer in you posts or pages.
Version: 2.9.0
Author: Dan Fraticiu
Author URI: http://www.nfr.ro
Author Email: [email protected]
*/

add_action('add_attachment', 'generate_gallery_xml');
add_action('delete_attachment', 'generate_gallery_xml');
add_action('edit_attachment', 'generate_gallery_xml');

function generate_gallery_xml($id){
$attachment = get_post($id);

//if($attachment->post_mime_type != 'image') return; //if the attachment in not image we don't care

$args = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
'post_parent' => $attachment->post_parent,
'post_mime_type' => 'image'
);
$attachments = get_posts($args);
if ($attachments) {

$upload_dir = wp_upload_dir();

$filename = $upload_dir['basedir'].'/sw-gallery/gallery-'.$attachment->post_parent.'.xml';

$fh = fopen($filename,'w') OR die('Can\'t open file, please check you CHMOD permissions');

$xml_content = '<?xml version="1.0" encoding="UTF-8"?>

<simpleviewergallery
galleryStyle="MODERN"
title="SimpleViewer Gallery"
textColor="FFFFFF"
frameColor="FFFFFF"
frameWidth="20"
thumbPosition="LEFT"
thumbColumns="3"
thumbRows="4"
showOpenButton="TRUE"
showFullscreenButton="TRUE"
maxImageWidth="640"
maxImageHeight="640"
useFlickr="false"
flickrUserName=""
flickrTags=""
languageCode="AUTO"
languageList=""
imagePath="images/"
thumbPath="thumbs/"
>';

foreach ($attachments as $a) {
$image = '
<image imageURL="'.wp_get_attachment_url($a->ID).'" thumbURL="'.wp_get_attachment_thumb_url($a->ID).'" linkURL="" linkTarget="" >
<caption><![CDATA['.apply_filters('the_content',$a->post_content).']]></caption>
</image>
';
$xml_content.=$image;
}

$xml_content .= '</simpleviewergallery>';

fwrite($fh, $xml_content);
fclose($fh);
}

}

register_activation_hook( __FILE__, 'sw_gallery_activate' );

function sw_gallery_activate(){
$upload_dir = wp_upload_dir();

mkdir($upload_dir['basedir'].'/sw-gallery/', 0777);
}

?>


Ünsal Korkmaz comments:

i didnt try code yet but i will use it on wpmu blogs. can you convert this for wpmu? like auto creating sw-gallery folder.

need to go atm. will back in 10-12 hours, so i will try it when return. thx a lot for help btw :)


Dan Fraticiu comments:

I've updated the code, it will automaticly create the sw-gallery folder in the upload folder (whereever that is). I can't test it on WPMU, but I can't se why it won't work.


Ünsal Korkmaz comments:

/home/aaa/public_html/wp-content/blogs.dir/1/files//sw-gallery/gallery-24.xml
Warning: fopen(/home/aaa/public_html/wp-content/blogs.dir/1/files//sw-gallery/gallery-24.xml) [function.fopen]: failed to open stream: No such file or directory in /home/aaa/public_html/wp-content/plugins/sw-gallery.php on line 69
Can't open file, please check you CHMOD permissions


i am getting this error :-/


Dan Fraticiu comments:

Try again with the updated code. After you update the code deactivate and activate again the plugin and then checj if it creates the folder
/home/aaa/public_html/wp-content/blogs.dir/1/files//sw-gallery/

If still doesn't work, can I get an account on your blog and one for FTP, it would be easier to find the problem. In my WP install (locally) it works so it's either a peprmission problem, or something related to WP MU.


Ünsal Korkmaz comments:

dude. i really try to find solution but creating a file seems so buggy atm.

can you make a different solution?
i can accept more query for each post.

and please try it on a wp3.0-alpha because i will make site on 3.0-alpha.


Dan Fraticiu comments:


Dan Fraticiu comments:

I can't think of any other way of doing this.

If you are still intrested in my idea and you can grant me some access to your ftp I'd be happy to help.

If not good luck.


Ünsal Korkmaz comments:

After lots of try;

* sw-gallery folder creating have problem. If i create it manually, xml files creating as normal
* Try this: upload 3 photo, check xml file. There is no problem. Delete a photo then check xml file. No change, so its not removing deleted one. Delete 1 more photo too. First deleted photo data disappearing but there is still 2 photo data in xml. So basically not working for latest deleted photo


Ünsal Korkmaz comments:

and.. i found 1 more thing:
* when delete a photo, its not removing that photo data but adding
<p class="attachment"><a href='http://aaa.com/files/2010/02/bizim-006.jpg' title='bizim 006'><img width="300" height="225" src="http://aaa.com/files/2010/02/bizim-006-300x225.jpg" class="attachment-medium" alt="" title="bizim 006" /></a></p>
to other photo data's CDATA section


Dan Fraticiu comments:

HI, you are write there was a problem with the deleting, because WP fired my function before any deleting was done, so the deleted attachmente still made it to the xml file.

Try this one:
<?php
/*
Plugin Name: Simple Viewer Gallery
Plugin URI: none
Description: Simple Viewer Gallery allows you to easely insert simple viewer in you posts or pages.
Version: 2.9.0
Author: Dan Fraticiu
Author URI: http://www.nfr.ro
Author Email: [email protected]
*/

add_action('add_attachment', 'generate_gallery_xml');
add_action('delete_attachment', 'generate_gallery_xml');
add_action('edit_attachment', 'generate_gallery_xml');

function generate_gallery_xml($id){
$attachment = get_post($id);

//if($attachment->post_mime_type != 'image') return; //if the attachment in not image we don't care

$args = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
'post_parent' => $attachment->post_parent,
'post_mime_type' => 'image'
);
$attachments = get_posts($args);
if ($attachments) {

$upload_dir = wp_upload_dir();

$filename = $upload_dir['basedir'].'sw-gallery/gallery-'.$attachment->post_parent.'.xml'; //check this path

$fh = fopen($filename,'w') OR die('Can\'t open file, please check you CHMOD permissions');

$xml_content = '<?xml version="1.0" encoding="UTF-8"?>

<simpleviewergallery
galleryStyle="MODERN"
title="SimpleViewer Gallery"
textColor="FFFFFF"
frameColor="FFFFFF"
frameWidth="20"
thumbPosition="LEFT"
thumbColumns="3"
thumbRows="4"
showOpenButton="TRUE"
showFullscreenButton="TRUE"
maxImageWidth="640"
maxImageHeight="640"
useFlickr="false"
flickrUserName=""
flickrTags=""
languageCode="AUTO"
languageList=""
imagePath="images/"
thumbPath="thumbs/"
>';

foreach ($attachments as $a) {
if($a->ID != $id){
$image = '
<image imageURL="'.wp_get_attachment_url($a->ID).'" thumbURL="'.wp_get_attachment_thumb_url($a->ID).'" linkURL="" linkTarget="" >
<caption><![CDATA['.$a->post_content.']]></caption>
</image>
';
$xml_content.=$image;
}
}

$xml_content .= '</simpleviewergallery>';

fwrite($fh, $xml_content);
fclose($fh);
}

}

register_activation_hook( __FILE__, 'sw_gallery_activate' );

function sw_gallery_activate(){
$upload_dir = wp_upload_dir();

mkdir($upload_dir['basedir'].'sw-gallery/', 0777); //check this path
}

?>


Make sure you deactive and activate the plugin to allow it to make the folder. If things don't work out, see the lines with comments after them. It seems that WP MU gets the path with an ending '/' while WP get's it without. SO if it doesn't work, try adding a '/' before "sw-gallery" in hose lines.

2010-02-27

Laura Gentry answers:

Here's what you'll have to do:

1) Install the Theme Preview plugin located here and activate it: [[LINK href="http://wordpress.org/extend/plugins/theme-preview"]]http://wordpress.org/extend/plugins/theme-preview[[/LINK]]

2) Upload this theme to your wp-content/themes folder but don't activate it: [[LINK href="http://lauragentry.com/downloads/gallery-xml-for-simpleviewer.zip"]]http://lauragentry.com/downloads/gallery-xml-for-simpleviewer.zip[[/LINK]]

3) Go to any post and add this to the end of the URL string "&preview_theme=gallery-xml-for-simpleviewer"

Like this:

[[LINK href="http://www.lauragentry.com/wordpress/?p=277&preview_theme=gallery-xml-for-simpleviewer"]]http://www.lauragentry.com/wordpress/?p=277&preview_theme=gallery-xml-for-simpleviewer[[/LINK]]

That's your post's XML that pulls in any attached image, thumbnail image and corresponding title.

Now in your post template when you're embedding your Simpleviewer code, you just need to use that URL in your embed code in place of the gallery.xml URL. You'll need to change the "p=[post id #]" to "p=<?php the_ID(); ?>" and you should be good to go.

You can edit the index.php file inside of the Gallery XML for Simpleviewer theme to edit any Simpleviewer parameters you might want or you can take them out completely and pass them through with your embed code.

Good luck!

2010-02-26

Sony Murdianto answers:

please check you CHMOD permissions