3 require_once 'ConvertStyle.php';
5 class Pman_Crm_ImportHtml 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");
28 if(isset($_REQUEST['_convertToPlain']))
30 require_once 'System.php';
31 $tmpdir = System::mktemp("-d convertPlain");
32 $path = $tmpdir . '/' . time() . '.html';
34 if(isset($_REQUEST['_check_unsubscribe'])){
35 libxml_use_internal_errors (true);
36 $doc = new DOMDocument('1.0', 'UTF-8');
37 $doc->loadHTML($_REQUEST['bodytext']);
38 $xpath = new DOMXpath($doc);
39 foreach ($xpath->query('//a[@href]') as $a) {
40 $href = $a->getAttribute('href');
42 if(!preg_match('/^#unsubscribe/', $href)){
45 $a->parentNode->replaceChild($doc->createTextNode($a->nodeValue . ' {unsubscribe_link}'), $a);
48 $_REQUEST['bodytext'] = $doc->saveHTML();
49 libxml_use_internal_errors (false);
52 if(!file_exists($path)){
53 file_put_contents($path, $_REQUEST['bodytext']);
55 require_once 'File/Convert.php';
56 $fc = new File_Convert($path, 'text/html');
57 $plain = $fc->convert('text/plain');
58 $this->jok(file_get_contents($plain));
61 if(isset($_REQUEST['importUrl']))
63 $this->checkHeader($_REQUEST['importUrl']);
64 $data = $this->convertStyle($_REQUEST['importUrl'], '', true);
71 $htmlFile = DB_DataObject::factory('images');
72 $htmlFile->setFrom(array(
74 'ontable' =>'crm_mailing_list_message'
76 $htmlFile->onUpload(false);
78 if($htmlFile->mimetype != 'text/html')
80 $this->jerr('accept html file only!');
82 if(!file_exists($htmlFile->getStoreName()))
84 $this->jerr('update failed!');
87 $data = $this->convertStyle('', $htmlFile->getStoreName(), false);
91 unlink($htmlFile->getStoreName()) or die('Unable to delete the file');