public function __construct()
 {
     parent::__construct();
     if (!DEBUG_MODE) {
         exit('Access denied');
     }
     $this->resloader->clear();
     $this->resloader->setMerge(false);
     $this->warning_params = app('profiler')->getWarningParams();
     $this->chmod_folders = array(array('folder' => 'data', 'path' => data_path(), 'level' => 1), array('folder' => 'data/cache', 'path' => data_path() . '/cache', 'level' => 2), array('folder' => 'data/logs', 'path' => data_path() . '/logs', 'level' => 2), array('folder' => 'data/logs/debug', 'path' => data_path() . '/logs/debug', 'level' => 3), array('folder' => 'data/sqls', 'path' => data_path() . '/sqls', 'level' => 2), array('folder' => 'data/updates', 'path' => data_path() . '/updates', 'level' => 2), array('folder' => 'public_html/cache', 'path' => public_path() . '/cache', 'level' => 1), array('folder' => 'public_html/cache/app', 'path' => public_path() . '/cache/app', 'level' => 2), array('folder' => 'public_html/cache/app/css', 'path' => public_path() . '/cache/app/css', 'level' => 3), array('folder' => 'public_html/cache/app/js', 'path' => public_path() . '/cache/app/js', 'level' => 3), array('folder' => 'public_html/cache/captcha', 'path' => public_path() . '/cache/captcha', 'level' => 2), array('folder' => 'public_html/cache/core', 'path' => public_path() . '/cache/core', 'level' => 2), array('folder' => 'public_html/cache/core/css', 'path' => public_path() . '/cache/core/css', 'level' => 3), array('folder' => 'public_html/cache/core/js', 'path' => public_path() . '/cache/core/js', 'level' => 3), array('folder' => 'public_html/uploads', 'path' => public_path() . '/uploads', 'level' => 1), array('folder' => 'public_html/uploads/avatars', 'path' => public_path() . '/uploads/avatars', 'level' => 2), array('folder' => 'public_html/uploads/other', 'path' => public_path() . '/uploads/other', 'level' => 2), array('folder' => 'public_html/uploads/photo', 'path' => public_path() . '/uploads/photo', 'level' => 2), array('folder' => 'public_html/uploads/photo/cache', 'path' => public_path() . '/uploads/photo/cache', 'level' => 3), array('folder' => 'public_html/uploads/photo/main', 'path' => public_path() . '/uploads/photo/main', 'level' => 3), array('folder' => 'public_html/uploads/photo/original', 'path' => public_path() . '/uploads/photo/original', 'level' => 3), array('folder' => 'public_html/uploads/tmp', 'path' => public_path() . '/uploads/tmp', 'level' => 2), array('folder' => 'public_html/uploads/video', 'path' => public_path() . '/uploads/video', 'level' => 2));
     $data = app('profiler')->getDebugInfo();
     $this->data = array_reverse($data, true);
 }
Example #2
0
 public function onPageRequest(PageRequestEvent $event)
 {
     if ($event->page_matches("sitemap.xml")) {
         global $config;
         $this->sitemap_filepath = data_path("cache/sitemap.xml");
         // determine if new sitemap needs to be generated
         if ($this->new_sitemap_needed()) {
             // determine which type of sitemap to generate
             if ($config->get_bool("sitemap_generatefull", false)) {
                 $this->handle_full_sitemap();
                 // default false until cache fixed
             } else {
                 $this->handle_smaller_sitemap();
             }
         } else {
             $this->display_existing_sitemap();
         }
     }
 }
Example #3
0
 /**
  * @return string
  */
 private function build_tag_popularity()
 {
     global $database;
     $tags_min = $this->get_tags_min();
     // Make sure that the value of $tags_min is at least 1.
     // Otherwise the database will complain if you try to do: LOG(0)
     if ($tags_min < 1) {
         $tags_min = 1;
     }
     // check if we have a cached version
     $cache_key = data_path("cache/tag_popul-" . md5("tp" . $tags_min) . ".html");
     if (file_exists($cache_key)) {
         return file_get_contents($cache_key);
     }
     $tag_data = $database->get_all("\n\t\t\t\tSELECT tag, count, FLOOR(LOG(count)) AS scaled\n\t\t\t\tFROM tags\n\t\t\t\tWHERE count >= :tags_min\n\t\t\t\tORDER BY count DESC, tag ASC\n\t\t\t\t", array("tags_min" => $tags_min));
     $html = "Results grouped by log<sub>10</sub>(n)";
     $lastLog = "";
     foreach ($tag_data as $row) {
         $h_tag = html_escape($row['tag']);
         $count = $row['count'];
         $scaled = $row['scaled'];
         if ($lastLog != $scaled) {
             $lastLog = $scaled;
             $html .= "<p>{$lastLog}<br>";
         }
         $link = $this->tag_link($row['tag']);
         $html .= "<a href='{$link}'>{$h_tag}&nbsp;({$count})</a>\n";
     }
     if (SPEED_HAX) {
         file_put_contents($cache_key, $html);
     }
     return $html;
 }
Example #4
0
 /**
  * This function grabs all the CSS and JavaScript files sprinkled throughout Shimmie's folders,
  * concatenates them together into two large files (one for CSS and one for JS) and then stores
  * them in the /cache/ directory for serving to the user.
  * 
  * Why do this? Two reasons:
  *  1. Reduces the number of files the user's browser needs to download.
  *  2. Allows these cached files to be compressed/minified by the admin.
  * 
  * TODO: This should really be configurable somehow...
  */
 protected function add_auto_html_headers()
 {
     global $config;
     $data_href = get_base_href();
     $theme_name = $config->get_string('theme', 'default');
     $this->add_html_header("<script type='text/javascript'>base_href = '{$data_href}';</script>", 40);
     # 404/static handler will map these to themes/foo/bar.ico or lib/static/bar.ico
     $this->add_html_header("<link rel='icon' type='image/x-icon' href='{$data_href}/favicon.ico'>", 41);
     $this->add_html_header("<link rel='apple-touch-icon' href='{$data_href}/apple-touch-icon.png'>", 42);
     $css_files = array();
     $css_latest = 0;
     foreach (array_merge(zglob("lib/*.css"), zglob("ext/*/style.css"), zglob("themes/{$theme_name}/style.css")) as $css) {
         $css_files[] = $css;
         $css_latest = max($css_latest, filemtime($css));
     }
     $css_cache_file = data_path("cache/style.{$theme_name}.{$css_latest}.css");
     if (!file_exists($css_cache_file)) {
         $css_data = "";
         foreach ($css_files as $file) {
             $file_data = file_get_contents($file);
             $pattern = '/url[\\s]*\\([\\s]*["\']?([^"\'\\)]+)["\']?[\\s]*\\)/';
             $replace = 'url("../../' . dirname($file) . '/$1")';
             $file_data = preg_replace($pattern, $replace, $file_data);
             $css_data .= $file_data . "\n";
         }
         file_put_contents($css_cache_file, $css_data);
     }
     $this->add_html_header("<link rel='stylesheet' href='{$data_href}/{$css_cache_file}' type='text/css'>", 43);
     $js_files = array();
     $js_latest = 0;
     foreach (array_merge(zglob("lib/*.js"), zglob("ext/*/script.js"), zglob("themes/{$theme_name}/script.js")) as $js) {
         $js_files[] = $js;
         $js_latest = max($js_latest, filemtime($js));
     }
     $js_cache_file = data_path("cache/script.{$theme_name}.{$js_latest}.js");
     if (!file_exists($js_cache_file)) {
         $js_data = "";
         foreach ($js_files as $file) {
             $js_data .= file_get_contents($file) . "\n";
         }
         file_put_contents($js_cache_file, $js_data);
     }
     $this->add_html_header("<script src='{$data_href}/{$js_cache_file}' type='text/javascript'></script>", 44);
 }
Example #5
0
function _load_extensions()
{
    global $_event_listeners;
    ctx_log_start("Loading extensions");
    if (COMPILE_ELS && file_exists("data/cache/event_listeners.php")) {
        require_once "data/cache/event_listeners.php";
    } else {
        _set_event_listeners(get_declared_classes());
        if (COMPILE_ELS) {
            _dump_event_listeners($_event_listeners, data_path("cache/event_listeners.php"));
        }
    }
    ctx_log_endok();
}
Example #6
0
 private function set_dir()
 {
     global $config;
     // Determine directory (none = default)
     $dir = $config->get_string("cron_uploader_dir", "");
     // Sets new default dir if not in config yet/anymore
     if ($dir == "") {
         $dir = data_path("cron_uploader");
         $config->set_string('cron_uploader_dir', $dir);
     }
     // Make the directory if it doesn't exist yet
     if (!is_dir($dir . "/queue/")) {
         mkdir($dir . "/queue/", 0775, true);
     }
     if (!is_dir($dir . "/uploaded/")) {
         mkdir($dir . "/uploaded/", 0775, true);
     }
     if (!is_dir($dir . "/failed_to_upload/")) {
         mkdir($dir . "/failed_to_upload/", 0775, true);
     }
     $this->root_dir = $dir;
     return $dir;
 }
Example #7
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $user, $page;
     if ($event->page_matches("oekaki")) {
         if ($user->can("create_image")) {
             if ($event->get_arg(0) == "create") {
                 $this->theme->display_page();
                 $this->theme->display_block();
             }
             if ($event->get_arg(0) == "claim") {
                 // FIXME: move .chi to data/oekaki/$ha/$hash mirroring images and thumbs
                 // FIXME: .chi viewer?
                 // FIXME: clean out old unclaimed images?
                 $pattern = data_path('oekaki_unclaimed/' . $_SERVER['REMOTE_ADDR'] . ".*.png");
                 foreach (glob($pattern) as $tmpname) {
                     assert(file_exists($tmpname));
                     $pathinfo = pathinfo($tmpname);
                     if (!array_key_exists('extension', $pathinfo)) {
                         throw new UploadException("File has no extension");
                     }
                     log_info("oekaki", "Processing file [{$pathinfo['filename']}]");
                     $metadata = array();
                     $metadata['filename'] = 'oekaki.png';
                     $metadata['extension'] = $pathinfo['extension'];
                     $metadata['tags'] = 'oekaki tagme';
                     $metadata['source'] = null;
                     $event = new DataUploadEvent($tmpname, $metadata);
                     send_event($event);
                     if ($event->image_id == -1) {
                         throw new UploadException("File type not recognised");
                     } else {
                         unlink($tmpname);
                         $page->set_mode("redirect");
                         $page->set_redirect(make_link("post/view/" . $event->image_id));
                     }
                 }
             }
         }
         if ($event->get_arg(0) == "upload") {
             // FIXME: this allows anyone to upload anything to /data ...
             // hardcoding the ext to .png should stop the obvious exploit,
             // but more checking may be wise
             if (isset($_FILES["picture"])) {
                 header('Content-type: text/plain');
                 $file = $_FILES['picture']['name'];
                 $ext = strpos($file, '.') === FALSE ? '' : substr($file, strrpos($file, '.'));
                 $uploadname = $_SERVER['REMOTE_ADDR'] . "." . time();
                 $uploadfile = data_path('oekaki_unclaimed/' . $uploadname);
                 log_info("oekaki", "Uploading file [{$uploadname}]");
                 $success = TRUE;
                 if (isset($_FILES["chibifile"])) {
                     $success = $success && move_uploaded_file($_FILES['chibifile']['tmp_name'], $uploadfile . ".chi");
                 }
                 // hardcode the ext, so nobody can upload "foo.php"
                 $success = $success && move_uploaded_file($_FILES['picture']['tmp_name'], $uploadfile . ".png");
                 # $ext);
                 if ($success) {
                     echo "CHIBIOK\n";
                 } else {
                     echo "CHIBIERROR\n";
                 }
             } else {
                 echo "CHIBIERROR No Data\n";
             }
         }
     }
 }
Example #8
0
 private function download_all_images()
 {
     global $database, $page;
     $images = $database->get_all("SELECT hash, ext FROM images");
     $filename = data_path('imgdump-' . date('Ymd') . '.zip');
     $zip = new ZipArchive();
     if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) === TRUE) {
         foreach ($images as $img) {
             $img_loc = warehouse_path("images", $img["hash"], FALSE);
             $zip->addFile($img_loc, $img["hash"] . "." . $img["ext"]);
         }
         $zip->close();
     }
     $page->set_mode("redirect");
     $page->set_redirect(make_link($filename));
     //TODO: Delete file after downloaded?
     return false;
     // we do want a redirect, but a manual one
 }
Example #9
0
function _load_event_listeners()
{
    global $_shm_event_listeners;
    ctx_log_start("Loading extensions");
    $cache_path = data_path("cache/shm_event_listeners.php");
    if (COMPILE_ELS && file_exists($cache_path)) {
        require_once $cache_path;
    } else {
        _set_event_listeners();
        if (COMPILE_ELS) {
            _dump_event_listeners($_shm_event_listeners, $cache_path);
        }
    }
    ctx_log_endok();
}