WYSIJA_help_install

The MailPoet Newsletters WYSIJA help install class.

Defined (1)

The class is defined in the following location(s).

/helpers/install.php  
  1. class WYSIJA_help_install extends WYSIJA_object{ 
  2.  
  3. function __construct() { 
  4. if(file_exists(ABSPATH . 'wp-admin'.DS.'includes'.DS.'upgrade.php')) require_once(ABSPATH . 'wp-admin'.DS.'includes'.DS.'upgrade.php'); 
  5.  
  6. function install() { 
  7. $values=array(); 
  8. $model_config=WYSIJA::get('config', 'model'); 
  9. // test server against few things to make sure the installation can be done 
  10. $helper_server=WYSIJA::get('server', 'helper'); 
  11. $missing_capabilities=$helper_server->unhealthy(); 
  12.  
  13. // if it returns false it means we're all good 
  14. if($missing_capabilities!==false) { 
  15. // it will fail only if we have more than one missing capabilities or if we have just one and that's a required function 
  16. if(count($missing_capabilities) > 1 || 
  17. (count($missing_capabilities)==1 && (!isset($missing_capabilities['functions']) || isset($missing_capabilities['functions']['required']))) ) { 
  18. // here we need to return unfortunately 
  19. $this->error(__('Your server cannot run MailPoet.', WYSIJA), 1); 
  20.  
  21. if(isset($missing_capabilities['functions']['required'])) { 
  22. $this->error(sprintf(__('Your server is missing one or many important PHP functions to run properly : %1$s', WYSIJA), '<strong>'.implode(', ', array_keys($missing_capabilities['functions']['required'])).'</strong>').' '.__('Please contact your host or server administrator to fix this.', WYSIJA)); 
  23.  
  24. return false; 
  25. }else{ 
  26. // here we're ok 
  27.  
  28. // create the tables there shouldn't be any issue since we've tested it before 
  29. if((int)get_option('installation_step')<1) { 
  30. if(!$this->createTables(WYSIJA_DIR.'sql'.DS.'install.sql')) return false; 
  31.  
  32. WYSIJA::update_option('installation_step', '1'); 
  33.  
  34.  
  35. // move data to uploads folder: this needs to be done prior to default campaign creation for dependency reasons 
  36. if((int)get_option('installation_step')<4) { 
  37. $this->moveData('themes'); 
  38. $this->moveData('dividers'); 
  39. $this->moveData('bookmarks'); 
  40. WYSIJA::update_option('installation_step', '4'); 
  41.  
  42.  
  43. // record custom fields lastname firstname in the user_field table 
  44. if((int)get_option('installation_step')<5) { 
  45. $this->recordDefaultUserField(); 
  46. WYSIJA::update_option('installation_step', '5'); 
  47.  
  48. // save default values for the fields : from_name, from_email replyto_name, replyto_email 
  49. if((int)get_option('installation_step')<6) { 
  50. $this->defaultSettings($values); 
  51. $model_config->save($values); 
  52. WYSIJA::update_option('installation_step', '6'); 
  53.  
  54.  
  55. //create a default list 
  56. if((int)get_option('installation_step')<7) { 
  57. $this->defaultList($values); 
  58. $model_config->save($values); 
  59. WYSIJA::update_option('installation_step', '7'); 
  60.  
  61.  
  62. // create a default campaign 
  63. if((int)get_option('installation_step')<8) { 
  64. $this->defaultCampaign($values); 
  65. $model_config->save($values); 
  66. WYSIJA::update_option('installation_step', '8'); 
  67.  
  68.  
  69. // synchronize our user table with wordpress users 
  70. if((int)get_option('installation_step')<9) { 
  71. $helper_import=WYSIJA::get('plugins_import', 'helper'); 
  72. $values['importwp_list_id']=$helper_import->importWP(); 
  73. $model_config->save($values); 
  74. WYSIJA::update_option('installation_step', '9'); 
  75.  
  76. // create subscription redirection page 
  77. if((int)get_option('installation_step')<10) { 
  78. $this->createPage($values); 
  79. $model_config->save($values); 
  80. WYSIJA::update_option('installation_step', '10'); 
  81.  
  82.  
  83. // create the default dir 
  84. if((int)get_option('installation_step')<11) { 
  85. $this->createWYSIJAdir($values); 
  86. $model_config->save($values); 
  87. WYSIJA::update_option('installation_step', '11'); 
  88.  
  89.  
  90. // create default subscription form 
  91. if((int)get_option('installation_step')<12) { 
  92. $this->create_default_subscription_form(); 
  93. WYSIJA::update_option('installation_step', '12'); 
  94.  
  95.  
  96. // save the confirmation email in the table 
  97.  
  98.  
  99. if((int)get_option('installation_step')<13) { 
  100. // make sure that the activation email is translated 
  101. $model_config->add_translated_default(); 
  102. WYSIJA::update_option('installation_step', '13'); 
  103.  
  104. if((int)get_option('installation_step')<14) { 
  105. $model_email=WYSIJA::get('email', 'model'); 
  106. $model_email->blockMe=true; 
  107. $values['confirm_email_id']=$model_email->insert( 
  108. array('type'=>'0',  
  109. 'from_email'=>$values['from_email'],  
  110. 'from_name'=>$values['from_name'],  
  111. 'replyto_email'=>$values['from_email'],  
  112. 'replyto_name'=>$values['from_name'],  
  113. 'subject'=>$model_config->getValue('confirm_email_title'),  
  114. 'body'=>$model_config->getValue('confirm_email_body'),  
  115. 'status'=>99)); 
  116. $model_config->save($values); 
  117. WYSIJA::update_option('installation_step', '14'); 
  118.  
  119.  
  120. // look for existing newsletter plugins to import from 
  121. if((int)get_option('installation_step')<15) { 
  122. $this->testNLplugins(); 
  123.  
  124. // administrator caps 
  125. $helper_wp_tools = WYSIJA::get('wp_tools', 'helper'); 
  126. $helper_wp_tools->set_default_rolecaps(); 
  127.  
  128. WYSIJA::update_option('installation_step', '15'); 
  129.  
  130.  
  131.  
  132. // save the config into the db 
  133.  
  134. if( (int) get_option('installation_step') < 16) { 
  135.  
  136. $model_config = WYSIJA::get('config', 'model'); 
  137.  
  138. $values['installed'] = true; 
  139. $values['manage_subscriptions'] = true; 
  140. $values['installed_time'] = time(); 
  141.  
  142. $values['wysija_db_version'] = WYSIJA::get_version(); 
  143.  
  144. $helper_toolbox = WYSIJA::get('toolbox', 'helper'); 
  145. $values['dkim_domain'] = $helper_toolbox->_make_domain_name(); 
  146.  
  147. if( get_option('wysija_reinstall', 0) ) $values['wysija_whats_new'] = WYSIJA::get_version(); 
  148. $model_config->save($values); 
  149.  
  150. WYSIJA::update_option('installation_step', '16'); 
  151.  
  152.  
  153.  
  154.  
  155. global $wysija_installing; 
  156. $wysija_installing=false; 
  157. WYSIJA::update_option('wysija_reinstall', 0); 
  158. return true; 
  159.  
  160.  
  161. // Description: Creates the default list. 
  162. function defaultList(&$values) { 
  163. $model_list=WYSIJA::get('list', 'model'); 
  164. $listname=__('My first list', WYSIJA); 
  165. $defaultListId=$model_list->insert(array( 
  166. 'name'=>$listname,  
  167. 'description'=>__('The list created automatically on install of the MailPoet.', WYSIJA),  
  168. 'is_public'=>1,  
  169. 'is_enabled'=>1)); 
  170. $values['default_list_id']=$defaultListId; 
  171. // Add Wordpress user as first subscriber of the default list. 
  172. $helper_user=WYSIJA::get('user', 'helper'); 
  173. $current_user=WYSIJA::wp_get_userdata(); 
  174.  
  175. $user_ids = array($current_user->ID); 
  176.  
  177. $id=$helper_user->addToList($values['default_list_id'], $user_ids); 
  178.  
  179. function defaultCampaign($valuesconfig) { 
  180. $modelCampaign=WYSIJA::get('campaign', 'model'); 
  181. $campaign_id=$modelCampaign->insert( 
  182. array( 
  183. 'name'=>__('5 Minute User Guide', WYSIJA),  
  184. 'description'=>'',  
  185.  
  186. )); 
  187.  
  188. $modelEmail=WYSIJA::get('email', 'model'); 
  189. $modelEmail->fieldValid=false; 
  190.  
  191. $dataEmail=array( 
  192. 'campaign_id'=>$campaign_id,  
  193. 'subject'=>__('5 Minute User Guide', WYSIJA) 
  194. ); 
  195.  
  196. // get default styles 
  197. $wjEngine = WYSIJA::get('wj_engine', 'helper'); 
  198.  
  199. // get solid divider 
  200. $hDividers = WYSIJA::get('dividers', 'helper'); 
  201. $defaultDivider = $hDividers->getDefault(); 
  202.  
  203. // get bookmarks from iconset 2 
  204. $hBookmarks = WYSIJA::get('bookmarks', 'helper'); 
  205. $bookmarks = $hBookmarks->getAllByIconset('medium', '02'); 
  206.  
  207. //-------------- 
  208. $dataEmail['wj_data'] = array( 
  209. 'version' => WYSIJA::get_version(),  
  210. 'header' => array( 
  211. 'text' => null,  
  212. 'image' => array( 
  213. 'src' => WYSIJA_EDITOR_IMG.'default-newsletter/newsletter/header.png',  
  214. 'width' => 600,  
  215. 'height' => 72,  
  216. 'alignment' => 'center',  
  217. 'static' => false 
  218. ),  
  219. 'alignment' => 'center',  
  220. 'static' => false,  
  221. 'type' => 'header' 
  222. ),  
  223. 'body' => array( 
  224. 'block-1' => array( 
  225. 'text' => array( 
  226. 'value' => '<h2><strong>'.__('Step 1:', WYSIJA).'</strong> '.__('hey, click on this text!', WYSIJA).'</h2>'.'<p>'.__('To edit, simply click on this block of text.', WYSIJA).'</p>' 
  227. ),  
  228. 'image' => null,  
  229. 'alignment' => 'left',  
  230. 'static' => false,  
  231. 'position' => 1,  
  232. 'type' => 'content' 
  233. ),  
  234. 'block-2' => array_merge(array( 
  235. 'position' => 2,  
  236. 'type' => 'divider' 
  237. ), $defaultDivider 
  238. ),  
  239. 'block-3' => array( 
  240. 'text' => array( 
  241. 'value' => '<h2><strong>'.__('Step 2:', WYSIJA).'</strong> '.__('play with this image', WYSIJA).'</h2>' 
  242. ),  
  243. 'image' => null,  
  244. 'alignment' => 'left',  
  245. 'static' => false,  
  246. 'position' => 3,  
  247. 'type' => 'content' 
  248. ),  
  249. 'block-4' => array( 
  250. 'text' => array( 
  251. 'value' => '<p>'.__('Position your mouse over the image to the left.', WYSIJA).'</p>' 
  252. ),  
  253. 'image' => array( 
  254. 'src' => WYSIJA_EDITOR_IMG.'default-newsletter/newsletter/pigeon.png',  
  255. 'width' => 281,  
  256. 'height' => 190,  
  257. 'alignment' => 'left',  
  258. 'static' => false 
  259. ),  
  260. 'alignment' => 'left',  
  261. 'static' => false,  
  262. 'position' => 4,  
  263. 'type' => 'content' 
  264. ),  
  265. 'block-5' => array_merge(array( 
  266. 'position' => 5,  
  267. 'type' => 'divider' 
  268. ), $defaultDivider 
  269. ),  
  270. 'block-6' => array( 
  271. 'text' => array( 
  272. 'value' => '<h2><strong>'.__('Step 3:', WYSIJA).'</strong> '.__('drop content here', WYSIJA).'</h2>'. 
  273. '<p>'.sprintf(__('Drag and drop %1$stext, posts, dividers.%2$s Look on the right!', WYSIJA), '<strong>', '</strong>').'</p>'. 
  274. '<p>'.sprintf(__('You can even %1$ssocial bookmarks%2$s like these:', WYSIJA), '<strong>', '</strong>').'</p>' 
  275. ),  
  276. 'image' => null,  
  277. 'alignment' => 'left',  
  278. 'static' => false,  
  279. 'position' => 6,  
  280. 'type' => 'content' 
  281. ),  
  282. 'block-7' => array( 
  283. 'width' => 184,  
  284. 'alignment' => 'center',  
  285. 'items' => array( 
  286. array_merge(array( 
  287. 'url' => 'http://www.facebook.com/mailpoetplugin',  
  288. 'alt' => 'Facebook',  
  289. 'cellWidth' => 61,  
  290. 'cellHeight' => 32 
  291. ), $bookmarks['facebook']),  
  292. array_merge(array( 
  293. 'url' => 'http://www.twitter.com/mail_poet',  
  294. 'alt' => 'Twitter',  
  295. 'cellWidth' => 61,  
  296. 'cellHeight' => 32 
  297. ), $bookmarks['twitter']),  
  298. array_merge(array( 
  299. 'url' => 'https://plus.google.com/+Mailpoet',  
  300. 'alt' => 'Google',  
  301. 'cellWidth' => 61,  
  302. 'cellHeight' => 32 
  303. ), $bookmarks['google']) 
  304. ),  
  305. 'position' => 7,  
  306. 'type' => 'gallery' 
  307. ),  
  308. 'block-8' => array_merge(array( 
  309. 'position' => 8,  
  310. 'type' => 'divider' 
  311. ), $defaultDivider 
  312. ),  
  313. 'block-9' => array( 
  314. 'text' => array( 
  315. 'value' => '<h2><strong>'.__('Step 4:', WYSIJA).'</strong> '.__('and the footer?', WYSIJA).'</h2>'. 
  316. '<p>'.sprintf(__('Change the footer\'s content in MailPoet\'s %1$sSettings%2$s page.', WYSIJA), '<strong>', '</strong>').'</p>' 
  317. ),  
  318. 'image' => null,  
  319. 'alignment' => 'left',  
  320. 'static' => false,  
  321. 'position' => 9,  
  322. 'type' => 'content' 
  323. ),  
  324. 'footer' => array( 
  325. 'text' => NULL,  
  326. 'image' => array( 
  327. 'src' => WYSIJA_EDITOR_IMG.'default-newsletter/newsletter/footer.png',  
  328. 'width' => 600,  
  329. 'height' => 46,  
  330. 'alignment' => 'center',  
  331. 'static' => false,  
  332. ),  
  333. 'alignment' => 'center',  
  334. 'static' => false,  
  335. 'type' => 'footer' 
  336. ); 
  337.  
  338. $dataEmail['wj_styles'] = array( 
  339. 'html' => array( 
  340. 'background' => 'e8e8e8' 
  341. ),  
  342. 'header' => array( 
  343. 'background' => 'e8e8e8' 
  344. ),  
  345. 'body' => array( 
  346. 'color' => '000000',  
  347. 'family' => 'Arial',  
  348. 'size' => 16,  
  349. 'background' => 'ffffff' 
  350. ),  
  351. 'footer' => array( 
  352. 'background' => 'e8e8e8' 
  353. ),  
  354. 'h1' => array( 
  355. 'color' => '000000',  
  356. 'family' => 'Trebuchet MS',  
  357. 'size' => 40 
  358. ),  
  359. 'h2' => array( 
  360. 'color' => '424242',  
  361. 'family' => 'Trebuchet MS',  
  362. 'size' => 30 
  363. ),  
  364. 'h3' => array( 
  365. 'color' => '424242',  
  366. 'family' => 'Trebuchet MS',  
  367. 'size' => 24 
  368. ),  
  369. 'a' => array( 
  370. 'color' => '4a91b0',  
  371. 'underline' => false 
  372. ),  
  373. 'unsubscribe' => array( 
  374. 'color' => '000000' 
  375. ),  
  376. 'viewbrowser' => array( 
  377. 'color' => '000000',  
  378. 'family' => 'Arial',  
  379. 'size' => 12 
  380. ); 
  381. //---- END DEFAULT EMAIL --------- 
  382. foreach( $dataEmail['wj_data'] as $key =>&$eachval) { 
  383. if($key=="body") { 
  384. foreach($eachval as &$realeachval) { 
  385. if(isset($realeachval['text']['value'])) $realeachval['text']['value']=base64_encode($realeachval['text']['value']); 
  386.  
  387. $dataEmail['params'] = array( 
  388. 'quickselection' => array( 
  389. 'wp-301' => array( 
  390. 'identifier' => 'wp-301',  
  391. 'width' => 281,  
  392. 'height' => 190,  
  393. 'url' => WYSIJA_EDITOR_IMG.'default-newsletter/newsletter/pigeon.png',  
  394. 'thumb_url' => WYSIJA_EDITOR_IMG.'default-newsletter/newsletter/pigeon-150x150.png' 
  395. ); 
  396. $wjEngine = WYSIJA::get('wj_engine', 'helper'); 
  397. $wjEngine->setData($dataEmail['wj_data']); 
  398. $result = false; 
  399. $dataEmail['params'] = base64_encode(serialize($dataEmail['params'])); 
  400. $dataEmail['wj_styles'] = base64_encode(serialize($dataEmail['wj_styles'])); 
  401. $dataEmail['wj_data'] = base64_encode(serialize($dataEmail['wj_data'])); 
  402.  
  403.  
  404. $dataEmail['replyto_name']=$dataEmail['from_name']=$valuesconfig['from_name']; 
  405. $dataEmail['replyto_email']=$dataEmail['from_email']=$valuesconfig['from_email']; 
  406. $data['email']['email_id']=$modelEmail->insert($dataEmail); 
  407.  
  408.  
  409.  
  410. $modelEmail = WYSIJA::get('email', 'model'); 
  411. $emailData = $modelEmail->getOne(array('wj_styles', 'subject', 'params', 'email_id'), array('email_id' => $data['email']['email_id'])); 
  412.  
  413. $wjEngine->setStyles($emailData['wj_styles'], true); 
  414.  
  415. $values = array('wj_data' => $wjEngine->getEncoded('data')); 
  416. $values['body'] = $wjEngine->renderEmail($emailData); 
  417. $result = $modelEmail->update($values, array('email_id' => $data['email']['email_id'])); 
  418.  
  419.  
  420. /** 
  421. * this function creates the table from a specified sql file and test that the tables have been properly created. 
  422. * TODO it should just need a SQL file and no other parameter 
  423. * @global type $wpdb 
  424. * @param type $sql_file 
  425. * @param type $main_table_ms 
  426. * @return boolean 
  427. */ 
  428. function createTables($sql_file, $main_table_ms=false) { 
  429. // prepare some parameters 
  430. $model_user=WYSIJA::get('user', 'model'); 
  431. $prefix = $model_user->getPrefix(); 
  432. $array_tables_to_test = array('user_list', 'user', 'list', 'campaign', 'campaign_list', 'email', 'user_field', 'queue', 'user_history', 'email_user_stat', 'url', 'email_user_url', 'url_mail'); 
  433.  
  434. // if we are running a ms file we use a different prefix and we verify different tables 
  435. if($main_table_ms) { 
  436. $prefix = $model_user->get_site_prefix(); 
  437. $array_tables_to_test = array('bounce'); 
  438.  
  439.  
  440. // load the sql file, read it and separate the queries 
  441. $handle = fopen($sql_file, 'r'); 
  442. $query = fread($handle, filesize($sql_file)); 
  443. fclose($handle); 
  444.  
  445. $query=str_replace('CREATE TABLE IF NOT EXISTS `', 'CREATE TABLE IF NOT EXISTS `'.$prefix, $query); 
  446. $queries=explode('-- QUERY ---', $query); 
  447.  
  448. // execute the queries one by one 
  449. global $wpdb; 
  450. $has_errors = false; 
  451.  
  452. foreach($queries as $qry) { 
  453. $last_error = $wpdb->last_error; 
  454. $wpdb->query($qry); 
  455.  
  456. if( !empty($wpdb->last_error) && $last_error != $wpdb->last_error ) { 
  457. $this->notice($wpdb->last_error); 
  458. $has_errors = true; 
  459.  
  460.  
  461. // list the tables that haven't been created 
  462. $missingtables=array(); 
  463. foreach($array_tables_to_test as $table_name) { 
  464. if(!$model_user->query("SHOW TABLES like '".$prefix.$table_name."';")) { 
  465. $missingtables[]=$prefix.$table_name; 
  466.  
  467. // return the result 
  468. if($missingtables) { 
  469. $this->error(sprintf(__('These tables could not be created on installation: %1$s', WYSIJA), implode(', ', $missingtables)), 1); 
  470. $has_errors=true; 
  471. if($has_errors) return false; 
  472. return true; 
  473.  
  474. /** 
  475. * @param type $values 
  476. * @return boolean 
  477. */ 
  478. function createWYSIJAdir(&$values) { 
  479. $upload_dir = wp_upload_dir(); 
  480.  
  481. $dirname=$upload_dir['basedir'].DS.'wysija'.DS; 
  482. $url=$upload_dir['baseurl'].'/wysija/'; 
  483. if(!file_exists($dirname)) { 
  484. if(!mkdir($dirname, 0755, true)) { 
  485. return false; 
  486.  
  487. // Create index.html to protect main wysija data directory. 
  488. $filename = 'index.html'; 
  489. fclose(fopen($dirname.$filename, "w")); 
  490.  
  491. $values['uploadfolder']=$dirname; 
  492. $values['uploadurl']=$url; 
  493.  
  494. function moveData($folder) { 
  495. $fileHelper = WYSIJA::get('file', 'helper'); 
  496.  
  497. // get target directory 
  498. $targetDir = $fileHelper->makeDir($folder); 
  499. if($targetDir === FALSE) { 
  500. // directory does not exist and could not be created 
  501. return FALSE; 
  502. } else { 
  503. // define source directory 
  504. $sourceDir = WYSIJA_DATA_DIR.$folder.DS; 
  505.  
  506. // don't do anything if source directory does not exist 
  507. if(is_dir($sourceDir) === FALSE) return FALSE; 
  508.  
  509. // scan for files 
  510. $files = scandir($sourceDir); 
  511.  
  512. // recursively copy files 
  513. foreach($files as $filename) { 
  514. if(!in_array($filename, array('.', '..', '.DS_Store', 'Thumbs.db'))) { 
  515. $this->rcopy($sourceDir.$filename, $targetDir.$filename); 
  516.  
  517. function rrmdir($dir) { 
  518. if (is_dir($dir)) { 
  519. $files = scandir($dir); 
  520. foreach ($files as $file) 
  521. if ($file != '.' && $file != '..') $this->rrmdir("$dir".DS."$file"); 
  522. rmdir($dir); 
  523. else if (file_exists($dir)) { 
  524. $dir=str_replace('/', DS, $dir); 
  525. unlink($dir); 
  526.  
  527. function rcopy($src, $dst) { 
  528. if (file_exists($dst)) $this->rrmdir($dst); 
  529. if (is_dir($src)) { 
  530. mkdir($dst); 
  531. $files = scandir($src); 
  532. foreach ($files as $file) 
  533. if ($file != '.' && $file != '..') $this->rcopy("$src/$file", "$dst/$file"); 
  534. else if (file_exists($src)) { 
  535. copy(str_replace('/', DS, $src), str_replace('/', DS, $dst)); 
  536. function recordDefaultUserField() { 
  537.  
  538. $modelUF=WYSIJA::get("user_field", "model"); 
  539. $arrayInsert=array( 
  540. array('name'=>__('First name', WYSIJA), 'column_name'=>'firstname', 'error_message'=>__('Please enter first name', WYSIJA)),  
  541. array('name'=>__('Last name', WYSIJA), 'column_name'=>'lastname', 'error_message'=>__('Please enter last name', WYSIJA))); 
  542. foreach($arrayInsert as $insert) { 
  543. $modelUF->insert($insert); 
  544. $modelUF->reset(); 
  545.  
  546.  
  547.  
  548. function defaultSettings(&$values) { 
  549.  
  550. /** get the user data for the admin */ 
  551. //$datauser=wp_get_current_user(); 
  552. $current_user=WYSIJA::wp_get_userdata(); 
  553.  
  554. $values['replyto_name'] = $values['from_name'] = $current_user->user_login; 
  555. $values['emails_notified'] = $current_user->user_email; 
  556. $values['replyto_email'] = $values['from_email'] = 'info@' . WJ_Utils::get_domain(); 
  557.  
  558.  
  559. function createPage(&$values) { 
  560.  
  561. /** get the user data for the admin */ 
  562. $my_post = array( 
  563. 'post_status' => 'publish',  
  564. 'post_type' => 'wysijap',  
  565. 'post_author' => 1,  
  566. 'post_content' => '[wysija_page]',  
  567. 'post_title' => __('Subscription confirmation', WYSIJA),  
  568. 'post_name' => 'subscriptions'); 
  569.  
  570. //check if the post already exists? 
  571. $helpersWPPOSTS=WYSIJA::get('wp_posts', 'model'); 
  572. $postss=$helpersWPPOSTS->get_posts(array('post_type'=>'wysijap')); 
  573. $postid=false; 
  574. if($postss) { 
  575. if(isset($postss[0]['post_content']) && strpos($postss[0]['post_content'], '[wysija_page]')!==false) { 
  576. $postid=$postss[0]['ID']; 
  577.  
  578. if(!$postid) { 
  579. remove_all_actions('pre_post_update'); 
  580. remove_all_actions('save_post'); 
  581. remove_all_actions('wp_insert_post'); 
  582. $values['confirm_email_link']=wp_insert_post( $my_post ); 
  583. flush_rewrite_rules(); 
  584. }else $values['confirm_email_link']=$postid; 
  585.  
  586.  
  587.  
  588.  
  589. function testNLplugins() { 
  590. $importHelp=WYSIJA::get('plugins_import', 'helper'); 
  591. $importHelp->testPlugins(); 
  592.  
  593. function create_default_subscription_form() { 
  594. // form engine 
  595. $helper_form_engine = WYSIJA::get('form_engine', 'helper'); 
  596.  
  597. // set default data 
  598. $helper_form_engine->set_data(); 
  599.  
  600. // create form in database 
  601. $model_forms = WYSIJA::get('forms', 'model'); 
  602. $model_forms->reset(); 
  603.  
  604. // get form id back because it's required to generate the html form 
  605. $form_id = $model_forms->insert(array('name' => __('Subscribe to our Newsletter', WYSIJA))); 
  606.  
  607. if((int)$form_id > 0) { 
  608. // set form engine data 
  609. $helper_form_engine->set_data(array_merge($helper_form_engine->get_data(), array('form_id' => (int)$form_id))); 
  610.  
  611. // update form in database 
  612. $model_forms->reset(); 
  613. $model_forms->update(array('data' => $helper_form_engine->get_encoded('data')), array('form_id' => $form_id));