Browse Source

add UI to create and edit sites

* moves API key to settings screen
* adds Superfeedr subscription URL in settings screen
main
Aaron Parecki 8 years ago
parent
commit
b2822f4396
7 changed files with 123 additions and 9 deletions
  1. +62
    -0
      controllers/Controller.php
  2. +7
    -0
      public/assets/styles.css
  3. +3
    -0
      public/index.php
  4. +2
    -8
      views/dashboard.php
  5. +1
    -0
      views/footer-block.php
  6. +1
    -1
      views/layout-loggedin.php
  7. +47
    -0
      views/new-site.php

+ 62
- 0
controllers/Controller.php View File

@ -129,6 +129,68 @@ class Controller {
return $response;
}
public function new_site(Request $request, Response $response) {
if(!$this->_is_logged_in($request, $response)) {
return $response;
}
if(!$role=$this->_get_role($request, $response)) {
return $response;
}
if($request->get('account')) {
// permissions are checked already by _get_role
$site = ORM::for_table('sites')->where_id_is($request->get('account'))->find_one();
} else {
$site = null;
}
$response->setContent(view('new-site', [
'title' => 'Create New Site',
'user' => $this->_user(),
'accounts' => $this->_accounts(),
'role' => $role,
'site' => $site
]));
return $response;
}
public function save_site(Request $request, Response $response) {
if(!$this->_is_logged_in($request, $response)) {
return $response;
}
if(!$role=$this->_get_role($request, $response)) {
return $response;
}
if($request->get('account')) {
// permissions are checked already by _get_role
$site = ORM::for_table('sites')->where_id_is($request->get('account'))->find_one();
$site->name = $request->get('name');
$site->url = $request->get('url');
$site->save();
} else {
$site = ORM::for_table('sites')->create();
$site->created_by = session('user_id');
$site->created_at = date('Y-m-d H:i:s');
$site->name = $request->get('name');
$site->url = $request->get('url');
$site->save();
$role = ORM::for_table('roles')->create();
$role->site_id = $site->id;
$role->user_id = session('user_id');
$role->role = 'owner';
$role->token = random_string(32);
$role->save();
}
$response->setStatusCode(302);
$response->headers->set('Location', '/dashboard?account='.$site->id);
return $response;
}
public function webmention_details(Request $request, Response $response, $args) {
session_start();

+ 7
- 0
public/assets/styles.css View File

@ -9,3 +9,10 @@
background-color: rgba(248,246,255,1);
font-size: 0.9em;
}
h2.site-name .edit-site {
visibility: hidden;
}
h2.site-name:hover .edit-site {
visibility: visible;
}

+ 3
- 0
public/index.php View File

@ -24,6 +24,9 @@ $templates = new League\Plates\Engine(dirname(__FILE__).'/../views');
$router->addRoute('GET', '/', 'Controller::index');
$router->addRoute('GET', '/dashboard', 'Controller::dashboard');
$router->addRoute('GET', '/site/new', 'Controller::new_site');
$router->addRoute('GET', '/site/edit', 'Controller::new_site');
$router->addRoute('POST', '/site/save', 'Controller::save_site');
$router->addRoute('GET', '/api', 'Controller::api');
$router->addRoute('GET', '/webmention/{code}/details', 'Controller::webmention_details');
$router->addRoute('GET', '/dashboard/send', 'Controller::dashboard_send');

+ 2
- 8
views/dashboard.php View File

@ -2,6 +2,8 @@
<div class="ui main text container" style="margin-top: 80px; margin-bottom: 40px;">
<h2 class="site-name"><?= $site->name ?> <a href="/site/edit?account=<?= $site->id ?>" class="edit-site" style="font-size: 0.8em;"><i class="setting icon"></i></a></h2>
<div class="ui top attached tabular menu">
<a class="item active" data-tab="send-from-source">Find Links</a>
<a class="item" data-tab="send-source-target">Send Webmention</a>
@ -62,14 +64,6 @@
<div class="ui message">It looks like you haven't sent any webmentions yet! Try entering one of your post URLs above and send some.</div>
<? endif; ?>
<form class="ui form">
<div class="field">
<label>API Key</label>
<input type="text" readonly="" value="<?= $role->token ?>">
</div>
<p>Use this key when sending webmentions using the <a href="/api">API</a>.</p>
</form>
</div>
<script>

+ 1
- 0
views/footer-block.php View File

@ -4,6 +4,7 @@
<div class="three wide column">
<h4 class="ui inverted header">Telegraph</h4>
<div class="ui inverted link list">
<a href="/api" class="item">API</a>
<a href="https://github.com/aaronpk/Telegraph" class="item">Open Source</a>
<a href="https://github.com/aaronpk/Telegraph/issues" class="item">Issues</a>
<a href="http://webmention.net" class="item">About Webmention</a>

+ 1
- 1
views/layout-loggedin.php View File

@ -18,9 +18,9 @@
<? foreach($accounts as $account): ?>
<a class="item" href="/dashboard?account=<?= $account->id ?>"><?= $this->e($account->name) ?></a>
<? endforeach; ?>
<a class="item" href="/site/new"><i class="plus icon"></i> New Site</a>
<!--
<div class="divider"></div>
<a class="item" href="/new-site"><i class="plus icon"></i> New Site</a>
<a class="item" href="/profile"><i class="user icon"></i> Profile</a>
-->
<div class="divider"></div>

+ 47
- 0
views/new-site.php View File

@ -0,0 +1,47 @@
<?php $this->layout('layout-loggedin', ['title' => $title, 'accounts' => $accounts, 'user' => $user]); ?>
<div class="ui main text container" style="margin-top: 80px; margin-bottom: 40px;">
<?php if($site): ?>
<h2>Edit Site</h2>
<?php else: ?>
<h2>Create a New Site</h2>
<p>Create a new site to help organize your webmentions. Each site has its own API key for sending webmentions, or for receiving mentions from Superfeedr.</p>
<?php endif; ?>
<form action="/site/save" method="post" class="ui form">
<div class="field">
<label>Name</label>
<input type="text" name="name" value="<?= $site ? $site->name : '' ?>">
</div>
<div class="field">
<label>URL</label>
<input type="url" name="url" placeholder="http://example.com/" value="<?= $site ? $site->url : '' ?>">
</div>
<button class="ui button"><?= $site ? 'Save' : 'Create' ?> Site</button>
<input type="hidden" name="account" value="<?= $site ? $site->id : '' ?>">
</form>
<p style="margin-top: 1em;">Enter your website's home page URL above, and you will be able to receive webmentions from a Superfeedr tracking feed to that domain.</p>
<?php if($site): ?>
<form class="ui form">
<div class="field">
<label>API Key</label>
<input type="text" readonly="" value="<?= $role->token ?>">
<p>Use this key when sending webmentions using the <a href="/api">API</a>.</p>
</div>
<div class="field">
<label>Superfeedr Webhook URL</label>
<input type="text" readonly="" value="<?= Config::$base ?>superfeedr/<?= $role->token ?>">
<p>Create a <a href="https://superfeedr.com/tracker">Superfeedr tracker</a> subscription and set this URL as the web hook URL.</p>
<p>If you are using Telegraph to send webmentions as well as receive webmentions from Superfeedr, it is recommended you create a separate site for Superfeedr so you can more easily separate the two uses of the service.</p>
</div>
</form>
<?php endif; ?>
</div>

Loading…
Cancel
Save