コード例 #1
0
ファイル: output.php プロジェクト: 4otaku/draw
	public function single ($query) {

		$config = Globals::user('comments', 'single_item');

		$perpage = $config['per_page'];
		$display = $config['display'];
		$inverted = $config['inverted'];

		if ($query['page'] != 'all') {			
			$page = $query['page'];
			$start = ($page - 1) * $perpage;
			$limit = " limit $start, $perpage";	
		} else {
			$limit = "";
			$page = 1;
			$start = 0;
		}
		
		$root = $display == 'ladder' ? "and root = 0" : "";		
		$direction = (bool) $inverted ? "desc" : "asc";
		
		$params = array('deleted', $query['place'], $query['item_id']);
		$condition = "area != ? and place = ? and item_id = ? $root order by date $direction $limit";

		$comments = Database::set_counter()->get_full_vector('comment', $condition, $params, false);
		
		$total = Database::get_counter();
		$current = (bool) $inverted ? $total - $start : $start;
			
		if ($display == 'ladder') {
			$roots = array_keys($comments);
			
			$condition = "area != ? and place = ? and item_id = ? and ".
				Database::array_in('root', $roots)." order by date";
			$params = array_merge($params, $roots);
			
			$children = Database::get_full_vector('comment', $condition, $params, false);
			$this->build_tree($children);
		} else {
			$children = array();
		}
		
		if ($display == 'quotation') {
			$parents = array();
			
			foreach ($comments as $comment) {
				$parents[] = $comment['parent'];
			}
			
			$condition = "area != ? and place = ? and item_id = ? and ".
				Database::array_in('id', $parents);
			$params = array_merge($params, $parents);
							
			$parents = Database::get_full_vector('comment', $condition, $params, false);
		} else {
			$parents = array();
		}		

		foreach ($comments as $id => $comment) {
			$item_children = array();
			$item_parent = null;
			
			foreach ($children as $child_id => $child) {
				if ($id == $child['root']) {				
					$item_children[$child_id] = new Item_Comment($child, $display);
				}
			}
			
			foreach ($parents as $parent_id => $parent) {
				if ($parent_id == $comment['parent']) {				
					$item_parent = new Item_Comment($parent);
				}
			}
			
			$this->items[$id] = new Item_Comment(
				array_merge(
					$comment, 
					array(
						'items' => $item_children,
						'quotation' => $item_parent,
						'index' => (bool) $inverted ? $current-- : ++$current,
					)
				),
				$display
			);
		}

		$this->items[] = new Item_Comment_Navi(array(
			'curr_page' => $page,
			'pagecount' => ceil($total / $perpage),
			'query' => $query,
			'module' => 'comments',
		));
	}
コード例 #2
0
ファイル: comment.php プロジェクト: 4otaku/draw
	public function postprocess () {

		switch ($this->flag) {
			case 'quotation':
			
				if (
					empty($this->data['quotation']) &&
					!empty($this->data['parent']) && 
					!empty($this->parent->data['items'][$this->data['parent']])
				) {
					$this->data['quotation'] = $this->parent->data['items'][$this->data['parent']];
				}
				break;
			case 'ladder':

				if (!empty($this->parent)) {

					$keys = array_keys($this->parent->data['items']);
					$local_index = array_search($this->data['id'], $keys) + 1;
					
					$this->data['index'] = $this->parent->data['index'].'.'.$local_index;
				}
			
				if (!empty($this->data['items'])) {
					if (empty($this->parent)) {
						$tree_length = 0;
						
						foreach ($this->data['items'] as $child) {
							$tree_length = max($tree_length, count($child['tree']));
						}
						
						$config = Globals::user('comments', 'single_item');
						
						if ($tree_length * $config['max_single_margin'] < $config['max_margin']) {
							$this->data['margin'] = $config['max_single_margin'];
						} else {
							$this->data['margin'] = round($config['max_margin'] / $tree_length);
						}
					}
					
					$indirect_children = array();
					
					foreach ($this->data['items'] as $id => $child) {
						if ($this->data['id'] != $child->last_of('tree')) {
							$indirect_children[$id] = $child;
							unset($this->data['items'][$id]);
						}
					}
					
					foreach ($this->data['items'] as $id => $child) {
						foreach ($indirect_children as $indirect_id => $indirect_child) {
							if (in_array($id, $indirect_child['tree'])) {
								$this->data['items'][$id]->add_to('items', $indirect_child, $indirect_id);
							}
						}
					}
				}
				break;
			default: 
				break;
		}
		
		parent::postprocess();
		
		if (!empty($this->parent) && !empty($this->parent->data['place'])) {
			$this->data['place'] = $this->parent->data['place'];
			$this->data['link'] = $this->parent['link'];
		}
	}