How to make an activity to everyone to see on Social Engine? - zend-framework

I am trying to make an activity published by an admin to be visible to every member of the network, not just their friends.
As far as I could make until now, is that the table stream is preventing my message to became public, it only make a profile message. Visible only in its feed.
Does anyone have any idea how to enforce this?
[EDIT]
My code below is picking tweets in my account, I am using some settings i created (like the screen_name from twitter and the user who is publishing the tweet at the feed).
The code is doing as follows:
-> Checking if there is settings for twitter user to read its messages.
-> Save it in a table
-> Authorizing (in theory) to everyone to read this messages, ether is friend of the publisher or not.
-> Adding the activity, that I also created.
$TwitterUser = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.screen_name' );
if ($TwitterUser != '') {
// Ultimo tweet postado
$TwitterUser = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.screen_name' );
$table = Engine_Api::_ ()->getDbtable ( 'tweets', 'user' );
$query = $table->select ()->order ( 'tweets_id desc')->limit(1);
$lastTweet = $table->fetchRow ( $query );
// Set the configuration parameters
$config = array ('adapter' => 'Zend_Http_Client_Adapter_Socket', 'ssltransport' => 'tls' );
// Instantiate a client object
if (is_null ( $lastTweet )) {
$client = new Zend_Http_Client ( "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$TwitterUser&count=4&include_rts=1", $config );
} else {
$client = new Zend_Http_Client ( "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$TwitterUser&include_rts=1&since_id=" . $lastTweet->real_id, $config );
}
// The following request will be sent over a TLS secure connection.
$response = $client->request ();
// Pegando a resposta
$body = json_decode ( $response->getBody () );
if (! empty ( $body )) {
$db = Engine_Api::_()->getDbtable('tweets', 'user')->getAdapter();
$db->beginTransaction();
try
{
$table = Engine_Api::_ ()->getDbtable ( 'users', 'user' );
$twitter_user = $table->fetchRow ( $table->select ()->where ( 'user_id = ?', Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.user_id' ) ) );
$table = Engine_Api::_ ()->getDbtable ( 'tweets', 'user' );
$activityApi = Engine_Api::_ ()->getDbtable ( 'actions', 'activity' );
foreach ( array_reverse($body) as $tweet ) {
$data = explode ( ' ', $tweet->created_at );
$meses = array ('Jan' => '01', 'Fev' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12' );
$tweet_date = $data ['5'] . "-" . $meses [$data [1]] . '-' . $data [2] . " " . $data [3];
$tweet_date = (date ( 'Y-m-d H:i:s', strtotime ( $tweet_date ) ));
$last_tweet = $table->createRow();
$last_tweet->setFromArray(array(
'real_id' => $tweet->id_str,
'user_id' => $tweet->user->id_str,
'screen_name' => $tweet->user->screen_name,
'body' => $tweet->text,
'retweeted' => $tweet->retweeted,
'created_at' => $tweet_date,
'profile_image_url' => $tweet->user->profile_image_url,
'coordinates' => $tweet->coordinates
));
$last_tweet->save();
// Authorizations
$auth = Engine_Api::_()->authorization()->context;
$auth->setAllowed($last_tweet, 'everyone', 'view', true);
$auth->setAllowed($last_tweet, 'everyone', 'comment', true);
$auth->setAllowed($last_tweet, 'everyone', 'likes', true);
$action = $activityApi->addActivity ($twitter_user,$last_tweet, 'post_twitter', $tweet->text);
if( $action ) {
$activityApi->attachActivity($action, $last_tweet);
}
}
// Commit
$db->commit();
} catch ( Exception $e ) {
$db->rollBack ();
throw $e;
}
}
}
No problems happens, but the tweet that I am tracking only could be red by the user I used to publish it.

You should create entries in stream table for this action_id.

Related

Custom FacetWP dropdown not showing posts

I have been able to render a dropdown facet in FacetWP front end with:
add_filter( 'facetwp_facet_html', function( $output, $params ) {
if ( 'today_or_month' == $params['facet']['name'] ) {
$selected = isset( $params['selected'] ) ? $params['selected'] : '';
$output = '<select class="facetwp-dropdown">';
$output .= '<option value="">Select date range</option>';
$output .= '<option value="today"' . ( 'today' == $selected ? ' selected' : '' ) . '>Today</option>';
$output .= '<option value="month"' . ( 'month' == $selected ? ' selected' : '' ) . '>This Month</option>';
$output .= '<option value="test"' . ( 'test' == $selected ? ' selected' : '' ) . '>Test</option>';
$output .= '</select>';
}
return $output;
}, 10, 2 );
All 'event' posts show under the Facet dropdown on page load but when I select an option from the dropdown the queries do not return any posts in the FacetWP template. When I select "Select date range" again all the posts show again.
The queries are as follows:
add_filter( 'facetwp_query_args', function( $args, $class ) {
if (!isset($class->http_params['get']['facetwp'])) return $args;
$selected = $class->http_params['get']['facetwp']['today_or_month'];
$current_month = date( 'Y-m' );
if ( 'today' == $selected ) {
$args['meta_query'][] = array(
'key' => 'event_date_start',
'value' => date( 'Y-m-d' ),
'compare' => '<=',
);
$args['meta_query'][] = array(
'key' => 'event_date_end',
'value' => date( 'Y-m-d' ),
'compare' => '>=',
);
}
elseif ( 'month' == $selected ) {
$args['meta_query'][] = array(
'key' => 'event_date_start',
'value' => date( 'Y-m-01' ),
'compare' => '>=',
);
$args['meta_query'][] = array(
'key' => 'event_date_end',
'value' => date( 'Y-m-t' ),
'compare' => '<=',
);
}
elseif ( 'test' == $selected ) {
$args['meta_query'][] = array(
'key' => 'event_date_start',
'value' => $current_month,
'compare' => 'LIKE',
);
}
$args['post_type'] = 'event';
return $args;
}, 10, 2 );
Does anybody know why the query is not returning any posts in the front end?
I thought maybe I need to convert to a timestamp from ACF custom fields first? Something like this:
$start_date = get_field( 'event_date_start', $params['post_id'] );
$end_date = get_field( 'event_date_end', $params['post_id'] );
$start_timestamp = strtotime( $start_date );
$end_timestamp = strtotime( $end_date );
And then use these variables as the key:
'key' => '$start_timestamp ',
Any help at all would be great. Been going over and over this! Thank you so much. I am begging.
I have tried to run the code as above, I expected some of the custom post types of event to show up in the FacetWP template area according to the dropdown selections. Instead no posts show at all (they should show as some of the posts have February dates).

How to load post ID using the gform_form_post_get_meta filter?

Trying to load post ID (and then some ACF field) of the post, where the form is currently embedded. Using get_the_id() or global $post w/ $post->ID returns NULL.
Loading post ID works correctly when using the other Gravity Forms filters (e.g. gform_admin_pre_render), but I was told using the gform_form_post_get_meta is the better way to do ths. What is the right approach for this?
add_filter( 'gform_form_post_get_meta' , 'my_populate_cpt_as_choices' );
function my_populate_cpt_as_choices( $form ) {
$current_post_id = get_the_id();
$postargs = array(
'post_type' => 'suhlasy',
'post_status' => 'publish',
'posts_per_page' => '-1',
);
$posts = get_posts( $postargs );
$input_id = 1; // this makes sure the checkbox labels and inputs correspond
foreach ( $posts as $post ) {
//skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
if ( $input_id % 10 == 0 ) {
$input_id++;
}
$post_id = $post->ID;
$id_souhlasu = 1200 + $input_id;
$title = get_the_title($post_id);
$checkbox_text = get_field('checkbox_text', $post_id);
$text_suhlasu = get_field('text_suhlasu', $post_id);
$kategoria = get_field('kategoria_suhlas', $post_id);
// getting other fields for this post to display as values or checkbox labels
$nazev_souhlasu = GF_Fields::create( array(
'type' => 'consent',
'id' => $id_souhlasu, // The Field ID must be unique on the form
'formId' => $form['id'],
'isRequired' => true,
'label' => $title,
'parameterName' => 'my_custom_parameter',
'checkboxLabel' => $checkbox_text,
'description' => '<h2>' . $current_post_id . $post_id . $kategoria . '</h2><br>' . $text_suhlasu,
'pageNumber' => 1, // Ensure this is correct
) );
$form['fields'][] = $nazev_souhlasu;
$input_id++;
}
return $form;
}

Send email to all the rows from mysql in codeigniter

i need to send emails to all the rows in database table with their corresponsing data. i am able to send single emails by their id, but now i need to send in bulk. i have done in pure php but in codeigniter not able to figure out. how to do this.
my controller is
public function autoformcomplete()
{
$this->load->model('admin/Reminder_model');
$datan = $this->Reminder_model->autoformemail();
//this should be in whileloop, that i am not able to figure out
$email = $datan[0]['email'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'text',
'charset' => 'utf-8',
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$this->email->set_crlf("\r\n");
$subject = "Complete Your Partially Filled Application-".$appid."";
$data['datan'] = $datan;
$mesg = $this->load->view('email/reminder/form_complete',$data,true);
$this->email->to($email);
$this->email->from('mail#mail.com','My Company');
$this->email->subject($subject);
$this->email->message($mesg);
$this->email->send();
echo "sent";
}
My Model is
public function autoformemail(){
$this->db->order_by('id', 'DESC');
$query = $this->db->get('appstbldata');
return $query->result_array();
}
Just use a foreach loop
public function autoformcomplete() {
$this->load->model( 'admin/Reminder_model' );
$datan = $this->Reminder_model->autoformemail();
foreach ( $datan as $index => $val ) {
// $val now references the current pointer to an element in your $datan array
$email = $val['email'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'text',
'charset' => 'utf-8',
);
$this->email->initialize( $config );
$this->email->set_mailtype( "html" );
$this->email->set_newline( "\r\n" );
$this->email->set_crlf( "\r\n" );
$subject = "Complete Your Partially Filled Application-" . $appid . "";
$data['datan'] = $datan;
$mesg = $this->load->view( 'email/reminder/form_complete', $data, true );
$this->email->to( $email );
$this->email->from( 'mail#mail.com', 'My Company' );
$this->email->subject( $subject );
$this->email->message( $mesg );
$this->email->send();
echo "sent";
}
}
I dunno what your point of $data['datan'] = $datan; line is though

Paragraph breaks missing from shortcode output

I created a shortcode in Wordpress to perform a query and display the content, but the content line breaks are being removed.
add_shortcode( 'resource' , 'Resource' );
function Resource($atts) {
$atts = shortcode_atts( array(
'category' => ''
), $atts );
$categories = explode(',' , $atts['category']);
$args = array(
'post_type' => 'resource',
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page'=> -1,
'tax_query' => array( array(
'taxonomy' => 'category',
'field' => 'term_id',
'operator' => 'AND',
'terms' => $categories
) )
);
$string = '';
$query = new WP_Query( $args );
if( ! $query->have_posts() ) {
$string .= '<p>no listings at this time...</p>';
}
while( $query->have_posts() ){
$query->the_post();
$string .= '<div id="links"><div id="linksImage">' . get_the_post_thumbnail() . '</div>
<div id="linksDetails"><h1>'. get_the_title() .'</h1><p>' . get_the_content() . '</p>
<p>for more information CLICK HERE</div></div>';
}
wp_reset_postdata();
$output = '<div id="linksWrapper">' . $string . '</div>';
return $output;
}
Any suggestion on why this is happening and what to do to fix it. This is only happening on the shortcode output. On regular pages - the content displays correctly.
found a solution through more searches:
function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
works perfect, so I thought I would share..

tax_query to get posts with a field with empty value?

I defined a custom field, to be able to hide posts from home, like this:
/* Campo adicional que puede ocultar noticia de la home */
function mnd_get_custom_field( $value ) {
global $post;
$custom_field = get_post_meta( $post->ID, $value, true );
if ( !empty( $custom_field ) )
return is_array( $custom_field ) ? stripslashes_deep( $custom_field ) : stripslashes( wp_kses_decode_entities( $custom_field ) );
return false;
}
function mnd_add_custom_meta_box() {
add_meta_box( 'home-page', __( 'Home page', 'mnd' ), 'mnd_meta_box_output', 'post', 'normal', 'high' );
}
add_action( 'add_meta_boxes', 'mnd_add_custom_meta_box' );
function mnd_meta_box_output( $post ) {
wp_nonce_field( 'my_mnd_meta_box_nonce', 'mnd_meta_box_nonce' ); ?>
<p>
<label for="mnd_hide_homepage"><?php _e( 'Hide from homepage', 'mnd' ); ?>:</label>
<input type="checkbox" name="mnd_hide_homepage" id="mnd_hide_homepage" checked="<?php echo mnd_get_custom_field( 'mnd_hide_homepage' ) == 1 ? 'checked' : ''; ?>" value="1" size="50" />
</p>
<?php
}
function mnd_meta_box_save( $post_id ) {
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if( !isset( $_POST['mnd_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['mnd_meta_box_nonce'], 'my_mnd_meta_box_nonce' ) ) return;
if( !current_user_can( 'edit_post', get_the_id() ) ) return;
if( isset( $_POST['mnd_hide_homepage'] ) )
update_post_meta( $post_id, 'mnd_hide_homepage', esc_attr( $_POST['mnd_hide_homepage'] ) );
}
add_action( 'save_post', 'mnd_meta_box_save' );
and I'm trying like:
// The Query
$ppp = 12;
$page = $_GET['page'];
$args_count = array(
'post_type' => 'post',
'paged' => false,
'status' => 'publish'
);
$posts_home_count = new WP_Query( $args_count );
$manyPosts = $posts_home_count->found_posts;
$paginas = $manyPosts / $ppp;
wp_reset_postdata();
$meta_params = array(
array(
'key' => 'mnd_hide_homepage',
'value' => 1,
'compare' => '!=',
'type' => 'NUMERIC'
)
);
$args = array(
'post_type' => 'post',
'posts_per_page' => $ppp,
'paged' => $page,
'page' => $page,
'status' => 'publish'/*,
'meta_query' => $meta_params */
);
//print_r ( $args );
$posts_home = new WP_Query( $args );
And it won't return any posts,
But if I change to
'compare' => '=',
Then it returns all the checked posts
Any idea what I'm missing?
There are some problems with Meta Query sometimes and the problem is not always visible. Try the following:
var_dump the WP_Query object and check the SQL manually. Do you see the problem?
Did you try to remove 'type' => 'NUMERIC'?
The “hack” solution (untested):
global $wpdb;
$ids = $wpdb->get_results("
SELECT $wpdb->posts.id FROM $wpdb->posts
WHERE post_status=publish
INNER JOIN $wpdb->post_meta
ON $wpdb->post_meta.post_id = $wpdb->posts.id
AND $wpdb->post_meta.key = 'mnd_hide_homepage'
AND $wpdb->post_meta.value != '1'
");
// put the ids with post__in into the WP_Query arguments
Maybe this is the solution. If not, it may help to find it.
Try this:
array(
'key' => 'mnd_hide_homepage',
'value' => '1',
'compare' => '!=',
'type' => 'NUMERIC'
)
Or
array(
'key' => 'mnd_hide_homepage',
'value' => array('1'),
'compare' => 'NOT IN'
)