示例#1
0
 public function getOption($option)
 {
     $dbh = new CandyDB();
     $sth = $dbh->prepare('SELECT option_value FROM ' . DB_PREFIX . 'options WHERE option_key = "' . $option . '"');
     $sth->execute();
     return stripslashes($sth->fetchColumn());
 }
示例#2
0
 public function listPages()
 {
     $dbh = new CandyDB();
     $sth = $dbh->prepare('SELECT * FROM ' . DB_PREFIX . 'pages');
     $sth->execute();
     return $sth->fetchAll(PDO::FETCH_CLASS);
 }
示例#3
0
 public static function savePlugins($enabled)
 {
     $json = mysql_escape_string(json_encode($enabled));
     $dbh = new CandyDB();
     $sth = $dbh->prepare('UPDATE ' . DB_PREFIX . 'options SET option_value="' . $json . '" WHERE option_key="enabled_plugins"');
     $sth->execute();
     self::installPlugin($enabled);
 }
示例#4
0
 public static function getColors()
 {
     $dbh = new CandyDB();
     $sth = $dbh->prepare('SELECT option_value FROM ' . DB_PREFIX . 'options WHERE option_key = "colors"');
     $sth->execute();
     $colors = $sth->fetchColumn();
     $colors = json_decode($colors);
     return $colors;
 }
示例#5
0
 public static function signin($username, $password)
 {
     $salt = SALT;
     $user = $username;
     $pass = sha1($password . $salt);
     $dbh = new CandyDB();
     $sth = $dbh->prepare('SELECT name FROM ' . DB_PREFIX . 'users WHERE username = "******" AND password = "******"');
     $sth->execute();
     $result = $sth->fetchColumn();
     $return = $result != false ? true : false;
     return $return;
 }
示例#6
0
 public static function enabledPlugins()
 {
     $dbh = new CandyDB();
     $sth = $dbh->prepare('SELECT option_value FROM ' . DB_PREFIX . 'options WHERE option_key = "enabled_plugins"');
     $sth->execute();
     $plugins = $sth->fetchColumn();
     if ($plugins != false) {
         $plugins = json_decode($plugins);
         return $plugins;
     } else {
         return false;
     }
 }
示例#7
0
 public static function updateSettings($site_title, $theme, $homepage, $site_url)
 {
     $data = array('site_title' => $site_title, 'theme' => $theme, 'homepage' => $homepage, 'site_url' => $site_url);
     $dbh = new CandyDB();
     foreach ($data as $key => $value) {
         $sth = $dbh->prepare('UPDATE ' . DB_PREFIX . 'options SET option_value="' . $value . '" WHERE option_key="' . $key . '"');
         $sth->execute();
     }
     $plugins = Plugins::enabledPlugins();
     foreach ($plugins as $plugin) {
         if (method_exists($plugin, 'saveSettings')) {
             $plugin::saveSettings();
         }
     }
 }
示例#8
0
 public static function getAdminFields($page)
 {
     $dbh = new CandyDB();
     $sth = $dbh->prepare("SELECT * FROM " . DB_PREFIX . "fields WHERE post_id={$page}");
     $sth->execute();
     $fields = $sth->fetchAll(PDO::FETCH_CLASS);
     $return = '';
     foreach ($fields as $value) {
         $input = self::getInput($value->field_type, $value->field_name, $value->field_value);
         $return .= '<li>';
         $return .= '<h3>' . $value->field_title . '</h3>';
         $return .= '<p>' . $value->field_desc . '</p>';
         $return .= $input;
         $return .= '</li>';
     }
     echo $return;
 }
示例#9
0
function theNav($class = 'nav', $active = 'active-page')
{
    global $Candy;
    $html = '<ul class="' . $class . '">';
    $pages = $Candy['options']->getOption('nav');
    $pages = json_decode($pages);
    $path = URL_PATH;
    $curpage = isset($_GET['page']) ? $_GET['page'] : $Candy['options']->getOption('homepage');
    $info = $Candy['pages']->loadPage($curpage);
    $homepage = $Candy['options']->getOption('homepage');
    foreach ($pages as $page) {
        $dbh = new CandyDB();
        $sth = $dbh->prepare('SELECT page_title, rewrite FROM ' . DB_PREFIX . 'pages WHERE page_id = ' . $page->id);
        $sth->execute();
        $pages_info = $sth->fetchAll(PDO::FETCH_CLASS);
        if (!empty($info)) {
            $html .= $page->id == $info[0]->page_id ? '<li class="' . $active . '">' : '<li>';
        } else {
            $html .= '<li>';
        }
        $html .= $homepage == $pages_info[0]->rewrite ? '<a href="' . $path . '" title="' . $pages_info[0]->page_title . '">' . $pages_info[0]->page_title . '</a>' : '<a href="' . $path . $pages_info[0]->rewrite . '">' . $pages_info[0]->page_title . '</a>';
        if (isset($page->children)) {
            $html .= '<ul class="candy-dropdown">';
            foreach ($page->children as $child) {
                $sth = $dbh->prepare('SELECT page_title, rewrite FROM ' . DB_PREFIX . 'pages WHERE page_id = ' . $child->id);
                $sth->execute();
                $child_info = $sth->fetchAll(PDO::FETCH_CLASS);
                $html .= '<li>';
                $html .= '<a href="' . $path . $child_info[0]->rewrite . '">' . $child_info[0]->page_title . '</a>';
                $html .= '</li>';
            }
            $html .= '</ul>';
        }
        $html .= '</li>';
    }
    $html .= '</ul>';
    echo $html;
}
示例#10
0
 public static function getPostTitle($permalink)
 {
     $dbh = new CandyDB();
     $sth = $dbh->prepare('SELECT post_title FROM ' . DB_PREFIX . 'posts WHERE permalink="' . $permalink . '"');
     $sth->execute();
     return $sth->fetchColumn();
 }
示例#11
0
 public static function deletePage($id)
 {
     $dbh = new CandyDB();
     $sth = $dbh->prepare('DELETE FROM ' . DB_PREFIX . 'pages WHERE page_id="' . $id . '"');
     $sth->execute();
 }
示例#12
0
 public static function resetPassword($email)
 {
     $password = "";
     $possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
     $maxlength = 10;
     $i = 0;
     while ($i < $maxlength) {
         $char = substr($possible, mt_rand(0, $maxlength - 1), 1);
         if (!strstr($password, $char)) {
             $password .= $char;
             $i++;
         }
     }
     $rand = sha1($password . SALT);
     $dbh = new CandyDB();
     $dbh->exec("UPDATE " . DB_PREFIX . "users SET password='******' WHERE email='{$email}'");
     mail($email, 'Your New CandyCMS Password', "Your new password is\n\n{$password}\n\nPlease change this after logging in.");
 }