Skocz do zawartości
Zaloguj się, aby obserwować  
Invisionize.eu

[Dokumentacja IPS4] Introduction to Content Items

Polecane posty

The Model
Skeleton
<?php
namespace IPS\yourapp;

class _YourClass extends \IPS\Content\Item
{

/**
* @brief Multiton Store */

     protected static $multitons;

/**
* @brief Default Values */

     protected static $defaultValues = NULL;

/**
* @brief Application */

     public static $application = 'yourapp';

/**
* @brief Module */

     public static $module = 'yourmodule';

/**
* @brief Database Table */

     public static $databaseTable = 'table';

/**
* @brief Database Prefix */

     public static $databasePrefix = 'prefix_';

/**
* @brief Database Column Map */

public static $databaseColumnMap = array( 'author' => 'author'

);

/**
* @brief Title

24

 */
public static $title = ‘thing’;

/**
* Get URL
*
* @param string|NULL
* @return \IPS\Http\Url */

$action Action

     public function url( $action=NULL )
     {
          $url = \IPS\Http\Url::internal( ... );
          if ( $action )
          {
               $url = $url->setQueryString( 'do', $action );
          }
          return $url;
     }

}

Introduction

The Content Item model represents content created by users (for example, in IP.Board a topic is a content item).

As you add more features to your Content Items you will add to and modify this skeleton.

Inheritance

Your model extends a number of classes. In turn, these are:-

\IPS\Content\Item

Provides the features of Content Items. It contains all the code for the various optional features of content items which you will activate by adding properties and interfaces to your model.

\IPS\Content

Provides a small number of features which are common to both Content Item models and Content Comment models (explained later) such as getting the author and working with $databaseColumnMap.

\IPS\Patterns\ActiveRecord

Provides the functionality to load items from the database, work with their properties, save and delete them.

Required Properties

string $application;

25

The application key that the Content Item belongs to.

string $module;

The module key that the Content Item belongs to.

array $multitons
array $defaultValues;

Simply requirements of \IPS\Patterns\ActiveRecord - you do not need to do anything other than define them.

string $databaseTable

Is the name of the database table which you store your Content Items in.

string $databasePrefix

If all of the columns in your database table start with the same prefix, you can define that here and then you do not need to specify it every time you look up the vale of a column. It is important that your database table has a column which called {$databasePrefix}id containing a numeric primary key.

array $databaseColumnMap

Features provided by the higher classes your model extends will examine this array to find out what columns certain things are stored as in your database.
Required elements:

author should contain the name of the column (without the $databasePrefix) which

contains the ID number of the member who posted the content.
title should contain the name of the column (without the $databasePrefix) which contains

the title of the content.
date should contain the name of the column (without the $databasePrefix) which

contains a unix timestamp of when the content item was created.
ip_address should contain the name of the column (without the $databasePrefix) which

contains the IP address of the user who posted the item.

string $title

The key for a language string which describes what your content item is (for example “Topic”, “File”, “Image”, “Event”, etc.)

Available Methods

In addition to those provided by \IPS\Patterns\ActiveRecord (which work exactly the same as for Nodes) a number of additional methods are available:

static getItemsWithPermission( ... ) Gets content items. See phpDocs for full details.

mapped( string $key )
Returns the value of a column specified by $databaseColumnMap.

author()

Gets the \IPS\Member object for the user who posted the content. Example:

26

     $item = YourClass::load( 1 );
     $user = $item->author();
     echo $user->name;

canView()

Returns a boolean value indicating if $member (NULL if the currently logged in member) can view the content item. By default will always return TRUE, but is affected if Permissions is enabled and if Hiding is enabled.

canEdit( \IPS\Member $member )
Returns a boolean value indicating if $member (NULL if the currently logged in member) can edit the content item.

canDelete( \IPS\Member $member )
Returns a boolean value indicating if $member (NULL if the currently logged in member) can delete the content item.

static modPermission( $type, \IPS\Member $member = NULL, \IPS\Node \Model $container = NULL )
Returns a boolean value indicating if $member (currently logged in member if NULL) has permission to perform the action specified by $type in the node specified by $container (if NULL, will check if they have permission in all nodes).

Acceptable values for $type: edit
delete
move

feature (if Featuring is enabled)
unfeature (if Featuring is enabled)
pin (if Pinning is enabled)
unpin (if Pinning is enabled)
lock (if Locking is enabled)
unlock (if Locking is enabled)
hide (if Hiding / Approving is enabled)
unhide (if Hiding / Approving is enabled)
view_hidden (if Hiding / Approving is enabled)

modAction( $action, \IPS\Member $member = NULL )

Performs moderator action specified by $action. Will throw OutOfRangeException if $member (currently logged member if NULL) does not have permission to do so.

The Controller

Skeleton

namespace IPS\yourapp\modules\front\yourmodule;
class _yourcontroller extends \IPS\Content\Controller
{

}

27

Introduction

The controller, just by being defined enables the ability for users to delete the content - if you append “&do=delete&id=X” to the URL needed to access your controller (where “X” is the ID number). It will automatically check if the user has permission to do so (which, by default, is only if the user is a moderator with permission to delete all content).

As you add more features to your Content Item, the controller will perform more actions. Naturally, you will also add your own methods to facilitate actually displaying your content.

Displaying a Table

You can use the \IPS\Helpers\Table\Content class to display a list of all the content items within a node.

$table = new \IPS\Helpers\Table\Content( 'IPS\yourApp\YourClass',
$node->url(), NULL, $node );
\IPS\Output::i()->output = $table;

The table will be paginated automatically and only show items that users have permission to see.

If you want to display items differently, you can specify a custom template to use:

$table->rowsTemplate = array( \IPS\Theme::i()-
>getTemplate( 'yourTemplateGroup' ), 'yourTemplate' );

See the default template (core —> front —> tables —> rows) for an example.

Creating an add item form

You can create a form for users to submit items from simply by calling the create() method:

\IPS\Output::i()->output = \IPS\yourApp
\YourClass::create( $node );

You must pass the node the content item is being created in (or NULL if your content items are independent of nodes or you will add an element on the submission form to select one) and the method will automatically handle showing the form, creating the item and redirecting to it.

The form elements to show are obtained from the formElements( array $values, \IPS\Node\Model $node ) method, which you can override to add additional form elements (they will also show on the edit form). It will automatically include items for a title, tags (if enabled - see Tags section) and the first comment (if comments are enabled and the first comment is required - see chapter 3) so ensure you call the method in the parent class to not override this. The names for the form elements are prefixed with the value of

28

the static $formLangPrefix property (which is a blank string unless overridden) - so you can use this to customise the titles used in the form elements.

There are several methods you can also override to perform actions at various points of the creation process:

canCreate( \IPS\Member $member, \IPS\Node\Model $container=NULL, bool $showError=FALSE )
Before the form is even shown, this method is ran to check if the member can create an item in this node. Most permission checking is done automatically, so you usually do not need to override this method, unless there are particular considerations (for example, in the messenger, members can be set to only be able to send a certain number of messages per day - so that is checked in this method within the messenger).

processBeforeCreate( array $values )
After the object has been created and default values such as the author, date and any fields which can be set by virtue of having the same key as a database column have been set - but before the item has been inserted into the database - this method is ran. It receives the values from the form.

processForm( array $values )
Immediately after processBeforeCreate(), this method is ran. It differs from processAfterCreate() in that it runs for edits as well as new items. You should use it to set any fields you added in formElements() which are more complicated than just setting the direct value (which would be done automatically).
The default method sets the title, tags (if enabled - see Tags section) and other data, so ensure you call the method in the parent class to not override this.

processAfterCreate( \IPS\Content\Comment $comment=NULL, array $values )
After the content item has been inserted into the database and all processing has done, including creating the first comment if enabled (see chapter 3), this method is ran. It receives an object for the first comment if applicable and the values from the form.

Notes

Post Counts

Post counts will automatically be increased when a member posts a content item. This may be undesirable, especially if your content items are just containers for comments which also increase post counts (like topics in IP.Board). You can disable this behaviour with a property:

public static $incrementPostCount = TRUE;

29

Containers Introduction

Content Items which belong to Nodes may define this relationship.

Other Requirements

None.

Behaviour that changes once implemented

None.

Additional methods available once implemented container()

Returns the container object.

canMove( \IPS\Member $member=NULL )
Returns a boolean value indicating if $member (currently logged in member if NULL) can move the item to another container.

move( \IPS\Node\Model $container ) Moves the item into a different container.

Additional methods available to the container class once implemented

get_items() get_comments() get_reviews() get_unapprovedItems() get_unapprovedComments() get_unapprovedReviews() set_items( $val ) set_comments( $val ) set_reviews( $val ) set_unapprovedItems( $val ) set_unapprovedComments( $val ) set_unapprovedReviews( $val )

Gets/sets the number of (approved) items/comments/reviews and number of unapproved of the same. Approved/unapproved only applies if your content is hideable (explained later).
By default, all the get_methods return NULL and the set_ methods do nothing. You can override them if your container wants to keep track of the numbers.

In order for unapproved comments/reviews to be tracked reliably, your content items must have “unapproved_comments” or “unapproved_reviews” elements in their database column map (see chapter 3).

setLastItem( \IPS\Content\Item $item )
setLastComment(
\IPS\Content\Comment $comment )
setLastReview(
\IPS\Content\Review $review )
These methods are called automatically when a new item/comment/review is posted. By default they do nothing, but you can override them if your container wants to keep track of

30

the last item/comment/review inside it. In some cases, the variable passed will be NULL, in which case, you must manually retrieve the last item/comment/review.
These methods should bubble, so if implemented, also call the same method on all child nodes.

getLastCommentTime()

If using setLastComment(), this method can be used in conjunction to return an \IPS \DateTime object with the time an item, comment or review was last posted. Is used for read marking.

How to implement

1. Add new property:

/**
* @brief Node Class */

     protected static $containerNodeClass = 'IPS\yourapp
\YourNodeClass';

2. Add container element to $databaseColumnMap pointing to the column in the database which contains the ID number for the container.

31

Permissions Introduction

Content Items can automatically check if the user has permission for certain actions by examining the container.

See Chapter 1 for more information on defining permissions within Nodes.

Other Requirements

Containers

Behaviour that changes once implemented

canView(...) will return false for an item a node the member does not have permission to view. This will also cause loadAndCheckPerms(...) to throw an OutOfRange exception if such an object is loaded.

All places where features do things will check the permission. For example, canCreate(...) will now return false if the member does not have permission to create content items in the specified node.

getItemsWithPermission(...) will only return items that the currently logged in user has permission to view (or other permission as specified by parameters).

Additional methods available once implemented

can( string $permission[, mixed $member ] )
Checks if the user has permission to perform the specified action. The action should match a value from the static $permissionMap property of the container class. $member can either be NULL (which will check the permission for the currently logged in member) or an \IPS\Member or an \IPS\Member\Group object.

permId()

Returns the numeric permission index ID.

How to implement

1. Add an interface:

implements \IPS\Content\Permissions

32

Content Router Introduction

Several features such as warnings are moderator permissions are handled centrally and automatically. To register your content items with the core, you need to create a simple extension file called a Content Router.

Other Requirements

Containers

Behaviour that changes once implemented

  • When creating a moderator, administrators will be able to setup moderator permissions for your content items.

  • When viewing a user’s profile, showing all content posted by that user will include your content items.

  • If you support hidden content items, when viewing the moderator control panel, hidden content items from your application will be shown.

  • When a moderator gives a user a warning, if the warning was issues from a piece of content in your application, which content will be associated with the warning.

  • When rebuilding a member’s post count, your content items will be accounted for.

  • When deleting all content posted by a member, your content items will be accounted for.

    Additional methods available once implemented

    None.

    How to implement

    1. CreateanewContentRouterextensioninyourapplicationwithfollowingcode:

           namespace IPS\yourApp\extensions\core\ContentRouter;
      
           class _YourClass 
           {
      
                public $classes = array( 'IPS\yourApp
           \YourContentItemClass' );
           }
      
    2. Adda$modPermpropertytoyourNodemodelwithakeythatwillbeusedasthekey to store the nodes that a moderator has permission for (it can be anything you like). Create a language string with the same key with a value representing what your nodes are called (for example, “Categories”).

33

3. Addlanguagestringsforeachoftheoftheavailablemoderatoractionsinthisformat:

can_<action>_<title>
Where “<title>” is the key defined by the static $title property in your content item model. If your content items support comments, repeat for the actions that can be performed on comments (edit, delete, hide, unhide, view_hidden) where “<title>” is the key defined by the static $title property in your content comment model.

34

Content Introduction

Some areas need the item’s content. For some items, this will be a description, or for others which require comments (see the $firstCommentRequired property explained in Chapter 3) this will be the content of the first comment.

Other Requirements Required:

None

Optional:

Comments

Behaviour that changes once implemented

None.

Additional methods available once implemented content()

Returns the content.

truncated( bool $oneLine=FALSE )
Returns the content in a format that it can be placed into a <div data-ipsTruncate> element to be truncated.

How to implement EITHER:

Add a content element to $databaseColumnMap pointing to the column in the database which contains the content.

OR:
Implement comments (see Chapter 3) for the first comment to be returned.

35

Featuring Introduction

Content Items can be featured to display on a home page or elsewhere.

Other Requirements Required:

None.

Optional:

Permissions.
Moderator Permissions.

Behaviour that changes once implemented

Users with appropriate moderator permission will see tools to feature/unfeature in content item tables.

Additional methods available once implemented

static featured( int $limit=10, string $order=‘RAND()’ )
Gets featured items. If Permissions is enabled, only items that the currently logged in user has permission to view will be returned.

canFeature( \IPS\Member $member=NULL )
Returns a boolean value indicating if $member (currently logged in member if NULL) can feature the item. Takes into consideration if it is already featured.

canUnfeature( \IPS\Member $member=NULL )
Returns a boolean value indicating if $member (currently logged in member if NULL) can unfeature the item. Takes into consideration if it is already featured.

How to implement

1. Add an interface:

implements \IPS\Content\Featurable
2. Add a featured element to $databaseColumnMap pointing to the column in the

database which contains if the content item is featured or not.
3. Add a feature/unfeature button in the template for viewing your content item: {{if $item->canFeature()}}

36

     <a href='{$item->url()->setQueryString( array( 'do' =>
'moderate', 'action' => 'feature' ) )}'>{lang="feature"}</a>
{{endif}}
{{if $item->canUnfeature()}}
     <a href='{$item->url()->setQueryString( array( 'do' =>
'moderate', 'action' => 'unfeature' ) )}'>{lang="unfeature"}</a>
{{endif}}

37

Pinning Introduction

Content Items can be pinned which will cause them to be shown at the top of listings.

Other Requirements Requirements:

Containers

Optional:

Moderator Permissions

Behaviour that changes once implemented

Pinned items will show at the top of content item tables.
Users with appropriate moderator permission will see tools to feature/unfeature in

content item tables.

Additional methods available once implemented

canPin( \IPS\Member $member=NULL )
Returns a boolean value indicating if $member (currently logged in member if NULL) can pin the item. Takes into consideration if it is already featured.

canUnpin( \IPS\Member $member=NULL )
Returns a boolean value indicating if $member (currently logged in member if NULL) can unpin the item. Takes into consideration if it is already featured.

How to implement

1. Add an interface:

implements \IPS\Content\Pinnable
2. Add a pinned element to $databaseColumnMap pointing to the column in the

database which contains if the content item is pinned or not.

3. Add a pin/unpin button in the template for viewing your content item:

{{if $item->canPin()}}
     <a href='{$item->url()->setQueryString( array( 'do' =>
'moderate', 'action' => 'pin' ) )}'>{lang="pin"}</a>
{{endif}}

38

{{if $item->canUnpin()}}
     <a href='{$item->url()->setQueryString( array( 'do' =>
'moderate', 'action' => 'unpin' ) )}'>{lang="unpin"}</a>
{{endif}}

39

Locking Introduction

Content items can be locked which prevents further comments from being added.

Other Requirements Required:

Comments Optional:

Moderator Permissions

Behaviour that changes once implemented

Locked items will no longer receive comments, unless the user has permission to comment on locked items.

Users with appropriate moderator permission will see tools to lock/unlock in content item tables.

Additional methods available once implemented

canLock( \IPS\Member $member=NULL )
Returns a boolean value indicating if $member (currently logged in member if NULL) can lock the item. Takes into consideration if it is already locked.

canUnlock( \IPS\Member $member=NULL )
Returns a boolean value indicating if $member (currently logged in member if NULL) can unlock the item. Takes into consideration if it is already locked.

How to implement

  1. Add an interface:

         implements \IPS\Content\Lockable
    
  2. Add a locked element to $databaseColumnMap pointing to the column in the database which contains if the content item is locked or not. Or a locked element for a a text column.

  3. Add a pin/unpin button in the template for viewing your content item:

{{if $item->canLock()}}

40

     <a href='{$item->url()->setQueryString( array( 'do' =>
'moderate', 'action' => 'lock' ) )}'>{lang="lock"}</a>
{{endif}}
{{if $item->canUnlock()}}
     <a href='{$item->url()->setQueryString( array( 'do' =>

'moderate', 'action' => 'unlock' ) )}'>{lang="unlock"}</a> {{endif}}

41

Hiding / Approving Introduction

Content Items can be hidden to non-staff members. This can be used to require staff approval before content can be viewed, and as a way for staff members to hide undesirable content.

Other Requirements Requirements:

None.

Optional:

Containers
Moderator permissions

Behaviour that changes once implemented

  • canView(...) will return false for an item that is hidden if the member cannot view hidden items. This will also cause loadAndCheckPerms(...) to throw an OutOfRange exception if such an object is loaded.

  • Hidden items will only show to users who have permission to view hidden content.

  • Users with appropriate moderator permission will see tools to lock/unlock in content item

    tables.

  • Users who are set to have all new content moderated will have their content hidden until

    it is manually approved.

    Additional methods available once implemented

    hidden()

    Returns a number indicating the hidden state:
    -1 means the content is hidden, but was previously unhidden.
    0 means the content is unhidden (default, normal status).
    1 means the content is hidden and was marked hidden at the time of posting.

    canHide( \IPS\Member $member=NULL )
    Returns a boolean value indicating if $member (currently logged in member if NULL) can hide the item. Takes into consideration if it is already locked.

    canUnhide( \IPS\Member $member=NULL )
    Returns a boolean value indicating if $member (currently logged in member if NULL) can unhide the item. Takes into consideration if it is already locked.

    static canViewHiddenItems( \IPS\Member $member=NULL )
    Returns a boolean value indicating if $member (currently logged in member if NULL) can view hidden items. To check an individual item, use canView().

42

How to implement

1. Add an interface:

implements \IPS\Content\Hideable
2. Add either a hidden or an approved element to $databaseColumnMap pointing to

the column in the database which contains the status of the content.


Optionally you can also add approved_by (to store the member ID of who approved the item) and approved_date (to store a timestamp of when the item was approved).

3. Add hide/unhide buttons in the template for viewing your content item:

{{if $item->canHide()}}
     <li><a href='{$item->url()->setQueryString( array( 'do' =>
'moderate', 'action' => 'hide' ) )}'>{lang="hide"}</a></li>
{{endif}}
{{if $item->canUnhide()}}
     <li><a href='{$item->url()->setQueryString( array( 'do' =>
'moderate', 'action' => 'unhide' ) )}'>{{if $item->hidden() ===
1}}{lang="approve"}{{else}}{lang="unhide"}{{endif}}</a></li>
{{endif}}

4. If a user is configured to have their content approved, their content will be hidden by default automatically. You may want to override the method that handles this so, for example you can make certain nodes have all content posted to them require approval. To do this, override the moderateNewItems(...) method - for example:

     public static function moderateNewItems( \IPS\Member $member,
\IPS\Node\Model $container = NULL )
     {
          if ( $container and $container->bitoptions['moderation']
and !static::modPermission( 'unhide', $member, $container ) )
          {
               return TRUE;
          }
          return parent::moderateNewItems( $member, $container );
     }

Element

Value if unhidden (normal, default)

Value if hidden (was previously unhidden)

Value if pending approval

hidden

0

-1

1

approved

1

-1

0

43

Tags Introduction

Content items can be tagged by members. Tags can be used to find other different types of content with the same tags.

Other Requirements

Containers

Behaviour that changes once implemented

A field to input tags will be added to the create/edit form. Prefixes and tags will be displayed in content tables.

Additional methods available once implemented

static canTag( \IPS\Member $member=NULL, \IPS\Node\Model $container)
Returns a boolean tag indicating if $member (currently logged in member if NULL) can tag items in $container. You can override this method if you have a per-node setting to enable/ disable tags.

static canPrefix( \IPS\Member $member=NULL, \IPS\Node\Model $container)
Returns a boolean tag indicating if $member (currently logged in member if NULL) can put prefixes on items in $container. You can override this method if you have a per-node setting to enable/disable prefixes.

tags()

Returns an array of tags for the item.

prefix()

Returns the prefix for the item (or NULL).

How to implement

1. Add an interface:

     implements \IPS\Content\Tags

2. Displaytagsandprefixesinthepageforviewingyouritem:

{{if $item->prefix()}}
     <a
href="{url="app=core&module=system&controller=tags&tag={$item-
>prefix()}" seoTemplate="tags"}">{$item->prefix()}</a>

44

{{endif}}

{{if count( $file->tags() )}}
     <ul>
          {{foreach $file->tags() as $tag}}
               <li><a
href="{url="app=core&module=system&controller=tags&tag={$tag}"
seoTemplate="tags"}">{$tag}</a></li>
          {{endforeach}}
     </ul>

{{endif}}

45

Searching Introduction

Content Items can be included in search results and the activity stream.

Other Requirements

Required

Content Router Tags

Optional
Containers
Permissions
Hiding / Approving

Behaviour that changes once implemented

Content will be indexed and included in search results and the activity stream. The index will automatically be updated when content is created, edited, moved, hidden, etc. and works automatically with both the MySQL index and Sphinx.

Additional methods available once implemented

None.

How to implement

1. Add an interface:

     implements \IPS\Content\Searchable

46

Reputation Introduction

Users can “like” or give reputation on content items. A member’s total reputation displays on their profile.

Other Requirements

None.

Behaviour that changes once implemented

None.

Additional methods available once implemented reputation()

Returns an integer indicating the current reputation for the item.

canGiveReputation( int $type, \IPS\Member $member=NULL )
Returns a boolean value indicating if $member (currently logged in member if NULL) can give $type (1 for positive, -1 for negative) reputation on the item.

giveReputation( $type, \IPS\Member $member=NULL )
Gives reputation on the item. Will throw DomainException if $member is not allowed to give reputation on the item.

repGiven( \IPS\Member $member=NULL )
Returns an integer (1 for positive, -1 for negative, 0 for no reputation given) indicating what reputation $member (currently logged in member if NULL) has given to the item.

How to implement

1. Add an interface:

     implements \IPS\Content\Reputation

2. Addapropertyspecifyingakeytodistinguishreputationgivenonthistypeofcontent item as opposed to another. It can be anything you like, though convention is to use the name of the column in your database table (with prefix) which stores the ID.

     public static $reputationType = 'item_id';

3. Addreputationbuttonsontothepagewhichdisplaysyouritem: 47

     {template="reputation" app="core" group="global"
params=“$item"}

48

Following Introduction

Members can follow containers ands be notified when new content items are posted into them.

Other Requirements

Containers Content

Behaviour that changes once implemented

After posting a new content item, members who are following the node it was posted into will receive a notification. If the content needs to be approved by a moderator, the notifications will be delayed until the content has been approved.

Additional methods available once implemented

static containerFollowers( \IPS\Node\Model $container, int $privacy=3, array $frequencyTypes=array( ‘immediate’, ‘daily’, ‘weekly ), array $limit=array( 0, 25 ), string $order=‘name’ )
Returns an \IPS\Db\Select object which can be iterated on to get details about which members are following $container. See phpDocs for available options. $privacy is a bitwise value using the \IPS\Content\FOLLOW_* constants - the default value, 3, includes public and anonymous follows.

How to implement

1. Add an interface:

     implements \IPS\Content\Followable

2. Addthefollowbuttonontothepagewhereyoudisplaythecontentitemsinanode:

{template="follow" app="core" group="global"
params=“‘yourApp’,’YourCNodeClass’, $node->_id, \IPS\yourApp
\YourContentClass::containerFollowers( $node )->count( TRUE )"}

49

Page Views Introduction

Content Items can automatically keep track of the number of times they have been viewed.

Other Requirements

None.

Behaviour that changes once implemented

When the item is viewed, a column in the database table which contains the number of views will be updated.

stats() will return an element containing the number of views. Additional methods available once implemented

None.

How to implement

  1. Add an interface:

         implements \IPS\Content\Views
    
  2. Add views element to $databaseColumnMap pointing to the column in the database

    which contains the view count.

  3. Ensure that your controller calls parent::manage() at the start of the manage() method.

50

Share Links Introduction

Content Items can provide links to share the content on social media sites.

Other Requirements

None.

Behaviour that changes once implemented

None.

Additional methods available once implemented sharelinks()

Returns an array of share links.

How to implement

1. Add an interface:

     implements \IPS\Content\Shareable

2. Display the links somewhere in your template:

     {template="sharelinks" app="core" group="global"
params="$item"}

51

Reports Introduction

Content Items can be reported to moderators.

Other Requirements

Content

Behaviour that changes once implemented

None.

Additional methods available once implemented

canReport( [$member] )

Checks if the member (either the given member or the currently logged in member) can report the content, taking into consideration if their group is allowed to submit reports, if they can view the content, if they are the author and if they have already reported that item.

report( $reportContent )

Submits a report.

How to implement

  1. Add an interface:

         implements \IPS\Content\ReportCenter
    
  2. Add a new properties to define a CSS class name to represent your content item when viewing reports.

         public static $icon = 'icon';
    
  3. Display a link somewhere in your template. You should not call canReport() to check if the user has permission to report as this is a moderately intensive method. You can however, include some basic checks, checking the user can make reports and isn’t the author, for example:

{{if !\IPS\Member::loggedIn()->group['gbw_no_report'] and $item-
>author()->member_id != \IPS\Member::loggedIn()->member_id }}

52

     <a href='{$item->url('report')}' data-ipsDialog data-
ipsDialog-size='narrow' data-ipsDialog-
title="{lang="report_post"}" data-ipsDialog-
flashMessage="{lang="node_error"}" title='{lang="report_post"}'><i
class='icon-exclamation-sign'></i>&nbsp; {lang="report_post"}</a>
{{endif}}

53

Read Markers Introduction

Content Items can keep track of which members have read them.

Other Requirements Requirements:

None.

Optional:

Containers Comments.

Behaviour that changes once implemented

When the item is viewed, it will be marked read for that member.

Additional methods available once implemented

static containerUnread( \IPS\Node\Model $container, \IPS\Member $member=NULL ) Returns a boolean value indicating if the provided container (or children thereof) contain unread items.

static markContainerRead( \IPS\Node\Model $container, \IPS\Member $member=NULL )
Marks all items in the container (and it’s children) as read.

unread( \IPS\Member $member=NULL )
Returns 0 if item is read, -1 if it is unread and has never been read or 1 if unread but has been read previously (only applies when using with comments). If $member is NULL, will use currently logged in member.

markRead( \IPS\Member $member=NULL )
Marks the item as read by $member (currently logged in member if NULL).

timeLastRead( \IPS\Member $member=NULL )
Returns an \IPS\DateTime object indicating when $member (currently logged in member if NULL) last read the item.

How to implement

1. Add an interface:

     implements \IPS\Content\ReadMarkers

54

  1. Add updated element to $databaseColumnMap pointing to the column in the database which contains either the timestamp the content was last updated, unless you’re using comments or reviews, in which case last_comment / last_review will be used.

  2. Ensure that your controller calls parent::manage() at the start of the manage() method, or otherwise, make sure you call markRead() manually when the item is viewed.

In order to use containerUnread() and markContainerRead() your containers must have implemented the following methods (see Containers section):
• get__items()
• get__comments()

• setLastComment()
• getLastCommentTime()

55

Polls Introduction

Members can add polls to content items.

Other Requirements

None.

Behaviour that changes once implemented

When creating or editing a content item, a new tab will show allowing the member to submit a poll.

Additional methods available once implemented

static canCreatePoll( \IPS\Member $member \IPS\Node\Model $container )
Returns a boolean indicating if the member can create a poll in this container ($container will be NULL if your content items do not use them). You can override this method to add per-container settings about polls.

getPoll()

Returns the \IPS\Poll object associated with the content item, or NULL if there isn’t one.

How to implement

1. Add an interface:

     implements \IPS\Content\Polls
  1. Addpollelementto$databaseColumnMappointingtothecolumninthedatabase

    which contains the ID number for the poll.

  2. Displaythepollsomewhereinyourtemplate:

         {$item->getPoll()|raw}
    

Optionally, your class can observe when someone votes on the poll. To implement: 1. Add an interface:

     implements \SplObserver

2. Addanupdatemethodthatdoeswhateveryouneedtodowhenthepollreceivesa vote. It will receive the \IPS\Poll object as the subject.

56

3. Whendisplayingyouritem,attachittothepoll:

if ( $poll = $topic->getPoll() )
{
     $poll->attach( $item );
}

57

Rating Introduction

Members can rate content items (a score between 1 and 5). This should only be used if reviews (see chapter 4) are not being used.

Other Requirements

None.

Behaviour that changes once implemented

None.

Additional methods available once implemented canRate( \IPS\Member $member = NULL )

Returns a boolean value indicating if the currently logged in member can rate the item.

averageRating()

Returns the average rating for the content item.

rating()

Displays starts indicating current average rating. If the currently logged in member can rate, they will be able to click on the stars to rate.

How to implement

  1. Add an interface:

    implements \IPS\Content\Ratings

  2. Optionally add the following elements to $databaseColumnMap (adding either rating_average or rating_total and rating_hits will prevent the need to query for the average rating when displaying the form):

    rating_average, for the current average rating
    rating_total, for the total of all ratings
    rating_hits, for the number of times the item has been rated

  3. Display the rating in your template:

         {$item->rating()|raw}
    

58

Embedding Introduction

When the URL to your content is posted elsewhere in the community, the link can be automatically replaced with a preview of the content.

Other Requirements

Content Router

Behaviour that changes once implemented

When the URL to your content is posted elsewhere on the community, it will be replaced with a preview of the content.

Additional methods available once implemented

None.

How to implement

  1. Ensure that the URLs to your content contain an “id” parameter which is the primary ID of your content. If this is not the case, you will need to override the loadFromUrl method in your class (this is defined in \IPS\Patterns\ActiveRecord):

         public function loadFromUrl( \IPS\Http\Url $url )
         {
    

    return static::load( ... ); }

  2. Add an interface:

    implements \IPS\Content\Embeddable

  3. To get the content to be embedded, a call will be made to the item’s URL with

“&do=embed” appended. Ensure this sends the desired output for the embed preview. 

 

Example: 

Wyświetl pełny artykuł

Udostępnij ten post


Link to postu
Udostępnij na innych stronach

Bądź aktywny! Zaloguj się lub utwórz konto

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Zaloguj się, aby obserwować  

  • Kto przegląda   0 użytkowników

    Brak zalogowanych użytkowników przeglądających tę stronę.

×

Ważne informacje

Kontynuując przeglądanie strony, wyrażasz zgodę na używanie przez nas plików cookies.