All posts by RaceRay

Written by

"Enthusiastic Sim-Racer from the north of germany. I write here about web development, hardware, software and latest motion simulator technologies."

Conditional statements for url in XenForo templates

[gard]
If  you need to check a conditional statement in your XenForo template for a specific part of a url just use the following syntax:

<li id="menu-item-14" class="<xen:if is="{$requestPaths.requestUri} == '/community/marketplace/categories/marketplace.7/'"> current-menu-item</xen:if>"><a href="http://www.xsimulator.net/community/marketplace/categories/marketplace.7/">Marketplace</a></li>

In this example, if the current Url is

'/community/marketplace/categories/marketplace.7/'

the class will be extended with

current-menu-item

I use that piece of code to get the current page link in in the main navigation of the XSimulator forum.
[gard]

phpinfo in XenForo

XenForo 1.2 You ll find the phpinfo() when you log into your admin panel and than add the following parameter to the admin url admin.php?tools/phpinfo

There is no direct link to it in the admin panel, so thats a really “nice to know”.

MySql String replace with REPLACE()

[gard]
Often i have to replace clearly identifiable strings (strings, text) with a new string in a MySQL column. Either its possible to use php, read the DB content and use str_replace() for string replacement, there is a much better way:

Thank God, MySQL offers a native REPLACE() function therefore:

REPLACE(str,from_str,to_str)

Returns the string str with all occurrences of the string from_str replaced by the string to_strREPLACE()performs a case-sensitive match when searching for from_str.

In this example i replace all appearance of the string [youtube] with an empty string in the column xf_post of my XenForo database:

UPDATE xf_post SET message = REPLACE(message, '[/youtube]', '') WHERE message LIKE '%[/youtube]%';

[gard]

 

2DOF Motion Simulator with truck wiper motor playseat

In this article, you will find the step-by-step tutorial you can follow to achieve a DIY 2DOF simulator for 700€ : dozen of pictures, videos…

This is the link to my original post from Gamoover:
http://www.gamoover.net/Forums/index.php?topic=27617.0

Same link: English translated by google
[gard]

The concept:

A dynamic simulator which integrates the driver, the seat, pedals and steering wheel (but not the screens!)
The two axes (2DOF: Two Degrees of Freedom) are Roll and Pitch.

The principle is inspired by the commercial model from Frex http://www.frex.com
but with gearmotors (wiper motor + rod) replacing the electric linear actuators.

A glogal overview of the electrical stuff:
RacingMat-electrical setup

Simtools

This simulator requires an additional software to extract games telemetry data and send the data to the motors: Simtools can be downloaded here

Two computers:

Pc #1 (graphic card “7970 lightning”, Windows 7) :

– The car games (Dirt3, rFactorLite and Richard Burns Rally)
– SimTools GameEngine

PC #2 (Recycling) connected via a crossover cable RJ45 to PC #1

– SimTools GameManager

Electronic cards : Arduino + Motomonster

An Arduino card linked to computer #2 with a USB cable.
The Arduino controls the MotoMonster shield “motor driver board”.

The power board Sparkfun “MotoMonster” drives the two motors (12V 47A = 575W) according to the instructions of the Arduino (5V 5mA = 25 mW).

For simplicity, the motor driver board is equivalent to 4 relays:

driving the right motor forward this means mounting the right side,
driving the right motor in the other direction this means lowering the right side,
driving the left motor forward this means mounting the left side,
driving the left motor in the other direction this means lowering the left side,

An arduino program (C language)

This program interprets the data sent via serial port by SimTools and sends it to the motor control board.
It performs a feedback control by reading the values of the potentiometer coupled to the motors :
-> The actual position is compared to the setpoint, and this will create a new updated order sent to the MotoMonster card.

This feedback loop is performed every 80 ms.

12V power supply and DC motors

A heavy 12V Power Supply Unit about 30A. Electric Motors

2 Truck Wiper Motors for actuating the movable platform, with their positioning potentiometer (for feedback).

 

Structure in rectangular steel tube:

 

– the frame
the frame rests on the ground and supports the movable platform via a motor drive shaft (U joint).

– the moving part: the “cockpit”

– A true racing bucket seat (tubular). The fiber seats are lighter but more expensive.
– A harness! important to feel the seat movements and for realism of immersion
– Force Feedback steering wheel and pedals

The dimensions

Here are the quotations to give you an idea :

The step-by-step pictures:

Structure

It was very convenient to have the bucket seat’s mounting plate: I drilled the structure easily!

Power Drill and a conical tool to adjust the hole to good diameter
Take care to ensure the shaft ‘s squareness : it has to be vertical !
http://gamoovernet.pixhotel.fr/pics_gamoovernet690px/20130401124851-RacingMat-cardan-et-chassis-3-.JPG

Then I crossed the bars at 45 ° to triangulate my frame :

The gimbal (U joint) is blocked in rotation along the yaw axis.

the gimbal assembly:

which gives this 🙂


and this

XenForo Nginx rewrite rules configuration for friendly url

[gard]
Use the following configuration file to run your XenForo forum installation delivered by the Nginx webserver with friendly urls:

The rules are very simple:

Open your nginx.conf (You often in /etc/nginx):

Inside the server block {} insert two location related sections:

location / {
try_files $uri $uri/ /index.php?$uri&$args;
}

location ~ /(internal_data|library) {
internal;
}

The first location block specifies the url rewriting process. The second location part prevents external access to the internal XenForo related data structures. Thats for security purposes of the forum installation.

If you forum is located within a subfolder like e.g. domain.com/forum or domain.com/community just add the name of the subfolder to the location parts:

location /forum/ {
try_files $uri $uri/ /forum/index.php?$uri&$args;
}

location ~ /forum/(internal_data|library) {
internal;
}

Restart the nginx webserver.

All done. Your XenForo installation should be running fine now with search engine friendly urls like domain.com/forum/this-is-my-post.2
[gard]

Disable author meta box for specific pages and posts – WordPress

[gard]
Sometimes its necessary to give your posts or pages switches to turn on and off specific template elements on your site. WordPress makes it really easy:

 

If not already done, activate the Custom fields on the Screen Options menue at the upper right corner of your post:

Add New Post ‹ XSimulator — WordPress

Than create any field and value, e.g.:
Name: hide-author
Value: 0

You can call the name as you want it. We define it in the template next.

custom fields in WordPress

 

Now we open content.php and go to line 60:

<?php     if ( is_single() && get_the_author_meta( 'description' ) && is_multi_author() ) :?>
			<?php get_template_part( 'author-bio' ); ?>
		 <?php endif; ?>

Change it so something like:

if ( is_single() && get_post_meta($post->ID,  'hide-author', true) != '1') :
                    ?>
			<?php get_template_part( 'author-bio' ); ?>
		<?php endif; ?>

As you can see, you can grab  the new custom field and create a condition with:

 get_post_meta($post->ID,  'hide-author', true) != '1')

Now you can specify in all your posts and pages if you like to disable or enable the author box. Very easy!
[gard]

 

Three and multi columns responsive css layout

One of the best source for a responsive easy adaptable responsive multi column layout is http://www.responsivegridsystem.com

It´s not a bloated framework, neither a boilerplate or similar. It´s just a little bunch of very smart code to create a responsive div layout. I´ll use it at the frontpage of XSimulator.net.

Just a example for a responsive three column layout:

HTML:

<div class="col span_1_of_3">Column 1</div>
<div class="col span_1_of_3">Column 2</div>
<div class="col span_1_of_3">Column 3</div>

CSS

/* Reset - Responsive first */

.col:first-child {
margin-left: 0;
}
.col {
display: block;
float: left;
margin: 1% 0 1% 1.6%;
}
.span_1_of_3 {
width: 31.7%;
}

/* non responsive */
@media (max-width: 643px) {
.span_1_of_3 {
            width: 100%;
        }
        .col {
            margin: 1% 0 1% 0%;
        }
}

Result: (Scale your browser to see it responsive):

Column 1
Column 2
Column 3

Get it:
http://www.responsivegridsystem.com/

WordPress breadcrumbs without plugin

Open your theme functions.php and add the following code:

function xsimu_breadcrumb() {
        echo ' <ul id="breadcrumbs">';
    if (!is_home()) {
        echo '<li> <a href="';
        echo get_option('home');
        echo '">';
        echo 'Home';
        echo "</a><span class='separator'>»</span></li>";
        if (is_category() || is_single()) {
            echo ' <li>';
            the_category('<span class="separator">»</span></li><li> ');
            if (is_single()) {
                echo "</li><li><span class='separator'>»</span>";
                the_title();
                echo '</li>';
            }
        } elseif (is_page()) {
            echo '<li>';
            echo the_title();
            echo '</li>';
        }
    }
    elseif (is_tag()) {single_tag_title();}
    elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
    elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
    elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
    elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
    elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
    elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
    echo '</ul>';
}

Add the following function in one of your templates. Most times you will use the header.php

<?php xsimu_breadcrumb(); ?>

Congratulations. You are done;)

Pagination for WordPress without Plugin

When i started the creating process of this theme i considered to integrate one of the popular WordPress plugins for pagination. I than  decided to publish the XSimulator theme for free and i felt that it could lead to any problems and issues for someone else to make a similar looking theme when the requirements  are a lot of different plugins he must install first. Fortunately i found a great programmed script which is very easy to implement and powerful.

Open your functions.php and create a new function:

/* Adds pagination 
 * 
 * @since XSimulator 1.0
 * @param $range total list of pages 
 * @param $range count of maximum page links from left and right side of the current page link.
 * @bool $show_one_page_hint shows a text like: page 1 of 6
 * @bool $show_one_pager Do not show nav arrows
 * 
 */
function xsimu_pagination($range = 3, $show_one_pager = true, $show_page_hint = false)
{
    global $wp_query;
    $num_of_pages = (int)$wp_query->max_num_pages;

    if(!is_single() && $num_of_pages > 1)
    {
        $current_page = get_query_var('paged') === 0 ? 1 : get_query_var('paged');
        $num_of_display_pages = ($range * 2) + 1;        

        $output = '<div id="pagination">';

        if($show_page_hint)
        {
            $output .= '<span>Page ' . $current_page . ' of ' . $num_of_pages . '</span>';
        }

		if($current_page > 2 && $current_page > $range + 1 && $num_of_display_pages < $num_of_pages)
		{
			$output .= '<a href="' . get_pagenum_link(1) . '" title="Page 1 - Latest article">«</a>';
		}
		if($show_one_pager && $current_page > 1)
		{
			$output .= '<a href="' . get_pagenum_link($current_page - 1) . '" title="Page ' . ($current_page - 1) . ' - Latest Artikel">‹</a>';
		}

		for($i = 1; $i <= $num_of_pages; $i++)
		{
			if($i < $current_page + $range + 1 && $i > $current_page - $range - 1)
            {
				if($current_page === $i)
				{
					$output .= '<span class="current">' . $i . '</span>';
				}
				else
				{
					$output .= '<a href="' . get_pagenum_link($i) . '" title="Page ' . $i . '" >' . $i . '</a>';
				}
            }
		}

		if($show_one_pager && $current_page < $num_of_pages)
		{
			$output .= '<a href="' . get_pagenum_link($current_page + 1) . '" title="Page ' . ($current_page + 1) . ' - Older article">›</a>';
		}
		if($current_page < $num_of_pages - 1 && $current_page + $range < $num_of_pages && $num_of_display_pages < $num_of_pages)
		{
			$output .= '<a href="' . get_pagenum_link($num_of_pages) . '" title="Page ' . $num_of_pages . ' - Older article">»</a>';
		}

		$output .= '</div>';

        return $output;

    }
}

Open the template file where you want to publish your pagination. E.g. category.php

echo xsimu_pagination(2, true, false);

You´re ready:)

Thanks to the author of the original script on the page smart-webentwicklung.de