protected function doClean($value) { // Getting URL $url = parent::doClean($value); // Getting key $urlExp = explode('/', $url); $id = $urlExp[count($urlExp) - 1]; // Building URL $jHeberg = "http://www.jheberg.net/api/check-link"; $jHeberg .= "?id=" . $id; if ($this->getOption('key') != null) { $jHeberg .= "&key=" . $this->getOption('key'); } // Calling URL (getting JSON string) $json = file_get_contents($jHeberg); // If calling fails again if ($json === false) { throw new sfValidatorError($this, 'calling'); } // Decoding JSON in array $json = json_decode($json, true); // Declaring size define('SIZE', $json['fileSize']); // AntiLeech mode if ($this->getOption('antileech')) { $q = Doctrine_Query::create()->select('COUNT(*)')->from('Ips')->where('ip = ?', $json['ownerIp'])->andWhere('uid = ?', sfContext::getInstance()->getUser()->getAttribute("id"))->execute(array(), Doctrine::HYDRATE_SINGLE_SCALAR); // If owner IP doesn't match if ($q == 0) { throw new sfValidatorError($this, 'antileech'); } } return $url; }
protected function doClean($value) { if (preg_match('/^[\\w\\+-]+\\./', $value)) { $value = 'http://' . $value; } return parent::doClean($value); }
/** * @see sfValidatorUrl */ protected function doClean($value) { try { return parent::doClean($value); } catch (sfValidatorError $e) { if (strncmp($value, 'page:', 5) === 0 && dmDb::table('DmPage')->findOneBySource($value)) { return $value; } elseif (strncmp($value, 'media:', 6) === 0 && dmDb::table('DmMedia')->findOneByIdWithFolder(substr($value, 6))) { return $value; } elseif ('#' === $value[0]) { return $value; } elseif ('@' === $value[0]) { return $value; } throw $e; } }