Changeset 1332

Show
Ignore:
Timestamp:
12/03/07 21:27:44 (1 year ago)
Author:
dramirez
Message:

Blogs: Added the assign_field configuration option (#184). Bugfix: You can add content for another user(#186). Added one extension point to put a custom text when there is no posts available.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/mod/blog/README

    r1251 r1332  
    1111  'blog/lib/weblogs_init.php'. 
    1212 
     13$CFG->assign_field (default value: false) 
     14        To configure if you want to show a select box that allows you assign a content to any 
     15        of your grups 
     16         
    1317Extension points 
    1418================ 
     
    4650  Know implementations: 
    4751 
     52weblog:nocontent:description 
     53        File(s): 
     54                - blog/lib/weblogs_view.php 
     55        Action: 
     56                Allows to add a customized description for empty contents page 
     57                Receive the contextExtension as parameter 
     58        Know implementations: 
     59         
     60         
    4861Visualization 
    4962------------- 
  • devel/mod/blog/default_template.php

    r1278 r1332  
    44    global $template_definition; 
    55 
    6     $template_definition[] = array( 
    7         'id' => 'weblogpost', 
    8         'name' => __gettext("Weblog Post"), 
    9         'description' => __gettext("A template for each weblog post."), 
    10         'glossary' => array( 
    11             '{{title}}' => __gettext('Post title'), 
    12             '{{body}}' => __gettext('The text of the post'), 
    13             '{{username}}' => __gettext('The username of the person making the post'), 
    14             '{{usericon}}' => __gettext('Their user icon'), 
    15             '{{fullname}}' => __gettext('Their full name'), 
    16             '{{date}}' => __gettext('The time and date of the post'), 
    17             '{{commentslink}}' => __gettext('A link to any comments'), 
    18             '{{links}}' => __gettext('Any more links'), 
    19             '{{comments}}' => __gettext('A list of comments, if any'), 
    20             '{{postedby}}' => __gettext("'Posted by' string") 
    21         ) 
    22     ); 
    23  
    24     $template_definition[] = array( 
    25         'id' => 'weblogcomments', 
    26         'name' => __gettext("Weblog Comments"), 
    27         'description' => __gettext("A placeholder for weblog comments."), 
    28         'glossary' => array( 
    29             '{{comments}}' => __gettext('The list of comments themselves'), 
    30             '{{paging}}' => __gettext('The list of page links when there are lots of comments'), 
    31             '{{comments_str}}' => __gettext("'Comments' string") 
    32         ) 
    33     ); 
    34  
    35     $template_definition[] = array( 
    36         'id' => 'weblogcomment', 
    37         'name' => __gettext("Individual weblog comment"), 
    38         'description' => __gettext("A template for each individual weblog comment. (Displayed one after the other, embedded in the comment placeholder.)"), 
    39         'glossary' => array( 
    40             '{{body}}' => __gettext('Post body'), 
    41             '{{postedname}}' => __gettext('The name of the person making the comment'), 
    42             '{{weblogcomment}}' => __gettext('When the comment was posted'), 
    43             '{{usericon}}' => __gettext('The usericon of the person making the comment, if available'), 
    44             '{{permalink}}' => __gettext('A permalink to the comment'), 
    45             '{{links}}' => __gettext('Any more links'), 
    46         ) 
    47     ); 
    48  
    496    templates_add_context('weblogpost', 'mod/blog/templates/blog_post.html'); 
    507    templates_add_context('weblogcomments', 'mod/blog/templates/blog_comments.html'); 
  • devel/mod/blog/everyone.php

    r1077 r1332  
    2626        $body .= '<ul>'; 
    2727        //url . $weblog_name . "/{$extensionContext}/archive 
    28         $body .= '<li><a href="'.url.$extensionContext.'/everyone/people">' . __gettext('Personal blog posts') . '</a></li>'; 
    29         $body .= '<li><a href="'.url.$extensionContext.'/everyone/communities">' . __gettext('Community blog posts') . '</a></li>'; 
    30         $body .= '<li><a href="'.url.$extensionContext.'/everyone/commented">' . __gettext('Posts with comments') . '</a></li>'; 
    31         $body .= '<li><a href="'.url.$extensionContext.'/everyone/uncommented">' . __gettext('Posts with no comments') . '</a></li>'; 
     28        $body .= '<li><a href="'.url.$extensionContext.'/everyone/people">' . __gettext("Personal blog posts") . '</a></li>'; 
     29        $body .= '<li><a href="'.url.$extensionContext.'/everyone/communities">' . __gettext("Community blog posts") . '</a></li>'; 
     30        $body .= '<li><a href="'.url.$extensionContext.'/everyone/commented">' . __gettext("Posts with comments") . '</a></li>'; 
     31        $body .= '<li><a href="'.url.$extensionContext.'/everyone/uncommented">' . __gettext("Posts with no comments") . '</a></li>'; 
    3232        $body .= '</ul>'; 
    3333 
  • devel/mod/blog/lib.php

    r1280 r1332  
    121121  global $CFG, $function; 
    122122 
     123     
     124    // Load default template 
     125        $function['init'][] = $CFG->dirroot . "mod/blog/default_template.php"; 
    123126 
    124127    // Functions to perform upon initialisation 
    125128        $function['weblogs:init'][] = $CFG->dirroot . "mod/blog/lib/weblogs_init.php"; 
    126         $function['weblogs:init'][] = $CFG->dirroot . "mod/blog/lib/weblogs_actions.php"; 
    127  
    128     // Load default template 
    129         $function['init'][] = $CFG->dirroot . "mod/blog/default_template.php"; 
     129        $function['weblogs:init'][] = $CFG->dirroot . "mod/blog/lib/weblogs_actions.php";         
    130130 
    131131    // Init for search 
     
    147147        $function['weblogs:posts:view'][] = $CFG->dirroot . "mod/blog/lib/weblogs_posts_view.php"; 
    148148 
     149    // Add assign list 
     150        $function['weblogs:assign:field'][] = $CFG->dirroot. "mod/blog/lib/weblogs_assign_field.php";  
     151         
    149152    // Put this one before the Flag content form         
    150153        $index = count($function['weblogs:posts:view:individual']); 
     
    211214  $CFG->templates->variables_substitute['blogsummary'][]= "blog_summary_keyword"; 
    212215  $CFG->templates->variables_substitute['blogexecutivesummary'][] = "blog_executive_summary_keyword"; 
     216   
    213217  // Delete users 
    214218  listen_for_event("user", "delete", "blog_user_delete"); 
    215219 
     220  // Display modules 
    216221  if (!isset ($CFG->display_field_module)) { 
    217222    $CFG->display_field_module= array (); 
     
    221226    $CFG->display_field_module["select"]= "blog"; 
    222227  } 
     228 
     229  if (!array_key_exists("select_associative", $CFG->display_field_module)) { 
     230    $CFG->display_field_module["select_associative"]= "blog"; 
     231  } 
     232 
    223233  if (!array_key_exists("selectg", $CFG->display_field_module)) { 
    224234    $CFG->display_field_module["selectg"]= "blog"; 
     
    238248    $CFG->weblog_extensions= array (); 
    239249  } 
    240   $CFG->weblog_extensions['weblog']= array (); 
     250   
     251   
     252  //$CFG->weblog_extensions['weblog']= array (); 
    241253 
    242254        // Register file river hook (if there) 
     
    248260                river_register_friendlyname_hook('weblog_post::post', 'blog_get_friendly_name'); 
    249261        } 
    250    
    251262} 
    252263 
     
    566577  break; 
    567578 
     579  case "select_associative": 
     580      $run_result = "<select name=\"" . $parameter[0] . "\" id=\"" . $cleanid . "\" />"; 
     581      foreach ($parameter[6] as $option_value => $option) { 
     582        $run_result .= "<option value=\"" . htmlspecialchars(stripslashes($option_value), ENT_COMPAT, 'utf-8') . "\" "; 
     583        if ($parameter[1] == $option_value) { 
     584          $run_result .= " selected "; 
     585        } 
     586        $run_result .= " >$option</option>"; 
     587 
     588      } 
     589      $run_result .= "</select><br>"; 
     590  break; 
    568591 
    569592  case "select": 
     
    638661    case "selectg": 
    639662    case "vertical_radio": 
     663    case "select_associative": 
    640664      $run_result .= $parameter[0]; 
    641665    break; 
  • devel/mod/blog/lib/permissions_check.php

    r1251 r1332  
    1313    // be set in run("your_unit_name:init") 
    1414     
    15         global $page_owner; 
     15        global $messages,$profile_id; 
     16         
    1617         
    1718        if ($parameter == "weblog") { 
    18             if ($page_owner == $_SESSION['userid'] && logged_on && user_info("user_type",$page_owner) != "external") { 
     19            if ($profile_id == $_SESSION['userid'] && logged_on && user_info("user_type",$profile_id) != "external") { 
    1920                $run_result = true; 
    2021            } 
    2122        } 
    22          
     23        
    2324        if (logged_on) { 
    2425            // $parameter[0] = context 
    2526            // $parameter1[1] = $post->owner 
    26             if ($parameter[0] == "weblog:edit") { 
    27                 if ($parameter[1] == $_SESSION['userid'] && logged_on && user_info("user_type",$page_owner) != "external") { 
     27            if (is_array($parameter) && $parameter[0] == "weblog:edit") { 
     28                if ($parameter[1] == $_SESSION['userid'] && logged_on && user_info("user_type",$profile_id) != "external") { 
    2829                    $run_result = true; 
    2930                } 
  • devel/mod/blog/lib/weblogs_actions.php

    r1280 r1332  
    1616        $post->icon = optional_param('new_weblog_icon',user_info("icon",$_SESSION['userid']),PARAM_INT); 
    1717        if (logged_on && !empty($post->body) && !empty($post->access) && run("permissions:check", "weblog")) { 
     18 
    1819            $post->posted = time(); 
    1920            $post->owner = $USER->ident; 
    2021            $post->weblog = $page_owner; 
     22            if(isset($CFG->assign_field) && $CFG->assign_field){ 
     23                $assigned = optional_param('assign_to',null,PARAM_INT); 
     24              if(!empty($assigned)){ 
     25                $post->weblog = $assigned; 
     26                define('redirect_url',url . user_info("username",$assigned) . "/$extensionContext/"); 
     27              }  
     28            } 
     29            else{ 
     30              define('redirect_url',url . user_info("username",$page_owner) . "/$extensionContext/");            
     31            } 
    2132 
    2233            $post = plugin_hook("weblog_post","create",$post); 
     
    3445                $rssresult = run("weblogs:rss:publish", array($page_owner, false)); 
    3546                $rssresult = run("profile:rss:publish", array($page_owner, false)); 
    36                 if (user_type($page_owner) == "person") { 
    37                     $messages[] = __gettext("Your post has been added to your weblog."); 
    38                 } 
    39             } 
    40             // define('redirect_url',url . $_SESSION['username'] . "/weblog/"); 
    41             define('redirect_url',url . user_info("username",$page_owner) . "/$extensionContext/"); 
     47                $type = "post"; 
     48                if(is_array($CFG->weblog_extensions[$extensionContext]) &&  
     49                   array_key_exists('type',$CFG->weblog_extensions[$extensionContext])){ 
     50                  $type = strtolower($CFG->weblog_extensions[$extensionContext]['type']); 
     51                } 
     52 
     53                if (user_type($post->weblog) == "person") { 
     54                    $messages[] = sprintf(__gettext("Your %s has been added."),$type); 
     55                } 
     56                else{ 
     57                    $messages[] = sprintf(__gettext("Your %s has been added to the %s group."),$type,user_info("name",$post->weblog));                   
     58                } 
     59            } 
    4260        } else { 
    4361            $messages[] = __gettext("Your post wasn't added to the blog. This was probably because it was empty, or you don't currently have permission to post in this blog."); 
  • devel/mod/blog/lib/weblogs_all_users_view.php

    r1077 r1332  
    5454} 
    5555 
    56 $removefilter = ' (<a href="' . url . $extensionContext.'/everyone/skip/' . $weblog_offset . '">' . __gettext('Remove filter') . '</a>)'; 
     56$removefilter = ' (<a href="' . url . $extensionContext.'/everyone/skip/' . $weblog_offset . '">' . __gettext("Remove filter") . '</a>)'; 
    5757 
    5858switch ($view_filter) { 
    5959    case "people": 
    6060        $where1 = '(' . $where1 . ') AND owner = weblog'; 
    61         $run_result .= '<p>' . __gettext('Filtered: Showing personal blog posts') . $removefilter . '</p>'; 
     61        $run_result .= '<p>' . __gettext("Filtered: Showing personal blog posts") . $removefilter . '</p>'; 
    6262        break; 
    6363    case "communities": 
    6464        $where1 = '(' . $where1 . ') AND owner != weblog'; 
    65         $run_result .= '<p>' . __gettext('Filtered: Showing community blog posts') . $removefilter . '</p>'; 
     65        $run_result .= '<p>' . __gettext("Filtered: Showing community blog posts") . $removefilter . '</p>'; 
    6666        break; 
    6767    case "commented": 
    6868        //a join would be better, but doesn't work with users:access_level_sql_where anyway - sven 
    6969        $where1 = '(' . $where1 . ') AND (SELECT COUNT(ident) FROM ' . $CFG->prefix . 'weblog_comments WHERE post_id = ' . $CFG->prefix . 'weblog_posts.ident) > 0'; 
    70         $run_result .= '<p>' . __gettext('Filtered: Showing posts with comments') . $removefilter . '</p>'; 
     70        $run_result .= '<p>' . __gettext("Filtered: Showing posts with comments") . $removefilter . '</p>'; 
    7171        break; 
    7272    case "uncommented": 
    7373        $where1 = '(' . $where1 . ') AND (SELECT COUNT(ident) FROM ' . $CFG->prefix . 'weblog_comments WHERE post_id = ' . $CFG->prefix . 'weblog_posts.ident) = 0'; 
    74         $run_result .= '<p>' . __gettext('Filtered: Showing posts with no comments') . $removefilter . '</p>'; 
     74        $run_result .= '<p>' . __gettext("Filtered: Showing posts with no comments") . $removefilter . '</p>'; 
    7575        break; 
    7676    case "date": 
     
    8787                $where1 = '(' . $where1 . ') AND (posted BETWEEN ' . $start . ' AND ' . $end . ')'; 
    8888                $nicedate = gmstrftime("%B %d, %Y", $start); 
    89                 $run_result .= '<p>' . __gettext('Filtered: Showing posts from ') . $nicedate . $removefilter . '</p>'; 
     89                $run_result .= '<p>' . __gettext("Filtered: Showing posts from ") . $nicedate . $removefilter . '</p>'; 
    9090                $view_filter = 'date'; 
    9191            } 
     
    9797            $html_filter_value = htmlspecialchars($view_filter_value); 
    9898            $where1 = '(' . $where1 . ') AND ident IN (SELECT ref FROM ' . $CFG->prefix . 'tags WHERE tag =' . $sql_filter_value . ' AND tagtype = "weblog")'; 
    99             $run_result .= '<p>' . __gettext('Filtered: Showing posts tagged with ') . '"' . $html_filter_value . '"' . $removefilter . '</p>'; 
     99            $run_result .= '<p>' . __gettext("Filtered: Showing posts tagged with ") . '"' . $html_filter_value . '"' . $removefilter . '</p>'; 
    100100        } 
    101101        break; 
  • devel/mod/blog/lib/weblogs_posts_add.php

    r1280 r1332  
    22 
    33    global $page_owner; 
     4    global $profile_id; 
    45    global $CFG; 
     6    global $messages; 
    57 
    68    if (logged_on) { 
    79 
    810 
    9     if (!run("permissions:check", "weblog")) { 
     11   if (!run("permissions:check", "weblog")) { 
    1012        if (logged_on) { 
    1113            $page_owner = $_SESSION['userid']; 
     
    1315            $page_owner = -1; 
    1416        } 
     17    } 
     18    //Getting the field from the context extension 
     19    $extensionContext = trim(optional_param('extension','weblog')); 
     20 
     21    if (!run("permissions:check", array("weblog:edit",$profile_id))) { 
     22      $messages[] = __gettext("Permission denied"); 
     23      $messages[] = __gettext("You can modify only your own content!"); 
     24      $redirect_url = url . user_info('username', $_SESSION['userid']) . "/$extensionContext/"; 
     25      $_SESSION['messages'] = $messages; 
     26      header("Location: " . $redirect_url); 
     27      exit; 
     28    } 
     29 
     30    $contentType = __gettext("Post"); 
     31    if(array_key_exists($extensionContext,$CFG->weblog_extensions)){ 
     32      $contentType = (array_key_exists('type',$CFG->weblog_extensions[$extensionContext])) ? $CFG->weblog_extensions[$extensionContext]['type'] : $contentType; 
     33      $extraField = (array_key_exists('field',$CFG->weblog_extensions[$extensionContext])) ? $CFG->weblog_extensions[$extensionContext]['field'] : ''; 
     34      $extraValue = (array_key_exists('values',$CFG->weblog_extensions[$extensionContext])) ? $CFG->weblog_extensions[$extensionContext]['values'] : ''; 
    1535    } 
    1636 
     
    2141 
    2242    $username = $_SESSION['username']; 
    23     $addPost = __gettext("Add a new post"); // gettext variable 
    24     $postTitle = __gettext("Post title:"); // gettext variable 
    25     $postBody = __gettext("Post body:"); // gettext variable 
    26     $Keywords = __gettext("Keywords (Separated by commas):"); // gettext variable 
    27     $keywordDesc = __gettext("Keywords commonly referred to as 'Tags' are words that represent the weblog post you have just made. This will make it easier for others to search and find your posting."); // gettext variable 
     43    $addPost = sprintf(__gettext("Add a new %s"),$contentType); 
     44    $postTitle = sprintf(__gettext("%s title:"),$contentType); 
     45    $postBody = sprintf(__gettext("%s body:"),$contentType);  
     46    $Keywords = __gettext("Keywords (Separated by commas):");  
     47    $keywordDesc = __gettext("Keywords commonly referred to as 'Tags' are words that represent the weblog post you have just made. This will make it easier for others to search and find your posting.");  
    2848    $accessRes = __gettext("Access restrictions:"); // gettext variable 
    29     $postButton = __gettext("Post"); // gettext variable 
     49    $postButton = __gettext("Publish"); // gettext variable 
    3050 
    31     //Getting the field from the context extension 
    32     $extensionContext = trim(optional_param('extension','weblog')); 
    3351 
    34     if(array_key_exists($extensionContext,$CFG->weblog_extensions)){ 
    35       $extraField = (isset($CFG->weblog_extensions[$extensionContext]['field'])) ? $CFG->weblog_extensions[$extensionContext]['field'] : ''; 
    36       $extraValue = (isset($CFG->weblog_extensions[$extensionContext]['values'])) ? $CFG->weblog_extensions[$extensionContext]['values'] : ''; 
    37     } 
    3852 
    3953    $body = <<< END 
     
    4458 
    4559END; 
    46  
     60     
     61    if(isset($CFG->assign_field) && $CFG->assign_field){ 
     62      $body .= run("weblogs:assign:field"); 
     63    } 
     64                            
    4765    $body .= templates_draw(array( 
    4866                                'context' => 'databoxvertical', 
  • devel/mod/blog/lib/weblogs_posts_edit.php

    r1280 r1332  
    1010$username = user_info('username', $post->weblog); 
    1111 
    12 if (!run("permissions:check", array("weblog:edit",$post->owner))) { 
    13     exit(__gettext("Access Denied")); 
    14 } 
    15  
    16 $editPost = __gettext("Edit a post"); 
    17 $postTitle = __gettext("Post title:"); 
    18 $postBody = __gettext("Post body:"); 
    19 $Keywords = __gettext("Keywords (Separated by commas):"); // gettext variable 
    20 $keywordDesc = __gettext("Keywords commonly referred to as 'Tags' are words that represent the weblog post you have just made. This will make it easier for others to search and find your posting."); // gettext variable 
    21 $accessRes = __gettext("Access restrictions:"); // gettext variable 
    22 $postButton = __gettext("Save Post"); // gettext 
    23  
    2412//Getting the field from the context extension 
    2513$extensionContext = trim(optional_param('extension','weblog')); 
    2614 
    27 if(array_key_exists($extensionContext,$CFG->weblog_extensions)){ 
    28   $extraType  = (isset($CFG->weblog_extensions[$extensionContext]['type'])) ? $CFG->weblog_extensions[$extensionContext]['type'] : ''; 
    29   $extraField = (isset($CFG->weblog_extensions[$extensionContext]['field'])) ? $CFG->weblog_extensions[$extensionContext]['field'] : ''; 
    30   $extraValue = (isset($CFG->weblog_extensions[$extensionContext]['values'])) ? $CFG->weblog_extensions[$extensionContext]['values'] : ''; 
     15if (!($aver=run("permissions:check", array("weblog:edit",$post->owner)))) { 
     16    $messages[] = __gettext("Permission denied"); 
     17    $messages[] = __gettext("You can modify only your own content!"); 
     18    $redirect_url = url . user_info('username', $_SESSION['userid']) . "/$extensionContext/"; 
     19    $_SESSION['messages'] = $messages; 
     20    header("Location: " . $redirect_url); 
     21
     22 
     23 
     24$contentType = __gettext("Post"); 
     25if(is_array($CFG->weblog_extensions) && array_key_exists($extensionContext,$CFG->weblog_extensions) && is_array($CFG->weblog_extensions[$extensionContext])){ 
     26 echo "DENTRO"; 
     27  $contentType  = (array_key_exists('type',$CFG->weblog_extensions[$extensionContext])) ? $CFG->weblog_extensions[$extensionContext]['type'] : $contentType; 
     28  $extraType  = (array_key_exists('type',$CFG->weblog_extensions[$extensionContext])) ? $CFG->weblog_extensions[$extensionContext]['type'] : ''; 
     29  $extraField = (array_key_exists('field',$CFG->weblog_extensions[$extensionContext])) ? $CFG->weblog_extensions[$extensionContext]['field'] : ''; 
     30  $extraValue = (array_key_exists('values',$CFG->weblog_extensions[$extensionContext])) ? $CFG->weblog_extensions[$extensionContext]['values'] : ''; 
    3131  if(array_key_exists('extra_type',$CFG->weblog_extensions[$extensionContext])){ 
    3232    $extraTypes = $CFG->weblog_extensions[$extensionContext]['extra_type']; 
     
    5454  } 
    5555} 
     56else{ 
     57  if($tags = get_records_select('tags','tagtype= ? and ref = ?',array('weblog',$post->ident),'ident ASC')){ 
     58    $first = true; 
     59    foreach($tags as $key => $tag){ 
     60       if (empty($first)) { 
     61          $keywords .= ", "; 
     62       } 
     63       $keywords .= stripslashes($tag->tag); 
     64       $first = false; 
     65    } 
     66  } 
     67} 
     68 
     69$editPost = sprintf(__gettext("Edit a %s"),$contentType); 
     70$postTitle = sprintf(__gettext("%s title:"),$contentType); 
     71$postBody = sprintf(__gettext("%s body:"),$contentType); 
     72$Keywords = __gettext("Keywords (Separated by commas):");  
     73$keywordDesc = __gettext("Keywords commonly referred to as 'Tags' are words that represent the weblog post you have just made. This will make it easier for others to search and find your posting."); 
     74$accessRes = __gettext("Access restrictions:"); // gettext variable 
     75$postButton = __gettext("Publish"); 
    5676 
    5777 
     
    108128                                'name' => $Keywords, 
    109129                                'column1' => "<i>$keywordDesc</i>", 
    110                                 'column2' => display_input_field(array("edit_weblog_keywords","","keywords","weblog")) 
     130                                'column2' => display_input_field(array("edit_weblog_keywords","","keywords","weblog",$post->ident)) 
    111131                            ) 
    112132                            ); 
  • devel/mod/blog/lib/weblogs_view.php

    r1077 r1332  
    109109else{ 
    110110  $type =(isset($extraType))?$extraType:$extensionContext; 
    111   $run_result = "<p>".sprintf(__gettext("You currently don't have any %s"), strtolower($type))."</p>"; 
     111  $emptyText = "<p>".sprintf(__gettext("You currently don't have any %s"), strtolower($type))."</p>"; 
     112  $empty = run("weblog:nocontent:description",$type); 
     113  $emptyText = (empty($empty))?$emptyText:$empty; 
     114  $run_result = $emptyText; 
    112115} 
    113116?>