0

I have the following problem. In the admin panel, I have a multiple image gallery. The user can select multiple pictures and save. The data are being played in the DB as follows:

<br />::nossos_trabalhos_galeria_x::3::/nossos_trabalhos_galeria_x::<br /><br />::nossos_trabalhos_galeria|0|nossos_trabalhos_galeria_x::images/nossos_trabalhos/53/lighthouse.jpg::/nossos_trabalhos_galeria|0|nossos_trabalhos_galeria_x::<br />::nossos_trabalhos_galeria|1|nossos_trabalhos_galeria_x::images/nossos_trabalhos/53/penguins.jpg::/nossos_trabalhos_galeria|1|nossos_trabalhos_galeria_x::<br />::nossos_trabalhos_galeria|2|nossos_trabalhos_galeria_x::images/nossos_trabalhos/53/koala.jpg::/nossos_trabalhos_galeria|2|nossos_trabalhos_galeria_x::<br />

So do a 'select' and caught the results:

$db = &JFactory::getDBO();

$table = '#__cck_store_form_nossos_trabalhos';

$select_query = "SELECT nossos_trabalhos_galeria_x FROM $table";

$db->setQuery($select_query);

$db->query();

$row = $db->loadRow();

But all that matters to me is the image path. Then I can separate his position by 'explode':

$r1 = explode('::',$row[0]);
var_dump($r1);

So I get the result:

array (size=17)
  0 => string '<br />' (length=6)
  1 => string 'nossos_trabalhos_galeria_x' (length=26)
  2 => string '3' (length=1)
  3 => string '/nossos_trabalhos_galeria_x' (length=27)
  4 => string '<br /><br />' (length=12)
  5 => string 'nossos_trabalhos_galeria|0|nossos_trabalhos_galeria_x' (length=53)
  6 => string 'images/nossos_trabalhos/53/lighthouse.jpg' (length=41)
  7 => string '/nossos_trabalhos_galeria|0|nossos_trabalhos_galeria_x' (length=54)
  8 => string '<br />' (length=6)
  9 => string 'nossos_trabalhos_galeria|1|nossos_trabalhos_galeria_x' (length=53)
  10 => string 'images/nossos_trabalhos/53/penguins.jpg' (length=39)
  11 => string '/nossos_trabalhos_galeria|1|nossos_trabalhos_galeria_x' (length=54)
  12 => string '<br />' (length=6)
  13 => string 'nossos_trabalhos_galeria|2|nossos_trabalhos_galeria_x' (length=53)
  14 => string 'images/nossos_trabalhos/53/koala.jpg' (length=36)
  15 => string '/nossos_trabalhos_galeria|2|nossos_trabalhos_galeria_x' (length=54)
  16 => string '<br />' (length=6)

My biggest question is, how can I get the image paths within the array to create a gallery?

----- EDIT -----

Thanks for the replies. Solved my problem in a very simple way. I called this same result through an option called joomla 'getValue', he brought me all the data within an array stdClass. Then it was just enough to do a foreach and call the position.

Red Vulpine
  • 433
  • 5
  • 17

3 Answers3

0

You are going to have to use a regular expression to check if a given item is an image URL. If it is then add it to a new array or do something with it.

Fabien Warniez
  • 2,731
  • 1
  • 21
  • 30
0

if you have multiple type of images then you can use following code to extract the image urls:

$ext  = array("jpg","jpeg","png","gif");

$gallery_url = array_filter(array_map(function($var) use($ext){return in_array(end(explode(".", $var)),$ext)?$var:false;}, $r1));
print_r($gallery_url);

gallery_url is an array having only image urls

EDIT: if images are same type then :

$gallery_url = array_filter(array_map(function($var){return end(explode(".", $var))=='jpg'?$var:false; },$r1));
Adesh Pandey
  • 769
  • 1
  • 9
  • 22
0

Well just for starters - if all the images are jpegs, then loop through the array and look for all lines that end with .jpg (or whatever the image type could be). To quote another question: startsWith() and endsWith() functions in PHP

Community
  • 1
  • 1
warwickf
  • 123
  • 6