looking for wrong seperator
[Pman.Core] / ImportMailMessage.php
1 <?php
2
3 // should be in import folder... need to know where this is used though...
4
5 require_once 'ConvertStyle.php';
6
7 class Pman_Core_ImportMailMessage extends Pman_Core_ConvertStyle 
8 {
9     function getAuth()
10     {
11         if (HTML_FlexyFramework::get()->cli) {
12             return true;
13         }
14         $this->authUser = $this->getAuthUser();
15         if (!$this->authUser) {
16             return false;
17         }
18         return true;
19     }
20     
21     function get($v, $opts=array())
22     {
23         $this->post();
24         
25         return $this->jerr("not allowed");
26     }
27     
28     function post($v)
29     {   
30         if(isset($_REQUEST['_convertToPlain']))
31         {
32             require_once 'System.php';
33             $tmpdir  = System::mktemp("-d convertPlain");
34             $path = $tmpdir . '/' . time() . '.html';
35             
36             if(isset($_REQUEST['_check_unsubscribe'])){
37                 libxml_use_internal_errors (true);
38                 $doc = new DOMDocument('1.0', 'UTF-8');
39                 $doc->loadHTML($_REQUEST['bodytext']);
40                 $xpath = new DOMXpath($doc);
41                 foreach ($xpath->query('//a[@href]') as $a) { 
42                     $href = $a->getAttribute('href');
43                     
44                     if(!preg_match('/^#unsubscribe/', $href)){
45                         continue;
46                     }
47                     $a->parentNode->replaceChild($doc->createTextNode($a->nodeValue . ' {unsubscribe_link}'), $a);
48                 }
49                 
50                 $_REQUEST['bodytext'] = $doc->saveHTML();
51                 libxml_use_internal_errors (false);
52             }
53             
54             if(!file_exists($path)){
55                file_put_contents($path, $_REQUEST['bodytext']); 
56             }
57             require_once 'File/Convert.php';
58             $fc = new File_Convert($path, 'text/html');
59             
60             $plain = $fc->convert('text/plain');
61             $this->jok(file_get_contents($plain));
62         }
63         
64         // Import from URL
65         if(isset($_REQUEST['importUrl']))
66         {
67             $this->checkHeader($_REQUEST['importUrl']);
68             $data = $this->convertStyle($_REQUEST['importUrl'], '', true);
69          
70             $this->jok($data);
71             
72         }
73      
74         // Import from file
75         $htmlFile = DB_DataObject::factory('images');
76         $htmlFile->setFrom(array(
77                'onid' => 0,
78                'ontable' =>'crm_mailing_list_message'
79         ));
80         $htmlFile->onUpload(false);
81        
82         if($htmlFile->mimetype != 'text/html')
83         {
84             $this->jerr('accept html file only!');
85         }
86         if(!file_exists($htmlFile->getStoreName()))
87         {
88             $this->jerr('update failed!');
89         }
90         
91         $data = $this->convertStyle('', $htmlFile->getStoreName(), false);
92         
93         $htmlFile->delete();
94         
95         unlink($htmlFile->getStoreName()) or die('Unable to delete the file');
96         
97         $this->jok($data);
98     }
99     
100 }