phpBB

Development Wiki

User talk:Posey

From phpBB Development Wiki

Explanation
I personally find it hard to navigate through the Wiki, so I've listed my most used articles and written a few for my own personal reference..
Just found this gem: Area51 Docs: Developing Extensions

GitHub

How to use GitHub properly: Git
How to push from Desktop to Online:

git push 'online_repository_link' master -f

Template IF Statements

Here is a list of available IF Statements for template files: Template IF Statements

<!-- IF S_USER_LOGGED_IN --> // If user is logged in (still counts for bots)
<!-- IF S_IS_BOT --> // If user is a bot
<!-- IF S_REGISTERED_USER --> // If user is logged in and NOT a bot
<!-- IF EDIT_SELF --> // If user can edit own content (profile)
<!-- IF U_MCP --> // If user is moderator
<!-- IF U_ACP --> // If user is administrator

Events

Here is a list of all available phpBB Events (PHP, Template, ACP): Event List

# Event_List#PHP_Events_.28Hook_Locations.29
# Event_List#Template_Events
# Event_List#ACP_Template_Events

Standard services.yml and listener.php

Note that the order of the dependencies must be the same in the arguments-list in services.yml and in the __construct of the listener.php!
The passing of dependencies in this way replaces the need of using global $var in most cases.
Here you can find an example and all possibilities: Dependency_list

Tables

Here is a list of all available phpBB Tables: Tables

Adding your own Table

Author: acme
Extension: demo
Table: tablename

config/tables.yml

parameters:
   
acme.demo.tables.tablename: %core.table_prefix%tablename

config/services.yml

imports:
   - { 
resourcetables.yml }
services:
   
acme.demo.listener:
      class: 
acme\demo\event\main_listener
      arguments
:
         - %
acme.demo.tables.tablename%

event/main_listener.php

class main_listener implements EventSubscriberInterface
{
   
/** @var string */
   
protected $tablename_table;

   
/**
   * Constructor
   *
   * @param string        $tablename_table    Acme Demo Tablename
   */

   
public function __construct($tablename_table)
   {
      
$this->tablename_table   $tablename_table;
   }
   ...

migrations/your_migration_file.php

namespace acme\demo\migrations;

class 
your_migration_file extends \phpbb\db\migration\migration
{
   public function 
update_schema()
   {
      return array(
         
'add_tables'   => array(
            
$this->table_prefix 'tablename'   => array(
               
'COLUMNS'   => array(
                  
'column_one_id'    => array('UINT'NULL'auto_increment'),
                  
'column_two_txt'   => array('VCHAR:250'''),
               ),

               
'PRIMARY_KEY'   => 'column_one_id',
            ),
         ),
      );
   }

   public function 
revert_schema()
   {
      return array(
         
'drop_tables'   => array(
            
$this->table_prefix 'tablename',
         ),
      );
   }
}

Read more about: Umil.table_column_add - | - Or about the Database_Type_Map (VHCAR, UINT, etc..)

Custom Profile Fields

Adding profile field: pizza

migrations/profilefield_pizza.php

namespace acme\demo\migrations;

class 
profilefield_pizza extends \phpbb\db\migration\profilefield_base_migration
{
   public function 
update_data()
   {
      return array(
         array(
'custom', array(array($this'create_custom_field'))),
      );
   }

   protected 
$profilefield_name 'phpbb_pizza';
   protected 
$profilefield_database_type = array('VCHAR''');
   protected 
$profilefield_data = array(
      
'field_name'           => 'phpbb_pizza',
      
'field_type'           => 'profilefields.type.string',
      
'field_ident'          => 'phpbb_pizza',
      
'field_length'         => '40',
      
'field_minlen'         => '5',
      
'field_maxlen'         => '255',
      
'field_novalue'        => '',
      
'field_default_value'  => '',
      
'field_validation'     => '.*',
      
'field_required'       => 0,
      
'field_show_novalue'   => 0,
      
'field_show_on_reg'    => 0,
      
'field_show_on_pm'     => 1,
      
'field_show_on_vt'     => 1,
      
'field_show_on_ml'     => 0,
      
'field_show_profile'   => 1,
      
'field_hide'           => 0,
      
'field_no_view'        => 0,
      
'field_active'         => 1,
      
'field_is_contact'     => 1,
      
'field_contact_desc'   => '',
      
'field_contact_url'    => '',
   );
   protected 
$user_column_name 'user_pizza';
}

If you want to know all possibilities for the database_type, read here: Database_Type_Map

Template File

The custom profile field automatically shows up in the UCP and when filled in, in the places you've set it to show up in profilefield_pizza.php. If you want to use it in any other place in a template file:

<!-- BEGIN custom_fields -->
   <!-- IF 
custom_fields.FIELD_NAME eq 'PIZZA' -->{custom_fields.FIELD_NAME}{L_COLON} {custom_fields.FIELD_VALUE}<!-- ENDIF -->
<!-- 
END custom_fields -->

Standard CPF's

Here is a list of all standard Custom Profile Fields. So you can also check what form of validation each type uses..

field_idfield_namefield_typefield_identfield_validation
1phpbb_locationprofilefields.type.stringphpbb_location*
2phpbb_websiteprofilefields.type.urlphpbb_website
3phpbb_interestsprofilefields.type.textphpbb_interests*
4phpbb_occupationprofilefields.type.textphpbb_occupation*
5phpbb_aolprofilefields.type.stringphpbb_aol*
6phpbb_icqprofilefields.type.stringphpbb_icq[0-9]+
7phpbb_wlmprofilefields.type.stringphpbb_wlm*
8phpbb_yahooprofilefields.type.stringphpbb_yahoo*
9phpbb_facebookprofilefields.type.stringphpbb_facebook[\w.]+
10phpbb_twitterprofilefields.type.stringphpbb_twitter[\w_]+
11phpbb_skypeprofilefields.type.stringphpbb_skype[a-zA-Z][\w\.,\-_]+
12phpbb_youtubeprofilefields.type.stringphpbb_youtube[a-zA-Z][\w\,m\-_]+
13phpbb_googleplusprofilefields.type.stringphpbb_googelplus[\w]+

Parsing Text

If you want to insert and retrieve text from a database, and want to parse BBCode, Smilies, etc..
Here is the tutorial to read all about it: Tutorial.Parsing_text

Notifications

Everything about creating Notifications can be found here: Notifications Tutorial
Do note that all notification.type have to use acme.demo. infront in order to work.
List #2.1

public function get_type()
{
     return 
'acme.demo.notification.type.my_cool_notification';
}

List #3

$this->notification_manager->add_notifications(array(
      
'acme.demo.notification.type.my_cool_notification',
   ), 
$my_notification_data);

Permissions

Adding Permissions

Adding Permissions through migration file: Migrations/Tools/Permission
More information on it by VSE: (Dev-Change) Permissions

Checking Permissions

$this->auth->acl_get('u_view_portal'// Get one specific permission
$this->auth->acl_gets('a_''m_'// Get multiple permissions
$this->auth->acl_getf_global('m_'); // Get a forum global

Database Queries

Database_Abstraction_Layer

SQL Build Query (LEFT JOIN)

Dbal.sql_build_query

SQL Build Array

Dbal.sql_build_array

Functions

Here is a list of all documented functions: Functions Category
And here is a list of all Basic Functions: Using_phpBB3's_Basic_Functions

request_var

Now used instead of %_GET, $_POST, $_COOKIE and $_REQUEST (in most cases)
Used to get user input into php files.
You can read all about it here: Request_var

Standard

$something request_var('name-attr''')
name-attr: Name attribute of a field
'': Default value and type identifier

Submit

$submit = (isset($_POST['submit-name'])) ? true false// submit-name: Name attribute of the submit button

if($submit)
{
   
// Do something after submit
}

Submit Protection

When using users' input, it's important to check for CSRF: Wikipedia:Cross-site_request_forgery

Form Key

Add a form key to your form: Function.add_form_key
Check the form key: Function.check_form_key

$form_key 'MyFormName'// The name attribute of your form
add_form_key($form_key);

if (
check_form_key($form_keyfalse''true))
{
   
// Continue with your form processing..
}
else 
{
   
trigger_error($this->user->lang['FORM_INVALID']);
}

Confirm Box

$submit = (isset($_POST['submit-name'])) ? true false;

if (
$submit)
{
   if (
confirm_box(true))
   {
        
// Process your form here
           // Process some more ..
        // Show success message and redirect to a given url
        // In this case we redirect them to /memberlist.php?mode=team after 3 seconds of displaying {L_SUCCESS_SUBMIT}
        
$redirect_url append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}""mode=team");
        
$message $this->user->lang['SUCCESS_SUBMIT'] . '<br /><br />' sprintf($this->user->lang['RETURN_TO'], '<a href="' $redirect_url '">''</a>');
        
meta_refresh(3$redirect_url); // After showing the messing for 3 sec, auto redirects
        
trigger_error($message); // Shows message after successful 'Yes' confirmed
   
}
   else
   {
      
$s_hidden_fields build_hidden_fields(array(
           
'submit'    => true,      // All hidden fields needed to come to a successful 'confirm_box(true)'
           
'msg_id'    => $msg_id,   // eg. the submit button name attr and a hidden msg_id
      
));

      
confirm_box(false$this->user->['CONFIRM_SUBMIT'], $s_hidden_fields);
   }
}

Creating Modules

Creating_modules
Example Modules