Textpattern CMS support forum

You are not logged in. Register | Login | Help

#21 2009-05-13 17:34:08

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,781
Website

Re: soo_image: simple yet powerful image tags

Well, I think we’re getting closer. Add this line directly above the foreach block shown above:

_soo_echo($this->html_attributes());

and show me the resulting echo.


Code is topiary

Offline

#22 2009-05-13 17:42:46

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 983
Website

Re: soo_image: simple yet powerful image tags

Array: 1 item:
  alt: My alt text for image 33!

This is with the if ( $value or $property == 'alt') still commented out.

Last edited by johnstephens (2009-05-13 17:43:59)

Offline

#23 2009-05-13 17:51:10

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,781
Website

Re: soo_image: simple yet powerful image tags

OK, my guess is that this is a known bug that was fixed in PHP 5.2.4. Could be tricky to work around. What happens if you replace that last _soo_echo() call with _soo_echo($this->properties());

Edit: better make that a var_dump() instead — _soo_echo() is going to be prone to the same PHP bug.

Last edited by jsoo (2009-05-13 18:02:06)


Code is topiary

Offline

#24 2009-05-13 18:08:45

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 983
Website

Re: soo_image: simple yet powerful image tags

With if ( $value or $property == 'alt') still commented out, _soo_echo($this->properties())); gives me this:

 Array: 25 items:
  alt: My alt text for image 33!
  src: /images/33.png
  width: 305
  height: 299
  element_name: img
  is_empty: 1
  is_block: 
   Array: 0 item:
   Array: 0 item:
  class: 
  dir: 
  id: 
  lang: 
  onclick: 
  ondblclick: 
  onkeydown: 
  onkeypress: 
  onkeyup: 
  onmousedown: 
  onmousemove: 
  onmouseout: 
  onmouseover: 
  onmouseup: 
  style: 
  title: My caption for image 33!

Offline

#25 2009-05-13 18:22:46

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,781
Website

Re: soo_image: simple yet powerful image tags

Ugly, but:

Replace the first foreach block in tag() (the one we’ve been working on) with this:

		$hidden = array('element_name', 'is_empty', 'is_block', 'contents', 'can_contain');
		foreach ( $this->properties() as $property => $value )
			if ( ( $value or $property == 'alt' ) and !in_array($property, $hidden) )
				$out .= " $property=\"$value\"";

Code is topiary

Offline

#26 2009-05-13 18:42:21

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 983
Website

Re: soo_image: simple yet powerful image tags

It worked like magic— on both the <soo_image id="33" /> tag and on the select tag that pulls in images from Article Image field through my image-display form. The only idiosyncrasy I found was that it no longer displays the images in the order entered in the Article Image field— I entered “27,29,30,33,31,32”, and soo_image_select is showing them “27,32,33,30,29,31”.

Thank you again!

Last edited by johnstephens (2009-05-13 18:43:17)

Offline

#27 2009-05-13 18:55:53

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,781
Website

Re: soo_image: simple yet powerful image tags

Glad we’re getting somewhere. As to the images not appearing in sequence, that is a bug in soo_image_select(). Find this block in that function:

		if ( isset($ids) )
			$query->where_in('id', $ids);

and replace with

		if ( isset($ids) ) {
			$sort = '';
			$query->where_in('id', $ids)->order_by_field($ids);
		}

Let me know if that preserves the sequence of article-images, and I’ll put it in the next release.


Code is topiary

Offline

#28 2009-05-13 19:15:38

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 983
Website

Re: soo_image: simple yet powerful image tags

Looks like it sorted them into numeric order.

Article Image order: 27,29,30,33,31,32

Display order: 27,29,30,31,32,33

Offline

#29 2009-05-13 19:39:41

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,781
Website

Re: soo_image: simple yet powerful image tags

My mistake; I did not have the ORDER BY FIELD syntax correct. Try this instead:

		if ( isset($ids) ) {
			$sort = '';
			$query->where_in('id', $ids)->order_by_field('id', $ids);
		}

Edit: Oops, need to edit soo_txp_obj also. Soo_Txp_Data class, order_by_field() function, replace with:

	function order_by_field( $field, $list ) { // for preserving arbitrary order
		if ( is_string($list) ) $list = do_list($list);
		if ( count($list) > 1 )
			$this->order_by[] = 'field(' . $field . ', ' .
				implode(', ', quote_list(doSlash($list))) . ')';
	}

Last edited by jsoo (2009-05-13 19:57:08)


Code is topiary

Offline

#30 2009-05-13 19:57:42

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 983
Website

Re: soo_image: simple yet powerful image tags

Thanks— $query->where_in('id', $ids)->order_by_field('id', $ids); produces the same sort order as $query->where_in('id', $ids)->order_by_field($ids);.

Offline

Board footer

Powered by FluxBB