dc:subject elements, matching a * whitespace-bounded word given in the subject query param. */ // header('Content-Type: application/rss+xml'); require_once '../includes/common.php'; require_once 'FeedMagick/SaxFeedFilter.php'; class DCSubjectFilter extends FeedMagick_SaxFeedFilter { var $curr_subjects; var $any_subjects; var $nany_subjects; var $all_subjects; var $nall_subjects; var $only_subjects; var $SUBJECT_TAGS = array( 'http://purl.org/dc/elements/1.1/:subject', 'dc:subject', ); function additionalFormParameters() { ?>




any_subjects = array_unique(explode(' ', $_GET['any'])); if (isset($_GET['nany']) && $_GET['nany'] != '') $this->nany_subjects = array_unique(explode(' ', $_GET['nany'])); if (isset($_GET['all']) && $_GET['all'] != '') $this->all_subjects = array_unique(explode(' ', $_GET['all'])); if (isset($_GET['nall']) && $_GET['nall'] != '') $this->nall_subjects = array_unique(explode(' ', $_GET['nall'])); if (isset($_GET['only']) && $_GET['only'] != '') $this->only_subjects = array_unique(explode(' ', $_GET['only'])); FeedMagick_SaxFeedFilter::startDoc(); } function startItem() { $this->allow_item = true; $this->curr_subjects = array(); FeedMagick_SaxFeedFilter::startItem(); } function close(&$tag) { global $log; // Are we inside an item's elements? if ($this->in_item) { // Is this a tag recognized as a subject? if (array_search($tag, $this->SUBJECT_TAGS) !== false) { $subjects = explode(' ', $this->getCDATA()); $this->curr_subjects = array_merge($this->curr_subjects, $subjects); } } // Proceed as normal with tag processing. FeedMagick_SaxFeedFilter::close($tag); } function endItem() { global $log; // Reduce the list of subjects found down to a unique set. $curr_subjects = array_unique($this->curr_subjects); // Assume all is well with this item... list($b_any, $b_nany, $b_all, $b_nall, $b_only) = array(true, true, true, true, true); // Do any of the 'any' subjects appear in the current list? if ($this->any_subjects) { $isect = array_intersect($curr_subjects, $this->any_subjects); $b_any = !(empty($isect)); } // Ensure none of the 'nany' subjects are in the current list. if ($this->nany_subjects) { $isect = array_intersect($curr_subjects, $this->nany_subjects); $b_nany = empty($isect); } // Ensure all of the 'all' subjects are found in the current list. if ($this->all_subjects) { $diff = array_diff($this->all_subjects, $curr_subjects); $b_all = empty($diff); } // Ensure none of the 'nall' subjects are found in the current list. if ($this->nall_subjects) { $diff = array_diff($this->nall_subjects, $curr_subjects); $b_nall = !(empty($diff)); } // Make sure that only the 'only' subjects are found if ($this->only_subjects) { $diff1 = array_diff($this->only_subjects, $curr_subjects); $diff2 = array_diff($curr_subjects, $this->only_subjects); $b_only = empty($diff1) && empty($diff2); } $this->allow_item = ($b_any && $b_nany && $b_all && $b_nall && $b_only); FeedMagick_SaxFeedFilter::endItem(); } } // Instantiate and run the filter only when not being used as an include. if (strpos(basename(__FILE__), basename($_SERVER['SCRIPT_FILENAME'])) !== false) { processFilter(new DCSubjectFilter()); } ?>