Daily Lucky Numbers:
6
18
23
29
39
48

Recent posts

#1
General Code/Script Inquiries / Re: Retrieving a line from a t...
Last post by Chen Zhen - June 12, 2022, 11:20:08 PM
vbgamer has a mod that stores links in the database.
Its copyright allows me to edit it & post it on the forum.
I'm attaching it to this post so you can use it for your needs.

Mod Details:
- can change the permissions of adding/editing links to admin only (if that's your preference)
- BBCode option to allow you to use links as an ID#
- BBC membergroup permission is available for the admin which can set the permission to allow/disallow all BBC links as BBC (admin permissions)
- BBC membergroup permission to allow/disallow all BBC per category (mod admin)
- option to allow same window / external window for the BBC link
- each link shows its ID# to the left of its name in each category list
- each link shows its ID# in the edit link template
- option to provide a unique BBC name

If the membergroup has the permission to view the link & use the BBC then it will count the hits.
However if you only have the allow BBC checked then it will not count the hits.

 
#2
EhPortal Support / Re: Enable HTML Block or PHP b...
Last post by grandseb59 - June 12, 2022, 09:14:30 AM
ok thank you
#3
General Code/Script Inquiries / Re: Retrieving a line from a t...
Last post by Aaron - June 10, 2022, 11:17:38 AM
How would I do it via database? I originally thought of doing it that way but I thought a file would be easier to update/upload but not overloading my server is the number 1 priority lol
#4
General Code/Script Inquiries / Re: Retrieving a line from a t...
Last post by Chen Zhen - June 09, 2022, 08:18:42 PM
If you really need to use a .txt file then try this...

contents for file : list.txt
https://simplemachines.org, SMF
https://web-develop.ca, WebDev

BBCode insert for your SMF source file:
            array(
                'tag' => 'test',
                'type' => 'unparsed_content',
                'before' => '[test]',
                'after' => '[/test]',
                'validate' => function(&$tag, $url) {
                    if (preg_match('%([^"&?/ ])%i', $url, $match)) {
                        $f = fopen('./list.txt', 'r');
                        list($lines, $value) = array(array(), array());
                        if (!empty($f)) {
                            while (!feof($f)) {
                                $lines[] = fgets($f);
                            }
                            $lineValue = !empty($match[1]) && abs($match[1]) > 0 ? abs($match[1]) - 1 : 0;
                            if (!empty($lines[$lineValue])) {
                                $value = explode(',', $lines[$lineValue]);
                                $tag['content'] = !empty($value) && count($value) > 1 ? '<a href="' . $value[0] . '">' . $value[1] . '</a>' : '<a href="$1" class="bbc_link" target="_blank" rel="noopener">$1</a>';
                            }
                        }
                        if (count($value) < 2)
                            $tag['content'] = '<a href="$1" class="bbc_link" target="_blank" rel="noopener">$1</a>';
                    }
                    else
                        $tag['content'] = '<a href="$1" class="bbc_link" target="_blank" rel="noopener">$1</a>';
                },
                'trim' => 'both',
                'quoted' => 'optional',
            ),

I still included the link & text since it makes more sense to do it that way.
#5
General Code/Script Inquiries / Re: Retrieving a line from a t...
Last post by Chen Zhen - June 09, 2022, 06:15:39 PM
A more efficient way would be to store the data in your database.
Does the source have to be a text file?

If you must use a file why not a CSV file?
You can put the file into an array & then just use the key (line #) that you're after.

Here is an example of a file named list.csv that contains links with their text:
https://simplemachines.org, SMF
https://web-develop.ca, WebDev

Here is an example of your BBCODE that brings up a link by line #:
            array(
                'tag' => 'test',
                'type' => 'unparsed_content',
                'before' => '[test]',
                'after' => '[/test]',
                'validate' => function(&$tag, $url) {
                    if (preg_match('%([^"&?/ ])%i', $url, $match)) {
                        $rows = array_map('str_getcsv', file('./list.csv'));
                        $csv = array();
                        foreach ($rows as $row) {
                          $csv[] = $row;
                        }
                        $value = !empty($match[1]) && abs($match[1]) > 0 ? abs($match[1]) - 1 : 0;
                        $tag['content'] = !empty($csv[$value]) ? '<a href="'. $csv[$value][0] .'">' . $csv[$value][1] . '</a>' : '<a href="$1" class="bbc_link" target="_blank" rel="noopener">$1</a>';
                    }
                    else
                        $tag['content'] = '<a href="$1" class="bbc_link" target="_blank" rel="noopener">$1</a>';
                },
                'trim' => 'both',
                'quoted' => 'optional',
            ),


If you put something like this BBC:
Quote[test]1[/test]

.. it should show the following:
WebDev


I haven't tested this but you should have an idea of what to do.
Yes a lengthy file will cause a delay when using line breaks to separate data.
#6
General Code/Script Inquiries / Retrieving a line from a text ...
Last post by Aaron - June 08, 2022, 11:34:19 PM
I'm trying to figure out how to retrieve a specific line from a text file hosted on the root of my site through tags:

array(
'tag' => 'test',
'type' => 'unparsed_content',
'before' => '[test]',
'after' => '[/test]',
'validate' => function(&$tag, $url)
{
if (preg_match('%([^"&?/ ])%i', $url, $match)) {$file = file_get_contents("./list.txt"); $match = explode(PHP_EOL,$file); $array = array_filter($m); $value = $match[1];
$tag['content'] = '<a="'. $value .'">Test Link</a>';
}
else
$tag['content'] = '<a href="$1" class="bbc_link" target="_blank" rel="noopener">$1</a>';
},
'trim' => 'both',
'quoted' => 'optional',
),

Basically trying to have the number placed in the [test][/test] tags retrieve the line number (for example 123 retrieves 124 etc.) which will then be placed within the anchor. This code reads the text file but only retrieves line 2 (because of the $match[1]).

I'm also not sure if theres a more efficient way of doing this (currently the file is small at 18KB but will grow).

Thanks
#7
EhPortal Support / Re: Article to fetch Latest Po...
Last post by Aaron - June 07, 2022, 09:01:31 PM
Hi thank you very much it works perfect!
#8
EhPortal Support / Re: Article to fetch Latest Po...
Last post by Chen Zhen - June 05, 2022, 01:13:23 AM
This is just an example that you can tweak.

Create a board that has a profile setting of read only which will only allow admins to post in it.
Make your posts in that board that you want to appear on your front page block.

Now create a PHP block with the following code in it:
$admin_group_id = 0;
$admin_ids = array(1);
$board_ids = array(1);
$board_profile = 4;

//$query_where = 'mem.id_member IN ({array_int:admin_ids}) AND FIND_IN_SET({int:groupid}, b.member_groups) != 0 AND b.id_profile = {int:read_only} AND m.id_board IN ({array_int:board_ids})';

$query_where = 'mem.id_member IN ({array_int:admin_ids}) AND FIND_IN_SET({int:groupid}, b.member_groups) != 0 AND b.id_profile = {int:read_only}';
$query_where_params = array('groupid' => $admin_group_id, 'admin_ids' => $admin_ids, 'board_ids' => $board_ids, 'read_only' => $board_profile);
$query_limit = 10;
$query_order = 'm.id_msg DESC';
$limit_body = true;
$override_permissions = false;

$queryPosts = ehPortal_queryPosts($query_where, $query_where_params, $query_limit, $query_order, $output_method, $limit_body, $override_permissions);

function ehPortal_queryPosts($query_where, $query_where_params, $query_limit, $query_order, $limit_body, $override_permissions)
{
    global $scripturl, $txt, $user_info;
    global $modSettings, $smcFunc, $context;

    if (!empty($modSettings['enable_likes']))
        $context['can_like'] = allowedTo('likes_like');

    // Find all the posts. Newer ones will have higher IDs.
    $request = $smcFunc['db_query']('substring', '
        SELECT
            m.poster_time, m.subject, m.id_topic, m.id_member, m.id_msg, m.id_board, m.likes, b.name AS board_name, b.member_groups, b.id_profile,
            COALESCE(mem.real_name, m.poster_name) AS poster_name, ' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
            COALESCE(lt.id_msg, lmr.id_msg, 0) >= m.id_msg_modified AS is_read,
            COALESCE(lt.id_msg, lmr.id_msg, -1) + 1 AS new_from') . ', ' . ($limit_body ? 'SUBSTRING(m.body, 1, 384) AS body' : 'm.body') . ', m.smileys_enabled
        FROM {db_prefix}messages AS m
            INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)' . ($modSettings['postmod_active'] ? '
            INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)' : '') . '
            LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!$user_info['is_guest'] ? '
            LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = {int:current_member})
            LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = m.id_board AND lmr.id_member = {int:current_member})' : '') . '
        WHERE 1=1 ' . ($override_permissions ? '' : '
            AND {query_wanna_see_board}') . ($modSettings['postmod_active'] ? '
            AND m.approved = {int:is_approved}
            AND t.approved = {int:is_approved}' : '') . '
        ' . (empty($query_where) ? '' : 'AND ' . $query_where) . '
        ORDER BY ' . $query_order . '
        ' . ($query_limit == '' ? '' : 'LIMIT ' . $query_limit),
        array_merge($query_where_params, array(
            'current_member' => $user_info['id'],
            'is_approved' => 1,
        ))
    );
    $posts = array();
    while ($row = $smcFunc['db_fetch_assoc']($request))
    {
        $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

        // Censor it!
        censorText($row['subject']);
        censorText($row['body']);

        $preview = strip_tags(strtr($row['body'], array('<br>' => '&#10;')));

        // Build the array.
        $posts[$row['id_msg']] = array(
            'id' => $row['id_msg'],
            'board' => array(
                'id' => $row['id_board'],
                'name' => $row['board_name'],
                'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
                'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
            ),
            'topic' => $row['id_topic'],
            'poster' => array(
                'id' => $row['id_member'],
                'name' => $row['poster_name'],
                'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
                'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
            ),
            'subject' => $row['subject'],
            'short_subject' => shorten_subject($row['subject'], 25),
            'preview' => $smcFunc['strlen']($preview) > 128 ? $smcFunc['substr']($preview, 0, 128) . '...' : $preview,
            'body' => $row['body'],
            'time' => timeformat($row['poster_time']),
            'timestamp' => $row['poster_time'],
            'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
            'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">' . $row['subject'] . '</a>',
            'new' => !empty($row['is_read']),
            'is_new' => empty($row['is_read']),
            'new_from' => $row['new_from'],
        );

        // Get the likes for each message.
        if (!empty($modSettings['enable_likes']))
            $posts[$row['id_msg']]['likes'] = array(
                'count' => $row['likes'],
                'you' => in_array($row['id_msg'], prepareLikesContext($row['id_topic'])),
                'can_like' => !$context['user']['is_guest'] && $row['id_member'] != $context['user']['id'] && !empty($context['can_like']),
            );
    }
    $smcFunc['db_free_result']($request);   

    echo '
        <div style="width: 100%;overflow: hidden;">
            <div style="width: 100%;text-align: center;margin: 0 auto;color: blue;font-size: 1.5em;text-decoration: underline;padding: 1em;">IMPORTANT POSTS</div>';
    foreach ($posts as $post) {
        $date = date('Y-m-d', $post['timestamp']);
        echo '
            <div>Board: ' . $post['board']['link'] . '</div>
            <div>Topic: ' . $post['link'] . '</div>
            <div>Author: ' . $post['poster']['link'] . '</div>
            <div>Date: ' . $date . '</div>
            <hr />';
    }
    echo '
        </div>';
}



You can change the $query_where, $query_where_params and the database SELECT to filter what you're trying to display.
The above finds the latest 10 posts from member id #1 (more can be added to the array) & admin group id 0 in boards set to read-only. 
I put in $board_ids to help show you as an example but the above query doesn't use it because that string is commented out.
#9
EhPortal Support / Re: Article to fetch Latest Po...
Last post by Chen Zhen - June 04, 2022, 10:43:55 PM

I can help you with a PHP block that will contain some specifics for the query.

The ssi_queryPosts function in SSI.php sounds like it will do what you want.
You just need to give it arguments to target your query.
#10
EhPortal Support / Article to fetch Latest Post i...
Last post by Aaron - May 29, 2022, 06:38:34 PM
Hi, I'm using Ehportal currently which is working great. I was wanting to make the home/portal page to display the latest posts from certain topics (topics only I/the admin can post in), which would then of course display the latest post at the top (regardless of which topic it is).

Is this doable for the Article feature or would it be better instead to make a php/html block for display on the home/portal page instead and specify topics by ID that way?

Thank you