{"id":21840218,"url":"https://github.com/gocom/rah_swap","last_synced_at":"2025-04-14T10:51:44.339Z","repository":{"id":2386460,"uuid":"3352201","full_name":"gocom/rah_swap","owner":"gocom","description":"Swap Textpattern CMS' database on-the-fly with a template tag","archived":false,"fork":false,"pushed_at":"2022-04-16T23:29:04.000Z","size":37,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T00:04:51.379Z","etag":null,"topics":["php","textpattern","textpattern-plugin"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gocom.png","metadata":{"files":{"readme":"README.textile","changelog":null,"contributing":"CONTRIBUTING.textile","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":["https://www.paypal.me/jukkasvahn"]}},"created_at":"2012-02-04T11:03:16.000Z","updated_at":"2022-04-16T23:03:03.000Z","dependencies_parsed_at":"2022-09-09T16:00:19.288Z","dependency_job_id":null,"html_url":"https://github.com/gocom/rah_swap","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocom%2Frah_swap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocom%2Frah_swap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocom%2Frah_swap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocom%2Frah_swap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gocom","download_url":"https://codeload.github.com/gocom/rah_swap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248868857,"owners_count":21174754,"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":["php","textpattern","textpattern-plugin"],"created_at":"2024-11-27T21:25:13.069Z","updated_at":"2025-04-14T10:51:44.318Z","avatar_url":"https://github.com/gocom.png","language":"PHP","funding_links":["https://www.paypal.me/jukkasvahn"],"categories":[],"sub_categories":[],"readme":"h1. rah_swap\n\n\"Download\":https://github.com/gocom/rah_swap/releases | \"Packagist\":https://packagist.org/packages/rah/rah_swap | \"Issues\":https://github.com/gocom/rah_swap/issues\n\nSwap connected \"Textpattern CMS\":https://textpattern.com MySQL database link on the fly using a template tag. The plugin has the potential to allow pulling templates, articles and other content from different databases.\n\nh2. Install\n\nUsing \"Composer\":https://getcomposer.org:\n\nbc. $ composer require rah/rah_swap\n\nOr \"download\":https://github.com/gocom/rah_swap/releases an installer package.\n\nh2. Basics\n\nbc. \u003crah::swap db=\"myNewDatabase\"\u003e\n    ...contained statement...\n\u003c/rah::swap\u003e\n\nThe plugin introduces a new tag, @\u003crah::swap/\u003e@. The tag can be used both as a container and as a single, self-closing tag. When used as a container the database connection link is changed for just the wrapped code. The original link is restored on the closing tag pair.\n\nh2. Attributes\n\n*db*\nDatabase's name. If @db@ is the only attribute set, currently connected database is changed using current connection's credentials (user, password, host). A new link isn't created, but merely the database is swapped reusing the old connection.\nExample: @db=\"myDatabase\"@ Default: _undefined_\n\n*user*\nUsername used to connect to the database.\nExample: @user=\"username\"@ Default: _undefined_\n\n*pass*\nUser's password. Can be left empty if the user doesn't have a password.\nExample: @pass=\"password\"@ Default: _undefined_\n\n*host*\nThe database server. The @host@ can contain a hostname, a port number or a path to a local socket. Defaults to @localhost@.\nExample: @host=\"hostname.tld:3306\"@ Default: _undefined_\n\n*dbcharset*\nDatabase's character set. Usually this attribute should *not* be used, but should be left as it is. Textpattern uses UTF-8, and using non-unicode character set can cause unexpected results.\nExample: @dbcharset=\"latin1\"@ Default: _undefined_\n\n*client_flags*\nExtra flags passed to the database client. Normally you shouldn't worry about this attribute. Usually the attribute should *not* be used.\nExample: @client_flags=\"\"@ Default: _undefined_\n\n*reset*\nA boolean attribute that when set, resets the database connection back to its original state. If the tag is used as a container, resetting is done automatically on the closing tag pair without the need of the @reset@ attribute. When rah_swap's tags are used as self-closing single tags, use @reset@ when you want to resume to Textpattern's original database connection.\nExample: @reset@ Default: _undefined_\n\n*link*\nName of predefined database credentials config item. If the @link@ attribute is defined, the used credentials are pulled from a pre-defined config array variable, @$rah_swap@, stored in Textpattern's configuration file, @config.php@.\nExample: @link=\"template_db\"@ Default: _undefined_\n\nh2. Configuration\n\nWith the help of the tag's @link@ attribute, database connection credentials can be saved to Textpattern's configuration file (i.e. @/textpattern/config.php@) instead of them being specified with the tag attributes.\n\nDefining the database's connection credentials is done basically in the same way as Textpattern's core database details are defined. Rah_swap expects a global variable named as @$rah_swap@, containing a multi-dimensional array, allowing multiple links to be configured. Example config would look similar to following:\n\nbc.. $rah_swap['link1'] = [\n    'db' =\u003e 'MyDatabase1',\n    'user' =\u003e 'MyUsername1',\n    'pass' =\u003e 'MyPassword1',\n    'host' =\u003e 'localhost',\n];\n\n$rah_swap['link2'] = [\n    'db' =\u003e 'MyDatabase2',\n    'user' =\u003e 'MyUsername2',\n    'pass' =\u003e 'MyPassword2',\n    'host' =\u003e 'localhost',\n];\n\np. Where @link1@ and @link2@ would be the name of the link configurations and would be used as a @rah_swap@ tag's @link@ attribute's value.\n\nbc. \u003crah::swap link=\"link1\" /\u003e\n\u003crah::swap link=\"link2\" /\u003e\n\nh2. Examples\n\nh3. Simple usage example\n\nThe contents wrapped in the @\u003crah::swap\u003e@ tags will be pulled from database named as **promotional_content_db**.\n\nbc. \u003crah::swap db=\"promotional_content_db\"\u003e\n    \u003ctxp:article_custom category=\"promo_2011_06\"\u003e\n        \u003ctxp:body/\u003e\n    \u003c/txp:article_custom\u003e\n\u003c/rah::swap\u003e\n\nIn the example @promotional_content_db@ would be a database used by second Textpattern installation. The installation would be used to host promotional content and campaigns redistributed to multiple sites.\n\nh3. Showing downloads from a second installation\n\nbc. \u003crah::swap db=\"downloads\"\u003e\n    \u003ctxp:file_download\u003e\n        \u003ctxp:file_download_link\u003e\n            \u003ctxp:file_download_name/\u003e\n        \u003c/txp:file_download_link\u003e\n    \u003c/txp:file_download\u003e\n\u003c/rah::swap\u003e\n\nAbove serves file downloads from **downloads** database using Textpattern's \"file tags\":https://docs.textpattern.com/tags/file-tags.\n\nh3. As a self-closing tag\n\nTemplates are going to be fetched from **templates** database.\n\nbc. \u003crah::swap link=\"templates\"/\u003e\n\u003ctxp:output_form form=\"header\"/\u003e\n\u003ctxp:output_form form=\"cdn_template_banner_256x145\"/\u003e\n\u003ctxp:output_form form=\"cdn_template_banner_256x145\"/\u003e\n\u003crah::swap reset/\u003e\n\nThe connection is reset back to normal using the @reset@ attribute.\n\nh2. Changelog\n\nh3. Version 0.2.0 - 2022/04/17\n\n* Textpattern \u003e= 4.7.0 and PHP \u003e= 7.0 compatibility.\n* Now requires Textpattern \u003e= 4.7.0.\n\nh3. Version 0.1.0 - 2013/05/06\n\n* Initial release.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgocom%2Frah_swap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgocom%2Frah_swap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgocom%2Frah_swap/lists"}