protected function initialize() { if (BUILD_DATABASE === TRUE) { $sql_filepath = 'assets/plugins/' . strtolower($this->page_type) . '/assets/sql/build_plugin_tables.sql'; // If custom DB tables are required for the plugin, build them here if (file_exists($sql_filepath) and is_readable($sql_filepath)) { $sql = Utilities::load_file($sql_filepath); try { $this->db->query($sql); } catch (Exception $e) { ECMS_Error::log_exception($e); } } } // Add custom actions for the plugin or allow overwrite of core actions $this->access_points = array_merge($this->access_points, $this->register_custom_actions()); }
/** * Creates the database tables necessary for the CMS to function * * @param array $menuPages The menu configuration array * @return void */ public static function build_database() { // Loads necessary MySQL to build and populate the database $file_array = array(); $var_arr = array(); $file_array[] = CMS_PATH . 'core/resources/sql/build_database.sql'; $file_array[] = CMS_PATH . 'core/resources/sql/build_table_pages.sql'; $file_array[] = CMS_PATH . 'core/resources/sql/build_table_entries.sql'; $file_array[] = CMS_PATH . 'core/resources/sql/build_table_categories.sql'; $file_array[] = CMS_PATH . 'core/resources/sql/build_table_entry_categories.sql'; $file_array[] = CMS_PATH . 'core/resources/sql/build_table_featured.sql'; $file_array[] = CMS_PATH . 'core/resources/sql/build_table_users.sql'; $file_array[] = CMS_PATH . 'core/resources/sql/build_table_comments.sql'; // If an admin is initializing the ECMS, create his or her account if (DEV_PASS !== '') { $filepath = CMS_PATH . 'core/resources/sql/insert_users_entry.sql'; // Create a salted hash of the password $password_hash = AdminUtilities::createSaltedHash(DEV_PASS); // Assign variables needed to properly parse the file $var_arr = array($filepath => array('display' => DEV_DISPLAY_NAME, 'username' => DEV_USER_NAME, 'email' => DEV_EMAIL, 'vcode' => sha1(uniqid(time(), TRUE)), 'clearance' => DEV_CLEARANCE, 'password' => $password_hash)); // Add the file to the array $file_array[] = $filepath; } // Load the files $sql = Utilities::load_file($file_array, $var_arr); // Execute the loaded queries try { $dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME; $db = new PDO($dsn, DB_USER, DB_PASS); $db->query($sql); } catch (Exception $e) { ECMS_Error::log_exception($e); } }
private function _send_verification_email($to, $vcode) { // Generate the From: field data if (isset($_SESSION['user'])) { $from = $_SESSION['user']['name'] . ' <' . $_SESSION['user']['email'] . '>'; } else { ECMS_Error::log_exception(new Exception('You must be logged in to do that.')); } // Create a boundary string to separate the email parts $mime_boundary = '_x' . sha1(time()) . 'x'; // Create the email subject $subject = '[' . SITE_NAME . '] An Account Has Been Created for You!'; // Generate headers for the email $headers = <<<MESSAGE From: {$from} MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="==PHP-alt{$mime_boundary}" MESSAGE; // Email location $filepath = CMS_PATH . 'core/resources/email/verification.email'; // Variables for the email $var_arr = array('mime_boundary' => $mime_boundary, 'vcode' => $vcode); // Load the message $message = Utilities::load_file($filepath, $var_arr); return mail($to, $subject, $message, $headers); }
private function _send_comment_notification($comment) { // Generate the From: field data $from = SITE_NAME . ' <' . SITE_CONTACT_EMAIL . '>'; // Create a boundary string to separate the email parts $mime_boundary = '_x' . sha1(time()) . 'x'; // Load entry data $this->get_entry_by_id($comment->entry_id); if (is_object($this->entries[0])) { // Create the email subject $subject = '[' . SITE_NAME . '] New Comment on "' . $this->entries[0]->title . '"'; // Load the page data to get the slug $page = $this->get_page_data_by_id($this->entries[0]->page_id); $entry_link = SITE_URL . $page->page_slug . '/' . $this->entries[0]->slug; $comment_link = $entry_link . '#comment-' . $comment->comment_id; } else { throw new Exception("Something went wrong loading entry data!"); } // Generate headers for the email $headers = "From: {$from}\nMIME-Version: 1.0\n" . "Content-Type: multipart/alternative;\n" . ' boundary="==PHP-alt' . $mime_boundary . '"'; // Email location $filepath = CMS_PATH . 'core/resources/email/comment-notification.email'; // Variables for the email $var_arr = array('mime_boundary' => $mime_boundary, 'commenter' => $comment->name, 'comment' => $comment->comment, 'comment_link' => $comment_link, 'entry_link' => $entry_link, 'entry_title' => $this->entries[0]->title); // Load the message $template_message = Utilities::load_file($filepath, $var_arr); // Load comment subscribers $subscribers = $this->get_comment_subscribers($comment->entry_id); // Loop through subscribers and send the email foreach ($subscribers as $subscriber) { $to = $subscriber->name . ' <' . $subscriber->email . '>'; // Generate an unsubscribe link for each $unsubscribe_link = SITE_URL . 'comments/notifications/' . $comment->entry_id . '/' . Utilities::strtohex($subscriber->email); // Insert the custom unsubscribe link into the message $replace_pairs = array('{unsubscribe_link}' => $unsubscribe_link); $message = strtr($template_message, $replace_pairs); mail($to, $subject, $message, $headers); } }