1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8namespace Tiki\MailIn\Action; 9 10use Tiki\MailIn\Account; 11use Tiki\MailIn\Source\Message; 12use TikiLib; 13 14class ArticlePut implements ActionInterface 15{ 16 private $topicId; 17 private $type; 18 19 function __construct(array $params) 20 { 21 $this->topicId = isset($params['topic']) ? (int)$params['topic'] : 0; 22 $this->type = isset($params['type']) ? (int)$params['type'] : null; 23 } 24 25 function getName() 26 { 27 return tr('Submit Article'); 28 } 29 30 function isEnabled() 31 { 32 global $prefs; 33 34 return $prefs['feature_submissions'] == 'y'; 35 } 36 37 function isAllowed(Account $account, Message $message) 38 { 39 $user = $message->getAssociatedUser(); 40 $perms = TikiLib::lib('tiki')->get_user_permission_accessor($user, 'topic', $this->topicId); 41 42 if (! $perms->submit_article && ! $perms->edit_submission) { 43 return false; 44 } 45 46 return true; 47 } 48 49 function execute(Account $account, Message $message) 50 { 51 $artlib = TikiLib::lib('art'); 52 $tikilib = TikiLib::lib('tiki'); 53 54 $title = $message->getSubject(); 55 $heading = $message->getBody(); 56 $topicId = $this->topicId; 57 $userm = $message->getAssociatedUser(); 58 $authorName = $userm; 59 $body = ''; 60 $publishDate = $tikilib->now; 61 $cur_time = explode(',', $tikilib->date_format('%Y,%m,%d,%H,%M,%S', $publishDate)); 62 $expireDate = $tikilib->make_time($cur_time[3], $cur_time[4], $cur_time[5], $cur_time[1], $cur_time[2], $cur_time[0] + 1); 63 $subId = 0; 64 $type = $this->type; 65 $useImage = 'n'; 66 $image_x = ''; 67 $image_y = ''; 68 $imgname = ''; 69 $imgsize = ''; 70 $imgtype = ''; 71 $imgdata = ''; 72 $topline = ''; 73 $subtitle = ''; 74 $linkto = ''; 75 $image_caption = ''; 76 $lang = ''; 77 $rating = 7; 78 $isfloat = 'n'; 79 80 $subid = $artlib->replace_submission($title, $authorName, $topicId, $useImage, $imgname, $imgsize, $imgtype, $imgdata, $heading, $body, $publishDate, $expireDate, $userm, $subId, $image_x, $image_y, $type, $topline, $subtitle, $linkto, $image_caption, $lang, $rating, $isfloat); 81 82 $perms = TikiLib::lib('tiki')->get_user_permission_accessor($user, 'topic', $this->topicId); 83 if ($perms->autoapprove_submission) { 84 $artlib->approve_submission($subid); 85 } 86 87 return true; 88 } 89} 90