|
Server IP : 10.2.73.233 / Your IP : 216.73.216.223 Web Server : Apache/2.4.59 (Debian) System : Linux polon 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64 User : www-data ( 33) PHP Version : 5.6.40-64+0~20230107.71+debian10~1.gbp673146 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/ifk/web/assets/../prado4.3.2/Util/Behaviors/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
/**
* TPageGlobalizationCharsetBehavior class file.
*
* @author Brad Anderson <belisoful@icloud.com>
* @link https://github.com/pradosoft/prado
* @license https://github.com/pradosoft/prado/blob/master/LICENSE
*/
namespace Prado\Util\Behaviors;
use Prado\Prado;
use Prado\TPropertyValue;
use Prado\Web\UI\WebControls\TMetaTag;
/**
* TPageGlobalizationCharsetBehavior class.
*
* TPageGlobalizationCharsetBehavior attaches to pages and adds charset
* meta to the head from globalization. If there is no globalization,
* the default charset is used, 'utf-8'.
* @author Brad Anderson <belisoful@icloud.com>
* @since 4.2.0
*/
class TPageGlobalizationCharsetBehavior extends \Prado\Util\TBehavior
{
/** @var bool check the existing meta tags for the charset before adding it */
private $_checkMetaCharset = false;
/**
* This handles the TPage.OnInitComplete event to place no-cache
* meta in the head.
* @return array of events as keys and methods as values
*/
public function events()
{
return ['OnInitComplete' => 'addCharsetMeta'];
}
/**
* This method places no-cache meta in the head.
* @param object $page object raising the event
* @param mixed $param the parameter of the raised event
*/
public function addCharsetMeta($page, $param)
{
if ($head = $page->getHead()) {
$hasCharset = false;
$metatags = $head->getMetaTags();
if ($this->_checkMetaCharset) {
foreach ($metatags as $meta) {
if (empty($meta->getHttpEquiv()) && empty($meta->getContent()) && empty($meta->getName()) && empty($meta->getScheme()) && !empty($meta->getCharset())) {
$hasCharset = true;
}
}
}
if (!$hasCharset) {
$charset = 'utf-8';
if ($globalization = Prado::getApplication()->getGlobalization()) {
$charset = $globalization->getCharset();
}
$meta = new TMetaTag();
$meta->setCharset($charset);
$metatags->add($meta);
}
}
}
/**
* @return bool checks existing meta tags for no cache
*/
public function getCheckMetaCharset()
{
return $this->_checkMetaCharset;
}
/**
* @param bool $value checks existing meta tags for no cache
*/
public function setCheckMetaCharset($value)
{
$this->_checkMetaCharset = TPropertyValue::ensureBoolean($value);
}
}