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; }
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; }
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 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 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'); } }
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(); }
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; }
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 __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(); } }
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); } } }
/** * 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; }
function perch_content_custom($key = null, $opts = array(), $return = false) { if ($key === null) { return ' '; } if (isset($opts['skip-template']) && $opts['skip-template'] == true) { $return = true; $postpro = false; if (isset($opts['return-html']) && $opts['return-html']) { $postpro = true; } } else { $postpro = true; } if (isset($opts['split-items']) && $opts['split-items'] == true) { $return = true; } if (isset($opts['pagination_var'])) { $opts['pagination-var'] = $opts['pagination_var']; } $Content = PerchContent::fetch(); $out = $Content->get_custom($key, $opts); // Post processing - if there are still <perch:x /> tags if ($postpro) { if (is_array($out)) { // return-html if (isset($out['html'])) { if (strpos($out['html'], '<perch:') !== false) { $Template = new PerchTemplate(); $out['html'] = $Template->apply_runtime_post_processing($out['html']); } } // split-items if (PerchUtil::count($out) && !isset($out['html'])) { $Template = new PerchTemplate(); foreach ($out as &$html_item) { if (strpos($html_item, '<perch:') !== false) { $html_item = $Template->apply_runtime_post_processing($html_item); } } } } else { if (strpos($out, '<perch:') !== false) { $Template = new PerchTemplate(); $out = $Template->apply_runtime_post_processing($out); } } } if ($return) { return $out; } echo $out; PerchUtil::flush_output(); }
/** * 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; }
/** * 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 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; }
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 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); }
public function to_array() { $out = parent::to_array(); if ($out['categoryDynamicFields'] != '') { $dynamic_fields = PerchUtil::json_safe_decode($out['categoryDynamicFields'], 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 static function get_settings_select_list($Form, $id, $details, $setting) { $opts = array(); $opts[] = array('value' => '', 'label' => ''); $c = __CLASS__; $Sets = new $c(); $sets = $Sets->all(); if (PerchUtil::count($sets)) { foreach ($sets as $Set) { $opts[] = array('value' => $Set->id(), 'label' => $Set->setTitle()); } } return $Form->select($id, $opts, $Form->get($details, $id, $setting['default'])); }
public function __construct($args) { if (PerchUtil::count($args)) { $this->event = array_shift($args); $this->subject = array_shift($args); $this->args = $args; $Perch = Perch::fetch(); if ($Perch->admin) { $Users = new PerchUsers(); $this->user = $Users->get_current_user(); } else { $this->runtime = true; } } }
function render_tree($Pages, $groupID, $parentID = 0, $class = false) { $pages = $Pages->get_by_parent($parentID, $groupID); $s = ''; $s = '<ol class="' . $class . '">'; if (PerchUtil::count($pages)) { foreach ($pages as $Page) { $s .= '<li><div class="page icon">' . PerchUtil::html($Page->pageNavText()) . '</div>'; $s .= render_tree($Pages, $groupID, $Page->id(), $class); $s .= '</li>'; } } $s .= '</ol>'; return $s; }
public static function get_all_remote() { $out = array(); if (self::$bucket_list === false) { self::load_bucket_list(); } if (PerchUtil::count(self::$bucket_list)) { foreach (self::$bucket_list as $name => $bucket) { if (isset($bucket['type']) && $bucket['type'] != 'file') { $bucket['name'] = $name; $out[] = self::factory($bucket); } } } return $out; }
function render_tree($Categories, $Set, $parentID = 0, $class = false) { $categories = $Categories->get_by_parent($parentID, $Set->id()); $s = ''; $s = '<ol class="' . $class . '">'; if (PerchUtil::count($categories)) { foreach ($categories as $Category) { $s .= '<li id="category_' . $Category->id() . '" data-parent="' . $parentID . '"><div class="category icon">'; $s .= '<input type="text" name="c-' . $Category->id() . '" value="' . $Category->catOrder() . '" />'; $s .= '' . PerchUtil::html($Category->catTitle()) . '</div>'; $s .= render_tree($Categories, $Set, $Category->id()); $s .= '</li>'; } } $s .= '</ol>'; return $s; }
public function get_as_array($user_specific = false) { $CurrentUser = $this->CurrentUser; if ($user_specific && $CurrentUser->logged_in()) { $sql = 'SELECT * FROM (SELECT DISTINCT settingID, settingValue FROM ' . $this->table . ' WHERE userID=' . $this->db->pdb((int) $CurrentUser->id()) . ' OR userID=0 ORDER BY userID DESC) AS settings GROUP BY settingID'; } else { $sql = 'SELECT DISTINCT settingID, settingValue FROM ' . $this->table . ' WHERE userID=0'; } $rows = $this->db->get_rows($sql); $out = array(); if (PerchUtil::count($rows) > 0) { foreach ($rows as $row) { $out[$row['settingID']] = $row['settingValue']; } } return $out; }
public function get_pages($column = false, $table = false) { if ($column === false || $table === false) { return false; } $db = PerchDB::fetch(); $sql = 'SELECT DISTINCT ' . $column . ' FROM ' . PERCH_DB_PREFIX . $table . ' WHERE ' . $column . ' != `*`'; $rows = $db->get_rows($sql); if (PerchUtil::count($rows) > 0) { $out = array(); foreach ($rows as $row) { $out[] = $row[$column]; } return $out; } return false; }
public function update_post_counts() { $sql = 'SELECT authorID, COUNT(*) AS qty FROM ' . PERCH_DB_PREFIX . 'blog_posts WHERE postStatus=\'Published\' AND postDateTime<=' . $this->db->pdb(date('Y-m-d H:i:00')) . ' GROUP BY authorID'; $rows = $this->db->get_rows($sql); if (PerchUtil::count($rows)) { // reset counts to zero $sql = 'UPDATE ' . PERCH_DB_PREFIX . 'blog_authors SET authorPostCount=0'; $this->db->execute($sql); foreach ($rows as $row) { $sql = 'UPDATE ' . PERCH_DB_PREFIX . 'blog_authors SET authorPostCount=' . $this->db->pdb($row['qty']) . ' WHERE authorID=' . $this->db->pdb((int) $row['authorID']) . ' LIMIT 1'; $this->db->execute($sql); } } }
/** * Get an array of templates in the content folder. * * @param string $path * @return void * @author Drew McLellan */ public function get_templates($path = false, $include_hidden = false, $initial_path = false) { $Perch = Perch::fetch(); if ($path === false) { $path = PERCH_TEMPLATE_PATH . '/forms/emails'; } if ($initial_path === false) { $initial_path = $path; } $a = array(); $groups = array(); $p = false; if (is_dir($path)) { if ($dh = opendir($path)) { while (($file = readdir($dh)) !== false) { if (substr($file, 0, 1) != '.' && ($include_hidden || substr($file, 0, 1) != '_') && !preg_match($Perch->ignore_pattern, $file)) { $extension = PerchUtil::file_extension($file); if ($extension == 'html' || $extension == 'htm') { $p = str_replace($initial_path, '', $path); if (!$p) { $a[PerchLang::get('Templates')][] = array('filename' => $file, 'value' => $file, 'path' => $file, 'label' => $this->template_display_name($file)); } else { $a[] = array('filename' => $file, 'value' => ltrim($p, '/') . '/' . $file, 'path' => ltrim($p, '/') . '/' . $file, 'label' => $this->template_display_name($file)); } } else { // Use this one of infinite recursive nesting. Group stuff below normalised for HTML select optgroups that only do one level //$a[$this->template_display_name($file)] = $this->get_templates($path.'/'.$file, $include_hidden, $initial_path); if ($p) { $group_name = $this->template_display_name(trim($p, '/\\') . '/' . $file); } else { $group_name = $this->template_display_name($file); } $groups[$group_name] = $this->get_templates($path . '/' . $file, $include_hidden, $initial_path); } } } closedir($dh); } if (PerchUtil::count($a)) { $a = PerchUtil::array_sort($a, 'label'); } } return $a + $groups; }
/** * Get a flat array of granted privID for the role, for repopulating checkboxes on edit page * * @param string $roleID * @return void * @author Drew McLellan */ public function get_flat_for_role($Role) { $roleID = $Role->id(); if ($Role->roleMasterAdmin()) { // Master admin has all privs, so just selected everything unfiltered $sql = 'SELECT privID FROM ' . $this->table; } else { $sql = 'SELECT privID FROM ' . PERCH_DB_PREFIX . 'user_role_privileges WHERE roleID=' . $this->db->pdb((int) $roleID); } $rows = $this->db->get_rows($sql); $out = array(); if (PerchUtil::count($rows)) { foreach ($rows as $row) { $out[] = $row['privID']; } } return $out; }
public function subscribe_from_form($Form) { $Settings = $this->api->get('Settings'); $api_key = $Settings->get('perch_mailchimp_api_key')->settingValue(); $list_id = $Settings->get('perch_mailchimp_list_id')->settingValue(); $merge_vars = array(); $groupings = array(); $confirmed = false; $double_optin = true; $send_welcome = true; $update_existing = true; $replace_interests = false; $FormTag = $Form->get_form_attributes(); if ($FormTag->is_set('double_optin')) { $double_optin = $FormTag->double_optin(); } if ($FormTag->is_set('send_welcome')) { $send_welcome = $FormTag->send_welcome(); } $attr_map = $Form->get_attribute_map('mailer'); if (PerchUtil::count($attr_map)) { foreach ($attr_map as $fieldID => $merge_var) { switch ($merge_var) { case 'email': $email = $Form->data[$fieldID]; break; case 'confirm_subscribe': $confirmed = PerchUtil::bool_val($Form->data[$fieldID]); break; default: $merge_vars[$merge_var] = $Form->data[$fieldID]; break; } } } if ($confirmed) { $MailChimp = new MailChimp($api_key); $result = $MailChimp->call('lists/subscribe', array('id' => $list_id, 'email' => array('email' => $email), 'merge_vars' => $merge_vars, 'double_optin' => $double_optin, 'update_existing' => $update_existing, 'replace_interests' => $replace_interests, 'send_welcome' => $send_welcome)); return $result; } return false; }
public function mark_as_spam() { $data = array(); $data['responseSpam'] = '1'; $this->update($data); $json = PerchUtil::json_safe_decode($this->responseSpamData(), true); if (PerchUtil::count($json)) { $API = new PerchAPI(1, 'perch_forms'); $Forms = new PerchForms_Forms($API); $Form = $Forms->find($this->formID()); if ($Form) { $opts = $Form->get_settings(); if (isset($opts['akismet']) && $opts['akismet']) { if (isset($opts['akismetAPIKey']) && $opts['akismetAPIKey'] != '') { PerchForms_Akismet::submit_spam($opts['akismetAPIKey'], $json['fields'], $json['environment']); } } } } }