Esempio n. 1
0
 private static function send_with_drupal($url, $options, $ignore_error)
 {
     ShareaholicUtilities::log($url);
     ShareaholicUtilities::log($options);
     ShareaholicUtilities::log('-----------------');
     $request = array();
     $result = array();
     $request['method'] = isset($options['method']) ? $options['method'] : 'GET';
     $request['headers'] = isset($options['headers']) ? $options['headers'] : array();
     $request['max_redirects'] = isset($options['redirection']) ? $options['redirection'] : 5;
     $request['timeout'] = isset($options['timeout']) ? $options['timeout'] : 15;
     $request['headers']['User-Agent'] = isset($options['user-agent']) ? $options['user-agent'] : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0';
     if (isset($options['body'])) {
         if (isset($request['headers']['Content-Type']) && $request['headers']['Content-Type'] === 'application/json') {
             $request['data'] = json_encode($options['body']);
         } else {
             $request['data'] = http_build_query($options['body']);
         }
     } else {
         $request['body'] = NULL;
     }
     $response = drupal_http_request($url, $request);
     if (isset($response->error)) {
         ShareaholicUtilities::log($response->error);
         if (!$ignore_error) {
             ShareaholicUtilities::log_event('CurlRequestFailure', array('error_message' => $response->error, 'url' => $url));
         }
         return false;
     }
     $result['headers'] = $response->headers;
     $result['body'] = $response->data;
     $result['response'] = array('code' => $response->code, 'message' => $response->status_message);
     return $result;
 }
/**
 * Submit handler for the shareaholic_apps_configuration form
 * When submitted, update the location settings
 *
 */
function shareaholic_apps_configuration_form_submit($form, &$form_state)
{
    $settings = ShareaholicUtilities::get_settings();
    if (empty($settings['recommendations']) || empty($settings['share_buttons'])) {
        return;
    }
    $form_input = $form_state['input'];
    $page_types = ShareaholicUtilities::page_types();
    foreach ($page_types as $key => $page_type) {
        foreach (array('share_buttons', 'recommendations') as $app) {
            foreach (array('above', 'below') as $location) {
                $location_name = "{$page_type->type}_{$location}_content";
                if ($location === 'above' && $app === 'recommendations') {
                    continue;
                }
                if (!isset($form_input[$app][$location_name]) || !isset($form_input[$app]["{$location_name}_location_id"]) || $form_input[$app][$location_name] !== 'on') {
                    $settings[$app][$location_name] = 'off';
                } else {
                    $settings[$app][$location_name] = 'on';
                    $settings['location_name_ids'][$app][$location_name] = $form_input[$app]["{$location_name}_location_id"];
                }
            }
        }
    }
    ShareaholicUtilities::set_settings($settings);
    ShareaholicUtilities::log_event('UpdatedSettings');
    drupal_set_message(t('Shareaholic Settings Saved'), 'status');
}
Esempio n. 3
0
 private static function send_with_wp($url, $options, $ignore_error)
 {
     $request = array();
     $result = array();
     $request['method'] = isset($options['method']) ? $options['method'] : 'GET';
     $request['headers'] = isset($options['headers']) ? $options['headers'] : array();
     $request['redirection'] = isset($options['redirection']) ? $options['redirection'] : 5;
     $request['timeout'] = isset($options['timeout']) ? $options['timeout'] : 15;
     $request['user-agent'] = isset($options['user-agent']) ? $options['user-agent'] : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0';
     if (isset($options['body'])) {
         if (isset($request['headers']['Content-Type']) && $request['headers']['Content-Type'] === 'application/json') {
             $request['body'] = json_encode($options['body']);
         } else {
             $request['body'] = $options['body'];
         }
     } else {
         $request['body'] = NULL;
     }
     $request['sslverify'] = false;
     $response = wp_remote_request($url, $request);
     if (is_wp_error($response)) {
         $error_message = $response->get_error_message();
         ShareaholicUtilities::log($error_message);
         if (!$ignore_error) {
             ShareaholicUtilities::log_event('HttpRequestFailure', array('error_message' => $error_message, 'url' => $url));
         }
         return false;
     }
     return $response;
 }
function shareaholic_advanced_settings_form_submit($form, &$form_state)
{
    if (ShareaholicUtilities::has_tos_and_apikey()) {
        ShareaholicUtilities::update_options(array('disable_og_tags' => $form_state['values']['disable_og_tags'] === 1 ? 'on' : 'off', 'disable_internal_share_counts_api' => $form_state['values']['disable_internal_share_counts_api'] === 1 ? 'on' : 'off'));
        drupal_set_message(t('Settings Saved: please clear your cache.'), 'status');
    }
}
 public static function get_overrides()
 {
     $output = '';
     if (ShareaholicUtilities::get_env() === 'staging') {
         $output = "data-shr-environment='stage' data-shr-assetbase='//cdn-staging-shareaholic.s3.amazonaws.com/v2/'";
     }
     return $output;
 }
Esempio n. 6
0
    public static function get_overrides()
    {
        $output = '';
        if (ShareaholicUtilities::get_env() === 'staging') {
            $output = <<<DOC
        shr.setAttribute('data-shr-environment', 'stage');
        shr.setAttribute('data-shr-assetbase', '//cdn-staging-shareaholic.s3.amazonaws.com/v2/');
        shr.src = '//cdn-staging-shareaholic.s3.amazonaws.com/assets/pub/shareaholic.js';
DOC;
        }
        return $output;
    }
Esempio n. 7
0
 /**
  * Get the share_buttons configuration to be used by Shareaholic.js
  *
  * This function returns an object for the share buttons configuration
  * which will be consumed by Shareaholic.js
  *
  * @return array an associative array of configuration for share buttons
  */
 public static function get_share_buttons_config()
 {
     $share_buttons = array();
     $disable_share_counts_api = ShareaholicUtilities::get_option('disable_internal_share_counts_api');
     $share_counts_connect_check = ShareaholicUtilities::get_option('share_counts_connect_check');
     if (isset($disable_share_counts_api)) {
         if (isset($share_counts_connect_check) && $share_counts_connect_check == 'SUCCESS' && $disable_share_counts_api != 'on') {
             $share_buttons['get_share_counts'] = '%get_share_counts%';
         }
     }
     return $share_buttons;
 }
Esempio n. 8
0
 function get_shr_like_buttonset($position)
 {
     $trace = debug_backtrace();
     $deprecation = new ShareaholicDeprecation('get_shr_like_buttonset');
     $deprecation->push($trace[0]['file'], $trace[0]['line']);
     $settings = ShareaholicUtilities::get_settings();
     $page_type = ShareaholicUtilities::page_type();
     switch ($position) {
         case 'Top':
             $id = isset($settings['location_name_ids']["{$page_type}_above_content"]) ? $settings['location_name_ids']["{$page_type}_above_content"] : NULL;
             break;
         case 'Bottom':
             $id = isset($settings['location_name_ids']["{$page_type}_below_content"]) ? $settings['location_name_ids']["{$page_type}_below_content"] : NULL;
             break;
     }
     echo ShareaholicPublic::canvas($id, 'share_buttons');
 }
Esempio n. 9
0
 /**
  * A job that clears up the shareaholic share counts transients
  */
 public static function remove_transients()
 {
     global $wpdb;
     $older_than = time() - 60 * 60;
     // older than an hour ago
     ShareaholicUtilities::log('Start of Shareaholic transient cleanup');
     $query = "SELECT REPLACE(option_name, '_transient_timeout_', '') AS transient_name FROM {$wpdb->options} WHERE option_name LIKE '\\_transient\\_timeout\\_shr\\_api\\_res-%%' AND option_value < %s LIMIT 5000";
     $transients = $wpdb->get_col($wpdb->prepare($query, $older_than));
     $options_names = array();
     foreach ($transients as $transient) {
         $options_names[] = esc_sql('_transient_' . $transient);
         $options_names[] = esc_sql('_transient_timeout_' . $transient);
     }
     if ($options_names) {
         $options_names = "'" . implode("','", $options_names) . "'";
         $result = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name IN ({$options_names})");
         if (!$result) {
             ShareaholicUtilities::log('Transient Query Error!!!');
         }
     }
     ShareaholicUtilities::log('End of Shareaholic transient cleanup');
 }
Esempio n. 10
0
 /**
  * Handles publishing or updating a post
  *
  * @param  string $post_id the post id
  * @return bool   whether the request worked
  */
 public static function post_notify($post_id)
 {
     global $wpdb;
     $post = get_post($post_id);
     $url = get_permalink($post_id);
     $tags = wp_get_post_tags($post_id, array('fields' => 'names'));
     $categories = array_map(array('ShareaholicNotifier', 'post_notify_iterator'), get_the_category($post_id));
     if (function_exists('has_post_thumbnail') && has_post_thumbnail($post_id)) {
         $featured_image = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'large');
     } else {
         $featured_image = ShareaholicUtilities::post_first_image();
         if (!$featured_image) {
             $featured_image = '';
         }
     }
     if ($post->post_author) {
         $author_data = get_userdata($post->post_author);
         $author_name = $author_data->display_name;
     }
     $notification = array('url' => $url, 'api_key' => ShareaholicUtilities::get_option('api_key'), 'content' => array('title' => $post->post_title, 'excerpt' => $post->post_excerpt, 'body' => $post->post_content, 'featured-image-url' => $featured_image), 'metadata' => array('author-id' => $post->post_author, 'author-name' => $author_name, 'post-type' => $post->post_type, 'post-id' => $post_id, 'post-tags' => $tags, 'post-categories' => $categories, 'post-language' => get_bloginfo('language'), 'published' => $post->post_date_gmt, 'updated' => get_lastpostmodified('GMT'), 'visibility' => $post->post_status), 'diagnostics' => array('platform' => 'wordpress', 'platform-version' => get_bloginfo('version'), 'shareaholic-version' => Shareaholic::VERSION, 'wp-multisite' => is_multisite(), 'wp-theme' => get_option('template'), 'wp-posts-total' => $wpdb->get_var("SELECT count(ID) FROM {$wpdb->posts} where post_type = 'post' AND post_status = 'publish'"), 'wp-pages-total' => $wpdb->get_var("SELECT count(ID) FROM {$wpdb->posts} where post_type = 'page' AND post_status = 'publish'"), 'wp-comments-total' => wp_count_comments()->approved, 'wp-users-total' => $wpdb->get_var("SELECT count(ID) FROM {$wpdb->users}")));
     return self::send_notification($notification);
 }
Esempio n. 11
0
 /**
  *
  * Performs a request using cURL
  *
  * @param string $url       the url you are GETing to
  * @param array  $data      an associative array of the data you are posting
  * @param string $data_type either an empty string or 'json'
  * @param string $method    the HTTP verb to be used
  *
  * @return array the returned data json decoded
  */
 private static function send_request($url, $data, $data_type, $method)
 {
     $curl = curl_init();
     curl_setopt_array($curl, array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false));
     /*
      * Because many shared hosting providers set `open_basedir` in php.ini
      * that means we can't always set CURLOPT_FOLLOWLOCATION.
      * This next block is an attempt around that by sending head requests
      * to determine if there will be a redirect and then following it.
      * Shamelessly stolen from here:
      *   http://us2.php.net/manual/en/function.curl-setopt.php#102121
      */
     $mr = 5;
     if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, $mr > 0);
         curl_setopt($curl, CURLOPT_MAXREDIRS, $mr);
     } else {
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
         if ($mr > 0) {
             $newurl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
             $rch = curl_copy_handle($curl);
             curl_setopt($rch, CURLOPT_HEADER, true);
             curl_setopt($rch, CURLOPT_NOBODY, true);
             curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
             curl_setopt($rch, CURLOPT_RETURNTRANSFER, true);
             do {
                 curl_setopt($rch, CURLOPT_URL, $newurl);
                 $header = curl_exec($rch);
                 if (curl_errno($rch)) {
                     $code = 0;
                 } else {
                     $code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
                     if ($code == 301 || $code == 302) {
                         preg_match('/Location:(.*?)\\n/', $header, $matches);
                         $newurl = trim(array_pop($matches));
                     } else {
                         $code = 0;
                     }
                 }
             } while ($code && --$mr);
             curl_close($rch);
             if (!$mr) {
                 if ($maxredirect === null) {
                     trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING);
                 } else {
                     $maxredirect = 0;
                 }
                 return false;
             }
             curl_setopt($curl, CURLOPT_URL, $newurl);
         }
     }
     /* end stolen code */
     if ($method == 'POST') {
         curl_setopt_array($curl, array(CURLOPT_POST => 1, CURLOPT_HTTPHEADER => array("Accept: application/json,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain")));
         if ($data_type == 'json') {
             curl_setopt_array($curl, array(CURLOPT_POSTFIELDS => json_encode($data), CURLOPT_HTTPHEADER => array('Content-Type: application/json', 'Content-Length: ' . strlen(json_encode($data)))));
         } else {
             curl_setopt_array($curl, array(CURLOPT_POSTFIELDS => ShareaholicQueryStringBuilder::build_query_string($data)));
         }
     }
     $result = curl_exec($curl);
     $info = curl_getinfo($curl);
     ShareaholicUtilities::log(curl_error($curl));
     ShareaholicUtilities::log(curl_getinfo($curl));
     curl_close($curl);
     if (preg_match('/^20*/', $info['http_code'])) {
         return ShareaholicUtilities::object_to_array(json_decode($result)) ? ShareaholicUtilities::object_to_array(json_decode($result)) : $result;
     } else {
         return false;
     }
 }
Esempio n. 12
0
/**
 * Submit handler for the shareaholic_failure_modal
 * When submitted, try to create an api key for the user
 *
 */
function shareaholic_failure_modal_form_submit($form, &$form_state)
{
    ShareaholicUtilities::get_or_create_api_key();
}
Esempio n. 13
0
 /**
  * Insert the Open Graph Tags
  */
 public static function insert_og_tags($node = false, $view_mode = '')
 {
     $markup = '';
     $disable_og_tags_check = ShareaholicUtilities::get_option('disable_og_tags');
     if ($disable_og_tags_check && $disable_og_tags_check == 'on') {
         return;
     }
     if ($view_mode != 'full') {
         return;
     }
     if ($node && (!isset($node->shareaholic_options["shareaholic_exclude_og_tags"]) || !$node->shareaholic_options["shareaholic_exclude_og_tags"])) {
         $image_url = self::get_image_url_for($node);
         if (!empty($image_url)) {
             $markup .= "\n<!-- Shareaholic Open Graph Tags -->\n";
             $markup .= "<meta property='og:image' content='" . $image_url . "' />";
             $markup .= "\n<!-- Shareaholic Open Graph Tags End -->\n";
         }
     }
     $element = array('#type' => 'markup', '#markup' => $markup);
     drupal_add_html_head($element, 'shareaholic_og_tags');
 }
Esempio n. 14
0
 /**
  * This function fires when the plugin is uninstalled.
  */
 public function uninstall()
 {
     ShareaholicUtilities::log_event("Uninstall");
     delete_option('shareaholic_settings');
 }
Esempio n. 15
0
 /**
  * Call the content manager for a post before it is updated
  *
  * We do this because a user may change their permalink
  * and so we tell CM that the old permalink is not longer valid
  *
  */
 public static function before_post_is_updated($post_id)
 {
     ShareaholicUtilities::notify_content_manager_singlepage(get_post($post_id));
 }
}
?>

    <div class="fieldset-footer">
      <span class="helper"><i class="icon-star"></i> Re-crawl your content, exclude certain pages from being recommended, etc.</span>
      <button class='app_wide_settings btn' data-href='recommendations/edit'><?php 
print t('Edit Related & Promoted Content Settings');
?>
</button>
      <div class="app-status">
        &nbsp;&nbsp;&nbsp;&nbsp;<strong><?php 
print t('Status:');
?>
</strong>
        <?php 
$status = ShareaholicUtilities::recommendations_status_check();
if ($status == 'processing' || $status == 'unknown') {
    echo '<img class="shrsb_health_icon" align="top" src="' . SHAREAHOLIC_ASSET_DIR . '/img/circle_yellow.png" />' . t('Processing');
} else {
    echo '<img class="shrsb_health_icon" align="top" src="' . SHAREAHOLIC_ASSET_DIR . '/img/circle_green.png" />' . t('Ready');
}
?>
      </div>
    </div>
  </fieldset>

  <div class='clear'></div>

  <fieldset class="app">
    <legend><h2><i class="icon icon-share_buttons"></i><?php 
print t('Share Buttons');
<div class='reveal-modal' id='editing_modal'>
  <div id='iframe_container' class='bg-loading-img' allowtransparency='true'></div>
  <a class="close-reveal-modal">&#215;</a>
</div>

<script>
window.first_part_of_url = "<?php 
echo ShareaholicUtilities::URL . '/publisher_tools/' . ShareaholicUtilities::get_option('api_key');
?>
/";
window.verification_key = "<?php 
echo ShareaholicUtilities::get_option('verification_key');
?>
";
window.shareaholic_api_key = "<?php 
echo ShareaholicUtilities::get_option('api_key');
?>
";
</script>

<div class='unit size3of5'>
<?php 
$form = drupal_get_form('shareaholic_apps_configuration_form');
print drupal_render($form);
?>
</div>

  <div class="signuppromo unit size1of5">
  <p class="promoh1"><?php 
print t('Gain access to more features with a FREE Shareaholic account:');
?>
Esempio n. 18
0
</div>
      <?php 
}
?>
    </fieldset>
    
    <div class='clear'></div>
    
    <fieldset class="app">
      <legend><h2><?php 
_e('Your Shareaholic Site ID', 'shareaholic');
?>
</h2></legend>
      <?php 
if (ShareaholicUtilities::get_option('api_key')) {
    echo '<code>' . ShareaholicUtilities::get_option('api_key') . '</code>';
} else {
    _e('Not set.', 'shareaholic');
}
?>
    </fieldset>
    
    <div class='clear'></div>
    
    <form name='reset_settings' method='post' action='<?php 
echo $action;
?>
'>
      <?php 
wp_nonce_field($action, 'nonce_field');
?>
Esempio n. 19
0
 /**
  * This function is for all settings that are specific to wordpress
  * and are not stored in a publisher configuration object. So far
  * this only inclues disabling the tracking.
  */
 private static function transform_wordpress_specific_settings()
 {
     $new_shareaholic_settings = array();
     $analytics_settings = get_option('ShareaholicAnalytics');
     $sexybookmarks_settings = get_option('SexyBookmarks');
     $new_shareaholic_settings['disable_og_tags'] = $sexybookmarks_settings['ogtags'] == '0' ? 'on' : 'off';
     ShareaholicUtilities::update_options($new_shareaholic_settings);
 }
Esempio n. 20
0
 /**
  * A post just transitioned state. Do something.
  *
  */
 public static function post_transitioned($new_status, $old_status, $post)
 {
     $post_type = get_post_type($post);
     if ($new_status == 'publish' && $post_type != 'nav_menu_item' && $post_type != 'attachment') {
         // Post was just published
         ShareaholicUtilities::clear_fb_opengraph(get_permalink($post->ID));
         ShareaholicUtilities::notify_content_manager_singlepage($post);
     }
     if ($old_status == 'publish' && $new_status != 'publish') {
         // Notify CM that the post is no longer public
         ShareaholicUtilities::notify_content_manager_singlepage($post);
     }
 }
 /**
  *
  */
 public static function show_header()
 {
     $settings = ShareaholicUtilities::get_settings();
     $settings['base_link'] = ShareaholicUtilities::URL . '/publisher_tools/' . $settings['api_key'] . '/';
     $settings['website_settings_link'] = $settings['base_link'] . 'websites/edit?verification_key=' . $settings['verification_key'];
     ShareaholicUtilities::load_template('header', array('settings' => $settings));
 }
Esempio n. 22
0
<script type="text/javascript"
        data-sorendpoint="<?php 
echo Shareaholic::URL;
?>
"
        data-sorassetbase="<?php 
echo ShareaholicUtilities::asset_url('assets');
?>
"
        src="<?php 
echo ShareaholicUtilities::asset_url('assets/headerWidget.js');
?>
">
</script>
<link href="<?php 
echo ShareaholicUtilities::asset_url('assets/header.css');
?>
" media="all" rel="stylesheet" type="text/css">

<!-- Start Header Template -->
<div class="new-design flat-layout wordpress-admin" style="display:none;">
  <header class="header-section js-header">
    <div class="header">
      <a href= "https://shareaholic.com" class="logo"></a>
      <nav class="header-nav">
      </nav>
      <ul class="user-nav js-logged-out" style="display:none;">
        <div class="hiring">
          <a href="https://shareaholic.com/careers?utm_source=univ_header_wp_plugin&utm_medium=link&utm_campaign=careers" target="_blank">We're Hiring</a>
        </div>
        <li><a href="#" class="btn dark-green js-action-signup">Sign Up Free</a></li>
Esempio n. 23
0
<div style="margin-top:45px;"></div>
<div class='clear'>
  <small class="muted">
    <?php 
echo sprintf(__('%sShareaholic for WordPress v' . ShareaholicUtilities::get_version() . '%s | %sPrivacy Policy%s | %sTerms of Service%s | %sSupport Center%s | %sAPI%s | %sSocial Analytics%s', 'shareaholic'), '<a href="https://shareaholic.com/?src=wp_admin" target="_new">', '</a>', '<a href="https://shareaholic.com/privacy/?src=wp_admin" target="_new">', '</a>', '<a href="https://shareaholic.com/terms/?src=wp_admin" target="_new">', '</a>', '<a href="http://support.shareaholic.com/" target="_new">', '</a>', '<a href="https://shareaholic.com/api/?src=wp_admin" target="_new">', '</a>', '<a href="https://shareaholic.com/publishers/analytics/' . ShareaholicUtilities::get_host() . '/30?src=wp_admin" target="_new">', '</a>');
?>
  </small>
  <br />
  <small class="muted">
    <?php 
echo sprintf(__('If you like our work, show some love and %sgive us a good rating%s. Made with much love in Boston, Massachusetts.', 'shareaholic'), '<a href="http://wordpress.org/support/view/plugin-reviews/shareaholic?rate=5#postform" target="_new">', '</a>');
?>
  </small>
  <br />
  <br />
  <iframe src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fshareaholic&amp;width&amp;layout=standard&amp;action=like&amp;show_faces=true&amp;share=false&amp;height=80&amp;width=500&amp;appId=207766518608" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe>
</div>

<!-- Start of Async HubSpot Analytics -->
<script type="text/javascript">
var _hsq = _hsq || [];
_hsq.push(["setContentType", "standard-page"]);
	(function(d,s,i,r) {
	if (d.getElementById(i)){return;}
	var n = d.createElement(s),e = document.getElementsByTagName(s)[0];
	n.id=i;n.src = '//js.hubspot.com/analytics/'+(Math.ceil(new Date()/r)*r)+'/210895.js';
	e.parentNode.insertBefore(n, e);
	})(document, "script", "hs-analytics",300000);
</script>
<!-- End of Async HubSpot Analytics Code -->
Esempio n. 24
0
 /**
  * Function to return related permalinks for a given permalink to bootstrap the Related Content app until the off-line processing routines complete
  *
  * @return list of related permalinks in JSON
  */
 public static function permalink_related()
 {
     global $post;
     // Input Params
     $permalink = isset($_GET['permalink']) ? $_GET['permalink'] : NULL;
     $match = isset($_GET['match']) ? $_GET['match'] : "random";
     // match method
     $n = isset($_GET['n']) ? intval($_GET['n']) : 10;
     // number of related permalinks to return
     $related_permalink_list = array();
     // Get post ID
     if ($permalink == NULL) {
         // default to random match if no permalink is available
         $match = "random";
     } else {
         $post_id = url_to_postid($permalink);
         // for non-default paths - handle both https and http versions of the permalink
         if ($post_id == 0) {
             $parse = parse_url($permalink);
             if ($parse['scheme'] == "https") {
                 $permalink = str_replace("https", "http", $permalink);
                 $post_id = url_to_postid($permalink);
             } else {
                 if ($parse['scheme'] == "http") {
                     $permalink = str_replace("http", "https", $permalink);
                     $post_id = url_to_postid($permalink);
                 }
             }
         }
     }
     if ($match == "random") {
         $args = array('posts_per_page' => $n, 'orderby' => 'rand');
         $rand_posts = get_posts($args);
         foreach ($rand_posts as $post) {
             $related_link = array('page_id' => $post->ID, 'url' => get_permalink($post->ID), 'title' => $post->post_title, 'description' => $post->post_excerpt, 'image_url' => ShareaholicUtilities::permalink_thumbnail($post->ID, "medium"), 'score' => 1);
             array_push($related_permalink_list, $related_link);
         }
         wp_reset_postdata();
     } else {
         // other methods coming soon
     }
     // Construct results array
     $result = array('request' => array('api_key' => ShareaholicUtilities::get_option('api_key'), 'url' => $permalink), 'internal' => $related_permalink_list);
     header('Content-Type: application/json; charset=utf-8');
     header('Cache-Control: max-age=180');
     // 3 minutes
     echo json_encode($result);
     exit;
 }
Esempio n. 25
0
 /**
  * Renders footer
  */
 public static function show_footer()
 {
     ShareaholicUtilities::load_template('footer');
 }
Esempio n. 26
0
 /**
  * This function is in charge of sending the "get started" email
  */
 public static function send_welcome_email()
 {
     $site_url = get_bloginfo('url');
     $api_key = ShareaholicUtilities::get_option('api_key');
     $payment_url = 'https://shareaholic.com/account';
     $shr_wp_dashboard_url = admin_url('admin.php?page=shareaholic-settings');
     $sign_up_link = 'https://shareaholic.com/publisher_tools/' . ShareaholicUtilities::get_option('api_key') . '/verify?verification_key=' . ShareaholicUtilities::get_option('verification_key') . '&redirect_to=' . 'https://shareaholic.com/publisher_tools/' . ShareaholicUtilities::get_option('api_key') . '/websites/edit?verification_key=' . ShareaholicUtilities::get_option('verification_key');
     $to = get_bloginfo('admin_email');
     $subject = 'Thank you for installing Shareaholic for WordPress!';
     $message = "\n    <p>Hi there,</p>\n    \n    <p>Thank you for installing Shareaholic on {$site_url}! You are one step closer to growing your website traffic and revenue with our award winning  all-in-one content amplification platform. Completing your set-up is easy, just follow these three easy steps and you'll be ready to go:</p>\n        \n    <p><strong>Step 1. Customize to your needs</strong><br /><br />\n    \n    Personalize the design of the Share Buttons and Related Content Recommendations App to match your website using the \"Customize\" buttons in your <a href='{$shr_wp_dashboard_url}'>Shareaholic App Manager in WordPress</a>, then choose where you want them to appear on your website using the checkboxes!\n            \n    <p><strong>Step 2: Sign-up for a free Shareaholic account</strong><br /><br />\n    \n    This will allow you to add more (free!) features like Analytics, Floating Share Buttons, Follow Buttons and more. <strong><a href='{$sign_up_link}'>Click here to sign-up</a></strong>, or <a href='{$sign_up_link}'>login to an existing Shareaholic account</a> and we'll automatically sync the plugin settings with your account.</p>\n    \n    <p><strong>Step 3: Control your earnings and setup how you would like to get paid</strong><br /><br />\n    \n    Decide how much you would like to earn from Promoted Content (native ads that appear in the Related Content app) and other monetization apps by editing your settings in the \"Monetization\" section of the plugin. Next, visit the \"Username and email address\" <a href='{$payment_url}'>section of your Shareaholic.com account</a> to add your PayPal information, so you can collect the revenue you generate from Shareaholic.</p>\n    \n    <p>Have questions? Simply reply to this email and we will help you out!</p>\n\n    <p>Let's get started,<br /><br />\n    \n    Mary Anne & Cameron<br />\n    Shareaholic Happiness Team<br />\n    <a href='http://support.shareaholic.com'>support.shareaholic.com</a><br /><br />\n    <img width='200' height='36' src='https://shareaholic.com/assets/layouts/shareaholic-logo.png' alt='Shareaholic' title='Shareaholic' /><br />\n    <p style='font-size:12px;color:#C3C2C2;'>This is an automated, one-time e-mail sent by your WordPress CMS directly to the website admin</p><br />\n    <img width='0' height='0' src='https://www.google-analytics.com/collect?v=1&tid=UA-12964573-6&cid={$api_key}&t=event&ec=email&ea=open&el={$site_url}-{$api_key}&cs=lifecycle&cm=email&cn=wp_welcome_email' />";
     $headers = "From: Shareaholic <*****@*****.**>\r\n";
     $headers .= "Reply-To: Mary Anne <*****@*****.**>\r\n";
     $headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
     $headers .= "MIME-Version: 1.0\r\n";
     $headers .= "Content-type: text/html; charset=utf-8\r\n";
     if (function_exists('wp_mail')) {
         wp_mail($to, $subject, $message, $headers);
     }
 }
Esempio n. 27
0
?>
</span>
  
    <button class='app_wide_settings btn' data-href='monetizations/edit'><?php 
_e('Edit Monetization Settings', 'shareaholic');
?>
</button>
  
  </fieldset>
  </div>

  <div class="row" style="padding-top:20px; padding-bottom:35px; clear:both;">
    <div class="span2"><input type='submit' onclick="this.value='<?php 
echo sprintf(__('Saving Changes...', 'shareaholic'));
?>
';" value='<?php 
echo sprintf(__('Save Changes', 'shareaholic'));
?>
'></div>
  </div>
  </form>
</div>
<?php 
ShareaholicUtilities::load_template('why_to_sign_up', array('url' => Shareaholic::URL));
?>
</div>


<?php 
ShareaholicAdmin::show_footer();
ShareaholicAdmin::include_snapengage();
Esempio n. 28
0
 /**
  * Checks whether the api key has been verified
  * using the rails endpoint. Once the key has
  * been verified, we store that away so that we
  * don't have to check again.
  *
  * @return bool
  */
 public static function api_key_verified()
 {
     $settings = self::get_settings();
     if (isset($settings['api_key_verified']) && $settings['api_key_verified']) {
         return true;
     }
     $api_key = $settings['api_key'];
     if (!$api_key) {
         return false;
     }
     $response = drupal_http_request(self::API_URL . '/publisher_tools/' . $api_key . '/verified', array('method' => 'GET'));
     if (self::has_bad_response($response, 'FailedApiKeyVerified')) {
         return false;
     }
     $response = (array) $response;
     $result = $response['data'];
     if ($result == 'true') {
         ShareaholicUtilities::update_options(array('api_key_verified' => true));
         return true;
     }
     return false;
 }
Esempio n. 29
0
/**
 * Implements hook_node_insert().
 * When a node is created, notify CM to scrape its details
 * and clear FB cache
 *
 * @param $node The node that has been created
 */
function shareaholic_node_insert($node)
{
    ShareaholicContentSettings::insert($node);
    ShareaholicContentManager::single_page_worker($node);
    ShareaholicUtilities::clear_fb_opengraph($node);
}
Esempio n. 30
0
<!-- This site is powered by Shareaholic - https://shareaholic.com -->
<script type='text/javascript' data-cfasync='false'>
  //<![CDATA[
    _SHR_SETTINGS = <?php 
echo json_encode($base_settings);
?>
;

    (function() {
      var shr = document.createElement('script');
      shr.setAttribute('data-cfasync', 'false');
      shr.src = '<?php 
echo ShareaholicUtilities::asset_url('assets/pub/shareaholic.js');
?>
';
      shr.type = 'text/javascript'; shr.async = 'true';
      <?php 
echo $overrides;
?>

      shr.onload = shr.onreadystatechange = function() {
        var rs = this.readyState;
        if (rs && rs != 'complete' && rs != 'loaded') return;
        var site_id = '<?php 
echo $api_key;
?>
';
        try { Shareaholic.init(site_id); } catch (e) {}
      };
      var s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(shr, s);