예제 #1
0
/**
 * Change columns get_posts() query
 * 
 * @param type $query
 * @return void
 */
function mashsb_sort_shares_by($query)
{
    if (!is_admin()) {
        return false;
    }
    $orderby = $query->get('orderby');
    if ('Share Count' == $orderby) {
        $query->set('meta_key', 'mashsb_shares');
        $query->set('orderby', 'meta_value_num');
    }
}
 /**
  * Admin BeforeRender
  *
  * Sets the last stuff before an call with the admin-prefix
  *
  * @param type $event
  */
 public function admin_beforeRender($event)
 {
     // setting up the default title-variable for default view
     if (!key_exists('title', $this->Controller->viewVars)) {
         $this->Controller->set('title', $this->Controller->name);
     }
 }
예제 #3
0
 /**
  * Set values to keys
  * @param type $key
  * @param type $value
  * @param type $duration duration for which the data should be cached
  * @return \Framework\Cache\Driver\Memcached
  * @throws Exception\Service
  */
 public function set($key, $value, $duration = 120)
 {
     if (!$this->_isValidService()) {
         throw new Exception\Service("Not connected to a valid service");
     }
     $this->_service->set($key, $value, MEMCACHE_COMPRESSED, $duration);
     return $this;
 }
 /**
  * Sets the return value
  * 
  * @param type $Itemid
  * @return type
  */
 protected function setReturn($Itemid = null, $message = '')
 {
     if (empty($Itemid)) {
         return;
     }
     $newUrl = base64_encode(urlencode(JRoute::_($this->getMenuitemUrl($Itemid), false)));
     $this->input->set('return', $newUrl);
     if (!empty($message)) {
         $this->session->set('asar.message', $message);
     }
 }
예제 #5
0
 /**
  * 
  * @param type $name nombre de la tabla de la base de datos.
  * @param type $basedir ruta del directorio table donde se encuentra el XML
  * con la estructura de la tabla de la base de datos.
  */
 public function __construct($name = '', $basedir = '')
 {
     if (strtolower(FS_DB_TYPE) == 'mysql') {
         $this->db = new fs_mysql();
     } else {
         $this->db = new fs_postgresql();
     }
     $this->table_name = $name;
     $this->base_dir = $basedir;
     $this->cache = new fs_cache();
     $this->default_items = new fs_default_items();
     if (!self::$errors) {
         self::$errors = array();
     }
     if (!self::$checked_tables) {
         self::$checked_tables = $this->cache->get_array('fs_checked_tables', TRUE);
         if (self::$checked_tables) {
             /// nos aseguramos de que existan todas las tablas que se suponen comprobadas
             $tables = $this->db->list_tables();
             foreach (self::$checked_tables as $ct) {
                 if (!$this->db->table_exists($ct, $tables)) {
                     $this->clean_checked_tables();
                     break;
                 }
             }
         }
     }
     if ($name != '') {
         if (!in_array($name, self::$checked_tables)) {
             if ($this->check_table($name)) {
                 self::$checked_tables[] = $name;
                 $this->cache->set('fs_checked_tables', self::$checked_tables, 5400, TRUE);
             }
         }
     }
 }
예제 #6
0
 /**
  * Unified save child function.
  *
  * @param int $parent_id
  * @param int $child_id
  * @param array $save_fields
  * @return bool|WP_Error
  */
 function save_child($parent_id, $child_id, $save_fields = array())
 {
     $parent = get_post(intval($parent_id));
     $child = get_post(intval($child_id));
     $post_data = array();
     if (empty($parent) || empty($child)) {
         return new WP_Error('wpcf-relationship-save-child', 'no parent/child post');
     }
     // Save relationship
     update_post_meta($child->ID, '_wpcf_belongs_' . $parent->post_type . '_id', $parent->ID);
     // Check if added via AJAX
     $check = get_post_meta($child->ID, '_wpcf_relationship_new', true);
     $new = !empty($check);
     delete_post_meta($child->ID, '_wpcf_relationship_new');
     // Set post data
     $post_data['ID'] = $child->ID;
     // Title needs to be checked if submitted at all
     if (!isset($save_fields['_wp_title'])) {
         // If not submitted that means it is not offered to be edited
         if (!empty($child->post_title)) {
             $post_title = $child->post_title;
         } else {
             // DO NOT LET IT BE EMPTY
             $post_title = $child->post_type . ' ' . $child->ID;
         }
     } else {
         $post_title = $save_fields['_wp_title'];
     }
     $post_data['post_title'] = $post_title;
     $post_data['post_content'] = isset($save_fields['_wp_body']) ? $save_fields['_wp_body'] : $child->post_content;
     $post_data['post_type'] = $child->post_type;
     // Check post status - if new, convert to 'publish' else keep remaining
     if ($new) {
         $post_data['post_status'] = 'publish';
     } else {
         $post_data['post_status'] = get_post_status($child->ID);
     }
     /*
      *
      *
      *
      *
      *
      *
      * UPDATE POST
      */
     $cf = new WPCF_Field();
     if (isset($_POST['wpcf_post_relationship'][$parent_id]) && isset($_POST['wpcf_post_relationship'][$parent_id][$child_id])) {
         $_POST['wpcf'] = array();
         foreach ($_POST['wpcf_post_relationship'][$parent_id][$child_id] as $slug => $value) {
             $_POST['wpcf'][$cf->__get_slug_no_prefix($slug)] = $value;
             $_POST['wpcf'][$slug] = $value;
         }
     }
     unset($cf);
     /**
     * avoid filters for children
     * /
             global $wp_filter;
             $save_post = $wp_filter['save_post'];
             $wp_filter['save_post'] = array();
     */
     $updated_id = wp_update_post($post_data);
     /*
        $wp_filter['save_post'] = $save_post;
     */
     unset($save_post);
     if (empty($updated_id)) {
         return new WP_Error('relationship-update-post-failed', 'Updating post failed');
     }
     // Save parents
     if (!empty($save_fields['parents'])) {
         foreach ($save_fields['parents'] as $parent_post_type => $parent_post_id) {
             update_post_meta($child->ID, '_wpcf_belongs_' . $parent_post_type . '_id', $parent_post_id);
         }
     }
     // Update taxonomies
     if (!empty($save_fields['taxonomies']) && is_array($save_fields['taxonomies'])) {
         $_save_data = array();
         foreach ($save_fields['taxonomies'] as $taxonomy => $t) {
             if (!is_taxonomy_hierarchical($taxonomy)) {
                 $_save_data[$taxonomy] = strval($t);
                 continue;
             }
             foreach ($t as $term_id) {
                 if ($term_id != '-1') {
                     $term = get_term($term_id, $taxonomy);
                     if (empty($term)) {
                         continue;
                     }
                     $_save_data[$taxonomy][] = $term_id;
                 }
             }
         }
         wp_delete_object_term_relationships($child->ID, array_keys($save_fields['taxonomies']));
         foreach ($_save_data as $_taxonomy => $_terms) {
             wp_set_post_terms($child->ID, $_terms, $_taxonomy, $append = false);
         }
     }
     // Unset non-types
     unset($save_fields['_wp_title'], $save_fields['_wp_body'], $save_fields['parents'], $save_fields['taxonomies']);
     /*
      *
      *
      *
      *
      *
      *
      * UPDATE Loop over fields
      */
     foreach ($save_fields as $slug => $value) {
         if (defined('WPTOOLSET_FORMS_VERSION')) {
             // Get field by slug
             $field = wpcf_fields_get_field_by_slug(str_replace(WPCF_META_PREFIX, '', $slug));
             if (empty($field)) {
                 continue;
             }
             // Set config
             $config = wptoolset_form_filter_types_field($field, $child->ID);
             // Check if valid
             $valid = wptoolset_form_validate_field('post', $config, $value);
             if (is_wp_error($valid)) {
                 $errors = $valid->get_error_data();
                 $msg = sprintf(__('Child post "%s" field "%s" not updated:', 'wpcf'), $child->post_title, $field['name']);
                 wpcf_admin_message_store($msg . ' ' . implode(', ', $errors), 'error');
                 continue;
             }
         }
         $this->cf->set($child, $field);
         $this->cf->context = 'post_relationship';
         $this->cf->save($value);
     }
     do_action('wpcf_relationship_save_child', $child, $parent);
     clean_post_cache($parent->ID);
     clean_post_cache($child->ID);
     // Added because of caching meta 1.5.4
     wp_cache_flush();
     return true;
 }
예제 #7
0
 /**
  * Unified save child function.
  * 
  * @param type $child_id
  * @param type $parent_id
  */
 function save_child($parent_id, $child_id, $save_fields = array())
 {
     global $wpdb;
     $parent = get_post(intval($parent_id));
     $child = get_post(intval($child_id));
     $post_data = array();
     if (empty($parent) || empty($child)) {
         return new WP_Error('wpcf-relationship-save-child', 'no parent/child post');
     }
     // Save relationship
     update_post_meta($child->ID, '_wpcf_belongs_' . $parent->post_type . '_id', $parent->ID);
     // Check if added via AJAX
     $check = get_post_meta($child->ID, '_wpcf_relationship_new', true);
     $new = !empty($check);
     delete_post_meta($child->ID, '_wpcf_relationship_new');
     if ($new) {
     }
     // Set post data
     $post_data['ID'] = $child->ID;
     // Title needs to be checked if submitted at all
     if (!isset($save_fields['_wp_title'])) {
         // If not submitted that means it is not offered to be edited
         if (!empty($child->post_title)) {
             $post_title = $child->post_title;
         } else {
             // DO NOT LET IT BE EMPTY
             $post_title = $child->post_type . ' ' . $child->ID;
         }
     } else {
         $post_title = $save_fields['_wp_title'];
     }
     $post_data['post_title'] = $post_title;
     $post_data['post_content'] = !empty($save_fields['_wp_body']) ? $save_fields['_wp_body'] : '';
     $post_data['post_type'] = $child->post_type;
     // TODO This should be revised
     $post_data['post_status'] = 'publish';
     /*
      * 
      * 
      * 
      * 
      * 
      * 
      * UPDATE POST
      */
     $updated_id = wp_update_post($post_data);
     if (empty($updated_id)) {
         return new WP_Error('relationship-update-post-failed', 'Updating post failed');
     }
     // Save parents
     if (!empty($save_fields['parents'])) {
         foreach ($save_fields['parents'] as $parent_post_type => $parent_post_id) {
             update_post_meta($child->ID, '_wpcf_belongs_' . $parent_post_type . '_id', $parent_post_id);
         }
     }
     // Unset non-types
     unset($save_fields['_wp_title'], $save_fields['_wp_body'], $save_fields['parents']);
     /*
      * 
      * 
      * 
      * 
      * 
      * 
      * UPDATE Loop over fields
      */
     foreach ($save_fields as $slug => $value) {
         $this->cf->set($child, $slug);
         $this->cf->context = 'post_relationship';
         $this->cf->save($value);
     }
     // Set the language
     // TODO WPML
     // TODO Move this and use hook
     global $sitepress;
     if (isset($sitepress)) {
         $lang_details = $sitepress->get_element_language_details($parent->ID, 'post_' . $parent->post_type);
         if ($lang_details) {
             $sitepress->set_element_language_details($child->ID, 'post_' . $child->post_type, null, $lang_details->language_code);
         }
     }
     do_action('wpcf_relationship_save_child', $child, $parent);
     clean_post_cache($parent->ID);
     clean_post_cache($child->ID);
     return true;
 }
예제 #8
0
/**
 * 
 * @global array $custom_post_types
 * @param type $q
 * @return type
 */
function add_custom_posts_per_page(&$q)
{
    if (!is_admin()) {
        global $custom_post_types;
        $custom_post_types = array('health');
        if ($q->is_archive) {
            // any archive
            if (isset($q->query_vars['post_type'])) {
                if (in_array($q->query_vars['post_type'], $custom_post_types)) {
                    $q->set('posts_per_page', 12);
                }
            }
        }
        //
        return $q;
    }
}
 /**
  * Set a service to the injected container
  *
  * @param string $id,       The service id
  * @param mixed $service,   The service
  */
 public function set($id, $service)
 {
     $this->_container->set($id, $service);
 }
예제 #10
0
 /**
  * Autoriza el contacto con las personas que se interesen por la compra o
  * renta del $inmueble, mandandoles un correo a todas ellas. Se mandara a
  * llamar este metodo cuando el usuario pague por ese inmueble en particular.
  * @param type $inmueble
  */
 public static function autorizarContacto($inmueble)
 {
     $arrendador = APIUsuario::usuarioActual();
     if (!$arrendador->isAuthenticated()) {
         return false;
     }
     $inmueble->set("activado", true);
     $query = new ParseQuery("UsuarioVeDatosCasa");
     $query->equalTo("idInmueble", $inmueble);
     $query->equalTo("arrendador", $arrendador);
     $query->equalTo("validado", false);
     $res = $query->find();
     $fin = count($res);
     for ($i = 0; $i < $fin; $i++) {
         //$res[$i]-> fetch();
         $user = $res[$i]->get("idUsuario");
         $user->fetch();
         $mail = $user->get("email");
         $asunto = "El arrendador de la casa que solicitaste se quiere contactar contigo!";
         $txt = "Hola! " . $user->get("username") . ", Nos complase informarte que el usuario " . $arrendador->get("username") . " ha desidido contactarse contigo y llegar a un acuerdo para la venta/renta de su casa ubicada en " . $inmueble->get("direccion") . ". Puedes ponerte en contacto con el a traves de este correo: " . $arrendador->get("email") . ".";
         APIUsuario::enviarNotificacion($mail, $asunto, $txt);
         //echo "se envio correo informativo a ". $mail. " con el contenido: <br>". $txt." <br>";
         $res[$i]->set("validado", true);
         $res[$i]->save();
     }
 }
 /**
  * Añade un elemento a la lista de cambios del usuario.
  * @param type $txt texto descriptivo.
  * @param type $url URL del elemento (albarán, factura, artículos...).
  * @param type $nuevo TRUE si el elemento es nuevo, FALSE si se ha modificado.
  */
 public function new_change($txt, $url, $nuevo = FALSE)
 {
     $this->get_last_changes();
     if (count($this->last_changes) > 0) {
         if ($this->last_changes[0]['url'] == $url) {
             $this->last_changes[0]['nuevo'] = $nuevo;
         } else {
             array_unshift($this->last_changes, array('texto' => ucfirst($txt), 'url' => $url, 'nuevo' => $nuevo, 'cambio' => date('d-m-Y H:i:s')));
         }
     } else {
         array_unshift($this->last_changes, array('texto' => ucfirst($txt), 'url' => $url, 'nuevo' => $nuevo, 'cambio' => date('d-m-Y H:i:s')));
     }
     /// sólo queremos 10 elementos
     $num = 10;
     foreach ($this->last_changes as $i => $value) {
         if ($num > 0) {
             $num--;
         } else {
             unset($this->last_changes[$i]);
         }
     }
     $this->cache->set('last_changes_' . $this->user->nick, $this->last_changes);
 }
예제 #12
0
 /**
  * setParams
  * 
  * Sets the parameters of the view
  * 
  * @param string $name key value must be string because this will be the variable name
  * @param mixture $value can have multiple data types
  * 
  * @return void
  */
 protected function setParams($name, $value)
 {
     $this->view->set($name, $value);
 }
예제 #13
0
/**
 * Adds the paramters to the WP_Tax query to exclude the 'hidden' episode attribute taxonomy.
 * @param type $query 
 * @return type
 */
function convergence_exclude_episode_attribute_hidden($query)
{
    if (is_object($query->tax_query) && !is_user_logged_in()) {
        $tax_query = $query->tax_query->queries;
        $tax_query['hidden'] = convergence_exclude_episode_attributes('hidden');
        $query->set('tax_query', $tax_query);
    }
    return $query;
}
 /**
  * beforeRender
  *
  * @param type $controller 
  */
 public function beforeRender($controller)
 {
     $railroadPrefs = $this->RailroadPref->find('list');
     $railroadLines = array();
     if (!empty($controller->request->data[$controller->modelClass][$this->settings['pref']['id']])) {
         $lineId = $this->RailroadStation->getPrefLineId($controller->request->data[$controller->modelClass][$this->settings['pref']['id']]);
         if (!empty($lineId)) {
             $query = array('conditions' => array('RailroadLine.id' => $lineId), 'order' => array('RailroadLine.sort' => 'ASC'));
             $railroadLines = $this->RailroadLine->find('list', $query);
         }
     }
     $railroadStations = array();
     if (!empty($controller->request->data[$controller->modelClass][$this->settings['line']['id']])) {
         $query = array('conditions' => array('RailroadStation.railroad_line_id' => $controller->request->data[$controller->modelClass][$this->settings['line']['id']]), 'order' => array('RailroadStation.sort' => 'ASC'));
         $railroadStations = $this->RailroadStation->find('list', $query);
     }
     $controller->set(array($this->settings['pref']['list'] => $railroadPrefs, $this->settings['line']['list'] => $railroadLines, $this->settings['station']['list'] => $railroadStations));
 }
예제 #15
0
 /**
  * @author Tonjoo
  * 
  * Query to unpaid invoices for each customer
  * @param type $query 
  * @return type
  */
 public function get_dx_invoice_by_customer_and_invoice_status($query)
 {
     global $pagenow;
     if (is_admin() && $pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'dx_invoice' && isset($_GET['customer_id']) && isset($_GET['invoice_status'])) {
         if (current_user_can('manage_options')) {
             $query->set('meta_query', array(array('key' => '_client', 'value' => htmlspecialchars($_GET['customer_id']), 'compare' => '='), array('key' => '_dx_status_invoice', 'value' => htmlspecialchars($_GET['invoice_status']), 'compare' => '=')));
         }
     }
 }