Rhea Landing: The Conquest of Saturn


Rhea Landing: The Conquest of Saturn
nedka

nedka

21/12/2016 15:36
phpBB 3.2.0 will be launched officially on 07 Jan 2017 17:00 UTC. It's the time to update code changes for your extensions and styles, make them stable to use with the new branch. This article will help you to find out component changes between phpBB 3.1 and 3.2.

FOR STYLE DESIGNERS

The Twig Loop
If the Twig variable is a loop (array), the prefix loops. is required in 3.1. As of 3.2, this requirement has been removed, allowing you to use natural Twig syntax.

Old way:

Chép
{% for item in loops.items %}
	{{ item.NAME }}
{% endfor %}
New way:
Chép
{% for item in items %}
	{{ item.NAME }}
{% endfor %}
Use the old way in 3.2: OK

Including CSS Files
In 3.1, the template tag <!-- INCLUDECSS abc.css --> could only be used in the template event overall_header_head_append, or before this event is dispatched. As of 3.2, it can now be called from anywhere.

Font Awesome
phpBB 3.2 included the Font Awesome icons. It is used by the default style prosilver, as same as the ACP style. The benefit of the new beautiful icons is they make it easy to improve GUI elements of your extension.

FOR EXTENSION WRITERS

Notifications
This is the most importtant change in 3.2. phpBB 3.1 extensions that use the notification system will be broken by 3.2.

Get the list of users to receiver notifications (The method find_users_for_notification)
Old way:
Chép
public function find_users_for_notification($data, $options = array())
{
	$sql = 'SELECT user_id
		FROM ' . USERS_TABLE . '
		WHERE user_type <> ' . USER_IGNORE;
	$result = $this->db->sql_query($sql);

	$users = array();
	while ($row = $this->db->sql_fetchrow($result))
	{
		$users[$row['user_id']] = array('');
	}
	$this->db->sql_freeresult($result);

	return $users;
}
New way:
Chép
public function find_users_for_notification($data, $options = array())
{
	$sql = 'SELECT user_id
		FROM ' . USERS_TABLE . '
		WHERE user_type <> ' . USER_IGNORE;
	$result = $this->db->sql_query($sql);

	$users = array();
	while ($row = $this->db->sql_fetchrow($result))
	{
		$users[$row['user_id']] = $this->notification_manager->get_default_methods();
	}
	$this->db->sql_freeresult($result);

	return $users;
}
The difference between two code blocks above:
Chép
$users[$row['user_id']] = array('');
Chép
$users[$row['user_id']] = $this->notification_manager->get_default_methods();
In 3.1, the returned data array has its keys are user IDs (user_id). Each key has its value as an empty array (array('')). As of 3.2, we must specify the default method of receiving notifications for each user (via emails or direct notifications). The selected method is assigned as the child array value, make the difference between two phpBB branches.

Insert notification data to the database (The method create_insert_array)
Old way:
Chép
public function create_insert_array($data, $pre_create_data = array())
{
	// Your code go here...
	return parent::create_insert_array($data, $pre_create_data);
}
New way:
Chép
public function create_insert_array($data, $pre_create_data = array())
{
	// Your code go here...
	parent::create_insert_array($data, $pre_create_data);
}
In 3.1, this method returned a data array from the parent class. Otherwise, the data array in 3.2 is now added to the class property. So it is no longer necessary to use a return at the end.

Defining the notification type in YAML (./config/services.yml)
Old way:
Chép
services:
    vinabb.demo.notification.type.abc:
        class: vinabb\demo\notification\type\abc
        scope: prototype
New way:
Chép
services:
    vinabb.demo.notification.type.abc:
        class: vinabb\demo\notification\type\abc
        shared: false
In 3.1, we use scope: prototype. But since 3.2, we use shared: false by the requirement from the Symfony version of this phpBB branch.

Use the old way in 3.2: ERROR

Shared Services in Symfony
This change is same as defining the notification type in YAML above.

By default, all Symfony services are shared ones. This means a class is instantiated once, and used each time you ask for it from the service container. In some cases, however, it is desired to unshare a class, where a new instance is created each time you ask for the service. In 3.1, this was defined by setting the scope: prototype. For 3.2 with Symfony 2.8, scope: prototype is now deprecated and replaced by shared: false.

Use the old way in 3.2: ERROR

Class Names as Arguments in YAML
According to YAML specification, unquoted strings can not start with @, so you must wrap these arguments with single quotes. Do same as for the parameters that begin with %. @abc or %abc% without single quotes will be marked as errors as soon in later Symfony versions.

Old way:
Chép
services:
    vinabb.demo.abc:
        class: vinabb\demo\controller\abc
        arguments:
            - @cache.driver
            - %tables.notifications%
    calls:
        - [set_controller_helper, [@controller.helper]]
New way:
Chép
services:
    vinabb.demo.abc:
        class: vinabb\demo\controller\abc
        arguments:
            - '@cache.driver'
            - '%tables.notifications%'
    calls:
        - [set_controller_helper, ['@controller.helper']]
Use the old way in 3.2: OK

Language
3.2 comes with a new class, language, is now independent from the class user. We use this class for language actions as: adding language files, force the language to display, get the language strings...

Adding language files from the core
Old way:
Chép
$this->user->add_lang('posting');
New way:
Chép
$this->language->add_lang('posting');
Adding language files from the extension
Old way:
Chép
$this->user->add_lang_ext('vinabb/demo', 'posting');
New way:
Chép
$this->language->add_lang('posting', 'vinabb/demo');
Set the user language to display
Old way: (set before the language class is loaded)
Chép
$this->user->data['user_lang'] = 'vi';
New way:
Chép
$this->language->set_user_language('vi');
Set the system language to display
Old way: (set before the language class is loaded)
Chép
$this->config['default_lang'] = 'vi';
New way:
Chép
$this->language->set_default_language('vi');
Get the language string
Old way:
Chép
$this->user->lang['ABC'];
$this->user->lang('ABC', 123);
New way:
Chép
$this->language->lang('ABC');
$this->language->lang('ABC', 123);
Check for existing language variables
Old way:
Chép
if (isset($this->user->lang['ABC']))
New way:
Chép
if ($this->language->is_set('ABC'))
Use the old way in 3.2: OK

New BBCode Engine
In 3.1, BBCode text is stored as HTML, with BBCode tags being replaced at rendering time. As of 3.2, with the new s9e Text Formattter, BBCode text is stored as XML and transformed into HTML at rendering time. All BBCode functions will continue to work as they did in 3.1. BBCode text stored in the old HTML format will still display as normal, even before being converted to the new XML format, via the edit-save actions.

However, you should update stored BBCode text to the new XML format to avoid unexpected problems.
Chép
$parser = $this->container->get('text_formatter.parser')->get_parser();
$text_formatter_utils = $this->container->get('text_formatter.utils');
$text = 'stored BBCode text as HTML';

// Unparse text back to its original form
$text = $text_formatter_utils->unparse($text);

// Transforme into XML
$text = $parser->parse($text);
Group Name
Old way:
Chép
$name = ($row['group_type'] == GROUP_SPECIAL) ? $this->user->lang['G_' . $row['group_name']] : $row['group_name'];
New way:
Chép
$name = $this->group_helper->get_name($row['group_name']);
Use the old way in 3.2: OK

PHP Arrays
Since PHP 5.4, short array syntax has been added, e.g. $array = [];. Because the minimum PHP version of phpBB 3.1 is 5.3.3, we must the old way $array = array(); to keep the compatibility. The minimum PHP version in phpBB 3.2 is bumped to 5.4, and now we can use any of two ways above. Old or new way is not important, it is your favour.

Use the old way in 3.2: Được

Database Management Systems
And also because PHP 5.4, both the support for SQLite 2.8.x and the PHP MSSQL extension have been dropped. When you call the method $this->db->get_sql_layer() to determine the DBMS, there are 2 values are no longer exist: mssql and sqlite.

Old values:
Chép
mssql -> SQL Server 2000
mssql_odbc -> SQL Server 2000 (ODBC)
mssqlnative -> SQL Server 2005+
mysql -> MySQL
mysqli -> MySQLi
oracle -> Oracle
postgres -> PostgreSQL
sqlite -> SQLite 2.8.2 - 3.6.14
sqlite3 -> SQLite 3.6.15+
New values:
Chép
mssql_odbc -> SQL Server 2000 (ODBC)
mssqlnative -> SQL Server 2005+
mysql -> MySQL
mysqli -> MySQLi
oracle -> Oracle
postgres -> PostgreSQL
sqlite3 -> SQLite 3.6.15+
Filesystem
phpBB 3.2 has a new class filesystem for directory and file actions.

Uploading files
phpBB 3.2 introduces two new classes for uploading files: filespec and upload. Below is an example code to upload an image file to the server.
Chép
// Name of the input tag in HTML code, e.g. <input type="file" name="test_image">
protected $form_name = 'test_image';

// The destination directory to store uploaded files
protected $path;

// Collection of errors
protected $errors = [];

public function upload_file()
{
	// Set the file extensions
	$this->upload->set_allowed_extensions(['gif', 'jpg', 'jpeg', 'png', 'svg'])
		->set_disallowed_content((isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false));

	// The upload file is selected?
	$form_name = $this->request->file($this->form_name);

	if ($form_name['name'] == '')
	{
		return false;
	}

	// Handle upload
	$file = $this->upload->handle_upload('files.types.form', $this->form_name);

	// If there was an error during move, then clean up leftovers
	if (sizeof($file->error))
	{
		$file->remove();
		$this->errors = array_merge($this->errors, $file->error);

		return false;
	}

	// Move file and overwrite any existing image
	if (!sizeof($this->errors))
	{
		$file->move_file($this->path, true);
	}

	// Return the result filename
	return $file->get('realname');
}
Use the old way in 3.2: ERROR

SUMMARY
We introduced you to 3 changes in style design and 7 component changes in extension development. You are ready to bring the new phpBB branch to your works. Go go Rhea, conquer Saturn, dear astronauts!

Reference: https://area51.phpbb.com/docs/dev/32x/e ... _rhea.html


VinaBB

Quan điểm

  • Không đề cập chính trị, tôn giáo, nội dung đồi trụy.
  • Giữ gìn sự trong sáng của Tiếng Việt.
  • Không chia sẻ phần mềm vi phạm bản quyền.
  • Không rao vặt và không nhận đặt quảng cáo.
  • Dù trong túi hết tiền thì diễn đàn phpBB của anh cũng phải ngay ngắn.

Chuyện tình VinaBB

17/07/2004: Yêu phpBB từ phiên bản 2.0.10.
22/10/2006: Cất tiếng cười chào đời.
11/06/2007: Chính thức định cư trên Olympus, Sao Hỏa.
11/06/2009: Mất liên lạc với Trái Đất. [ Phiên bản 2007 ]
28/07/2016: Trôi dạt đến mặt trăng Rhea, Sao Thổ.
12/12/2016: Cuộc hành trình mới lại bắt đầu…

Code in Viet Nam

Cống hiến hết mình vì Tổ Quốc Việt Nam Xã Hội Chủ Nghĩa

Quản trị viên

nedka

VinaBB

NEDKA Solutions

Đơn vị chủ quản

Chúng tôi chịu trách nhiệm toàn bộ nội dung có trên VinaBB.vn trước pháp luật.