CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request

Started by Abbas Ali, November 08, 2005, 01:46:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Abbas Ali

This depends on client browser rather than server.

What we are doing -

  • Calling a php script random.php using XML HTTP Request from a pure HTML file
  • random.php prints the actual content returned from CpmFetch
  • We are populating a div with this content
  • You can use any element instead of div

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).


<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


<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


<?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.
Chief Geek at Ranium Systems

n3n

in firefox it works quite nice, but in IE (windows) it doesnt seem to work.
Have you tested it ?

Abbas Ali

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


onload = getPhotos();


from the above javascript and ADD


<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
Chief Geek at Ranium Systems

n3n

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.

Abbas Ali

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?
Chief Geek at Ranium Systems

n3n

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.


mona87

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!

explora57

Absolutely spot on done me a good turn here my friend thankyou vm.

Bill