Welcome to Geeklog Monday, March 18 2019 @ 11:48 am EDT

Geeklog Forums

Article Number Search block


Status: offline

miklos

Forum User
Newbie
Registered: 16/09/04
Posts: 9
Hi,

I've set up an extra article number in gl_stories as described in this thread:

http://www.geeklog.net/forum/viewtopic.php?forum=3&showtopic=41336

Basically, it's just an auto-incrementing unique number for each story (1, 2, 3 etc.)

I'd like to make a block which has an HTML form that will take an article number as input, and transport the user to the corresponding article. The script would do something like this, I think:

1. Get the Article Number from the HTML form

2. Make sure it's a number between 1 and the highest article number

3. Find out what the corresponding story ID (sid) in gl_stories is from the entered article number (article_number)

4. Send the user to http://mysite.com/article.php?story=$sid_that_corresponds_to_user-entered_article_number

How would I go about doing this? Would it work by putting the code in lib-custom, or should I make a special article_number_search_handler.php file at the top level of my site? Any advice on the actual code would be welcome too!

Thanks for reading this.

Status: offline

machinari

Forum User
Full Member
Registered: 22/03/04
Posts: 1512
Tell me what is the name of your article number column and I'll do it.. actually I've just done it.

wouldn't it make more sense though just to have a dropdown of article titles and then choose from those? else how does one know an article based upon a number?

Status: offline

miklos

Forum User
Newbie
Registered: 16/09/04
Posts: 9
Wow, thanks Machinari! My article number column in gl_stories is called "article_number".

The reason I wanted to do this is sort of to provide an easy bibliographic reference on a site where there's hundreds of articles, and the titles aren't real descriptive - so, for example, my professor could put on a take-home exam, "Go to #32 and translate," or "Find three items on the website that have some linguistic feature and list their numbers..."

Anyway, thanks again for this, and for your enlightening contributions to the "article numbering" thread.

Best,
miklos

Status: offline

machinari

Forum User
Full Member
Registered: 22/03/04
Posts: 1512
cool, create a php block named according to the following function. It's a bit of an ugly refresh, but it will do you I think. The only way around the refresh is to integrate this into your index.php. This is a good place to start tho.
I've not tested it so let me know.
PHP Formatted Code

/*
redirects a user to a given article number.
articles must be numbered to work.
*/

function phpblock_gotoArticleNumber(){
    global $_TABLES, $_CONF;

    //get input
    if(isset($_POST['articleNum'])){
        $articleNum = COM_applyFilter($_POST['articleNum'],true);
        if(!empty($articleNum)){
            //respond to input
            $articleID = DB_getItem($_TABLES['stories'], 'sid', "article_number='$articleNum'");
            if(!empty($articleID)){
                $articleURL = $_CONF['site_url'] . '/article.php?story=' . $articleID;
                return COM_refresh('$articleURL');
            }
        }
    }

    //display form
    $thispage = COM_getCurrentURL();
    $display = '<form action="' . $thispage . '" method="POST">' . LB
            . '<input type="submit" value="Go to Article#" />' . LB
            . '<input type="textbox" size="3" name="articleNum" />' . LB
            . '</form>' . LB;

    return $display;
}

 

Status: offline

miklos

Forum User
Newbie
Registered: 16/09/04
Posts: 9
Hi machinari,

When I try it, it redirects me to

http://mysite.com/$articleURL

...which gives a 404. (I'd give the actual URL but it's currently on an unaccessible intranet).

When I'm logged in and at the Blocks admin page, it redirects me to

http://mysite.com/admin/$articleURL

I'm pretty sure I copied and pasted it correctly...I was thinking at first that I should change this line:

$articleID = DB_getItem($_TABLES['stories'], 'sid', &quot;article_number='$articleNum'&quotWink;

to this:

$articleID = DB_getItem($_TABLES['gl_stories'], 'sid', &quot;article_number='$articleNum'&quotWink;

...but that writes an error to error.log, so I'm not too sure what the problem is.

Thanks a lot though - it'll be perfect when it works! Big Grin

Status: offline

machinari

Forum User
Full Member
Registered: 22/03/04
Posts: 1512
sorry miklos, change COM_refresh('$articleURL') to COM_refresh($articleURL). Just remove the single quotes. I had them in there for testing a url and forgot to take them out when I put in the variable.

Status: offline

miklos

Forum User
Newbie
Registered: 16/09/04
Posts: 9
Thanks machinari! It's now perfect. Excellent!

All times are EDT. The time is now 11:48 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content