コード例 #1
0
 public function __construct()
 {
     parent::__construct("https://i-share.carli.illinois.edu/newbooks/newbooks.cgi?library=WHEdb&list=all&day=7&op=and&text=&lang=English&submit=RSS");
     $nitems = count($this->xml->channel->item);
     for ($i = 0; $i < $nitems; ++$i) {
         $tidy_desc = \str_replace(array('&lt;B&gt;', '&lt;/B&gt;', '<description>', '</description>'), '', $this->xml->channel->item[$i]->description->asXML());
         $matches = array();
         if (\preg_match('@&lt;img border="0" src="(.*)" vspace="3" border="0" align="right"/&gt;@', $tidy_desc, $matches)) {
             if (\util\Utility::isValidImage($matches[1])) {
                 $imgurl = $matches[1];
             } else {
                 $imgurl = "";
             }
             $tidy_desc = str_replace($matches[0], '', $tidy_desc);
         } else {
             $imgurl = "";
         }
         $fieldstr = \explode('&lt;BR/&gt;', $tidy_desc);
         $this->xml->channel->item[$i]->description = \implode("\n", $fieldstr);
         $fields = array();
         foreach ($fieldstr as $f) {
             //separate field name and field value
             $matches = array();
             if (\preg_match("/^([-a-zA-Z_ ]*[a-zA-Z]{4}): /", $f, $matches)) {
                 $fname = \strtolower(str_replace(' ', '_', \trim($matches[1])));
                 $fvalue = \trim(str_replace($matches[0], '', $f));
                 $fields[$fname] = $fvalue;
                 $this->xml->channel->item[$i]->addChild($fname, $fvalue);
             }
         }
         $cn_data = \cn\processor\Factory::make($fields)->data();
         foreach ($cn_data as $name => $value) {
             $name = \htmlspecialchars($name);
             $value = \htmlspecialchars($value);
             $this->xml->channel->item[$i]->addChild($name, $value);
         }
         unset($this->xml->channel->item[$i]->description[0]);
         if (!\util\Utility::isValidImage($imgurl)) {
             $imgurl = "";
         }
         $this->xml->channel->item[$i]->addChild('cover', $imgurl);
     }
 }
コード例 #2
0
 private static function normalize($cn)
 {
     $cn_orig = $cn;
     $regex_alpha = "([A-Z]{1,3})";
     $regex_num = "([0-9]{0,4})";
     $regex_extra = "([ ]?\\.[A-Z0-9][0-9]*)";
     $regex = "/^{$regex_alpha}{$regex_num}?{$regex_extra}?/";
     $matches = array();
     if (preg_match($regex, $cn, $matches)) {
         //normalize alpha
         $alpha = $matches[1];
         //.\util\Utility::ntimes('*',3-strlen($matches[1]));
         //normalize num
         if (array_key_exists(2, $matches)) {
             $num = $matches[2] . \util\Utility::ntimes('*', 4 - strlen($matches[2]));
         } else {
             $num = "****";
         }
         //normalize extra
         if (array_key_exists(3, $matches)) {
             $extra_match = array();
             if (preg_match("/([A-Z])/", $matches[3], $extra_match)) {
                 $ch = $extra_match[0];
                 $i = 2;
             } else {
                 $ch = '*';
                 $i = 1;
             }
             $extra = $ch . substr($matches[3], $i);
         } else {
             $extra = "";
         }
         return str_split($alpha . $num . $extra);
     }
     error_log("failed to normalize: {$cn_orig}");
     return;
 }
コード例 #3
0
 public function matches($range)
 {
     foreach (\util\Utility::parseRange($range) as $r) {
         if (count($r) === 1) {
             if ($this->equals($r[0])) {
                 return true;
             }
         } else {
             if ($this->greaterThan($r[0]) && $this->lessThan($r[1])) {
                 return true;
             }
         }
     }
     return false;
 }