Documentation is available at story-defs.php
- <?php
- /* ******************************************************************** */
- /* CATALYST PHP Source Code */
- /* -------------------------------------------------------------------- */
- /* This program is free software; you can redistribute it and/or modify */
- /* it under the terms of the GNU General Public License as published by */
- /* the Free Software Foundation; either version 2 of the License, or */
- /* (at your option) any later version. */
- /* */
- /* This program is distributed in the hope that it will be useful, */
- /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
- /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
- /* GNU General Public License for more details. */
- /* */
- /* You should have received a copy of the GNU General Public License */
- /* along with this program; if not, write to: */
- /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
- /* Boston, MA 02111-1307 USA */
- /* -------------------------------------------------------------------- */
- /* */
- /* Filename: story-defs.php */
- /* Author: Paul Waite */
- /* Description: Definitions for managing and using Axyl stories/news */
- /* */
- /* ******************************************************************** */
- /** @package cm */
- include_once("catalog-defs.php");
- /** HTMLArea wysiwyg */
- ("htmlarea-defs.php");
- // HTMLArea settings..
- htmlarea_plugins("CSS,ContextMenu,ListType,CharacterMap");
- // Some global widths for form elements etc..
- $width = 590;
- $width_img_preview = 125;
- $height_img_preview = 125;
- $width_icon_preview = 90;
- $height_icon_preview = 50;
- $widthpx = $width . "px";
- $smlwidthpx = ceil($width/3) . "px";
- $stdwidthpx = ceil($width/2) . "px";
- $bigwidthpx = ceil((2 * $width)/3) . "px";
- /** New story ID indicator */
- ("NEW_STORY", -1);
- /**
- * A class which encapsulates a story or article item. Provides methods
- * to get/save to database, edit the story in a popup window, and view it.
- * Also provides methods to index/unindex to Lucene.
- * @package cm
- */
- class story extends RenderableObject {
- var $story_id = NEW_STORY; // Our unique DB key for the story
- var $story_category = false; // The group of stories this belongs to
- var $story_category_desc = ""; // Wordy descriptive version of above
- var $has_media = true; // By category: associated media
- var $has_multimedia = false; // By category: more then one assoc. media
- var $has_precis = true; // By category: has a precis
- var $has_expiry = true; // By category: has an expiry option
- var $has_multilang = true; // By category: can be translated
- var $language = 0; // Language this story is in
- var $story_headline = ""; // Headline of this story (0 = default)
- var $story_precis = ""; // The lead-in section of this story
- var $story_content = ""; // The main story body content
- var $story_author = ""; // The story author - FK from ax_user.user_id
- var $story_author_name = ""; // The story author full name
- var $story_type = ""; // The story type - 'a' - Article, 'f' - Feature
- var $story_date = ""; // Datetime written, DISPLAY_DATE_FORMAT format
- var $story_date_ts = 0; // Unix timestamp of datetime story was written
- var $expiry_date = ""; // Datetime to expire, DISPLAY_DATE_FORMAT format
- var $expiry_date_ts = 0; // Unix timestamp of datetime story should expire
- var $lastmodified = ""; // Datetime last modified, NICE_FULLDATETIME format
- var $lastmodified_ts = 0; // Unix timestamp of datetime story last modified
- var $story_media = array(); // An array of media associated with this story
- var $story_icon; // The catalogitem object of the icon image for this story
- var $story_icon_url; // The URL for the icon image for this story
- var $visible = false; // True if story is visible on the website
- var $story_locs = array(); // An array of locations this story is published to
- var $story_translations = array(); // An array of media associated with this story
- var $root_translation_id = -1; // Story ID of root (original) of translated stories
- var $root_translation_lang; // Language of root (original) of translated stories
- // Internal Flags and Vars..
- var $deleted = false; // True if story has been flagged as deleted
- var $info_msg = ""; // Contains info/error message as appropriate
- var $newstory = false; // True if we just created this story
- var $valid = false; // True if story was retreived successfully
- var $storymode = ""; // Mode of action on this story
- var $formname = ""; // Name of the form we use
- var $bytesize = 0; // Size of article + media in bytes
- var $wordcount = 0; // Number of words written
- var $microsite_name; // Microsite this story is for (if any)
- // .....................................................................
- /** Constructor
- * @param mixed $id Story ID, or false if not known
- * @param mixed $category String category identifier, or false if unknown
- * @param mixed $language Integer language code, or false if default
- */
- function story($id=false, $category=false, $language=false) {
- global $RESPONSE;
- global $storymode;
- global $story_id, $cat, $lang;
- // Set up our vars..
- $this->initialise();
- // Form..
- $this->formname = "storyfm";
- // Default the mode..
- if (!isset($storymode)) $this->storymode = "view";
- else $this->storymode = $storymode;
- // Set the story ID..
- if ($id === false) {
- if (isset($story_id)) {
- $this->story_id = $story_id;
- }
- }
- else {
- $this->story_id = $id;
- }
- // Set the category..
- if ($category === false) {
- if (isset($cat)) {
- $this->story_category = $cat;
- }
- }
- else {
- $this->story_category = $category;
- }
- // Set the language..
- if ($language === false) {
- if (isset($lang)) {
- $this->language = $lang;
- }
- }
- else {
- $this->language = $language;
- }
- // Detect new story creation..
- if ($this->story_id === false || $this->story_id == NEW_STORY) {
- // Create a brand new one
- $this->story_id = get_next_sequencevalue("seq_story_id", "ax_story", "story_id");
- $this->story_date_ts = time();
- $this->story_date = timestamp_to_displaydate(DISPLAY_DATE_FORMAT, $this->story_date_ts);
- $this->newstory = true;
- $this->valid = true;
- $this->get_author_info();
- $this->get_category_info();
- $this->get_default_locations();
- $this->storymode = "adding";
- // Also deal with possible microsite story creation..
- if ($RESPONSE->microsites_mode == MICROSITES_ENABLED
- && $RESPONSE->microsite_detected != "") {
- $this->microsite_name = $RESPONSE->microsite_detected;
- debugbr("setting microsite name for new story: $this->microsite_name");
- }
- }
- // Further processing for existing stories..
- if (!$this->newstory) {
- if ($this->storymode == "adding") {
- $this->newstory = true;
- $this->valid = true;
- // Also deal with possible microsite story creation..
- if ($RESPONSE->microsites_mode == MICROSITES_ENABLED
- && $RESPONSE->microsite_detected != "") {
- $this->microsite_name = $RESPONSE->microsite_detected;
- debugbr("setting microsite name for new story: $this->microsite_name");
- }
- }
- else {
- // Attempt to get the story
- $this->get_story();
- }
- // Process POST from form..
- $this->POSTprocess();
- // Final get for display..
- $this->get_story();
- }
- } // story
- // .....................................................................
- /** Initialise local vars.. */
- function initialise() {
- global $RESPONSE;
- $this->language = 0;
- $this->story_headline = "";
- $this->story_content = "";
- $this->story_precis = "";
- if (isset($RESPONSE)) {
- $this->story_author = $RESPONSE->userid;
- $this->story_author_name = $RESPONSE->name;
- }
- else {
- $this->story_author = "";
- $this->story_author_name = "";
- }
- $this->story_type = "a";
- $this->story_date = "";
- $this->story_date_ts = 0;
- $this->expiry_date = "";
- $this->expiry_date_ts = 0;
- $this->lastmodified = "";
- $this->lastmodified_ts = 0;
- $this->deleted = false;
- $this->visible = true;
- $this->newstory = false;
- $this->info_msg = "";
- $this->valid = false;
- } // story initialise
- // .....................................................................
- /**
- * Get a story in total. We always access stories by their ID.
- * @param mixed $id Story ID, or false if not known
- */
- function get_story($id=false) {
- global $RESPONSE;
- $res = false;
- if ($id !== false) $this->story_id = $id;
- if ($this->story_id !== false) {
- $q = "SELECT * FROM ax_story s";
- $q .= " WHERE story_id=$this->story_id";
- $storyQ = dbrecordset($q);
- if ($storyQ->hasdata) {
- // Main story content..
- $this->language = $storyQ->field("lang_id");
- $this->story_category = $storyQ->field("category_id");
- $this->story_headline = $storyQ->field("story_headline");
- $this->story_precis = $storyQ->field("story_precis");
- $this->story_content = $storyQ->field("story_content");
- $this->story_author = $storyQ->field("story_author");
- $this->story_type = $storyQ->field("story_type");
- $this->story_icon_url = $storyQ->field("story_icon_url");
- if ($storyQ->field("story_icon") != "") {
- $iconitem = new catalogitem($storyQ->field("story_icon"));
- if ($iconitem->valid) {
- $this->story_icon = new story_media($this->story_id, $iconitem);
- }
- }
- // Dates and flags..
- $story_date = $storyQ->field("story_date");
- if ($story_date != "") {
- $this->story_date = datetime_to_displaydate(DISPLAY_DATE_FORMAT, $story_date);
- $this->story_date_ts = datetime_to_timestamp($story_date);
- }
- $expiry_date = $storyQ->field("expiry_date");
- if ($expiry_date != "") {
- $this->expiry_date = datetime_to_displaydate(DISPLAY_DATE_FORMAT, $expiry_date);
- $this->expiry_date_ts = datetime_to_timestamp($expiry_date);
- }
- $this->lastmodified = datetime_to_displaydate(NICE_FULLDATETIME, $storyQ->field("last_modified"));
- $this->lastmodified_ts = datetime_to_timestamp($storyQ->field("last_modified"));
- $this->deleted = $storyQ->istrue("deleted");
- $this->visible = $storyQ->istrue("visible");
- $res = true;
- // Now go grab sundry other associated story info..
- $this->get_author_info();
- $this->get_category_info();
- if ($this->has_media) {
- $this->get_story_media();
- }
- $this->get_story_locations();
- $this->get_story_metrics();
- $this->get_story_microsite();
- }
- else {
- $this->info_msg = "No record of story ID: $this->story_id";
- }
- }
- else {
- $this->info_msg = "No story ID given";
- }
- // Did we succeed..?
- $this->valid = $res;
- return $res;
- } // story get_story
- // .....................................................................
- /**
- * Determine wwhether user can edit this story.
- * @return boolean True if user can edit the story, else false.
- */
- function user_can_edit() {
- global $RESPONSE;
- $can = false;
- if ($RESPONSE->ismemberof_group("Editor")
- || ($RESPONSE->ismemberof_group("Author") && $this->story_author == $RESPONSE->userid)
- ) {
- $can = true;
- }
- return $can;
- } // user_can_edit
- // .....................................................................
- /**
- * Get story author info. Allow override of user id via argument
- * passed in, otherwise use the resident story author ID.
- * @param string $userid Override user_id to use to get info
- * @access private
- */
- function get_author_info($userid=false) {
- if ($userid !== false) {
- $story_author = $userid;
- }
- else {
- $story_author = $this->story_author;
- }
- if ($story_author != "" && $story_author !== false) {
- $su = dbrecordset("SELECT * FROM ax_user WHERE user_id='" . addslashes($story_author) . "'");
- if ($su->hasdata) {
- $this->story_author_name = $su->field("full_name");
- $this->story_author = $story_author;
- }
- }
- } // get_author_info
- // .....................................................................
- /**
- * Get story category info. Allow override of category id via argument
- * passed in, otherwise use the resident story category ID.
- * @param integer $catid Override category_id to use to get info
- * @access private
- */
- function get_category_info($catid=false) {
- if ($catid !== false) {
- $story_category = $catid;
- }
- else {
- $story_category = $this->story_category;
- }
- if ($story_category != "" && $story_category !== false) {
- $cat = dbrecordset("SELECT * FROM ax_story_category WHERE category_id=$story_category");
- if ($cat->hasdata) {
- $this->story_category_desc = $cat->field("category_desc");
- $this->has_media = $cat->istrue("has_media");
- $this->has_multimedia = $cat->istrue("has_multimedia");
- $this->has_precis = $cat->istrue("has_precis");
- $this->has_expiry = $cat->istrue("has_expiry");
- $this->has_multilang = $cat->istrue("has_multilang");
- $this->story_category = $story_category;
- }
- }
- } // get_category_info
- // .....................................................................
- /**
- * Get media associated with this story. This should be called after the
- * story category info has been ascertained. This method populates the
- * class variable 'story_media', an array which contains media catalog
- * ID and the filename separated by "|".
- * @access private
- */
- function get_story_media() {
- $this->story_media = array();
- $q = "SELECT * FROM ax_story_media";
- $q .= " WHERE story_id=$this->story_id";
- $q .= " ORDER BY display_order";
- $sm = dbrecordset($q);
- if ($sm->hasdata) {
- do {
- $cat_id = $sm->field("cat_id");
- $media = new story_media($this->story_id);
- $media->get_catalogitem($cat_id);
- $media->justify = $sm->field("justify");
- $media->caption = $sm->field("caption");
- $media->width = $sm->field("width");
- $media->height = $sm->field("height");
- $this->story_media[$cat_id] = $media;
- debugbr("adding story media: $cat_id " . $media->catalogitem->filepath, DBG_DEBUG);
- } while ($sm->get_next());
- }
- } // get_story_media
- // .....................................................................
- /**
- * Get the story locations defined for this story. This method
- * is an internal one designed to be used to populate the current
- * locations to publish the story in.
- * @access private
- */
- function get_story_locations() {
- $this->story_locs = array();
- $q = "SELECT * FROM ax_story_location";
- $q .= " WHERE story_id=$this->story_id";
- $loc = dbrecordset($q);
- if ($loc->hasdata) {
- do {
- $locid = $loc->field("location_id");
- $this->story_locs[] = $locid;
- } while ($loc->get_next());
- }
- } // get_story_locations
- // .....................................................................
- /**
- * Get the microsite associated with this story, if any. If none, then
- * we leave the 'microsite_name' local class variable unset.
- * @access private
- */
- function get_story_microsite() {
- global $RESPONSE;
- if ($RESPONSE->microsites_mode == MICROSITES_ENABLED) {
- if (isset($this->microsite_name)) {
- unset($this->microsite_name);
- }
- $q = "SELECT * FROM ax_microsite_story";
- $q .= " WHERE story_id=$this->story_id";
- $ms = dbrecordset($q);
- if ($ms->hasdata) {
- $this->microsite_name = $ms->field("microsite_name");
- }
- }
- } // get_story_microsite
- // .....................................................................
- /**
- * Get the default locations for this story category. This method
- * is an internal one designed to be used to populate the initial
- * locations to publish a new story to.
- * @access private
- */
- function get_default_locations() {
- $this->story_locs = array();
- $q = "SELECT * FROM ax_story_category_locs";
- $q .= " WHERE category_id=$this->story_category";
- $loc = dbrecordset($q);
- if ($loc->hasdata) {
- do {
- $locid = $loc->field("location_id");
- $this->story_locs[] = $locid;
- } while ($loc->get_next());
- }
- } // get_default_locations
- // .....................................................................
- /**
- * Get the story locations defined for this story. This method
- * is an internal one designed to be used to populate the current
- * locations to publish the story in.
- * @access private
- */
- function get_story_metrics() {
- global $RESPONSE;
- $words = $this->story_headline . $this->story_precis . $this->story_content;
- $bytesize = strlen($words);
- if (count($this->story_media) > 0) {
- foreach ($this->story_media as $media) {
- if (isset($media->catalogitem) && $media->catalogitem->filepath != "") {
- if (file_exists($RESPONSE->site_docroot . $media->catalogitem->filepath)) {
- $bytesize += filesize($RESPONSE->site_docroot . $media->catalogitem->filepath);
- }
- }
- } // foreach
- }
- $this->bytesize = $bytesize;
- $this->wordcount = $this->word_count();
- } // get_story_metrics
- // .....................................................................
- /**
- * Get the stories which are translated versions of this one.
- * @access private
- */
- function get_story_translations() {
- $this->story_translations = array();
- // Find root story info for this set of translations..
- debugbr("translation family: this story ID is $this->story_id");
- $this->root_translation_id = -1;
- $q = "SELECT st.story_id as sid, s.lang_id as lang";
- $q .= " FROM ax_story_translation st, ax_story s";
- $q .= " WHERE st.translated_story_id=$this->story_id";
- $q .= " AND s.story_id=st.story_id";
- $q .= " AND s.deleted=FALSE";
- $q .= " UNION ";
- $q .= "SELECT st.story_id as sid, s.lang_id as lang";
- $q .= " FROM ax_story_translation st, ax_story s";
- $q .= " WHERE st.story_id=$this->story_id";
- $q .= " AND s.story_id=st.story_id";
- $q .= " AND s.deleted=FALSE";
- $trans = dbrecordset($q);
- if ($trans->hasdata) {
- $this->root_translation_id = $trans->field("sid");
- $this->root_translation_lang = $trans->field("lang");
- debugbr("translation story id root = $this->root_translation_id");
- // Add root story if it's not us..
- if ($this->root_translation_id != $this->story_id) {
- debugbr("ADDING translation story id (root)=$this->root_translation_id lang=$this->root_translation_lang");
- $this->story_translations[$this->root_translation_id] = $this->root_translation_lang;
- }
- }
- // Now get all translations of the root..
- $q = "SELECT st.translated_story_id as sid, s.lang_id as lang";
- $q .= " FROM ax_story_translation st, ax_story s";
- $q .= " WHERE st.story_id=$this->root_translation_id";
- $q .= " AND s.story_id=st.translated_story_id";
- $q .= " AND s.deleted=FALSE";
- $trans = dbrecordset($q);
- if ($trans->hasdata) {
- do {
- $storyid = $trans->field("sid");
- $langid = $trans->field("lang");
- // Add story if it's not us..
- if ($storyid != $this->story_id) {
- debugbr("ADDING translation story id=$storyid lang=$langid");
- $this->story_translations[$storyid] = $langid;
- }
- } while ($trans->get_next());
- }
- } // get_story_translations
- // .....................................................................
- /** Index this story to Lucene, if enabled for this website. */
- function index() {
- global $CONTEXT, $LIBDIR;
- // Deal with Lucene indexing if enabled. In this case we then
- // use the unique story_id as the index ID, and index the story
- // heading and body text. We also categorise it..
- if ( isset($CONTEXT) && $CONTEXT->configvalue("Lucene Site Indexing") ) {
- include_once("lucene-defs.php");
- $allcontent[] = $this->story_headline;
- $allcontent[] = $this->story_precis;
- $allcontent[] = $this->story_content;
- $I = new lucene_indexmsg();
- $I->index_field("category:Text", "news");
- $I->index_field("title:Text", $this->story_headline);
- $I->index_field("story_date:Date", $this->story_date_ts);
- $I->index_field("story_author:Text", $this->story_author);
- $I->index_field("story_lang:Text", $this->language);
- $I->index_field("story_category:Text", $this->story_category);
- $I->index_field("story_type:Text", $this->story_type);
- if ($this->story_url != "") {
- $I->index_field("story_url:Text", $this->story_url);
- }
- $I->index_content($this->story_id, strip_tags(implode(" ", $allcontent)));
- $I->send();
- }
- } // story index
- // .....................................................................
- /** Un-Index this story from Lucene, if enabled for this website. */
- function unindex() {
- global $CONTEXT, $LIBDIR;
- if ( isset($CONTEXT) && $CONTEXT->configvalue("Lucene Site Indexing") ) {
- include_once("lucene-defs.php");
- $UI = new lucene_unindexmsg();
- $UI->unindex($this->story_id);
- $UI->send();
- }
- } // unindex
- // .....................................................................
- /** Routine to save the story to the database. */
- function save_story() {
- if ($this->story_id) {
- if ($this->newstory) {
- $sup = new dbinsert("ax_story");
- $sup->set("story_id", $this->story_id);
- }
- else {
- $sup = new dbupdate("ax_story");
- }
- $sup->set("lang_id", $this->language);
- $sup->set("story_headline", $this->story_headline);
- $sup->set("story_precis", $this->story_precis);
- $sup->set("story_content", $this->story_content);
- $sup->set("story_author", ($this->story_author != "") ? $this->story_author : NULLVALUE);
- $sup->set("story_type", $this->story_type);
- $sup->set("story_icon_url", $this->story_icon_url);
- $sup->set("category_id", ($this->story_category !== false) ? $this->story_category : NULLVALUE);
- if (isset($this->story_icon) && $this->story_icon !== "") {
- $sup->set("story_icon", $this->story_icon->catalogitem->cat_id);
- }
- else {
- $sup->set("story_icon", NULLVALUE);
- }
- if ($this->story_date_ts == 0) {
- $sup->set("story_date", NULLVALUE);
- }
- else {
- $sup->set("story_date", timestamp_to_datetime($this->story_date_ts));
- }
- if ($this->expiry_date_ts == 0) {
- $sup->set("expiry_date", NULLVALUE);
- }
- else {
- $sup->set("expiry_date", timestamp_to_datetime($this->expiry_date_ts));
- }
- $sup->set("last_modified", 'now()');
- $sup->set("visible", $this->visible);
- $sup->set("deleted", $this->deleted);
- $sup->where("story_id=$this->story_id");
- if ($sup->execute()) {
- // Index to Lucene..
- $this->index();
- $this->newstory = false;
- }
- }
- } // save_story
- // .....................................................................
- /** Remove the story from the system. We actually just flag it as
- * deleted on the database, and keep the record.
- */
- function delete_story() {
- global $RESPONSE, $CONTEXT;
- if ($this->valid && !$this->deleted) {
- $del = new dbupdate("ax_story");
- $del->set("deleted", true);
- $del->where("story_id=$this->story_id");
- $this->deleted = $del->execute();
- if ($this->deleted) {
- if ($RESPONSE->microsites_mode == MICROSITES_ENABLED) {
- $msdel = new dbdelete("ax_microsite_story");
- $msdel->where("story_id=$this->story_id");
- $msdel->execute();
- }
- $this->unindex();
- $this->info_msg = "Story has been marked as deleted";
- }
- }
- } // delete_story
- // .....................................................................
- /** Process the POST from form. This method deals with POSTed content
- * from the edit form.
- */
- function POSTprocess() {
- global $RESPONSE;
- global $storysave_x; // Clicked save
- global $storyedit_x; // Clicked edit
- global $storycancel_x; // Clicked cancel
- global $translate_x; // Clicked translate
- global $story_headline; // Story headline
- global $story_precis; // Story precis/lead-in
- global $story_content; // Story content
- global $story_media; // Reference to picture, movie etc.
- global $story_icon; // Reference to icon catalog item
- global $story_icon_url; // URL for story icon
- global $uploadmedia; // Uploaded media file present
- global $story_locs; // List of locations to publish to
- global $caption; // New image caption
- global $media_justify; // Image justify setting 'left' or 'right'
- global $media_width; // Image width px
- global $media_height; // Image height px
- global $story_author; // Story author
- global $story_type; // Story type
- global $story_date; // Story date setting
- global $story_language; // Story language setting
- global $new_language; // New story langauage - translated
- global $expiry_date; // Expiry date setting
- global $visible; // Visible flag
- debugbr("POSTprocess: storymode initial: $this->storymode", DBG_DEBUG);
- debugbr("story microsite: '$this->microsite_name'");
- // Save story
- if (isset($storysave_x)) {
- if (isset($story_headline)) $this->story_headline = $story_headline;
- if (isset($story_precis)) $this->story_precis = $story_precis;
- if (isset($story_content)) $this->story_content = $story_content;
- if (isset($story_author)) $this->story_author = $story_author;
- if (isset($story_type)) $this->story_type = $story_type;
- if (isset($story_icon_url)) $this->story_icon_url = $story_icon_url;
- if ($this->has_multilang && isset($story_language)) {
- $this->language = $story_language;
- }
- // Story dates..
- if (isset($story_date)) {
- $this->story_date = $story_date;
- if ($story_date != "") {
- // Convert user-supplied date-time..
- $this->story_date_ts = displaydate_to_timestamp($story_date);
- }
- else {
- // Supply default of 'now'. Story date must have a value..
- $this->story_date_ts = time();
- }
- $this->story_date = timestamp_to_displaydate(DISPLAY_DATE_FORMAT, $this->story_date_ts);
- }
- if ($this->has_expiry && isset($expiry_date)) {
- $this->expiry_date = $expiry_date;
- if ($expiry_date != "") {
- $this->expiry_date_ts = displaydate_to_timestamp($expiry_date);
- $this->expiry_date = timestamp_to_displaydate(DISPLAY_DATE_FORMAT, $this->expiry_date_ts);
- }
- else {
- $this->expiry_date_ts = 0;
- }
- }
- // Visible flag..
- $this->visible = isset($visible);
- // Story icon
- if (isset($story_icon) && $story_icon != "") {
- $icon_bits = explode("|", $story_icon);
- $cat_id = $icon_bits[0];
- $newci = new catalogitem($cat_id);
- if ($newci->valid) {
- $this->story_icon = new story_media($this->story_id, $newci);
- }
- }
- else {
- unset($this->story_icon);
- }
- // Save it if changed..
- $this->save_story();
- // Microsite story link for new stories..
- if ($this->storymode == "adding" && isset($this->microsite_name)) {
- $mssin = new dbinsert("ax_microsite_story");
- $mssin->set("microsite_name", $this->microsite_name);
- $mssin->set("story_id", $this->story_id);
- $mssin->execute();
- }
- // Media data POSTings..
- if ($this->has_media) {
- // Some defaults..
- if ($media_width == "") $media_width = 0;
- if ($media_height == "") $media_height = 0;
- // Deal with a new media file upload. In this case we
- // assume we are just adding, if we have multimedia set
- // otherwise we will clear out pre-existing media first..
- $smdel = new dbdelete("ax_story_media");
- $smdel->where("story_id=$this->story_id");
- $smdel->execute();
- $this->story_media = array();
- if (isset($uploadmedia) && $uploadmedia != "none" && $uploadmedia != "") {
- $newci = new catalogitem();
- $errmsgs = $newci->upload($caption, $this->category);
- if ($newci->valid) {
- $smin = new dbinsert("ax_story_media");
- $smin->set("story_id", $this->story_id);
- $smin->set("cat_id", $newci->cat_id);
- $smin->set("caption", $caption);
- $smin->set("justify", $media_justify);
- $smin->set("width", $media_width);
- $smin->set("height", $media_height);
- $smin->execute();
- $media = new story_media($this->story_id, $newci);
- $media->caption = $caption;
- $media->justify = $media_justify;
- $media->width = $media_width;
- $media->height = $media_height;
- $this->story_media[$newci->cat_id] = $media;
- }
- else {
- if (count($errmsgs) > 0) {
- $this->info_msg = implode("<br>", $errmsgs);
- }
- }
- }
- // Otherwise, just re-create the media refs..
- else {
- $smdel = new dbdelete("ax_story_media");
- $smdel->where("story_id=$this->story_id");
- $smdel->execute();
- // Turn incoming value(s) into an array..
- $new_story_media = array();
- if (is_array($story_media)) {
- $new_story_media = $story_media;
- }
- elseif ($story_media != "") {
- $new_story_media = array($story_media);
- }
- // Start from scratch and rebuild media array..
- $this->story_media = array();
- foreach ($new_story_media as $cat_info) {
- if ($cat_info != "") {
- $cat_bits = explode("|", $cat_info);
- $cat_id = $cat_bits[0];
- $newci = new catalogitem($cat_id);
- if ($newci->valid) {
- // Save it to database..
- $ssin = new dbinsert("ax_story_media");
- $ssin->set("story_id", $this->story_id);
- $ssin->set("cat_id", $cat_id);
- $ssin->set("caption", $caption);
- $ssin->set("justify", $media_justify);
- $ssin->set("width", $media_width);
- $ssin->set("height", $media_height);
- $ssin->execute();
- // Save it to local media array too..
- $media = new story_media($this->story_id, $newci);
- $media->caption = $caption;
- $media->justify = $media_justify;
- $media->width = $media_width;
- $media->height = $media_height;
- $this->story_media[$cat_id] = $media;
- }
- }
- } // foreach
- }
- } // has_media
- // Story publish to locations..
- $sldel = new dbdelete("ax_story_location");
- $sldel->where("story_id=$this->story_id");
- $sldel->execute();
- $this->story_locs = array();
- if (isset($story_locs)) {
- foreach ($story_locs as $loc_id) {
- if ($loc_id != "") {
- $slin = new dbinsert("ax_story_location");
- $slin->set("story_id", $this->story_id);
- $slin->set("location_id", $loc_id);
- $slin->execute();
- }
- }
- $this->story_locs = $story_locs;
- }
- $this->info_msg = "Story was saved";
- $this->storymode = "viewagain";
- } // storysave_x
- // Edit story
- elseif (isset($storyedit_x)) {
- $this->storymode = "edit";
- } // storyedit_x
- // Cancel current mode
- elseif (isset($storycancel_x)) {
- $this->storymode = "viewagain";
- } // storycancel_x
- // Translate current story into new language.
- elseif (isset($translate_x)) {
- $translation = $this->get_translation($new_language);
- if ($translation !== false) {
- $this->get_story($translation);
- }
- } // translate_x
- // Remove story
- elseif ($this->storymode == "remove") {
- $this->delete_story();
- $this->storymode = "viewagain";
- } // remove
- debugbr("POSTprocess: storymode final: $this->storymode", DBG_DEBUG);
- } // story POSTprocess
- // .....................................................................
- /**
- * Returns the story_id of a translation of the current story in the
- * given language. If it already exists, then it just returns the story
- * ID. If it doesn't exist, then it simply makes a copy of this story,
- * assigns it the language it _will_ be translated into, and records a
- * relationship to the other associated translations in the database table
- * 'story_tranlsation'. This latter table allows us to put a list of
- * languages (or little country flags) on any stories which have alternatives
- * in another language.
- * @param integer $language Language to get translated story in
- */
- function get_translation($language) {
- // Check if this story already has a translation available, and
- // we just return the translated story id if so..
- $this->get_story_translations();
- foreach ($this->story_translations as $translated_storyid => $chklang) {
- if ($chklang == $language) {
- return $translated_storyid;
- break;
- }
- }
- // Preserve some info for use later on..
- $original_story_id = $this->story_id;
- $original_translations = $this->story_translations;
- // Create new story..
- start_transaction();
- $this->story_id = get_next_sequencevalue("seq_story_id", "ax_story", "story_id");
- // Set the new language..
- $this->language = $language;
- $this->story_date_ts = time();
- $this->story_date = timestamp_to_displaydate(DISPLAY_DATE_FORMAT, $this->story_date_ts);
- $this->newstory = true;
- $this->valid = true;
- $this->save_story();
- // Duplicate media..
- $ord = 1;
- foreach ($this->story_media as $cat_id => $media) {
- $in = new dbinsert("ax_story_media");
- $in->set("story_id", $this->story_id);
- $in->set("cat_id", $cat_id);
- $in->set("caption", $media->caption);
- $in->set("width", $media->width);
- $in->set("height", $media->height);
- $in->set("justify", $media->justify);
- $in->set("display_order", $ord++);
- $in->execute();
- }
- // Duplicate sports..
- foreach ($this->story_sports as $sport_id) {
- $in = new dbinsert("ax_story_sport");
- $in->set("story_id", $this->story_id);
- $in->set("sport_id", $sport_id);
- $in->execute();
- }
- // Duplicate locations..
- $ord = 1;
- foreach ($this->story_locs as $loc_id) {
- $in = new dbinsert("ax_story_location");
- $in->set("story_id", $this->story_id);
- $in->set("location_id", $loc_id);
- $in->set("display_order", $ord++);
- $in->execute();
- }
- if (commit()) {
- // Create translated story relationship..
- if ($this->root_translation_id == -1) {
- $root_trans_id = $original_story_id;
- }
- else {
- $root_trans_id = $this->root_translation_id;
- }
- $in = new dbinsert("ax_story_translation");
- $in->set("story_id", $root_trans_id);
- $in->set("translated_story_id", $this->story_id);
- $in->execute();
- }
- return $this->story_id;
- } // translate_into
- // .....................................................................
- /** Do a re-count of the story words. Set our local variable
- * and also return the value as a by-product..
- * @return integer Count of words in the story
- */
- function word_count() {
- $words = explode(" ",
- $this->story_headline . " "
- . $this->story_precis . " "
- . $this->story_content
- );
- return count($words);
- } // word_count
- // .....................................................................
- /** Generate a precis from the story content.
- * @param integer $maxwords Maximum number of words for the precis
- * @param integer $minwords Minimum number of words for the precis
- * @return string The precis
- */
- function make_precis($maxwords=50, $minwords=5) {
- $precis = "";
- $patt = "(([\S]+[\s]+){" . $minwords . "," . $maxwords . "})";
- preg_match("/$patt/", strip_tags($this->story_content), $matches);
- if (isset($matches[1])) {
- $precis = $matches[1];
- }
- $precis = str_replace("\x0d\x0a", " ", $precis);
- return $precis;
- } // make_precis
- // .....................................................................
- /**
- * Return the rendering of the story icon (if one exists) either as a
- * standard HTML anchor tag if an icon URL exists, or as an image.
- * @return string HTML for anchor or image of the story icon
- */
- function render_story_icon() {
- $s = "";
- if (isset($this->story_icon) && is_object($this->story_icon)) {
- $s = $this->story_icon->catalogitem->Insitu();
- if ($this->story_icon_url != "") {
- $a = new anchor($this->story_icon_url, $s);
- if (stristr($this->story_icon_url, "http")) {
- $a->settarget("_new");
- }
- $s = $a->render();
- }
- }
- return $s;
- } // render_story_icon
- // .....................................................................
- /** Render the story details as an edit form.
- * @return string The editform complete.
- */
- function editform() {
- global $RESPONSE;
- global $LIBDIR, $CMDIR, $IMAGESDIR;
- global $width, $width_img_preview;
- global $widthpx, $smlwidthpx, $stdwidthpx, $bigwidthpx;
- // CONTROL BUTTONS
- $s = "";
- if ($this->user_can_edit()) {
- $savb = new form_imagebutton("storysave", "Save", "", "$LIBDIR/img/_save.gif", "Save changes", 57, 15);
- $canb = new form_imagebutton("storycancel", "Cancel", "", "$LIBDIR/img/_cancel.gif", "Cancel", 57, 15);
- if ($this->newstory) {
- $canb->set_onclick("window.close()");
- }
- $s .= $savb->render() . " " . $canb->render();
- }
- $CONTROL_BUTTONS = $s;
- $Tst = new table("story");
- $Tst->setpadding(4);
- $rowbg = "axbglite";
- // EDITOR HEADER
- $Thd = new table("editor heading");
- $Thd->tr($rowbg);
- $title = "$this->story_category_desc ";
- if ($this->newstory) {
- $title .= "New Article";
- }
- else {
- $title .= "Editor";
- }
- $Thd->td("<h3>$title</h3>", "axfg");
- $Thd->td($CONTROL_BUTTONS);
- $Thd->td_alignment("right");
- $Tst->tr($rowbg);
- $Tst->td($Thd->render(), "border-bottom:1px solid black");
- $Tst->td_colspan(2);
- // ERRMSG
- if ($this->info_msg != "") {
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td($this->info_msg, "axerror");
- $Tst->td_colspan(2);
- $Tst->td_alignment("center");
- }
- // MICROSITE
- if (isset($this->microsite_name)) {
- $Fld = new form_labelfield("story_microsite", $this->microsite_name);
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td("Microsite:", "axfg");
- $Tst->td($Fld->render());
- }
- // HEADLINE
- $Fld = new form_textfield("story_headline", "Headline", $this->story_headline);
- $Fld->setclass("axtxtbox");
- $Fld->setstyle("width:$widthpx;");
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td("Headline:", "axfg");
- $Tst->td_css("padding-top:10px;");
- $Tst->td($Fld->render());
- $Tst->td_css("padding-top:10px;");
- // PRECIS/LEAD IN
- if ($this->has_precis) {
- $Fld = new form_wysiwygfield("story_precis", "Lead In", $this->story_precis);
- $Fld->setclass("axmemo");
- $Fld->setstyle("width:$widthpx;height:120px;");
- $Fld->set_statusbar(false);
- $Fld->set_toolbar("basic");
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td("Lead In:", "axfg");
- $Tst->td_css("vertical-align:top;padding-top:5px;");
- $Tst->td($Fld->render());
- }
- // STORY AUTHOR
- if ($RESPONSE->ismemberof_group("Editor")) {
- // Editors can change the author..
- $Fld = new form_combofield("story_author", "Author", $this->story_author);
- $Fld->setclass("axcombo");
- $Fld->setstyle("width:$stdwidthpx;");
- $Fld->additem("");
- $q = "SELECT * FROM ax_user u, ax_user_group ug, ax_group g";
- $q .= " WHERE ug.user_id=u.user_id";
- $q .= " AND g.group_id=ug.group_id";
- $q .= " AND g.group_desc IN ('Editor','Author')";
- $q .= " AND u.enabled";
- $q .= " ORDER BY u.full_name";
- $authors = dbrecordset($q);
- if ($authors->hasdata) {
- $Fld->add_querydata($authors, "user_id", "full_name");
- }
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td("Author:", "axfg");
- $Tst->td($Fld->render());
- }
- else {
- // Standard authors can't change by-line..
- $Fld = new form_labelfield("story_author", "<b>$this->story_author_name ($this->story_author)</b>");
- $hid = new form_hiddenfield("story_author", $this->story_author);
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td("Author:", "axfg");
- $Tst->td($Fld->render() . $hid->render());
- }
- // STORY CONTENT
- $Fld = new form_wysiwygfield("story_content", "Article", $this->story_content);
- $Fld->setclass("axmemo");
- $Fld->setstyle("width:$widthpx;height:350px;");
- $Fld->register_plugins("all");
- $Fld->set_toolbar("full");
- $Fld->set_statusbar(false);
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td("Content:", "axfg");
- $Tst->td_css("vertical-align:top;padding-top:5px;");
- $Tst->td($Fld->render());
- // STORY MEDIA
- if ($this->has_media) {
- // CATALOG
- $catalog = new catalog();
- $catalog->search("", array("image"));
- // Media details table..
- $Tmed = new table("storymedia");
- $Tmed->tr();
- $Tmed->setwidth("100%");
- // Find the first (selected) media object $selmedia_first. This object
- // is used extensively below to populate the various form fields. We
- // currently only properly support one object (the first one).
- if (count($this->story_media) > 0) {
- reset($this->story_media);
- list($catid, $selmedia_first) = each($this->story_media);
- }
- else {
- $selmedia_first = new story_media();
- }
- // Media selector..
- $Fld = new form_combofield("story_media", "Media", $selmedia_first->keyinfo());
- $Fld->setclass("axcombo");
- $Fld->setstyle("width:$bigwidthpx;");
- $Fld->additem("", "None");
- foreach ($catalog->catalogitems as $catid => $catitem) {
- if (isset($this->story_media[$catid])) {
- $media = $this->story_media[$catid];
- }
- else {
- $media = new story_media($this->story_id, $catitem);
- $media->caption = $catitem->cat_name;
- }
- $key = $media->keyinfo();
- $label = $media->catalogitem->cat_name;
- if ($label == "") {
- $label = $media->catalogitem->filepath;
- }
- $Fld->additem($key, $label);
- }
- $Fld->set_onchange("imgPreview(this.options[this.selectedIndex].value)");
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tmed->tr($rowbg);
- $Tmed->td($Fld->render());
- $Tmed->td_alignment("", "top");
- // Create a preview image..
- $imgFld = new img(
- $selmedia_first->catalogitem->filepath,
- "preview",
- "Preview",
- $width_img_preview,
- $height_img_preview
- );
- $imgFld->setalign("right");
- $imgFld->sethspace(4);
- $Tmed->td($imgFld->render());
- $Tmed->td_alignment("right", "top");
- $Tmed->td_rowspan(4);
- // Width and Height override fields
- $sizes_defaulted = ($selmedia_first->width == 0 || $selmedia_first->height == 0);
- if ($sizes_defaulted) {
- $width = $selmedia_first->catalogitem->width;
- $height = $selmedia_first->catalogitem->height;
- }
- else {
- $width = $selmedia_first->width;
- $height = $selmedia_first->height;
- }
- $Tin = new table();
- $Tin->tr();
- $wFld = new form_textfield("media_width", "Width", $width);
- $wFld->setclass("axnumbox");
- $wFld->setstyle("width:50px");
- $hFld = new form_textfield("media_height", "Height", $height);
- $hFld->setclass("axnumbox");
- $hFld->setstyle("width:50px");
- $dFld = new form_checkbox("media_size_default");
- $dFld->setclass("axchkbox");
- $dFld->checked = ($sizes_defaulted === true);
- if ($sizes_defaulted) {
- $wFld->disabled = true;
- $hFld->disabled = true;
- }
- $dFld->set_onclick("defSizingToggle(this)");
- $Tin->td("Sizing:", "axfg");
- $Tin->td($wFld->render() . " x " . $hFld->render() . " Default " . $dFld->render(), "axfg");
- $Tin->set_width_profile("20%,80%");
- $Tmed->tr($rowbg);
- $Tmed->td($Tin->render());
- // Image justify setting
- $Fld = new form_combofield("media_justify", "Justify", $selmedia_first->justify);
- $Fld->setclass("axcombo");
- $Fld->setstyle("width:100px");
- $Fld->additem("", "default");
- $Fld->additem("left", "Left");
- $Fld->additem("right", "Right");
- $Tin = new table();
- $Tin->td("Justify:", "axfg");
- $Tin->td($Fld->render());
- $Tin->set_width_profile("20%,80%");
- $Tmed->tr($rowbg);
- $Tmed->td($Tin->render());
- // File upload field - allows them to add media on the
- // fly to go with a story..
- $Fld = new form_fileuploadfield("uploadmedia", "Upload");
- $Fld->setclass("axtxtbox");
- $Fld->setstyle("width:$smlwidthpx;");
- $Tmed->tr($rowbg);
- $Tmed->td($Fld->render());
- // Now we render the above sub-table $Tmed inside the main table..
- $Tst->tr($rowbg);
- $Tst->td("Image:", "axfg");
- $Tst->td_css("vertical-align:top;padding-top:5px;");
- $Tst->td($Tmed->render());
- // CAPTION
- // NB: We kinda support multiple media, but the issue of them
- // each having a separate caption is not resolved in this current
- // implementation - recommend using a recmaintainer for that
- // when the time comes.
- $Fld = new form_textfield("caption", "Caption", $selmedia_first->caption);
- $Fld->setclass("axtxtbox");
- $Fld->setstyle("width:$stdwidthpx;");
- $Tst->tr($rowbg);
- $Tst->td("Image Caption:", "axfg");
- $Tst->td($Fld->render());
- $Tmed = new table("storyicon");
- $Tmed->tr();
- $Tmed->setwidth("100%");
- if (isset($this->story_icon)) {
- $selicon_first = $this->story_icon;
- }
- else {
- $selicon_first = new story_media();
- }
- // Icon selector..
- $Fld = new form_combofield("story_icon", "Icon", $selicon_first->keyinfo());
- $Fld->setclass("axcombo");
- $Fld->setstyle("width:$bigwidthpx;");
- $Fld->additem("", "None");
- foreach ($catalog->catalogitems as $catid => $catitem) {
- $icon = new story_media($this->story_id, $catitem);
- $icon->caption = $catitem->cat_name;
- $key = $icon->keyinfo();
- $label = $icon->catalogitem->cat_name;
- if ($label == "") {
- $label = $icon->catalogitem->filepath;
- }
- $Fld->additem($key, $label);
- }
- $Fld->set_onchange("iconPreview(this.options[this.selectedIndex].value)");
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tmed->tr($rowbg);
- $Tmed->td($Fld->render());
- $Tmed->td_alignment("", "top");
- // Create a preview icon..
- $imgFld = new img(
- $selicon_first->catalogitem->filepath,
- "iconpreview",
- "Icon Preview",
- $width_icon_preview,
- $height_icon_preview
- );
- $imgFld->setalign("right");
- $imgFld->sethspace(4);
- $Tmed->td($imgFld->render());
- $Tmed->td_alignment("right", "top");
- $Tmed->td_rowspan(2);
- // Now we render the above sub-table $Tmed inside the main table..
- $Tst->tr($rowbg);
- $Tst->td("Icon:", "axfg");
- $Tst->td($Tmed->render());
- // Icon URL entry field
- $Fld = new form_textfield("story_icon_url", "Url", $this->story_icon_url);
- $Fld->setclass("axtxtbox");
- $Fld->setstyle("width:$stdwidthpx");
- $Tst->tr($rowbg);
- $Tst->td("Link to:", "axfg");
- $Tst->td($Fld->render());
- // This allows us to preview images without refresh..
- $RESPONSE->head->add_script(
- "function imgPreview(key) {\n"
- . " var keyparts=key.split('|');\n"
- . " var imgfile=keyparts[1];\n"
- . " if (imgfile!='') {\n"
- . " document.$this->formname.preview.src=imgfile;\n"
- . " }\n"
- . "}\n"
- . "function iconPreview(key) {\n"
- . " var keyparts=key.split('|');\n"
- . " var iconfile=keyparts[1];\n"
- . " if (iconfile!='') {\n"
- . " document.$this->formname.iconpreview.src=iconfile;\n"
- . " }\n"
- . "}\n"
- . "function defSizingToggle(chkbox) {\n"
- . " if (chkbox.checked) {\n"
- . " document.$this->formname.media_width.value='';\n"
- . " document.$this->formname.media_width.disabled=true;\n"
- . " document.$this->formname.media_height.value='';\n"
- . " document.$this->formname.media_height.disabled=true;\n"
- . " }\n"
- . " else {\n"
- . " document.$this->formname.media_width.disabled=false;\n"
- . " document.$this->formname.media_height.disabled=false;\n"
- . " }\n"
- . "}\n"
- );
- }
- // STORY DATE
- $Fld = new form_textfield("story_date", "Article date", $this->story_date);
- $Fld->setclass("axdatetime");
- $Fld->setstyle("width:$smlwidthpx;");
- $Fld->set_onblur("isNonBlank(this, 'Please fill in a story date.');");
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td("Article Date:", "axfg");
- $Tst->td($Fld->render() . " <small><i>eg: dd/mm/yyyy [hh:mm]</i></small>");
- // EXPIRY DATE
- if ($this->has_expiry) {
- $Fld = new form_textfield("expiry_date", "Expiry date", $this->expiry_date);
- $Fld->setclass("axdatetime");
- $Fld->setstyle("width:$smlwidthpx;");
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td("Expiry Date:", "axfg");
- $Tst->td($Fld->render());
- }
- // STORY TYPE
- $Fld = new form_combofield("story_type", "Article type", $this->story_type);
- $Fld->setclass("axcombo");
- $Fld->setstyle("width:$smlwidthpx;");
- $Fld->additem("n", "News item");
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td("Article Type:", "axfg");
- $Tst->td($Fld->render());
- // LANGUAGE
- if ($this->has_multilang) {
- $this->get_story_translations();
- $Tlng = new table("language");
- $Fld = new form_combofield("story_language", "", $this->language);
- $Fld->setclass("axcombo");
- $Fld->setstyle("width:$smlwidthpx;");
- // Fill the dropdown selector with all possibilities..
- $q = "SELECT * FROM ax_language";
- $q .= " WHERE enabled=TRUE";
- $q .= " ORDER BY display_order";
- $langs = dbrecordset($q);
- if ($langs->hasdata) {
- $Fld->add_querydata($langs, "lang_id", "lang_desc");
- }
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tlng->tr($rowbg);
- $Tlng->td($Fld->render());
- $Fld = new form_combofield("new_language");
- $Fld->setclass("axcombo");
- $Fld->setstyle("width:$smlwidthpx;");
- $Fld->additem("", "— Translate into —");
- // Determine languages already translated..
- $already_translated = array($this->language);
- foreach ($this->story_translations as $sid => $langid) {
- $already_translated[] = $langid;
- }
- $q = "SELECT * FROM ax_language WHERE enabled=TRUE";
- if (count($already_translated) > 0) {
- $langlist = implode(",", $already_translated);
- if ($langlist != "") {
- $q .= " AND NOT lang_id IN (" . implode(",", $already_translated) . ")";
- }
- }
- $q .= " ORDER BY display_order";
- $tlangs = dbrecordset($q);
- if ($tlangs->hasdata) {
- $Fld->add_querydata($tlangs, "lang_id", "lang_desc");
- }
- $transbtn = new form_imagebutton("translate", "", "", "$LIBDIR/img/_translate.gif", "Translate", 77, 15);
- $Tlng->td($Fld->render());
- $Tlng->td_alignment("right");
- $Tlng->td($transbtn->render());
- $Tlng->td_alignment("left");
- if (count($this->story_translations) > 0) {
- $translist = array();
- foreach ($this->story_translations as $trans_story_id => $trans_lang_id) {
- $lq = dbrecordset("SELECT * FROM ax_language WHERE lang_id=$trans_lang_id");
- if ($lq->hasdata) {
- $translist[] = ucfirst($lq->field("lang_desc"));
- }
- }
- if (count($translist) > 0) {
- $Tlng->tr($rowbg);
- $Tlng->td("Existing Translations: " . implode(" | ", $translist));
- $Tlng->td_colspan(2);
- }
- }
- $Tst->tr($rowbg);
- $Tst->td("Language:", "axfg");
- $Tst->td_alignment("", "top");
- $Tst->td($Tlng->render());
- }
- // VISIBLE
- $Fld = new form_checkbox("visible", "Visible");
- $Fld->checked = $this->visible;
- $Fld->setclass("axchkbox");
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td("Visible:", "axfg");
- $Tst->td($Fld->render());
- // STORY LOCATIONS
- $Fld = new form_combofield("story_locs", "", $this->story_locs);
- $Fld->multiselect = true;
- $Fld->setclass("axlistbox");
- $Fld->size = 6;
- $Fld->setstyle("width:$stdwidthpx;");
- $q = "SELECT * FROM ax_content_location";
- $q .= " WHERE enabled=TRUE";
- $q .= " ORDER BY location_name";
- $locs = dbrecordset($q);
- if ($locs->hasdata) {
- $Fld->add_querydata($locs, "location_id", "location_name");
- }
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td("Publish to:", "axfg");
- $Tst->td_alignment("", "top");
- $Tst->td($Fld->render());
- // LAST MODIFIED
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tst->tr($rowbg);
- $Tst->td("Last modified:", "axfg");
- $Tst->td($this->lastmodified);
- // Rule-off row..
- $Tst->tr("axfoot");
- $Tst->td("", "axfoot");
- $Tst->td_colspan(2);
- $Tst->set_width_profile("20%,80%");
- // Add field validation scripts..
- $RESPONSE->add_scriptsrc("$LIBDIR/js/fieldvalidation.js");
- return $Tst->render();
- } // editform
- // .....................................................................
- /** Render the story as a maintainer reader would view it. Note that this
- * is not a fully dressed-up story viewer. It is designed as a view that
- * a story administrator would see, showing all the technical bits and
- * pieces such as story byte-size etc. You should create your own viewer
- * for rendering stories 'prettily' on your website.
- * @return string The HTML for the view story content.
- */
- function view() {
- global $RESPONSE;
- global $LIBDIR;
- // CONTROL BUTTONS
- $s = "";
- // Buttons for administrators and editors only..
- $doneb = new form_imagebutton("closewin", "Close", "", "$LIBDIR/img/_done.gif", "Close viewer", 57, 15);
- $doneb->set_onclick("window.close()");
- if ($this->user_can_edit()) {
- $editb = new form_imagebutton("storyedit", "Edit", "", "$LIBDIR/img/_edit.gif", "Edit this article", 42, 15);
- $remvb = new form_imagebutton("storyremove", "Delete", "", "$LIBDIR/img/_delete.gif", "Delete this article", 57, 15);
- $remvb->set_onclick("remove_confirm()");
- $s .= $editb->render() . " " . $remvb->render();
- // Removal protection..
- $RESPONSE->head->add_script(
- "function remove_confirm() {\n"
- . " var msg = '\\n\\nWARNING: Do you really want to delete\\n';\n"
- . " msg += 'the article. This is irrevocable.\\n';"
- . " rc = confirm(msg);\n"
- . " if (rc) {\n"
- . " document.$this->formname.storymode.value='remove';\n"
- . " document.$this->formname.submit();\n"
- . " }\n"
- . " else alert('Delete is cancelled.');\n"
- . "}\n"
- );
- }
- if ($s != "") $s .= " ";
- $s .= $doneb->render();
- $CONTROL_BUTTONS = $s;
- $Tvw = new table("storyviewer");
- $Tvw->setpadding(3);
- $rowbg = "axbgdark";
- // EDITOR HEADER
- $Thd = new table("viewerhead");
- $Thd->tr($rowbg);
- $title = $this->story_category_desc;
- if (isset($this->microsite_name)) {
- $title .= "<br><small>(Microsite $this->microsite_name)</small>";
- }
- $Thd->td("<h3>$title</h3>", "axfg");
- $Thd->td($CONTROL_BUTTONS);
- $Thd->td_alignment("right", "bottom");
- if ($this->language != 0) {
- $lq = dbrecordset("SELECT * FROM ax_language WHERE lang_id=$this->language");
- if ($lq->hasdata) {
- $Thd->tr($rowbg);
- $Thd->td("in " . $lq->field("lang_desc"));
- $Thd->td_colspan(2);
- }
- }
- $Tvw->tr($rowbg);
- $Tvw->td($Thd->render(), "border-bottom:1px solid black");
- $Tvw->td_colspan(2);
- if ($this->info_msg != "") {
- $Tvw->tr($rowbg);
- $Tvw->td($this->info_msg, "axerror");
- $Tvw->td_colspan(2);
- $Tvw->td_alignment("center");
- }
- // HEADLINE, BY-LINE, STORY TYPE & WORDCOUNT
- // STORY TYPE
- switch ($this->story_type) {
- case "n":
- $type = "News article";
- break;
- default:
- $type = "";
- }
- $Thd = new table("masthead");
- $Thd->tr($rowbg);
- $Thd->td("<h2>" . $this->story_headline . "</h2>",
- "vertical-align:bottom;padding-bottom:0px;margin-bottom:0px;"
- );
- $Thd->td($type);
- $Thd->td_alignment("right");
- $Thd->tr($rowbg);
- $byline = "by ";
- $byline .= ($this->story_author_name != "") ? $this->story_author_name : "(anonymous)";
- $Thd->td("<h6>$byline</h6>",
- "vertical-align:top;padding-bottom:5px;"
- );
- $Thd->td($this->wordcount . " words (" . nicebytesize($this->bytesize) . ")");
- $Thd->td_alignment("right");
- if (isset($this->story_icon)) {
- $Thd->tr();
- $Thd->td($this->render_story_icon());
- $Thd->td_colspan(2);
- }
- $Tvw->tr($rowbg);
- $Tvw->td($Thd->render());
- $Tvw->td_colspan(2);
- // STORY DATE & EXPIRY DATE
- $Tvw->tr($rowbg);
- $Tvw->td( timestamp_to_displaydate(NICE_FULLDATETIME, $this->story_date_ts) );
- if ($this->has_expiry && $this->expiry_date != "") {
- if ($this->expiry_date_ts - $this->story_date_ts > 0) {
- $Tvw->td("expires on " . timestamp_to_displaydate(NICE_FULLDATETIME, $this->expiry_date_ts));
- }
- else {
- $Tvw->td("expired as of " . timestamp_to_displaydate(NICE_FULLDATETIME, $this->expiry_date_ts), "axhl");
- }
- $Tvw->td_alignment("right");
- }
- else {
- $Tvw->td(" ");
- }
- // PUBLISHING STATUS
- $status = "<b>Published to:</b> ";
- if (!$this->visible) {
- $status .= "Currently hidden";
- }
- else {
- if (count($this->story_locs) == 0) {
- $status .= "No location is selected";
- }
- else {
- $q .= "SELECT * FROM ax_content_location";
- $q .= " WHERE location_id in (" . implode(",", $this->story_locs) . ")";
- $locs = dbrecordset($q);
- if ($locs->hasdata) {
- $locnames = array();
- do {
- $locnames[] = $locs->field("location_name");
- } while ($locs->get_next());
- $status .= implode(", ", $locnames);
- }
- }
- }
- $Tvw->tr($rowbg);
- $Tvw->td($status, "padding-top:5px;padding-bottom:5px;border-top:1px solid black");
- $Tvw->td_colspan(2);
- // LEAD-IN & STORY CONTENT
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tvw->tr($rowbg);
- //$content = $this->story_precis . " " . $this->story_content;
- $media_content = "";
- if ($this->has_media) {
- if (count($this->story_media) > 0) {
- foreach ($this->story_media as $cat_id => $media) {
- $width = ($media->width > 0) ? $media->width : $media->catalogitem->width;
- $height = ($media->height > 0) ? $media->height : $media->catalogitem->height;
- $caption = ($media->caption != "") ? $media->caption : $media->catalogitem->cat_name;
- $pic = new img(
- $media->catalogitem->filepath,
- $caption,
- $caption,
- ($width > 0 ? $width : false),
- ($height > 0 ? $height : false)
- );
- $pic->setalign(($media->justify != "") ? $media->justify : "right");
- $pic->setstyle("padding:2px");
- $media_content .= $pic->render();
- } // foreach
- }
- }
- // Content..
- if (trim($this->story_precis) != "") {
- $content .= str_replace("\r\n\r\n", "<p>", trim($this->story_precis));
- }
- if (trim($media_content) != "") {
- $content .= $media_content;
- }
- if (trim($this->story_content) != "") {
- $content .= str_replace("\r\n\r\n", "<p>", trim($this->story_content));
- }
- $Tvw->td($content, "padding-top:20px;padding-bottom:50px;border-top:1px solid black");
- $Tvw->td_colspan(2);
- // TRANSLATIONS
- $this->get_story_translations();
- if (count($this->story_translations) > 0) {
- $RESPONSE->head->add_script(
- "function reloadViewer(url) {\n"
- . " document.location=url;\n"
- . "}\n"
- );
- $translinks = array();
- foreach ($this->story_translations as $trans_story_id => $trans_lang_id) {
- $lq = dbrecordset("SELECT * FROM ax_language WHERE lang_id=$trans_lang_id");
- if ($lq->hasdata) {
- $auth_code = $RESPONSE->get_auth_code();
- $shref = "/story-viewer.php";
- $shref = href_addparm($shref, "story_id", $trans_story_id);
- $shref = href_addparm($shref, "auth_code", $auth_code);
- $href = "javascript:reloadViewer('$shref')";
- $translink = new anchor($href, ucfirst($lq->field("lang_desc")));
- $translinks[] = $translink->render();
- }
- }
- if (count($translinks) > 0) {
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tvw->tr($rowbg);
- $Tvw->td("Translations: " . implode(" | ", $translinks), "border-top:1px solid black");
- $Tvw->td_colspan(2);
- }
- }
- // LAST MODIFIED
- $rowbg = ($rowbg == "axbglite") ? "axbgdark" : "axbglite";
- $Tvw->tr($rowbg);
- $Tvw->td("Last modified: $this->lastmodified",
- "border-top:1px solid black"
- );
- $Tvw->td("#$this->story_id", "border-top:1px solid black");
- $Tvw->td_alignment("right");
- // Rule-off row..
- $Tvw->tr("axfoot");
- $Tvw->td("", "axfoot");
- $Tvw->td_colspan(2);
- return $Tvw->render();
- } // view
- // .....................................................................
- /**
- * Return the content of this story formatted for plaintext display
- * @param integer $wrapchars Number of characters to wrap the lines at
- */
- function plaintext_content($wrapchars=0) {
- // Join all hard-breaks into single lines..
- $content = str_replace("\n", " ", $this->story_content);
- // Split into paragraphs..
- $paras = explode("<p>", $content);
- // Wrap each paragrph if required..
- if ($wrapchars > 0) {
- $newparas = array();
- foreach ($paras as $para) {
- $para = wordwrap($para, $wrapchars, "\r\n");
- $newparas[] = $para;
- }
- $paras = $newparas;
- }
- // Join up into multiple paragraphs split by CRLF..
- $content = strip_tags( implode("\r\n\r\n", $paras) );
- return $content;
- } // plaintext_content
- // .....................................................................
- /** Render the story. We render the story as a table within a form containing all
- * the form elements required to manipulate the story content, email it to
- * someone, save it, and delete it etc...
- * @return string The HTML for edit or view.
- */
- function html() {
- global $RESPONSE;
- // HIDDEN FIELDS
- $cathid = new form_hiddenfield("cat", $this->story_category);
- $authhid = new form_hiddenfield("auth_code", $RESPONSE->auth_code);
- $modehid = new form_hiddenfield("storymode", $this->storymode);
- $sidhid = new form_hiddenfield("story_id", $this->story_id);
- // STORY FORM, VIEW or EDIT..
- switch ($this->storymode) {
- case "edit":
- case "adding":
- $story_form = new multipart_form($this->formname);
- $story_form->add_text($this->editform());
- break;
- default:
- $story_form = new form($this->formname);
- $story_form->add_text($this->view());
- } // switch
- // Render hidden fields too..
- $story_form->add($cathid);
- $story_form->add($authhid);
- $story_form->add($modehid);
- $story_form->add($sidhid);
- return $story_form->render();
- } // story html
- } // story class
- // -----------------------------------------------------------------------
- /**
- * A container class for media item associated with a story. Contains
- * a single piece of media which is associated with this story.
- * @package cm
- */
- class story_media {
- /** ID of story this media belongs to */
- var $story_id = false;
- /** The catalogitem object */
- var $catalogitem;
- /** The caption for this item */
- var $caption = "";
- /** The way to justify this item */
- var $justify = "";
- /** Local override width */
- var $width = 0;
- /** Local override height */
- var $height = 0;
- // .....................................................................
- /**
- * Create a new piece of story media. This comprises a catalogitem
- * object, and a set of methods to access it.
- * @param mixed $id Story ID, or false if not known
- * @param mixed $item Object catalogitem, or false if initially undefined
- */
- function story_media($story_id=false, $item=false) {
- if ($story_id !== false) {
- $this->story_id = $story_id;
- }
- if ($item !== false && is_object($item)) {
- $this->catalogitem = $item;
- }
- else {
- $this->catalogitem = new catalogitem();
- }
- } // story_media
- // .....................................................................
- /**
- * Define this story media object from the given catalog item key. This
- * will obtain the given piece of catalog media from the database and
- * assign the object variables accordingly.
- * @param integer $catid Catalog item ID to obtain
- */
- function get_catalogitem($catid) {
- $this->catalogitem = new catalogitem($catid);
- } // get_catalogitem
- // .....................................................................
- /**
- * Return the keyinfo string for this media item. This is encoded
- * as follows, and is used in select combos:
- * 'cat_id|filepath|width|height|justify'
- */
- function keyinfo() {
- $info = array();
- if (isset($this->catalogitem)) {
- $info[] = $this->catalogitem->cat_id;
- $info[] = $this->catalogitem->filepath;
- $info[] = ($this->width != 0) ? $this->width : $this->catalogitem->width;
- $info[] = ($this->height != 0) ? $this->height : $this->catalogitem->height;
- $info[] = $this->justify;
- }
- return implode("|", $info);
- } // keyinfo
- } // story_media class
- // -----------------------------------------------------------------------
- ?>
Documentation generated by phpDocumentor 1.3.0RC3