diff --git a/includes/class-Template.php b/includes/class-Template.php new file mode 100644 index 0000000..1232063 --- /dev/null +++ b/includes/class-Template.php @@ -0,0 +1,49 @@ +. + +namespace itwikidelbot; + +/** + * Handle templates of text + * + * Templates are 'something.template' stuff into the /template directory + */ +class Template { + + const START_PLACEHOLDER = "\n"; + + /** + * @param $name string Template name + * @return string + */ + static function get( $name ) { + $path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $name . '.template'; + if( ! file_exists( $path ) ) { + throw new \InvalidArgumentException( 'unexisting template' ); + } + + $content = file_get_contents( $path ); + + // stripping header + $pos = strpos( $content, self::START_PLACEHOLDER ); + if( false === $pos ) { + throw new \Exception( 'missing header in template' ); + } + $pos += strlen( self::START_PLACEHOLDER ); + $content = substr( $content, $pos ); + + return rtrim( $content ); + } +} diff --git a/templates/CATEGORY_YEAR_CONTENT.template b/templates/CATEGORY_YEAR_CONTENT.template new file mode 100644 index 0000000..156fb00 --- /dev/null +++ b/templates/CATEGORY_YEAR_CONTENT.template @@ -0,0 +1,12 @@ + +This is the template for the content of a yearly category. + +Placeholdes: + %1$s: category title + %2$d: year + + +[[Categoria:Cancellazioni - 2018| 2018]] + + +[[%1$s| %2$d]] diff --git a/templates/CATEGORY_YEAR_SUMMARY.template b/templates/CATEGORY_YEAR_SUMMARY.template new file mode 100644 index 0000000..72bfef5 --- /dev/null +++ b/templates/CATEGORY_YEAR_SUMMARY.template @@ -0,0 +1,12 @@ + +This is the template for the summary of a yearly category. + +Placeholdes: + %1$s: category title + %2$d: year + + +Bot: creazione categoria annuale di servizio + + +Bot: creazione categoria annuale di servizio