/** * ExpressionEngine - by EllisLab * * @package ExpressionEngine * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2003 - 2011, EllisLab, Inc. * @license http://expressionengine.com/user_guide/license.html * @link http://expressionengine.com * @since Version 2.0 * @filesource */ // ------------------------------------------------------------------------
system/expressionengine/third_party/member_info/ system/expressionengine/third_party/member_info/pi.member_info.php
class Member_info {
$plugin_info = array( 'pi_name' => 'Member_info', 'pi_version' => '1.0', 'pi_author' => 'Isaac Raway', 'pi_author_url' => '', 'pi_description' => 'Gets member information for the supplied ID', 'pi_usage' => Member_info::usage(), );
class Member_info { public function __construct() { $this->EE =& get_instance(); } public static function usage() { // pkg.io uses ob_start, HEREDOC does the same thing, but it's shorter: return <<<END How to call this plugin: {exp:member_info:query member_id="something"} {/exp:member_info:query} END; } }
$plugin_info = array( ... 'pi_usage' => Member_info::usage(), );
And now the most important bullet point in the presentation:
public function query() { }
{exp:member_info:query} {/exp:member_info:query}
public function query() { // 1. Get params from fetch_param() - default value is FALSE // 2. Get the contents of the pair tag // 3. Setup a default response // 4. Run our query // 5. Parse results variables into the output // 6. Return the results as a string }
// 1. Get params from fetch_param() $requested_member_id = $this->EE->TMPL->fetch_param("member_id");
$test = $this->EE->TMPL->fetch_param("test", -1);
// 2. Get the contents of the pair tag $result = $this->EE->TMPL->tagdata;
{exp:member_info:query} This is the part that comes back in tagdata. {/exp:member_info:query}
// 3. Setup a default response $vars = array( 'found' => FALSE );
{exp:member_info:query} {if found} ... {if:else} No results found for that ID! {/if} {/exp:member_info:query}
// 4. Run our query if($requested_member_id) { $query = $this->EE->db->where('member_id', $requested_member_id) ->get('members');
// Check that we have at least one row if($query->num_rows() > 0) { // Replace the default return vars array // with the result row $vars = $query->row_array(); $vars['found'] = TRUE; }
// Check if request is for their own data, // if not we can provide less info: $vars['is_current_user'] = ( $requested_member_id == $this->EE->session->member_id ); }
// 5. Parse results variables into the output $result = $this->EE->TMPL->parse_variables($result, array($row));
// 6. Return the results as a string return $result;
{exp:member_info:query member_id="{segment_3}"} {if found} Screen Name: {screen_name}<br/> {if is_current_user} Registered Email Address: {email}<br/> Username: {username}<br/> <a href="{site_url}account/edit/{segment_3}">Edit</a> {/if} {if:else} Invalid request. {/if} {/exp:member_info:query}