MyBB Support

Registered time function MyBB?

Submitted by AndresXZ09, , Thread ID: 2741

Thread Closed

RE: Registered time function MyBB?

AndresXZ09
Closed Account
Level:
0
Reputation:
30
Posts:
1.22K
Likes:
139
Credits:
1.51K
OP
12-04-2015, 06:06 PM
#11
12-04-2015, 06:04 PM
AmN Wrote:
just create a plugin file: amn.php

place my code in it.

add:

Code:
function amn_info()
{
   return array(
'name'=> 'AmN',
'description'=> 'Noh.',
'website'=> 'http://askamn.com/',
'author'=> 'AmN',
'authorsite'=> 'http://askamn.com',
'version'=> '1.0',
'compatibility'=> '14*,15*,16*,17*,18*',
'guid'=> ''
);
}
function amn_activate()
{
   //BLA
}
$plugins->add_hook( 'postbit', 'years_of_service' );

function years_of_service(&$post)
{
        $yearsofservice = date( 'Y', TIME_NOW - $post['userregdate'] );
        $years = ( $yearsofservice == 1  ) ? 'year' : 'years';
        return str_replace( '<years_of_service>',' $yearsofservice . ' ' . $years . ' of service', $post['message'] );
}

Hell, I want to learn but I am not going to do so if you just do everything for me <.<

RE: Registered time function MyBB?

Sozin
Nan Ihier Gelair Mordor
Divine
Level:
0
Reputation:
91
Posts:
2.33K
Likes:
375
Credits:
11K
12-04-2015, 07:02 PM
#12
Meh, I thought you guys love Spoonfeeding.
Do not let your difficulties fill you with anxiety, after all it is only in the darkest nights that stars shine more brightly. - Ali(a.s)

Developer( PHP, Python, C++, HTML+CSS, JS I am available for Hire. Message Me for details.

RE: Registered time function MyBB?

linkzy
No pressure, no diamonds
Level:
0
Reputation:
181
Posts:
5.34K
Likes:
341
Credits:
54
12-04-2015, 07:06 PM
This post was last modified: 12-04-2015, 07:13 PM by linkzy
#13
is there a way to show it in postbit if the user is only register for more than 1 year :yus: Tongue @amn
| A | v4hl| Addicted | Senpai | Sui | Sensei | H | fdigl |


RE: Registered time function MyBB?

AndresXZ09
Closed Account
Level:
0
Reputation:
30
Posts:
1.22K
Likes:
139
Credits:
1.51K
OP
12-04-2015, 07:14 PM
#14
12-04-2015, 07:02 PM
AmN Wrote:
Meh, I thought you guys love Spoonfeeding.

So far with you code I did this

Code:
<?php

if(!defined("IN_MYBB")) {
die("You can not access this file directly. Please make sure IN_MYBB is defined.");
}

$plugins->add_hook('postbit', 'years_of_service');


// Information about the plugin
function yos_info()
{
return array(
'name' => 'Years of Service',
'description' => 'Add years of service to users post bit.',
'website' => 'http://askamn.com',
'author' => 'AmN',
'authorsite' => 'http://askamn.com',
'version' => '1.0',
'compatibility' => '*',
'gid' => '',
);
}

// Activate or deactivate the plugin
function yos_activate() {
global $db;

$yos_group = array(
'gid' => 'NULL',
'name' => 'yosplugin',
'title' => 'Years of Service',
'description' => 'Settings for the plugin',
'disporder' => "1",
'isdefault' => "1",
);
$db->insert_query('settinggroups', $yos_group);
$gid = $db->insert_id();

// Enable
$yos_setting = array(
'sid' => 'NULL',
'name' => 'yos_enable',
'title' => 'Do you want to enable the plugin?',
'description' => 'If you set this option to yes, this plugin will be active on your forum.',
'optionscode' => 'yesno',
'value' => '1',
'disporder' => 1,
'gid' => intval($gid),
);
$db->insert_query('settings', $yos_setting);
rebuild_settings();
}

// Deactivate
function yos_deactivate()
{
global $db;
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('yos_enable')");
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='yosplugin'");
rebuild_settings();
}

function years_of_service(){
global $mybb;

if ($mybb->settings['yos_enable'] == 1){
function years_of_service(&$post)
{
$yearsofservice = date('Y', TIME_NOW - $post['userregdate']);
$years = ($yearsofservice == 1)?'year':'years';
return str_replace('<years_of_service>','$yearsofservice.''.$years.'of service',$post['message']);
}
}
}

?>

Is that ok?

RE: Registered time function MyBB?

Sozin
Nan Ihier Gelair Mordor
Divine
Level:
0
Reputation:
91
Posts:
2.33K
Likes:
375
Credits:
11K
12-04-2015, 07:15 PM
#15
12-04-2015, 07:06 PM
linkzy Wrote:
is there a way to show it in postbit if the user is only register for more than 1 year :yus: Tongue @amn

huh.

/* Fall back if its less than 1 year */
if( $yearsofservice < 1 )
return;

what am i doing? I should have done it with the timestamp, but :fp: No time.
Do not let your difficulties fill you with anxiety, after all it is only in the darkest nights that stars shine more brightly. - Ali(a.s)

Developer( PHP, Python, C++, HTML+CSS, JS I am available for Hire. Message Me for details.

1

RE: Registered time function MyBB?

Sozin
Nan Ihier Gelair Mordor
Divine
Level:
0
Reputation:
91
Posts:
2.33K
Likes:
375
Credits:
11K
12-04-2015, 07:16 PM
#16
12-04-2015, 07:14 PM
AndresXZ09 Wrote:
12-04-2015, 07:02 PM
AmN Wrote:
Meh, I thought you guys love Spoonfeeding.

So far with you code I did this


Code:
<?php

if(!defined("IN_MYBB")) {
die("You can not access this file directly. Please make sure IN_MYBB is defined.");
}

$plugins->add_hook('postbit', 'years_of_service');


// Information about the plugin
function yos_info()
{
return array(
'name' => 'Years of Service',
'description' => 'Add years of service to users post bit.',
'website' => 'http://askamn.com',
'author' => 'AmN',
'authorsite' => 'http://askamn.com',
'version' => '1.0',
'compatibility' => '*',
'gid' => '',
);
}

// Activate or deactivate the plugin
function yos_activate() {
global $db;

$yos_group = array(
'gid' => 'NULL',
'name' => 'yosplugin',
'title' => 'Years of Service',
'description' => 'Settings for the plugin',
'disporder' => "1",
'isdefault' => "1",
);
$db->insert_query('settinggroups', $yos_group);
$gid = $db->insert_id();

// Enable
$yos_setting = array(
'sid' => 'NULL',
'name' => 'yos_enable',
'title' => 'Do you want to enable the plugin?',
'description' => 'If you set this option to yes, this plugin will be active on your forum.',
'optionscode' => 'yesno',
'value' => '1',
'disporder' => 1,
'gid' => intval($gid),
);
$db->insert_query('settings', $yos_setting);
rebuild_settings();
}

// Deactivate
function yos_deactivate()
{
global $db;
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('yos_enable')");
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='yosplugin'");
rebuild_settings();
}

function years_of_service(){
global $mybb;

if ($mybb->settings['yos_enable'] == 1){
function years_of_service(&$post)
{
$yearsofservice = date('Y', TIME_NOW - $post['userregdate']);
$years = ($yearsofservice == 1)?'year':'years';
return str_replace('<years_of_service>','$yearsofservice.''.$years.'of service',$post['message']);
}
}
}

?>

Is that ok?

why dont you install - run and check it lol.
Do not let your difficulties fill you with anxiety, after all it is only in the darkest nights that stars shine more brightly. - Ali(a.s)

Developer( PHP, Python, C++, HTML+CSS, JS I am available for Hire. Message Me for details.

RE: Registered time function MyBB?

AndresXZ09
Closed Account
Level:
0
Reputation:
30
Posts:
1.22K
Likes:
139
Credits:
1.51K
OP
12-04-2015, 07:17 PM
This post was last modified: 12-04-2015, 07:17 PM by AndresXZ09
#17
12-04-2015, 07:15 PM
AmN Wrote:
12-04-2015, 07:06 PM
linkzy Wrote:
is there a way to show it in postbit if the user is only register for more than 1 year :yus: Tongue @amn

huh.

/* Fall back if its less than 1 year */
if( $yearsofservice < 1 )
return;

what am i doing? I should have done it with the timestamp, but :fp: No time.

I don't understand :noh:

Cuz you're the senpai here

RE: Registered time function MyBB?

linkzy
No pressure, no diamonds
Level:
0
Reputation:
181
Posts:
5.34K
Likes:
341
Credits:
54
12-04-2015, 07:27 PM
#18
@AmN Tested the code doesnt works - Parse error: syntax error, unexpected '' . $years . '' (T_CONSTANT_ENCAPSED_STRING) in C:\wamp\www\mybb\inc\plugins\test.php on line 33
| A | v4hl| Addicted | Senpai | Sui | Sensei | H | fdigl |


RE: Registered time function MyBB?

AndresXZ09
Closed Account
Level:
0
Reputation:
30
Posts:
1.22K
Likes:
139
Credits:
1.51K
OP
12-04-2015, 07:28 PM
#19
12-04-2015, 07:27 PM
linkzy Wrote:
@AmN Tested the code doesnt works - Parse error: syntax error, unexpected '' . $years . '' (T_CONSTANT_ENCAPSED_STRING) in C:\wamp\www\mybb\inc\plugins\test.php on line 33

If you just copy and paste the code it's not going to work xd

RE: Registered time function MyBB?

linkzy
No pressure, no diamonds
Level:
0
Reputation:
181
Posts:
5.34K
Likes:
341
Credits:
54
12-04-2015, 07:30 PM
#20
12-04-2015, 07:28 PM
AndresXZ09 Wrote:
12-04-2015, 07:27 PM
linkzy Wrote:
@AmN Tested the code doesnt works - Parse error: syntax error, unexpected '' . $years . '' (T_CONSTANT_ENCAPSED_STRING) in C:\wamp\www\mybb\inc\plugins\test.php on line 33

If you just copy and paste the code it's not going to work xd

yeah :3 - trying to fix it :#
| A | v4hl| Addicted | Senpai | Sui | Sensei | H | fdigl |



Users browsing this thread: 1 Guest(s)