function Lenta_EditFav($msg_id, $priority = 0, $title = "", $action = "edit", $pfx = "CM") { global $session, $stars; session_start(); $user_id = $_SESSION['uid']; $objResponse = new xajaxResponse(); $msg_id = intval($msg_id); $GLOBALS['xajax']->setCharEncoding("windows-1251"); $action = trim($action); switch ($action) { case "update": //$title = pg_escape_string(substr($title, 0, 128)); $title = substr($title, 0, 128); switch ($pfx) { case 'CM': $updatefav = lenta::AddFav($user_id, $msg_id, 0, 0, 0, $priority, $title); $fav_href = "/commune/?id={$editfav['commune_id']}&site=Topic&post={$msg_id}"; break; case 'PF': $updatefav = lenta::AddFav($user_id, 0, $msg_id, 0, 0, $priority, $title); $fav_href = "/users/{$editfav['login']}/viewproj.php?prjid={$msg_id}"; break; case 'BL': $updatefav = lenta::AddFav($user_id, 0, 0, $msg_id, 0, $priority, $title); $fav_href = "/blogs/view.php?tr={$msg_id}"; break; } $editfav = lenta::GetFav($user_id, $msg_id, $pfx); $key = $msg_id; // $fav_href = ( $pfx=='CM' ? "/commune/?id={$editfav['commune_id']}&site=Topic&post={$msg_id}" : "/users/{$editfav['login']}/viewproj.php?prjid={$msg_id}"); $outHTML = __lentaPrntFavContent($editfav, $key, $user_id, $pfx, $fav_href); $objResponse->assign("fav" . $pfx . $msg_id, "innerHTML", $outHTML); // $objResponse->assign('favstar'.$pfx.$msg_id, "src", "/images/ico_star_{$priority}.gif"); $objResponse->assign('favstar' . $pfx . $msg_id, "src", "/images/bookmarks/" . $stars[$priority]); break; case "edit": $editfav = lenta::GetFav($user_id, $msg_id, $pfx); $editfav['title'] = str_replace("<br/>", "\r\n", reformat2($editfav['title'], 20, 0, 1)); $outHTML = "<table border=\"0\" cellpadding=\"1\" cellspacing=\"0\"><tbody><tr valign=\"top\"><td style=\"padding-left: 3px;\">"; $outHTML .= "<ul class=\"post-f-fav-sel\">"; $outHTML .= "<li><IMG alt=\"\" border=\"0\" id='favpic" . $pfx . $msg_id . "-0' width=\"15\" height=\"15\" src=\"/images/ico_star_0" . ($editfav['priority'] != 0 ? "_empty" : "") . ".gif\" hspace=\"1\" vspace=\"1\" onclick=\"FavPriorityLenta({$msg_id}, 0, '{$pfx}')\" style=\"cursor:pointer;\"></li>"; $outHTML .= "<li><IMG alt=\"\" border=\"0\" id='favpic" . $pfx . $msg_id . "-1' width=\"15\" height=\"15\" src=\"/images/ico_star_1" . ($editfav['priority'] != 1 ? "_empty" : "") . ".gif\" hspace=\"1\" vspace=\"1\" onclick=\"FavPriorityLenta({$msg_id}, 1, '{$pfx}')\" style=\"cursor:pointer;\"></li>"; $outHTML .= "<li><IMG alt=\"\" border=\"0\" id='favpic" . $pfx . $msg_id . "-2' width=\"15\" height=\"15\" src=\"/images/ico_star_2" . ($editfav['priority'] != 2 ? "_empty" : "") . ".gif\" hspace=\"1\" vspace=\"1\" onclick=\"FavPriorityLenta({$msg_id}, 2, '{$pfx}')\" style=\"cursor:pointer;\"></li>"; $outHTML .= "<li><IMG alt=\"\" border=\"0\" id='favpic" . $pfx . $msg_id . "-3' width=\"15\" height=\"15\" src=\"/images/ico_star_3" . ($editfav['priority'] != 3 ? "_empty" : "") . ".gif\" hspace=\"1\" vspace=\"1\" onclick=\"FavPriorityLenta({$msg_id}, 3, '{$pfx}')\" style=\"cursor:pointer;\"></li>"; $outHTML .= "</ul></td><td>"; $outHTML .= "<div class=\"fav-one-edit-txt\">"; $outHTML .= "<INPUT id='favpriority" . $pfx . $msg_id . "' type='hidden' value='" . $editfav['priority'] . "'>"; $outHTML .= "<INPUT id='currtitle' type='hidden' value='" . $editfav['title'] . "'>"; $outHTML .= "<textarea rows=\"3\" cols=\"7\" id='favtext" . $pfx . $msg_id . "'>{$editfav['title']}</textarea>"; $outHTML .= "<div class=\"fav-one-edit-btns\">"; $outHTML .= "<INPUT type='button' value='Сохранить' onClick='if(document.getElementById(\"favtext" . $pfx . $msg_id . "\").value.length>128){alert(\"Слишком длинное название закладки!\");return false;}else{xajax_Lenta_EditFav(" . $msg_id . ", document.getElementById(\"favpriority" . $pfx . $msg_id . "\").value, document.getElementById(\"favtext" . $pfx . $msg_id . "\").value, \"update\", \"{$pfx}\");}'>"; $outHTML .= "<INPUT type='button' value='Отмена' onClick='xajax_Lenta_EditFav(" . $msg_id . ", " . $editfav['priority'] . ", document.getElementById(\"currtitle\").value, \"default\", \"{$pfx}\");'>"; $outHTML .= "</div></td></tr></tbody></table>"; //$outHTML = "<li class=\"fav-one-edit c\">"; $outHTML = "<ul class=\"post-f-fav-sel\">"; $outHTML .= "<li><a href=\"\" onclick=\"FavPriorityLenta({$msg_id}, 0, '{$pfx}'); return false;\"><img src=\"../../images/bookmarks/bsg.png\" alt=\"\" id='favpic" . $pfx . $msg_id . "-0' /></a></li>"; $outHTML .= "<li><a href=\"\" onclick=\"FavPriorityLenta({$msg_id}, 1, '{$pfx}'); return false;\"><img src=\"../../images/bookmarks/bsgr.png\" alt=\"\" id='favpic" . $pfx . $msg_id . "-1'/></a></li>"; $outHTML .= "<li><a href=\"\" onclick=\"FavPriorityLenta({$msg_id}, 2, '{$pfx}'); return false;\"><img src=\"../../images/bookmarks/bsy.png\" alt=\"\" id='favpic" . $pfx . $msg_id . "-2'/></a></li>"; $outHTML .= "<li><a href=\"\" onclick=\"FavPriorityLenta({$msg_id}, 3, '{$pfx}'); return false;\"><img src=\"../../images/bookmarks/bsr.png\" alt=\"\" id='favpic" . $pfx . $msg_id . "-3'/></a></li>"; $outHTML .= "</ul>"; $outHTML .= "<div class=\"fav-one-edit-txt\">"; $outHTML .= "<INPUT id='favpriority" . $pfx . $msg_id . "' type='hidden' value='" . $editfav['priority'] . "'>"; $outHTML .= "<INPUT id='currtitle' type='hidden' value='" . $editfav['title'] . "'>"; $outHTML .= "<textarea rows=\"3\" cols=\"7\" id='favtext" . $pfx . $msg_id . "'>{$editfav['title']}</textarea>"; $outHTML .= "<div class=\"fav-one-edit-btns\"><input type=\"button\" value=\"Сохранить\" onClick='if(document.getElementById(\"favtext" . $pfx . $msg_id . "\").value.length>128){alert(\"Слишком длинное название закладки!\");return false;}else{xajax_Lenta_EditFav(" . $msg_id . ", document.getElementById(\"favpriority" . $pfx . $msg_id . "\").value, document.getElementById(\"favtext" . $pfx . $msg_id . "\").value, \"update\", \"{$pfx}\"); \$(\"fav" . $pfx . $msg_id . "edit\").dispose();}'/> <input type=\"button\" value=\"Отмена\" onClick='xajax_Lenta_EditFav(" . $msg_id . ", " . $editfav['priority'] . ", document.getElementById(\"currtitle\").value, \"default\", \"{$pfx}\"); \$(\"fav" . $pfx . $msg_id . "edit\").dispose();' /></div>"; $outHTML .= "</div>"; //$outHTML .= "</li>"; $objResponse->insertAfter("fav" . $pfx . $msg_id, "li", "fav" . $pfx . $msg_id . "edit"); $objResponse->assign("fav" . $pfx . $msg_id . "edit", "className", "fav-one-edit"); $objResponse->assign("fav" . $pfx . $msg_id . "edit", "innerHTML", $outHTML); // $objResponse->assign("fav".$pfx.$msg_id, "innerHTML", $outHTML); break; default: $editfav = lenta::GetFav($user_id, $msg_id, $pfx); $key = $msg_id; // $fav_href = ( $pfx=='CM' ? "/commune/?id={$editfav['commune_id']}&site=Topic&post={$msg_id}" : "/users/{$editfav['login']}/viewproj.php?prjid={$msg_id}"); switch ($pfx) { case 'CM': $updatefav = lenta::AddFav($user_id, $msg_id, 0, 0, 0, $priority, $title); $fav_href = "/commune/?id={$editfav['commune_id']}&site=Topic&post={$msg_id}"; break; case 'PF': $updatefav = lenta::AddFav($user_id, 0, $msg_id, 0, 0, $priority, $title); $fav_href = "/users/{$editfav['login']}/viewproj.php?prjid={$msg_id}"; break; case 'BL': $updatefav = lenta::AddFav($user_id, 0, 0, $msg_id, 0, $priority, $title); $fav_href = "/blogs/view.php?tr={$msg_id}"; break; } $outHTML = __lentaPrntFavContent($editfav, $key, $user_id, $pfx, $fav_href); $objResponse->assign("fav" . $pfx . $msg_id, "innerHTML", $outHTML); break; } return $objResponse; }
/** * Выводит блок закладок пользователя * * @param array $favs массив закладок * @param integer $user_id id пользователя * * @return HTML HTML-код */ function __lentaPrntFavs($favs, $user_id) { if (!is_array($favs)) { return false; } ob_start(); foreach ($favs as $key => $fav) { $pfx = substr($key, 0, 2); $fav_id = substr($key, 2); switch ($pfx) { case 'CM': $fav_href = "/commune/?id={$fav['commune_id']}&site=Topic&post={$fav_id}"; break; case 'PF': $fav_href = "/users/{$fav['user_login']}/viewproj.php?prjid={$fav_id}"; break; case 'BL': $fav_href = getFriendlyURL("blog", $fav_id); break; } echo "<li id=\"fav{$key}\">"; echo __lentaPrntFavContent($fav, $fav_id, $user_id, $pfx, $fav_href); echo "</li>"; } $str = ob_get_contents(); ob_end_clean(); return $str; }