index.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Blocks; |
| 4 | |
| 5 | use Kubio\Core\Blocks\BlockBase; |
| 6 | use Kubio\Core\Registry; |
| 7 | |
| 8 | class CopyrightBlock extends BlockBase { |
| 9 | |
| 10 | const CONTAINER = 'container'; |
| 11 | const OUTER = 'outer'; |
| 12 | |
| 13 | public function mapPropsToElements() { |
| 14 | |
| 15 | $template = $this->getTemplateValue(); |
| 16 | return array( |
| 17 | self::OUTER => array( 'innerHTML' => $this->render_template( $template ) ), |
| 18 | ); |
| 19 | } |
| 20 | |
| 21 | function getTemplateValue() { |
| 22 | $template = $this->getBlockInnerHtml(); |
| 23 | return $template; |
| 24 | } |
| 25 | |
| 26 | function render_template( $content = '' ) { |
| 27 | $default = '© {year} {site-name}.'; |
| 28 | $msg = $content ? $content : $default; |
| 29 | |
| 30 | // replace placeholders with actual values |
| 31 | $msg = str_replace( '{year}', gmdate( 'Y' ), $msg ); |
| 32 | $msg = str_replace( '{site-name}', get_bloginfo( 'name' ), $msg ); |
| 33 | |
| 34 | // sanitize the message to allow only post like content |
| 35 | $msg = wp_kses_post( $msg ); |
| 36 | |
| 37 | $msg = sprintf( '<p>%s</p>', $msg ); |
| 38 | return html_entity_decode( $msg ); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | Registry::registerBlock( |
| 43 | __DIR__, |
| 44 | CopyrightBlock::class |
| 45 | ); |
| 46 |