Created
April 12, 2013 08:53
-
-
Save real34/5370618 to your computer and use it in GitHub Desktop.
CakePHP 2.x helper to include in your Controllers to automatically inject Bugherd script in your layouts
This file contains hidden or 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
<?php | |
App::uses('Helper', 'View/Helper'); | |
App::uses('File', 'Utility'); | |
class BugherdHelper extends Helper { | |
public $helpers = array(); | |
private $__bugherdBlacklistedLayouts = array('ajax', 'admin_popup'); | |
private $__bugherdKey = 'TODO: Fill me with your project key'; | |
public function beforeLayout($layoutFile) { | |
parent::beforeLayout($layoutFile); | |
if ($this->__acceptBugherdScript($layoutFile)) { | |
$this->__injectBugherdScript($this->_View); | |
} | |
} | |
private function __acceptBugherdScript($layoutFile) { | |
$layoutName = $this->__filenameWithoutExtension($layoutFile); | |
return !in_array($layoutName, $this->__bugherdBlacklistedLayouts); | |
} | |
private function __injectBugherdScript(View $View) { | |
$bugherdScript = <<<JS | |
<script type='text/javascript'> | |
var BugHerdConfig = { | |
feedback: { | |
tab_text: "Nous transmettre un feedback", | |
option_title_text: "Choisir une option", | |
option_pin_text: "J'ai une suggestion concernant une partie spécifique de cette page.", | |
option_site_text: "J'ai une suggestion concernant cette page ou le site dans son ensemble.", | |
feedback_entry_placeholder: "écrire un commentaire ou décrire le problème", | |
feedback_email_placeholder: "votre adresse email", | |
feedback_submit_text: "envoyer la suggestion", | |
confirm_success_text: "Votre suggestion a été envoyée.", | |
confirm_loading_text: "Envoi de la suggestion en cours.", | |
confirm_close_text: "fermer", | |
confirm_error_text: "L'envoi de la suggestion a échoué.", | |
confirm_retry_text: "Veuillez réessayer", | |
confirm_extension_text: "Saviez-vous que vous vous pouvez joindre une capture d'écran à votre rapport de bug ?", | |
confirm_extension_link_text: "Découvrez comment.", | |
} | |
}; | |
(function (d, t) { | |
var bh = d.createElement(t), s = d.getElementsByTagName(t)[0]; | |
bh.type = 'text/javascript'; | |
bh.src = '//www.bugherd.com/sidebarv2.js?apikey={$this->__bugherdKey}'; | |
s.parentNode.insertBefore(bh, s); | |
})(document, 'script'); | |
</script> | |
JS; | |
$View->append('script', $bugherdScript); | |
} | |
private function __filenameWithoutExtension($path) { | |
$File = new File($path); | |
return ($File === false) ? '' : $File->name(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment