public function set($file, $namespace, $default_fields = false)
 {
     $Perch = Perch::fetch();
     // called to make sure constants are defined.
     if ($file && substr($file, -5) !== '.html') {
         $file .= '.html';
     }
     $this->namespace = $namespace;
     if (strpos($file, '~') !== false) {
         $local_file = PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . substr($file, strpos($file, '~') + 1));
         $user_file = PerchUtil::file_path(PERCH_TEMPLATE_PATH . substr($file, strpos($file, 'templates') + 9));
     } else {
         $local_file = PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . $this->app_id . '/templates/' . $file);
         $user_file = PerchUtil::file_path(PERCH_TEMPLATE_PATH . '/' . $file);
     }
     if (file_exists($user_file)) {
         $template_file = $user_file;
     } else {
         $template_file = $local_file;
     }
     $this->Template = new PerchTemplate($template_file, $namespace, $relative_path = false);
     $this->Template->enable_encoding();
     $this->Template->apply_post_processing = true;
     if ($default_fields) {
         $this->Template->append($default_fields);
     }
     $this->file = $this->Template->file;
     return $this->Template->status;
 }
Exemple #2
0
function perch_get_javascript($opts = false, $return = false)
{
    $feathers = PerchSystem::get_registered_feathers();
    $out = '';
    if (PerchUtil::count($feathers)) {
        $count = PerchUtil::count($feathers);
        $i = 0;
        $components = array();
        foreach ($feathers as $feather) {
            $classname = 'PerchFeather_' . $feather;
            $Feather = new $classname($components);
            $out .= $Feather->get_javascript($opts, $i, $count);
            $components = $Feather->get_components();
            $i++;
        }
    }
    // Inject script when authed
    if (isset($_COOKIE['cmsa'])) {
        $out .= PerchSystem::get_helper_js();
    }
    if ($return) {
        return $out;
    }
    echo $out;
    PerchUtil::flush_output();
}
Exemple #3
0
 public function render_inputs($details = array())
 {
     if (!class_exists('PerchGallery_Albums')) {
         require_once PerchUtil::file_path(PERCH_PATH . '/addons/apps/perch_gallery/PerchGallery_Albums.class.php');
         require_once PerchUtil::file_path(PERCH_PATH . '/addons/apps/perch_gallery/PerchGallery_Album.class.php');
     }
     $id = $this->Tag->input_id();
     $val = '';
     if (isset($details[$id]) && $details[$id] != '') {
         $json = $details[$id];
         $val = $json['albumSlug'];
     }
     $API = new PerchAPI(1, 'perch_gallery');
     $Albums = new PerchGallery_Albums($API);
     $albums = $Albums->return_all();
     $opts = array();
     $opts[] = array('label' => '', 'value' => '');
     if (PerchUtil::count($albums)) {
         foreach ($albums as $Album) {
             $opts[] = array('label' => $Album->albumTitle(), 'value' => $Album->albumSlug());
         }
     }
     if (PerchUtil::count($opts)) {
         $s = $this->Form->select($id, $opts, $val);
     } else {
         $s = '-';
     }
     return $s;
 }
function perch_forms_form_handler($SubmittedForm)
{
    if ($SubmittedForm->validate()) {
        $API = new PerchAPI(1.0, 'perch_forms');
        $Forms = new PerchForms_Forms($API);
        $formKey = $SubmittedForm->id;
        $Form = $Forms->find_by_key($formKey);
        if (!is_object($Form)) {
            $data = array();
            $data['formKey'] = $formKey;
            $data['formTemplate'] = $SubmittedForm->templatePath;
            $data['formOptions'] = PerchUtil::json_safe_encode(array('store' => true));
            $attrs = $SubmittedForm->get_form_attributes();
            if ($attrs->label()) {
                $data['formTitle'] = $attrs->label();
            } else {
                $data['formTitle'] = PerchUtil::filename($formKey, false);
            }
            $Form = $Forms->create($data);
        }
        if (is_object($Form)) {
            $Form->process_response($SubmittedForm);
        }
    }
    $Perch = Perch::fetch();
    PerchUtil::debug($Perch->get_form_errors($SubmittedForm->formID));
}
 /**
  * @param string $address
  * @param int    $limit
  *
  * @return $this
  */
 public function geocode($address, $limit = 1)
 {
     try {
         $this->addresses = $this->geocoder->limit($limit)->geocode($address);
     } catch (\Geocoder\Exception\NoResult $ex) {
         $this->errorKey = 'no_results';
         $this->error = RootLocator_Errors::noResults();
         PerchUtil::debug(sprintf('Locator: %s', $ex->getMessage()), 'error');
     } catch (\Geocoder\Exception\HttpError $ex) {
         $this->errorKey = 'http_error';
         $this->error = RootLocator_Errors::httpError();
         PerchUtil::debug(sprintf('Locator: %s', $ex->getMessage()), 'error');
     } catch (\Geocoder\Exception\InvalidCredentials $ex) {
         $this->errorKey = 'invalid_credentials';
         $this->error = RootLocator_Errors::invalidCredentials();
         PerchUtil::debug(sprintf('Locator: %s', $ex->getMessage()), 'error');
     } catch (\Geocoder\Exception\QuotaExceeded $ex) {
         $this->errorKey = 'quota_exceeded';
         $this->error = RootLocator_Errors::quotaExceeded();
         PerchUtil::debug(sprintf('Locator: %s', $ex->getMessage()), 'error');
     } catch (Exception $ex) {
         $this->errorKey = 'unknown';
         $this->error = RootLocator_Errors::unknown();
         PerchUtil::debug(sprintf('Locator: %s', $ex->getMessage()), 'error');
     }
     return $this;
 }
 public function update_tree_position($pageID, $parentID, $order = false)
 {
     PerchUtil::debug('updating tree position');
     $sql = 'SELECT * FROM ' . PERCH_DB_PREFIX . 'navigation_pages
 			WHERE groupID=' . $this->db->pdb((int) $this->id()) . ' AND pageID=' . $this->db->pdb((int) $parentID) . '
 			LIMIT 1';
     $parentPage = $this->db->get_row($sql);
     $data = array();
     $data['pageParentID'] = $parentID;
     if ($order === false) {
         if (is_array($parentPage)) {
             $sql = 'SELECT MAX(pageOrder) FROM ' . PERCH_DB_PREFIX . 'navigation_pages WHERE pageParentID=' . $this->db->pdb((int) $parentID);
         } else {
             $sql = 'SELECT MAX(pageOrder) FROM ' . PERCH_DB_PREFIX . 'navigation_pages WHERE pageParentID=0';
         }
         $max = $this->db->get_count($sql);
         $max = (int) $max + 1;
     } else {
         $data['pageOrder'] = $order;
     }
     if (is_array($parentPage)) {
         $data['pageDepth'] = (int) $parentPage['pageDepth'] + 1;
         $data['pageTreePosition'] = $parentPage['pageTreePosition'] . '-' . str_pad($data['pageOrder'], 3, '0', STR_PAD_LEFT);
     } else {
         PerchUtil::debug('Could not find parent page');
         $data['pageDepth'] = 1;
         $data['pageTreePosition'] = '000-' . str_pad($data['pageOrder'], 3, '0', STR_PAD_LEFT);
     }
     $sql = 'SELECT navpageID FROM ' . PERCH_DB_PREFIX . 'navigation_pages 
     		WHERE groupID=' . $this->db->pdb((int) $this->id()) . ' AND pageID=' . $this->db->pdb((int) $pageID) . '
     		LIMIT 1';
     $pk = $this->db->get_value($sql);
     $this->db->update(PERCH_DB_PREFIX . 'navigation_pages', $data, 'navpageID', $pk);
 }
 public function run()
 {
     $result = false;
     switch ($this->importType()) {
         case 'subscribers':
             $Subscribers = new PerchMailChimp_Subscribers($this->api);
             $result = $Subscribers->import_next($this);
             break;
         case 'campaigns':
             $Campaigns = new PerchMailChimp_Campaigns($this->api);
             $result = $Campaigns->import_next($this);
             break;
         case 'webhooks':
             $Webhooks = new PerchMailChimp_Webhooks($this->api);
             $result = $Webhooks->import_next($this);
             break;
     }
     if ($result && $result['result'] == 'success') {
         if ($result['count'] < $this->importCount()) {
             // looks like that's all the pages, so self-delete.
             PerchUtil::debug('Result count is ' . $result['count']);
             PerchUtil::debug('Import count is ' . $this->importCount());
             PerchUtil::debug('Deleting.');
             $this->delete();
             return;
         }
         $this->update(['importOffset' => $this->importOffset() + $this->importCount()]);
         return $result;
     }
     return $result;
 }
 public function import()
 {
     $MailChimpAPI = $this->get_api_instance();
     $lists = $MailChimpAPI->get("lists");
     if ($MailChimpAPI->success()) {
         if (isset($lists['lists']) && PerchUtil::count($lists['lists'])) {
             $all_lists = $lists['lists'];
             foreach ($all_lists as $list) {
                 $data = $this->map_fields($list);
                 if (!$this->remote_list_exists_locally($list['id'])) {
                     PerchUtil::debug('Importing list: ' . $list['id']);
                     $this->create($data);
                 } else {
                     $Lists = new PerchMailChimp_Lists($this->api);
                     $List = $Lists->get_one_by('listMailChimpID', $list['id']);
                     if ($List) {
                         $List->update($data);
                     }
                 }
             }
         }
     } else {
         PerchUtil::debug($MailChimpAPI->getLastResponse(), 'error');
     }
 }
 public function form_login($SubmittedForm)
 {
     $email = isset($SubmittedForm->data['email']) ? $SubmittedForm->data['email'] : false;
     $clear_pwd = isset($SubmittedForm->data['password']) ? $SubmittedForm->data['password'] : false;
     if (!$email || !$clear_pwd) {
         PerchUtil::debug('Email or password not send.', 'error');
         return false;
     }
     $sql = 'SELECT * FROM ' . $this->table . ' WHERE memberAuthType=\'native\' AND memberEmail=' . $this->db->pdb($email) . ' AND memberStatus=\'active\' AND (memberExpires IS NULL OR memberExpires>' . $this->db->pdb(date('Y-m-d H:i:s')) . ') LIMIT 1';
     $result = $this->db->get_row($sql);
     if (PerchUtil::count($result)) {
         if (strlen($clear_pwd) > 72) {
             return false;
         }
         $stored_password = $result['memberPassword'];
         // check which type of password - default is portable
         if (defined('PERCH_NONPORTABLE_HASHES') && PERCH_NONPORTABLE_HASHES) {
             $portable_hashes = false;
         } else {
             $portable_hashes = true;
         }
         $Hasher = new PasswordHash(8, $portable_hashes);
         if ($Hasher->CheckPassword($clear_pwd, $stored_password)) {
             PerchUtil::debug('Password is ok.', 'auth');
             $user_row = $this->verify_user('native', $result['memberAuthID']);
             return $user_row;
         } else {
             PerchUtil::debug('Password failed to match.', 'auth');
             return false;
         }
     } else {
         PerchUtil::debug('User not found.', 'auth');
     }
     return false;
 }
Exemple #10
0
 private function _compile_stylesheet($file)
 {
     PerchUtil::debug('Compiling SASS file: ' . $file, 'notice');
     if (!$this->_site_path) {
         $login_path_parts = explode('/', PERCH_LOGINPATH);
         $path_parts = explode(DIRECTORY_SEPARATOR, PERCH_PATH);
         foreach ($login_path_parts as $part) {
             if ($part != '') {
                 array_pop($path_parts);
             }
         }
         $path = implode(DIRECTORY_SEPARATOR, $path_parts);
         $this->_site_path = $path;
     }
     $compiled_name = PerchUtil::file_path(PERCH_RESFILEPATH . '/' . $this->_get_compiled_name($file));
     include_once 'SassParser.php';
     $syntax = substr($file, -4, 4);
     $options = array('style' => 'expanded', 'cache' => FALSE, 'syntax' => $syntax, 'debug' => FALSE, 'callbacks' => array('warn' => 'warn', 'debug' => 'debug'));
     // Execute the compiler.
     $parser = new SassParser($options);
     try {
         file_put_contents($compiled_name, $parser->toCss(PerchUtil::file_path($this->_site_path . $file)));
     } catch (Exception $e) {
         PerchUtil::debug($e->getMessage(), 'error');
     }
 }
 public function render_inputs($details = array())
 {
     $id = $this->Tag->input_id();
     $val = '';
     if (isset($details[$id]) && $details[$id] != '') {
         $json = $details[$id];
         $val = $json['tag'];
     }
     $DB = PerchDB::fetch();
     $sql = 'SELECT * FROM ' . PERCH_DB_PREFIX . 'members_tags ORDER BY tagDisplay';
     $memberTags = $DB->get_rows($sql);
     $opts = array();
     $opts[] = array('label' => '', 'value' => '');
     if (PerchUtil::count($memberTags)) {
         foreach ($memberTags as $memberTag) {
             $opts[] = array('label' => $memberTag['tagDisplay'], 'value' => $memberTag['tag']);
         }
     }
     if (PerchUtil::count($opts)) {
         $s = $this->Form->select($id, $opts, $val);
     } else {
         $s = '-';
     }
     return $s;
 }
 public function get_index($items)
 {
     if (PerchUtil::count($items) && PerchUtil::count($this->tags)) {
         $index = array();
         foreach ($this->tags as $Tag) {
             $FieldType = PerchFieldTypes::get($Tag->type(), false, $Tag);
             foreach ($items as $item) {
                 foreach ($item as $key => $val) {
                     if ($key == $Tag->id()) {
                         $field_index = $FieldType->get_index($val);
                         if (PerchUtil::count($field_index)) {
                             foreach ($field_index as $field_index_item) {
                                 if ($key == $field_index_item['key']) {
                                     $indexing_key = $this->id() . '.' . $key;
                                 } else {
                                     $indexing_key = $this->id() . '.' . $key . '.' . $field_index_item['key'];
                                 }
                                 $index[] = array('key' => $indexing_key, 'value' => $field_index_item['value']);
                             }
                         }
                     }
                 }
             }
         }
         return $index;
     }
     return false;
 }
 /**
  * Return property from the userAccountData json store
  * with an optional default for missing values
  *
  * @param $key
  * @param null $default
  * @return null
  */
 public function userProperty($key, $default = null)
 {
     $accountData = PerchUtil::json_safe_decode($this->userAccountData(), true);
     if (isset($accountData[$key]) && $accountData[$key]) {
         return $accountData[$key];
     }
     return $default;
 }
 public function to_array($template_ids = false)
 {
     $out = parent::to_array();
     if (PerchUtil::count($template_ids) && in_array('campaignURL', $template_ids)) {
         $out['campaignURL'] = $this->campaignURL();
     }
     return $out;
 }
 /**
  * Return a list of icon files as an array
  *
  * @return array
  */
 public function icons()
 {
     $return = array();
     foreach ($this->iconMap as $event => $filename) {
         $return[$event] = PerchUtil::file_path($this->api->app_path() . '/' . $this->icon_dir . '/' . $filename . $this->icon_ext);
     }
     return $return;
 }
 public static function expire_all()
 {
     $files = glob(PerchUtil::file_path(PERCH_RESFILEPATH . '/perch_blog.*.cache'));
     if (PerchUtil::count($files)) {
         foreach ($files as $filename) {
             unlink($filename);
         }
     }
 }
 public function update_all_in_set()
 {
     $Categories = new PerchCategories_Categories();
     $categories = $Categories->get_by('setID', $this->id());
     if (PerchUtil::count($categories)) {
         foreach ($categories as $Cat) {
             $Cat->update_meta(false);
         }
     }
 }
Exemple #18
0
function listing_form_handler($SubmittedForm)
{
    if ($SubmittedForm->formID == 'listing' && $SubmittedForm->validate()) {
        $API = new PerchAPI(1.0, 'listing');
        $Listings = new Listings($API);
        $Listings->receive_new_listing($SubmittedForm);
    }
    $Perch = Perch::fetch();
    PerchUtil::debug($Perch->get_form_errors($SubmittedForm->formID));
}
 public function __construct($args)
 {
     if (PerchUtil::count($args)) {
         $this->event = array_shift($args);
         $this->subject = array_shift($args);
         $this->args = $args;
         $Users = new PerchUsers();
         $this->user = $Users->get_current_user();
     }
 }
Exemple #20
0
function perch_mailchimp_form_handler($SubmittedForm)
{
    if ($SubmittedForm->validate()) {
        $API = new PerchAPI(1.0, 'perch_mailchimp');
        $Subscribers = new PerchMailChimp_Subscribers($API);
        $Subscribers->subscribe_from_form($SubmittedForm);
    }
    $Perch = Perch::fetch();
    PerchUtil::debug($Perch->get_form_errors($SubmittedForm->formID));
}
 /**
  * Parse a string of entered tags (e.g. "this, that, the other") into an array of tags
  * @param  [type] $str [description]
  * @return [type]      [description]
  */
 public function parse_string($str)
 {
     $tags = explode(',', $str);
     $out = array();
     if (PerchUtil::count($tags)) {
         foreach ($tags as $tag) {
             $out[] = array('tag' => PerchUtil::urlify(trim($tag)), 'tagDisplay' => trim($tag));
         }
     }
     return $out;
 }
 public function display_name()
 {
     $out = '';
     if (strpos($this->templatePath(), '/') !== false) {
         $segments = explode('/', $this->templatePath());
         array_pop($segments);
         $out .= PerchUtil::filename(implode('/', $segments)) . ' → ';
     }
     $out .= $this->templateTitle();
     return $out;
 }
 public static function load_bucket_list()
 {
     $bucket_list_file = PerchUtil::file_path(PERCH_PATH . '/config/buckets.php');
     if (file_exists($bucket_list_file)) {
         self::$bucket_list = (include $bucket_list_file);
         if (self::$bucket_list == false) {
             self::$bucket_list = array();
         }
     } else {
         self::$bucket_list = array();
     }
 }
 /**
  * Fetch the unique stored users from the database and
  * decode the stored user data.
  *
  * @return array
  */
 public function get_stored_users_unique()
 {
     $return = array();
     $sql = "SELECT `userAccountData` FROM " . $this->table . " GROUP BY `userAccountID` ORDER BY `actionDateTime` DESC";
     $results = $this->db->get_rows($sql);
     if (PerchUtil::count($results)) {
         foreach ($results as $row) {
             $return[] = PerchUtil::json_safe_decode($row['userAccountData'], true);
         }
     }
     return $return;
 }
 public function output($return = false)
 {
     $alerts = $this->alerts;
     $s = '';
     for ($i = 0; $i < PerchUtil::count($alerts); $i++) {
         $s .= '<p class="alert ' . $alerts[$i]['type'] . '">' . $alerts[$i]['message'] . '</p>';
     }
     $this->alerts = array();
     if ($return) {
         return $s;
     }
     echo $s;
 }
 public function to_array($template_ids = false)
 {
     $out = parent::to_array();
     if (PerchUtil::count($template_ids) && in_array('campaignURL', $template_ids)) {
         $out['campaignURL'] = $this->campaignURL();
     }
     $Lists = new PerchMailChimp_Lists($this->api);
     $List = $Lists->find((int) $this->listID());
     if ($List) {
         $out = array_merge($out, $List->to_array());
     }
     return $out;
 }
 /**
  * Shift all users of this role over to the new role given.
  *
  * @param string $new_roleID 
  * @return void
  * @author Drew McLellan
  */
 public function migrate_users($new_roleID)
 {
     $Users = new PerchUsers();
     $users = $Users->get_by_role($this->id());
     $data = array();
     $data['roleID'] = $new_roleID;
     if (PerchUtil::count($users)) {
         foreach ($users as $User) {
             $User->update($data);
         }
     }
     return true;
 }
 public function delete()
 {
     if ($this->clean_resources && !$this->resourceInLibrary()) {
         $Perch = Perch::fetch();
         $bucket = $Perch->get_resource_bucket($this->resourceBucket());
         $file_path = PerchUtil::file_path($bucket['file_path'] . '/' . $this->resourceFile());
         if (file_exists($file_path) && !is_dir($file_path)) {
             unlink($file_path);
             PerchUtil::debug('Deleting resource: ' . $file_path);
         }
     }
     return parent::delete();
 }
 public function find_or_create($slug, $title)
 {
     $sql = 'SELECT * FROM ' . $this->table . ' WHERE tagSlug=' . $this->db->pdb($slug) . ' LIMIT 1';
     $row = $this->db->get_row($sql);
     if (PerchUtil::count($row)) {
         return $this->return_instance($row);
     }
     // Tag wasn't found, so create a new one and return it.
     $data = array();
     $data['tagSlug'] = $slug;
     $data['tagTitle'] = $title;
     return $this->create($data);
 }
Exemple #30
0
function perch_category($path, $opts = array(), $return = false)
{
    $path = rtrim(ltrim($path, '/'), '/') . '/';
    $opts = PerchUtil::extend(array('set' => false, 'skip-template' => false, 'template' => 'category.html', 'filter' => 'catPath', 'match' => 'eq', 'value' => $path), $opts);
    $Categories = new PerchCategories_Categories();
    $r = $Categories->get_custom($opts);
    if ($opts['skip-template']) {
        $return = true;
    }
    if ($return) {
        return $r;
    }
    echo $r;
}