public function __call($method, $arguments)
 {
     if (isset($this->details[$method])) {
         return $this->details[$method];
     } else {
         // check for Author details
         if (substr($method, 0, 6) == 'author') {
             if (!$this->Author) {
                 $this->_load_author();
             }
             if (is_object($this->Author)) {
                 return $this->Author->{$field}();
             }
         }
         // look in dynamic fields
         $dynamic_fields = PerchUtil::json_safe_decode($this->postDynamicFields(), true);
         if (isset($dynamic_fields[$method])) {
             return $dynamic_fields[$method];
         }
         // try database
         PerchUtil::debug('Looking up missing property ' . $method, 'notice');
         if (isset($this->details[$this->pk])) {
             $sql = 'SELECT ' . $method . ' FROM ' . $this->table . ' WHERE ' . $this->pk . '=' . $this->db->pdb($this->details[$this->pk]);
             $this->details[$method] = $this->db->get_value($sql);
             return $this->details[$method];
         }
     }
     return false;
 }
    public function get_processed($raw = false)
    {
        PerchUtil::debug($raw);
        $html = '<div id="simona_piechart_' . $raw['chart_id'] . '" style="min-height: 60px;"></div>';
        $is3d = $raw['is3d'] ? 'true' : 'false';
        $r = '<script type="text/javascript">/* <![CDATA[ */ ';
        $r .= <<<EOT
if (typeof CMSPieChart =='undefined') {
  var CMSPieChart={};
  CMSPieChart.charts=[];
  document.write('<scr'+'ipt type="text\\/javascript" src="{$this->_location}js/simona_piechart_public.js"><'+'\\/sc'+'ript>');
}
CMSPieChart.charts.push({
  'chart_id':'simona_piechart_{$raw['chart_id']}',
  'title':'{$raw['title']}',
  'data':'{$raw['data']}',
  'width':'{$raw['width']}',
  'height':'{$raw['height']}',
  'is3d':{$is3d},
});
EOT;
        $r .= '/* ]]> */';
        $r .= '</script>';
        $out = $html . $r;
        return $out;
    }
 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);
 }
 /**
  * @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 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');
     }
 }
Beispiel #6
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 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;
 }
 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;
 }
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));
}
Beispiel #10
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));
}
Beispiel #11
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));
}
function perch_members_form_handler($SubmittedForm)
{
    if ($SubmittedForm->validate()) {
        $API = new PerchAPI(1.0, 'perch_members');
        switch ($SubmittedForm->formID) {
            case 'login':
                $PerchMembers_Auth = new PerchMembers_Auth($API);
                if (!$PerchMembers_Auth->handle_login($SubmittedForm)) {
                    $SubmittedForm->throw_error('login');
                }
                break;
            case 'profile':
                $Session = PerchMembers_Session::fetch();
                if ($Session->logged_in && $Session->get('token') == $SubmittedForm->data['token']) {
                    $Members = new PerchMembers_Members($API);
                    if (is_object($Members)) {
                        $Member = $Members->find($Session->get('memberID'));
                    }
                    if (is_object($Member)) {
                        $Member->update_profile($SubmittedForm);
                        $PerchMembers_Auth = new PerchMembers_Auth($API);
                        $PerchMembers_Auth->refresh_session_data($Member);
                    }
                } else {
                    $SubmittedForm->throw_error('login');
                }
                break;
            case 'register':
                $Members = new PerchMembers_Members($API);
                $Members->register_with_form($SubmittedForm);
                break;
            case 'reset':
                $Members = new PerchMembers_Members($API);
                $Members->reset_member_password($SubmittedForm);
                break;
            case 'password':
                $Session = PerchMembers_Session::fetch();
                if ($Session->logged_in && $Session->get('token') == $SubmittedForm->data['token']) {
                    $Members = new PerchMembers_Members($API);
                    if (is_object($Members)) {
                        $Member = $Members->find($Session->get('memberID'));
                    }
                    if (is_object($Member)) {
                        $Member->change_password($SubmittedForm);
                    }
                } else {
                    $SubmittedForm->throw_error('login');
                }
                break;
        }
    }
    $Perch = Perch::fetch();
    PerchUtil::debug($Perch->get_form_errors($SubmittedForm->formID));
}
 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 attempt_install()
 {
     PerchUtil::debug('Attempting app installation: ' . $this->api->app_id);
     $sql = 'SHOW TABLES LIKE "' . $this->table . '"';
     $result = $this->db->get_value($sql);
     if ($result == false) {
         $activation_file = PerchUtil::file_path(PERCH_PATH . '/addons/apps/' . $this->api->app_id . '/activate.php');
         if (file_exists($activation_file)) {
             $API = $this->api;
             return include $activation_file;
         }
     }
     return false;
 }
function perch_comments_form_handler($SubmittedForm)
{
    if ($SubmittedForm->formID == 'comment' && $SubmittedForm->validate()) {
        $API = new PerchAPI(1.0, 'perch_comments');
        $Comments = new PerchComments_Comments($API);
        $Comments->receive_new_comment($SubmittedForm);
    }
    if ($SubmittedForm->formID == 'vote' && $SubmittedForm->validate()) {
        $API = new PerchAPI(1.0, 'perch_comments');
        $Comments = new PerchComments_Comments($API);
        $Comments->receive_new_vote($SubmittedForm);
    }
    $Perch = Perch::fetch();
    PerchUtil::debug($Perch->get_form_errors($SubmittedForm->formID));
}
 public function parse_string_to_ids($tag_string)
 {
     $tags = $this->_tag_parse($tag_string);
     PerchUtil::debug($tags);
     $ids = array();
     if (PerchUtil::count($tags)) {
         foreach ($tags as $tag) {
             $Tag = $this->find_or_create(PerchUtil::urlify($tag), $tag);
             if ($Tag) {
                 $ids[] = $Tag->id();
             }
         }
     }
     return $ids;
 }
 private function issue_ban_request($url, $pattern)
 {
     PerchUtil::debug('Varnish banning page: ' . $url . $pattern);
     try {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url . $pattern);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "BAN");
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_exec($ch);
         curl_close($ch);
     } catch (Exception $e) {
         PerchUtil::debug($e->getMessage(), 'error');
         return false;
     }
     return true;
 }
 /**
  *
  */
 public function populate($api_key, $list_id, $echo_feedback = false)
 {
     $MailChimp = new MailChimp($api_key);
     if ($echo_feedback) {
         $API = new PerchAPI(1.0, 'perch_mailchimp');
         $Lang = $API->get('Lang');
     }
     $opts = array('apikey' => $api_key, 'filters' => array('list_id' => $list_id));
     $result = $MailChimp->call('lists/list', $opts);
     if ($result) {
         $this->db->execute('TRUNCATE TABLE ' . $this->table);
         //store title in data array
         $stats_array = array('title' => $result['data'][0]['name'], 'total' => $result['data'][0]['stats']['member_count']);
         $list_opts = array('apikey' => $api_key, 'id' => $list_id);
         $activity = $MailChimp->call('lists/activity', $list_opts);
         PerchUtil::debug($activity);
         foreach ($activity as $stat) {
             if ($stat['day'] == date('Y-m-d', strtotime('-1 days'))) {
                 $stats_array['yesterday'] = $stat['subs'] + $stat['other_adds'];
             } elseif ($stat['day'] == date('Y-m-d')) {
                 $stats_array['today'] = $stat['subs'] + $stat['other_adds'];
             }
         }
         //insert stats array
         $this->db->insert($this->table, $stats_array);
         if ($echo_feedback) {
             echo '<li class="icon success">';
             echo $Lang->get('Importing statistics for list %s', $list_id);
             echo '</li>';
             flush();
         }
         // history table
         $sql = 'SELECT * FROM ' . PERCH_DB_PREFIX . 'mailchimp_history WHERE historyDate = ' . $this->db->pdb(date('Y-m-d', strtotime('-1 days'))) . ' LIMIT 1';
         if (!($row = $this->db->get_row($sql))) {
             //insert a row for yesterday
             $history_data = array('historyDate' => date('Y-m-d', strtotime('-1 days')), 'historyTotal' => $stats_array['yesterday']);
             $this->db->insert(PERCH_DB_PREFIX . 'mailchimp_history', $history_data);
             if ($echo_feedback) {
                 echo '<li class="icon success">';
                 echo $Lang->get('Importing history for list %s', $list_id);
                 echo '</li>';
                 flush();
             }
         }
     }
     return true;
 }
 function __call($method, $arguments)
 {
     if (isset($this->details[$method])) {
         return $this->details[$method];
     } else {
         PerchUtil::debug('Looking up missing property ' . $method, 'notice');
         $array = $this->to_array();
         if (isset($array[$method])) {
             return $array[$method];
         }
         if (isset($this->details[$this->pk])) {
             $sql = 'SELECT ' . $method . ' FROM ' . $this->table . ' WHERE ' . $this->pk . '=' . $this->db->pdb($this->details[$this->pk]);
             $this->details[$method] = $this->db->get_value($sql);
             return $this->details[$method];
         }
     }
     return false;
 }
 public static function submit_spam($key, $fields, $environment)
 {
     self::$apiKey = $key;
     PerchUtil::debug('Submitting spam to Akismet');
     $Perch = Perch::fetch();
     $data = array();
     $data['blog'] = self::get_site_url();
     $data['user_ip'] = $environment['REMOTE_ADDR'];
     $data['user_agent'] = $environment['HTTP_USER_AGENT'];
     $data['referrer'] = $environment['HTTP_REFERER'];
     //$data['permalink']            = $Perch->get_page();
     $data['comment_type'] = 'comment';
     $data['comment_author'] = isset($fields['name']) ? $fields['name'] : '';
     $data['comment_author_email'] = isset($fields['email']) ? $fields['email'] : '';
     $data['comment_author_url'] = isset($fields['url']) ? $fields['url'] : '';
     $data['comment_content'] = isset($fields['body']) ? $fields['body'] : '';
     $data = array_merge($environment, $data);
     $result = self::make_request('submit-spam', $data);
 }
Beispiel #21
0
 /**
  * Output the form fields for the edit page
  *
  * @param array $details 
  * @return void
  * @author Rachel Andrew
  */
 public function render_inputs($details = array())
 {
     $id = $this->Tag->input_id();
     $val = '';
     if (isset($details[$id]) && $details[$id] != '') {
         $json = $details[$id];
         $val = $json['status_id'];
         PerchUtil::debug($json);
     } else {
         $json = array();
     }
     $s = $this->Form->text($this->Tag->input_id(), $val);
     if (isset($json['tweetHTML'])) {
         $API = new PerchAPI(1.0, 'perch_twitter');
         $Lang = $API->get('Lang');
         $s .= '<div class="preview" style="color: #000"><strong>' . $Lang->get('Tweet text') . ':</strong> ' . $json['tweetHTML'] . '</div>';
     }
     return $s;
 }
Beispiel #22
0
/**
 * 
 * function called by scripts (eg:a cron job or scheduled task) to upate the Tweets.
 */
function perch_twitter_update_tweets()
{
    $found = 0;
    $API = new PerchAPI(1.0, 'perch_twitter');
    PerchUtil::debug('Updating');
    $TwitterSettings = new PerchTwitter_Settings($API);
    $CurrentSettings = $TwitterSettings->find();
    if (is_object($CurrentSettings)) {
        $details = $CurrentSettings->to_array();
        $Twitter = new PerchTwitter();
        //update tweets
        $twitter_id_str = $details['settingTwitterID'];
        $twitter_id_array = explode(',', $twitter_id_str);
        for ($i = 0; $i < sizeOf($twitter_id_array); $i++) {
            $twitter_id = trim($twitter_id_array[$i]);
            $found += $Twitter->get_tweets('favorites', $twitter_id);
            $found += $Twitter->get_tweets('mine', $twitter_id);
        }
    }
    return $found;
}
 public static function get_static($key, $minutes)
 {
     if (PERCH_PRODUCTION_MODE < PERCH_PRODUCTION) {
         return false;
     }
     if (self::$disabled) {
         return false;
     }
     PerchUtil::debug('Fetching from cache: ' . $key);
     $file = PerchUtil::file_path(PERCH_RESFILEPATH . '/perch_blog.' . $key . '.cache');
     if (file_exists($file)) {
         $stat = stat($file);
         $mod_time = (int) $stat['mtime'];
         if (time() - $minutes * 60 < $mod_time) {
             return file_get_contents($file);
         }
     } else {
         PerchUtil::debug('Cache file not found: ' . $key);
     }
     return false;
 }
 public function log_resources($resourceIDs = false)
 {
     if ($resourceIDs === false) {
         $Resources = new PerchResources();
         $resourceIDs = $Resources->get_logged_ids();
     }
     if (PerchUtil::count($resourceIDs) && $this->api) {
         PerchUtil::debug('Logging resources for ' . $this->api->app_id);
         $app_id = $this->api->app_id;
         $sql = 'DELETE FROM ' . PERCH_DB_PREFIX . 'resource_log WHERE appID=' . $this->db->pdb($app_id) . ' AND itemFK=' . $this->db->pdb($this->pk) . ' AND itemRowID=' . $this->db->pdb((int) $this->id());
         $this->db->execute($sql);
         $sql = 'INSERT IGNORE INTO ' . PERCH_DB_PREFIX . 'resource_log(`appID`, `itemFK`, `itemRowID`, `resourceID`) VALUES';
         $vals = array();
         foreach ($resourceIDs as $id) {
             $vals[] = '(' . $this->db->pdb($app_id) . ',' . $this->db->pdb($this->pk) . ',' . (int) $this->id() . ',' . (int) $id . ')';
         }
         $sql .= implode(',', $vals);
         $this->db->execute($sql);
     } else {
         PerchUtil::debug('No ids to log.');
     }
 }
 public function get_table_meta($table)
 {
     $sql = 'SELECT * FROM ' . $table . ' LIMIT 1';
     $link = $this->get_link();
     $result = $link->query($sql);
     self::$queries++;
     if ($result) {
         $r = array();
         $i = 0;
         while ($i < $result->columnCount()) {
             $r[] = $result->fetchColumn($i);
             $i++;
         }
         $result = NULL;
         return $r;
     } else {
         PerchUtil::debug("Invalid query: " . $link->error, 'error');
         return false;
     }
 }
 private function thumbnail_file_with_imagick($file_path, $save_as, $w = 0, $h = 0)
 {
     try {
         $real_save_as = $save_as;
         $save_as = tempnam(PERCH_RESFILEPATH, '_im_tmp_');
         $Image = new Imagick($file_path . '[0]');
         $Image->setImageFormat('jpg');
         if ($Image->getImageHeight() <= $Image->getImageWidth()) {
             $Image->thumbnailImage($w * $this->density, 0);
         } else {
             $Image->thumbnailImage(0, $w * $this->density);
         }
         // progressive jpg?
         if ($this->progressive_jpeg) {
             $Image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
         }
         $Image->writeImage($save_as);
         copy($save_as, $real_save_as);
         unlink($save_as);
         $save_as = $real_save_as;
         $out = array();
         $out['w'] = (int) $Image->getImageWidth() / $this->density;
         $out['h'] = (int) $Image->getImageHeight() / $this->density;
         $out['file_path'] = $save_as;
         $parts = explode(DIRECTORY_SEPARATOR, $save_as);
         $out['file_name'] = array_pop($parts);
         $out['web_path'] = str_replace(PERCH_RESFILEPATH . DIRECTORY_SEPARATOR, PERCH_RESPATH . '/', $save_as);
         $out['density'] = $this->density;
         $out['mime'] = 'image/' . $Image->getImageFormat();
         $Image->destroy();
         return $out;
     } catch (Exception $e) {
         PerchUtil::debug('Unable to create thumbnail', 'error');
         PerchUtil::debug($e, 'error');
     }
     return false;
 }
Beispiel #27
0
 public function dispatch_form($key, $post, $files)
 {
     $key = base64_decode($key);
     $parts = explode(':', $key);
     $formID = $parts[0];
     $appIDs = $parts[1];
     $template = $parts[2];
     $timestamp = isset($parts[3]) ? $parts[3] : false;
     if ($appIDs) {
         $appIDs = explode(' ', $appIDs);
         if (is_array($appIDs)) {
             foreach ($appIDs as $appID) {
                 if (function_exists($appID . '_form_handler')) {
                     $API = new PerchAPI(1.0, $appID);
                     $SubmittedForm = $API->get('SubmittedForm');
                     $SubmittedForm->populate($formID, $template, $post, $files, $timestamp);
                     call_user_func($appID . '_form_handler', $SubmittedForm);
                 } else {
                     PerchUtil::debug($appID . ' form handler not found.', 'error');
                 }
             }
         }
     }
 }
 public function set($type = 'success', $message = 'Thank you')
 {
     // type = success, notice, error
     $this->alerts[] = array('type' => $type, 'message' => $message);
     PerchUtil::debug('Setting alert: ' . $message . ' (' . $type . ')');
 }
 public function form_login($SubmittedForm)
 {
     PerchUtil::debug('Method form_login not implemented in ' . get_class($this));
 }
Beispiel #30
0
if (PerchUtil::get('token')) {
    $mode = 'enter_token';
    $Users = new PerchUsers();
    $User = $Users->get_by_password_recovery_token(PerchUtil::get('token'));
    if (!$User) {
        $mode = 'token_expired';
    } else {
        if (PerchUtil::post('username') && PerchUtil::post('new_password')) {
            if (PerchUtil::post('username') == $User->userUsername()) {
                PerchUtil::debug('Username matches');
                if (PerchUtil::post('new_password') == PerchUtil::post('new_password2')) {
                    if ($User->password_meets_requirements(PerchUtil::post('new_password'))) {
                        $User->set_new_password(PerchUtil::post('new_password'));
                        $mode = 'password_set';
                    } else {
                        PerchUtil::debug($User->msg, 'notice');
                        $error = 'weak_password';
                    }
                } else {
                    $error = 'non_matching_passwords';
                }
            } else {
                $error = 'non_matching_username';
            }
        }
    }
}
if (isset($_POST['reset']) && $_POST['reset'] == '1' && isset($_POST['email']) && $_POST['email'] != '') {
    $email = $_POST['email'];
    if (PerchUtil::is_valid_email($email)) {
        $Users = new PerchUsers();