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("search-lucene-defs.php");
  28. include_once("search-index-defs.php");
  29. include_once("search-query-defs.php");
  30. /** Filesystem access */
  31. ("file-defs.php");
  32.  
  33. // -----------------------------------------------------------------------
  34. /**
  35. * A class which encpasulates an item which can be in the catalog.
  36. * @package catalog
  37. */
  38. class catalogitem extends RenderableObject {
  39. var $cat_id; // Unique catalog record key for the catalog item
  40. var $cat_name = ""; // Name of this catalog item
  41. var $cat_desc = ""; // Full description of catalog item
  42. var $mime_type = ""; // Mime-type of catalog item
  43. var $mime_category = ""; // Mime category eg: document, movie, audio etc.
  44. var $keywords = ""; // Any keywords associated with it
  45. var $category = ""; // Optional user-defined category for item
  46. var $filesize = ""; // Size of catalog item in bytes
  47. var $filepath = ""; // Website URL path to the item (with leading '/')
  48. var $physicalpath = ""; // Full physical path on the filesystem
  49. var $fileexists = false; // True if file exists at filepath
  50. var $width = 0; // Pixel width of this item
  51. var $height = 0; // Pixel height of this item
  52. var $uploaded_ts = 0; // Unix timestamp of datetime item was added to catalog
  53. var $uploaded = ""; // Datetime uploaded, NICE_FULLDATETIME format
  54. var $errmsg = ""; // Contains error message if invalid
  55. var $valid = false; // True if item was retreived successfully
  56. var $newcat = false; // True if we just created this story
  57.  
  58. // .....................................................................
  59. /** Constructor
  60. * @param integer $id Optional unique catalog item ID
  61. */
  62. function catalogitem($id=false) {
  63. // The all-important catalog ID..
  64. $this->cat_id = $id;
  65. if (!$id) {
  66. $this->newcat = true;
  67. $this->valid = true;
  68. }
  69. // Further processing for existing items..
  70. if (!$this->newcat) {
  71. // Attempt to get the catlog item
  72. $this->get();
  73. }
  74.  
  75. } // catalogitem
  76. // .....................................................................
  77. /** Get current or nominated catalog item definition from the database.
  78. * @param integer $id Optional unique catalog item ID to get
  79. */
  80. function get($id=false) {
  81. global $RESPONSE;
  82. $res = false;
  83. if ($id) $this->cat_id = $id;
  84. if ($this->cat_id) {
  85. $catQ = dbrecordset("SELECT * FROM ax_catalog WHERE cat_id=$this->cat_id");
  86. if ($catQ->hasdata) {
  87. $this->cat_name = $catQ->field("cat_name");
  88. $this->cat_desc = $catQ->field("cat_desc");
  89. $this->mime_type = $catQ->field("mime_type");
  90. $this->mime_category = $catQ->field("mime_category");
  91. $this->keywords = $catQ->field("keywords");
  92. $this->category = $catQ->field("category");
  93. $this->filesize = $catQ->field("filesize");
  94. $this->filepath = $catQ->field("filepath");
  95. $this->width = $catQ->field("width");
  96. $this->height = $catQ->field("height");
  97. $this->uploaded_ts = datetime_to_timestamp($catQ->field("upload_timestamp"));
  98. $this->uploaded = timestamp_to_displaydate(NICE_FULLDATETIME, $this->uploaded_ts);
  99. // Update status of physical file..
  100. $this->physicalpath = $RESPONSE->site_docroot . $this->filepath;
  101. $this->fileexists = file_exists($this->physicalpath);
  102. $res = true;
  103. $this->newcat = false;
  104. }
  105. else $this->errmsg = "No record of catalog item: $this->cat_id";
  106. }
  107. else $this->errmsg = "No catalog ID was given";
  108. // Did we succeed..?
  109. $this->valid = $res;
  110. return $res;
  111. } // get
  112. // .....................................................................
  113. /** Save current catalog item definition to the database. Inserts
  114. * if brand new, else performs an update.
  115. */
  116. function save() {
  117. global $RESPONSE;
  118. $res = false;
  119. if ($this->newcat || ($this->cat_id && $this->valid)) {
  120. if ($this->newcat) {
  121. $this->cat_id = get_next_sequencevalue("seq_cat_id", "ax_catalog", "cat_id");
  122. $this->uploaded_ts = time();
  123. $this->uploaded = timestamp_to_displaydate(NICE_FULLDATETIME, $this->uploaded_ts);
  124. $cup = new dbinsert("ax_catalog");
  125. $cup->set("cat_id", $this->cat_id);
  126. $this->newcat = false;
  127. }
  128. else {
  129. $cup = new dbupdate("ax_catalog");
  130. $cup->where("cat_id=$this->cat_id");
  131. }
  132. $cup->set("cat_name", $this->cat_name);
  133. $cup->set("cat_desc", $this->cat_desc);
  134. $cup->set("mime_type", $this->mime_type);
  135. $cup->set("mime_category", $this->mime_category);
  136. $cup->set("keywords", $this->keywords);
  137. $cup->set("category", $this->category);
  138. $cup->set("filesize", $this->filesize);
  139. $cup->set("filepath", $this->filepath);
  140. $cup->set("width", $this->width);
  141. $cup->set("height", $this->height);
  142. $cup->set("upload_timestamp", timestamp_to_datetime($this->uploaded_ts));
  143. $res = $cup->execute();
  144. if ($res) {
  145. // Index to search engine..
  146. $this->index();
  147. // Update status of physical file..
  148. $this->physicalpath = $RESPONSE->site_docroot . $this->filepath;
  149. $this->fileexists = file_exists($this->physicalpath);
  150. }
  151. }
  152. return $res;
  153. } // save
  154. // .....................................................................
  155. /**
  156. * Remove the catalog item from the database and disk. This method
  157. * normally tries to remove the physical file first, and if that succeeds
  158. * it removes the database record. If $deletefile is false then the file
  159. * will be left and only the DB record deleted.
  160. * @param boolean $deletefile If true the physical file will be deleted
  161. * @return boolean True if the operation succeeded, else false.
  162. */
  163. function delete($deletefile=true) {
  164. global $RESPONSE, $IMAGESDIR;
  165. $deleted = false;
  166. $err = false;
  167. if ($this->cat_id && $this->valid) {
  168. // First, deal to the physical file..
  169. if ($deletefile) {
  170. if (file_exists($this->physicalpath)) {
  171. // Avoid deleting images which are part of the standard issue..
  172. if (substr($this->filepath, 0, strlen($IMAGESDIR)) != $IMAGESDIR) {
  173. if (!is_writeable($this->physicalpath) || !unlink($this->physicalpath)) {
  174. $err = true;
  175. }
  176. }
  177. }
  178. }
  179. // Delete the database record now..
  180. if (!$err) {
  181. $dcat = new dbdelete("ax_catalog");
  182. $dcat->where("cat_id=$this->cat_id");
  183. $res = $dcat->execute();
  184. if ($res) {
  185. // Remove from search engine index..
  186. $this->unindex();
  187. $this->valid = false;
  188. $deleted = true;
  189. }
  190. }
  191. }
  192. return $deleted;
  193. } // delete
  194. // .....................................................................
  195. /**
  196. * Index this catalog item to the search engine.
  197. * If it exists already, index entry for this item is replaced.
  198. */
  199. function index() {
  200. global $SE_AVAILABLE;
  201. if ($this->valid && $SE_AVAILABLE) {
  202. $I = new searchengine_indexer();
  203. // Make sure these fields are stored..
  204. $I->define_field("catname", "Text", STORED);
  205. $I->define_field("category", "Text", STORED);
  206. $I->define_field("mimecat", "Text", STORED);
  207. $I->define_field("uploaded", "Date", STORED);
  208. $I->define_field("path", "text", STORED);
  209. // Index the fields..
  210. $I->index_field("Id", "CAT_" . $this->cat_id);
  211. $I->index_field("keywords", $this->keywords);
  212. $I->index_field("catname", $this->cat_name);
  213. $I->index_field("category", $this->category);
  214. $I->index_field("mimecat", $this->mime_category);
  215. $I->index_field("uploaded", $this->uploaded_ts);
  216. $I->index_field("path", $this->filepath);
  217. // Index the content..
  218. $allcontent[] = $this->cat_name;
  219. $allcontent[] = $this->cat_desc;
  220. $allcontent[] = $this->keywords;
  221. $I->index_content("CAT_" . $this->cat_id, implode(" ", $allcontent));
  222. $I->execute();
  223. }
  224. } // index
  225. // .....................................................................
  226. /** Remove this catalog item from the search engine index. */
  227.  
  228. function unindex() {
  229. global $SE_AVAILABLE;
  230. if ($this->valid && $SE_AVAILABLE) {
  231. $UI = new searchengine_unindexer();
  232. $UI->unindex("CAT_" . $this->cat_id);
  233. $UI->execute();
  234. }
  235. } // unindex
  236. // .....................................................................
  237. /** Return the catalog item as a clickable icon.
  238. * @param boolean $autostart Movies etc. if true start automatically
  239. */
  240. function AsIcon($showcontrols=false, $autostart=false, $loop=false) {
  241. $icon = "";
  242. $tooltip = basename($this->filepath);
  243. // Set commonsense values for movies..
  244. if (!$showcontrols) {
  245. $autostart = true;
  246. $loop = true;
  247. }
  248. switch ($this->mime_category) {
  249. case "movie":
  250. $media = new MediaObject($this->filepath, $this->width, $this->height, $autostart, $loop, $showcontrols);
  251. $media->AsIcon($tooltip);
  252. $icon = $media->render();
  253. break;
  254. case "audio":
  255. $media = new MediaObject($this->filepath, $this->width, $this->height, $autostart, $loop, $showcontrols);
  256. $media->AsIcon($tooltip);
  257. $icon = $media->render();
  258. break;
  259. case "flash":
  260. $media = new FlashObject($this->filepath, $this->width, $this->height, $autostart, $loop);
  261. $media->AsIcon($tooltip);
  262. $icon = $media->render();
  263. break;
  264. case "document":
  265. $media = new DocumentObject($this->filepath, $this->width, $this->height);
  266. $media->AsIcon($tooltip);
  267. $icon = $media->render();
  268. break;
  269. case "image":
  270. $media = new img($this->filepath, $this->cat_name);
  271. $media->AsIcon($tooltip);
  272. $icon = $media->render();
  273. break;
  274. default:
  275. $icon = $this->AsLink();
  276. } // switch
  277. return $icon;
  278. } // AsIcon
  279. // .....................................................................
  280. /** Return the catalog item as image, a clickable icon, or otherwise a link.
  281. * @param boolean $autostart Movies etc. if true start automatically
  282. */
  283. function Insitu($showcontrols=false, $autostart=false, $loop=false) {
  284. $catmedia = "";
  285. $tooltip = basename($this->filepath);
  286. // Set commonsense values for movies..
  287. if (!$showcontrols) {
  288. $autostart = true;
  289. $loop = true;
  290. }
  291. switch ($this->mime_category) {
  292. case "movie":
  293. $media = new MediaObject($this->filepath, $this->width, $this->height, $autostart, $loop, $showcontrols);
  294. $catmedia = $media->render();
  295. break;
  296. case "flash":
  297. $media = new FlashObject($this->filepath, $this->width, $this->height, $autostart, $loop);
  298. $catmedia = $media->render();
  299. break;
  300. case "image":
  301. $media = new img(
  302. $this->filepath,
  303. str_replace(" ", "", $this->cat_name),
  304. ($this->cat_desc != "" ? $this->cat_desc : $this->cat_name)
  305. );
  306. $catmedia = $media->render();
  307. break;
  308. default:
  309. $catmedia = $this->AsIcon();
  310. } // switch
  311. return $catmedia;
  312. } // In-situ
  313. // .....................................................................
  314. /** Return the catalog item as a clickable hyperlink. */
  315.  
  316. function AsLink() {
  317. $catlink = new anchor($this->filepath, $this->cat_name);
  318. $catlink->set_linkover_text( basename($this->filepath) );
  319. return $catlink->render();
  320. } // AsLink
  321. // .....................................................................
  322. /**
  323. * Create this catalog item from a media file on disk. The media item
  324. * should be located at a physical path on disk somewhere. It will be grabbed,
  325. * moved to a new location, and the item record saved to the DB.
  326. * NOTE: this may be an existing catalogitem, OR a newly created one. This
  327. * is not determined by this routine, but must be set up before calling this
  328. * method. The save() method then does whatever is necessary.
  329. * @param string $srcpath The full physical filesystem path to the source media
  330. * @param string $destpath The full physical path of where to move the media
  331. * @param string $filepath The relative path of the media, to save on DB record
  332. * @param string $mimetype The mime type of the file, eg: "image/jpeg"
  333. * @param string $name Media file associated name
  334. * @param string $category Media file associated category
  335. * @param string $desc Media file full description
  336. * @param string $keywords Media file associated keywords
  337. * @return boolean True if all ok, else false
  338. */
  339. function create(
  340. $srcpath, $destpath, $filepath,
  341. $mimetype="",
  342. $width=0, $height=0,
  343. $name="", $category="", $desc="", $keywords=""
  344. ) {
  345. global $RESPONSE;
  346.  
  347. // Valid flag..
  348. $this->valid = false;
  349.  
  350. // Move file to destination & create our catalog record..
  351. if (is_readable($srcpath)) {
  352.  
  353. // Determine mime-type
  354. if ($mimetype == "") {
  355. $mimetype = mimetype_from_filename($srcpath);
  356. }
  357. // Determine mime-category..
  358. $mime_category = mimetype_category($mimetype);
  359.  
  360. // Size of this file..
  361. $filesize = filesize($srcpath);
  362.  
  363. // Image metrics..
  364. if ($mime_category == "image") {
  365. $imginfo = getimagesize($srcpath);
  366. $width = $imginfo[0];
  367. $height = $imginfo[1];
  368. }
  369. // Move to destination, if different to source location..
  370. if (realpath($destpath) != realpath($srcpath)) {
  371. if (copy($srcpath, $destpath) === false) {
  372. $errmsgs[] = "failed to copy new media to its destination: $srcpath --> $destpath";
  373. }
  374. }
  375. // Store file in database..
  376. if ($name == "") {
  377. $name = basename($srcpath);
  378. }
  379. $this->cat_name = $name;
  380. $this->cat_desc = $desc;
  381. $this->keywords = $keywords;
  382. $this->category = $category;
  383. $this->mime_category = $mime_category;
  384. $this->mime_type = $mimetype;
  385. $this->filesize = $filesize;
  386. $this->filepath = $filepath;
  387. $this->physicalpath = $destpath;
  388. $this->fileexists = file_exists($destpath);
  389. $this->width = $width;
  390. $this->height = $height;
  391. if ($this->save()) {
  392. $this->valid = true;
  393. }
  394. else {
  395. $errmsgs[] = "failed to save catalog item $this->cat_id to database.";
  396. }
  397. }
  398. // Return the status..
  399. return $this->valid;
  400.  
  401. } // create
  402. // .....................................................................
  403. /**
  404. * Process an uploaded media file, and define this catalog item to be
  405. * the newly uploaded file. Assuming a valid upload is performed, this
  406. * catalog item will be added to the database, and the file stahsed
  407. * in the media directory. This method is provided to allow for easy
  408. * handling of upload form submission particularly for the Axyl media
  409. * catalog. Ie. use this if you have a form which is just for uploading
  410. * new images, movies etc. to the Axyl catalog.
  411. * @param string $name Media file associated name
  412. * @param string $category Media file associated category
  413. * @param string $desc Media file full description
  414. * @param string $keywords Media file associated keywords
  415. * @return array Error messages, if any occurred
  416. */
  417. function upload($name="", $category="", $desc="", $keywords="") {
  418. global $CATALOGDIR, $RESPONSE;
  419. global $_overwrite;
  420.  
  421. $this->valid = false;
  422. $errmsgs = array();
  423. $up = new fileupload();
  424. if ($up->uploaded_count >= 1) {
  425. // Process uploaded file..
  426. $file_mime = $up->mimetype;
  427.  
  428. // The relative URL path we will save on the DB record..
  429. $filepath = "$CATALOGDIR/$up->filename";
  430. // The physical path on the filesystem..
  431. $destpath = $RESPONSE->site_docroot . $filepath;
  432.  
  433. // Check pre-existence/overwrite flag..
  434. if (!file_exists($destpath) || isset($_overwrite)) {
  435. // Determine mime_category..
  436. $mime_category = mimetype_category($file_mime);
  437. if ($mime_category == "") {
  438. $file_mime = mimetype_from_filename($up->filename);
  439. $mime_category = mimetype_category($file_mime);
  440. if ($mime_category == "") {
  441. $errmsgs[] = "That file is of a type unknown to the system [$file_mime].";
  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 the search
  588. * engine 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 $SE_AVAILABLE;
  599.  
  600. // Initialise catalog..
  601. $this->catalogitems = array();
  602.  
  603. // KEYWORD SEARCH..
  604. if ($keywords != "" && $SE_AVAILABLE) {
  605. $thesearch = new searchengine_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
  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. $wheres[] = "category IN ('" . implode("','", $categories) . "')";
  714. }
  715. }
  716. if (count($wheres) > 0) {
  717. $cQ->where( implode(" AND ", $wheres) );
  718. }
  719.  
  720. // SORT ORDER
  721. switch ($sortby) {
  722. case "uploaded":
  723. $cQ->orderby("upload_timestamp DESC");
  724. break;
  725. case "catname":
  726. $cQ->orderby("cat_name");
  727. break;
  728. case "mimecat":
  729. $cQ->orderby("mime_category");
  730. break;
  731. case "category":
  732. $cQ->orderby("category");
  733. break;
  734. default:
  735. $cQ->orderby("upload_timestamp DESC");
  736. break;
  737. } // switch
  738.  
  739. $cQ->execute();
  740. if ($cQ->hasdata) {
  741. do {
  742. $ci = new catalogitem();
  743. $ci->cat_id = $cQ->field("cat_id");
  744. $ci->cat_name = $cQ->field("cat_name");
  745. $ci->category = $cQ->field("category");
  746. $ci->mime_category = $cQ->field("mime_category");
  747. $ci->uploaded_ts = datetime_to_timestamp($cQ->field("upload_timestamp"));
  748. $ci->uploaded = timestamp_to_displaydate(NICE_FULLDATETIME, $ci->uploaded_ts);
  749. $ci->filepath = $cQ->field("filepath");
  750. $ci->valid = true;
  751. $ci->newcat = false;
  752. $this->catalogitems[$ci->cat_id] = $ci;
  753. } while ($cQ->get_next());
  754. }
  755. }
  756.  
  757. } // search
  758. // .....................................................................
  759. /** Return the HTML for this catalog. Returns the list of catalog items
  760. * as an HTML table.
  761. * @return string HTML table containing the whole catalog
  762. */
  763. function html() {
  764. global $RESPONSE, $LIBDIR;
  765. return "";
  766. } // html
  767.  
  768.  
  769.  
  770. } // catalog class
  771. // -----------------------------------------------------------------------
  772.  
  773. ?>

Documentation generated by phpDocumentor 1.3.0RC3