├── config.json ├── src └── Artemis │ ├── assets │ ├── images │ │ ├── image.png │ │ ├── static │ │ │ ├── instagram.png │ │ │ ├── kodportali.png │ │ │ └── screenshoot.png │ │ └── user-images │ │ │ └── kodportali.png │ └── fonts │ │ └── ubuntu-bold.ttf │ ├── entities │ ├── Image.php │ ├── User.php │ └── Settings.php │ ├── utils │ ├── Utils.php │ ├── Internet.php │ ├── Config.php │ ├── Timezone.php │ ├── ImageCompress.php │ └── Terminal.php │ ├── run.php │ ├── setup-windows.php │ └── Main.php ├── setup.ini ├── start.cmd ├── setup.cmd ├── composer.json ├── LICENSE ├── start.ps1 ├── start.sh └── README.md /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "username": "kullanıcı-adı", 3 | "password": "şifre", 4 | "timezone": "auto", 5 | "randomImage": false 6 | } -------------------------------------------------------------------------------- /src/Artemis/assets/images/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anilmisirlioglu/InstagramPPChanger/HEAD/src/Artemis/assets/images/image.png -------------------------------------------------------------------------------- /src/Artemis/assets/fonts/ubuntu-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anilmisirlioglu/InstagramPPChanger/HEAD/src/Artemis/assets/fonts/ubuntu-bold.ttf -------------------------------------------------------------------------------- /src/Artemis/assets/images/static/instagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anilmisirlioglu/InstagramPPChanger/HEAD/src/Artemis/assets/images/static/instagram.png -------------------------------------------------------------------------------- /src/Artemis/assets/images/static/kodportali.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anilmisirlioglu/InstagramPPChanger/HEAD/src/Artemis/assets/images/static/kodportali.png -------------------------------------------------------------------------------- /src/Artemis/assets/images/static/screenshoot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anilmisirlioglu/InstagramPPChanger/HEAD/src/Artemis/assets/images/static/screenshoot.png -------------------------------------------------------------------------------- /src/Artemis/assets/images/user-images/kodportali.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anilmisirlioglu/InstagramPPChanger/HEAD/src/Artemis/assets/images/user-images/kodportali.png -------------------------------------------------------------------------------- /setup.ini: -------------------------------------------------------------------------------- 1 | [git] 2 | ; Eğer sistem git yazılımını bulamazsa, bu yolda arar 3 | ; Bu kısım daha implement edilmedi, daha sonra implement et 4 | git.path="C:\Program Files\Git\bin" 5 | 6 | [composer] 7 | ; Eğer sistem composer yazılımını bulamazsa, bu yolda arar. 8 | composer.path="C:\composer" 9 | 10 | [curl] 11 | ; Eğer sistem geçerli binary içinde bulamazsa, bu yoldaki alır. 12 | curl.cainfo.path="C:\php\cacert.pem" -------------------------------------------------------------------------------- /start.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | TITLE InstagramPPUpdater Code by An!l 3 | cd /d %~dp0 4 | 5 | if exist bin\php\php.exe ( 6 | set PHPRC="" 7 | set PHP_BINARY="bin\php\php.exe" 8 | ) else ( 9 | set PHP_BINARY="php" 10 | ) 11 | 12 | if exist src\Artemis\run.php ( 13 | set RUNNER_FILE="src\Artemis\run.php" 14 | ) else ( 15 | echo src\Artemis\run.php not found. 16 | pause 17 | exit 1 18 | ) 19 | 20 | %PHP_BINARY% -c bin\php %RUNNER_FILE% %* || pause -------------------------------------------------------------------------------- /setup.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | TITLE InstagramPPUpdater Code by An!l [Setup] 3 | cd /d %~dp0 4 | 5 | if exist bin\php\php.exe ( 6 | set PHPRC="" 7 | set PHP_BINARY="bin\php\php.exe" 8 | ) else ( 9 | set PHP_BINARY="php" 10 | ) 11 | 12 | if exist src\Artemis\setup-windows.php ( 13 | set RUNNER_FILE="src\Artemis\setup-windows.php" 14 | ) else ( 15 | echo src\Artemis\setup-windows.php not found. 16 | pause 17 | exit 1 18 | ) 19 | 20 | %PHP_BINARY% -c bin\php %RUNNER_FILE% %* || pause -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nightrich/instagramppupdater", 3 | "version": "1.4", 4 | "license": "MIT", 5 | "description": "Anlık instagram profil fotoğrafı güncelleyici.", 6 | "type": "project", 7 | "homepage": "https://kodportali.com", 8 | "require": { 9 | "php": ">=7.2", 10 | "mgp25/instagram-php": "dev-master", 11 | "ext-gd": "*", 12 | "ext-json": "*" 13 | }, 14 | "authors": [ 15 | { 16 | "name": "Anıl Mısırlıoğlu", 17 | "email": "misirlioglisamet@gmail.com", 18 | "homepage": "https://kodportali.com", 19 | "role": "Owner & Developer" 20 | } 21 | ], 22 | "autoload": { 23 | "psr-4": {"": "src/"} 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Artemis/entities/Image.php: -------------------------------------------------------------------------------- 1 | path = $filePath; 18 | 19 | $pathInfo = pathinfo($filePath); 20 | $this->extension = $pathInfo['extension']; 21 | $this->basename = $pathInfo['basename']; 22 | $this->filename = $pathInfo['filename']; 23 | } 24 | 25 | public function getPath() : string{ 26 | return $this->path; 27 | } 28 | 29 | public function setPath(string $path) : void{ 30 | $this->path = $path; 31 | } 32 | 33 | public function getExtension() : string{ 34 | return $this->extension; 35 | } 36 | 37 | public function getBasename() : string{ 38 | return $this->basename; 39 | } 40 | 41 | public function getFilename() : string{ 42 | return $this->filename; 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Anıl Mısırlıoğlu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/Artemis/utils/Utils.php: -------------------------------------------------------------------------------- 1 | . 18 | * 19 | */ 20 | 21 | namespace Artemis\utils; 22 | 23 | class Utils{ 24 | 25 | public static function hexadecimalToRGB(string $hex) : array{ 26 | $parse = intval(str_replace('#', '', $hex), 16); 27 | return [ 28 | ($parse >> 16) & 0xFF, 29 | ($parse >> 8) & 0xFF, 30 | ($parse >> 0) & 0xFF 31 | ]; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /start.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding(PositionalBinding=$false)] 2 | param ( 3 | [string]$php = "", 4 | [switch]$Loop = $false, 5 | [string]$file = "", 6 | [string][Parameter(ValueFromRemainingArguments)]$extraKodPortaliArgs 7 | ) 8 | 9 | if($php -ne ""){ 10 | $binary = $php 11 | }elseif(Test-Path "bin\php\php.exe"){ 12 | $env:PHPRC = "" 13 | $binary = "bin\php\php.exe" 14 | }else{ 15 | $binary = "php" 16 | } 17 | 18 | if($file -eq ""){ 19 | if(Test-Path "src/Artemis/run.php"){ 20 | $file = "src/Artemis/run.php" 21 | }else{ 22 | echo "src\Artemis\run.php not found." 23 | pause 24 | exit 1 25 | } 26 | } 27 | 28 | function StartSystem{ 29 | $command = "powershell -NoProfile " + $binary + " " + $file + " " + $extraKodPortaliArgs 30 | iex $command 31 | } 32 | 33 | $loops = 0 34 | 35 | StartSystem 36 | 37 | while($Loop){ 38 | if($loops -ne 0){ 39 | echo ("Restarted " + $loops + " times") 40 | } 41 | $loops++ 42 | echo "To escape the loop, press CTRL+C now. Otherwise, wait 5 seconds for the server to restart." 43 | echo "" 44 | Start-Sleep 5 45 | StartServer 46 | } -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DIR="$(cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" 3 | cd "$DIR" 4 | 5 | while getopts "p:f:l" OPTION 2; /dev/null; do 6 | case ${OPTION} in 7 | p) 8 | PHP_BINARY="$OPTARG" 9 | ;; 10 | f) 11 | RUNNER_FILE="$OPTARG" 12 | ;; 13 | l) 14 | DO_LOOP="yes" 15 | ;; 16 | \?) 17 | break 18 | ;; 19 | esac 20 | done 21 | 22 | if [[ "$PHP_BINARY" == "" ]]; then 23 | if [[ -f ./bin/php7/bin/php ]]; then 24 | export PHPRC="" 25 | PHP_BINARY="./bin/php7/bin/php" 26 | elif [[ ! -z $(type php) ]]; then 27 | PHP_BINARY=$(type -p php) 28 | else 29 | echo "Couldn't find a working PHP 7 binary, please use the installer." 30 | exit 1 31 | fi 32 | fi 33 | 34 | if [[ "$RUNNER_FILE" == "" ]]; then 35 | if [[ -f ./src/Artemis/run.php ]]; then 36 | RUNNER_FILE="./src/Artemis/run.php" 37 | else 38 | echo "src/Artemis/run.php not found" 39 | exit 1 40 | fi 41 | fi 42 | 43 | LOOPS=0 44 | 45 | set +e 46 | 47 | if [[ "$DO_LOOP" == "yes" ]]; then 48 | while true; do 49 | if [[ ${LOOPS} -gt 0 ]]; then 50 | echo "Restarted $LOOPS times" 51 | fi 52 | "$PHP_BINARY" "$RUNNER_FILE" $@ 53 | echo "To escape the loop, press CTRL+C now. Otherwise, wait 5 seconds for the server to restart." 54 | echo "" 55 | sleep 5 56 | ((LOOPS++)) 57 | done 58 | else 59 | exec "$PHP_BINARY" "$RUNNER_FILE" $@ 60 | fi -------------------------------------------------------------------------------- /src/Artemis/entities/User.php: -------------------------------------------------------------------------------- 1 | . 18 | * 19 | */ 20 | 21 | namespace Artemis\entities; 22 | 23 | class User{ 24 | 25 | /** @var string */ 26 | private $username; 27 | /** @var string */ 28 | private $password; 29 | 30 | public function __construct(string $username, string $password){ 31 | $this->username = $username; 32 | $this->password = $password; 33 | } 34 | 35 | public function getUsername() : string{ 36 | return $this->username; 37 | } 38 | 39 | public function getPassword() : string{ 40 | return $this->password; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /src/Artemis/utils/Internet.php: -------------------------------------------------------------------------------- 1 | . 18 | * 19 | */ 20 | 21 | namespace Artemis\utils; 22 | 23 | trait Internet{ 24 | 25 | public function downloadRandomImage() : void{ 26 | file_put_contents( 27 | __DIR__ . '/../assets/images/image.jpg', 28 | ($content = file_get_contents(sprintf( 29 | Config::IMAGE_API_URL, 30 | mt_rand(0, 1085) /* Total image count*/, 31 | Config::INSTAGRAM_PP_SIZES, 32 | Config::INSTAGRAM_PP_SIZES 33 | ))) 34 | ); 35 | 36 | !$content ? $this->downloadRandomImage() : Terminal::log(Terminal::AQUA . 'API \'den yeni resim başarıyla indirildi.', IMAGE_API); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/Artemis/entities/Settings.php: -------------------------------------------------------------------------------- 1 | . 18 | * 19 | */ 20 | 21 | namespace Artemis\entities; 22 | 23 | use Artemis\utils\Config; 24 | use Artemis\utils\Terminal; 25 | use Exception; 26 | 27 | class Settings{ 28 | 29 | /** @var User */ 30 | private $user; 31 | /** @var string */ 32 | private $timezone; 33 | /** @var bool */ 34 | private $randomImage; 35 | 36 | public function __construct(){ 37 | try{ 38 | Terminal::log(Terminal::GREEN . 'Ayar dosyası okunuyor.', SYSTEM); 39 | 40 | $json = json_decode(file_get_contents(Config::CONFIG_JSON_DIR)); 41 | $this->user = new User($json->username, $json->password); 42 | $this->timezone = $json->timezone ?? Config::DEFAULT_TIMEZONE; 43 | $this->randomImage = $json->randomImage ?? true; 44 | 45 | Terminal::log(Terminal::GREEN . 'Ayar dosyası başarıyla okundu.', SYSTEM); 46 | }catch(Exception $exception){ 47 | die('Olmaması gereken bir hata ile karşılaştık. Hata: ' . $exception->getMessage()); 48 | } 49 | } 50 | 51 | public function getUser() : User{ 52 | return $this->user; 53 | } 54 | 55 | public function getTimezone() : string{ 56 | return $this->timezone; 57 | } 58 | 59 | public function getRandomImageOpt() : bool{ 60 | return $this->randomImage; 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /src/Artemis/utils/Config.php: -------------------------------------------------------------------------------- 1 | . 18 | * 19 | */ 20 | 21 | namespace Artemis\utils; 22 | 23 | class Config{ 24 | 25 | /** @var int */ 26 | public const INSTAGRAM_PP_SIZES = 320; // 320px x 320px 27 | 28 | /** @var int */ 29 | public const IMAGE_THICKNESS = 12; 30 | 31 | /** @var float */ 32 | public const TEXT_FONT_SIZE = 30.0; 33 | /** @var int */ 34 | public const TEXT_PADDING = 1; 35 | /** @var string */ 36 | public const TEXT_FONT = __DIR__ . '/../assets/fonts/ubuntu-bold.ttf'; 37 | /** @var string */ 38 | public const TEXT_COLOR = 'FFFFFF'; 39 | 40 | /** @var string */ 41 | public const IMAGE_API_URL = 'https://picsum.photos/id/%d/%d/%d?blur=2'; 42 | 43 | /** @var string */ 44 | public const USER_IMAGES_DIR = __DIR__ . '/../assets/images/user-images'; 45 | /** @var string */ 46 | public const CONFIG_JSON_DIR = __DIR__ . '/../../../config.json'; 47 | 48 | /** @var string */ 49 | public const DEFAULT_TIMEZONE = 'Europe/Istanbul'; 50 | 51 | /** 52 | * Renk kodları hexadecimal formatında olmak zorundadır. 53 | * 54 | * @var array 55 | */ 56 | public const HEX_COLORS = [ 57 | 'A0522D', 58 | '8470FF', 59 | '00BFFF', 60 | '00CED1', 61 | '00FF00', 62 | 'FFFF00', 63 | 'CD661D', 64 | 'B22222', 65 | 'FF3030', 66 | 'DC143C', 67 | 'FF1493', 68 | 'CD1076', 69 | 'FF34B3', 70 | 'FF00FF', 71 | 'B452CD', 72 | 'C71585', 73 | '7D26CD' 74 | ]; 75 | } -------------------------------------------------------------------------------- /src/Artemis/run.php: -------------------------------------------------------------------------------- 1 | . 18 | * 19 | */ 20 | 21 | declare(strict_types=1); 22 | 23 | namespace Artemis{ 24 | 25 | use Artemis\utils\Terminal; 26 | 27 | function critical_error($message){ 28 | echo '[HATA] ' . $message . PHP_EOL; 29 | } 30 | 31 | function logSys(string $text, string $prefix = SYSTEM) : void{ 32 | Terminal::log($text, $prefix); 33 | } 34 | 35 | define('Artemis\NAME', 'Instagram Profil Photo Updater'); 36 | define('Artemis\MIN_PHP_VERSION', '7.2.0'); 37 | 38 | if(PHP_INT_SIZE < 8) 39 | critical_error('Running ' . NAME . ' with 32-bit systems/PHP is no longer supported. Please upgrade to a 64-bit system, or use a 64-bit PHP binary if this is a 64-bit system.'); 40 | 41 | if(php_sapi_name() !== 'cli') 42 | critical_error('You must run ' . NAME . ' using the CLI.'); 43 | 44 | if(version_compare(MIN_PHP_VERSION, PHP_VERSION) > 0) 45 | critical_error(NAME . ' requires PHP >= ' . MIN_PHP_VERSION . ', but you have PHP ' . PHP_VERSION . '.'); 46 | 47 | ini_set('memory_limit', '-1'); 48 | 49 | define('Artemis\PATH', dirname(__FILE__, 3) . DIRECTORY_SEPARATOR); 50 | define('Artemis\COMPOSER_AUTOLOAD_PATH', PATH . 'vendor/autoload.php'); 51 | 52 | ini_set('memory_limit', '-1'); 53 | 54 | if(COMPOSER_AUTOLOAD_PATH !== false and is_file(COMPOSER_AUTOLOAD_PATH)){ 55 | require_once(COMPOSER_AUTOLOAD_PATH); 56 | }else{ 57 | critical_error('Composer autoloader not found at ' . COMPOSER_AUTOLOAD_PATH); 58 | critical_error('Please install/update Composer dependencies or use provided builds.'); 59 | exit(1); 60 | } 61 | 62 | new Main(); 63 | } 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PROJECT DEPRECATED 2 | 3 | # Instagram PP Changer v1.4 4 | 5 | # ![Instagram Logo](src/Artemis/assets/images/static/instagram.png) 6 | Instagram profil fotoğrafınızı dakika başı o anki tarihe göre farklı resimler ile günceller. 7 | 8 | ## Ekran Görüntüsü 9 | ![SS](src/Artemis/assets/images/static/screenshoot.png) 10 | 11 | --- 12 | ## Gereksinimler 13 | 14 | - PHP 7.2 15 | - ext-curl 16 | - ext-gd 17 | - ext-json 18 | - ext-zlib 19 | - ext-mbstring 20 | - ext-exif 21 | - [mgp25/instagram](https://github.com/mgp25/Instagram-API) 22 | 23 | --- 24 | 25 | ## Yazılım Kurulumu 26 | 27 | **Windows**: Şimdilik sadece windows için büyük oranda otomatik olan sistem desteklenmektedir. Yapmanız gereken 'setup.cmd' dosyasını çalıştırmanız. 28 | 29 | --- 30 | 31 | ## SSS 32 | 33 | ### Yazılımın Çalışma Mantığı Nedir? 34 | Yazılım PHP tabanlı olarak çalışır. mgp25/instagram API 'si ile çalışır. Görüntüler tamamen random olarak gelir ve düzenlenir. Ardından Instagram profil fotoğrafınız güncellenir. Yazılım sadece komut arayüzünde çalışır. 35 | 36 | ### Hesap Bilgilerimiz Depolanıyor mu? 37 | Hayır hesap verileriniz depolanmıyor. Tamamen sizin kendi bilgisayarınızda kalıyor. 3.parti sunuculara aktarılmıyor. Tamamen güvenlidir. 38 | 39 | ### Instagram Hesabıma Yazılımdan Nasıl Giriş Yapacağım? 40 | config.json dosyasınde belirtilen yerlere kullanıcı adınız ve şifrenizi yazdığınız takdirde sistem otomatik olarak giriş yapıcaktır. 41 | 42 | ### Yazılımı Nasıl Çalıştıracağım? 43 | Yazılımı buradan indirip kullandığınız platforma göre başlatın. Eğer windows kullanıyorsanız 'start.cmd' veya 'start.ps1' dosyasına çift tıklayıp çalıştırmanız yeterlidir. Linux kullanıcıları projeyi klonlayıp yazılımın kök dizinine gidip './start.sh' yazması yeterli olucaktır. Sadece komut arayüzünde (cli) çalışır. Ayrıca çalış tırmadan önce composer'i kurmayı unutmayınız. 44 | 45 | ### Yazılımı Bir Kere Çalıştırdıktan Sonra Kapatsak Sorun Olurmur? 46 | Eğer her dakika güncellenmesini istiyorsanız yazılımın her daim açık kalması gerekir. Kapattığınız taktirde profil fotoğrafınızı değiştirmeyide durdurur. 47 | 48 | ### Çalıştırdığımız Zaman PHP Extension Hatası Alıyorum, Neden? 49 | Bunun sebebi gerekli php eklentilerinin kurulu olmamasıdır. Bunun için dosya içinde bulunan 'bin' dosyasını kullanın. 50 | 51 | ### cURL Hatası Alıyorum, Neden? 52 | Proje içindeki 'bin/php/cacert.pem' dosyasının, dosya yolunu yine aynı 'bin/php' içindeki 'php.ini' dosyasındaki 'curl.cainfo' karşısına yapıştırın. 53 | 54 | ### Kendi ülkemin zaman dilimini nasıl ayarlayabilirim? 55 | 'congig.json' dosyası içerisindeki 'timezone' değerini değiştirerek kendi ülkenin zaman dilimine ayarlayabilirsin. PHP tarafından desteklenen tüm zaman dilimleri için bu linke bakın: https://www.php.net/manual/tr/timezones.php 56 | -------------------------------------------------------------------------------- /src/Artemis/setup-windows.php: -------------------------------------------------------------------------------- 1 | . 18 | * 19 | */ 20 | 21 | namespace Artemis\utils; 22 | 23 | class ImageCompress{ 24 | 25 | public function resizeImage(string $file, int $h = Config::INSTAGRAM_PP_SIZES, int $w = Config::INSTAGRAM_PP_SIZES, $crop = false) : ImageCompress{ 26 | list($width, $height) = getimagesize($file); 27 | $r = $width / $height; 28 | if($crop){ 29 | if($width > $height){ 30 | $width = ceil($width - ($width * abs($r - $w / $h))); 31 | }else{ 32 | $height = ceil($height - ($height * abs($r - $w / $h))); 33 | } 34 | $newWidth = $w; 35 | $newHeight = $h; 36 | }else{ 37 | if($w / $h > $r){ 38 | $newWidth = $h * $r; 39 | $newHeight = $h; 40 | }else{ 41 | $newHeight = $w / $r; 42 | $newWidth = $w; 43 | } 44 | } 45 | 46 | $src = imagecreatefrompng($file); 47 | $destination = imagecreatetruecolor($newWidth, $newWidth); 48 | 49 | imagecopyresampled($destination, $src, 0, 0 ,0 ,0, $newWidth, $newHeight, $width, $height); 50 | imagepng($destination, dirname($file, 1) . DIRECTORY_SEPARATOR . 'image.png'); 51 | imagedestroy($destination); 52 | imagedestroy($src); 53 | 54 | return $this; 55 | } 56 | 57 | public function writeOnImage( 58 | string $file, 59 | string $text, 60 | string $font = Config::TEXT_FONT, 61 | float $fontSize = Config::TEXT_FONT_SIZE, 62 | int $padding = Config::TEXT_PADDING, 63 | string $color = Config::TEXT_COLOR 64 | ) : ImageCompress{ 65 | list($width, $height) = getimagesize($file); 66 | 67 | $image = imagecreatefrompng($file); 68 | 69 | $textRows = $this->getTextRowsFromText($fontSize, $font, $text, $width - ($padding * 2)); 70 | 71 | for($i = 0; $i < count($textRows); $i++){ 72 | imagettfbbox($fontSize, 0, $font, $textRows[$i]); 73 | $text_width = $this->getTextWidth($fontSize, $font, $textRows[$i]); 74 | $text_height = $this->getMaxTextHeight($fontSize, $font, $textRows) * 3; 75 | 76 | $position_center = ceil(($width - $text_width) / 2); 77 | 78 | $test = (count($textRows) - $i) - ceil(count($textRows) / 2); 79 | $position_middle = ceil(($height - ($text_height * $test)) / 2); 80 | 81 | $textColor = imagecolorallocate($image, ...Utils::hexadecimalToRGB($color)); 82 | $strokeColor = imagecolorallocate($image, 220, 20, 60); 83 | $this->imageTtfStrokeText( 84 | $image, 85 | $fontSize, 86 | 0, 87 | $position_center, 88 | $position_middle, 89 | $textColor, 90 | $strokeColor, // Gray 91 | $font, 92 | $textRows[$i], 93 | 2 94 | ); 95 | } 96 | 97 | imagepng($image, dirname($file, 1) . DIRECTORY_SEPARATOR . 'image.png'); 98 | imagedestroy($image); 99 | 100 | return $this; 101 | } 102 | 103 | public function jpgConvertToPng(string $file, string $fileName = null) : ImageCompress{ 104 | imagepng(imagecreatefromstring(file_get_contents($file)), dirname($file, 1) . DIRECTORY_SEPARATOR . ($fileName == null ? 'image.png' : $fileName . '.png')); 105 | 106 | return $this; 107 | } 108 | 109 | public function drawCircleOnImage(string $file, int $thickness = Config::IMAGE_THICKNESS) : ImageCompress{ 110 | list($width, $height) = getimagesize($file); 111 | 112 | $image = imagecreatefrompng($file); 113 | $ellipseColor = imagecolorallocate($image, ...Utils::hexadecimalToRGB(Config::HEX_COLORS[mt_rand(0, count(Config::HEX_COLORS) - 1)])); 114 | 115 | imagesetthickness($image, 2); 116 | 117 | for($i = $thickness; $i > 0; $i--) 118 | imagearc($image, $width / 2, $height / 2, $width - $i, $height - $i, 0, 360, $ellipseColor); 119 | 120 | imagepng($image, dirname($file, 1) . DIRECTORY_SEPARATOR . 'image.png'); 121 | imagedestroy($image); 122 | 123 | return $this; 124 | } 125 | 126 | private function imageTtfStrokeText( 127 | &$image, 128 | int $size, 129 | int $angle, 130 | int $x, 131 | int $y, 132 | &$textColor, 133 | &$strokeColor, 134 | string $fontFile, 135 | string $text, 136 | $px 137 | ) : array{ 138 | for($c1 = ($x - abs($px)); $c1 <= ($x + abs($px)); $c1++) 139 | for($c2 = ($y - abs($px)); $c2 <= ($y + abs($px)); $c2++) 140 | imagettftext($image, $size, $angle, $c1, $c2, $strokeColor, $fontFile, $text); 141 | 142 | return imagettftext($image, $size, $angle, $x, $y, $textColor, $fontFile, $text); 143 | } 144 | 145 | private function getTextWidth(float $fontSize, string $font, string $text) : float{ 146 | $line_box = imagettfbbox($fontSize, 0, $font, $text); 147 | return ceil($line_box[0] + $line_box[2]); 148 | } 149 | 150 | private function getTextHeight(float $fontSize, string $font, string $text) : float{ 151 | $line_box = imagettfbbox($fontSize, 0, $font, $text); 152 | return ceil($line_box[1] - $line_box[7]); 153 | } 154 | 155 | private function getMaxTextHeight(float $fontSize, string $font, array $textArray) : float{ 156 | $maxHeight = 0; 157 | for($i = 0; $i < count($textArray); $i++){ 158 | $height = $this->getTextHeight($fontSize, $font, $textArray[$i]); 159 | if($height > $maxHeight) 160 | $maxHeight = $height; 161 | } 162 | 163 | return $maxHeight; 164 | } 165 | 166 | private function getTextRowsFromText(float $fontSize, string $font, string $text, float $maxWidth) : array{ 167 | $text = str_replace("\n", "\n ", $text); 168 | $text = str_replace("\\n", "\n ", $text); 169 | $words = explode(" ", $text); 170 | 171 | $rows = []; 172 | $tmpRow = ""; 173 | for($i = 0; $i < count($words); $i++){ 174 | if($i == count($words) -1){ 175 | $rows[] = $tmpRow.$words[$i]; 176 | break; 177 | } 178 | 179 | if($this->getTextWidth($fontSize, $font, $tmpRow.$words[$i]) > $maxWidth){ 180 | $rows[] = $tmpRow; 181 | $tmpRow = ""; 182 | }elseif($this->stringEndsWith($tmpRow, "\n ")){ 183 | $tmpRow = str_replace("\n ", "", $tmpRow); 184 | $rows[] = $tmpRow; 185 | $tmpRow = ""; 186 | } 187 | 188 | $tmpRow .= $words[$i] . " "; 189 | 190 | } 191 | 192 | return $rows; 193 | } 194 | 195 | private function stringEndsWith(string $haystack, string $needle) : bool{ 196 | return $needle === "" || substr($haystack, -strlen($needle)) === $needle; 197 | } 198 | 199 | } -------------------------------------------------------------------------------- /src/Artemis/Main.php: -------------------------------------------------------------------------------- 1 | . 18 | * 19 | */ 20 | 21 | namespace Artemis; 22 | 23 | use Artemis\entities\Image; 24 | use Artemis\entities\Settings; 25 | use Artemis\utils\Config; 26 | use Artemis\utils\ImageCompress; 27 | use Artemis\utils\Internet; 28 | use Artemis\utils\Terminal; 29 | use Artemis\utils\Timezone; 30 | use Exception; 31 | use InstagramAPI\Instagram; 32 | 33 | class Main{ 34 | 35 | use Internet; 36 | 37 | /** @var Instagram */ 38 | private $instagram; 39 | /** @var Settings */ 40 | private $settings; 41 | /** @var Timezone */ 42 | private $timezone; 43 | /** @var ImageCompress */ 44 | private $imageCompress; 45 | /** @var Image[] */ 46 | private $images = []; 47 | 48 | public function __construct(){ 49 | logSys(Terminal::GOLD . 'Uygulama başlatılıyor...', SYSTEM); 50 | 51 | $this->settings = new Settings; 52 | $this->imageCompress = new ImageCompress; 53 | $this->timezone = new Timezone($this->settings->getTimezone()); 54 | $this->startInstagram(); 55 | 56 | $this->startApp(); 57 | } 58 | 59 | private function startInstagram() : void{ 60 | logSys(Terminal::GREEN . 'Instagram başlatılıyor...', SYSTEM); 61 | 62 | Instagram::$allowDangerousWebUsageAtMyOwnRisk = true; 63 | $this->instagram = new Instagram; 64 | 65 | logSys(Terminal::GREEN . 'Instagram başarıyla başlatıldı.', SYSTEM); 66 | 67 | $this->loginInstagramAccount(); 68 | } 69 | 70 | private function loginInstagramAccount() : void{ 71 | $user = $this->settings->getUser(); 72 | 73 | try{ 74 | logSys(Terminal::YELLOW . 'Instagram hesabınıza giriş yapılıyor.', SYSTEM); 75 | 76 | $response = $this->instagram->login( 77 | ($username = $user->getUsername()), 78 | ($password = $user->getPassword()) 79 | ); 80 | 81 | if($response !== null and $response->isTwoFactorRequired()){ 82 | logSys(Terminal::YELLOW . 'Hesabınızın iki adımlı doğrulaması açık. Lütfen size gelen doğrulama kodunu giriniz...', API); 83 | $twoFactorIdentifier = $response->getTwoFactorInfo()->getTwoFactorIdentifier(); 84 | $verificationCode = trim(fgets(STDIN)); 85 | $this->instagram->finishTwoFactorLogin($username, $password, $twoFactorIdentifier, $verificationCode); 86 | } 87 | 88 | logSys(Terminal::GOLD . $username . Terminal::GREEN . ' hesabına başarıyla giriş yapıldı.', API); 89 | }catch(Exception $exception){ 90 | logSys(Terminal::RED . 'Bir sebepten dolayı hesabınıza giriş yapamadık. Hata: ' . Terminal::WHITE . $exception->getMessage(), API); 91 | exit(1); 92 | } 93 | 94 | } 95 | 96 | private function setupImageSys(){ 97 | if(!$this->settings->getRandomImageOpt()){ 98 | logSys(Terminal::GREEN . 'Görüntüler kullanıcı tarafından belirlenenler arasından çekilicek.'); 99 | 100 | if(file_exists(Config::USER_IMAGES_DIR)){ 101 | $open = opendir(Config::USER_IMAGES_DIR); 102 | while(($read = readdir($open))){ 103 | if(is_file(($dir = Config::USER_IMAGES_DIR . DIRECTORY_SEPARATOR . $read))){ 104 | $ext = pathinfo($dir)['extension']; 105 | if($ext == 'jpg' or $ext = 'png') 106 | $this->images[] = new Image($dir); 107 | } 108 | } 109 | } 110 | 111 | if(count($this->images) == 0){ 112 | logSys(Terminal::RED . 'Sistem png formatında resim bulamadı.', IMAGE_PROCESSOR); 113 | exit(1); 114 | } 115 | }else logSys(Terminal::GREEN . 'Görüntüler internetten rastgele çekilicek.'); 116 | } 117 | 118 | private function startApp() : void{ 119 | logSys(Terminal::DARK_PURPLE . 'Sistemin zaman dilimi ' . Terminal::WHITE . $this->timezone->get() . Terminal::DARK_PURPLE . ' olarak ayarlandı.', SYSTEM); 120 | 121 | $this->setupImageSys(); 122 | 123 | sleep(60 - (time() % 60)); 124 | 125 | $i = 0; 126 | static $imageFile = __DIR__ . '/assets/images/image.%s'; 127 | while(true){ 128 | logSys(Terminal::LIGHT_PURPLE . 'Sistem tekrardan aktif.', SYSTEM); 129 | 130 | $png = null; 131 | if(!$this->settings->getRandomImageOpt()){ 132 | $image = $this->images[$i] ?? (function(int &$i) : Image{ 133 | $i = 0; 134 | return $this->images[$i]; 135 | })($i); 136 | $path = $image->getPath(); 137 | if($image->getExtension() == 'jpg'){ 138 | logSys(Terminal::GREEN . 'Görüntü jpg formatından png formatına çevriliyor...', IMAGE_PROCESSOR); 139 | 140 | $this->imageCompress->jpgConvertToPng($path, $image->getFilename()); 141 | 142 | logSys(Terminal::GREEN . 'Görüntü jpg formatından png formatına başarıyla çevrildi.', IMAGE_PROCESSOR); 143 | 144 | unlink($path); 145 | 146 | $image->setPath(str_replace('jpg', 'png', $path)); 147 | 148 | logSys(Terminal::RED . 'Eski görüntü verisi silindi.', SYSTEM); 149 | } 150 | file_put_contents( 151 | ($png = sprintf($imageFile, 'png')), 152 | file_get_contents($image->getPath()) 153 | ); 154 | }else{ 155 | $this->downloadRandomImage(); 156 | 157 | $jpg = sprintf($imageFile, 'jpg'); 158 | 159 | logSys(Terminal::GREEN . 'Görüntü jpg formatından png formatına çevriliyor...', IMAGE_PROCESSOR); 160 | 161 | $this->imageCompress->jpgConvertToPng($jpg); 162 | 163 | logSys(Terminal::GREEN . 'Görüntü jpg formatından png formatına başarıyla çevrildi.', IMAGE_PROCESSOR); 164 | unlink($jpg); 165 | 166 | logSys(Terminal::RED . 'Eski görüntü verisi silindi.', SYSTEM); 167 | 168 | $png = sprintf($imageFile, 'png'); 169 | } 170 | 171 | if($png != null){ 172 | logSys(Terminal::GREEN . 'Görüntü yeniden boyutlandırıp, yeniden düzenleniyor...', IMAGE_PROCESSOR); 173 | 174 | $this->imageCompress 175 | ->resizeImage($png) 176 | ->drawCircleOnImage($png) 177 | ->writeOnImage($png, date('H:i')) 178 | ->writeOnImage($png, PHP_EOL . date('d.m.Y')); 179 | 180 | logSys(Terminal::GREEN . 'Görüntü yeniden boyutlandırıldı ve düzenlendi. Görüntü verisi kaydedildi.', IMAGE_PROCESSOR); 181 | 182 | try{ 183 | $this->instagram->account->changeProfilePicture($png); 184 | 185 | logSys(Terminal::GREEN . 'Profil fotoğrafınız güncellendi.', API); 186 | }catch(Exception $exception){ 187 | logSys(Terminal::RED . 'Profil fotoğrafı bir sebepten dolayı değiştirilemedi. Program kapatılıyor. Hata: ' . Terminal::WHITE . $exception->getMessage(), API); 188 | } 189 | 190 | $sleep = 60 - (time() % 60); 191 | logSys(Terminal::GOLD . 'Bir dahaki güncelleme için ' . Terminal::AQUA . $sleep . Terminal::GOLD . ' saniye bekleniyor...'); 192 | 193 | $i++; 194 | 195 | usleep(($sleep * 1000000) - 500000); 196 | }else{ 197 | logSys(Terminal::RED . 'Sistem belirlenemeyen bir hata sebebi ile çöktü.', SYSTEM); 198 | exit(1); 199 | } 200 | } 201 | 202 | } 203 | 204 | } -------------------------------------------------------------------------------- /src/Artemis/utils/Terminal.php: -------------------------------------------------------------------------------- 1 | . 18 | * 19 | */ 20 | 21 | namespace Artemis\utils; 22 | 23 | define('IMAGE_PROCESSOR', Terminal::GOLD . 'Görüntü İşleyici' . Terminal::GRAY . ' > '); 24 | define('IMAGE_API', Terminal::YELLOW . 'Image' . Terminal::WHITE . 'API' . Terminal::GRAY . ' > '); 25 | define('SYSTEM', Terminal::AQUA . 'Sistem' . Terminal::GRAY . ' > '); 26 | define('API', Terminal::LIGHT_PURPLE . 'Instagram' . Terminal::WHITE . 'API' . Terminal::GRAY . ' > '); 27 | 28 | class Terminal{ 29 | 30 | public const ESCAPE = "\xc2\xa7"; //§ 31 | 32 | public const BLACK = self::ESCAPE . "0"; 33 | public const DARK_BLUE = self::ESCAPE . "1"; 34 | public const DARK_GREEN = self::ESCAPE . "2"; 35 | public const DARK_AQUA = self::ESCAPE . "3"; 36 | public const DARK_RED = self::ESCAPE . "4"; 37 | public const DARK_PURPLE = self::ESCAPE . "5"; 38 | public const GOLD = self::ESCAPE . "6"; 39 | public const GRAY = self::ESCAPE . "7"; 40 | public const DARK_GRAY = self::ESCAPE . "8"; 41 | public const BLUE = self::ESCAPE . "9"; 42 | public const GREEN = self::ESCAPE . "a"; 43 | public const AQUA = self::ESCAPE . "b"; 44 | public const RED = self::ESCAPE . "c"; 45 | public const LIGHT_PURPLE = self::ESCAPE . "d"; 46 | public const YELLOW = self::ESCAPE . "e"; 47 | public const WHITE = self::ESCAPE . "f"; 48 | 49 | public const OBFUSCATED = self::ESCAPE . "k"; 50 | public const BOLD = self::ESCAPE . "l"; 51 | public const STRIKETHROUGH = self::ESCAPE . "m"; 52 | public const UNDERLINE = self::ESCAPE . "n"; 53 | public const ITALIC = self::ESCAPE . "o"; 54 | public const RESET = self::ESCAPE . "r"; 55 | 56 | public static $FORMAT_BOLD = ""; 57 | public static $FORMAT_OBFUSCATED = ""; 58 | public static $FORMAT_ITALIC = ""; 59 | public static $FORMAT_UNDERLINE = ""; 60 | public static $FORMAT_STRIKETHROUGH = ""; 61 | public static $FORMAT_RESET = ""; 62 | public static $COLOR_BLACK = ""; 63 | public static $COLOR_DARK_BLUE = ""; 64 | public static $COLOR_DARK_GREEN = ""; 65 | public static $COLOR_DARK_AQUA = ""; 66 | public static $COLOR_DARK_RED = ""; 67 | public static $COLOR_PURPLE = ""; 68 | public static $COLOR_GOLD = ""; 69 | public static $COLOR_GRAY = ""; 70 | public static $COLOR_DARK_GRAY = ""; 71 | public static $COLOR_BLUE = ""; 72 | public static $COLOR_GREEN = ""; 73 | public static $COLOR_AQUA = ""; 74 | public static $COLOR_RED = ""; 75 | public static $COLOR_LIGHT_PURPLE = ""; 76 | public static $COLOR_YELLOW = ""; 77 | public static $COLOR_WHITE = ""; 78 | 79 | private static $formattingCodes = null; 80 | 81 | public static function log(string $text, string $prefix = SYSTEM) : void{ 82 | $text = Terminal::DARK_GRAY . '[' . Terminal::YELLOW . date('H:i:s') . Terminal::DARK_GRAY . '] ' . $prefix . $text . Terminal::RESET . PHP_EOL; 83 | echo ((self::hasFormattingCodes() ? self::toANSI($text) : self::clean($text))); 84 | } 85 | 86 | public static function hasFormattingCodes(){ 87 | if(self::$formattingCodes === null){ 88 | $opts = getopt("", ["enable-ansi", "disable-ansi"]); 89 | if(isset($opts["disable-ansi"])){ 90 | self::$formattingCodes = false; 91 | }else{ 92 | $stdout = fopen("php://stdout", "w"); 93 | self::$formattingCodes = (isset($opts["enable-ansi"]) or ( //user explicitly told us to enable ANSI 94 | stream_isatty($stdout) and //STDOUT isn't being piped 95 | ( 96 | getenv('TERM') !== false or //Console says it supports colours 97 | (function_exists('sapi_windows_vt100_support') and sapi_windows_vt100_support($stdout)) //we're on windows and have vt100 support 98 | ) 99 | )); 100 | fclose($stdout); 101 | } 102 | self::init(); 103 | } 104 | return self::$formattingCodes; 105 | } 106 | 107 | public static function init() : void{ 108 | if(self::hasFormattingCodes()){ 109 | switch(PHP_OS_FAMILY){ 110 | case "Linux": 111 | case "Mac": 112 | case "BSD": 113 | self::getEscapeCodes(); 114 | return; 115 | case "Windows": 116 | case "Android": 117 | self::getFallbackEscapeCodes(); 118 | return; 119 | } 120 | } 121 | } 122 | 123 | protected static function getEscapeCodes(){ 124 | self::$FORMAT_BOLD = `tput bold`; 125 | self::$FORMAT_OBFUSCATED = `tput smacs`; 126 | self::$FORMAT_ITALIC = `tput sitm`; 127 | self::$FORMAT_UNDERLINE = `tput smul`; 128 | self::$FORMAT_STRIKETHROUGH = "\x1b[9m"; //`tput `; 129 | self::$FORMAT_RESET = `tput sgr0`; 130 | $colors = (int) `tput colors`; 131 | if($colors > 8){ 132 | self::$COLOR_BLACK = $colors >= 256 ? `tput setaf 16` : `tput setaf 0`; 133 | self::$COLOR_DARK_BLUE = $colors >= 256 ? `tput setaf 19` : `tput setaf 4`; 134 | self::$COLOR_DARK_GREEN = $colors >= 256 ? `tput setaf 34` : `tput setaf 2`; 135 | self::$COLOR_DARK_AQUA = $colors >= 256 ? `tput setaf 37` : `tput setaf 6`; 136 | self::$COLOR_DARK_RED = $colors >= 256 ? `tput setaf 124` : `tput setaf 1`; 137 | self::$COLOR_PURPLE = $colors >= 256 ? `tput setaf 127` : `tput setaf 5`; 138 | self::$COLOR_GOLD = $colors >= 256 ? `tput setaf 214` : `tput setaf 3`; 139 | self::$COLOR_GRAY = $colors >= 256 ? `tput setaf 145` : `tput setaf 7`; 140 | self::$COLOR_DARK_GRAY = $colors >= 256 ? `tput setaf 59` : `tput setaf 8`; 141 | self::$COLOR_BLUE = $colors >= 256 ? `tput setaf 63` : `tput setaf 12`; 142 | self::$COLOR_GREEN = $colors >= 256 ? `tput setaf 83` : `tput setaf 10`; 143 | self::$COLOR_AQUA = $colors >= 256 ? `tput setaf 87` : `tput setaf 14`; 144 | self::$COLOR_RED = $colors >= 256 ? `tput setaf 203` : `tput setaf 9`; 145 | self::$COLOR_LIGHT_PURPLE = $colors >= 256 ? `tput setaf 207` : `tput setaf 13`; 146 | self::$COLOR_YELLOW = $colors >= 256 ? `tput setaf 227` : `tput setaf 11`; 147 | self::$COLOR_WHITE = $colors >= 256 ? `tput setaf 231` : `tput setaf 15`; 148 | }else{ 149 | self::$COLOR_BLACK = self::$COLOR_DARK_GRAY = `tput setaf 0`; 150 | self::$COLOR_RED = self::$COLOR_DARK_RED = `tput setaf 1`; 151 | self::$COLOR_GREEN = self::$COLOR_DARK_GREEN = `tput setaf 2`; 152 | self::$COLOR_YELLOW = self::$COLOR_GOLD = `tput setaf 3`; 153 | self::$COLOR_BLUE = self::$COLOR_DARK_BLUE = `tput setaf 4`; 154 | self::$COLOR_LIGHT_PURPLE = self::$COLOR_PURPLE = `tput setaf 5`; 155 | self::$COLOR_AQUA = self::$COLOR_DARK_AQUA = `tput setaf 6`; 156 | self::$COLOR_GRAY = self::$COLOR_WHITE = `tput setaf 7`; 157 | } 158 | } 159 | 160 | protected static function getFallbackEscapeCodes(){ 161 | self::$FORMAT_BOLD = "\x1b[1m"; 162 | self::$FORMAT_OBFUSCATED = ""; 163 | self::$FORMAT_ITALIC = "\x1b[3m"; 164 | self::$FORMAT_UNDERLINE = "\x1b[4m"; 165 | self::$FORMAT_STRIKETHROUGH = "\x1b[9m"; 166 | self::$FORMAT_RESET = "\x1b[m"; 167 | self::$COLOR_BLACK = "\x1b[0;30m"; 168 | self::$COLOR_DARK_BLUE = "\x1b[0;34m"; 169 | self::$COLOR_DARK_GREEN = "\x1b[0;32m"; 170 | self::$COLOR_DARK_AQUA = "\x1b[0;36m"; 171 | self::$COLOR_DARK_RED = "\x1b[0;30m"; 172 | self::$COLOR_PURPLE = "\x1b[0;35m"; 173 | self::$COLOR_GOLD = "\x1b[38;5;214m"; 174 | self::$COLOR_GRAY = "\x1b[0;37m"; 175 | self::$COLOR_DARK_GRAY = "\x1b[1;30m"; 176 | self::$COLOR_BLUE = "\x1b[1;34m"; 177 | self::$COLOR_GREEN = "\x1b[1;32m"; 178 | self::$COLOR_AQUA = "\x1b[1;36m"; 179 | self::$COLOR_RED = "\x1b[1;31m"; 180 | self::$COLOR_LIGHT_PURPLE = "\x1b[1;35m"; 181 | self::$COLOR_YELLOW = "\x1b[1;33m"; 182 | self::$COLOR_WHITE = "\x1b[1;37m"; 183 | } 184 | 185 | public static function toANSI($string) : string{ 186 | if(!is_array($string)) 187 | $string = self::tokenize($string); 188 | 189 | $newString = ""; 190 | foreach($string as $token){ 191 | switch($token){ 192 | case self::BOLD: 193 | $newString .= self::$FORMAT_BOLD; 194 | break; 195 | case self::OBFUSCATED: 196 | $newString .= self::$FORMAT_OBFUSCATED; 197 | break; 198 | case self::ITALIC: 199 | $newString .= self::$FORMAT_ITALIC; 200 | break; 201 | case self::UNDERLINE: 202 | $newString .= self::$FORMAT_UNDERLINE; 203 | break; 204 | case self::STRIKETHROUGH: 205 | $newString .= self::$FORMAT_STRIKETHROUGH; 206 | break; 207 | case self::RESET: 208 | $newString .= self::$FORMAT_RESET; 209 | break; 210 | //Colors 211 | case self::BLACK: 212 | $newString .= self::$COLOR_BLACK; 213 | break; 214 | case self::DARK_BLUE: 215 | $newString .= self::$COLOR_DARK_BLUE; 216 | break; 217 | case self::DARK_GREEN: 218 | $newString .= self::$COLOR_DARK_GREEN; 219 | break; 220 | case self::DARK_AQUA: 221 | $newString .= self::$COLOR_DARK_AQUA; 222 | break; 223 | case self::DARK_RED: 224 | $newString .= self::$COLOR_DARK_RED; 225 | break; 226 | case self::DARK_PURPLE: 227 | $newString .= self::$COLOR_PURPLE; 228 | break; 229 | case self::GOLD: 230 | $newString .= self::$COLOR_GOLD; 231 | break; 232 | case self::GRAY: 233 | $newString .= self::$COLOR_GRAY; 234 | break; 235 | case self::DARK_GRAY: 236 | $newString .= self::$COLOR_DARK_GRAY; 237 | break; 238 | case self::BLUE: 239 | $newString .= self::$COLOR_BLUE; 240 | break; 241 | case self::GREEN: 242 | $newString .= self::$COLOR_GREEN; 243 | break; 244 | case self::AQUA: 245 | $newString .= self::$COLOR_AQUA; 246 | break; 247 | case self::RED: 248 | $newString .= self::$COLOR_RED; 249 | break; 250 | case self::LIGHT_PURPLE: 251 | $newString .= self::$COLOR_LIGHT_PURPLE; 252 | break; 253 | case self::YELLOW: 254 | $newString .= self::$COLOR_YELLOW; 255 | break; 256 | case self::WHITE: 257 | $newString .= self::$COLOR_WHITE; 258 | break; 259 | default: 260 | $newString .= $token; 261 | break; 262 | } 263 | } 264 | return $newString; 265 | } 266 | 267 | public static function tokenize(string $string) : array{ 268 | return preg_split("/(" . self::ESCAPE . "[0-9a-fk-or])/", $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); 269 | } 270 | 271 | public static function clean(string $string, bool $removeFormat = true) : string{ 272 | if($removeFormat){ 273 | return str_replace(self::ESCAPE, "", preg_replace(["/" . self::ESCAPE . "[0-9a-fk-or]/", "/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/"], "", $string)); 274 | } 275 | return str_replace("\x1b", "", preg_replace("/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/", "", $string)); 276 | } 277 | } --------------------------------------------------------------------------------