[Phpslash-commit] CVS: phpslash-ft/class Author.class,1.11,1.12
Brought to you by:
joestewart,
nhruby
|
From: Lars H. <lh...@us...> - 2001-12-16 21:33:42
|
Update of /cvsroot/phpslash/phpslash-ft/class
In directory usw-pr-cvs1:/tmp/cvs-serv18377/phpslash-ft/class
Modified Files:
Author.class
Log Message:
inserted an array in Author::getAuthors which would limit the view to special authors
Index: Author.class
===================================================================
RCS file: /cvsroot/phpslash/phpslash-ft/class/Author.class,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** Author.class 2001/12/14 03:58:18 1.11
--- Author.class 2001/12/16 21:33:40 1.12
***************
*** 1,357 ****
! <?php
!
! /* $Id$ */
!
! /**
! * Provides an API to the PHPSlash Author Management.
! *
! * This object is how we do anything with authors.
! *
! */
! class Author {
! var $author_templ, $db, $perm, $psl;
!
! /**
! * The Author Constructor
! *
! * sets up the local version of the global _PSL array, the templates
! * and a few other things
! * @access private
! */
!
! function Author () {
!
! global $perm, $_PSL;
!
! $this->db = new slashDB;
! $this->perm = $perm;
! $this->psl = $_PSL;
!
! /* Templates */
! $this->author_templ = new Template($this->psl['templatedir'], "remove");
! $this->author_templ->debug = 0;
! $this->author_templ->set_file(array(
! listauthor => "authorList.tpl",
! newauthor => "authorNew.tpl"
! ));
!
! $this->author_templ->set_var( array(
! ROOTDIR => $this->psl['rootur'],
! IMAGEDIR => $this->psl['imageurl']
! ));
! }
!
! /*
! * METHODS
! */
!
! /**
! * listAuthor - list all Authors
! *
! * displays the complete list of authors
! * Used only by admin
! * @access public
! */
! function listAuthor() {
!
! $q = "SELECT *
! FROM psl_author
! ORDER BY author_name";
! $this->db->query($q);
!
! titlebar("100%","Existing Authors");
!
! $this->author_templ->set_block("listauthor","row","rows");
!
! $count = 0;
!
! while ($this->db->next_record()) {
!
! $author_id = $this->db->Record[author_id];
!
! $this->author_templ->set_var(array(
! ACTION_URL => $this->psl['phpself'],
! AUTHOR_ID => $author_id,
! NAME => $this->db->f("author_name"),
! REALNAME => $this->db->f("author_realname"),
! EMAIL => $this->db->f("email"),
! URL => $this->db->f("url"),
! QUOTE => $this->db->f("quote"),
! PASSWORD => $this->db->f("password"),
! COUNT => $count,
! PERMSEL => $this->perm->perm_sel("permission[$count]", $this->db->f("perms")),
! AMP => $this->psl['amp']
! ));
! $this->author_templ->parse("rows","row",true);
! $count++;
! };
! $this->author_templ->parse(OUT,array("listauthor"));
! $this->author_templ->p(OUT);
! }
!
! /**
! * saveAuthor - save the author info to the DB
! *
! * Saves the author in the $ary array to the DB
! * Obligatory fields: author_name, image, width, height, alt_text
! * Optional fields: author_id (only if this author is already in the DB),
! * onlinkbar (if blank, defaults to 0)
! * Returns true if sucessful (author added or updated), false on error
! * Used only by admin
! *
! * @param array $ary
! *
! * @access public
! */
! function saveAuthor($ary) {
!
! if ($ary[author_name] == "") {
! error("There is no author_name in Author.class::saveAuthor");
! return false;
! }
! if ($ary[password] == "") {
! error("There is no password in Author.class::saveAuthor");
! return false;
! }
! if (!is_array($ary[permission]) or (count($ary[permission]) < 1)) {
! error("You need to select some permissions in Author.class::saveAuthor");
! return false;
! }
!
! /* addslashes for the (') AND str_replace for the (") */
!
! $ary["quote"] = clean($ary["quote"]);
! $ary[author_name] = addslashes(str_replace('\"',""",stripslashes($ary["author_name"])));
! // $ary[author_name] = str_replace(" "," ",stripslashes($ary["author_name"]));
! $ary[author_realname] = addslashes(str_replace('\"',""",stripslashes(
! $ary["author_realname"])));
!
! /* if a record exists, then we update, else we insert a new author! */
!
! $this->db->query("SELECT author_id
! FROM psl_author
! WHERE author_id = '$ary[author_id]'");
!
! $joined_perms = join(',',$ary[permission]);
! if ($this->db->next_record()) {
! $q = "UPDATE psl_author
! SET author_name = '$ary[author_name]',
! author_realname = '$ary[author_realname]',
! url = '$ary[url]',
! email = '$ary[email]',
! quote = '$ary[quote]',
! password = '$ary[password]',
! perms = '$joined_perms'
! WHERE author_id = '$ary[author_id]'";
! } else {
! $ary[author_id] = generateID("psl_author_seq");
!
! $q = "INSERT INTO psl_author
! (author_id,
! author_name,
! author_realname,
! url,
! email,
! quote,
! password,
! seclev,
! perms)
! VALUES ('$ary[author_id]',
! '$ary[author_name]',
! '$ary[author_realname]',
! '$ary[url]',
! '$ary[email]',
! '$ary[quote]',
! '$ary[password]',
! '$ary[seclev]',
! '$joined_perms')";
! }
!
! # echo "<BR><PRE><B>QUERY: $q</B></PRE><BR>\n";
! $this->db->query($q);
! return true;
! }
!
! /**
! * deleteAuthor - deletes the author info to the DB
! *
! * Given the author_id, it deletes that from the author table. The
! * psl_author_lut and psl_author_submission_lut table must be cleaned
! * first by updating all the stories to point to different authors. It
! * will also check and make sure there are NO stories/submissions
! * associated with this author before deleting it. Returns true if
! * author is deleted, false if not.
! *
! * @param integer author_id_to_delete
! * @param string author_id
! *
! * @access public
! */
! function deleteAuthor($author_id_to_delete, $author_id="") {
!
! if ($author_id_to_delete == $author_id) {
! echo "<BR><BR>You can't delete yourself! Create another user, log in as he/she and then delete this account.<BR><BR>";
! return false;
! };
!
! if (!$author_id_to_delete) {
! return false;
! }
!
! $q = "DELETE
! FROM psl_author
! WHERE author_id = '$author_id_to_delete'";
! $this->db->query($q);
! if ($this->db->affected_rows() > 0) {
! return true;
! } else {
! return false;
! };
! }
!
! /**
! * newAuthor - spits out a blank form for input
! *
! * Just prints out the "form" and points the user to the "save" method
! * Used only by admin
! *
! * @access public
! */
! function newAuthor() {
!
! titlebar("100%","Add a new Author");
!
! $this->author_templ->set_var(array(
! ACTION_URL => $this->psl['phpself'],
! PERMSEL => $this->perm->perm_sel("permission", $this->db->f("perms")),
! AUTHOR_ID => "",
! NAME => "",
! REALNAME => $this->author_id,
! EMAIL => "",
! URL => "",
! QUOTE => "",
! PASSWORD => "",
! SECLEV => ""
! ));
!
! $this->author_templ->parse(OUT,array("newauthor"));
! $this->author_templ->p(OUT);
!
! }
!
! /**
! * editAuthor - spits out a form for updating author info
! *
! * Just prints out the "form" with the user's info and
! * points the user to the "save" method
! * Used only by admin
! *
! * @param integer id
! * @access public
! */
! function editAuthor($id) {
!
! titlebar("100%","Update Author ($id)");
!
! $q = "SELECT *
! FROM psl_author
! WHERE author_id = '$id' ";
! $this->db->query($q);
!
!
!
! while ($this->db->next_record()) {
!
! $author_id = $this->db->Record[author_id];
!
! $this->author_templ->set_var(array(
! ACTION_URL => $this->psl['phpself'],
! AUTHOR_ID => $author_id,
! NAME => $this->db->f("author_name"),
! REALNAME => $this->db->f("author_realname"),
! EMAIL => $this->db->f("email"),
! URL => $this->db->f("url"),
! QUOTE => $this->db->f("quote"),
! PASSWORD => $this->db->f("password"),
! SECLEV => $this->db->f("seclev"),
! COUNT => $count,
! PERMSEL => $this->perm->perm_sel("permission", $this->db->f("perms")),
! AMP => $this->psl['amp']
! ));
! };
!
! $this->author_templ->parse(OUT,array("newauthor"));
! $this->author_templ->p(OUT);
!
! }
!
! /**
! * getName - return name assign to id
! *
! * when given a author id, getName returns the name
! *
! * @param integer id
! * @access public
! * return author_name
! */
! function getName($id) {
! if (!$id) {
! return false;
! } else {
! $q = "SELECT author_name
! FROM psl_author
! WHERE author_id = $id";
! $this->db->query($q);
! $this->db->next_record();
! return $this->db->f("author_name");
! };
! }
!
! /**
! * getId - return id assign to name
! *
! * when given a name, getId returns the id
! *
! * @param string name
! * @access public
! * return author_id
! */
!
! function getId($name) {
! if (!$name) {
! return false;
! } else {
! $q = "SELECT author_id
! FROM psl_author
! WHERE author_name = $name";
! $this->db->query($q);
! $this->db->next_record();
! return $this->db->f("author_id");
! };
! }
!
!
! /**
! * getAuthors - returns array with author ids and names
! *
! *
! * @access public
! * return author_array(id, name)
! */
! function getAuthors() {
!
! $q = "SELECT author_id, author_name
! FROM psl_author
! ORDER BY author_name";
! $this->db->query($q);
!
! while ($this->db->next_record()) {
! $author_array[] = array(
! "id" => $this->db->f("author_id"),
! "name" => $this->db->f("author_name")
! );
! }
! return $author_array;
! }
! } /* end of Author.class */
! ?>
--- 1,362 ----
! <?php
!
! /* $Id$ */
!
! /**
! * Provides an API to the PHPSlash Author Management.
! *
! * This object is how we do anything with authors.
! *
! */
! class Author {
! var $author_templ, $db, $perm, $psl;
!
! /**
! * The Author Constructor
! *
! * sets up the local version of the global _PSL array, the templates
! * and a few other things
! * @access private
! */
!
! function Author () {
!
! global $perm, $_PSL;
!
! $this->db = new slashDB;
! $this->perm = $perm;
! $this->psl = $_PSL;
!
! /* Templates */
! $this->author_templ = new Template($this->psl['templatedir'], "remove");
! $this->author_templ->debug = 0;
! $this->author_templ->set_file(array(
! listauthor => "authorList.tpl",
! newauthor => "authorNew.tpl"
! ));
!
! $this->author_templ->set_var( array(
! ROOTDIR => $this->psl['rootur'],
! IMAGEDIR => $this->psl['imageurl']
! ));
! }
!
! /*
! * METHODS
! */
!
! /**
! * listAuthor - list all Authors
! *
! * displays the complete list of authors
! * Used only by admin
! * @access public
! */
! function listAuthor() {
!
! $q = "SELECT *
! FROM psl_author
! ORDER BY author_name";
! $this->db->query($q);
!
! titlebar("100%","Existing Authors");
!
! $this->author_templ->set_block("listauthor","row","rows");
!
! $count = 0;
!
! while ($this->db->next_record()) {
!
! $author_id = $this->db->Record[author_id];
!
! $this->author_templ->set_var(array(
! ACTION_URL => $this->psl['phpself'],
! AUTHOR_ID => $author_id,
! NAME => $this->db->f("author_name"),
! REALNAME => $this->db->f("author_realname"),
! EMAIL => $this->db->f("email"),
! URL => $this->db->f("url"),
! QUOTE => $this->db->f("quote"),
! PASSWORD => $this->db->f("password"),
! COUNT => $count,
! PERMSEL => $this->perm->perm_sel("permission[$count]", $this->db->f("perms")),
! AMP => $this->psl['amp']
! ));
! $this->author_templ->parse("rows","row",true);
! $count++;
! };
! $this->author_templ->parse(OUT,array("listauthor"));
! $this->author_templ->p(OUT);
! }
!
! /**
! * saveAuthor - save the author info to the DB
! *
! * Saves the author in the $ary array to the DB
! * Obligatory fields: author_name, image, width, height, alt_text
! * Optional fields: author_id (only if this author is already in the DB),
! * onlinkbar (if blank, defaults to 0)
! * Returns true if sucessful (author added or updated), false on error
! * Used only by admin
! *
! * @param array $ary
! *
! * @access public
! */
! function saveAuthor($ary) {
!
! if ($ary[author_name] == "") {
! error("There is no author_name in Author.class::saveAuthor");
! return false;
! }
! if ($ary[password] == "") {
! error("There is no password in Author.class::saveAuthor");
! return false;
! }
! if (!is_array($ary[permission]) or (count($ary[permission]) < 1)) {
! error("You need to select some permissions in Author.class::saveAuthor");
! return false;
! }
!
! /* addslashes for the (') AND str_replace for the (") */
!
! $ary["quote"] = clean($ary["quote"]);
! $ary[author_name] = addslashes(str_replace('\"',""",stripslashes($ary["author_name"])));
! // $ary[author_name] = str_replace(" "," ",stripslashes($ary["author_name"]));
! $ary[author_realname] = addslashes(str_replace('\"',""",stripslashes(
! $ary["author_realname"])));
!
! /* if a record exists, then we update, else we insert a new author! */
!
! $this->db->query("SELECT author_id
! FROM psl_author
! WHERE author_id = '$ary[author_id]'");
!
! $joined_perms = join(',',$ary[permission]);
! if ($this->db->next_record()) {
! $q = "UPDATE psl_author
! SET author_name = '$ary[author_name]',
! author_realname = '$ary[author_realname]',
! url = '$ary[url]',
! email = '$ary[email]',
! quote = '$ary[quote]',
! password = '$ary[password]',
! perms = '$joined_perms'
! WHERE author_id = '$ary[author_id]'";
! } else {
! $ary[author_id] = generateID("psl_author_seq");
!
! $q = "INSERT INTO psl_author
! (author_id,
! author_name,
! author_realname,
! url,
! email,
! quote,
! password,
! seclev,
! perms)
! VALUES ('$ary[author_id]',
! '$ary[author_name]',
! '$ary[author_realname]',
! '$ary[url]',
! '$ary[email]',
! '$ary[quote]',
! '$ary[password]',
! '$ary[seclev]',
! '$joined_perms')";
! }
!
! # echo "<BR><PRE><B>QUERY: $q</B></PRE><BR>\n";
! $this->db->query($q);
! return true;
! }
!
! /**
! * deleteAuthor - deletes the author info to the DB
! *
! * Given the author_id, it deletes that from the author table. The
! * psl_author_lut and psl_author_submission_lut table must be cleaned
! * first by updating all the stories to point to different authors. It
! * will also check and make sure there are NO stories/submissions
! * associated with this author before deleting it. Returns true if
! * author is deleted, false if not.
! *
! * @param integer author_id_to_delete
! * @param string author_id
! *
! * @access public
! */
! function deleteAuthor($author_id_to_delete, $author_id="") {
!
! if ($author_id_to_delete == $author_id) {
! echo "<BR><BR>You can't delete yourself! Create another user, log in as he/she and then delete this account.<BR><BR>";
! return false;
! };
!
! if (!$author_id_to_delete) {
! return false;
! }
!
! $q = "DELETE
! FROM psl_author
! WHERE author_id = '$author_id_to_delete'";
! $this->db->query($q);
! if ($this->db->affected_rows() > 0) {
! return true;
! } else {
! return false;
! };
! }
!
! /**
! * newAuthor - spits out a blank form for input
! *
! * Just prints out the "form" and points the user to the "save" method
! * Used only by admin
! *
! * @access public
! */
! function newAuthor() {
!
! titlebar("100%","Add a new Author");
!
! $this->author_templ->set_var(array(
! ACTION_URL => $this->psl['phpself'],
! PERMSEL => $this->perm->perm_sel("permission", $this->db->f("perms")),
! AUTHOR_ID => "",
! NAME => "",
! REALNAME => $this->author_id,
! EMAIL => "",
! URL => "",
! QUOTE => "",
! PASSWORD => "",
! SECLEV => ""
! ));
!
! $this->author_templ->parse(OUT,array("newauthor"));
! $this->author_templ->p(OUT);
!
! }
!
! /**
! * editAuthor - spits out a form for updating author info
! *
! * Just prints out the "form" with the user's info and
! * points the user to the "save" method
! * Used only by admin
! *
! * @param integer id
! * @access public
! */
! function editAuthor($id) {
!
! titlebar("100%","Update Author ($id)");
!
! $q = "SELECT *
! FROM psl_author
! WHERE author_id = '$id' ";
! $this->db->query($q);
!
!
!
! while ($this->db->next_record()) {
!
! $author_id = $this->db->Record[author_id];
!
! $this->author_templ->set_var(array(
! ACTION_URL => $this->psl['phpself'],
! AUTHOR_ID => $author_id,
! NAME => $this->db->f("author_name"),
! REALNAME => $this->db->f("author_realname"),
! EMAIL => $this->db->f("email"),
! URL => $this->db->f("url"),
! QUOTE => $this->db->f("quote"),
! PASSWORD => $this->db->f("password"),
! SECLEV => $this->db->f("seclev"),
! COUNT => $count,
! PERMSEL => $this->perm->perm_sel("permission", $this->db->f("perms")),
! AMP => $this->psl['amp']
! ));
! };
!
! $this->author_templ->parse(OUT,array("newauthor"));
! $this->author_templ->p(OUT);
!
! }
!
! /**
! * getName - return name assign to id
! *
! * when given a author id, getName returns the name
! *
! * @param integer id
! * @access public
! * return author_name
! */
! function getName($id) {
! if (!$id) {
! return false;
! } else {
! $q = "SELECT author_name
! FROM psl_author
! WHERE author_id = $id";
! $this->db->query($q);
! $this->db->next_record();
! return $this->db->f("author_name");
! };
! }
!
! /**
! * getId - return id assign to name
! *
! * when given a name, getId returns the id
! *
! * @param string name
! * @access public
! * return author_id
! */
!
! function getId($name) {
! if (!$name) {
! return false;
! } else {
! $q = "SELECT author_id
! FROM psl_author
! WHERE author_name = $name";
! $this->db->query($q);
! $this->db->next_record();
! return $this->db->f("author_id");
! };
! }
!
!
! /**
! * getAuthors - returns array with author ids and names
! *
! *
! * @access public
! * @param $ary - permission array for futute use
! * @return author_array(id, name)
! */
! function getAuthors($ary = "") {
!
! $q = "SELECT DISTINCT author_id, author_name
! FROM psl_author ";
! if ( !$ary[mode] == "all") {
! $q .= ", psl_story
! WHERE psl_story.user_id = psl_author.author_id ";
! }
! $q .= " ORDER BY author_name";
! $this->db->query($q);
!
! while ($this->db->next_record()) {
! $author_array[] = array(
! "id" => $this->db->f("author_id"),
! "name" => $this->db->f("author_name")
! );
! }
! return $author_array;
! }
! } /* end of Author.class */
! ?>
|