public static function bookmark($target_url) { global $prli_options, $prli_blogurl, $prli_link; $redirect_type = esc_html((isset($_GET['rt']) and $_GET['rt'] != '-1') ? $_GET['rt'] : ''); $track = esc_html((isset($_GET['trk']) and $_GET['trk'] != '-1') ? $_GET['trk'] : ''); $group = esc_html((isset($_GET['grp']) and $_GET['grp'] != '-1') ? $_GET['grp'] : ''); $result = prli_create_pretty_link(esc_url_raw($target_url, array('http', 'https')), '', '', '', $group, $track, '', $redirect_type); $plink = $prli_link->getOne($result); $target_url = $plink->url; $target_url_title = $plink->name; $pretty_link = $prli_blogurl . PrliUtils::get_permalink_pre_slug_uri() . $plink->slug; $twitter_status = substr($target_url_title, 0, 114 - strlen($pretty_link)) . (strlen($target_url_title) > 114 ? "..." : '') . " | {$pretty_link}"; require PRLI_VIEWS_PATH . '/prli-tools/bookmarklet.php'; }
/** * Get a Pretty Link for a long, ugly URL. * * @param string $username Required, an admin user of this blog * * @param string $password Required, the password for this user * * @param string $target_url Required, it is the value of the Target URL you * want the Pretty Link to redirect to * * @param string $slug Optional, slug for the Pretty Link (string that comes * after the Pretty Link's slash) if this value isn't set * then a random slug will be automatically generated. * * @param string $name Optional, name for the Pretty Link. If this value isn't * set then the name will be the slug. * * @param string $description Optional, description for the Pretty Link. * * @param integer $group_id Optional, the group that this link will be placed in. * If this value isn't set then the link will not be * placed in a group. * * @param boolean $link_track_me Optional, If true the link will be tracked, * if not set the default value (from the pretty * link option page) will be used * * @param boolean $link_nofollow Optional, If true the nofollow attribute will * be set for the link, if not set the default * value (from the pretty link option page) will * be used * * @param string $link_redirect_type Optional, valid values include '307' or '301', * if not set the default value (from the pretty * link option page) will be used * * @return boolean / string The Full Pretty Link if Successful and false for Failure. * This function will also set a global variable named * $prli_pretty_slug which gives the slug of the link * created if the link is successfully created -- it will * set a variable named $prli_error_messages if the link * was not successfully created. */ function prli_xmlrpc_create_pretty_link($args) { $username = $args[0]; $password = $args[1]; if (!get_option('enable_xmlrpc')) { return new IXR_Error(401, __('Sorry, XML-RPC Not enabled for this website', 'pretty-link')); } if (!user_pass_ok($username, $password)) { return new IXR_Error(401, __('Sorry, Login failed', 'pretty-link')); } // make sure user is an admin $userdata = get_userdatabylogin($username); if (!isset($userdata->user_level) or (int) $userdata->user_level < 8) { return new IXR_Error(401, __('Sorry, you must be an administrator to access this resource', 'pretty-link')); } // Target URL Required if (!isset($args[2])) { return new IXR_Error(401, __('You must provide a target URL', 'pretty-link')); } $target_url = $args[2]; $slug = isset($args[3]) ? $args[3] : ''; $name = isset($args[4]) ? $args[4] : ''; $description = isset($args[5]) ? $args[5] : ''; $group_id = isset($args[6]) ? $args[6] : ''; $track_me = isset($args[7]) ? $args[7] : ''; $nofollow = isset($args[8]) ? $args[8] : ''; $redirect_type = isset($args[9]) ? $args[9] : ''; $param_forwarding = isset($args[10]) ? $args[10] : 'off'; $param_struct = isset($args[11]) ? $args[11] : ''; if ($link = prli_create_pretty_link($target_url, $slug, $name, $description, $group_id, $track_me, $nofollow, $redirect_type, $param_forwarding, $param_struct)) { return $link; } else { return new IXR_Error(401, __('There was an error creating your Pretty Link', 'pretty-link')); } }
public function get_target_to_pretty_urls($urls = array(), $create_pretty_links = false) { global $wpdb, $prli_blogurl; if (empty($urls)) { return false; } $decoded_urls = array_map(create_function('$url', 'return html_entity_decode(urldecode($url));'), $urls); if (count($decoded_urls) > 1) { $where = "IN (" . implode(',', array_map(create_function('$url', 'return "\\"{$url}\\"";'), $decoded_urls)) . ")"; } else { $where = "= '" . html_entity_decode(urldecode($decoded_urls[0])) . "'"; } $query = "SELECT li.url AS target_url, " . "CONCAT(%s, li.slug) AS pretty_url " . "FROM {$this->table_name} AS li " . "WHERE li.url {$where}"; $query = $wpdb->prepare($query, $prli_blogurl . PrliUtils::get_permalink_pre_slug_uri()); $results = (array) $wpdb->get_results($query); $prli_lookup = array(); foreach ($results as $url_hash) { if (isset($prli_lookup[$url_hash->target_url])) { $prli_lookup[$url_hash->target_url][] = $url_hash->pretty_url; } else { $prli_lookup[$url_hash->target_url] = array($url_hash->pretty_url); } } if ($create_pretty_links) { foreach ($decoded_urls as $url) { if (!isset($prli_lookup[$url])) { if ($id = prli_create_pretty_link($url)) { $prli_lookup[$url] = array(prli_get_pretty_link_url($id)); } } } } return $prli_lookup; }
function update($id, $values, $create_link = false) { global $wpdb, $frmdb, $frm_field, $frm_settings; if ($create_link or isset($values['options']) or isset($values['item_meta']) or isset($values['field_options'])) { $values['status'] = 'published'; } if (isset($values['form_key'])) { $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $frmdb->forms, 'form_key', $id); } $form_fields = array('form_key', 'name', 'description', 'status', 'prli_link_id'); $new_values = array(); if (isset($values['options'])) { $options = array(); $defaults = FrmFormsHelper::get_default_opts(); foreach ($defaults as $var => $default) { $options[$var] = isset($values['options'][$var]) ? $values['options'][$var] : $default; } $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0; $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); $options = apply_filters('frm_form_options_before_update', $options, $values); $new_values['options'] = serialize($options); } foreach ($values as $value_key => $value) { if (in_array($value_key, $form_fields)) { $new_values[$value_key] = $value; } } if (!empty($new_values)) { $query_results = $wpdb->update($frmdb->forms, $new_values, array('id' => $id)); if ($query_results) { wp_cache_delete($id, 'frm_form'); } } else { $query_results = true; } $all_fields = $frm_field->getAll(array('fi.form_id' => $id)); if ($all_fields and (isset($values['options']) or isset($values['item_meta']) or isset($values['field_options']))) { if (!isset($values['item_meta'])) { $values['item_meta'] = array(); } $existing_keys = array_keys($values['item_meta']); foreach ($all_fields as $fid) { if (!in_array($fid->id, $existing_keys)) { $values['item_meta'][$fid->id] = ''; } } foreach ($values['item_meta'] as $field_id => $default_value) { $field = $frm_field->getOne($field_id); if (!$field) { continue; } $field_options = maybe_unserialize($field->field_options); if (isset($values['options']) or isset($values['field_options']['custom_html_' . $field_id])) { //updating the settings page if (isset($values['field_options']['custom_html_' . $field_id])) { $field_options['custom_html'] = isset($values['field_options']['custom_html_' . $field_id]) ? $values['field_options']['custom_html_' . $field_id] : (isset($field_options['custom_html']) ? $field_options['custom_html'] : FrmFieldsHelper::get_default_html($field->type)); $field_options = apply_filters('frm_update_form_field_options', $field_options, $field, $values); $frm_field->update($field_id, array('field_options' => $field_options)); } else { if ($field->type == 'hidden') { $prev_opts = $field_options; $field_options = apply_filters('frm_update_form_field_options', $field_options, $field, $values); if ($prev_opts != $field_options) { $frm_field->update($field_id, array('field_options' => $field_options)); } unset($prev_opts); } } } else { //updating the form foreach (array('size', 'max', 'label', 'invalid', 'required_indicator', 'blank', 'classes') as $opt) { $field_options[$opt] = isset($values['field_options'][$opt . '_' . $field_id]) ? trim($values['field_options'][$opt . '_' . $field_id]) : ''; } $field_options['separate_value'] = isset($values['field_options']['separate_value_' . $field_id]) ? trim($values['field_options']['separate_value_' . $field_id]) : 0; $field_options = apply_filters('frm_update_field_options', $field_options, $field, $values); $default_value = maybe_serialize($values['item_meta'][$field_id]); $field_key = isset($values['field_options']['field_key_' . $field_id]) ? $values['field_options']['field_key_' . $field_id] : $field->field_key; $field_type = isset($values['field_options']['type_' . $field_id]) ? $values['field_options']['type_' . $field_id] : $field->type; $field_description = isset($values['field_options']['description_' . $field_id]) ? $values['field_options']['description_' . $field_id] : $field->description; $frm_field->update($field_id, array('field_key' => $field_key, 'type' => $field_type, 'default_value' => $default_value, 'field_options' => $field_options, 'description' => $field_description)); } } } if (isset($values['form_key']) && class_exists('PrliLink')) { $form = $this->getOne($id); global $prli_link; $prlink = $prli_link->getOne($form->prli_link_id); if ($prlink) { $prli = array(); $prli['url'] = FrmFormsHelper::get_direct_link($values['form_key']); $prli['slug'] = $prlink->slug; $prli['name'] = $prlink->name; $prli['param_forwarding'] = $prlink->param_forwarding; $prli['param_struct'] = $prlink->param_struct; $prli['redirect_type'] = $prlink->redirect_type; $prli['description'] = $prlink->description; $prli['track_me'] = $prlink->track_me; $prli['nofollow'] = $prlink->nofollow; $prli['group_id'] = $prlink->group_id; $prli_link->update($form->prli_link_id, $prli); //update target url } else { if ($create_link && $form->is_template != 1) { $link_id = prli_create_pretty_link(FrmFormsHelper::get_direct_link($values['form_key']), $values['form_key'], $form->name, $form->description, $group_id = ''); $wpdb->update($frmdb->forms, array('prli_link_id' => $link_id), array('id' => $id)); } } } do_action('frm_update_form', $id, $values); do_action('frm_update_form_' . $id, $values); return $query_results; }