Example #1
0
/**
 * Get post meta
 *
 * @param string   $key     Meta key. Required.
 * @param int|null $post_id Post ID. null for current post. Optional
 * @param array    $args    Array of arguments. Optional.
 *
 * @return mixed
 */
function rwmb_meta($key, $args = array(), $post_id = null)
{
    $post_id = empty($post_id) ? get_the_ID() : $post_id;
    $args = wp_parse_args($args, array('type' => 'text'));
    // Set 'multiple' for fields based on 'type'
    $args['multiple'] = in_array($args['type'], array('checkbox_list', 'file', 'image', 'plupload_image', 'thickbox_image'));
    $meta = get_post_meta($post_id, $key, !$args['multiple']);
    // Get uploaded files info
    if ('file' == $args['type']) {
        if (is_array($meta) && !empty($meta)) {
            $files = array();
            foreach ($meta as $id) {
                $files[$id] = rwmb_file_info($id);
            }
            $meta = $files;
        }
    } elseif (in_array($args['type'], array('image', 'plupload_image', 'thickbox_image'))) {
        if (is_array($meta) && !empty($meta)) {
            global $wpdb;
            $meta = implode(',', $meta);
            // Re-arrange images with 'menu_order'
            $meta = $wpdb->get_col("\n\t\t\t\tSELECT ID FROM {$wpdb->posts}\n\t\t\t\tWHERE post_type = 'attachment'\n\t\t\t\tAND ID in ({$meta})\n\t\t\t\tORDER BY menu_order ASC\n\t\t\t");
            $images = array();
            foreach ($meta as $id) {
                $images[$id] = rwmb_image_info($id, $args);
            }
            $meta = $images;
        }
    } elseif ('taxonomy' == $args['type']) {
        $meta = emtpy($args['taxonomy']) ? array() : wp_get_post_terms($post_id, $args['taxonomy']);
    }
    return $meta;
}
Example #2
0
/**
* USAGE: odc_mysql_safe( string $query [, array $params ] )
* $query - SQL query WITHOUT any user-entered parameters. Replace parameters with "?"
*     e.g. $query = "SELECT date from history WHERE login = ?"
* $params - array of parameters
*
* Example:
*    odc_mysql_safe( "SELECT secret FROM db WHERE login = ?", array($login) );    # one parameter
*    odc_mysql_safe( "SELECT secret FROM db WHERE login = ? AND password = ?", array($login, $password) );    # multiple parameters
* That will result safe query to MySQL with escaped $login and $password.
**/
function odc_mysql_safe($connection, $query,$params=false) {
	
	if(emtpy($connection) || empty($query)){
		return NULL;
	}
	
    if ($params) {
        foreach ($params as $v){ 
        	$v = mysql_real_escape_string($v, $connection); 
        }    # Escaping parameters
        # str_replace - replacing ? -> %s. %s is ugly in raw sql query
        # vsprintf - replacing all %s to parameters
        $sql_query = vsprintf( str_replace("?","'%s'",$query), $params );   
    }
    return ($sql_query);
} 
Example #3
0
 public function login($username, $password)
 {
     if ($this->session->has_userdata('email')) {
         return true;
     }
     if (empty($username) && empty(emtpy($password))) {
         return -1;
     }
     $ret = $this->db->select('`id`,`name`,`city`,`surname`,`age`,`gender`,`handicap`,`password`,`email`')->from('`users`')->where('`email`', $username)->get();
     if ($ret->num_rows() === 0) {
         return false;
     }
     $ret = $ret->row_array();
     //echo $ret['password']."\n";
     //echo $password;
     $v = $password === trim($ret['password']);
     if ($v) {
         $this->session->set_userdata($ret);
         return $ret;
     } else {
         return false;
     }
 }
Example #4
0
 public function attachPostUploadInfo(&$FilesArray, &$result)
 {
     if (!is_array($FilesArray)) {
         return;
     }
     /* if a single file is uploaded then check if it has duplicates
        and inform user about available file duplicates */
     $msg = '';
     $prompt_to_open_file = false;
     switch (sizeof($FilesArray)) {
         case 0:
             break;
         case 1:
             reset($FilesArray);
             $f = current($FilesArray);
             $d = DM\Files::getDuplicates($f['id']);
             $paths = array();
             if (sizeof($d) > 0) {
                 foreach ($d as $dup) {
                     $paths[] = $dup['pathtext'];
                 }
                 $paths = array_unique($paths);
                 //msg: there are duplicates
                 $msg = str_replace('{paths}', "\n<br />" . implode('<br />', $paths), L\get('UploadedFileExistsInFolders'));
                 $prompt_to_open_file = true;
                 $result['data']['id'] = $f['id'];
             }
             break;
         default:
             $filenames = array();
             foreach ($FilesArray as $f) {
                 $d = DM\Files::getDuplicates($f['id']);
                 if (sizeof($d) > 1) {
                     //msg: Following files have duplicates
                     $filenames[] = (empty($f['dir']) ? '' : $f['dir'] . DIRECTORY_SEPARATOR) . $f['name'];
                 }
             }
             if (!emtpy($filenames)) {
                 $msg = L\get('FollowingFilesHaveDuplicates') . "\n<br />" . implode('<br />', $filenames);
             }
             break;
     }
     if (!empty($msg)) {
         $result['msg'] = $msg;
     }
     if ($prompt_to_open_file) {
         $result['prompt_to_open'] = true;
     }
 }
Example #5
0
function createFileFolderArrayWin($ftp_rawlist, $type)
{
    // Go through array of files/folders
    foreach ($ftp_rawlist as $ff) {
        // Split up array into values
        $ff = preg_split("/[\\s]+/", $ff, 4);
        $date = $ff[0];
        $time = $ff[1];
        $size = $ff[2];
        $file = $ff[3];
        if ($size == "<DIR>") {
            $size = "d";
        }
        // Format date
        $day = substr($date, 3, 2);
        $month = substr($date, 0, 2);
        $year = substr($date, 6, 2);
        $date = formatFtpDate($day, $month, $year);
        // Format time
        $time = formatWinFtpTime($time);
        // Add folder to array
        if ($size == "d") {
            $foldAllAr[] = $file . "|d|" . $date . "|" . $time . "|||";
            $foldNameAr[] = $file;
            $foldDateAr[] = $date;
            $foldTimeAr[] = $time;
        }
        // Add file to array
        if ($size != "d") {
            $fileAllAr[] = $file . "|" . $size . "|" . $date . "|" . $time . "|||";
            $fileNameAr[] = $file;
            $fileSizeAr[] = $size;
            $fileDateAr[] = $date;
            $fileTimeAr[] = $time;
        }
    }
    // Check there are files and/or folders to display
    if (!empty($foldAllAr) || !empty($fileAllAr)) {
        // Set sorting order
        if ($_POST["sort"] == "") {
            $sort = "n";
        } else {
            $sort = $_POST["sort"];
        }
        if ($_POST["ord"] == "") {
            $ord = "asc";
        } else {
            $ord = $_POST["ord"];
        }
        // Return folders
        if ($type == "folders") {
            if (!emtpy($foldAllAr)) {
                $sortAr = array();
                // Set the folder arrays to sort
                if ($sort == "n") {
                    $sortAr = $foldNameAr;
                }
                if ($sort == "d") {
                    $sortAr = $foldDateAr;
                }
                if ($sort == "t") {
                    $sortAr = $foldTimeAr;
                }
                // Multisort array
                if (!empty($sortAr)) {
                    if ($ord == "asc") {
                        array_multisort($sortAr, SORT_ASC, $foldAllAr);
                    } else {
                        array_multisort($sortAr, SORT_DESC, $foldAllAr);
                    }
                }
                // Format and display folder content
                $folders = getFileListHtml($foldAllAr, "icon_16_folder.gif");
            }
            return $folders;
        }
        // Return files
        if ($type == "files") {
            if (!emtpy($fileAllAr)) {
                // Set the folder arrays to sort
                if ($sort == "n") {
                    $sortAr = $fileNameAr;
                }
                if ($sort == "s") {
                    $sortAr = $fileSizeAr;
                }
                if ($sort == "d") {
                    $sortAr = $fileDateAr;
                }
                if ($sort == "t") {
                    $sortAr = $fileTimeAr;
                }
                // Multisort folders
                if ($ord == "asc") {
                    array_multisort($sortAr, SORT_ASC, $fileAllAr);
                } else {
                    array_multisort($sortAr, SORT_DESC, $fileAllAr);
                }
                // Format and display file content
                $files = getFileListHtml($fileAllAr, "icon_16_file.gif");
            }
            return $files;
        }
    }
}
Example #6
0
 /**
  * Find the path of a given node
  * @param array $node The node to start with
  * @param boolean $includeSelf Wheter or not to include given node in result
  * @param boolean $returnAsArray Wheter or not to return array or unordered list
  * @return array or unordered list
  */
 public function getPath($node, $includeSelf = FALSE, $returnAsArray = FALSE)
 {
     if (emtpy($node)) {
         return FALSE;
     }
     $leftcol = $this->left_column_name;
     $rightcol = $this->right_column_name;
     $leftval = (int) $node[$leftcol];
     $rightval = (int) $node[$rightcol];
     if ($includeSelf) {
         $this->db->where($leftcol . ' <= ' . $leftval . ' AND ' . $rightcol . ' >= ' . $rightval);
     } else {
         $this->db->where($leftcol . ' < ' . $leftval . ' AND ' . $rightcol . ' > ' . $rightval);
     }
     $this->db->order_by($leftcol);
     $query = $this->db->get($this->table_name);
     if ($query->num_rows() > 0) {
         if ($returnAsArray) {
             return $query->result_array();
         } else {
             return $this->buildCrumbs($query->result_array());
         }
     }
     return FALSE;
 }
Example #7
0
 /**
  * validateCallback
  * @param $callback
  * @param $name
  * @return string
  * @throws SkeletonException
  */
 protected function validateCallback($callback, $name)
 {
     if ($callback && (!empty($callback) && is_array($callback))) {
         if (array_key_exists('controller', $callback)) {
             $controller = $callback['controller'];
         } else {
             throw new SkeletonException("Error: you need to declare the controller in route {$name}");
         }
         if (array_key_exists('function', $callback)) {
             $function = $callback['function'];
         } else {
             throw new SkeletonException("Error: you need to declare the function in route {$name} or use the callback as string.");
         }
         if (is_string($controller) && is_string($function)) {
             if (class_exists($controller)) {
                 if (method_exists($controller, $function)) {
                     $callback = "{$controller}:{$function}";
                 } else {
                     throw new SkeletonException("Error: method {$function} inexistent in route {$name}");
                 }
             } else {
                 throw new SkeletonException("Error: callback class not existent in route {$name}");
             }
         } else {
             throw new SkeletonException("Error you need to use string to declare your callback in route {$name}");
         }
     } else {
         if ($callback && (is_string($callback) && !emtpy($callback))) {
             if (!class_exists($callback)) {
                 throw new SkeletonException("Error: callback class not existent in route {$name}");
             }
         } else {
             throw new SkeletonException("Error: callback need to be declared in route {$name}");
         }
     }
     return $callback;
 }
Example #8
0
"><div class="float">
<ul class="pret"><li class="ndot">
<table border="1px"><tbody>
<?php 
        foreach ($ar_up_acc as $k => $v) {
            ?>
<tr>
<td class="tdacc" style="width:240px;">
<?php 
            $id = false;
            $chk = '';
            if ($showpostn) {
                if (isset($_POST[$v . '_upload']) && $_POST[$v . '_upload'] == 'on') {
                    $chk = ' checked="checked"';
                    $id = true;
                } elseif (isset($upload_acc[$v]) && (!emtpy($upload_acc[$v]['user']) && !empty($upload_acc[$v]['pass']))) {
                    $chk = ' checked="checked"';
                    $id = true;
                }
            }
            ?>
<input type="checkbox" id="<?php 
            echo $v;
            ?>
_upload" name="<?php 
            echo $v;
            ?>
_upload" onclick="clk(this,'<?php 
            echo $v;
            ?>
_upbox','<?php 
Example #9
0
 public function actionDynamicdistrict()
 {
     //echo CHtml::tag("option", array("value" => ''), '请选择地区', true);
     if ($_GET["city"]) {
         $data = Area::model()->findAll("parent_id=:parent_id", array(":parent_id" => $_GET["city"]));
         $data = CHtml::listData($data, "id", "name");
         foreach ($data as $value => $name) {
             echo CHtml::tag("option", array("value" => $value), CHtml::encode($name), true);
         }
     }
     if (emtpy($_GET["city"])) {
         echo CHtml::tag("option", array("value" => ''), '请选择地区', true);
     }
 }
Example #10
0
<?php

$nome = $_POST['nome'];
$url = $_POST['url'];
$imagem = $_POST['imagem'];
$tipo = $_POST['tipo'];
if (empty($nome) or empty($url) or empty($imagem) or emtpy($tipo)) {
    echo "Campo obrigatorios vazios";
}
Example #11
0
    return $this->renderer->render($response, 'index.phtml', array('experiments' => $settings['ex_template']));
});
$app->get('/impressum/', function ($request, $response, $args) use($app) {
    return $this->renderer->render($response, 'impressum.html');
});
$app->get('/{exp:ex[1-3]}', function ($request, $response, $args) use($app, $settings) {
    $prefix = $args['exp'];
    $data = $app->data->getDatasets($prefix);
    $template = $settings['ex_template'][$prefix];
    return $this->renderer->render($response, 'dataset.phtml', array('data' => $data, 'id' => $template['id'], 'title' => $template['title'], 'prefix' => $prefix));
});
$app->get('/{exp:ex[1-3]}/{dataset}', function ($request, $response, $args) use($app, $settings) {
    $exp = $args['exp'];
    $dataset = $args['dataset'];
    $data = $app->data->getDetectors($exp . "_" . $dataset);
    if (!$data || emtpy($data)) {
        return $response->withStatus(404);
    }
    $template = $settings['ex_template'][$exp];
    return $this->renderer->render($response, 'experiment.phtml', array('data' => $data, 'id' => $template['id'], 'title' => $template['title'], 'exp' => $exp, 'dataset' => $dataset));
});
$app->get('/{exp:ex[1-3]}/{dataset}/{detector}', function ($request, $response, $args) use($app) {
    return $app->helper->detect_route($args, $app, $this, $response, false);
});
$app->get('/{exp:ex[1-3]}/{dataset}/{detector}/{project}/{version}/{misuse}', function ($request, $response, $args) use($app) {
    return $app->helper->review_route($args, $app, $this, $response, $request, false, false);
});
$app->get('/{exp:ex[1-3]}/{dataset}/{detector}/{project}/{version}/{misuse}/{reviewer}', function ($request, $response, $args) use($app) {
    return $app->helper->review_route($args, $app, $this, $response, $request, false, true);
});
$app->group('/private', function () use($app) {
Example #12
0
 /**
  * checkStorage
  *
  * @param array   $amount Amount
  * @param boolean $force  Force, ignore storage size
  *
  * @return boolean
  */
 public function checkStorage($amount, $force = null)
 {
     if (!is_array($amount)) {
         throw new Exception("Must be array", 1);
     }
     $hangar = array('metal' => 22, 'crystal' => 23, 'deuterium' => 24);
     $check = array();
     foreach ($hangar as $k => $v) {
         if (!emtpy($amount[$k])) {
             if ($this->current_planet["planet_" . $k] + $amount[$k] >= ProductionLib::maxStorable($this->current_planet[$this->resource[$v]])) {
                 $check[$k] = false;
             } else {
                 $check[$k] = true;
             }
         } else {
             $check[$k] = true;
         }
     }
     if ($check['metal'] === true && $check['crystal'] === true && $check['deuterium'] === true) {
         return false;
     } else {
         if (is_null($force)) {
             foreach ($hangar as $k => $v) {
                 if ($check[$k] === false) {
                     return sprintf($this->langs['tr_full_storage'], strtolower($this->langs['info'][$v]['name']));
                 } else {
                     continue;
                 }
             }
         } else {
             return $check;
         }
     }
 }
Example #13
0
 public function newsPublic()
 {
     $currentPage = $this->app['http']->request->get('page') <= 0 ? 1 : $this->app['http']->request->get('page');
     $itemsPerPage = $this->app['http']->request->get('count') <= 0 ? 5 : $this->app['http']->request->get('count');
     $neighbours = $this->app['http']->request->get('neighbor') <= 0 ? 1 : $this->app['http']->request->get('neighbor');
     $totalItems = $this->db_website->ypyz_document_article()->count();
     if ($totalItems == 0) {
         return null;
     }
     $pagination = new Pagination($totalItems, $currentPage, $itemsPerPage, $neighbours);
     $offset = $pagination->offset();
     $limit = $pagination->limit();
     $res = $this->pdo->query("SELECT ypyz_document_article.id,ypyz_document.title,ypyz_document.comment,ypyz_document.description,ypyz_picture.path FROM ypyz_document_article\n        LEFT JOIN ypyz_document ON ypyz_document_article.id=ypyz_document.id\n        LEFT JOIN ypyz_picture ON ypyz_picture.id=ypyz_document.cover_id LIMIT {$offset},{$limit}");
     $result_arr = $res->fetchAll(\PDO::FETCH_ASSOC);
     foreach ($result_arr as $key => $res) {
         $result['data'][$key]['id'] = $res['id'];
         $result['data'][$key]['title'] = $res['title'];
         if (emtpy($res['comment'])) {
             $result['data'][$key]['comment'] = 0;
         } else {
             $result['data'][$key]['comment'] = $res['comment'];
         }
         if (emtpy($res['description'])) {
             $result['data'][$key]['description'] = "暂无描述";
         } else {
             $result['data'][$key]['description'] = $res['description'];
         }
         if ($res['path'] != null) {
             $result['data'][$key]['thumb'] = "http://www.didijiankang.cn/webhtml/" . $res['path'];
         } else {
             $result['data'][$key]['thumb'] = "";
         }
     }
     $totalPages = $pagination->totalPages();
     if ($currentPage > $totalPages) {
         $result['page']['current_cursor'] = $totalPages;
         $result['page']['previous_cursor'] = $totalPages == 1 ? 1 : $totalPages - 1;
         $result['page']['next_cursor'] = $totalPages;
     } else {
         $result['page']['current_cursor'] = $currentPage;
         $result['page']['previous_cursor'] = $currentPage <= 1 ? 1 : $currentPage - 1;
         if ($currentPage + 1 >= $totalPages) {
             $result['page']['next_cursor'] = $totalPages;
         } else {
             $result['page']['next_cursor'] = $currentPage + 1;
         }
     }
     $result['page']['total_number'] = $totalItems;
     return $result;
 }
/**
 * AJAX handler for Social Media Account Binding
 */
function tdr_bind_social_media_accounts()
{
    /*
    	HOW TO IMPLEMENT THE SOCIAL MEDIA ACCOUNT CAPTURE FORM
        ===========================================================================
    	**** YOUR FORM ****
    	Attributes:
    		data-tdr-promotion-name="STRING_PROMOTION_SLUG" // The slug for the promotion
    		data-tdr-promotion-referrer="STRING_REFERRAL_ID" // The referral code for the contest
    
    	*** YOUR FORM BUTTON ***
    		<button> with type="submit" class="tdr_bind_social_media_accounts"
    
        *** AJAX SUBMISSION events ***
    		.tdr_bind_social_media_working // Shows while the form submission is performed via AJAX
    		.tdr_bind_social_media_accounts // The <button> hidden during form submission via AJAX
    		successful promotion entries trigger a jQuery event 'tdr_bind_social_media_success' on the FORM element
    
    	*** INPUT TAGS ***
    		wrap input tags in containers with control-group class // allows for validation errors
    
    	*** DIVS FOR SUCCESS AND ERROR ***
    	Success and Failure divs as siblings (outside of) form tag
    		* (Display: none)
    		class=tdr_bind_social_media_error
    		class=tdr_bind_social_media_validation_error
    		class=tdr_bind_social_media_success
    */
    // Setup request return info for client callback
    $return_array = array('message' => '', 'error' => '', 'invalid_message' => '', 'invalid' => array());
    // Parse Data into associative array from JSON
    $form_data = json_decode(stripslashes($_POST['data']), true);
    // Fail & return error if parsing problem
    if (empty($form_data)) {
        $return_array['error'] = 'There was a problem processing your request';
        // parsed JSON was empty
    } else {
        // Decode user information
        $form_data['user_information'] = array_map('urldecode', $form_data['user_information']);
        // Filter and sanitize form data
        $promotion_name = sanitize_title($form_data['request_details']['promotion_name']);
        $provided_referral_id = filter_var($form_data['request_details']['referrer_id'], FILTER_SANITIZE_STRING);
        // Escape HTML from received data
        $user_information = array_map('esc_html', $form_data['user_information']);
        // Check for required form data -- IF promotion name and referral id are present, go ahead
        if (!emtpy($promotion_name) && !empty($provided_referral_id)) {
            $promotion_object = new tdr_promotions();
            // Validate promotion name matches a real campaign -- so meta update filter below only gets valid promotions
            if (!empty($promotion_name) && $promotion_object->get_the_raw_promotion_by_slug($promotion_name)) {
                $filter_update_meta_result = false;
                // Allow social media meta to be defined on a promotion-by-promotion basis
                $filter_update_meta_result = apply_filters('tdr_promotions_create_user', $filter_update_meta_result, $promotion_name, $provided_referral_id, $form_data['user_information']);
                // If filter not used or unsuccessful, use standard rules for twitter/facebook/google+
                if (!$user_registration_result) {
                    // Query for the user
                    $referral_id_query_args = array('role' => 'promo-' . $promotion_name, 'meta_key' => 'referral_id', 'meta_value' => $provided_referral_id);
                    // Execute search for referral id
                    $referral_id_query = new WP_User_Query($referral_id_query_args);
                    // Check if match was found
                    if ($referral_id_query->total_users == "1") {
                        $user_list = $referral_id_query->get_results();
                        // Get the query results
                        $user_id = $user_list[0]->ID;
                        // Get the user ID
                        // Perform the meta update for expected fields that are defined
                        $social_media_fields = array('facebook_id' => 'facebook_id', 'google_plus' => 'google_plus', 'twitter_handle' => 'twitter_handle');
                        foreach ($social_media_fields as $field_name => $meta_key_name) {
                            if (array_key_exists($field_name, $user_information)) {
                                // Field was in form
                                update_usermeta($user_id, $meta_key_name, $user_information[$field_name]);
                            }
                        }
                    }
                    $return_array['message'] = 'Successfully associated social media account(s) with contestant account';
                }
            } else {
                $return_array['invalid_message'] = 'There was a problem processing your request';
                // Bad promotion name
                $return_array['error'] = true;
                // Client only checks to see if error is not false
            }
        } else {
            // Referral id may be user-submitted. Add to invalid fields list if was empty
            if (empty($provided_referral_id)) {
                // Report and have highlighted in front end
                $return_array['invalid'][] = 'referrer_id';
            }
            $return_array['invalid_message'] = 'Missing required information for registration.';
            // May be referral id or promotion name
            // Promotion name is never meant to be user defined -- just returning na error is important
            // Either field being wrong throws an error:
            $return_array['error'] = true;
            // Client only checks to see if error is not false
        }
    }
    // Convert result to JSON
    $return_json = json_encode($return_array);
    // Print out JSON Response
    echo $return_json;
    die;
    // this is required to return a proper result
}