/** * Renders the view. * * @return string (X)HTML * * @global array The paths of system files and folders. * @global array The configuration of the plugins. * @global array The localization of the core. * @global array The localization of the plugins. */ public function render() { global $pth, $plugin_cf, $tx, $plugin_tx; $phpVersion = '5.3.0'; $ptx = $plugin_tx['advancedform']; $imgdir = $pth['folder']['plugins'] . 'advancedform/images/'; $ok = tag('img src="' . $imgdir . 'ok.png" alt="ok"'); $warn = tag('img src="' . $imgdir . 'warn.png" alt="warning"'); $fail = tag('img src="' . $imgdir . 'fail.png" alt="failure"'); $o = tag('hr') . '<h4>' . $ptx['syscheck_title'] . '</h4>' . (version_compare(PHP_VERSION, $phpVersion) >= 0 ? $ok : $fail) . ' ' . sprintf($ptx['syscheck_phpversion'], $phpVersion) . tag('br') . tag('br') . PHP_EOL; foreach (array('ctype', 'mbstring', 'pcre', 'session', 'spl') as $ext) { $o .= (extension_loaded($ext) ? $ok : $fail) . ' ' . sprintf($ptx['syscheck_extension'], $ext) . tag('br') . PHP_EOL; } $o .= tag('br') . (strtoupper($tx['meta']['codepage']) == 'UTF-8' ? $ok : $warn) . ' ' . $ptx['syscheck_encoding'] . tag('br') . PHP_EOL; $o .= (!get_magic_quotes_runtime() ? $ok : $warn) . ' ' . $ptx['syscheck_magic_quotes'] . tag('br') . PHP_EOL; $filename = $pth['folder']['plugins'] . 'jquery/jquery.inc.php'; $o .= (file_exists($filename) ? $ok : $fail) . ' ' . $ptx['syscheck_jquery'] . tag('br') . PHP_EOL; $filename = $pth['folder']['plugins'] . $plugin_cf['advancedform']['captcha_plugin'] . '/captcha.php'; $o .= (file_exists($filename) ? $ok : $warn) . ' ' . $ptx['syscheck_captcha_plugin'] . tag('br') . tag('br') . PHP_EOL; foreach (array('config/', 'css/', 'languages/') as $folder) { $folders[] = $pth['folder']['plugins'] . 'advancedform/' . $folder; } $folders[] = Data::folder(); foreach ($folders as $folder) { $o .= (is_writable($folder) ? $ok : $warn) . ' ' . sprintf($ptx['syscheck_writable'], $folder) . tag('br') . PHP_EOL; } return $o; }
/** * Creates the form template. * * @return void * * @throws \InvalidArgumentException * * @todo Replace e() with Exceptions. */ public function execute() { $form = Data::fetchForm($this->id); if (isset($form)) { $filename = Data::folder() . $this->id . '.tpl'; if (!file_put_contents($filename, $this->renderTemplate($form))) { e('cntsave', 'file', $filename); } $filename = Data::folder() . 'css/' . $this->id . '.css'; if (!file_put_contents($filename, $this->renderCSS($form))) { e('cntsave', 'file', $filename); } } else { throw new \InvalidArgumentException(); } }
/** * Main plugin call. * * @param string $id A form ID. * * @return string (X)HTML. * * @global array The configuration of the plugins. * @global array The localization of the plugins. * @global string The script name. * @global string The (X)HTML fragment containing error messages. * @global array The paths of system files and folders. */ public static function main($id) { global $plugin_cf, $plugin_tx, $sn, $e, $pth; $pcf = $plugin_cf['advancedform']; $ptx = $plugin_tx['advancedform']; $fn = $pth['folder']['plugins'] . $pcf['captcha_plugin'] . '/captcha.php'; if (file_exists($fn)) { include_once $fn; } else { e('cntopen', 'file', $fn); } $hooks = Data::folder() . $id . '.inc' . ($pcf['php_extension'] ? '.php' : ''); if (file_exists($hooks)) { include $hooks; } $form = Data::fetchForm($id); if (!isset($form)) { $e .= '<li>' . sprintf($ptx['error_form_missing'], $id) . '</li>' . PHP_EOL; return ''; } if (isset($_POST['advfrm']) && $_POST['advfrm'] == $id) { $validator = new FormValidator($form); if (($res = $validator->validate()) === true) { if ($form->isStored()) { self::appendCsv($id); } if (!self::mail($form, false)) { return self::formView($form); } if (function_exists('advfrm_custom_thanks_page')) { self::fields($fields); $thanks = advfrm_custom_thanks_page($id, $fields); } if (empty($thanks)) { $thanks = $form->getThanksPage(); } if (!empty($thanks)) { if (!self::mail($form, true)) { return self::formView($form); } header('Location: ' . $sn . '?' . $thanks); // FIXME: exit()? } else { $view = MailView::make($form, false, true); return $view->render(); } } else { return $res . self::formView($form); } } return self::formView($form); }
/** * Returns the view of a form by instatiating the template. * * @return string (X)HTML. * * @global string The (X)HTML fragment for insertion into the HEAD element. * @global array The configuration of the plugins. */ protected function renderTemplate() { global $hjs, $plugin_cf; $fn = Data::folder() . 'css/' . $this->form->getName() . '.css'; if (file_exists($fn)) { $hjs .= tag('link rel="stylesheet" href="' . $fn . '" type="text/css"') . PHP_EOL; } $fn = Data::folder() . 'js/' . $this->form->getName() . '.js'; if (file_exists($fn)) { $hjs .= '<script type="text/javascript" src="' . $fn . '"></script>' . PHP_EOL; } $fn = Data::folder() . $this->form->getName() . '.tpl' . ($plugin_cf['advancedform']['php_extension'] ? '.php' : ''); $advfrm_script = file_get_contents($fn); foreach ($this->form->getFields() as $field) { $field = Field::make($field); $fieldView = new FieldView($this->form->getName(), $field); $advfrm_script = str_replace('<?field ' . $field->getName() . '?>', $fieldView->render(), $advfrm_script); } extract($GLOBALS); ob_start(); eval('?>' . $advfrm_script); return ob_get_clean(); }
/** * Returns the body of the mail. * * @param bool $html Whether to return (X)HTML. * * @return string * * @global array The configuration of the core. */ protected function getBody($html) { global $cf; $o = ''; if ($html) { if ($cf['xhtml']['endtags'] == 'true') { $o .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional' . '//EN"' . ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . PHP_EOL . '<html xmlns="http://www.w3.org/1999/xhtml">' . PHP_EOL; } else { $o .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional' . '//EN"' . ' "http://www.w3.org/TR/html4/loose.dtd">' . PHP_EOL . '<html>' . PHP_EOL; } $o .= '<head>' . PHP_EOL . '<style type="text/css">' . PHP_EOL; $o .= $this->getMailCSS($this->pluginFolder . 'css/stylesheet.css'); $fn = Data::folder() . 'css/' . $this->form->getName() . '.css'; if (file_exists($fn)) { $o .= $this->getMailCSS($fn); } $o .= '</style>' . PHP_EOL . '</head>' . PHP_EOL . '<body>' . PHP_EOL; } $view = MailView::make($this->form, !$this->isConfirmation, $html); $o .= $view->render(); if ($html) { $o .= '</body>' . PHP_EOL . '</html>' . PHP_EOL; } return $o; }