task_post.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: task_post.php 26754 2011-12-22 08:14:22Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class task_post {
  12. var $version = '1.0';
  13. var $name = 'post_name';
  14. var $description = 'post_desc';
  15. var $copyright = '<a href="http://www.comsenz.com" target="_blank">Comsenz Inc.</a>';
  16. var $icon = '';
  17. var $period = '';
  18. var $periodtype = 0;
  19. var $conditions = array(
  20. 'act' => array(
  21. 'title' => 'post_complete_var_act',
  22. 'type' => 'mradio',
  23. 'value' => array(
  24. array('newthread', 'post_complete_var_act_newthread'),
  25. array('newreply', 'post_complete_var_act_newreply'),
  26. array('newpost', 'post_complete_var_act_newpost'),
  27. ),
  28. 'default' => 'newthread',
  29. 'sort' => 'complete',
  30. ),
  31. 'forumid' => array(
  32. 'title' => 'post_complate_var_forumid',
  33. 'type' => 'select',
  34. 'value' => array(),
  35. 'sort' => 'complete',
  36. ),
  37. 'threadid' => array(
  38. 'title' => 'post_complate_var_threadid',
  39. 'type' => 'text',
  40. 'value' => '',
  41. 'sort' => 'complete',
  42. ),
  43. 'num' => array(
  44. 'title' => 'post_complete_var_num',
  45. 'type' => 'text',
  46. 'value' => '',
  47. 'sort' => 'complete',
  48. ),
  49. 'time' => array(
  50. 'title' => 'post_complete_var_time',
  51. 'type' => 'text',
  52. 'value' => '',
  53. 'sort' => 'complete',
  54. )
  55. );
  56. function task_post() {
  57. global $_G;
  58. loadcache('forums');
  59. $this->conditions['forumid']['value'][] = array(0, '&nbsp;');
  60. if(empty($_G['cache']['forums'])) $_G['cache']['forums'] = array();
  61. foreach($_G['cache']['forums'] as $fid => $forum) {
  62. $this->conditions['forumid']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name'], $forum['type'] == 'group' ? 1 : 0);
  63. }
  64. }
  65. function csc($task = array()) {
  66. global $_G;
  67. $taskvars = array('num' => 0);
  68. foreach(C::t('common_taskvar')->fetch_all_by_taskid($task['taskid']) as $taskvar) {
  69. if($taskvar['value']) {
  70. $taskvars[$taskvar['variable']] = $taskvar['value'];
  71. }
  72. }
  73. $taskvars['num'] = $taskvars['num'] ? $taskvars['num'] : 1;
  74. $tbladd = $sqladd = '';
  75. if($taskvars['act'] == 'newreply' && $taskvars['threadid']) {
  76. $threadid = $taskvars['threadid'];
  77. } else {
  78. if($taskvars['forumid']) {
  79. $forumid = $taskvars['forumid'];
  80. }
  81. if($taskvars['author']) {
  82. return TRUE;
  83. }
  84. }
  85. if($taskvars['act']) {
  86. if($taskvars['act'] == 'newthread') {
  87. $first = '1';
  88. } elseif($taskvars['act'] == 'newreply') {
  89. $first = '0';
  90. }
  91. }
  92. $starttime = $task['applytime'];
  93. if($taskvars['time'] = floatval($taskvars['time'])) {
  94. $endtime = $task['applytime'] + 3600 * $taskvars['time'];
  95. }
  96. $num = C::t('forum_post')->count_by_search(0, $threadid, null, 0, $forumid, $_G['uid'], null, $starttime, $endtime, null, $first);
  97. if($num && $num >= $taskvars['num']) {
  98. return TRUE;
  99. } elseif($taskvars['time'] && TIMESTAMP >= $task['applytime'] + 3600 * $taskvars['time'] && (!$num || $num < $taskvars['num'])) {
  100. return FALSE;
  101. } else {
  102. return array('csc' => $num > 0 && $taskvars['num'] ? sprintf("%01.2f", $num / $taskvars['num'] * 100) : 0, 'remaintime' => $taskvars['time'] ? $task['applytime'] + $taskvars['time'] * 3600 - TIMESTAMP : 0);
  103. }
  104. }
  105. function view($task, $taskvars) {
  106. global $_G;
  107. $return = $value = '';
  108. if(!empty($taskvars['complete']['forumid'])) {
  109. $value = intval($taskvars['complete']['forumid']['value']);
  110. loadcache('forums');
  111. $value = '<a href="forum.php?mod=forumdisplay&fid='.$value.'"><strong>'.$_G['cache']['forums'][$value]['name'].'</strong></a>';
  112. } elseif(!empty($taskvars['complete']['threadid'])) {
  113. $value = intval($taskvars['complete']['threadid']['value']);
  114. $thread = C::t('forum_thread')->fetch($value);
  115. $value = '<a href="forum.php?mod=viewthread&tid='.$value.'"><strong>'.($thread['subject'] ? $thread['subject'] : 'TID '.$value).'</strong></a>';
  116. } elseif(!empty($taskvars['complete']['author'])) {
  117. $value = $taskvars['complete']['author']['value'];
  118. $authorid = C::t('common_member')->fetch_uid_by_username($value);
  119. $value = '<a href="home.php?mod=space&uid='.$authorid.'"><strong>'.$value.'</strong></a>';
  120. }
  121. $taskvars['complete']['num']['value'] = intval($taskvars['complete']['num']['value']);
  122. $taskvars['complete']['num']['value'] = $taskvars['complete']['num']['value'] ? $taskvars['complete']['num']['value'] : 1;
  123. if($taskvars['complete']['act']['value'] == 'newreply') {
  124. if($taskvars['complete']['threadid']) {
  125. $return .= lang('task/post', 'task_complete_act_newreply_thread', array('value' => $value, 'num' => $taskvars['complete']['num']['value']));
  126. } else {
  127. $return .= lang('task/post', 'task_complete_act_newreply_author', array('value' => $value, 'num' => $taskvars['complete']['num']['value']));
  128. }
  129. } else {
  130. if($taskvars['complete']['forumid']) {
  131. $return .= lang('task/post', 'task_complete_forumid', array('value' => $value));
  132. }
  133. if($taskvars['complete']['act']['value'] == 'newthread') {
  134. $return .= lang('task/post', 'task_complete_act_newthread', array('num' => $taskvars['complete']['num']['value']));
  135. } else {
  136. $return .= lang('task/post', 'task_complete_act_newpost', array('num' => $taskvars['complete']['num']['value']));
  137. }
  138. }
  139. return $return;
  140. }
  141. function sufprocess($task) {
  142. }
  143. }
  144. ?>