🎉 Hello world
This commit is contained in:
		
							
								
								
									
										21
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| # Shaarli umami | ||||
|  | ||||
| Allows to add umami tracking in Shaarli | ||||
|  | ||||
| ## Installation | ||||
|  | ||||
| ### Via Git | ||||
|  | ||||
| Run the following command from the plugins folder of your Shaarli installation: | ||||
|  | ||||
| git clone https://git.shikiryu.com/Shikiryu/shaarli-plugin-umami umami | ||||
|  | ||||
| It'll create the autosave folder. | ||||
|  | ||||
| ### Manually | ||||
|  | ||||
| Create the folder plugins/umami in your Shaarli installation. Download the ZIP file of this repository and copy all files in the newly created folder. | ||||
|  | ||||
| ## Configure | ||||
|  | ||||
| Configure umami's domain with protocol and without a trailing / | ||||
							
								
								
									
										3
									
								
								umami.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								umami.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| <!-- Umami --> | ||||
| <script async defer data-website-id="%s" src="%s/umami.js"></script> | ||||
| <!-- End Umami Code --> | ||||
							
								
								
									
										4
									
								
								umami.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								umami.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| description="A plugin that adds Umami tracking code to Shaarli pages." | ||||
| parameters="UMAMI_URL;UMAMI_SITEID" | ||||
| parameter.UMAMI_URL="Umami URL" | ||||
| parameter.UMAMI_SITEID="Umami site ID" | ||||
							
								
								
									
										74
									
								
								umami.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								umami.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,74 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Umami plugin. | ||||
|  * Adds tracking code on each page. | ||||
|  */ | ||||
|  | ||||
| use Shaarli\Plugin\PluginManager; | ||||
|  | ||||
| /** | ||||
|  * Initialization function. | ||||
|  * It will be called when the plugin is loaded. | ||||
|  * This function can be used to return a list of initialization errors. | ||||
|  * | ||||
|  * @param $conf ConfigManager instance. | ||||
|  * | ||||
|  * @return array List of errors (optional). | ||||
|  */ | ||||
| function umami_init($conf) | ||||
| { | ||||
|     $umamiUrl = $conf->get('plugins.UMAMI_URL'); | ||||
|     $umamiSiteid = $conf->get('plugins.UMAMI_SITEID'); | ||||
|     if (empty($umamiUrl) || empty($umamiSiteid)) { | ||||
|         $error = t('Umami plugin error: ' . | ||||
|             'Please define UMAMI_URL and UMAMI_SITEID in the plugin administration page.'); | ||||
|         return [$error]; | ||||
|     } | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Hook render_footer. | ||||
|  * Executed on every page redering. | ||||
|  * | ||||
|  * Template placeholders: | ||||
|  *   - text | ||||
|  *   - endofpage | ||||
|  *   - js_files | ||||
|  * | ||||
|  * Data: | ||||
|  *   - _PAGE_: current page | ||||
|  *   - _LOGGEDIN_: true/false | ||||
|  * | ||||
|  * @param array $data data passed to plugin | ||||
|  * | ||||
|  * @return array altered $data. | ||||
|  */ | ||||
| function hook_umami_render_footer($data, $conf) | ||||
| { | ||||
|     $umamiUrl = $conf->get('plugins.UMAMI_URL'); | ||||
|     $umamiSiteid = $conf->get('plugins.UMAMI_SITEID'); | ||||
|     if (empty($umamiUrl) || empty($umamiSiteid)) { | ||||
|         return $data; | ||||
|     } | ||||
|  | ||||
|     // Free elements at the end of the page. | ||||
|     $data['endofpage'][] = sprintf( | ||||
|         file_get_contents(PluginManager::$PLUGINS_PATH . '/umami/umami.html'), | ||||
|         $umamiSiteid, | ||||
|         $umamiUrl | ||||
|     ); | ||||
|  | ||||
|     return $data; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * This function is never called, but contains translation calls for GNU gettext extraction. | ||||
|  */ | ||||
| function umami_dummy_translation() | ||||
| { | ||||
|     // meta | ||||
|     t('A plugin that adds umami tracking code to Shaarli pages.'); | ||||
|     t('Umami URL'); | ||||
|     t('Umami site ID'); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user