Forum Replies Created

Viewing 15 replies - 1 through 15 (of 18 total)
  • Forum: Hacks
    In reply to: New Post via Email Piping
    Thread Starter Jeffrey Cannon

    (@jacannon2)

    I did resolve this issue.

    #!/usr/bin/php -q
    <?php
    /**/
    //setup global $_SERVER variables to keep WP from trying to redirect
    $_SERVER = array(
      "HTTP_HOST" => "domain.com",
      "SERVER_NAME" => "domain.com",
      "REQUEST_URI" => "/email_pipe/reader.php", // location of this file
      "REQUEST_METHOD" => "GET"
    );
    
    //require the WP bootstrap
    require_once('/home/user/public_html/wp-load.php');
    
    switch_to_blog(70);
    
    //include email parser
    require_once('/home/user/public_html/email_pipe/include/rfc822_addresses.php');
    require_once('/home/user/public_html/email_pipe/include/mime_parser.php');
    
    // read from stdin
    $fd = fopen("php://stdin", "r");
    $email = "";
    while (!feof($fd))
    {
    	$email .= fread($fd, 1024);
    }
    fclose($fd);
    
    //create the email parser class
    $mime=new mime_parser_class;
    $mime->ignore_syntax_errors = 1;
    $parameters=array(
    	'Data'=>$email,
    );
    
    $mime->Decode($parameters, $decoded);
    
    //---------------------- GET EMAIL HEADER INFO -----------------------//
    
    //get the name and email of the sender
    $fromName = $decoded[0]['ExtractedAddresses']['from:'][0]['name'];
    $fromEmail = $decoded[0]['ExtractedAddresses']['from:'][0]['address'];
    
    //get the name and email of the recipient
    $toEmail = $decoded[0]['ExtractedAddresses']['to:'][0]['address'];
    $toName = $decoded[0]['ExtractedAddresses']['to:'][0]['name'];
    
    //get the subject
    $subject = $decoded[0]['Headers']['subject:'];
    
    if (!$subject) {$subject = "(no subject)";}
    
    $removeChars = array('<','>');
    
    //get the message id
    $messageID = str_replace($removeChars,'',$decoded[0]['Headers']['message-id:']);
    
    //get the reply id
    $replyToID = str_replace($removeChars,'',$decoded[0]['Headers']['in-reply-to:']);
    
    //---------------------- FIND THE BODY -----------------------//
    
    //get the message body
    if(substr($decoded[0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Body'])){
    
    	$body = $decoded[0]['Body'];
    
    } elseif(substr($decoded[0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Parts'][0]['Body'])) {
    
    	$body = $decoded[0]['Parts'][0]['Body'];
    
    } elseif(substr($decoded[0]['Parts'][0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Parts'][0]['Parts'][0]['Body'])) {
    
    	$body = $decoded[0]['Parts'][0]['Parts'][0]['Body'];
    
    }
    
    //create email message
    $email = "
    
    Message ID: $messageID
    
    Reply ID: $replyToID
    
    Subject: $subject
    
    To: $toName $toEmail
    
    From: $fromName $fromEmail
    
    Body: $body
    
    ";
    
    $email_post = "
    To: $toName $toEmail
    
    From: $fromName $fromEmail
    
    Subject: $subject
    
    $body
    ";
    
    // Create post object
    $my_post = array(
      'post_title'    => $subject,
      'post_content'  => $email_post,
      'post_status'   => 'publish',
      'post_author'   => 52,
      'post_type' => 'ticket'
    );
    
    // Insert the post into the database
    $new_post = wp_insert_post( $my_post );
    
    // Update status to: New
    $wpdb->insert(
    	'blog_70_term_relationships',
    	array(
    		'object_id' => $new_post,
    		'term_taxonomy_id' => 5
    	),
    	array(
    		'%d',
    		'%d'
    	)
    );
    
    // Update priority to: High
    $wpdb->insert(
    	'blog_70_term_relationships',
    	array(
    		'object_id' => $new_post,
    		'term_taxonomy_id' => 3
    	),
    	array(
    		'%d',
    		'%d'
    	)
    );
    
    // Update type to: Start
    $wpdb->insert(
    	'blog_70_term_relationships',
    	array(
    		'object_id' => $new_post,
    		'term_taxonomy_id' => 17
    	),
    	array(
    		'%d',
    		'%d'
    	)
    );
    
    // Send email
    //mail('[email protected]',$subject, $email);
    
    ?>

    Things I discovered through trial and error…

    The EOL (end of line) Conversion for the file had to be Unix and not Windows format. I think it also had to be created in UTF-8 and not ANSI.

    I had to specify the server variables at the beginning or the switch_to_blog() function wouldn’t work at all.

    After the new post was created I had to use MySQL queries to update the post’s taxonomy because it wouldn’t work using the WordPress functions. I think this was because they didn’t recognize the switch_to_blog() function.

    Thread Starter Jeffrey Cannon

    (@jacannon2)

    Anyone?

    Thread Starter Jeffrey Cannon

    (@jacannon2)

    Something to note…

    I’ve noticed when I type in the URL, hit enter, click the url and hit enter again (basically refresh the page before it loads), it loads faster.

    Not sure if that gives any clue as to why it loads slow on the first time and not on the second time, but it’s a trick I’ve found to view the site faster.

    Still doesn’t help everyone else who waits for it to load the first time.

    Thread Starter Jeffrey Cannon

    (@jacannon2)

    No, it’s still running slow.

    WordPress is slow and SilverStripe is fast.

    I assume that means MySQL is doing fine.

    Is there anything else to rule out or try?

    Thread Starter Jeffrey Cannon

    (@jacannon2)

    I installed SilverStripe and it seems to be doing just fine.

    https://wp.bwoc.cc/silver/

    Should I try another one?

    Thread Starter Jeffrey Cannon

    (@jacannon2)

    There’s not one.

    It usually shows up if I change the settings for the permalinks, but since it’s a fresh install I didn’t.

    Thread Starter Jeffrey Cannon

    (@jacannon2)

    Done.

    Still 16 seconds.

    Thread Starter Jeffrey Cannon

    (@jacannon2)

    What would be something that I could set up with MySQL that would give us the information we need?

    I’ve never really done anything from scratch. I’ve always used pre-packaged setups for my websites.

    Thread Starter Jeffrey Cannon

    (@jacannon2)

    Done.

    Same load time.

    Thread Starter Jeffrey Cannon

    (@jacannon2)

    Loaded in 1 second…

    https://wp.bwoc.cc/info/

    I discovered the feeds are created by these files within the wp-includes folder:

    – feed-atom.php
    – feed-rdf.php
    – feed-rss.php
    – feed-rss2.php
    – feed.php

    Of course any changes to these files will be overwritten on an update, but that’s where they are (for the curious).

    I was having the same problem and with mine I figured out that it was reading the theme files from my test directory that I had previously been using before I moved the WordPress install to my root directory.

    Something to look in to.

    Here’s the code tweaked with some code found in the query_posts page you provided from the WordPress Codex:

    <?php
    $categoryvariable=$cat; // assign the variable as current category
    $query= 'cat=' . $categoryvariable. '&orderby=date&order=ASC'; // concatenate the query
    query_posts($query); // run the query
    ?>
    <h2>Recent Posts</h2>
    <ul>
    	<?php if (have_posts()) : ?>
    	<?php while (have_posts()) : the_post(); ?>
    	<li>
    	<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    	<?php the_title(); ?>
    	</a>
    	</li>
    	<?php endwhile; ?>
    </ul>

    Is this closer to what you’re talking about?

    Thread Starter Jeffrey Cannon

    (@jacannon2)

    Just checking to see if anyone knows what’s going on?

    This should work for you…

    <?php if (is_category('Loans')) {
    	query_posts("category_name=Loans&showposts=3"); ?>
    	<h2>Recent Posts</h2>
    	<ul>
    	<?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>
    	<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
        <?php endwhile; ?>
    	</ul>
    <?php } ?>
Viewing 15 replies - 1 through 15 (of 18 total)