MyBB Hacks

Full Version: how to write this code?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
terzier Wrote:I do not know what the title should give this thread. and I also do not know what else to ask anyone else. hopefully I can get a solution here. Ouch

I want to develop a slide based on the thread Johnny S.

of the thread, I want to do is on each slide (Slide Nivo) The images files (certainly with images ([*img - [/img*]). with extensions jpg; jpeg; png; gif) taken from the forums that have been set previously.

a friend told to use the "Regex". however, conflating PHP with RegEx really makes me confused. Out

The following code is just copy-paste that I get from some communities. I know, that there are shortcomings and errors of this code. I ask that anyone willing to correct the code to be run like that I mean.  Whip

Code:
***** Slider Gallery Thread Start *****/ 

// Slider Images
 /* LATEST THREADS */
 
$query = $db->query("
       SELECT t.*, p.message
       FROM ".TABLE_PREFIX."threads t
       LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid = t.firstpost)
       WHERE t.fid IN (17,18) AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid
       ORDER BY t.dateline DESC
       LIMIT 1");
 
if(!$db->num_rows($query))
 
    {
        // Needs to output a nice "no posts here" box
        $title = 'Error';
        $message = 'No Message';
       
        eval("\$tricks = \"".$templates->get("member_profile_no_content")."\";");
 
    }
    else
 
    {
    // Set up the parser options.
    $parser_options = array(
        "allow_html" => $forum['allowhtml'],
        "allow_mycode" => $forum['allowmycode'],
        "allow_smilies" => $forum['allowsmilies'],
        "allow_imgcode" => $forum['allowimgcode'],
        "allow_videocode" => $forum['allowvideocode'],
         "filter_badwords" => 1
        );
       
    while($threads = $db->fetch_array($query))
 
        {
        $threads['threadlink'] = get_thread_link($threads['tid']);
 
       
        if($threads['lastposteruid'] == 0)
 
        {
            $lastposterlink = $threads['lastposter'];
 
        }
        else
        {
            $lastposterlink = build_profile_link($threads['lastposter'], $threads['lastposteruid']);
 
        }
        $view_string = 'Views';
        $reply_string = 'Replies';
        if($threads['views'] == 1)
 
        {
            $view_string = 'Views';
 
        }
 
        if($threads['replies'] == 1)
 
        {
            $reply_string = 'Replies';
 
        }
        $threads['profilelink'] = build_profile_link($threads['username'], $threads['uid']);
        $threads['reply'] = $lang->sprintf($lang->thread_views_stats, my_number_format($threads['replies']), $reply_string, my_number_format($threads['views']), $view_string);
        $threads['date'] = my_date($mybb->settings['dateformat'], $threads['dateline']);
        $threads['time'] = my_date($mybb->settings['timeformat'], $threads['dateline']);
        $threads['lastpostlink'] = get_thread_link($threads['tid'], 0, "lastpost");
        $threads['message'] = my_substr($threads['message'], 0, 150) . "...";
        $threads['message'] = $parser->parse_message($threads['message'], $options);
        eval("\$tricks .= \"".$templates->get("depan_slides")."\";");
    }
        }

/***** Slider Gallery Thread End *****/ 


terzier Wrote:I have made a similar thread in various forums such as this but of everything that did not get a solution. hope there are experts who are willing to help.
Yipi

sorry if my english poor Ouch
38 people who read but no one answered Ouch . please help to anyone who could. Erf
(11-10-2013 02:41 PM)terzier Wrote: [ -> ]38 people who read but no one answered Ouch
Yeah, sorry about that.  I got bored and hit the refresh button about 30 times... >_>
I'll reset it back to 0 for you.  Hope that helps.




Oh ya, look at inc/class_parser.php for some awesome regexes.
terzier Wrote:I am a little familiar with your style of sharing. that is, every person you ask, you will not be directly responsible. but just to give a little feedback, so that "the questioner" can cultivate deeper.

I'll do all right. however, please help me if I have an impasse.

i look at inc/class_parser.php and I think, just this part that I saw was very interesting related to my posting this. Yes

Code:
		// Convert images when allowed.
		if($options['allow_imgcode'] != 0)
		{
			$message = preg_replace_callback("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_callback1'), $message);
			$message = preg_replace_callback("#\[img=([0-9]{1,3})x([0-9]{1,3})\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_callback2'), $message);
			$message = preg_replace_callback("#\[img align=([a-z]+)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_callback3'), $message);
			$message = preg_replace_callback("#\[img=([0-9]{1,3})x([0-9]{1,3}) align=([a-z]+)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_callback4'), $message);
		}
		


if true in any part of the code should be added?
and, please correct the code in the first post.

Me Wrote:implore your help. I'm not a genius PHP master like you. Ouch
is not there anything that can help me? Erf
Yumi or rateU , I know you are a genius coder. or anyone else, please help me. Erf

This is the code that I know that I got from various forums. please correction. Ouch

Code:
/***** Slider Gallery Thread Start *****/ 

// Slider Images
 /* LATEST THREADS */
 
$query = $db->query('
       SELECT t.*, p.message, a.aid, a.attachname, a.filename, f.name,
       FROM '.TABLE_PREFIX.'threads t,
       LEFT JOIN '.TABLE_PREFIX.'posts p ON (p.pid = t.firstpost)
       LEFT JOIN '.TABLE_PREFIX.'attachments a ON(a.pid=p.pid)
       LEFT join '.TABLE_PREFIX.'forums f ON (f.fid=t.fid)
       LEFT JOIN '.TABLE_PREFIX.'users u ON (u.uid=t.uid)
       WHERE t.fid IN (17,18) AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.firstpost=p.pid
       ORDER BY t.dateline DESC
       LIMIT 1');

if(!$db->num_rows($query))
 
    {
        // Needs to output a nice "no posts here" box
        $title = 'Error';
        $message = 'No Message';
       
        eval("\$tricks = \"".$templates->get("member_profile_no_content")."\";");
 
    }
    else
 
    {
    // Set up the parser options.
    $parser_options = array(
        "allow_html" => $forum['allowhtml'],
        "allow_mycode" => $forum['allowmycode'],
        "allow_smilies" => $forum['allowsmilies'],
        "allow_imgcode" => $forum['allowimgcode'],
        "allow_videocode" => $forum['allowvideocode'],
         "filter_badwords" => 1
        );

        
    while($threads = $db->fetch_array($query))
 
        {
        $threads['threadlink'] = get_thread_link($threads['tid']);
 
       
        if($threads['lastposteruid'] == 0)
 
        {
            $lastposterlink = $threads['lastposter'];
 
        }
        else
        {
            $lastposterlink = build_profile_link($threads['lastposter'], $threads['lastposteruid']);
 
        }

        $view_string = 'Views';
        $reply_string = 'Replies';
        if($threads['views'] == 1)
 
        {
            $view_string = 'Views';
 
        }
 
        if($threads['replies'] == 1)
 
        {
            $reply_string = 'Replies';
 
        }
        
        /*********** tambahan tester ******************/
        
        // Convert images when allowed.
        if($options['allow_imgcode'] != 0)
        {
            $message = preg_replace_callback("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_callback1'), $message);
            $message = preg_replace_callback("#\[img=([0-9]{1,3})x([0-9]{1,3})\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_callback2'), $message);
            $message = preg_replace_callback("#\[img align=([a-z]+)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_callback3'), $message);
            $message = preg_replace_callback("#\[img=([0-9]{1,3})x([0-9]{1,3}) align=([a-z]+)\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", array($this, 'mycode_parse_img_callback4'), $message);
        }        

        // Convert images when allowed.
        if($options['allow_imgcode'] != "no")
        {
            $message = preg_replace("#\[img\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "\$this->mycode_parse_img('$2')\n", $message);
            $message = preg_replace("#\[img=([0-9]{1,3})x([0-9]{1,3})\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#ise", "\$this->mycode_parse_img('$4', array('$1', '$2'));", $message);
        }


        if ($thread['message'])
        {
            $message = 'http://([\w-]+\.)+[\w-]+(/[\w- ./]*)+\.(?:gif|jpg|jpeg|png|bmp|GIF|JPEG|JPG|PNG|BMP|Gif|Jpg|Jpeg|Png|Bmp)$';
        }
        else
        {
            $message = '';
        }

        /*********** tambahan tester ******************/

        if ($thread['thumbnail'])
        {
            $thumbnail = '<a href="'.$mybb->settings['bburl'].'/attachment.php?aid='.$aid.'" target=_blank><img src="./uploads/'.$thread['thumbnail'].'" alt="" title="" width="100%" height="100px"></a>';
        }
        else
        {
            $thumbnail = '';
        }

        // tambahan dari alfa //

        while($slide = $db->fetch_array($query)) {

        $message = $slide['message'];

        $pattern = '/\[img\]([^\[]*)\[/';

        preg_match_all($pattern, $message, $matches);

        $matches = array_merge($match[2], $match[3]);

        foreach($matches as $key => $value)
        { 
            if (empty($value))
            { 
                unset($matches[$key]); 
            } 
        } 

        }

        // tambahan dari alfa //

        $threads['profilelink'] = build_profile_link($threads['username'], $threads['uid']);
        $threads['reply'] = $lang->sprintf($lang->thread_views_stats, my_number_format($threads['replies']), $reply_string, my_number_format($threads['views']), $view_string);
        $threads['date'] = my_date($mybb->settings['dateformat'], $threads['dateline']);
        $threads['time'] = my_date($mybb->settings['timeformat'], $threads['dateline']);
        $threads['lastpostlink'] = get_thread_link($threads['tid'], 0, "lastpost");
        $threads['message'] = my_substr($threads['message'], 0, 150) . "...";
        $threads['message'] = $parser->parse_message($threads['message'], $options);

        // tambah //

        // tambah //
        
        eval("\$tricks .= \"".$templates->get("depan_slides")."\";");
    }
        }

/***** Slider Gallery Thread End *****/ 


but after adding the above code, the result is just a white page.
Ouch

the above code is only part of the code pages http://yories.terzier.com/teras.php and not the full code.

terzier Wrote:really need help. Ouch
This question is too difficult to answer? Ouch

because I can't solve this problem alone I beseech the coding genius here to help. I'm not going to ask again if anyone is willing to help me this question. Erf
Have you tried asking elsewhere?
I don't do custom coding unfortunately.
I've tried to ask to many existing MyBB forums.
such as:
in:
- yaldaram: http://yaldaram.com/thread-6559.html
- mybb.com: http://community.mybb.com/thread-147381.html
- http://www.communityplugins.com (pavemen).
(hidden thread, because I posted in the private area)

and in stackoverflow.com
http://stackoverflow.com/questions/19776...http://stackoverflow.com/questions/19776461/regex-code-to-call-the-images-into-a-

of all that, I get the same results. [Image: JFBQ00197070418B.gif] much to see but nothing helped. and ultimately my problem is not resolved. [Image: 8dcf9699.gif]


edit. Biggrin
almost complete. Yipi

thank you Yumi. for your help Yes

-------------------------------

edit. Frown
I think it is finished, it is still just a dead end. I was desperate. [Image: JFBQ00197070418B.gif]
Reference URL's