{"id":16184360,"url":"https://github.com/mattmezza/shrtnr","last_synced_at":"2025-07-19T20:40:11.241Z","repository":{"id":57016540,"uuid":"127018430","full_name":"mattmezza/shrtnr","owner":"mattmezza","description":"A simple PHP shortener.","archived":false,"fork":false,"pushed_at":"2018-04-19T13:14:27.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-13T15:36:29.537Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattmezza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-27T16:52:16.000Z","updated_at":"2018-04-19T13:14:17.000Z","dependencies_parsed_at":"2022-08-22T09:40:38.141Z","dependency_job_id":null,"html_url":"https://github.com/mattmezza/shrtnr","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmezza%2Fshrtnr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmezza%2Fshrtnr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmezza%2Fshrtnr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattmezza%2Fshrtnr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattmezza","download_url":"https://codeload.github.com/mattmezza/shrtnr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247656039,"owners_count":20974286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T07:09:56.561Z","updated_at":"2025-04-07T12:46:22.061Z","avatar_url":"https://github.com/mattmezza.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"shrtnr\n=====\n\nYour super simple and fast private goo·gl/bit·ly system, privately hosted wherever you want, completely frontend agnostic.\n\n## Installation\n\n- `composer require mattmezza/shrtnr`\n- define the env variables needed and set up the DB (check below)\n\n## Usage\n\nThe `Shrtnr` class offers a very simple API:\n\n- `shrtn(string $from, string $ip = null) : string` -\u003e Given a URI gives back the destination URL of the rule matching with the `from` field (or throws a `NoRuleException` if no rule is associated with the passed URI)\n\nCan be used like this (in this example we forward the query string to the destination URL):\n\n```php\n$both = explode(\"?\", $_SERVER[\"REQUEST_URI\"]);\n$uri = $both[0];\n$shrtnr = new Shrtnr();\ntry {\n    $to = $shrtnr-\u003eshrtn($uri);\n    if (count($both) \u003e 1) {\n        $to .= \"?\" . $_SERVER[\"QUERY_STRING\"];\n    }\n    header(\"Location: $to\");\n} catch (NoRuleException $e) {\n    die($e-\u003egetMessage());\n}\n\n```\n\n## Admin usage\n\nTo add, edit, remove and search for clicks and rules you can check out the DAOs `Clicks` and `Rules` that are exposing a couple of methods for CRUD ops.\n\n## DB\n\n`shrtnr` connects to the DB using three ENV variables `DB` which is the DSN (e.g. `mysql:host=127.0.0.1;dbname=shrtnr`), `DB_USER` and `DB_PASS` respectively for the db user and password.\n\nThe DB itself should be built as follows:\n\n```sql\nCREATE TABLE IF NOT EXISTS `clicks` (\n        `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n        `rule_id` int(11) unsigned NOT NULL,\n        `clicked_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,\n        `from` varchar(256) NOT NULL DEFAULT '',\n        `to` varchar(256) NOT NULL DEFAULT '',\n        `ip` varchar(16) DEFAULT NULL,\n        PRIMARY KEY (`id`),\n        KEY `rule_id` (`rule_id`),\n        CONSTRAINT `clicks_ibfk_1` FOREIGN KEY (`rule_id`) REFERENCES `rules` (`id`) ON DELETE CASCADE ON UPDATE CASCADE\n      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;\nCREATE TABLE IF NOT EXISTS `rules` (\n        `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n        `user_id` varchar(256) DEFAULT NULL,\n        `from` varchar(256) NOT NULL,\n        `to` varchar(256) NOT NULL,\n        `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,\n        `enabled` tinyint(1) NOT NULL DEFAULT '1',\n        `modified_at` datetime DEFAULT NULL,\n        PRIMARY KEY (`id`),\n        UNIQUE KEY `from` (`from`)\n      ) ENGINE=InnoDB DEFAULT CHARSET=utf8\n```\n\n## Entities\n\n`shrtnr` works with two main entities: `Rule` and `Click`.\n\n### Rule\n\nIt is the rule that instructs the system what to do for a specific URI. It has info about the matching URI and the destination URL. It also has a field `user_id` that should report an id of the user who created the rule (can be either a string or a numeric id).\n\n### Click\n\nIt represents an applied rule, it is created when somebody goes to the URI and gets redirected to the matching destination. It reports info about the IP address and references the applied rule.\n\n## Development\n\n- `git clone https://github.com/mattmezza/shrtnr.git`\n- `cd shrtnr`\n- define the `DB`, `DB_USER`, `DB_PASS` env variable\n- `composer migrate`\n- `composer test`\n\n\n##### Matteo Merola \u003cmattmezza@gmail.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattmezza%2Fshrtnr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattmezza%2Fshrtnr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattmezza%2Fshrtnr/lists"}