public function check($capabilityText) { if (substr($capabilityText, 0, strlen($this->prefix) + 1) !== $this->prefix . "1") { return false; } $value = base64_decode(str_replace(array("-a", "-b", "-", "_"), array("+", "/", "+", "/"), substr($capabilityText, strlen($this->prefix) + 1))); if (strlen($value) >= 16 && ($result = Dbl::ql($this->dblink, "select * from Capability where salt=?", $value)) && ($row = Dbl::fetch_first_object($result)) && ($row->timeExpires == 0 || $row->timeExpires >= time())) { return $row; } else { return false; } }
} $url = str_replace('${EMAIL}', urlencode($row[1]), $url); $url = str_replace('${ID}', urlencode($row[2]), $url); // fwrite(STDOUT, "$row[1] $fetchscript " . escapeshellarg($url) . " "); fwrite(STDOUT, "{$row['1']} "); $handle = popen($fetchscript . " " . escapeshellarg($url), "r"); $data = stream_get_contents($handle); $status = pclose($handle); $content_type = ""; if ($data && ($nl = strpos($data, "\n")) !== false) { $content_type = substr($data, 0, $nl); $data = substr($data, $nl + 1); } $worked = false; if (pcntl_wifexitedsuccess($status) && preg_match(',\\Aimage/,', $content_type)) { $sresult = Dbl::fetch_first_object(Dbl::qe("select ContactImage.* from ContactImage join ContactInfo using (contactImageId) where ContactInfo.contactId=?", $row[0])); if ($sresult && $sresult->mimetype === $content_type && $sresult->data === $data) { $worked = "unchanged"; } else { $iresult = Dbl::qe("insert into ContactImage set contactId=?, mimetype=?, data=?", $row[0], $content_type, $data); if ($iresult) { Dbl::qe("update ContactInfo set contactImageId=? where contactId=?", $iresult->insert_id, $row[0]); $worked = true; } } } if ($worked === "unchanged") { fwrite(STDERR, strlen($data) . "B " . $content_type . " (unchanged)\n"); } else { if ($worked) { fwrite(STDERR, strlen($data) . "B " . $content_type . "\n");
public function document($dtype, $did = 0) { assert($did || $dtype == DTYPE_SUBMISSION || $dtype == DTYPE_FINAL); if ($dtype == DTYPE_SUBMISSION || $dtype == DTYPE_FINAL) { if ($this->finalPaperStorageId <= 0) { $psi = [DTYPE_SUBMISSION, $this->paperStorageId]; } else { $psi = [DTYPE_FINAL, $this->finalPaperStorageId]; } if ($did == 0 || $did == $psi[1]) { return (object) ["paperId" => $this->paperId, "documentType" => $psi[0], "paperStorageId" => $psi[1], "mimetype" => get_s($this, "mimetype"), "size" => get_i($this, "size"), "timestamp" => get_i($this, "timestamp"), "sha1" => get_s($this, "sha1")]; } } // load document object from database if pre-loaded version doesn't work return Dbl::fetch_first_object("select paperId, documentType, paperStorageId, mimetype, size, timestamp, sha1, filename from PaperStorage where paperStorageId=?", $did); }