Edit file File name : class.A2OptDrupal.php Content :<?php class A2OptDrupal extends A2OptBase { public $app; public $db_connection; public $db_host; public $db_prefix; public $db_name; public $db_user; public $db_passwd; public $memcached_socket; public $db_port; public $is_cagefs; public $dr_ver; public function __construct($app) { global $cpanel; $this->exit_on_error = false; $this->db_connection = new MySQLi(); $this->db_name = ''; $this->db_host = ''; $this->db_prefix = ''; $this->db_user = ''; $this->db_port = '3306'; $this->db_password = ''; $this->app = $app; $this->path = $app->path; $this->domain = $app->domain; $this->dr_ver = $app->dr_ver; $this->type = 'Drupal'; $this->db_connect(); if (is_null($this->db_connection)) { $this->dr_log('Drupal Unable to connect to DB ' . $this->path); $this->log_action('Unable to connect to DB ' . $this->path); $this->type = null; return; } $this->title = $this->check_app_title($this->get_variable('site_name'), $app); $this->set_instance(); $this->is_cagefs = $this->is_cagefs(); $this->exit_on_error = true; } public function dr_log($data) { // @fixme this was in for debugging as $this->log_action is not functioning while in this class. $this->home is also not available so we cannot put the logs in the user's directory without hard-coding. // if support has flagged this account for logging, then we check if a file exists for today, create if not /* $log = $this->home . '/.a2opt/a2opt-' . date('mdy') . '.log'; touch($log); // append supplied data to the log file $handle = fopen($log, 'a') or die('Cannot open file: ' . $log); fwrite($handle, date('Y-m-d H:i:s') . ':::A2OptDrupal8:::' . $data . "\n"); */ return; } public function enable_file_cache() {//Drupal $this->dr_log('Drupal enable_file_cache'); $this->check_app_path(); $key_prefix = rand(); chdir($this->path); $res = shell_exec('echo y | drush dl filecache'); unset($res); $res = shell_exec('echo y | drush en filecache'); unset($res); //`cache-clear all` is deprecated for Drupal 8 and later. Please use the `cache-rebuild` command instead. $res = shell_exec('drush cc all'); unset($res); if ($default_cache_class = $this->get_setting('cache_default_class')) { if ($default_cache_class != 'MemCacheDrupal') { $this->set_setting('cache_default_class', 'DrupalFileCache'); } } else { $this->set_setting('cache_default_class', 'DrupalFileCache'); } $this->set_setting('cache_backends', 'sites/all/modules/filecache/filecache.inc', true, true); $t = preg_replace('/[^A-Za-z0-9\-]/', '', $this->title); $this->set_setting('filecache_directory', "{$this->home}/drupalcache-{$t}"); $this->set_setting('cache_class_cache_form', 'DrupalDatabaseCache'); $this->set_setting('page_cache_without_database', true); $this->set_setting('page_cache_invoke_hooks', false); } public function enable_boost() {//Drupal $this->check_app_path(); $key_prefix = rand(); chdir($this->path); $res = shell_exec('echo y | drush dl boost'); unset($res); $res = shell_exec('echo y | drush en boost'); unset($res); $res = shell_exec('drush cc all'); unset($res); $this->set_variable('cache', 0);//must disable core file cache $this->set_variable('boost_enabled_application/rss', true); $this->set_variable('boost_enabled_application/rss+xml', true); $this->set_variable('boost_enabled_application/xml', true); $this->set_variable('boost_enabled_text/html', true); $this->set_variable('boost_enabled_text/javascript', true); $this->set_variable('boost_enabled_text/xml', true); } public function enable_core_file_cache() { $this->set_variable('cache', 1); $this->set_variable('cache_lifetime', '3600'); $this->set_variable('page_compression', 1); } public function is_core_file_cache_enabled() { return (bool) ($this->get_variable('cache') == 1); } public function disable_core_file_cache() { $this->set_variable('cache', 0); $this->set_variable('page_compression', 0); } public function enable_core_block_cache() { $this->set_variable('block_cache', 1); $this->set_variable('cache_lifetime', '3600'); } public function is_core_block_cache_enabled() { return (bool) ($this->get_variable('block_cache') == 1); } public function disable_core_block_cache() { $this->set_variable('block_cache', 0); } public function enable_core_css_cache() { $this->set_variable('preprocess_css', 1); } public function is_core_css_cache_enabled() { return (bool) ($this->get_variable('preprocess_css') == 1); } public function disable_core_css_cache() { $this->set_variable('preprocess_css', 0); } public function enable_core_js_cache() { $this->set_variable('preprocess_js', 1); } public function is_core_js_cache_enabled() { return (bool) ($this->get_variable('preprocess_js') == 1); } public function disable_core_js_cache() { $this->set_variable('preprocess_js', 0); } public function is_logging_minimized() { $limit = $this->get_variable('dblog_row_limit'); return !($limit === false || intval($limit) > 100); } public function enable_db_maintenance() { chdir($this->path); $res = shell_exec('echo y | drush dl db_maintenance'); unset($res); $res = shell_exec('echo y | drush en db_maintenance'); unset($res); $res = shell_exec('drush cc all'); unset($res); $this->set_variable('db_maintenance_all_tables', 1); $this->set_variable('db_maintenance_log', 0); $this->set_variable('db_maintenance_cron_frequency', '2592000'); } public function disable_db_maintenance() { chdir($this->path); $res = shell_exec('echo y | drush dis db_maintenance'); unset($res); $res = shell_exec('drush cc all'); unset($res); return true; } public function is_db_maintenance() { return ($this->get_variable('db_maintenance_all_tables') === 1 || ( is_array($this->get_variable("db_maintenance_table_list_{$this->db_name}")) && count($this->get_variable("db_maintenance_table_list_{$this->db_name}")) > 0 ) ) && $this->get_variable('db_maintenance_log') === 0 && $this->get_variable('db_maintenance_cron_frequency') == '2592000' && $this->is_module_enabled('db_maintenance'); } public function shell_exec($command, $y = false) { if ($this->is_cagefs) { return shell_exec("/bin/cagefs_enter.proxied $command"); } else { return shell_exec("$command"); } } public function exec($command, $y = false) { $res = false; if ($this->is_cagefs) { exec("/bin/cagefs_enter.proxied $command", $res); } else { exec("$command", $res); } return $res; } public function enable_memcached($socket = '') {//Drupal $this->check_app_path(); chdir($this->path); $res = $this->exec('drush dl memcache -y'); unset($res); $res = $this->exec('drush en memcache -y'); unset($res); $res = shell_exec('drush cc all'); unset($res); if (isset($this->instance->socket)) { $this->memcached_socket = $this->instance->socket; } elseif (isset($socket) && $socket != '') { $this->memcached_socket = $socket; } else { die('no Memcached socket given'); } $this->set_setting('cache_backends', 'sites/all/modules/memcache/memcache.inc', true, true); $this->set_setting('memcache_stampede_protection', false); $this->set_setting('cache_default_class', 'MemCacheDrupal'); $this->set_setting('cache_class_cache_form', 'DrupalDatabaseCache'); $this->set_setting('page_cache_without_database', true); $this->set_setting('page_cache_invoke_hooks', false); $this->set_setting('memcache_servers', array("{$this->memcached_socket}" => 'default')); $this->set_setting('memcache_key_prefix', rand()); $this->set_setting('memcache_key_hash_algorithm', 'sha1'); $this->set_setting('memcache_extension', 'Memcached');//set preferred library $this->app->swiftcache->memcached->enabled = true; } public function disable_memcached() {//Drupal $this->check_app_path(); $res = shell_exec('echo y | drush dis memcache'); $this->remove_setting('cache_backends'); $this->remove_setting('memcache_stampede_protection'); $this->remove_setting('cache_default_class'); $this->remove_setting('cache_class_cache_form'); $this->remove_setting('page_cache_without_database'); $this->remove_setting('page_cache_invoke_hooks'); $this->remove_setting('memcache_servers'); $this->remove_setting('memcache_key_prefix'); $this->remove_setting('memcache_key_hash_algorithm'); $this->app->swiftcache->memcached->enabled = false; } public function is_memcached_enabled() { $cache_default_class = $this->get_setting('cache_default_class'); return ( $cache_default_class == 'MemCacheDrupal' && in_array( 'sites/all/modules/memcache/memcache.inc', $this->get_setting('cache_backends', true) ) ); } public function get_optimizations() { $thisclass = $this; return array( 'Core File Cache' => array( 'optimized' => $this->is_core_file_cache_enabled(), 'description' => "Cache pages for anonymous users. To learn more: visit the <a href=\"https://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/drupal2/optimizing-drupal\" target='_blank'>Knowledge Base</a>", 'enable' => function () use (&$thisclass) { $thisclass->enable_core_file_cache(); }, 'disable' => function () use (&$thisclass) { $thisclass->disable_core_file_cache(); }, 'type' => 'core' ), 'Core Block Cache' => array( 'optimized' => $this->is_core_block_cache_enabled(), 'description' => "Cache Drupal blocks. To learn more: visit the <a href=\"https://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/drupal2/optimizing-drupal\" target='_blank'>Knowledge Base</a>", 'enable' => function () use (&$thisclass) { $thisclass->enable_core_block_cache(); }, 'disable' => function () use (&$thisclass) { $thisclass->disable_core_block_cache(); }, 'type' => 'core' ), 'Aggregate CSS' => array( 'optimized' => $this->is_core_css_cache_enabled(), 'description' => "Combine and compress CSS files. To learn more: visit the <a href=\"https://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/drupal2/optimizing-drupal\" target='_blank'>Knowledge Base</a>", 'enable' => function () use (&$thisclass) { $thisclass->enable_core_css_cache(); }, 'disable' => function () use (&$thisclass) { $thisclass->disable_core_css_cache(); }, 'type' => 'core' ), 'Aggregate JavaScript' => array( 'optimized' => $this->is_core_js_cache_enabled(), 'description' => "Combine and compress JavaScript files. To learn more: visit the <a href=\"https://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/drupal2/optimizing-drupal\" target='_blank'>Knowledge Base</a>", 'enable' => function () use (&$thisclass) { $thisclass->enable_core_js_cache(); }, 'disable' => function () use (&$thisclass) { $thisclass->disable_core_js_cache(); }, 'type' => 'core' ), 'Minimize Database Logging' => array( 'optimized' => $this->is_logging_minimized(), 'description' => "Log only the last 100 messages to the database. To learn more: visit the <a href=\"https://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/drupal2/optimizing-drupal\" target='_blank'>Knowledge Base</a>", 'enable' => function () use (&$thisclass) { $thisclass->set_variable('dblog_row_limit', '100'); }, 'disable' => function () use (&$thisclass) { $thisclass->set_variable('dblog_row_limit', '1000'); }, 'type' => 'core' ), 'Clear Cache Weekly' => array( 'optimized' => $this->is_cache_cron(), 'description' => 'A weekly cron that will clear the drupal cache to keep the database clean and quick', 'enable' => function () use (&$thisclass) { $thisclass->enable_cache_cron(); }, 'disable' => function () use (&$thisclass) { $thisclass->disable_cache_cron(); }, 'type' => 'cron' ), 'Update Drupal Daily' => array( 'optimized' => $this->is_update_cron(), 'description' => 'Disable the Update Manager module and use a daily cron to automatically update drupal and its modules instead.', 'enable' => function () use (&$thisclass) { $thisclass->disable_update_manager(); $thisclass->enable_update_cron(); }, 'disable' => function () use (&$thisclass) { $thisclass->enable_update_manager(); $thisclass->disable_update_cron(); }, 'type' => 'cron' ), 'DB Maintenance Module' => array( 'optimized' => $this->is_db_maintenance(), 'description' => 'DB maintenance optimizes selected tables in the database during regular intervals.', 'enable' => function () use (&$thisclass) { $thisclass->enable_db_maintenance(); }, 'disable' => function () use (&$thisclass) { $thisclass->disable_db_maintenance(); }, 'type' => 'module' ), 'Memcached' => array( 'optimized' => $this->is_memcached_enabled(), 'description' => 'Caching of database query results in memory', 'controller' => 'Memcached', 'advanced' => true ), 'TurboCache' => array( 'optimized' => $this->app->swiftcache->turbocache->enabled, 'description' => 'Static file caching by the web Server', 'controller' => 'TurboCache', 'advanced' => true ) ); } public function get_percent_optimized() { $optimizations = $this->get_optimizations(); $count = 0; foreach ($optimizations as $name => $optimization) { if ($optimization['optimized']) { $count ++; } } return round(($count / (count($optimizations))) * 100); } public function set_optimization($name, $optimize) { $optimizations = $this->get_optimizations(); if (array_key_exists($name, $optimizations)) { if (isset($optimizations[$name]['type'])) { switch ($optimize) { case true: if (isset($optimizations[$name]['enable'])) { $optimizations[$name]['enable'](); } break; case false: if (isset($optimizations[$name]['disable'])) { $optimizations[$name]['disable'](); } break; } } } return $this->get_optimizations(); } public function optimize() { $optimizations = $this->get_optimizations(); foreach ($optimizations as $name => $optimization) { if (!$optimization['optimized']) { $this->set_optimization($name, true); } } } public function get_dblog_row_limit() { if (!($limit = $this->get_variable('dblog_row_limit'))) { $limit = 0; } return $limit; } public function disable_cache_cron() { if ($this->is_cache_cron()) {//set the cron if missing $this->disable_cron(rtrim($this->app->path, '/') . '/drush cache-clear all'); } return !$this->is_cache_cron(); } public function enable_cache_cron() { if (!$this->is_cache_cron()) {//set the cron if missing //set up random times to execute the cron once per week $hour = rand(0, 23); $minute = rand(0, 59); $weekday = rand(0, 6); if ($this->is_cagefs()) { $command = "/usr/bin/cagefs_enter.proxied cd {$this->app->path}; {$this->app->path}/drush cache-clear all >/dev/null 2>&1"; } else { $command = "cd {$this->app->path}; {$this->app->path}/drush cache-clear all >/dev/null 2>&1"; } $this->enable_cron($minute, $hour, '*', '*', $weekday, $command); } return $this->is_cache_cron(); } public function get_cache_cron_id() { $path = trim("{$this->app->path}", '/'); return $this->get_cron_id("{$path}/drush cache-clear"); } public function is_cache_cron() { return !($this->get_cache_cron_id() === false); } public function enable_drush() { if (!file_exists("{$this->path}/drush")) { copy('/opt/a2-optimized/drupal/drush', "{$this->path}/drush"); } if (!is_executable("{$this->path}/drush")) { chmod("{$this->path}/drush", 0770); } } public function disable_update_manager() { chdir($this->path); $this->enable_drush(); if ($this->is_cagefs()) { $command = '/usr/bin/cagefs_enter.proxied echo y | drush dis update'; } else { $command = 'echo y | drush dis update'; } $res = shell_exec($command); return true; } public function enable_update_manager() { chdir($this->path); $this->enable_drush(); if ($this->is_cagefs()) { $command = '/usr/bin/cagefs_enter.proxied echo y | drush en update'; } else { $command = 'echo y | drush en update'; } $res = shell_exec($command); return true; } public function disable_update_cron() { global $cpanel; if ($this->is_update_cron()) {//set the cron if missing if ($this->is_cpanel()) { $count = $this->get_update_cron_id(); //set the cron in cPanel $res = $cpanel->api2( 'Cron', 'remove_line', array( 'line' => $count, ) ); unset($res); } else { $cmd = str_replace('/', "\/", preg_quote(rtrim($this->app->path, '/') . '/drush up')); shell_exec("crontab -l | sed 's/[^\\n\\r]*{$cmd}[^\\n\\r]*//' | crontab"); } } return !$this->is_update_cron(); } public function enable_update_cron() { global $cpanel; if (!$this->is_update_cron()) {//set the cron if missing //set up random times to execute the cron once per week $hour = rand(0, 23); $minute = rand(0, 59); if ($this->is_cagefs()) { $command = "/usr/bin/cagefs_enter.proxied cd {$this->app->path}; {$this->app->path}/drush up >/dev/null 2>&1"; } else { $command = "cd {$this->app->path}; {$this->app->path}/drush up >/dev/null 2>&1"; } if ($this->is_cpanel()) { //set the cron in cPanel $res = $cpanel->api2( 'Cron', 'add_line', array( 'command' => $command, 'day' => '*', 'hour' => "{$hour}", 'minute' => "{$minute}", 'month' => '*', 'weekday' => '*', ) ); unset($res); } else { $cron = "{$minute} {$hour} * * * $command"; shell_exec("(crontab -l ; echo '{$cron}') | sort | uniq | crontab"); } } return $this->is_update_cron(); } public function get_update_cron_id() { global $cpanel; $path = trim("{$this->app->path}", '/'); if ($this->is_cpanel()) { $res = $cpanel->api2('Cron', 'listcron'); $res = $res['cpanelresult']['data']; foreach ($res as $i => $line) { $command = $line['command']; if (!(strpos($command, "{$path}/drush up") === false)) { return $line['count']; } } } else { exec('crontab -l', $res); foreach ($res as $i => $line) { if ( !(strpos($line, "{$path}/drush up") === false)) { return $i; } } } return false; } public function is_update_cron() { return !($this->get_update_cron_id() === false); } /* The previous regex in db_connect was choking when db credentials had a '*' in it (passwords) orig: if(preg_match("/(\\\$databases[^*]*\\);)/msiU", $settings, $matches )){ */ public function db_connect() { $this->dr_log('db_connect 7 : ' . $this->path); if (file_exists("{$this->path}/sites/default/settings.php")) { $settings = file_get_contents("{$this->path}/sites/default/settings.php"); if (preg_match('/^\s*(\$databases.+\)\;)$/Uims', $settings, $matches )) { $db_array = array_pop($matches); $this->parse_db($db_array); $this->dr_log('Connecting to the Drupal database host: ' . $this->db_host . ', user: ' . $this->db_user); try { $this->db_connection = new MySQLi($this->db_host, $this->db_user, $this->db_passwd, $this->db_name); if ($this->db_connection->connect_errno) { $this->error('Could not connect to the Drupal database: ' . $this->db_connection->connect_error); $this->db_connection = null; } } catch (Exception $e) { $this->error('Could not connect to the Drupal database'); $this->db_connection = null; } } else { $this->error('Invalid Drupal database settings'); $this->db_connection = null; } } else { $this->error('Invalid Drupal database settings'); $this->db_connection = null; } } public function parse_db($db_array) { /* * $databases = array ( 'default' => array ( 'default' => array ( 'database' => 'wp_drup749', 'username' => 'wp_drup749', 'password' => '(7ZS-PT4J9', 'host' => 'localhost', 'port' => '', 'driver' => 'mysql', 'prefix' => 'nup_', ), ), ); */ if (preg_match('/[\'"]database[\'"].*[\'"]([0-9a-zA-Z\$_]*)[\'"].*,/', $db_array, $db_match)) { $this->db_name = array_pop($db_match); } if (preg_match('/[\'"]username[\'"].*=>.*[\'"](.*)[\'"],/', $db_array, $db_match)) { $this->db_user = array_pop($db_match); } if (preg_match('/[\'"]password[\'"].*=>.*[\'"](.*)[\'"],/', $db_array, $db_match)) { $this->db_passwd = array_pop($db_match); } if (preg_match('/[\'"]host[\'"].*=>.*[\'"](.*)[\'"],/', $db_array, $db_match)) { $this->db_host = array_pop($db_match); } if (preg_match('/[\'"]prefix[\'"].*=>.*[\'"]([0-9a-zA-Z\$_]*)[\'"],/', $db_array, $db_match)) { $this->db_prefix = array_pop($db_match); } if (preg_match('/[\'"]prefix[\'"].*=>.*[\'"]([0-9]*)[\'"],/', $db_array, $db_match)) { $this->db_port = array_pop($db_match); } if (empty($this->db_port)) { $this->db_port = '3306'; } } public function get_table($name) { try { $pdo = new A2OptPDO($this->db_host, $this->db_user, $this->db_passwd, $this->db_name); } catch (PDOException $e) { $this->error('Could not connect to the database.'); return false; } $var = "{$this->db_prefix}{$name}"; $table = ''; $stmt = $pdo->prepare('SHOW Tables LIKE ?'); $stmt->execute(array($var)); if ($res = $stmt->fetchAll()) { $table = $res[0][0]; } else { $var = "%{$name}"; $stmt = $pdo->prepare('SHOW Tables LIKE ?'); $stmt->execute(array($var)); if ($res = $stmt->fetchAll()) { $table = $res[0][0]; } } return $table; } public function get_variable($name = 'site_name') { $this->dr_log('Drupal get_variable ' . $name . ' for ' . $this->path); $value = false; try { $pdo = new A2OptPDO($this->db_host, $this->db_user, $this->db_passwd, $this->db_name); } catch (PDOException $e) { $this->error('Could not connect to the database.'); $this->dr_log('Drupal get_variable could not connect to ' . $this->path); return false; } if ($this->dr_ver == 7) { $table_name = $this->get_table('variable'); } else { $table_name = $this->get_table('config'); } if (!$table_name) { $this->dr_log('Drupal get_variable no table ' . $this->path); return false; } $stmt = $pdo->prepare("select value from {$table_name} where name=?"); $stmt->execute(array($name)); if ($res = $stmt->fetchAll()) { $this->dr_log('Drupal get_variable result... ' . $this->path); return unserialize($res[0][0]); // This is not advisable in PHP7, readdress if cPanel moves to PHP7+ for it's runtime } return false; } public function get_setting($name, $array = false) { $value = false; $settings_file = "{$this->path}/sites/default/settings.php"; if (file_exists($settings_file)) { $settings = file_get_contents($settings_file); if (!$array) { if (!(preg_match('/\$conf\[[\'"]' . $name . '[\'"]\].*[\'"](.+)[\'"][ \t]*;/iU', $settings, $matches) === false)) { return $matches[1]; } } else { if (!(preg_match_all('/\$conf\[[\'"]' . $name . '[\'"]\].*[\'"](.+)[\'"][ \t]*;/iU', $settings, $matches) === false)) { array_shift($matches); $arr = array(); foreach ($matches as $key => $match) { $arr[] = $match[0]; } return $arr; } } return false; } return false; } public function set_setting($name, $value, $array = false, $append = false) { $settings_file = "{$this->path}/sites/default/settings.php"; if (file_exists($settings_file)) { $settings = file_get_contents($settings_file); if ($array === true) { $values = $this->get_setting($name, true); foreach ($values as $i => $v) { if ($v === $value) { return true; } } if ($append === true) { $this->append_setting($name, $value, true); } else { $this->replace_setting($name, $value, true); } } else { $this->replace_setting($name, $value); } } return false; } public function append_setting($name, $value, $array = false) { $settings_file = "{$this->path}/sites/default/settings.php"; if (file_exists($settings_file)) { $settings = file_get_contents($settings_file); if ($array === true) { $settings = "{$settings}\n\$conf['{$name}'][] = '{$value}';"; } else { if ($value === true) { $settings .= "\n\$conf['{$name}'] = true;"; } elseif ($value === false) { $settings .= "\n\$conf['{$name}'] = false;"; } elseif (is_array($value)) { $settings .= "\n\$conf['{$name}'] = " . var_export($value, true) . ';'; } else { $settings .= "\n\$conf['{$name}'] = '{$value}';"; } } $this->save_settings($settings); } } public function replace_setting($name, $value, $replace = '') { $settings_file = "{$this->path}/sites/default/settings.php"; if (file_exists($settings_file)) { $settings = file_get_contents($settings_file); switch ($replace) { case '': $this->remove_setting($name); $this->append_setting($name, $value, false); break; case 'all': $this->remove_setting($name); $this->append_setting($name, $value, true); break; default: $this->remove_setting($name, $value); $this->append_setting($name, $value, true); } } } public function save_settings($settings) { $settings_file = "{$this->path}/sites/default/settings.php"; if (file_exists($settings_file)) { chmod($settings_file, 0664); if (is_writable($settings_file) && $fp = fopen($settings_file, 'w')) { fwrite($fp, $settings); fclose($fp); } else { $this->error("{$settings_file} is not writable by the web server."); } } } public function remove_setting($name, $value = 'RemoveAll') { $settings_file = "{$this->path}/sites/default/settings.php"; if (file_exists($settings_file)) { $settings = file_get_contents($settings_file); switch ($value) { case 'RemoveAll': $preg = "[^;]*\\\$conf\[[\"']{$name}[\"'']\][^;]*;"; break; case true: $preg = "[^;]*\\\$conf\[[\"']{$name}[\"'']\].*true[^;]*;"; break; case false: $preg = "[^;]*\\\$conf\[[\"']{$name}[\"'']\].*false[^;]*;"; break; default: $preg = "[^;]*\\\$conf\[[\"']{$name}[\"'']\].*" . preg_quote($value) . '[^;]*;'; } $settings = preg_replace("/{$preg}/Uim", '', $settings); $this->save_settings($settings); } } public function set_variable($name = null, $value = null) { if (is_null($value) || is_null($name)) { return false; } $value = serialize($value); $table_name = $this->get_table('variable'); if (!$table_name) { return false; } try { $pdo = new A2OptPDO($this->db_host, $this->db_user, $this->db_passwd, $this->db_name); } catch (PDOException $e) { $this->error('Could not connect to the database.'); return false; } $stmt = $pdo->prepare("update {$table_name} set value=? where name=?"); $stmt->execute(array($value,$name)); if ($stmt->rowCount() == 1) { return true; } else { $stmt = $pdo->prepare("insert into {$table_name} set value=?, name=?"); $stmt->execute(array($value,$name)); if ($stmt->rowCount() == 1) { return true; } } return false; } public function is_module_enabled($name = '') { if ($name == '') { return false; } $table_name = $this->get_table('system'); if (!$table_name) { return false; } try { $pdo = new A2OptPDO($this->db_host, $this->db_user, $this->db_passwd, $this->db_name); } catch (PDOException $e) { $this->error('Could not connect to the database.'); return false; } $stmt = $pdo->prepare("SELECT name,status FROM {$table_name} WHERE type='module' AND status='1' and name=?;"); $stmt->execute(array($name)); return ($stmt->rowCount() == 1); } public function get_turbocache_defaults() { return array( 'reject_urls' => array( 'admin', 'login', 'register' ), 'reject_cookies' => array('SESS'), 'time' => '15 Minutes', 'ttl' => 900, 'enabled' => true ); } } Save