Ejemplo n.º 1
0
 /**
  * Trigger a previously bound event
  *
  * @param string $module Navigate CMS application or module
  * @param string $event Codename of the event to fire
  * @param mixed $parameter One and only parameter to send to the event
  */
 public function trigger($module, $event, $parameter)
 {
     $messages = array();
     if (!is_array($this->events[$module][$event])) {
         return $messages;
     }
     foreach ($this->events[$module][$event] as $trigger) {
         if (APP_DEBUG) {
             firephp_nv::log($trigger, $module . '/' . $event);
         }
         $messages[$trigger['extension']] = call_user_func($trigger['function'], $parameter);
     }
     return $messages;
 }
Ejemplo n.º 2
0
/**
 * Shows the last PHP JSON decoding error.
 * This function needs APP_DEBUG enabled or the url parameter "debug=true".
 * The error is sent to the Firebug FirePHP plugin within Mozilla Firefox.
 *
 * @param string $prepend String to prepend before the error (if exists)
 */
function debug_json_error($prepend = '')
{
    $error = '';
    if (!empty($prepend)) {
        $prepend .= ' - ';
    }
    if (function_exists('json_last_error')) {
        switch (json_last_error()) {
            case JSON_ERROR_NONE:
                $error = '';
                break;
            case JSON_ERROR_DEPTH:
                $error = 'Maximum stack depth exceeded';
                break;
            case JSON_ERROR_STATE_MISMATCH:
                $error = 'Underflow or the modes mismatch';
                break;
            case JSON_ERROR_CTRL_CHAR:
                $error = 'Unexpected control character found';
                break;
            case JSON_ERROR_SYNTAX:
                $error = 'Syntax error, malformed JSON';
                break;
            case JSON_ERROR_UTF8:
                $error = 'Malformed UTF-8 characters, possibly incorrectly encoded';
                break;
            default:
                $error = 'Unknown error';
                break;
        }
    }
    if (!empty($error) && (APP_DEBUG || $_GET['debug'] == 'true')) {
        firephp_nv::log($prepend . $error);
    }
}
Ejemplo n.º 3
0
function nvweb_list_parse_filters($raw, $object = 'item')
{
    global $website;
    global $current;
    $filters = array();
    if (!is_array($raw)) {
        $raw = str_replace("'", '"', $raw);
        $aFilters = json_decode($raw, true);
    } else {
        $aFilters = $raw;
    }
    if (APP_DEBUG && json_last_error() > 0) {
        firephp_nv::log($raw, json_last_error_msg());
    }
    $comparators = array('eq' => '=', 'neq' => '!=', 'gt' => '>', 'gte' => '>=', 'lt' => '<', 'lte' => '<=');
    for ($f = 0; $f < count($aFilters); $f++) {
        $filter = $aFilters[$f];
        $key = array_keys($filter);
        $key = $key[0];
        $value = $filter[$key];
        if (substr($key, 0, 9) == 'property.') {
            // object property value
            // TODO: filters for values in DICTIONARY
            $key = substr($key, 9);
            if (!is_array($value)) {
                if (substr($value, 0, 1) == '$') {
                    if (!isset($_REQUEST[substr($value, 1)])) {
                        continue;
                    }
                    // ignore this filter
                    $value = $_REQUEST[substr($value, 1)];
                    if (empty($value)) {
                        // ignore empty values
                        continue;
                    }
                } else {
                    if (strpos($value, 'property.') === 0) {
                        // retrieve the property value
                        $value = nvweb_properties(array('property' => str_replace("property.", "", $value)));
                    }
                }
                $filters[] = ' AND i.id IN ( 
                                 SELECT node_id 
                                   FROM nv_properties_items
                                  WHERE website = ' . $website->id . ' AND
                                        property_id = ' . protect($key) . ' AND
                                        element = "item" AND
                                        value = ' . protect($value) . '
                               )';
            } else {
                foreach ($value as $comp_type => $comp_value) {
                    if (!is_array($comp_value) && substr($comp_value, 0, 1) == '$') {
                        if (!isset($_REQUEST[substr($comp_value, 1)])) {
                            continue;
                        }
                        // ignore this filter
                        $comp_value = $_REQUEST[substr($comp_value, 1)];
                        if (empty($comp_value)) {
                            // ignore empty values
                            continue;
                        }
                    } else {
                        if (!is_array($comp_value) && strpos($comp_value, 'property.') === 0) {
                            // retrieve the property value
                            $comp_value = nvweb_properties(array('property' => str_replace("property.", "", $comp_value)));
                        }
                    }
                    if (isset($comparators[$comp_type])) {
                        $filters[] = ' 
                            AND i.id IN ( 
                                 SELECT node_id 
                                   FROM nv_properties_items
                                  WHERE website = ' . $website->id . ' AND
                                        property_id = ' . protect($key) . ' AND
                                        element = "item" AND
                                        value ' . $comparators[$comp_type] . ' ' . protect($comp_value, null, true) . '
                            )';
                    } else {
                        if ($comp_type == 'like' || $comp_type == 'not_like') {
                            if (is_array($comp_value)) {
                                // multivalue, query with REGEXP: http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_regexp
                                $filters[] = ' 
                                AND i.id IN ( 
                                     SELECT node_id 
                                       FROM nv_properties_items
                                      WHERE website = ' . $website->id . ' AND
                                            property_id = ' . protect($key) . ' AND
                                            element = "item" AND
                                            value ' . ($comp_type == 'like' ? 'REGEXP' : 'NOT REGEXP') . ' "' . implode('|', $comp_value) . '"
                                )';
                            } else {
                                // single value, standard LIKE
                                $filters[] = ' 
                                AND i.id IN ( 
                                     SELECT node_id 
                                       FROM nv_properties_items
                                      WHERE website = ' . $website->id . ' AND
                                            property_id = ' . protect($key) . ' AND
                                            element = "item" AND
                                            value ' . ($comp_type == 'like' ? 'LIKE' : 'NOT LIKE') . ' ' . protect('%' . $comp_value . '%', null, true) . '
                                )';
                            }
                        } else {
                            if ($comp_type == 'in' || $comp_type == 'nin') {
                                if ($comp_type == 'nin') {
                                    $comp_type = 'NOT IN';
                                } else {
                                    $comp_type = 'IN';
                                }
                                if (!is_array($comp_value)) {
                                    $comp_value = explode(",", $comp_value);
                                }
                                if (empty($comp_value)) {
                                    $comp_value = array(0);
                                }
                                // avoid SQL query exception
                                $filters[] = ' 
                            AND i.id IN ( 
                                SELECT node_id 
                                  FROM nv_properties_items
                                 WHERE website = ' . $website->id . ' AND
                                        property_id = ' . protect($key) . ' AND
                                        element = "item" AND
                                        value ' . $comp_type . '(' . implode(",", array_map(function ($v) {
                                    return protect($v);
                                }, array_values($comp_value))) . ')
                            )';
                            }
                        }
                    }
                }
            }
        } else {
            // object value
            switch ($key) {
                case 'id':
                    $field = 'i.id';
                    $direct_filter = true;
                    break;
                case 'author':
                    $field = 'i.author';
                    $direct_filter = true;
                    break;
                case 'date_to_display':
                    $field = 'i.date_to_display';
                    $direct_filter = true;
                    break;
                case 'score':
                    $field = 'i.score';
                    $direct_filter = true;
                    break;
                case 'votes':
                    $field = 'i.votes';
                    $direct_filter = true;
                    break;
                default:
                    continue;
                    break;
            }
            if ($direct_filter) {
                if (!is_array($value)) {
                    if (substr($value, 0, 1) == '$') {
                        if (!isset($_REQUEST[substr($value, 1)])) {
                            continue;
                        }
                        // ignore this filter
                        $value = $_REQUEST[substr($value, 1)];
                        if (empty($value)) {
                            // ignore empty values
                            continue;
                        }
                    } else {
                        if (strpos($value, 'property.') === 0) {
                            // retrieve the property value
                            $value = nvweb_properties(array('property' => str_replace("property.", "", $value)));
                        }
                    }
                    $filters[] = ' AND ' . $field . ' = ' . protect($value);
                } else {
                    foreach ($value as $comp_type => $comp_value) {
                        if (!is_array($comp_value) && substr($comp_value, 0, 1) == '$') {
                            if (!isset($_REQUEST[substr($comp_value, 1)])) {
                                continue;
                            }
                            // ignore this filter
                            $comp_value = $_REQUEST[substr($comp_value, 1)];
                            if (empty($comp_value)) {
                                // ignore empty values
                                continue;
                            }
                        } else {
                            if (!is_array($comp_value) && strpos($comp_value, 'property.') === 0) {
                                // retrieve the property value
                                $comp_value = nvweb_properties(array('property' => str_replace("property.", "", $comp_value)));
                            }
                        }
                        if (isset($comparators[$comp_type])) {
                            $filters[] = ' AND ' . $field . ' ' . $comparators[$comp_type] . ' ' . protect($comp_value, null, true);
                        } else {
                            if ($comp_type == 'like' || $comp_type == 'not_like') {
                                if (is_array($comp_value)) {
                                    // multivalue, query with REGEXP: http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_regexp
                                    $filters[] = ' AND ' . $field . ' ' . ($comp_type == 'like' ? 'REGEXP' : 'NOT REGEXP') . ' "' . implode('|' . $comp_value) . '"';
                                } else {
                                    // single value, standard LIKE
                                    $filters[] = ' AND ' . $field . ' ' . ($comp_type == 'like' ? 'LIKE' : 'NOT LIKE') . ' ' . protect('%' . $comp_value . '%', null, true);
                                }
                            } else {
                                if ($comp_type == 'in' || $comp_type == 'nin') {
                                    if ($comp_type == 'nin') {
                                        $comp_type = 'NOT IN';
                                    } else {
                                        $comp_type = 'IN';
                                    }
                                    if (is_array($comp_value)) {
                                        $comp_value = implode(",", array_map(function ($v) {
                                            return protect($v);
                                        }, array_values($comp_value)));
                                    } else {
                                        if (empty($comp_value)) {
                                            $comp_value = 0;
                                            // avoid SQL query exception
                                        }
                                    }
                                    $filters[] = ' AND ' . $field . ' ' . $comp_type . '(' . $comp_value . ')';
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $filters = implode("\n", $filters);
    return $filters;
}