Source for file catalog-defs.php

Documentation is available at catalog-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: catalog-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Handle media catalog items and lists. */
  24. /* */
  25. /* ******************************************************************** */
  26. /** @package catalog */
  27. include_once("lucene-defs.php");
  28. /** Filesystem access */
  29. ("file-defs.php");
  30.  
  31. // -----------------------------------------------------------------------
  32. /**
  33. * A class which encpasulates an item which can be in the catalog.
  34. * @package catalog
  35. */
  36. class catalogitem extends RenderableObject {
  37. var $cat_id; // Unique catalog record key for the catalog item
  38. var $cat_name = ""; // Name of this catalog item
  39. var $cat_desc = ""; // Full description of catalog item
  40. var $mime_type = ""; // Mime-type of catalog item
  41. var $mime_category = ""; // Mime category eg: document, movie, audio etc.
  42. var $keywords = ""; // Any keywords associated with it
  43. var $category = ""; // Optional user-defined category for item
  44. var $filesize = ""; // Size of catalog item in bytes
  45. var $filepath = ""; // Website URL path to the item (with leading '/')
  46. var $physicalpath = ""; // Full physical path on the filesystem
  47. var $fileexists = false; // True if file exists at filepath
  48. var $width = 0; // Pixel width of this item
  49. var $height = 0; // Pixel height of this item
  50. var $uploaded_ts = 0; // Unix timestamp of datetime item was added to catalog
  51. var $uploaded = ""; // Datetime uploaded, NICE_FULLDATETIME format
  52. var $errmsg = ""; // Contains error message if invalid
  53. var $valid = false; // True if item was retreived successfully
  54. var $newcat = false; // True if we just created this story
  55.  
  56. // .....................................................................
  57. /** Constructor
  58. * @param integer $id Optional unique catalog item ID
  59. */
  60. function catalogitem($id=false) {
  61. // The all-important catalog ID..
  62. $this->cat_id = $id;
  63. if (!$id) {
  64. $this->newcat = true;
  65. $this->valid = true;
  66. }
  67. // Further processing for existing items..
  68. if (!$this->newcat) {
  69. // Attempt to get the catlog item
  70. $this->get();
  71. }
  72.  
  73. } // catalogitem
  74. // .....................................................................
  75. /** Get current or nominated catalog item definition from the database.
  76. * @param integer $id Optional unique catalog item ID to get
  77. */
  78. function get($id=false) {
  79. global $RESPONSE;
  80. $res = false;
  81. if ($id) $this->cat_id = $id;
  82. if ($this->cat_id) {
  83. $catQ = dbrecordset("SELECT * FROM ax_catalog WHERE cat_id=$this->cat_id");
  84. if ($catQ->hasdata) {
  85. $this->cat_name = $catQ->field("cat_name");
  86. $this->cat_desc = $catQ->field("cat_desc");
  87. $this->mime_type = $catQ->field("mime_type");
  88. $this->mime_category = $catQ->field("mime_category");
  89. $this->keywords = $catQ->field("keywords");
  90. $this->category = $catQ->field("category");
  91. $this->filesize = $catQ->field("filesize");
  92. $this->filepath = $catQ->field("filepath");
  93. $this->width = $catQ->field("width");
  94. $this->height = $catQ->field("height");
  95. $this->uploaded_ts = datetime_to_timestamp($catQ->field("upload_timestamp"));
  96. $this->uploaded = timestamp_to_displaydate(NICE_FULLDATETIME, $this->uploaded_ts);
  97. // Update status of physical file..
  98. $this->physicalpath = $RESPONSE->site_docroot . $this->filepath;
  99. $this->fileexists = file_exists($this->physicalpath);
  100. $res = true;
  101. $this->newcat = false;
  102. }
  103. else $this->errmsg = "No record of catalog item: $this->cat_id";
  104. }
  105. else $this->errmsg = "No catalog ID was given";
  106. // Did we succeed..?
  107. $this->valid = $res;
  108. return $res;
  109. } // get
  110. // .....................................................................
  111. /** Save current catalog item definition to the database. Inserts
  112. * if brand new, else performs an update.
  113. */
  114. function save() {
  115. global $RESPONSE;
  116. $res = false;
  117. if ($this->newcat || ($this->cat_id && $this->valid)) {
  118. if ($this->newcat) {
  119. $this->cat_id = get_next_sequencevalue("seq_cat_id", "ax_catalog", "cat_id");
  120. $this->uploaded_ts = time();
  121. $this->uploaded = timestamp_to_displaydate(NICE_FULLDATETIME, $this->uploaded_ts);
  122. $cup = new dbinsert("ax_catalog");
  123. $cup->set("cat_id", $this->cat_id);
  124. $this->newcat = false;
  125. }
  126. else {
  127. $cup = new dbupdate("ax_catalog");
  128. $cup->where("cat_id=$this->cat_id");
  129. }
  130. $cup->set("cat_name", $this->cat_name);
  131. $cup->set("cat_desc", $this->cat_desc);
  132. $cup->set("mime_type", $this->mime_type);
  133. $cup->set("mime_category", $this->mime_category);
  134. $cup->set("keywords", $this->keywords);
  135. $cup->set("category", $this->category);
  136. $cup->set("filesize", $this->filesize);
  137. $cup->set("filepath", $this->filepath);
  138. $cup->set("width", $this->width);
  139. $cup->set("height", $this->height);
  140. $cup->set("upload_timestamp", timestamp_to_datetime($this->uploaded_ts));
  141. $res = $cup->execute();
  142. if ($res) {
  143. // Index to Lucene..
  144. $this->index();
  145. // Update status of physical file..
  146. $this->physicalpath = $RESPONSE->site_docroot . $this->filepath;
  147. $this->fileexists = file_exists($this->physicalpath);
  148. }
  149. }
  150. return $res;
  151. } // save
  152. // .....................................................................
  153. /**
  154. * Remove the catalog item from the database and disk. This method
  155. * normally tries to remove the physical file first, and if that succeeds
  156. * it removes the database record. If $deletefile is false then the file
  157. * will be left and only the DB record deleted.
  158. * @param boolean $deletefile If true the physical file will be deleted
  159. * @return boolean True if the operation succeeded, else false.
  160. */
  161. function delete($deletefile=true) {
  162. global $RESPONSE, $IMAGESDIR;
  163. $deleted = false;
  164. $err = false;
  165. if ($this->cat_id && $this->valid) {
  166. // First, deal to the physical file..
  167. if ($deletefile) {
  168. if (file_exists($this->physicalpath)) {
  169. // Avoid deleting images which are part of the standard issue..
  170. if (substr($this->filepath, 0, strlen($IMAGESDIR)) != $IMAGESDIR) {
  171. if (!is_writeable($this->physicalpath) || !unlink($this->physicalpath)) {
  172. $err = true;
  173. }
  174. }
  175. }
  176. }
  177. // Delete the database record now..
  178. if (!$err) {
  179. $dcat = new dbdelete("ax_catalog");
  180. $dcat->where("cat_id=$this->cat_id");
  181. $res = $dcat->execute();
  182. if ($res) {
  183. // Remove from Lucene index..
  184. $this->unindex();
  185. $this->valid = false;
  186. $deleted = true;
  187. }
  188. }
  189. }
  190. return $deleted;
  191. } // delete
  192. // .....................................................................
  193. /**
  194. * Index this catalog item to Lucene.
  195. * If it exists already, index entry for this item is replaced.
  196. */
  197. function index() {
  198. global $CONTEXT;
  199. if ($this->valid && isset($CONTEXT) && $CONTEXT->configvalue("Lucene Site Indexing") ) {
  200. $I = new lucene_indexmsg();
  201. // Make sure these fields are stored..
  202. $I->define_field("catname", "Text", STORED);
  203. $I->define_field("category", "Text", STORED);
  204. $I->define_field("mimecat", "Text", STORED);
  205. $I->define_field("uploaded", "Date", STORED);
  206. $I->define_field("path", "text", STORED);
  207. // Index the fields..
  208. $I->index_field("Id", "CAT_" . $this->cat_id);
  209. $I->index_field("keywords", $this->keywords);
  210. $I->index_field("catname", $this->cat_name);
  211. $I->index_field("category", $this->category);
  212. $I->index_field("mimecat", $this->mime_category);
  213. $I->index_field("uploaded", $this->uploaded_ts);
  214. $I->index_field("path", $this->filepath);
  215. // Index the content..
  216. $allcontent[] = $this->cat_name;
  217. $allcontent[] = $this->cat_desc;
  218. $allcontent[] = $this->keywords;
  219. $I->index_content("CAT_" . $this->cat_id, implode(" ", $allcontent));
  220. $I->send();
  221. }
  222. } // index
  223. // .....................................................................
  224. /** Remove this catalog item from the Lucene index. */
  225.  
  226. function unindex() {
  227. global $CONTEXT;
  228. if ($this->valid && isset($CONTEXT) && $CONTEXT->configvalue("Lucene Site Indexing") ) {
  229. $UI = new lucene_unindexmsg();
  230. $UI->unindex("CAT_" . $this->cat_id);
  231. $UI->send();
  232. }
  233. } // unindex
  234. // .....................................................................
  235. /** Return the catalog item as a clickable icon.
  236. * @param boolean $autostart Movies etc. if true start automatically
  237. */
  238. function AsIcon($showcontrols=false, $autostart=false, $loop=false) {
  239. $icon = "";
  240. $tooltip = basename($this->filepath);
  241. // Set commonsense values for movies..
  242. if (!$showcontrols) {
  243. $autostart = true;
  244. $loop = true;
  245. }
  246. switch ($this->mime_category) {
  247. case "movie":
  248. $media = new MediaObject($this->filepath, $this->width, $this->height, $autostart, $loop, $showcontrols);
  249. $media->AsIcon($tooltip);
  250. $icon = $media->render();
  251. break;
  252. case "audio":
  253. $media = new MediaObject($this->filepath, $this->width, $this->height, $autostart, $loop, $showcontrols);
  254. $media->AsIcon($tooltip);
  255. $icon = $media->render();
  256. break;
  257. case "flash":
  258. $media = new FlashObject($this->filepath, $this->width, $this->height, $autostart, $loop);
  259. $media->AsIcon($tooltip);
  260. $icon = $media->render();
  261. break;
  262. case "document":
  263. $media = new DocumentObject($this->filepath, $this->width, $this->height);
  264. $media->AsIcon($tooltip);
  265. $icon = $media->render();
  266. break;
  267. case "image":
  268. $media = new img($this->filepath, $this->cat_name);
  269. $media->AsIcon($tooltip);
  270. $icon = $media->render();
  271. break;
  272. default:
  273. $icon = $this->AsLink();
  274. } // switch
  275. return $icon;
  276. } // AsIcon
  277. // .....................................................................
  278. /** Return the catalog item as image, a clickable icon, or otherwise a link.
  279. * @param boolean $autostart Movies etc. if true start automatically
  280. */
  281. function Insitu($showcontrols=false, $autostart=false, $loop=false) {
  282. $catmedia = "";
  283. $tooltip = basename($this->filepath);
  284. // Set commonsense values for movies..
  285. if (!$showcontrols) {
  286. $autostart = true;
  287. $loop = true;
  288. }
  289. switch ($this->mime_category) {
  290. case "movie":
  291. $media = new MediaObject($this->filepath, $this->width, $this->height, $autostart, $loop, $showcontrols);
  292. $catmedia = $media->render();
  293. break;
  294. case "flash":
  295. $media = new FlashObject($this->filepath, $this->width, $this->height, $autostart, $loop);
  296. $catmedia = $media->render();
  297. break;
  298. case "image":
  299. $media = new img(
  300. $this->filepath,
  301. str_replace(" ", "", $this->cat_name),
  302. ($this->cat_desc != "" ? $this->cat_desc : $this->cat_name)
  303. );
  304. $catmedia = $media->render();
  305. break;
  306. default:
  307. $catmedia = $this->AsIcon();
  308. } // switch
  309. return $catmedia;
  310. } // In-situ
  311. // .....................................................................
  312. /** Return the catalog item as a clickable hyperlink. */
  313.  
  314. function AsLink() {
  315. $catlink = new anchor($this->filepath, $this->cat_name);
  316. $catlink->set_linkover_text( basename($this->filepath) );
  317. return $catlink->render();
  318. } // AsLink
  319. // .....................................................................
  320. /**
  321. * Create this catalog item from a media file on disk. The media item
  322. * should be located at a physical path on disk somewhere. It will be grabbed,
  323. * moved to a new location, and the item record saved to the DB.
  324. * NOTE: this may be an existing catalogitem, OR a newly created one. This
  325. * is not determined by this routine, but must be set up before calling this
  326. * method. The save() method then does whatever is necessary.
  327. * @param string $srcpath The full physical filesystem path to the source media
  328. * @param string $destpath The full physical path of where to move the media
  329. * @param string $filepath The relative path of the media, to save on DB record
  330. * @param string $mimetype The mime type of the file, eg: "image/jpeg"
  331. * @param string $name Media file associated name
  332. * @param string $category Media file associated category
  333. * @param string $desc Media file full description
  334. * @param string $keywords Media file associated keywords
  335. * @return boolean True if all ok, else false
  336. */
  337. function create(
  338. $srcpath, $destpath, $filepath,
  339. $mimetype="",
  340. $width=0, $height=0,
  341. $name="", $category="", $desc="", $keywords=""
  342. ) {
  343. global $RESPONSE;
  344.  
  345. // Valid flag..
  346. $this->valid = false;
  347.  
  348. // Move file to destination & create our catalog record..
  349. if (is_readable($srcpath)) {
  350.  
  351. // Determine mime-type
  352. if ($mimetype == "") {
  353. $mimetype = mimetype_from_filename($srcpath);
  354. }
  355. // Determine mime-category..
  356. $mime_category = mimetype_category($mimetype);
  357.  
  358. // Size of this file..
  359. $filesize = filesize($srcpath);
  360.  
  361. // Image metrics..
  362. if ($mime_category == "image") {
  363. $imginfo = getimagesize($srcpath);
  364. $width = $imginfo[0];
  365. $height = $imginfo[1];
  366. }
  367. // Move to destination, if different to source location..
  368. if (realpath($destpath) != realpath($srcpath)) {
  369. if (copy($srcpath, $destpath) === false) {
  370. $errmsgs[] = "failed to copy new media to its destination: $srcpath --> $destpath";
  371. }
  372. }
  373. // Store file in database..
  374. if ($name == "") {
  375. $name = basename($srcpath);
  376. }
  377. $this->cat_name = $name;
  378. $this->cat_desc = $desc;
  379. $this->keywords = $keywords;
  380. $this->category = $category;
  381. $this->mime_category = $mime_category;
  382. $this->mime_type = $mimetype;
  383. $this->filesize = $filesize;
  384. $this->filepath = $filepath;
  385. $this->physicalpath = $destpath;
  386. $this->fileexists = file_exists($destpath);
  387. $this->width = $width;
  388. $this->height = $height;
  389. if ($this->save()) {
  390. $this->valid = true;
  391. }
  392. else {
  393. $errmsgs[] = "failed to save catalog item $this->cat_id to database.";
  394. }
  395. }
  396. // Return the status..
  397. return $this->valid;
  398.  
  399. } // create
  400. // .....................................................................
  401. /**
  402. * Process an uploaded media file, and define this catalog item to be
  403. * the newly uploaded file. Assuming a valid upload is performed, this
  404. * catalog item will be added to the database, and the file stahsed
  405. * in the media directory. This method is provided to allow for easy
  406. * handling of upload form submission particularly for the Axyl media
  407. * catalog. Ie. use this if you have a form which is just for uploading
  408. * new images, movies etc. to the Axyl catalog.
  409. * @param string $name Media file associated name
  410. * @param string $category Media file associated category
  411. * @param string $desc Media file full description
  412. * @param string $keywords Media file associated keywords
  413. * @return array Error messages, if any occurred
  414. */
  415. function upload($name="", $category="", $desc="", $keywords="") {
  416. global $CATALOGDIR, $RESPONSE;
  417. global $_overwrite;
  418.  
  419. $this->valid = false;
  420. $errmsgs = array();
  421. $up = new fileupload();
  422. if ($up->uploaded_count >= 1) {
  423. // Process uploaded file..
  424. $file_mime = $up->mimetype;
  425.  
  426. // The relative URL path we will save on the DB record..
  427. $filepath = "$CATALOGDIR/$up->filename";
  428. // The physical path on the filesystem..
  429. $destpath = $RESPONSE->site_docroot . $filepath;
  430.  
  431. // Check pre-existence/overwrite flag..
  432. if (!file_exists($destpath) || isset($_overwrite)) {
  433. // Determine mime_category..
  434. if ($mime_category == "" ) {
  435. $mime_category = mimetype_category($file_mime);
  436. if ($mime_category == "") {
  437. $file_mime = mimetype_from_filename($up->filename);
  438. $mime_category = mimetype_category($file_mime);
  439. if ($mime_category == "") {
  440. $errmsgs[] = "That file is of a type unknown to the system [$file_mime].";
  441. }
  442. }
  443. }
  444. // Carry on if legal mime_category..
  445. if ($mime_category != "") {
  446. // Store file in catalog..
  447. $srcpath = tempnam("/tmp", "CATA");
  448. $tempdir = dirname($srcpath);
  449. $tempfname = basename($srcpath);
  450. if ($up->store($tempdir, $tempfname)) {
  451.  
  452. // If we are doing this from a microsite, then possibly
  453. // assign the category, if not already assigned..
  454. if ($RESPONSE->microsites_mode == MICROSITES_ENABLED) {
  455. if ($RESPONSE->microsite_detected != "" && $category == "") {
  456. $category = $RESPONSE->microsite_detected;
  457. }
  458. }
  459. // Move new media file into place, and save data to DB..
  460. $this->create(
  461. $srcpath, $destpath, $filepath,
  462. $file_mime,
  463. 0, 0,
  464. $name, $category, $desc, $keywords
  465. );
  466. // Tidy up temporary file..
  467. if (is_writeable($srcpath)) {
  468. unlink($srcpath);
  469. }
  470. }
  471. else {
  472. $errmsgs[] = $up->error_message();
  473. }
  474. }
  475. else {
  476. $errmsgs[] = "No content type was specified.";
  477. }
  478. }
  479. else {
  480. $errmsgs[] = "File exists. Check the box to overwrite.";
  481. $overwrite_chk = true;
  482. }
  483. }
  484. else {
  485. $errmsgs[] = "Nothing was uploaded.";
  486. }
  487. return $errmsgs;
  488. } // upload
  489. // .....................................................................
  490. /**
  491. * Render the catalog item. We render it as either and icon or a link,
  492. * both being clickable to view the content.
  493. * @param string $mode Mode of rendering: 'icon' or 'link'.
  494. * @return string HTML rendering of this catalog item in given mode
  495. */
  496. function html($mode="link") {
  497. $s = "";
  498. switch ($mode) {
  499. case "icon":
  500. $s = $this->AsIcon();
  501. break;
  502. case "insitu":
  503. $s = $this->Insitu(false);
  504. break;
  505. default: // case "link"
  506. $s = $this->AsLink();
  507. } // switch
  508. return $s;
  509. } // html
  510.  
  511.  
  512.  
  513. } // catalogitem class
  514. // -----------------------------------------------------------------------
  515.  
  516. /**
  517. * This class encapsulates a media catalog, which is a collection of
  518. * catalogitem objects.
  519. * @package catalog
  520. */
  521. class catalog extends RenderableObject {
  522. /** The array of catalogitem objects in this catalog */
  523.  
  524. var $catalogitems = array();
  525. /** The array of categories (optional) */
  526.  
  527. var $categories = array();
  528. // .....................................................................
  529. /** Constructor */
  530.  
  531. function catalog($catalogitems=false) {
  532. if (is_array($catalogitems)) {
  533. $this->catalogitems = $catalogitems;
  534. }
  535. } // catalog
  536. // .....................................................................
  537. /** Return the count of items in the catalog currently.
  538. * @return integer Count of items in the catalog.
  539. */
  540. function itemcount() {
  541. return count($this->catalogitems);
  542. }
  543. // .....................................................................
  544. /**
  545. * Define the list of user categories which is used to categorise
  546. * the catalog items in this catalog. This is submitted as an
  547. * associative array with a single word string as key, and a multi-word
  548. * string as the value (category description).
  549. * @param array $cats Array of catalog categories: ID => description
  550. */
  551. function set_categories($categories) {
  552. if (is_array($categories)) {
  553. $this->categories = $categories;
  554. }
  555. } // define_categories
  556. // .....................................................................
  557. /**
  558. * Add catalog item to the catalog. The catalog will add the new item
  559. * by cat_id. If that ID already exists it is overwritten.
  560. * @param object $catitem The catalog item to add
  561. */
  562. function additem($catitem) {
  563. if (is_object($catitem) && is_a($catitem, "catalogitem")) {
  564. $this->catalogitems[$catitem->cat_id] = $catitem;
  565. }
  566. } // additem
  567. // .....................................................................
  568. /**
  569. * Find a catalogitem by filepath. Just trawls the array of catalog
  570. * items in this catalog comparing filepaths. Returns false if not found
  571. * else a copy of the catalogitem object.
  572. * @param string $filepath Website URL that image is located at.
  573. * @return mixed False if we didn't match a filepath, else catalog item copy.
  574. */
  575. function get_catalogitem_by_filepath($filepath) {
  576. $found = false;
  577. foreach ($this->catalogitems as $catitem) {
  578. if ($catitem->filepath == $filepath) {
  579. $found = $catitem;
  580. break;
  581. }
  582. }
  583. return $found;
  584. } // get_catalogitem_by_filepath
  585. // .....................................................................
  586. /**
  587. * Perform a search for catalog items. This method will use Lucene
  588. * if it is available and keywords are provided, otherwise it will
  589. * just go to the database. The end result is that this catalog is
  590. * populated with the results of the search, having been cleared out
  591. * beforehand.
  592. * @param string $keywords Keywords to search for
  593. * @param array $mimecats Array of content types (mime categories)
  594. * @param array $categories Array of media user-categories
  595. * @param strong $sortby Sort order for results
  596. */
  597. function search($keywords="", $mimecats="", $categories="", $sortby="") {
  598. global $CONTEXT;
  599.  
  600. // Initialise catalog..
  601. $this->catalogitems = array();
  602.  
  603. // LUCENE KEYWORD SEARCH..
  604. if ($keywords != "" && isset($CONTEXT) && $CONTEXT->configvalue("Lucene Site Indexing")) {
  605. $thesearch = new lucene_search();
  606.  
  607. // CONTENT TYPES
  608. if (is_array($mimecats) && count($mimecats) > 0) {
  609. $terms = array();
  610. foreach ($mimecats as $mimecat) {
  611. // The nullstring represents 'Any' or 'All'..
  612. if ($mimecat != "") $terms[] = $mimecat;
  613. }
  614. if (count($terms) > 0) {
  615. $thesearch->must_match( "mimecat:(" . implode(" ", $terms) . ")" );
  616. }
  617. }
  618.  
  619. // CATEGORIES
  620. $thesearch->does_not_match( "category:sitecontent" );
  621. if (is_array($categories) && count($categories) > 0) {
  622. $terms = array();
  623. foreach ($categories as $cat) {
  624. // The nullstring represents 'Any' or 'All'..
  625. if ($cat != "") $terms[] = $cat;
  626. }
  627. if (count($terms) > 0) {
  628. $thesearch->must_match( "category:(" . implode(" ", $terms) . ")" );
  629. }
  630. }
  631.  
  632. // KEYWORDS
  633. // Keywords matching. We search the keywords fields, and
  634. // also the default text field..
  635. if ($keywords != "") {
  636. $words = explode(" ", $keywords);
  637. $terms = array();
  638. foreach ($words as $word) {
  639. if ($word != "") $terms[] = "$word^2";
  640. }
  641. $keyword_terms = implode(" ", $terms);
  642.  
  643. $terms = array();
  644. foreach ($words as $word) {
  645. if ($word != "") $terms[] = $word;
  646. }
  647. $text_terms = implode(" ", $terms);
  648. // Construct the search terms..
  649. $thesearch->must_match( "(keywords:($keyword_terms) ($text_terms))" );
  650. }
  651.  
  652. // SORT ORDER
  653. switch ($sortby) {
  654. case "rank":
  655. $thesearch->set_sortorder("RANK");
  656. break;
  657. case "uploaded":
  658. $thesearch->set_sortorder("uploaded:Date:Desc");
  659. break;
  660. case "catname":
  661. $thesearch->set_sortorder("catname");
  662. break;
  663. case "mimecat":
  664. $thesearch->set_sortorder("mimecat,uploaded:Date:Desc");
  665. break;
  666. case "category":
  667. $thesearch->set_sortorder("category,uploaded:Date:Desc");
  668. break;
  669. default:
  670. $thesearch->set_sortorder("uploaded:Date:Desc");
  671. break;
  672. } // switch
  673.  
  674. // RETURN FIELDS
  675. $thesearch->set_returnfields("catname,category,mimecat,uploaded:Date,path");
  676. $thesearch->execute();
  677.  
  678. // Populate the catalog..
  679. if ($thesearch->hitcount() > 0) {
  680. foreach ($thesearch->hit as $hit) {
  681. $ci = new catalogitem();
  682. $bits = explode("_", $hit["Id"]);
  683. $ci->cat_id = $bits[1];
  684. $ci->cat_name = $hit["catname"];
  685. $ci->category = $hit["category"];
  686. $ci->mime_category = $hit["mimecat"];
  687. $ci->uploaded_ts = $hit["uploaded"];
  688. $ci->uploaded = timestamp_to_displaydate(NICE_FULLDATETIME, $ci->uploaded_ts);
  689. $ci->filepath = $hit["path"];
  690. $ci->valid = true;
  691. $ci->newcat = false;
  692. $this->catalogitems[$ci->cat_id] = $ci;
  693. }
  694. }
  695.  
  696. } // got keywords & lucene
  697. else {
  698. $cQ = new dbselect("ax_catalog");
  699. $wheres = array();
  700.  
  701. // CONTENT TYPES
  702. if (is_array($mimecats) && count($mimecats) > 0) {
  703. // The nullstring represents 'Any' or 'All'..
  704. if (!in_array("", $mimecats)) {
  705. $wheres[] = "mime_category IN ('" . implode("','", $mimecats) . "')";
  706. }
  707. }
  708.  
  709. // CATEGORIES
  710. if (is_array($categories) && count($categories) > 0) {
  711. // The nullstring represents 'Any' or 'All'..
  712. if (!in_array("", $categories)) {
  713. if ($where != "") $where .= " AND ";
  714. $wheres[] = "category IN ('" . implode("','", $categories) . "')";
  715. }
  716. }
  717. if (count($wheres) > 0) {
  718. $cQ->where( implode(" AND ", $wheres) );
  719. }
  720.  
  721. // SORT ORDER
  722. switch ($sortby) {
  723. case "uploaded":
  724. $cQ->orderby("upload_timestamp DESC");
  725. break;
  726. case "catname":
  727. $cQ->orderby("cat_name");
  728. break;
  729. case "mimecat":
  730. $cQ->orderby("mime_category");
  731. break;
  732. case "category":
  733. $cQ->orderby("category");
  734. break;
  735. default:
  736. $cQ->orderby("upload_timestamp DESC");
  737. break;
  738. } // switch
  739.  
  740. $cQ->execute();
  741. if ($cQ->hasdata) {
  742. do {
  743. $ci = new catalogitem();
  744. $ci->cat_id = $cQ->field("cat_id");
  745. $ci->cat_name = $cQ->field("cat_name");
  746. $ci->category = $cQ->field("category");
  747. $ci->mime_category = $cQ->field("mime_category");
  748. $ci->uploaded_ts = datetime_to_timestamp($cQ->field("upload_timestamp"));
  749. $ci->uploaded = timestamp_to_displaydate(NICE_FULLDATETIME, $ci->uploaded_ts);
  750. $ci->filepath = $cQ->field("filepath");
  751. $ci->valid = true;
  752. $ci->newcat = false;
  753. $this->catalogitems[$ci->cat_id] = $ci;
  754. } while ($cQ->get_next());
  755. }
  756. }
  757.  
  758. } // search
  759. // .....................................................................
  760. /** Return the HTML for this catalog. Returns the list of catalog items
  761. * as an HTML table.
  762. * @return string HTML table containing the whole catalog
  763. */
  764. function html() {
  765. global $RESPONSE, $LIBDIR;
  766. return $s;
  767. } // html
  768.  
  769.  
  770.  
  771. } // catalog class
  772. // -----------------------------------------------------------------------
  773.  
  774. ?>

Documentation generated by phpDocumentor 1.3.0RC3