Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Fix for EE Multi-relationship field in PHP4

// http://expressionengine.com/forums/viewreply/192755/

Open your /system/modules/weblog/mod.weblog.php file and find from this line:
    
    // -------------------------------------------
    // 'weblog_entries_tagdata' hook.

to this line:
    
    //
    // -------------------------------------------

Replace between those comments with this:

    if (isset($EXT->extensions['weblog_entries_tagdata']))
    {
        // -- PHP4 Fix For call_user_func_array not passing by reference
        global $Weblog; $Weblog = $this;
        // -- End Fix
        
        $tagdata = $EXT->call_extension('weblog_entries_tagdata', $tagdata, $row, $this);
        if ($EXT->end_script === TRUE) return $tagdata;
        
        // -- PHP4 Fix For call_user_func_array not passing by reference
        $this = $Weblog; unset($Weblog);
        // -- End Fix
    

Admin in-page edit links for EE

// Add in in-page edit links for superadmins.

{if logged_in_group_id == "1"}

	<div id="admin">
		<ul>
			<li><a href="/eengine/index.php?&C=edit&M=edit_entry&entry_id={entryID}" target="_blank">Edit this page</a></li>
			<li><a href="/eengine/index.php?C=logout" target="_blank">Logout</a></li>
		</ul>
	</div>

{/if}

Fix for ExpressionEngine File Extension in PHP4

Find the following line (around 5388):

switch ($row['field_type'])


before that place this line:

$field_type = "";


So that switch should look like this:

$field_type = "";
switch ($row['field_type'])
{
    case 'text' :  $field_type = $LANG->line('text_input');
        break;
    case 'textarea' :  $field_type = $LANG->line('textarea');
        break;
    case 'select' :  $field_type = $LANG->line('select_list');
        break;
    case 'date' :  $field_type = $LANG->line('date_field');
        break;
    case 'rel' :  $field_type = $LANG->line('relationship');
        break;
} 


http://expressionengine.com/forums/viewthread/38843/#181791

Hack for the EE Extension: File

Try changing line 496 from this:

$target_path = preg_match("/^\//", $f['server_path']) ? $f['server_path'] : PATH.$f['server_path'];

to this:

$target_path = preg_match("/(^\/|^[a-z]:)/", $f['server_path']) ? $f['server_path'] : PATH.$f['server_path'];

Dynamic page titles in Expression Engine

// Puts the weblog name and entry title in the title tag in Expression Engine

<title>{exp:weblog:info weblog="name-of-weblog-here"}
    {blog_title}
{/exp:weblog:info} | {exp:weblog:entries}
    {title} 
{/exp:weblog:entries}</title>

Redirect after login

// This code allows you to use the free-standing login page to redirect members who login to individual start pages based on their group membership. Its use is explained in greater detail here:

http://www.firewhite.com/weblog/redirectafterlogin

// <?php global $SESS, $DB;


        {
        	$memid = $SESS->userdata['member_id'];
        	$group_no = $DB->query("select group_id from exp_members where member_id='$memid'");
        	$group_num = $group_no->row['group_id'];
$login_path = '';
        	$group_name = '';
        	if($group_num == 1) {
        		$group_name = 'consultants';
        	} else if($group_num <= 4) {
        		$group_name = 'default';
        	} else {
        		$group = $DB->query("select group_title from exp_member_groups where group_id='$group_num'");
        		$group_name = str_replace(" ", "", strtolower($group->row['group_title']));
        		$group_name = preg_replace("/(.*)_.*/", "\\1", $group_name);
        		$template = $DB->query("select group_name from exp_template_groups where group_name like '$group_name'");
        		if ($template->num_rows < 1)
        			$group_name = 'default';

        	}
            
        };
header("location: http://www.firewhite.com/$group_name/start"); exit();?>
    

?>

Site map, based on sections (e.g. weblogs) and categories

This will generate a site map using nested lists and h3 & h4 tags. Fairly rough, but serviceable.

{exp:query sql="SELECT blog_name, blog_title, blog_description FROM exp_weblogs"}
<h3><a href="{path={blog_name}}" title="{blog_description}">{blog_title}</a></h3>
{exp:weblog:category_archive weblog="{blog_name} "style="nested" orderby="title"}
 {categories}<h4 id="{category_id}"><a href="{path={blog_name}/articles}" title="{category_description}">{category_name}</a></h4>{/categories}
 {entry_titles}<a href="{path={blog_name}/detail}">{title}</a>{/entry_titles}
{/exp:weblog:category_archive}
<div class="separator"></div>
{/exp:query}

Linking to Stylesheets

http://eedocs.pmachine.com/templates/globals/stylesheet.html

<link rel="stylesheet" type="text/css" media="all" href="{stylesheet=static/style}" />

<link media="screen" type="text/css" href="{stylesheet=static/style}" />


Using FlashObject and the miniFLV player to play videos from an entry

Ideally, at some point, I'll modify the plug-in for EE that shows Flash objects to use flashobject.js.

This code assumes custom fields in the blog.

FlashObject: http://blog.deconcept.com/flashobject/
MiniFLV: http://www.richnetapps.com/miniflv.htm

Online Example.

{if project_video}
{if project_video_title}<h4>{project_video_title}: Video Clip</h4>{/if}

<div id="videoClip">
<p style="margin: 10px 0; padding: 10px; border: 3px solid red;"><a href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank" title="Get Flash Player"><img src="http://www.macromedia.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Flash Player" height="31" width="88" align="left" style="padding-right: 10px"></a>Flash 7 or above and JavaScript are required to view the project video clip. Please download the <a href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank" title="Get Flash Player">latest Flash plug-in</a>.</p>
{if project_video_alt}<p>{project_video_alt}</p>{/if}
</div>

<script type="text/javascript">
   // define the flash video movieclip that plays the videos
   var fo = new FlashObject("/images/videoplayer.swf", "video", "340", "230", "7", "#ffffff");
   fo.addVariable("file", "{project_video}"); // pass the clip name from the project_video field in entry
   fo.addVariable("aplay", "false");// autoplay
   fo.addVariable("size", "true"); //autosize
   fo.addVariable("autorew", "true"); //auto-rewind; doesn't work for some reason
  fo.write("videoClip"); // replace the targeted div with a Flash Object
</script>

{/if}

Snippets Plugin

Coding to use for the Expression Engine Snippets Plugin:

In the actual pages:
{exp:snippets template="static/index"}
{page_title}Site: {title}{/page_title}
{page_section}journal{/page_section}
{/exp:snippets}


In the header include (static/index in this case):
%page_title%
%page_section%
<?
$fof_title="%nl_title%";
$fof_section="%nl_section%";
?>


Define them as variables in PHP for easy if/else statements. :)