use an adapter pattern to customize notice list item output
This commit is contained in:
		@@ -281,6 +281,32 @@ abstract class MicroAppPlugin extends Plugin
 | 
				
			|||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $adapter = $this->adaptNoticeListItem($nli);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!empty($adapter)) {
 | 
				
			||||||
 | 
					            $adapter->show();
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            $this->oldShowNotice($nli);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Given a notice list item, returns an adapter specific
 | 
				
			||||||
 | 
					     * to this plugin.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param NoticeListItem $nli item to adapt
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return NoticeListItemAdapter adapter or null
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    function adaptNoticeListItem($nli)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    function oldShowNotice($nli)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        $out = $nli->out;
 | 
					        $out = $nli->out;
 | 
				
			||||||
        $notice = $nli->notice;
 | 
					        $notice = $nli->notice;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -303,8 +329,6 @@ abstract class MicroAppPlugin extends Plugin
 | 
				
			|||||||
        $out->elementEnd('div');
 | 
					        $out->elementEnd('div');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $nli->showNoticeOptions();
 | 
					        $nli->showNoticeOptions();
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -535,4 +559,21 @@ abstract class MicroAppPlugin extends Plugin
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Custom HTML output for your special notice; called when a
 | 
				
			||||||
 | 
					     * matching notice turns up in a NoticeListItem.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * All micro-app classes must override this method.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param Notice $notice
 | 
				
			||||||
 | 
					     * @param HTMLOutputter $out
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @fixme WARNING WARNING WARNING base plugin stuff below tries to close
 | 
				
			||||||
 | 
					     * a div that this function opens in the BookmarkPlugin child class.
 | 
				
			||||||
 | 
					     * This is probably wrong.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    abstract function showNotice($notice, $out);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										75
									
								
								lib/noticelistitemadapter.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								lib/noticelistitemadapter.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,75 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * StatusNet - the distributed open-source microblogging tool
 | 
				
			||||||
 | 
					 * Copyright (C) 2011, StatusNet, Inc.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For use by microapps to customize notice list item output
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * PHP version 5
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					 * it under the terms of the GNU Affero General Public License as published by
 | 
				
			||||||
 | 
					 * the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					 * (at your option) any later version.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This program is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					 * GNU Affero General Public License for more details.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * You should have received a copy of the GNU Affero General Public License
 | 
				
			||||||
 | 
					 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @category  Microapp
 | 
				
			||||||
 | 
					 * @package   StatusNet
 | 
				
			||||||
 | 
					 * @author    Evan Prodromou <evan@status.net>
 | 
				
			||||||
 | 
					 * @copyright 2011 StatusNet, Inc.
 | 
				
			||||||
 | 
					 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
 | 
				
			||||||
 | 
					 * @link      http://status.net/
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if (!defined('STATUSNET')) {
 | 
				
			||||||
 | 
					    // This check helps protect against security problems;
 | 
				
			||||||
 | 
					    // your code file can't be executed directly from the web.
 | 
				
			||||||
 | 
					    exit(1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * For use by microapps to customize NoticeListItem output
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @category  Microapp
 | 
				
			||||||
 | 
					 * @package   StatusNet
 | 
				
			||||||
 | 
					 * @author    Evan Prodromou <evan@status.net>
 | 
				
			||||||
 | 
					 * @copyright 2011 StatusNet, Inc.
 | 
				
			||||||
 | 
					 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
 | 
				
			||||||
 | 
					 * @link      http://status.net/
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class NoticeListItemAdapter
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    protected $nli;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Wrap a notice list item.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param NoticeListItem $nli item to wrap
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    function __construct($nli)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->nli = $nli;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Delegate unimplemented methods to the notice list item attribute.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param string $name      Name of the method
 | 
				
			||||||
 | 
					     * @param array  $arguments Arguments called
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return mixed Return value of the method.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    function __call($name, $arguments)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return call_user_func_array(array($this->nli, $name), $arguments);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user