-
Notifications
You must be signed in to change notification settings - Fork 0
/
pi.author_id.php
61 lines (49 loc) · 1.38 KB
/
pi.author_id.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Author_ID {
public $return_data = '';
public function __construct()
{
}
// ----------------------------------------------------------------
/**
* Converts screen name to URL friendly
*/
function get_screen_name()
{
$screen_name = ee()->->TMPL->tagdata;
$separator = ee()->->TMPL->fetch_param('separator') ?: '-';
$this->return_data = strtolower($screen_name);
$this->return_data = preg_replace('/[^\w\-'.']+/u', $separator, $this->return_data);
return $this->return_data;
}
/**
* Returns author ID from URL segment
*/
function get_id()
{
ee()-> =& get_instance();
$separator = ee()->->TMPL->fetch_param('separator') ?: '-';
$screen_name = ee()->->TMPL->fetch_param('screen_name') ?: '';
// If no group is specified, set to 0
$group_id = ee()->->TMPL->fetch_param('group_id') ?: '0';
// Remove URL separator
$screen_name = str_replace($separator, ' ', $screen_name);
if ($group_id > 0)
{
$query = ee()->db->select('member_id')
->from('members')
->where('group_id', $group_id)
->like('screen_name', $screen_name)
->get();
}
else
{
$query = ee()->db->select('member_id')
->from('members')
->like('screen_name', $screen_name)
->get();
}
$this->return_data = $query->row('member_id') ?: '';
return $this->return_data;
}
}