I am trying to implement the remote submission for story link. The big problem is if someone tries to use it and is not logged on. You get an access denied message. There is no way to be able to login and get redirected to the storylink form. I have tried a million things including login_direction and login_toboboggin. What is the solution?

Comments

mstef’s picture

As I said in the other post, I have finally (hours) found a way to get around this problem. I would much rather like a different solution because I feel like mine is going to destroy something. But I will share if anyone wants.

frjo’s picture

Category: bug » feature
Priority: Critical » Normal

Please post your solution here. Others may be able to build upon and improve it.

mstef’s picture

OK..this is a crazy one. I added two other features too. If you try to submit a link that is already submitted, the error now includes a link to the submitted node. ALSO: if you try to use remote submission, and the link is already in, I found a way to have to redirect automatically without even seeing the form. Lets get started..

First off: The way drupal handles URL's is strange and it was completely encoding the submission url's way more than they should be. I was getting parse errors in my address bar. So to fix this I did this:
Create a file in root called transfer.php:

$url = $_SERVER['HTTP_REFERER'];
header("Location: $url");

Then modify user.module, telling it to redirect to that file after logging in. The point of this is that transfer.php capture the url you intended to use and redirects to it, before drupal can eat it up.
function user_block($op = 'list', $delta = 0, $edit = array()) {
$form['#action'] = url($_GET['q'], 'destination=transfer.php');

Now the biggest problem is that if the user is not logged in and uses a remote submission link, they get access denied and the games over. So install login toboggan. Leave the settings alone. Enable the login block in the content area with its visibility set with php code to:

$test = $_SERVER['REQUEST_URI'];
if(strlen($test) > 19) {
  $test = substr($test, 0, 19);
  if($test == '/node/add/storylink'){
   return TRUE;
  }
}
return FALSE;

Now it will only show on access denied pages coming from remote submission links..

To make storylink.module give a link to the already submitted node when you press submit change the function to this:
function vote_storylink_validate(&$node) {
vote_storylink_node_build($node);
if ($nid = db_result(db_query("SELECT ln.nid FROM {links} l INNER JOIN {links_node} ln ON l.lid = ln.lid WHERE ln.nid != %d AND LOWER(l.url) = LOWER('%s')", $node->nid, $node->vote_storylink_url))) {
form_set_error('vote_storylink_url', t('The URL is already submitted. Click here to view it.'));
}
}

And to enable the site to auto detect remote submissions url to check for dupes then redirect make a block with this as the body:

$suburl = $_SERVER['REQUEST_URI'];
$suburl = strstr($suburl, "=");
$suburl = urldecode(substr($suburl, 1, strpos($suburl,"&",0)-1));
if ($nid = db_result(db_query("SELECT ln.nid FROM {links} l INNER JOIN {links_node} ln ON l.lid = ln.lid WHERE LOWER(l.url) = LOWER('%s')", $suburl))) {
 header("Location: http://www.SITE.com/node/$nid");
}

And this for the visibility:

$test = $_SERVER['REQUEST_URI'];
if(strlen($test) > 19) {
  $test = substr($test, 0, 19);
  if($test == '/node/add/storylink'){
   return TRUE;
  }
}
return FALSE;

AND BINGO...i almost killed myself trying to figure this out...

mstef’s picture

The 'click here to view' link got messed up

it should be 'http://www.mysite.com/node/.'$nid

mstef’s picture

I just noticed one problem..

if the user is NOT logged in and users the remote button on a story that IS submitted, they wil not get redirected. They will have to press submit, then they will get the redirect link. I am trying to fix now.

mstef’s picture

I don't really know javascript but is there a way to clean this link up..

perhaps make it like

mstef’s picture

Sorry the last post got kinda messed up too..

Every other bookmarking site..when you hover, you see the actual link. Not 5 yards of javascript code. Is there a way you can make it nice like that..or atleast have the link like

solipsist’s picture

The JS results from the JS code being in the href="" and not handled with onClick. For more graceful degradation I suggest externalizing all JS in a separate file and then dynamically add an onclick event handler to the link tag which returns false so that it cancels the request. Users without JS enabled can still submit sites manually.

mstef’s picture

Could you explain how to do that exactly..I suck with javascript.

discursives’s picture

this is really interesting.

alexandreracine’s picture

Status: Active » Closed (fixed)

Not sure if I should close it, feel free to reopen.

Cleaning a little...

4.x versions are not supported anymore.

-You can upgrade
-You can sponsor future developpement of this module (look on the related pages on drupal.org)