system/classes/story.class.php
branchHEAD
changeset 7370 e5bbed84d3b1
parent 7365 33a378b62bb0
child 7378 5c0a38462d53
     1.1 --- a/system/classes/story.class.php	Sat Oct 10 16:40:52 2009 +0200
     1.2 +++ b/system/classes/story.class.php	Sun Oct 11 11:00:55 2009 +0200
     1.3 @@ -263,11 +263,6 @@
     1.4                  STORY_AL_NUMERIC,
     1.5                  '_frontpage'
     1.6                ),
     1.7 -            'comment_expire' => array
     1.8 -              (
     1.9 -                STORY_AL_NUMERIC,
    1.10 -                '_comment_expire'
    1.11 -              ),
    1.12             'commentcode' => array
    1.13                (
    1.14                  STORY_AL_NUMERIC,
    1.15 @@ -404,15 +399,17 @@
    1.16  
    1.17          // Overwrite the date with the timestamp.
    1.18          $this->_date = $story['unixdate'];
    1.19 +
    1.20          if (!empty($story['expireunix'])) {
    1.21              $this->_expire = $story['expireunix'];
    1.22          } else {
    1.23 -            $this->_expire = '0';
    1.24 +            $this->_expire = 0;
    1.25          }
    1.26 +
    1.27          if (!empty($story['cmt_expire_unix'])) {
    1.28              $this->_comment_expire = $story['cmt_expire_unix'];
    1.29          } else {
    1.30 -            $this->_comment_expire = '0';
    1.31 +            $this->_comment_expire = 0;
    1.32          }
    1.33  
    1.34          // Store the original SID
    1.35 @@ -471,6 +468,12 @@
    1.36              }
    1.37              $this->_date = time();
    1.38              $this->_expire = time();
    1.39 +            if ($_CONF['article_comment_close_enabled']) {
    1.40 +                $this->_comment_expire = time() +
    1.41 +                    ($_CONF['article_comment_close_days'] * 86400);
    1.42 +            } else {
    1.43 +                $this->_comment_expire = 0;
    1.44 +            }
    1.45              $this->_commentcode = $_CONF['comment_code'];
    1.46              $this->_trackbackcode = $_CONF['trackback_code'];
    1.47              $this->_title = '';
    1.48 @@ -570,7 +573,12 @@
    1.49              $this->_trackbackcode = $_CONF['trackback_code'];
    1.50              $this->_featured = 0;
    1.51              $this->_expire = time();
    1.52 -            $this->_expiredate = 0;
    1.53 +            if ($_CONF['article_comment_close_enabled']) {
    1.54 +                $this->_comment_expire = time() +
    1.55 +                    ($_CONF['article_comment_close_days'] * 86400);
    1.56 +            } else {
    1.57 +                $this->_comment_expire = 0;
    1.58 +            }
    1.59  
    1.60              if (DB_getItem($_TABLES['topics'], 'archive_flag', "tid = '{$this->_tid}'") == 1) {
    1.61                  $this->_frontpage = 0;
    1.62 @@ -697,7 +705,8 @@
    1.63              if ($save === 1) {
    1.64                  $varname = '_' . $fieldname;
    1.65                  $sql .= $fieldname . ', ';
    1.66 -                if (($fieldname == 'date') || ($fieldname == 'expire') || ($fieldname == 'comment_expire')) {
    1.67 +                if (($fieldname == 'date') || ($fieldname == 'expire') ||
    1.68 +                        ($fieldname == 'comment_expire')) {
    1.69                      // let the DB server do this conversion (cf. timezone hack)
    1.70                      $values .= 'FROM_UNIXTIME(' . $this->{$varname} . '), ';
    1.71                  } else {
    1.72 @@ -861,7 +870,12 @@
    1.73  
    1.74          $this->_expire = time();
    1.75          $this->_date = time();
    1.76 -        $this->_expiredate = 0;
    1.77 +        if ($_CONF['article_comment_close_enabled']) {
    1.78 +            $this->_comment_expire = time() +
    1.79 +                ($_CONF['article_comment_close_days'] * 86400);
    1.80 +        } else {
    1.81 +            $this->_comment_expire = 0;
    1.82 +        }
    1.83  
    1.84          // Handle Magic GPC Garbage:
    1.85          while (list($key, $value) = each($array))
    1.86 @@ -1292,7 +1306,7 @@
    1.87      /**
    1.88       * Provide access to story elements. For the editor.
    1.89       *
    1.90 -     * This is a peudo-property, implementing a getter for story
    1.91 +     * This is a pseudo-property, implementing a getter for story
    1.92       * details as if as an associative array. Personally, I'd
    1.93       * rather be able to assign getters and setters to actual
    1.94       * properties to mask controlled access to private member
    1.95 @@ -1383,43 +1397,67 @@
    1.96              break;
    1.97  
    1.98          case 'cmt_close':
    1.99 -            if (isset($this->_comment_expire) && $this->_comment_expire != 0) {
   1.100 -                $return = true;
   1.101 +            $return = ($this->_comment_expire == 0) ? false : true;
   1.102 +
   1.103 +            break;
   1.104 +
   1.105 +        case 'cmt_close_second':
   1.106 +            if ($this->_comment_expire == 0) {
   1.107 +                $return = date('s', time() +
   1.108 +                               ($_CONF['article_comment_close_days'] * 86400));
   1.109              } else {
   1.110 -                $return = false;
   1.111 -                //return default expire time to form
   1.112 -                $this->_comment_expire = $this->_date + ($_CONF['article_comment_close_days']*86400);
   1.113 +                $return = date('s', $this->_comment_expire);
   1.114              }
   1.115 -            
   1.116 -            break;
   1.117 -            
   1.118 -        case 'cmt_close_second':
   1.119 -            $return = date('s', $this->_comment_expire);
   1.120  
   1.121              break;
   1.122  
   1.123          case 'cmt_close_minute':
   1.124 -            $return = date('i', $this->_comment_expire);
   1.125 +            if ($this->_comment_expire == 0) {
   1.126 +                $return = date('i', time() +
   1.127 +                               ($_CONF['article_comment_close_days'] * 86400));
   1.128 +            } else {
   1.129 +                $return = date('i', $this->_comment_expire);
   1.130 +            }
   1.131  
   1.132              break;
   1.133  
   1.134          case 'cmt_close_hour':
   1.135 -            $return = date('H', $this->_comment_expire);
   1.136 +            if ($this->_comment_expire == 0) {
   1.137 +                $return = date('H', time() +
   1.138 +                               ($_CONF['article_comment_close_days'] * 86400));
   1.139 +            } else {
   1.140 +                $return = date('H', $this->_comment_expire);
   1.141 +            }
   1.142  
   1.143              break;
   1.144  
   1.145          case 'cmt_close_day':
   1.146 -            $return = date('d', $this->_comment_expire);
   1.147 +            if ($this->_comment_expire == 0) {
   1.148 +                $return = date('d', time() +
   1.149 +                               ($_CONF['article_comment_close_days'] * 86400));
   1.150 +            } else {
   1.151 +                $return = date('d', $this->_comment_expire);
   1.152 +            }
   1.153  
   1.154              break;
   1.155  
   1.156          case 'cmt_close_month':
   1.157 -            $return = date('m', $this->_comment_expire);
   1.158 +            if ($this->_comment_expire == 0) {
   1.159 +                $return = date('m', time() +
   1.160 +                               ($_CONF['article_comment_close_days'] * 86400));
   1.161 +            } else {
   1.162 +                $return = date('m', $this->_comment_expire);
   1.163 +            }
   1.164  
   1.165              break;
   1.166  
   1.167          case 'cmt_close_year':
   1.168 -            $return = date('Y', $this->_comment_expire);
   1.169 +            if ($this->_comment_expire == 0) {
   1.170 +                $return = date('Y', time() +
   1.171 +                               ($_CONF['article_comment_close_days'] * 86400));
   1.172 +            } else {
   1.173 +                $return = date('Y', $this->_comment_expire);
   1.174 +            }
   1.175  
   1.176              break;
   1.177  
   1.178 @@ -1573,11 +1611,11 @@
   1.179              break;
   1.180              
   1.181          case 'commentcode':
   1.182 -            //check to see if comment_time has passed
   1.183 +            // check to see if comment_time has passed
   1.184              if ($this->_comment_expire != 0 && (time() > $this->_comment_expire) && $this->_commentcode == 0 ) {
   1.185 +                // if comment code is not 1, change it to 1
   1.186 +                DB_query("UPDATE {$_TABLES['stories']} SET commentcode = '1' WHERE sid = '$this->_sid'");
   1.187                  $return = 1;
   1.188 -                //if comment code is not 1, change it to 1
   1.189 -                DB_query("UPDATE {$_TABLES['stories']} SET commentcode = '1' WHERE sid = '$this->_sid'");
   1.190              } else {
   1.191                  $return = $this->_commentcode;
   1.192              }
   1.193 @@ -1895,7 +1933,7 @@
   1.194  
   1.195          $this->_expire = $expiredate;
   1.196          
   1.197 -        //comment expire time
   1.198 +        // comment expire time
   1.199          if (isset($array['cmt_close_flag'])) {
   1.200              $cmt_close_ampm = COM_applyFilter($array['cmt_close_ampm']);
   1.201              $cmt_close_hour = COM_applyFilter($array['cmt_close_hour'], true);
   1.202 @@ -1914,11 +1952,13 @@
   1.203              if ($cmt_close_ampm == 'am' AND $cmt_close_hour == 12) {
   1.204                  $cmt_close_hour = '00';
   1.205              }
   1.206 -            
   1.207 +
   1.208              $cmt_close_date
   1.209              = strtotime("$cmt_close_month/$cmt_close_day/$cmt_close_year $cmt_close_hour:$cmt_close_minute:$cmt_close_second");
   1.210 -            
   1.211 +
   1.212              $this->_comment_expire = $cmt_close_date;
   1.213 +        } else {
   1.214 +            $this->_comment_expire = 0;
   1.215          }
   1.216  
   1.217  
   1.218 @@ -2028,12 +2068,8 @@
   1.219          } elseif ($this->_show_topic_icon != 1) {
   1.220              $this->_show_topic_icon = 0;
   1.221          }
   1.222 +    }
   1.223  
   1.224 -        if (empty($this->_comment_expire)) {
   1.225 -            $this->_comment_expire = $this->_date
   1.226 -                            + ($_CONF['article_comment_close_days'] * 86400);
   1.227 -        }
   1.228 -    }
   1.229  // End Private Methods.
   1.230  
   1.231  /**************************************************************************/