ここの情報は古いです。ご理解頂いた上でお取り扱いください。

source: OpenPNE3/trunk/apps/mobile_mail_frontend/modules/member/actions/actions.class.php @ 11879

Last change on this file since 11879 was 11879, checked in by ebihara, 11 years ago

#3970:added support for replying a mail from a mail action

File size: 1.6 KB
Line 
1<?php
2
3/**
4 * This file is part of the OpenPNE package.
5 * (c) OpenPNE Project (http://www.openpne.jp/)
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file and the NOTICE file that were distributed with this source code.
9 */
10
11/**
12 * member actions.
13 *
14 * @package    OpenPNE
15 * @subpackage member
16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
17 */
18class memberActions extends sfActions
19{
20  public function executeImage(sfWebRequest $request)
21  {
22    $member = $this->getRoute()->getMember();
23    if (!$member)
24    {
25      return sfView::NONE;
26    }
27
28    foreach ($request->getMailMessage() as $part)
29    {
30      $count = $member->getMemberImage()->count();
31      if ($count >= 3)
32      {
33        throw new opRuntimeException('Cannot add an image any more.');
34      }
35
36      $tok = strtok($part->contentType, ';');
37      if ('text/plain' === $tok)
38      {
39        continue;
40      }
41
42      $tmppath = tempnam(sys_get_temp_dir(), 'IMG');
43
44      $fh = fopen($tmppath, 'w');
45      fwrite($fh, base64_decode($part->getContent(), true));
46      fclose($fh);
47
48      $validator = new opValidatorImageFile();
49      $validFile = $validator->clean(array(
50        'tmp_name' => $tmppath,
51        'type'     => $tok,
52      ));
53
54      $file = new File();
55      $file->setFromValidatedFile($validFile);
56      $file->setName('m_'.$member->getId().'_'.$file->getName());
57
58      $memberImage = new MemberImage();
59      $memberImage->setMember($member);
60      $memberImage->setFile($file);
61      if (!$count)
62      {
63        $memberImage->setIsPrimary(true);
64      }
65
66      $memberImage->save();
67    }
68
69    return sfView::NONE;
70  }
71}
Note: See TracBrowser for help on using the repository browser.