Initial commit - Typo3 11.5.41
This commit is contained in:
230
typo3conf/ext/sr_freecap/Classes/Domain/Model/Font.php
Normal file
230
typo3conf/ext/sr_freecap/Classes/Domain/Model/Font.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
namespace SJBR\SrFreecap\Domain\Model;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2012-2022 Stanislas Rolland <typo3AAAA(arobas)sjbr.ca>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
* A copy is found in the textfile GPL.txt and important notices to the license
|
||||
* from the author is found in LICENSE.txt distributed with these scripts.
|
||||
*
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
*/
|
||||
|
||||
use SJBR\SrFreecap\Utility\FontMakingUtility;
|
||||
use SJBR\SrFreecap\Validation\Validator\TtfFileValidator;
|
||||
use TYPO3\CMS\Core\Core\Environment;
|
||||
use TYPO3\CMS\Extbase\Annotation\Validate;
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
|
||||
/**
|
||||
* Font object
|
||||
*
|
||||
* This file must be iso-8859-2-encoded!
|
||||
*
|
||||
*/
|
||||
class Font extends AbstractEntity
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $charactersIncludedInFont;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @Validate("NumberRange", options={"minimum": 5, "maximum": 255})
|
||||
*/
|
||||
protected $characterWidth;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @Validate("NumberRange", options={"minimum": 5, "maximum": 255})
|
||||
*/
|
||||
protected $characterHeight;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
**/
|
||||
protected $endianness;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @Validate("NotEmpty")
|
||||
* @Validate("StringLength", options={"minimum": 1, "maximum": 255})
|
||||
* @Validate("\SJBR\SrFreecap\Validation\Validator\TtfFileValidator")
|
||||
**/
|
||||
protected $ttfFontFileName = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
**/
|
||||
protected $gdFontFilePrefix = 'font';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
**/
|
||||
protected $pngImageFileName = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
**/
|
||||
protected $gdFontData = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
**/
|
||||
protected $gdFontFileName = '';
|
||||
|
||||
public function __construct(
|
||||
$charactersIncludedInFont = 0,
|
||||
$characterWidth = 34,
|
||||
$characterHeight = 50,
|
||||
$endianness = 0,
|
||||
$ttfFontFileName = '',
|
||||
$gdFontFilePrefix = '',
|
||||
$pngImageFileName = '',
|
||||
$gdFontData = '',
|
||||
$gdFontFileName = ''
|
||||
) {
|
||||
$this->setCharactersIncludedInFont($charactersIncludedInFont);
|
||||
$this->setCharacterWidth($characterWidth);
|
||||
$this->setCharacterHeight($characterHeight);
|
||||
$this->setEndianness($endianness);
|
||||
$this->setTtfFontFileName($ttfFontFileName);
|
||||
$this->setGdFontFilePrefix($gdFontFilePrefix);
|
||||
$this->setPngImageFileName($pngImageFileName);
|
||||
$this->setGdFontData($gdFontData);
|
||||
$this->setGdFontFileName($gdFontFileName);
|
||||
}
|
||||
|
||||
public function setCharactersIncludedInFont($charactersIncludedInFont) {
|
||||
$this->charactersIncludedInFont = (int)$charactersIncludedInFont;
|
||||
}
|
||||
|
||||
public function getCharactersIncludedInFont() {
|
||||
return $this->charactersIncludedInFont;
|
||||
}
|
||||
|
||||
public function setCharacterWidth($characterWidth) {
|
||||
$this->characterWidth = (int)$characterWidth;
|
||||
}
|
||||
|
||||
public function getCharacterWidth() {
|
||||
return $this->characterWidth;
|
||||
}
|
||||
|
||||
public function setCharacterHeight($characterHeight) {
|
||||
$this->characterHeight = (int)$characterHeight;
|
||||
}
|
||||
|
||||
public function getCharacterHeight() {
|
||||
return $this->characterHeight;
|
||||
}
|
||||
|
||||
public function setEndianness($endianness) {
|
||||
$this->endianness = (int)$endianness;
|
||||
}
|
||||
|
||||
public function getEndianness() {
|
||||
return $this->endianness;
|
||||
}
|
||||
|
||||
public function setTtfFontFileName($ttfFontFileName) {
|
||||
$this->ttfFontFileName = (string)$ttfFontFileName;
|
||||
}
|
||||
|
||||
public function getTtfFontFileName() {
|
||||
return $this->ttfFontFileName;
|
||||
}
|
||||
|
||||
public function setGdFontFilePrefix($gdFontFilePrefix = 'font') {
|
||||
$this->gdFontFilePrefix = (string)$gdFontFilePrefix;
|
||||
}
|
||||
|
||||
public function getGdFontFilePrefix() {
|
||||
return $this->gdFontFilePrefix;
|
||||
}
|
||||
|
||||
|
||||
public function setPngImageFileName($pngImageFileName) {
|
||||
$this->pngImageFileName = (string)$pngImageFileName;
|
||||
}
|
||||
|
||||
public function getPngImageFileName() {
|
||||
return $this->pngImageFileName;
|
||||
}
|
||||
|
||||
public function setGdFontData($gdFontData) {
|
||||
$this->gdFontData = (string)$gdFontData;
|
||||
}
|
||||
|
||||
public function getGdFontdata() {
|
||||
return $this->gdFontData;
|
||||
}
|
||||
|
||||
public function setGdFontFileName($gdFontFileName) {
|
||||
$this->gdFontFileName = (string)$gdFontFileName;
|
||||
}
|
||||
|
||||
public function getGdFontFileName() {
|
||||
return $this->gdFontFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates teh GD font file
|
||||
*/
|
||||
public function createGdFontFile()
|
||||
{
|
||||
switch ($this->charactersIncludedInFont) {
|
||||
case 1:
|
||||
$characters = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z';
|
||||
$startCharacter = 'a';
|
||||
break;
|
||||
case 2:
|
||||
$characters = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o'
|
||||
.',p,q,r,s,t,u,v,w,x,y,z,-,-,-,-,-'
|
||||
.',-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-'
|
||||
.',-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-'
|
||||
.',-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-'
|
||||
.',-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-'
|
||||
.',-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-'
|
||||
.',-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,ß'
|
||||
.',à,á,â,ă,ä,Í,ć,ç,č,é,ę,ë,ě,Í,î,ď'
|
||||
.',đ,ń,ň,ó,ô,ő,ö,-,ř,ů,ú,ű,ü,ý,ţ,-';
|
||||
$startCharacter = 'a';
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
$characters = '0,1,2,3,4,5,6,7,8,9';
|
||||
$startCharacter = '0';
|
||||
break;
|
||||
}
|
||||
$numberOfCharacters = count(explode(',', $characters));
|
||||
$this->setPngImageFileName(FontMakingUtility::makeFontImage($characters, $this->ttfFontFileName, $this->characterWidth, $this->characterHeight));
|
||||
if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] ?? false) {
|
||||
$image = @ImageCreateFromPNG(Environment::getPublicPath() . '/' . $this->pngImageFileName);
|
||||
} else {
|
||||
$image = @ImageCreateFromGIF(Environment::getPublicPath() . '/' . $this->pngImageFileName);
|
||||
}
|
||||
if ($image !== false) {
|
||||
$this->setGdFontdata(FontMakingUtility::makeFont($image, $numberOfCharacters, $startCharacter, $this->characterWidth, $this->characterHeight, $this->endianness));
|
||||
ImageDestroy($image);
|
||||
}
|
||||
}
|
||||
}
|
||||
109
typo3conf/ext/sr_freecap/Classes/Domain/Model/Word.php
Normal file
109
typo3conf/ext/sr_freecap/Classes/Domain/Model/Word.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
namespace SJBR\SrFreecap\Domain\Model;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2012-2020 Stanislas Rolland <typo32020(arobas)sjbr.ca>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
* A copy is found in the textfile GPL.txt and important notices to the license
|
||||
* from the author is found in LICENSE.txt distributed with these scripts.
|
||||
*
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
|
||||
|
||||
/**
|
||||
* Word object
|
||||
*/
|
||||
class Word extends AbstractEntity
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $wordHash;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $hashFunction;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $wordCypher;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $attempts;
|
||||
|
||||
public function __construct(
|
||||
$wordHash = '',
|
||||
$hashFunction = 'md5',
|
||||
$wordCypher = array(),
|
||||
$attempts = 0
|
||||
)
|
||||
{
|
||||
$this->setWordHash($wordHash);
|
||||
$this->setHashFunction($hashFunction);
|
||||
$this->setWordCypher($wordCypher);
|
||||
$this->setAttempts($attempts);
|
||||
}
|
||||
|
||||
public function setWordHash($wordHash)
|
||||
{
|
||||
$this->wordHash = (string)$wordHash;
|
||||
}
|
||||
|
||||
public function getWordHash()
|
||||
{
|
||||
return $this->wordHash;
|
||||
}
|
||||
|
||||
public function setHashFunction($hashFunction)
|
||||
{
|
||||
$this->hashFunction = (string)$hashFunction;
|
||||
}
|
||||
|
||||
public function getHashFunction()
|
||||
{
|
||||
return $this->hashFunction;
|
||||
}
|
||||
|
||||
public function setWordCypher($wordCypher)
|
||||
{
|
||||
$this->wordCypher = (array)$wordCypher;
|
||||
}
|
||||
|
||||
public function getWordCypher()
|
||||
{
|
||||
return $this->wordCypher;
|
||||
}
|
||||
|
||||
public function setAttempts($attempts)
|
||||
{
|
||||
$this->attempts = (int)$attempts;
|
||||
}
|
||||
|
||||
public function getAttempts()
|
||||
{
|
||||
return $this->attempts;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace SJBR\SrFreecap\Domain\Repository;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2012-2018 Stanislas Rolland <typo3@sjbr.ca>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
* A copy is found in the textfile GPL.txt and important notices to the license
|
||||
* from the author is found in LICENSE.txt distributed with these scripts.
|
||||
*
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
*/
|
||||
|
||||
use SJBR\SrFreecap\Domain\Model\Font;
|
||||
use TYPO3\CMS\Core\Core\Environment;
|
||||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Persistence\Repository;
|
||||
|
||||
/**
|
||||
* Font repository
|
||||
*/
|
||||
class FontRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* @var string Name of the extension this controller belongs to
|
||||
*/
|
||||
protected $extensionKey = 'sr_freecap';
|
||||
|
||||
/**
|
||||
* Writes the GD font file
|
||||
*
|
||||
* @param Font the object to be stored
|
||||
* @return \SJBR\SrFreecap\Domain\Repository\FontRepository $this
|
||||
*/
|
||||
public function writeFontFile(Font $font)
|
||||
{
|
||||
$directory = Environment::getPublicPath() . '/' . 'uploads/' . ExtensionManagementUtility::getCN($this->extensionKey) . '/';
|
||||
GeneralUtility::mkdir_deep($directory);
|
||||
$fileName = $directory . $font->getGdFontFilePrefix() . '_' . md5($font->getGdFontData()) . '.gdf';
|
||||
if (GeneralUtility::writeFile($fileName, $font->getGdFontData())) {
|
||||
$font->setGdFontFileName($fileName);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
namespace SJBR\SrFreecap\Domain\Repository;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2012-2021 Stanislas Rolland <typo3AAAA(arobas)sjbr.ca>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
* A copy is found in the textfile GPL.txt and important notices to the license
|
||||
* from the author is found in LICENSE.txt distributed with these scripts.
|
||||
*
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
*/
|
||||
|
||||
use SJBR\SrFreecap\Domain\Model\Word;
|
||||
use SJBR\SrFreecap\Domain\Session\SessionStorage;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Persistence\Repository;
|
||||
|
||||
/**
|
||||
* Word repository in session storage
|
||||
*/
|
||||
class WordRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* The session sorage handler
|
||||
* @var SessionStorage
|
||||
*/
|
||||
protected $sessionStorage;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct(SessionStorage $sessionStorage)
|
||||
{
|
||||
// Get an instance of the session storage handler
|
||||
$this->sessionStorage = $sessionStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object stored in the user's session
|
||||
*
|
||||
* @return Word the stored object
|
||||
*/
|
||||
public function getWord()
|
||||
{
|
||||
$word = $this->sessionStorage->restoreFromSession();
|
||||
// If no Word object is found in session data, initialize a new one
|
||||
if (!is_object($word)) {
|
||||
$word = new Word();
|
||||
}
|
||||
return $word;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the object into the user's session
|
||||
*
|
||||
* @param Word the object to be stored
|
||||
* @return WordRepository
|
||||
*/
|
||||
public function setWord(Word $object)
|
||||
{
|
||||
$this->sessionStorage->writeToSession($object);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up the session: removes the stored object from the user's session
|
||||
*
|
||||
* @return WordRepository
|
||||
*/
|
||||
public function cleanUpWord()
|
||||
{
|
||||
$this->sessionStorage->cleanUpSession();
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
namespace SJBR\SrFreecap\Domain\Session;
|
||||
|
||||
/*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2012-2021 Stanislas Rolland <typo3AAAA(arobas)sjbr.ca>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
* A copy is found in the textfile GPL.txt and important notices to the license
|
||||
* from the author is found in LICENSE.txt distributed with these scripts.
|
||||
*
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Session\UserSession;
|
||||
use TYPO3\CMS\Core\Session\UserSessionManager;
|
||||
use TYPO3\CMS\Core\Session\Backend\Exception\SessionNotFoundException;
|
||||
use TYPO3\CMS\Core\SingletonInterface;
|
||||
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
|
||||
|
||||
/**
|
||||
* Session storage
|
||||
*/
|
||||
class SessionStorage implements SingletonInterface
|
||||
{
|
||||
const SESSIONNAMESPACE = 'tx_srfreecap';
|
||||
|
||||
/**
|
||||
* Returns the object stored in the user's PHP session
|
||||
*
|
||||
* @return Object the stored object
|
||||
*/
|
||||
public function restoreFromSession()
|
||||
{
|
||||
$sessionData = $this->getUser()->getSessionData(self::SESSIONNAMESPACE);
|
||||
if ($sessionData === null) {
|
||||
return null;
|
||||
}
|
||||
return unserialize($sessionData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an object into the PHP session
|
||||
*
|
||||
* @param $object any serializable object to store into the session
|
||||
* @return SessionStorage
|
||||
*/
|
||||
public function writeToSession($object)
|
||||
{
|
||||
$sessionData = serialize($object);
|
||||
$this->getUser()->setAndSaveSessionData(self::SESSIONNAMESPACE, $sessionData);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up the session: removes the stored object from the PHP session
|
||||
*
|
||||
* @return SessionStorage
|
||||
*/
|
||||
public function cleanUpSession()
|
||||
{
|
||||
$this->getUser()->setAndSaveSessionData(self::SESSIONNAMESPACE, null);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a frontend user session
|
||||
*
|
||||
* @return User The current frontend user object
|
||||
*/
|
||||
protected function getUser() : FrontendUserAuthentication
|
||||
{
|
||||
if (!isset($GLOBALS['TSFE']) || !$GLOBALS['TSFE']->fe_user) {
|
||||
throw new SessionNotFoundException('No frontend user found in session!');
|
||||
}
|
||||
return $GLOBALS['TSFE']->fe_user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user