public static function fetch()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
 public function render_runtime($contents, $Template)
 {
     if (strpos($contents, 'perch:member') !== false) {
         //PerchUtil::debug(PerchUtil::html($contents));
         $Session = PerchMembers_Session::fetch();
         $this->Session = $Session;
         // CONTENT
         $contents = $Template->replace_content_tags('member', $Session->to_array(), $contents);
         // Clean up
         $s = '/<perch:member\\s[^>]*\\/>/';
         $contents = preg_replace($s, '', $contents);
         // CONDITIONALS
         $content_vars = array('foo' => 'bar');
         $index_in_group = 0;
         $contents = $this->parse_paired_tags('member', false, $contents, $content_vars, $index_in_group, 'parse_conditional');
     }
     return $contents;
 }
 public function change_password($SubmittedForm)
 {
     $data = $SubmittedForm->data;
     if (isset($data['old_password']) && isset($data['password'])) {
         $old_clear_pwd = $data['old_password'];
         $new_clear_pwd = $data['password'];
         // check existing password
         $API = new PerchAPI(1.0, 'perch_members');
         $Session = PerchMembers_Session::fetch();
         $PerchMembers_Auth = new PerchMembers_Auth($API);
         $new_password = $PerchMembers_Auth->encrypt_new_password($Session->get('memberID'), $old_clear_pwd, $new_clear_pwd);
         if ($new_password) {
             $this->update(array('memberPassword' => $new_password));
             return true;
         } else {
             $SubmittedForm->throw_error('valid', 'old_password');
             return false;
         }
     }
     return false;
 }
 public function log_out()
 {
     $Session = PerchMembers_Session::fetch();
     $session_id = $Session->get('sessionID');
     $Session->logged_in = false;
     $Session->load(array());
     $this->_destroy_session($session_id);
     return;
 }
Exemplo n.º 5
0
 public function receive_new_listing($SubmittedForm)
 {
     $API = new PerchAPI(1.0, 'perch_members');
     $Session = PerchMembers_Session::fetch();
     $input = $SubmittedForm->data;
     $data = array();
     $data['listingDateTime'] = date('Y-m-d H:i:s');
     $data['memberID'] = $Session->get('memberID');
     $data['listingType'] = $input['listingType'];
     $data['listingTitle'] = $input['listingTitle'];
     $data['listingSlug'] = PerchUtil::urlify($input['listingTitle']);
     foreach ($this->static_fields as $field) {
         if (!isset($data[$field])) {
             if (isset($input[$field]) && $input[$field] != '') {
                 $data[$field] = trim($input[$field]);
             }
         }
     }
     // dynamic fields
     $dynamic_fields = array();
     foreach ($input as $field => $val) {
         if (!isset($data[$field])) {
             $dynamic_fields[$field] = trim($val);
         }
     }
     $data['listingDynamicFields'] = PerchUtil::json_safe_encode($dynamic_fields);
     foreach ($data as $key => $val) {
         switch ($key) {
             case 'listingHTML':
                 if (!class_exists('\\Netcarver\\Textile\\Parser', false) && class_exists('Textile', true)) {
                     // sneaky autoloading hack
                 }
                 if (PERCH_HTML5) {
                     $Textile = new \Netcarver\Textile\Parser('html5');
                 } else {
                     $Textile = new \Netcarver\Textile\Parser();
                 }
                 if (PERCH_RWD) {
                     $val = $Textile->setDimensionlessImages(true)->textileRestricted($val);
                 } else {
                     $val = $Textile->textileRestricted($val);
                 }
                 if (defined('PERCH_XHTML_MARKUP') && PERCH_XHTML_MARKUP == false) {
                     $val = str_replace(' />', '>', $val);
                 }
                 break;
         }
         $data[$key] = $val;
     }
     // print_r($data);
     // die();
     if (isset($data['listingID'])) {
         if ($this->check_title_exists($data['listingTitle'], $data['listingID'])) {
             $Listings = new Listings($API);
             $Listing = $Listings->find($data['listingID']);
             // Don't allow people to change their URL
             unset($data['listingSlug']);
             $r = $Listing->update($data);
         } else {
             $SubmittedForm->throw_error('duplicate', 'listingTitle');
             return false;
         }
     } else {
         if ($this->check_title_exists($data['listingTitle'])) {
             $r = $this->create($data);
         } else {
             $SubmittedForm->throw_error('duplicate', 'listingTitle');
             return false;
         }
     }
     return $r;
     PerchUtil::debug('this' . $SubmittedForm);
 }
Exemplo n.º 6
0
function perch_member_form($template, $return = false)
{
    $API = new PerchAPI(1.0, 'perch_members');
    $Template = $API->get('Template');
    $Template->set(PerchUtil::file_path('members/forms/' . $template), 'forms');
    $Session = PerchMembers_Session::fetch();
    $data = $Session->to_array();
    $html = $Template->render($data);
    $html = $Template->apply_runtime_post_processing($html, $data);
    if ($return) {
        return $html;
    }
    echo $html;
}
Exemplo n.º 7
0
function listings_for_member($listingType, $opts = false, $return = false)
{
    $API = new PerchAPI(1.0, 'listing');
    $Session = PerchMembers_Session::fetch();
    $defaults = array();
    $defaults['template'] = 'listings_list.html';
    $defaults['count'] = false;
    $defaults['sort'] = 'listingDateTime';
    $defaults['sort-order'] = 'ASC';
    $defaults['paginate'] = false;
    $defaults['pagination-var'] = 'page';
    // $defaults['filter']          = 'filter';
    // $defaults['value']           = $Session->get('memberID');
    if (is_array($opts)) {
        $opts = array_merge($defaults, $opts);
    } else {
        $opts = $defaults;
    }
    $Listings = new Listings($API);
    $r = $Listings->get_custom($listingType, $opts);
    if ($return) {
        return $r;
    }
    echo $r;
}
Exemplo n.º 8
0
function perch_pages_navigation($opts = array(), $return = false)
{
    $Pages = new PerchContent_Pages();
    $Perch = Perch::fetch();
    // translate renamed options from Perch v1
    if (isset($opts['from_path'])) {
        $opts['from-path'] = $opts['from_path'];
    }
    if (isset($opts['hide_extensions'])) {
        $opts['hide-extensions'] = $opts['hide_extensions'];
    }
    $default_opts = array('from-path' => '/', 'levels' => 0, 'hide-extensions' => false, 'hide-default-doc' => true, 'flat' => false, 'template' => array('item.html'), 'include-parent' => false, 'skip-template' => false, 'siblings' => false, 'only-expand-selected' => false, 'add-trailing-slash' => false, 'navgroup' => false, 'access-tags' => false, 'include-hidden' => false, 'from-level' => false, 'use-attributes' => true);
    if (class_exists('PerchMembers_Session')) {
        $Session = PerchMembers_Session::fetch();
        if ($Session->logged_in) {
            $default_opts['access-tags'] = $Session->get_tags();
        }
    }
    if (is_array($opts)) {
        $opts = array_merge($default_opts, $opts);
    } else {
        $opts = $default_opts;
    }
    if ($opts['skip-template']) {
        $return = true;
    }
    $current_page = $Perch->get_page();
    if ($opts['from-path'] == '*') {
        $opts['from-path'] = $current_page;
    }
    $r = $Pages->get_navigation($opts, $current_page);
    if ($return) {
        return $r;
    }
    echo $r;
    PerchUtil::flush_output();
}