Completed
Pull Request — master (#25)
by Erwan
04:33
created
search/fulltext_directory.php 2 patches
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -9,103 +9,103 @@
 block discarded – undo
9 9
 
10 10
 class fulltext_directory
11 11
 {
12
-    /** @var \phpbb\db\driver\driver_interface */
13
-    protected $db;
14
-
15
-    /**
16
-     * Constructor.
17
-     *
18
-     * @param \phpbb\db\driver\driver_interface $db
19
-     */
20
-    public function __construct(\phpbb\db\driver\driver_interface $db)
21
-    {
22
-        $this->db = $db;
23
-    }
24
-
25
-    /**
26
-     * Performs a search on keywords depending on display specific params. You have to run split_keywords() first.
27
-     *
28
-     * @param array  $keywords_ary contains each words to search
29
-     * @param string $fields       contains either titleonly (link titles should be searched), desconly (only description bodies should be searched)
30
-     * @param string $terms        is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)
31
-     * @param array  $sort_by_sql  contains SQL code for the ORDER BY part of a query
32
-     * @param string $sort_key     is the key of $sort_by_sql for the selected sorting
33
-     * @param string $sort_dir     is either a or d representing ASC and DESC
34
-     * @param string $sort_days    specifies the maximum amount of days a post may be old
35
-     * @param array  $ex_cid_ary   specifies an array of category ids which should not be searched
36
-     * @param int    $cat_id       is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
37
-     * @param array  &$id_ary      passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
38
-     * @param int    $start        indicates the first index of the page
39
-     * @param int    $per_page     number of ids each page is supposed to contain
40
-     *
41
-     * @return int total number of results
42
-     */
43
-    public function keyword_search($keywords_ary, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_cid_ary, $cat_id, &$id_ary, $start, $per_page)
44
-    {
45
-        $matches = [];
46
-
47
-        switch ($fields) {
48
-            case 'titleonly':
49
-                $matches[] = 'l.link_name';
50
-            break;
51
-
52
-            case 'desconly':
53
-                $matches[] = 'l.link_description';
54
-            break;
55
-
56
-            default:
57
-                $matches = ['l.link_name', 'l.link_description'];
58
-        }
59
-
60
-        $search_query = '';
61
-
62
-        foreach ($keywords_ary as $word) {
63
-            $match_search_query = '';
64
-            foreach ($matches as $match) {
65
-                $match_search_query .= (($match_search_query) ? ' OR ' : '').'LOWER('.$match.') ';
66
-                $match_search_query .= $this->db->sql_like_expression(str_replace('*', $this->db->get_any_char(), $this->db->get_any_char().strtolower($word).$this->db->get_any_char()));
67
-            }
68
-            $search_query .= ((!$search_query) ? '' : (($terms == 'all') ? ' AND ' : ' OR ')).'('.$match_search_query.')';
69
-        }
70
-        $direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
71
-
72
-        if (is_array($sort_by_sql[$sort_key])) {
73
-            $sql_sort_order = implode(' '.$direction.', ', $sort_by_sql[$sort_key]).' '.$direction;
74
-        } else {
75
-            $sql_sort_order = $sort_by_sql[$sort_key].' '.$direction;
76
-        }
77
-
78
-        $sql_array = [
79
-            'SELECT'      => 'l.link_id',
80
-            'FROM'        => [
81
-                    DIR_LINK_TABLE    => 'l', ],
82
-            'WHERE'        => 'l.link_active = 1
12
+	/** @var \phpbb\db\driver\driver_interface */
13
+	protected $db;
14
+
15
+	/**
16
+	 * Constructor.
17
+	 *
18
+	 * @param \phpbb\db\driver\driver_interface $db
19
+	 */
20
+	public function __construct(\phpbb\db\driver\driver_interface $db)
21
+	{
22
+		$this->db = $db;
23
+	}
24
+
25
+	/**
26
+	 * Performs a search on keywords depending on display specific params. You have to run split_keywords() first.
27
+	 *
28
+	 * @param array  $keywords_ary contains each words to search
29
+	 * @param string $fields       contains either titleonly (link titles should be searched), desconly (only description bodies should be searched)
30
+	 * @param string $terms        is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)
31
+	 * @param array  $sort_by_sql  contains SQL code for the ORDER BY part of a query
32
+	 * @param string $sort_key     is the key of $sort_by_sql for the selected sorting
33
+	 * @param string $sort_dir     is either a or d representing ASC and DESC
34
+	 * @param string $sort_days    specifies the maximum amount of days a post may be old
35
+	 * @param array  $ex_cid_ary   specifies an array of category ids which should not be searched
36
+	 * @param int    $cat_id       is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
37
+	 * @param array  &$id_ary      passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
38
+	 * @param int    $start        indicates the first index of the page
39
+	 * @param int    $per_page     number of ids each page is supposed to contain
40
+	 *
41
+	 * @return int total number of results
42
+	 */
43
+	public function keyword_search($keywords_ary, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_cid_ary, $cat_id, &$id_ary, $start, $per_page)
44
+	{
45
+		$matches = [];
46
+
47
+		switch ($fields) {
48
+			case 'titleonly':
49
+				$matches[] = 'l.link_name';
50
+			break;
51
+
52
+			case 'desconly':
53
+				$matches[] = 'l.link_description';
54
+			break;
55
+
56
+			default:
57
+				$matches = ['l.link_name', 'l.link_description'];
58
+		}
59
+
60
+		$search_query = '';
61
+
62
+		foreach ($keywords_ary as $word) {
63
+			$match_search_query = '';
64
+			foreach ($matches as $match) {
65
+				$match_search_query .= (($match_search_query) ? ' OR ' : '').'LOWER('.$match.') ';
66
+				$match_search_query .= $this->db->sql_like_expression(str_replace('*', $this->db->get_any_char(), $this->db->get_any_char().strtolower($word).$this->db->get_any_char()));
67
+			}
68
+			$search_query .= ((!$search_query) ? '' : (($terms == 'all') ? ' AND ' : ' OR ')).'('.$match_search_query.')';
69
+		}
70
+		$direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
71
+
72
+		if (is_array($sort_by_sql[$sort_key])) {
73
+			$sql_sort_order = implode(' '.$direction.', ', $sort_by_sql[$sort_key]).' '.$direction;
74
+		} else {
75
+			$sql_sort_order = $sort_by_sql[$sort_key].' '.$direction;
76
+		}
77
+
78
+		$sql_array = [
79
+			'SELECT'      => 'l.link_id',
80
+			'FROM'        => [
81
+					DIR_LINK_TABLE    => 'l', ],
82
+			'WHERE'        => 'l.link_active = 1
83 83
 				'.(($search_query) ? 'AND ('.$search_query.')' : '').'
84 84
 				'.(count($ex_cid_ary) ? ' AND '.$this->db->sql_in_set('l.link_cat', $ex_cid_ary, true) : '').'
85 85
 				'.(($cat_id) ? ' AND '.$this->db->sql_in_set('l.link_cat', $cat_id) : '').'
86 86
 				'.(($sort_days) ? ' AND l.link_time >= '.(time() - ($sort_days * 86400)) : ''),
87
-            'ORDER_BY'    => $sql_sort_order,
88
-        ];
87
+			'ORDER_BY'    => $sql_sort_order,
88
+		];
89 89
 
90
-        if ($sql_sort_order[0] == 'u') {
91
-            $sql_array['LEFT_JOIN'][] = [
92
-                'FROM'    => [USERS_TABLE => 'u'],
93
-                'ON'      => 'u.user_id = l.link_user_id',
94
-            ];
95
-        }
90
+		if ($sql_sort_order[0] == 'u') {
91
+			$sql_array['LEFT_JOIN'][] = [
92
+				'FROM'    => [USERS_TABLE => 'u'],
93
+				'ON'      => 'u.user_id = l.link_user_id',
94
+			];
95
+		}
96 96
 
97
-        $sql = $this->db->sql_build_query('SELECT', $sql_array);
98
-        $result = $this->db->sql_query($sql);
99
-        while ($row = $this->db->sql_fetchrow($result)) {
100
-            $id_ary[] = $row['link_id'];
101
-        }
97
+		$sql = $this->db->sql_build_query('SELECT', $sql_array);
98
+		$result = $this->db->sql_query($sql);
99
+		while ($row = $this->db->sql_fetchrow($result)) {
100
+			$id_ary[] = $row['link_id'];
101
+		}
102 102
 
103
-        $this->db->sql_freeresult($result);
103
+		$this->db->sql_freeresult($result);
104 104
 
105
-        $total_match_count = count($id_ary);
105
+		$total_match_count = count($id_ary);
106 106
 
107
-        $id_ary = array_slice($id_ary, $start, (int) $per_page);
107
+		$id_ary = array_slice($id_ary, $start, (int) $per_page);
108 108
 
109
-        return $total_match_count;
110
-    }
109
+		return $total_match_count;
110
+	}
111 111
 }
Please login to merge, or discard this patch.
Braces   +15 added lines, -7 removed lines patch added patch discarded remove patch
@@ -44,7 +44,8 @@  discard block
 block discarded – undo
44 44
     {
45 45
         $matches = [];
46 46
 
47
-        switch ($fields) {
47
+        switch ($fields)
48
+        {
48 49
             case 'titleonly':
49 50
                 $matches[] = 'l.link_name';
50 51
             break;
@@ -59,9 +60,11 @@  discard block
 block discarded – undo
59 60
 
60 61
         $search_query = '';
61 62
 
62
-        foreach ($keywords_ary as $word) {
63
+        foreach ($keywords_ary as $word)
64
+        {
63 65
             $match_search_query = '';
64
-            foreach ($matches as $match) {
66
+            foreach ($matches as $match)
67
+            {
65 68
                 $match_search_query .= (($match_search_query) ? ' OR ' : '').'LOWER('.$match.') ';
66 69
                 $match_search_query .= $this->db->sql_like_expression(str_replace('*', $this->db->get_any_char(), $this->db->get_any_char().strtolower($word).$this->db->get_any_char()));
67 70
             }
@@ -69,9 +72,12 @@  discard block
 block discarded – undo
69 72
         }
70 73
         $direction = (($sort_dir == 'd') ? 'DESC' : 'ASC');
71 74
 
72
-        if (is_array($sort_by_sql[$sort_key])) {
75
+        if (is_array($sort_by_sql[$sort_key]))
76
+        {
73 77
             $sql_sort_order = implode(' '.$direction.', ', $sort_by_sql[$sort_key]).' '.$direction;
74
-        } else {
78
+        }
79
+        else
80
+        {
75 81
             $sql_sort_order = $sort_by_sql[$sort_key].' '.$direction;
76 82
         }
77 83
 
@@ -87,7 +93,8 @@  discard block
 block discarded – undo
87 93
             'ORDER_BY'    => $sql_sort_order,
88 94
         ];
89 95
 
90
-        if ($sql_sort_order[0] == 'u') {
96
+        if ($sql_sort_order[0] == 'u')
97
+        {
91 98
             $sql_array['LEFT_JOIN'][] = [
92 99
                 'FROM'    => [USERS_TABLE => 'u'],
93 100
                 'ON'      => 'u.user_id = l.link_user_id',
@@ -96,7 +103,8 @@  discard block
 block discarded – undo
96 103
 
97 104
         $sql = $this->db->sql_build_query('SELECT', $sql_array);
98 105
         $result = $this->db->sql_query($sql);
99
-        while ($row = $this->db->sql_fetchrow($result)) {
106
+        while ($row = $this->db->sql_fetchrow($result))
107
+        {
100 108
             $id_ary[] = $row['link_id'];
101 109
         }
102 110
 
Please login to merge, or discard this patch.
event/listener.php 3 patches
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -14,196 +14,196 @@
 block discarded – undo
14 14
 
15 15
 class listener implements EventSubscriberInterface
16 16
 {
17
-    /** @var \phpbb\db\driver\driver_interface */
18
-    protected $db;
19
-
20
-    /** @var \phpbb\controller\helper */
21
-    protected $helper;
22
-
23
-    /** @var \phpbb\template\template */
24
-    protected $template;
25
-
26
-    /** @var \phpbb\user */
27
-    protected $user;
28
-
29
-    /** @var \ernadoo\phpbbdirectory\core\helper */
30
-    protected $dir_helper;
31
-
32
-    /** @var string $table_prefix */
33
-    protected $table_prefix;
34
-
35
-    /** @var string phpEx */
36
-    protected $php_ext;
37
-
38
-    /**
39
-     * Constructor.
40
-     *
41
-     * @param \phpbb\db\driver\driver_interface   $db           Database object
42
-     * @param \phpbb\controller\helper            $helper       Controller helper object
43
-     * @param \phpbb\template\template            $template     Template object
44
-     * @param \phpbb\user                         $user         User object
45
-     * @param \ernadoo\phpbbdirectory\core\helper $dir_helper   PhpBB Directory extension helper object
46
-     * @param string                              $table_prefix prefix table
47
-     * @param string                              $php_ext      phpEx
48
-     */
49
-    public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\user $user, \ernadoo\phpbbdirectory\core\helper $dir_helper, $table_prefix, $php_ext)
50
-    {
51
-        $this->db = $db;
52
-        $this->helper = $helper;
53
-        $this->template = $template;
54
-        $this->user = $user;
55
-        $this->dir_helper = $dir_helper;
56
-        $this->table_prefix = $table_prefix;
57
-        $this->php_ext = $php_ext;
58
-    }
59
-
60
-    /**
61
-     * Assign functions defined in this class to event listeners in the core.
62
-     *
63
-     * @return array
64
-     * @static
65
-     */
66
-    public static function getSubscribedEvents()
67
-    {
68
-        return [
69
-            'core.common'                             => 'set_constants_tables',
70
-            'core.delete_user_after'                  => 'update_links_with_anonymous',
71
-            'core.page_header'                        => 'add_page_header_variables',
72
-            'core.permissions'                        => 'permissions_add_directory',
73
-            'core.user_setup'                         => 'load_language_on_setup',
74
-            'core.viewonline_overwrite_location'      => 'add_page_viewonline',
75
-        ];
76
-    }
77
-
78
-    /**
79
-     * Define table constants.
80
-     *
81
-     * @return null
82
-     */
83
-    public function set_constants_tables()
84
-    {
85
-        define('DIR_CAT_TABLE', $this->table_prefix.'directory_cats');
86
-        define('DIR_COMMENT_TABLE', $this->table_prefix.'directory_comments');
87
-        define('DIR_LINK_TABLE', $this->table_prefix.'directory_links');
88
-        define('DIR_VOTE_TABLE', $this->table_prefix.'directory_votes');
89
-        define('DIR_WATCH_TABLE', $this->table_prefix.'directory_watch');
90
-    }
91
-
92
-    /**
93
-     * Display links to Directory.
94
-     *
95
-     * @return null
96
-     */
97
-    public function add_page_header_variables()
98
-    {
99
-        $ext_theme_path = $this->dir_helper->get_ext_name().'/styles/prosilver/theme/';
100
-        $theme_lang_path = $this->user->lang_name;
101
-
102
-        // Prevent 'Twig_Error_Loader' if user's lang directory doesn't exist
103
-        if (!file_exists($ext_theme_path.$theme_lang_path.'/directory.css')) {
104
-            // Fallback to English language.
105
-            $theme_lang_path = 'en';
106
-        }
107
-
108
-        $this->template->assign_vars([
109
-            'T_DIR_THEME_LANG_NAME'  => $theme_lang_path,
110
-            'U_DIRECTORY'            => $this->helper->route('ernadoo_phpbbdirectory_base_controller'),
111
-        ]);
112
-    }
113
-
114
-    /**
115
-     * Show users as viewing Directory on Who Is Online page.
116
-     *
117
-     * @param object $event The event object
118
-     *
119
-     * @return null
120
-     */
121
-    public function add_page_viewonline($event)
122
-    {
123
-        if (strrpos($event['row']['session_page'], 'app.'.$this->php_ext.'/directory') === 0) {
124
-            $event['location'] = $this->user->lang['DIRECTORY'];
125
-            $event['location_url'] = $this->helper->route('ernadoo_phpbbdirectory_base_controller');
126
-        }
127
-    }
128
-
129
-    /**
130
-     * Load common language files during user setup.
131
-     *
132
-     * @param object $event The event object
133
-     *
134
-     * @return null
135
-     */
136
-    public function load_language_on_setup($event)
137
-    {
138
-        $lang_set_ext = $event['lang_set_ext'];
139
-        $lang_set_ext[] = [
140
-            'ext_name' => 'ernadoo/phpbbdirectory',
141
-            'lang_set' => 'directory_common',
142
-        ];
143
-        $event['lang_set_ext'] = $lang_set_ext;
144
-    }
145
-
146
-    /**
147
-     * Add administrative permissions to manage Directory.
148
-     *
149
-     * @param object $event The event object
150
-     *
151
-     * @return null
152
-     */
153
-    public function permissions_add_directory($event)
154
-    {
155
-        $categories = $event['categories'];
156
-        $categories = array_merge($categories, ['dir' => 'ACL_CAT_DIRECTORY']);
157
-        $event['categories'] = $categories;
158
-
159
-        $permissions = $event['permissions'];
160
-
161
-        $permissions = array_merge($permissions, [
162
-            'm_delete_dir'            => ['lang' => 'ACL_M_DELETE_DIR',            'cat' => 'dir'],
163
-            'm_delete_comment_dir'    => ['lang' => 'ACL_M_DELETE_COMMENT_DIR',    'cat' => 'dir'],
164
-            'm_edit_dir'              => ['lang' => 'ACL_M_EDIT_DIR',            'cat' => 'dir'],
165
-            'm_edit_comment_dir'      => ['lang' => 'ACL_M_EDIT_COMMENT_DIR',    'cat' => 'dir'],
166
-
167
-            'u_comment_dir'            => ['lang' => 'ACL_U_COMMENT_DIR',            'cat' => 'dir'],
168
-            'u_delete_dir'             => ['lang' => 'ACL_U_DELETE_DIR',            'cat' => 'dir'],
169
-            'u_delete_comment_dir'     => ['lang' => 'ACL_U_DELETE_COMMENT_DIR',    'cat' => 'dir'],
170
-            'u_edit_dir'               => ['lang' => 'ACL_U_EDIT_DIR',            'cat' => 'dir'],
171
-            'u_edit_comment_dir'       => ['lang' => 'ACL_U_EDIT_COMMENT_DIR',    'cat' => 'dir'],
172
-            'u_search_dir'             => ['lang' => 'ACL_U_SEARCH_DIR',            'cat' => 'dir'],
173
-            'u_submit_dir'             => ['lang' => 'ACL_U_SUBMIT_DIR',            'cat' => 'dir'],
174
-            'u_vote_dir'               => ['lang' => 'ACL_U_VOTE_DIR',            'cat' => 'dir'],
175
-        ]);
176
-
177
-        $event['permissions'] = $permissions;
178
-    }
179
-
180
-    /**
181
-     * Update Directory tables if needed, after deleted an user.
182
-     *
183
-     * @param object $event The event object
184
-     *
185
-     * @return null
186
-     */
187
-    public function update_links_with_anonymous($event)
188
-    {
189
-        $user_ids = $event['user_ids'];
190
-
191
-        if (!is_array($user_ids)) {
192
-            $user_ids = [$user_ids];
193
-        }
194
-
195
-        $sql = 'UPDATE '.DIR_COMMENT_TABLE.'
17
+	/** @var \phpbb\db\driver\driver_interface */
18
+	protected $db;
19
+
20
+	/** @var \phpbb\controller\helper */
21
+	protected $helper;
22
+
23
+	/** @var \phpbb\template\template */
24
+	protected $template;
25
+
26
+	/** @var \phpbb\user */
27
+	protected $user;
28
+
29
+	/** @var \ernadoo\phpbbdirectory\core\helper */
30
+	protected $dir_helper;
31
+
32
+	/** @var string $table_prefix */
33
+	protected $table_prefix;
34
+
35
+	/** @var string phpEx */
36
+	protected $php_ext;
37
+
38
+	/**
39
+	 * Constructor.
40
+	 *
41
+	 * @param \phpbb\db\driver\driver_interface   $db           Database object
42
+	 * @param \phpbb\controller\helper            $helper       Controller helper object
43
+	 * @param \phpbb\template\template            $template     Template object
44
+	 * @param \phpbb\user                         $user         User object
45
+	 * @param \ernadoo\phpbbdirectory\core\helper $dir_helper   PhpBB Directory extension helper object
46
+	 * @param string                              $table_prefix prefix table
47
+	 * @param string                              $php_ext      phpEx
48
+	 */
49
+	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\user $user, \ernadoo\phpbbdirectory\core\helper $dir_helper, $table_prefix, $php_ext)
50
+	{
51
+		$this->db = $db;
52
+		$this->helper = $helper;
53
+		$this->template = $template;
54
+		$this->user = $user;
55
+		$this->dir_helper = $dir_helper;
56
+		$this->table_prefix = $table_prefix;
57
+		$this->php_ext = $php_ext;
58
+	}
59
+
60
+	/**
61
+	 * Assign functions defined in this class to event listeners in the core.
62
+	 *
63
+	 * @return array
64
+	 * @static
65
+	 */
66
+	public static function getSubscribedEvents()
67
+	{
68
+		return [
69
+			'core.common'                             => 'set_constants_tables',
70
+			'core.delete_user_after'                  => 'update_links_with_anonymous',
71
+			'core.page_header'                        => 'add_page_header_variables',
72
+			'core.permissions'                        => 'permissions_add_directory',
73
+			'core.user_setup'                         => 'load_language_on_setup',
74
+			'core.viewonline_overwrite_location'      => 'add_page_viewonline',
75
+		];
76
+	}
77
+
78
+	/**
79
+	 * Define table constants.
80
+	 *
81
+	 * @return null
82
+	 */
83
+	public function set_constants_tables()
84
+	{
85
+		define('DIR_CAT_TABLE', $this->table_prefix.'directory_cats');
86
+		define('DIR_COMMENT_TABLE', $this->table_prefix.'directory_comments');
87
+		define('DIR_LINK_TABLE', $this->table_prefix.'directory_links');
88
+		define('DIR_VOTE_TABLE', $this->table_prefix.'directory_votes');
89
+		define('DIR_WATCH_TABLE', $this->table_prefix.'directory_watch');
90
+	}
91
+
92
+	/**
93
+	 * Display links to Directory.
94
+	 *
95
+	 * @return null
96
+	 */
97
+	public function add_page_header_variables()
98
+	{
99
+		$ext_theme_path = $this->dir_helper->get_ext_name().'/styles/prosilver/theme/';
100
+		$theme_lang_path = $this->user->lang_name;
101
+
102
+		// Prevent 'Twig_Error_Loader' if user's lang directory doesn't exist
103
+		if (!file_exists($ext_theme_path.$theme_lang_path.'/directory.css')) {
104
+			// Fallback to English language.
105
+			$theme_lang_path = 'en';
106
+		}
107
+
108
+		$this->template->assign_vars([
109
+			'T_DIR_THEME_LANG_NAME'  => $theme_lang_path,
110
+			'U_DIRECTORY'            => $this->helper->route('ernadoo_phpbbdirectory_base_controller'),
111
+		]);
112
+	}
113
+
114
+	/**
115
+	 * Show users as viewing Directory on Who Is Online page.
116
+	 *
117
+	 * @param object $event The event object
118
+	 *
119
+	 * @return null
120
+	 */
121
+	public function add_page_viewonline($event)
122
+	{
123
+		if (strrpos($event['row']['session_page'], 'app.'.$this->php_ext.'/directory') === 0) {
124
+			$event['location'] = $this->user->lang['DIRECTORY'];
125
+			$event['location_url'] = $this->helper->route('ernadoo_phpbbdirectory_base_controller');
126
+		}
127
+	}
128
+
129
+	/**
130
+	 * Load common language files during user setup.
131
+	 *
132
+	 * @param object $event The event object
133
+	 *
134
+	 * @return null
135
+	 */
136
+	public function load_language_on_setup($event)
137
+	{
138
+		$lang_set_ext = $event['lang_set_ext'];
139
+		$lang_set_ext[] = [
140
+			'ext_name' => 'ernadoo/phpbbdirectory',
141
+			'lang_set' => 'directory_common',
142
+		];
143
+		$event['lang_set_ext'] = $lang_set_ext;
144
+	}
145
+
146
+	/**
147
+	 * Add administrative permissions to manage Directory.
148
+	 *
149
+	 * @param object $event The event object
150
+	 *
151
+	 * @return null
152
+	 */
153
+	public function permissions_add_directory($event)
154
+	{
155
+		$categories = $event['categories'];
156
+		$categories = array_merge($categories, ['dir' => 'ACL_CAT_DIRECTORY']);
157
+		$event['categories'] = $categories;
158
+
159
+		$permissions = $event['permissions'];
160
+
161
+		$permissions = array_merge($permissions, [
162
+			'm_delete_dir'            => ['lang' => 'ACL_M_DELETE_DIR',            'cat' => 'dir'],
163
+			'm_delete_comment_dir'    => ['lang' => 'ACL_M_DELETE_COMMENT_DIR',    'cat' => 'dir'],
164
+			'm_edit_dir'              => ['lang' => 'ACL_M_EDIT_DIR',            'cat' => 'dir'],
165
+			'm_edit_comment_dir'      => ['lang' => 'ACL_M_EDIT_COMMENT_DIR',    'cat' => 'dir'],
166
+
167
+			'u_comment_dir'            => ['lang' => 'ACL_U_COMMENT_DIR',            'cat' => 'dir'],
168
+			'u_delete_dir'             => ['lang' => 'ACL_U_DELETE_DIR',            'cat' => 'dir'],
169
+			'u_delete_comment_dir'     => ['lang' => 'ACL_U_DELETE_COMMENT_DIR',    'cat' => 'dir'],
170
+			'u_edit_dir'               => ['lang' => 'ACL_U_EDIT_DIR',            'cat' => 'dir'],
171
+			'u_edit_comment_dir'       => ['lang' => 'ACL_U_EDIT_COMMENT_DIR',    'cat' => 'dir'],
172
+			'u_search_dir'             => ['lang' => 'ACL_U_SEARCH_DIR',            'cat' => 'dir'],
173
+			'u_submit_dir'             => ['lang' => 'ACL_U_SUBMIT_DIR',            'cat' => 'dir'],
174
+			'u_vote_dir'               => ['lang' => 'ACL_U_VOTE_DIR',            'cat' => 'dir'],
175
+		]);
176
+
177
+		$event['permissions'] = $permissions;
178
+	}
179
+
180
+	/**
181
+	 * Update Directory tables if needed, after deleted an user.
182
+	 *
183
+	 * @param object $event The event object
184
+	 *
185
+	 * @return null
186
+	 */
187
+	public function update_links_with_anonymous($event)
188
+	{
189
+		$user_ids = $event['user_ids'];
190
+
191
+		if (!is_array($user_ids)) {
192
+			$user_ids = [$user_ids];
193
+		}
194
+
195
+		$sql = 'UPDATE '.DIR_COMMENT_TABLE.'
196 196
 			SET comment_user_id = '.ANONYMOUS.'
197 197
 			WHERE '.$this->db->sql_in_set('comment_user_id', $user_ids);
198
-        $this->db->sql_query($sql);
198
+		$this->db->sql_query($sql);
199 199
 
200
-        $sql = 'UPDATE '.DIR_LINK_TABLE.'
200
+		$sql = 'UPDATE '.DIR_LINK_TABLE.'
201 201
 			SET link_user_id = '.ANONYMOUS.'
202 202
 			WHERE '.$this->db->sql_in_set('link_user_id', $user_ids);
203
-        $this->db->sql_query($sql);
203
+		$this->db->sql_query($sql);
204 204
 
205
-        $sql = 'DELETE FROM '.DIR_WATCH_TABLE.'
205
+		$sql = 'DELETE FROM '.DIR_WATCH_TABLE.'
206 206
 			WHERE '.$this->db->sql_in_set('user_id', $user_ids);
207
-        $this->db->sql_query($sql);
208
-    }
207
+		$this->db->sql_query($sql);
208
+	}
209 209
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -159,19 +159,19 @@
 block discarded – undo
159 159
         $permissions = $event['permissions'];
160 160
 
161 161
         $permissions = array_merge($permissions, [
162
-            'm_delete_dir'            => ['lang' => 'ACL_M_DELETE_DIR',            'cat' => 'dir'],
163
-            'm_delete_comment_dir'    => ['lang' => 'ACL_M_DELETE_COMMENT_DIR',    'cat' => 'dir'],
164
-            'm_edit_dir'              => ['lang' => 'ACL_M_EDIT_DIR',            'cat' => 'dir'],
165
-            'm_edit_comment_dir'      => ['lang' => 'ACL_M_EDIT_COMMENT_DIR',    'cat' => 'dir'],
166
-
167
-            'u_comment_dir'            => ['lang' => 'ACL_U_COMMENT_DIR',            'cat' => 'dir'],
168
-            'u_delete_dir'             => ['lang' => 'ACL_U_DELETE_DIR',            'cat' => 'dir'],
169
-            'u_delete_comment_dir'     => ['lang' => 'ACL_U_DELETE_COMMENT_DIR',    'cat' => 'dir'],
170
-            'u_edit_dir'               => ['lang' => 'ACL_U_EDIT_DIR',            'cat' => 'dir'],
171
-            'u_edit_comment_dir'       => ['lang' => 'ACL_U_EDIT_COMMENT_DIR',    'cat' => 'dir'],
172
-            'u_search_dir'             => ['lang' => 'ACL_U_SEARCH_DIR',            'cat' => 'dir'],
173
-            'u_submit_dir'             => ['lang' => 'ACL_U_SUBMIT_DIR',            'cat' => 'dir'],
174
-            'u_vote_dir'               => ['lang' => 'ACL_U_VOTE_DIR',            'cat' => 'dir'],
162
+            'm_delete_dir'            => ['lang' => 'ACL_M_DELETE_DIR', 'cat' => 'dir'],
163
+            'm_delete_comment_dir'    => ['lang' => 'ACL_M_DELETE_COMMENT_DIR', 'cat' => 'dir'],
164
+            'm_edit_dir'              => ['lang' => 'ACL_M_EDIT_DIR', 'cat' => 'dir'],
165
+            'm_edit_comment_dir'      => ['lang' => 'ACL_M_EDIT_COMMENT_DIR', 'cat' => 'dir'],
166
+
167
+            'u_comment_dir'            => ['lang' => 'ACL_U_COMMENT_DIR', 'cat' => 'dir'],
168
+            'u_delete_dir'             => ['lang' => 'ACL_U_DELETE_DIR', 'cat' => 'dir'],
169
+            'u_delete_comment_dir'     => ['lang' => 'ACL_U_DELETE_COMMENT_DIR', 'cat' => 'dir'],
170
+            'u_edit_dir'               => ['lang' => 'ACL_U_EDIT_DIR', 'cat' => 'dir'],
171
+            'u_edit_comment_dir'       => ['lang' => 'ACL_U_EDIT_COMMENT_DIR', 'cat' => 'dir'],
172
+            'u_search_dir'             => ['lang' => 'ACL_U_SEARCH_DIR', 'cat' => 'dir'],
173
+            'u_submit_dir'             => ['lang' => 'ACL_U_SUBMIT_DIR', 'cat' => 'dir'],
174
+            'u_vote_dir'               => ['lang' => 'ACL_U_VOTE_DIR', 'cat' => 'dir'],
175 175
         ]);
176 176
 
177 177
         $event['permissions'] = $permissions;
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -100,7 +100,8 @@  discard block
 block discarded – undo
100 100
         $theme_lang_path = $this->user->lang_name;
101 101
 
102 102
         // Prevent 'Twig_Error_Loader' if user's lang directory doesn't exist
103
-        if (!file_exists($ext_theme_path.$theme_lang_path.'/directory.css')) {
103
+        if (!file_exists($ext_theme_path.$theme_lang_path.'/directory.css'))
104
+        {
104 105
             // Fallback to English language.
105 106
             $theme_lang_path = 'en';
106 107
         }
@@ -120,7 +121,8 @@  discard block
 block discarded – undo
120 121
      */
121 122
     public function add_page_viewonline($event)
122 123
     {
123
-        if (strrpos($event['row']['session_page'], 'app.'.$this->php_ext.'/directory') === 0) {
124
+        if (strrpos($event['row']['session_page'], 'app.'.$this->php_ext.'/directory') === 0)
125
+        {
124 126
             $event['location'] = $this->user->lang['DIRECTORY'];
125 127
             $event['location_url'] = $this->helper->route('ernadoo_phpbbdirectory_base_controller');
126 128
         }
@@ -188,7 +190,8 @@  discard block
 block discarded – undo
188 190
     {
189 191
         $user_ids = $event['user_ids'];
190 192
 
191
-        if (!is_array($user_ids)) {
193
+        if (!is_array($user_ids))
194
+        {
192 195
             $user_ids = [$user_ids];
193 196
         }
194 197
 
Please login to merge, or discard this patch.