Jump to content

Need help with an ancient news CMS [flat files for db, no mysql]


xDx

Recommended Posts

CuteNews is an ancient news CMS that has not seen an update in years and it's support forums are dead. I have experience with it from long ago and I decided to make a website (a diary of sorts) where I upload daily stuff. My site is ready, I have been using it for a while now (over 160 articles), fixed some deprecated php errors (by trial and error, because I'm an absolute ape), but there is one thing that I cannot figure out by myself. So CuteNews has a feature where you can archive your news/articles and then when you search for something there's a checkbox to search in the archives. I tried everything and it just won't work. I'm using PHP Version 7.4.29, if I had to guess its something to do with that. I have not modified any related files, been looking at the code all day and I'm almost ready to throw in the towel and give up on archiving. If you can please take a look at the attached .txt file and tell me if you see anything wrong.

// Variables by default
list($template, $dosearch, $search, $user, $archives) = GET('template, dosearch, search, user, archives');
list($search_st, $number, $category_exclude) = GET('search_st, number, category_exclude', 'GPG');
list($_fd, $_fm, $_fy) = GET('from_date_day, from_date_month, from_date_year');
list($_td, $_tm, $_ty) = GET('to_date_day, to_date_month, to_date_year');

Both $user and $archives do not seem to be working. Otherwise the search functions properly.

if ($dosearch)
{
    $mc_start = microtime(true);

    // Remove parameters for go to news from searchbox
    $_static_qr = 'dosearch,archives,search,from_date_year,from_date_month,from_date_day,to_date_year,to_date_month,to_date_day,search_st,number,archive,template';

    $st = -1;
    $_next_link = FALSE;
    $_number    = $number;
    $archive_id = 0;

    // get archive list
    $_list_archives = db_get_archives();
    krsort($_list_archives);
    reset($_list_archives);

    $news = db_index_load('');
    $c_time = ctime();
    $itemid = 0;

    if (strlen($search) < 3)
    {
        echo "<div>Too short request!</div>";
    }
    else
    {
        $block = '';
        $found = 0;

        do
        {
            reset($news);

            // repeat, while data exists
            while ($news)
            {
                // pop top element
                $id = key($news);
                unset($news[$id]);

                if ($id > $c_time) continue;
                if ($id < $date_from || $id > $date_to) continue;

                $nbp = db_get_nloc($id);
                if ($block !== $nbp)
                    $ent = db_news_load($block = $nbp);

                // @syslog internal error
                if (empty($ent)) continue;

                $item = $ent[$id];

                // Check category (exclude for search)
                if ($item['c']) {
                    $categories = explode(',', $item['c']);
                    if (isset($category_exclude) && array_intersect($categories, $category_exclude)) {
                        continue;
                    }
                }

                $MB = function_exists('mb_strtolower');

                $Ts = $MB ? mb_strtolower($item['t'], 'UTF-8') : strtolower($item['t']);
                $Fs = $MB ? mb_strtolower($item['f'], 'UTF-8') : strtolower($item['f']);
                $Ss = $MB ? mb_strtolower($item['s'], 'UTF-8') : strtolower($item['s']);

                $_query = spsep($search, ' ');
                foreach ($_query as $_id => $_val) $_query[$_id] = preg_quote($_val, '/');

                // By user, but user not match
                if ($user && !$user != $item['u'])
                    continue;

                // Query string not found
                if (!preg_match('/'.join('.*?', $_query).'/uis', $Fs . $Ss . $Ts))
                    continue;

                $st++;
                if ($st < $search_st) continue;

                if ($found == 0)
                    echo "<p class='cutenews_found_news'>".i18n('Search results for')." &quot;".cn_htmlspecialchars($search)."&quot;</p><div class='cn_search_body'>";

                $found++;
                $title = cn_htmlspecialchars($item['t']);

                // Call: id, archiveid, template
                if (getoption('rw_engine'))
                {
                    $url = cn_rewrite('full_story', cn_put_alias($id));
                    if (getoption('search_hl')) $url .= "?qhl=".urlencode($search);
                }
                else
                {
                    if (getoption('search_hl'))
                        $url = cn_url_modify($_static_qr, 'id='.$id, "qhl=".urlencode($search));
                    else
                        $url = cn_url_modify($_static_qr, 'id='.$id);
                }

                $itemid++;
                echo "<div class='cutenews_search_item'>$itemid <b><a href='$url'>$title</a></b> (". date("d F, Y", $id) .")</div>";

                $_number--;
                if ($_number == 0)
                {
                    $_next_link = TRUE;
                    break 2;
                }
            }

            // Next archive, if present
            if ($archives && count($_list_archives))
            {
                $archive_id = key($_list_archives);

                // Load ID from archives
                $news = array_keys(db_index_load("archive-$archive_id"));
                krsort($news);

                unset($_list_archives[$archive_id]);
            }
            // Only in active news, or no archives left
            else break;
        }
        while (TRUE);

        // show results ------------
        if (!$found)
        {
            echo "<p class='cutenews_not_match'>".i18n('There are no news articles matching your search criteria')."</p>";
        }
        else
        {   // Close "cn_search_body"
            echo "</div>";
        }

        echo '<div class="cn_paginate_search">';
        $__PHP_SELF = $PHP_SELF; $PHP_SELF = $_SERVER['SCRIPT_NAME'];
        if ($search_st - $number >= 0 && $number) echo ' <a href="'.cn_url_modify('search_st='.($search_st - $number)).'">&lt;&lt; Prev</a> ';
        if ($search_st) echo ' (skip <b class="search_skip">'.$search_st.'</b> items) ';
        if ($_next_link) echo ' <a href="'.cn_url_modify('search_st='.($search_st + $number)).'">Next &gt;&gt;</a>';
        $PHP_SELF = $__PHP_SELF; unset($__PHP_SELF);
        echo '</div>';
    }

    echo '<p class="cutenews_search_results"><i>'.i18n('Search performed for').' '.round(microtime(true) - $mc_start, 4).' s.</i></p>';
}

return TRUE;

 

Screenshot 2022-06-01 at 22-42-35.png

search.txt

Link to comment
Share on other sites

I'm not that interested in looking at a defunct project, but the obvious question of where to start, would be -- have you for example, started with this line:

 

$_list_archives = db_get_archives();

Have you dumped the result of that call and examined the data structure?  

Using this technique follow through the code, and anywhere that you expect archive or user processing to occur, do a print_r or var_dump and see what you can find.  Alternatively if you have the option of xdebug setup, you could add a breakpoint and step through the code interactively. 

Link to comment
Share on other sites

Certainly not trying to be an ass, but if it's so old the support forums are defunct you can pretty much guarantee there are major issues with it. I'd have to bet the biggest problem you're running into is that PHP has moved on - php 5 will mostly work on a php 7.x environment, but I wouldn't bet the bank on it.

If you value your time, change your CMS - there are a lot out there. WordPress is everywhere and simple to use, so there is a ton of documentation as well as an absolute boatload of themes and plugins. If you're being safe it's not quite plug-n-play, and I do recommend reading the reviews on any themes and plugins you may use, but it's a decent starting place if you just want a site up. With just over 160 articles, it shouldn't be too difficult to migrate (even manually). And at least you won't have to spend most of your time trying to duct tape defunct and deprecated code while simultaneously putting the entire server in harm's way by using dangerously out-of-date code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.