| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | package LJ::LJcom; |
|---|
| 4 | use strict; |
|---|
| 5 | |
|---|
| 6 | LJ::register_hook('construct_userpic_url', sub { |
|---|
| 7 | return 0; # off for now. doing it globally instead. (% of users, not % of userpics) |
|---|
| 8 | |
|---|
| 9 | my $userpic = shift or return; |
|---|
| 10 | my $userid = $userpic->userid; |
|---|
| 11 | my $picid = $userpic->id; |
|---|
| 12 | |
|---|
| 13 | my $ip = LJ::get_remote_ip(); |
|---|
| 14 | my $ip_class = LJ::LJcom::ip_class($ip); |
|---|
| 15 | return unless $ip_class; |
|---|
| 16 | return unless LJ::Knob->instance("cdn-userpic-$ip_class")->check($picid); |
|---|
| 17 | return 0; |
|---|
| 18 | }); |
|---|
| 19 | |
|---|
| 20 | LJ::register_hook('set_alternate_statimg', sub { |
|---|
| 21 | my $r = eval { Apache->request } or return 0; |
|---|
| 22 | my $ip = $r->connection->remote_ip; |
|---|
| 23 | my $ipclass = LJ::LJcom::ip_class($ip); |
|---|
| 24 | return unless $ipclass; |
|---|
| 25 | |
|---|
| 26 | # first, reset everything to normal. |
|---|
| 27 | $LJ::IMGPREFIX = $LJ::IMGPREFIX_BAK; |
|---|
| 28 | $LJ::STATPREFIX = $LJ::STATPREFIX_BAK; |
|---|
| 29 | $LJ::USERPIC_ROOT = $LJ::USERPICROOT_BAK; |
|---|
| 30 | |
|---|
| 31 | my $cdn_settings = $LJ::CDN{$ipclass} || {}; |
|---|
| 32 | |
|---|
| 33 | #use Data::Dumper; |
|---|
| 34 | #warn "ipclass = $ipclass, settings = " . join(",", %$cdn_settings); |
|---|
| 35 | |
|---|
| 36 | if (LJ::Knob->instance("cdn-stat-$ipclass")->check($ip)) { |
|---|
| 37 | $LJ::STATPREFIX = $cdn_settings->{STATPREFIX} if $cdn_settings->{STATPREFIX}; |
|---|
| 38 | $LJ::IMGPREFIX = $cdn_settings->{IMGPREFIX} if $cdn_settings->{IMGPREFIX}; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | if (LJ::Knob->instance("cdn-userpic-$ipclass")->check($ip)) { |
|---|
| 42 | $LJ::USERPIC_ROOT = $cdn_settings->{USERPIC_ROOT} if $cdn_settings->{USERPIC_ROOT}; |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | return 1; |
|---|
| 46 | }); |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | # |
|---|
| 50 | # |
|---|
| 51 | # |
|---|
| 52 | LJ::register_hook('construct_adcall', sub { |
|---|
| 53 | my %opts = @_; # This is the same opts that are passed to sub ads {} in weblib.pl |
|---|
| 54 | |
|---|
| 55 | my $pagetype = delete $opts{'orient'}; |
|---|
| 56 | my $username = delete $opts{'user'}; |
|---|
| 57 | return unless LJ::SUP->is_sup_ad_case($username); |
|---|
| 58 | |
|---|
| 59 | my $u = LJ::load_user($username); |
|---|
| 60 | # if no user specified try to guess the user to correlate to SUP-6A adv table |
|---|
| 61 | $u = LJ::get_active_journal() unless $u; |
|---|
| 62 | |
|---|
| 63 | my $remote = LJ::get_remote(); |
|---|
| 64 | my %params; |
|---|
| 65 | |
|---|
| 66 | # Remove BML- prefix if it exists |
|---|
| 67 | $pagetype =~ s/^BML-//; |
|---|
| 68 | if ($pagetype eq 'Sponsored-Profile' && $u && $u->is_sponsored) { |
|---|
| 69 | $pagetype .= '-' . $u->sponsored_u->sponsor->community->{'user'}; |
|---|
| 70 | } |
|---|
| 71 | $params{adzone} = $pagetype; |
|---|
| 72 | $params{i1} = $u->id if $u; |
|---|
| 73 | $params{i2} = $remote->id if $remote; |
|---|
| 74 | $params{r} = int(rand(1e9)); |
|---|
| 75 | $params{cp} = eval { Apache->notes("codepath") } || ""; |
|---|
| 76 | $params{vid} = $LJ::SUP_REQUEST_ID; |
|---|
| 77 | $params{srv} = 1; |
|---|
| 78 | |
|---|
| 79 | return $LJ::SUP_BASE_ADCALL_URL . "?" . join('&', |
|---|
| 80 | map { "$_=" . LJ::eurl($params{$_}) } |
|---|
| 81 | keys %params); |
|---|
| 82 | }); |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | LJ::register_hook("post_create", sub { |
|---|
| 86 | my $arg = shift; |
|---|
| 87 | return undef unless $arg && $arg->{userid}; |
|---|
| 88 | my $u = LJ::load_userid($arg->{userid}) or return undef; |
|---|
| 89 | |
|---|
| 90 | my $lang = LJ::SUP->is_sup_language(); |
|---|
| 91 | return unless $lang; |
|---|
| 92 | |
|---|
| 93 | # make their language explicit in database, so russia-tagger script |
|---|
| 94 | # tags them for the right reason (BML_LANG). |
|---|
| 95 | unless ($u->prop("browselang")) { |
|---|
| 96 | $u->set_prop("browselang" => $lang); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | # and also add them immediately to this class (the class that |
|---|
| 100 | # is eligible to do SUP stuff in future, and also who gets |
|---|
| 101 | # SUP advertising if a plus user...) |
|---|
| 102 | $u->add_to_class("sup_user"); # in future, rename to "sup_eligible" |
|---|
| 103 | |
|---|
| 104 | # Subscribe SUP user |
|---|
| 105 | $u->subscribe( event => 'SupOfficialPost', method => 'Inbox' ); |
|---|
| 106 | $u->subscribe( event => 'SupOfficialPost', method => 'Email' ) |
|---|
| 107 | if $arg->{news}; |
|---|
| 108 | }); |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | # Returns SUP ad mapping for specified URI. |
|---|
| 112 | # If it is not SUP case returns undef. |
|---|
| 113 | # If SUP does not override ads logic for specified URI returns undef also. |
|---|
| 114 | # $LJ::SUP_AD_MAPPING hash has the same structure and purpose as $LJ::AD_MAPPING |
|---|
| 115 | # Only the differences between 6A and SUP ads logic |
|---|
| 116 | # should be placed in the $LJ::SUP_AD_MAPPING |
|---|
| 117 | |
|---|
| 118 | LJ::register_hook("get_ad_uri_mapping", sub { |
|---|
| 119 | my $uri = shift; |
|---|
| 120 | return unless LJ::SUP->is_sup_ad_case(); |
|---|
| 121 | return $LJ::SUP_AD_MAPPING{$uri}; |
|---|
| 122 | }); |
|---|
| 123 | |
|---|
| 124 | # Returns SUP page mapping for specified pagetype. |
|---|
| 125 | # If it is not SUP case returns undef. |
|---|
| 126 | # If SUP does not override page mapping for specified pagetype returns undef also. |
|---|
| 127 | # $LJ::SUP_AD_PAGE_MAPPING hash has the same structure and purpose as $LJ::AD_PAGE_MAPPING |
|---|
| 128 | # Only the differences between 6A and SUP ads units |
|---|
| 129 | # should be placed in the $LJ::AD_PAGE_MAPPING |
|---|
| 130 | |
|---|
| 131 | LJ::register_hook('get_page_mapping', sub { |
|---|
| 132 | my $pagetype = shift; |
|---|
| 133 | return unless LJ::SUP->is_sup_ad_case(); |
|---|
| 134 | return $LJ::SUP_AD_PAGE_MAPPING{$pagetype}; |
|---|
| 135 | }); |
|---|
| 136 | |
|---|
| 137 | LJ::register_hook('get_advertising_url', sub { |
|---|
| 138 | if (LJ::SUP->is_sup_ad_case()) { |
|---|
| 139 | return "http://www.sol-agency.ru/blogs.html"; |
|---|
| 140 | } else { |
|---|
| 141 | return "http://www.sixapart.com/advertising/"; |
|---|
| 142 | } |
|---|
| 143 | }); |
|---|
| 144 | |
|---|
| 145 | LJ::register_hook('get_ad_details', sub { |
|---|
| 146 | my $adunit = shift; |
|---|
| 147 | return unless LJ::SUP->is_sup_ad_case(); |
|---|
| 148 | return $LJ::SUP_AD_TYPE{$adunit}; |
|---|
| 149 | }); |
|---|
| 150 | |
|---|
| 151 | LJ::register_hook('start_request', sub{ |
|---|
| 152 | $LJ::SUP_ADV_PER_PAGE = 0; |
|---|
| 153 | $LJ::SUP_REQUEST_ID = int(rand(1e9)); |
|---|
| 154 | %LJ::REQ_CACHE_EXT_BLOCK = (); |
|---|
| 155 | @LJ::SUP_LJ_ENTRY_REQ = (); |
|---|
| 156 | return; |
|---|
| 157 | }); |
|---|
| 158 | |
|---|
| 159 | LJ::register_hook('notify_event_displayed', sub{ |
|---|
| 160 | my $entry = shift; |
|---|
| 161 | push @LJ::SUP_LJ_ENTRY_REQ, [$entry->journalid, $entry->posterid, $entry->ditemid]; |
|---|
| 162 | }); |
|---|
| 163 | |
|---|
| 164 | LJ::register_hook('notify_ad_block', sub{ |
|---|
| 165 | $LJ::SUP_ADV_PER_PAGE++; |
|---|
| 166 | return; |
|---|
| 167 | }); |
|---|
| 168 | |
|---|
| 169 | LJ::register_hook('get_tos_uri', sub { |
|---|
| 170 | return unless BML::get_language() eq 'ru'; |
|---|
| 171 | return "/legal/tos-russian-translation.bml"; |
|---|
| 172 | }); |
|---|
| 173 | |
|---|
| 174 | LJ::register_hook('get_policy_uri', sub { |
|---|
| 175 | return unless BML::get_language() eq 'ru'; |
|---|
| 176 | return "/abuse/policy-russian-translation.bml"; |
|---|
| 177 | }); |
|---|
| 178 | |
|---|
| 179 | ## |
|---|
| 180 | ## Allow SUP Plus users to use Mass Privacy Tool. |
|---|
| 181 | ## (Currently, this tool is accessible by Paid users only |
|---|
| 182 | ## |
|---|
| 183 | LJ::register_hook('check_cap_mass_privacy', sub { |
|---|
| 184 | my $u = shift; |
|---|
| 185 | |
|---|
| 186 | return 1 if (LJ::SUP->is_sup_enabled($u) && $u->in_class('plus')); |
|---|
| 187 | return; ## return undef otherwise |
|---|
| 188 | ## the short form below is incorrect |
|---|
| 189 | ## return $u->in_class('sup_user') && $u->in_class('plus'); |
|---|
| 190 | }); |
|---|
| 191 | |
|---|
| 192 | LJ::register_hook('identity_section_ad', sub { |
|---|
| 193 | return unless LJ::SUP->is_sup_ad_case; |
|---|
| 194 | return LJ::ad_display( type => 'app', orient => 'BML-App-Confirm', use_wrapper => 0 ); |
|---|
| 195 | }); |
|---|
| 196 | |
|---|
| 197 | #switch of notifications to parent comment poster when commenting in SUP Managed journals |
|---|
| 198 | LJ::register_hook('talklib_email_parent_comment_poster', sub { |
|---|
| 199 | my %opts = @_; |
|---|
| 200 | |
|---|
| 201 | my $user = $opts{user}; |
|---|
| 202 | my $journal = $opts{journal}; |
|---|
| 203 | my $talkid = $opts{talkid}; |
|---|
| 204 | |
|---|
| 205 | if ($LJ::SUP_MANAGED_JOURNALS{$journal->user}) { |
|---|
| 206 | my $cmtobj = LJ::Comment->new($journal, jtalkid => $talkid); |
|---|
| 207 | my $ev = LJ::Event::JournalNewComment->new($cmtobj); |
|---|
| 208 | my $notification = LJ::NotificationMethod::Email->new($user); |
|---|
| 209 | $notification->notify($ev); |
|---|
| 210 | |
|---|
| 211 | return 1; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | return; |
|---|
| 215 | }); |
|---|
| 216 | |
|---|
| 217 | LJ::register_hook("login_redirect_extra", sub { |
|---|
| 218 | my $host = shift; |
|---|
| 219 | return unless $LJ::OPENID_DEST_DOMAIN_TRUSTED{ $host }; |
|---|
| 220 | |
|---|
| 221 | # This P3P header should be set to enable login when login page is in <iframe> tag on the other site |
|---|
| 222 | eval{ |
|---|
| 223 | my $r = Apache->request; |
|---|
| 224 | my $header_name = 'P3P'; |
|---|
| 225 | my $header_body = 'CP="NON DSP COR CUR ADM DEV PSA PSD OUR UNR BUS UNI COM NAV INT DEM STA"'; |
|---|
| 226 | $r->header_out($header_name, $header_body); |
|---|
| 227 | $r->err_header_out($header_name, $header_body); |
|---|
| 228 | }; |
|---|
| 229 | }); |
|---|
| 230 | |
|---|
| 231 | LJ::register_hook("journal_spotlight_domain", sub { |
|---|
| 232 | return "sup" if LJ::SUP->is_remote_sup; |
|---|
| 233 | return; |
|---|
| 234 | }); |
|---|
| 235 | |
|---|
| 236 | ## link to SUP mobile page from standard page /htdocs/manage/mobile.bml |
|---|
| 237 | LJ::register_hook('mobile_footer_additional_block', sub { |
|---|
| 238 | my $remote = LJ::get_remote(); |
|---|
| 239 | return unless $remote; |
|---|
| 240 | return unless LJ::SUP->is_sup_enabled($remote); |
|---|
| 241 | return q[<br><div style='font-size: 1.2em; font-weight: bold'><a href="<?siteroot?>/sup/mobile.bml?force=1">Mobile features provided by SUP</a></div><br>]; |
|---|
| 242 | }); |
|---|
| 243 | |
|---|
| 244 | ## Defines whether redirect should be performed from the current page (passed as input params |
|---|
| 245 | ## to the last choosen mobile page (from SUP to LJ or from LJ to SUP) |
|---|
| 246 | LJ::register_hook('need_mobile_page_redirect', sub { |
|---|
| 247 | my %params = @_; |
|---|
| 248 | |
|---|
| 249 | my $remote = LJ::get_remote(); |
|---|
| 250 | return unless $remote; |
|---|
| 251 | |
|---|
| 252 | ## Do not redirect non-SUP users anywhere. |
|---|
| 253 | return unless LJ::SUP->is_sup_enabled($remote); |
|---|
| 254 | |
|---|
| 255 | ## Rules are: |
|---|
| 256 | ## Remember the page user visited last time. |
|---|
| 257 | ## Redirect user to that page next time. |
|---|
| 258 | ## If there is a flag in URL (?force=1), then do not redirect and remember the page |
|---|
| 259 | |
|---|
| 260 | my $called_from = Apache->request->uri; |
|---|
| 261 | my $prop_name = 'last_chosen_mobile_page'; |
|---|
| 262 | my $preferred_mobile_page = $remote->prop($prop_name); |
|---|
| 263 | if (!$preferred_mobile_page) { |
|---|
| 264 | ## no page is selected yet - no redirect needed |
|---|
| 265 | $remote->set_prop($prop_name, $called_from); |
|---|
| 266 | return; |
|---|
| 267 | } |
|---|
| 268 | elsif ($preferred_mobile_page ne $called_from) { |
|---|
| 269 | if ($params{get_args}->{force}) { |
|---|
| 270 | ## save the page, no redirect |
|---|
| 271 | $remote->set_prop($prop_name, $called_from); |
|---|
| 272 | return; |
|---|
| 273 | } |
|---|
| 274 | else{ |
|---|
| 275 | ## Preferred page and current one does not match, |
|---|
| 276 | ## no force flag is set, so do redirect. |
|---|
| 277 | ## Redirect must be with full URL (http://...), |
|---|
| 278 | ## otherwise it will be handled by Apache internally |
|---|
| 279 | return "$LJ::SITEROOT$preferred_mobile_page"; |
|---|
| 280 | } |
|---|
| 281 | } |
|---|
| 282 | return; |
|---|
| 283 | }); |
|---|
| 284 | |
|---|
| 285 | ## |
|---|
| 286 | ## Hook 'modify_navbar' is called from LJ/Nav.pm |
|---|
| 287 | ## and from 'cgi-bin/bml/scheme/dystopia.look' |
|---|
| 288 | ## |
|---|
| 289 | LJ::register_hook('modify_navbar', sub{ |
|---|
| 290 | my $aref = shift; |
|---|
| 291 | |
|---|
| 292 | ## |
|---|
| 293 | ## New menu items are for SUP users only |
|---|
| 294 | ## |
|---|
| 295 | return unless LJ::SUP->is_remote_sup(); |
|---|
| 296 | |
|---|
| 297 | ## |
|---|
| 298 | ## Do not add this crumb if menu is plain (has no subitems). |
|---|
| 299 | ## (see $opts->{'barenav'} in LJ/Nav.pm) |
|---|
| 300 | ## |
|---|
| 301 | if (grep { $_->{links} } @$aref) { |
|---|
| 302 | my $ljru_menu_id = 'ljru-menu'; |
|---|
| 303 | my $ljru_menu = { |
|---|
| 304 | name => BML::ml('ljru.nav.ljru'), |
|---|
| 305 | id => $ljru_menu_id, |
|---|
| 306 | url => 'http://www.livejournal.ru/', |
|---|
| 307 | links => [ |
|---|
| 308 | { url => 'http://avito.livejournal.ru/', |
|---|
| 309 | text => BML::ml('ljru.nav.avito')}, |
|---|
| 310 | { url => 'http://www.livejournal.ru/themes', |
|---|
| 311 | text => BML::ml('ljru.nav.themes')}, |
|---|
| 312 | { url => 'http://www.livejournal.ru/photos', |
|---|
| 313 | text => BML::ml('ljru.nav.photo')}, |
|---|
| 314 | { url => 'http://www.livejournal.ru/ratings', |
|---|
| 315 | text => BML::ml('ljru.nav.ratings')}, |
|---|
| 316 | { url => 'http://www.livejournal.ru/communities', |
|---|
| 317 | text => BML::ml('ljru.nav.communities')}, |
|---|
| 318 | { url => 'http://www.livejournal.ru/celebrities', |
|---|
| 319 | text => BML::ml('ljru.nav.celebrities')}, |
|---|
| 320 | { url => 'http://www.livejournal.ru/counter', |
|---|
| 321 | text => BML::ml('ljru.nav.mystats')}, |
|---|
| 322 | ], |
|---|
| 323 | }; |
|---|
| 324 | |
|---|
| 325 | ## Add avito menu item into the Journal menu block |
|---|
| 326 | unless ($LJ::DISABLED{avito}) { |
|---|
| 327 | my @journal_item = grep { $_->{id} eq "horizon-menu-journal" || $_->{id} eq 'vertigo-menu-journal' } @$aref; |
|---|
| 328 | if (@journal_item) { |
|---|
| 329 | unless (grep { $_->{url} eq $LJ::BAZAR_URL } @{$journal_item[0]->{links}} ) { |
|---|
| 330 | push @{$journal_item[0]->{links}}, {url => $LJ::BAZAR_URL, text => BML::ml('ljru.nav.post_to_bazar')}; |
|---|
| 331 | } |
|---|
| 332 | } |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | ## |
|---|
| 336 | ## In horizon scheme, replace the first item. |
|---|
| 337 | ## Othewise, insert as first item. |
|---|
| 338 | ## |
|---|
| 339 | if ($aref->[0]->{id} eq "horizon-menu-home") { |
|---|
| 340 | $aref->[0] = $ljru_menu; |
|---|
| 341 | } |
|---|
| 342 | else{ |
|---|
| 343 | ## add the SUP menu unless it has been already added |
|---|
| 344 | unless (grep { $_->{id} eq $ljru_menu_id } @$aref) { |
|---|
| 345 | unshift @$aref, $ljru_menu; |
|---|
| 346 | } |
|---|
| 347 | } |
|---|
| 348 | } |
|---|
| 349 | else{ |
|---|
| 350 | my $siteroot = $LJ::SITEROOT; |
|---|
| 351 | @$aref = ( |
|---|
| 352 | { 'name' => BML::ml('ljru.nav.in_focus'), 'url' => 'http://www.livejournal.ru/' }, |
|---|
| 353 | { 'name' => BML::ml('horizon.barenav.create'), 'url' => "$siteroot/create.bml" }, |
|---|
| 354 | { 'name' => BML::ml('horizon.barenav.post'), 'url' => "$siteroot/update.bml" }, |
|---|
| 355 | { 'name' => BML::ml('horizon.barenav.explore'), 'url' => "$siteroot/site/search.bml" }, |
|---|
| 356 | { 'name' => BML::ml('horizon.barenav.giftshop'),'url' => "$siteroot/shop/" }, |
|---|
| 357 | { 'name' => BML::ml('ljru.nav.avito'), 'url' => 'http://avito.livejournal.ru/' }, |
|---|
| 358 | ); |
|---|
| 359 | } |
|---|
| 360 | return; |
|---|
| 361 | }); |
|---|
| 362 | |
|---|
| 363 | LJ::register_hook("add_extra_cells_in_controlstrip", sub { |
|---|
| 364 | my $rret = shift; |
|---|
| 365 | |
|---|
| 366 | my $journal = LJ::get_active_journal(); |
|---|
| 367 | return unless $journal; |
|---|
| 368 | return unless LJ::SUP->is_sup_enabled($journal); |
|---|
| 369 | |
|---|
| 370 | my $ret = ""; |
|---|
| 371 | |
|---|
| 372 | $ret .= "<td id='lj_controlstrip_search' class='lj_controlstrip_search_sup'>"; |
|---|
| 373 | $ret .= "<form action='http://search.livejournal.ru/ljsearch' method='get'>"; |
|---|
| 374 | $ret .= "<table cellspacing='10'>"; |
|---|
| 375 | $ret .= "<tr>"; |
|---|
| 376 | $ret .= "<td style='width:100%'>"; |
|---|
| 377 | $ret .= "<input id='lj_controlstrip_search_input_text' class='lj_controlstrip_search_input_text_sup' type='text' name='query' />"; |
|---|
| 378 | $ret .= "</td>"; |
|---|
| 379 | $ret .= "<td>"; |
|---|
| 380 | $ret .= "<input id='lj_controlstrip_search_submit' class='lj_controlstrip_search_submit_sup' type='submit' value='search' />"; |
|---|
| 381 | $ret .= "</td>"; |
|---|
| 382 | $ret .= "</tr>"; |
|---|
| 383 | $ret .= "</table>"; |
|---|
| 384 | $ret .= "<input type='hidden' name='ie' value='utf-8' />"; |
|---|
| 385 | $ret .= "</form>"; |
|---|
| 386 | $ret .= "</td>"; |
|---|
| 387 | $ret .= "<td style='width:143px'><div style='width:143px'></div></td>"; |
|---|
| 388 | |
|---|
| 389 | $$rret .= $ret; |
|---|
| 390 | }); |
|---|
| 391 | |
|---|
| 392 | LJ::register_hook('modify_scheme_list', sub { |
|---|
| 393 | my $list = shift; |
|---|
| 394 | |
|---|
| 395 | if (!LJ::SUP->is_remote_sup()) { |
|---|
| 396 | @$list = grep { !$_->{sup_only} } @$list; |
|---|
| 397 | } |
|---|
| 398 | }); |
|---|
| 399 | |
|---|
| 400 | LJ::register_hook('rewrite_redirect_after_create', sub { |
|---|
| 401 | my $u = shift; |
|---|
| 402 | if (LJ::SUP->is_sup_enabled($u)) { |
|---|
| 403 | # if user is SUP enabled user - we skip step2.bml page emulating as though user has choosen "Plus" type. |
|---|
| 404 | # below is the code from apropriate case in step2.bml |
|---|
| 405 | LJ::run_hook('set_default_style', $u); |
|---|
| 406 | |
|---|
| 407 | my $redirect = undef; |
|---|
| 408 | LJ::run_hooks("create.bml_postsession", { |
|---|
| 409 | post => {'choose_plus.x' => 1, 'choose_plus.y' => 1}, |
|---|
| 410 | u => $u, |
|---|
| 411 | redirect => \$redirect, |
|---|
| 412 | }); |
|---|
| 413 | $redirect ||= "$LJ::SITEROOT/manage/profile/"; |
|---|
| 414 | return $redirect; |
|---|
| 415 | } |
|---|
| 416 | return undef; |
|---|
| 417 | }); |
|---|
| 418 | |
|---|
| 419 | LJ::register_hook('add_extra_fields_in_postreg_settings', sub { |
|---|
| 420 | my $u = shift; |
|---|
| 421 | my $ret = ''; |
|---|
| 422 | if (LJ::SUP->is_sup_enabled($u)) { |
|---|
| 423 | $ret .= "<form method='post' action='$LJ::SITEROOT/manage/account/'><p><label for=''>"; |
|---|
| 424 | $ret .= BML::ml('ljcom.userinfo.accounttype') . ':</label>'; |
|---|
| 425 | $ret .= ' ' . LJ::LJcom::acct_name($u->{'caps'}) . ' '; |
|---|
| 426 | $ret .= LJ::form_auth(); |
|---|
| 427 | $ret .= "<input style='font-size:11px' type='submit' value=\"" . BML::ml('.change_account_type') . "\"/></p></form>"; |
|---|
| 428 | } |
|---|
| 429 | return $ret; |
|---|
| 430 | }); |
|---|
| 431 | |
|---|
| 432 | LJ::register_hook('payment_completed', sub { |
|---|
| 433 | # should last until 01.01.2008 |
|---|
| 434 | return if time > 1199134800; |
|---|
| 435 | |
|---|
| 436 | my $param = shift; |
|---|
| 437 | # LJ::Pay::Payment object or payment id may be passed as an argument |
|---|
| 438 | my $pmt = ref $param ? $param : LJ::Pay::Payment->load(payid => int $param); |
|---|
| 439 | return unless $pmt; |
|---|
| 440 | |
|---|
| 441 | return unless $pmt->get_used eq 'Y' && $pmt->get_forwhat eq 'cart'; |
|---|
| 442 | |
|---|
| 443 | my $payer = LJ::load_userid($pmt->get_userid); |
|---|
| 444 | return unless LJ::isu($payer) && LJ::SUP->is_sup_enabled($payer); |
|---|
| 445 | |
|---|
| 446 | my $coupons_to_generate = scalar grep { $_->get_item eq 'paidacct' && $_->get_qty == 12 } $pmt->get_items; |
|---|
| 447 | for (1..$coupons_to_generate) { |
|---|
| 448 | # FIXME: '5' should a constant or a config param |
|---|
| 449 | LJ::Pay::new_coupon('dollaroffint', 5, $payer->id, 0, 1); |
|---|
| 450 | } |
|---|
| 451 | }); |
|---|
| 452 | |
|---|
| 453 | LJ::register_hook('extra_privacy_options', sub { |
|---|
| 454 | my $u = shift; |
|---|
| 455 | |
|---|
| 456 | return if $LJ::DISABLED{my_guests_statistics}; |
|---|
| 457 | |
|---|
| 458 | use vars '%ML'; |
|---|
| 459 | local *ML = \%BML::ML; |
|---|
| 460 | my $ret = "<tr><td class='field_name'>$ML{'extra_privacy_options.my_guests_opt_out'}</td>\n<td>"; |
|---|
| 461 | $ret .= LJ::html_check({ |
|---|
| 462 | 'type' => 'check', |
|---|
| 463 | 'name' => 'opt_disable_my_guests', |
|---|
| 464 | 'id' => 'opt_disable_my_guests', |
|---|
| 465 | 'selected' => $u->prop('opt_disable_my_guests'), |
|---|
| 466 | }); |
|---|
| 467 | $ret .= " <label for='opt_disable_my_guests'>$ML{'extra_privacy_options.my_guests_opt_out.label'}</label><br />\n"; |
|---|
| 468 | $ret .= "<span class='helper'>$ML{'extra_privacy_options.my_guests_opt_out.note'}</span>"; |
|---|
| 469 | $ret .= "</td></tr>\n"; |
|---|
| 470 | |
|---|
| 471 | return $ret; |
|---|
| 472 | }); |
|---|
| 473 | |
|---|
| 474 | LJ::register_hook('set_extra_privacy_options', sub { |
|---|
| 475 | my $u = shift; |
|---|
| 476 | my $post = shift; |
|---|
| 477 | |
|---|
| 478 | return if $LJ::DISABLED{my_guests_statistics}; |
|---|
| 479 | |
|---|
| 480 | my $val = ($post->{opt_disable_my_guests}) ? 1 : 0; |
|---|
| 481 | $u->set_prop('opt_disable_my_guests', $val); |
|---|
| 482 | }); |
|---|
| 483 | |
|---|
| 484 | ## |
|---|
| 485 | ## This hook is called from both S2 journals and talkread.bml |
|---|
| 486 | ## |
|---|
| 487 | LJ::register_hook('show_thread_expander', sub { |
|---|
| 488 | return 0 if $LJ::DISABLED{thread_expander}; |
|---|
| 489 | my $u = LJ::load_userid(Apache->request->notes("journalid")); |
|---|
| 490 | return 1 if $u && $u->get_cap('thread_expander'); |
|---|
| 491 | my $remote = LJ::get_remote(); |
|---|
| 492 | return 1 if $remote && $remote->get_cap('thread_expander'); |
|---|
| 493 | return 0; |
|---|
| 494 | }); |
|---|
| 495 | |
|---|
| 496 | LJ::register_hook("subscriptions_manage_my_account_extra", sub { |
|---|
| 497 | my $remote = shift; |
|---|
| 498 | |
|---|
| 499 | return undef unless LJ::SUP->is_remote_sup(); |
|---|
| 500 | return LJ::Subscription::Pending->new($remote, event => 'SupOfficialPost', ); |
|---|
| 501 | }); |
|---|
| 502 | |
|---|
| 503 | LJ::register_hook("after_entry_post_extra_options", sub { |
|---|
| 504 | my %opts = @_; |
|---|
| 505 | my $ju = $opts{user}; |
|---|
| 506 | my $itemlink = $opts{itemlink}; |
|---|
| 507 | |
|---|
| 508 | return if $LJ::DISABLED{avito}; |
|---|
| 509 | return undef unless LJ::SUP->is_remote_sup(); |
|---|
| 510 | |
|---|
| 511 | use vars '%ML'; |
|---|
| 512 | local *ML = \%BML::ML; |
|---|
| 513 | return "<li><a href=\"$LJ::BAZAR_POST_URL$itemlink\">".$ML{'after_entry_post_extra_option'}."</a></li>\n"; |
|---|
| 514 | }); |
|---|
| 515 | |
|---|
| 516 | LJ::register_hook("rss_extra_info", sub { |
|---|
| 517 | my $journalinfo = shift; |
|---|
| 518 | my $item = shift; |
|---|
| 519 | my $u = $journalinfo->{u}; |
|---|
| 520 | return '' unless LJ::SUP->is_sup_enabled($u); |
|---|
| 521 | |
|---|
| 522 | my %params; |
|---|
| 523 | $params{adzone} = 'LJCom_Rss_1x1'; |
|---|
| 524 | $params{i1} = $u->id; |
|---|
| 525 | $params{r} = int(rand(1e9)); |
|---|
| 526 | $params{vid} = int(rand(1e9)); |
|---|
| 527 | $params{srv} = 1; |
|---|
| 528 | my $url = $LJ::SUP_BASE_ADCALL_URL . "?" . join('&', |
|---|
| 529 | map { "$_=" . LJ::eurl($params{$_}) } |
|---|
| 530 | keys %params); |
|---|
| 531 | return "<img src='$url' width='1' height='1' border='0'>"; |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | }); |
|---|
| 535 | |
|---|
| 536 | |
|---|
| 537 | 1; |
|---|