Changeset 356 for branches

Show
Ignore:
Timestamp:
03/25/06 01:12:37 (3 years ago)
Author:
anti
Message:

+ this is some seriosly old code, but there is some tagging stuff in here

Location:
branches/plogger-with-tags
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/plogger-with-tags/admin/plog-admin-functions.php

    r154 r356  
    720720 
    721721 
     722function parse_tags($str) { 
     723        // 1. compress all whitespace 
     724        $str = preg_replace('/\s{2,}/','',$str); 
     725        // 2. extract any phrases in quotes 
     726        preg_match_all('/"([(\w|\s)]+)"/',$str,$phrases); 
     727        preg_match_all('/"([^"]+)"/',$str,$phrases); 
     728 
     729        // 2. now remove the phrases 
     730        $str = preg_replace('/"([^"]*)"/','',$str); 
     731        // 3. get single words 
     732        $words = preg_split('/\s+/',$str); 
     733        $tags = array_merge($phrases[1],$words); 
     734 
     735        $usable_tags = array(); 
     736        foreach($tags as $tag) { 
     737               if (empty($tag)) continue; 
     738               if (!preg_match('/[^\W]/',$tag)) continue; 
     739               $usable_tags[] = $tag; 
     740        } 
     741        return $usable_tags; 
     742} 
     743 
     744function update_picture_tags($picture_id,$tags) { 
     745        global $TABLE_PREFIX; 
     746        $tags = parse_tags(SmartStripSlashes($tags)); 
     747        $picture_id = intval($picture_id); 
     748 
     749        /* process any tags for the picture */ 
     750        $existing_tags = $existing_rels = array(); 
     751        if (sizeof($tags) > 0) { 
     752                $tagsql = join('","',$tags); 
     753                $sql = 'SELECT * FROM '.$TABLE_PREFIX.'tags WHERE `tag` IN ("'.$tagsql.'")'; 
     754                $result = mysql_query($sql); 
     755                while($tag_row = mysql_fetch_assoc($result)) { 
     756                        $existing_tags[$tag_row['tag']] = $tag_row['id']; 
     757                }; 
     758 
     759                $sql = 'SELECT * FROM '.$TABLE_PREFIX.'tag2picture WHERE `picture_id` ="'.$picture_id.'"'; 
     760                $result = mysql_query($sql); 
     761                while($tag_row = mysql_fetch_assoc($result)) { 
     762                        $existing_rels[$tag_row['tag_id']] = $tag_row['picture_id']; 
     763                }; 
     764        }; 
     765 
     766        foreach($tags as $tag) { 
     767                if (!isset($existing_tags[$tag])) { 
     768                        // must be a new tag, register it 
     769                        $formatted = mysql_real_escape_string(preg_replace("/[^\w|\.|'|\-|\[|\]]/","_",$tag)); 
     770                        $sql = 'INSERT INTO '.$TABLE_PREFIX.'tags (`tag`,`tagdate`,`formatted`) 
     771                                        VALUES ("'.mysql_real_escape_string($tag).'","'.$formatted.'",NOW())'; 
     772                        print $sql; 
     773                        $result = mysql_query($sql); 
     774                        $existing_tags[$tag] = mysql_insert_id(); 
     775                }; 
     776 
     777                if (!isset($existing_rels[$existing_tags[$tag]])) { 
     778                        // no connection between tag and picture? create if 
     779                        $sql = 'INSERT INTO '.$TABLE_PREFIX.'tag2picture (`picture_id`,`tag_id`,`tagdate`) 
     780                                        VALUES ("'.$picture_id.'","'.$existing_tags[$tag].'",NOW())'; 
     781                        mysql_query($sql); 
     782                }; 
     783        } 
     784 
     785        // now remove links to any tags that have been deleted 
     786        foreach($existing_rels as $tag_id => $pic_id) { 
     787                if (!in_array($tag_id,$existing_tags)) { 
     788                        $sql = "DELETE FROM `".$TABLE_PREFIX."tag2picture` 
     789                                        WHERE `picture_id` = '$picture_id' AND `tag_id` = '$tag_id'";   
     790                        mysql_query($sql); 
     791                }; 
     792 
     793        } 
     794} 
    722795?> 
  • branches/plogger-with-tags/admin/plog-manage.php

    r154 r356  
    307307                 
    308308                $output .= '<form class="edit" action="'.$_SERVER["PHP_SELF"].'" method="post">'; 
    309                  
    310                  
    311                 $output .= 'Caption:<br/><input size="80" name="caption" id="caption" value="'.$photo['caption'].'"> 
    312                                     Allow Comments? <input type="checkbox" id="allow_comments" name="allow_comments" value="1"'." $state>"; 
     309 
     310                $tagsql = "SELECT tag FROM ".$TABLE_PREFIX."tags tags,".$TABLE_PREFIX."tag2picture rel 
     311                WHERE tags.id = rel.tag_id AND rel.picture_id = " . $photo['id']; 
     312                $result = mysql_query($tagsql); 
     313                $tags = array(); 
     314 
     315                while($tag_row = mysql_fetch_assoc($result)) { 
     316                        $tag_value = $tag_row["tag"]; 
     317                        // if tag contains spaces, then surround it with quotes 
     318                        if (preg_match("/\s/",$tag_value)) $tag_value = '"' . $tag_value . '"'; 
     319                        $tags[] = $tag_value; 
     320                }; 
     321 
     322                $tagvalue = join(' ',$tags); 
     323 
     324                $output .= 'Caption:<br/><input size="80" name="caption" id="caption" value="'.$photo['caption'].'"><br/>'; 
     325                $output .= "Tags:<br/> <input size='80' id='tags' name='tags' value='".$tagvalue."'><br/>"; 
     326                $output .= 'Allow Comments? <input type="checkbox" id="allow_comments" name="allow_comments" value="1"'." $state>"; 
    313327                                         
    314328                $output .= '<input type="hidden" name="level" value="'.$_REQUEST['level'].'"><input type="hidden"  
     
    413427        else if ($_POST['action'] == 'update-picture') { 
    414428                $action_result = update_picture($_POST['pid'],$_POST['caption'],$_POST['allow_comments']); 
     429                update_picture_tags($_POST['pid'],$_POST['tags']); 
    415430        } 
    416431        else if ($_POST['action'] == 'update-album') { 
  • branches/plogger-with-tags/admin/plog-upload.php

    r151 r356  
    8080                                         
    8181                                $result = add_picture($album_id,$_FILES["userfile"]["tmp_name"],$_FILES["userfile"]["name"],$_REQUEST["caption"]); 
    82                                 $output .= '<p class="actions">'.$result["output"].'</p>'; 
     82                                if (!empty($result['errors'])) { 
     83                                        $output .= '<p class="errors">'.$result["errors"].'</p>'; 
     84                                } else { 
     85                                        $output .= '<p class="actions">'.$result["output"].'</p>'; 
     86                                        update_picture_tags($result["picture_id"],$_POST["tags"]); 
     87                                }; 
    8388                         
    8489                } 
     
    9398      &nbsp;<input name="userfile" type="file"/><br /> 
    9499                        Picture Caption (optional): <input name="caption" size="60"/><br /> 
     100                        Tags (optional): <input name="tags" size="60"/><br /> 
    95101                        </div>'; 
    96102 
  • branches/plogger-with-tags/gallery.php

    r153 r356  
    8181        $output .= ' 
    8282                <div id="wrapper"> 
    83                         <table id="header-table" width="100%"><tr><td>'.generate_header().'</td><td style="text-align: right; vertical-align: bottom;">'.generate_jump_menu().generate_search_box().'</td></tr></table>'; 
     83                        <table id="header-table" width="100%"><tr><td>'.generate_header().'</td><td style="text-align: right; vertical-align: bottom;"> <a href="'.$SERVER["PHP_SELF"].'?level=tags">tags</a> '.generate_jump_menu().generate_search_box().'</td></tr></table>'; 
    8484         
    8585        if ($level != "picture"){ 
     
    262262 
    263263                        $num_items = 1; 
     264                } 
     265 
     266                if ($level == "tags") { 
     267                        $output .= '<div id="inner_wrapper"><div id="big-picture-container">'; 
     268                        $output .= generate_tag_interface(); 
     269                        $output .= '</div></div>'; 
    264270                } 
    265271                 
     
    11031109} 
    11041110 
     1111function generate_tag_interface() { 
     1112        global $TABLE_PREFIX; 
     1113 
     1114        $selected_tag = $_GET["tag"]; 
     1115        $sel_id = 0; 
     1116        $sql = "SELECT * FROM ".$TABLE_PREFIX."tags"; 
     1117        $result = run_query($sql); 
     1118        $filter = 0; 
     1119        $output = ''; 
     1120        while($row = mysql_fetch_assoc($result)) { 
     1121                if ($row['id'] == $selected_tag) $filter=$row['tag']; 
     1122                $output .= "<a href='" . $_SERVER["PHP_SELF"] . '?level=tags&tag=' . $row['id'] . "'>" . $row['tag'] . '</a> '; 
     1123        }; 
     1124        if ($filter) { 
     1125                $output .= "<h1>Pictures tagged with `$filter`</h1>"; 
     1126                $output .= '<ul class="slides">'; 
     1127                $sql = "SELECT p.*,path,tag FROM ".$TABLE_PREFIX."pictures p, ".$TABLE_PREFIX."tags tag, ".$TABLE_PREFIX."tag2picture t2p WHERE (p.id = t2p.picture_id AND t2p.tag_id = tag.id AND tag.id = '$selected_tag')"; 
     1128                $result = mysql_query($sql); 
     1129                while($row = mysql_fetch_assoc($result)) { 
     1130                       $thumbpath = generate_thumb($row['path'], $row['id'], 'small'); 
     1131                       $output .= "<li class='thumbnail'>"; 
     1132                       $imgtag = '<img class="photos" src="'.$thumbpath.'" title="'.htmlspecialchars($row["description"]).'" alt="'.htmlspecialchars($row["description"]).'" />'; 
     1133                       $output .= "<a href='" . generate_url("picture",$row['id']) . "'>"; 
     1134                       $output .= $imgtag; 
     1135                       $output .= "</a></li>"; 
     1136                }; 
     1137                $output .= "</ul>"; 
     1138        }; 
     1139        return $output; 
     1140} 
     1141 
    11051142// function for generating the slideshow javascript 
    11061143function generate_slideshow_js($id, $mode) { 
  • branches/plogger-with-tags/plog-connect.php

    r3 r356  
    55 
    66$DB_HOST = "localhost"; 
    7 $DB_USER = ""; 
    8 $DB_PW = ""; 
    9 $DB_NAME = ""; 
     7$DB_USER = "plogtag"; 
     8$DB_PW = "plogtag"; 
     9$DB_NAME = "plogtag"; 
    1010 
    1111$dbh = mysql_connect ($DB_HOST, $DB_USER, $DB_PW) or die ("Plogger cannot connect to the database because: " . mysql_error()); 
    1212mysql_select_db ($DB_NAME); 
     13 
    1314 
    1415function run_query($query){