Jump to content

Developer Documentation

Content Items

  1. Building a model for Content Items

    Inheritance Chain Your content model extends several 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. The rest of the guides in this section cover implementing these features. \IPS\Content Provides a small number of features which are common to both Content Item models and Content Comme
  2. Featuring content with Content Items

    How to implement featuring To support featuring content items in your application, you first need to implement the interface in your content item model: implements \IPS\Content\Featurable Next, you need to add a featured key to your $databaseColumnMap, with the value being the name of the column in your database table that stores the featured status of the item. Finally, you need to add support to your templates. For example: {{if $item->canFeature()}} <a href='{$item
  3. Complete example of Content Items

    Here is an example of a content item model that makes use of several of the features discussed in this section. <?php namespace IPS\downloads; /** * File Model */ class _File extends \IPS\Content\Item implements \IPS\Content\Permissions, \IPS\Content\Tags, \IPS\Content\Reputation, \IPS\Content\Followable, \IPS\Content\ReportCenter, \IPS\Content\ReadMarkers, \IPS\Content\Hideable, \IPS\Content\Featurable, \IPS\Content\Pinnable, \IPS\Content\Lockable, \IPS\Content\Shareable { /** * @
  4. Pinning content with Content Items

    How to implement pinning In order to support pinning content items in your model, you need to implement the following interface: implements \IPS\Content\Pinnable Next, you should add a pinned key to your $databaseColumnMap, with the value being the name of the database column that stores the pinned status of your items. Finally, you need to add support to your templates. For example: {{if $item->canPin()}} <a href='{$item->url()->setQueryString( array( 'do' =>
  5. Locking content with Content Items

    In order to support locking of content items, you need to have implemented comments. How to implement locking To support locking and unlocking content items in your application, you first need to implement the interface in your content item model: implements \IPS\Content\Lockable Next, you need to add a locked key to your $databaseColumnMap property, with the value being the name of the database column that stores the locked state of your content items. Finally, you need to
  6. Hiding/approving content with Content Items

    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.   How to implement hiding and approving To support featuring content items in your application, you first need to implement the interface in your content item model: implements \IPS\Content\Hideable Next, add either a hidden or approved key to your $databaseColumnMap property, with the value be
  7. Tagging content with Content Items

    Content items can be tagged by members. Tags can be used to find other different types of content with the same tags. A prefix is one of the item's tags which is shown highlighted and prefixes the title when displayed.   How to implement tagging Tagging requires that your content items belong inside a container node. First, you need to implement the tagging interface: implements \IPS\Content\Tags Then, you can display the prefix and tags in the view for your item, like so:
  8. Searching content with Content Items

    How to implement searching Search functionality (and related functionality like Activity Streams) is automatically handled for you by the core of IPS Community Suite. You simply need to indicate that your content items should be searchable by implementing the interface: implements \IPS\Content\Searchable Note that you must also have implemented the ContentRouter extension.   Changes after implementation Content will be indexed and included in search results and the act
  9. Implementing the follow system in Content Items

    How to implement following Note: Your application must also implement searching (\IPS\Content\Searchable) in order to implement following. The first step is to implement the followable interface in your content item model, like so: implements \IPS\Content\Followable Next, you need to insert the template includes that will display the follow button inside your nodes and inside the content items themselves. In your node view (e.g. forum view), insert this tag: {template="follo
  10. Supporting page views in Content Items

    Your content item can automatically track the number of times it is viewed by implementing the page view interface. Note that guest page caching may render the count inaccurate since a cached page won't increase the view count.   Implementing page view tracking First, you need to implement the page view interface in your content item model, like so: implements \IPS\Content\Views Next, add a views key to your $databaseColumnMap, with the value being the name of the database
  11. Implementing share links in Content Items

    Share links allow users to share content items to various social networks, as configured by the administrator.   How to implement share links First, your content item model needs to implement the share links interface, like so: implements \IPS\Content\Shareable Finally, include the share links template inside your content item view: {template="sharelinks" app="core" group="global" params="$item"}   Additional model methods available array sharelinks() R
  12. Implementing read markers in Content Items

    Content read markers allow members to easily see which content items they've viewed through the use of a small icon in the content list view. They are a standard feature of the IPS Community Suite, and you should implement them if your application deals with user-generated content in any way.   How to implement read marking First, your content item model needs to implement the read marking interface, like so: implements \IPS\Content\ReadMarkers Next, you should add a key to
  13. Supporting polls in Content Items

    By implementing polls in your application, members will be able to attach a poll when creating a new content item. The process is automatic; a new tab will be displayed on the create item form that allows the poll to be managed   How to implement polls First, your content item model needs to implement the poll interface, like so: implements \IPS\Content\Polls Next, add a poll key to your $databaseColumnMap with the value being the name of the database column that stores the
  14. Supporting content rating in Content Items

    Ratings allow members to rate content items out of 5 or 10 (depending on settings) stars.   How to implement ratings First, you need to implement the rating interface in your content item model, like so: implements \IPS\Content\Ratings Next, add the following keys to the $databaseColumnMap property of your model. These are optional, but adding them will make your application much more efficient at returning the average rating when viewed. As usual, the value of each key sho
  15. Supporting content embedding in Content Items

    Throughout the IPS Community Suite, content items can be embedded in other content, generating a small preview of the content. You can support this kind of embedding in your own content items, allowing them to be embedded elsewhere in the suite. Note: You must have implemented the ContentRouter extension for embedding to be supported.   How to implement embedding First, you need to implement the embedding interface in your content item model, like so: implements \IPS\Cont
  16. Anonymous Content

    Throughout the IPS Community Suite, content items can be posted as anonymous.   Implementing page view tracking First, you need to implement the Anonymous interface in your content item model, like so: implements \IPS\Content\Anonymous Next, add a is_anon and last_comment_anon key to your $databaseColumnMap, with the value being the name of the database column that stores the bit.   To determine if a content item or comment was posted anonymous, you can use the new
  17. Building a controller for Content Items

    Simply by being defined, a controller that extends \IPS\Content\Controller will inherit a lot of functionality. Like all kinds of controllers, your content item controller belongs in the <app>/modules/<location> directory, such as yourapp/modules/front/somemodule/somecontroller.php.  If you haven't already read about standard controllers in IPS4, I recommend you go there now and grasp the fundamentals before continuing. Content item controllers are simply a more specialized
  18. Creating content items

    Creating an "Add Item" form You can create a form that allows users to create new content items by simply calling the following in a controller method: \IPS\Output::i()->output = \IPS\yourApp\YourModelClass::create( $node ); You must pass the node into which the content item is being created as a parameter (or pass NULL if you are creating content items independent of nodes, or if you will add a form element from which the user can select the node themselves). The create() method
  19. Using containers with Content Items

    In most cases, your content items will exist inside container node structures that categorize them - for example. topics (item) in a forum (node), or images (item) in an album (node). A number of methods are available within the content item model to make working with these relationships easier.   Adding support for container nodes The first step you need to take is add a new static property to your content item model.   protected static $containerNodeClass = 'string';
  20. Permissions in Content Items

    Content items can automatically check if the user has permission to perform certain actions by examining the container node object. For this functionality to be supported, as you might expect, your content items need to be using container nodes. Consult the documentation on container nodes and supporting containers in content items for more information.   Supporting permissions in content items All you need to do to support permissions is implement the permissions interface in you
  21. Content router extensions for Content Items

    Many features of IPS4 are handled centrally and automatically, such as warnings and moderator permissions. In order to support this, you need to register your content item types with the core, and this is done via a simple Content Router extension. For more information on the extensions, see the extensions guide. In order for this functionality to work, you need to support containers in your content items and in your node models.   How to implement a ContentRouter extension T
  22. Getting content from a Content Item

    If you use content items in your application, it probably goes without saying that you'll want to use the content within those items at some point. There's two possibilities depending on whether your model uses a specific column for content, or expects the first comment to act as the content (such as in the Forums application). For a specific content field Simply add a content key to the $databaseColumnMap, with the value being the column in the database that contains the content.
×
×
  • Create New...