[geeklog-cvs] geeklog: Added an option to create a copy of a story (feature re...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Thu Dec 31 09:56:44 EST 2009


changeset 7562:4c4e857652c3
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/4c4e857652c3
user: Dirk Haun <dirk at haun-online.de>
date: Thu Dec 31 11:07:10 2009 +0100
description:
Added an option to create a copy of a story (feature request #0000811)

diffstat:

 public_html/admin/story.php    |  22 +++++++++++-----------
 public_html/docs/history       |   1 +
 system/classes/story.class.php |  46 +++++++++++++++++++++++++++++++++++++++++++++-
 system/lib-admin.php           |  17 ++++++++++++-----
 4 files changed, 69 insertions(+), 17 deletions(-)

diffs (211 lines):

diff -r bc430611e2fd -r 4c4e857652c3 public_html/admin/story.php
--- a/public_html/admin/story.php	Wed Dec 30 16:21:43 2009 +0100
+++ b/public_html/admin/story.php	Thu Dec 31 11:07:10 2009 +0100
@@ -163,8 +163,8 @@
 
     $header_arr = array(
         array('text' => $LANG_ADMIN['edit'], 'field' => 'edit', 'sort' => false),
+        array('text' => 'Copy', 'field' => 'copy', 'sort' => false),
         array('text' => $LANG_ADMIN['title'], 'field' => 'title', 'sort' => true),
-
         array('text' => $LANG_ACCESS['access'], 'field' => 'access', 'sort' => false),
         array('text' => $LANG24[34], 'field' => 'draft_flag', 'sort' => true)
     );
@@ -550,7 +550,7 @@
     $story_templates->set_var('lang_metadescription', $LANG_ADMIN['meta_description']);
     $story_templates->set_var('meta_description', $story->EditElements('meta_description'));
     $story_templates->set_var('lang_metakeywords', $LANG_ADMIN['meta_keywords']);
-    $story_templates->set_var('meta_keywords', $story->EditElements('meta_keywords'));    
+    $story_templates->set_var('meta_keywords', $story->EditElements('meta_keywords'));
     if ($_CONF['meta_tags'] > 0) {
         $story_templates->set_var('hide_meta', '');
     } else {
@@ -590,7 +590,7 @@
     $story_templates->set_var ('trackback_options',
             COM_optionList ($_TABLES['trackbackcodes'], 'code,name',
                             $story->EditElements('trackbackcode')));
-    // comment expire 
+    // comment expire
     $story_templates->set_var('lang_cmt_disable', $LANG24[63]);
     if ($story->EditElements('cmt_close')) {
         $story_templates->set_var('is_checked5', 'checked="checked"');
@@ -601,10 +601,10 @@
 
     $month_options = COM_getMonthFormOptions($story->EditElements('cmt_close_month'));
     $story_templates->set_var('cmt_close_month_options', $month_options);
-    
+
     $day_options = COM_getDayFormOptions($story->EditElements('cmt_close_day'));
     $story_templates->set_var('cmt_close_day_options', $day_options);
-    
+
     // ensure that the year dropdown includes the close year
     $endtm = mktime(0, 0, 0, date('m'),
                 date('d') + $_CONF['article_comment_close_days'], date('Y'));
@@ -618,7 +618,7 @@
         $year_options = COM_getYearFormOptions($close_year);
     }
     $story_templates->set_var('cmt_close_year_options', $year_options);
-    
+
     $cmt_close_ampm = '';
     $cmt_close_hour = $story->EditElements('cmt_close_hour');
     //correct hour
@@ -636,19 +636,19 @@
         $ampm_select = '<input type="hidden" name="cmt_close_ampm" value=""' . XHTML . '>';
     }
     $story_templates->set_var ('cmt_close_ampm_selection', $ampm_select);
-    
+
     if ($_CONF['hour_mode'] == 24) {
         $hour_options = COM_getHourFormOptions ($story->EditElements('cmt_close_hour'), 24);
     } else {
         $hour_options = COM_getHourFormOptions ($cmt_close_hour);
     }
     $story_templates->set_var('cmt_close_hour_options', $hour_options);
-    
+
     $minute_options = COM_getMinuteFormOptions($story->EditElements('cmt_close_minute'));
     $story_templates->set_var('cmt_close_minute_options', $minute_options);
-    
+
     $story_templates->set_var('cmt_close_second', $story->EditElements('cmt_close_second'));
-    
+
     if (($_CONF['onlyrootfeatures'] == 1 && SEC_inGroup('Root'))
         or ($_CONF['onlyrootfeatures'] !== 1)) {
         $featured_options = "<select name=\"featured\">" . LB
@@ -859,7 +859,7 @@
                              $editor);
     $display .= COM_siteFooter();
     COM_output($display);
-} else if ($mode == 'edit') {
+} elseif (($mode == 'edit') || ($mode == 'clone')) {
     $display .= COM_siteHeader('menu', $LANG24[5]);
     $sid = '';
     if (isset ($_GET['sid'])) {
diff -r bc430611e2fd -r 4c4e857652c3 public_html/docs/history
--- a/public_html/docs/history	Wed Dec 30 16:21:43 2009 +0100
+++ b/public_html/docs/history	Thu Dec 31 11:07:10 2009 +0100
@@ -3,6 +3,7 @@
 ??? ??, 2010 (1.6.2)
 ------------
 
+- Added an option to create a copy of a story (feature request #0000811) [Dirk]
 - Updated FCKeditor to version 2.6.5 [Dirk]
 - Prepare database for storing IPv6 addresses (feature request #0000971) [Dirk]
 - Implemented re-authentication when trying to submit a form with an expired
diff -r bc430611e2fd -r 4c4e857652c3 system/classes/story.class.php
--- a/system/classes/story.class.php	Wed Dec 30 16:21:43 2009 +0100
+++ b/system/classes/story.class.php	Thu Dec 31 11:07:10 2009 +0100
@@ -433,7 +433,7 @@
 
         $sid = addslashes(COM_applyFilter($sid));
 
-        if (!empty($sid) && (($mode == 'edit') || ($mode == 'view'))) {
+        if (!empty($sid) && (($mode == 'edit') || ($mode == 'view') || ($mode == 'clone'))) {
             $sql = array();
 
             $sql['mysql']
@@ -535,6 +535,19 @@
                     return STORY_INVALID_SID;
                 }
                 $this->loadFromArray($story);
+
+                /**
+                * The above SQL also got the story owner's username etc. from
+                * the DB. If the user doing the cloning is different from the
+                * original author, we need to fix those here.
+                */
+                if (($mode == 'clone') && ($this->_uid != $_USER['uid'])) {
+                    $this->_uid = $_USER['uid'];
+                    $story['owner_id'] = $this->_uid;
+                    $uresult = DB_query("SELECT username, fullname, photo, email FROM {$_TABLES['users']} WHERE uid = {$_USER['uid']}");
+                    list($this->_username, $this->_fullname, $this->_photo, $this->_email) = DB_fetchArray($uresult);
+                }
+
                 if (!isset($story['owner_id'])) {
                     $story['owner_id'] = 1;
                 }
@@ -593,9 +606,40 @@
             $this->_numemails = 0;
             $this->_statuscode = 0;
             $this->_owner_id = $this->_uid;
+
+        } elseif ($mode == 'clone') {
+
+            // new story, new sid ...
+            $this->_sid = COM_makesid();
+            $this->_old_sid = $this->_sid;
+
+            // assign ownership to current user
+            if (COM_isAnonUser()) {
+                $this->_uid = 1;
+            } else {
+                $this->_uid = $_USER['uid'];
+            }
+            $this->_owner_id = $this->_uid;
+
+            // use current date + time
+            $this->_date = time();
+            $this->_expire = time();
+
+            // if the original story uses comment expire, update the time
+            if ($this->_comment_expire != 0) {
+                $this->_comment_expire = time() +
+                    ($_CONF['article_comment_close_days'] * 86400);
+            }
+
+            // reset counters
+            $this->_hits = 0;
+            $this->_comments = 0;
+            $this->_trackbacks = 0;
+            $this->_numemails = 0;
         }
 
         $this->_sanitizeData();
+
         return STORY_LOADED_OK;
     }
 
diff -r bc430611e2fd -r 4c4e857652c3 system/lib-admin.php
--- a/system/lib-admin.php	Wed Dec 30 16:21:43 2009 +0100
+++ b/system/lib-admin.php	Thu Dec 31 11:07:10 2009 +0100
@@ -901,6 +901,7 @@
         break;
 
     case 'access':
+    case 'copy':
     case 'edit':
     case 'edit_adv':
         $access = SEC_hasAccess($A['owner_id'], $A['group_id'],
@@ -926,10 +927,16 @@
             } elseif ($fieldname == 'edit') {
                 $editmode = 'std';
             }
-            $editurl = $_CONF['site_admin_url']
-                     . '/story.php?mode=edit&editor=' . $editmode
-                     . '&sid=' . $A['sid'];
-            $retval = COM_createLink($icon_arr['edit'], $editurl);
+            if ($fieldname == 'copy') {
+                $copyurl = $_CONF['site_admin_url']
+                         . '/story.php?mode=clone&sid=' . $A['sid'];
+                $retval = COM_createLink($icon_arr['copy'], $copyurl);
+            } else {
+                $editurl = $_CONF['site_admin_url']
+                         . '/story.php?mode=edit&editor=' . $editmode
+                         . '&sid=' . $A['sid'];
+                $retval = COM_createLink($icon_arr['edit'], $editurl);
+            }
         }
         break;
 
@@ -1063,7 +1070,7 @@
     static $added_token;
 
     $retval = '';
-    
+
     switch($fieldname) {
         case 'edit':
             $retval = COM_createLink($icon_arr['edit'],



More information about the geeklog-cvs mailing list