Re: [belajar-sql] php function

54 views
Skip to first unread message
Message has been deleted

Feris Thia

unread,
May 22, 2013, 2:13:07 AM5/22/13
to belaj...@googlegroups.com
Anda programmer Pak ?

Dengan pertanyaan ini, silahkan dianalisa sendiri.. sepertinya tidak akan ada yang mau melihat script sepanjang ini. Mohon dimaklumi, karena rekan-rekan disini sudah punya banyak kerjaan.

Regards,

Feris



On Wed, May 22, 2013 at 12:29 PM, Dedi Upit <dedi...@gmail.com> wrote:
<?php

function num_post($user_id){
global $db,$memcache;
$cache_num_post=$memcache->get('num_post_'.$user_id);
if(!empty($cache_num_post))
return $cache_num_post;
$query=$db->prepare_query("SELECT count(larticle_id) as numpost
FROM lumonata_articles
WHERE lpost_by=%d",$user_id);
$result=$db->do_query($query);
$data=$db->fetch_array($result);
$numpost=$data['numpost'];
$memcache->set('num_post_'.$user_id,$numpost,false,CACHE_TIME_LONG);
mysql_close($db);
return $numpost;
}
function num_album($user_id,$type){
global $db,$memcache;
$cache_num_album=$memcache->get('num_album_'.$user_id.$type);
if(!empty($cache_num_album))
return $cache_num_album;
$query=$db->prepare_query("SELECT count(larticle_id) as numpost
FROM lumonata_articles
WHERE lpost_by=%d AND larticle_type=%s",$user_id,$type);
$result=$db->do_query($query);
$data=$db->fetch_array($result);
$numpost=$data['numpost'];
$memcache->set('num_album_'.$user_id.$type,$numpost,false,CACHE_TIME_LONG);
mysql_close($db);
return $numpost;
}
function num_board_photo($user_id,$type){ // [AM20120718]
global $db,$memcache;
$cache_num_board_photo=$memcache->get('num_board_photo_'.$user_id);
if(!empty($cache_num_board_photo)){
return $cache_num_board_photo;
}else{
$query=$db->prepare_query("SELECT count(lumonata_articles.larticle_id) as numpost
FROM lumonata_articles 
INNER JOIN lumonata_attachment ON lumonata_articles.larticle_id = lumonata_attachment.larticle_id
WHERE lumonata_articles.lpost_by=%d AND 
(lumonata_articles.larticle_type=%s OR lumonata_articles.larticle_type=%s OR lumonata_articles.larticle_type=%s) ",
$user_id,$type,'status','status_repost');
$result=$db->do_query($query);
$data=$db->fetch_array($result);
$numpost=$data['numpost'];
$memcache->set('num_board_photo_'.$user_id,$numpost,false,CACHE_TIME_LONG);
mysql_close($db);
return $numpost;
}
}
function profile_post($token,$username,$start=0,$length=20,$format='json'){
global $db,$memcache;
$result=array();
$cache_profile_post=$memcache->get('profile_post_'.$username.$format);
if(!empty($cache_profile_post))
return $cache_profile_post;
$the_token=token_decode($token);
if($username=='me' || empty($username))
$id=$the_token->id;
else 
$id=fetch_user_ID_by_username($username);
/* Wahya 18 Juli 2012 */

$query=$db->prepare_query("SELECT *
FROM lumonata_articles
WHERE lpost_by=%d
ORDER BY ldlu DESC
LIMIT %d,%d",$id,$start,$length);
/* Wahya 18 Juli 2012 */

$result_db=$db->do_query($query);
while($data=$db->fetch_array($result_db)){
$objContent=new html2text($data['larticle_content']);
$content= $objContent->get_text();
if($data['larticle_type']=='status_repost' || $data['larticle_type']=='articles_repost')
$article_id_for_attachment=$data['loriginal_post'];
else 
$article_id_for_attachment=$data['larticle_id'];
$result[]=array(
'id'=>intval($data['larticle_id']),
'original_id'=>intval($data['loriginal_post']),
'parent_id'=>intval($data['lparent']),
'title'=>replace_url_string($data['larticle_title']),
'original_id'=>intval($data['loriginal_post']),
'content'=>replace_url_string($content),
'status'=>$data['larticle_status'],
'type'=>$data['larticle_type'],
'num_repost'=>intval($data['lno_repost']),
'num_reply'=>intval($data['lno_reply']),
'num_like'=>intval($data['lcount_like']),
'post_date'=>strtotime($data['lpost_date']),
'user' =>getinfo($data['lpost_by'],'array'),
'post_url'=>permalink($data['larticle_id'],true,$data['lpost_by']),
'attachment'=>array('image'=>get_image_attachment($article_id_for_attachment),
'video'=>get_embed($article_id_for_attachment,'video'),
'link'=>get_embed($article_id_for_attachment,'link'),
'voice'=>get_embed($article_id_for_attachment,'voice')
),
'latitude'=>get_additional_field($data['larticle_id'], 'latitude', 'location_map'),
'longitude'=>get_additional_field($data['larticle_id'], 'latitude', 'location_map'),
'box_id'=>intval($data['lshare_to'])
);
//echo "<pre>".print_r(get_attachment($data['larticle_id']),true)."</pre>";
}
if($format=='json'){
$the_return = json_encode($result);
}else{
$the_return = $result;
}
$memcache->set('profile_post_'.$username.$format,$the_return,false,CACHE_TIME_SHORT);
return $the_return;
}
function board($token,$start=0,$length=20,$type='board',$box_id=0,$format='json'){
global $db,$memcache;
$result=array();
$isLike=FALSE;
$isNotification=FALSE;
$cache_board_post=$memcache->get('board_post_'.$token.$type.$box_id.$format);
if(!empty($cache_board_post))
return $cache_board_post;
$the_token=token_decode($token);
if($type=='board'){
if(empty($box_id)){
$query=$db->prepare_query("SELECT DISTINCT(b.larticle_id),b.* 
 FROM lumonata_board a, lumonata_articles b
 WHERE a.postid=b.larticle_id 
 AND a.subscriber=%d
 ORDER BY b.ldlu DESC
 LIMIT %d,%d",$the_token->id,$start,$length);
/*
$last_grep_board_time=get_additional_field($the_token->id, 'last_grep_board_time', 'user');
if(empty($last_grep_board_time))
add_additional_field($the_token->id, 'last_grep_board_time', time(), 'user');
else
$last_grep_board_time=get_additional_field($the_token->id, 'last_grep_board_time', 'user');
$query=$db->prepare_query("SELECT b.* 
 FROM lumonata_board a, lumonata_articles b
 WHERE a.postid=b.larticle_id 
 AND a.subscriber=%d AND a.postby<>%d
 AND b.ldlu > %s
 ORDER BY b.ldlu DESC
 LIMIT %d,%d",$the_token->id,$the_token->id,date("Y-m-d H:i:s",$last_grep_board_time),$start,$length);
*/
}else{ // [AM20120928] 
$the_count=1;
$friends_id="";
$post_by_in="";
$friend_q=$db->prepare_query("
          SELECT DISTINCT(a.lfriend_id) 
  FROM lumonata_friendship a,lumonata_friends_list_rel b, lumonata_users c 
  WHERE a.lfriendship_id=b.lfriendship_id
  AND b.lfriends_list_id=%d
  AND c.luser_id = a.luser_id
  ORDER BY c.ldlu
  LIMIT 100
  ", $box_id);
$the_friend_r=$db->do_query($friend_q);
$num_friend=$db->num_rows($the_friend_r);
while($friend_d=$db->fetch_array($the_friend_r)){
if($the_count==$num_friend){
$friends_id.=$friend_d['lfriend_id'];
}else{
$friends_id.=$friend_d['lfriend_id'].",";
}
$the_count++;
}
if(!empty($friends_id)){
$post_by_in="a.postby in (".$friends_id.")OR ";
}
$query=$db->prepare_query("SELECT DISTINCT(b.larticle_id),b.* 
 FROM lumonata_board a, lumonata_articles b
 WHERE a.postid=b.larticle_id 
 AND a.subscriber=%d 
 AND ( ".$post_by_in."
   (a.postby=%d AND a.sharebox=%d)
 
 )
 ORDER BY b.ldlu DESC
 LIMIT %d,%d",
 $the_token->id,
 $the_token->id,
 $box_id,
 $start,
 $length
 );
}
}elseif($type=='notifications'){ 
$query=$db->prepare_query("SELECT a.*,b.laction_name as action_name,b.luser_id as user_id
FROM lumonata_articles a, lumonata_notifications b
WHERE a.larticle_id=b.lpost_id AND
(b.laction_name='post_tag' OR b.laction_name='like' ) AND
b.laffected_user=%d
ORDER BY b.laction_date DESC
LIMIT %d,%d",$the_token->id,$start,$length);
$isNotification=TRUE;
}elseif($type=='like'){ 
$query=$db->prepare_query("SELECT a.*
FROM lumonata_articles a, lumonata_notifications b
WHERE a.larticle_id=b.lpost_id AND
b.laction_name='like' AND
b.luser_id=%d
GROUP BY a.larticle_id
ORDER BY b.laction_date DESC
LIMIT %d,%d",$the_token->id,$start,$length);
}elseif($type=='fav'){
$query=$db->prepare_query("SELECT a.*
FROM lumonata_articles a, lumonata_comments c
WHERE a.larticle_id=c.larticle_id AND
c.lcomment_type='fav' AND c.luser_id=%d
ORDER BY c.lcomment_date DESC
LIMIT %d,%d",$the_token->id,$start,$length);
}
$result_db=$db->do_query($query);
while($data=$db->fetch_array($result_db)){
$objContent=new html2text($data['larticle_content']);
$content= $objContent->get_text();
if($isNotification==TRUE){
if($data['action_name']=="like")
$isLike=TRUE;
else
$isLike=FALSE;
}
if($data['larticle_type']=='status_repost' || $data['larticle_type']=='articles_repost')
$article_id_for_attachment=$data['loriginal_post'];
else 
$article_id_for_attachment=$data['larticle_id'];
if($type=='notifications' && $data['action_name']=='like'){
$user = getinfo($data['user_id'],'array');
}else{
$user = getinfo($data['lpost_by'],'array');
}
$result[]=array(
'id'=>intval($data['larticle_id']),
'original_id'=>intval($data['loriginal_post']),
'parent_id'=>intval($data['lparent']),
'title'=>replace_url_string($data['larticle_title']),
'original_id'=>intval($data['loriginal_post']),
'content'=>replace_url_string($content),
'status'=>$data['larticle_status'],
'type'=>$data['larticle_type'],
'num_repost'=>intval($data['lno_repost']),
'num_reply'=>intval($data['lno_reply']),
'num_like'=>intval($data['lcount_like']),
'post_date'=>strtotime($data['lpost_date']),
'user' =>$user,
'post_url'=>permalink($data['larticle_id'],true,$data['lpost_by']),
'attachment'=>array('image'=>get_image_attachment($article_id_for_attachment),
'video'=>get_embed($article_id_for_attachment,'video'),
'link'=>get_embed($article_id_for_attachment,'link'),
'voice'=>get_embed($article_id_for_attachment,'voice')
),
'latitude'=>get_additional_field($data['larticle_id'], 'latitude', 'location_map'),
'longitude'=>get_additional_field($data['larticle_id'], 'latitude', 'location_map'),
'box_id'=>intval($data['lshare_to']),
'isLike'=>$isLike
);
//echo "<pre>".print_r(get_attachment($data['larticle_id']),true)."</pre>";
}
edit_additional_field($the_token->id, 'last_grep_board_time', time(), 'user');
if($format=='json'){
$the_return = json_encode($result);
}else{
$the_return = $result;
}
$memcache->set('profile_post_'.$username.$format,$the_return,false,CACHE_TIME);
return $the_return;
}
function get_image_attachment($article_id){
global $db,$memcache;
$result=array();
$cache_image_attachment=$memcache->get('image_attachment_'.$article_id);
if(!empty($cache_image_attachment))
return $cache_image_attachment;
$sql=$db->prepare_query("SELECT * 
FROM lumonata_attachment 
WHERE larticle_id=%d
GROUP BY lattach_loc
LIMIT 3",$article_id);
$result_db=$db->do_query($sql);
while($data=$db->fetch_array($result_db)){
$result[]= array('attachment_id'=> $data['lattach_id'],
'original'=>'http://'.PLUGINS_URL.'/gallery/files/'.$data['lattach_loc'],
'small'=>'http://'.PLUGINS_URL.'/gallery/files/croped/s/'.$data['lattach_loc'],
'medium'=>'http://'.PLUGINS_URL.'/gallery/files/croped/m/'.$data['lattach_loc'],
'large'=>'http://'.PLUGINS_URL.'/gallery/files/croped/l/'.$data['lattach_loc'],
'extralarge'=>'http://'.PLUGINS_URL.'/gallery/files/croped/xl/'.$data['lattach_loc'],);
}
$memcache->set('image_attachment_'.$article_id,$result,false,CACHE_TIME_LONG);
return $result;
}
function get_embed($article_id,$type){
global $memcache;
$cache_embed=$memcache->get('embed_'.$article_id.$type);
if(!empty($cache_embed))
return $cache_embed;
$url=get_additional_field($article_id,'p_url_attached','attach_url');
if( $type=='video' && (preg_match("/youtube.com/i", $url) || preg_match("/vimeo.com/i", $url))){
$the_return= array('embed_url'=>$url,
  'embed_content'=> json_decode(get_additional_field($article_id,'p_att_json','attach_url'),true));
}elseif($type=='voice'){
$voice_file=get_additional_field($article_id, 'file_name', 'voice_note');
if(!empty($voice_file))
$voiceNote='http://'.PLUGINS_URL.'/voicenote/files/'.$voice_file; // [AM20120803]
else 
$voiceNote='';
$the_return= array('source'=>$voiceNote);
}elseif($type=='link' && !(preg_match("/youtube.com/i", $url) || preg_match("/vimeo.com/i", $url))){
$the_return = array('embed_url'=>$url,
'embed_content'=> json_decode(get_additional_field($article_id,'p_att_json','attach_url'),true));
}
$memcache->set('embed_'.$article_id.$type,$the_return,false,CACHE_TIME_LONG);
return $the_return;
}
function send_post($token,$status,$type='status',$action='new_post',$application_device='web',$long=0,$lat=0,$locname='',$box=0,$original_id=0,$parent_id=0){
global $db,$err_codes; 
if ($type!='article'){ // [AM20120719]
$status = substr($status, 0, 200);
}
$content='';
$token=token_decode($token);
//BEGIN [X20110112-1] 
if($action=='repost' && !empty($original_id)){
$parent_id =0;
$sql_share = $db->prepare_query("SELECT lumonata_articles.*, lumonata_users.lusername 
FROM lumonata_articles 
INNER JOIN lumonata_users ON lumonata_articles.lpost_by = lumonata_users.luser_id 
AND lumonata_articles.larticle_id=%d",$original_id);
$query_share = $db->do_query($sql_share);
$fetch_share = $db->fetch_array($query_share);
        if(empty($fetch_share['loriginal_post']) || ($fetch_share['loriginal_post']=='')){
$original_id = $fetch_share['larticle_id'];
//$status_post = $_POST['status'].' " @'.$fetch_share['lusername'].' : '.$fetch_share['larticle_title'].' "';
$status = $status.' [span:rp]RP[:span] @'.$fetch_share['lusername'].' : '.$fetch_share['larticle_title'].' '; //[A20120329]
}else{
$original_id = $fetch_share['loriginal_post'];
$post_before = $fetch_share['larticle_title'];
$sql_share_original = $db->prepare_query("SELECT lumonata_articles.*,lumonata_users.lusername 
FROM lumonata_articles 
INNER JOIN lumonata_users ON lumonata_articles.lpost_by = lumonata_users.luser_id 
AND lumonata_articles.larticle_id=%d",$original_id);
$query_share_original = $db->do_query($sql_share_original);
$fetch_share_original = $db->fetch_array($query_share_original);
$status = $status.' [span:rp]RP[:span] @'.$fetch_share['lusername'].' : '.$post_before.' '; //[A20120329]
}
 
insert_comment(0, $_POST['loriginalid'], '','','','','repost');
//update root count
update_count_repost($original_id);
        if(($fetch_share['larticle_type']=='album') or ($fetch_share['larticle_type']=='album_repost')){
        $type = 'album_repost';
}elseif($fetch_share['larticle_type']=='articles' || $fetch_share['larticle_type']=='articles_repost'){
$type = 'articles_repost';
$content=$fetch_share['larticle_content'];
$status=$status." [span:rp]RP[:span] ".$fetch_share['larticle_title'];
}else{
$type = 'status_repost';
}
}elseif($action=='reply' && !empty($parent_id)){
$status = $status;
if(isset($type))
$type = $type;
else
$type = 'status';

if(!empty($original_id))
$original_id = $original_id;
else
$original_id =0;
$sql_share = $db->prepare_query("SELECT lumonata_articles.*,lumonata_users.lusername 
FROM lumonata_articles 
INNER JOIN lumonata_users ON lumonata_articles.lpost_by = lumonata_users.luser_id 
AND lumonata_articles.larticle_id=%d",$original_id);
$query_share = $db->do_query($sql_share);
$fetch_share = $db->fetch_array($query_share);
$parent_id = $parent_id;
if($type=='status')
update_count_reply($parent_id);
}
if(!empty($box)){
$saveit=save_post(token_encode($token),$status, $content, 'publish', $type, 'allowed','',$box,$original_id,$parent_id);
}else{
$saveit=save_post(token_encode($token),$status, $content, 'publish', $type, 'allowed','','',$original_id,$parent_id);
}
$post_id=mysql_insert_id();
//[A20120229-1]
if(isset($_FILES['photo']) && !empty($_FILES['photo']['type'])){
 
$file_name = $_FILES['photo']['name'];
            $file_size = $_FILES['photo']['size'];
            $file_type = $_FILES['photo']['type'];
            $file_source = $_FILES['photo']['tmp_name'];
            $name = file_name_filter($file_name);
            $ext = file_name_filter($file_name,true);
            $name = 'board-'.time().'-'.$name.$ext;
            
            $board_image_name=$name;
            
            
$tgName[0] = '../../lumonata-plugins/gallery/files/croped/s/'.$name ;
$tgName[1] = '../../lumonata-plugins/gallery/files/croped/m/'.$name ;
$tgName[2] = '../../lumonata-plugins/gallery/files/croped/l/'.$name ;
$tgName[3] = '../../lumonata-plugins/gallery/files/croped/xl/'.$name ;
$tgName[4] = '../../lumonata-plugins/gallery/files/'.$name ;
if(is_allow_file_type($file_type, 'image')){
if(copy($file_source, $tgName[4])){
upload_crop($file_source, $tgName[0], $file_type, 50, 50);
upload_crop($file_source, $tgName[1], $file_type, 160, 120);
upload_resize($file_source,$tgName[2],$file_type, 400, 300);
upload_resize($file_source,$tgName[3],$file_type, 800, 600);
}
insert_attachment($post_id, '', '', $name);
}else{ 
            return '{"result":"'.$err_codes[415]." File type sent is:".$file_type.'"}';
}
}//[A20120229-1]
if(isset($_FILES['voice']) && !empty($_FILES['voice']['type'])){
$file_name = $_FILES['voice']['name'];
            $file_size = $_FILES['voice']['size'];
            $file_type = $_FILES['voice']['type'];
            $file_source = $_FILES['voice']['tmp_name'];
            
            $name = file_name_filter($file_name);
            $ext = file_name_filter($file_name,true);
            $name = 'voicenote-'.time().'-'.$name.$ext;
            
            
            $folder_name = upload_folder_name();
            
            $allow_audio_type = array('amr','wav','mp3','mp4','ogg','webm','caf');
            
if(!is_dir('../../lumonata-plugins/voicenote/files/'.$folder_name)){
                if(!create_dir('../../lumonata-plugins/voicenote/files/'.$folder_name))
            return '{"result":"'.$err_codes[500].'"}';
            }
            
            $destination='../../lumonata-plugins/voicenote/files/'.$folder_name.'/'.$name;
            if(in_array($ext,$allow_audio_type) || $file_type=='audio/mp3' || $file_type=='audio/mpeg'){
            upload($file_source, $destination);
            //add_additional_field($post_id, 'attachment', $folder_name.'/'.$name, 'voice_note');
add_additional_field($post_id, 'file_name', $folder_name.'/'.$name, 'voice_note');
//print_r($_FILES);
            }else{ 
            return '{"result":"'.$err_codes[415]." File type sent is:".$file_type.'"}';
            }
}
if(!empty($locname) || !empty($lat) || !empty($long)){
//modified on 25 June 2012 by aankun
add_additional_field( $post_id, 'latitude', $lat, 'location_map');
add_additional_field( $post_id, 'longitude', $long, 'location_map');
add_additional_field( $post_id, 'location_name', $locname, 'location_map');
//modified on 25 June 2012 by aankun ^^^
}
if(!empty($original_id)){
$sql_repost = $db->prepare_query("SELECT lumonata_articles.*,lumonata_users.lusername 
 FROM lumonata_articles 
 INNER JOIN lumonata_users ON lumonata_articles.lpost_by = lumonata_users.luser_id 
         AND lumonata_articles.larticle_id=%d",$original_id);
$query_repost= $db->do_query($sql_repost);
$fetch_repost = $db->fetch_array($query_repost);
}
if($saveit){
//B[AM20120910]
if($action=='repost'){
if ($fetch_share['larticle_type']=='board_photo' || $fetch_share['larticle_type']=='board_photo_repost'){
//process_point($_COOKIE['user_id'],'photo','add'); 
}else{
process_point($token->id,'post','add'); 
}
}elseif($action=='board_photo' || $fetch_share['larticle_type']=='board_photo' || $fetch_share['larticle_type']=='board_photo_repost'){
//process_point($_COOKIE['user_id'],'photo','add'); 
}else{
process_point($token->id,'post','add'); 
}
//E[AM20120910]
add_additional_field( $post_id, 'application_device', $application_device, 'post_devices');
$query=$db->prepare_query("SELECT * 
FROM lumonata_articles 
WHERE larticle_status='publish' AND larticle_id=%d",$post_id);
/*modify by wahya*/
$post_result=$db->do_query($query);
$post=$db->fetch_array($post_result);
if(is_contain_tag($post['larticle_title'])){
    $user_tagged=get_match_tags($post['larticle_title']);
   
    foreach ($user_tagged[1] as $keytag =>$valtag){
    if( is_exist_user($valtag) ){
    $effected_id=fetch_user_ID_by_username($valtag);
if($effected_id==$token->id){
//nge mention diri sendiri
}else{
$save_notification = save_notification($post['larticle_id'], $token->id, $token->id, $effected_id, 'post_tag', 0);
$permalink=permalink($post['larticle_id'],false,$post['lpost_by']);
tagmail($token->id,$effected_id, $post['larticle_title'], $permalink);
}
    }
    }
    }

       
if(isUrl($post['larticle_title'])){
$the_url=get_web_address($post['larticle_title']);
if( preg_match("/youtube.com/i", $the_url) || preg_match("/vimeo.com/i", $the_url) ){
$jsonAttachment=fetch_normal_vid($the_url,false);
$jsonAttachment=json_encode($jsonAttachment);
}else{
$jsonAttachment=fetch_normal_url($the_url,false);
$jsonAttachment=json_encode($jsonAttachment);
}
add_additional_field( $post['larticle_id'], 'p_url_attached', $the_url, 'attach_url');
add_additional_field( $post['larticle_id'], 'p_att_json', $jsonAttachment, 'attach_url');
}
//Check Attachment
/*
if($action=='repost'){
$image=fetch_attachment($original_id,"ASC",true,1);
if(!empty($image['lattach_loc'])){
insert_attachment($post['larticle_id'], '', '', $image['lattach_loc']);
}
}
*/
if($action!='reply' && $box==0){
//[A20120420]
$o_url = '';
$p_url = '';
$add_title = '';
$s_url = '';
$link_url='';
if($action=='repost'){
$id_to_check=$post['loriginal_post'];
}else{
$id_to_check=$post['larticle_id'];
}
$origin_photo_data=is_post_having_board_photo($id_to_check,true);
if($origin_photo_data['status']==TRUE){
$album = $origin_photo_data['data'];
$o_url = ROOT_PATH.'/lumonata-plugins/gallery/files/'.$album['lattach_loc'];
insert_attachment($post['larticle_id'], '', '', $album['lattach_loc']);
}
$origin_url=is_post_having_url_attached($id_to_check);
if($origin_url['status']==TRUE){
$postContent=str_replace($origin_url['url'],'', $post['larticle_title']);
$link_url = $origin_url['url'];
}else{
$postContent=$post['larticle_title'];
}
/*
if(isset($_FILES['photo'])){
$o_url = ROOT_PATH.'/lumonata-plugins/gallery/files/'.$board_image_name ;
$add_title = 'Board Photo - iPosting';
}
*/
$p_url = permalink($post['larticle_id'],false,$post['lpost_by']);
$add_title = 'Board Photo - iPosting';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://kro.co/api?url='.$p_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$s_url = curl_exec($ch);
curl_close($ch);
$postContent = $postContent.' '.$link_url;
$postContent = str_replace('[span:rp]RP[:span]','RP',$postContent);
scm_post_on_facebook($postContent,$s_url,$o_url,$add_title,$post['lpost_by']);
scm_post_on_twitter($postContent,$s_url,'',$post['lpost_by']);
}


$objContent=new html2text($post['larticle_content']);
$content= $objContent->get_text();
//date('d/m/Y H:i a',$post['lpost_date']);
//'post_date'=>nicetime($post['lpost_date'],date("Y-m-d H:i:s")),
if($post['larticle_type']=='status_repost' || $post['larticle_type']=='articles_repost')
$article_id_for_attachment=$post['loriginal_post'];
else 
$article_id_for_attachment=$post['larticle_id'];
$array_result[]=array(
'id'=>intval($post['larticle_id']),
'original_id'=>intval($post['loriginal_post']),
'parent_id'=>intval($post['lparent']),
'title'=>replace_url_string($post['larticle_title']),
'original_id'=>intval($post['loriginal_post']),
'content'=>replace_url_string($content),
'status'=>$post['larticle_status'],
'type'=>$post['larticle_type'],
'num_repost'=>intval($post['lno_repost']),
'num_reply'=>intval($post['lno_reply']),
'num_like'=>intval($post['lcount_like']),
'post_date'=>strtotime($post['lpost_date']),
'user' =>getinfo($post['lpost_by'],'array'),
'post_url'=>permalink($post['larticle_id'],true,$post['lpost_by']),
'attachment'=>array('image'=>get_image_attachment($article_id_for_attachment),
'video'=>get_embed($article_id_for_attachment,'video'),
'link'=>get_embed($article_id_for_attachment,'link'),
'voice'=>get_embed($article_id_for_attachment,'voice')
),
'latitude'=>get_additional_field($post['larticle_id'], 'latitude', 'location_map'),
'longitude'=>get_additional_field($post['larticle_id'], 'latitude', 'location_map'),
'box_id'=>intval($post['lshare_to'])
);
return json_encode($array_result);
}
}
function save_post($token,$title,$content,$status,$type,$comments,$sef='',$share_to=0,$original_post=0,$lparent=0){
       global $db,$allowedposttags,$allowedtitletags;
       
        $token=token_decode($token);
        
        if(empty($title)){
           //$num_untitled=is_num_articles('title=Untitled&type='.$type)+1;
           $title="Untitled";
        }else{
       
        $title=str_replace("<", "&lt;", $title);/*W20111220-1*/
       
            $title=kses(rem_slashes($title),$allowedtitletags);
            
        }
        
        //$content=str_replace("<", "&lt;", $content); /*W20111220-1*/
        $content=rem_slashes($content);
        
        /*Formulating the SEF URL.
         First count the number of same title and applications at article table.
         If same title found then add numberic after the SEF created.
         If there are no same title, then use the original SEF
        */
        
        if(empty($sef)){
            $num_by_title_and_type=is_num_articles('title='.$title.'&type='.$type);
            if($num_by_title_and_type>0){
                for($i=2;$i<=$num_by_title_and_type+1;$i++){
                $sef=generateSefUrl($title)."-".$i;
                if(is_num_articles('sef='.$sef.'&type='.$type) < 1){
                $sef=$sef;
                break;
                }
                }
            }else{
                $sef=generateSefUrl($title);
            }
        }
        

     $sql=$db->prepare_query("INSERT INTO lumonata_articles(larticle_title,
                                                                larticle_content,
                                                                larticle_status,
                                                                larticle_type,
                                                                lcomment_status,
                                                                lsef,
                                                                lpost_by,
                                                                lpost_date,
                                                                lupdated_by,
                                                                ldlu,
                                                                lshare_to,
                                                                loriginal_post,
                                                                lparent)
                                VALUES(%s,%s,%s,%s,%s,%s,%d,%s,%d,%s,%d,%d,%d)",
                                                                $title,
                                                                $content,
                                                                $status,
                                                                $type,
                                                                $comments,
                                                                $sef,
                                                                $token->id,
                                                                date("Y-m-d H:i:s"),
                                                                $token->id,
                                                                date("Y-m-d H:i:s"),
                                                                $share_to,
                                                                $original_post,
                                                                $lparent);
       
        if(reset_order_id("lumonata_articles"))
            return $db->do_query($sql);
        
        return false;
    }
//[X20110112-1] widia add code here    
    function update_count_repost($article_id){
    global $db;
    //find the update number of approved comment
         $query=$db->prepare_query("SELECT count(*) as jml
FROM lumonata_articles 
WHERE loriginal_post=%d",$article_id);
         $result=$db->do_query($query);
         $thenumber_of_repost=$db->fetch_array($result);
         $tmp = $thenumber_of_repost['jml'] + 1;

         //update the number in lumonata_articles table
         $query_update=$db->prepare_query("UPDATE lumonata_articles
            SET lno_repost=%d 
            WHERE larticle_id=%d",$tmp,$article_id);
        
         return $db->do_query($query_update);
    }
    
    function update_count_reply($article_id){
    global $db;
    //find the update number of approved comment
         $query=$db->prepare_query("SELECT count(*) as jml
FROM lumonata_articles 
WHERE lparent=%d",$article_id);
         $result=$db->do_query($query);
         $thenumber_of_repost=$db->fetch_array($result);
         $tmp = $thenumber_of_repost['jml'] + 1;

         //update the number in lumonata_articles table
         $query_update=$db->prepare_query("UPDATE lumonata_articles
            SET lno_reply=%d 
            WHERE larticle_id=%d",$tmp,$article_id);
        
         return $db->do_query($query_update);
    }
   //widia end code
   
   function readAllMentions($token){
    global $db;
   
    $token=token_decode($token);
   
$query=$db->prepare_query("UPDATE lumonata_notifications
SET lstatus='read'
WHERE laffected_user=%d",$token->id);
$result=$db->do_query($query);
if($result){
return '{"result": "ok"}';
}else{
return '{"result": "error"}';
}
   } 
   
   function countNotif($token){
    $token=token_decode($token);
    $cnt=count_notifications($token->id);
    return '{"result": '.$cnt.'}';
   }
   
   function deletePost($token,$post_id,$format='json'){
    global $db;
   
    $token=token_decode($token);
   
    $article = fetch_artciles_by_id($post_id);
       
   
    $delete_queue=get_meta_data('timeline_delete_queue','crontime');
   
    $sql=$db->prepare_query("SELECT COUNT(postid) as countPost
    FROM lumonata_board 
    WHERE postid=%d",$post_id);
   
    $countPostResult=$db->do_query($sql);
    $countPostData=$db->fetch_array($countPostResult);
   
    $queueArray[$post_id]['noOfPost']=$countPostData['countPost'];
    $queueArray[$post_id]['limit']=0;
   
    if(empty($delete_queue)){
    $encode_queue=json_encode($queueArray);
    }else{
    $decode_queue= json_decode($delete_queue,true);
    $queue_merge=$decode_queue+$queueArray;
    $encode_queue=json_encode($queue_merge);
    }
   
    update_meta_data('timeline_delete_queue',$encode_queue,'crontime');
   
   
    if($token->id==$article['lpost_by']){
//B[AM20120910]
    $att = fetch_attachment($post_id,'DESC',true);
$nnn = $db->num_rows($att);
if($nnn>0) $is_board_photo = true;
else $is_board_photo = false;
//E[AM20120910]
    $result=delete_article($post_id, $article['larticle_type']);
   
    if($result){
//B[AM20120910]
    if($is_board_photo){
process_point($token->id,'photo','delete'); 
}else{
process_point($token->id,'post','delete');
}
    //E[AM20120910]
$response=array(
'result'=>'ok'
);
}else{
$response=array(
'result'=>'error'
);
}
    }
$response_json=json_encode($response);
return $response_json;
   
   }
   
   function getPostReplies($post_id,$type,$attachment_id=0){
    global $db;
   
    if($type=='photo_comment'){
   
    $query=$db->prepare_query("SELECT * 
    FROM lumonata_articles
                                WHERE loriginal_post=%d 
                                ORDER BY lpost_date",$attachment_id);
   
    }elseif($type=='album'){
   
    $query=$db->prepare_query("SELECT * 
    FROM lumonata_articles
                                WHERE lparent=%d AND
                                larticle_type=%s
                                ORDER BY lpost_date",$post_id,'reply_album');
    }else{
   
    $query=$db->prepare_query("SELECT * 
    FROM lumonata_articles
                                WHERE lparent=%d 
                                ORDER BY lpost_date",$post_id);
    }
   
    $result_db=$db->do_query($query);
//'post_date'=>date(get_date_format()." ".get_time_format(),strtotime($post['lpost_date'])),
    while($post=$db->fetch_array($result_db)){
   
    $objContent=new html2text($post['larticle_content']);
$content= $objContent->get_text();
    $result[]=array(
'id'=>intval($post['larticle_id']),
'original_id'=>intval($post['loriginal_post']),
'parent_id'=>intval($post['lparent']),
'title'=>replace_url_string($post['larticle_title']),
'original_id'=>intval($post['loriginal_post']),
'content'=>replace_url_string($content),
'status'=>$post['larticle_status'],
'type'=>$post['larticle_type'],
'num_repost'=>intval($post['lno_repost']),
'num_reply'=>intval($post['lno_reply']),
'num_like'=>intval($post['lcount_like']),
    'post_date'=>strtotime($post['lpost_date']),
'user' =>getinfo($post['lpost_by'],'array'),
'post_url'=>permalink($post['larticle_id'],true,$post['lpost_by']),
'attachment'=>array('image'=>get_image_attachment($post['larticle_id']),
'video'=>get_embed($post['larticle_id'],'video'),
'link'=>get_embed($post['larticle_id'],'link'),
'voice'=>get_embed($post['larticle_id'],'voice')
),
'latitude'=>get_additional_field($post['larticle_id'], 'latitude', 'location_map'),
'longitude'=>get_additional_field($post['larticle_id'], 'latitude', 'location_map'),
'box_id'=>intval($post['lshare_to'])
);
    }
    return json_encode($result);
   }
   
   function getPostReposts($post_id){
    global $db;
   
    /*
    $query=$db->prepare_query("SELECT a.* 
    FROM lumonata_articles a, lumonata_comments b
                                WHERE b.larticle_id=%d AND
                                 b.lcomment_type='repost' AND
                                 b.larticle_id=a.larticle_id
                                ORDER BY a.lpost_date",$post_id);
    */
// [AM20120807]
    $query=$db->prepare_query("SELECT * 
    FROM lumonata_articles 
    WHERE loriginal_post=%d AND larticle_type=%s ORDER BY lpost_date",$post_id,'status_repost');
   
    //'post_date'=>date(get_date_format()." ".get_time_format(),strtotime($post['lpost_date'])),
    $result_db=$db->do_query($query);
    while($post=$db->fetch_array($result_db)){
   
    $objContent=new html2text($post['larticle_content']);
$content= $objContent->get_text();
    $result[]=array(
'id'=>intval($post['larticle_id']),
'original_id'=>intval($post['loriginal_post']),
'parent_id'=>intval($post['lparent']),
'title'=>replace_url_string($post['larticle_title']),
'original_id'=>intval($post['loriginal_post']),
'content'=>replace_url_string($content),
'status'=>$post['larticle_status'],
'type'=>$post['larticle_type'],
'num_repost'=>intval($post['lno_repost']),
'num_reply'=>intval($post['lno_reply']),
'num_like'=>intval($post['lcount_like']),
    'post_date'=>strtotime($post['lpost_date']),
'user' =>getinfo($post['lpost_by'],'array'),
'post_url'=>permalink($post['larticle_id'],true,$post['lpost_by']),
'attachment'=>array('image'=>get_image_attachment($post['larticle_id']),
'video'=>get_embed($post['larticle_id'],'video'),
'link'=>get_embed($post['larticle_id'],'link'),
'voice'=>get_embed($post['larticle_id'],'voice')
),
'latitude'=>get_additional_field($post['larticle_id'], 'latitude', 'location_map'),
'longitude'=>get_additional_field($post['larticle_id'], 'latitude', 'location_map'),
'box_id'=>intval($post['lshare_to'])
);
    }
    return json_encode($result);
   }
   
   function createAlbum($token,$title,$description,$box_id){
  global $db;
  $isSuccess=save_post($token,$title, $description, 'publish', 'album', 'allowed','',$box_id,0,0);
  $post_id=mysql_insert_id();
 
  if($isSuccess){
  return '{"id":'.$post_id.',"album_name":"'.$title.'","description":"'.$description.'","box_id":'.$box_id.'}';
  }else{
  return '{"result":"Create album failed"}';
  }
   }
   
   
   function detail_status($token,$article_id,$format='json'){
global $db;
$the_token=token_decode($token);
$id=$the_token->id;
$query=$db->prepare_query("SELECT * FROM lumonata_articles 
WHERE larticle_status='publish' AND
larticle_id = %d
ORDER BY lpost_date DESC",$article_id);
$result=$db->do_query($query);
$data=$db->fetch_array($result);
$objContent=new html2text($data['larticle_content']);
$content= $objContent->get_text();

if($data['larticle_type']=='status_repost' || $data['larticle_type']=='articles_repost')
$article_id_for_attachment=$data['loriginal_post'];
else 
$article_id_for_attachment=$data['larticle_id'];
$response=array(
'id'=>intval($data['larticle_id']),
'original_id'=>intval($data['loriginal_post']),
'parent_id'=>intval($data['lparent']),
'title'=>replace_url_string($data['larticle_title']),
'original_id'=>intval($data['loriginal_post']),
'content'=>$content,
'status'=>$data['larticle_status'],
'type'=>$data['larticle_type'],
'num_repost'=>intval($data['lno_repost']),
'num_reply'=>intval($data['lno_reply']),
'num_like'=>intval($data['lcount_like']),
'post_date'=>strtotime($data['lpost_date']),
'user' =>getinfo($data['lpost_by'],'array'),
'post_url'=>permalink($data['larticle_id'],true,$data['lpost_by']),
'attachment'=>array('image'=>get_image_attachment($article_id_for_attachment),
'video'=>get_embed($article_id_for_attachment,'video'),
'link'=>get_embed($article_id_for_attachment,'link'),
'voice'=>get_embed($article_id_for_attachment,'voice')
),
'latitude'=>get_additional_field($data['larticle_id'], 'latitude', 'location_map'),
'longitude'=>get_additional_field($data['larticle_id'], 'latitude', 'location_map'),
'box_id'=>intval($data['lshare_to'])
);
$response_json=json_encode($response);
return $response_json;
}
function replace_url_string($string){
return preg_replace("#[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]#", "[url]\\0[/url]", $string);
}
?>





pertanyaan saya  script mana untuk menampilkan di status biar bisa di lihat org banyak ?
(untuk sementara dengan script ini hanya tampil di my profil)

--
You received this message because you are subscribed to the Google Groups "Belajar SQL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to belajar-sql...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks & Best Regards,

Feris Thia
Business Intelligence Consultant
PT. Putera Handal Indotama
Phone  : +6221-70387738
Mobile : +628176-474-525

Dedi Upit

unread,
May 22, 2013, 2:29:22 AM5/22/13
to belaj...@googlegroups.com
Dear Feris Thia
bukan tapi pelajar...klo boleh tau ini artinya apa?

$parent_id =0;
$sql_share = $db->prepare_query("SELECT lumonata_articles.*, lumonata_users.lusername 
FROM lumonata_articles 
INNER JOIN lumonata_users ON lumonata_articles.lpost_by = lumonata_users.luser_id 
AND lumonata_articles.larticle_id=%d",$original_id);

<span class="App
...

Feris Thia

unread,
May 22, 2013, 2:42:24 AM5/22/13
to belaj...@googlegroups.com
Baik, kalau pelajar bukannya harus kerjain PR nya dulu ? Bisa coba terangkan ke saya dulu apa yang sudah dikerjakan dan dipahami ? Dan bagian mana yang tidak dipahami ?

Buat urutan pertanyaan yang baik. Ini juga nasehat untuk bekal di karir ataupun jadi pengusaha.

Regards,

Feris

On Wed, May 22, 2013 at 1:29 PM, Dedi Upit <dedi...@gmail.com> wrote:
Dear Feris Thia
bukan tapi pelajar...klo boleh tau ini artinya apa?




Dedi Upit

unread,
May 22, 2013, 2:52:06 AM5/22/13
to belaj...@googlegroups.com
Dear feris thia 

saya sedang mengerjakan tugas bagaimana status yang di buat akan terkirim ke status pertemanan orang lain bukan ke profil kita sendiri ..apakah ada query dsini untuk menampilkan ke orang lain 
saya belum paham tentang query mana yang akan di tampilkan di status 

terimakasih 


2013/5/22 Feris Thia <fe...@phi-integration.com>

--
You received this message because you are subscribed to a topic in the Google Groups "Belajar SQL" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/belajar-sql/F47SJ7SIZ6I/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to belajar-sql...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages