Exemple #1
0
 static function uninstallCategorize()
 {
     if ($confirm) {
         SQL::current()->query("DROP TABLE __categorize");
         SQL::current()->delete("post_attributes", "name = 'category_id'");
     }
 }
Exemple #2
0
function add_signature_updated_at()
{
    if (!SQL::current()->query("SELECT signature FROM __comments")) {
        echo __("Adding signature column to comments table...", "comments") . test(SQL::current()->query("ALTER TABLE __comments ADD  signature VARCHAR(32) DEFAULT '' AFTER status"));
    }
    if (!SQL::current()->query("SELECT updated_at FROM __comments")) {
        echo __("Adding updated_at column to comments table...", "comments") . test(SQL::current()->query("ALTER TABLE __comments ADD  updated_at DATETIME DEFAULT '0000-00-00 00:00:00' AFTER created_at"));
    }
}
Exemple #3
0
 static function __uninstall($confirm)
 {
     if ($confirm) {
         foreach (Attachment::find() as $attachment) {
             @unlink(uploaded($attachment->path, true));
         }
         SQL::current()->query("DROP TABLE __attachments");
     }
 }
Exemple #4
0
 /**
  * Bind the default datasource to another named connection
  * @param  string $name The datasource name
  * @return bool       `true` if correctly changed
  */
 public static function defaultTo($name)
 {
     if (isset(self::$connections[$name])) {
         self::$current = $name;
         return true;
     } else {
         return false;
     }
 }
Exemple #5
0
 static function __uninstall($confirm)
 {
     if ($confirm) {
         SQL::current()->query("DROP TABLE __milestones");
         SQL::current()->query("DROP TABLE __tickets");
         SQL::current()->query("DROP TABLE __revisions");
     }
     Group::remove_permission("add_milestone");
     Group::remove_permission("add_ticket");
     Group::remove_permission("add_revision");
     Group::remove_permission("edit_milestone");
     Group::remove_permission("edit_ticket");
     Group::remove_permission("edit_revision");
     Group::remove_permission("edit_own_ticket");
     Group::remove_permission("edit_own_revision");
     Group::remove_permission("delete_milestone");
     Group::remove_permission("delete_ticket");
     Group::remove_permission("delete_revision");
     Group::remove_permission("delete_own_ticket");
     Group::remove_permission("delete_own_revision");
     Group::remove_permission("code_in_revisions");
 }
Exemple #6
0
 static function __uninstall($confirm)
 {
     if ($confirm) {
         SQL::current()->query("DROP TABLE __types");
         SQL::current()->query("DROP TABLE __extensions");
         SQL::current()->query("DROP TABLE __notes");
     }
     Group::remove_permission("add_type");
     Group::remove_permission("add_extension");
     Group::remove_permission("add_note");
     Group::remove_permission("edit_type");
     Group::remove_permission("edit_extension");
     Group::remove_permission("edit_note");
     Group::remove_permission("edit_own_extension");
     Group::remove_permission("edit_own_note");
     Group::remove_permission("delete_type");
     Group::remove_permission("delete_extension");
     Group::remove_permission("delete_note");
     Group::remove_permission("delete_own_extension");
     Group::remove_permission("delete_own_note");
     Group::remove_permission("code_in_notes");
 }
Exemple #7
0
 /**
  * Function: notify
  * Emails everyone that wants to be notified for a new comment
  *
  * Parameters:
  *     $author - The new comment author
  *     $body - The new comment message
  *     $post - The new comment post ID
  */
 static function notify($author, $body, $post)
 {
     $post = new Post($post);
     $emails = SQL::current()->select("comments", "author_email", array("notify" => 1, "post_id" => $post->id))->fetchAll();
     $list = array();
     foreach ($emails as $email) {
         $list[] = $email["author_email"];
     }
     $config = Config::current();
     $to = implode(", ", $list);
     $subject = $config->name . __("New Comment");
     $message = __("There is a new comment at ") . $post->url() . "\n Poster: " . fix($author) . "\n Message: " . fix($body);
     $headers = "From:" . $config->email . "\r\n" . "Reply-To:" . $config->email . "\r\n" . "X-Mailer: PHP/" . phpversion();
     $sent = email($to, $subject, $message, $headers);
 }
Exemple #8
0
    $sql = SQL::current(true);
    if ($sql->connect(true) and !empty($config->url) and $sql->count("users")) {
        error(__("Already Installed"), __("Chyrp is already correctly installed and configured."));
    }
}
if (!is_writable(MAIN_DIR) and !file_exists(MAIN_DIR . "/.htaccess") or file_exists(MAIN_DIR . "/.htaccess") and !is_writable(MAIN_DIR . "/.htaccess") and !$htaccess_has_chyrp) {
    $errors[] = _f("STOP! Before you go any further, you must create a .htaccess file in Chyrp's install directory and put this in it:\n<pre>%s</pre>", array(fix($htaccess)));
}
if (!is_writable(INCLUDES_DIR)) {
    $errors[] = __("Chyrp's includes directory is not writable by the server. In order for the installer to generate your configuration files, please CHMOD or CHOWN it so that Chyrp can write to it.");
}
if (!empty($_POST)) {
    if ($_POST['adapter'] == "sqlite" and !@is_writable(dirname($_POST['database']))) {
        $errors[] = __("SQLite database file could not be created. Please make sure your server has write permissions to the location for the database.");
    } else {
        $sql = SQL::current(array("host" => $_POST['host'], "username" => $_POST['username'], "password" => $_POST['password'], "database" => $_POST['database'], "prefix" => $_POST['prefix'], "adapter" => $_POST['adapter']));
        if (!$sql->connect(true)) {
            $errors[] = _f("Could not connect to the specified database:\n<pre>%s</pre>", array($sql->error));
        } elseif ($_POST['adapter'] == "pgsql") {
            new Query($sql, "CREATE FUNCTION year(timestamp) RETURNS double precision AS 'select extract(year from \$1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT");
            new Query($sql, "CREATE FUNCTION month(timestamp) RETURNS double precision AS 'select extract(month from \$1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT");
            new Query($sql, "CREATE FUNCTION day(timestamp) RETURNS double precision AS 'select extract(day from \$1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT");
            new Query($sql, "CREATE FUNCTION hour(timestamp) RETURNS double precision AS 'select extract(hour from \$1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT");
            new Query($sql, "CREATE FUNCTION minute(timestamp) RETURNS double precision AS 'select extract(minute from \$1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT");
            new Query($sql, "CREATE FUNCTION second(timestamp) RETURNS double precision AS 'select extract(second from \$1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT");
        }
    }
    if (empty($_POST['name'])) {
        $errors[] = __("Please enter a name for your website.");
    }
    if (!isset($_POST['timezone'])) {
Exemple #9
0
 /**
  * Function: safecol
  * Wraps a column in proper escaping if it is a SQL keyword.
  *
  * Doesn't check every keyword, just the common/sensible ones.
  *
  * ...Okay, it only does two. "order" and "group".
  *
  * Parameters:
  *     $name - Name of the column.
  */
 public static function safecol($name)
 {
     $lower = strtolower($name);
     if ($lower === "order" or $lower === "group") {
         return SQL::current()->adapter == "mysql" ? "`" . $name . "`" : '"' . $name . '"';
     } else {
         return $name;
     }
 }
Exemple #10
0
#     <Feather>
require_once INCLUDES_DIR . "/interface/Feather.php";
# Set the error handler to exit on error if this is being run from the tester.
if (TESTER) {
    set_error_handler("error_panicker");
}
# Redirect to the installer if there is no config.
if (!file_exists(INCLUDES_DIR . "/config.yaml.php")) {
    redirect("install.php");
}
# Start the timer that keeps track of Chyrp's load time.
timer_start();
# Load the config settings.
$config = Config::current();
# Prepare the SQL interface.
$sql = SQL::current();
# Set the timezone for date(), etc.
set_timezone($config->timezone);
# Initialize connection to SQL server.
$sql->connect();
# Sanitize all input depending on magic_quotes_gpc's enabled status.
sanitize_input($_GET);
sanitize_input($_POST);
sanitize_input($_COOKIE);
sanitize_input($_REQUEST);
# Begin the session.
session();
# Set the locale for gettext.
set_locale($config->locale);
# Load the translation engine.
load_translator("chyrp", INCLUDES_DIR . "/locale/" . $config->locale . ".mo");
Exemple #11
0
 /**
  * Function: delete
  * Deletes a given object. Calls the @delete_(model)@ trigger with the objects ID.
  *
  * Parameters:
  *     $model - The model name.
  *     $id - The ID of the object to delete.
  */
 protected static function destroy($model, $id)
 {
     $model = strtolower($model);
     if (Trigger::current()->exists("delete_" . $model)) {
         Trigger::current()->call("delete_" . $model, new $model($id));
     }
     SQL::current()->delete(pluralize($model), array("id" => $id));
 }
Exemple #12
0
/**
 * Function: keywords
 * Handle keyword-searching.
 *
 * Parameters:
 *     $query - The query to parse.
 *     $plain - WHERE syntax to search for non-keyword queries.
 *     $table - If specified, the keywords will be checked against this table's columns for validity.
 *
 * Returns:
 *     An array containing the "WHERE" queries and the corresponding parameters.
 */
function keywords($query, $plain, $table = null)
{
    if (!trim($query)) {
        return array(array(), array());
    }
    $search = array();
    $matches = array();
    $where = array();
    $params = array();
    if ($table) {
        $columns = SQL::current()->select($table)->fetch();
    }
    $queries = explode(" ", $query);
    foreach ($queries as $query) {
        if (!preg_match("/([a-z0-9_]+):(.+)/", $query)) {
            $search[] = $query;
        } else {
            $matches[] = $query;
        }
    }
    $times = array("year", "month", "day", "hour", "minute", "second");
    foreach ($matches as $match) {
        list($test, $equals, ) = explode(":", $match);
        if ($equals[0] == '"') {
            if (substr($equals, -1) != '"') {
                foreach ($search as $index => $part) {
                    $equals .= " " . $part;
                    unset($search[$index]);
                    if (substr($part, -1) == '"') {
                        break;
                    }
                }
            }
            $equals = ltrim(trim($equals, '"'), '"');
        }
        if (in_array($test, $times)) {
            if ($equals == "today") {
                $where["created_at like"] = date("%Y-m-d %");
            } elseif ($equals == "yesterday") {
                $where["created_at like"] = date("%Y-m-d %", now("-1 day"));
            } elseif ($equals == "tomorrow") {
                error(__("Error"), "Unfortunately our flux capacitor is currently having issues. Try again yesterday.");
            } else {
                $where[strtoupper($test) . "(created_at)"] = $equals;
            }
        } elseif ($test == "author") {
            $user = new User(array("login" => $equals));
            if ($user->no_results and $equals == "me") {
                $where["user_id"] = Visitor::current()->id;
            } else {
                $where["user_id"] = $user->id;
            }
        } elseif ($test == "group") {
            $group = new Group(array("name" => $equals));
            $test = "group_id";
            $equals = $group->no_results ? 0 : $group->id;
        } else {
            $where[$test] = $equals;
        }
    }
    if ($table) {
        foreach ($where as $col => $val) {
            if (!isset($columns[$col])) {
                if ($table == "posts") {
                    $where["post_attributes.name"] = $col;
                    $where["post_attributes.value like"] = "%" . $val . "%";
                }
                unset($where[$col]);
            }
        }
    }
    if (!empty($search)) {
        $where[] = $plain;
        $params[":query"] = "%" . join(" ", $search) . "%";
    }
    $keywords = array($where, $params);
    Trigger::current()->filter($keywords, "keyword_search", $query, $plain);
    return $keywords;
}
Exemple #13
0
 public function post_latest_comment_attr($attr, $post)
 {
     if (isset($this->latest_comments)) {
         return fallback($this->latest_comments[$post->id], null);
     }
     $times = SQL::current()->select("comments", array("MAX(created_at) AS latest", "post_id"), array("status not" => "spam", "status != 'denied' OR (\n                                                                             (\n                                                                                 user_id != 0 AND\n                                                                                 user_id = :visitor_id\n                                                                             ) OR (\n                                                                                 id IN " . self::visitor_comments() . "\n                                                                             )\n                                                                         )"), null, array(":visitor_id" => Visitor::current()->id), null, null, "post_id");
     foreach ($times->fetchAll() as $row) {
         $this->latest_comments[$row["post_id"]] = $row["latest"];
     }
     return fallback($this->latest_comments[$post->id], null);
 }
Exemple #14
0
 function delete_posts($aggregate_name)
 {
     $sql = SQL::current();
     $attrs = $sql->select("post_attributes", "post_id", array("name" => "aggregate", "value" => $aggregate_name))->fetchAll();
     foreach ($attrs as $attr) {
         Post::delete($attr["post_id"]);
     }
 }
Exemple #15
0
/**
 * Function: update_user_password_column
 * Updates the @password@ column on the "users" table to have a length of 60.
 *
 * Versions: 2.0rc3 => 2.0
 */
function update_user_password_column()
{
    $sql = SQL::current();
    if (!($column = $sql->query("SHOW COLUMNS FROM __users WHERE Field = 'password'"))) {
        return;
    }
    if ($column->fetchObject()->Type == "varchar(60)") {
        return;
    }
    echo __("Updating `password` column on `users` table...") . "\n";
    echo " - " . __("Backing up `users` table...") . test($backup = $sql->select("users"));
    if (!$backup) {
        return;
    }
    $backups = $backup->fetchAll();
    echo " - " . __("Dropping `users` table...") . test($drop = $sql->query("DROP TABLE __users"));
    if (!$drop) {
        return;
    }
    echo " - " . __("Creating `users` table...") . test($create = $sql->query("CREATE TABLE IF NOT EXISTS `__users` (\n                                            `id` int(11) NOT NULL AUTO_INCREMENT,\n                                            `login` varchar(64) DEFAULT '',\n                                            `password` varchar(60) DEFAULT NULL,\n                                            `full_name` varchar(250) DEFAULT '',\n                                            `email` varchar(128) DEFAULT '',\n                                            `website` varchar(128) DEFAULT '',\n                                            `group_id` int(11) DEFAULT '0',\n                                            `joined_at` datetime DEFAULT '0000-00-00 00:00:00',\n                                            PRIMARY KEY (`id`),\n                                            UNIQUE KEY `login` (`login`)\n                                        ) DEFAULT CHARSET=utf8"));
    if (!$create) {
        echo " -" . test(false, _f("Backup written to %s.", array("./_users.bak.txt")));
        return file_put_contents("./_users.bak.txt", var_export($backups, true));
    }
    foreach ($backups as $backup) {
        echo " - " . _f("Restoring user #%d...", array($backup["id"])) . test($insert = $sql->insert("users", $backup), _f("Backup written to %s.", array("./_users.bak.txt")));
        if (!$insert) {
            return file_put_contents("./_users.bak.txt", var_export($backups, true));
        }
    }
    echo " -" . test(true);
}
Exemple #16
0
 /**
  * Function: safecol
  * Wraps a column in proper escaping if it is a SQL keyword.
  *
  * Doesn't check every keyword, just the common/sensible ones.
  *
  * ...Okay, it only does two. "order" and "group".
  *
  * Parameters:
  *     $name - Name of the column.
  */
 public static function safecol($name)
 {
     return preg_replace("/(([^a-zA-Z0-9_]|^)(order|group)([^a-zA-Z0-9_]|\n\$))/i", SQL::current()->adapter == "mysql" ? "\\2`\\3`\n\\4" : '\\2"\\3"\\4', $name);
 }
Exemple #17
0
 static function user_count($user_id)
 {
     $count = SQL::current()->count("comments", array("user_id" => $user_id));
     return $count;
 }
Exemple #18
0
 public function ajax_tag_post()
 {
     if (empty($_POST['name']) or empty($_POST['post'])) {
         exit("{}");
     }
     $sql = SQL::current();
     $post = new Post($_POST['post']);
     $tag = $_POST['name'];
     if (!$post->editable()) {
         exit("{}");
     }
     $tags = $sql->select("post_attributes", "value", array("name" => "tags", "post_id" => $post->id));
     if ($tags and $value = $tags->fetchColumn()) {
         $tags = YAML::load($value);
     } else {
         $tags = array();
     }
     $tags[$tag] = sanitize($tag);
     $sql->replace("post_attributes", array("post_id", "name"), array("name" => "tags", "value" => YAML::dump($tags), "post_id" => $post->id));
     exit("{ url: \"" . url("tag/" . $tags[$tag], MainController::current()) . "\", tag: \"" . $_POST['name'] . "\" }");
 }
Exemple #19
0
 /**
  * Function: open_tickets
  * Returns the total number of open tickets in the milestone.
  */
 public function open_tickets()
 {
     return SQL::current()->count("tickets", array("milestone_id" => $this->id, "state" => array("new", "open")));
 }
Exemple #20
0
 /**
  * Function: archive_list
  * Generates an array of all of the archives, by month.
  *
  * Parameters:
  *     $limit - Amount of months to list
  *     $order_by - What to sort it by
  *     $order - "asc" or "desc"
  *
  * Returns:
  *     The array. Each entry as "month", "year", and "url" values, stored as an array.
  */
 public function archives_list($limit = 0, $order_by = "created_at", $order = "desc")
 {
     if (isset($this->archives_list["{$limit},{$order_by},{$order}"])) {
         return $this->archives_list["{$limit},{$order_by},{$order}"];
     }
     $sql = SQL::current();
     $dates = $sql->select("posts", array("DISTINCT YEAR(created_at) AS year", "MONTH(created_at) AS month", "created_at AS created_at", "COUNT(id) AS posts"), array("status" => "public", Post::feathers()), $order_by . " " . strtoupper($order), array(), $limit == 0 ? null : $limit, null, array("created_at"));
     $archives = array();
     $grouped = array();
     while ($date = $dates->fetchObject()) {
         if (isset($grouped[$date->month . " " . $date->year])) {
             $archives[$grouped[$date->month . " " . $date->year]]["count"]++;
         } else {
             $grouped[$date->month . " " . $date->year] = count($archives);
             $archives[] = array("month" => $date->month, "year" => $date->year, "when" => $date->created_at, "url" => url("archive/" . when("Y/m/", $date->created_at)), "count" => $date->posts);
         }
     }
     return $this->archives_list["{$limit},{$order_by},{$order}"] = $archives;
 }
Exemple #21
0
 /**
  * Function: display
  * Display the page.
  *
  * If "posts" is in the context and the visitor requested a feed, they will be served.
  *
  * Parameters:
  *     $file - The theme file to display.
  *     $context - The context for the file.
  *     $title - The title for the page.
  */
 public function display($file, $context = array(), $title = "")
 {
     if (is_array($file)) {
         for ($i = 0; $i < count($file); $i++) {
             $check = ($file[$i][0] == "/" or preg_match("/[a-zA-Z]:\\\\/", $file[$i])) ? $file[$i] : THEME_DIR . "/" . $file[$i];
             if (file_exists($check . ".twig") or $i + 1 == count($file)) {
                 return $this->display($file[$i], $context, $title);
             }
         }
     }
     $this->displayed = true;
     $route = Route::current();
     $trigger = Trigger::current();
     # Serve feeds.
     if ($this->feed) {
         if ($trigger->exists($route->action . "_feed")) {
             return $trigger->call($route->action . "_feed", $context);
         }
         if (isset($context["posts"])) {
             return $this->feed($context["posts"]);
         }
     }
     $this->context = array_merge($context, $this->context);
     $visitor = Visitor::current();
     $config = Config::current();
     $theme = Theme::current();
     $theme->title = $title;
     $this->context["theme"] = $theme;
     $this->context["flash"] = Flash::current();
     $this->context["trigger"] = $trigger;
     $this->context["modules"] = Modules::$instances;
     $this->context["feathers"] = Feathers::$instances;
     $this->context["title"] = $title;
     $this->context["site"] = $config;
     $this->context["visitor"] = $visitor;
     $this->context["route"] = Route::current();
     $this->context["hide_admin"] = isset($_COOKIE["hide_admin"]);
     $this->context["version"] = CHYRP_VERSION;
     $this->context["now"] = time();
     $this->context["debug"] = DEBUG;
     $this->context["POST"] = $_POST;
     $this->context["GET"] = $_GET;
     $this->context["sql_queries"] =& SQL::current()->queries;
     $this->context["visitor"]->logged_in = logged_in();
     $this->context["enabled_modules"] = array();
     foreach ($config->enabled_modules as $module) {
         $this->context["enabled_modules"][$module] = true;
     }
     $context["enabled_feathers"] = array();
     foreach ($config->enabled_feathers as $feather) {
         $this->context["enabled_feathers"][$feather] = true;
     }
     $this->context["sql_debug"] =& SQL::current()->debug;
     $trigger->filter($this->context, array("main_context", "main_context_" . str_replace("/", "_", $file)));
     $file = ($file[0] == "/" or preg_match("/[a-zA-Z]:\\\\/", $file)) ? $file : THEME_DIR . "/" . $file;
     if (!file_exists($file . ".twig")) {
         error(__("Template Missing"), _f("Couldn't load template: <code>%s</code>", array($file . ".twig")));
     }
     try {
         return $this->twig->getTemplate($file . ".twig")->display($this->context);
     } catch (Exception $e) {
         $prettify = preg_replace("/([^:]+): (.+)/", "\\1: <code>\\2</code>", $e->getMessage());
         $trace = debug_backtrace();
         $twig = array("file" => $e->filename, "line" => $e->lineno);
         array_unshift($trace, $twig);
         error(__("Error"), $prettify, $trace);
     }
 }
Exemple #22
0
 /**
  * Function: update
  * Updates the user with the given login, password, full name, e-mail, website, and <Group> ID.
  *
  * Passes all of the arguments to the update_user trigger.
  *
  * Parameters:
  *     $login - The new Login to set.
  *     $password - The new Password to set, already encoded.
  *     $full_name - The new Full Name to set.
  *     $email - The new E-Mail to set.
  *     $website - The new Website to set.
  *     $group_id - The new <Group> to set.
  *
  * See Also:
  *     <add>
  */
 public function update($login = null, $password = null, $email = null, $full_name = null, $website = null, $group_id = null, $joined_at = null)
 {
     if ($this->no_results) {
         return false;
     }
     $sql = SQL::current();
     $trigger = Trigger::current();
     $old = clone $this;
     foreach (array("login", "password", "email", "full_name", "website", "group_id", "joined_at") as $attr) {
         $this->{$attr} = ${$attr} = ${$attr} !== null ? ${$attr} : $this->{$attr};
     }
     $new_values = array("login" => strip_tags($login), "password" => $password, "email" => strip_tags($email), "full_name" => strip_tags($full_name), "website" => strip_tags($website), "group_id" => $group_id, "joined_at" => $joined_at);
     $trigger->filter($new_values, "before_update_user");
     $sql->update("users", array("id" => $this->id), $new_values);
     $trigger->call("update_user", $this, $old);
 }
Exemple #23
0
 /**
  * Function: check_url
  * Checks if a given clean URL is already being used as another post's URL.
  *
  * Parameters:
  *     $clean - The clean URL to check.
  *
  * Returns:
  *     The unique version of the passed clean URL. If it's not used, it's the same as $clean. If it is, a number is appended.
  */
 static function check_url($clean)
 {
     $count = SQL::current()->count("posts", array("clean" => $clean));
     return (!$count or empty($clean)) ? $clean : $clean . "-" . ($count + 1);
 }
Exemple #24
0
 /**
  * Function: view
  * Updates the view count of the topic.
  */
 public function view()
 {
     $this->view_count++;
     SQL::current()->update("topics", array("id" => $this->id), array("view_count" => $this->view_count));
 }
Exemple #25
0
 /**
  * Function: display
  * Renders the page.
  *
  * Parameters:
  *     $action - The template file to display, in (theme dir)/pages.
  *     $context - Context for the template.
  *     $title - The title for the page. Defaults to a camlelization of the action, e.g. foo_bar -> Foo Bar.
  */
 public function display($action, $context = array(), $title = "")
 {
     $this->displayed = true;
     fallback($title, camelize($action, true));
     $this->context = array_merge($context, $this->context);
     $trigger = Trigger::current();
     $trigger->filter($this->context, array("admin_context", "admin_context_" . str_replace("/", "_", $action)));
     # Are there any extension-added pages?
     foreach (array("write" => array(), "manage" => array("import", "export"), "settings" => array(), "extend" => array("modules", "feathers", "themes")) as $main_nav => $val) {
         ${$main_nav} = $val;
         $trigger->filter(${$main_nav}, $main_nav . "_pages");
     }
     $visitor = Visitor::current();
     $route = Route::current();
     $this->context["theme"] = Theme::current();
     $this->context["flash"] = Flash::current();
     $this->context["trigger"] = $trigger;
     $this->context["title"] = $title;
     $this->context["site"] = Config::current();
     $this->context["visitor"] = $visitor;
     $this->context["logged_in"] = logged_in();
     $this->context["route"] = $route;
     $this->context["hide_admin"] = isset($_SESSION["hide_admin"]);
     $this->context["now"] = time();
     $this->context["version"] = CHYRP_VERSION;
     $this->context["debug"] = DEBUG;
     $this->context["feathers"] = Feathers::$instances;
     $this->context["modules"] = Modules::$instances;
     $this->context["admin_theme"] = $this->admin_theme;
     $this->context["theme_url"] = Config::current()->chyrp_url . "/admin/themes/" . $this->admin_theme;
     $this->context["POST"] = $_POST;
     $this->context["GET"] = $_GET;
     $this->context["navigation"] = array();
     $show = array("write" => array($visitor->group->can("add_draft", "add_post", "add_page")), "manage" => array($visitor->group->can("view_own_draft", "view_draft", "edit_own_draft", "edit_own_post", "edit_post", "delete_own_draft", "delete_own_post", "delete_post", "add_page", "edit_page", "delete_page", "add_user", "edit_user", "delete_user", "add_group", "edit_group", "delete_group")), "settings" => array($visitor->group->can("change_settings")), "extend" => array($visitor->group->can("toggle_extensions")));
     foreach ($show as $name => &$arr) {
         $trigger->filter($arr, $name . "_nav_show");
     }
     $this->context["navigation"]["write"] = array("title" => __("Write"), "show" => in_array(true, $show["write"]), "selected" => in_array($action, $write) or match("/^write_/", $action));
     $this->context["navigation"]["manage"] = array("title" => __("Manage"), "show" => in_array(true, $show["manage"]), "selected" => in_array($action, $manage) or match(array("/^manage_/", "/^edit_/", "/^delete_/", "/^new_/"), $action));
     $this->context["navigation"]["settings"] = array("title" => __("Settings"), "show" => in_array(true, $show["settings"]), "selected" => in_array($action, $settings) or match("/_settings\$/", $action));
     $this->context["navigation"]["extend"] = array("title" => __("Extend"), "show" => in_array(true, $show["extend"]), "selected" => in_array($action, $extend));
     $this->subnav_context($route->action);
     $trigger->filter($this->context["selected"], "nav_selected");
     $this->context["sql_debug"] = SQL::current()->debug;
     $file = MAIN_DIR . "/admin/themes/%s/pages/" . $action . ".twig";
     $template = file_exists(sprintf($file, $this->admin_theme)) ? sprintf($file, $this->admin_theme) : sprintf($file, "default");
     $config = Config::current();
     if (!file_exists($template)) {
         foreach (array(MODULES_DIR => $config->enabled_modules, FEATHERS_DIR => $config->enabled_feathers) as $path => $try) {
             foreach ($try as $extension) {
                 if (file_exists($path . "/" . $extension . "/pages/admin/" . $action . ".twig")) {
                     $template = $path . "/" . $extension . "/pages/admin/" . $action . ".twig";
                 }
             }
         }
         if (!file_exists($template)) {
             error(__("Template Missing"), _f("Couldn't load template: <code>%s</code>", array($template)));
         }
     }
     # Try the theme first
     try {
         $this->theme->getTemplate($template)->display($this->context);
     } catch (Exception $t) {
         # Fallback to the default
         try {
             $this->default->getTemplate($template)->display($this->context);
         } catch (Exception $e) {
             $prettify = preg_replace("/([^:]+): (.+)/", "\\1: <code>\\2</code>", $e->getMessage());
             $trace = debug_backtrace();
             $twig = array("file" => $e->filename, "line" => $e->lineno);
             array_unshift($trace, $twig);
             error(__("Error"), $prettify, $trace);
         }
     }
 }
Exemple #26
0
 static function exists($attachment_id)
 {
     return SQL::current()->count("attachments", array("id" => $attachment_id)) == 1;
 }
Exemple #27
0
 public function main_index($main)
 {
     $ids = array();
     # this mammoth query allows searching for posts on the main page in 1 query
     $record = SQL::current()->query("SELECT __posts.id FROM __posts\n                        LEFT JOIN __post_attributes\n                            ON (__posts.id = __post_attributes.post_id\n                            AND __post_attributes.name = 'category_id')\n                        LEFT JOIN __categorize\n                            ON (__post_attributes.value = __categorize.id\n                            AND __post_attributes.name = 'category_id')\n                        WHERE (__categorize.show_on_home = 1\n                            OR __post_attributes.value IS NULL\n                            OR __post_attributes.value = 0)\n                        GROUP BY __posts.id\n                    ");
     foreach ($record->fetchAll() as $entry) {
         $ids[] = $entry['id'];
     }
     if (empty($ids)) {
         return false;
     }
     $posts = new Paginator(Post::find(array("placeholders" => true, "where" => array("id" => $ids))), Config::current()->posts_per_page);
     if (empty($posts)) {
         return false;
     }
     $main->display(array("pages/index"), array("posts" => $posts));
     return true;
 }
Exemple #28
0
 static function delete_user($user)
 {
     SQL::current()->update("likes", array("user_id" => $user->id), array("user_id" => 0));
 }
Exemple #29
0
function fix_quotes()
{
    $sql = SQL::current();
    if (!($tags = $sql->select("post_attributes", array("post_id", "value"), array("name" => "tags")))) {
        return;
    }
    foreach ($tags->fetchAll() as $attr) {
        $sql->replace("post_attributes", array("post_id" => $attr["post_id"], "name" => "tags", "value" => YAML::dump(YAML::load($attr["value"]))));
    }
}
Exemple #30
0
function add_comment_notify_field()
{
    if (!SQL::current()->query("SELECT notify FROM __comments")) {
        echo __("Adding notify column to comments table...", "comments") . test(SQL::current()->query("ALTER TABLE __comments ADD notify INTEGER DEFAULT 0 AFTER parent_id"));
    }
}