|
From: <ada...@us...> - 2003-07-09 20:24:27
|
Update of /cvsroot/phpwebsite-comm/modules/article/class
In directory sc8-pr-cvs1:/tmp/cvs-serv30555/class
Added Files:
Article.php ArticleManager.php Section.php
Log Message:
Initial commit to CVS
--- NEW FILE: Article.php ---
<?php
/**
* This is the PHPWS_Article class. It handles saving, updating, and organization
* of sections. It also contains functions that allow this article to be edited
* and saved.
*
* @version \$Id\$
*
* @author Eloi George <el...@NO...>
* @basecode Adam Morton's PageMaster Module
* @module Article Manager
* @param int id : Database id of this article
* @param string title : Title of this article
* @param array sections : Array of sections controlled by this article (key=SECT_id, value=SECT_OBJ)
* @param array order : Array denoting the order of the sections within this article (key=order 0,1,2..., value=SECT_id)
* @param int sectionID : Generated alphabetical temporary section ids
* @param array RemoveList : Generated array of sections to be deleted on article save
* @param int mainarticle : Whether this article is the main article for this site or not
* @param int rank : This article's priority position in a summary listing
[...1061 lines suppressed...]
return $timeleft;
return FALSE;
}
/**
* Displays this article's row in a fatCat category display
*
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param id : Id of the article to show.
*/
function view_category_row ($id)
{
$this = new PHPWS_Article($id);
$this->view(false);
}
}
?>
--- NEW FILE: ArticleManager.php ---
<?php
/**
* This is the PHPWS_ArticleManager class. It controls interaction and
* organization with PHPWS_Article objects.
*
* @version \$Id\$
*
* @author Eloi George <el...@NO...>
* @basecode Adam Morton's PageMaster Module
* @module Article Manager
* @param object homearticle : The current homearticle stored as a PHPWS_Article object.
* @param int home_num : Number of summaries that will be displayed on the home page.
* @param array articles : Array of article rows to be displayed.
* @param string list_group : Specifies whether to show all stories or just the User's stories.
* @param string list_sort : The field we'll use to sort the listing results.
* @param string list_order : Specifies what to order the search results by. Ascending or Descending.
* @param string group_array : Choices used to build the article listing query.
* @param string sort_array : Choices used to build the article listing query.
* @param string order_array : Choices used to build the article listing query.
* @param string sql_article_table : SQL string fragment specifying what tables will be used.
* @param string sql_predicate : ending SQL string fragment that can filter out all unauthorized records.
* @param array error : Holds all Error Flags for the entire module.
* @param array val : Configuration Variables from mod_article_config.
* @param array image_directory : Current Root Image Directory from configuration file.
* @param array image_path : Complete path to Root Image Directory from configuration file.
* @param string filter : Letter that a list is being filtered by.
* @param string current_user : Name of the user belonging to the current settings.
*/
class PHPWS_ArticleManager
{
var $homearticle;
var $home_num;
var $articles;
var $list_group;
var $list_sort;
var $list_order;
var $group_array;
var $sort_array;
var $order_array;
var $sql_article_table;
var $sql_predicate;
var $error;
var $val;
var $image_directory;
var $image_path;
var $filter;
/**
* ArticleManager constructor.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function PHPWS_ArticleManager ()
{
/* Load module default settings */
include(PHPWS_SOURCE_DIR . 'mod/article/conf/config.php');
$result = $GLOBALS['core']->quickFetch('SELECT * FROM mod_article_config', true);
$this->val = $result;
/* Set up sql code to retrieve pages available to this user */
/* This method of setting up the sql allows me to add group-based restrictions later */
$this->sql_article_table = $GLOBALS['core']->tbl_prefix.'mod_article AS A';
$this->sql_predicate = "";
/* Set up the list search criteria */
/* Unapproved listings show up under "My Listings" only */
$this->group_array = array(' WHERE approved'=>'All'
,' WHERE created_username = ' =>'My');
$this->sort_array = array('title'=>'Article Title'
,'publication_date'=>'Publication Date'
,'expiration_date'=>'Expiration Date'
,'created_date'=>'Date Created'
,'updated_date'=>'Last Update');
$this->order_array = array('ASC'=>'Ascending', 'DESC'=>'Descending');
/* Default search criteria defaults to showing "my" articles only */
if ($_SESSION['OBJ_user']->username)
$this->list_group = ' WHERE created_username = ';
else
$this->list_group = ' WHERE approved';
$this->list_sort = 'title';
$this->list_order = "ASC";
}
/**
* Displays the main menu with main functions like "Set as Main", "New Article" and "List Articles"
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function main_menu ()
{
$GLOBALS['CNT_article']['title'] = "Article Manager";
/* If search criteria are specified, set them */
if ($_POST['LIST_group'])
{
$this->list_group = $_POST['LIST_group'];
$this->list_sort = $_POST['LIST_sort'];
$this->list_order = $_POST['LIST_order'];
}
$tags['SEARCHQUERY'] = $_SESSION['translate']->it('Show me [var1] stuff ordered by [var2][var3]'
, $GLOBALS['core']->formSelect('LIST_group', $this->group_array, $this->list_group, NULL, TRUE)
, $GLOBALS['core']->formSelect('LIST_sort', $this->sort_array, $this->list_sort, NULL, TRUE)
, $GLOBALS['core']->formSelect('LIST_order', $this->order_array, $this->list_order, NULL, TRUE))
. $GLOBALS['core']->formSubmit($_SESSION['translate']->it('List Articles'), 'ARTICLE_vars[disp:main_menu]');
if ($this->can("create"))
$tags['BTN_CREATE'] = $GLOBALS['core']->formSubmit($_SESSION['translate']->it('Create New Article'), 'ARTICLE_vars[edit:create]');
if ($_SESSION['OBJ_user']->allow_access('article', 'global_article_prefs'))
$tags['BTN_CONFIG_EDIT'] = $GLOBALS['core']->formSubmit($_SESSION['translate']->it('Edit Configuration'), 'ARTICLE_vars[config:edit]');
if ($_SESSION['OBJ_user']->allow_access('article', "images_in_library"))
$tags['BTN_IMG_LIB'] = $GLOBALS['core']->formSubmit($_SESSION['translate']->it('Image Library'), 'ARTICLE_vars[config:image_library]');
$content[0] = $GLOBALS['core']->processTemplate($tags,'article','menu.tpl');
$content[0] .= $GLOBALS['core']->formHidden('module', 'article');
$title = $_SESSION['translate']->it('Main Menu');
$content = $GLOBALS['core']->makeForm('ARTICLE_main_menu', 'index.php', $content, 'post', 0, 0);
$_SESSION['OBJ_layout']->popbox($title, $content, NULL, 'CNT_article');
}
/**
* Lists the articles stored in the database in user-selectable formats
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function list_articles ()
{
/* Set up display variables */
$now = date('Y-m-d H:i:s');
if ($this->list_sort == 'title')
{
$temp_date_title = 'Date Published';
$temp_date = 'publication_date';
}
else
{
$temp_date_title = $this->sort_array[$this->list_sort];
$temp_date = $this->list_sort;
}
/* Set up authorization flags for faster operation */
$Fedit = $_SESSION['translate']->it('Edit');
if($_SESSION['OBJ_user']->allow_access('article', 'set_mainarticle'))
$Fset_main = $_SESSION['translate']->it('Set as Main');
if($_SESSION['OBJ_user']->allow_access('article', 'change_dates'))
{
$Fexpire = $_SESSION['translate']->it('Expire');
$Fpublish = $_SESSION['translate']->it('Publish');
}
if($_SESSION['OBJ_user']->allow_access('article', 'delete_articles'))
$Fdelete = $_SESSION['translate']->it('Delete');
/* If article row datum hasn't been retrieved/viewed yet... */
if(!isset($this->pager) || !isset($_REQUEST['PAGER_limit']))
{
$this->pager = new PHPWS_Pager;
$this->pager->setLinkBack('./index.php?module=article&disp=main_menu');
$this->pager->makeArray(TRUE);
$this->pager->limit = $this->val['listings_per_page'];
if ($this->list_group==' WHERE created_username = ')
$where = $this->list_group .= '"'.$_SESSION['OBJ_user']->username.'"';
else
$where = $this->list_group;
$result = $GLOBALS['core']->getCol('SELECT id FROM ' . $this->sql_article_table
. $where . $this->sql_predicate . ' ORDER BY '
. $this->list_sort . ' ' . $this->list_order);
$this->pager->setData($result);
$result = NULL;
}
$this->pager->pageData();
if (!$data = implode(',', $this->pager->getData()))
{
$_SESSION['OBJ_layout']->popbox($_SESSION['translate']->it('No Articles Found!')
, $_SESSION['translate']->it('No matching articles were found in the database!')
, NULL, 'CNT_article');
return;
}
/* Retrieve all article listings for this page */
$sql = 'SELECT id,title,created_username,approved,mainarticle,editlock,edituser,'
. $temp_date . ' FROM ' . $this->sql_article_table
. ' WHERE id IN (' . $data . ') ORDER BY '
. $this->list_sort . ' ' . $this->list_order;
if(!($result = $GLOBALS['core']->getall($sql)) || $count=sizeof($result) < 1)
return;
/* Now create the Row HTML */
foreach($result as $value)
{
$row = array();
$GLOBALS['core']->toggle($bg, " class=\"bg_medium\"");
$row['BG'] = $bg;
/* If this page is viewable, allow the user to toggle the mainpage switch. */
if ($value['approved'] && $value['publication_date'] <= $now
&& ($value['expiration_date']==NULL || $value['expiration_date'] > $now))
$is_viewable = TRUE;
else
$is_viewable = FALSE;
/* Set up title */
$tba = (!$value['approved'])
?" ((TBA))"
:"";
$row['ARTICLE_TITLE'] = '<a href=index.php?module=article&view='.$value['id']
.' id='.$value['id'].'>'. stripslashes($value['title']) . $tba.'</a>';
/* Set var to show whether this is the homepage article or not */
if($value['mainarticle'])
$row['HOME_FLAG'] = '<font color="lime"><b><i>'
. $_SESSION['translate']->it('CURRENT') . '</i></b></font>';
else
if ($is_viewable && isset($Fset_main))
$row['HOME_FLAG'] = '<input type="submit" name="ARTICLE_vars[edit:set_main]" value="'.$Fset_main.'" />';
/* Set up date */
$row['DATE'] = substr($value[$temp_date],0,10);
/* Set var to expire/publish the article */
if (isset($Fexpire))
$row['PUB_EXP'] = ($is_viewable)
?'<input type="submit" name="ARTICLE_vars[edit:expire]" value="'.$Fexpire.'" />'
:'<input type="submit" name="ARTICLE_vars[edit:publish]" value="'.$Fpublish.'" />';
/* Set up Edit button */
if ($this->can("edit",$value['created_username']))
/* If someone else is not editing this page... */
if (!PHPWS_Article::isLocked(&$value['editlock'], &$value['edituser']))
$row['EDIT'] = '<input type="submit" name="ARTICLE_vars[edit:'
.$value['id'].']" value="'.$Fedit.'" />';
else
$row['EDIT'] = '['.$_SESSION['translate']->it('Locked').']';
/* Set up Delete button */
if (isset($Fdelete))
$row['DELETE'] = '<input type="submit" name="ARTICLE_vars[edit:delete]" value="'.$Fdelete.'" />';
$content[0] = $GLOBALS['core']->processTemplate($row,'article','listing_row.tpl')
. $GLOBALS['core']->formHidden('module', 'article')
. $GLOBALS['core']->formHidden('ARTICLE_id', $value['id']);
$tags['LIST_ROWS'] .= $GLOBALS['core']->makeForm('ARTICLE_main_menu', 'index.php#'.$value['id'], $content, 'post', 0, 0);
}
/* Create Table HTML */
$tags['TITLE'] = $_SESSION['translate']->it('Title');
$tags['HOME_FLAG'] = $_SESSION['translate']->it('Homepage') . '?'
. $_SESSION['OBJ_help']->show_link('article', 'list_mainarticle');
$tags['DATE'] = $_SESSION['translate']->it($temp_date_title);
$tags['ACTION'] = $_SESSION['translate']->it('Action')
. $_SESSION['OBJ_help']->show_link('article', 'list_action');
$tags['PAGE_BACKWARD_LINK'] = $this->pager->getBackLink();
$tags['PAGE_FORWARD_LINK'] = $this->pager->getForwardLink();
$tags['SECTION_LINKS'] = $this->pager->getSectionLinks();
$tags['SECTION_INFO'] = $this->pager->getSectionInfo() . $_SESSION['translate']->it('Articles');
$tags['LIMIT_LINKS'] = $this->pager->getLimitLinks();
$tags['LIMIT_LINKS_LABEL'] = $_SESSION['translate']->it('Rows to show per page: ');
$content = $GLOBALS['core']->processTemplate($tags,'article','listing.tpl');
$_SESSION['OBJ_layout']->popbox($_SESSION['translate']->it('Current Articles')
, $content, NULL, 'CNT_article');
}
/**
* Lists the articles stored in the database in a "News Page"
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function list_news ()
{
/* Set up display variables */
$now = date('Y-m-d H:i:s');
/* If article row datum hasn't been retrieved/viewed yet... */
if(!isset($this->pager) || !isset($_REQUEST['PAGER_limit']) || isset($_REQUEST['newsFilter']))
{
$this->pager = new PHPWS_Pager;
$this->pager->setLinkBack('./index.php?module=article&disp=news');
$this->pager->makeArray(TRUE);
$this->pager->limit = $this->val['listings_per_page'];
if (isset($_REQUEST['newsFilter']))
$this->filter = $_REQUEST['newsFilter'];
if ($this->filter!='')
$filter = ' AND title LIKE "'.$this->filter.'%" ORDER BY title ASC';
else
$filter = ' ORDER BY updated_date DESC';
$result = $GLOBALS['core']->getCol('SELECT id FROM ' . $this->sql_article_table
. ' WHERE ' . $this->get_published_sql() . $this->sql_predicate . $filter);
$this->pager->setData($result);
$result = NULL;
}
$this->pager->pageData();
if ($data = implode(',', $this->pager->getData()))
{
/* Retrieve all article listings for this page */
$sql = 'SELECT * FROM ' . $this->sql_article_table
. ' WHERE id IN (' . $data . ') ORDER BY updated_date DESC';
if(!$result = $GLOBALS['core']->query($sql))
return;
while($summary=$result->fetchrow(DB_FETCHMODE_ASSOC))
{
$temp = new PHPWS_Article($summary['id'], $summary);
$temp->view(false);
}
unset($temp);
unset($result);
}
else
$GLOBALS['CNT_article_summaries']['content'] = '<br /><br />'
. $_SESSION['translate']->it('No matching articles were found in the database!')
. '<br /><br />';
/* Create NewsPage HTML */
$alphabet = PHPWS_User::alphabet();
$tags['ALPHABET'] = $GLOBALS['core']->moduleLink($_SESSION['translate']->it('ALL'), 'article', array('disp'=>'news', 'newsFilter'=>'') ) . " \n";
foreach ($alphabet as $alphachar)
if ($alphachar!=$this->filter)
$tags['ALPHABET'] .= $GLOBALS['core']->moduleLink($alphachar, 'article', array('disp'=>'news', 'newsFilter'=>$alphachar) ) . " \n";
else
$tags['ALPHABET'] .= $alphachar . " \n";
$tags['PAGE_BACKWARD_LINK'] = $this->pager->getBackLink();
$tags['PAGE_FORWARD_LINK'] = $this->pager->getForwardLink();
$tags['SECTION_LINKS'] = $this->pager->getSectionLinks();
$tags['SECTION_INFO'] = $this->pager->getSectionInfo() . $_SESSION['translate']->it('Articles');
$tags['LIMIT_LINKS'] = $this->pager->getLimitLinks();
$tags['LIMIT_LINKS_LABEL'] = $_SESSION['translate']->it('Rows to show per page: ');
$title = $_SESSION['translate']->it('All Articles');
if ($this->filter!='')
$title .= $_SESSION['translate']->it(' Starting With `[var1]`', $this->filter);
$GLOBALS['Layout_title'] = $title . ' - ' . $_SESSION['OBJ_layout']->page_title;
$GLOBALS['CNT_article_summaries']['title'] = '<center><b>' . $title . '</b></center>';
$content = $GLOBALS['core']->processTemplate($tags,'article','pager.tpl');
$GLOBALS['CNT_article_summaries']['content'] = $content
. $GLOBALS['CNT_article_summaries']['content'] . $content;
}
/**
* Sets the main article in the database and in this PHPWS_ArticleManager class.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function set_main_article ()
{
if($_POST['ARTICLE_id'])
{
$GLOBALS['core']->query('UPDATE mod_article SET mainarticle=0 WHERE mainarticle=1', true);
$GLOBALS['core']->query('UPDATE mod_article SET mainarticle=1 WHERE id='.$_POST['ARTICLE_id'], true);
}
}
/**
* Simply displays the homepage article.
*
* @author Adam Morton <ad...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function show_mainarticle ()
{
if ($row=$GLOBALS['core']->quickFetch('SELECT id from mod_article WHERE mainarticle = 1',TRUE))
{
$temp = new PHPWS_Article($row['id']);
$temp->view();
unset($temp);
}
}
/**
* Bridge function to the search module to allow articles to be searched
*
* This function is optimised to only conduct one query.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param string $where The "where" clause for the SQL statement.
* @return array List of articles containing the search term.
*/
function search($where)
{
$returnArray = array();
$sql = 'SELECT A.id,A.title,A.summary FROM ' . $this->sql_article_table
. ','.$GLOBALS['core']->tbl_prefix.'mod_article_sections AS S '
. $where . ' AND A.id=S.article_id AND '. $this->get_published_sql()
. $this->sql_predicate . ' ORDER BY updated_date DESC';
$articleResult = $GLOBALS['core']->query($sql);
while ($articleResult && $resultRow = $articleResult->fetchrow(DB_FETCHMODE_ASSOC))
{
/* Only save/show the first occurence per article */
if (!isset($returnArray[$resultRow['id']]))
$returnArray[$resultRow['id']] = '<b>' . $resultRow['title'] . '</b><br />' . $resultRow['summary'] . '...';
}
return $returnArray;
}// END FUNC searchArticles()
/**
* Displays summary listings of last n articles on the homepage.
*
* Also displays the "Past n Articles" Block & the "Popular Articles" Block.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function view_summaries ()
{
$TotalCount = $this->val['summaries_on_homepage'] + $this->val['prev_n_articles'];
/* Determine how many summaries we're going to show */
if ($TotalCount<1)
return;
$GLOBALS['CNT_article_summaries']['title'] .= '<center><b>'
. $_SESSION['translate']->it('Also on this Site') . '...</b></center>';
/* Load records to display */
$sql = 'SELECT * FROM ' . $this->sql_article_table
. ' WHERE ' . $this->get_published_sql() . $this->sql_predicate
. ' AND announce ORDER BY updated_date DESC LIMIT ' . $TotalCount;
$result = $GLOBALS['core']->query($sql);
/* If there are summaries to display, display 'em */
if ($this->val['summaries_on_homepage']>0)
for($i=0; $i < $this->val['summaries_on_homepage'] && $summary=$result->fetchrow(DB_FETCHMODE_ASSOC); $i++)
{
$temp = new PHPWS_Article($summary['id'], $summary);
$temp->view(false);
}
/* If there are x articles before these, display the "Prev Articles" Block */
if ($this->val['prev_n_articles']>0)
{
for($i=0; $i < $this->val['prev_n_articles'] && $summary=$result->fetchrow(DB_FETCHMODE_ASSOC); $i++)
{
if ($i>0)
$content .= '<br />';
$content .= date('F d', strtotime($summary['updated_date']))
. ' <br /><a href="index.php?module=article&view='
. $summary['id'] .'">' . $summary['title'] . "</a><br />\n";
}
if (isset($content))
{
$GLOBALS['CNT_article_past']['title'] =
$_SESSION['translate']->it('Previous').' '.$this->val['prev_n_articles']
. ' ' . $_SESSION['translate']->it('Articles');
$GLOBALS['CNT_article_past']['content'] = &$content;
}
}
/* Reset the variable used to hold the class */
unset($temp);
}
/**
* Displays a block listing of the n most popular last n articles.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function view_popular ()
{
if ($this->val['popular_articles']<1)
return;
/* Load records to display */
$sql = 'SELECT * FROM ' . $this->sql_article_table
. ' WHERE ' . $this->get_published_sql() . $this->sql_predicate
. ' ORDER BY hits DESC LIMIT ' . $this->val['popular_articles'];
$result = $GLOBALS['core']->query($sql);
/* If there are summaries to display, display 'em */
$i = 0;
while($summary=$result->fetchrow(DB_FETCHMODE_ASSOC))
{
if ($i++ > 0)
$content .= '<br />';
$content .= date('F d', strtotime($summary['updated_date']))
. ' <br /><a href="index.php?module=article&view='
. $summary['id'] .'">' . $summary['title'] . "</a><br />\n";
}
if (isset($content))
{
$GLOBALS['CNT_article_popular']['title'] = $_SESSION['translate']->it('Popular Articles');
$GLOBALS['CNT_article_popular']['content'] = &$content;
}
}
/* Edits the module's default settings.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function edit_configuration ()
{
include(PHPWS_SOURCE_DIR . 'mod/article/inc/editconfig.php');
}
/**
* Saves the module's default settings to the database.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function save_configuration ()
{
include(PHPWS_SOURCE_DIR . 'mod/article/inc/saveconfig.php');
}
/**
* Resets the module's default settings.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function reset_configuration ()
{
$GLOBALS['core']->sqlDelete("mod_article_config");
$GLOBALS['core']->sqlInsert(array(),"mod_article_config", 0, 0, 0, 0);
}
/**
* Determines whether user is authorized to edit, create, delete articles.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param action to authorize
* @param username to compare against
* @return TRUE or FALSE
* @access public
*/
function can($action = NULL, $username = NULL)
{
if ($action == "edit")
return ($_SESSION['OBJ_user']->allow_access('article', "edit_articles")
|| ((($this->val['users_can_submit'] && $_SESSION['OBJ_user']->isUser())
|| $_SESSION['OBJ_user']->allow_access('article', "edit_own_article"))
&& $_SESSION['OBJ_user']->username==$username));
elseif ($action == "delete")
return ($_SESSION['OBJ_user']->allow_access('article', "delete_articles")
|| ($_SESSION['OBJ_user']->allow_access('article', "delete_own_article")
&& $_SESSION['OBJ_user']->username==$username));
elseif ($action == "create")
return ($_SESSION['OBJ_user']->allow_access('article', "create_articles")
|| ($this->val['users_can_submit'] && $_SESSION['OBJ_user']->isUser()));
else
return false;
}
/**
* Allows adds or deletes of files from the Image Library
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function manage_library ()
{
include(PHPWS_SOURCE_DIR . 'mod/article/conf/config.php');
$title = $_SESSION['translate']->it('Image Library Management');
/* Display Errors */
$content .= $this->get_error('LIB_loaded_image');
/* File upload section */
$myelements[0] = $GLOBALS['core']->formHidden('MAX_FILE_SIZE', '26000')
. $GLOBALS['core']->formFile('LIB_loaded_image', 33, 255, $_SESSION['translate']->it('File to Upload').': ')
. "\n " . $GLOBALS['core']->formSubmit($_SESSION['translate']->it("Save"), 'ARTICLE_vars[config:save_library_item]')
. $_SESSION['OBJ_help']->show_link('article', "section_lib_image")
. $GLOBALS['core']->formHidden('module', 'article');
$content .= "<br />\n"
. $GLOBALS['core']->makeForm('LIB_add', 'index.php', $myelements, 'post', 0, TRUE)
. "\n<br />\n";
/* Display table header */
$content .=
"<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">
<tr>
<td width=\"100%\" class=\"bg_dark\">Image Name</td>
<td align=\"center\" class=\"bg_dark\">Action</td>
</tr>\n";
/* Create array of library files & sort 'em */
$dir_handle = opendir($this->image_path . 'library/');
while($value = readdir($dir_handle))
{
if ($value != '.' && $value != '..' && $value != 'CVS')
$lib_array[$value] = $value;
}
closedir($dir_handle);
/* Sort the list & output to a table */
if ($lib_array)
{
asort($lib_array);
foreach($lib_array as $value)
{
$content .= "<tr>\n\t<td width=\"100%\"$bg>";
$myelements[0] = $GLOBALS['core']->formHidden('module', 'article')
. $GLOBALS['core']->formHidden("LIB_image", $value)
. stripslashes($value)
. "</td>\n\t<td$bg>"
. $GLOBALS['core']->formSubmit($_SESSION['translate']->it('Delete')
, "ARTICLE_vars[config:delete_library_item]") . "\n";
$content .= $GLOBALS['core']->makeForm('LIB_management', 'index.php', $myelements, 'post', 0, 0)
. "\n\t</td>\n</tr>";
$GLOBALS['core']->toggle($bg, " class=\"bg_medium\"");
}
}
else
$content .= "<tr>\n\t<td>"
. $_SESSION['translate']->it('No Images in Library')
."</td>\n</tr>";
$content .= "\n</table>\n";
$_SESSION['OBJ_layout']->popbox($title, $content, NULL, 'CNT_article');
}
/**
* Deletes an imagefile from the library.
*
* @author Adam Morton <ad...@NO...>
* @module Article Manager
* @param string imagename: Name of file to delete.
* @return none
*/
function del_lib_item ($imagename = NULL)
{
include(PHPWS_SOURCE_DIR . 'mod/article/conf/config.php');
if ($imagename)
if (!unlink($this->image_path . 'library/' . $imagename))
$this->error['LIB_loaded_image'] .= $_SESSION['translate']->it('[var1] could not be deleted.', $imagename);
}
/**
* Saves an imagefile to the library.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function save_lib_item ()
{
$image = EZform::saveImage('LIB_loaded_image'
, $this->image_path . 'library/'
, $this->val['max_image_width']
, $this->val['max_image_height']
, $this->val['max_image_size'] * 1024);
if (!is_array($image))
$GLOBALS['CNT_article']['content'] .= $image;
}
/**
* Prints an error message selected by passing the function an error $type
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param array type : Type of error that occured. Prints an appropriate error message
* based on the type.
* @return string : Error output text
*/
function get_error ($type = NULL)
{
if (isset($this->error[$type]))
{
$GLOBALS['CNT_article']['content'] .= "\n<span class=\"errortext\">ERROR!<br />\n";
foreach($this->error[$type] as $msg)
$GLOBALS['CNT_article']['content'] .= $msg . "<br />\n";
$GLOBALS['CNT_article']['content'] .= "</span>\n";
unset($this->error[$type]);
}
}
/**
* Approves an article for publication
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param array info_array : Array containing the Article Id
* @return none
*/
function approve ($id)
{
$query_data['approved'] = true;
$GLOBALS['core']->sqlUpdate($query_data, 'mod_article', 'id', $id);
PHPWS_Fatcat::activate($id, 'article');
}
/**
* Deletes an unpublishable article
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param array info_array : Array containing the Article Id
* @return none
*/
function refuse ($id)
{
$GLOBALS['core']->sqlDelete('mod_article_sections', 'article_id', $id);
$GLOBALS['core']->sqlDelete('mod_article', 'id', $id);
PHPWS_Fatcat::purge($id, 'article');
}
/**
* Creates sql text to retrieve published pages.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return string : sql text
*/
function get_published_sql ()
{
$now = date("Y-m-d H:i:s");
return "approved AND publication_date<='$now' AND"
." (expiration_date IS NULL OR expiration_date>'$now') AND mainarticle=0";
}
}
?>
--- NEW FILE: Section.php ---
<?php
/**
* This is the PHPWS_Article_Section class. It holds data for a single section in a article.
* It also contains functions for manipulation of the data and updating or
* deleting this section.
*
* @version \$Id\$
*
* @author Eloi George <el...@NO...>
* @basecode Adam Morton's PageMaster Module
* @package phpWebSite
* @module Article Manager
* @param int id : Database id of this article
* @param string title : Title of this article
* @param string text : Body text of this article
* @param array image : Array of image information
* name = Image Name.
* directory = Location of Image File.
* height = Height of Image (in pixels). NULL for Library Images.
* width = Width of Image (in pixels). NULL for Library Images.
* alt = Alternate text to display for the Image.
* link = If Image is a link, this contains the target URL.
* caption = An optional line of text to display below the image
* @param string template : Template to use for displaying this section
* @param int article_id : Database Id of this section's parent article
* @param int new_page : Whether this section starts on a new page or not
* @param int edited : FLAG Whether this section has been changed.
* @param string old_image : Name of the image that's being replaced
* @param string temp_image : Name of the new image sitting in a temporary position
*/
class PHPWS_Article_Section
{
var $id;
var $title;
var $text;
var $image;
var $template;
var $article_id;
var $new_page;
var $edited;
var $old_image;
var $temp_image;
/**
* Constructor for the PHPWS_Article_Section object.
*
* @author Adam Morton <ad...@NO...>
* @param int SECT_id : Database id of the section's data to be loaded into the class.
* @param int data : To optimize the # of table queries, PHPWS_Article can send the
* data as an array.
* @return none
*/
function PHPWS_Article_Section ($SECT_id = NULL, $data = NULL)
{
if($SECT_id)
{
if ($data==null)
{
$result = $GLOBALS['core']->sqlSelect("mod_article_sections", 'id', $SECT_id);
$data = &$result[0];
}
$this->id = $SECT_id;
$this->title = $data['title'];
$this->text = $data['text'];
$this->image['name'] = $data['image_name'];
$this->image['directory'] = $data['image_directory'];
$this->image['height'] = $data['image_height'];
$this->image['width'] = $data['image_width'];
$this->image['alt'] = $data['image_alt'];
$this->image['link'] = $data['image_link'];
$this->image['caption'] = $data['image_caption'];
$this->template = $data['template'];
$this->new_page = $data['new_page'];
$this->article_id = $data['article_id'];
}
else
{
/* Assign a temporary id to this new section and increment it */
$this->id = $_SESSION['SES_ART_article']->sectionID++;
$this->title = $this->text = '';
$this->image['name'] = $this->image['directory'] = $this->image['height']
= $this->image['width'] = $this->image['alt'] = $this->image['link']
= $this->image['caption'] = '';
$this->template = $_SESSION['SES_ART_master']->val['default_section_template'];
$this->new_page = 0;
}
$this->edited = 0;
}
/**
* Displays this section in the context of a article object.
*
* @author Adam Morton <ad...@NO...>
* @author Eloi George <el...@NO...>
* @param boolean $edit_mode Simple flag to tell section whether or not the article is in edit mode.
* @param string article_id : id of this article
* @param string created_username : username of the user that created this article
* @param date created_date : Date this article was created
* @param string updated_username : username of the lastuser to update this article
* @param date updated_date : Date this article was last updated
* @return Display data for this section.
*/
function view_section ($edit_mode = NULL,&$article_id,&$created_username,&$created_date,&$updated_username,&$updated_date)
{
include(PHPWS_SOURCE_DIR . 'mod/article/conf/config.php');
if($this->template)
{
/* Develop image appearance */
if ($this->image['name'])
{
/* If this is a temporary image, look in the main directory */
if ($this->temp_image)
$temp_image = $_SESSION['SES_ART_master']->image_directory . $this->image['name'];
else
$temp_image = $_SESSION['SES_ART_master']->image_directory . $this->image['directory'] . $this->image['name'];
/* If this is a library picture, calculate image specs on the fly */
/* in case the picture has been altered. */
if ($this->image['directory'] == 'library/')
{
/* Determine image display specs */
$image_size = getimagesize($temp_image);
$this->image['width'] = $image_size[0];
$this->image['height'] = $image_size[1];
}
$image_string = '<img src="' . $temp_image
. '" width="' . $this->image['width'] . '" height="'
. $this->image['height'] . '" alt="' . $this->image['alt']
. '" title="' . $this->image['alt'] . '" />';
if ($this->image['link'])
$image_string = '<a href="http://'. $this->image['link'] . '">'
. $image_string . '</a>';
$template_array['IMAGE'] = $image_string;
$template_array['CAPTION'] = $this->image['caption'];
}
if (!$this->title) $this->title = ' ';
$template_array['TITLE'] = $this->title;
$template_array['TEXT'] = PHPWS_Core::parseOutput($this->text);
$template_array['PRINT_ICON'] = '<a href="index.php?module=article&op=view_printable&ARTICLE_id=' . $article_id .
'&lay_quiet=1" target="_blank"><img src="mod/article/img/print.gif" border="0" width="22" height="20" alt="Printable Version"/></a>';
$template_array['CREATED_DATE'] = $created_date;
$template_array['UPDATED_DATE'] = $updated_date;
// If Username is blank, substitute "Anonymous"
if(!$created_username)
$template_array['CREATED_USER'] = $_SESSION['translate']->it('Anonymous');
else
$template_array['CREATED_USER'] = $created_username;
if(!$updated_username)
$template_array['UPDATED_USER'] = $_SESSION['translate']->it('Anonymous');
else
$template_array['UPDATED_USER'] = $updated_username;
$section_content = $GLOBALS['core']->processTemplate($template_array, 'article', "section/".$this->template . ".tpl");
}
if ($edit_mode)
{
$myform[0] = $GLOBALS["core"]->formHidden("module", "article")
. $GLOBALS["core"]->formHidden("SECT_id", $this->id);
$remove = $_SESSION['translate']->it('Remove');
if($_SESSION['OBJ_user']->js_on)
{
$js_vars['message'] = $_SESSION['translate']->it('Are you sure you want to [var1] [var2]?'
, $_SESSION['translate']->it('delete'), $this->title);
$js_vars['name'] = $remove;
$js_vars['value'] = 'section=remove:'.$this->id;
$js_vars['location'] = 'index.php?module=article§ion=remove&SECT_id='.$this->id;
$myform[0] .= $GLOBALS['core']->js_insert("confirm", 'SECT_options', $this->id, 0, $js_vars);
}
else $myform[0] .= $GLOBALS['core']->formSubmit($remove, 'ARTICLE_vars[section:remove]');
$myform[0] .= $_SESSION['OBJ_help']->show_link('article', 'section_remove');
$myform[0] .= $GLOBALS['core']->formSubmit($_SESSION['translate']->it('Edit'), 'ARTICLE_vars[section:edit]')
.$_SESSION['OBJ_help']->show_link('article', 'section_edit');
if (count($_SESSION['SES_ART_article']->order)>1)
{
$myform[0] .= $GLOBALS['core']->formSubmit($_SESSION['translate']->it('Move Up'), 'ARTICLE_vars[section:move_up]');
$myform[0] .= $GLOBALS['core']->formSubmit($_SESSION['translate']->it('Move Down'), 'ARTICLE_vars[section:move_down]')
.$_SESSION['OBJ_help']->show_link('article', 'section_move');
}
$section_content .= "<div class=\"smalltext\" style=\"clear : both;\" align=\"right\">\n"
. $GLOBALS["core"]->makeForm("SECT_options" . $this->id, 'index.php#'
. $this->id, $myform, "post", 0, 0) . '</div><hr />';
}
return $section_content;
}
/**
* Displays an editing interface for this section.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*
*/
function edit_section ()
{
include(PHPWS_SOURCE_DIR . 'mod/article/conf/config.php');
if (is_numeric($this->id))
$section_title = '<div name="'.$this->id.'" class="bg_dark">'
. $_SESSION['translate']->it('Edit Section') . '</div>';
else
$section_title = '<div name="new section" class="bg_dark">'
. $_SESSION['translate']->it('New Section') . '</div>';
$myelements[0] = $GLOBALS['core']->formCheckBox('SECT_new_page',1,$this->new_page,NULL, $_SESSION['translate']->it("Start on new page?"))
. $_SESSION['OBJ_help']->show_link('article', 'section_new_page') . "<br />";
$myelements[0] .= $_SESSION['SES_ART_master']->get_error('SECT_title')
. $_SESSION['translate']->it('Section Title').':<br />'
. $GLOBALS['core']->js_insert('wysiwyg', 'SECT_edit', 'SECT_title');
$myelements[0] .= $GLOBALS['core']->formTextField('SECT_title', htmlspecialchars($this->title), 55, 79)
. $_SESSION['OBJ_help']->show_link('article', 'section_title') . '<br />';
$myelements[0] .= $_SESSION['translate']->it('Text').':<br />'
. $GLOBALS['core']->js_insert('wysiwyg', 'SECT_edit', 'SECT_text');
$myelements[0] .= $GLOBALS['core']->formTextArea("SECT_text", stripslashes($this->text), 20, 79)
. $_SESSION['OBJ_help']->show_link('article', 'section_text') . '<br />';
/* If there is a current image, show it */
if($this->image['name'])
/* If this is a temporary image, look in the main directory */
if ($this->temp_image)
$myelements[0] .= "<img src=\"" .$_SESSION['SES_ART_master']->image_directory . $this->image['name'] . "\" /><br />";
else
$myelements[0] .= "<img src=\"" .$_SESSION['SES_ART_master']->image_directory . $this->image['directory'] . $this->image['name'] . "\" /><br />";
/* If user is allowed to play around with the images... */
if ($_SESSION['OBJ_user']->allow_access('article', 'images_in_articles')
|| ($_SESSION['SES_ART_master']->val['user_images_in_article'] && $_SESSION['OBJ_user']->isUser()))
{
/* allow them to remove it */
if($this->image['name'])
$myelements[0] .= $_SESSION['translate']->it('Remove Image').'? '
. $GLOBALS['core']->formCheckBox('removeImage', 1, NULL, NULL) . "<br />";
/* If allowed, upload your image here */
if ($_SESSION['OBJ_user']->allow_access('article', 'upload_images')
|| ($_SESSION['SES_ART_master']->val['user_upload_images'] && $_SESSION['OBJ_user']->isUser()))
{
$myelements[0] .= $GLOBALS['core']->formHidden('MAX_FILE_SIZE', '26000');
$myelements[0] .= $_SESSION['SES_ART_master']->get_error('SECT_loaded_image')
. $_SESSION['translate']->it("Upload a new image").': '
. $GLOBALS['core']->formFile('SECT_loaded_image', 33, 255)
. $_SESSION['OBJ_help']->show_link('article', 'section_image') . '<br />';
}
/* Or you can select one from the image library */
$dir_handle = opendir($_SESSION['SES_ART_master']->image_path . 'library/');
while($value = readdir($dir_handle))
{
if ($value != "." && $value != ".." && $value != "CVS")
$lib_array[$value] = $value;
if ($value == $this->image['name']) $lib_selected = $value;
}
closedir($dir_handle);
/* Sort the list & put the default "None" at the top */
if ($lib_array)
{
asort($lib_array);
$lib_array = array('None'=>'None') + $lib_array;
}
else $lib_array = array('None'=>'None');
$myelements[0] .= $_SESSION['translate']->it('Or select one from the library').': '
. $GLOBALS['core']->formSelect('SECT_lib_image', $lib_array, $this->image['name'], NULL, NULL, NULL)
. $_SESSION['OBJ_help']->show_link('article', "section_lib_image") . "<br /><br />";
/* Enter alt text, link, & image_caption */
$myelements[0] .= $_SESSION['SES_ART_master']->get_error('SECT_alt')
. $_SESSION['translate']->it('Short Image Description').': '
. $GLOBALS['core']->formTextField('SECT_alt', htmlspecialchars($this->image['alt']), 79, 255)
. $_SESSION['OBJ_help']->show_link('article', 'section_image_desc') . '<br />';
$myelements[0] .= $_SESSION['translate']->it('This Image Links To') . '...: '
. $GLOBALS['core']->formTextField('SECT_link', htmlspecialchars($this->image['link']), 79, 255)
. $_SESSION['OBJ_help']->show_link('article', 'section_image_link') . '<br />';
$myelements[0] .= $_SESSION['translate']->it('Link caption').': '
. $GLOBALS['core']->formTextField('SECT_image_caption', htmlspecialchars($this->image['caption']), 79, 255)
. $_SESSION['OBJ_help']->show_link('article', 'section_image_caption') . '<br />';
}
/* Template Selection */
if (($_SESSION['OBJ_user']->allow_access('article', 'choose_section_template')
|| ($_SESSION['SES_ART_master']->val['users_select_section_tpl']
&& $_SESSION['OBJ_user']->isUser())
|| (!$_SESSION['OBJ_user']->allow_access('article', 'insert_external_pages')
&& substr($this->template, 0, 11)=='Page Insert'))
&& $sect_tpl_array = $GLOBALS['core']->listTemplates('article',false,'section'))
{
/* If user cannot embed external pages, strip the templates out */
if (!$_SESSION['OBJ_user']->allow_access('article', 'insert_external_pages'))
{
$stop = sizeof($sect_tpl_array);
for ($count = 1; ($count < $stop); $count++)
if (substr($sect_tpl_array[$count], 0, 11)=='Page Insert')
unset($sect_tpl_array[$count]);
}
/* Strip the extensions off for readability */
$sect_tpl_array = str_replace('.tpl', NULL, $sect_tpl_array);
/* Sort the list */
asort($sect_tpl_array);
$myelements[0] .= $_SESSION['translate']->it('Section Template').': '
. $GLOBALS['core']->formSelect("SECT_template", $sect_tpl_array, $this->template, true, NULL, NULL)
. $_SESSION['OBJ_help']->show_link('article', 'section_template')
. "<br /><br />";
}
$myelements[0] .= $GLOBALS["core"]->formHidden("module", "article")
. $GLOBALS['core']->formSubmit($_SESSION['translate']->it('Save Section'), 'ARTICLE_vars[section:save]')
. $_SESSION['OBJ_help']->show_link('article', 'section_save');
return $section_title
. $GLOBALS["core"]->makeForm('SECT_edit', 'index.php#'.$this->id, $myelements, 'post', 0, 1)
. '<br />';
}
/**
* Applies changes to this section in memory.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function update ()
{
$temp_name = NULL;
if(!$this->title && !$this->text && !isset($_POST['SECT_title']) && !isset($_POST['SECT_text']))
{
$_SESSION['SES_ART_master']->error['SECT_title'][]
= $_SESSION['translate']->it("You tried to save an empty section");
return;
}
/* Image Removal */
if(isset($_POST['removeImage']) && $this->image['name'] && $this->image['directory']!="library/")
{
/* If this is the original image, place its name into "old_image" */
if (!$this->old_image)
$this->old_image = $this->image['name'];
/* otherwise, if this is a new(uncommitted) image, delete it */
else
{
@unlink($_SESSION['SES_ART_master']->image_path.$this->image['name']);
$this->temp_image = NULL;
}
/* Blank out the "imagename" var */
$this->image['name'] = NULL;
}
/* If there was posted data, assign it to the proper variables */
if (isset($_POST['SECT_title']))
$this->title = PHPWS_Core::parseInput($_POST['SECT_title']);
if (isset($_POST['SECT_text']))
$this->text = PHPWS_Core::parseInput($_POST['SECT_text']);
if (isset($_POST['SECT_alt']))
$this->image['alt'] = $_POST['SECT_alt'];
if (isset($_POST['SECT_link']))
$this->image['link'] = $_POST['SECT_link'];
if (isset($_POST['SECT_image_caption']))
$this->image['caption'] = $_POST['SECT_image_caption'];
if (isset($_POST['SECT_template']))
$this->template = $_POST['SECT_template'];
if (isset($_POST['SECT_new_page']))
$this->new_page = 1;
else
$this->new_page = 0;
/* If a file was uploaded and is valid... */
if ($_FILES['SECT_loaded_image']['size'])
{
/* Give it a unique name */
$ext = strrchr($_FILES['SECT_loaded_image']['name'], ".");
$_FILES['SECT_loaded_image']['name'] = time() . "-" . $_SESSION['OBJ_user']->user_id . $ext;
/* Place it into the temporary directory */
$image = EZform::saveImage("SECT_loaded_image"
, $_SESSION['SES_ART_master']->image_path
, $_SESSION['SES_ART_master']->val['max_image_width']
, $_SESSION['SES_ART_master']->val['max_image_height']
, $_SESSION['SES_ART_master']->val['max_image_size'] * 1024);
if (is_array($image))
{
/* If this is replacing the original image, place the original into "old_image" */
if (!$this->old_image)
$this->old_image = $this->image['name'];
else
/* If this is replacing a new(uncommitted) image, delete the obsolete one */
if ($this->temp_image)
@unlink($_SESSION['SES_ART_master']->image_path.$this->temp_image);
/* Set the new image information */
$this->image = array_merge($this->image, $image);
$this->temp_image = $this->image['name'];
if (!$this->image['directory'] || $this->image['directory']=="library/")
$this->image['directory'] = $this->AssignDir();
}
else
$GLOBALS['CNT_article']['content'] .= $image;
}
/* otherwise, if a file was selected from the library... */
elseif ($_POST['SECT_lib_image'] != "None")
{
/* Assign the file to the temp variables */
$this->image['name'] = $_POST['SECT_lib_image'];
$this->image['directory'] = "library/";
/* If this is replacing a new(uncommitted) image, delete the obsolete one */
if ($this->temp_image)
@unlink($_SESSION['SES_ART_master']->image_path.$this->temp_image);
$this->temp_image = $this->image['height'] = $this->image['width'] = "";
}
/* Make sure that there's an alt tag for the image */
if($this->image['name'])
if (!$this->image['alt'])
$_SESSION['SES_ART_master']->error['SECT_alt'][] = $_SESSION['translate']->it("You must provide a short description for your image");
/* If this is a new section, add it to the article */
if(!in_array($this->id, $_SESSION['SES_ART_article']->order))
$_SESSION['SES_ART_article']->add_section();
else
/* otherwise, just update the article's data */
$_SESSION['SES_ART_article']->update_section($this->id);
}
/**
* Saves this section to the database.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param int parentid : ID of the parent article
* @return none
*/
function save ($parentid=NULL)
{
/* Setup query data for this section. */
$query_data['title'] = $this->title;
$query_data['text'] = $this->text;
$query_data['template'] = $this->template;
$query_data['new_page'] = $this->new_page;
if ($parentid)
$this->article_id = $query_data['article_id'] = $parentid;
/* If there's an old image here... */
if ($this->old_image)
{
/* If WIKI is running, copy the old image to "/old" */
if (isset($_SESSION['OBJ_WIKI']))
PHPWS_File::fileCopy($_SESSION['SES_ART_master']->image_path.$this->image['directory'].$this->old_image
, $_SESSION['SES_ART_master']->image_path."old/"
, $this->old_image, TRUE, FALSE);
/* Get rid of it */
@unlink($_SESSION['SES_ART_master']->image_path.$this->image['directory'].$this->old_image);
}
/* If none exists, Pre-allocate an ID for this section */
if(!is_numeric($this->id))
$newid = $GLOBALS['core']->db->nextId($GLOBALS['core']->tbl_prefix . "mod_article_sections");
else
$newid = $this->id;
/* Assign the new image data */
if ($this->image['name'])
{
$query_data['image_name'] = $this->image['name'];
$query_data['image_directory'] = $this->image['directory'];
$query_data['image_height'] = $this->image['height'];
$query_data['image_width'] = $this->image['width'];
$query_data['image_alt'] = PHPWS_Core::parseInput($this->image['alt']);
$query_data['image_link'] = $this->image['link'];
$query_data['image_caption'] = PHPWS_Core::parseInput($this->image['caption']);
/* Move any images from its holding area to its assigned space */
if ($this->temp_image
&& PHPWS_File::fileCopy($_SESSION['SES_ART_master']->image_path.$this->temp_image
, $_SESSION['SES_ART_master']->image_path.$this->image['directory']
, $newid.strrchr($this->image['name'], "."), TRUE, FALSE))
{
@unlink($_SESSION['SES_ART_master']->image_path.$this->image['name']);
$query_data['image_name'] = $this->image['name'] = $newid.strrchr($this->image['name'], ".");
}
}
else
$query_data['image_height'] = $query_data['image_width'] = $query_data['image_alt'] =
$query_data['image_link'] = $query_data['image_caption'] = "";
/* If this is a new section, save it to get an ID assigned */
if(!is_numeric($this->id))
{
/* Create a new article in the table */
$this->id = $query_data['id'] = $newid;
$GLOBALS['core']->sqlInsert($query_data, 'mod_article_sections', 0, 0, 0, 0);
}
else
/* otherwise, save the data */
$GLOBALS['core']->sqlUpdate($query_data, "mod_article_sections", 'id', $this->id);
/* Erase section flags */
$this->edited = $this->old_image = $this->temp_image = NULL;
}
/**
* Deletes this section from the database.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return none
*/
function delete_section ()
{
$GLOBALS['core']->sqlDelete("mod_article_sections", 'id', $this->id);
if ($this->image['name'] && $this->image['directory'] != "library/")
@unlink($_SESSION['SES_ART_master']->image_path.$this->image['directory'].$this->image['name']);
}
/**
* Assigns a free image directory.
*
* Imagefile Storage Optimization
* Most OSs optimally search & retrieve up to about 500 files per directory.
* This function just makes new directories as the old ones are filled up.
* It assumes that the first directory (/1) is already created.
*
* @author Eloi George <el...@NO...>
* @module Article Manager
* @param none
* @return string : directory name
*/
function AssignDir ()
{
/* Load up all numbered image directories */
$dir_list = array();
$dir_handle = opendir($_SESSION['SES_ART_master']->image_path);
while($value = readdir($dir_handle))
{
if (is_numeric($value) && is_dir($_SESSION['SES_ART_master']->image_path.$value))
$dir_list[] = $value;
}
closedir($dir_handle);
/* Find the highest directory number in a sorted list */
sort($dir_list);
$last_dir = end($dir_list);
/* Count how many files are in the last directory. Allow for "." & ".."*/
$count = -2;
if ($dir_handle = opendir($_SESSION['SES_ART_master']->image_path . $last_dir . "/"))
while($value = readdir($dir_handle))
$count++;
closedir($dir_handle);
/* If this dir is full, then make a new directory */
if ($count > 499)
{
$oldumask = umask(0);
if (!mkdir($_SESSION['SES_ART_master']->image_path . ++$last_dir, 0775))
$_SESSION['SES_ART_master']->error['SECT_loaded_image'][] = $_SESSION['translate']->it("Image Directory \"$last_dir\" could not be created. Image was not saved.");
umask($oldumask);
}
return $last_dir . "/";
}
}
?>
|