Daily Lucky Numbers:
8
11
19
29
40
42

phg7.3 and above need help

Started by replikacep, February 14, 2022, 03:14:01 PM

Previous topic - Next topic

replikacep




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


Chen Zhen

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.

replikacep

#2
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

Chen Zhen


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);

replikacep

 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

replikacep

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

replikacep

#6

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  :-[ 

Chen Zhen

I must have made an error in the regex and glad you figured it out.
I'll look at the other code later today.

replikacep

I edited the mod with your help, thanks

If we solve the last problem, there will be no more problems.  :-[

Chen Zhen

#9
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;
}

replikacep

YOU ARE THE KING MAN  :) THANK YOU VERY MUCH  :)
I am very grateful for your help

Chen Zhen

#11
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);
}

replikacep

Thanks for your valuable information

you helped me, thank you, good luck :)

replikacep

#13
Merhaba,

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


Chen Zhen

3 open what?
I don't use the mod so you'll have to be more specific.