Skip to content

Instantly share code, notes, and snippets.

@rsanchez
Created September 6, 2011 18:46
Show Gist options
  • Save rsanchez/1198583 to your computer and use it in GitHub Desktop.
Save rsanchez/1198583 to your computer and use it in GitHub Desktop.
cp_js_end referer
<?php
class My_ext {
/* blah blah blah */
public function cp_js_end()
{
//be courteous to other users of this hook
$str = $this->EE->extensions->last_call;
$this->EE->load->helper('array');
//we need to look at the referring page, this script is loaded in it's own request
parse_str(parse_url(@$_SERVER['HTTP_REFERER'], PHP_URL_QUERY), $get);
$controller = element('C', $get);
$method = element('M', $get);
if ($controller === 'content_publish' && $method === 'entry_form')
{
//bingo! we're on the publish page
$str .= '
$(document).ready(function(){
//EMBIGGEN MY TITLE!
$("input[name=title]").css("font-size", "80px");
});
';
}
return $str;
}
}
@rsanchez
Copy link
Author

rsanchez commented Mar 8, 2012

The script that is created using cp_js_end is loaded externally, which means that

<?php
if ($this->EE->input->get('C') === 'content_publish')

will not work as you might expect. You've got to look back to the referring page's query string to ascertain which CP page is currently loaded.

@siebird
Copy link

siebird commented Mar 8, 2012

Missing a semi-colon after $method = element('M', $get) - was getting a white screen and just figured that out!

@alexmglover
Copy link

Beautiful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment