KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.62
System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64
User : www ( 80)
PHP Version : 8.3.8
Disable Function : NONE
Directory :  /domains/irtiweb/CATS/lib/artichow/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /domains/irtiweb/CATS/lib/artichow/AntiSpam.class.php
<?php
/*
 * This work is hereby released into the Public Domain.
 * To view a copy of the public domain dedication,
 * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
 * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
 *
 */

require_once dirname(__FILE__)."/Graph.class.php";

/**
 * AntiSpam
 * String printed on the images are case insensitive.
 *
 * @package Artichow
 */
class awAntiSpam extends awImage {

	/**
	 * Anti-spam string
	 *
	 * @var string
	 */
	protected $string;

	/**
	 * Noise intensity
	 *
	 * @var int
	 */
	protected $noise = 0;

	/**
	 * Construct a new awAntiSpam image
	 *
	 * @param string $string A string to display
	 */
	public function __construct($string = '') {

		parent::__construct();

		$this->string = (string)$string;

	}

	/**
	 * Create a random string
	 *
	 * @param int $length String length
	 * @return string String created
	 */
	public function setRand($length) {

		$length = (int)$length;

		$this->string = '';

		$letters = 'aAbBCDeEFgGhHJKLmMnNpPqQRsStTuVwWXYZz2345679';
		$number = strlen($letters);

		for($i = 0; $i < $length; $i++) {
			$this->string .= $letters{mt_rand(0, $number - 1)};
		}

		return $this->string;

	}

	public function setText($text) {

		$this->string = $text;

		return $this->string;

	}

	/**
	 * Set noise on image
	 *
	 * @param int $nois Noise intensity (from 0 to 10)
	 */
	public function setNoise($noise) {
		if($noise < 0) {
			$noise = 0;
		}
		if($noise > 10) {
			$noise = 10;
		}
		$this->noise = (int)$noise;
	}

	/**
	 * Save string value in session
	 * You can use check() to verify the value later
	 *
	 * @param string $qName A name that identify the anti-spam image
	 */
	public function save($qName) {
		$this->session();
		$session = 'artichow_'.(string)$qName;
		$_SESSION[$session] = $this->string;
	}

	/**
	 * Verify user entry
	 *
	 * @param string $qName A name that identify the anti-spam image
	 * @param string $value User-defined value
	 * @param bool $case TRUE for case insensitive check, FALSE for case sensitive check ? (default to TRUE)
	 * @return bool TRUE if the value is correct, FALSE otherwise
	 */
	public function check($qName, $value, $case = TRUE) {

		$this->session();

		$session = 'artichow_'.(string)$qName;

		return (
			array_key_exists($session, $_SESSION) === TRUE and
			$case ?
				(strtolower($_SESSION[$session]) === strtolower((string)$value)) :
				($_SESSION[$session] === (string)$value)
		);

	}

	/**
	 * Draw image
	 */
	public function draw() {
		$fonts = array(
			ARTICHOW_FONT.DIRECTORY_SEPARATOR.'Tuffy.ttf',
			ARTICHOW_FONT.DIRECTORY_SEPARATOR.'TuffyBold.ttf',
			ARTICHOW_FONT.DIRECTORY_SEPARATOR.'TuffyItalic.ttf',
			ARTICHOW_FONT.DIRECTORY_SEPARATOR.'TuffyBoldItalic.ttf'
		);

		$sizes = array(12, 12.5, 13, 13.5, 14, 15, 16, 17, 18, 19);

		$widths = array();
		$heights = array();
		$texts = array();

		for($i = 0; $i < strlen($this->string); $i++) {

			$fontKey = array_rand($fonts);
			$sizeKey = array_rand($sizes);

			$font = new awTTFFont(
				$fonts[$fontKey], $sizes[$sizeKey]
			);

			$text = new awText(
				$this->string{$i},
				$font,
				NULL,
				mt_rand(-15, 15)
			);

			$widths[] = $font->getTextWidth($text);
			$heights[] = $font->getTextHeight($text);
			$texts[] = $text;
		}

		$width = array_sum($widths);
		$height = array_max($heights);

		$totalWidth = $width + 10 + count($texts) * 10;
		$totalHeight = $height + 20;

		$this->setSize($totalWidth, $totalHeight);

		$this->create();

		for($i = 0; $i < strlen($this->string); $i++) {

			$this->drawer->string(
				$texts[$i],
				new awPoint(
					5 + array_sum(array_slice($widths, 0, $i)) + $widths[$i] / 2 + $i * 10,
					10 + ($height - $heights[$i]) / 2
				)
			);

		}

		$this->drawNoise($totalWidth, $totalHeight);

		$this->send();

	}

	protected function drawNoise($width, $height) {

		$points = $this->noise * 30;
		$color = new awColor(0, 0, 0);

		for($i = 0; $i < $points; $i++) {
			$this->drawer->point(
				$color,
				new awPoint(
					mt_rand(0, $width),
					mt_rand(0, $height)
				)
			);
		}

	}

	protected function session() {

		// Start session if needed
		if(!session_id()) {
			/* CATS Hack. Ensure session uses proper name. */
			@session_name(CATS_SESSION_NAME);
			session_start();
		}
	}
}

registerClass('AntiSpam');
?>

Anon7 - 2021