/** * Get next object in list */ function &get_next() { $Comment =& parent::get_next(); if (empty($Comment)) { $r = false; return $r; } return $Comment; }
/** * If the list is sorted by category... * * Note: this only supports one level of categories (nested cats will be flatened) */ function &get_category_group() { global $row; if (empty($this->current_Obj)) { // Very first call // Do a normal get_next() parent::get_next(); } if (empty($this->current_Obj)) { // We have reached the end of the list return $this->current_Obj; } $this->group_by_cat = 1; // Memorize main cat $this->main_cat_ID = $this->current_Obj->main_cat_ID; return $this->current_Obj; }
/** * Display the widget! * * @param array MUST contain at least the basic display params */ function display($params) { global $localtimenow; $this->init_display($params); if ($this->disp_params['order_by'] == 'RAND' && isset($this->BlockCache)) { // Do NOT cache if display order is random $this->BlockCache->abort_collect(); } global $Blog; $list_blogs = $this->disp_params['blog_ID'] ? $this->disp_params['blog_ID'] : $Blog->ID; //pre_dump( $list_blogs ); // Display photos: // TODO: permissions, complete statuses... // TODO: A FileList object based on ItemListLight but adding File data into the query? // overriding ItemListLigth::query() for starters ;) $FileCache =& get_FileCache(); $FileList = new DataObjectList2($FileCache); // Query list of files: $SQL = new SQL(); $SQL->SELECT('post_ID, post_datestart, post_datemodified, post_main_cat_ID, post_urltitle, post_canonical_slug_ID, post_tiny_slug_ID, post_ptyp_ID, post_title, post_excerpt, post_url, file_ID, file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc'); $SQL->FROM('T_categories INNER JOIN T_postcats ON cat_ID = postcat_cat_ID INNER JOIN T_items__item ON postcat_post_ID = post_ID INNER JOIN T_links ON post_ID = link_itm_ID INNER JOIN T_files ON link_file_ID = file_ID'); $SQL->WHERE('cat_blog_ID IN (' . $list_blogs . ')'); // fp> TODO: want to restrict on images :] $SQL->WHERE_and('post_status = "published"'); // TODO: this is a dirty hack. More should be shown. $SQL->WHERE_and('post_datestart <= \'' . remove_seconds($localtimenow) . '\''); if (!empty($this->disp_params['item_type'])) { // Get items only with specified type $SQL->WHERE_and('post_ptyp_ID = ' . intval($this->disp_params['item_type'])); } $SQL->GROUP_BY('link_ID'); $SQL->LIMIT($this->disp_params['limit'] * 4); // fp> TODO: because we have no way of getting images only, we get 4 times more data than requested and hope that 25% at least will be images :/ $SQL->ORDER_BY(gen_order_clause($this->disp_params['order_by'], $this->disp_params['order_dir'], 'post_', 'post_ID ' . $this->disp_params['order_dir'] . ', link_ID')); $FileList->sql = $SQL->get(); $FileList->query(false, false, false, 'Media index widget'); $layout = $this->disp_params['thumb_layout']; $nb_cols = $this->disp_params['grid_nb_cols']; $count = 0; $r = ''; /** * @var File */ while ($File =& $FileList->get_next()) { if ($count >= $this->disp_params['limit']) { // We have enough images already! break; } if (!$File->is_image()) { // Skip anything that is not an image // fp> TODO: maybe this property should be stored in link_ltype_ID or in the files table continue; } if ($layout == 'grid') { if ($count % $nb_cols == 0) { $r .= $this->disp_params['grid_colstart']; } $r .= $this->disp_params['grid_cellstart']; } else { $r .= $this->disp_params['item_start']; } // 1/ Hack a dirty permalink( will redirect to canonical): // $link = url_add_param( $Blog->get('url'), 'p='.$post_ID ); // 2/ Hack a link to the right "page". Very daring!! // $link = url_add_param( $Blog->get('url'), 'paged='.$count ); // 3/ Instantiate a light object in order to get permamnent url: $ItemLight = new ItemLight($FileList->get_row_by_idx($FileList->current_idx - 1)); // index had already been incremented $r .= '<a href="' . $ItemLight->get_permanent_url() . '">'; // Generate the IMG THUMBNAIL tag with all the alt, title and desc if available $r .= $File->get_thumb_imgtag($this->disp_params['thumb_size'], '', '', $ItemLight->title); $r .= '</a>'; if ($this->disp_params['disp_image_title']) { $title = $File->get('title') ? $this->get('title') : $ItemLight->title; $r .= '<span class="note">' . $title . '</span>'; } ++$count; if ($layout == 'grid') { $r .= $this->disp_params['grid_cellend']; if ($count % $nb_cols == 0) { $r .= $this->disp_params['grid_colend']; } } else { $r .= $this->disp_params['item_end']; } } // Exit if no files found if (empty($r)) { return; } echo $this->disp_params['block_start']; // Display title if requested $this->disp_title(); if ($layout == 'grid') { echo $this->disp_params['grid_start']; } else { echo $this->disp_params['list_start']; } echo $r; if ($layout == 'grid') { if ($count && $count % $nb_cols != 0) { echo $this->disp_params['grid_colend']; } echo $this->disp_params['grid_end']; } else { echo $this->disp_params['list_end']; } echo $this->disp_params['block_end']; return true; }
/** * If the list is sorted by category... * * This is basically just a stub for backward compatibility */ function &get_Comment() { $Comment =& parent::get_next(); if (empty($Comment)) { $r = false; return $r; } //pre_dump( $Comment ); return $Comment; }
/** * Display the widget! * * @param array MUST contain at least the basic display params */ function display($params) { $this->init_display($params); $UserCache =& get_UserCache(); $UserList = new DataObjectList2($UserCache); switch ($this->disp_params['order_by']) { case 'regdate': $sql_order = 'user_created_datetime DESC'; break; case 'moddate': $sql_order = 'user_profileupdate_date DESC'; break; case 'random': default: $sql_order = 'RAND()'; break; } // Query list of files: $SQL = new SQL(); $SQL->SELECT('*'); $SQL->FROM('T_users'); $SQL->WHERE('user_avatar_file_ID IS NOT NULL'); $SQL->ORDER_BY($sql_order); $SQL->LIMIT($this->disp_params['limit']); $UserList->sql = $SQL->get(); $UserList->query(false, false, false, 'User avatars widget'); $layout = $this->disp_params['thumb_layout']; $nb_cols = $this->disp_params['grid_nb_cols']; $count = 0; $r = ''; /** * @var User */ while ($User =& $UserList->get_next()) { if ($layout == 'grid') { if ($count % $nb_cols == 0) { $r .= $this->disp_params['grid_colstart']; } $r .= $this->disp_params['grid_cellstart']; } else { $r .= $this->disp_params['item_start']; } $identity_url = get_user_identity_url($User->ID); $avatar_tag = $User->get_avatar_imgtag($this->disp_params['thumb_size']); if ($this->disp_params['bubbletip'] == '1') { // Bubbletip is enabled $bubbletip_param = ' rel="bubbletip_user_' . $User->ID . '"'; $avatar_tag = str_replace('<img ', '<img ' . $bubbletip_param . ' ', $avatar_tag); } if (!empty($identity_url)) { $r .= '<a href="' . $identity_url . '">' . $avatar_tag . '</a>'; } else { $r .= $avatar_tag; } ++$count; if ($layout == 'grid') { $r .= $this->disp_params['grid_cellend']; if ($count % $nb_cols == 0) { $r .= $this->disp_params['grid_colend']; } } else { $r .= $this->disp_params['item_end']; } } // Exit if no files found if (empty($r)) { return; } echo $this->disp_params['block_start']; // Display title if requested $this->disp_title(); if ($layout == 'grid') { echo $this->disp_params['grid_start']; } else { echo $this->disp_params['list_start']; } echo $r; if ($layout == 'grid') { if ($count && $count % $nb_cols != 0) { echo $this->disp_params['grid_colend']; } echo $this->disp_params['grid_end']; } else { echo $this->disp_params['list_end']; } echo $this->disp_params['block_end']; return true; }
/** * Display the widget! * * @param array MUST contain at least the basic display params */ function display($params) { $this->init_display($params); $UserCache =& get_UserCache(); $UserList = new DataObjectList2($UserCache); switch ($this->disp_params['order_by']) { case 'regdate': $sql_order = 'user_created_datetime DESC'; break; case 'moddate': $sql_order = 'user_profileupdate_date DESC'; break; case 'random': default: $sql_order = 'RAND()'; break; } // Query list of users with picture and not closed: $SQL = new SQL(); $SQL->SELECT('*'); $SQL->FROM('T_users'); $SQL->WHERE('user_avatar_file_ID IS NOT NULL'); $SQL->WHERE_and('user_status <> "closed"'); if (is_logged_in()) { // Add filters global $current_User, $DB; switch ($this->disp_params['gender']) { // Filter by gender case 'same': $SQL->WHERE_and('user_gender = "' . $current_User->gender . '"'); break; case 'opposite': $SQL->WHERE_and('user_gender != "' . $current_User->gender . '"'); break; } switch ($this->disp_params['location']) { // Filter by location case 'city': $SQL->WHERE_and('user_city_ID ' . (empty($current_User->city_ID) ? 'IS NULL' : '= "' . $current_User->city_ID . '"')); case 'subregion': $SQL->WHERE_and('user_subrg_ID ' . (empty($current_User->subrg_ID) ? 'IS NULL' : '= "' . $current_User->subrg_ID . '"')); case 'region': $SQL->WHERE_and('user_rgn_ID ' . (empty($current_User->rgn_ID) ? 'IS NULL' : '= "' . $current_User->rgn_ID . '"')); case 'country': $SQL->WHERE_and('user_ctry_ID ' . (empty($current_User->ctry_ID) ? 'IS NULL' : '= "' . $current_User->ctry_ID . '"')); break; case 'closest': if (!empty($current_User->city_ID)) { // Check if users exist with same city $user_exists = $DB->get_var('SELECT user_ID FROM T_users WHERE user_city_ID ="' . $current_User->city_ID . '" AND user_ID != "' . $current_User->ID . '" LIMIT 1'); if (!empty($user_exists)) { $SQL->WHERE_and('user_city_ID = "' . $current_User->city_ID . '"'); $SQL->WHERE_and('user_subrg_ID = "' . $current_User->subrg_ID . '"'); $SQL->WHERE_and('user_rgn_ID = "' . $current_User->rgn_ID . '"'); $SQL->WHERE_and('user_ctry_ID = "' . $current_User->ctry_ID . '"'); break; } } if (!empty($current_User->subrg_ID) && empty($user_exists)) { // Check if users exist with same sub-region $user_exists = $DB->get_var('SELECT user_ID FROM T_users WHERE user_subrg_ID ="' . $current_User->subrg_ID . '" AND user_ID != "' . $current_User->ID . '" LIMIT 1'); if (!empty($user_exists)) { $SQL->WHERE_and('user_subrg_ID = "' . $current_User->subrg_ID . '"'); $SQL->WHERE_and('user_rgn_ID = "' . $current_User->rgn_ID . '"'); $SQL->WHERE_and('user_ctry_ID = "' . $current_User->ctry_ID . '"'); break; } } if (!empty($current_User->rgn_ID) && empty($user_exists)) { // Check if users exist with same region $user_exists = $DB->get_var('SELECT user_ID FROM T_users WHERE user_rgn_ID ="' . $current_User->rgn_ID . '" AND user_ID != "' . $current_User->ID . '" LIMIT 1'); if (!empty($user_exists)) { $SQL->WHERE_and('user_rgn_ID = "' . $current_User->rgn_ID . '"'); $SQL->WHERE_and('user_ctry_ID = "' . $current_User->ctry_ID . '"'); break; } } if (!empty($current_User->ctry_ID) && empty($user_exists)) { // Check if users exist with same country $user_exists = $DB->get_var('SELECT user_ID FROM T_users WHERE user_ctry_ID ="' . $current_User->ctry_ID . '" AND user_ID != "' . $current_User->ID . '" LIMIT 1'); if (!empty($user_exists)) { $SQL->WHERE_and('user_ctry_ID = "' . $current_User->ctry_ID . '"'); } } break; } } $SQL->ORDER_BY($sql_order); $SQL->LIMIT(intval($this->disp_params['limit'])); $UserList->sql = $SQL->get(); $UserList->query(false, false, false, 'User avatars widget'); $avatar_link_attrs = ''; if ($this->disp_params['style'] == 'badges') { // Remove borders of <td> elements $this->disp_params['grid_cellstart'] = str_replace('>', ' style="border:none">', $this->disp_params['grid_cellstart']); $avatar_link_attrs = ' class="avatar_rounded"'; } $layout = $this->disp_params['thumb_layout']; $nb_cols = intval($this->disp_params['grid_nb_cols']); $count = 0; $r = ''; /** * @var User */ while ($User =& $UserList->get_next()) { if ($layout == 'grid') { // Grid layout if ($count % $nb_cols == 0) { $r .= $this->disp_params['grid_colstart']; } $r .= $this->disp_params['grid_cellstart']; } elseif ($layout == 'flow') { // Flow block layout $r .= $this->disp_params['flow_block_start']; } else { // List layout $r .= $this->disp_params['item_start']; } $identity_url = get_user_identity_url($User->ID); $avatar_tag = $User->get_avatar_imgtag($this->disp_params['thumb_size']); if ($this->disp_params['bubbletip'] == '1') { // Bubbletip is enabled $bubbletip_param = ' rel="bubbletip_user_' . $User->ID . '"'; $avatar_tag = str_replace('<img ', '<img ' . $bubbletip_param . ' ', $avatar_tag); } if (!empty($identity_url)) { $r .= '<a href="' . $identity_url . '"' . $avatar_link_attrs . '>'; $r .= $avatar_tag; if ($this->disp_params['style'] == 'badges') { // Add user login after picture $r .= '<br >' . $User->get_colored_login(); } $r .= '</a>'; } else { $r .= $avatar_tag; } ++$count; if ($layout == 'grid') { // Grid layout $r .= $this->disp_params['grid_cellend']; if ($count % $nb_cols == 0) { $r .= $this->disp_params['grid_colend']; } } elseif ($layout == 'flow') { // Flow block layout $r .= $this->disp_params['flow_block_end']; } else { // List layout $r .= $this->disp_params['item_end']; } } // Exit if no files found if (empty($r)) { return; } echo $this->disp_params['block_start']; // Display title if requested $this->disp_title(); echo $this->disp_params['block_body_start']; if ($layout == 'grid') { echo $this->disp_params['grid_start']; } elseif ($layout == 'flow') { // Flow block layout echo $this->disp_params['flow_start']; } else { echo $this->disp_params['list_start']; } echo $r; if ($layout == 'grid') { if ($count && $count % $nb_cols != 0) { echo $this->disp_params['grid_colend']; } echo $this->disp_params['grid_end']; } elseif ($layout == 'flow') { // Flow block layout echo $this->disp_params['flow_end']; } else { echo $this->disp_params['list_end']; } echo $this->disp_params['block_body_end']; echo $this->disp_params['block_end']; return true; }
/** * Display the widget! * * @param array MUST contain at least the basic display params */ function display($params) { global $localtimenow, $DB, $Blog; $this->init_display($params); $blog_ID = intval($this->disp_params['blog_ID']); if (empty($blog_ID)) { // Use current blog by default $blog_ID = $Blog->ID; } $BlogCache =& get_BlogCache(); if (!$BlogCache->get_by_ID($blog_ID, false, false)) { // No blog exists return; } // Display photos: // TODO: permissions, complete statuses... // TODO: A FileList object based on ItemListLight but adding File data into the query? // overriding ItemListLigth::query() for starters ;) // Init caches $FileCache =& get_FileCache(); $ItemCache =& get_ItemCache(); // Query list of files and posts fields: // Note: We use ItemQuery to get attachments from all posts which should be visible ( even in case of aggregate blogs ) $ItemQuery = new ItemQuery($ItemCache->dbtablename, $ItemCache->dbprefix, $ItemCache->dbIDname); $ItemQuery->SELECT('post_ID, post_datestart, post_datemodified, post_main_cat_ID, post_urltitle, post_canonical_slug_ID, post_tiny_slug_ID, post_ityp_ID, post_title, post_excerpt, post_url, file_ID, file_type, file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc, file_path_hash'); $ItemQuery->FROM_add('INNER JOIN T_links ON post_ID = link_itm_ID'); $ItemQuery->FROM_add('INNER JOIN T_files ON link_file_ID = file_ID'); $ItemQuery->where_chapter($blog_ID); if ($this->disp_params['item_visibility'] == 'public') { // Get images only of the public items $ItemQuery->where_visibility(array('published')); } else { // Get image of all available posts for current user $ItemQuery->where_visibility(NULL); } $ItemQuery->WHERE_and('( file_type = "image" ) OR ( file_type IS NULL )'); $ItemQuery->WHERE_and('post_datestart <= \'' . remove_seconds($localtimenow) . '\''); $ItemQuery->WHERE_and('link_position != "cover"'); if (!empty($this->disp_params['item_type'])) { // Get items only with specified type $ItemQuery->WHERE_and('post_ityp_ID = ' . intval($this->disp_params['item_type'])); } $ItemQuery->GROUP_BY('link_ID'); // fp> TODO: because no way of getting images only, we get 4 times more data than requested and hope that 25% at least will be images :/ // asimo> This was updated and we get images and those files where we don't know the file type yet. Now we get 2 times more data than requested. // Maybe it would be good to get only the requested amount of files, because after a very short period the file types will be set for all images. $ItemQuery->LIMIT(intval($this->disp_params['limit']) * 2); $ItemQuery->ORDER_BY(gen_order_clause($this->disp_params['order_by'], $this->disp_params['order_dir'], 'post_', 'post_ID ' . $this->disp_params['order_dir'] . ', link_ID')); // Init FileList with the above defined query $FileList = new DataObjectList2($FileCache); $FileList->sql = $ItemQuery->get(); $FileList->query(false, false, false, 'Media index widget'); $layout = $this->disp_params['thumb_layout']; $nb_cols = $this->disp_params['grid_nb_cols']; $count = 0; $r = ''; /** * @var File */ while ($File =& $FileList->get_next()) { if ($count >= $this->disp_params['limit']) { // We have enough images already! break; } if (!$File->is_image()) { // Skip anything that is not an image // Only images are selected or those files where we don't know the file type yet. // This check is only for those files where we don't know the filte type. The file type will be set during the check. continue; } if ($layout == 'grid') { // Grid layout if ($count % $nb_cols == 0) { $r .= $this->disp_params['grid_colstart']; } $r .= $this->disp_params['grid_cellstart']; } elseif ($layout == 'flow') { // Flow block layout $r .= $this->disp_params['flow_block_start']; } else { // List layout $r .= $this->disp_params['item_start']; } // 1/ Hack a dirty permalink( will redirect to canonical): // $link = url_add_param( $Blog->get('url'), 'p='.$post_ID ); // 2/ Hack a link to the right "page". Very daring!! // $link = url_add_param( $Blog->get('url'), 'paged='.$count ); // 3/ Instantiate a light object in order to get permamnent url: $ItemLight = new ItemLight($FileList->get_row_by_idx($FileList->current_idx - 1)); // index had already been incremented $r .= '<a href="' . $ItemLight->get_permanent_url() . '">'; // Generate the IMG THUMBNAIL tag with all the alt, title and desc if available $r .= $File->get_thumb_imgtag($this->disp_params['thumb_size'], '', '', $ItemLight->title); $r .= '</a>'; if ($this->disp_params['disp_image_title']) { // Dislay title of image or item $title = $File->get('title') ? $File->get('title') : $ItemLight->title; if (!empty($title)) { $r .= '<span class="note">' . $title . '</span>'; } } ++$count; if ($layout == 'grid') { // Grid layout $r .= $this->disp_params['grid_cellend']; if ($count % $nb_cols == 0) { $r .= $this->disp_params['grid_colend']; } } elseif ($layout == 'flow') { // Flow block layout $r .= $this->disp_params['flow_block_end']; } else { // List layout $r .= $this->disp_params['item_end']; } } // Exit if no files found if (empty($r)) { return; } echo $this->disp_params['block_start']; // Display title if requested $this->disp_title(); echo $this->disp_params['block_body_start']; if ($layout == 'grid') { // Grid layout echo $this->disp_params['grid_start']; } elseif ($layout == 'flow') { // Flow block layout echo $this->disp_params['flow_start']; } else { // List layout echo $this->disp_params['list_start']; } echo $r; if ($layout == 'grid') { // Grid layout if ($count && $count % $nb_cols != 0) { echo $this->disp_params['grid_colend']; } echo $this->disp_params['grid_end']; } elseif ($layout == 'flow') { // Flow block layout echo $this->disp_params['flow_end']; } else { // List layout echo $this->disp_params['list_end']; } echo $this->disp_params['block_body_end']; echo $this->disp_params['block_end']; return true; }