The Beast Within

A look inside EE's source code

Rob Sanchez
EECI 2011
October 21, 2011

Hi.

A good composer does not imitate; he steals.
Igor Stravinsky

Why is knowing the source important?

What is EE, really?

Let's look at a page load

File Structure

Template Tags

{exp:channel:entries channel="users"
  search:cf_username="{username}"}

  {if no_results}Why?!?{/if}
  {title}

{/exp:channel:entries}

system/expressionengine/modules/
channel/mod.channel.php
, entries function

Template Tags

class Channel
{
  function entries()
  {
    var_dump($this->EE->TMPL->tagparams);

...

Template Tags

Error Messages

Example: "Disallowed Key Characters."

http://ee2.local/index.php/site/index/?st.louis,mo=true

Error Messages

Example: "Disallowed Key Characters."

Take a deep breath, open favorite text editor, do a folder search for the offending error message.

system/codeigniter/system/core/Input.php, line 552

function _clean_input_keys($str)
{
    if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
    {
        exit('Disallowed Key Characters.');
    }

...

Error Messages

Example: "Disallowed Key Characters."

function _clean_input_keys($str)
{
    if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
    {
        var_dump($str);
        exit('Disallowed Key Characters.');
    }

...

Error Messages

Example: "Disallowed Key Characters."

Error Messages

Example: "You are not authorized to access this page"

http://ee2.local/admin.php?S=0&D=cp&C=content_edit&M=delete_entries

Error Messages

Example: "You are not authorized to access this page"

Searching for that error message turned up:

system/expressionengine/language/english/cp_lang.php, line 275

'unauthorized_access' => 
'You are not authorized to access this page',

Searching for unauthorized_access turns up 385 occurrences. Yikes. Let's narrow that down.

http://ee2.local/admin.php?S=0&D=cp&C=content_edit&M=delete_entries

system/expressionengine/controllers/cp/content_edit.php.

Error Messages

Example: "You are not authorized to access this page"

public function delete_entries()
{
    if ( ! $this->cp->allowed_group('can_access_content'))
    {
        show_error(lang('unauthorized_access'));
    }

    if ( ! $this->cp->allowed_group('can_delete_self_entries') AND
         ! $this->cp->allowed_group('can_delete_all_entries'))
    {
        show_error(lang('unauthorized_access'));
    }

Error Messages

Example: "You are not authorized to access this page"

public function delete_entries()
{
    if ( ! $this->cp->allowed_group('can_access_content'))
    {
        show_error(lang('unauthorized_access').' 1st');
    }

    if ( ! $this->cp->allowed_group('can_delete_self_entries') AND
         ! $this->cp->allowed_group('can_delete_all_entries'))
    {
        show_error(lang('unauthorized_access').' 2nd');
    }

Error Messages

Example: "You are not authorized to access this page"

Now we know it's related to can_delete_all_entries or can_delete_self_entries

Libraries

Found in system/codeigniter/system/core, system/expressionengine/libraries and system/codeigniter/system/libraries

Libraries

Models

$this->EE->load->model('member_model');
There are <?php echo $this->EE->member_model->get_member_count(5); ?>
in the Members group.

Final Thoughts

Thank you!

robsanchez.com/eeci_2011/slides