Source for file metadata-defs.php

Documentation is available at metadata-defs.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: metadata-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Various bits n pieces for maintaining metadata. */
  24. /* */
  25. /* ******************************************************************** */
  26. /** @package cm */
  27. include_once("recmaint-defs.php");
  28.  
  29. // -----------------------------------------------------------------------
  30. // Width of form elements..
  31.  
  32. $ewidth = "250px";
  33. $cwidth = "150px";
  34. $pwidth = "90px";
  35.  
  36. // -----------------------------------------------------------------------
  37. /**
  38. * A class which is derived from the generic tag class, and which is
  39. * specifically for the HTML META tag.
  40. * @package cm
  41. */
  42. class meta_tag extends HTMLtag {
  43. /** Constructor. Creates an empty HTML meta tag object. */
  44.  
  45. function meta_tag() {
  46. $this->HTMLtag("meta");
  47. }
  48. } // meta_tag class
  49. // -----------------------------------------------------------------------
  50.  
  51. /**
  52. * A class which encapsulates a meta tag which itself contains particular
  53. * information, which may be in a specified language, and may have been
  54. * picked from a defined vocabulary/encoding scheme.
  55. * @package cm
  56. */
  57. class data_meta_tag extends meta_tag {
  58. /**
  59. * Constructor
  60. * @param string $name The name of the metadata item
  61. * @param string $content The metadata information content itself
  62. * @param string $lang The language the content is in
  63. * @param string $scheme The scheme/vocabulary the content was picked from
  64. */
  65. function data_meta_tag($name, $content, $lang="", $scheme="") {
  66. $this->meta_tag();
  67. $this->add_attribute("name", $name);
  68. $this->add_attribute("content", $content);
  69. if ($lang != "") {
  70. $this->add_attribute("lang", $lang);
  71. }
  72. if ($scheme != "") {
  73. $this->add_attribute("scheme", $scheme);
  74. }
  75. } // data_meta_tag
  76.  
  77. } // data_meta_tag class
  78. // -----------------------------------------------------------------------
  79.  
  80. /**
  81. * A class which encapsulates a meta tag which represents a reference to
  82. * an item using a URL/URI.
  83. * @package cm
  84. */
  85. class uri_meta_tag extends meta_tag {
  86. /**
  87. * Constructor
  88. * @param string $rel The name of the metadata item for this reference
  89. * @param string $href The URL/URI for this reference
  90. * @param string $hreflang The language the refernced item is in
  91. */
  92. function uri_meta_tag($rel, $href, $hreflang="") {
  93. $this->meta_tag();
  94. $this->add_attribute("rel", $rel);
  95. $this->add_attribute("href", $href);
  96. if ($hreflang != "") {
  97. $this->add_attribute("hreflang", $hreflang);
  98. }
  99. } // uri_meta_tag
  100.  
  101. } // uri_meta_tag class
  102. // -----------------------------------------------------------------------
  103.  
  104. /**
  105. * A class which encapsulates a scheme qualifier. A qualifier is an
  106. * attribute which is used in a metadata tag to qualify or refine it.
  107. * Qualifiers can have default values or allowed lists of values, but
  108. * essentially they just allow the user to enter a string of content
  109. * against a named attribute in the meta tag.
  110. * @package cm
  111. */
  112. class enc_qualifier extends RenderableObject {
  113. /** Whether object contains valid data */
  114.  
  115. var $valid = false;
  116. /** Unique encoding scheme ID */
  117.  
  118. var $scheme_id = "";
  119. /** Name of this qualifier */
  120.  
  121. var $qual_name = "";
  122. /** Label for qualifier */
  123.  
  124. var $qual_label = "";
  125. /** Blurb regarding this qualifier */
  126.  
  127. var $comments = "";
  128. /** Default value of this qualifier */
  129.  
  130. var $default_value = "";
  131. /** Allowed list of values for this qualifier */
  132.  
  133. var $list_of_values = "";
  134. /** Display order */
  135.  
  136. var $display_order = 0;
  137. // .....................................................................
  138. /**
  139. * Constructor
  140. * @param integer $scheme_id Unique ID of this scheme
  141. * @param string $qualname Name of this qualifier
  142. */
  143. function enc_qualifier($scheme_id="", $qualname="") {
  144. $this->get($scheme_id, $qualname);
  145. } // enc_qualifier
  146. // .....................................................................
  147. /**
  148. * Get the data for this qualifier.
  149. * @param integer $scheme_id The unique ID of the scheme to get
  150. * @param string $qualname Name of this qualifier
  151. */
  152. function get($scheme_id="", $qual_name="") {
  153. $this->valid = false;
  154. if ($scheme_id != "") {
  155. $this->scheme_id = $scheme_id;
  156. }
  157. if ($qual_name != "") {
  158. $this->qual_name = $qual_name;
  159. }
  160. if ($this->scheme_id != "" && $this->qual_name != "") {
  161. $q = "SELECT * FROM ax_enc_qualifier";
  162. $q .= " WHERE enc_scheme_id=$this->scheme_id";
  163. $q .= " AND qual_name='" . escape_string($this->qual_name) . "'";
  164. $qual = dbrecordset($q);
  165. if ($qual->hasdata) {
  166. $this->qual_label = $qual->field("qual_label");
  167. $this->comments = $qual->field("comments");
  168. $this->default_value = $qual->field("default_value");
  169. $this->list_of_values = $qual->field("list_of_values");
  170. $this->display_order = $qual->field("display_order");
  171. $this->valid = true;
  172. }
  173. }
  174. return $this->valid;
  175. } // get
  176.  
  177.  
  178.  
  179. } // enc_qualifier class
  180. // -----------------------------------------------------------------------
  181.  
  182. /**
  183. * A class which encapsulates a metadata scheme. This is a set of
  184. * rules or a set of values (a vocabulary) designed to help people
  185. * when entering metadata. This class holds the details of the
  186. * scheme (name, tag, description), link(s) to resources on the scheme
  187. * and possibly values for it.
  188. * @package cm
  189. */
  190. class metadata_scheme extends RenderableObject {
  191. /** Whether object contains valid data */
  192.  
  193. var $valid = false;
  194. /** Unique encoding scheme ID */
  195.  
  196. var $scheme_id = "";
  197. /** Name of this encoding scheme */
  198.  
  199. var $enc_scheme_name = "";
  200. /** Label for scheme */
  201.  
  202. var $label = "";
  203. /** Scheme name to be used in meta tags */
  204.  
  205. var $tag_name = "";
  206. /** A description of the scheme */
  207.  
  208. var $description = "";
  209. /** URI of scheme data */
  210.  
  211. var $datasrc_uri = "";
  212. /** Reference URL for this scheme */
  213.  
  214. var $reference_url = "";
  215. /** Array of scheme key/value pairs */
  216.  
  217. var $values = array();
  218. /** Array of scheme qualifier objects */
  219.  
  220. var $qualifiers = array();
  221. /** Whether this is the 'preferred' scheme, of many */
  222.  
  223. var $preferred = false;
  224. // .....................................................................
  225. /**
  226. * Constructor
  227. * @param integer $scheme_id Unique ID of this scheme
  228. */
  229. function metadata_scheme($scheme_id="") {
  230. $this->get($scheme_id);
  231. } // metadata_scheme
  232. // .....................................................................
  233. /**
  234. * Get the data for this scheme.
  235. * @param integer $scheme_id The unique ID of the scheme to get
  236. * @return boolean Whether the get succeeded and object is valid
  237. */
  238. function get($scheme_id="") {
  239. $this->valid = false;
  240. if ($scheme_id != "") {
  241. $this->scheme_id = $scheme_id;
  242. }
  243. if ($this->scheme_id != "") {
  244. $q = "SELECT * FROM ax_enc_scheme";
  245. $q .= " WHERE enc_scheme_id=$this->scheme_id";
  246. $scheme = dbrecordset($q);
  247. if ($scheme->hasdata) {
  248. $this->enc_scheme_name = $scheme->field("enc_scheme_name");
  249. $this->label = $scheme->field("label");
  250. $this->tag_name = $scheme->field("tag_name");
  251. $this->description = $scheme->field("description");
  252. $this->datasrc_uri = $scheme->field("datasrc_uri");
  253. $this->reference_url = $scheme->field("reference_url");
  254. $this->valid = true;
  255. }
  256. // Data values..
  257. $this->values = array();
  258. $q = "SELECT * FROM ax_enc_value";
  259. $q .= " WHERE enc_scheme_id=$this->scheme_id";
  260. $q .= " ORDER BY enc_label";
  261. $enc_values = dbrecordset($q);
  262. if ($enc_values->hasdata) {
  263. do {
  264. $enc_label = $enc_values->field("enc_label");
  265. $enc_value = $enc_values->field("enc_value");
  266. $this->values[$enc_label] = $enc_value;
  267. } while ($enc_values->get_next());
  268. }
  269. // Qualifiers..
  270. $q = "SELECT qual_name FROM ax_enc_qualifier";
  271. $q .= " WHERE enc_scheme_id=$this->scheme_id";
  272. $q .= " ORDER BY display_order";
  273. $enc_quals = dbrecordset($q);
  274. if ($enc_quals->hasdata) {
  275. do {
  276. $qual_name = $enc_quals->field("qual_name");
  277. $qual = new enc_qualifier($this->scheme_id, $qual_name);
  278. if ($qual->valid) {
  279. $this->qualifiers[$qual_name] = $qual;
  280. }
  281. } while ($enc_quals->get_next());
  282. }
  283. }
  284. return $this->valid;
  285. } // get
  286.  
  287. // .....................................................................
  288. /**
  289. * Render this scheme as HTML. This produces a table containing the
  290. * schem in a format suitable for a metadata definition form. If only
  291. * a reference URL, then a simple URL is used, if values are available
  292. * then a combo is used, if a qualifier set is defined, then a special
  293. * qualifier assembly widget is displayed. In the latter two cases,
  294. * an end-result for content s produced, and you can pass in the name
  295. * of a javascript function to call to insert the result.
  296. * @param string $formname Name of the form this will go into
  297. * @param string $fieldname Name of form field to update when content defined
  298. * @param string $fieldvalue Initial value of form field we are updating
  299. * @param string $schemefield Name of form field of scheme to update
  300. */
  301. function definition_form($formname="", $fieldname="", $fieldvalue="", $schemefield="") {
  302. global $RESPONSE, $LIBDIR, $ewidth, $cwidth, $pwidth;
  303. $Tsch = new table("scheme_" . $this->scheme_id);
  304. $Tsch->setwidth("100%");
  305. $Tsch->setpadding(2);
  306.  
  307. $Tsch->tr("axbglite");
  308. $title = "<b>$this->label</b>";
  309.  
  310. if ($this->reference_url != "") {
  311. if ($this->tag_name != "") {
  312. $URLlabel = "($this->tag_name)";
  313. }
  314. else {
  315. $URLlabel = "(see reference)";
  316. }
  317. $schref = new anchor($this->reference_url, $URLlabel);
  318. $schref->settarget("_new");
  319. $title .= "&nbsp;" . $schref->render();
  320. }
  321. elseif ($this->tag_name != "") {
  322. $title .= " ($this->tag_name)";
  323. }
  324. if ($this->preferred) {
  325. $title .= " <span class=\"axhl\"><small>*preferred*</small></span>";
  326. }
  327. $Tsch->td($title, "axbglite");
  328. $Tsch->td_colspan(2);
  329. $Tsch->td_width("70%");
  330. $maxwords = 15;
  331. $words = explode(" ", $this->description);
  332. if (count($words) > $maxwords) {
  333. $pattern = "/(([\S]+[\s]+){1," . $maxwords . "})/";
  334. $matches = array();
  335. preg_match($pattern, $this->description, $matches);
  336. if (isset($matches[1])) {
  337. $desc = $matches[1];
  338. }
  339. else {
  340. $desc = $this->description;
  341. }
  342. $desc = "<span title=\"$this->description\">$desc</span>...";
  343. }
  344. else {
  345. $desc = $this->description;
  346. }
  347. $Tsch->td("<p>$desc</p>", "axbgdarker");
  348. $Tsch->td_alignment("", "top");
  349. $Tsch->td_width("30%");
  350. $Tsch->td_rowspan(2);
  351. $Tsch->td_css("padding:6px;");
  352.  
  353. $Fldname = "elem_" . $this->scheme_id . "_scheme";
  354. if (count($this->values) > 0) {
  355. $sch_F = new form_combofield($Fldname);
  356. $sch_F->setclass("axcombo");
  357. $sch_F->setstyle("width:$ewidth");
  358. foreach ($this->values as $label => $val) {
  359. $sch_F->additem($val, $label);
  360. }
  361. $sch_F->setvalue($fieldvalue);
  362. if ($fieldname != "") {
  363. $scr = "document.forms.$formname.$fieldname.value=this.value;";
  364. if ($schemefield != "") {
  365. $scr .= "document.forms.$formname.$schemefield.value='$this->scheme_id';";
  366. }
  367. $sch_F->set_onchange($scr);
  368. }
  369. $Tsch->tr("axbgdark");
  370. $Tsch->td("Values:", "axfg");
  371. $Tsch->td_alignment("", "top");
  372. $Tsch->td($sch_F->render());
  373. $Tsch->td_alignment("", "top");
  374. }
  375. elseif (count($this->qualifiers) > 0) {
  376. $Tq = new table($Fldname);
  377. $bset = new form_imagebutton("_set", "", "", "$LIBDIR/img/_set.gif", "Set as metadata content", 57, 15 );
  378. $bset->set_onclick("scheme_set('$this->scheme_id','$formname','$fieldname','$schemefield')");
  379. if ($fieldvalue != "") {
  380. $fieldvalues = explode(",", $fieldvalue);
  381. $initvalues = array();
  382. foreach ($fieldvalues as $val) {
  383. $bits = explode("=", $val);
  384. $qualname = trim($bits[0]);
  385. $qualval = trim($bits[1]);
  386. $initvalues[$qualname] = $qualval;
  387. }
  388. }
  389. $qual_listbox = new form_combofield($Fldname);
  390. $qual_listbox->setclass("axlistbox");
  391. $qual_listbox->setstyle("width:$ewidth;");
  392. $qual_listbox->size = 4;
  393. // Make a new record maintainer..
  394. $qual_maintainer = new recmaintainer($formname, $qual_listbox, "pfx$this->scheme_id");
  395. foreach ($this->qualifiers as $qual) {
  396. $qual_listbox->additem($qual->qual_name, $qual->qual_label);
  397. // Populate maintainer data. The maintainer add_record method
  398. // requires an associative array keyed on listbox key id..
  399. if (isset($initvalues[$qual->qual_name])) {
  400. $initvalue = $initvalues[$qual->qual_name];
  401. }
  402. else {
  403. $initvalue = "";
  404. }
  405. $rec = array(
  406. "qual_value" => $initvalue,
  407. "qual_comments" => $qual->comments
  408. );
  409. $qual_maintainer->add_record($qual->qual_name, $rec);
  410. }
  411. // ..................................................................
  412. // The listbox field..
  413. $Tq->tr("axbgdark");
  414. $Tq->td( "Qualifiers:", "axfg" );
  415. $Tq->td_alignment("", "top");
  416. $Tq->td( $qual_listbox->render() );
  417. $Tq->td_alignment("", "top");
  418. // ..................................................................
  419. // Value field
  420. $Fld = new form_textfield("qual_value");
  421. $Fld->setstyle("width:$ewidth;");
  422. $Fld->setclass("axtxtbox");
  423. if ($qual->default_value != "") {
  424. $Fld->setvalue($qual->default_value);
  425. }
  426. $qual_maintainer->register_field($Fld);
  427. $Tq->tr("axbglite");
  428. $Tq->td( "Value:", "axfg" );
  429. $Tq->td( $Fld->render() );
  430. // ..................................................................
  431. // Comments field
  432. $Fld = new form_memofield("qual_comments");
  433. $Fld->setstyle("width:$ewidth;height:80px;");
  434. $Fld->setclass("axmemo");
  435. $Fld->disabled = true;
  436. $qual_maintainer->register_field($Fld);
  437. $Tq->tr("axbgdark");
  438. $Tq->td( "Comments:", "axfg" );
  439. $Tq->td_alignment( "", "top" );
  440. $Tq->td( $Fld->render() );
  441. $Tq->tr("axbglite");
  442. $Tq->td( "&nbsp;" );
  443. $Tq->td( $bset->render() );
  444. $Tq->tr("axbglite");
  445. $Tq->td( $qual_maintainer->render() );
  446. $Tq->td_colspan(2);
  447. $Tq->set_width_profile("29%,71%");
  448. // Plug it in..
  449. $Tsch->tr("axbgdark");
  450. $Tsch->td($Tq->render());
  451. $Tsch->td_colspan(2);
  452. }
  453. elseif ($this->tag_name != "") {
  454. $sch_F = new form_textfield($Fldname);
  455. $sch_F->setclass("axtxtbox");
  456. $sch_F->setstyle("width:$ewidth");
  457. $sch_F->setvalue($fieldvalue);
  458. if ($fieldname != "") {
  459. $scr = "document.forms.$formname.$fieldname.value=this.value;";
  460. if ($schemefield != "") {
  461. $scr .= "document.forms.$formname.$schemefield.value='$this->scheme_id';";
  462. }
  463. $sch_F->set_onchange($scr);
  464. }
  465. $Tsch->tr("axbgdark");
  466. $Tsch->td("Value:");
  467. $Tsch->td_alignment("", "top");
  468. $Tsch->td($sch_F->render());
  469. $Tsch->td_alignment("", "top");
  470. }
  471. $Tsch->tr("axhdg");
  472. $Tsch->td();
  473. $Tsch->td_height(2);
  474. $Tsch->td_colspan(3);
  475. // Return rendered table..
  476. $Tsch->set_width_profile("20%,50%,30%");
  477. return $Tsch->render();
  478. } // definition_form
  479.  
  480.  
  481.  
  482. } // metadata_scheme class
  483. // -----------------------------------------------------------------------
  484.  
  485. /**
  486. * A class which encapsulates a metadata element. This is the actual
  487. * object which will be rendered into the end-user content (eg. the
  488. * webpage), and contains everything necessary for that process.
  489. * @package cm
  490. */
  491. class metadata_element extends RenderableObject {
  492. // CONTROL FLAGS etc.
  493. /** Whether info has been already got */
  494.  
  495. var $gotinfo = false;
  496. /** Whether schemes have been already got */
  497.  
  498. var $gotschemes = false;
  499. /** Whether object contains valid data */
  500.  
  501. var $valid = false;
  502. // METADATA ELEMENT
  503. /** The element ID for this item */
  504.  
  505. var $element_id = "";
  506. /** The element ID of the parent element of this item */
  507.  
  508. var $parent_element_id = "";
  509. /** Child element_ids of this element */
  510.  
  511. var $child_element_ids = array();
  512. /** Whether this element is instantiated as layout metadata */
  513.  
  514. var $instantiated = false;
  515. /** The meta schema that this item was sourced from */
  516.  
  517. var $schema_name = "";
  518. /** The namespace code for the schema */
  519.  
  520. var $schema_namespace = "";
  521. /** The refence URi for the schema */
  522.  
  523. var $schema_namespace_uri = "";
  524. /** The base name of this element */
  525.  
  526. var $element_name = "";
  527. /** The full tag name of this element */
  528.  
  529. var $tag_name = "";
  530. /** Label against the element value field */
  531.  
  532. var $label = "";
  533. /** Element description, usage details */
  534.  
  535. var $description = "";
  536. /** Whether this element should be indexed */
  537.  
  538. var $indexed = false;
  539. /** Whether this element can be searched for */
  540.  
  541. var $searchable = false;
  542. /** Whether optional, mandatory, conditional or recommended */
  543.  
  544. var $obligation = "o";
  545. /** Obligation, descriptive */
  546.  
  547. var $obligation_desc = "";
  548. /** The default value for this element */
  549.  
  550. var $default_value = "";
  551. /** A list of permitted element values */
  552.  
  553. var $list_of_values = "";
  554. /** Order of display */
  555.  
  556. var $display_order = 0;
  557. /** Schemes associated with this metadata element. This
  558. is an associative array keyed by scheme ID */
  559. var $schemes = array();
  560. /** ID of preferred scheme for this metadata element */
  561.  
  562. var $preferred_scheme_id = "";
  563. // METADATA DATA
  564. /** The content of this metadata tag. This is the actual metadata
  565. content which gets rendered in the HTML/XML tag itself */
  566. var $tag_value;
  567. /** Whether the tag value is actually a URL/URI */
  568.  
  569. var $linked_uri = false;
  570. /** The language of the content or resource referenced by URI */
  571.  
  572. var $language = "";
  573. /** The encoding scheme/vocabulary used to pick the tag content */
  574.  
  575. var $enc_scheme_id = "";
  576. /** The tag used to identify the encoding scheme used */
  577.  
  578. var $enc_scheme_tag = "";
  579. /** Whether this is a base element, or has a parent */
  580.  
  581. var $base_element = true;
  582. // .....................................................................
  583. /** Constructor */
  584.  
  585. function metadata_element($element_id="", $schema_name="") {
  586. $this->get($element_id, $schema_name);
  587. } // metadata_element
  588.  
  589. // .....................................................................
  590. /**
  591. * Get all the relevant data for this metadata element.
  592. * @param integer $element_id ID of this metadata element
  593. * @param string $schema_name Name of schema set this element belongs to
  594. * @return boolean Whether the get succeeded and object is valid
  595. */
  596. function get($element_id="", $schema_name="") {
  597. $this->valid = false;
  598. if ($element_id != "") {
  599. $this->element_id = $element_id;
  600. }
  601. if ($schema_name != "") {
  602. $this->schema_name = $schema_name;
  603. }
  604. if ($this->element_id != "" && $this->schema_name != "") {
  605. // Get the full metadata tag name..
  606. $q = "SELECT tag_name, parent_element";
  607. $q .= " FROM ax_meta_element";
  608. $q .= " WHERE element_id=$this->element_id";
  609. $elem = dbrecordset($q);
  610. if ($elem->hasdata) {
  611. $tag_name = $elem->field("tag_name");
  612. $this->element_name = $tag_name;
  613. $this->parent_element_id = $elem->field("parent_element");
  614. if ($this->parent_element_id != "") {
  615. $this->base_element = false;
  616. }
  617. $tag_name = get_full_tag_name($tag_name, $this->parent_element_id);
  618.  
  619. // Get schema details..
  620. $q = "SELECT * FROM ax_meta_schema";
  621. $q .= " WHERE schema_name='" . escape_string($this->schema_name) . "'";
  622. $schema = dbrecordset($q);
  623. if ($schema->hasdata) {
  624. $this->schema_namespace = $schema->field("namespace");
  625. $this->schema_namespace_uri = $schema->field("namespace_uri");
  626. }
  627. // Prefix the namespace identifier..
  628. if ($this->schema_namespace != "") {
  629. $tag_name = strtoupper($this->schema_namespace) . "." . $tag_name;
  630. }
  631. $this->tag_name = $tag_name;
  632. // Flag data is valid..
  633. $this->valid = true;
  634. }
  635. }
  636. return $this->valid;
  637. } // get
  638.  
  639. // .....................................................................
  640. /**
  641. * Get all the info which are associated with this metadata element.
  642. */
  643. function get_info() {
  644. if ($this->valid && !$this->gotinfo) {
  645. $q = "SELECT *";
  646. $q .= " FROM ax_site_meta_element";
  647. $q .= " WHERE element_id=$this->element_id";
  648. $q .= " AND schema_name='" . escape_string($this->schema_name) . "'";
  649. $elem = dbrecordset($q);
  650. if ($elem->hasdata) {
  651. $this->label = $elem->field("label");
  652. $this->description = $elem->field("description");
  653. $this->indexed = $elem->istrue("indexed");
  654. $this->searchable = $elem->istrue("searchable");
  655. $this->obligation = $elem->field("obligation");
  656. switch ($this->obligation) {
  657. case 'o': $this->obligation_desc = "Optional"; break;
  658. case 'm': $this->obligation_desc = "Mandatory"; break;
  659. case 'c': $this->obligation_desc = "Conditional"; break;
  660. case 'r': $this->obligation_desc = "Recommended"; break;
  661. default:
  662. $this->obligation_desc = "Unspecified";
  663. }
  664. $this->default_value = $elem->field("default_value");
  665. $this->list_of_values = $elem->field("list_of_values");
  666. $this->display_order = $elem->field("display_order");
  667. $this->gotinfo = true;
  668. }
  669. }
  670. } // get_info
  671.  
  672. // .....................................................................
  673. /**
  674. * Get all the schemes which are associated with this metadata element.
  675. */
  676. function get_schemes() {
  677. if ($this->valid && !$this->gotschemes) {
  678. $q = "SELECT es.preferred_enc_scheme,ese.enc_scheme_id";
  679. $q .= " FROM ax_meta_element_set es, ax_element_set_enc ese";
  680. $q .= " WHERE es.element_id=$this->element_id";
  681. $q .= " AND es.schema_name='" . escape_string($this->schema_name) . "'";
  682. $q .= " AND ese.element_id=es.element_id";
  683. $q .= " AND ese.schema_name=es.schema_name";
  684. $schemesQ = dbrecordset($q);
  685. if ($schemesQ->hasdata) {
  686. $this->schemes = array();
  687. $pref_scheme_id = $schemesQ->field("preferred_enc_scheme");
  688. if ($pref_scheme_id != "") {
  689. $scheme = new metadata_scheme($pref_scheme_id);
  690. if ($scheme->valid) {
  691. $scheme->preferred = true;
  692. $this->schemes[$pref_scheme_id] = $scheme;
  693. }
  694. }
  695. do {
  696. $scheme_id = $schemesQ->field("enc_scheme_id");
  697. $scheme = new metadata_scheme($scheme_id);
  698. if ($scheme->valid) {
  699. $this->schemes[$scheme_id] = $scheme;
  700. }
  701. } while ($schemesQ->get_next());
  702. }
  703. $this->gotschemes = true;
  704. }
  705. } // get_schemes
  706.  
  707. // .....................................................................
  708. /**
  709. * Inherit schemes from parent metadata elements. This involves a
  710. * traversal of the lineage (parentage) of this current metadata element
  711. * and retreival of the schemes of each one. Where the scheme is not
  712. * already associated with this element, it is added.
  713. */
  714. function inherit_schemes() {
  715. if (!$this->base_element) {
  716. $parent_elemid = $this->parent_element_id;
  717. while ($parent_elemid != "") {
  718. $q = "SELECT * FROM ax_element_set_enc ese, ax_meta_element e";
  719. $q .= " WHERE ese.element_id=$parent_elemid";
  720. $q .= " AND ese.schema_name='" . escape_string($this->schema_name) . "'";
  721. $q .= " AND e.element_id=ese.element_id";
  722. $parentschemes = dbrecordset($q);
  723. if ($parentschemes->hasdata) {
  724. do {
  725. $parent_elemid = $parentschemes->field("parent_element");
  726. $scheme_id = $parentschemes->field("enc_scheme_id");
  727. if (!in_array($scheme_id, $this->schemes)) {
  728. $scheme = new metadata_scheme($scheme_id);
  729. if ($scheme->valid) {
  730. $this->schemes[$scheme_id] = $scheme;
  731. }
  732. }
  733. } while ($parentschemes->get_next());
  734. }
  735. else {
  736. $parent_elemid = "";
  737. }
  738. } // while
  739. }
  740. } // inherit_schemes
  741.  
  742. // .....................................................................
  743. /**
  744. * Set the tag value of this meta data element. This is used when the
  745. * content is NOT a URI/URL. If it is, then use set_uri() instead.
  746. * @param string $val The value for this meta data element content
  747. */
  748. function set_tag_value($val) {
  749. $this->tag_value = $val;
  750. $this->linked_uri = false;
  751. } // set_tag_value
  752.  
  753. // .....................................................................
  754. /**
  755. * Set the tag value to be a URI. Same as setting tag value but we also
  756. * flick the uri flag as well.
  757. * @param string $href The URL/URI for this meta data element
  758. */
  759. function set_uri($uri) {
  760. $this->set_tag_value($uri);
  761. $this->linked_uri = true;
  762. } // set_uri
  763.  
  764. // .....................................................................
  765. /**
  766. * Set the language of the content of this meta data element
  767. * @param string $lang The language code for the content of this element
  768. */
  769. function set_language($lang) {
  770. $this->language = $lang;
  771. } // set_language
  772.  
  773. // .....................................................................
  774. /**
  775. * Set the scheme used to define the content of this meta data element. If
  776. * the tag of the scheme is not specified, then we go and find it by looking
  777. * up the scheme record in the DB.
  778. * @param integer $scheme_id The ID of the scheme used for picking the content
  779. * @param string $scheme_tag The tag name of the scheme
  780. */
  781. function set_scheme($scheme_id, $scheme_tag="") {
  782. $this->enc_scheme_id = $scheme_id;
  783. if ($scheme_tag != "") {
  784. $this->enc_scheme_tag = $scheme_tag;
  785. }
  786. else {
  787. $scheme = dbrecordset("SELECT * FROM ax_enc_scheme WHERE enc_scheme_id=$scheme_id");
  788. if ($scheme->hasdata) {
  789. $this->enc_scheme_tag = $scheme->field("tag_name");
  790. }
  791. }
  792. } // set_scheme
  793.  
  794. // .....................................................................
  795. /**
  796. * Render a definition form for this metadata element as HTML. This is a
  797. * self-contained table, and it has all of the element details, and fields
  798. * for setting the content, language, and scheme. It is not enclosed in
  799. * a form.
  800. * @return string An HTML rendering of metadata definition fields
  801. */
  802. function definition_form($formname="") {
  803. // Width of form elements..
  804. global $RESPONSE, $LIBDIR, $cwidth, $ewidth, $cwidth, $pwidth;
  805.  
  806. $this->get_info();
  807. $this->get_schemes();
  808.  
  809. // Generic script which inserts scheme data into metadata
  810. // form fields automatically on scheme data-entry..
  811. $RESPONSE->add_script(
  812. "function scheme_set(schid,fm,datfld,schfld) {\n"
  813. . " var datObj=eval('pfx'+schid+'dat_'+fm);\n"
  814. . " if (datObj!=null) {\n"
  815. . " var postData=findFieldObj(fm,datfld);\n"
  816. . " if (postData!=null) {\n"
  817. . " postData.value='';\n"
  818. . " for (var id in datObj) {\n"
  819. . " qual_value=getValue(fm,'qual_value',id,'pfx'+schid);\n"
  820. . " if (qual_value!='') {\n"
  821. . " if (postData.value!='') postData.value+='; ';\n"
  822. . " newqual=id+'='+qual_value;\n"
  823. . " postData.value+=newqual;\n"
  824. . " if (schfld != '') {\n"
  825. . " var postSche=findFieldObj(fm,schfld);\n"
  826. . " if (postSche != null) {\n"
  827. . " comboSet(postSche,schid);\n"
  828. . " }\n"
  829. . " }\n"
  830. . " }\n"
  831. . " }\n"
  832. . " }\n"
  833. . " }\n"
  834. . "}\n"
  835. );
  836.  
  837. $s = "";
  838. $Te = new table("eledef");
  839. $Te->setwidth("100%");
  840. $Te->setpadding(2);
  841.  
  842. // CONTENT SECTION
  843. $Te->tr("axbgdark");
  844. $Te->td("METADATA TAG COMPOSER", "axsubhdg");
  845. $Te->td_colspan(3);
  846.  
  847. $Te->tr("axbglite");
  848. $Te->td("<h2>$this->tag_name</h2>");
  849. $Te->td_colspan(2);
  850. $info = "<p><b>$this->label</b><br>";
  851. $maxwords = 30;
  852. $words = explode(" ", $this->description);
  853. if (count($words) > $maxwords) {
  854. $pattern = "/(([\S]+[\s]+){1," . $maxwords . "})/";
  855. $matches = array();
  856. preg_match($pattern, $this->description, $matches);
  857. if (isset($matches[1])) {
  858. $desc = $matches[1];
  859. }
  860. else {
  861. $desc = $this->description;
  862. }
  863. $desc = "<span title=\"$this->description\">$desc</span>...";
  864. }
  865. else {
  866. $desc = $this->description;
  867. }
  868. $info .= "$desc</p>";
  869. if ($this->obligation_desc != "" && $this->obligation_desc != "Unspecified") {
  870. $info .= "<p>This metadata element is $this->obligation_desc.</p>";
  871. }
  872. $Te->td($info, "axbgdarker");
  873. $Te->td_alignment("", "top");
  874. $Te->td_rowspan(6);
  875.  
  876. // Metadata Content
  877. if ($this->list_of_values != "") {
  878. $content_F = new form_combofield("elem_" . $this->element_id . "_content");
  879. $content_F->setclass("axcombo");
  880. $content_F->setstyle("width:$ewidth");
  881. $vals = explode(",", $this->list_of_values);
  882. foreach ($vals as $val) {
  883. $content_F->additem($val);
  884. }
  885. }
  886. else {
  887. $content_F = new form_memofield("elem_" . $this->element_id . "_content");
  888. $content_F->setclass("axmemo");
  889. $content_F->setstyle("width:$ewidth;height:60px");
  890. }
  891. if (isset($this->tag_value)) {
  892. $content_F->setvalue($this->tag_value);
  893. }
  894. elseif (isset($this->linked_uri)) {
  895. $content_F->setvalue($this->linked_uri);
  896. }
  897. elseif ($this->default_value != "") {
  898. $content_F->setvalue($this->default_value);
  899. }
  900. $Te->tr("axbgdark");
  901. $Te->td("Content:", "axfg");
  902. $Te->td_alignment("", "top");
  903. $Te->td_css("padding-top:3px");
  904. $Te->td($content_F->render());
  905. $Te->td_alignment("", "top");
  906.  
  907. // URI flag
  908. if ($this->list_of_values == "") {
  909. $chkUri_F = new form_checkbox("elem_" . $this->element_id . "_chkuri");
  910. $chkUri_F->setclass("axchkbox");
  911. $chkUri_F->checked = $this->linked_uri;
  912. $Te->tr("axbgdark");
  913. $Te->td("Content is a URI:", "axfg");
  914. $Te->td($chkUri_F->render());
  915. }
  916.  
  917. // Metadata Language
  918. $Te->tr("axbglite");
  919. $Te->td("Language code:", "axfg");
  920. $lang_F = new form_textfield("elem_" . $this->element_id . "_lang");
  921. $lang_F->setclass("axtxtbox");
  922. $lang_F->setstyle("width:$pwidth");
  923.  
  924. if (isset($this->language)) {
  925. $lang_F->setvalue($this->language);
  926. }
  927. $Te->td($lang_F->render());
  928.  
  929. // Metadata Scheme code
  930. $scheme_F = new form_combofield("elem_" . $this->element_id . "_scheme");
  931. $scheme_F->setclass("axcombo");
  932. $q = "SELECT * FROM ax_enc_scheme";
  933. $q .= " WHERE enabled=TRUE";
  934. $q .= " ORDER BY tag_name";
  935. $schQ = dbrecordset($q);
  936. $scheme_F->additem("");
  937. if ($schQ->hasdata) {
  938. do {
  939. $schid = $schQ->field("enc_scheme_id");
  940. $tag_name = $schQ->field("tag_name");
  941. if ($tag_name != "") {
  942. $scheme_F->additem($schid, $tag_name);
  943. }
  944. } while ($schQ->get_next());
  945. }
  946. if (isset($this->enc_scheme_id)) {
  947. $scheme_F->setvalue($this->enc_scheme_id);
  948. }
  949. $Te->tr("axbgdark");
  950. $Te->td("Scheme:", "axfg");
  951. $Te->td($scheme_F->render());
  952.  
  953. // A save button & done button
  954. $bsave = new form_imagebutton("save", "", "", "$LIBDIR/img/_save.gif", "Save metadata content", 57, 15 );
  955. $bdone = new form_imagebutton("done", "", "", "$LIBDIR/img/_done.gif", "Exit without saving", 57, 15 );
  956. $bsave->set_onclick("meta_action('save','$this->element_id','$this->schema_name')");
  957. $bdone->set_onclick("meta_action('done','$this->element_id','$this->schema_name')");
  958. $Te->tr("axbglite");
  959. $Te->td("&nbsp;");
  960. $Te->td($bsave->render() . "&nbsp;" . $bdone->render());
  961.  
  962. // LANGUAGES
  963. $Te->tr("axbglite");
  964. $Te->td("LANGUAGES", "axhdg");
  965. $Te->td_colspan(3);
  966. $q = "SELECT * FROM ax_enc_scheme WHERE enc_scheme_name LIKE 'ISO639%' ORDER BY enc_scheme_name";
  967. $iso639 = dbrecordset($q);
  968. if ($iso639->hasdata) {
  969. do {
  970. $iso639id = $iso639->field("enc_scheme_id");
  971. if ($iso639id != "") {
  972. $iso639_scheme = new metadata_scheme($iso639id);
  973. if ($iso639_scheme->valid) {
  974. $schdef = $iso639_scheme->definition_form(
  975. $formname,
  976. "elem_" . $this->element_id . "_lang"
  977. );
  978. $Te->tr("axbgdark");
  979. $Te->td( $schdef );
  980. $Te->td_colspan(3);
  981. }
  982. }
  983. } while ($iso639->get_next());
  984. }
  985.  
  986. // SCHEMES APPLICABLE TO THIS ELEMENT
  987. $Te->tr("axbglite");
  988. $Te->td("APPLICABLE SCHEMES", "axhdg");
  989. $Te->td_colspan(3);
  990. foreach ($this->schemes as $scheme) {
  991. $schdef = $scheme->definition_form(
  992. $formname,
  993. "elem_" . $this->element_id . "_content",
  994. "",
  995. "elem_" . $this->element_id . "_scheme"
  996. );
  997. $Te->tr("axbgdark");
  998. $Te->td( $schdef );
  999. $Te->td_colspan(3);
  1000. }
  1001. $Te->set_width_profile("20%,50%,30%");
  1002. return $Te->render();
  1003. } // definition_form
  1004.  
  1005. // .....................................................................
  1006. /**
  1007. * Process the POST of the form of this metadata element. We are just
  1008. * looking for the few fields containing the relevant data.
  1009. * NOTE: We do NOT save anything to the database, we just update our
  1010. * class variables with the newly POSTed data.
  1011. */
  1012. function POSTprocess() {
  1013. global $mode;
  1014. if (isset($mode) && $mode == "save") {
  1015. $pfx = "elem_" . $this->element_id;
  1016. $contentvar = $pfx . "_content";
  1017. $langvar = $pfx . "_lang";
  1018. $chkurivar = $pfx . "_chkuri";
  1019. $schemevar = $pfx . "_scheme";
  1020.  
  1021. global $$contentvar, $$langvar, $$chkurivar, $$schemevar;
  1022.  
  1023. $content = $$contentvar;
  1024. $language = $$langvar;
  1025. $chkUri = isset($$chkurivar);
  1026. $scheme_id = $$schemevar;
  1027.  
  1028. if ($chkUri) {
  1029. $this->set_uri($content);
  1030. }
  1031. else {
  1032. $this->set_tag_value($content);
  1033. }
  1034. if ($language != "") {
  1035. $this->set_language($language);
  1036. }
  1037. if ($scheme_id != "") {
  1038. $this->set_scheme($scheme_id);
  1039. }
  1040. }
  1041. } // POSTprocess
  1042.  
  1043. // .....................................................................
  1044. /**
  1045. * Render this metadata element as a metatag object. This method
  1046. * creates the metatag object and returns it.
  1047. * @return object The metadata element as a metatag object
  1048. */
  1049. function metatag() {
  1050. if ($this->linked_uri) {
  1051. $metatag = new uri_meta_tag(
  1052. $this->tag_name,
  1053. $this->tag_value,
  1054. $this->language
  1055. );
  1056. }
  1057. else {
  1058. $metatag = new data_meta_tag(
  1059. $this->tag_name,
  1060. $this->tag_value,
  1061. $this->language,
  1062. $this->enc_scheme_tag
  1063. );
  1064. }
  1065. return $metatag;
  1066. } // metatag
  1067.  
  1068. // .....................................................................
  1069. /**
  1070. * Render this metadata element as HTML.
  1071. * @return string The HTML rendering of this metadata element
  1072. */
  1073. function html() {
  1074. $meta = $this->metatag();
  1075. return $meta->html();
  1076. } // html
  1077.  
  1078.  
  1079.  
  1080. } // metadata_element class
  1081. // -----------------------------------------------------------------------
  1082.  
  1083. /**
  1084. * A class which holds multiple metadata elements, for a given layout.
  1085. * Acquires all the metadata elements for a given layout. Provides the
  1086. * means to render these.
  1087. * @package cm
  1088. */
  1089. class layout_metadata_elements {
  1090. // Public
  1091. /** The layout these elements are for */
  1092.  
  1093. var $layout_id = "";
  1094. /** The metadata elements themselves */
  1095.  
  1096. var $metadata_elements = array();
  1097.  
  1098. // Private
  1099. /** Standard form name to use
  1100. @access private */
  1101. var $formname = "";
  1102. // .....................................................................
  1103. /** Constructor
  1104. * @param integer $layout_id The unique ID of the layout
  1105. * @param string $formname The form name to use for form rendering
  1106. * @param boolean $instantiated_only True means get only existing meta data
  1107. */
  1108. function layout_metadata_elements($layout_id="", $formname="", $instantiated_only=false) {
  1109. $this->get($layout_id, $instantiated_only);
  1110. if ($formname == "") {
  1111. $formname = "layout_" . $this->layout_id . "_metadata";
  1112. }
  1113. $this->formname = $formname;
  1114. } // layout_metadata_elements
  1115. // .....................................................................
  1116. /**
  1117. * Get all of the metadata elements associated with this layout. We can
  1118. * do this in two modes, determined by the $instantiated_only flag. If
  1119. * this is true then we only grab the data for the metadata elements
  1120. * which exist for the layout. Otherwise we grab ALL of them. The
  1121. * latter is for editing, and the former is for page rendering where
  1122. * we want minimal Db traffic.
  1123. * @param integer $layout_id The ID of the layout to get elements for
  1124. * @return boolean Whether the get succeeded and object is valid
  1125. */
  1126. function get($layout_id="", $instantiated_only=false) {
  1127. if ($layout_id != "") {
  1128. $this->layout_id = $layout_id;
  1129. }
  1130. // Populate ALL metadata elements, as blanks..
  1131. if (!$instantiated_only) {
  1132. $q = "SELECT * FROM ax_site_meta_element";
  1133. $q .= " WHERE enabled=TRUE";
  1134. $q .= " ORDER BY display_order";
  1135. $allmeta = dbrecordset($q);
  1136. if ($allmeta->hasdata) {
  1137. do {
  1138. $element_id = $allmeta->field("element_id");
  1139. $schema_name = $allmeta->field("schema_name");
  1140. $meta = new metadata_element($element_id, $schema_name);
  1141. // Add this new element to our array..
  1142. $meta->get_info();
  1143. $this->add_metadata_element($meta);
  1144. } while ($allmeta->get_next());
  1145. }
  1146. }
  1147.  
  1148. // Overlay with metadata which has been defined..
  1149. if ($this->layout_id != "") {
  1150. $q = "SELECT * FROM ax_layout_metadata";
  1151. $q .= " WHERE layout_id=$this->layout_id";
  1152. $laymeta = dbrecordset($q);
  1153. if ($laymeta->hasdata) {
  1154. do {
  1155. $element_id = $laymeta->field("element_id");
  1156. $schema_name = $laymeta->field("schema_name");
  1157. $tag_value = $laymeta->field("meta_tag_value");
  1158. $scheme_id = $laymeta->field("enc_scheme_id");
  1159. $uri = $laymeta->istrue("linked_uri");
  1160. $language = $laymeta->field("language");
  1161. if ($instantiated_only) {
  1162. $meta = new metadata_element($element_id, $schema_name);
  1163. $meta->get_info();
  1164. }
  1165. else {
  1166. $meta = $this->get_metadata_element($element_id);
  1167. }
  1168. if ($meta !== false) {
  1169. $meta->instantiated = true;
  1170. if ($scheme_id != "") {
  1171. $meta->set_scheme($scheme_id);
  1172. }
  1173. if ($uri) {
  1174. $meta->set_uri($tag_value);
  1175. }
  1176. else {
  1177. $meta->set_tag_value($tag_value);
  1178. }
  1179. if ($language != "") {
  1180. $meta->set_language($language);
  1181. }
  1182. // Add this new element to our array..
  1183. $this->add_metadata_element($meta);
  1184. }
  1185. } while ($laymeta->get_next());
  1186. $this->valid = true;
  1187. }
  1188. }
  1189. } // get
  1190.  
  1191. // .....................................................................
  1192. /** Assembles all metadata elements for this layout. */
  1193.  
  1194. function perform_hierarchy_scan() {
  1195. // Determine hierarchical relationships between the
  1196. // metadata elements, ie. parent->child->child.. etc.
  1197. foreach ($this->metadata_elements as $element_id => $element) {
  1198. if (!$element->base_element && $element->parent_element_id != "") {
  1199. $parent_element = $this->get_metadata_element($element->parent_element_id);
  1200. if ($parent_element !== false) {
  1201. $parent_element->child_element_ids[] = $element_id;
  1202. $this->add_metadata_element($parent_element);
  1203. }
  1204. }
  1205. } // foreach
  1206. } // perform_hierarchy_scan
  1207.  
  1208. // .....................................................................
  1209. /** Returns the number of meta elements in this layout.
  1210. * @return integer Number of metadata elements currently in this layout
  1211. */
  1212. function meta_element_count() {
  1213. return count($this->metadata_elements);
  1214. } // meta_element_count
  1215.  
  1216. // .....................................................................
  1217. /**
  1218. * Return meta data tree entry.
  1219. * @return string The table containing all metadata elements so far.
  1220. * @access private
  1221. */
  1222. function metadata_tree_entry($Ttree, $indent, $element_id) {
  1223. global $RESPONSE, $LIBDIR, $cwidth, $ewidth, $cwidth, $pwidth;
  1224. // Write current element..
  1225. $element = $this->get_metadata_element($element_id);
  1226. if ($element !== false) {
  1227. // Do this present element..
  1228. $padding = new img("$LIBDIR/img/_pad.gif", "", "", (18 * $indent), 1);
  1229. $Ttree->tr("axbglite");
  1230. $elem_link = new anchor("#", $element->label);
  1231. if ($element->instantiated) {
  1232. $elem_link->set_onclick("meta_action('edit','$element->element_id','$element->schema_name')");
  1233. $bunset = new form_imagebutton("unset", "", "", "$LIBDIR/img/_redx.gif", "Un-set", 9, 9);
  1234. $bunset->set_onclick("meta_action('unset','$element->element_id','$element->schema_name')");
  1235. $Ttree->td($bunset->render(), "padding-top:5px");
  1236. $Ttree->td_alignment("", "top");
  1237. $Ttree->td($padding->render() . $elem_link->render(), "axfg");
  1238. $Ttree->td_alignment("", "top");
  1239. $Ttree->td(($element->tag_value != "") ? $element->tag_value : "&nbsp;");
  1240. $Ttree->td_alignment("", "top");
  1241. $Ttree->td(($element->language != "") ? $element->language : "&nbsp;");
  1242. $Ttree->td_alignment("center", "top");
  1243. $Ttree->td(($element->enc_scheme_tag != "") ? $element->enc_scheme_tag : "&nbsp;");
  1244. $Ttree->td_alignment("center", "top");
  1245. }
  1246. else {
  1247. $elem_link->set_onclick("meta_action('add','$element->element_id','$element->schema_name')");
  1248. $pad = new form_imagebutton("pad", "", "", "$LIBDIR/img/_pad.gif", "", 9, 1);
  1249. $Ttree->td($pad->render());
  1250. $Ttree->td($padding->render() . $elem_link->render(), "axfg");
  1251. $Ttree->td_alignment("", "top");
  1252. switch ($element->obligation) {
  1253. case "m": $msg = "<span class=\"axhl\">mandatory</span>"; break;
  1254. case "r": $msg = "recommended"; break;
  1255. default: $msg = "&nbsp;";
  1256. }
  1257. $Ttree->td($msg);
  1258. $Ttree->td_alignment("", "top");
  1259. $Ttree->td("&nbsp;");
  1260. $Ttree->td("&nbsp;");
  1261. }
  1262.  
  1263. // And now do any children..
  1264. if (count($element->child_element_ids) > 0) {
  1265. $child_indent = $indent + 1;
  1266. foreach ($element->child_element_ids as $child_element_id) {
  1267. $Ttree = $this->metadata_tree_entry($Ttree, $child_indent, $child_element_id);
  1268. }
  1269. }
  1270. }
  1271. // Return the tree table..
  1272. return $Ttree;
  1273. } // metadata_tree_entry
  1274.  
  1275. // .....................................................................
  1276. /**
  1277. * Returns a string containing a table which contains all of the meta
  1278. * data in a nice tree view.
  1279. * @return string A table containing all metadata elements for viewing
  1280. */
  1281. function metadata_tree() {
  1282. global $RESPONSE;
  1283. $this->perform_hierarchy_scan();
  1284. $Ttree = new table("metadata_tree");
  1285. $Ttree->setpadding(2);
  1286. $Ttree->td("&nbsp;");
  1287. $Ttree->td("<i>Tag</i>", "axfg");
  1288. $Ttree->td("<i>Content</i>", "axfg");
  1289. $Ttree->td("<i>Lang</i>", "axfg");
  1290. $Ttree->td_alignment("center");
  1291. $Ttree->td("<i>Scheme</i>", "axfg");
  1292. $Ttree->td_alignment("center");
  1293. foreach ($this->metadata_elements as $element_id => $element) {
  1294. if ($element->base_element) {
  1295. $indent = 0;
  1296. $Ttree = $this->metadata_tree_entry($Ttree, $indent, $element_id);
  1297. }
  1298. } // foreach
  1299. $Ttree->set_width_profile("1%,25%,49%,5%,20%");
  1300. // Return rendered content..
  1301. return $Ttree->render();
  1302. } // metadata_tree
  1303.  
  1304. // .....................................................................
  1305. /**
  1306. * Add a metadata element to our array of elements. We add it to an
  1307. * associative array keyed on the element_id, ensuring no duplicates.
  1308. * @param object $meta The metadata element object to add
  1309. */
  1310. function add_metadata_element($meta) {
  1311. $this->metadata_elements[$meta->element_id] = $meta;
  1312. } // add_metadata_element
  1313.  
  1314. // .....................................................................
  1315. /**
  1316. * Return a metadata element, given its element_id.
  1317. * @param integer $element_id The element ID of the element to return
  1318. */
  1319. function get_metadata_element($element_id) {
  1320. if (isset($this->metadata_elements[$element_id])) {
  1321. return $this->metadata_elements[$element_id];
  1322. }
  1323. else {
  1324. return false;
  1325. }
  1326. } // get_metadata_element
  1327. // .....................................................................
  1328. /**
  1329. * Saves the layout metadata for a given element. This saves data to
  1330. * the ax_layout_metadata table.
  1331. * @param integer $element_id The element ID of the element to return
  1332. */
  1333. function save_metadata_element($element_id) {
  1334. $element = $this->get_metadata_element($element_id);
  1335. if ($element !== false) {
  1336. if ($element->instantiated) {
  1337. $meup = new dbupdate("ax_layout_metadata");
  1338. $meup->where("layout_id=$this->layout_id");
  1339. $meup->where("AND element_id=$element->element_id");
  1340. $meup->where("AND schema_name='" . escape_string($element->schema_name) . "'");
  1341. }
  1342. else {
  1343. $meup = new dbinsert("ax_layout_metadata");
  1344. $meup->set("layout_id", $this->layout_id);
  1345. $meup->set("element_id", $element->element_id);
  1346. $meup->set("schema_name", $element->schema_name);
  1347. }
  1348. $meup->set("meta_tag_value", $element->tag_value);
  1349. if ($element->enc_scheme_id != "") {
  1350. $meup->set("enc_scheme_id", $element->enc_scheme_id);
  1351. }
  1352. else {
  1353. $meup->set("enc_scheme_id", NULLVALUE);
  1354. }
  1355. $meup->set("linked_uri", $element->linked_uri);
  1356. $meup->set("language", $element->language);
  1357. $ok = $meup->execute();
  1358.  
  1359. // Alter instantiation status if created new..
  1360. if (!$element->instantiated && $ok) {
  1361. $element->instantiated = true;
  1362. $this->add_metadata_element($element);
  1363. }
  1364. }
  1365. } // save_metadata_element
  1366. // .....................................................................
  1367. /**
  1368. * Removes the layout metadata for a given element. This deletes the
  1369. * relevant record from the ax_layout_metadata table.
  1370. * @param integer $element_id The element ID of the element to remove
  1371. */
  1372. function remove_metadata_element($element_id) {
  1373. $element = $this->get_metadata_element($element_id);
  1374. if ($element !== false && $element->instantiated) {
  1375. $medel = new dbdelete("ax_layout_metadata");
  1376. $medel->where("layout_id=$this->layout_id");
  1377. $medel->where("AND element_id=$element->element_id");
  1378. $medel->where("AND schema_name='" . escape_string($element->schema_name) . "'");
  1379. $medel->execute();
  1380. }
  1381. } // remove_metadata_element
  1382. // .....................................................................
  1383. /**
  1384. * Insert the instantiated metatags into the given webpage. This is
  1385. * intended to be used on the $RESPONSE object to actually jam the
  1386. * tags for this layout into the webapage.
  1387. * @param reference Reference to Webpage object to insert metatags into
  1388. */
  1389. function insert_metatags(&$webpage) {
  1390. global $RESPONSE;
  1391. foreach ($this->metadata_elements as $element_id => $element) {
  1392. if ($element->instantiated) {
  1393. $metatag = $element->metatag();
  1394. $RESPONSE->insert_metatag($element_id, $metatag);
  1395. }
  1396. }
  1397. } // insert_metatags
  1398. // .....................................................................
  1399. /**
  1400. * Render all of the elements as HTML
  1401. * @return string HTML rendering of all contained metadata elements
  1402. */
  1403. function html() {
  1404. $s = "";
  1405. foreach ($this->metadata_elements as $element_id => $element) {
  1406. if ($element->instantiated) {
  1407. $s .= $element->html();
  1408. }
  1409. }
  1410. return $s;
  1411. } // html
  1412.  
  1413.  
  1414.  
  1415. } // layout_metadata_elements class
  1416. // -----------------------------------------------------------------------
  1417.  
  1418. /**
  1419. * Function to format a tag name which might have multiple parents.
  1420. * The expected format is that the sequence of tag names will each
  1421. * be separated by a dot ".". Here we just format it with the first
  1422. * descendant lowercased, and all others proper-cased.
  1423. * @param string $tag_name The tag name, with descendants separated by dots
  1424. */
  1425. function format_tag_name($tag_name) {
  1426. $result = $tag_name;
  1427. $bits = explode(".", $tag_name);
  1428. if (count($bits) > 1) {
  1429. $fmtarr = array();
  1430. $first = true;
  1431. foreach ($bits as $tagbit) {
  1432. if ($first) {
  1433. $fmtarr[] = strtolower($tagbit);
  1434. $first = false;
  1435. }
  1436. else {
  1437. $fmtarr[] = ucfirst($tagbit);
  1438. }
  1439. }
  1440. $result = implode(".", $fmtarr);
  1441. }
  1442. return $result;
  1443. } // format_tag_name
  1444. // -----------------------------------------------------------------------
  1445.  
  1446. /**
  1447. * Function to acquire the full tag name including descendants, given
  1448. * the tag name, and the parent element ID of that tag.
  1449. * @param string $tag_name The starting tag name
  1450. * @param integer $parent_elemid The parent element ID of that tag
  1451. * @return string The full descendant tag name
  1452. */
  1453. function get_full_tag_name($tag_name, $parent_elemid) {
  1454. while ($parent_elemid != "") {
  1455. $parent = dbrecordset("SELECT tag_name FROM ax_meta_element WHERE element_id=$parent_elemid");
  1456. if ($parent->hasdata) {
  1457. $tag_name = $parent->field("tag_name") . "." . $tag_name;
  1458. $parent_elemid = $parent->field("parent_element");
  1459. }
  1460. else {
  1461. $parent_elemid = "";
  1462. }
  1463. }
  1464. return $tag_name;
  1465. } // get_full_tag_name
  1466. // -----------------------------------------------------------------------
  1467.  
  1468. ?>

Documentation generated by phpDocumentor 1.3.0RC3