Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request  (Read 17772 times)

0 Members and 1 Guest are viewing this topic.

Abbas Ali

  • Administrator
  • Coppermine addict
  • *****
  • Country: in
  • Offline Offline
  • Gender: Male
  • Posts: 2165
  • Spread the PHP Web
    • Ranium Systems
CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
« on: November 08, 2005, 01:46:13 pm »

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

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

n3n

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 173
Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
« Reply #1 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 ?
Logged

Abbas Ali

  • Administrator
  • Coppermine addict
  • *****
  • Country: in
  • Offline Offline
  • Gender: Male
  • Posts: 2165
  • Spread the PHP Web
    • Ranium Systems
Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
« Reply #2 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
Logged
Chief Geek at Ranium Systems

n3n

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 173
Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
« Reply #3 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.
Logged

Abbas Ali

  • Administrator
  • Coppermine addict
  • *****
  • Country: in
  • Offline Offline
  • Gender: Male
  • Posts: 2165
  • Spread the PHP Web
    • Ranium Systems
Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
« Reply #4 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?
Logged
Chief Geek at Ranium Systems

n3n

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 173
Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
« Reply #5 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.

Logged

mona87

  • Coppermine newbie
  • Offline Offline
  • Posts: 11
Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
« Reply #6 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!
Logged

explora57

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: CpmFetch - Using CpmFetch on HTML pages via XML HTTP Request
« Reply #7 on: November 20, 2008, 02:40:31 pm »

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

Bill
Logged
Pages: [1]   Go Up
 

Page created in 0.024 seconds with 20 queries.