Skip to content
Browse files

updated the csrftoken data model again. I removed the url and now it'…

…s just owner and token. Updated the HUD view.
  • Loading branch information...
1 parent 6785c38 commit 69a1d4558377f331d99268caeba5dac15c1cc9c4 Joey Guerra committed
View
7 app/models/Csrftoken.php
@@ -9,16 +9,15 @@ public function __construct($values = array()){
public $id;
public $owner_id;
public $token;
- public $url;
public static function install(){
- $query = "create table if not exists csrftokens (owner_id int, token text, url text)";
+ $query = "create table if not exists csrftokens (owner_id int, token text)";
$db = Repo::get_provider();
$result = $db->query($query);
return $result;
}
- public static function find_by_url($url, $owner_id){
+ public static function find( $owner_id){
$model = new Model(null, "csrftokens");
- $token = $model->single("owner_id = :owner_id and url = :url", array("owner_id"=>$owner_id, "url"=>$url));
+ $token = $model->single("owner_id = :owner_id", array("owner_id"=>$owner_id));
return $token;
}
public static function save($token){
View
3 app/models/Post.php
@@ -64,6 +64,9 @@ public function post_meta(){
public function set_post_meta($value){
$this->post_meta = $value;
}
+ public static function get_statii(){
+ return array("Public"=>"public", "Pending"=>"pending", "Draft"=>"draft");
+ }
public static function get_excerpt($post){
if($post->excerpt !== null) return $post->excerpt;
$lines = explode(PHP_EOL, $post->body);
View
5 app/resources/AppResource.php
@@ -86,7 +86,7 @@ public static function request_was_made($publisher, $info){
$publisher->set_unauthed();
return;
}
- $csrf_token = Csrftoken::find_by_url($publisher->class_name, AuthController::current_user()->id);
+ $csrf_token = Csrftoken::find(AuthController::current_user()->id);
if($csrf_token === null) return;
if($csrf_token->token != $_POST["_csrf_token"]){
$publisher->set_unauthed();
@@ -100,10 +100,9 @@ public static function request_has_finished($publisher, $info){
//$salt = microtime(true).mt_rand(10000,90000);
if(AuthController::is_authed()){
$hash = self::get_hash();
- $csrf_token = Csrftoken::find_by_url($publisher->class_name, AuthController::current_user()->id);
+ $csrf_token = Csrftoken::find(AuthController::current_user()->id);
if($csrf_token === null){
$csrf_token->owner_id = AuthController::current_user()->id;
- $csrf_token->url = $publisher->class_name;
}
$csrf_token->token = $hash;
Csrftoken::save($csrf_token);
View
11 app/resources/HudResource.php
@@ -13,6 +13,17 @@ public function __destruct(){
}
public function get($bookmark){
$this->bookmark = json_decode(urldecode($bookmark));
+ $this->bookmark->status = "Public";
+ $this->bookmark->type = "bookmark";
+ $this->title = "Your 6d HUD";
+ $this->output = View::render("hud/index", $this);
+ return View::render_layout("modal", $this);
+ }
+ public function post(Post $post){
+ $post->owner_id = AuthController::current_user()->id;
+ $post = Post::save($post);
+ App::set_user_message("Bookmark saved");
+ $this->set_redirect_to(AuthController::current_user()->signin . "/hud?bookmark=" . array("bookmark"=>urlencode(json_encode($post))));
$this->title = "Your 6d HUD";
$this->output = View::render("hud/index", $this);
return View::render_layout("modal", $this);
View
2 app/resources/PostsResource.php
@@ -68,7 +68,6 @@ public function post(Post $post){
return View::render_layout('default', $this);
}
public static function set_bookmark_description_and_title($post){
- error_log(json_encode($post));
$html = file_get_contents($post->body);
error_log($html);
$matches = array();
@@ -80,7 +79,6 @@ public static function set_bookmark_description_and_title($post){
$pattern = "<meta\s+name=['\"]??description['\"]??\s+content=['\"]??(.+)['\"]??\s*\/?>";
$post->excerpt = $matches[1];
- error_log(json_encode($matches));
return $post;
}
}
View
5 app/views/bookmarklet/index_html.php
@@ -1,4 +1,5 @@
<p>Drag this bookmarklet onto your bookmarks bar to use it.</p>
-<a href="javascript:(function(){if(chin){chin.show_hud();return;};var%20h=false;var%20ss=document.getElementsByTagName('script');ss=Array.prototype.slice.call(ss);var%20s=ss.pop();while(s!=null){if(s.src!=undefined){if(s.src.indexOf('dashboard.js')!=-1){h=true;}s=ss.pop();}};if(!h){s=document.createElement('script');s.onload=function(){chin.show_hud;};s.src='<?php echo App::url_for("js/hud.js");?>?'+Math.floor((+new%20Date)/864e5);document.body.appendChild(s);}})();" title="Your 6d Bookmarklet Dashboard">Your 6d Bookmarklet Dashboard</a>
+<a href="javascript:(function(){if('chin' in window){chin.show_hud();return;};var%20h=false;var%20ss=document.getElementsByTagName('script');ss=Array.prototype.slice.call(ss);var%20s=ss.pop();while(s!=null){if(s.src!=undefined){if(s.src.indexOf('hud.js')!=-1){h=true;}s=ss.pop();}};if(!h){s=document.createElement('script');s.src='<?php echo App::url_for("js/hud.js");?>?'+Math.floor((+new%20Date)/864e5);document.body.appendChild(s);}})();" title="6d HUD">6d HUD</a>
+
<p>If you're using IE, just create a favorite link with the following in the address field.</p>
-<pre><code>javascript:(function(){if(chin){chin.show_hud();return;};var%20h=false;var%20ss=document.getElementsByTagName('script');ss=Array.prototype.slice.call(ss);var%20s=ss.pop();while(s!=null){if(s.src!=undefined){if(s.src.indexOf('dashboard.js')!=-1){h=true;}s=ss.pop();}};if(!h){s=document.createElement('script');s.onload=function(){chin.show_hud;};s.src='<?php echo App::url_for("js/hud.js");?>?'+Math.floor((+new%20Date)/864e5);document.body.appendChild(s);}})();</code></pre>
+<pre><code>javascript:(function(){if(chin){chin.show_hud();return;};var%20h=false;var%20ss=document.getElementsByTagName('script');ss=Array.prototype.slice.call(ss);var%20s=ss.pop();while(s!=null){if(s.src!=undefined){if(s.src.indexOf('hud.js')!=-1){h=true;}s=ss.pop();}};if(!h){s=document.createElement('script');s.onload=function(){chin.show_hud();};s.src='<?php echo App::url_for("js/hud.js");?>?'+Math.floor((+new%20Date)/864e5);document.body.appendChild(s);}})();</code></pre>
View
16 app/views/hud/index_html.php
@@ -6,11 +6,23 @@
</div>
<div>
<label for="excerpt">Description</label>
- <textarea name="post[excerpt]" id="excerpt"><?php echo $bookmark->description;?></textarea>
+ <textarea name="post[excerpt]" id="excerpt"><?php echo $bookmark->excerpt;?></textarea>
</div>
<div>
<label for="url">Link</label>
- <input type="text" name="post[body]" id="url" value="<?php echo $bookmark->url;?>" />
+ <input type="text" name="post[body]" id="body" value="<?php echo $bookmark->body;?>" />
+ </div>
+ <div>
+ <label for="status">Status</label>
+ <select id="status" name="post[status]">
+ <?php foreach(Post::get_statii() as $key=>$value):?>
+ <option value="<?php echo $value;?>"<?php echo ($bookmark->status === $value ? " selected" : null);?>><?php echo $key;?></option>
+ <?php endforeach;?>
+ </select>
+ </div>
+ <div>
+ <label for="type">Type</label>
+ <input type="text" name="post[type]" id="type" value="<?php echo $bookmark->type;?>" />
</div>
<button type="submit">Share</button>
</form>
View
6 app/views/layouts/modal_html.php
@@ -5,6 +5,12 @@
<?php echo $css;?>
</head>
<body>
+ <div class="chat-bubble" id="user_message"<?php echo (App::get_user_message() === null ? ' style="display:none;"' : null);?>>
+ <?php echo App::get_user_message();?>
+ <div class="chat-bubble-arrow-border"></div>
+ <div class="chat-bubble-arrow"></div>
+ </div>
+
<?php echo $output;?>
</body>
</html>
View
2 app/views/post/edit_html.php
@@ -13,7 +13,7 @@
<div>
<label for="post[status]">Status</label>
<select id="post[status]" name="post[status]">
- <?php foreach(array("Public"=>"public", "Pending"=>"pending", "Draft"=>"draft") as $key=>$value):?>
+ <?php foreach(Post::get_statii() as $key=>$value):?>
<option value="<?php echo $value;?>"<?php echo ($post->status === $value ? " selected" : null);?>><?php echo $key;?></option>
<?php endforeach;?>
</select>
View
14 js/default.js
@@ -56,8 +56,8 @@ chin.root_url = function(){
chin.show_hud = function(){
var div = document.getElementById("sixd_hud");
if(div != null){
- div.style.display = "block";
- return;
+ var parent = div.parentNode;
+ parent.removeChild(div);
}
div = document.createElement("div");
@@ -90,21 +90,25 @@ chin.show_hud = function(){
excerpt.innerHTML = site_description;
url.name = "body";
url.setAttribute("value", window.location.href);
-
+ var close_button_style = {"border-radius":"50px", background: "white", color: "black"};
+ for(p in style){
+ close_button.style[p] = style[p];
+ }
var style = {"z-index":100000, position: "fixed", top: "1em", right: "1em", "border-radius": "5px", background: "rgba(0,0,0,.8)", color: "white",padding: "10px", "box-shadow":"rgba(0,0,0,.5) 0 0 50px"};
close_button.innerHTML = "x";
close_button.onclick = function(e){
div.style.display = "none";
};
+
for(p in style){
div.style[p] = style[p];
}
- var iframe_style = {border: "none", display: "block", width: "100%", height: "300px"};
+ var iframe_style = {border: "none", display: "block", width: "100%", height: "350px"};
for(p in iframe_style){
iframe.style[p] = iframe_style[p];
}
- iframe.src = chin.root_url() + "hud?bookmark=" + encodeURIComponent(JSON.stringify({title: site_title, description: site_description, url: url.getAttribute("value")}));
+ iframe.src = chin.root_url() + "hud?bookmark=" + encodeURIComponent(JSON.stringify({title: site_title, excerpt: site_description, body: url.getAttribute("value")}));
div.appendChild(close_button);
div.appendChild(iframe);
document.body.appendChild(div);

0 comments on commit 69a1d45

Please sign in to comment.
Something went wrong with that request. Please try again.