3 require_once 'ConvertStyle.php';
5 class Pman_Core_ImportMailMessage extends Pman_Core_ConvertStyle
9 if (HTML_FlexyFramework::get()->cli) {
12 $this->authUser = $this->getAuthUser();
13 if (!$this->authUser) {
23 return $this->jerr("not allowed");
29 if(isset($_REQUEST['_convertToPlain']))
31 require_once 'System.php';
32 $tmpdir = System::mktemp("-d convertPlain");
33 $path = $tmpdir . '/' . time() . '.html';
35 if(isset($_REQUEST['_check_unsubscribe'])){
36 libxml_use_internal_errors (true);
37 $doc = new DOMDocument('1.0', 'UTF-8');
38 $doc->loadHTML($_REQUEST['bodytext']);
39 $xpath = new DOMXpath($doc);
40 foreach ($xpath->query('//a[@href]') as $a) {
41 $href = $a->getAttribute('href');
43 if(!preg_match('/^#unsubscribe/', $href)){
46 $a->parentNode->replaceChild($doc->createTextNode($a->nodeValue . ' {unsubscribe_link}'), $a);
49 $_REQUEST['bodytext'] = $doc->saveHTML();
50 libxml_use_internal_errors (false);
53 if(!file_exists($path)){
54 file_put_contents($path, $_REQUEST['bodytext']);
56 require_once 'File/Convert.php';
57 $fc = new File_Convert($path, 'text/html');
58 $plain = $fc->convert('text/plain');
59 $this->jok(file_get_contents($plain));
63 if(isset($_REQUEST['importUrl']))
65 print_r($_REQUEST);exit;
66 $this->checkHeader($_REQUEST['importUrl']);
67 $data = $this->convertStyle($_REQUEST['importUrl'], '', true);
74 $htmlFile = DB_DataObject::factory('images');
75 $htmlFile->setFrom(array(
77 'ontable' =>'crm_mailing_list_message'
79 $htmlFile->onUpload(false);
81 if($htmlFile->mimetype != 'text/html')
83 $this->jerr('accept html file only!');
85 if(!file_exists($htmlFile->getStoreName()))
87 $this->jerr('update failed!');
90 $data = $this->convertStyle('', $htmlFile->getStoreName(), false);
94 unlink($htmlFile->getStoreName()) or die('Unable to delete the file');