示例#1
0
 /**
  * @dataProvider generate_string_list_data
  */
 public function test_generate_string_list($items, $expected_result)
 {
     $result = phpbb_generate_string_list($items, $this->user);
     $this->assertEquals($expected_result, $result);
 }
示例#2
0
 /**
  * Get the HTML formatted title of this notification
  *
  * @return string
  */
 public function get_title()
 {
     $thankers = $this->get_data('thankers');
     $usernames = array();
     if (!is_array($thankers)) {
         $thankers = array();
     }
     $thankers_cnt = sizeof($thankers);
     $thankers = $this->trim_user_ary($thankers);
     $trimmed_thankers_cnt = $thankers_cnt - sizeof($thankers);
     foreach ($thankers as $thanker) {
         $usernames[] = $this->user_loader->get_username($thanker['user_id'], 'no_profile');
     }
     if ($trimmed_thankers_cnt > 20) {
         $usernames[] = $this->user->lang('NOTIFICATION_MANY_OTHERS');
     } else {
         if ($trimmed_thankers_cnt) {
             $usernames[] = $this->user->lang('NOTIFICATION_X_OTHERS', $trimmed_thankers_cnt);
         }
     }
     return $this->user->lang($this->language_key, phpbb_generate_string_list($usernames, $this->user), $thankers_cnt);
 }
示例#3
0
 /**
  * Get the HTML formatted title of this notification
  *
  * @return string
  */
 public function get_title()
 {
     $responders = $this->get_data('responders');
     $usernames = array();
     if (!is_array($responders)) {
         $responders = array();
     }
     $responders = array_merge(array(array('poster_id' => $this->get_data('poster_id'), 'username' => $this->get_data('post_username'))), $responders);
     $responders_cnt = sizeof($responders);
     $responders = $this->trim_user_ary($responders);
     $trimmed_responders_cnt = $responders_cnt - sizeof($responders);
     foreach ($responders as $responder) {
         if ($responder['username']) {
             $usernames[] = $responder['username'];
         } else {
             $usernames[] = $this->user_loader->get_username($responder['poster_id'], 'no_profile');
         }
     }
     if ($trimmed_responders_cnt > 20) {
         $usernames[] = $this->user->lang('NOTIFICATION_MANY_OTHERS');
     } else {
         if ($trimmed_responders_cnt) {
             $usernames[] = $this->user->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt);
         }
     }
     return $this->user->lang($this->language_key, phpbb_generate_string_list($usernames, $this->user), $responders_cnt);
 }
示例#4
0
 /**
 * Validate contribution settings.
 *
 * @param array $contrib_categories		Contribution categories.
 * @param array $authors					Array in the form of array('author' => array(username => user_id),
 *	'active_coauthors' => array(...), 'nonactive_coauthors' => array(...), 'missing' =>
 	array('active_coauthors' => array(username => username)).
 * @param array $custom_fields			Custom field values.
 * @param string $old_permalink			Old permalink. Defaults to empty string.
 *
 * @return array Returns array containing any errors found.
 */
 public function validate($contrib_categories = array(), $authors, $custom_fields, $old_permalink = '')
 {
     phpbb::$user->add_lang('ucp');
     $error = array();
     if (utf8_clean_string($this->contrib_name) == '') {
         $error[] = phpbb::$user->lang['EMPTY_CONTRIB_NAME'];
     }
     if (!$this->contrib_type) {
         $error[] = phpbb::$user->lang['EMPTY_CONTRIB_TYPE'];
     } else {
         // Check for a valid type
         $valid_type = false;
         foreach ($this->types->get_all() as $type_id => $class) {
             if (!$class->acl_get('submit')) {
                 continue;
             }
             if ($this->contrib_type == $type_id) {
                 $valid_type = true;
                 break;
             }
         }
         if (!$valid_type) {
             $error[] = phpbb::$user->lang['EMPTY_CONTRIB_TYPE'];
         } else {
             $this->set_type($this->contrib_type);
             $error = array_merge($error, $this->type->validate_contrib_fields($custom_fields));
             if (!$this->contrib_name_clean) {
                 // If they leave it blank automatically create it
                 $this->generate_permalink();
             }
             if (($permalink_error = $this->validate_permalink($this->contrib_name_clean, $old_permalink)) !== false) {
                 $error[] = $permalink_error;
             }
         }
         if (!$contrib_categories) {
             $error[] = phpbb::$user->lang['EMPTY_CATEGORY'];
         } else {
             $categories = titania::$cache->get_categories();
             $category = new \titania_category();
             foreach ($contrib_categories as $category_id) {
                 if (!isset($categories[$category_id])) {
                     $error[] = phpbb::$user->lang['NO_CATEGORY'];
                 } else {
                     if ($categories[$category_id]['category_type'] != $this->contrib_type) {
                         $error[] = phpbb::$user->lang['WRONG_CATEGORY'];
                     }
                 }
                 if ($valid_type) {
                     $category->__set_array($categories[$category_id]);
                     if ($category->is_option_set('team_only') && !$this->type->acl_get('moderate')) {
                         $error[] = phpbb::$user->lang['CATEGORY_NOT_ALLOWED'];
                     }
                 }
             }
         }
     }
     if (!$this->contrib_desc) {
         $error[] = phpbb::$user->lang['EMPTY_CONTRIB_DESC'];
     }
     $author = key($authors['author']);
     $missing_coauthors = array_merge($authors['missing']['active_coauthors'], $authors['missing']['nonactive_coauthors']);
     if (!empty($missing_coauthors)) {
         $error[] = phpbb::$user->lang('COULD_NOT_FIND_USERS', phpbb_generate_string_list($missing_coauthors, phpbb::$user));
     }
     $duplicates = array_intersect($authors['active_coauthors'], $authors['nonactive_coauthors']);
     if (!empty($duplicates)) {
         $error[] = phpbb::$user->lang('DUPLICATE_AUTHORS', phpbb_generate_string_list(array_keys($duplicates), phpbb::$user));
     }
     if (isset($authors['active_coauthors'][$author]) || isset($authors['nonactive_coauthors'][$author])) {
         $error[] = phpbb::$user->lang['CANNOT_ADD_SELF_COAUTHOR'];
     }
     if (!empty($authors['missing']['new_author'])) {
         $error[] = phpbb::$user->lang('CONTRIB_CHANGE_OWNER_NOT_FOUND', key($authors['missing']['new_author']));
     }
     if ($this->contrib_demo !== '') {
         $demos = json_decode($this->contrib_demo, true);
         foreach ($demos as $url) {
             if ($url !== '' && !preg_match('#^http[s]?://(.*?\\.)*?[a-z0-9\\-]{2,4}#i', $url)) {
                 $error[] = phpbb::$user->lang('FIELD_INVALID_URL', phpbb::$user->lang['CONTRIB_DEMO']);
                 break;
             }
         }
     }
     // Hooks
     titania::$hook->call_hook_ref(array(__CLASS__, __FUNCTION__), $error, $this);
     return $error;
 }