Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 how do i bring the Xthread field into the portal?
ollie2015 Offline
Member
***
Posts: 90
Joined: Jan 2015
Post: #11
RE: how do i bring the Xthread field into the portal?
all it does is put a conditional on which thread to pull, all the normal contents show up
09-21-2015 07:29 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #12
RE: how do i bring the Xthread field into the portal?
Conditional in where?

09-21-2015 07:30 AM
Find all posts by this user Quote this message in a reply
ollie2015 Offline
Member
***
Posts: 90
Joined: Jan 2015
Post: #13
RE: how do i bring the Xthread field into the portal?

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
<?php

/***************************************************************************
 *
 *	OUGC Show in Portal plugin (/inc/plugins/ougc_showinportal.php)
 *	Author: Omar Gonzalez
 *	Copyright: © 2012-2014 Omar Gonzalez
 *
 *	Website: http://omarg.me
 *
 *	Choose what threads to show in portal while creating / editing.
 *
 ***************************************************************************

****************************************************************************
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

// Die if IN_MYBB is not defined, for security reasons.
defined('IN_MYBB') or die('Direct initialization of this file is not allowed.');

// Run/Add Hooks
if(defined('IN_ADMINCP'))
{
	$plugins->add_hook('admin_config_settings_start', array('OUGC_ShowInPortal', 'lang_load'));
	$plugins->add_hook('admin_style_templates_set', array('OUGC_ShowInPortal', 'lang_load'));
	$plugins->add_hook('admin_config_settings_change', array('OUGC_ShowInPortal', 'lang_load'));
	$plugins->add_hook('admin_formcontainer_end', 'ougc_showinportal_modtools');
	$plugins->add_hook('admin_config_mod_tools_add_thread_tool_commit', 'ougc_showinportal_modtools_commit');
	$plugins->add_hook('admin_config_mod_tools_edit_thread_tool_commit', 'ougc_showinportal_modtools_commit');
}
else
{
	global $settings;

	$plugins->add_hook('moderation_start', 'ougc_showinportal_moderation');
	$plugins->add_hook('newthread_end', 'ougc_showinportal_newthread_end');
	$plugins->add_hook('datahandler_post_insert_thread', 'ougc_showinportal_insert_thread');
	$plugins->add_hook('showthread_end', 'ougc_showinportal_showthread_end');
	$plugins->add_hook('datahandler_post_insert_post', 'ougc_showinportal_post_insert_post');
	$plugins->add_hook('newreply_end', 'ougc_showinportal_newthread_end');
	$plugins->add_hook('postbit', 'ougc_showinportal_postbit');
	$plugins->add_hook('portal_start', 'ougc_showinportal_portal');
	$plugins->add_hook('xmlhttp_update_post', 'ougc_showinportal_xmlhttp');

	// My Alerts
	$plugins->add_hook('myalerts_load_lang', array('OUGC_ShowInPortal', 'lang_load'));
	$plugins->add_hook('misc_help_helpdoc_start', 'ougc_showinportal_myalerts_helpdoc');
	$plugins->add_hook('myalerts_alerts_output_end', 'ougc_showinportal_myalerts_output');

	if(in_array(THIS_SCRIPT, array('forumdisplay.php', 'showthread.php', 'newthread.php', 'newreply.php')))
	{
		global $templatelist;

		if(!isset($templatelist))
		{
			$templatelist = '';
		}
		else
		{
			$templatelist .= ',';
		}

		$templatelist .= 'ougcshowinportal_input';
	}
}

// PLUGINLIBRARY
defined('PLUGINLIBRARY') or define('PLUGINLIBRARY', MYBB_ROOT.'inc/plugins/pluginlibrary.php');

// Plugin API
function ougc_showinportal_info()
{
	global $lang, $showinportal;
	$showinportal->lang_load();

	return array(
		'name'			=> 'OUGC Show in Portal',
		'description'	=> $lang->setting_group_ougc_showinportal_desc,
		'website'		=> 'http://omarg.me',
		'author'		=> 'Omar G.',
		'authorsite'	=> 'http://omarg.me',
		'version'		=> '1.8',
		'versioncode'	=> 1800,
		'compatibility'	=> '18*',
		'myalerts'		=> 105,
		'pl'			=> array(
			'version'	=> 12,
			'url'		=> 'http://mods.mybb.com/view/pluginlibrary'
		)
	);
}

// _activate() routine
function ougc_showinportal_activate()
{
	global $PL, $lang, $cache, $showinportal;
	$showinportal->lang_load();
	ougc_showinportal_deactivate();

	// Add settings group
	$PL->settings('ougc_showinportal', $lang->setting_group_ougc_showinportal, $lang->setting_group_ougc_showinportal_desc, array(
		'groups'	=> array(
		   'title'			=> $lang->setting_ougc_showinportal_groups,
		   'description'	=> $lang->setting_ougc_showinportal_groups_desc,
		   'optionscode'	=> 'groupselect',
			'value'			=>	'3,4,6',
		),
		'forums'	=> array(
		   'title'			=> $lang->setting_ougc_showinportal_forums,
		   'description'	=> $lang->setting_ougc_showinportal_forums_desc,
		   'optionscode'	=> 'forumselect',
			'value'			=>	'',
		),
		'tag'		=> array(
		   'title'			=> $lang->setting_ougc_showinportal_tag,
		   'description'	=> $lang->setting_ougc_showinportal_tag_desc,
		   'optionscode'	=> 'text',
			'value'			=>	'[!--more--]',
		),
		'myalerts'	=> array(
		   'title'			=> $lang->setting_ougc_showinportal_myalerts,
		   'description'	=> $lang->setting_ougc_showinportal_myalerts_desc,
		   'optionscode'	=> 'yesno',
			'value'			=>	0,
		)
	));

	// Add template group
	$PL->templates('ougcshowinportal', '<lang:setting_group_ougc_showinportal>', array(
		'input'		=> '<br /><label><input type="checkbox" class="checkbox" name="{$name}" value="1"{$checked} />&nbsp;{$message}</label>'
	));

	// Modify templates
	require_once MYBB_ROOT.'inc/adminfunctions_templates.php';
	find_replace_templatesets('newreply_modoptions', '#'.preg_quote('stick_thread}</label>').'#', 'stick_thread}</label><!--OUGC_SHOWINPORTAL-->');
	find_replace_templatesets('showthread_quickreply', '#'.preg_quote('{$closeoption}').'#', '{$closeoption}<!--OUGC_SHOWINPORTAL-->');

	// Insert/update version into cache
	$plugins = $cache->read('ougc_plugins');
	if(!$plugins)
	{
		$plugins = array();
	}

	$info = ougc_showinportal_info();

	if(!isset($plugins['showinportal']))
	{
		$plugins['showinportal'] = $info['versioncode'];
	}

	/*~*~* RUN UPDATES START *~*~*/
	if($plugins['showinportal'] <= 1200)
	{
		// Update DB entries
		ougc_showinportal_install();
	}
	/*~*~* RUN UPDATES END *~*~*/

	$plugins['showinportal'] = $info['versioncode'];
	$cache->update('ougc_plugins', $plugins);
}

// _deactivate() routine
function ougc_showinportal_deactivate($rebuilt=true)
{
	ougc_showinportal_pl_check();

	// Revert template edits
	require_once MYBB_ROOT.'inc/adminfunctions_templates.php';
	find_replace_templatesets('newreply_modoptions', '#'.preg_quote('<!--OUGC_SHOWINPORTAL-->').'#', '', 0);
	find_replace_templatesets('showthread_quickreply', '#'.preg_quote('<!--OUGC_SHOWINPORTAL-->').'#', '', 0);
	find_replace_templatesets('forumdisplay_inlinemoderation', '#'.preg_quote('<!--OUGC_SHOWINPORTAL-->').'#', '', 0);
	find_replace_templatesets('showthread_moderationoptions', '#'.preg_quote('<!--OUGC_SHOWINPORTAL-->').'#', '', 0);
}

// _install() routine
function ougc_showinportal_install()
{
	global $db;

	// Add DB entries
	if(!$db->field_exists('showinportal', 'threads'))
	{
		$db->add_column('threads', 'showinportal', 'int(1) NOT NULL DEFAULT \'0\'');
	}

	if($db->table_exists('alert_settings') && $db->table_exists('alert_setting_values'))
	{
		$query = $db->simple_select('alert_settings', 'id', 'code=\'ougc_showinportal\'');

		if(!($id = (int)$db->fetch_field($query, 'id')))
		{
			$id = (int)$db->insert_query('alert_settings', array('code' => 'ougc_showinportal'));
	
			// Only update the first time
			$db->delete_query('alert_setting_values', 'setting_id=\''.$id.'\'');

			$query = $db->simple_select('users', 'uid');
			while($uid = (int)$db->fetch_field($query, 'uid'))
			{
				$settings[] = array(
					'user_id'		=> $uid,
					'setting_id'	=> $id,
					'value'			=> 1
				);
			}

			if(!empty($settings))
			{
				$db->insert_query_multiple('alert_setting_values', $settings);
			}
		}
	}
}

// _is_installed() routine
function ougc_showinportal_is_installed()
{
	global $db;

	return $db->field_exists('showinportal', 'threads');
}

// _uninstall() routine
function ougc_showinportal_uninstall()
{
	global $db, $PL, $cache;
	ougc_showinportal_pl_check();

	// Drop DB entries
	if($db->field_exists('showinportal', 'threads'))
	{
		$db->drop_column('threads', 'showinportal');
	}

	if($db->table_exists('alert_settings'))
	{
		$db->delete_query('alert_settings', 'code=\'ougc_showinportal\'');
	}

	$PL->settings_delete('ougc_showinportal');
	$PL->templates_delete('ougcshowinportal');

	// Delete version from cache
	$plugins = (array)$cache->read('ougc_plugins');

	if(isset($plugins['showinportal']))
	{
		unset($plugins['showinportal']);
	}

	if(!empty($plugins))
	{
		$cache->update('ougc_plugins', $plugins);
	}
	else
	{
		$PL->cache_delete('ougc_plugins');
	}
}

// PluginLibrary dependency check & load
function ougc_showinportal_pl_check()
{
	global $lang, $showinportal;
	$showinportal->lang_load();
	$info = ougc_showinportal_info();

	if(!file_exists(PLUGINLIBRARY))
	{
		flash_message($lang->sprintf($lang->ougc_showinportal_pl_required, $info['pl']['url'], $info['pl']['version']), 'error');
		admin_redirect('index.php?module=config-plugins');
		exit;
	}

	global $PL;

	$PL or require_once PLUGINLIBRARY;

	if($PL->version < $info['pl']['version'])
	{
		flash_message($lang->sprintf($lang->ougc_showinportal_pl_old, $info['pl']['url'], $info['pl']['version'], $PL->version), 'error');
		admin_redirect('index.php?module=config-plugins');
		exit;
	}
}

// Moderator Tools
function ougc_showinportal_modtools()
{
	global $mybb, $run_module, $form_container, $lang;

	if(!($run_module == 'config' && !empty($form_container->_title) && !empty($lang->thread_moderation) && $form_container->_title == $lang->thread_moderation && $mybb->get_input('action') != 'add_post_tool' && $mybb->get_input('action') != 'edit_post_tool'))
	{
		return;
	}

	global $form, $showinportal;
	$showinportal->lang_load();

	if($mybb->get_input('action') != 'add_thread_tool' && !isset($mybb->input['showinportal']))
	{
		global $thread_options;

		$mybb->input['showinportal'] = (int)$thread_options['showinportal'];
	}

	$sip = $mybb->get_input('showinportal', 1);
	$sip = ($sip > 3 || $sip < 0 ? 0 : (int)$sip);

	$form_container->output_row($lang->ougc_showinportal_modtool.' <em>*</em>', '', $form->generate_select_box('showinportal', array(
		0	=> $lang->no_change,
		1	=> $lang->ougc_showinportal_modtool_show,
		2	=> $lang->ougc_showinportal_modtool_remove,
		3	=> $lang->toggle
	), $sip, array('id' => 'showinportal')), 'showinportal');
}

// Save moderator tools input
function ougc_showinportal_modtools_commit()
{
	global $mybb;

	if($mybb->request_method == 'post')
	{
		global $db, $thread_options, $update_tool, $new_tool;

		$sip = $mybb->get_input('showinportal', 1);
		$thread_options['showinportal'] = ($sip > 3 || $sip < 0 ? 0 : $sip);

		$var = $mybb->get_input('action') == 'add_thread_tool' ? 'new_tool' : 'update_tool';

		${$var}['threadoptions'] = $db->escape_string(serialize($thread_options));

		if($mybb->get_input('action') == 'add_thread_tool')
		{
			global $tid;

			$db->update_query('modtools', $new_tool, 'tid=\''.$tid.'\'');
		}
	}
}

// Moderation magic
function ougc_showinportal_moderation()
{
	global $mybb;

	global $mybb;

	// Custom moderator tools process
	if(!in_array($mybb->get_input('action'), array('showinportal', 'multishowinportal', 'multiunshowinportal')))
	{
		if(in_array($mybb->get_input('action'), array('reports', 'allreports', 'getip', 'cancel_delayedmoderation', 'delayedmoderation', 'do_delayedmoderation', 'openclosethread', 'stick', 'removeredirects', 'deletethread', 'do_deletethread', 'deletepoll', 'do_deletepoll', 'approvethread', 'unapprovethread', 'deleteposts', 'do_deleteposts', 'mergeposts', 'do_mergeposts', 'move', 'do_move', 'threadnotes', 'do_threadnotes', 'merge', 'do_merge', 'split', 'do_split', 'removesubscriptions', 'multideletethreads', 'do_multideletethreads', 'multiopenthreads', 'multiclosethreads', 'multiapprovethreads', 'multiunapprovethreads', 'multistickthreads', 'multiunstickthreads', 'multimovethreads', 'do_multimovethreads', 'multideleteposts', 'do_multideleteposts', 'multimergeposts', 'do_multimergeposts', 'multisplitposts', 'do_multisplitposts', 'multiapproveposts', 'multiunapproveposts')) || ($tid = $mybb->get_input('action', 1)) < 1)
		{
			return;
		}

		// Took from xThreads START
		control_object($GLOBALS['db'], '
			function simple_select($table, $fields="*", $conditions="", $options=array())
			{
				static $done=false;
				if(!$done && $table == "modtools" && substr($conditions, 0, 4) == "tid=" && empty($options))
				{
					$done = true;
					ougc_showinportal_moderation_custom();
				}
				return parent::simple_select($table, $fields, $conditions, $options);
			}
		');
		// Took from xThreads END

		return;
	}
}

// Took from xThreads START
function ougc_showinportal_moderation_custom()
{
	global $custommod;

	if(!is_object($custommod))
	{
		return;
	}

	control_object($custommod, '
		function execute_thread_moderation($thread_options, $tids)
		{
			if(!$thread_options[\'deletethread\'])
			{
				ougc_showinportal_moderation_custom_do($tids, $thread_options[\'showinportal\']);
			}
			return parent::execute_thread_moderation($thread_options, $tids);
		}
	');
	
}

function ougc_showinportal_moderation_custom_do($tids, $sip)
{
	$sip = ($sip > 3 || $sip < 0 ? 0 : $sip);

	if(!$sip)
	{
		return;
	}

	global $showinportal;

	switch($sip)
	{
		case 1:
		case 2:
			$showinportal->thread_update($sip, $tids);
			break;
		case 3:
			global $db;

			$query = $db->simple_select('threads', 'tid, showinportal', 'tid IN (\''.implode('\',\'', $tids).'\')');
			while($thread = $db->fetch_array($query))
			{
				if($thread['showinportal'])
				{
					$remove[] = (int)$thread['tid'];
				}
				else
				{
					$show[] = (int)$thread['tid'];
				}
			}

			empty($remove) or $showinportal->thread_update(0, $remove);
			empty($show) or $showinportal->thread_update(1, $show);
			break;
	}
}
// Took from xThreads END

// Insert plugin variable at new thread
function ougc_showinportal_newthread_end()
{
	global $modoptions;

	if(!isset($modoptions) || my_strpos($modoptions, '<!--OUGC_SHOWINPORTAL-->') === false)
	{
		return;
	}

	global $showinportal, $mybb, $fid;

	if(!$showinportal->can_moderate($fid))
	{
		return;
	}

	global $templates, $lang, $thread;
	$showinportal->lang_load();

	// Figure out if checked
	if(THIS_SCRIPT == 'newreply.php' && !isset($mybb->input['modoptions']) && !isset($mybb->input['modoptions']['showinportal']) && isset($thread['showinportal']))
	{
		$mybb->input['modoptions']['showinportal'] = (int)$thread['showinportal'];
	}
	$sip = (int)$mybb->input['modoptions']['showinportal'];

	$checked = '';
	if(!empty($sip))
	{
		$checked = ' checked="checked"';
	}

	// Show the option
	$name = 'modoptions[showinportal]';
	$message = $lang->ougc_showinportal_input_newthread;
	eval('$ougc_showinportal = "'.$templates->get('ougcshowinportal_input').'";');

	$modoptions = str_replace('<!--OUGC_SHOWINPORTAL-->', $ougc_showinportal, $modoptions);
}

// Validate thread input
function ougc_showinportal_insert_thread(&$dh)
{
	global $settings;
	$dh->thread_insert_data['showinportal'] = 0;

	// Only moderators  and valid groups can use this
	if(is_moderator($dh->data['fid']))
	{
		global $showinportal;

		// Check if a valid forum
		// Set this thread to be shown in portal
		if($showinportal->can_moderate($dh->data['fid']) && !empty($dh->data['modoptions']['showinportal']))
		{
			$dh->thread_insert_data['showinportal'] = 1;
		}
	}
}

// Quickreply moderation
function ougc_showinportal_showthread_end()
{
	global $showinportal, $settings, $thread;

	if(!$showinportal->can_moderate($thread['fid']))
	{
		return;
	}

	global $templates, $lang, $quickreply, $moderationoptions;
	$showinportal->lang_load();

	// Figure out if checked
	$checked = '';
	if($thread['showinportal'])
	{
		$checked = ' checked="checked"';
	}

	// Show the option
	$name = 'modoptions[showinportal]';
	$message = $lang->ougc_showinportal_input_quickreply;
	eval('$ougc_showinportal = "'.$templates->get('ougcshowinportal_input').'";');

	$quickreply = str_replace('<!--OUGC_SHOWINPORTAL-->', $ougc_showinportal, $quickreply);
}

// Validate reply input
function ougc_showinportal_post_insert_post(&$args)
{
	global $showinportal;

	$thread = get_thread($args->data['tid']);

	if($thread['showinportal'] && !$args->data['modoptions']['showinportal'])
	{
		$showinportal->thread_update(0, $thread['tid']);
	}
	if(!$thread['showinportal'] && $args->data['modoptions']['showinportal'])
	{
		$showinportal->thread_update(1, $thread['tid']);
	}
}

// Remove MyCode from posts (only if visible in portal)
function ougc_showinportal_postbit(&$post)
{
	global $thread, $plugins;
	$plugins->remove_hook('postbit', 'ougc_showinportal_postbit'); // we just need this to run once

	if($thread['firstpost'] != $post['pid'] || !$thread['showinportal'])
	{
		return;
	}

	global $showinportal, $settings;

	if(!$showinportal->can_moderate($thread['fid']))
	{
		return;
	}

	$post['message'] = preg_replace('#'.preg_quote($settings['ougc_showinportal_tag']).'#', '', $post['message']);
}

// AJAX tricks
function ougc_showinportal_xmlhttp()
{
	global $post;

	ougc_showinportal_postbit($post);
}

// Alter portal behavior
function ougc_showinportal_portal()
{
	global $db, $settings;

	control_object($db, '
		function query($string, $hide_errors=0, $write_query=0)
		{
			if(!$write_query && strpos($string, \'ORDER BY t.dateline DESC\'))
			{
				$string = strtr($string, array(
					\'t.closed\' => \'t.showinportal=\\\'1\\\' AND t.closed\'
				));
			}
			if(!$write_query && strpos($string, \'OUNT(t.tid) AS thread\'))
			{
				$string = strtr($string, array(
					\'t.visible\' => \'t.showinportal=\\\'1\\\' AND t.visible\'
				));
			}
			return parent::query($string, $hide_errors, $write_query);
		}
	');

	// Replace MyCode with a "Read More..." kind of link
	if(!empty($settings['ougc_showinportal_tag']))
	{
		global $plugins;

		$plugins->add_hook('portal_announcement', create_function('', 'global $announcement;	ougc_showinportal_cutoff($announcement[\'message\'], $announcement[\'fid\'], $announcement[\'tid\']);'));
	}
}

// Remove the cutoff mycode
function ougc_showinportal_cutoff(&$message, $fid, $tid)
{
	global $settings;

	if(!$message || !$settings['ougc_showinportal_tag'])
	{
		return;
	}

	if(!preg_match('#'.($tag = preg_quote($settings['ougc_showinportal_tag'])).'#', $message))
	{
		return;
	}

	$msg = preg_split('#'.$tag.'#', $message);
	if(!(isset($msg[0]) && my_strlen($msg[0]) >= (int)$settings['minmessagelength']))
	{
		return;
	}

	global $lang, $forum_cache, $showinportal;
	$showinportal->lang_load();

	$forum_cache or cache_forums();

	// Find out what langguage variable to use
	$lang_var = 'ougc_showinportal_readmore';
	if((bool)$forum_cache[$fid]['allowmycode'])
	{
		$lang_var .= '_mycode';
	}
	elseif((bool)$forum_cache[$fid]['allowhtml'])
	{
		$lang_var .= '_html';
	}

	$message = $msg[0].$lang->sprintf($lang->{$lang_var}, $settings['bburl'], get_thread_link($tid));
}

// control_object by Zinga Burga from MyBBHacks ( mybbhacks.zingaburga.com ), 1.62
if(!function_exists('control_object'))
{
	function control_object(&$obj, $code)
	{
		static $cnt = 0;
		$newname = '_objcont_'.(++$cnt);
		$objserial = serialize($obj);
		$classname = get_class($obj);
		$checkstr = 'O:'.strlen($classname).':"'.$classname.'":';
		$checkstr_len = strlen($checkstr);
		if(substr($objserial, 0, $checkstr_len) == $checkstr)
		{
			$vars = array();
			// grab resources/object etc, stripping scope info from keys
			foreach((array)$obj as $k => $v)
			{
				if($p = strrpos($k, "\0"))
				{
					$k = substr($k, $p+1);
				}
				$vars[$k] = $v;
			}
			if(!empty($vars))
			{
				$code .= '
					function ___setvars(&$a) {
						foreach($a as $k => &$v)
							$this->$k = $v;
					}
				';
			}
			eval('class '.$newname.' extends '.$classname.' {'.$code.'}');
			$obj = unserialize('O:'.strlen($newname).':"'.$newname.'":'.substr($objserial, $checkstr_len));
			if(!empty($vars))
			{
				$obj->___setvars($vars);
			}
		}
		// else not a valid object or PHP serialize has changed
	}
}

// MyAlerts: Help Documents
function ougc_showinportal_myalerts_helpdoc()
{
	global $helpdoc, $lang, $settings;

	if($helpdoc['name'] != $lang->myalerts_help_alert_types)
	{
        return;
    }

    if($settings['ougc_showinportal_myalerts'])
    {
		global $showinportal;
		$showinportal->lang_load();

        $helpdoc['document'] .= $lang->ougc_showinportal_myalerts_helpdoc;
    }
}

// MyAlerts: Output
function ougc_showinportal_myalerts_output(&$args)
{
	global $mybb;

	if($args['alert_type'] != 'ougc_showinportal' || !$mybb->user['myalerts_settings']['ougc_showinportal'])
	{
		return;
    }

	global $showinportal, $lang;
	$showinportal->lang_load();

	$lang_var = 'ougc_showinportal_myalerts_showinportal';
	if(!$args['content'][0])
	{
		$lang_var = 'ougc_showinportal_myalerts_unshowinportal';
	}

	$thread = get_thread($args['tid']);

	if(!$thread)
	{
		return;
	}

	$args['threadLink'] = $mybb->settings['bburl'].'/'.get_thread_link($thread['tid']);
	$args['message'] = $lang->sprintf($lang->{$lang_var}, $args['user'], $args['threadLink'], htmlspecialchars_uni($thread['subject']), $args['dateline']);
	$args['rowType'] = 'showinportal';
}

// Magicfull
class OUGC_ShowInPortal
{
	// Build class
	function __construct()
	{
		global $settings;

		if($settings['ougc_showinportal_myalerts'])
		{
			$settings['myalerts_alert_ougc_showinportal'] = 1;
		}
	}

	// Loads language strings
	function lang_load()
	{
		global $lang;

		isset($lang->setting_group_ougc_showinportal) or $lang->load('ougc_showinportal');

		// MyAlerts, ugly bitch
		if(isset($lang->ougc_showinportal_myalerts_setting))
		{
			$lang->myalerts_setting_ougc_showinportal = $lang->ougc_showinportal_myalerts_setting;
		}
	}

	// $PL->is_member() helper
	function is_member($gids, $usergroup=false)
	{
		global $PL;
		$PL or require_once PLUGINLIBRARY;

		if($usergroup !== false)
		{
			$usergroup = array('usergroup' => (int)$usergroup);
		}

		return (bool)$PL->is_member($gids, $usergroup);
	}

	// Verify if current user can moderate a spesific forum
	function can_moderate($fid)
	{
		if(!is_moderator($fid))
		{
			return false;
		}

		global $settings;

		if(($settings['portal_announcementsfid'] != -1 && !$this->is_member($settings['portal_announcementsfid'], $fid)) && !$settings['portal_announcementsfid'])
		{
			return false;
		}

		if($this->is_member($settings['ougc_showinportal_forums'], $fid))
		{
			return false;
		}

		if(($settings['ougc_showinportal_groups'] != -1 && !$this->is_member($settings['ougc_showinportal_groups'])) || !$settings['ougc_showinportal_groups'])
		{
			return false;
		}

		return true;
	}

	// Update one or more threads
	function thread_update($sip, $tids)
	{
		if(!is_array($tids))
		{
			$tids = array($tids);
		}

		global $db, $lang;
		$this->lang_load();

		$sip = (int)(bool)$sip;
		$where = implode('\',\'', array_filter(array_map('intval', $tids)));
		$db->update_query('threads', array('showinportal' => $sip), 'tid IN (\''.$where.'\')');

		$lang_var = 'ougc_showinportal_pm_subject'.($sip ? '' : '_removed');
		$lang_var_message = 'ougc_showinportal_pm_message'.($sip ? '' : '_removed');

		$this->send_pm(array(
			'subject'	=> $lang->{$lang_var},
			'message'	=> $lang->{$lang_var_message},
			'touid'		=> $uid
		), -1, true, $tids);

		$this->my_alerts($sip, $tids);

		return true;
	}

	// Send a Private Message to a user  (Copied from MyBB 1.7)
	function send_pm($pm, $fromid=0, $admin_override=false, $tids)
	{
		global $mybb;

		if(!$mybb->settings['enablepms'])
		{
			return false;
		}

		if(!is_array($pm))
		{
			return false;
		}

		if(!$pm['subject'] ||!$pm['message'] || (!$pm['receivepms'] && !$admin_override))
		{
			return false;
		}

		global $lang, $db, $session;
		$lang->load('messages');

		require_once MYBB_ROOT."inc/datahandlers/pm.php";

		$pmhandler = new PMDataHandler();

		$pm['touid'] = array();

		$query = $db->simple_select('threads', 'uid', 'uid!=\'0\' AND uid!=\''.(int)$mybb->user['uid'].'\' AND tid IN (\''.implode('\',\'', array_filter(array_map('intval', $tids))).'\')');
		while($uid = (int)$db->fetch_field($query, 'uid'))
		{
			$pm['touid'][$uid] = $uid;
		}

		if(!$pm['touid'])
		{
			return;
		}

		// Build our final PM array
		$pm = array(
			'subject'		=> $pm['subject'],
			'message'		=> $lang->sprintf($pm['message'], $mybb->settings['bbname']),
			'icon'			=> -1,
			'fromid'		=> ($fromid == 0 ? (int)$mybb->user['uid'] : ($fromid < 0 ? 0 : $fromid)),
			'toid'			=> $pm['touid'],
			'bccid'			=> array(),
			'do'			=> '',
			'pmid'			=> '',
			'saveasdraft'	=> 0,
			'options'	=> array(
				'signature'			=> 0,
				'disablesmilies'	=> 0,
				'savecopy'			=> 0,
				'readreceipt'		=> 0
			)
		);

		if(isset($mybb->session))
		{
			$pm['ipaddress'] = $mybb->session->packedip;
		}

		// Admin override
		$pmhandler->admin_override = (int)$admin_override;

		$pmhandler->set_data($pm);

		if($pmhandler->validate_pm())
		{
			$pmhandler->insert_pm();
			return true;
		}

		return false;
	}

	// MyAlerts support
	function my_alerts($sip, $tids)
	{
		global $mybb;

		if(!$mybb->settings['ougc_showinportal_myalerts'])
		{
			return;
		}

		$plugins = (array)$mybb->cache->read('euantor_plugins');

		if(empty($plugins['myalerts']))
		{
			return;
		}

		$info = ougc_showinportal_info();

		if(str_replace('.', '', $plugins['myalerts']['version']) < $info['myalerts'])
		{
			return;
		}

		global $Alerts;

		if(!(!empty($Alerts) && $Alerts instanceof Alerts))
		{
			return;
		}

		global $db;

		// Get list of users
		$query = $db->simple_select('threads', 'uid, tid', 'uid!=\'0\' AND uid!=\''.(int)$mybb->user['uid'].'\' AND tid IN (\''.implode('\',\'', array_filter(array_map('intval', $tids))).'\')');
		while($thread = $db->fetch_array($query))
		{
			$Alerts->addAlert($thread['uid'], 'ougc_showinportal', $thread['tid'], $mybb->user['uid'], array($sip));
		}
	}
}
$GLOBALS['showinportal'] = new OUGC_ShowInPortal;

09-21-2015 07:32 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #14
RE: how do i bring the Xthread field into the portal?
From the quick read, I think this should work:
(09-21-2015 07:18 AM)RateU Wrote:  For temporary solution, try to select any forum(s) in Forums to pull announcements from setting (choose Select forums, then select any forum(s) there) instead of choosing All Forums.

09-21-2015 07:38 AM
Find all posts by this user Quote this message in a reply
ollie2015 Offline
Member
***
Posts: 90
Joined: Jan 2015
Post: #15
RE: how do i bring the Xthread field into the portal?
yes thank you but why? I just go in and selected all the current forums and it shows up !!!
09-21-2015 07:47 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #16
RE: how do i bring the Xthread field into the portal?
MyBB changed how portal_announcementsfid setting works. It uses -1 if you choose All Forums option.

(This post was last modified: 09-21-2015 07:52 AM by RateU.)
09-21-2015 07:52 AM
Find all posts by this user Quote this message in a reply
ollie2015 Offline
Member
***
Posts: 90
Joined: Jan 2015
Post: #17
RE: how do i bring the Xthread field into the portal?
is it a feature i should request or a bug i should report?
09-21-2015 07:56 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: