热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

facebook有哪些信息_Facebook喜欢带有评论的照片库

facebook有哪些信息FacebooklikephotogallerywithcommentsHaveyouthoughtaboutownfacebook-stylephoto

facebook有哪些信息

Facebook like photo gallery with comments
Facebook like photo gallery with comments

Facebook like photo gallery with comments Have you thought about own facebook-style photo gallry system with comments? I think – yes. Today I made up my mind to prepare it for you. Main idea – when we click at images – they popup (ajax) with bigger image at the left and comments section at the right. All images are in the database (mySQL). And, of course, we will use PHP to achieve our result. Also, our comment system will prevent accepting more than 1 comment per 10 mins (to avoid spam).

Facebook喜欢带有评论的照片库您是否考虑过自己的带有评论的Facebook风格的照片库系统? 我想是的。 今天,我下定决心为您准备它。 主要思想-当我们单击图像时-它们会弹出(ajax),左侧显示较大的图像,右侧显示注释部分。 所有图像都在数据库(mySQL)中。 而且,当然,我们将使用PHP来达到目的。 此外,我们的评论系统将防止每10分钟接收超过1条评论(以避免垃圾邮件)。

现场演示

[sociallocker]

[社交储物柜]

打包下载

[/sociallocker]

[/ sociallocker]

Now – download the source files and lets start coding !

现在–下载源文件并开始编码!

步骤1. SQL (Step 1. SQL)

For our gallery I prepared two SQL tables: first table keeps records of our images. It contains several fields: title, filename, description, time of adding and comments count. Another table keeps comments. So, execute next SQL instructions:

对于我们的画廊,我准备了两个SQL表:第一个表保留我们图像的记录。 它包含几个字段:标题,文件名,描述,添加时间和评论数。 另一个表保留注释。 因此,执行下一条SQL指令:


CREATE TABLE IF NOT EXISTS `s281_photos` (`id` int(10) unsigned NOT NULL auto_increment,`title` varchar(255) default '',`filename` varchar(255) default '',`description` text NOT NULL,`when` int(11) NOT NULL default '0',`comments_count` int(11) NOT NULL default '0',PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `s281_photos` (`title`, `filename`, `description`, `when`) VALUES
('Item #1', 'photo1.jpg', 'Description of Item #1', UNIX_TIMESTAMP()),
('Item #2', 'photo2.jpg', 'Description of Item #2', UNIX_TIMESTAMP()+1),
('Item #3', 'photo3.jpg', 'Description of Item #3', UNIX_TIMESTAMP()+2),
('Item #4', 'photo4.jpg', 'Description of Item #4', UNIX_TIMESTAMP()+3),
('Item #5', 'photo5.jpg', 'Description of Item #5', UNIX_TIMESTAMP()+4),
('Item #6', 'photo6.jpg', 'Description of Item #6', UNIX_TIMESTAMP()+5),
('Item #7', 'photo7.jpg', 'Description of Item #7', UNIX_TIMESTAMP()+6),
('Item #8', 'photo8.jpg', 'Description of Item #8', UNIX_TIMESTAMP()+7),
('Item #9', 'photo9.jpg', 'Description of Item #9', UNIX_TIMESTAMP()+8),
('Item #10', 'photo10.jpg', 'Description of Item #10', UNIX_TIMESTAMP()+9);
CREATE TABLE IF NOT EXISTS `s281_items_cmts` (`c_id` int(11) NOT NULL AUTO_INCREMENT ,`c_item_id` int(12) NOT NULL default '0',`c_ip` varchar(20) default NULL,`c_name` varchar(64) default '',`c_text` text NOT NULL ,`c_when` int(11) NOT NULL default '0',PRIMARY KEY (`c_id`),KEY `c_item_id` (`c_item_id`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8;


CREATE TABLE IF NOT EXISTS `s281_photos` (`id` int(10) unsigned NOT NULL auto_increment,`title` varchar(255) default '',`filename` varchar(255) default '',`description` text NOT NULL,`when` int(11) NOT NULL default '0',`comments_count` int(11) NOT NULL default '0',PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `s281_photos` (`title`, `filename`, `description`, `when`) VALUES
('Item #1', 'photo1.jpg', 'Description of Item #1', UNIX_TIMESTAMP()),
('Item #2', 'photo2.jpg', 'Description of Item #2', UNIX_TIMESTAMP()+1),
('Item #3', 'photo3.jpg', 'Description of Item #3', UNIX_TIMESTAMP()+2),
('Item #4', 'photo4.jpg', 'Description of Item #4', UNIX_TIMESTAMP()+3),
('Item #5', 'photo5.jpg', 'Description of Item #5', UNIX_TIMESTAMP()+4),
('Item #6', 'photo6.jpg', 'Description of Item #6', UNIX_TIMESTAMP()+5),
('Item #7', 'photo7.jpg', 'Description of Item #7', UNIX_TIMESTAMP()+6),
('Item #8', 'photo8.jpg', 'Description of Item #8', UNIX_TIMESTAMP()+7),
('Item #9', 'photo9.jpg', 'Description of Item #9', UNIX_TIMESTAMP()+8),
('Item #10', 'photo10.jpg', 'Description of Item #10', UNIX_TIMESTAMP()+9);
CREATE TABLE IF NOT EXISTS `s281_items_cmts` (`c_id` int(11) NOT NULL AUTO_INCREMENT ,`c_item_id` int(12) NOT NULL default '0',`c_ip` varchar(20) default NULL,`c_name` varchar(64) default '',`c_text` text NOT NULL ,`c_when` int(11) NOT NULL default '0',PRIMARY KEY (`c_id`),KEY `c_item_id` (`c_item_id`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8;

步骤2. PHP (Step 2. PHP)

Now, please create empty index.php file and put next code:

现在,请创建一个空的index.php文件并放入下一个代码:

index.php (index.php)


// disable warnings
if (version_compare(phpversion(), "5.3.0", ">=") == 1)error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
elseerror_reporting(E_ALL & ~E_NOTICE);
require_once('classes/CMySQL.php'); // include service classes to work with database and comments
require_once('classes/CMyComments.php');
if ($_POST['action'] == 'accept_comment') {echo $GLOBALS['MyComments']->acceptComment();exit;
}
// prepare a list with photos
$sPhotos = '';
$aItems = $GLOBALS['MySQL']->getAll("SELECT * FROM `s281_photos` ORDER by `when` ASC"); // get photos info
foreach ($aItems as $i => $aItemInfo) {$sPhotos .= '

'.$aItemInfo['title'].' item

'.$aItemInfo['description'].'
';
}
?>



Facebook like photo gallery with comments

Back to original tutorial on Script Tutorials

Last photos:

test1
test2



// disable warnings
if (version_compare(phpversion(), "5.3.0", ">=") == 1)error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
elseerror_reporting(E_ALL & ~E_NOTICE);
require_once('classes/CMySQL.php'); // include service classes to work with database and comments
require_once('classes/CMyComments.php');
if ($_POST['action'] == 'accept_comment') {echo $GLOBALS['MyComments']->acceptComment();exit;
}
// prepare a list with photos
$sPhotos = '';
$aItems = $GLOBALS['MySQL']->getAll("SELECT * FROM `s281_photos` ORDER by `when` ASC"); // get photos info
foreach ($aItems as $i => $aItemInfo) {$sPhotos .= '

'.$aItemInfo['title'].' item

'.$aItemInfo['description'].'
';
}
?>



Facebook like photo gallery with comments

Back to original tutorial on Script Tutorials

Last photos:

test1
test2



We have just created main index file of our gallery. By default – script generates a list of images (with title and description), and it also generates an empty hidden object which we are going to use in order to accept custom content by ajax requests. Also, when we post comments, we forward this request (to accept new comment) into comments class. Now, lets review next important php file:

我们刚刚创建了画廊的主索引文件。 默认情况下,脚本会生成一个图像列表(带有标题和描述),还会生成一个空的隐藏对象,我们将使用该对象来接受ajax请求的自定义内容。 同样,当我们发表评论时,我们会将这个请求(接受新评论)转发到评论类中。 现在,让我们回顾下一个重要的php文件:

photos_ajx.php (photos_ajx.php)


// disable warnings
if (version_compare(phpversion(), "5.3.0", ">=") == 1)error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
elseerror_reporting(E_ALL & ~E_NOTICE);
if ($_POST[&#39;action&#39;] &#61;&#61; &#39;get_info&#39; && (int)$_POST[&#39;id&#39;] > 0) {require_once(&#39;classes/CMySQL.php&#39;); // include service classes to work with database and commentsrequire_once(&#39;classes/CMyComments.php&#39;);// get photo info$iPid &#61; (int)$_POST[&#39;id&#39;];$aImageInfo &#61; $GLOBALS[&#39;MySQL&#39;]->getRow("SELECT * FROM &#96;s281_photos&#96; WHERE &#96;id&#96; &#61; &#39;{$iPid}&#39;");// prepare last 10 comments$sCommentsBlock &#61; $GLOBALS[&#39;MyComments&#39;]->getComments($iPid);$aItems &#61; $GLOBALS[&#39;MySQL&#39;]->getAll("SELECT * FROM &#96;s281_photos&#96; ORDER by &#96;when&#96; ASC"); // get photos info// Prev & Next navigation$sNext &#61; $sPrev &#61; &#39;&#39;;$iPrev &#61; (int)$GLOBALS[&#39;MySQL&#39;]->getOne("SELECT &#96;id&#96; FROM &#96;s281_photos&#96; WHERE &#96;id&#96; <&#39;{$iPid}&#39; ORDER BY &#96;id&#96; DESC LIMIT 1");$iNext &#61; (int)$GLOBALS[&#39;MySQL&#39;]->getOne("SELECT &#96;id&#96; FROM &#96;s281_photos&#96; WHERE &#96;id&#96; > &#39;{$iPid}&#39; ORDER BY &#96;id&#96; ASC LIMIT 1");$sPrevBtn &#61; ($iPrev) ? &#39;

&#39; : &#39;&#39;;$sNextBtn &#61; ($iNext) ? &#39;
&#39; : &#39;&#39;;require_once(&#39;classes/Services_JSON.php&#39;);$oJson &#61; new Services_JSON();header(&#39;Content-Type:text/Javascript&#39;);echo $oJson->encode(array(&#39;data1&#39; &#61;> &#39;&#39; . $sPrevBtn . $sNextBtn,&#39;data2&#39; &#61;> $sCommentsBlock,));exit;
}


// disable warnings
if (version_compare(phpversion(), "5.3.0", ">&#61;") &#61;&#61; 1)error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
elseerror_reporting(E_ALL & ~E_NOTICE);
if ($_POST[&#39;action&#39;] &#61;&#61; &#39;get_info&#39; && (int)$_POST[&#39;id&#39;] > 0) {require_once(&#39;classes/CMySQL.php&#39;); // include service classes to work with database and commentsrequire_once(&#39;classes/CMyComments.php&#39;);// get photo info$iPid &#61; (int)$_POST[&#39;id&#39;];$aImageInfo &#61; $GLOBALS[&#39;MySQL&#39;]->getRow("SELECT * FROM &#96;s281_photos&#96; WHERE &#96;id&#96; &#61; &#39;{$iPid}&#39;");// prepare last 10 comments$sCommentsBlock &#61; $GLOBALS[&#39;MyComments&#39;]->getComments($iPid);$aItems &#61; $GLOBALS[&#39;MySQL&#39;]->getAll("SELECT * FROM &#96;s281_photos&#96; ORDER by &#96;when&#96; ASC"); // get photos info// Prev & Next navigation$sNext &#61; $sPrev &#61; &#39;&#39;;$iPrev &#61; (int)$GLOBALS[&#39;MySQL&#39;]->getOne("SELECT &#96;id&#96; FROM &#96;s281_photos&#96; WHERE &#96;id&#96; <&#39;{$iPid}&#39; ORDER BY &#96;id&#96; DESC LIMIT 1");$iNext &#61; (int)$GLOBALS[&#39;MySQL&#39;]->getOne("SELECT &#96;id&#96; FROM &#96;s281_photos&#96; WHERE &#96;id&#96; > &#39;{$iPid}&#39; ORDER BY &#96;id&#96; ASC LIMIT 1");$sPrevBtn &#61; ($iPrev) ? &#39;

&#39; : &#39;&#39;;$sNextBtn &#61; ($iNext) ? &#39;
&#39; : &#39;&#39;;require_once(&#39;classes/Services_JSON.php&#39;);$oJson &#61; new Services_JSON();header(&#39;Content-Type:text/Javascript&#39;);echo $oJson->encode(array(&#39;data1&#39; &#61;> &#39;&#39; . $sPrevBtn . $sNextBtn,&#39;data2&#39; &#61;> $sCommentsBlock,));exit;
}

This file sends back information about requested photo. This is an enlarged image, block with comments and navigation buttons (to open previous / next images ajaxy). As you can see – we use comments class, now, it’s time to look at it too:

该文件发回有关所请求照片的信息。 这是一个放大的图像&#xff0c;带有注释和导航按钮的块(用于以ajaxy方式打开上一个/下一个图像)。 如您所见–我们现在使用注释类&#xff0c;现在也该看看它了&#xff1a;

classes / CMyComments.php (classes/CMyComments.php)


class CMyComments {// constructorfunction CMyComments() {}// return comments blockfunction getComments($i) {// draw last 10 comments$sComments &#61; &#39;&#39;;$aComments &#61; $GLOBALS[&#39;MySQL&#39;]->getAll("SELECT * FROM &#96;s281_items_cmts&#96; WHERE &#96;c_item_id&#96; &#61; &#39;{$i}&#39; ORDER BY &#96;c_when&#96; DESC LIMIT 10");foreach ($aComments as $i &#61;> $aCmtsInfo) {$sWhen &#61; date(&#39;F j, Y H:i&#39;, $aCmtsInfo[&#39;c_when&#39;]);$sComments .&#61; <<

Comment from {$aCmtsInfo[&#39;c_name&#39;]} ({$sWhen}):

{$aCmtsInfo[&#39;c_text&#39;]}



EOF;}return <<

Comments

Don&#96;t forget to fill both fields (Name and Comment)
You can&#39;t post more than one comment per 10 minutes (spam protection)
 
{$sComments}


EOF;}function acceptComment() {$iItemId &#61; (int)$_POST[&#39;id&#39;]; // prepare necessary information$sIp &#61; $this->getVisitorIP();$sName &#61; $GLOBALS[&#39;MySQL&#39;]->escape(strip_tags($_POST[&#39;name&#39;]));$sText &#61; $GLOBALS[&#39;MySQL&#39;]->escape(strip_tags($_POST[&#39;text&#39;]));if ($sName && $sText) {// check - if there is any recent post from you or not$iOldId &#61; $GLOBALS[&#39;MySQL&#39;]->getOne("SELECT &#96;c_item_id&#96; FROM &#96;s281_items_cmts&#96; WHERE &#96;c_item_id&#96; &#61; &#39;{$iItemId}&#39; AND &#96;c_ip&#96; &#61; &#39;{$sIp}&#39; AND &#96;c_when&#96; >&#61; UNIX_TIMESTAMP() - 600 LIMIT 1");if (! $iOldId) {// if everything is fine - allow to add comment$GLOBALS[&#39;MySQL&#39;]->res("INSERT INTO &#96;s281_items_cmts&#96; SET &#96;c_item_id&#96; &#61; &#39;{$iItemId}&#39;, &#96;c_ip&#96; &#61; &#39;{$sIp}&#39;, &#96;c_when&#96; &#61; UNIX_TIMESTAMP(), &#96;c_name&#96; &#61; &#39;{$sName}&#39;, &#96;c_text&#96; &#61; &#39;{$sText}&#39;");$GLOBALS[&#39;MySQL&#39;]->res("UPDATE &#96;s281_photos&#96; SET &#96;comments_count&#96; &#61; &#96;comments_count&#96; &#43; 1 WHERE &#96;id&#96; &#61; &#39;{$iItemId}&#39;");// and print out last 10 comments$sOut &#61; &#39;&#39;;$aComments &#61; $GLOBALS[&#39;MySQL&#39;]->getAll("SELECT * FROM &#96;s281_items_cmts&#96; WHERE &#96;c_item_id&#96; &#61; &#39;{$iItemId}&#39; ORDER BY &#96;c_when&#96; DESC LIMIT 10");foreach ($aComments as $i &#61;> $aCmtsInfo) {$sWhen &#61; date(&#39;F j, Y H:i&#39;, $aCmtsInfo[&#39;c_when&#39;]);$sOut .&#61; <<

Comment from {$aCmtsInfo[&#39;c_name&#39;]} ({$sWhen}):

{$aCmtsInfo[&#39;c_text&#39;]}



EOF;}return $sOut;}}return 1;}// get visitor IPfunction getVisitorIP() {$ip &#61; "0.0.0.0";if( ( isset( $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;] ) ) && ( !empty( $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;] ) ) ) {$ip &#61; $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;];} elseif( ( isset( $_SERVER[&#39;HTTP_CLIENT_IP&#39;])) && (!empty($_SERVER[&#39;HTTP_CLIENT_IP&#39;] ) ) ) {$ip &#61; explode(".",$_SERVER[&#39;HTTP_CLIENT_IP&#39;]);$ip &#61; $ip[3].".".$ip[2].".".$ip[1].".".$ip[0];} elseif((!isset( $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;])) || (empty($_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;]))) {if ((!isset( $_SERVER[&#39;HTTP_CLIENT_IP&#39;])) && (empty($_SERVER[&#39;HTTP_CLIENT_IP&#39;]))) {$ip &#61; $_SERVER[&#39;REMOTE_ADDR&#39;];}}return $ip;}
}
$GLOBALS[&#39;MyComments&#39;] &#61; new CMyComments();
?>


class CMyComments {// constructorfunction CMyComments() {}// return comments blockfunction getComments($i) {// draw last 10 comments$sComments &#61; &#39;&#39;;$aComments &#61; $GLOBALS[&#39;MySQL&#39;]->getAll("SELECT * FROM &#96;s281_items_cmts&#96; WHERE &#96;c_item_id&#96; &#61; &#39;{$i}&#39; ORDER BY &#96;c_when&#96; DESC LIMIT 10");foreach ($aComments as $i &#61;> $aCmtsInfo) {$sWhen &#61; date(&#39;F j, Y H:i&#39;, $aCmtsInfo[&#39;c_when&#39;]);$sComments .&#61; <<

Comment from {$aCmtsInfo[&#39;c_name&#39;]} ({$sWhen}):

{$aCmtsInfo[&#39;c_text&#39;]}



EOF;}return <<

Comments

Don&#96;t forget to fill both fields (Name and Comment)
You can&#39;t post more than one comment per 10 minutes (spam protection)
 
{$sComments}


EOF;}function acceptComment() {$iItemId &#61; (int)$_POST[&#39;id&#39;]; // prepare necessary information$sIp &#61; $this->getVisitorIP();$sName &#61; $GLOBALS[&#39;MySQL&#39;]->escape(strip_tags($_POST[&#39;name&#39;]));$sText &#61; $GLOBALS[&#39;MySQL&#39;]->escape(strip_tags($_POST[&#39;text&#39;]));if ($sName && $sText) {// check - if there is any recent post from you or not$iOldId &#61; $GLOBALS[&#39;MySQL&#39;]->getOne("SELECT &#96;c_item_id&#96; FROM &#96;s281_items_cmts&#96; WHERE &#96;c_item_id&#96; &#61; &#39;{$iItemId}&#39; AND &#96;c_ip&#96; &#61; &#39;{$sIp}&#39; AND &#96;c_when&#96; >&#61; UNIX_TIMESTAMP() - 600 LIMIT 1");if (! $iOldId) {// if everything is fine - allow to add comment$GLOBALS[&#39;MySQL&#39;]->res("INSERT INTO &#96;s281_items_cmts&#96; SET &#96;c_item_id&#96; &#61; &#39;{$iItemId}&#39;, &#96;c_ip&#96; &#61; &#39;{$sIp}&#39;, &#96;c_when&#96; &#61; UNIX_TIMESTAMP(), &#96;c_name&#96; &#61; &#39;{$sName}&#39;, &#96;c_text&#96; &#61; &#39;{$sText}&#39;");$GLOBALS[&#39;MySQL&#39;]->res("UPDATE &#96;s281_photos&#96; SET &#96;comments_count&#96; &#61; &#96;comments_count&#96; &#43; 1 WHERE &#96;id&#96; &#61; &#39;{$iItemId}&#39;");// and print out last 10 comments$sOut &#61; &#39;&#39;;$aComments &#61; $GLOBALS[&#39;MySQL&#39;]->getAll("SELECT * FROM &#96;s281_items_cmts&#96; WHERE &#96;c_item_id&#96; &#61; &#39;{$iItemId}&#39; ORDER BY &#96;c_when&#96; DESC LIMIT 10");foreach ($aComments as $i &#61;> $aCmtsInfo) {$sWhen &#61; date(&#39;F j, Y H:i&#39;, $aCmtsInfo[&#39;c_when&#39;]);$sOut .&#61; <<

Comment from {$aCmtsInfo[&#39;c_name&#39;]} ({$sWhen}):

{$aCmtsInfo[&#39;c_text&#39;]}



EOF;}return $sOut;}}return 1;}// get visitor IPfunction getVisitorIP() {$ip &#61; "0.0.0.0";if( ( isset( $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;] ) ) && ( !empty( $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;] ) ) ) {$ip &#61; $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;];} elseif( ( isset( $_SERVER[&#39;HTTP_CLIENT_IP&#39;])) && (!empty($_SERVER[&#39;HTTP_CLIENT_IP&#39;] ) ) ) {$ip &#61; explode(".",$_SERVER[&#39;HTTP_CLIENT_IP&#39;]);$ip &#61; $ip[3].".".$ip[2].".".$ip[1].".".$ip[0];} elseif((!isset( $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;])) || (empty($_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;]))) {if ((!isset( $_SERVER[&#39;HTTP_CLIENT_IP&#39;])) && (empty($_SERVER[&#39;HTTP_CLIENT_IP&#39;]))) {$ip &#61; $_SERVER[&#39;REMOTE_ADDR&#39;];}}return $ip;}
}
$GLOBALS[&#39;MyComments&#39;] &#61; new CMyComments();
?>

This class performs two main functions – it can accept new comments and also it can give us a box with comments. There are two more service classes: CMySQL.php and Services_JSON.php. They are two known classes to work with database and json. You can adjust database settings in database class. Both classes available in our package.

此类执行两个主要功能–可以接受新评论&#xff0c;也可以给我们提供带有评论的框。 还有另外两个服务类&#xff1a;CMySQL.php和Services_JSON.php。 它们是两个与数据库和json一起使用的已知类。 您可以在数据库类中调整数据库设置。 这两个类均在我们的包装中提供。

步骤3. Javascript (Step 3. Javascript)

现在&#xff0c;我们应该使用Javascript准备用户界面行为&#xff0c;请为该项目准备下一个文件&#xff1a; (Now we should prepare user interface behavior with using Javascript, please prepare next file for the project:)

js / script.js (js/script.js)


// close photo preview block
function closePhotoPreview() {$(&#39;#photo_preview&#39;).hide();$(&#39;#photo_preview .pleft&#39;).html(&#39;empty&#39;);$(&#39;#photo_preview .pright&#39;).html(&#39;empty&#39;);
};
// display photo preview block
function getPhotoPreviewAjx(id) {$.post(&#39;photos_ajx.php&#39;, {action: &#39;get_info&#39;, id: id},function(data){$(&#39;#photo_preview .pleft&#39;).html(data.data1);$(&#39;#photo_preview .pright&#39;).html(data.data2);$(&#39;#photo_preview&#39;).show();}, "json");
};
// submit comment
function submitComment(id) {var sName &#61; $(&#39;#name&#39;).val();var sText &#61; $(&#39;#text&#39;).val();if (sName && sText) {$.post(&#39;index.php&#39;, { action: &#39;accept_comment&#39;, name: sName, text: sText, id: id },function(data){if (data !&#61; &#39;1&#39;) {$(&#39;#comments_list&#39;).fadeOut(1000, function () {$(this).html(data);$(this).fadeIn(1000);});} else {$(&#39;#comments_warning2&#39;).fadeIn(1000, function () {$(this).fadeOut(1000);});}});} else {$(&#39;#comments_warning1&#39;).fadeIn(1000, function () {$(this).fadeOut(1000);});}
};
// init
$(function(){// onclick event handlers$(&#39;#photo_preview .photo_wrp&#39;).click(function (event) {event.preventDefault();return false;});$(&#39;#photo_preview&#39;).click(function (event) {closePhotoPreview();});$(&#39;#photo_preview img.close&#39;).click(function (event) {closePhotoPreview();});// display photo preview ajaxy$(&#39;.container .photo img&#39;).click(function (event) {if (event.preventDefault) event.preventDefault();getPhotoPreviewAjx($(this).attr(&#39;id&#39;));});
})


// close photo preview block
function closePhotoPreview() {$(&#39;#photo_preview&#39;).hide();$(&#39;#photo_preview .pleft&#39;).html(&#39;empty&#39;);$(&#39;#photo_preview .pright&#39;).html(&#39;empty&#39;);
};
// display photo preview block
function getPhotoPreviewAjx(id) {$.post(&#39;photos_ajx.php&#39;, {action: &#39;get_info&#39;, id: id},function(data){$(&#39;#photo_preview .pleft&#39;).html(data.data1);$(&#39;#photo_preview .pright&#39;).html(data.data2);$(&#39;#photo_preview&#39;).show();}, "json");
};
// submit comment
function submitComment(id) {var sName &#61; $(&#39;#name&#39;).val();var sText &#61; $(&#39;#text&#39;).val();if (sName && sText) {$.post(&#39;index.php&#39;, { action: &#39;accept_comment&#39;, name: sName, text: sText, id: id },function(data){if (data !&#61; &#39;1&#39;) {$(&#39;#comments_list&#39;).fadeOut(1000, function () {$(this).html(data);$(this).fadeIn(1000);});} else {$(&#39;#comments_warning2&#39;).fadeIn(1000, function () {$(this).fadeOut(1000);});}});} else {$(&#39;#comments_warning1&#39;).fadeIn(1000, function () {$(this).fadeOut(1000);});}
};
// init
$(function(){// onclick event handlers$(&#39;#photo_preview .photo_wrp&#39;).click(function (event) {event.preventDefault();return false;});$(&#39;#photo_preview&#39;).click(function (event) {closePhotoPreview();});$(&#39;#photo_preview img.close&#39;).click(function (event) {closePhotoPreview();});// display photo preview ajaxy$(&#39;.container .photo img&#39;).click(function (event) {if (event.preventDefault) event.preventDefault();getPhotoPreviewAjx($(this).attr(&#39;id&#39;));});
})

Please note, we use jQuery instructions in our script (I hope that you haven’t forgot that we linked jQuery library in the header section through google service).

请注意&#xff0c;我们在脚本中使用了jQuery指令(希望您不要忘记我们通过Google服务在标头部分中链接了jQuery库)。

步骤4. CSS (Step 4. CSS)

In the long run, we should stylize our page elements (our container with photos, photo preview area with comments):

从长远来看&#xff0c;我们应该样式化页面元素(带有照片的我们的容器&#xff0c;带有评论的照片预览区域)&#xff1a;

css / main.css (css/main.css)


/* project styles */
.container {border: 1px solid #111111;color: #000000;margin: 20px auto;overflow: hidden;padding: 15px;position: relative;text-align: center;width: 1090px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;
}
.photo {border: 1px solid transparent;float: left;margin: 4px;overflow: hidden;padding: 4px;white-space: nowrap;/* CSS3 Box sizing property */-moz-box-sizing: border-box;-webkit-box-sizing: border-box;-o-box-sizing: border-box;box-sizing: border-box;/* CSS3 transition */-moz-transition: border 0.2s ease 0s;-ms-transition: border 0.2s ease 0s;-o-transition: border 0.2s ease 0s;-webkit-transition: border 0.2s ease 0s;transition: border 0.2s ease 0s;
}
.photo:hover {border-color: #444;
}
.photo img {cursor: pointer;width: 200px;
}
.photo p, .photo i {display: block;
}
.photo p {font-weight: bold;
}
/* preview styles */
#photo_preview {background-color: rgba(0, 0, 0, 0.7);bottom: 0;color: #000000;display: none;left: 0;overflow: hidden;position: fixed;right: 0;top: 0;z-index: 10;
}
.photo_wrp {background-color: #FAFAFA;height: auto;margin: 100px auto 0;overflow: hidden;padding: 15px;text-align: center;vertical-align: middle;width: 1000px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;
}
.close {cursor: pointer;float: right;
}
.pleft {float: left;overflow: hidden;position: relative;width: 600px;
}
.pright {float: right;position: relative;width: 360px;
}
.preview_prev, .preview_next {cursor: pointer;margin-top: -64px;opacity: 0.5;position: absolute;top: 50%;-moz-transition: opacity 0.2s ease 0s;-ms-transition: opacity 0.2s ease 0s;-o-transition: opacity 0.2s ease 0s;-webkit-transition: opacity 0.2s ease 0s;transition: opacity 0.2s ease 0s;
}
.preview_prev:hover, .preview_next:hover {opacity: 1;
}
.preview_prev {left: 20px;
}
.preview_next {right: 40px;
}
/* comments styles */
#comments form {margin: 10px 0;text-align: left;
}
#comments table td.label {color: #000;font-size: 13px;padding-right: 3px;text-align: right;width: 105px;
}
#comments table label {color: #000;font-size: 16px;font-weight: normal;vertical-align: middle;
}
#comments table td.field input, #comments table td.field textarea {border: 1px solid #96A6C5;font-family: Verdana,Arial,sans-serif;font-size: 16px;margin-top: 2px;padding: 6px;width: 250px;
}
#comments_list {margin: 10px 0;text-align: left;
}
#comments_list .comment {border-top: 1px solid #000;padding: 10px 0;
}
#comments_list .comment:first-child {border-top-width:0px;
}
#comments_list .comment span {font-size: 11px;
}


/* project styles */
.container {border: 1px solid #111111;color: #000000;margin: 20px auto;overflow: hidden;padding: 15px;position: relative;text-align: center;width: 1090px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;
}
.photo {border: 1px solid transparent;float: left;margin: 4px;overflow: hidden;padding: 4px;white-space: nowrap;/* CSS3 Box sizing property */-moz-box-sizing: border-box;-webkit-box-sizing: border-box;-o-box-sizing: border-box;box-sizing: border-box;/* CSS3 transition */-moz-transition: border 0.2s ease 0s;-ms-transition: border 0.2s ease 0s;-o-transition: border 0.2s ease 0s;-webkit-transition: border 0.2s ease 0s;transition: border 0.2s ease 0s;
}
.photo:hover {border-color: #444;
}
.photo img {cursor: pointer;width: 200px;
}
.photo p, .photo i {display: block;
}
.photo p {font-weight: bold;
}
/* preview styles */
#photo_preview {background-color: rgba(0, 0, 0, 0.7);bottom: 0;color: #000000;display: none;left: 0;overflow: hidden;position: fixed;right: 0;top: 0;z-index: 10;
}
.photo_wrp {background-color: #FAFAFA;height: auto;margin: 100px auto 0;overflow: hidden;padding: 15px;text-align: center;vertical-align: middle;width: 1000px;-moz-border-radius: 5px;-ms-border-radius: 5px;-o-border-radius: 5px;-webkit-border-radius: 5px;border-radius: 5px;
}
.close {cursor: pointer;float: right;
}
.pleft {float: left;overflow: hidden;position: relative;width: 600px;
}
.pright {float: right;position: relative;width: 360px;
}
.preview_prev, .preview_next {cursor: pointer;margin-top: -64px;opacity: 0.5;position: absolute;top: 50%;-moz-transition: opacity 0.2s ease 0s;-ms-transition: opacity 0.2s ease 0s;-o-transition: opacity 0.2s ease 0s;-webkit-transition: opacity 0.2s ease 0s;transition: opacity 0.2s ease 0s;
}
.preview_prev:hover, .preview_next:hover {opacity: 1;
}
.preview_prev {left: 20px;
}
.preview_next {right: 40px;
}
/* comments styles */
#comments form {margin: 10px 0;text-align: left;
}
#comments table td.label {color: #000;font-size: 13px;padding-right: 3px;text-align: right;width: 105px;
}
#comments table label {color: #000;font-size: 16px;font-weight: normal;vertical-align: middle;
}
#comments table td.field input, #comments table td.field textarea {border: 1px solid #96A6C5;font-family: Verdana,Arial,sans-serif;font-size: 16px;margin-top: 2px;padding: 6px;width: 250px;
}
#comments_list {margin: 10px 0;text-align: left;
}
#comments_list .comment {border-top: 1px solid #000;padding: 10px 0;
}
#comments_list .comment:first-child {border-top-width:0px;
}
#comments_list .comment span {font-size: 11px;
}

现场演示

结论 (Conclusion)

And again, we have just prepared our next practically useful tutorial. Sure that this material will useful for your own projects. Good luck in your work!

同样&#xff0c;我们刚刚准备了下一个实用的教程。 确保该材料将对您自己的项目有用。 祝您工作顺利&#xff01;

翻译自: https://www.script-tutorials.com/facebook-like-photo-gallery-with-comments/

facebook有哪些信息



推荐阅读
  • 在使用 Cacti 进行监控时,发现已运行的转码机未产生流量,导致 Cacti 监控界面显示该转码机处于宕机状态。进一步检查 Cacti 日志,发现数据库中存在 SQL 查询失败的问题,错误代码为 145。此问题可能是由于数据库表损坏或索引失效所致,建议对相关表进行修复操作以恢复监控功能。 ... [详细]
  • 本文详细解析了使用C++实现的键盘输入记录程序的源代码,该程序在Windows应用程序开发中具有很高的实用价值。键盘记录功能不仅在远程控制软件中广泛应用,还为开发者提供了强大的调试和监控工具。通过具体实例,本文深入探讨了C++键盘记录程序的设计与实现,适合需要相关技术的开发者参考。 ... [详细]
  • PTArchiver工作原理详解与应用分析
    PTArchiver工作原理及其应用分析本文详细解析了PTArchiver的工作机制,探讨了其在数据归档和管理中的应用。PTArchiver通过高效的压缩算法和灵活的存储策略,实现了对大规模数据的高效管理和长期保存。文章还介绍了其在企业级数据备份、历史数据迁移等场景中的实际应用案例,为用户提供了实用的操作建议和技术支持。 ... [详细]
  • 基于Net Core 3.0与Web API的前后端分离开发:Vue.js在前端的应用
    本文介绍了如何使用Net Core 3.0和Web API进行前后端分离开发,并重点探讨了Vue.js在前端的应用。后端采用MySQL数据库和EF Core框架进行数据操作,开发环境为Windows 10和Visual Studio 2019,MySQL服务器版本为8.0.16。文章详细描述了API项目的创建过程、启动步骤以及必要的插件安装,为开发者提供了一套完整的开发指南。 ... [详细]
  • 在对WordPress Duplicator插件0.4.4版本的安全评估中,发现其存在跨站脚本(XSS)攻击漏洞。此漏洞可能被利用进行恶意操作,建议用户及时更新至最新版本以确保系统安全。测试方法仅限于安全研究和教学目的,使用时需自行承担风险。漏洞编号:HTB23162。 ... [详细]
  • 本文介绍了一种自定义的Android圆形进度条视图,支持在进度条上显示数字,并在圆心位置展示文字内容。通过自定义绘图和组件组合的方式实现,详细展示了自定义View的开发流程和关键技术点。示例代码和效果展示将在文章末尾提供。 ... [详细]
  • 为了确保数据库的高效运行,本文介绍了一种方法,通过编写定时任务脚本来自动清理 `order` 表中状态为 0 或为空的无效订单记录。该脚本使用 PHP 编写,并设置时区为中国标准时间,每 10 分钟执行一次,以保持数据库的整洁和性能优化。此外,还详细介绍了如何配置定时任务以及脚本的具体实现步骤。 ... [详细]
  • Codeforces竞赛解析:Educational Round 84(Div. 2评级),题目A:奇数和问题
    Codeforces竞赛解析:Educational Round 84(Div. 2评级),题目A:奇数和问题 ... [详细]
  • 属性类 `Properties` 是 `Hashtable` 类的子类,用于存储键值对形式的数据。该类在 Java 中广泛应用于配置文件的读取与写入,支持字符串类型的键和值。通过 `Properties` 类,开发者可以方便地进行配置信息的管理,确保应用程序的灵活性和可维护性。此外,`Properties` 类还提供了加载和保存属性文件的方法,使其在实际开发中具有较高的实用价值。 ... [详细]
  • 在Linux系统中避免安装MySQL的简易指南
    在Linux系统中避免安装MySQL的简易指南 ... [详细]
  • DVWA学习笔记系列:深入理解CSRF攻击机制
    DVWA学习笔记系列:深入理解CSRF攻击机制 ... [详细]
  • OpenAI首席执行官Sam Altman展望:人工智能的未来发展方向与挑战
    OpenAI首席执行官Sam Altman展望:人工智能的未来发展方向与挑战 ... [详细]
  • 本文详细介绍了在MySQL中如何高效利用EXPLAIN命令进行查询优化。通过实例解析和步骤说明,文章旨在帮助读者深入理解EXPLAIN命令的工作原理及其在性能调优中的应用,内容通俗易懂且结构清晰,适合各水平的数据库管理员和技术人员参考学习。 ... [详细]
  • 本文深入解析了JDK 8中HashMap的源代码,重点探讨了put方法的工作机制及其内部参数的设定原理。HashMap允许键和值为null,但键为null的情况只能出现一次,因为null键在内部通过索引0进行存储。文章详细分析了capacity(容量)、size(大小)、loadFactor(加载因子)以及红黑树转换阈值的设定原则,帮助读者更好地理解HashMap的高效实现和性能优化策略。 ... [详细]
  • MSP430F5438 ADC12模块应用与学习心得
    在最近的实践中,我深入研究了MSP430F5438的ADC12模块。尽管该模块的功能相对简单,但通过实际操作,我对MSP430F5438A和MSP430F5438之间的差异有了更深刻的理解。本文将分享这些学习心得,并探讨如何更好地利用ADC12模块进行数据采集和处理。 ... [详细]
author-avatar
手机用户上官婉儿
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有