Never been to DZone Snippets 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

About this user

Sasha http://nothing-less.net

« Newer Snippets
Older Snippets »
Showing 1-10 of 70 total  RSS 

Compress file in SSH

The below will compress a file or folder in .tar.gz format in SSH.

tar -zcvf <new_tar_filename>.tar.gz <filename/directory>

Run a simple Update Query

In PHP.

$result = mysql_query("UPDATE example SET age='22' WHERE age='21'") 
or die(mysql_error());  

Consistent Thumbnail Width

download system/core/core.image_lib.php, open it up in and editor and change:

var $master_dim            = 'height';

to
var $master_dim            = 'width'; 


This will resize all thumbnails to have the same width, regardless of their height (the EE default resizes them all to the same height, regardless of their width.)

Display list of Links (using LinkList Module)

Requires the LinkList module.

<ul>
{exp:linklist:entries linklist="links" orderby="url_title" sort="ASC" status="open" limit="30" paginate="both"}
<li class="topspaced">
 <span class="larger">{linklist:url_title}</span><br />
&nbsp;&nbsp;&nbsp;<img src="/images/icons/link.png" width="16" height="16" alt="Link" border="0" /> <a href="{linklist:url}">{linklist:url}</a><br />
&nbsp;&nbsp;&nbsp;<img src="/images/icons/tag_green.png" width="16" height="16" alt="Tags" border="0" />{keywords}<a href="{path="main/links"}">{keyword}</a> {/keywords}
</li>
{paginate}
			<p class="center">Page {current_page} of {total_pages} Pages {pagination_links}</p>
		{/paginate}
{/exp:linklist:entries}
</ul>

Gallery: Display a list of parent categories only

The below displays a list of all parent categories for a certain Gallery. Be sure to change the gallery_id if yours doesn't have an id of 1.

{exp:query sql="SELECT cat_id, cat_name FROM exp_gallery_categories WHERE gallery_id='1' AND parent_id='0' ORDER BY cat_order"}
<li><a href="{path=gallery/subcat}{cat_id}">{cat_name}</a></li>
{/exp:query}

Filter entries by custom field

It goes in mod.weblog.php.

Inside the build_sql_query() function.

Sandwiched between the ‘Add status declaration’ block and the ‘Build sorting clause’ block.

// ----------------------------------------------
//  Limit by custom weblog field
// ----------------------------------------------
if ($custom_field = $TMPL->fetch_param('custom_field'))
{
$custom_field_array= explode('|',$custom_field);

if ($custom_field_name = $custom_field_array['1'] AND $custom_field_value = $custom_field_array['0'])
{
if (isset($this->cfields[$custom_field_value]))
{
$custom_field_id = $this->cfields[$custom_field_value];
}

$sql .= "AND exp_weblog_data.field_id_".$custom_field_id." = '".$custom_field_name."' ";
}
}


You use it by passing string that looks like this:
custom_field_name|value


In the weblog tag parameter: custom_field

{exp:weblog:entries weblog="blog" custom_field="custom_field_name|value"}


Replace ‘custom_field_name’ with the name of the custom field your evaluating for. And replace ‘value’ with the value that the field needs to contain in order to fetch the relevant entries.

Hack at your own risk. No warranties, quarantees, or doggie fleas.

(code written by Solspace / http://www.pmachine.com/forums/viewthread/29199/)

Change the EE date fields to dropdown pickers

You can use the code below to change Expression Engine's custom date fields to easy dropdowns, instead of the confusing text fields.

JS in the head of your document:
<script language="JavaScript" type="text/javascript">
function entrydate()
{
	var month = document.entryform.start_month.value;
	var day = document.entryform.start_day.value;
	var year = document.entryform.start_year.value;
	var time = document.entryform.start_time.value;
	document.entryform.entry_date.value = year+month+day+" "+time;
}
</script>


Code for the actual fields:

<!-- Begin Month -->
<select name="start_month" onchange="entrydate();">
<option value="01-" >January</option>
<option value="02-" >February</option>
<option value="03-" >March</option>
<option value="04-" >April</option>
<option value="05-" >May</option>

<option value="06-" >June</option>
<option value="07-" >July</option>
<option value="08-" selected>August</option>
<option value="09-" >September</option>
<option value="10-" >October</option>
<option value="11-" >November</option>
<option value="12-" >December</option>

</select>
<!-- End Month -->

<!-- Begin Day -->
<select name="start_day" onchange="entrydate();">
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
<option value="4" >4</option>
<option value="5" >5</option>
<option value="6" >6</option>
<option value="7" >7</option>
<option value="8" >8</option>

<option value="9" >9</option>
<option value="10" >10</option>
<option value="11" >11</option>
<option value="12" >12</option>
<option value="13" >13</option>
<option value="14" >14</option>
<option value="15" >15</option>
<option value="16" >16</option>
<option value="17" >17</option>

<option value="18" >18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>

<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" selected>30</option>
<option value="31" >31</option>

</select>
<!-- End Day -->
<!-- Begin Year -->
<select name="start_year" onchange="entrydate();">
<option value="2005-" >2005</option>

<option value="2006-" selected>2006</option>
<option value="2007-" >2007</option>

</select>
<!-- End Year -->
<!-- Begin Time -->
<select name="start_time" onchange="entrydate();">
<option value="6:00 AM" >6:00 AM</option>
<option value="6:30 AM" >6:30 AM</option>
<option value="7:00 AM" >7:00 AM</option>
<option value="7:30 AM" >7:30 AM</option>

<option value="8:00 AM" selected>8:00 AM</option>
<option value="8:30 AM" >8:30 AM</option>
<option value="9:00 AM" >9:00 AM</option>
<option value="9:30 AM" >9:30 AM</option>
<option value="10:00 AM" >10:00 AM</option>
<option value="10:30 AM" >10:30 AM</option>
<option value="11:00 AM" >11:00 AM</option>
<option value="11:30 AM" >11:30 AM</option>
<option value="12:00 PM" >12:00 PM</option>

<option value="12:30 PM" >12:30 PM</option>
<option value="1:00 PM" >1:00 PM</option>
<option value="1:30 PM" >1:30 PM</option>
<option value="2:00 PM" >2:00 PM</option>
<option value="2:30 PM" >2:30 PM</option>
<option value="3:00 PM" >3:00 PM</option>
<option value="3:30 PM" >3:30 PM</option>
<option value="4:00 PM" >4:00 PM</option>
<option value="4:30 PM" >4:30 PM</option>

<option value="5:00 PM" >5:00 PM</option>
<option value="5:30 PM" >5:30 PM</option>
<option value="6:00 PM" >6:00 PM</option>
<option value="6:30 PM" >6:30 PM</option>
<option value="7:00 PM" >7:00 PM</option>
<option value="7:30 PM" >7:30 PM</option>
<option value="8:00 PM" >8:00 PM</option>
<option value="8:30 PM" >8:30 PM</option>
<option value="9:00 PM" >9:00 PM</option>

<option value="9:30 PM" >9:30 PM</option>
<option value="10:00 PM" >10:00 PM</option>
<option value="10:30 PM" >10:30 PM</option>
<option value="11:00 PM" >11:00 PM</option>
<option value="11:30 PM" >11:30 PM</option>

</select>
<!-- End Time -->
<input type="hidden" name="entry_date" value="2006-08-30 8:57 AM" />


Full credit for this goes to Solspace!

Generate a dropdown with months in a year

The below code will generate a form dropdown for all 12 months, with the current month selected. Handy for those date pickers!

<select name="start_month">
<?php
global $LOC;
$current_time_m = $LOC->decode_date('%m', $LOC->now);

for ($i = 1; $i <= 12; $i++) {
   echo "<option value='$i-'";
if ($i == $current_time_m) { echo " selected='selected'"; }
$month_text = date("F", mktime(0, 0, 0, $i+1, 0, 0, 0));
   echo ">$month_text</option>
"; } ?>
</select>

Generate a dropdown with days of the month

The below code will generate a form dropdown for all the days of the month, with today's day selected. Handy for those date pickers!

<select name="start_day">
<?php
global $LOC;
$current_time_day = $LOC->decode_date('%d', $LOC->now);

for ($i = 1; $i <= 31; $i++) {
   echo "<option value='$i'";
if ($i == $current_time_day) { echo " selected='selected'"; }
   echo ">$i</option>
";
} ?>
</select>

Restricr Search to a Member's Own Posts

Insert the below code just below the opening search form tags to restrict the search to a member's own posts if they are not a Super Admin.

{if group_id != "1"}<input type="hidden" class="input"  name="member_name" value="{screen_name}" />
{if:else}<p>You are logged in as a Super Admin, so all entries will be visible to you.</p>{/if}
« Newer Snippets
Older Snippets »
Showing 1-10 of 70 total  RSS