/** Get entries fullfilling a condition (bibtex & bibfilter) */ function getEntries($options) { global $wpdb, $papercite_table_name; // --- Filter the data $entries = $this->getData($options["file"], $options); if ($entries === FALSE) { $this->addMessage("[Could not find the bibliography file(s) with name [" . htmlspecialchars($options["file"]) . "]"); return false; } if (array_key_exists('key', $options)) { // Select only specified entries $keys = preg_split("-,-", $options["key"]); $a = array(); $n = 0; $result = papercite::getEntriesByKey($entries, $keys); if (array_key_exists("allow", $options) || array_key_exists("deny", $options) || array_key_exists("author", $options)) { $this->addMessage("[papercite] Filtering by (key argument) is compatible with filtering by type or author (allow, deny, author arguments)", E_USER_NOTICE); } } else { // Based on the entry types $allow = Papercite::array_get($options, "allow", ""); $deny = Papercite::array_get($options, "deny", ""); $allow = $allow ? preg_split("-,-", $allow) : array(); $deny = $deny ? preg_split("-,-", $deny) : array(); $author_matcher = new PaperciteAuthorMatcher(Papercite::array_get($options, "author", "")); $result = array(); $dbs = array(); foreach ($entries as $key => &$outer) { if (is_array($outer) && $outer[0] == "__DB__") { $dbs[] = $outer[1]; } else { foreach ($outer as &$entry) { $t =& $entry["entrytype"]; if ((sizeof($allow) == 0 || in_array($t, $allow)) && (sizeof($deny) == 0 || !in_array($t, $deny)) && $author_matcher->matches($entry) && Papercite::userFiltersMatch($options["filters"], $entry)) { $result[] = $entry; } } } } // --- Add entries from database if ($dbs) { $dbCond = $this->getDbCond($dbs); // Handles year and entry type by direct SQL foreach ($allow as &$v) { $v = '"' . $wpdb->escape($v) . '"'; } $allowCond = $allow ? "and entrytype in (" . implode(",", $allow) . ")" : ""; foreach ($deny as &$v) { $v = '"' . $wpdb->escape($v) . '"'; } $denyCond = $deny ? "and entrytype not in (" . implode(",", $deny) . ")" : ""; // Retrieve and filter further $st = "SELECT data FROM {$papercite_table_name} WHERE {$dbCond} {$denyCond} {$allowCond}"; $rows = $wpdb->get_col($st); if ($rows) { foreach ($rows as $data) { $entry = maybe_unserialize($data); if ($author_matcher->matches($entry) && Papercite::userFiltersMatch($options["filters"], $entry)) { $result[] = $entry; } } } } } return $result; }