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='" . addslashes($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. preg_match($pattern, $this->description, $matches);
  335. if (isset($matches[1])) {
  336. $desc = $matches[1];
  337. }
  338. else {
  339. $desc = $this->description;
  340. }
  341. $desc = "<span title=\"$this->description\">$desc</span>...";
  342. }
  343. else {
  344. $desc = $this->description;
  345. }
  346. $Tsch->td("<p>$desc</p>", "axbgdarker");
  347. $Tsch->td_alignment("", "top");
  348. $Tsch->td_width("30%");
  349. $Tsch->td_rowspan(2);
  350. $Tsch->td_css("padding:6px;");
  351.  
  352. $Fldname = "elem_" . $this->scheme_id . "_scheme";
  353. if (count($this->values) > 0) {
  354. $sch_F = new form_combofield($Fldname);
  355. $sch_F->setclass("axcombo");
  356. $sch_F->setstyle("width:$ewidth");
  357. foreach ($this->values as $label => $val) {
  358. $sch_F->additem($val, $label);
  359. }
  360. $sch_F->setvalue($fieldvalue);
  361. if ($fieldname != "") {
  362. $scr = "document.forms.$formname.$fieldname.value=this.value;";
  363. if ($schemefield != "") {
  364. $scr .= "document.forms.$formname.$schemefield.value='$this->scheme_id';";
  365. }
  366. $sch_F->set_onchange($scr);
  367. }
  368. $Tsch->tr("axbgdark");
  369. $Tsch->td("Values:", "axfg");
  370. $Tsch->td_alignment("", "top");
  371. $Tsch->td($sch_F->render());
  372. $Tsch->td_alignment("", "top");
  373. }
  374. elseif (count($this->qualifiers) > 0) {
  375. $Tq = new table($Fldname);
  376. $bset = new form_imagebutton("_set", "", "", "$LIBDIR/img/_set.gif", "Set as metadata content", 57, 15 );
  377. $bset->set_onclick("scheme_set('$this->scheme_id','$formname','$fieldname','$schemefield')");
  378. if ($fieldvalue != "") {
  379. $fieldvalues = explode(",", $fieldvalue);
  380. $initvalues = array();
  381. foreach ($fieldvalues as $val) {
  382. $bits = explode("=", $val);
  383. $qualname = trim($bits[0]);
  384. $qualval = trim($bits[1]);
  385. $initvalues[$qualname] = $qualval;
  386. }
  387. }
  388. $qual_listbox = new form_combofield($Fldname);
  389. $qual_listbox->setclass("axlistbox");
  390. $qual_listbox->setstyle("width:$ewidth;");
  391. $qual_listbox->size = 4;
  392. // Make a new record maintainer..
  393. $qual_maintainer = new recmaintainer($formname, $qual_listbox, "pfx$this->scheme_id");
  394. foreach ($this->qualifiers as $qual) {
  395. $qual_listbox->additem($qual->qual_name, $qual->qual_label);
  396. // Populate maintainer data. The maintainer add_record method
  397. // requires an associative array keyed on listbox key id..
  398. if (isset($initvalues[$qual->qual_name])) {
  399. $initvalue = $initvalues[$qual->qual_name];
  400. }
  401. else {
  402. $initvalue = "";
  403. }
  404. $rec = array(
  405. "qual_value" => $initvalue,
  406. "qual_comments" => $qual->comments
  407. );
  408. $qual_maintainer->add_record($qual->qual_name, $rec);
  409. }
  410. // ..................................................................
  411. // The listbox field..
  412. $Tq->tr("axbgdark");
  413. $Tq->td( "Qualifiers:", "axfg" );
  414. $Tq->td_alignment("", "top");
  415. $Tq->td( $qual_listbox->render() );
  416. $Tq->td_alignment("", "top");
  417. // ..................................................................
  418. // Value field
  419. $Fld = new form_textfield("qual_value");
  420. $Fld->setstyle("width:$ewidth;");
  421. $Fld->setclass("axtxtbox");
  422. if ($qual->default_value != "") {
  423. $Fld->setvalue($qual->default_value);
  424. }
  425. $qual_maintainer->register_field($Fld);
  426. $Tq->tr("axbglite");
  427. $Tq->td( "Value:", "axfg" );
  428. $Tq->td( $Fld->render() );
  429. // ..................................................................
  430. // Comments field
  431. $Fld = new form_memofield("qual_comments");
  432. $Fld->setstyle("width:$ewidth;height:80px;");
  433. $Fld->setclass("axmemo");
  434. $Fld->disabled = true;
  435. $qual_maintainer->register_field($Fld);
  436. $Tq->tr("axbgdark");
  437. $Tq->td( "Comments:", "axfg" );
  438. $Tq->td_alignment( "", "top" );
  439. $Tq->td( $Fld->render() );
  440. $Tq->tr("axbglite");
  441. $Tq->td( "&nbsp;" );
  442. $Tq->td( $bset->render() );
  443. $Tq->tr("axbglite");
  444. $Tq->td( $qual_maintainer->render() );
  445. $Tq->td_colspan(2);
  446. $Tq->set_width_profile("29%,71%");
  447. // Plug it in..
  448. $Tsch->tr("axbgdark");
  449. $Tsch->td($Tq->render());
  450. $Tsch->td_colspan(2);
  451. }
  452. elseif ($this->tag_name != "") {
  453. $sch_F = new form_textfield($Fldname);
  454. $sch_F->setclass("axtxtbox");
  455. $sch_F->setstyle("width:$ewidth");
  456. $sch_F->setvalue($fieldvalue);
  457. if ($fieldname != "") {
  458. $scr = "document.forms.$formname.$fieldname.value=this.value;";
  459. if ($schemefield != "") {
  460. $scr .= "document.forms.$formname.$schemefield.value='$this->scheme_id';";
  461. }
  462. $sch_F->set_onchange($scr);
  463. }
  464. $Tsch->tr("axbgdark");
  465. $Tsch->td("Value:");
  466. $Tsch->td_alignment("", "top");
  467. $Tsch->td($sch_F->render());
  468. $Tsch->td_alignment("", "top");
  469. }
  470. $Tsch->tr("axhdg");
  471. $Tsch->td();
  472. $Tsch->td_height(2);
  473. $Tsch->td_colspan(3);
  474. // Return rendered table..
  475. $Tsch->set_width_profile("20%,50%,30%");
  476. return $Tsch->render();
  477. } // definition_form
  478.  
  479.  
  480.  
  481. } // metadata_scheme class
  482. // -----------------------------------------------------------------------
  483.  
  484. /**
  485. * A class which encapsulates a metadata element. This is the actual
  486. * object which will be rendered into the end-user content (eg. the
  487. * webpage), and contains everything necessary for that process.
  488. * @package cm
  489. */
  490. class metadata_element extends RenderableObject {
  491. // CONTROL FLAGS etc.
  492. /** Whether info has been already got */
  493.  
  494. var $gotinfo = false;
  495. /** Whether schemes have been already got */
  496.  
  497. var $gotschemes = false;
  498. /** Whether object contains valid data */
  499.  
  500. var $valid = false;
  501. // METADATA ELEMENT
  502. /** The element ID for this item */
  503.  
  504. var $element_id = "";
  505. /** The element ID of the parent element of this item */
  506.  
  507. var $parent_element_id = "";
  508. /** Child element_ids of this element */
  509.  
  510. var $child_element_ids = array();
  511. /** Whether this element is instantiated as layout metadata */
  512.  
  513. var $instantiated = false;
  514. /** The meta schema that this item was sourced from */
  515.  
  516. var $schema_name = "";
  517. /** The namespace code for the schema */
  518.  
  519. var $schema_namespace = "";
  520. /** The refence URi for the schema */
  521.  
  522. var $schema_namespace_uri = "";
  523. /** The base name of this element */
  524.  
  525. var $element_name = "";
  526. /** The full tag name of this element */
  527.  
  528. var $tag_name = "";
  529. /** Label against the element value field */
  530.  
  531. var $label = "";
  532. /** Element description, usage details */
  533.  
  534. var $description = "";
  535. /** Whether this element should be indexed */
  536.  
  537. var $indexed = false;
  538. /** Whether this element can be searched for */
  539.  
  540. var $searchable = false;
  541. /** Whether optional, mandatory, conditional or recommended */
  542.  
  543. var $obligation = "o";
  544. /** Obligation, descriptive */
  545.  
  546. var $obligation_desc = "";
  547. /** The default value for this element */
  548.  
  549. var $default_value = "";
  550. /** A list of permitted element values */
  551.  
  552. var $list_of_values = "";
  553. /** Order of display */
  554.  
  555. var $display_order = 0;
  556. /** Schemes associated with this metadata element. This
  557. is an associative array keyed by scheme ID */
  558. var $schemes = array();
  559. /** ID of preferred scheme for this metadata element */
  560.  
  561. var $preferred_scheme_id = "";
  562. // METADATA DATA
  563. /** The content of this metadata tag. This is the actual metadata
  564. content which gets rendered in the HTML/XML tag itself */
  565. var $tag_value;
  566. /** Whether the tag value is actually a URL/URI */
  567.  
  568. var $linked_uri = false;
  569. /** The language of the content or resource referenced by URI */
  570.  
  571. var $language = "";
  572. /** The encoding scheme/vocabulary used to pick the tag content */
  573.  
  574. var $enc_scheme_id = "";
  575. /** The tag used to identify the encoding scheme used */
  576.  
  577. var $enc_scheme_tag = "";
  578. /** Whether this is a base element, or has a parent */
  579.  
  580. var $base_element = true;
  581. // .....................................................................
  582. /** Constructor */
  583.  
  584. function metadata_element($element_id="", $schema_name="") {
  585. $this->get($element_id, $schema_name);
  586. } // metadata_element
  587.  
  588. // .....................................................................
  589. /**
  590. * Get all the relevant data for this metadata element.
  591. * @param integer $element_id ID of this metadata element
  592. * @param string $schema_name Name of schema set this element belongs to
  593. * @return boolean Whether the get succeeded and object is valid
  594. */
  595. function get($element_id="", $schema_name="") {
  596. $this->valid = false;
  597. if ($element_id != "") {
  598. $this->element_id = $element_id;
  599. }
  600. if ($schema_name != "") {
  601. $this->schema_name = $schema_name;
  602. }
  603. if ($this->element_id != "" && $this->schema_name != "") {
  604. // Get the full metadata tag name..
  605. $q = "SELECT tag_name, parent_element";
  606. $q .= " FROM ax_meta_element";
  607. $q .= " WHERE element_id=$this->element_id";
  608. $elem = dbrecordset($q);
  609. if ($elem->hasdata) {
  610. $tag_name = $elem->field("tag_name");
  611. $this->element_name = $tag_name;
  612. $this->parent_element_id = $elem->field("parent_element");
  613. if ($this->parent_element_id != "") {
  614. $this->base_element = false;
  615. }
  616. $tag_name = get_full_tag_name($tag_name, $this->parent_element_id);
  617.  
  618. // Get schema details..
  619. $q = "SELECT * FROM ax_meta_schema";
  620. $q .= " WHERE schema_name='" . addslashes($this->schema_name) . "'";
  621. $schema = dbrecordset($q);
  622. if ($schema->hasdata) {
  623. $this->schema_namespace = $schema->field("namespace");
  624. $this->schema_namespace_uri = $schema->field("namespace_uri");
  625. }
  626. // Prefix the namespace identifier..
  627. if ($this->schema_namespace != "") {
  628. $tag_name = strtoupper($this->schema_namespace) . "." . $tag_name;
  629. }
  630. $this->tag_name = $tag_name;
  631. // Flag data is valid..
  632. $this->valid = true;
  633. }
  634. }
  635. return $this->valid;
  636. } // get
  637.  
  638. // .....................................................................
  639. /**
  640. * Get all the info which are associated with this metadata element.
  641. */
  642. function get_info() {
  643. if ($this->valid && !$this->gotinfo) {
  644. $q = "SELECT *";
  645. $q .= " FROM ax_site_meta_element";
  646. $q .= " WHERE element_id=$this->element_id";
  647. $q .= " AND schema_name='" . addslashes($this->schema_name) . "'";
  648. $elem = dbrecordset($q);
  649. if ($elem->hasdata) {
  650. $this->label = $elem->field("label");
  651. $this->description = $elem->field("description");
  652. $this->indexed = $elem->istrue("indexed");
  653. $this->searchable = $elem->istrue("searchable");
  654. $this->obligation = $elem->field("obligation");
  655. switch ($this->obligation) {
  656. case 'o': $this->obligation_desc = "Optional"; break;
  657. case 'm': $this->obligation_desc = "Mandatory"; break;
  658. case 'c': $this->obligation_desc = "Conditional"; break;
  659. case 'r': $this->obligation_desc = "Recommended"; break;
  660. default:
  661. $this->obligation_desc = "Unspecified";
  662. }
  663. $this->default_value = $elem->field("default_value");
  664. $this->list_of_values = $elem->field("list_of_values");
  665. $this->display_order = $elem->field("display_order");
  666. $this->gotinfo = true;
  667. }
  668. }
  669. } // get_info
  670.  
  671. // .....................................................................
  672. /**
  673. * Get all the schemes which are associated with this metadata element.
  674. */
  675. function get_schemes() {
  676. if ($this->valid && !$this->gotschemes) {
  677. $q = "SELECT es.preferred_enc_scheme,ese.enc_scheme_id";
  678. $q .= " FROM ax_meta_element_set es, ax_element_set_enc ese";
  679. $q .= " WHERE es.element_id=$this->element_id";
  680. $q .= " AND es.schema_name='" . addslashes($this->schema_name) . "'";
  681. $q .= " AND ese.element_id=es.element_id";
  682. $q .= " AND ese.schema_name=es.schema_name";
  683. $schemesQ = dbrecordset($q);
  684. if ($schemesQ->hasdata) {
  685. $this->schemes = array();
  686. $pref_scheme_id = $schemesQ->field("preferred_enc_scheme");
  687. if ($pref_scheme_id != "") {
  688. $scheme = new metadata_scheme($pref_scheme_id);
  689. if ($scheme->valid) {
  690. $scheme->preferred = true;
  691. $this->schemes[$pref_scheme_id] = $scheme;
  692. }
  693. }
  694. do {
  695. $scheme_id = $schemesQ->field("enc_scheme_id");
  696. $scheme = new metadata_scheme($scheme_id);
  697. if ($scheme->valid) {
  698. $this->schemes[$scheme_id] = $scheme;
  699. }
  700. } while ($schemesQ->get_next());
  701. }
  702. $this->gotschemes = true;
  703. }
  704. } // get_schemes
  705.  
  706. // .....................................................................
  707. /**
  708. * Inherit schemes from parent metadata elements. This involves a
  709. * traversal of the lineage (parentage) of this current metadata element
  710. * and retreival of the schemes of each one. Where the scheme is not
  711. * already associated with this element, it is added.
  712. */
  713. function inherit_schemes() {
  714. if (!$this->base_element) {
  715. $parent_elemid = $this->parent_element_id;
  716. while ($parent_elemid != "") {
  717. $q = "SELECT * FROM ax_element_set_enc ese, ax_meta_element e";
  718. $q .= " WHERE ese.element_id=$parent_elemid";
  719. $q .= " AND ese.schema_name='" . addslashes($this->schema_name) . "'";
  720. $q .= " AND e.element_id=ese.element_id";
  721. $parentschemes = dbrecordset($q);
  722. if ($parentschemes->hasdata) {
  723. do {
  724. $parent_elemid = $parentschemes->field("parent_element");
  725. $scheme_id = $parentschemes->field("enc_scheme_id");
  726. if (!in_array($scheme_id, $this->schemes)) {
  727. $scheme = new metadata_scheme($scheme_id);
  728. if ($scheme->valid) {
  729. $this->schemes[$scheme_id] = $scheme;
  730. }
  731. }
  732. } while ($parentschemes->get_next());
  733. }
  734. else {
  735. $parent_elemid = "";
  736. }
  737. } // while
  738. }
  739. } // inherit_schemes
  740.  
  741. // .....................................................................
  742. /**
  743. * Set the tag value of this meta data element. This is used when the
  744. * content is NOT a URI/URL. If it is, then use set_uri() instead.
  745. * @param string $val The value for this meta data element content
  746. */
  747. function set_tag_value($val) {
  748. $this->tag_value = $val;
  749. $this->linked_uri = false;
  750. } // set_tag_value
  751.  
  752. // .....................................................................
  753. /**
  754. * Set the tag value to be a URI. Same as setting tag value but we also
  755. * flick the uri flag as well.
  756. * @param string $href The URL/URI for this meta data element
  757. */
  758. function set_uri($uri) {
  759. $this->set_tag_value($uri);
  760. $this->linked_uri = true;
  761. } // set_uri
  762.  
  763. // .....................................................................
  764. /**
  765. * Set the language of the content of this meta data element
  766. * @param string $lang The language code for the content of this element
  767. */
  768. function set_language($lang) {
  769. $this->language = $lang;
  770. } // set_language
  771.  
  772. // .....................................................................
  773. /**
  774. * Set the scheme used to define the content of this meta data element. If
  775. * the tag of the scheme is not specified, then we go and find it by looking
  776. * up the scheme record in the DB.
  777. * @param integer $scheme_id The ID of the scheme used for picking the content
  778. * @param string $scheme_tag The tag name of the scheme
  779. */
  780. function set_scheme($scheme_id, $scheme_tag="") {
  781. $this->enc_scheme_id = $scheme_id;
  782. if ($scheme_tag != "") {
  783. $this->enc_scheme_tag = $scheme_tag;
  784. }
  785. else {
  786. $scheme = dbrecordset("SELECT * FROM ax_enc_scheme WHERE enc_scheme_id=$scheme_id");
  787. if ($scheme->hasdata) {
  788. $this->enc_scheme_tag = $scheme->field("tag_name");
  789. }
  790. }
  791. } // set_scheme
  792.  
  793. // .....................................................................
  794. /**
  795. * Render a definition form for this metadata element as HTML. This is a
  796. * self-contained table, and it has all of the element details, and fields
  797. * for setting the content, language, and scheme. It is not enclosed in
  798. * a form.
  799. * @return string An HTML rendering of metadata definition fields
  800. */
  801. function definition_form($formname="") {
  802. // Width of form elements..
  803. global $RESPONSE, $LIBDIR, $cwidth, $ewidth, $cwidth, $pwidth;
  804.  
  805. $this->get_info();
  806. $this->get_schemes();
  807.  
  808. // Generic script which inserts scheme data into metadata
  809. // form fields automatically on scheme data-entry..
  810. $RESPONSE->add_script(
  811. "function scheme_set(schid,fm,datfld,schfld) {\n"
  812. . " var datObj=eval('pfx'+schid+'dat_'+fm);\n"
  813. . " if (datObj!=null) {\n"
  814. . " var postData=findFieldObj(fm,datfld);\n"
  815. . " if (postData!=null) {\n"
  816. . " postData.value='';\n"
  817. . " for (var id in datObj) {\n"
  818. . " qual_value=getValue(fm,'qual_value',id,'pfx'+schid);\n"
  819. . " if (qual_value!='') {\n"
  820. . " if (postData.value!='') postData.value+='; ';\n"
  821. . " newqual=id+'='+qual_value;\n"
  822. . " postData.value+=newqual;\n"
  823. . " if (schfld != '') {\n"
  824. . " var postSche=findFieldObj(fm,schfld);\n"
  825. . " if (postSche != null) {\n"
  826. . " comboSet(postSche,schid);\n"
  827. . " }\n"
  828. . " }\n"
  829. . " }\n"
  830. . " }\n"
  831. . " }\n"
  832. . " }\n"
  833. . "}\n"
  834. );
  835.  
  836. $s = "";
  837. $Te = new table("eledef");
  838. $Te->setwidth("100%");
  839. $Te->setpadding(2);
  840.  
  841. // CONTENT SECTION
  842. $Te->tr("axbgdark");
  843. $Te->td("METADATA TAG COMPOSER", "axsubhdg");
  844. $Te->td_colspan(3);
  845.  
  846. $Te->tr("axbglite");
  847. $Te->td("<h2>$this->tag_name</h2>");
  848. $Te->td_colspan(2);
  849. $info = "<p><b>$this->label</b><br>";
  850. $maxwords = 30;
  851. $words = explode(" ", $this->description);
  852. if (count($words) > $maxwords) {
  853. $pattern = "/(([\S]+[\s]+){1," . $maxwords . "})/";
  854. preg_match($pattern, $this->description, $matches);
  855. if (isset($matches[1])) {
  856. $desc = $matches[1];
  857. }
  858. else {
  859. $desc = $this->description;
  860. }
  861. $desc = "<span title=\"$this->description\">$desc</span>...";
  862. }
  863. else {
  864. $desc = $this->description;
  865. }
  866. $info .= "$desc</p>";
  867. if ($this->obligation_desc != "" && $this->obligation_desc != "Unspecified") {
  868. $info .= "<p>This metadata element is $this->obligation_desc.</p>";
  869. }
  870. $Te->td($info, "axbgdarker");
  871. $Te->td_alignment("", "top");
  872. $Te->td_rowspan(6);
  873.  
  874. // Metadata Content
  875. if ($this->list_of_values != "") {
  876. $content_F = new form_combofield("elem_" . $this->element_id . "_content");
  877. $content_F->setclass("axcombo");
  878. $content_F->setstyle("width:$ewidth");
  879. $vals = explode(",", $this->list_of_values);
  880. foreach ($vals as $val) {
  881. $content_F->additem($val);
  882. }
  883. }
  884. else {
  885. $content_F = new form_memofield("elem_" . $this->element_id . "_content");
  886. $content_F->setclass("axmemo");
  887. $content_F->setstyle("width:$ewidth;height:60px");
  888. }
  889. if (isset($this->tag_value)) {
  890. $content_F->setvalue($this->tag_value);
  891. }
  892. elseif (isset($this->linked_uri)) {
  893. $content_F->setvalue($this->linked_uri);
  894. }
  895. elseif ($this->default_value != "") {
  896. $content_F->setvalue($this->default_value);
  897. }
  898. $Te->tr("axbgdark");
  899. $Te->td("Content:", "axfg");
  900. $Te->td_alignment("", "top");
  901. $Te->td_css("padding-top:3px");
  902. $Te->td($content_F->render());
  903. $Te->td_alignment("", "top");
  904.  
  905. // URI flag
  906. if ($this->list_of_values == "") {
  907. $chkUri_F = new form_checkbox("elem_" . $this->element_id . "_chkuri");
  908. $chkUri_F->setclass("axchkbox");
  909. $chkUri_F->checked = $this->linked_uri;
  910. $Te->tr("axbgdark");
  911. $Te->td("Content is a URI:", "axfg");
  912. $Te->td($chkUri_F->render());
  913. }
  914.  
  915. // Metadata Language
  916. $Te->tr("axbglite");
  917. $Te->td("Language code:", "axfg");
  918. $lang_F = new form_textfield("elem_" . $this->element_id . "_lang");
  919. $lang_F->setclass("axtxtbox");
  920. $lang_F->setstyle("width:$pwidth");
  921.  
  922. if (isset($this->language)) {
  923. $lang_F->setvalue($this->language);
  924. }
  925. $Te->td($lang_F->render());
  926.  
  927. // Metadata Scheme code
  928. $scheme_F = new form_combofield("elem_" . $this->element_id . "_scheme");
  929. $scheme_F->setclass("axcombo");
  930. $q = "SELECT * FROM ax_enc_scheme";
  931. $q .= " WHERE enabled=TRUE";
  932. $q .= " ORDER BY tag_name";
  933. $schQ = dbrecordset($q);
  934. $scheme_F->additem("");
  935. if ($schQ->hasdata) {
  936. do {
  937. $schid = $schQ->field("enc_scheme_id");
  938. $tag_name = $schQ->field("tag_name");
  939. if ($tag_name != "") {
  940. $scheme_F->additem($schid, $tag_name);
  941. }
  942. } while ($schQ->get_next());
  943. }
  944. if (isset($this->enc_scheme_id)) {
  945. $scheme_F->setvalue($this->enc_scheme_id);
  946. }
  947. $Te->tr("axbgdark");
  948. $Te->td("Scheme:", "axfg");
  949. $Te->td($scheme_F->render());
  950.  
  951. // A save button & done button
  952. $bsave = new form_imagebutton("save", "", "", "$LIBDIR/img/_save.gif", "Save metadata content", 57, 15 );
  953. $bdone = new form_imagebutton("done", "", "", "$LIBDIR/img/_done.gif", "Exit without saving", 57, 15 );
  954. $bsave->set_onclick("meta_action('save','$this->element_id','$this->schema_name')");
  955. $bdone->set_onclick("meta_action('done','$this->element_id','$this->schema_name')");
  956. $Te->tr("axbglite");
  957. $Te->td("&nbsp;");
  958. $Te->td($bsave->render() . "&nbsp;" . $bdone->render());
  959.  
  960. // LANGUAGES
  961. $Te->tr("axbglite");
  962. $Te->td("LANGUAGES", "axhdg");
  963. $Te->td_colspan(3);
  964. $q = "SELECT * FROM ax_enc_scheme WHERE enc_scheme_name LIKE 'ISO639%' ORDER BY enc_scheme_name";
  965. $iso639 = dbrecordset($q);
  966. if ($iso639->hasdata) {
  967. do {
  968. $iso639id = $iso639->field("enc_scheme_id");
  969. if ($iso639id != "") {
  970. $iso639_scheme = new metadata_scheme($iso639id);
  971. if ($iso639_scheme->valid) {
  972. $schdef = $iso639_scheme->definition_form(
  973. $formname,
  974. "elem_" . $this->element_id . "_lang"
  975. );
  976. $Te->tr("axbgdark");
  977. $Te->td( $schdef );
  978. $Te->td_colspan(3);
  979. }
  980. }
  981. } while ($iso639->get_next());
  982. }
  983.  
  984. // SCHEMES APPLICABLE TO THIS ELEMENT
  985. $Te->tr("axbglite");
  986. $Te->td("APPLICABLE SCHEMES", "axhdg");
  987. $Te->td_colspan(3);
  988. foreach ($this->schemes as $scheme) {
  989. $schdef = $scheme->definition_form(
  990. $formname,
  991. "elem_" . $this->element_id . "_content",
  992. "",
  993. "elem_" . $this->element_id . "_scheme"
  994. );
  995. $Te->tr("axbgdark");
  996. $Te->td( $schdef );
  997. $Te->td_colspan(3);
  998. }
  999. $Te->set_width_profile("20%,50%,30%");
  1000. return $Te->render();
  1001. } // definition_form
  1002.  
  1003. // .....................................................................
  1004. /**
  1005. * Process the POST of the form of this metadata element. We are just
  1006. * looking for the few fields containing the relevant data.
  1007. * NOTE: We do NOT save anything to the database, we just update our
  1008. * class variables with the newly POSTed data.
  1009. */
  1010. function POSTprocess() {
  1011. global $mode;
  1012. if (isset($mode) && $mode == "save") {
  1013. $pfx = "elem_" . $this->element_id;
  1014. $contentvar = $pfx . "_content";
  1015. $langvar = $pfx . "_lang";
  1016. $chkurivar = $pfx . "_chkuri";
  1017. $schemevar = $pfx . "_scheme";
  1018.  
  1019. global $$contentvar, $$langvar, $$chkurivar, $$schemevar;
  1020.  
  1021. $content = $$contentvar;
  1022. $language = $$langvar;
  1023. $chkUri = isset($$chkurivar);
  1024. $scheme_id = $$schemevar;
  1025.  
  1026. if ($chkUri) {
  1027. $this->set_uri($content);
  1028. }
  1029. else {
  1030. $this->set_tag_value($content);
  1031. }
  1032. if ($language != "") {
  1033. $this->set_language($language);
  1034. }
  1035. if ($scheme_id != "") {
  1036. $this->set_scheme($scheme_id);
  1037. }
  1038. }
  1039. } // POSTprocess
  1040.  
  1041. // .....................................................................
  1042. /**
  1043. * Render this metadata element as a metatag object. This method
  1044. * creates the metatag object and returns it.
  1045. * @return object The metadata element as a metatag object
  1046. */
  1047. function metatag() {
  1048. if ($this->linked_uri) {
  1049. $metatag = new uri_meta_tag(
  1050. $this->tag_name,
  1051. $this->tag_value,
  1052. $this->language
  1053. );
  1054. }
  1055. else {
  1056. $metatag = new data_meta_tag(
  1057. $this->tag_name,
  1058. $this->tag_value,
  1059. $this->language,
  1060. $this->enc_scheme_tag
  1061. );
  1062. }
  1063. return $metatag;
  1064. } // metatag
  1065.  
  1066. // .....................................................................
  1067. /**
  1068. * Render this metadata element as HTML.
  1069. * @return string The HTML rendering of this metadata element
  1070. */
  1071. function html() {
  1072. $meta = $this->metatag();
  1073. return $meta->html();
  1074. } // html
  1075.  
  1076.  
  1077.  
  1078. } // metadata_element class
  1079. // -----------------------------------------------------------------------
  1080.  
  1081. /**
  1082. * A class which holds multiple metadata elements, for a given layout.
  1083. * Acquires all the metadata elements for a given layout. Provides the
  1084. * means to render these.
  1085. * @package cm
  1086. */
  1087. class layout_metadata_elements {
  1088. // Public
  1089. /** The layout these elements are for */
  1090.  
  1091. var $layout_id = "";
  1092. /** The metadata elements themselves */
  1093.  
  1094. var $metadata_elements = array();
  1095.  
  1096. // Private
  1097. /** Standard form name to use
  1098. @access private */
  1099. var $formname = "";
  1100. // .....................................................................
  1101. /** Constructor
  1102. * @param integer $layout_id The unique ID of the layout
  1103. * @param string $formname The form name to use for form rendering
  1104. * @param boolean $instantiated_only True means get only existing meta data
  1105. */
  1106. function layout_metadata_elements($layout_id="", $formname="", $instantiated_only=false) {
  1107. $this->get($layout_id, $instantiated_only);
  1108. if ($formname == "") {
  1109. $formname = "layout_" . $this->layout_id . "_metadata";
  1110. }
  1111. $this->formname = $formname;
  1112. } // layout_metadata_elements
  1113. // .....................................................................
  1114. /**
  1115. * Get all of the metadata elements associated with this layout. We can
  1116. * do this in two modes, determined by the $instantiated_only flag. If
  1117. * this is true then we only grab the data for the metadata elements
  1118. * which exist for the layout. Otherwise we grab ALL of them. The
  1119. * latter is for editing, and the former is for page rendering where
  1120. * we want minimal Db traffic.
  1121. * @param integer $layout_id The ID of the layout to get elements for
  1122. * @return boolean Whether the get succeeded and object is valid
  1123. */
  1124. function get($layout_id="", $instantiated_only=false) {
  1125. if ($layout_id != "") {
  1126. $this->layout_id = $layout_id;
  1127. }
  1128. // Populate ALL metadata elements, as blanks..
  1129. if (!$instantiated_only) {
  1130. $q = "SELECT * FROM ax_site_meta_element";
  1131. $q .= " WHERE enabled=TRUE";
  1132. $q .= " ORDER BY display_order";
  1133. $allmeta = dbrecordset($q);
  1134. if ($allmeta->hasdata) {
  1135. do {
  1136. $element_id = $allmeta->field("element_id");
  1137. $schema_name = $allmeta->field("schema_name");
  1138. $meta = new metadata_element($element_id, $schema_name);
  1139. // Add this new element to our array..
  1140. $meta->get_info();
  1141. $this->add_metadata_element($meta);
  1142. } while ($allmeta->get_next());
  1143. }
  1144. }
  1145.  
  1146. // Overlay with metadata which has been defined..
  1147. if ($this->layout_id != "") {
  1148. $q = "SELECT * FROM ax_layout_metadata";
  1149. $q .= " WHERE layout_id=$this->layout_id";
  1150. $laymeta = dbrecordset($q);
  1151. if ($laymeta->hasdata) {
  1152. do {
  1153. $element_id = $laymeta->field("element_id");
  1154. $schema_name = $laymeta->field("schema_name");
  1155. $tag_value = $laymeta->field("meta_tag_value");
  1156. $scheme_id = $laymeta->field("enc_scheme_id");
  1157. $uri = $laymeta->istrue("linked_uri");
  1158. $language = $laymeta->field("language");
  1159. if ($instantiated_only) {
  1160. $meta = new metadata_element($element_id, $schema_name);
  1161. $meta->get_info();
  1162. }
  1163. else {
  1164. $meta = $this->get_metadata_element($element_id);
  1165. }
  1166. if ($meta !== false) {
  1167. $meta->instantiated = true;
  1168. if ($scheme_id != "") {
  1169. $meta->set_scheme($scheme_id);
  1170. }
  1171. if ($uri) {
  1172. $meta->set_uri($tag_value);
  1173. }
  1174. else {
  1175. $meta->set_tag_value($tag_value);
  1176. }
  1177. if ($language != "") {
  1178. $meta->set_language($language);
  1179. }
  1180. // Add this new element to our array..
  1181. $this->add_metadata_element($meta);
  1182. }
  1183. } while ($laymeta->get_next());
  1184. $this->valid = true;
  1185. }
  1186. }
  1187. } // get
  1188.  
  1189. // .....................................................................
  1190. /** Assembles all metadata elements for this layout. */
  1191.  
  1192. function perform_hierarchy_scan() {
  1193. // Determine hierarchical relationships between the
  1194. // metadata elements, ie. parent->child->child.. etc.
  1195. foreach ($this->metadata_elements as $element_id => $element) {
  1196. if (!$element->base_element && $element->parent_element_id != "") {
  1197. $parent_element = $this->get_metadata_element($element->parent_element_id);
  1198. if ($parent_element !== false) {
  1199. $parent_element->child_element_ids[] = $element_id;
  1200. $this->add_metadata_element($parent_element);
  1201. }
  1202. }
  1203. } // foreach
  1204. } // perform_hierarchy_scan
  1205.  
  1206. // .....................................................................
  1207. /** Returns the number of meta elements in this layout.
  1208. * @return integer Number of metadata elements currently in this layout
  1209. */
  1210. function meta_element_count() {
  1211. return count($this->metadata_elements);
  1212. } // meta_element_count
  1213.  
  1214. // .....................................................................
  1215. /**
  1216. * Return meta data tree entry.
  1217. * @return string The table containing all metadata elements so far.
  1218. * @access private
  1219. */
  1220. function metadata_tree_entry($Ttree, $indent, $element_id) {
  1221. global $RESPONSE, $LIBDIR, $cwidth, $ewidth, $cwidth, $pwidth;
  1222. // Write current element..
  1223. $element = $this->get_metadata_element($element_id);
  1224. if ($element !== false) {
  1225. // Do this present element..
  1226. $padding = new img("$LIBDIR/img/_pad.gif", "", "", (18 * $indent), 1);
  1227. $Ttree->tr("axbglite");
  1228. $elem_link = new anchor("#", $element->label);
  1229. if ($element->instantiated) {
  1230. $elem_link->set_onclick("meta_action('edit','$element->element_id','$element->schema_name')");
  1231. $bunset = new form_imagebutton("unset", "", "", "$LIBDIR/img/_redx.gif", "Un-set", 9, 9);
  1232. $bunset->set_onclick("meta_action('unset','$element->element_id','$element->schema_name')");
  1233. $Ttree->td($bunset->render(), "padding-top:5px");
  1234. $Ttree->td_alignment("", "top");
  1235. $Ttree->td($padding->render() . $elem_link->render(), "axfg");
  1236. $Ttree->td_alignment("", "top");
  1237. $Ttree->td(($element->tag_value != "") ? $element->tag_value : "&nbsp;");
  1238. $Ttree->td_alignment("", "top");
  1239. $Ttree->td(($element->language != "") ? $element->language : "&nbsp;");
  1240. $Ttree->td_alignment("center", "top");
  1241. $Ttree->td(($element->enc_scheme_tag != "") ? $element->enc_scheme_tag : "&nbsp;");
  1242. $Ttree->td_alignment("center", "top");
  1243. }
  1244. else {
  1245. $elem_link->set_onclick("meta_action('add','$element->element_id','$element->schema_name')");
  1246. $pad = new form_imagebutton("pad", "", "", "$LIBDIR/img/_pad.gif", "", 9, 1);
  1247. $Ttree->td($pad->render());
  1248. $Ttree->td($padding->render() . $elem_link->render(), "axfg");
  1249. $Ttree->td_alignment("", "top");
  1250. switch ($element->obligation) {
  1251. case "m": $msg = "<span class=\"axhl\">mandatory</span>"; break;
  1252. case "r": $msg = "recommended"; break;
  1253. default: $msg = "&nbsp;";
  1254. }
  1255. $Ttree->td($msg);
  1256. $Ttree->td_alignment("", "top");
  1257. $Ttree->td("&nbsp;");
  1258. $Ttree->td("&nbsp;");
  1259. }
  1260.  
  1261. // And now do any children..
  1262. if (count($element->child_element_ids) > 0) {
  1263. $child_indent = $indent + 1;
  1264. foreach ($element->child_element_ids as $child_element_id) {
  1265. $Ttree = $this->metadata_tree_entry($Ttree, $child_indent, $child_element_id);
  1266. }
  1267. }
  1268. }
  1269. // Return the tree table..
  1270. return $Ttree;
  1271. } // metadata_tree_entry
  1272.  
  1273. // .....................................................................
  1274. /**
  1275. * Returns a string containing a table which contains all of the meta
  1276. * data in a nice tree view.
  1277. * @return string A table containing all metadata elements for viewing
  1278. */
  1279. function metadata_tree() {
  1280. global $RESPONSE;
  1281. $this->perform_hierarchy_scan();
  1282. $Ttree = new table("metadata_tree");
  1283. $Ttree->setpadding(2);
  1284. $Ttree->td("&nbsp;");
  1285. $Ttree->td("<i>Tag</i>", "axfg");
  1286. $Ttree->td("<i>Content</i>", "axfg");
  1287. $Ttree->td("<i>Lang</i>", "axfg");
  1288. $Ttree->td_alignment("center");
  1289. $Ttree->td("<i>Scheme</i>", "axfg");
  1290. $Ttree->td_alignment("center");
  1291. foreach ($this->metadata_elements as $element_id => $element) {
  1292. if ($element->base_element) {
  1293. $indent = 0;
  1294. $Ttree = $this->metadata_tree_entry($Ttree, $indent, $element_id);
  1295. }
  1296. } // foreach
  1297. $Ttree->set_width_profile("1%,25%,49%,5%,20%");
  1298. // Return rendered content..
  1299. return $Ttree->render();
  1300. } // metadata_tree
  1301.  
  1302. // .....................................................................
  1303. /**
  1304. * Add a metadata element to our array of elements. We add it to an
  1305. * associative array keyed on the element_id, ensuring no duplicates.
  1306. * @param object $meta The metadata element object to add
  1307. */
  1308. function add_metadata_element($meta) {
  1309. $this->metadata_elements[$meta->element_id] = $meta;
  1310. } // add_metadata_element
  1311.  
  1312. // .....................................................................
  1313. /**
  1314. * Return a metadata element, given its element_id.
  1315. * @param integer $element_id The element ID of the element to return
  1316. */
  1317. function get_metadata_element($element_id) {
  1318. if (isset($this->metadata_elements[$element_id])) {
  1319. return $this->metadata_elements[$element_id];
  1320. }
  1321. else {
  1322. return false;
  1323. }
  1324. } // get_metadata_element
  1325. // .....................................................................
  1326. /**
  1327. * Saves the layout metadata for a given element. This saves data to
  1328. * the ax_layout_metadata table.
  1329. * @param integer $element_id The element ID of the element to return
  1330. */
  1331. function save_metadata_element($element_id) {
  1332. $element = $this->get_metadata_element($element_id);
  1333. if ($element !== false) {
  1334. if ($element->instantiated) {
  1335. $meup = new dbupdate("ax_layout_metadata");
  1336. $meup->where("layout_id=$this->layout_id");
  1337. $meup->where("AND element_id=$element->element_id");
  1338. $meup->where("AND schema_name='" . addslashes($element->schema_name) . "'");
  1339. }
  1340. else {
  1341. $meup = new dbinsert("ax_layout_metadata");
  1342. $meup->set("layout_id", $this->layout_id);
  1343. $meup->set("element_id", $element->element_id);
  1344. $meup->set("schema_name", $element->schema_name);
  1345. }
  1346. $meup->set("meta_tag_value", $element->tag_value);
  1347. if ($element->enc_scheme_id != "") {
  1348. $meup->set("enc_scheme_id", $element->enc_scheme_id);
  1349. }
  1350. else {
  1351. $meup->set("enc_scheme_id", NULLVALUE);
  1352. }
  1353. $meup->set("linked_uri", $element->linked_uri);
  1354. $meup->set("language", $element->language);
  1355. $ok = $meup->execute();
  1356.  
  1357. // Alter instantiation status if created new..
  1358. if (!$element->instantiated && $ok) {
  1359. $element->instantiated = true;
  1360. $this->add_metadata_element($element);
  1361. }
  1362. }
  1363. } // save_metadata_element
  1364. // .....................................................................
  1365. /**
  1366. * Removes the layout metadata for a given element. This deletes the
  1367. * relevant record from the ax_layout_metadata table.
  1368. * @param integer $element_id The element ID of the element to remove
  1369. */
  1370. function remove_metadata_element($element_id) {
  1371. $element = $this->get_metadata_element($element_id);
  1372. if ($element !== false && $element->instantiated) {
  1373. $medel = new dbdelete("ax_layout_metadata");
  1374. $medel->where("layout_id=$this->layout_id");
  1375. $medel->where("AND element_id=$element->element_id");
  1376. $medel->where("AND schema_name='" . addslashes($element->schema_name) . "'");
  1377. $medel->execute();
  1378. }
  1379. } // remove_metadata_element
  1380. // .....................................................................
  1381. /**
  1382. * Insert the instantiated metatags into the given webpage. This is
  1383. * intended to be used on the $RESPONSE object to actually jam the
  1384. * tags for this layout into the webapage.
  1385. * @param reference Reference to Webpage object to insert metatags into
  1386. */
  1387. function insert_metatags(&$webpage) {
  1388. global $RESPONSE;
  1389. foreach ($this->metadata_elements as $element_id => $element) {
  1390. if ($element->instantiated) {
  1391. $metatag = $element->metatag();
  1392. $RESPONSE->insert_metatag($element_id, $metatag);
  1393. }
  1394. }
  1395. } // insert_metatags
  1396. // .....................................................................
  1397. /**
  1398. * Render all of the elements as HTML
  1399. * @return string HTML rendering of all contained metadata elements
  1400. */
  1401. function html() {
  1402. $s = "";
  1403. foreach ($this->metadata_elements as $element_id => $element) {
  1404. if ($element->instantiated) {
  1405. $s .= $element->html();
  1406. }
  1407. }
  1408. return $s;
  1409. } // html
  1410.  
  1411.  
  1412.  
  1413. } // layout_metadata_elements class
  1414. // -----------------------------------------------------------------------
  1415.  
  1416. /**
  1417. * Function to format a tag name which might have multiple parents.
  1418. * The expected format is that the sequence of tag names will each
  1419. * be separated by a dot ".". Here we just format it with the first
  1420. * descendant lowercased, and all others proper-cased.
  1421. * @param string $tag_name The tag name, with descendants separated by dots
  1422. */
  1423. function format_tag_name($tag_name) {
  1424. $result = $tag_name;
  1425. $bits = explode(".", $tag_name);
  1426. if (count($bits) > 1) {
  1427. $fmtarr = array();
  1428. $first = true;
  1429. foreach ($bits as $tagbit) {
  1430. if ($first) {
  1431. $fmtarr[] = strtolower($tagbit);
  1432. $first = false;
  1433. }
  1434. else {
  1435. $fmtarr[] = ucfirst($tagbit);
  1436. }
  1437. }
  1438. $result = implode(".", $fmtarr);
  1439. }
  1440. return $result;
  1441. } // format_tag_name
  1442. // -----------------------------------------------------------------------
  1443.  
  1444. /**
  1445. * Function to acquire the full tag name including descendants, given
  1446. * the tag name, and the parent element ID of that tag.
  1447. * @param string $tag_name The starting tag name
  1448. * @param integer $parent_elemid The parent element ID of that tag
  1449. * @return string The full descendant tag name
  1450. */
  1451. function get_full_tag_name($tag_name, $parent_elemid) {
  1452. while ($parent_elemid != "") {
  1453. $parent = dbrecordset("SELECT tag_name FROM ax_meta_element WHERE element_id=$parent_elemid");
  1454. if ($parent->hasdata) {
  1455. $tag_name = $parent->field("tag_name") . "." . $tag_name;
  1456. $parent_elemid = $parent->field("parent_element");
  1457. }
  1458. else {
  1459. $parent_elemid = "";
  1460. }
  1461. }
  1462. return $tag_name;
  1463. } // get_full_tag_name
  1464. // -----------------------------------------------------------------------
  1465.  
  1466. ?>

Documentation generated by phpDocumentor 1.3.0RC3