Source for file classes_elements_phi.php

Documentation is available at classes_elements_phi.php

  1. <?php
  2.  
  3. class title extends b_element {
  4.  
  5. function title( $id, &$object ) {
  6. //make a title element out of the given element
  7. parent::b_element( 'div', $id );
  8. //title text
  9. $this->appendChild( new b_element( 'h1', NULL, $object->get_index() ) );
  10. //title icon
  11. if( $object->icon ) {
  12. $icon =& $this->appendChild( new b_element( 'img', $id.'_icon', NULL, array( 'src'=>$object->icon) ) );
  13. }
  14. //title tagline
  15. if( $object->tagline ) {
  16. $this->appendChild( new b_element( 'div', $id.'_tagline', $object->tagline ) );
  17. }
  18. }
  19. }
  20.  
  21. class text_area extends b_element {
  22. var $previewLength = 50;
  23. function text_area( $id, &$object, $field ) {
  24. //make a text area out of the given object's given field
  25. parent::b_element( 'div', $id );
  26. //NOTE: text parsing here
  27. $contentPreview = substr( $object->$field, 0, $this->previewLength );
  28. $elipsis = '... ';
  29. $contentFull = substr( $object->$field, $this->previewLength + 1 );
  30. $this->appendChild( new b_element('div', $id.'_preview', $contentPreview ) );
  31. $this->appendChild( new b_element('div', $id.'_elipsis', $elipsis, array('style'=>'display:none') ) );
  32. $this->appendChild( new b_element('div', $id.'_full', $contentFull, array('style'=>'width:250px') ) );
  33. }
  34. }
  35.  
  36. class link extends b_element {
  37. function link( $content, $href = '#', $attrArray = array() ) {
  38. if( $attrArray['id'] ) {
  39. $name = $attrArray['id'];
  40. unset( $attrArray['id'] );
  41. } else {
  42. $name = NULL;
  43. }
  44. parent::b_element( 'a', $name, $content, $attrArray );
  45. }
  46. }
  47.  
  48. class slide_show extends b_element {
  49.  
  50. function slide_show( $id, &$object ) {
  51. //make a slideshow out of the given object
  52. parent::b_element( 'div', $id );
  53. $show_images =& $this->appendChild( new b_element( 'div', $id.'_images' ) );
  54. $show_thumbs =& $this->appendChild( new b_element( 'div', $id.'_thumbs' ) );
  55. $show_info =&$this->appendChild( new b_element( 'div', $id.'_data' ) );
  56. if( !$images =& $object->imageArray ) {
  57. if( $files =& $object->get_files() ) {
  58. foreach( $files as $file ) {
  59. if( $file->type->type_class_name == 'image' ) {
  60. $images[] =& $file;
  61. }
  62. }
  63. } else {
  64. $images = array();
  65. }
  66. }
  67. foreach( $images as $image ) {
  68. //set image
  69. $show_images->appendChild( new b_element( 'img', $id.'_images_'.$image->id, NULL, array( 'src'=>$image->path ) ) );
  70. //set thumbnail
  71. $show_images->appendChild( new b_element( 'img', $id.'_thumbs_'.$image->id, NULL, array( 'src'=>$image->thumb_path ) ) );
  72. //set description
  73. $data =& $show_images->appendChild( new b_element( 'div', $id.'_data_'.$image->id ) );
  74. $data->appendChild( new title( $id.'_data_'.$image->id.'_title', $image ) );
  75. $data->appendChild( new text_area( $id.'_data_'.$image->id.'_description', $image, 'description' ) );
  76. }
  77. }
  78. }
  79.  
  80. class meta_data extends b_element {
  81. function meta_data( $id ) {
  82. //make a metadata node
  83. parent::b_element( 'section', $id );
  84. }
  85. }
  86.  
  87.  
  88. class data extends b_element {
  89. function data( $function, $parameters = array() ) {
  90. parent::b_element( 'data', NULL, NULL, array('function'=>$function) );
  91. foreach( $parameters as $parameter ) {
  92. $param =& $this->appendChild( new b_element( 'parameter' ) );
  93. if( is_array($parameter) ) {
  94. $json = new JSON();
  95. $param->setAttribute( 'unserialize', 'true' );
  96. $param->appendChild( $json->encode( $parameter ) );
  97. //$param->appendChild(toJScriptArray( $parameter, '~' ));
  98. //$param->appendChild( serializeToJs( $parameter ) );
  99. } else {
  100. $param->appendChild( $parameter );
  101. }
  102. }
  103. }
  104. }
  105.  
  106. function toJScriptArray( $array ) {
  107. $retString = '{ ';
  108. foreach( $array as $key => $elem ) {
  109. if( is_array( $elem ) ) {
  110. $retString .= $key.' : '.toJScriptArray($elem).',';
  111. } else {
  112. $retString .= $key.' : '.$elem.',';
  113. }
  114. }
  115. $retString = rtrim($retString, ',');
  116. return $retString.' }';
  117. }
  118.  
  119. class cluster extends b_element {
  120. //var $id =& $this->attributes['id'];
  121. var $cluster_object;
  122. /*
  123. * the constructor takes three parameters
  124. * object_param: specifies the object which the cluster is to be built around
  125. * shallow: specifies the starting depth of the cluster to construct
  126. * deep: specifies the ending depth of the cluster to construct
  127. */
  128. function cluster( $object_param = NULL, $deep = NULL, $shallow = NULL ) {
  129. //format the cluster layer
  130. $this->id = $object_param?$object_param->id:'root';
  131. parent::b_element( 'cluster', $this->id, ' ');
  132.  
  133. if( $object_param ) {
  134. $this->cluster_object =& $object_param;
  135. $this->setAttribute( 'type', $object_param->type->type_name );
  136. //add content
  137. //add a title element
  138.  
  139. //if the object is a project
  140. //if there is a description
  141. //add a textarea
  142. //if there are pictures
  143. //add a slideshow
  144. //if the object is a post
  145. //add a textarea
  146. //$data->appendChild( new text_area( $this->cluster_object->id.'_textarea_text', $this->cluster_object, 'text' ) );
  147. //$this->set_state( NULL, 'default', array( $this->cluster_object->id.'_textarea_text' => array( 'onmousedown'=>'noDrag();' ) ) );
  148.  
  149. }
  150. }
  151. function &get_state( $stateName, $attribute = NULL ) {
  152. //locate state
  153. $stateNameFull = $this->attributes['id'].($attribute?'_'.$attribute:'').'_'.$stateName;
  154. $state =& $this->getElementById( $stateNameFull );
  155. if( !$state ) {
  156. //if the meta section hasn't been created, create it
  157. if( !$meta =& $this->getElementById( $this->attributes['id'].'_meta' ) ) {
  158. $meta =& $this->appendChild( new meta_data( $this->attributes['id'].'_meta' ) );
  159. }
  160.  
  161. //if attribute is specified find it and set it to be the state's parent
  162. if( $attribute && $attribute =& $this->getElementById( $this->attributes['id'].'_'.$attribute ) ) {
  163. $parent =& $meta->appendChild( new b_element( 'attribute', NULL, NULL, array( 'id'=>$this->attributes['id'].'_'.$attribute ) ) );
  164. } else {
  165. $parent =& $meta;
  166. }
  167. //append the state to the parent element
  168. if( $stateName == 'default' ) {
  169. $state =& $parent->appendChild( new b_element( 'default', NULL, NULL, array( 'id'=> $stateNameFull ) ) );
  170. } else {
  171. $state =& $parent->appendChild( new b_element( 'state', NULL, NULL, array( 'id'=> $stateNameFull ) ) );
  172. }
  173. }
  174. return $state;
  175. }
  176. function set_state( $attribute, $stateName = 'default', $values = array() ) {
  177. /*
  178. * when specifying state name, make sure to specify the partial name, not the full name of the element,
  179. * so for example if you wanted to set the state 'right' for attribute 'position' in cluster 'root',
  180. * attribute='position', stateName='right' (stateName != 'root_position_right')
  181. *
  182. * values should be an array of tag values indexed by target:
  183. * [target1][style][value],
  184. * [class][value],
  185. * [target2][style][value]...
  186. */
  187. $state =& $this->get_state( $stateName, $attribute );
  188.  
  189. //set existing tags
  190. if( $definedTags = $state->getElementsByTagName( 'tag' ) ) {
  191. foreach( $definedTags as $key => $tag ) {
  192. if( $target = $values[ $tag->attributes['target'] ] ) {
  193. $definedTags[$key]->setAttributes( $target, true );
  194. unset( $values[ $tag->attributes['target'] ] );
  195. }
  196. }
  197. }
  198.  
  199. //add new tags
  200. foreach( $values as $target => $attributes ) {
  201. $values[$target]['target'] = $target;
  202. $state->appendChild( new b_element( 'tag', NULL, NULL, $values[$target] ) );
  203. }
  204. }
  205. function set_states( $attribute, $states = array() ) {
  206. foreach( $states as $key => $state ) {
  207. $this->set_state( $attribute, $key, $state );
  208. }
  209. }
  210. function getLocalNav() {
  211. $retObj = new b_element( 'div', $this->id.'_localNav', ' ' );
  212. //get relationship types
  213. $related = array();
  214. if( $relationshipTypes =& $this->cluster_object->get_allowed_relationship_types() ) {
  215. foreach( $relationshipTypes as $relationshipType ) {
  216. $related = array_merge( $related, $relationshipType->get_byValue( array( array( 'attribute'=>'primaryID', 'operator'=>'=', 'value'=>$this->id ), array( 'attribute'=>'secondaryID', 'operator'=>'=', 'value'=>$this->id ) ) ) );
  217. }
  218. }
  219. //add links to related by type
  220. foreach( $relationshipTypes as $relationshipType ) {
  221. $rType =& $GLOBALS['core']->get_relationship_type( $relationshipType );
  222. $retObj->appendChild( new link( $rType->name, '#', array('onmouseover'=>'showRelated('.$this->id.','.$relationshipType.');') ) );
  223. }
  224. }
  225. }
  226.  
  227. ?>

Documentation generated on Tue, 24 May 2005 03:57:01 -0400 by phpDocumentor 1.3.0RC3