Exemple #1
0
 /**
  * Gets the page configuration to be used by shareaholic.js
  *
  * This function returns a string representation of the page config object
  * which will be consumed by the shareaholic javascript.
  *
  * @return string The stringified version of the page config
  */
 public static function get_page_config()
 {
     $config = array('apps' => array(), 'endpoints' => array('local_recs_url' => admin_url('admin-ajax.php') . '?action=shareaholic_permalink_related', 'share_counts_url' => admin_url('admin-ajax.php') . '?action=shareaholic_share_counts_api'), 'user' => ShareaholicUtilities::user_info());
     $functions_map = self::get_function_definitions();
     $share_buttons = self::get_share_buttons_config();
     // if all the configurations are empty, return an empty JS object
     if (empty($share_buttons)) {
         return '{}';
     }
     $config['apps']['share_buttons'] = $share_buttons;
     // Get the json representation of the page configuration
     $json_string = json_encode($config);
     // Now iterate through the function mapping and do a string replace
     foreach ($functions_map as $placeholder => $implementation) {
         $json_string = str_replace('"' . $placeholder . '"', $implementation, $json_string);
     }
     return $json_string;
 }