Permalink
Browse files

Добавлен плагин check_pda

  • Loading branch information...
stdex committed Feb 23, 2017
1 parent 4790fdd commit 8363700267ae564a876418855d13c9debc00d805
Showing with 1,593 additions and 0 deletions.
  1. +100 −0 check_pda/MobileDetect.php
  2. +13 −0 check_pda/check_pda.php
  3. +1,458 −0 check_pda/lib/Mobile_Detect.php
  4. +12 −0 check_pda/readme
  5. +10 −0 check_pda/version
View
@@ -0,0 +1,100 @@
<?php
require_once 'lib/Mobile_Detect.php';
class Twig_Extension_MobileDetect extends Twig_Extension
{
protected $detector;
/**
* Constructor
*/
public function __construct()
{
$this->detector = new Mobile_Detect();
}
/**
* Twig functions
*
* @return array
*/
public function getFunctions()
{
$functions = array(
'get_available_devices' => new Twig_Function_Method($this, 'getAvailableDevices'),
'is_mobile' => new Twig_Function_Method($this, 'isMobile'),
'is_tablet' => new Twig_Function_Method($this, 'isTablet'),
);
foreach ($this->getAvailableDevices() as $device => $fixedName) {
$methodName = 'is'.$device;
$twigFunctionName = 'is_'.$fixedName;
$functions[$twigFunctionName] = new Twig_Function_Method($this, 'is'.$methodName);
}
return $functions;
}
/**
* Returns an array of all available devices
*
* @return array
*/
public function getAvailableDevices()
{
$availableDevices = array();
$rules = array_change_key_case($this->detector->getRules());
foreach ($rules as $device => $rule) {
$availableDevices[$device] = static::fromCamelCase($device);
}
return $availableDevices;
}
/**
* Pass through calls of undefined methods to the mobile detect library
*
* @param $name
* @param $arguments
* @return mixed
*/
public function __call($name, $arguments)
{
return call_user_func_array(array($this->detector, $name), $arguments);
}
/**
* Converts a string to camel case
*
* @param $string
* @return mixed
*/
protected static function toCamelCase($string)
{
return preg_replace('~\s+~', '', lcfirst(ucwords(strtr($string, '_', ' '))));
}
/**
* Converts a string from camel case
*
* @param $string
* @param string $separator
* @return string
*/
protected static function fromCamelCase($string, $separator = '_')
{
return strtolower(preg_replace('/(?!^)[[:upper:]]+/', $separator.'$0', $string));
}
/**
* The extension name
*
* @return string
*/
public function getName()
{
return 'mobile_detect.twig.extension';
}
}
View
@@ -0,0 +1,13 @@
<?php
// Protect against hack attempts
if (!defined('NGCMS')) die ('HAL');
add_act('core', 'check_pda');
function check_pda() {
global $twig;
require_once 'MobileDetect.php';
$twig->addExtension(new Twig_Extension_MobileDetect());
}
Oops, something went wrong.

0 comments on commit 8363700

Please sign in to comment.