forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: content syndication (cpmFetch) => Topic started by: Abbas Ali on November 08, 2005, 01:46:13 pm

Title: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
Post by: Abbas Ali on November 08, 2005, 01:46:13 pm
This depends on client browser rather than server.

What we are doing -

Add the following Java Script code to your html file in which you want to fetch the photos (normally within head tag of the html).

Code: [Select]
<script language="Javascript">
<!--
var x1;

x1 = createRequestObject();

function createRequestObject() {
  var x = false;

  try {
    x = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      x = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      x = false;
    }
  }

  if (!x && typeof XMLHttpRequest != "undefined") {
    x = new XMLHttpRequest();
  }

  return x;
}

function getPhotos() {
  x1.open('get','random.php'); //Replace random.php with whatever php script you are using to fetch photos
  x1.onreadystatechange = function() {
    if (x1.readyState == 4) {
      document.getElementById("photos").innerHTML = x1.responseText;
    }
  }
  x1.send(null);
}

onload = getPhotos();
//-->
</script>

and this is a sample html

Code: [Select]
<table>
  <tr>
    <td>this is some text</td>
    <td>
      <div id="photos">
    </td>
  </tr>
</table>

In above html code the div with id="photos" will get populated with the photos. You can place this div anywhere you want in your html. Infact you can use any element instead of div to accomplish this but make sure that id of that element is photos

And this is sample random.php

Code: [Select]
<?php
  
include "./cpmfetch/coppermine.php";
  
$objCpm = new cpm("/cpg133");
  print 
$objCpm->cpm_viewRandomMediaFromCategory(4,2,0);
  
$objCpm->cpm_close();
?>


In random.php replace the paths and function name as per your needs.

I am attaching a sample html file which will help you understand this better.
Title: Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
Post by: n3n on March 02, 2006, 01:57:41 pm
in firefox it works quite nice, but in IE (windows) it doesnt seem to work.
Have you tested it ?
Title: Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
Post by: Abbas Ali on March 03, 2006, 08:03:05 am
hmmm....after doing some research found the problem. For me its a bug of IE (for others it might be a feature). Some problem in IE's DOM reading capabilities...

Anyways REMOVE

Code: [Select]
onload = getPhotos();

from the above javascript and ADD

Code: [Select]
<script language="Javascript">
<!--
  getPhotos();
//-->
</script>

at the bottom of your html page just before closing html tag.

Do let me know whether this solves the problem.


Abbas
Title: Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
Post by: n3n on March 03, 2006, 02:21:17 pm
Hmm, tnx for the quick reply. I inserted the code, but hasnt changed anything.
Im using the code in my theme.php, because the copperminefetch code didnt work at all.
Title: Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
Post by: Abbas Ali on March 03, 2006, 06:55:26 pm
If you are using the code in theme.php...then why use XML HTTP at all? You can directly put the php code in theme.php

Can you please describe what exactly are you doing and where are you placing the javascript and html code given above in theme.php?
Title: Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
Post by: n3n on March 03, 2006, 07:11:32 pm
I made a css draggable box, that shows some stuff about the image, a link to comments/info, in there i want to place 2 rows of small
thumbs using cpmfetch.

The reason that i'm not using cpmfetch directly, is because i could not get it to work  ??? I;ve tried if for hours, and did not succeed.

Ill post the code in a moment, don;t have it here right now.

Title: Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
Post by: mona87 on October 13, 2006, 12:36:09 am
Thanks so much for the script, it worked perfectly for me.  I couldnt get the cmp to work with my html pages and this was jsut what i needed!

Thanks!
Title: Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
Post by: explora57 on November 20, 2008, 02:40:31 pm
Absolutely spot on done me a good turn here my friend thankyou vm.

Bill