Advertisement
LostKobrakai

Untitled

Feb 11th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * ProcessWire Entities Textformatter
  5.  *
  6.  * Formats text with PHP's htmlspecialchars() function.
  7.  *
  8.  * ProcessWire 2.x
  9.  * Copyright (C) 2010 by Ryan Cramer
  10.  * Licensed under GNU/GPL v2, see LICENSE.TXT
  11.  *
  12.  * http://www.processwire.com
  13.  * http://www.ryancramer.com
  14.  *
  15.  */
  16.  
  17. class TextformatterCoworker extends Textformatter {
  18.  
  19.     public static function getModuleInfo() {
  20.         return array(
  21.             'title' => __('Coworker', __FILE__), // Module Title
  22.             'summary' => __("Formats - Max Mustermann <max.mustermann@xxx.de> - into an array with name and email property.", __FILE__), // Module Summary
  23.             'version' => 100,
  24.         );
  25.     }
  26.  
  27.     public function format(&$str) {
  28.         $str = trim($str);
  29.         $name = trim(substr($str, 0, strpos($str, "<")));
  30.         $email = trim(substr($str, strpos($str, "<"), strlen($str) - 2), " \t\n\r\0\x0B<>");
  31.  
  32.         static $charset = false;
  33.         if($charset === false) $charset = $this->config->dbCharset;
  34.         if($charset == 'utf8'){
  35.             $name = htmlspecialchars($name, ENT_QUOTES, "UTF-8");
  36.             $email = htmlspecialchars($email, ENT_QUOTES, "UTF-8");
  37.         }else{
  38.             $name = htmlspecialchars($name, ENT_QUOTES);
  39.             $email = htmlspecialchars($email, ENT_QUOTES);
  40.         }
  41.  
  42.         $str = array(
  43.             "name" => $name,
  44.             "email" => $email
  45.         );
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement