From de4d164b2b605afe020fbabe853683980054be87 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Thu, 2 Nov 2023 22:23:56 +0000 Subject: [PATCH 01/24] docs: docs --- _docs/legalnotice.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/_docs/legalnotice.md b/_docs/legalnotice.md index 434989c..5f46aa9 100644 --- a/_docs/legalnotice.md +++ b/_docs/legalnotice.md @@ -9,3 +9,7 @@ To offer you SmartyURL features, we leverage third-party tools and libraries, in * IP2Location-PHP-Module, Copyright (C) 2005-2023 by IP2Location.com, MIT License . * Laminas/Escaper Copyright (c) 2020 Laminas Project a Series of LF Projects, LLC. , BSD 3-Clause “New” or “Revised” License . * MobileDetect , Copyright (c) 2021 Şerban Ghiţă, Nick Ilyin and contributors. , MIT License . + +## Trademark Notice +The word "QR Code" is a registered trademark of DENSO WAVE INCORPORATED +https://www.qrcode.com/en/faq.html#patentH2Title From 33aa4db83fd30410a947f03d5593206060ee8b4b Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Fri, 3 Nov 2023 01:48:09 +0000 Subject: [PATCH 02/24] dependency: adding chillerlan/php-qrcode --- _docs/legalnotice.md | 1 + composer.json | 3 +- composer.lock | 165 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 166 insertions(+), 3 deletions(-) diff --git a/_docs/legalnotice.md b/_docs/legalnotice.md index 5f46aa9..6084583 100644 --- a/_docs/legalnotice.md +++ b/_docs/legalnotice.md @@ -9,6 +9,7 @@ To offer you SmartyURL features, we leverage third-party tools and libraries, in * IP2Location-PHP-Module, Copyright (C) 2005-2023 by IP2Location.com, MIT License . * Laminas/Escaper Copyright (c) 2020 Laminas Project a Series of LF Projects, LLC. , BSD 3-Clause “New” or “Revised” License . * MobileDetect , Copyright (c) 2021 Şerban Ghiţă, Nick Ilyin and contributors. , MIT License . +* chillerlan/php-qrcode Copyright (c) 2015 Smiley , MIT License . ## Trademark Notice The word "QR Code" is a registered trademark of DENSO WAVE INCORPORATED diff --git a/composer.json b/composer.json index 65fabd6..b82a3fb 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "ip2location/ip2location-php": "^9.7", "mobiledetect/mobiledetectlib": "4.8.x-dev", "sokil/php-isocodes": "^4.2", - "sokil/php-isocodes-db-i18n": "^4.0" + "sokil/php-isocodes-db-i18n": "^4.0", + "chillerlan/php-qrcode": "dev-main" }, "require-dev": { "fakerphp/faker": "^1.9", diff --git a/composer.lock b/composer.lock index a7779d4..11a7ede 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,168 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e71443e813ee47717d7ec75781f7184b", + "content-hash": "cf3ab257606ccac693452dff20376556", "packages": [ + { + "name": "chillerlan/php-qrcode", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://github.com/chillerlan/php-qrcode.git", + "reference": "33ad99a1bd116fa329993b373224e16e5af43f6d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/chillerlan/php-qrcode/zipball/33ad99a1bd116fa329993b373224e16e5af43f6d", + "reference": "33ad99a1bd116fa329993b373224e16e5af43f6d", + "shasum": "" + }, + "require": { + "chillerlan/php-settings-container": "^2.1.4 || ^3.1", + "ext-mbstring": "*", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "chillerlan/php-authenticator": "^4.0 || ^5.0", + "phan/phan": "^5.4", + "phpmd/phpmd": "^2.13", + "phpunit/phpunit": "^9.6", + "setasign/fpdf": "^1.8.2", + "squizlabs/php_codesniffer": "^3.7" + }, + "suggest": { + "chillerlan/php-authenticator": "Yet another Google authenticator! Also creates URIs for mobile apps.", + "setasign/fpdf": "Required to use the QR FPDF output.", + "simple-icons/simple-icons": "SVG icons that you can use to embed as logos in the QR Code" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "chillerlan\\QRCode\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT", + "Apache-2.0" + ], + "authors": [ + { + "name": "Kazuhiko Arase", + "homepage": "https://github.com/kazuhikoarase/qrcode-generator" + }, + { + "name": "ZXing Authors", + "homepage": "https://github.com/zxing/zxing" + }, + { + "name": "Ashot Khanamiryan", + "homepage": "https://github.com/khanamiryan/php-qrcode-detector-decoder" + }, + { + "name": "Smiley", + "email": "smiley@chillerlan.net", + "homepage": "https://github.com/codemasher" + }, + { + "name": "Contributors", + "homepage": "https://github.com/chillerlan/php-qrcode/graphs/contributors" + } + ], + "description": "A QR code generator and reader with a user friendly API. PHP 7.4+", + "homepage": "https://github.com/chillerlan/php-qrcode", + "keywords": [ + "phpqrcode", + "qr", + "qr code", + "qr-reader", + "qrcode", + "qrcode-generator", + "qrcode-reader" + ], + "support": { + "docs": "https://php-qrcode.readthedocs.io", + "issues": "https://github.com/chillerlan/php-qrcode/issues", + "source": "https://github.com/chillerlan/php-qrcode" + }, + "funding": [ + { + "url": "https://www.paypal.com/donate?hosted_button_id=WLYUNAT9ZTJZ4", + "type": "custom" + }, + { + "url": "https://ko-fi.com/codemasher", + "type": "ko_fi" + } + ], + "time": "2023-10-29T19:15:03+00:00" + }, + { + "name": "chillerlan/php-settings-container", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/chillerlan/php-settings-container.git", + "reference": "4d02944424fa1f48abca96353257c93cbac856c1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/4d02944424fa1f48abca96353257c93cbac856c1", + "reference": "4d02944424fa1f48abca96353257c93cbac856c1", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^8.1" + }, + "require-dev": { + "phan/phan": "^5.4", + "phpmd/phpmd": "^2.13", + "phpunit/phpunit": "^10.2", + "squizlabs/php_codesniffer": "^3.7" + }, + "type": "library", + "autoload": { + "psr-4": { + "chillerlan\\Settings\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Smiley", + "email": "smiley@chillerlan.net", + "homepage": "https://github.com/codemasher" + } + ], + "description": "A container class for immutable settings objects. Not a DI container.", + "homepage": "https://github.com/chillerlan/php-settings-container", + "keywords": [ + "Settings", + "configuration", + "container", + "helper" + ], + "support": { + "issues": "https://github.com/chillerlan/php-settings-container/issues", + "source": "https://github.com/chillerlan/php-settings-container" + }, + "funding": [ + { + "url": "https://www.paypal.com/donate?hosted_button_id=WLYUNAT9ZTJZ4", + "type": "custom" + }, + { + "url": "https://ko-fi.com/codemasher", + "type": "ko_fi" + } + ], + "time": "2023-07-17T20:46:37+00:00" + }, { "name": "codeigniter4/framework", "version": "v4.4.3", @@ -4347,7 +4507,8 @@ "minimum-stability": "stable", "stability-flags": { "codeigniter4/shield": 20, - "mobiledetect/mobiledetectlib": 20 + "mobiledetect/mobiledetectlib": 20, + "chillerlan/php-qrcode": 20 }, "prefer-stable": false, "prefer-lowest": false, From 1e9d8264c3758f5f0735ffbc2d9474772329b203 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Fri, 3 Nov 2023 02:21:30 +0000 Subject: [PATCH 03/24] refactor: AuthGroups --- app/Config/AuthGroups.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Config/AuthGroups.php b/app/Config/AuthGroups.php index a3506a0..e7fea64 100644 --- a/app/Config/AuthGroups.php +++ b/app/Config/AuthGroups.php @@ -58,9 +58,9 @@ class AuthGroups extends ShieldAuthGroups 'super.admin' => 'Does he super admin', 'admin.manageotherurls' => 'can manage other users URLs', // not used yet // url - 'url.access' => 'Can Access URLs', // not used yet + 'url.access' => 'Can Access URLs', 'url.new' => 'Can Create a new URL', - 'url.manage' => 'Can Manage URL (edit , delete)', + 'url.manage' => 'Can Manage his/her URLs only (edit , delete)', ]; /** From 442d82e8ca6e4085f7ee9eec7d02c3eb562d2a13 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Fri, 3 Nov 2023 02:22:19 +0000 Subject: [PATCH 04/24] chore: adding qr version as config --- app/Config/Smartyurl.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/Config/Smartyurl.php b/app/Config/Smartyurl.php index da89e59..ccb5b04 100644 --- a/app/Config/Smartyurl.php +++ b/app/Config/Smartyurl.php @@ -87,6 +87,17 @@ class Smartyurl extends BaseConfig */ public int $maxUrlListPerPage = 100; + /** + * QR code version depends on your specific requirements and use case. + * QR codes come in various versions, ranging from Version 1 to Version 40 + * best from 3 to 7 + * default is 5 and if you have any error while generating QR Codes you can + * increase it. + * + * @var int + */ + public $qrCodeVersion = 5; + /** * The allowed pattern for Url Identifier * From 4f9d6999ac33542058c81e07bf9147d71265c35a Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Fri, 3 Nov 2023 02:23:14 +0000 Subject: [PATCH 05/24] feat: working on URL View Page --- app/Controllers/Url.php | 34 +++++++++++++++++++++++++++++++- app/Views/basic/url/urlinfo.php | 1 + src/SmartyUrl.php | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 app/Views/basic/url/urlinfo.php diff --git a/app/Controllers/Url.php b/app/Controllers/Url.php index 56b70e7..e6817bd 100644 --- a/app/Controllers/Url.php +++ b/app/Controllers/Url.php @@ -291,7 +291,39 @@ public function listData() public function view($UrlId) { - d($UrlId); + if (! auth()->user()->can('url.access', 'admin.manageotherurls', 'super.admin')) { + return smarty_permission_error(); + } + + $UrlModel = new UrlModel(); + $UrlTags = new UrlTags(); + $url_id = (int) esc(smarty_remove_whitespace_from_url_identifier($UrlId)); + if ($url_id === 0) { + // url_id given is not valid id + return redirect()->to('dashboard')->with('notice', lang('Url.urlError')); + } + $urlData = $UrlModel->where('url_id', $url_id)->first(); + + if ($urlData === null) { + // url not exsists in dataase + return redirect()->to('dashboard')->with('error', lang('Url.urlNotFoundShort')); + } + + // i will check the user permission , does he allowed to access this url info + $userCanManageUrl = $this->smartyurl->userCanAccessUrlInfo($url_id, (int) $urlData['url_user_id']); + if (! $userCanManageUrl) { + return smarty_permission_error('It not your URL 😉😉😉'); + } + $urlTagsCloud = $UrlTags->getUrlTagsCloud($url_id); + // $urlTagsCloud = '[{"value":"tag1","tag_id":"3"},{"value":"tag2","tag_id":"27"},{"value":"tag3","tag_id":"24"}]'; + + d($urlData); + dd($urlTagsCloud); + // i will also get the last 25 hits + + $data = []; + + return view(smarty_view('url/urlinfo'), $data); } public function new() diff --git a/app/Views/basic/url/urlinfo.php b/app/Views/basic/url/urlinfo.php new file mode 100644 index 0000000..ab35fac --- /dev/null +++ b/app/Views/basic/url/urlinfo.php @@ -0,0 +1 @@ +extend(smarty_view('layout')); diff --git a/src/SmartyUrl.php b/src/SmartyUrl.php index fc93023..71f582a 100644 --- a/src/SmartyUrl.php +++ b/src/SmartyUrl.php @@ -56,4 +56,39 @@ public function userCanManageUrl($urlId, $urlOwnerUserId = null): bool // check it this url is his own url and his usergroup has url.manage permissions return (bool) (auth()->user()->can('url.manage') && ($urlOwnerUserId === user_id())); } + + /** + * Check if the current logged-in user Can Access Url info for the specified URL. + * If $urlOwnerUserId is not provided, it will be retrieved from the database. + * permissions needed + * url.access or admin.manageotherurls and sure or he is super.admin + * + * @param int $urlId + * @param int $urlOwnerUserId + */ + public function userCanAccessUrlInfo($urlId, $urlOwnerUserId = null): bool + { + if ($urlOwnerUserId === null) { + // i will get the url data to know its owner + $UrlModel = new UrlModel(); + $url_id = (int) esc(smarty_remove_whitespace_from_url_identifier($urlId)); + $urlData = $UrlModel->where('url_id', $url_id)->first(); + if ($urlData === null) { + return false; + } + $urlOwnerUserId = (int) $urlData['url_user_id']; + } + // we will start from large permission to the lowest permission + if (auth()->user()->can('super.admin')) { + return true; + } + if (auth()->user()->can('admin.manageotherurls')) { + return true; + } + + // the above permissions are for superuser and admins and can deal with all urls not just there urls. + // but url.manage permission means his own urls only + // check it this url is his own url and his usergroup has url.manage permissions + return (bool) (auth()->user()->can('url.access') && ($urlOwnerUserId === user_id())); + } } From 55ac8a26e34ddf627faaeefb695209329c362ad3 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Fri, 3 Nov 2023 02:26:41 +0000 Subject: [PATCH 06/24] fix: fix variable name --- app/Controllers/Url.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Controllers/Url.php b/app/Controllers/Url.php index e6817bd..b476ba7 100644 --- a/app/Controllers/Url.php +++ b/app/Controllers/Url.php @@ -310,8 +310,8 @@ public function view($UrlId) } // i will check the user permission , does he allowed to access this url info - $userCanManageUrl = $this->smartyurl->userCanAccessUrlInfo($url_id, (int) $urlData['url_user_id']); - if (! $userCanManageUrl) { + $userCanAccessUrl = $this->smartyurl->userCanAccessUrlInfo($url_id, (int) $urlData['url_user_id']); + if (! $userCanAccessUrl) { return smarty_permission_error('It not your URL 😉😉😉'); } $urlTagsCloud = $UrlTags->getUrlTagsCloud($url_id); From 47e3c078bfaf34197f8a58e430df9753d9cfeb08 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Fri, 3 Nov 2023 03:43:51 +0000 Subject: [PATCH 07/24] docs: developers docs --- README.md | 19 +++++++------------ _docs/developers.md | 37 +++++++++++++++++++++++++++++++------ _docs/index.md | 6 ++++-- 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 939a51b..6982cbc 100644 --- a/README.md +++ b/README.md @@ -29,28 +29,23 @@ In addition to shortening URLs (based on domain that you use), SmartyURL also of * **Tracking and analytics** * **Customization** -## Server Requirements +## Installation -- You need a web hosting account (for a domain or sub-domain) with PHP 7.4 or higher support and the following PHP extensions (typically supported by most PHP hosting providers): +Currently, as SmartyURL is in its early stages, you can only install it using Composer. Once we release the first official version of SmartyURL, we will offer detailed installation instructions for other methods. - - [mysqlnd](http://php.net/manual/en/mysqlnd.install.php) , [intl](http://php.net/manual/en/intl.requirements.php) , [mbstring](http://php.net/manual/en/mbstring.installation.php) , [libcurl](https://www.php.net/manual/en/curl.setup.php) , [gmp](https://www.php.net/manual/en/gmp.installation.php) , [json](https://www.php.net/manual/en/json.installation.php), [bcmath](https://www.php.net/manual/en/bc.setup.php) - -- Your web hosting account should have MySQL 8.0+ support +see [Developers Guide](_docs/developers.md#installation) for more information about how to install SmartyURL. -Afterwards, you can refer to the [installation instructions](_docs/installation.md) to set up the tool on your hosting account and begin using it. +Certainly, please refer to the [documentation](_docs/index.md) for detailed instructions How configure, and effectively use SmartyURL for comprehensive guidance. -Certainly, please refer to the [documentation](_docs/index.md) for detailed instructions on how to install, configure, and effectively use Smart URL for comprehensive guidance. +## Documentation + +Please take a look to SmartyURL [documentation](_docs/index.md) for detailed installation, configuration, and usage instructions. **Visitors IP Country detection** SmartyURL uses the `ip2location/ip2location-php` library to determine visitors country based on their IP addresses. It includes the free "IP2Location™ LITE IP-COUNTRY Database" for both personal and commercial use. For enhanced geographical redirect conditions with more accurate and up-to-date IP-based country data or if you need more accuracy consider purchasing a licensed IP2Location database. Refer to [IP2Location Database Docs](_docs/ip2location.md) for more details. -## Documentation - -Please take a look to SmartyURL [documentation](_docs/index.md) for detailed installation, configuration, and usage instructions. - - ## License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. diff --git a/_docs/developers.md b/_docs/developers.md index 880506c..15a02ac 100644 --- a/_docs/developers.md +++ b/_docs/developers.md @@ -1,21 +1,45 @@ # SmartyURL Developer Guide +## Server Requirements + +- You need a web hosting account (for a domain or sub-domain) with PHP 7.4 or higher support and the following PHP extensions (typically supported by most PHP hosting providers): + + - [mysqlnd](http://php.net/manual/en/mysqlnd.install.php) , [intl](http://php.net/manual/en/intl.requirements.php) , [mbstring](http://php.net/manual/en/mbstring.installation.php) , [libcurl](https://www.php.net/manual/en/curl.setup.php) , [gmp](https://www.php.net/manual/en/gmp.installation.php) , [json](https://www.php.net/manual/en/json.installation.php), [bcmath](https://www.php.net/manual/en/bc.setup.php) + +- Your web hosting account should have MySQL 8.0+ support + ## Installation -Currently, as SmartyURL is in its early stages, you can only install it using Composer. Once we release the first official version of SmartyURL, we will offer detailed installation instructions for other methods. +Currently, as SmartyURL is in its early stages, you can only install it using `Composer`. Once we release the first official version of SmartyURL, we will offer detailed installation instructions for other methods. install SmartyURL using composer: ```cli -composer create-project extendy/smartyurl myapp +composer create-project extendy/smartyurl:dev-main myapp +cd myapp +composer install +cp env .env +``` +When using Composer, you can update SmartyURL dependencies in the future using `composer update`. However, for updating SmartyURL itself, manual updates or reinitializing the Composer project **are necessary**. + +For Extendy developers or Developers who prefer to keep SmartyURL up to date using `Git` rather than `Composer`, you can install it by running:: + +```bash +git clone https://github.com/Extendy/SmartyURL.git myapp cd myapp composer install cp env .env ``` +> [!IMPORTANT] +> When installing SmartyURL with `git`, you gain the flexibility to easily update SmartyURL in the future using `git fetch` and `git pull`. However, it's worth noting that using `git` may provide bleeding-edge releases, which might not be as stable or thoroughly tested. +> Therefore Installing SmartyURL using `git` is recommended for experienced or Extendy developers only. + + + Ensure that you've created a MySQL database, then proceed to edit the .env file. Update the database configuration and make any necessary changes to tailor the other settings to your specific requirements. -then run the migrate all command to import database: +Next, execute the 'migrate' command to import the database structure into your created database using: ```cli php spark migrate --all @@ -30,12 +54,13 @@ php spark shield:user create or by visiting your website and register new user -Ensure the user you've created is designated as a superadmin by modifying the `auth_groups_users` database table. Set the user's group name to 'superadmin' instead of 'user' for the created user. +Ensure the user you've created is designated as a superadmin by modifying the `auth_groups_users` database table. Set the user's group name to 'superadmin' instead of 'user' for the created user using phpMyAdmin or any mysql client and make sure the user status is active by set `active` to `1` in `users` tables. or you have to verify the email next time you login. Afterward, you can disable new user registration by editing the .env file. Make sure to set `Auth.allowRegistration` to 'false'. If it's not already present in your .env file, you can add it like this: -When logged in, you might be prompted to verify your email to activate your account. Please check your email for a verification link. If you are unable to access your email, you can manually set the 'active' value to 1 in the 'users' database table for the user you've created. - ```cli Auth.allowRegistration = false ``` + +When logged in, you might be prompted to verify your email to activate your account. Please check your email for a verification link. If you are unable to access your email or SmartyURL unable to send emails, you can manually set the 'active' value to 1 in the 'users' database table for the user you've created. + diff --git a/_docs/index.md b/_docs/index.md index dde8480..ca14157 100644 --- a/_docs/index.md +++ b/_docs/index.md @@ -24,9 +24,11 @@ In addition to shortening URLs (based on domain that you use), SmartyURL also of ## Server Requirements -You need a web hosting account (for a domain or sub-domain) with PHP 7.4 or higher support and the following PHP extensions (typically supported by most PHP hosting providers): +- You need a web hosting account (for a domain or sub-domain) with PHP 7.4 or higher support and the following PHP extensions (typically supported by most PHP hosting providers): -- [mysqlnd](http://php.net/manual/en/mysqlnd.install.php) , [intl](http://php.net/manual/en/intl.requirements.php) , [mbstring](http://php.net/manual/en/mbstring.installation.php) , [libcurl](https://www.php.net/manual/en/curl.setup.php) , [gmp](https://www.php.net/manual/en/gmp.installation.php) , [json](https://www.php.net/manual/en/json.installation.php), [bcmath](https://www.php.net/manual/en/bc.setup.php) + - [mysqlnd](http://php.net/manual/en/mysqlnd.install.php) , [intl](http://php.net/manual/en/intl.requirements.php) , [mbstring](http://php.net/manual/en/mbstring.installation.php) , [libcurl](https://www.php.net/manual/en/curl.setup.php) , [gmp](https://www.php.net/manual/en/gmp.installation.php) , [json](https://www.php.net/manual/en/json.installation.php), [bcmath](https://www.php.net/manual/en/bc.setup.php) + +- Your web hosting account should have MySQL 8.0+ support ## Installation From 46956bc089b4d78dd8451eb39c904ff274c5f5b9 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Fri, 3 Nov 2023 04:06:22 +0000 Subject: [PATCH 08/24] docs: docs --- _docs/developers.md | 13 ++++++++----- mkdocs.yml | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/_docs/developers.md b/_docs/developers.md index 15a02ac..e5585d7 100644 --- a/_docs/developers.md +++ b/_docs/developers.md @@ -12,7 +12,7 @@ Currently, as SmartyURL is in its early stages, you can only install it using `Composer`. Once we release the first official version of SmartyURL, we will offer detailed installation instructions for other methods. -install SmartyURL using composer: +### install SmartyURL using `Composer`: ```cli composer create-project extendy/smartyurl:dev-main myapp @@ -22,6 +22,8 @@ cp env .env ``` When using Composer, you can update SmartyURL dependencies in the future using `composer update`. However, for updating SmartyURL itself, manual updates or reinitializing the Composer project **are necessary**. +### Or install with `git` + For Extendy developers or Developers who prefer to keep SmartyURL up to date using `Git` rather than `Composer`, you can install it by running:: ```bash @@ -31,11 +33,11 @@ composer install cp env .env ``` -> [!IMPORTANT] -> When installing SmartyURL with `git`, you gain the flexibility to easily update SmartyURL in the future using `git fetch` and `git pull`. However, it's worth noting that using `git` may provide bleeding-edge releases, which might not be as stable or thoroughly tested. -> Therefore Installing SmartyURL using `git` is recommended for experienced or Extendy developers only. - +!!! note + When installing SmartyURL with `git`, you gain the flexibility to easily update SmartyURL in the future using `git fetch` and `git pull`. However, it's worth noting that using `git` may provide bleeding-edge releases, which might not be as stable or thoroughly tested. + Therefore Installing SmartyURL using `git` is recommended for experienced or Extendy developers only. +### After installing the files Ensure that you've created a MySQL database, then proceed to edit the .env file. Update the database configuration and make any necessary changes to tailor the other settings to your specific requirements. @@ -64,3 +66,4 @@ Auth.allowRegistration = false When logged in, you might be prompted to verify your email to activate your account. Please check your email for a verification link. If you are unable to access your email or SmartyURL unable to send emails, you can manually set the 'active' value to 1 in the 'users' database table for the user you've created. + diff --git a/mkdocs.yml b/mkdocs.yml index fd25d2b..4b68a14 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -13,4 +13,5 @@ nav: theme: readthedocs extra: version: 0.0.0-dev-DND - +markdown_extensions: + - admonition From eb2e31c083a59d41641c14856ece93da89d89e4f Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Fri, 3 Nov 2023 22:57:29 +0000 Subject: [PATCH 09/24] feat:show javascript disable notice , issue #81 --- app/Language/ar/Common.php | 1 + app/Language/en/Common.php | 1 + app/Views/basic/layout.php | 10 ++++++++++ app/Views/basic/users/login.php | 10 ++++++++++ 4 files changed, 22 insertions(+) diff --git a/app/Language/ar/Common.php b/app/Language/ar/Common.php index 3b0a2dd..ae4b317 100644 --- a/app/Language/ar/Common.php +++ b/app/Language/ar/Common.php @@ -1,6 +1,7 @@ 'لقد تم تعطيل جافا سكربت في المتصفح او ان المتصفح لا يدعم جافاسكربت وبالتالي لن يعمل التطبيق بالشكل الامثل ، فعل جافا سكربت او استخدم متصفح يدعم جافا سكربت.', 'dashboardTitle' => 'صفحة المعلومات', 'dashboardLnk' => 'صفحة المعلومات', 'accountSettingsLnk' => 'اعدادات الحساب', diff --git a/app/Language/en/Common.php b/app/Language/en/Common.php index df2bf83..f3028a6 100644 --- a/app/Language/en/Common.php +++ b/app/Language/en/Common.php @@ -1,6 +1,7 @@ 'JavaScript is disabled in your browser, impacting the application performance. Please enable JavaScript or switch to a JavaScript-supported browser for optimal functionality.', 'dashboardTitle' => 'Dashboard', 'dashboardLnk' => 'Dashboard', 'accountSettingsLnk' => 'Account Settings', diff --git a/app/Views/basic/layout.php b/app/Views/basic/layout.php index 7db970c..0e4fe73 100644 --- a/app/Views/basic/layout.php +++ b/app/Views/basic/layout.php @@ -246,6 +246,16 @@ class="nav-link ">
+ + + renderSection('main') ?> diff --git a/app/Views/basic/users/login.php b/app/Views/basic/users/login.php index 9f66e5a..bd8e72b 100644 --- a/app/Views/basic/users/login.php +++ b/app/Views/basic/users/login.php @@ -31,6 +31,16 @@ + + + - - + From c0666359fd11eaeb8b99ac20904adccb82d7e6d3 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Mon, 6 Nov 2023 00:21:58 +0000 Subject: [PATCH 18/24] fix: make table responive --- app/Views/basic/url/urlinfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Views/basic/url/urlinfo.php b/app/Views/basic/url/urlinfo.php index 174e4c7..741a117 100644 --- a/app/Views/basic/url/urlinfo.php +++ b/app/Views/basic/url/urlinfo.php @@ -167,7 +167,7 @@ class='bi bi-box-arrow-up-right'> href='' class='link-dark edit-link'> -
+
if (isset($lasthits) && count($lasthits) > 0) { ?> -
+
From 42c34b720df284a154c77969c39fdcd3146b3142 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Mon, 6 Nov 2023 00:29:28 +0000 Subject: [PATCH 19/24] feat: start working on URL QR Code generator --- app/Config/Routes.php | 1 + app/Controllers/Url.php | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index acb5756..3cd3ae6 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -27,6 +27,7 @@ $routes->get('edit/(:num)', 'Url::edit/$1', ['filter' => 'session']); $routes->post('edit/(:num)', 'Url::editAction/$1', ['filter' => 'session']); $routes->get('hits/(:num)', 'Url::hitslist/$1', ['filter' => 'session']); + $routes->get('qrcode/(:num)', 'Url::generateQRCode/$1', ['filter' => 'session']); }); // language route diff --git a/app/Controllers/Url.php b/app/Controllers/Url.php index 713e3f8..3be0f12 100644 --- a/app/Controllers/Url.php +++ b/app/Controllers/Url.php @@ -735,4 +735,9 @@ public function hitslist($UrlId) { echo 'URL HITS OF.' . $UrlId; } + + public function generateQRCode($UrlId) + { + echo 'Generate QR Code for.' . $UrlId; + } } From 085e3b6777c6fa59ac073c1baced6f9a47b55ad6 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Mon, 6 Nov 2023 18:37:29 +0000 Subject: [PATCH 20/24] Chore: rename _docs to docs for compatibility --- README.md | 10 +++++----- app/Config/Smarty.php | 2 +- {_docs => docs}/README.md | 0 {_docs => docs}/developers.md | 0 {_docs => docs}/index.md | 0 {_docs => docs}/installation.md | 0 {_docs => docs}/ip2location.md | 0 {_docs => docs}/legalnotice.md | 0 {_docs => docs}/license.md | 0 mkdocs.yml | 2 +- 10 files changed, 7 insertions(+), 7 deletions(-) rename {_docs => docs}/README.md (100%) rename {_docs => docs}/developers.md (100%) rename {_docs => docs}/index.md (100%) rename {_docs => docs}/installation.md (100%) rename {_docs => docs}/ip2location.md (100%) rename {_docs => docs}/legalnotice.md (100%) rename {_docs => docs}/license.md (100%) diff --git a/README.md b/README.md index 6982cbc..f8c16d3 100644 --- a/README.md +++ b/README.md @@ -33,17 +33,17 @@ In addition to shortening URLs (based on domain that you use), SmartyURL also of Currently, as SmartyURL is in its early stages, you can only install it using Composer. Once we release the first official version of SmartyURL, we will offer detailed installation instructions for other methods. -see [Developers Guide](_docs/developers.md#installation) for more information about how to install SmartyURL. +see [Developers Guide](docs/developers.md#installation) for more information about how to install SmartyURL. -Certainly, please refer to the [documentation](_docs/index.md) for detailed instructions How configure, and effectively use SmartyURL for comprehensive guidance. +Certainly, please refer to the [documentation](docs/index.md) for detailed instructions How configure, and effectively use SmartyURL for comprehensive guidance. ## Documentation -Please take a look to SmartyURL [documentation](_docs/index.md) for detailed installation, configuration, and usage instructions. +Please take a look to SmartyURL [documentation](docs/index.md) for detailed installation, configuration, and usage instructions. **Visitors IP Country detection** -SmartyURL uses the `ip2location/ip2location-php` library to determine visitors country based on their IP addresses. It includes the free "IP2Location™ LITE IP-COUNTRY Database" for both personal and commercial use. For enhanced geographical redirect conditions with more accurate and up-to-date IP-based country data or if you need more accuracy consider purchasing a licensed IP2Location database. Refer to [IP2Location Database Docs](_docs/ip2location.md) for more details. +SmartyURL uses the `ip2location/ip2location-php` library to determine visitors country based on their IP addresses. It includes the free "IP2Location™ LITE IP-COUNTRY Database" for both personal and commercial use. For enhanced geographical redirect conditions with more accurate and up-to-date IP-based country data or if you need more accuracy consider purchasing a licensed IP2Location database. Refer to [IP2Location Database Docs](docs/ip2location.md) for more details. ## License @@ -63,4 +63,4 @@ Also We would like to acknowledge the following resources and contributors for t ## SmartyURL Legal Notice -For more information, please refer to the [Legal Notice](_docs/legalnotice.md). +For more information, please refer to the [Legal Notice](docs/legalnotice.md). diff --git a/app/Config/Smarty.php b/app/Config/Smarty.php index db98e8d..6892c14 100644 --- a/app/Config/Smarty.php +++ b/app/Config/Smarty.php @@ -8,7 +8,7 @@ class Smarty extends BaseConfig { public $smarty_name = 'SmartyURL'; public $smarty_online_repo = 'https://smartyurl.extendy.net'; - public $smarty_version = '0.0.0-dev-DND'; + public $smarty_version = '0.0.0-dev-DND-1'; /** * @var string contain the file name of jquery supported version eg jquery-3.7.1 without js diff --git a/_docs/README.md b/docs/README.md similarity index 100% rename from _docs/README.md rename to docs/README.md diff --git a/_docs/developers.md b/docs/developers.md similarity index 100% rename from _docs/developers.md rename to docs/developers.md diff --git a/_docs/index.md b/docs/index.md similarity index 100% rename from _docs/index.md rename to docs/index.md diff --git a/_docs/installation.md b/docs/installation.md similarity index 100% rename from _docs/installation.md rename to docs/installation.md diff --git a/_docs/ip2location.md b/docs/ip2location.md similarity index 100% rename from _docs/ip2location.md rename to docs/ip2location.md diff --git a/_docs/legalnotice.md b/docs/legalnotice.md similarity index 100% rename from _docs/legalnotice.md rename to docs/legalnotice.md diff --git a/_docs/license.md b/docs/license.md similarity index 100% rename from _docs/license.md rename to docs/license.md diff --git a/mkdocs.yml b/mkdocs.yml index 4b68a14..69dc3a5 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,5 +1,5 @@ site_name: SmartyURL Docs -docs_dir: _docs +docs_dir: docs site_dir: site repo_url: https://github.com/Extendy/SmartyURL site_description: 'SmartyURL Documentation' From a2ff41a756329caf40269eedd15e32eb1f696595 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Mon, 6 Nov 2023 21:39:44 +0300 Subject: [PATCH 21/24] Create CNAME --- docs/CNAME | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/CNAME diff --git a/docs/CNAME b/docs/CNAME new file mode 100644 index 0000000..56c5734 --- /dev/null +++ b/docs/CNAME @@ -0,0 +1 @@ +gp.extendy.net \ No newline at end of file From d4b4197638f9447a6439e9e0298fea6a779b601e Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Mon, 6 Nov 2023 21:52:37 +0300 Subject: [PATCH 22/24] Delete CNAME --- docs/CNAME | 1 - 1 file changed, 1 deletion(-) delete mode 100644 docs/CNAME diff --git a/docs/CNAME b/docs/CNAME deleted file mode 100644 index 56c5734..0000000 --- a/docs/CNAME +++ /dev/null @@ -1 +0,0 @@ -gp.extendy.net \ No newline at end of file From 46badab995c22fe7eb51231f962f5bb1a3f25111 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Mon, 6 Nov 2023 21:52:49 +0300 Subject: [PATCH 23/24] Create CNAME --- docs/CNAME | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/CNAME diff --git a/docs/CNAME b/docs/CNAME new file mode 100644 index 0000000..3496165 --- /dev/null +++ b/docs/CNAME @@ -0,0 +1 @@ +docs.smartyurl.extendy.net \ No newline at end of file From f1bba793d17ad7485c374c8da18679da5e6b9825 Mon Sep 17 00:00:00 2001 From: Mohammed AlShannaq Date: Wed, 8 Nov 2023 23:18:07 +0000 Subject: [PATCH 24/24] Feat: View Url UI --- app/Controllers/Url.php | 70 ++++++++++++++++++++++++++++++++- app/Helpers/smarty_helper.php | 17 ++++++++ app/Views/basic/url/urlinfo.php | 68 +++++++++++++++++++++----------- 3 files changed, 132 insertions(+), 23 deletions(-) diff --git a/app/Controllers/Url.php b/app/Controllers/Url.php index 3be0f12..3c432f1 100644 --- a/app/Controllers/Url.php +++ b/app/Controllers/Url.php @@ -6,6 +6,9 @@ use App\Models\UrlModel; use App\Models\UrlTagsDataModel; use App\Models\UrlTagsModel; +use chillerlan\QRCode\Output\QROutputInterface; +use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\QROptions; use Extendy\Smartyurl\SmartyUrl; use Extendy\Smartyurl\UrlConditions; use Extendy\Smartyurl\UrlIdentifier; @@ -738,6 +741,71 @@ public function hitslist($UrlId) public function generateQRCode($UrlId) { - echo 'Generate QR Code for.' . $UrlId; + // set response type + $response = service('response'); + $response->setContentType('image/svg+xml'); + + $error = ''; + if (! auth()->user()->can('url.access', 'admin.manageotherurls', 'super.admin')) { + $error = 'Permission error'; + + return $response->setBody(smarty_svg_error($error)); + } + + $UrlModel = new UrlModel(); + $url_id = (int) esc(smarty_remove_whitespace_from_url_identifier($UrlId)); + + if ($url_id === 0) { + // url_id given is not valid id + $error = lang('Url.urlError'); + + return $response->setBody(smarty_svg_error($error)); + } + $urlData = $UrlModel->where('url_id', $url_id)->first(); + + if ($urlData === null) { + // url not exsists in dataase + $error = lang('Url.urlNotFoundShort'); + + return $response->setBody(smarty_svg_error($error)); + } + + // i will check the user permission , does he allowed to access this url info + $userCanAccessUrl = $this->smartyurl->userCanAccessUrlInfo($url_id, (int) $urlData['url_user_id']); + if (! $userCanAccessUrl) { + $error = 'not your URL 😉'; + + return $response->setBody(smarty_svg_error($error)); + } + + $Go_Url = esc(smarty_detect_site_shortlinker() . $urlData['url_identifier']); + + // prepare for the filename + // remove any special chars and white spaces will be _ + $pattern = '/[^\w\d\.,;!?@#$%^&*()_+-=:<>"\'\/\\\[\]{}|`~]+/u'; + $filename = setting('Smartyurl.siteName') . "_{$UrlId}.svg"; + $filename = str_replace(' ', '_', $filename); + $filename = preg_replace($pattern, '', $filename); + + // if query download i will set Content Disposition to attachment + $download = (int) $this->request->getGet('download'); // Access the 'download' parameter + if ($download === 1) { + $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"'); + } else { + $response->setHeader('Content-Disposition', 'inline; filename="' . $filename . '"'); + } + + // now I will generate QR Code + $options = new QROptions(); + // i will smarty detect qr version by text length + $options->version = smarty_smart_detect_qrversion($Go_Url); + $options->outputType = QROutputInterface::MARKUP_SVG; + $options->outputBase64 = false; + $options->drawLightModules = true; + $options->circleRadius = 0.4; + $out = (new QRCode($options))->render($Go_Url); + + // now i will return the image + return $response->setBody($out); } } diff --git a/app/Helpers/smarty_helper.php b/app/Helpers/smarty_helper.php index 467dcfc..381caa5 100644 --- a/app/Helpers/smarty_helper.php +++ b/app/Helpers/smarty_helper.php @@ -197,3 +197,20 @@ function smarty_get_user_username($userId) return $username; } } + +if (! function_exists('smarty_smart_detect_qrversion')) { + function smarty_smart_detect_qrversion($url) + { + return setting('Smartyurl.qrCodeVersion'); + } +} + +if (! function_exists('smarty_svg_error')) { + function smarty_svg_error($text) + { + return ' + + ' . $text . ' +'; + } +} diff --git a/app/Views/basic/url/urlinfo.php b/app/Views/basic/url/urlinfo.php index 741a117..1e0197a 100644 --- a/app/Views/basic/url/urlinfo.php +++ b/app/Views/basic/url/urlinfo.php @@ -98,39 +98,63 @@ class='bi bi-pencil edit-link-btn'> -
- : -
+ - +
+
+
+
+ : +
-
- : -
+ -
- : -
+
+ : +
-
-
- : + +
+ : +
+ + +
+
+ : +
+
+ : +
+
+ + + +
-
- : +
+
+ + " alt="Your SVG Image" class="pb-1"> + ?download=1" class="btn btn-sm btn-outline-dark"> + Download QR + + +
+
@@ -195,7 +219,7 @@ class='bi bi-pencil edit-link-btn'> } ?> - +