3 // should be in import folder... need to know where this is used though...
5 require_once 'ConvertStyle.php';
7 class Pman_Core_ImportMailMessage extends Pman_Core_ConvertStyle
12 if (HTML_FlexyFramework::get()->cli) {
16 $this->authUser = $this->getAuthUser();
17 if (!$this->authUser) {
24 function get($v, $opts=array())
28 return $this->jerr("not allowed");
33 if(isset($_REQUEST['_convertToPlain']))
35 require_once 'System.php';
36 $tmpdir = System::mktemp("-d convertPlain");
37 $path = $tmpdir . '/' . time() . '.html';
39 if(isset($_REQUEST['_check_unsubscribe'])){
40 libxml_use_internal_errors (true);
41 $doc = new DOMDocument('1.0', 'UTF-8');
42 $doc->loadHTML($_REQUEST['bodytext']);
43 $xpath = new DOMXpath($doc);
44 foreach ($xpath->query('//a[@href]') as $a) {
45 $href = $a->getAttribute('href');
47 if(!preg_match('/^#unsubscribe/', $href)){
50 $a->parentNode->replaceChild($doc->createTextNode($a->nodeValue . ' {unsubscribe_link}'), $a);
53 $_REQUEST['bodytext'] = $doc->saveHTML();
54 libxml_use_internal_errors (false);
57 if(!file_exists($path)){
58 file_put_contents($path, $_REQUEST['bodytext']);
60 require_once 'File/Convert.php';
61 $fc = new File_Convert($path, 'text/html');
63 $plain = $fc->convert('text/plain');
64 $this->jok(file_get_contents($plain));
68 if(isset($_REQUEST['importUrl']))
70 $this->checkHeader($_REQUEST['importUrl']);
71 $data = $this->convertStyle($_REQUEST['importUrl'], '', true);
78 $htmlFile = DB_DataObject::factory('images');
79 $htmlFile->setFrom(array(
81 'ontable' =>'crm_mailing_list_message'
83 $htmlFile->onUpload(false);
85 if($htmlFile->mimetype != 'text/html')
87 $this->jerr('accept html file only!');
89 if(!file_exists($htmlFile->getStoreName()))
91 $this->jerr('update failed!');
94 $data = $this->convertStyle('', $htmlFile->getStoreName(), false);
98 unlink($htmlFile->getStoreName()) or die('Unable to delete the file');