<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Footer Index',
'before_widget' => '<div class="section widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="sectionheader">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Footer Single',
'before_widget' => '<div class="section widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="sectionheader">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Footer Category',
'before_widget' => '<div class="section widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="sectionheader">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Footer Page',
'before_widget' => '<div class="section widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="sectionheader">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Footer Search',
'before_widget' => '<div class="section widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="sectionheader">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Footer Archive',
'before_widget' => '<div class="section widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="sectionheader">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Footer Contact',
'before_widget' => '<div class="section widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="sectionheader">',
'after_title' => '</h2>',
));
?>
<?php
class SofaiBloggr {

	function addOptions () {

		if (isset($_POST['sib_reset'])) { SofaiBloggr::initOptions(true); }

		if (isset($_POST['sib_save'])) {

			$aOptions = SofaiBloggr::initOptions(false);
			// use breadcrumbs?
			$aOptions[ 'usebread' ] = $_POST[ 'usebread' ];
			// image size - post details
			$aOptions[ 'is_postdetails' ] = $_POST[ 'is_postdetails' ];
			// image size - page
			$aOptions[ 'is_pagei' ] = $_POST[ 'is_pagei' ];
			// trim text
			$aOptions[ 'trim_text' ] = parseInt( $_POST[ 'trim_text' ] );
			// includance
			$aOptions[ 'footerpluggs' ] = $_POST[ 'footerpluggs' ];
			// twitter
			$aOptions[ 'twitter_title' ] = $_POST[ 'twitter_title' ];
			$aOptions[ 'twitts_number' ] = parseInt( $_POST[ 'twitts_number' ] );
			$aOptions[ 'twitter_user' ] = $_POST[ 'twitter_user' ];
			// Flickr
			$aOptions[ 'flickr_title' ] = $_POST[ 'flickr_title' ];
			$aOptions[ 'flickr_noi' ] = parseInt( $_POST[ 'flickr_noi' ] );
			$aOptions[ 'flickr_tou' ] = $_POST[ 'flickr_tou' ];
			$aOptions[ 'flickr_choice' ] = urlencode( $_POST[ 'flickr_choice' ] );
			// tagcloud
			$aOptions[ 'tagcloud_title' ] = $_POST[ 'tagcloud_title' ];
			// socialize
			$aOptions[ 'online_title' ] = $_POST[ 'online_title' ];
			// latest comments
			$aOptions[ 'latestcomments_title' ] = $_POST[ 'latestcomments_title' ];
			$aOptions[ 'latestcomments_numbr' ] = parseInt( $_POST[ 'latestcomments_numbr' ] );
			
			// translations
			$aOptions[ 'pagetag' ] = $_POST[ 'pagetag' ];
			$aOptions[ 'latest_articles' ] = $_POST[ 'latest_articles' ];
			$aOptions[ 'navigate_site' ] = $_POST[ 'navigate_site' ];
			$aOptions[ 'home_link' ] = $_POST[ 'home_link' ];
			$aOptions[ 'copytext' ] = $_POST[ 'copytext' ];
			$aOptions[ 'readmore' ] = $_POST[ 'readmore' ];
			$aOptions[ 'sing_comments' ] = $_POST[ 'sing_comments' ];
			$aOptions[ 'plur_comments' ] = $_POST[ 'plur_comments' ];
			$aOptions[ 'searchtitle' ] = $_POST[ 'searchtitle' ];
			$aOptions[ 'searchresults' ] = $_POST[ 'searchresults' ];
			$aOptions[ 'for_phrase' ] = $_POST[ 'for_phrase' ];
			$aOptions[ 'searchtag' ] = $_POST[ 'searchtag' ];
			$aOptions[ 'nametag' ] = $_POST[ 'nametag' ];
			$aOptions[ 'emailtag' ] = $_POST[ 'emailtag' ];
			$aOptions[ 'webtag' ] = $_POST[ 'webtag' ];
			$aOptions[ 'phonetag' ] = $_POST[ 'phonetag' ];
			$aOptions[ 'commenttag' ] = $_POST[ 'commenttag' ];
			$aOptions[ 'leavecomment' ] = $_POST[ 'leavecomment' ];
			$aOptions[ 'submittag' ] = $_POST[ 'submittag' ];
			$aOptions[ 'you_here' ] = $_POST[ 'you_here' ];
			
			update_option( 'sib_theme', $aOptions );

		}
		
		add_theme_page("Sofa iBloggr Options", "Sofa iBloggr Options", 'edit_themes', basename(__FILE__), array('SofaiBloggr', 'displayOptions'));
	}
	
	function initOptions ($bReset) {
		$aOptions = get_option( 'sib_theme' );
		if( !is_array( $aOptions) || $bReset ) {
			// use breadcrumbs?
			$aOptions[ 'usebread' ] = 'yes';
			// image size - post details
			$aOptions[ 'is_postdetails' ] = 'large';
			// image size - page
			$aOptions[ 'is_pagei' ] = 'large';
			// trim text
			$aOptions[ 'trim_text' ] = '25';
			// includance
			$aOptions[ 'footerpluggs' ] = '';
			// twitter
			$aOptions[ 'twitter_title' ] = 'Latest twitts';
			$aOptions[ 'twitts_number' ] = '3';
			$aOptions[ 'twitter_user' ] = 'dameer';
			// Flickr
			$aOptions[ 'flickr_title' ] = 'Flickr';
			$aOptions[ 'flickr_noi' ] = '6';
			$aOptions[ 'flickr_tou' ] = 'user';
			$aOptions[ 'flickr_choice' ] = '14897087%40N04';
			// tagcloud
			$aOptions[ 'tagcloud_title' ] = 'Tag Cloud';
			// socialize
			$aOptions[ 'online_title' ] = 'Join Me!';
			// latest comments
			$aOptions[ 'latestcomments_title' ] = 'Recently commented';
			$aOptions[ 'latestcomments_numbr' ] = '3';
			
			// translations
			$aOptions[ 'pagetag' ] = 'Page';
			$aOptions[ 'latest_articles' ] = '最新文章';
			$aOptions[ 'navigate_site' ] = '导航';
			$aOptions[ 'home_link' ] = '首页';
			$aOptions[ 'copytext' ] = '&copy; Company Name ';
			$aOptions[ 'readmore' ] = ' ...更多';
			$aOptions[ 'sing_comments' ] = '评论';
			$aOptions[ 'plur_comments' ] = '评论';
			$aOptions[ 'searchtitle' ] = '搜索';
			$aOptions[ 'searchresults' ] = '找到:';
			$aOptions[ 'for_phrase' ] = 'for';
			$aOptions[ 'searchtag' ] = '搜索';
			$aOptions[ 'nametag' ] = '名字';
			$aOptions[ 'emailtag' ] = 'E-mail';
			$aOptions[ 'webtag' ] = '网站';
			$aOptions[ 'phonetag' ] = '电话';
			$aOptions[ 'commenttag' ] = '评论';
			$aOptions[ 'leavecomment' ] = '评论';
			$aOptions[ 'submittag' ] = '提交';
			$aOptions[ 'you_here' ] = '当前位置:';
		}
		return $aOptions;
	}

	function displayOptions () {
		$aOptions = SofaiBloggr::initOptions( false );
?>
<style type="text/css"> 
.mytable {
	width: 800px;
	padding: 0;
	margin: 0;
	font: 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
	border: 1px solid #CCC;
	margin-bottom: 20px;
}
td {
	border-bottom: 1px solid #CCC;
	background: #fff;
	padding: 10px;
	color: #4f6b72;
}
td.right {
	text-align: right;
	border: none;
}
input, textarea, select.mlist {
	border: 1px solid #CFCFCF;
}
#wpcontent select.mlist {
	height: 200px;
	width: 200px;
	overflow: scroll;
}
#wpcontent .row {
	background-color: #F1F1F1; overflow: hidden; height: 30px; width: 700px; padding: 5px 10px 10px 10px; margin-bottom: 10px;
}
#wpcontent .cbholder {
	width: 300px; float: left; display: inline; padding: 11px 0 0 0;
}
#wpcontent .snholder {
	width: 300px; float: left; display: inline; padding: 5px 0;
}
#wpcontent .clear { height: 10px; width: 600px; clear: both; }
textarea {
	width: 99%;
}
p {
	font-weight: bold;
	color: #666666;
}
span.exp {
	font-weight: normal;
	font-style: italic;
}
</style>

<div class="wrap">
	<h2>Sofa iBloggr Theme Options</h2>
    <form action="#" method="post" enctype="multipart/form-data" name="massive_form" id="massive_form">

<table class="mytable">
  <tr>
    <td>
        <h2>Use breadcrumbs?</h2>
        <p>Decide whether you need it or not, it's optional...</p>
    </td>
  </tr>
  <tr>
    <td>
    <p>Select [ <span class="exp">Yes or No</span> ]</p>
        <select id="usebread" name="usebread" size="1">
        	<?php
			if( $aOptions['usebread'] == "yes" ) {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
            <?php
			} else if( $aOptions['usebread'] == "no" ) {
			?>
        	<option value="yes"> - YES - </option>
            <option value="no" selected="selected"> - NO - </option>
            <?php
			} else {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
			<?php
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sib_save" value="Save Options" /></td>
  </tr>
</table>

<table class="mytable">
  <tr>
    <td>
        <h2>Cut (trim) Post preview text</h2>
        <p>No need to use &lt;!-- more --&gt; text splitter when writting Post. Set preferred number of words after which Post preview text will be trimmed.</p>
    </td>
  </tr>
  <tr>
    <td>
    <p>Cut/trim Post preview text after NN number of words: [ select <span class="exp">number, integer (for example: 25)</span> ]</p>
    <input name="trim_text" id="trim_text" value="<?php echo stripslashes( $aOptions[ 'trim_text' ] ); ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sib_save" value="Save Options" /></td>
  </tr>
</table>


<table class="mytable">
  <tr>
    <td>
        <h2 id="is_settings">Image size settings</h2>
        <p>
        Page and Post details can use the following image size...
        </p>
    </td>
  </tr>
  <tr>
    <td>
    <p>Post details template image size: [ select <span class="exp">thumbnail, medium or large</span> ]</p>
        <select id="is_postdetails" name="is_postdetails" size="1">
        	<?php
			if ( $aOptions['is_postdetails'] == "thumbnail" ) {
			?>
        	<option value="thumbnail" selected="selected"> - Thumbnail - </option>
            <option value="medium"> - Medium - </option>
            <option value="large"> - Large - </option>
            <?php
			} else if ( $aOptions['is_postdetails'] == "medium" ) {
			?>
        	<option value="medium" selected="selected"> - Medium - </option>
            <option value="thumbnail"> - Thumbnail - </option>
            <option value="large"> - Large - </option>
            <?php
			} else if( $aOptions['is_postdetails'] == "large" ) {
			?>
        	<option value="large" selected="selected"> - Large - </option>
            <option value="thumbnail"> - Thumbnail - </option>
            <option value="medium"> - Medium - </option>
			<?php
			} else {
			?>
        	<option value="thumbnail" selected="selected"> - Thumbnail - </option>
            <option value="medium"> - Medium - </option>
            <option value="large"> - Large - </option>
            <?php	
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td>
        <p>
        You can use the following image size for all the Pages on your site as well...
        </p>
    </td>
  </tr>
  <tr>
    <td>
    <p>Use the following image format on Page template: [ select <span class="exp">thumbnail, medium or large</span> ]</p>
        <select id="is_pagei" name="is_pagei" size="1">
        	<?php
			if ( $aOptions[ 'is_pagei' ] == "thumbnail" ) {
			?>
        	<option value="thumbnail" selected="selected"> - Thumbnail - </option>
            <option value="medium"> - Medium - </option>
            <option value="large"> - Large - </option>
            <?php
			} else if ( $aOptions[ 'is_pagei' ] == "medium" ) {
			?>
        	<option value="medium" selected="selected"> - Medium - </option>
            <option value="thumbnail"> - Thumbnail - </option>
            <option value="large"> - Large - </option>
            <?php
			} else if( $aOptions[ 'is_pagei' ] == "large" ) {
			?>
        	<option value="large" selected="selected"> - Large - </option>
            <option value="thumbnail"> - Thumbnail - </option>
            <option value="medium"> - Medium - </option>
			<?php
			} else {
			?>
        	<option value="thumbnail" selected="selected"> - Thumbnail - </option>
            <option value="medium"> - Medium - </option>
            <option value="large"> - Large - </option>
            <?php	
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sib_save" value="Save Options" /></td>
  </tr>
</table>

<table class="mytable">
  <tr>
    <td>
        <h2  id="hpl_settings">Include the following Pluggers to site footer</h2>
        <p>Below is the list of available Pluggers which can be included in each page of your site. Tick the checkbox next to Plugger name you want to use.</p>
    </td>
  </tr>
  <tr>
    <td>
    <p>Check or uncheck available Plugger | Add sorting number to change the appearance order</p>
    <input type="hidden" name="footerpluggs" id="footerpluggs" value="<?php echo $aOptions[ 'footerpluggs' ]; ?>" size="100"></input>
    <?php
	$pluggers_path = TEMPLATEPATH . "/pluggers";
	$pluggers_dir = opendir( $pluggers_path );
	$arr_all_pluggers_sb = array();
	if( $aOptions[ 'footerpluggs' ] ) {
		$arr_all_pluggers_sb = explode( ",", $aOptions[ 'footerpluggs' ] );
	}
	while( ( $plugger_file_sb = readdir( $pluggers_dir ) ) !== false ) {
		if( $plugger_file_sb != "." && $plugger_file_sb != ".." ) {
			$pluggers_data_aray_sb = explode( "_", $plugger_file_sb );
			if( $pluggers_data_aray_sb[ 0 ] == "plugger" ) {
				$checked_sb = "";
				$pluggers_suffix_sb = explode( ".", $pluggers_data_aray_sb[ 1 ] );
				
				$sn_val_sb = "";
				$in_position_sb = key( preg_grep( "/{$pluggers_suffix_sb[ 0 ]}/i", $arr_all_pluggers_sb ) );
				if( strlen( $in_position_sb ) > 0 ) {
					$in_p_arr_sb = explode( ":", $arr_all_pluggers_sb[ $in_position_sb ] );
					$sn_val_sb = $in_p_arr_sb[ 1 ];
					$checked_sb = ' checked="checked"';
				}
				echo "<div class='row'>";
				echo "<div class='cbholder'>";
				echo "<input style='margin-right: 5px;' type='checkbox' id='" . $pluggers_suffix_sb[ 0 ] . "_footerpluggs' name='plugger_footerpluggs' value='" . $pluggers_suffix_sb[ 0 ] . "' " . $checked_sb . " onchange='makeValuePlugger( \"footerpluggs\" )' />";
				echo "<label for='" . $pluggers_suffix_sb[ 0 ] . "_footerpluggs'>" . $pluggers_suffix_sb[ 0 ] . "</label>";
				echo "</div>";
				echo "<div class='snholder'>";
				echo "<input type='text' style='margin-right: 5px;' name='sort_" . $pluggers_suffix_sb[ 0 ] . "_footerpluggs' id='sort_" . $pluggers_suffix_sb[ 0 ] . "' value='" . $sn_val_sb . "' size='2' onchange='makeValuePlugger( \"footerpluggs\" )'></input>";
				echo "<label for='sort_" . $pluggers_suffix_sb[ 0 ] . "_footerpluggs'> sort num.</label>"; 
                echo "</div>";
				echo "</div>";
			}
		}
	}
	closedir( $pluggers_dir );
	?>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sib_save" value="Save Options" /></td>
  </tr>
</table>

<table class="mytable">
  <tr>
    <td>
        <h2 id="ppt_settings">Plugger 'Twitter' settings</h2>
        <p>Displaying twitts on your site requires the following information...</p>
    </td>
  </tr>
  <tr>
    <td>
    <p>Twitter title [ <span class="exp">string, no HTML!</span> ]</p>
    <input name="twitter_title" id="twitter_title" value="<?php echo( stripslashes( $aOptions[ 'twitter_title' ] ) ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Number of displayed twitts [ <span class="exp">number, integer</span> ]</p>
    <input name="twitts_number" id="twitts_number" value="<?php echo $aOptions[ 'twitts_number' ]; ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Twitter user name [ <span class="exp">for example: bjorg</span> ]</p>
    <input name="twitter_user" id="twitter_user" value="<?php echo( stripslashes( $aOptions[ 'twitter_user' ] ) ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sib_save" value="Save Options" /></td>
  </tr>
</table>

<table class="mytable">
  <tr>
    <td>
        <h2 id="pfli_settings">Plugger 'Flickr'</h2>
        <p>Flickr settings</p>
    </td>
  </tr>
  <tr>
    <td>
    <p>Plugger title [ <span class="exp">string, no HTML!</span> ]</p>
    <input name="flickr_title" id="flickr_title" value="<?php echo( stripslashes( $aOptions[ 'flickr_title' ] ) ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Number of thumbnails to display [ <span class="exp">number, integer</span> ]</p>
    <input name="flickr_noi" id="flickr_noi" value="<?php echo $aOptions[ 'flickr_noi' ]; ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Display images by Tag or User? [ select <span class="exp">Tag or User</span> ]</p>
        <select id="flickr_tou" name="flickr_tou" size="1">
        	<?php
			if( $aOptions['flickr_tou'] == "all_tag" ) {
			?>
        	<option value="all_tag" selected="selected"> - Tag - </option>
            <option value="user"> - User - </option>
            <?php
			} else if( $aOptions['flickr_tou'] == "user" ) {
			?>
        	<option value="all_tag"> - Tag - </option>
            <option value="user" selected="selected"> - User - </option>
            <?php
			} else {
			?>
        	<option value="all_tag" selected="selected"> - Tag - </option>
            <option value="user"> - User - </option>
			<?php
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td>
    <p>If your choice was 'User', enter Flickr user ID [ <span class="exp">string, no HTML! For example: '14897087@N04'</span> ]<br />
    Otherwise enter tags separated by comma [ <span class="exp">string, no HTML! For example: 'wordpress, theme, web'</span> ]</p>
    <input name="flickr_choice" id="flickr_choice" value="<?php echo( stripslashes( urldecode( $aOptions[ 'flickr_choice' ] ) ) ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sib_save" value="Save Options" /></td>
  </tr>
</table>

<table class="mytable">
  <tr>
    <td>
        <h2 id="pptc_settings">Plugger 'Tag Cloud'</h2>
        <p>This Plugger unit will display tags cloud.</p>
    </td>
  </tr>
  <tr>
    <td>
    <p>Plugger title [ <span class="exp">string, no HTML!</span> ]</p>
    <input name="tagcloud_title" id="tagcloud_title" value="<?php echo( stripslashes( $aOptions[ 'tagcloud_title' ] ) ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sib_save" value="Save Options" /></td>
  </tr>
</table>

<table class="mytable">
  <tr>
    <td>
        <h2 id="ppoa_settings">Plugger 'Online Activity'</h2>
        <p>List of accounts to follow; LinkedIn, Facebook, Skype, RSS, Twitter, etc. You must edit source code of this Plugger manually because it's individual: open 'pluggers' folder, 'plugger_OnlineActivity.php' file, edit by following existing HTML pattern and save.</p>
    </td>
  </tr>
  <tr>
    <td>
    <p>Plugger title [ <span class="exp">string, no HTML!</span> ]</p>
    <input name="online_title" id="online_title" value="<?php echo( stripslashes( $aOptions[ 'online_title' ] ) ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sib_save" value="Save Options" /></td>
  </tr>
</table>
            
<table class="mytable">
  <tr>
    <td>
        <h2 id="ppt_settings">Plugger 'Latest Comments' settings</h2>
        <p>Would you like to have the latest comments always displayed in page footer?</p>
    </td>
  </tr>
  <tr>
    <td>
    <p>Latest comments title [ <span class="exp">string, no HTML!</span> ]</p>
    <input name="latestcomments_title" id="latestcomments_title" value="<?php echo( stripslashes( $aOptions[ 'latestcomments_title' ] ) ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Number of displayed items [ <span class="exp">number, integer</span> ]</p>
    <input name="latestcomments_numbr" id="latestcomments_numbr" value="<?php echo $aOptions[ 'latestcomments_numbr' ]; ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sib_save" value="Save Options" /></td>
  </tr>
</table>            
    
<table class="mytable">
  <tr>
    <td>
        <h2>Translations</h2>
        <p>
        Translate default theme phrases.
        </p>
    </td>
  </tr>
  <tr>
    <td>
    <p>Latest Articles (Home page latest articles title)</p>
    <input name="latest_articles" id="latest_articles" value="<?php echo stripslashes( $aOptions[ 'latest_articles' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Page (general phrase)</p>
    <input name="pagetag" id="pagetag" value="<?php echo stripslashes( $aOptions[ 'pagetag' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Navigate (open-close main navigation link label)</p>
    <input name="navigate_site" id="navigate_site" value="<?php echo stripslashes( $aOptions[ 'navigate_site' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Home (Home page link name in main navigation)</p>
    <input name="home_link" id="home_link" value="<?php echo stripslashes( $aOptions[ 'home_link' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>&copy; Company Name</p>
    <input name="copytext" id="copytext" value="<?php echo stripslashes( $aOptions[ 'copytext' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>...READ MORE</p>
    <input name="readmore" id="readmore" value="<?php echo stripslashes( $aOptions[ 'readmore' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Comment (singular)</p>
    <input name="sing_comments" id="sing_comments" value="<?php echo stripslashes( $aOptions[ 'sing_comments' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Comments (plural)</p>
    <input name="plur_comments" id="plur_comments" value="<?php echo stripslashes( $aOptions[ 'plur_comments' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Search the site (search form title)</p>
    <input name="searchtitle" id="searchtitle" value="<?php echo stripslashes( $aOptions[ 'searchtitle' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Found: (search results prefix string)</p>
    <input name="searchresults" id="searchresults" value="<?php echo stripslashes( $aOptions[ 'searchresults' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>for (general phrase)</p>
    <input name="for_phrase" id="for_phrase" value="<?php echo stripslashes( $aOptions[ 'for_phrase' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Search (button label)</p>
    <input name="searchtag" id="searchtag" value="<?php echo stripslashes( $aOptions[ 'searchtag' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Name (contact/comment form label)</p>
    <input name="nametag" id="nametag" value="<?php echo stripslashes( $aOptions[ 'nametag' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>E-mail (contact/comment form label)</p>
    <input name="emailtag" id="emailtag" value="<?php echo stripslashes( $aOptions[ 'emailtag' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Website (comment form label)</p>
    <input name="webtag" id="webtag" value="<?php echo stripslashes( $aOptions[ 'webtag' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Phone/Cell/Skype (contact form label)</p>
    <input name="phonetag" id="phonetag" value="<?php echo stripslashes( $aOptions[ 'phonetag' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Comments (comments section title)</p>
    <input name="commenttag" id="commenttag" value="<?php echo stripslashes( $aOptions[ 'commenttag' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Leave a Comment (comments form title)</p>
    <input name="leavecomment" id="leavecomment" value="<?php echo stripslashes( $aOptions[ 'leavecomment' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>Submit (button label)</p>
    <input name="submittag" id="submittag" value="<?php echo stripslashes( $aOptions[ 'submittag' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p>You are here: (breadcrumbs label/title)</p>
    <input name="you_here" id="you_here" value="<?php echo stripslashes( $aOptions[ 'you_here' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  
  <tr>
    <td class="right"><input type="submit" name="sib_save" value="Save Options" /></td>
  </tr>
</table>

    </form>
</div>

<script language="javascript" type="text/javascript">
		function makeValuePlugger( loc ) {
			var val = "";
			var old = eval( "document.getElementById( 'massive_form' )." + loc );
			var cbs = eval( "document.getElementById( 'massive_form' ).plugger_" + loc );
			for( var n = 0; n < cbs.length; n ++ ) {
				if( cbs[ n ].checked ) {
					var sort_field = eval( "document.getElementById( 'massive_form' ).sort_" + cbs[ n ].id );
					var sort_num = parseInt( sort_field.value );
					if( isNaN( sort_num ) ) sort_field.value = n + 1;
					val += cbs[ n ].value + ":" + sort_field.value + ",";
				} else {
					var sort_field = eval( "document.getElementById( 'massive_form' ).sort_" + cbs[ n ].id );
					sort_field.value = "";
				}
			}
			var temp = val.split( "," );
			temp.pop();
			temp.sort( function compareStrnum( a, b ) { return a.replace( /[^.0-9]/g, "" ) - b.replace( /[^.0-9]/g, "" ) } );
			old.value = temp;
		}
</script>

<?php
	}
}
// Register class
add_action( 'admin_menu', array( 'SofaiBloggr', 'addOptions' ) );
?>
<?php
// image harvest
function get_cont_custom_size_image( $cont = '', $img_type = 'thumbnail', $pid = 0 ) {
	$arrImages =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $pid );
	if( $arrImages && $cont != '' ) {
		$patterns = array( '|width=[\'"](.*?)[\'"].*?|i', '|height=[\'"](.*?)[\'"].*?|i' );
		$cont = preg_replace( $patterns, '', $cont );
		$arrKeys = array_keys( $arrImages );
		$i = 0;
		while( $i < count( $arrImages ) ) {
			// uploaded image width and height
			list( $aip_w, $aip_h ) = getimagesize( wp_get_attachment_url( $arrKeys[ $i ] ) );
			if( $img_type == 'thumbnail' ) {
				$required_file_path = wp_get_attachment_thumb_url( $arrKeys[ $i ] );
			} else if( $img_type == 'medium' ) {
				$medium_array = image_downsize( $arrKeys[ $i ], 'medium' );
				$required_file_path = $medium_array[ 0 ];
			} else if( $img_type == 'large' ) {
				// reqest large size Media settings
				$large_size_w = get_option( 'large_size_w' );
				// do we actually need downsampled image?
				if( (int)$large_size_w < (int)$aip_w ) {
					$large_array = image_downsize( $arrKeys[ $i ], 'large' );
					$required_file_path = $large_array[ 0 ];
				} else {
					$required_file_path = wp_get_attachment_url( $arrKeys[ $i ] );
				}
			}
			// save file type
			$file_extension_array = explode( '/', $arrImages[ $arrKeys[ $i ] ]->guid );
			$file_type_array = explode( '.', $file_extension_array[ count( $file_extension_array ) - 1 ] );
			// splitter
			$split_by_arr = explode( '.' . $file_type_array[ 1 ], $arrImages[ $arrKeys[ $i ] ]->guid );
			$split_by = $split_by_arr[ 0 ];
			$arr_orig = explode( 'src="' . $split_by, $cont );
			$arr_orig_first = explode( '.' . $file_type_array[ 1 ], $arr_orig[ 1 ] );
			$orig_size_tit = $arr_orig_first[ 0 ];
			$arr_chck_ext = explode( '"', $arr_orig[ 1 ] );
			$arr_first_member = explode( '.', $arr_chck_ext[ 0 ] );
			if( $arr_first_member[ 1 ] == $file_type_array[ 1 ] ) $cont = str_replace( ( $split_by . $orig_size_tit . '.' . $file_type_array[ 1 ] ), $required_file_path, $cont );
			$i ++;
		}
	} 
	return $cont;
}
//the_content() trim
function trim_the_content( $the_contents, $read_more_tag = ' READ MORE...', $perma_link_to = '', $all_words = 45 ) {
	// make the list of allowed tags
	$allowed_tags = array( 'a', 'abbr', 'b', 'blockquote', 'b', 'cite', 'code', 'div', 'em', 'fon', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'label', 'i', 'p', 'pre', 'span', 'strong', 'title', 'ul', 'ol', 'li', 'object', 'embed' );
	if( $the_contents != '' ) {
		// process allowed tags
		$allowed_tags = '<' . implode( '><', $allowed_tags ) . '>';
		$the_contents = str_replace( ']]>', ']]&gt;', $the_contents );
		$the_contents = strip_tags( $the_contents, $allowed_tags );
		// exclude HTML from counting words
		if( $all_words > count( preg_split( '/[\s]+/', strip_tags( $the_contents ), -1 ) ) ) return $the_contents;
		// count all
		$all_chunks = preg_split( '/([\s]+)/', $the_contents, -1, PREG_SPLIT_DELIM_CAPTURE );
		$the_contents = '';
		$count_words = 0;
		$enclosed_by_tag = false;
		foreach( $all_chunks as $chunk ) {
			// is tag opened?
			if( 0 < preg_match( '/<[^>]*$/s', $chunk ) ) $enclosed_by_tag = true;
			elseif( 0 < preg_match( '/>[^<]*$/s', $chunk ) ) $enclosed_by_tag = false;
			// get entire word
			if( !$enclosed_by_tag && '' != trim( $chunk ) && substr( $chunk, -1, 1 ) != '>' ) $count_words ++;
			$the_contents .= $chunk;
			if( $count_words >= $all_words && !$enclosed_by_tag ) break;
		}
                // note the class named 'more-link'. style it on your own
		$the_contents = $the_contents . '<a class="more-link" href="' . $perma_link_to . '">' . $read_more_tag . '</a>';
		// native WordPress check for unclosed tags
		$the_contents = force_balance_tags( $the_contents );
	}
	return $the_contents;
}
// make nice numberz
function parseInt( $string ) {
	if( preg_match( '/(\d+)/', $string, $array ) ) return $array[ 1 ];
	else return 0;
}
?>