Last active
July 20, 2016 13:42
-
-
Save mojowen/2033014 to your computer and use it in GitHub Desktop.
Prep Salsa Template for Facebook Sharing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// Default Values | |
var title = 'Welcome'; // What it should say on a page that it can't look up the information | |
var url = 'http://yoururl.org'; // Your base URL | |
var template = '00000'; //Your Template Key | |
var org = 'Your Organization'; //Your Org's Name | |
var chapter = '9999'; //If this is a chaptered page | |
var description = "Our slogan"; // Default description | |
var img = "https://www.google.com/images/srpr/logo3w.png"; //The default image | |
// Here we're checking to see if either the event_KEY or donate_page_KEY parameters are set in the URL | |
var eventkey =salsa.getParameter("event_KEY"); | |
var donatekey =salsa.getParameter("donate_page_KEY"); | |
var actionkey =salsa.getParameter("action_KEY"); | |
if( eventkey != false ) { | |
var event = DB.getObject('event', eventkey); | |
var title = event.Event_Name; | |
var url = 'https://salsa.wiredforchange.com/o/6121/c/'+chapter+'/t/'+template+'/p/salsa/event/common/public/?event_KEY='+eventkey; | |
var description = event.Description.stripTags(); | |
var img_fish = event.Description.match(/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\>]*)/i); | |
if( img_fish != null ) { | |
img = img_fish[1].replace(/ /,'%20'); | |
} | |
} | |
if( donatekey != false ) { | |
var donate_page = DB.getObject('donate_page', donatekey); | |
var title_fish = donate_page.Header.match(/<h1[^>]*>(.*?)<\/h1>/); | |
if( title_fish != null ) { | |
title = title_fish[1]; | |
} | |
var url = 'https://salsa.wiredforchange.com/o/6121/c/'+chapter+'/p/salsa/donation/common/public/?donate_page_KEY='+donatekey; | |
var description = donate_page.Header.stripTags(); | |
var img_fish = donate_page.Header.match(/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\>]*)/i); | |
if( img_fish != null ) { | |
img = img_fish[1].replace(/ /,'%20'); | |
} | |
} | |
if( actionkey != false ) { | |
var action_page = DB.getObject('action', actionkey); | |
var title = action_page.Title; | |
var url = 'http://salsa.wiredforchange.com/o/6121/c/'+chapter+'/p/dia/action/public/?action_KEY='+actionkey; | |
var description = action_page.Description.stripTags(); | |
var img_fish = action_page.Description.match(/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\>]*)/i); | |
if( img_fish != null ) { | |
img = img_fish[1].replace(/ /,'%20'); | |
} | |
} | |
// Ok, all done with Salsa extracting. Below I've used these extracted variables to set the title and other meta tags | |
?> | |
<title> <? print(title); ?> | <? print(org); ?> </title> | |
<meta property="og:title" content="<? print(title); ?> | <? print(org); ?> "/> | |
<meta property="og:type" content="non_profit"/> | |
<meta property="og:url" content="<? print(url); ?>"/> | |
<meta property="og:image" content="<? print(img); ?>"/> | |
<meta property="og:site_name" content="<? print(org); ?>"/> | |
<meta property="og:description" content="<? print(description); ?>"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment