public function get($class) { $full_class_name = 'PerchAPI_' . $class; switch ($class) { case 'DB': return PerchDB::fetch(); break; case 'Lang': if ($this->Lang === false) { $this->Lang = new $full_class_name($this->version, $this->app_id); } return $this->Lang; break; case 'Settings': return PerchSettings::fetch(); break; default: if ($this->Lang === false) { $this->Lang = new PerchAPI_Lang($this->version, $this->app_id); } return new $full_class_name($this->version, $this->app_id, $this->Lang); break; } return false; }
public static function fetch() { if (!isset(self::$instance)) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; }
public static function createGeocoder() { $PerchSettings = PerchSettings::fetch(); $apiKey = $PerchSettings->get('root_locator_google_api_key')->settingValue(); $httpAdapter = self::createHttpAdaptor(); $provider = new GoogleMaps($httpAdapter, null, null, true, $apiKey); return self::createGeocoderLibrary($provider); }
public function campaignURL() { $Settings = PerchSettings::fetch(); $url_template = $Settings->get('perch_mailchimp_campaign_url')->val(); $this->tmp_url_vars = $this->details; $out = preg_replace_callback('/{([A-Za-z0-9_\\-]+)}/', array($this, "substitute_url_vars"), $url_template); $this->tmp_url_vars = false; return $out; }
public function campaignURL() { $Settings = PerchSettings::fetch(); $url_template = $Settings->get('perch_mailchimp_campaign_url')->val(); $url_vars = $this->details; $out = preg_replace_callback('/{([A-Za-z0-9_\\-]+)}/', function ($matches) use($url_vars) { if (isset($url_vars[$matches[1]])) { return $url_vars[$matches[1]]; } }, $url_template); return $out; }
/** * Get an instance of the DrewM\MailChimp library */ protected function get_api_instance() { if (is_object($this->api_instance)) { return $this->api_instance; } $Settings = PerchSettings::fetch(); $api_key = $Settings->get('perch_mailchimp_api_key')->val(); $instance = new MailChimpAPI($api_key); if (is_object($instance)) { $instance->verify_ssl = false; $this->api_instance = $instance; return $instance; } return false; }
function __construct($version, $app_id = false) { $Settings = PerchSettings::fetch(); if (defined('PERCH_DB_DATABASE')) { $this->lang = $Settings->get('lang')->settingValue(); } if (!$this->lang) { $this->lang = 'en-gb'; } $ds = DIRECTORY_SEPARATOR; if (!$app_id) { $current_app = PerchUtil::get_current_app(); $path = $current_app['section']; } else { $path = 'addons' . $ds . 'apps' . $ds . $app_id; } $this->lang_dir = PERCH_PATH . $ds . $path . $ds . 'lang'; $this->lang_file = $this->lang_dir . $ds . $this->lang . '.txt'; }
public static function format_result($key, $options, $result) { $result['eventTitle'] = $result['col1']; $result['eventSlug'] = $result['col2']; $result['eventDateTime'] = $result['col3']; $result['eventDescHTML'] = $result['col4']; $result['eventID'] = $result['col5']; $result['_id'] = $result['col5']; $Settings = PerchSettings::fetch(); $html = PerchUtil::excerpt_char($result['eventDescHTML'], $options['excerpt-chars'], true); // keyword highlight $html = preg_replace('/(' . $key . ')/i', '<span class="keyword">$1</span>', $html); $match = array(); $match['url'] = $Settings->get('perch_events_detail_url')->settingValue(); self::$tmp_url_vars = $result; $match['url'] = preg_replace_callback('/{([A-Za-z0-9_\\-]+)}/', array('self', "substitute_url_vars"), $match['url']); self::$tmp_url_vars = false; $match['title'] = $result['eventTitle'] . ' - ' . strftime('%d %b %Y', strtotime($result['col3'])); $match['excerpt'] = $html; $match['key'] = $key; return $match; }
public static function format_result($key, $options, $result) { $result['campaignSubject'] = $result['col1']; $result['campaignSlug'] = $result['col2']; $result['campaignSendTime'] = $result['col3']; $result['campaignText'] = $result['col4']; $result['campaignID'] = $result['col5']; $result['_id'] = $result['col5']; $Settings = PerchSettings::fetch(); $html = PerchUtil::excerpt_char($result['campaignText'], $options['excerpt-chars'], true); // keyword highlight $html = preg_replace('/(' . $key . ')/i', '<span class="keyword">$1</span>', $html); $match = array(); $match['url'] = $Settings->get('perch_mailchimp_campaign_url')->settingValue(); self::$tmp_url_vars = $result; $match['url'] = preg_replace_callback('/{([A-Za-z0-9_\\-]+)}/', array('self', "substitute_url_vars"), $match['url']); self::$tmp_url_vars = false; $match['title'] = $result['campaignSubject']; $match['excerpt'] = $html; $match['key'] = $key; return $match; }
public function to_array($template_ids = false) { $out = parent::to_array(); $Categories = new PerchEvents_Categories(); $cats = $Categories->get_for_event($this->id()); $out['category_slugs'] = ''; $out['category_names'] = ''; if (PerchUtil::count($cats)) { $slugs = array(); $names = array(); foreach ($cats as $Category) { $slugs[] = $Category->categorySlug(); $names[] = $Category->categoryTitle(); // for template $out[$Category->categorySlug()] = true; } $out['category_slugs'] = implode(' ', $slugs); $out['category_names'] = implode(', ', $names); } if (PerchUtil::count($template_ids) && in_array('eventURL', $template_ids)) { $Settings = PerchSettings::fetch(); $url_template = $Settings->get('perch_events_detail_url')->val(); $this->tmp_url_vars = $out; $out['eventURL'] = preg_replace_callback('/{([A-Za-z0-9_\\-]+)}/', array($this, "substitute_url_vars"), $url_template); $this->tmp_url_vars = false; } if (isset($out['eventDynamicFields']) && $out['eventDynamicFields'] != '') { $dynamic_fields = PerchUtil::json_safe_decode($out['eventDynamicFields'], true); if (PerchUtil::count($dynamic_fields)) { foreach ($dynamic_fields as $key => $value) { $out['perch_' . $key] = $value; } } $out = array_merge($dynamic_fields, $out); } return $out; }
public function postURL() { $Settings = PerchSettings::fetch(); $url_template = $Settings->get('perch_blog_post_url')->val(); $this->tmp_url_vars = $this->details; if (!$this->Section) { $this->_load_section(); } if (is_object($this->Section)) { $this->tmp_url_vars = array_merge($this->tmp_url_vars, $this->Section->to_array()); } if (!$this->Blog) { $this->_load_blog(); } if (is_object($this->Blog)) { $this->tmp_url_vars = array_merge($this->tmp_url_vars, $this->Blog->to_array()); } $out = preg_replace_callback('/{([A-Za-z0-9_\\-]+)}/', array($this, "substitute_url_vars"), $url_template); $this->tmp_url_vars = false; return $out; }
$result = $Image->update($data); } else { if (isset($data['imageID'])) { unset($data['imageID']); } $result = $Images->create($data); if ($result) { $new_image = true; $Image = $result; } else { $message = $HTML->failure_message('Sorry, that image could not be updated.'); } } if ($result) { $bucket_name = 'default'; $Settings = PerchSettings::fetch(); $bucket_mode = $Settings->get('perch_gallery_bucket_mode')->val(); if ($bucket_mode == '') { $bucket_mode = 'single'; } switch ($bucket_mode) { case 'dynamic': $Album = $Albums->find($albumID); if (is_object($Album)) { $bucket_name = $Album->albumSlug(); } break; default: $bucket_name = $Settings->get('perch_gallery_bucket')->val(); break; }
private function activate() { /* Any attempt to circumvent activation invalidates your license. We're a small company trying to make something useful at a fair price. Please don't steal from us. */ $Perch = PerchAdmin::fetch(); $host = 'activation.grabaperch.com'; $path = '/activate/'; $url = 'http://' . $host . $path; $data = ''; $data['key'] = PERCH_LICENSE_KEY; $data['host'] = $_SERVER['SERVER_NAME']; $data['version'] = $Perch->version; $data['php'] = phpversion(); $content = http_build_query($data); $result = false; $use_curl = false; if (function_exists('curl_init')) { $use_curl = true; } if ($use_curl) { PerchUtil::debug('Activating via CURL'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $content); $result = curl_exec($ch); PerchUtil::debug($result); $http_status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_status != 200) { $result = false; PerchUtil::debug('Not HTTP 200: ' . $http_status); } curl_close($ch); } else { if (function_exists('fsockopen')) { PerchUtil::debug('Activating via sockets'); $fp = fsockopen($host, 80, $errno, $errstr, 10); if ($fp) { $out = "POST {$path} HTTP/1.1\r\n"; $out .= "Host: {$host}\r\n"; $out .= "Content-Type: application/x-www-form-urlencoded\r\n"; $out .= "Content-Length: " . strlen($content) . "\r\n"; $out .= "Connection: Close\r\n\r\n"; $out .= $content . "\r\n"; fwrite($fp, $out); stream_set_timeout($fp, 10); while (!feof($fp)) { $result .= fgets($fp, 128); } fclose($fp); } if ($result != '') { $parts = preg_split('/[\\n\\r]{4}/', $result); if (is_array($parts)) { $result = $parts[1]; } } } } // Should have a $result now if ($result) { $json = PerchUtil::json_safe_decode($result); if (is_object($json) && $json->result == 'SUCCESS') { // update latest version setting $Settings = new PerchSettings(); $Settings->set('latest_version', $json->latest_version); $Settings->set('on_sale_version', $json->on_sale_version); PerchUtil::debug($json); PerchUtil::debug('Activation: success'); return true; } else { PerchUtil::debug('Activation: failed'); $this->activation_failed = true; return false; } } // If activation can't complete, assume honesty. That's how I roll. return true; }
public function reload() { PerchUtil::debug('Reloading language data'); $Settings = PerchSettings::fetch(); $this->lang = $Settings->get('lang')->settingValue(); if (file_exists(PerchUtil::file_path(PERCH_PATH . '/addons/lang/' . $this->lang . '.txt'))) { $this->lang_dir = PerchUtil::file_path(PERCH_PATH . '/addons/lang'); } else { $this->lang_dir = PerchUtil::file_path(PERCH_CORE . '/lang'); } $this->lang_file = $this->lang_dir . DIRECTORY_SEPARATOR . $this->lang . '.txt'; $this->translations = false; }
private static function get_site_url() { $Settings = PerchSettings::fetch(); $siteURL = $Settings->get('siteURL')->settingValue(); if (substr($siteURL, 0, 4) != 'http') { $siteURL = 'http://' . $_SERVER['HTTP_HOST']; } return $siteURL; }
/** * Return google static map preview of coordinates * * @return bool|string */ public function preview() { $PerchSettings = PerchSettings::fetch(); $apiKey = $PerchSettings->get('root_locator_google_api_key')->settingValue(); if (!$this->hasCoordinates() || !$apiKey) { return false; } $base_url = 'https://maps.googleapis.com/maps/api/staticmap?'; $parameters = ['size' => '400x200', 'maptype' => 'roadmap', 'markers' => 'color:red|' . $this->addressLatitude() . ',' . $this->addressLongitude(), 'key' => $apiKey]; return '<img class="map-preview" src="' . $base_url . http_build_query($parameters) . '" />'; }
public static function get_helper_js() { $Settings = PerchSettings::fetch(); if ($Settings->get('content_frontend_edit')->val()) { $Content = PerchContent::fetch(); $Page = $Content->get_page(); $r = ''; if (is_object($Page)) { $r = '<script src="' . PERCH_LOGINPATH . '/core/assets/js/public_helper.js" async></script>'; $r .= '<script async>var cms_path=\'' . PerchUtil::html(PERCH_LOGINPATH . '/core/apps/content/page/?id=' . $Page->id()) . '\';</script>'; } return $r; } return false; }
public function render_settings($html) { if (strpos($html, 'perch:setting') !== false) { $Settings = PerchSettings::fetch(); $settings = $Settings->get_as_array(); $this->load($html); $this->namespace = 'setting'; $html = $this->render($settings); $s = '/<perch:setting[^>]*\\/>/s'; $html = preg_replace($s, '', $html); } return $html; }