Changeset 333

Show
Ignore:
Timestamp:
05/11/06 12:49:48 (3 years ago)
Author:
sven
Message:

tagging: functionised the conversion of a comma-separated keyword list into tags table entries.
units/files/files_actions.php: fixed a bug that prevented the editing of a folder's properties.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/.htaccess

    r276 r333  
    11RewriteEngine on 
     2RewriteBase /elgg/ 
    23Options +FollowSymLinks 
    34 
     
    78#php_flag short_open_tag off 
    89# Forgot that anyone might still have this turned on 
    9 #php_flag register_globals off 
     10php_flag register_globals off 
    1011 
    1112RewriteRule ^([0-9\-]+)\.css$ _templates/css.php?template=$1 
  • devel/lib/elgglib.php

    r307 r333  
    40844084} 
    40854085 
     4086 
     4087 
     4088// Take a comma-separated string of keywords and create the relevant tag entries 
     4089// in the database. Returns a cleaned comma-separated keyword string. 
     4090function insert_tags_from_string ($string, $tagtype, $ref, $access, $owner) { 
     4091 
     4092    $ref = (int) $ref; 
     4093    $owner = (int) $owner; 
     4094    $tagtype = trim($tagtype); 
     4095    $access = trim($access); 
     4096    $string = trim($string); 
     4097    $keywords = ""; 
     4098 
     4099    $string = str_replace("\n", "", $string); 
     4100    $string = str_replace("\r", "", $string); 
     4101    if ($string) { 
     4102        $keyword_list = explode(",", $string); 
     4103        //$keyword_list = array_unique($keyword_list); // maybe? 
     4104        sort($keyword_list); 
     4105        if (sizeof($keyword_list) > 0) { 
     4106            foreach($keyword_list as $key => $list_item) { 
     4107                $list_item = trim($list_item); 
     4108                if ($list_item) { 
     4109                    if ($key > 0) { 
     4110                        $keywords .= ", "; 
     4111                    } 
     4112                    $keywords .= $list_item; 
     4113                    $t = new StdClass; 
     4114                    $t->tagtype = $tagtype; 
     4115                    $t->access = $access; 
     4116                    $t->tag = $list_item; 
     4117                    $t->ref = $ref; 
     4118                    $t->owner = $owner; 
     4119                    insert_record('tags', $t); 
     4120                } 
     4121            } 
     4122        } 
     4123    } 
     4124 
     4125    return($keywords); 
     4126} 
     4127 
     4128 
    40864129?> 
  • devel/profile/edit.php

    r330 r333  
    6363        foreach($profiledetails as $field => $value) { 
    6464            $field = addslashes($field); 
    65             foreach($data['profile:details'] as $datatype) { 
    66                 if ($datatype[1] == $field && $datatype[2] == "keywords") { 
    67                     delete_records('tags','tagtype',$field,'owner',$owner); 
    68                 } 
    69             } 
    70                  
     65            $value = trim($value); 
     66 
    7167            if ($value != "") { 
    72                      
    7368                //TODO get rid of variable duplication here. (Penny) 
    74                 $owner  = (int) $page_owner; 
    75                 $access = $_POST['profileaccess'][$field];                     
     69                $access = $_POST['profileaccess'][$field]; 
    7670 
    7771                $pd = new StdClass; 
     
    7973                $pd->value  = $value; 
    8074                $pd->access = $access; 
    81                 $pd->owner  = $owner; 
     75                $pd->owner  = $page_owner; 
    8276 
    8377                $insert_id  = insert_record('profile_data',$pd); 
    84                      
    85                 foreach($data['profile:details'] as $datatype) { 
    86                     if ($datatype[1] == $field && $datatype[2] == "keywords") { 
    87                         $keywords = ""; 
    88                         $value = str_replace("\n","",$value); 
    89                         $value = str_replace("\r","",$value); 
    90                         $keyword_list = explode(",",$value); 
    91                         sort($keyword_list); 
    92                         if (sizeof($keyword_list) > 0) { 
    93                             foreach($keyword_list as $key => $list_item) { 
    94                                 $list_item = trim($list_item); 
    95                                 if ($list_item) { 
    96                                     if ($key > 0) { 
    97                                         $keywords .= ", "; 
    98                                     } 
    99                                     $keywords .= $list_item; 
    100                                     $t = new StdClass; 
    101                                     $t->tagtype = $field; 
    102                                     $t->access = $access; 
    103                                     $t->tag = $list_item; 
    104                                     $t->ref = $insert_id; 
    105                                     $t->owner = $owner; 
    106                                     insert_record('tags',$t); 
    107                                 } 
    108                             } 
    109                         } 
    110                         $value = $keywords; 
    111                     } 
     78            } 
    11279 
     80 
     81            foreach($data['profile:details'] as $datatype) { 
     82                if ($datatype[1] == $field && $datatype[2] == "keywords") { 
     83                    delete_records('tags', 'tagtype', $field, 'owner', $page_owner); 
     84                    $value = insert_tags_from_string ($value, $field, $insert_id, $access, $page_owner); 
    11385                } 
    114  
    11586            } 
    11687        } 
  • devel/units/files/files_actions.php

    r271 r333  
    2323            $insert_id = insert_record('file_folders',$f); 
    2424            $value = trim(optional_param('new_folder_keywords')); 
    25             if (!empty($value)) { 
    26                 $value = str_replace("\n","",$value); 
    27                 $value = str_replace("\r","",$value); 
    28                 $keyword_list = explode(",",$value); 
    29                 sort($keyword_list); 
    30                 if (sizeof($keyword_list) > 0) { 
    31                     foreach($keyword_list as $key => $list_item) { 
    32                         $t = new StdClass; 
    33                         $t->tagtype = 'folder'; 
    34                         $t->access = $f->access; 
    35                         $t->tag = trim($list_item); 
    36                         $t->ref = $insert_id; 
    37                         $t->owner = $USER->ident; 
    38                         insert_record('tags',$t); 
    39                     } 
    40                 } 
    41             } 
     25            insert_tags_from_string ($value, 'folder', $insert_id, $f->access, $f->owner); 
    4226            $messages[] = gettext("Your folder was created."); 
    4327        } else { 
     
    8771                $file_id = insert_record('files',$f); 
    8872                $value = trim(optional_param('new_file_keywords')); 
    89                 if (!empty($value)) { 
    90                     $value = str_replace("\n","",$value); 
    91                     $value = str_replace("\r","",$value); 
    92                     $keyword_list = explode(",",$value); 
    93                     sort($keyword_list); 
    94                     if (sizeof($keyword_list) > 0) { 
    95                         foreach($keyword_list as $key => $list_item) { 
    96                             $t = new StdClass; 
    97                             $t->tagtype = 'file'; 
    98                             $t->access = $access; 
    99                             $t->tag = trim($list_item); 
    100                             $t->ref = $file_id; 
    101                             $t->owner = $page_owner; 
    102                             insert_record('tags',$t); 
    103                         } 
    104                     } 
    105                 } 
     73                insert_tags_from_string ($value, 'file', $file_id, $access, $page_owner); 
    10674                $metadata = optional_param('metadata'); 
    10775                if (is_array($metadata)) { 
     
    144112                delete_records('tags','tagtype','file','ref',$f->ident); 
    145113                $file_keywords = trim(optional_param('edit_file_keywords')); 
    146                 if (!empty($file_keywords)) { 
    147                     $value = $file_keywords; 
    148                     $value = str_replace("\n","",$value); 
    149                     $value = str_replace("\r","",$value); 
    150                     $keyword_list = explode(",",$value); 
    151                     sort($keyword_list); 
    152                     if (sizeof($keyword_list) > 0) { 
    153                         foreach($keyword_list as $key => $list_item) { 
    154                             $t = new StdClass; 
    155                             $t->tagtype = 'file'; 
    156                             $t->access = $f->access; 
    157                             $t->tag = trim($list_item); 
    158                             $t->ref = $f->ident; 
    159                             $t->owner = $USER->ident; 
    160                             insert_record('tags',$t); 
    161                         } 
    162                     } 
    163                 } 
     114                insert_tags_from_string ($file_keywords, 'file', $f->ident, $f->access, $USER->ident); 
    164115                $redirect_url = url . $files_username . "/files/"; 
    165116                if ($file_folder != -1) { 
     
    179130        $f->ident = optional_param('edit_folder_id',0,PARAM_INT); 
    180131        $f->name = trim(optional_param('edit_folder_name')); 
    181         $f->access = trim(optional_param('edit_folder_group')); 
     132        $f->access = trim(optional_param('edit_folder_access')); 
    182133        $f->parent = optional_param('edit_folder_parent',0,PARAM_INT); 
    183134        if (!empty($f->ident) && !empty($f->name) && !empty($f->access) && !empty($f->parent)) { 
    184             $edit_owner = get_field('file_folders','owner','ident',$edit_folder_id); 
     135            $edit_owner = get_field('file_folders','owner','ident',$f->ident); 
    185136            if (run("permissions:check", array("files:edit",$edit_owner))) { 
    186137                if ($f->ident != $f->parent) { 
     
    188139                    delete_records('tags','tagtype','folder','ref',$f->ident); 
    189140                    $edit_value = trim(optional_param('edit_folder_keywords')); 
    190                     if (!empty($edit_value)) { 
    191                         $edit_value = str_replace("\n","",$edit_value); 
    192                         $edit_value = str_replace("\r","",$edit_value); 
    193                         $edit_keyword_list = explode(",",$edit_value); 
    194                         sort($edit_keyword_list); 
    195                         if (sizeof($edit_keyword_list) > 0) { 
    196                             foreach($edit_keyword_list as $key => $list_item) { 
    197                                 $t = new StdClass; 
    198                                 $t->tagtype = 'folder'; 
    199                                 $t->access = $f->access; 
    200                                 $t->tag = trim($list_item); 
    201                                 $t->ref = $f->ident; 
    202                                 $f->owner = $USER->ident; 
    203                                 insert_record('tags',$t); 
    204                             } 
    205                         } 
    206                     } 
     141                    insert_tags_from_string ($edit_value, 'folder', $f->ident, $f->access, $USER->ident); 
    207142                    $messages[] = gettext("The folder was edited."); 
    208143                } else { 
  • devel/units/magpie/function_update.php

    r269 r333  
    112112                                $id = insert_record('weblog_posts',$wp); 
    113113                                $tags = trim($weblog->autopost_tag); 
    114                                 if ($tags != "") { 
    115                                     $tags = explode(",",$tags); 
    116                                     foreach($tags as $tag) { 
    117                                         $tag = trim($tag); 
    118                                         if ($tag != "") { 
    119                                             $tag = $tag; 
    120                                             $t = new StdClass; 
    121                                             $t->tag = $tag; 
    122                                             $t->tagtype = 'weblog'; 
    123                                             $t->ref = $id; 
    124                                             $t->access = 'PUBLIC'; 
    125                                             $t->owner = $weblog_user_id; 
    126                                             insert_record('tags',$t); 
    127                                         } 
    128                                     } 
    129                                 } 
     114                                insert_tags_from_string ($tags, 'weblog', $id, 'PUBLIC', $weblog_user_id); 
    130115                                $rssresult = run("weblogs:rss:publish", array($weblog->user_id, false)); 
    131116                                $rssresult = run("profile:rss:publish", array($weblog->user_id, false)); 
  • devel/units/profile/function_actions.php

    r330 r333  
    33 
    44global $page_owner; 
     5$page_owner = (int) $page_owner; 
    56 
    67if (isset($_POST['action']) && $_POST['action'] == "profile:edit" && logged_on && run("permissions:check", "profile")) { 
     
    1213             
    1314            $field = addslashes($field); 
    14             foreach($data['profile:details'] as $datatype) { 
    15                 if ($datatype[1] == $field && $datatype[2] == "keywords") { 
    16                     delete_records('tags',"tagtype='$field'",'owner',$owner); 
    17                 } 
    18             } 
    19              
     15            $value = trim($value); 
     16 
    2017            if ($value != "") { 
    2118                //TODO get rid of variable duplication here. (Penny) 
    2219                $value = addslashes($value); 
    23                 $field = addslashes($field); 
     20                //$field = addslashes($field); 
    2421                $access = trim($_POST['profileaccess'][$field]); 
    2522                $owner = (int) $page_owner; 
     
    2926                $pd->value = $value; 
    3027                $pd->access = $access; 
    31                 $pd->owner = $owner; 
     28                $pd->owner = $page_owner; 
    3229                $insert_id = insert_record('profile_data',$pd); 
    3330                 
    3431                foreach($data['profile:details'] as $datatype) { 
    3532                    if ($datatype[1] == $field && $datatype[2] == "keywords") { 
    36                         $keywords = ""; 
    37                         $value = str_replace("\n","",$value); 
    38                         $value = str_replace("\r","",$value); 
    39                         $keyword_list = explode(",",$value); 
    40                         sort($keyword_list); 
    41                         if (sizeof($keyword_list) > 0) { 
    42                             foreach($keyword_list as $key => $list_item) { 
    43                                 $list_item = trim($list_item); 
    44                                 if ($list_item) { 
    45                                     if ($key > 0) { 
    46                                         $keywords .= ", "; 
    47                                     } 
    48                                     $keywords .= $list_item; 
    49                                     $t = new StdClass; 
    50                                     $t->tagtype = $field; 
    51                                     $t->access = $access; 
    52                                     $t->tag = $list_item; 
    53                                     $t->ref = $insert_id; 
    54                                     $t->owner = $owner; 
    55                                     insert_record('tags',$t); 
    56                                 } 
    57                             } 
    58                         } 
    59                         $value = $keywords; 
     33                        delete_records('tags', 'tagtype', $field, 'owner', $page_owner); 
     34                        $value = insert_tags_from_string ($value, $field, $insert_id, $access, $page_owner); 
    6035                    } 
    6136                } 
  • devel/units/weblogs/weblogs_actions.php

    r305 r333  
    1818             $insert_id = insert_record('weblog_posts',$post); 
    1919             $value = trim(optional_param('new_weblog_keywords')); 
    20              if (!empty($value)) { 
    21                  $value = str_replace("\n","",$value); 
    22                  $value = str_replace("\r","",$value); 
    23                  $keyword_list = explode(",",$value); 
    24                  sort($keyword_list); 
    25                  if (sizeof($keyword_list) > 0) { 
    26                      foreach($keyword_list as $key => $list_item) { 
    27                          $t = new StdClass; 
    28                          $t->tagtype = 'weblog'; 
    29                          $t->access = $post->access; 
    30                          $t->tag = $list_item; 
    31                          $t->ref = $insert_id; 
    32                          $t->owner = $USER->ident; 
    33                          insert_record('tags',$t); 
    34                      } 
    35                  } 
    36              } 
     20             insert_tags_from_string ($value, 'weblog', $insert_id, $post->access, $post->owner); 
     21 
    3722             $rssresult = run("weblogs:rss:publish", array($page_owner, false)); 
    3823             $rssresult = run("profile:rss:publish", array($page_owner, false)); 
     
    6550                 delete_records('tags','tagtype','weblog','ref',$post->ident); 
    6651                 $value = trim(optional_param('edit_weblog_keywords')); 
    67                  if (!empty($value)) { 
    68                      $value = str_replace("\n","",$value); 
    69                      $value = str_replace("\r","",$value); 
    70                      $keyword_list = explode(",",$value); 
    71                      sort($keyword_list); 
    72                      if (sizeof($keyword_list) > 0) { 
    73                          foreach($keyword_list as $key => $list_item) { 
    74                              $t = new StdClass; 
    75                              $t->tagtype = 'weblog'; 
    76                              $t->access = $post->access; 
    77                              $t->tag = trim($list_item); 
    78                              $t->ref = $post->ident; 
    79                              $t->owner = $oldpost->owner; 
    80                              insert_record('tags',$t); 
    81                          } 
    82                      } 
    83                  } 
    84                   
     52                 insert_tags_from_string ($value, 'weblog', $post->ident, $post->access, $oldpost->owner); 
     53 
    8554                 $rssresult = run("weblogs:rss:publish", array($page_owner, false)); 
    8655                 $rssresult = run("profile:rss:publish", array($page_owner, false));