Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[ljcom] r10926: LJSUP-9478: Admin tool for headers

Committer: gariev
LJSUP-9478: Admin tool for headers
U   trunk/cgi-bin/LJ/ExtBlock.pm
U   trunk/cgi-bin/LJ/FileStore.pm
U   trunk/cgi-bin/LJ/Hooks/Homepage.pm
U   trunk/cgi-bin/LJ/MogileFS/Frontend.pm
U   trunk/htdocs/admin/userheads/manage.bml
Modified: trunk/cgi-bin/LJ/ExtBlock.pm
===================================================================
--- trunk/cgi-bin/LJ/ExtBlock.pm	2011-08-25 09:14:39 UTC (rev 10925)
+++ trunk/cgi-bin/LJ/ExtBlock.pm	2011-08-25 10:27:22 UTC (rev 10926)
@@ -49,9 +49,12 @@
 sub load_by_id {
     my $class  = shift;
     my $id = shift;
+    my $opts = shift || {};
 
     ## 1. Find in local cache
-    return $LJ::REQ_CACHE_EXT_BLOCK{$id} if $LJ::REQ_CACHE_EXT_BLOCK{$id};
+    if ($LJ::REQ_CACHE_EXT_BLOCK{$id} && !$opts->{'skip_local_cache'}) {
+        return $LJ::REQ_CACHE_EXT_BLOCK{$id};
+    }
 
     ## 2. Find in memcache
     my $self = $class->_load_from_memcache($id);

Modified: trunk/cgi-bin/LJ/FileStore.pm
===================================================================
--- trunk/cgi-bin/LJ/FileStore.pm	2011-08-25 09:14:39 UTC (rev 10925)
+++ trunk/cgi-bin/LJ/FileStore.pm	2011-08-25 10:27:22 UTC (rev 10926)
@@ -9,48 +9,60 @@
 sub save_file {
     my $class = shift;
     my %args = @_;
+    
+    my $path            = $args{'path'};
+    my $content         = $args{'content'};
+    die "No content" unless $content;
+    my $content_length  = $args{'content_length'} || length($content);
+    my $mime_type       = $args{'mime_type'};
 
-    my $result = ();
-    $result = eval {LJ::MogileFS::Frontend->save_file(
-        content => $args{content},
-        fs_key  => $args{path},
-    )} if $args{content};
+    my $result = LJ::MogileFS::Frontend->save_file(
+        content => $content,
+        fs_key  => $path,
+    );
+    die "Can't save to MogileFS" unless $result; 
 
-    return undef if $@;
-    
-    return undef unless $result;
-
     my $dbh = LJ::get_db_writer();
-    my $res = $dbh->do("REPLACE INTO files (path, mime_type, content_length, change_time) VALUES (?, ?, ?, unix_timestamp(now()))", undef, $args{path}, $args{mime_type}, $args{content_length});
+    my $res = $dbh->do(
+        "REPLACE INTO files (path, mime_type, content_length, change_time) ".
+        "VALUES (?, ?, ?, unix_timestamp(now()))", 
+        undef, $path, $mime_type, $content_length,
+    );
+    die $DBI::errstr unless $res;
+    LJ::MemCache::delete($path);
 
-    LJ::MemCache::delete($args{path});
-
-    return $res ? $result : undef;
+    return $result;
 }
 
 sub get_path_info {
     my $class = shift;
     my %args  = @_;
 
-    my $dbh = LJ::get_db_reader();
-    
-    my ($file_info, $paths) = ();
-    my $path = $args{path};
-    $paths = LJ::MogileFS::Frontend->get_paths($path);
-    
-    if (!$LJ::FILES{$path}) {
-        $file_info = LJ::MemCache::get($path);
-        if (!$file_info) {
-            my $cache_for = $LJ::MOGILE_PATH_CACHE_TIMEOUT || 3600;
-            $file_info = $dbh->selectrow_hashref("SELECT mime_type, content_length, change_time FROM files WHERE path = ?", undef, $path);
-            LJ::MemCache::set($path, $file_info, $cache_for);
-        }
-        $LJ::FILES{$path} = $file_info;
+    my $path = $args{'path'};
+    return $LJ::FILES{$path} if $LJ::FILES{$path};
+
+    my $file_info = LJ::MemCache::get($path);
+    if (!$file_info) {
+        my $dbh = LJ::get_db_writer();
+        $file_info = $dbh->selectrow_hashref(
+            "SELECT mime_type, content_length, change_time FROM files WHERE path = ?", 
+            undef, $path
+        );
+        $file_info->{paths} = LJ::MogileFS::Frontend->get_paths($path);
+        my $cache_for = $LJ::MOGILE_PATH_CACHE_TIMEOUT || 3600;
+        LJ::MemCache::set($path, $file_info, $cache_for);
     }
-    $LJ::FILES{$path}->{paths} = $paths;
+    $LJ::FILES{$path} = $file_info;
 
     return $LJ::FILES{$path};
 }
 
+sub get_file_data {
+    my $class = shift;
+    my $path = shift;
+
+    return LJ::MogileFS::Frontend->get_file_data($path);
+}
+
 1;
 

Modified: trunk/cgi-bin/LJ/Hooks/Homepage.pm
===================================================================
--- trunk/cgi-bin/LJ/Hooks/Homepage.pm	2011-08-25 09:14:39 UTC (rev 10925)
+++ trunk/cgi-bin/LJ/Hooks/Homepage.pm	2011-08-25 10:27:22 UTC (rev 10926)
@@ -1,5 +1,6 @@
 package LJ::LJcom;
 use strict;
+use LJ::ServicePageReskinning;
 
 sub _is_xbox_reskining_active {
     my $params = shift;
@@ -66,12 +67,38 @@
 
 LJ::register_hook("service_page_reskining", sub {
     my $params = shift || {};
-   
-    if (LJ::_is_super8_branding_active()) {
-        LJ::need_res("stc/reskining/2011/june/super8/homepage.css");
-        return '';
+
+    ##
+    ## experimental ServicePageReskinning part 
+    ##
+    my $reskinning;
+    my %GET = LJ::Request->args;
+    if ($GET{'reskinning'}) {
+        $reskinning = LJ::ServicePageReskinning->load_by_id($GET{'reskinning'});
+    } else {
+        $reskinning = LJ::ServicePageReskinning->get_active;
     }
- 
+
+    if ($reskinning) {
+        warn "Using reskinning $reskinning->{id}";
+
+        my ($css_file) = grep { $_->{'kind'} eq 'css' } @{ $reskinning->{'files'} };
+        if ($css_file) {
+            my $absolute_name = 
+                "$LJ::FILEPREFIX$reskinning->{base_path}/$css_file->{filename}?v=$reskinning->{version}";
+            LJ::include_raw("css_link", $absolute_name);
+            my $text = LJ::Lang::ml("reskinning.$reskinning->{id}");
+            warn $text;
+            LJ::CleanHTML::clean(\$text, { allow => [ 'a' ] }); ## to add <a> tags
+            return qq[<dl class="b-reskining-about"><dt></dt><dd>$text</dd></dl>];
+        } else {
+            warn "No css file found for $reskinning->{id}";
+        }
+    }
+    ## 
+    ## end of /experimental ServicePageReskinning part
+    ##
+
     my $is_sup = LJ::SUP->is_remote_sup();
     my $time = time(); 
 

Modified: trunk/cgi-bin/LJ/MogileFS/Frontend.pm
===================================================================
--- trunk/cgi-bin/LJ/MogileFS/Frontend.pm	2011-08-25 09:14:39 UTC (rev 10925)
+++ trunk/cgi-bin/LJ/MogileFS/Frontend.pm	2011-08-25 10:27:22 UTC (rev 10926)
@@ -36,5 +36,12 @@
     return \@paths;
 }
 
+sub get_file_data {
+    my $class = shift;
+    my $fs_key = shift;
+
+    return LJ::mogclient()->get_file_data("file:" . md5_hex($fs_key));
+}
+
 1;
 

Modified: trunk/htdocs/admin/userheads/manage.bml
===================================================================
--- trunk/htdocs/admin/userheads/manage.bml	2011-08-25 09:14:39 UTC (rev 10925)
+++ trunk/htdocs/admin/userheads/manage.bml	2011-08-25 10:27:22 UTC (rev 10926)
@@ -31,7 +31,7 @@
 
         $content_length = bytes::length($userhead_content);
         $magic = substr $userhead_content, 0, 20;
-        $mime_type = format_magic($magic)
+        $mime_type = LJ::format_magic($magic)
             or die "Unknown format for upload";
         my $result = LJ::FileStore->save_file(path => "/userhead/" . $uh->get_uh_id, content => $userhead_content, mime_type => $mime_type, content_length => $content_length);
         unless ($result) {
@@ -165,19 +165,5 @@
 
 return $ret;
 
-sub format_magic {
-    my $magic = shift;
-    my $hex = unpack "H*", $magic;
-    my $mime;
-
-    $mime = 'text/plain'; # default value
-    # image formats
-    $mime = 'image/jpeg' if $magic =~ /^\xff\xd8/; # JPEG
-    $mime = 'image/gif'  if $magic =~ /^GIF8/;     # GIF
-    $mime = 'image/png'  if $magic =~ /^\x89PNG/;  # PNG
-
-    return $mime;
-}
-
 _code?>
 

Tags: bml, gariev, ljcom, pm
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments