Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Commit

Permalink
add adverticement complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Fish Thirteen committed Jun 10, 2014
1 parent 5b7f5e4 commit b759185
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
42 changes: 27 additions & 15 deletions MoegirlAD.hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,42 @@
*
*/
final class MoegirlADHooks {
public static function advertiseBottom($skin, &$text) {
$text = "Hello, World";
return true;
}

public static function onSkinAfterContent(&$data, Skin $skin) {
$val = "Not Loggin";

$currentUser = RequestContext::getMain()->getUser();
global $wgMoegirlADADCode;

if (is_object($currentUser) && $currentUser->isLoggedIn()) {
$editCount = $currentUser->getEditCount();
if (MoegirlADHooks::shouldShowADs()) {
$data .= $wgMoegirlADADCode;
}
}

if ($editCount != null && $editCount > 0) {
$val = "Has edited";
} else {
$val = "Not edited";
}
public static function onSiteNoticeAfter(&$siteNotice, $skin) {
global $wgMoegirlADADCode;

if (MoegirlADHooks::shouldShowADs()) {
$siteNotice = $wgMoegirlADADCode . $siteNotice;
}
$data = $val;
}


/**
* Check if the advertice should be display
*
* @return boolean
*/
public static function shouldShowADs() {
global $wgMoegirlADEnabled;
global $wgMoegirlADADCode;

if ($wgMoegirlADEnabled && $wgMoegirlADADCode != "") {
$currentUser = RequestContext::getMain()->getUser();

//只对未登录用户和没有编辑过任何条目的用户显示广告
return !(is_object($currentUser) && $currentUser->isLoggedIn() && $currentUser->getEditCount() != null && $currentUser->getEditCount() > 0);
} else {
return false;
}
}
}


Expand Down
17 changes: 15 additions & 2 deletions MoegirlAD.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,33 @@


/*
* Options:
* Options: (Check these settings in LocalSettings.php file)
*
* $wgMoegirlADEnabled
* - determine if show advertisement in moegirl.
*
* $wgMoegirlADADCode
* - The adverticement code form the advertising company
* E.g.
* $wgMoegirlADADCode = <<<EOD
* <!-- 728*90 -->
* <div id='div-gpt-ad-1388996185454-0' style='width:728px; height:90px;'>
* <script type='text/javascript'>
* googletag.cmd.push(function() { googletag.display('div-gpt-ad-1388996185454-0'); });
* </script>
* </div>
* EOD;
*
*/
$wgMoegirlADEnabled = true;
$wgMoegirlADADCode = "";



$wgAutoloadClasses['MoegirlADHooks'] = __DIR__ . '/MoegirlAD.hooks.php';


$wgHooks['SkinAfterBottomScripts'][] = 'MoegirlADHooks::advertiseBottom';
$wgHooks['SkinAfterContent'][] = 'MoegirlADHooks::onSkinAfterContent';
$wgHooks['SiteNoticeAfter'][] = 'MoegirlADHooks::onSiteNoticeAfter';

?>

0 comments on commit b759185

Please sign in to comment.