Sourcefabric Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Newscoop 4.2 Cookbook

Article object and attachment, comment, location

Article

The article object is set at the beginning of the main template based on the request URL. This object can be changed using the set_article function. The article object has the following properties:

Base properties/functions:

  • name: article name
  • number: article identifier in the Newscoop database
  • author: returns an object corresponding to the first author in the list of authors, with the following properties:
    • name
    • first_name
    • last_name
    • email
    • defined
  • authors: returns the complete list of authors for the current article - objects of type author (see above or "Author").
  • keywords: text containing the article keywords separated by the Newscoop defined separator (default is comma [,])
  • has_keyword (<keyword>): returns true if the given keyword existed in the article keywords list

Example:

{{ if $gimme->article->has_keyword (mp3podcast) }}<span class="audio"></span>{{ /if }}

Important: the command matches parts of the keyword. In the above example keywords "mp3podcast10" and "mp3podcasttalk" both return true.

  • type_name: article type name
  • type_translated: article type name translated to the environment language
  • <date_attribute>: article creation date field (year, month, day etc.)
  • creation_date: article creation date; you can customize the date display format by using the filter camp_date_format
  • publish_date: article publish date; you can customize the date display format by using the filter camp_date_format
  • last_update: time of the last article edit
  • template: the full path of the article template file
  • type-> <article_type>-> <article_type_attribute>: returns the content of an article field specific to a certain article type (see the "Article Types" chapter in Newscoop for Journalists and Editors); read the chapter Date and e-mail formatting in this Cookbook for formatting the content of type date/time; see also the notes below
  • url_name: the article name used in URL display (see the "Creating An Article" chapter in Newscoop for Journalists and Editors)
  • translated_to(<language_code>): true if an article translation for the language with the given code existed
  • subtitles_count(<field_name>): returns the number of the subtitles in the given content field; the article name is counted as the first subtitle so this function returns a number greater or equal to 1. If the specified field was not a content field it returns null.
  • subtitle_url_id(<field_name>): returns the URL parameter which sets the number of the subtitle to be displayed from the field <field_name>
  • current_subtitle_no(<field_name>): returns the number of the subtitle which will be displayed through the statement {{ $gimme->article-><field_name> }}; 0 for the default subtitle, 1 for the first subtitle defined in the article content field etc.
  • publication: the publication to which this article belongs to - object of type publication (see the chapter "Publication")
  • issue: the issue to which this article belongs to - object of type issue (see the chapter "Issue")
  • section: the section to which this article belongs to - object of type section
  • language: the article language - object of type language (see the chapter "Language")
  • owner: the user who created the article - object of type user (see the chapter "User")
  • defined: boolean value (true/false) - true if the article was set in the current environment; false otherwise

Comments related properties/functions:

  • comments_enabled: true if comments were enabled for the article publication, article type and the current article
  • comments_locked: true if comments were locked (meaning they can be listed but no new comments can be posted)
  • comment_count: returns the number of the comments posted to the article and approved

Accessibility properties/functions:

  • on_front_page: true if article front page flag was set
  • on_section_page: true if article section page flag was set
  • is_published: true if the article was published
  • is_public: true if the article was accessible to the public
  • is_indexed: true if the article was indexed by the search engine
  • content_accessible: returns true if the content of the article is accessible for reading: either it is public or the reader subscribed to the publication (see also Editing An Article and Creating a Publication chapters in Newscoop for Journalists and Editors)

Attachment related properties/functions:

  • has_attachments: true if the article had attached files
  • image: returns the image object that was defined in the template environment; if the image was not defined in the environment, returns the first image of the article; if the article didn't have any image attached returns an unset image object
  • image_index: returns the index of the current image inside the article; if the image wasn't defined in the environment or it doesn't belong to the article returns null.
  • has_image(<image_index>): true if the article had an attached image and it's index was equal to the given index
  • image(<image_index>): returns the attached image having the given index; if no such image existed, returns an unset image object. This is a function so the image index is given in between brackets. For example: $gimme->article->image(3)
  • image<image_index>: returns the attached image having the given index; if no such image existed, returns an unset image object. This is a property, not a function. For example: $gimme->article->image3
  • topics_count: returns the number of topics attached to this article
  • has_topics: true if the article had attached topics
  • has_topic(<topic_identifier>): true if the article had the specified topic attached to it

Statistics properties/functions:

  • reads: returns the number of readers that viewed this article since it was published
  • request_object_id: the identifier used in statistics gathering

<date_attribute> may be one of the following:

  • year: year (four digits)
  • mon: month as a number (1..12)
  • mday: day of the month as a number (1..31)
  • yday: day of the year (1..366)
  • wday: day of the week as a number (0=Sunday..6=Saturday)
  • hour: hour (0..23)
  • min: minute (two digits)
  • sec: seconds (two digits)
  • mon_name: name of the month
  • wday_name: day of the week

Note regarding the attribute type->[<article_type>->]<article_type_attribute>:

Attributes which are body fields (content) have the following properties:

  • all_subtitles: returns the whole content of the body field, not just the current subtitle
  • first_paragraph: returns the first paragraph of the current subtitle
  • subtitles_count: returns the number of the subtitles in the body field
  • subtitle_number: returns the number of the current subtitle: 0 for the default subtitle, 1 for the first subtitle defined in the article content field etc.
  • subtitle_is_current: true if the subtitle that would be displayed through the statement {{ $gimme->article-><article_type_attribute> }} is the same as the subtitle defined in the template environment (see also the chapter "Subtitle (subheads in long articles)" and current_subtitle_no(<field_name>) above)
  • has_previous_subtitles: true if the current subtitle from this field was not the first subtitle
  • has_next_subtitles: true if the current subtitle from this field was not the last subtitle

Example: displaying the first paragraph of the dynamic field "content":

$gimme->article->content->first_paragraph

Note regarding the attribute type->[<article_type>->]<article_type_attribute>:

In Newscoop the table cell containing the image link in article body fields has the class cs_img and the cell containing the caption text has the class caption; this allows the web designer to change the layout of the article images by using a CSS file. The image link has the following structure:

<table border="0" cellspacing="0" cellpadding="0" class="cs_img" align=left>
  <tr>
    <td align="center">
      <img src="/get_img?NrArticle=143&NrImage=1" border="0"
           hspace="5" vspace="5">
    </td>
  </tr>
  <tr><td align="center" class="caption">Newscoop team</td></tr>
</table>

Note regarding the attribute type->[<article_type>->]<article_type_attribute>:

The subtitle in the article body fields has the class articlesubhead; this allows the web designer to change the layout of the subtitles by using a CSS file. The subtitle anchor has the following structure:

<span class="articlesubhead">
    <a name="a1.250_s1">Version 2.3.0 - 2.3.1</a>
</span>

The structure of the anchor name is:

a<language_identifier>.<article_number>_s<subtitle_number>

Article Attachment

The article attachment object is usually initialized inside a list of article attachments. It is not initialized at the beginning of the template and can not be initialized by other Newscoop functions. The article attachment object has the following properties:

  • identifier: the attachment identifier in the Newscoop database (integer value)
  • file_name: the name of the attached document
  • mime_type: the mime type of the attached document
  • extension: the file extension of the attached document
  • description: the user filled description field of the attached document in the current language
  • size_b: the size of the attached document in bytes
  • size_kb: the size of the attached document in kilobytes
  • size_mb: the size of the attached document in megabytes
  • defined: boolean value (true/false) - true if the attachment was set in the current environment; false otherwise

Examples

Taken from Template Pack "The Custodian" (date 2011-03-15) file "if-audio.tpl"

{{ if ($gimme->attachment->extension == mp3) || ($gimme->attachment->extension == ogg) }}

Taken from Template Pack "The Custodian" (date 2011-03-15) file "if-audio.tpl"

<div class="audio-attachment-description">{{ $gimme->attachment->description }}</div>

Taken from Template Pack "The Custodian" (date 2011-03-15) file "if-audio.tpl"

<audio controls>
    <source src="http://{{ $gimme->publication->site }}{{ uri options="articleattachment" }}" type="{{ $gimme->attachment->mime_type }}">
</audio>

Article Comment

The comment object is usually initialized inside a list of article comments. It can be initialized at the beginning of the template from the URL request but can not be initialized by other Newscoop functions. The article comment object has the following properties:

  • identifier: the numerical identifier of the article comment from the database
  • real_name: the real name of the reader who posted the comment; the reader must be a registered Newscoop user; for anonymous readers this attribute will return an empty string
  • nickname: the nickname of the reader who posted the comment
  • reader_email: the email of the reader who posted the comment
  • anonymous_author: whether the reader is anonymous or not
  • submit_date: the date and time the comment was submitted
  • subject: the subject of the article comment
  • content: the content of the article comment
  • content_real: the raw representation of the content
  • level: the level of the current comment in the tree structure of the comments
  • article: the article where this comment was submitted to - object of type article
  • defined: true if the comment object had a valid value

Example

{{ list_article_comments columns="2" order="bydate desc"}}
{{ if $gimme->current_list->at_beginning }}
  <h2>{{ $gimme->article->comment_count }} Response(s) to &#8220;{{ $gimme->article->name }}&#8221;</h2>
  <ol class="commentlist">
{{ /if }}
   <li class="comment {{ if $gimme->current_list->column == "1" }}odd{{ else }}even{{ /if }}">
      <div class="comment-head cl">
         <div class="user-meta">
             <strong class="name">{{ $gimme->comment->nickname }}</strong> {{ $gimme->comment->submit_date|camp_date_format:"%e.%m.%Y at %H:%i" }}
          </div>
      </div>
      <div class="comment-entry">
          <p>{{ $gimme->comment->content }}</p>
      </div>
   </li>
{{ if $gimme->current_list->at_end }}
  </ol>
{{ /if }}
{{ /list_article_comments }}

Article Location

Note: this works only in Newscoop 3.5.0 and newer versions.

Maps require jQuery: In order to use display maps you must include jQuery in the header of your document, with a link like this:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">

The article "location" object is usually initialized inside a list of articles. It is not initialized at the beginning of the template and can not be initialized by other Newscoop functions. The article location object has the following properties:

  • name: the location's name
  • latitude: latitude in degrees
  • longitude: longitude in degrees
  • text: location's text description
  • content: location's rich text description
  • multimedia: list of multimedia items related to the location, see the "Location Multimedia" object.

Examples

{{ list_article_locations }}
    {{ if $gimme->location->enabled }}
        {{ $gimme->location->name }}{{ if $gimme->current_list->at_end }}{{ else }}, {{ /if }}
    {{ /if }}
{{ /list_article_locations }}

Listing all information for locations in an article

<h2>List article with geolocation information</h2>
<ul>
{{ list_articles}}
  {{ list_article_locations }}
    {{ if $gimme->location->enabled }}
      {{ if $gimme->current_list->at_beginning }}
        <ul>
          <li>LOCATION DATA FOR: {{ $gimme->article->name }}</li>
        <ul>
      {{ /if }}
            <li>list index: {{ $gimme->current_list->index }}</li>
            <li>name: {{ $gimme->location->name }}</li>
            <li>latitude: {{ $gimme->location->latitude }}</li>
            <li>longitude: {{ $gimme->location->longitude }}</li>
            <li>text: {{ $gimme->location->text }}</li>
            <li>content: {{ $gimme->location->content }}</li>
            <li>multimedia:</li>
              <ul>
                {{ foreach from=`$gimme->location->multimedia` item=multimediaitem }}
                  <li>src: {{ $multimediaitem->src }}</li>
                  <li>type: {{ $multimediaitem->type }}</li>
                  <li>spec: {{ $multimediaitem->spec }}</li>
                  <li>width: {{ $multimediaitem->width }}</li>
                  <li>height: {{ $multimediaitem->height }}</li>
                {{ /foreach }}
              </ul>
      {{ if $gimme->current_list->at_end }}
          </ul>
        </ul>
      {{ /if }}
    {{ /if }}
  {{ /list_article_locations }}
{{ /list_articles }}
</ul>

Ushahidi compatible KML format. You can use this as a feed to call as a layer in Ushahidi

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
  <name>{{ $gimme->publication->name }}</name>
  <description><![CDATA[ .]]></description>
{{ list_articles}}
  {{ list_article_locations }}
    {{ if $gimme->location->enabled }}
  <Style id="style{{ $gimme->article->number }}-{{ $gimme->current_list->index }}">
    <IconStyle>
      <Icon>
        <href>http://www.sourcefabric.org/javascript/geocoding/markers/marker-gold.png</href>
      </Icon>
    </IconStyle>
  </Style>
    {{ /if }}
  {{ /list_article_locations }}
{{ /list_articles }}
{{ list_articles}}
  {{ list_article_locations }}
    {{ if $gimme->location->enabled }}
  <Placemark>
    <name>{{ $gimme->location->name }} @ {{ $gimme->article->name }}</name>
    <description></description>
    <styleUrl>#style{{ $gimme->article->number }}-{{ $gimme->current_list->index }}</styleUrl>
    <Point>
      <coordinates>{{ $gimme->location->longitude }},{{ $gimme->location->latitude }},0.000000</coordinates>
    </Point>
  </Placemark>
    {{ /if }}
  {{ /list_article_locations }}
{{ /list_articles }}
</Document>
</kml>

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.