#

function declension($int, $expressions, $showint = true) {
settype($int, "integer");
$count = $int % 100;
if ($count >= 5 && $count <= 20) {
$result = ($showint? $int." ":"").$expressions['2'];
} else {
$count = $count % 10;
if ($count == 1) {
$result = ($showint? $int." ":"").$expressions['0'];
} elseif ($count >= 2 && $count <= 4) {
$result = ($showint? $int." ":"").$expressions['1'];
} else {
$result = ($showint? $int." ":"").$expressions['2'];
}
}
return $result;
}


echo ' '.price_format($total_price).' '.declension($total_price, array('', '',''), false).'.';

, , . true, , .

PHP / / 20.02.12 / [0]

#

function rmkdir($path, $mode = 0777) {
$path = rtrim(preg_replace(array("/\\\\/", "/\/{2,}/"), "/", $path), "/");
$e = explode("/", ltrim($path, "/"));
if(substr($path, 0, 1) == "/") {
$e[0] = "/".$e[0];
}
$c = count($e);
$cp = $e[0];
for($i = 1; $i < $c; $i++) {
if(!is_dir($cp) && [email protected]($cp, $mode)) {
return false;
}
$cp .= "/".$e[$i];
}
return @mkdir($path, $mode);
}

PHP / / 19.02.12 / [0]

#

function remove_dups($array, $row_element) {
$new_array[0] = $array[0];
foreach ($array as $current) {
$add_flag = 1;
foreach ($new_array as $tmp) {
if ($current[$row_element]==$tmp[$row_element]) {
$add_flag = 0; break;
}
}
if ($add_flag) $new_array[] = $current;
}
return $new_array;
}


:
2012 -
2012 -
2012 -

month
$array2 = remove_dups($array, 'month');


:
2012 -
2012 -

PHP / / 18.02.12 / [0]

( ) PHP #

4 , 10($nNumOfTags) .
$nNumTags = 10;
$szContent = strip_tags(" ");
$arr_tags = explode(' ', $szContent);
shuffle($arr_tags);
$nNumOfTags = 0;
$str_tag = '';
foreach ( $arr_tags as $tvalue ) {
$tvalue = trim($tvalue);
preg_match('/[a-zA-Z--]{4,}/', $tvalue, $t_v);
if ($t_v[0]) {
$str_tag .= $t_v[0].', ';
$nNumOfTags ++;
}
if ($nNumOfTags > $nNumTags)
break;
};
//$_POST['tags'] = substr($str_tag, 0, strlen($str_tag)-1);
$tags = substr($str_tag, 0, strlen($str_tag)-1);
echo $tags;
//: , , , , , , ,

PHP / / 13.02.12 / [0]

jQuery #

       jQuery

"" "" . ( ) . :

, , href .
$(function () {//
$('.lmenu a').each(function () { //
var location = window.location.href; //
var link = this.href;//
if(location == link) { //
$(this).addClass('active');//
}
});
});

?
, , , Match(). :
$(function () { //
$('.lmenu a').each(function () {//
var location = window.location.href //
var link = this.href// url
var result = location.match(link);// null

if(result != null) {// null
$(this).addClass('current');//
}
});
});

JavaScript, / : , , , / 12.02.12 / [0]

PHP #

index.php
$conf['db'] = array(
"server"=>"localhost",
"user"=>"root",
"pass"=>"",
"base"=>"superbase"
);

mysql_connect($conf['db']['server'], $conf['db']['user'], $conf['db']['pass'])or die("Could not connect: ".mysql_error());
mysql_select_db($conf['db']['base'])or die("Could not select: ".mysql_error());
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");

if($_GET['op'] === 'clear-all'){
mysql_query("DELETE FROM les_comments");
header("Location: index.php");
}

$time = time();

if(isset($_POST['uname'])){
$uname = mysql_real_escape_string($_POST['uname']);
setcookie("unamecom", $uname, $time + 1209600); //
}elseif(isset($_COOKIE["unamecom"])){
$uname = mysql_real_escape_string($_COOKIE["unamecom"]);
}else{
$uname = "";
}

if(!empty($_POST['uname']) && !empty($_POST['message']) && $_POST['op'] == 'add-comment') {


$comment = mysql_real_escape_string(strip_tags($_POST['message'], "

")); //
$ip = $_SERVER['REMOTE_ADDR'];
$client = $_SERVER['HTTP_USER_AGENT'];
$content_id = intval($_POST['content']);
$parent_id = intval($_POST['parent']);

mysql_query("INSERT INTO les_comments (`id`, `name`, `ip`, `client`, `comment`, `content_id`, `parent_id`, `time`) VALUES (NULL, '$uname', '$ip', '$client', '$comment', '$content_id', '$parent_id', '$time')");
}

/*
*/

$content_id = 0;// ( , ?)

//
$msg = array();
$result = mysql_query("SELECT * FROM les_comments WHERE content_id='$id'");
while($row = mysql_fetch_assoc($result)){
$msg[] = $row;
}
$count = count($msg);

$parent = 0;
$form = "






*



";

$i = 0;
if($count){
$comments = "
: {$count}
".$form;

$msg = crazysort($msg);
while($i<$count){
$margin = $msg[$i]['level'] * 20;
$date = date("d.m.Y H:i",$msg[$i]['time']);
$comments .= "
{$msg[$i]['name']} ({$date})
{$msg[$i]['comment']}
";
$i++;
}
}else{
$comments = "
".$form;
}

//
function crazysort(&$comments, $parentComment = 0, $level = 0, $count = null){
if (is_array($comments) && count($comments)){
$return = array();
if (is_null($count)){
$c = count($comments);
}else{
$c = $count;
}
for($i=0;$i<$c;$i++){
if (!isset($comments[$i])) continue;
$comment = $comments[$i];
$parentId = $comment['parent_id'];
if ($parentId == $parentComment){
$comment['level'] = $level;
$commentId = $comment['id'];
$return[] = $comment;
unset($comments[$i]);
while ($nextReturn = crazysort($comments, $commentId, $level+1, $c)){
$return = array_merge($return, $nextReturn);
}
}
}
return $return;
}
return false;
}
?>













echo $comments;
echo "
";
?>





sql
CREATE TABLE IF NOT EXISTS `les_comments` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
`ip` VARCHAR(15) NOT NULL,
`client` VARCHAR(250) NOT NULL,
`comment` TEXT NOT NULL,
`content_id` INT(11) NOT NULL DEFAULT '0',
`parent_id` INT(11) NOT NULL DEFAULT '0',
`time` INT(10) NOT NULL DEFAULT '0',
PRIMARY KEY(`id`)
) ENGINE=MYISAMDEFAULT CHARSET=utf8 AUTO_INCREMENT=1;


style.css
html,body{background-color:#C9CCCD;color:#000000;height:100%;font:normal 14px/20px arial}

.clear{clear:both}

.comments-all{font-size:12px;background-color:#E4E6E6; background-image:url('/images/h-rule.gif');background-repeat:no-repeat;margin-top:30px;margin-bottom:20px;padding:10px 20px; height:20px}
.add-comment{border-bottom:1px dashed #000; cursor:pointer; float:right}
.comment-title{font-size:12px; background-color:#EAEBEB; margin-top:20px; padding:5px 20px;height:20px}
.comment-message{font-size:12px; background-color:#F1F2F2; padding:5px 20px}

.comment{padding:40px 50px}
.editor{display:none; margin-top:1px;padding-top:20px; padding-left:20px;background-color:#F3F5F5}
.comment-ans{float:right; border-bottom:1px dashed #444; cursor:pointer}
#uname{font-size:16px; font-weight:bold;padding:5px;margin:10px 10px 10px 0}
#submit{padding:10px;margin:15px 0;font-weight:bold}

PHP, JavaScript / / 11.02.12 / [0]