function time_ago_in_words($time)
{
    $from_time = strtotime($time);
    $to_time = strtotime(gmd());
    $distance_in_minutes = round(($to_time - $from_time) / 60);
    if ($distance_in_minutes < 0) {
        return (string) $distance_in_minutes . 'E';
    }
    if (between($distance_in_minutes, 0, 1)) {
        return '1 minute';
    } elseif (between($distance_in_minutes, 2, 44)) {
        return $distance_in_minutes . ' minutes';
    } elseif (between($distance_in_minutes, 45, 89)) {
        return '1 hour';
    } elseif (between($distance_in_minutes, 90, 1439)) {
        return round($distance_in_minutes / 60) . ' hours';
    } elseif (between($distance_in_minutes, 1440, 2879)) {
        return '1 day';
    } elseif (between($distance_in_minutes, 2880, 43199)) {
        return round($distance_in_minutes / 1440) . ' days';
    } elseif (between($distance_in_minutes, 43200, 86399)) {
        return '1 month';
    } elseif (between($distance_in_minutes, 86400, 525959)) {
        return round($distance_in_minutes / 43200) . ' months';
    } elseif ($distance_in_minutes > 525959) {
        return number_format(round($distance_in_minutes / 525960, 1), 1) . ' years';
    }
}
Example #2
0
function compact_time($datetime)
{
    $datetime = new DateTime($datetime);
    if ($datetime->format('M d, Y') == gmd('M d, Y')) {
        return $datetime->format('H:i');
    } else {
        return $datetime->format('M d');
    }
}
Example #3
0
<?php

render(false);
if (!empty(Request::$params->forum_post)) {
    $preview = true;
    $forum_post = ForumPost::blank(array_merge(request::$params->forum_post, array('creator_id' => User::$current->id)));
    $forum_post->created_at = gmd();
    render_partial("post", array('post' => $forum_post));
}
 /**
  * Check time column
  *
  * Called by save() and create(), checks if time $column
  * exists and automatically sets a value to it.
  */
 private function check_time_column($column, &$d)
 {
     if (!$this->column_exists($column)) {
         return;
     }
     $type = self::model_data()->table->get_type($column);
     if ($type == 'date' || $type == 'datetime' || $type == 'year' || $type == 'timestamp') {
         $d[] = $time = gmd();
     } elseif ($type == 'time') {
         $d[] = $time = gmd('H:i:s');
     } else {
         return;
     }
     $this->{$column} = $time;
     return true;
 }
Example #5
0
 function set_avatar($params)
 {
     $post = Post::find($params['post_id']);
     if (!$post->can_be_seen_by($this)) {
         $this->record_errors->add('access', "denied");
         return false;
     }
     // vde($params);
     if ($params['top'] < 0 or $params['top'] > 1 or $params['bottom'] < 0 or $params['bottom'] > 1 or $params['left'] < 0 or $params['left'] > 1 or $params['right'] < 0 or $params['right'] > 1 or $params['top'] >= $params['bottom'] or $params['left'] >= $params['right']) {
         $this->record_errors->add('parameter', "error");
         return false;
     }
     $tempfile_path = ROOT . "public/data/" . $this->id . ".avatar.jpg";
     $use_sample = $post->has_sample();
     if ($use_sample) {
         $image_path = $post->sample_path();
         $image_ext = "jpg";
         $size = $this->reduce_and_crop($post->sample_width, $post->sample_height, $params);
         # If we're cropping from a very small region in the sample, use the full
         # image instead, to get a higher quality image.
         if ($size['crop_bottom'] - $size['crop_top'] < CONFIG::avatar_max_height or $size['crop_right'] - $size['crop_left'] < CONFIG::avatar_max_width) {
             $use_sample = false;
         }
     }
     if (!$use_sample) {
         $image_path = $post->file_path();
         $image_ext = $post->file_ext;
         $size = $this->reduce_and_crop($post->width, $post->height, $params);
     }
     try {
         Danbooru::resize($image_ext, $image_path, $tempfile_path, $size, 95);
     } catch (Exception $x) {
         if (file_exists($tempfile_path)) {
             unlink($tempfile_path);
         }
         $this->record_errors->add("avatar", "couldn't be generated (" . $x->getMessage() . ")");
         return false;
     }
     rename($tempfile_path, $this->avatar_path());
     chmod($this->avatar_path(), 0775);
     $this->update_attributes(array('avatar_post_id' => $params['post_id'], 'avatar_top' => $params['top'], 'avatar_bottom' => $params['bottom'], 'avatar_left' => $params['left'], 'avatar_right' => $params['right'], 'avatar_width' => $size['width'], 'avatar_height' => $size['height'], 'avatar_timestamp' => gmd()));
     return true;
 }
Example #6
0
 function related()
 {
     if (gmd() > $this->cached_related_expires_on) {
         $length = ceil($this->post_count / 3);
         $length < 12 && ($length = 12);
         $length > 8760 && ($length = 8760);
         DB::update("tags SET cached_related = ?, cached_related_expires_on = ? WHERE id = ?", implode(",", array_flat($this->calculate_related($this->name))), gmd_math('add', 'T' . $length . 'H'), $this->id);
         $this->reload();
     }
     $related = explode(',', $this->cached_related);
     $i = 0;
     $groups = array();
     foreach ($related as $rel) {
         $group[] = $rel;
         if ($i & 1) {
             $groups[] = $group;
             $group = array();
         }
         $i++;
     }
     return $groups;
 }
Example #7
0
define('ROOT', str_replace('\\', '/', dirname(__FILE__)) . '/');
define('SYSROOT', ROOT . 'system/');
include ROOT . 'config/config.php';
include SYSROOT . 'config.php';
include SYSROOT . 'database/initialize.php';
include SYSROOT . 'load_functions.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    set_time_limit(0);
    $queries = array("CREATE TABLE IF NOT EXISTS `bans` (\n      `user_id` int(11) NOT NULL,\n      `reason` text NOT NULL,\n      `expires_at` datetime NULL,\n      `banned_by` int(11) NOT NULL,\n      `old_level` int(11) NOT NULL,\n      `delete_me` int(11) NOT NULL,\n      KEY `user_id` (`user_id`),\n      KEY `delete_me` (`delete_me`)\n    ) ENGINE=InnoDB DEFAULT CHARSET=utf8", "CREATE TABLE IF NOT EXISTS `comments` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `post_id` int(11) NOT NULL,\n      `user_id` int(11) NOT NULL,\n      `ip_addr` varchar(16) NOT NULL,\n      `created_at` datetime DEFAULT '0000-00-00 00:00:00',\n      `body` text NOT NULL,\n      `updated_at` datetime NULL,\n      PRIMARY KEY (`id`),\n      KEY `image_id` (`post_id`),\n      KEY `owner_ip` (`ip_addr`),\n      KEY `posted` (`created_at`),\n      KEY `fk_comments__user_id` (`user_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ", "CREATE TABLE IF NOT EXISTS `favorites` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `post_id` int(11) NOT NULL,\n      `user_id` int(11) NOT NULL,\n      `created_at` datetime DEFAULT '0000-00-00 00:00:00',\n      PRIMARY KEY (`id`),\n      UNIQUE KEY `image_id` (`post_id`,`user_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ", "CREATE TABLE IF NOT EXISTS `flagged_post_details` (\n      `created_at` datetime NULL,\n      `post_id` int(11) NOT NULL,\n      `user_id` int(11) NOT NULL,\n      `reason` varchar(512) NOT NULL,\n      `is_resolved` tinyint(1) NOT NULL DEFAULT '0',\n      KEY `post_id` (`post_id`),\n      KEY `fk_flag_post_details__user_id` (`user_id`)\n    ) ENGINE=InnoDB DEFAULT CHARSET=utf8", "CREATE TABLE IF NOT EXISTS `notes` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `created_at` DATETIME NULL,\n      `updated_at` DATETIME NULL,\n      `user_id` int(11) NOT NULL,\n      `x` int(11) NOT NULL,\n      `y` int(11) NOT NULL,\n      `width` int(11) NOT NULL,\n      `height` int(11) NOT NULL,\n      `ip_addr` varchar(64) NOT NULL,\n      `version` int(11) NOT NULL DEFAULT '1',\n      `is_active` tinyint(1) NOT NULL DEFAULT '1',\n      `post_id` int(11) NOT NULL,\n      `body` text NOT NULL,\n      PRIMARY KEY (`id`),\n      KEY `post_id` (`post_id`),\n      KEY `user_id` (`user_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ", "CREATE TABLE IF NOT EXISTS `note_versions` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `created_at` DATETIME NULL,\n      `updated_at` DATETIME NULL,\n      `x` int(11) NOT NULL,\n      `y` int(11) NOT NULL,\n      `width` int(11) NOT NULL,\n      `height` int(11) NOT NULL,\n      `body` int(11) NOT NULL,\n      `version` int(11) NOT NULL,\n      `ip_addr` varchar(64) NOT NULL,\n      `is_active` tinyint(1) NOT NULL DEFAULT '1',\n      `note_id` int(11) NOT NULL,\n      `post_id` int(11) NOT NULL,\n      `user_id` int(11) NOT NULL,\n      PRIMARY KEY (`id`),\n      KEY `user_id` (`user_id`),\n      KEY `fk_note_versions__note_id` (`note_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ", "CREATE TABLE IF NOT EXISTS `pools` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `name` varchar(255) NOT NULL,\n      `description` varchar(128) NOT NULL,\n      `user_id` int(11) NOT NULL,\n      `is_active` tinyint(1) NOT NULL DEFAULT '1',\n      `created_at` DATETIME NULL,\n      `updated_at` DATETIME NULL,\n      `post_count` int(3) NOT NULL DEFAULT '0',\n      `is_public` binary(1) NOT NULL DEFAULT '1',\n      PRIMARY KEY (`id`),\n      UNIQUE KEY `pool_name` (`name`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ", "CREATE TABLE IF NOT EXISTS `pools_posts` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `post_id` int(11) NOT NULL,\n      `pool_id` int(11) NOT NULL,\n      `sequence` varchar(16) NOT NULL,\n      `next_post_id` int(11) DEFAULT NULL,\n      `prev_post_id` int(11) DEFAULT NULL,\n      PRIMARY KEY (`id`),\n      KEY `post_id` (`post_id`),\n      KEY `fk_pools_posts__next_post_id` (`next_post_id`),\n      KEY `fk_pools_posts__prev_post_id` (`prev_post_id`),\n      KEY `fk_pools_posts__pool_id` (`pool_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ", "DROP TRIGGER IF EXISTS `pools_posts_insert_trg`", "CREATE TRIGGER `pools_posts_insert_trg` BEFORE INSERT ON `pools_posts`\n     FOR EACH ROW UPDATE pools SET post_count = post_count + 1 WHERE id = NEW.pool_id", "DROP TRIGGER IF EXISTS `pools_posts_delete_trg`", "CREATE TRIGGER `pools_posts_delete_trg` BEFORE DELETE ON `pools_posts`\n     FOR EACH ROW UPDATE pools SET post_count = post_count - 1 WHERE id = OLD.pool_id", "CREATE TABLE IF NOT EXISTS `posts` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `user_id` int(11) NOT NULL,\n      `ip_addr` varchar(64) NOT NULL,\n      `file_size` int(11) NOT NULL,\n      `md5` varchar(32) NOT NULL,\n      `last_commented_at` datetime DEFAULT NULL,\n      `file_ext` varchar(4) NOT NULL,\n      `last_noted_at` datetime DEFAULT NULL,\n      `source` varchar(249) DEFAULT NULL,\n      `cached_tags` text NOT NULL,\n      `width` int(11) NOT NULL,\n      `height` int(11) NOT NULL,\n      `created_at` datetime NULL,\n      `rating` char(1) NOT NULL DEFAULT 'q',\n      `note` varchar(255) NOT NULL,\n      `preview_width` int(3) NOT NULL,\n      `preview_height` int(3) NOT NULL,\n      `actual_preview_width` int(3) NOT NULL,\n      `actual_preview_height` int(3) NOT NULL,\n      `score` int(3) NOT NULL,\n      `is_shown_in_index` tinyint(1) NOT NULL DEFAULT '1',\n      `is_held` tinyint(1) NOT NULL DEFAULT '0',\n      `has_children` tinyint(1) NOT NULL DEFAULT '0',\n      `status` enum('deleted','flagged','pending','active') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'active',\n      `is_rating_locked` tinyint(1) NOT NULL DEFAULT '0',\n      `is_note_locked` tinyint(1) NOT NULL DEFAULT '0',\n      `parent_id` int(11) DEFAULT NULL,\n      `sample_width` int(5) DEFAULT NULL,\n      `sample_height` int(5) DEFAULT NULL,\n      `sample_size` int(11) DEFAULT NULL,\n      `index_timestamp` datetime NULL,\n      `jpeg_width` int(11) DEFAULT NULL,\n      `jpeg_height` int(11) DEFAULT NULL,\n      `jpeg_size` int(11) DEFAULT NULL,\n      `random` int(11) NOT NULL,\n      PRIMARY KEY (`id`),\n      UNIQUE KEY `images__hash` (`md5`),\n      KEY `images__owner_id` (`user_id`),\n      KEY `images__width` (`width`),\n      KEY `images__height` (`height`),\n      KEY `fk_posts__parent_id` (`parent_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ", "DROP TRIGGER IF EXISTS `trg_posts__insert`", "CREATE TRIGGER `trg_posts__insert` AFTER INSERT ON `posts`\n     FOR EACH ROW UPDATE table_data SET row_count = row_count + 1 WHERE name = 'posts'", "DROP TRIGGER IF EXISTS `trg_posts__delete`", "CREATE TRIGGER `trg_posts__delete` AFTER DELETE ON `posts`\n    FOR EACH ROW\n    BEGIN\n      UPDATE pools SET post_count = post_count - 1 WHERE id IN (SELECT pool_id FROM pools_posts WHERE post_id = OLD.id);\n      UPDATE table_data SET row_count = row_count - 1 WHERE name = 'posts';\n    END", "CREATE TABLE IF NOT EXISTS `posts_tags` (\n      `post_id` int(11) NOT NULL,\n      `tag_id` int(11) NOT NULL,\n      UNIQUE KEY `post_id` (`post_id`,`tag_id`),\n      KEY `fk_posts_tags__post_id` (`post_id`),\n      KEY `fk_posts_tags__tag_id` (`tag_id`)\n    ) ENGINE=InnoDB DEFAULT CHARSET=utf8", "DROP TRIGGER IF EXISTS `trg_posts_tags__insert`", "CREATE TRIGGER `trg_posts_tags__insert` BEFORE INSERT ON `posts_tags`\n     FOR EACH ROW UPDATE tags SET post_count = post_count + 1 WHERE tags.id = NEW.tag_id", "DROP TRIGGER IF EXISTS `trg_posts_tags__delete`", "CREATE TRIGGER `trg_posts_tags__delete` BEFORE DELETE ON `posts_tags`\n     FOR EACH ROW UPDATE tags SET post_count = post_count - 1 WHERE tags.id = OLD.tag_id", "CREATE TABLE IF NOT EXISTS `post_votes` (\n      `post_id` int(11) NOT NULL,\n      `user_id` int(11) NOT NULL,\n      `score` int(1) DEFAULT '0',\n      `updated_at` datetime NULL DEFAULT '0000-00-00 00:00:00',\n      UNIQUE KEY `post_id` (`post_id`,`user_id`),\n      KEY `score` (`score`),\n      KEY `fk_user_id__users_id` (`user_id`)\n    ) ENGINE=InnoDB DEFAULT CHARSET=utf8", "CREATE TABLE IF NOT EXISTS `table_data` (\n      `name` varchar(11) CHARACTER SET ucs2 NOT NULL,\n      `row_count` int(11) NOT NULL DEFAULT '0',\n      KEY `name` (`name`)\n    ) ENGINE=InnoDB DEFAULT CHARSET=utf8", "CREATE TABLE IF NOT EXISTS `tags` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `name` varchar(64) NOT NULL,\n      `post_count` int(11) NOT NULL DEFAULT '0',\n      `cached_related` text,\n      `cached_related_expires_on` datetime DEFAULT NULL,\n      `tag_type` smallint(6) NOT NULL,\n      `is_ambiguous` tinyint(1) NOT NULL DEFAULT '0',\n      PRIMARY KEY (`id`),\n      UNIQUE KEY `tags__name` (`name`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ", "CREATE TABLE IF NOT EXISTS `tag_aliases` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `name` varchar(64) NOT NULL,\n      `alias_id` int(11) NOT NULL,\n      `is_pending` tinyint(1) NOT NULL DEFAULT '0',\n      `reason` varchar(128) NOT NULL,\n      PRIMARY KEY (`id`),\n      UNIQUE KEY `alias_unique` (`name`,`alias_id`),\n      KEY `name` (`name`),\n      KEY `alias_id` (`alias_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ", "CREATE TABLE IF NOT EXISTS `tag_implications` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `predicate_id` int(11) NOT NULL,\n      `consequent_id` int(11) NOT NULL,\n      `is_pending` tinyint(1) NOT NULL DEFAULT '0',\n      `reason` varchar(128) NOT NULL,\n      PRIMARY KEY (`id`),\n      UNIQUE KEY `implication_unique` (`predicate_id`,`consequent_id`),\n      KEY `fk_consequent_id` (`consequent_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ", "CREATE TABLE IF NOT EXISTS `tag_subscriptions` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `user_id` int(11) NOT NULL,\n      `tag_query` text CHARACTER SET latin1 NOT NULL,\n      `cached_post_ids` text CHARACTER SET latin1 NOT NULL,\n      `name` varchar(32) CHARACTER SET latin1 NOT NULL,\n      `is_visible_on_profile` tinyint(1) NOT NULL DEFAULT '1',\n      PRIMARY KEY (`id`),\n      KEY `user_id` (`user_id`),\n      KEY `name` (`name`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ", "CREATE TABLE IF NOT EXISTS `users` (\n      `id` int(11) NOT NULL AUTO_INCREMENT,\n      `name` varchar(32) NOT NULL,\n      `password_hash` varchar(32) DEFAULT NULL,\n      `created_at` datetime NULL,\n      `level` int(11) NOT NULL DEFAULT '20',\n      `email` varchar(249) DEFAULT NULL,\n      `avatar_post_id` int(11) DEFAULT NULL,\n      `avatar_width` double DEFAULT NULL,\n      `avatar_height` double DEFAULT NULL,\n      `avatar_top` double DEFAULT NULL,\n      `avatar_bottom` double DEFAULT NULL,\n      `avatar_left` double DEFAULT NULL,\n      `avatar_right` double DEFAULT NULL,\n      `avatar_timestamp` datetime NULL,\n      `my_tags` text,\n      `show_samples` tinyint(1) NOT NULL DEFAULT '1',\n      `show_advanced_editing` tinyint(1) NOT NULL DEFAULT '0',\n      `pool_browse_mode` tinyint(1) NOT NULL DEFAULT '0',\n      `use_browser` tinyint(1) NOT NULL DEFAULT '0',\n      `always_resize_images` tinyint(1) NOT NULL DEFAULT '0',\n      `last_logged_in_at` datetime NULL,\n      `last_commented_read_at` datetime NULL,\n      `last_deleted_post_seen_at` datetime NULL,\n      `language` text NOT NULL,\n      `secondary_languages` text NOT NULL,\n      `receive_dmails` tinyint(1) NOT NULL DEFAULT '1',\n      PRIMARY KEY (`id`),\n      UNIQUE KEY `users__name` (`name`),\n      KEY `fk_users__avatar_post_id` (`avatar_post_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ", "CREATE TABLE IF NOT EXISTS `user_blacklisted_tags` (\n      `user_id` int(11) NOT NULL,\n      `tags` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,\n      UNIQUE KEY `user_id` (`user_id`)\n    ) ENGINE=InnoDB DEFAULT CHARSET=utf8", "ALTER TABLE `comments`\n      ADD CONSTRAINT `fk_comments__post_id` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE,\n      ADD CONSTRAINT `fk_comments__user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE", "ALTER TABLE `flagged_post_details`\n      ADD CONSTRAINT `fk_flag_post_details__user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),\n      ADD CONSTRAINT `fk_flag_post_det__post_id` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE", "ALTER TABLE `pools_posts`\n      ADD CONSTRAINT `fk_pools_posts__next_post_id` FOREIGN KEY (`next_post_id`) REFERENCES `posts` (`id`) ON DELETE SET NULL,\n      ADD CONSTRAINT `fk_pools_posts__pool_id` FOREIGN KEY (`pool_id`) REFERENCES `pools` (`id`) ON DELETE CASCADE,\n      ADD CONSTRAINT `fk_pools_posts__post_id` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE,\n      ADD CONSTRAINT `fk_pools_posts__prev_post_id` FOREIGN KEY (`prev_post_id`) REFERENCES `posts` (`id`) ON DELETE SET NULL", "ALTER TABLE `posts`\n      ADD CONSTRAINT `fk_parent_id__posts_id` FOREIGN KEY (`parent_id`) REFERENCES `posts` (`id`) ON DELETE SET NULL", "ALTER TABLE `posts_tags`\n      ADD CONSTRAINT `fk_posts_tags__post_id` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE,\n      ADD CONSTRAINT `fk_posts_tags__tag_id` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) ON DELETE CASCADE", "ALTER TABLE `post_votes`\n      ADD CONSTRAINT `fk_post_id__posts_id` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) ON DELETE CASCADE,\n      ADD CONSTRAINT `fk_user_id__users_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE", "ALTER TABLE `tag_aliases`\n      ADD CONSTRAINT `fk_alias_id` FOREIGN KEY (`alias_id`) REFERENCES `tags` (`id`) ON DELETE CASCADE", "ALTER TABLE `tag_implications`\n      ADD CONSTRAINT `fk_consequent_id` FOREIGN KEY (`consequent_id`) REFERENCES `tags` (`id`) ON DELETE CASCADE,\n      ADD CONSTRAINT `fk_predicate_id` FOREIGN KEY (`predicate_id`) REFERENCES `tags` (`id`) ON DELETE CASCADE", "ALTER TABLE `user_blacklisted_tags`\n      ADD CONSTRAINT `fk_user_bl_tags__user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE", "INSERT INTO `table_data` VALUES ('posts', 0)", "INSERT INTO `table_data` VALUES ('users', 0)", "INSERT INTO `table_data` VALUES ('non-explicit_posts', 0)");
    foreach ($queries as $query) {
        DB::execute_sql($query);
    }
    extract($_POST);
    $password_hash = md5($name . $password);
    $user_id = DB::insert('users (created_at, name, password_hash, level, show_advanced_editing) VALUES (?, ?, ?, ?, ?)', gmd(), $name, $password_hash, 50, 1);
    DB::insert('user_blacklisted_tags VALUES (?, ?)', $user_id, implode("\r\n", CONFIG::$default_blacklists));
    DB::update("table_data set row_count = row_count + 1 where name = 'users'");
    $dp = ROOT . 'public/data/';
    foreach (array($dp, "{$dp}/avatars", "{$dp}/export", "{$dp}/image", "{$dp}/import", "{$dp}/jpeg", "{$dp}/preview", "{$dp}/sample") as $dir) {
        @mkdir($dir);
    }
    unlink('index.php');
    rename('index_.php', 'index.php');
    cookie_put('login', $name);
    cookie_put('pass_hash', $password_hash);
    notice('Installation completed');
    header('Location: /');
    exit;
}
if (function_exists('finfo_open')) {
Example #8
0
    }
    // @preload = @preload.delete_if { |post| not post.can_be_seen_by?(@current_user) }
}
if ($from_api and isset(Request::$params->api_version) && Request::$params->api_version == "2" and Request::$format != "json") {
    respond_to_error("V2 API is JSON-only", array(), array('status' => 424));
}
// @posts.replace(results)
$posts = $results;
unset($results);
switch (Request::$format) {
    case 'json':
        if (empty(Request::$params->api_version) || Request::$params->api_version != "2") {
            render('json', to_json(array_map(function ($p) {
                return $p->api_attributes();
            }, (array) $posts)));
            return;
        }
        $api_data = Post::batch_api_data($posts, array('exclude_tags' => !empty(Request::$params->include_tags) ? false : true, 'exclude_votes' => !empty(Request::$params->include_votes) ? false : true, 'exclude_pools' => !empty(Request::$params->include_pools) ? false : true));
        render('json', to_json($api_data));
        break;
    case 'xml':
        ActionView::$layout = false;
        return;
        break;
}
if (!empty($split_tags)) {
    $tags = Tag::parse_query($tags);
} else {
    $tags['include'] = Tag::count_by_period(gmd_math('sub', '1D'), gmd(), array('limit' => 25, 'exclude_types' => CONFIG::$exclude_from_tag_sidebar));
}
calc_pages();
Example #9
0
 function touch_index_timestamp()
 {
     $this->index_timestamp = gmd();
 }
Example #10
0
/**
 * GMD math.
 *
 * Adds, substracts or calculates difference of a date interval from current date.
 * For more info check the DateTime class in the PHP manual.
 *
 * @param string $type - 'add', 'sub' or 'diff'.
 * @param string $q    - days, hours, mins or seconds to do the math with.
 */
function gmd_math($type, $q, $format = 'Y-m-d H:i:s')
{
    $dt = new DateTime(gmd());
    if ($type == 'diff') {
        $dt2 = new DateTime($q);
        $dt = date_diff($dt, $dt2);
    } else {
        $dt->{$type}(new DateInterval("P{$q}"));
    }
    return $dt->format($format);
}
Example #11
0
<?php

User::$current->update_attribute('last_forum_topic_read_at', gmd());
render(false);