Skip to content

Commit ca8f971

Browse files
author
Ben Roberts
committed
login issues fiexed, site search, owner sees draft list
1 parent d60bccc commit ca8f971

12 files changed

Lines changed: 122 additions & 50 deletions

File tree

blog/controller/auth/login.php

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ public function index() {
2323
// make sure they actually submitted something
2424
if(!empty($me)){
2525

26-
//clean up the url given to us, just in case
27-
$me = trim($me);
28-
if(strpos($me, 'http') !== 0){
29-
$me = 'http://'.$me;
30-
}
26+
$me = $this->normalize_url($me);
3127

3228
//look up user's auth provider
3329
$auth_endpoint = IndieAuth\Client::discoverAuthorizationEndpoint($me);
@@ -39,19 +35,23 @@ public function index() {
3935

4036
$redir_url = $this->url->link('auth/login/callback', ($controller ? 'c='.$controller : ''), '');
4137
if($scope){
38+
// if a scope is given we are actually looking to get a token
4239
$redir_url = $this->url->link('auth/login/tokencallback', ($controller ? 'c='.$controller : ''), '');
4340
}
4441

4542
//build our get request
43+
$trimmed_me = trim($me, '/'); //in case we get it back without the /
4644
$data_array = array(
4745
'me' => $me,
4846
'redirect_uri' => $redir_url,
49-
'response_type' => 'code',
50-
'state' => substr(md5($me.$this->url->link('')),0,8),
47+
'response_type' => 'id',
48+
'state' => substr(md5($trimmed_me.$this->url->link('')),0,8),
5149
'client_id' => $this->url->link('')
5250
);
51+
$this->log->write(print_r($data_array,true));
5352
if($scope){
5453
$data_array['scope'] = $scope;
54+
$data_array['response_type'] = 'code';
5555
}
5656

5757
$get_data = http_build_query($data_array);
@@ -79,16 +79,28 @@ public function callback() {
7979
$redir_url = $this->url->link('auth/login/callback', 'c='.$this->request->get['c'], '');
8080
}
8181

82-
$me = $this->request->get['me'];
82+
$me = $this->normalize_url($this->request->get['me']);
8383
$code = $this->request->get['code'];
8484
$state = (isset($this->request->get['state']) ? $this->request->get['state'] : null);
8585

86+
$this->log->write('callback received ...');
87+
$this->log->write(print_r($this->request->get,true));
88+
8689
$result = $this->confirm_auth($me, $code, $redir_url, $state);
8790

8891
if($result){
8992
// we successfullly confirmed auth
9093
$this->session->data['user_site'] = $this->request->get['me'];
91-
$this->session->data['success'] = "You are now logged in as ".$this->request->get['me'];
94+
$this->session->data['success'] = "You are now logged in as ".$me;
95+
96+
$token_user = str_replace(array('http://', 'https://'),array('',''), $me);
97+
98+
$myself = trim($this->normalize_url(HTTP_SERVER),'/');
99+
$myself = trim(str_replace(array('http://', 'https://'),array('',''), $myself), '/');
100+
101+
if($token_user == $myself) {
102+
$this->session->data['is_owner'] = true;
103+
}
92104
}
93105

94106
$this->response->redirect($url);
@@ -108,11 +120,12 @@ public function tokencallback() {
108120
$redir_url = $this->url->link('auth/login/tokencallback', 'c='.$this->request->get['c'], '');
109121
}
110122

111-
$me = $this->request->get['me'];
123+
$me = $this->normalize_url($this->request->get['me']);
112124
$code = $this->request->get['code'];
113125
$state = (isset($this->request->get['state']) ? $this->request->get['state'] : null);
114126

115127
$result = $this->confirm_auth($me, $code, $redir_url, $state);
128+
$this->log->write($result);
116129

117130
if($result){
118131
// we successfullly confirmed auth
@@ -146,6 +159,8 @@ private function confirm_auth( $me, $code, $redir, $state = null ) {
146159
}
147160

148161
$post_data = http_build_query($post_array);
162+
$this->log->write('post_data: '.$post_data);
163+
$this->log->write('endpoint: '.$auth_endpoint);
149164

150165
$ch = curl_init($auth_endpoint);
151166

@@ -159,11 +174,19 @@ private function confirm_auth( $me, $code, $redir, $state = null ) {
159174

160175
$results = array();
161176
parse_str($response, $results);
162-
177+
$this->log->write('endpoint_response: '.$response);
178+
//$this->log->write(print_r($results, true));
179+
180+
$results['me'] = $this->normalize_url($results['me']);
181+
182+
$trimmed_me = trim($me, '/');
183+
$trimmed_result_me = trim($results['me'], '/');
184+
163185
if($state){
164-
return ($results['me'] == $me && $state == substr(md5($me.$client_id),0,8));
186+
//$this->log->write('state = '.$state. ' ' .substr(md5($trimmed_me.$client_id),0,8));
187+
return ($trimmed_result_me == $trimmed_me && $state == substr(md5($trimmed_me.$client_id),0,8));
165188
} else {
166-
return $results['me'] == $me ;
189+
return $trimmed_result_me == $trimmed_me ;
167190
}
168191

169192
}
@@ -207,5 +230,14 @@ private function get_token( $me, $code, $redir, $state = null ) {
207230

208231
return $results;
209232
}
233+
234+
235+
private function normalize_url($url) {
236+
$url = trim($url);
237+
if(strpos($url, 'http') !== 0){
238+
$url = 'http://'.$url;
239+
}
240+
return $url;
241+
}
210242
}
211243
?>

blog/controller/auth/logout.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class ControllerAuthLogout extends Controller {
33
public function index() {
44
unset($this->session->data['user_site']);
55
unset($this->session->data['token']);
6+
unset($this->session->data['is_owner']);
67
$this->session->data['success'] = "Logged out";
78
$this->response->redirect($this->url->link(''));
89
}

blog/controller/blog/article.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ public function index() {
5050
$this->document->addMeta('twitter:card', 'summary');
5151
$this->document->addMeta('twitter:title', $short_title);
5252
$this->document->addMeta('twitter:description', $description);
53+
$this->document->addMeta('twitter:image', '/image/static/icon_200.jpg');
5354

5455
$this->document->addMeta('og:type', 'article');
5556
$this->document->addMeta('og:title', $short_title);
5657
$this->document->addMeta('og:description', $description);
57-
$this->document->addMeta('og:image', '/image/static/icon_128.jpg');
58+
$this->document->addMeta('og:image', '/image/static/icon_200.jpg');
5859

5960
$data['header'] = $this->load->controller('common/header');
6061
$data['footer'] = $this->load->controller('common/footer');

blog/controller/blog/note.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ public function index() {
6969
$this->document->addMeta('twitter:card', 'summary');
7070
$this->document->addMeta('twitter:title', $short_title);
7171
$this->document->addMeta('twitter:description', $description);
72+
$this->document->addMeta('twitter:image', '/image/static/icon_200.jpg');
7273

7374
$this->document->addMeta('og:type', 'article');
7475
$this->document->addMeta('og:title', $short_title);
7576
$this->document->addMeta('og:description', $description);
76-
$this->document->addMeta('og:image', '/image/static/icon_128.jpg');
77+
$this->document->addMeta('og:image', '/image/static/icon_200.jpg');
7778

7879
$data['header'] = $this->load->controller('common/header');
7980
$data['footer'] = $this->load->controller('common/footer');

blog/controller/blog/photo.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ public function index() {
5151
$this->document->addMeta('twitter:card', 'summary');
5252
$this->document->addMeta('twitter:title', $short_title);
5353
$this->document->addMeta('twitter:description', $description);
54+
$this->document->addMeta('twitter:image', '/image/static/icon_200.jpg');
5455

5556
$this->document->addMeta('og:type', 'article');
5657
$this->document->addMeta('og:title', $short_title);
5758
$this->document->addMeta('og:description', $description);
58-
$this->document->addMeta('og:image', '/image/static/icon_128.jpg');
59+
$this->document->addMeta('og:image', '/image/static/icon_200.jpg');
5960

6061
$data['header'] = $this->load->controller('common/header');
6162
$data['footer'] = $this->load->controller('common/footer');

blog/controller/common/footer.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function index() {
1515
$data['login'] = $this->url->link('auth/login');
1616

1717
$data['google_analytics_id'] = GOOGLE_ANALYTICS_ID;
18+
$data['sitesearch'] = trim(str_replace(array('http://','https://'),array('',''), HTTP_SERVER), '/');
1819

1920
$data['mylinks'] = array();
2021

@@ -28,23 +29,20 @@ public function index() {
2829
'target' => $result['target']);
2930
}
3031

32+
if($this->session->data['is_owner']){
33+
$this->load->model('blog/post');
34+
$data['recent_drafts'] = $this->model_blog_post->getRecentDrafts(10);
35+
}
3136

3237
$this->load->model('blog/mention');
33-
$data['recent_mentions'] = array();
34-
foreach ($this->model_blog_mention->getRecentMentions(10) as $result) {
35-
$data['recent_mentions'][] = $result;
36-
}
38+
$data['recent_mentions'] = $this->model_blog_mention->getRecentMentions(10);
3739

3840
$this->load->model('blog/like');
39-
$data['likes'] = array();
41+
$data['likes'] = $this->model_blog_like->getGenericLikes();
4042
$data['like_count'] = $this->model_blog_like->getGenericLikeCount();
41-
foreach ($this->model_blog_like->getGenericLikes() as $result) {
42-
$data['likes'][] = $result;
43-
}
4443

4544
$this->load->model('blog/post');
4645
$data['recent_posts'] = array();
47-
4846
foreach ($this->model_blog_post->getRecentPosts(10) as $result) {
4947
if(empty($result['title'])){
5048
if($result['post_type'] == 'photo'){

blog/controller/common/home.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
<?php
22
class ControllerCommonHome extends Controller {
33
public function index() {
4-
$this->document->setTitle($this->config->get('config_meta_title'));
5-
$this->document->setDescription($this->config->get('config_meta_description'));
4+
$short_title = SITE_TITLE;
5+
$description = "OpenBlog site: ".SITE_TITLE;
6+
7+
$this->document->setTitle($short_title);
8+
$this->document->setDescription($description);
9+
10+
$this->document->addMeta('twitter:card', 'summary');
11+
$this->document->addMeta('twitter:title', $short_title);
12+
$this->document->addMeta('twitter:description', $description);
13+
$this->document->addMeta('twitter:image', '/image/static/icon_200.jpg');
14+
15+
$this->document->addMeta('og:type', 'website');
16+
$this->document->addMeta('og:title', $short_title);
17+
$this->document->addMeta('og:description', $description);
18+
$this->document->addMeta('og:image', '/image/static/icon_200.jpg');
619

720
$data['header'] = $this->load->controller('common/header');
821
$data['footer'] = $this->load->controller('common/footer');
@@ -12,6 +25,7 @@ public function index() {
1225
$this->load->model('blog/category');
1326
$this->load->model('blog/comment');
1427
$this->load->model('blog/like');
28+
1529

1630
$data['posts'] = array();
1731

@@ -28,7 +42,7 @@ public function index() {
2842
$data['posts'][] = array_merge($result, array(
2943
'body_html' => html_entity_decode($result['body']),
3044
'author' => $author,
31-
'author_image' => '/image/static/icon_128.jpg',
45+
'author_image' => '/image/static/icon_200.jpg',
3246
'categories' => $categories,
3347
'comment_count' => $comment_count,
3448
'like_count' => $like_count
@@ -45,7 +59,7 @@ public function index() {
4559
$data['side_posts'][] = array_merge($result, array(
4660
'body_html' => html_entity_decode(isset($result['excerpt']) ? $result['excerpt']. '...' : $result['body']),
4761
'author' => $author,
48-
'author_image' => '/image/static/icon_128.jpg',
62+
'author_image' => '/image/static/icon_200.jpg',
4963
'categories' => $categories,
5064
'comment_count' => $comment_count,
5165
'like_count' => $like_count

blog/controller/micropub/receive.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
class ControllerMicropubReceive extends Controller {
33
public function index() {
4-
$this->log->write('good');
54
$headers = apache_request_headers();
65
if(isset($this->request->post['access_token']) || isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) || isset($headers['Authorization'])){
76
$token = $this->request->post['access_token'];
@@ -19,32 +18,24 @@ public function index() {
1918

2019

2120
if(!empty($auth_info) && in_array('post', explode(' ', $auth_info['scope']))) {
22-
$this->log->write('good 2');
2321

2422
$token_user = str_replace(array('http://', 'https://'),array('',''), $auth_info['user']);
2523
$myself = str_replace(array('http://', 'https://'),array('',''), HTTP_SERVER);
2624

2725
if($token_user == $myself || $token_user.'/' == $myself || $token_user == $myself .'/' ) {
28-
$this->log->write('good 3');
2926

3027
//$this->log->write(print_r($this->request->post, true));
3128
if(isset($this->request->post['operation']) && strtolower($this->request->post['operation']) == 'delete'){
32-
$this->log->write('debug 4');
3329
$this->deletePost();
3430
} elseif(isset($this->request->post['operation']) && strtolower($this->request->post['operation']) == 'undelete'){
35-
$this->log->write('debug 5');
3631
$this->undeletePost();
3732
} elseif(isset($this->request->post['type']) && $this->request->post['type'] == 'article'){
38-
$this->log->write('debug 6');
3933
$this->createArticle();
4034
} elseif(isset($_FILES['photo']) && !empty($_FILES['photo'])){
41-
$this->log->write('debug 7');
4235
$this->createPhoto();
4336
} elseif(isset($this->request->post['operation']) && strtolower($this->request->post['operation']) == 'edit'){
44-
$this->log->write('debug 8');
4537
$this->editPost();
4638
} else {
47-
$this->log->write('debug 9');
4839
$this->createNote();
4940
}
5041

@@ -63,7 +54,7 @@ public function index() {
6354
}
6455

6556
private function undeletePost(){
66-
$this->log->write('called undeletePost()');
57+
//$this->log->write('called undeletePost()');
6758
$post = $this->getPostByURL($this->request->post['url']);
6859
if($post && isset($this->request->post['syndication'])){
6960
$this->load->model('blog/post');
@@ -78,7 +69,7 @@ private function undeletePost(){
7869
}
7970

8071
private function deletePost(){
81-
$this->log->write('called deletePost()');
72+
//$this->log->write('called deletePost()');
8273
$post = $this->getPostByURL($this->request->post['url']);
8374
if($post && isset($this->request->post['syndication'])){
8475
$this->load->model('blog/post');
@@ -98,7 +89,7 @@ private function deletePost(){
9889
}
9990

10091
private function editPost(){
101-
$this->log->write('called editPost()');
92+
//$this->log->write('called editPost()');
10293
$post = $this->getPostByURL($this->request->post['url']);
10394
if($post && isset($this->request->post['syndication'])){
10495
$this->load->model('blog/post');
@@ -112,7 +103,7 @@ private function editPost(){
112103
}
113104

114105
private function createNote(){
115-
$this->log->write('called createNote()');
106+
//$this->log->write('called createNote()');
116107
$this->load->model('blog/note');
117108
$data = array();
118109
$data['body'] = $this->request->post['content'];
@@ -148,9 +139,9 @@ private function createNote(){
148139
}
149140
}
150141

151-
$this->log->write(print_r($data,true));
142+
//$this->log->write(print_r($data,true));
152143
$note_id = $this->model_blog_note->newNote($data);
153-
$this->log->write($note_id);
144+
//$this->log->write($note_id);
154145
$this->cache->delete('posts');
155146
$this->cache->delete('notes');
156147

@@ -174,9 +165,8 @@ private function createNote(){
174165
}
175166

176167
private function createArticle(){
177-
$this->log->write('called createArticle()');
168+
//$this->log->write('called createArticle()');
178169
//$this->log->write($this->request->post['content']);
179-
//$this->log->write('called createArticle');
180170
$this->load->model('blog/article');
181171
$data = array();
182172
$data['body'] = $this->request->post['content'];
@@ -233,7 +223,7 @@ private function createArticle(){
233223
}
234224

235225
private function createPhoto(){
236-
$this->log->write('called createPhoto()');
226+
//$this->log->write('called createPhoto()');
237227
$upload_shot = $_FILES['photo'];
238228

239229
if( $upload_shot['error'] == 0) {

0 commit comments

Comments
 (0)