Forums / Setup & design / One click to add and remove notification

One click to add and remove notification

Author Message

Daniele P.

Monday 29 November 2004 4:06:55 am

Now if you want to remove a node form the notification you have to:
1) go to the /notification/setting page
2) select the node you want to remove
3) click delete
4) click store to be sure...
5) click a link to return to the site

Replace the template
design/standard/templates/toolbar/full/notification.tpl
with the following and for each node you get the button "Keep me updated" or "Remove"

Please note that a there is bug related to this code:
http://ez.no/community/bug_reports/node_not_set_and_fatal_error

Now it works once every time you clear the cache.

Let me know it was usefull.

Tested only with 3.5.0rc1, may works with 3.4.4, earlyer needs
at least a workarond for {set scope=root subscribed=true()}.

{*?template charset=iso-8859-15?*}
<div class="toolbar-item {$placement}">
    <div class="toolbox">
        <div class="toolbox-design">
            <h2>{'Notification'|i18n( 'design/standard/toolbar' )}</h2>
            <div class="toolbox-content">
            {section show=not(is_set($node))}
              {* Expect to be here when you aren't in a node: e.g /notification/settings *}
              {* Or if there are problem: http://ez.no/community/bug_reports/node_not_set_and_fatal_error *}
              $node.node_id not set:
              {* FIXME: requires i18n *}
              Notification not avaliable for this page.
            {section-else}
              {let subscribed=false()}
                {section show=eq($current_user.contentobject_id,$anonymous_user_id)}
                  <a class="menuitem" href={"/user/login/"|ezurl}>{"Login"|i18n("design/standard/layout")}</a>
                {section-else}
                  {let subscribed_nodes=fetch( 'notification', 'subscribed_nodes')}
                    {* FIXME is possible to use one function instead of looping? E.g.: $subscribed_nodes_array|contains($node.node_id) *}
                    {section name=Rules loop=$subscribed_nodes}
                      {section show=eq($Rules:item.node.node_id,$node.node_id)}
                        {* FIXME is possible to stop the loop if we found one occurrence *}
                        {set scope=root subscribed=true()}
                        <form method="post" action={"/content/action/"|ezurl}>
                          <input type="hidden" name="ContentNodeID" value="{$node.node_id}" />
                          <input type="hidden" name="ContentObjectID" value="{$node.contentobject_id.}" />
                          <input type="hidden" name="NodeID" value="{$node.node_id}" />
                          {* NOTE this action require a patch to kernel/content/action.php*}
                          <input class="button" type="submit" name="ActionRemoveFromNotification" value="{'Remove'|i18n('design/standard/notification')}" />
                          {* FIXME css design class *}
                          <input type="hidden" name="ClassIdentifier" value="forum_topic" />
                        </form>
                      {/section}
                    {/section}
                  {/let}
                  {section show=not($subscribed)}
                    <form method="post" action={"content/action/"|ezurl}>
                      <input type="hidden" name="ContentNodeID" value="{$node.node_id}" />
                      <input type="hidden" name="ContentObjectID" value="{$node.contentobject_id.}" />
                      <input type="hidden" name="NodeID" value="{$node.node_id}" />
                      <input class="button forum-keep-me-updated" type="submit" name="ActionAddToNotification" value="{'Keep me updated'|i18n( 'design/base' )}" />
                      {* FIXME css design class *}
                      <input type="hidden" name="ClassIdentifier" value="forum_topic" />
                    </form>
                  {/section}
                {/section}
              {/let}  
            {/section}
            </div>
        </div>
    </div>
</div>

# Also add in kernel/content/action.php after
else if ( $http->hasPostVariable( "ActionAddToNotification" ) )
{
....
}

else if ( $http->hasPostVariable( "ActionRemoveFromNotification" ) )
{
    include_once( 'kernel/classes/notification/handler/ezsubtree/ezsubtreenotificationrule.php' );
    $user =& eZUser::currentUser();

    $nodeID = $http->postVariable( 'ContentNodeID' );

    if ( $http->hasPostVariable( 'ViewMode' ) )
        $viewMode = $http->postVariable( 'ViewMode' );
    else
        $viewMode = 'full';

    if ( !$user->isLoggedIn() )
    {
        eZDebug::writeError( 'User not logged in trying to unsubscribe for notification, node ID: ' . $nodeID,
                             'kernel/content/action.php' );
        $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $nodeID . '/' );
        return;
    }
    $contentNode = eZContentObjectTreeNode::fetch( $nodeID );
    if ( !$contentNode->attribute( 'can_read' ) )
    {
        eZDebug::writeError( 'User does not have access to unsubscribe for notification, node ID: ' . $nodeID . ', user ID: ' . $user->attribute( 'contentobject_id' ),
                             'kernel/content/action.php' );
        $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $nodeID . '/' );
        return;
    }

    $nodeIDList =& eZSubtreeNotificationRule::fetchNodesForUserID( $user->attribute( 'contentobject_id' ), false );
    if ( in_array( $nodeID, $nodeIDList ) )
    {
        eZSubtreeNotificationRule::removeByNodeAndUserID( $user->attribute( 'contentobject_id' ), $nodeID );
    }
    $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $nodeID . '/' );
    return;
}

eZ debug

Timing: Jan 19 2025 00:10:01
Script start
Timing: Jan 19 2025 00:10:01
Module start 'content'
Timing: Jan 19 2025 00:10:03
Module end 'content'
Timing: Jan 19 2025 00:10:03
Script end

Main resources:

Total runtime2.2115 sec
Peak memory usage4,096.0000 KB
Database Queries183

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0114 587.8438180.8125
Module start 'content' 0.01142.0434 768.6563438.1250
Module end 'content' 2.05470.1567 1,206.7813337.7813
Script end 2.2115  1,544.5625 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00450.2047210.0002
Check MTime0.00140.0641210.0001
Mysql Total
Database connection0.00100.043410.0010
Mysqli_queries2.131896.39381830.0116
Looping result0.00230.10241810.0000
Template Total2.159897.721.0799
Template load0.00220.100820.0011
Template processing2.157697.560221.0788
Template load and register function0.00030.011910.0003
states
state_id_array0.00210.096910.0021
state_identifier_array0.00250.111620.0012
Override
Cache load0.00180.0798250.0001
Sytem overhead
Fetch class attribute can translate value0.00190.087320.0010
Fetch class attribute name0.00090.040810.0009
XML
Image XML parsing0.00040.019120.0002
class_abstraction
Instantiating content class attribute0.00000.000210.0000
General
dbfile0.00640.2890210.0003
String conversion0.00000.000530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
1content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 15
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs