Forum Replies Created

Viewing 15 replies - 1 through 15 (of 26 total)
  • Thread Starter cmarshall

    (@cmarshall)

    Just FYI. I just fixed an error:

    else
    						{
    						$mypost = next ( $posts );
    						}
    					echo '</div>';
    					}
    /* THIS IS THE FIX */		echo '</div> <!-- listposts_new_posts -->';
    			$display = ob_get_contents();

    You can delete the calendar stuff. I added a filter to remove eventcalendar3 entries.

    Thread Starter cmarshall

    (@cmarshall)

    Here’s the whole kit n’ kaboodle. Open wide…

    <?php
    /*
    Plugin Name: ListPosts
    Version: 1.0
    Plugin URI: https://www.example.com
    Description: Lists new posts like the front page.. Add <!- - LIST_POSTS - -> to a page or a post to generate the form.
    Author: Example
    Author URI: https://www.exa,ple.com
    */
    function lp_get_the_password_form($id) {
    	$id = "password_$id";
    	$output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
    	<p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
    	<p><label for="'.__($id).'">' . __("Password:") . '</label> <input name="post_password" id="'.__($id).'" type="password" size="20" /> <input type="submit" name="Submit" value="' . __("Submit") . '" /></p>
    	</form>
    	';
    	return $output;
    }
    function lp_get_posts()
    {
    	global $wpdb;
    	$today = current_time('mysql', 1);
    
    	return $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 5");
    }
    
    function listposts ( $in_content )
    {
    	if ( preg_match ( "/<!-- LIST_POSTS -->/", $in_content ) )
    		{
    		$posts = lp_get_posts();
    		ob_start();
    			?><div class="listposts_new_posts">
    			<div class="listposts_header">Latest Information</div><?php
    				ec3_filter_the_posts ( $posts );
    				$mypost = current ( $posts );
    				while ( $mypost )
    					{
    					if ( !$mypost->ec3_schedule )
    						{
    						$url = get_permalink( $mypost->ID );
    						$title = htmlspecialchars( $mypost->post_title );
    						$meta = '';
    						$cats = wp_get_post_categories ( $mypost->ID );
    						foreach ( $cats as $cat )
    							{
    							if ( $meta )
    								{
    								$meta .= ", ";
    								}
    							$meta .= '<a href="' . get_category_link($cat) . '" title="' . sprintf(__("View all posts in %s"), get_the_category_by_ID($cat)) . '">'.get_the_category_by_ID($cat).'</a>';
    							}
    						ec3_filter_the_content ( $mypost->post_content );
    						$content = $mypost->post_content;
    						if ( !empty($mypost->post_password) )
    							{ // if there's a password
    							if ( stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $mypost->post_password )
    								{	// and it doesn't match the cookie
    								$content = lp_get_the_password_form($mypost->ID);
    								}
    							}
    						$content = apply_filters ( 'the_content', $content );
    						$content = str_replace(']]>', ']]>', $content);
    						$content = get_extended ( $content );
    						echo '<div class="listposts_post">';
    							echo '<div class="listposts_post_title"><a href="'.$url.'">';
    							echo $title;
    							echo '</a></div>';
    							if ( $meta )
    								{
    								echo '<div class="listposts_category_meta">Posted in '.$meta.'</div>';
    								}
    							echo '<div class="listposts_post_teaser">'.$content['main'];
    							if ( $content['extended'] )
    								{
    								echo '<div class="listposts_post_more"><a href="'.$url.'">Read More...</a></div>';
    								}
    
    							$mypost = next ( $posts );
    
    							if ( $mypost )
    								{
    								echo '<div class="post_separator"></div>';
    								}
    							echo '</div>';
    						}
    					else
    						{
    						$mypost = next ( $posts );
    						}
    					echo '</div>';
    					}
    			$display = ob_get_contents();
    		ob_end_clean();
    		$in_content = preg_replace ( "/(<p[^>]*>)*?<!-- LIST_POSTS -->(<\/p[^>]*>)/", $display, $in_content );
    		}
    
    	return $in_content;
    }
    add_filter ( 'the_content', 'listposts' );
    ?>
    Thread Starter cmarshall

    (@cmarshall)

    I meant on the WP page.

    Don’t forget that the WP page contains a direct download link, so people often don’t go to the plugin home page.

    It’s a nice plugin, and scriptalicious isn’t a bad system to have, so I won’t lose much sleep over it, but it did mean I spent a few extra minutes figuring out why it didn’t work right off the bat.

    Thread Starter cmarshall

    (@cmarshall)

    Well, I solved it, but it would have been nice to do it in a less “hacky” fashion:

    function lp_get_posts()
    {
    	global $wpdb;
    	$today = current_time('mysql', 1);
    
    	return $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 5");
    }
    
    function listposts ( $in_content )
    {
    	if ( preg_match ( "/<!-- LIST_POSTS -->/", $in_content ) )
    		{
    		$posts = lp_get_posts();
    Thread Starter cmarshall

    (@cmarshall)

    er, that’s “COOKIEHASH”.

    The file in question is wp-settings.php.

    The offending section is this one:

    if (strpos($_SERVER['PHP_SELF'], 'install.php') === false) {
        // Used to guarantee unique hash cookies
        $cookiehash = md5(get_option('siteurl'));
    	define('COOKIEHASH', $cookiehash);
    }
    
    if ( !defined('USER_COOKIE') )
    	define('USER_COOKIE', 'wordpressuser_'. COOKIEHASH);
    if ( !defined('PASS_COOKIE') )
    	define('PASS_COOKIE', 'wordpresspass_'. COOKIEHASH);
    if ( !defined('COOKIEPATH') )
    	define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
    if ( !defined('SITECOOKIEPATH') )
    	define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );
    if ( !defined('COOKIE_DOMAIN') )
    	define('COOKIE_DOMAIN', false);

    This calls get_option('siteurl') and get_option('home'). However, the plugins have not yet been scanned for their add_filter() calls, so the intercepted calls are not made.

    It may be as simple as moving the above section to below this section:

    if ( get_option('active_plugins') ) {
    	$current_plugins = get_option('active_plugins');
    	if ( is_array($current_plugins) ) {
    		foreach ($current_plugins as $plugin) {
    			if ('' != $plugin && file_exists(ABSPATH . PLUGINDIR . '/' . $plugin))
    				include_once(ABSPATH . PLUGINDIR . '/' . $plugin);
    		}
    	}
    }

    But I’m not so sure about that. Some of the plugins may need the constants above defined.

    If anyone is interested, I wrote a plugin that does something similar. Check out the main page in my profile link. At the moment, there is only one post there, but it will list the latest five non-event posts.

    Don’t worry about. Doesn’t sound like a forum that I’d find very useful.

    I like to play in Webmaster World. They’re grown-ups there (mostly -I think I shorted the curve a bit).

    Thread Starter cmarshall

    (@cmarshall)

    Hmpf. Nothing, huh? No big deal.

    However, it looks like the problem is really a usability one. I’m used to including links very subtly inline, and the WP theme for these forums makes links darn near invisible.

    In any case, here’s a bigger link:

    BIGGER LINK

    This is done with a plugin and a theme. They work together.

    First of all, you can get older versions here.

    Second, there are a number of reasons that the upgrade may have broken. I suspect that you may not have confined your mods to the wp-content directory, or that you are relying on a plugin that can’t handle the upgrade. I had to delete all my admin theme plugins because they broke when used with other plugins. I stick with the vanilla admin theme.

    I do constant backups of the DB and source. If there is a problem, I can always revert. I recommend that you follow a similar best practice.

    If you do an upgrade, logging into the admin should invoke a DB upgrade. In many cases, this is simply a version change, but it could be more comprehensive.

    Again, I cannot say this strongly enough: USE THE wp-content DIRECTORY FOR ALL YOUR MODS! It’s quite possible to do radical changes to the appearance and operation of the site without hacking the core. Also, even if you do stick with the wp-content directory, you could rely on internal calls that may not survive upgrades.

    Also, be conservative with which plugins you use. Plugins may not survive upgrades very gracefully, especially big upgrades. A good example is what happened to the Role Manager plugin. It broke in 2.2. Luckily, a German guy took it over and applied a fix. Plugins can also step on each other. I had to remove the wp-sticky plugin because it stepped on the event calendar 3 plugin, and I decided that I needed events more than sticky posts.

    Good luck.

    I like it. You do have to be a green lover to get into it, but I like green.

    I like the fact that the two backgrounds sync up so well.

    Thread Starter cmarshall

    (@cmarshall)

    Just an update. I was able to hack this without TOO much nose-holding, thusly:

    In my wp_head handler:

    if ( $_GET['page_id'] )
    		{
    		$page = get_page ( $_GET['page_id'] );
    		}
    	elseif ( $_GET['p'] )
    		{
    		$page = get_post ( $_GET['p'] );
    		}
    
    	if ( $page )
    		{
    		$page = $page->post_content;
    		}
    
    	if ( preg_match ( "/<!-- MY_TRIGGER_COMMENT -->/", $page ) )
    		{
    		echo '<script src="https://maps.google.com/maps?file=api&amp;v=2&amp;key='.$gkey.'" type="text/javascript"></script>'."\n";
    		}

    That does it for now. I still have a lot of testing to go, so we’ll see how it holds up (I need to test the plugin as a post, as opposed to a page. It may need work).

    I have to take some issue with the philosophy that any aspect of a project is “not debatable.” In my world, the User Experience is always king, and we should be doing everything we can to always optimize the UE.

    The “that’s just the way it works” outlook is one that is very attractive to (and typical of) engineers and “purists.” We become enamored with the beauty of the design or philosophy, and blind to the UE.

    Thread Starter cmarshall

    (@cmarshall)

    That’s pretty much what I thought.

    Here’s why I ask (Actually, this is very much a debatable issue, and should be debated):

    I have a mondo heavy-duty plugin that displays some real bitchin’ Google Maps stuff.

    Kewl, Knarly, etc. <wave hang-ten fingers/>

    The problem is that the GM API is REAL BIG, and introduces SERIOUS lag time to the page. I just found out that the GM API sticks <style> tags in their include, so I can’t reference it from the content.

    This means that EVERYONE, whether or not they will ever use the GM stuff, has to pay for it.

    UPDATE: I’ll probably write some real, bloody, dripping, machete-style hack that will look for a “page_id” or a “p” in the argument list, and will read the content from the DB (bad thing to do, as it bypasses all kinds of nice stuff). I’ll peek in the content to see if my trigger comments are there. If so, I’ll include the files. If not, I’ll just skip them.

    Thread Starter cmarshall

    (@cmarshall)

    Thread Starter cmarshall

    (@cmarshall)

    REALLY ANNOYING FOLLOW-UP:
    This won’t work for admin. Admin re-loads straight from the DB, so it can’t be patched. Probably more secure, but it means that you need to hack the core to use admin on local machines without going in and changing the database.

    Thread Starter cmarshall

    (@cmarshall)

    Okay, I got it working.

    I remember someone once saying that filter/hook function names should always be lowercase, so that’s what I did, and now it works just ducky.

    This could be a useful function for people who like to have test laptops with all kinds of virtual systems (like I do), so I’ll share my very simple patcher. You will need to add your own local URIs:

    <?php
    /*
    Plugin Name: localhosts
    Plugin URI: https://...
    Description: Makes things local, for testing.
    Version: 1.0
    */
    function get_uri( $ret )
        {
        if ( preg_match ( '|10\.211\.55\.2|', $_SERVER['SERVER_ADDR'] ) )
            {
            $ret = "https://10.211.55.2/.../public_html/main";
            }
        elseif ( preg_match ( '|127\.0\.0\.1|', $_SERVER['SERVER_ADDR'] ) || preg_match ( '|localhost|', $_SERVER['REQUEST_URI'] ) )
            {
            $ret = "https://localhost/.../public_html/main";
            }
        return $ret;
        }
    
    add_filter ( 'option_home', 'get_uri', 10, 1 );
    add_filter ( 'option_siteurl', 'get_uri', 10, 1 );
    ?>
Viewing 15 replies - 1 through 15 (of 26 total)