[3.3][BETA] Calendar Tag

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Anti-Spam Guide
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

[3.3][BETA] Calendar Tag

Post by martti »

Extension Name: Calendar Tag
Author: martti
Extension Description:
This phpBB extension produces highly configurable Calendar Date Tags next to the topic titles for the Calendar Extension Set
Extension Version: 0.3.0
Requirements: When it's not possible for you to have PHP compiled with --enable-calendar see the PHP Ext Calendar extension for a solution.

Extension Download: https://github.com/marttiphpbb/phpbb-ex ... master.zip The files are to be put into ext/marttiphpbb/calendartag
Github repository: https://github.com/marttiphpbb/phpbb-ext-calendartag
Languages: en
Templates: Prosilver (others may work)
Screenshots:

Viewtopic:

Image

Viewforum

Image

MCP

Image

ACP Placement

Image

ACP Format

Image

ACP Template
Image
Last edited by martti on Wed Apr 08, 2020 9:53 am, edited 3 times in total.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.2][BETA] Calendar Tag

Post by martti »

New version 0.2.0 fixes the right padding with zero problem.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.3][BETA] Calendar Tag

Post by martti »

New version 0.3.0 is for phpBB 3.3+
sidik
Registered User
Posts: 2
Joined: Sun Jan 24, 2021 8:22 pm

Re: [3.3][BETA] Calendar Tag

Post by sidik »

I have some personal customization of PhpBB and I have a custom view on topics with their posts in one special forum, where there are topics with calendar mono events. It is inspired here. And I would like to insert the event date range into topic description the same way it looks in the standard topic view.

Is it possible to insert it by some easy way? I can take the columns with event data from topic table and manually convert it to string and insert in the page, but it will not be so sophistic and driven by extension configuration. Here is my external page:

Code: Select all

<?php
/**
 *
 * This file is part of the phpBB Forum Software package.
 *
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
 * @license GNU General Public License, version 2 (GPL-2.0)
 *
 * For full copyright and license information, please see
 * the docs/CREDITS.txt file.
 *
 */

/**
 */

/**
 * @ignore
 */
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewforum');

/* This function outputs an SQL WHERE statement for use when grabbing
* posts and topics */

function create_where_clauses($gen_id, $type)
{
    global $db, $auth;

    $size_gen_id = sizeof($gen_id);

    switch ($type) {
        case 'forum':
            $type = 'forum_id';
            break;
        case 'topic':
            $type = 'topic_id';
            break;
        default:
            trigger_error('No type defined');
    }

    // Set $out_where to nothing, this will be used of the gen_id
    // size is empty, in other words "grab from anywhere" with
    // no restrictions
    $out_where = '';

    if ($size_gen_id > 0) {
        // Get a list of all forums the user has permissions to read
        $auth_f_read = array_keys($auth->acl_getf('f_read', true));

        if ($type == 'topic_id') {
            $sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
                        WHERE ' . $db->sql_in_set('topic_id', $gen_id) . '
                        AND ' . $db->sql_in_set('forum_id', $auth_f_read);

            $result = $db->sql_query($sql);

            while ($row = $db->sql_fetchrow($result)) {
                // Create an array with all acceptable topic ids
                $topic_id_list[] = $row['topic_id'];
            }

            unset($gen_id);

            $gen_id = $topic_id_list;
            $size_gen_id = sizeof($gen_id);
        }

        $j = 0;

        for ($i = 0; $i < $size_gen_id; $i++) {
            $id_check = (int)$gen_id[$i];

            // If the type is topic, all checks have been made and the query can start to be built
            if ($type == 'topic_id') {
                $out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
            } // If the type is forum, do the check to make sure the user has read permissions
            else if ($type == 'forum_id' && $auth->acl_get('f_read', $id_check)) {
                $out_where .= ($j == 0) ? 'WHERE ' . $type . ' = ' . $id_check . ' ' : 'OR ' . $type . ' = ' . $id_check . ' ';
            }

            $j++;
        }
    }

    if ($out_where == '' && $size_gen_id > 0) {
        trigger_error('A list of topics/forums has not been created');
    }

    return $out_where;
}

$search_limit = 100;

$forum_id = array(4); // Fixed ID of forum in DB
$forum_id_where = create_where_clauses($forum_id, 'forum');

$posts_ary = array(
    'SELECT' => 'p.*, t.*, u.username, u.user_colour',

    'FROM' => array(
        POSTS_TABLE => 'p',
    ),

    'LEFT_JOIN' => array(
        array(
            'FROM' => array(USERS_TABLE => 'u'),
            'ON' => 'u.user_id = p.poster_id'
        ),
        array(
            'FROM' => array(TOPICS_TABLE => 't'),
            'ON' => 'p.topic_id = t.topic_id'
        ),
    ),

    'WHERE' => str_replace( array('WHERE ', 'forum_id'), array('', 't.forum_id'), $forum_id_where) . '
                        AND t.topic_status <> ' . ITEM_MOVED . '
                         AND t.topic_visibility = 1',

    'ORDER_BY' => 't.topic_time ASC, p.post_time ASC',
);

$posts = $db->sql_build_query('SELECT', $posts_ary);

$posts_result = $db->sql_query_limit($posts, $search_limit);

$old_topic_id = '';

while ($posts_row = $db->sql_fetchrow($posts_result)) {
    $topic_id = $posts_row['topic_id'];
    $topic_title = $posts_row['topic_title'];
    $post_author = get_username_string('full', $posts_row['poster_id'], $posts_row['username'], $posts_row['user_colour']);
    $post_date = $user->format_date($posts_row['post_time']);
    $post_link = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $posts_row['forum_id'] . '&amp;t=' . $posts_row['topic_id'] . '&amp;p=' . $posts_row['post_id']) . '#p' . $posts_row['post_id'];

    $post_text = nl2br($posts_row['post_text']);

    $bbcode = new bbcode(base64_encode($bbcode_bitfield));
    $bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']);

    $post_text = smiley_text($post_text);

    $template->assign_block_vars('announcements', array(
        'TOPIC_TITLE' => censor_text($topic_title),
        'TOPIC_SWITCH' => $topic_id != $old_topic_id,
        'POST_AUTHOR' => $post_author,
        'POST_LINK' => $post_link,
        'POST_TEXT' => censor_text($post_text),
    ));

    $old_topic_id = $topic_id;
}

$template->assign_vars(array(
    'U_FORUM_RESERVATIONS'   => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . 4))
);

page_header('Reservations overview');

$template->set_filenamesp(array(
    'body' => 'reservations.html'
));

page_footer();
and associated html template is following:

Code: Select all

<!-- INCLUDE overall_header.html -->
<h1 style="text-align: center; display: block; margin-left: auto; margin-right: auto; margin-bottom: 15px;">
    <a href="{U_FORUM_RESERVATIONS}">&gt;&gt;&gt; Reservations overview - edit &lt;&lt;&lt;</a>
</h1>
<!-- BEGIN announcements -->
<!-- IF announcements.TOPIC_SWITCH  -->
<!-- IF not announcements.S_FIRST_ROW  -->
        </ul>
    </div>
</div>
<!-- ENDIF -->
<div class="forumbg">
    <div class="inner">
        <ul class="topiclist">
            <li class="header">
                <dl class="row-item">
                    <dt>
                        <div class="list-inner">
                            <a href="{announcements.POST_LINK}">{announcements.TOPIC_TITLE} : {announcements.POST_TEXT}</a>
                        </div>
                    </dt>
                </dl>
            </li>
        </ul>
        <ul class="topiclist topics">
<!-- ELSE -->
            <li class="row<!-- IF announcements.S_ROW_COUNT is even --> bg1<!-- ELSE --> bg2<!-- ENDIF -->">
                <dl class="row-item">
                    <dt style="min-height: 0px">
                        <div class="list-inner" style="padding-left: 5px;">
                            <b>{announcements.POST_AUTHOR}:</b> {announcements.POST_TEXT}
                        </div>
                    </dt>
                </dl>
            </li>
<!-- ENDIF -->
<!-- IF announcements.S_LAST_ROW -->
        </ul>
    </div>
</div>
<!-- ENDIF -->
<!-- END announcements -->
<!-- INCLUDE overall_footer.html -->
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.3][BETA] Calendar Tag

Post by martti »

sidik wrote: Sun Jan 24, 2021 8:46 pm ...
This phpBB extension "Calendar Tag" listens to two PHP events, as we can see in event/listener.php

Code: Select all

	static public function getSubscribedEvents():array
	{
		return [
			'marttiphpbb.topicsuffixtags'	=> 'set_suffix_tags',
			'marttiphpbb.topicprefixtags'	=> 'set_prefix_tags',
		];
	}
These are normally triggered by the "Topic Prefix Tag" and/or the "Topic Suffix Tag" extension.

You can also trigger one of these events yourself. You should send the keys:
  • tags : empty array that will be filled with a string, representing the tag (it is an array, because in theory there could be more listeners to the event other than this Calendar Tag extension)
  • topic_data; array with data (columns) of the concerning topic.

Code: Select all

//  \phpbb\event\dispatcher $dispatcher

$topic_data = // fetch topic columns into array
$tags = [];		
$vars = ['topic_data', 'tags'];
extract($this->dispatcher->trigger_event('marttiphpbb.topicsuffixtags', compact($vars))); // or marttiphpbb.topicprefixtags, depending on your placement

// $tags contains now the calendar tag if there is one (i.e. use reset($tags) to get a string - or false, See https://www.php.net/manual/en/function.reset.php)
User avatar
Carlton2001
Registered User
Posts: 16
Joined: Thu May 03, 2007 4:31 pm
Location: France

Re: [3.3][BETA] Calendar Tag

Post by Carlton2001 »

Hello martti

Your Calendar Extension Set is pretty amazing and fulfilled all my needs.
It works well on my dev forum (even if I have to install 8 extensions).

But I am a little worried that your project will not succeed given the few updates.
I am very reluctant to use the extension on my production forum.

What can we expect ?
sidik
Registered User
Posts: 2
Joined: Sun Jan 24, 2021 8:22 pm

Re: [3.3][BETA] Calendar Tag

Post by sidik »

martti wrote: Mon Jan 25, 2021 11:31 am ...
Thanks a lot, it worked exactly as described. In $topic_data I have inserted $posts_row with all columns of topic table and I have used global $phpbb_dispatcher because it is not implemented as a class with dispatcher member and it worked like a charm. Result tag I have inserted into the template as a next field and it can be used there.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.3][BETA] Calendar Tag

Post by martti »

sidik wrote: Mon Jan 25, 2021 10:25 pm Thanks a lot, it worked exactly as described. ...
Great, I'm happy it works. Reusablility was a key concern in development of the Calendar Extension Set.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.3][BETA] Calendar Tag

Post by martti »

Carlton2001 wrote: Mon Jan 25, 2021 4:05 pm Hello martti

Your Calendar Extension Set is pretty amazing and fulfilled all my needs.
It works well on my dev forum (even if I have to install 8 extensions).

But I am a little worried that your project will not succeed given the few updates.
I am very reluctant to use the extension on my production forum.

What can we expect ?
It has already succeeded for me as I needed a calendar for my board. At the same time I wanted my effort to be useful for others.
It is true that I have not been very active in the development for phpBB extensions last year. But for the Calendar Extension Set, I think the extensions published are pretty stable, as we don't see error reports.
For me it becomes more and more the question: what can we expect from phpBB itself? What direction is it going?
User avatar
Carlton2001
Registered User
Posts: 16
Joined: Thu May 03, 2007 4:31 pm
Location: France

Re: [3.3][BETA] Calendar Tag

Post by Carlton2001 »

Thank you for your reply.

I confess I coudn't resist and I installed it on my production server a few hours after my previous post, it is so well done.
I didn't see any bugs either in the way I use it but you can count on me to report them on Github if I see some ;).

Thank you for your work.
ilContadino
Registered User
Posts: 22
Joined: Fri Feb 04, 2022 9:44 pm

Re: [3.3][BETA] Calendar Tag

Post by ilContadino »

I'm not able to make it work. What am I doing wrong?

I have installed and enabled these extensions:
Schermata 2022-04-13 alle 20.49.11.png

What is the exact way to write and format the topic in order to display it in the calendar?

Schermata 2022-04-13 alle 20.52.17 copia.jpg
Schermata 2022-04-13 alle 20.52.28 copia.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.3][BETA] Calendar Tag

Post by martti »

ilContadino wrote: Wed Apr 13, 2022 6:54 pm I'm not able to make it work. What am I doing wrong?

I have installed and enabled these extensions:
Schermata 2022-04-13 alle 20.49.11.png


What is the exact way to write and format the topic in order to display it in the calendar?
...
You need also the Calendar Mono Input extension (and JQuery UI Datepicker helper extension)
I don't see how you got the tag without a way to input the data (?).
ilContadino
Registered User
Posts: 22
Joined: Fri Feb 04, 2022 9:44 pm

Re: [3.3][BETA] Calendar Tag

Post by ilContadino »

Thanks martti, I was sure I was missing something, now it works perfectly. But, is it possibile to allow creating events based on groups/member permissions? I'd like that just simple users cannot be able to create events.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.3][BETA] Calendar Tag

Post by martti »

ilContadino wrote: Thu Apr 14, 2022 11:33 pm Thanks martti, I was sure I was missing something, now it works perfectly. But, is it possibile to allow creating events based on groups/member permissions? I'd like that just simple users cannot be able to create events.
In order to keep things simple there are no extra permissions introduced by the Calendar extensions.

The permissions are inherited from the ability to start topics in a certain forum (forum permissions).

In your case the workflow is to create an extra forum
  • where simple users cannot start topics (but have the permission to view the topics)
  • but where users from a special group have the forum-permission to start topics (or the moderator or admin group)
  • and where the calendar input is enabled
ilContadino
Registered User
Posts: 22
Joined: Fri Feb 04, 2022 9:44 pm

Re: [3.3][BETA] Calendar Tag

Post by ilContadino »

In your case the workflow is to create an extra forum where simple users cannot start topics (but have the permission to view the topics)
Perfect martti that is a great solution.

Thanks a lot for this great calandar!

Return to “Extensions in Development”