Created
November 24, 2011 13:25
-
-
Save pnegri/1391343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class mobile_detector_controller | |
{ | |
function classico($params) { | |
global $build_page_cache,$expiration_date; // Acessar globais de geração de Cache | |
// Desabilitar cache para url | |
$build_page_cache = false; $expiration_date = 0; | |
// Setar Cookie 'ignorarMobile' com valor 1 | |
web::cookie_set_variable('ignorarMobile',1,time()+(60*60*24*365)); | |
// Redirecionar para URL padrão | |
redirect_to( web::document_url() ); | |
} | |
function mobile($params) { | |
global $build_page_cache,$expiration_date; // Acessar globais de geração de Cache | |
// Desabilitar cache para url | |
$build_page_cache = false; $expiration_date = 0; | |
// Setar Cookie 'ignorarMobile' com valor 0 | |
web::cookie_set_variable('ignorarMobile',0,time()+(60*60*24*365)); | |
// Redirecionar para URL padrão + Endereço do Mobile | |
redirect_to( web::document_url() + '/m' ); | |
} | |
function before_head() | |
{ | |
if (web::document_requested() != '/') return; // Só adicionar ao <head> se for a capa | |
$html = <<<ENDOFHTML | |
__VLAMIR_COLOCAR_O_JAVA_SCRIPT_QUE_DETECTA_AQUI_DENTRO | |
ENDOFHTML; | |
return $html; | |
} | |
} | |
// Configurar permissão deste componente para pública | |
component::set_default_permission('mobile_detector_controller','public'); | |
// Registrar o componente com a string "mobile_detector_controller", criar o objeto mobile_detector_controller | |
component::register('mobile_detector_controller', new mobile_detector_controller()); | |
controller::register('/admin/configurar-modo-classico', 'mobile_detector_controller', 'classico' ); | |
controller::register('/admin/configurar-modo-mobile', 'mobile_detector_controller', 'mobile' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment