WebDev

SMF Modifications => General Code/Script Inquiries => Topic started by: replikacep on February 14, 2022, 03:14:01 PM

Title: phg7.3 and above need help
Post by: replikacep on February 14, 2022, 03:14:01 PM



if (!empty($modSettings['enable_pretty_topics']) && !empty($modSettings['enable_pretty_urls']))
    {
        preg_match_all('/"'.preg_quote($scripturl, '/').'\?topic=([0-9]*).*?"/e', $buffer, $temp_topics, PREG_PATTERN_ORDER);
       
        $topic_pattern = $boardurl . '/{B_NAME}{TOPIC_SUBJECT}-t{TOPIC_ID}.{TREST}.html{OTHER}';
       
        if (isset($temp_topics))
        {
            $temp_topics = array_unique($temp_topics[1]);
            foreach ($temp_topics as $index => $value)
            {
                $temp_topics[$index] = (int) $value;
               
                if ($value == 0)
                    unset($temp_topics[$index]);
            }
        }
       
        if (!empty($temp_topics))
        {
            $request = $smcFunc['db_query']('', '
            SELECT m.id_topic, m.id_board, m.subject' . ((!empty($modSettings['seo4smf_topic_board'])) ? ',b.name' : '') . '
            FROM {db_prefix}topics as t
                LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
                ' . ((!empty($modSettings['seo4smf_topic_board'])) ? 'LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)' : '') . '
            WHERE t.id_topic IN ({array_int:topics_array})',
                array
                (
                    'topics_array' => $temp_topics,
                )
            );
       
            if ($smcFunc['db_num_rows']($request) != 0)
            {
                $topic_array = array();
                while ($row = $smcFunc['db_fetch_assoc']($request))
                {
                    $topic_array[$row['id_topic']] = array(
                        'subject' => format_url($row['subject']),
                        'board' => (isset($row['name'])) ? format_url($row['name']) : '',
                        'board_id' => $row['id_board'],
                        'topic' => $row['id_topic'],
                    );
                }
                $smcFunc['db_free_result']($request);
               
                $find_topics = array();
                $replaces_topics = array();
                   
                if (!empty($modSettings['seo4smf_topic_board'])) {
                    foreach ($topic_array as $id => $values)
                    {
                        $find_topics[] = '"' . preg_quote($scripturl, '/') . '\?topic=(' . preg_quote($id, '/') . ')\.([0-9]+)"';
                        $replaces_topics[] = str_replace(array('{B_NAME}', '{TOPIC_SUBJECT}', '{TOPIC_ID}', '{TREST}', '{OTHER}'), array($values['board'].'/', $values['subject'], $id, '$2', ''), $topic_pattern);
                       
                        $find_topics[] = '"' . preg_quote($scripturl, '/') . '\?topic=(' . preg_quote($id, '/') . ')\.((?:from|msg[0-9]+|new))"';
                        $replaces_topics[] = str_replace(array('{B_NAME}', '{TOPIC_SUBJECT}', '{TOPIC_ID}', '{TREST}', '{OTHER}'), array($values['board'].'/', $values['subject'], $id, 0, ';$2'), $topic_pattern);
                    }
                }
                else {
                    foreach ($topic_array as $id => $values)
                    {
                        $find_topics[] = '"' . preg_quote($scripturl, '/') . '\?topic=(' . preg_quote($id, '/') . ')\.([0-9]+)"';
                        $replaces_topics[] = str_replace(array('{B_NAME}', '{TOPIC_SUBJECT}', '{TOPIC_ID}', '{TREST}', '{OTHER}'), array('', $values['subject'], $id, '$2', ''), $topic_pattern);
                       
                        $find_topics[] = '"' . preg_quote($scripturl, '/') . '\?topic=(' . preg_quote($id, '/') . ')\.((?:from|msg[0-9]+|new))"';
                        $replaces_topics[] = str_replace(array('{B_NAME}', '{TOPIC_SUBJECT}', '{TOPIC_ID}', '{TREST}', '{OTHER}'), array('', $values['subject'], $id, 0, ';$2'), $topic_pattern);
                    }
                }
               
                if (!empty($find_topics) && !empty($replaces_topics))
                    $buffer = preg_replace($find_topics, $replaces_topics, $buffer);
            }
            else $smcFunc['db_free_result']($request);
        }
    }
   
    if (!empty($modSettings['enable_pretty_profiles']) && !empty($modSettings['enable_pretty_urls']))
    {
        preg_match_all('/"'.preg_quote($scripturl, '/').'\?action=profile;u=([0-9]+)"/e', $buffer, $temp_profiles, PREG_PATTERN_ORDER);
             
        if (isset($temp_profiles))
        {
            $temp_profiles = array_unique($temp_profiles[1]);
            $profiles = array();

            foreach ($temp_profiles as $index => $value)
            {   
                $temp_profiles[$index] = (int) $value;
                if ($value == 0)
                    unset($temp_profiles[$index]);
            }
        }




https://www.php.net/manual/tr/function.preg-replace-callback.php

can you help me how can i adapt this in php 7.3 and php 7.4 please help

The mod I'm trying to sleep with is attached

Title: Re: phg7.3 and above need help
Post by: Chen Zhen on February 14, 2022, 10:03:44 PM
QuoteThe mod I'm trying to sleep with is attached

 ;D  ;D
Google translate didn't do you well with that statement. I'm not a fan of Pretty URL's since it can cause too many issues with other mods but to each their own.

The e-modifier has been deprecated since PHP 7.0 but I suppose it was previously only throwing warnings.
I can look at this tomorrow to change it to a callback but did you look for an update to that mod? I thought I saw an update for it post PHP 7 release.
Title: Re: phg7.3 and above need help
Post by: replikacep on February 15, 2022, 05:14:58 AM
I would be very grateful if you could help me with the mod update.
mod works for now 7.0 and 7.2 also works fine:)
but 7.3 and 7.4 also give an error in the error log

I don't own the mod, I'm improving myself
The owner of the mod has not been on the market for 5 years

How would I talk to you if it wasn't for google translate? :o
Title: Re: phg7.3 and above need help
Post by: Chen Zhen on February 15, 2022, 10:33:51 PM

I just looked at the code snippet you provided and from what I can see the /e modifier wasn't needed.
Those 2 preg_match_all searches are just to return arrays containing topics id's and user id's.
All you need to do is remove the /e modifier.

preg_match_all('/"'.preg_quote($scripturl, '/').'\?topic=([0-9]*).*?"', $buffer, $temp_topics, PREG_PATTERN_ORDER);
preg_match_all('/"'.preg_quote($scripturl, '/').'\?action=profile;u=([0-9]+)"', $buffer, $temp_profiles, PREG_PATTERN_ORDER);
Title: Re: phg7.3 and above need help
Post by: replikacep on February 16, 2022, 06:14:13 AM
 Guest

e3d6a2661b43f3c24a45888561b0d818
https://www.replikacep.com/index.php?dummy=1&topic=31498.0
/home/replikac/public_html/Seo4Smf.php (Line 859)
Backtrace information

Type of error: General
Error message Select
2: preg_match_all(): No ending delimiter '/' found

i did what you said

i am getting this type of error in the error log
Title: Re: phg7.3 and above need help
Post by: replikacep on February 16, 2022, 07:36:53 AM
Seo4Smf.php


BUL : preg_match_all('/"'.preg_quote($scripturl, '/').'\?topic=([0-9]*).*?"/e', $buffer, $temp_topics, PREG_PATTERN_ORDER);
DEGİŞ : preg_match_all('"'.preg_quote($scripturl, '/').'\?topic=([0-9]*).*?"', $buffer, $temp_topics, PREG_PATTERN_ORDER);
BUL : preg_match_all('/"'.preg_quote($scripturl, '/').'\?action=profile;u=([0-9]+)"/e', $buffer, $temp_profiles, PREG_PATTERN_ORDER);
DEGİŞ . preg_match_all('"'.preg_quote($scripturl, '/').'\?action=profile;u=([0-9]+)"', $buffer, $temp_profiles, PREG_PATTERN_ORDER);

THE WAY I MADE

THANK YOU VERY MUCH PROBLEM SOLVED
Title: Re: phg7.3 and above need help
Post by: replikacep on February 16, 2022, 09:35:13 AM

For some reason I can't run the above codes.

I need to be able to show it in the footer, can you help me with this?

It works in rc2, I couldn't run it in 2.1.1, I couldn't figure out what kind of logic my friend used

sorry i'm making you do extra work  :-[ 
Title: Re: phg7.3 and above need help
Post by: Chen Zhen on February 16, 2022, 12:12:25 PM
I must have made an error in the regex and glad you figured it out.
I'll look at the other code later today.
Title: Re: phg7.3 and above need help
Post by: replikacep on February 16, 2022, 05:38:35 PM
I edited the mod with your help, thanks

If we solve the last problem, there will be no more problems.  :-[
Title: Re: phg7.3 and above need help
Post by: Chen Zhen on February 16, 2022, 09:22:18 PM
Replace exactly what you posted with this:

// add possible SMF links to this array
$searchLinks = array(
'<a href="https://www.simplemachines.org" title="Simple Machines" target="_blank" class="new_win">Simple Machines</a>',
'<a href="https://www.simplemachines.org" title="Simple Machines" target="_blank" rel="noopener">Simple Machines</a>',
);
$code = '';
if (!empty($modSettings['seo4smf_enable_sitemap']) && !empty($modSettings['seo4smf_sitemap_show']) && $modSettings['seo4smf_sitemap_show'] != 2)
$code = ' | <a href="' . $scripturl . '?action=sitemap" title="' . $txt['seo4smf_sitemap'] . '">' . $txt['seo4smf_sitemap'] . '</a>';
$code = ' <a href="http://www.smf.gen.tr/smf/index.php" title="Smf Destek" target="blank_">Seo4Smf &copy; Smf.Gen.Tr</a>' . $code;
$code = ' <a href="https://www.replikacep.com" title="Replikacep.com" target="blank_">|</a>' . $code;

foreach ($searchLinks as $search) {
$pos = strrpos($buffer, $search);
if (strpos($buffer, $code) === false && $pos !== false) {
$buffer = substr_replace($buffer, $search . $code, $pos, strlen($search));
break;
}
}
if (!empty($what_to_search))
$buffer = preg_replace($what_to_search, $what_to_replace, $buffer);

return $buffer;
}
Title: Re: phg7.3 and above need help
Post by: replikacep on February 17, 2022, 12:51:49 AM
YOU ARE THE KING MAN  :) THANK YOU VERY MUCH  :)
I am very grateful for your help
Title: Re: phg7.3 and above need help
Post by: Chen Zhen on February 18, 2022, 06:13:09 PM
I'll give you something a bit better that will allow you to insert links at the bottom of the page.
You seem to have some basic knowledge of PHP so perhaps you can understand how to apply this code.

Since SMF changes their copyright hyperlink attributes at times with their version releases, the following code should be able to pick it up.
This is assuming they keep the "href" the same but possibly change the id or some other attribute.

Add this function prior the the ?> at the end of the file:
function smfAppendLinks($linksArray, $afterLink, $buffer)
{
    // DOM method
    $linksArray = array_reverse($linksArray, false);
    list($links, $i) = array(array(), 0);
    $dom = new DOMDocument();
    libxml_use_internal_errors(true);
    $dom->loadHTML($buffer);
    $nodes = $dom->getElementsByTagName('a');
    foreach ($nodes as $node) {
        $href = $nodes->item($i)->getAttribute('href');
        if (substr($href, 0, strlen($afterLink)) == $afterLink)
            $links[] = array('id' => $i, 'href' => $href);
        $i++;
    }

    if (!empty($links)) {
        $key = array_key_last($links);
        $x = $links[$key]['id'];
        foreach ($linksArray as $link) {
            $nodex = $dom->createElement("a", $link['text']);
            $nodex->setAttribute('href', $link['href']);
            if (!empty($link['title']))
                $nodex->setAttribute('title', $link['title']);
            if (!empty($link['target']))
                $nodex->setAttribute('target', $link['target']);
            if (!empty($link['style']))
                $nodex->setAttribute('style', $link['style']);
            if (!empty($link['class']))
                $nodex->setAttribute('class', $link['class']);
            $nodes->item($x)->parentNode->insertBefore($nodex, $nodes->item($x)->nextSibling);
            if (!empty($link['partition'])) {
                $textNode = $dom->createTextNode($link['partition']);
                $nodes->item($x)->parentNode->insertBefore($textNode, $nodes->item($x)->nextSibling);
            }
        }

    }
    $buffer = $dom->saveHTML();
    return $buffer;
}

As an example, it can be used by replacing the code you posted above with this:
list($linksArray, $afterLink) = array(array(), 'https://www.simplemachines.org');
$linksArray[] = array('href' => 'https://www.replikacep.com', 'title' => 'Android Telefon Yazılım Rom Destek Teknoloji Sitesi', 'target' => 'blank_', 'text' => 'Replikacep', 'partition' => ' | ', 'class' => '', 'style' => 'cursor: pointer;');
$linksArray[] = array('href' => 'http://www.smf.gen.tr/smf/index.php', 'title' => 'Smf Destek', 'target' => 'blank_', 'text' => 'Seo4Smf &copy; Smf.Gen.Tr', 'partition' => ' | ', 'class' => '', 'style' => 'cursor: pointer;');
if (!empty($modSettings['seo4smf_enable_sitemap']) && !empty($modSettings['seo4smf_sitemap_show']) && $modSettings['seo4smf_sitemap_show'] != 2) {
$linksArray[] = array('href' => $scripturl . '?action=sitemap', 'title' => $txt['seo4smf_sitemap'], 'target' => 'blank_', 'text' => $txt['seo4smf_sitemap'], 'partition' => ' | ', 'class' => '', 'style' => 'cursor: pointer;');
}
return smfAppendLinks($linksArray, $afterLink, $buffer);
}
Title: Re: phg7.3 and above need help
Post by: replikacep on February 21, 2022, 01:32:39 AM
Thanks for your valuable information

you helped me, thank you, good luck :)
Title: Re: phg7.3 and above need help
Post by: replikacep on February 21, 2022, 06:14:51 AM
Merhaba,

paylaşım için teşekkürler  modu indirip denedim kurulumda sorun yok fakat 3 tane açık var

Title: Re: phg7.3 and above need help
Post by: Chen Zhen on February 21, 2022, 03:26:30 PM
3 open what?
I don't use the mod so you'll have to be more specific.
Title: Re: phg7.3 and above need help
Post by: replikacep on February 21, 2022, 03:58:02 PM
Quote from: Chen Zhen on February 21, 2022, 03:26:30 PM3 open what?
I don't use the mod so you'll have to be more specific.

Someone warned me that there may be an important open in the coding for 3 modes, that is, hacking, do you think there is any open in the codes?

Edit : Do you think there is a security vulnerability in the codes I posted, can you help me?
Title: Re: phg7.3 and above need help
Post by: Chen Zhen on February 21, 2022, 04:43:21 PM
The mod seems to have been removed from the SMF mod site.
I've read about vulnerabilities due to non-sanitized URL input used for SQL injection.
However SMF's smcFunc should sanitize the data, I don't know if the mod uses it or does direct DB commands
I'll need your copy of the mod to look at it.

Unless you are willing to use an updated SEO mod from SMF?
Title: Re: phg7.3 and above need help
Post by: replikacep on February 21, 2022, 04:51:11 PM
BuyurunSeo4SMF 2.1 FÄ°NAL.zip


I don't think it's a security hole, but it's good to have a look.
Title: Re: phg7.3 and above need help
Post by: Chen Zhen on February 21, 2022, 08:29:59 PM

I think the exploit flag for that mod may be for a prior version, perhaps when it was used on the SMF 1 branch.
At a glance I don't see any serious issue but I may not be seeing it if it exists.

For the attachment:

I added the DOM version of the copyright additions.
If you want line breaks instead of " | ", I can show you how to do that with that function.
I'm not sure if you're keeping that other mod installed so you can change it to look for that other URL if you want.
Also I removed the installation mysql file edit for no connection since I don't see the point of it.
I added a bit of code to ensure integer values from the URL request.
That's about it.
 

Title: Re: phg7.3 and above need help
Post by: replikacep on February 22, 2022, 01:27:06 PM
sitemap won't work
I think there is something wrong where you did it.

there is a problem with the lines you added

Title: Re: php7.3 and above need help
Post by: Chen Zhen on February 22, 2022, 07:17:04 PM
It wasn't loading your language file plus the hooks weren't being removed when the mod is uninstalled but opt to keep settings.
Here is an amended package...
Title: Re: phg7.3 and above need help
Post by: replikacep on February 24, 2022, 07:02:42 AM
i couldn't get the sitemap to work so i gave up on using it
Title: Re: phg7.3 and above need help
Post by: Chen Zhen on February 24, 2022, 07:03:01 PM


Now I see what I did wrong because the function I added a DOM parser to doubles for HTML & XML content.

So when you click the sitemap link, it shows a list of boards in HTML and if you then opt the XML link it shows a bunch of topics in XML format. Is this correct?

I'd like you to try this copy...
 
Title: Re: phg7.3 and above need help
Post by: replikacep on February 25, 2022, 02:53:47 AM
https://katmulkiyet.net/index.php?action=sitemap;xml

the sitemap does not work, it only has English support and moreover, it does not attract the topics.
Title: Re: phg7.3 and above need help
Post by: Chen Zhen on February 25, 2022, 07:08:38 PM
The way I tried to detect a XML string was not good.
Ok, try this package...
Title: Re: phg7.3 and above need help
Post by: replikacep on February 26, 2022, 07:12:42 AM
this is working:  Disable XML Enhanced Look
If your XML sitemap is not working as expected try enabling this



this is not working : Enable XML Sitemap?

I'm throwing the admin password privately


sshot-1.png


https://katmulkiyet.net/index.php?action=sitemap;xml
Title: Re: phg7.3 and above need help
Post by: Chen Zhen on February 26, 2022, 12:41:30 PM
I'll look at this later today.
With the admin access, I can now test it myself.
Title: Re: phg7.3 and above need help
Post by: replikacep on March 01, 2022, 04:38:44 AM
Quote from: Chen Zhen on February 26, 2022, 12:41:30 PMI'll look at this later today.
With the admin access, I can now test it myself.

Sanırım unutma
Quote from: Chen Zhen on February 26, 2022, 12:41:30 PMI'll look at this later today.
With the admin access, I can now test it myself.

i think you forgot
EhPortal 1.39.6 © 2024, WebDev