1 |
<?php |
2 |
// vim: ts=4 foldcolumn=4 foldmethod=marker |
3 |
/** |
4 |
* WP_User class found here. |
5 |
* |
6 |
* This file is part of Reblog, |
7 |
* a derivative work of Feed On Feeds. |
8 |
* |
9 |
* Distributed under the Gnu Public License. |
10 |
* |
11 |
* @package Refeed |
12 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
13 |
* @author Michal Migurski <mike@stamen.com> |
14 |
* @author Michael Frumin <mfrumin@eyebeam.org> |
15 |
* @copyright ©2004 Michael Frumin, Michal Migurski |
16 |
* @link http://reblog.org Reblog |
17 |
* @link http://feedonfeeds.com Feed On Feeds |
18 |
* @version $Revision: 1.2 $ |
19 |
*/ |
20 |
|
21 |
/** |
22 |
* WP_User is an authentication class for authenticating with the WordPress cookie |
23 |
* |
24 |
* note that it authenticates for free in the /out directory, for public viewing of the |
25 |
* output items/feeds |
26 |
*/ |
27 |
class WP_User extends RF_User |
28 |
{ |
29 |
|
30 |
var $name = ''; |
31 |
|
32 |
function _authenticate(&$dbh) |
33 |
{ |
34 |
if(basename(dirname($_SERVER['SCRIPT_NAME'])) == "out") { |
35 |
if(empty($_GET['user'])) { |
36 |
$_GET['user'] = 1; |
37 |
} |
38 |
$name = $dbh->getOne("SELECT user_login FROM wp_users WHERE ID = ?", array($_GET['user'])); |
39 |
$user = new WP_User(array('id' => $_GET['user'], 'name' => $name)); |
40 |
return $user; |
41 |
} |
42 |
|
43 |
$uname = ''; |
44 |
$pass = ''; |
45 |
foreach($_COOKIE as $k => $v) { |
46 |
if(preg_match('/^wordpressuser\w+$/', $k)) { |
47 |
$uname = $v; |
48 |
} |
49 |
else if(preg_match('/^wordpresspass\w+$/', $k)) { |
50 |
$pass = $v; |
51 |
} |
52 |
} |
53 |
|
54 |
if(!(empty($uname) || empty($pass))) { |
55 |
$row = $dbh->getRow("SELECT * FROM wp_users WHERE user_login = ?", array($uname), DB_FETCHMODE_ASSOC); |
56 |
|
57 |
if(!DB::isError($row)) { |
58 |
if(!empty($row['ID']) && md5($row['pass'] == $pass)) { |
59 |
$user = new WP_User(array('id' => $row['ID'], 'name' => $uname)); |
60 |
return $user; |
61 |
} |
62 |
} |
63 |
} |
64 |
|
65 |
// this should really back up directories looking for the wp-login.php |
66 |
// and also include a return url so that it redirects to refeed after login |
67 |
header(sprintf("Location: ../wp-login.php?redirect_to=%s", urlencode($_SERVER['REQUEST_URI']))); |
68 |
|
69 |
} |
70 |
|
71 |
function WP_User($args) |
72 |
{ |
73 |
$this->name = empty($args['name']) ? $this->id : $args['name']; |
74 |
|
75 |
parent::RF_User($args); |
76 |
} |
77 |
|
78 |
function selfName() |
79 |
{ |
80 |
return $this->name; |
81 |
} |
82 |
|
83 |
|
84 |
} |
85 |
|
86 |
?> |