Example #1
0
/**
 * 递归去除array中的空键
 */
function array_trim($array)
{
    $array = (array) $array;
    foreach ($array as $k => $v) {
        if ($v == '' || $v == array()) {
            unset($array[$k]);
        } elseif (is_array($v)) {
            $array[$k] = array_trim($v);
        }
    }
    return $array;
}
Example #2
0
/**
 * Trim all non-array values in an n-dimension array.
 */
function array_trim(&$arr)
{
    if (!is_array($arr)) {
        return false;
    }
    foreach ($arr as $key => $val) {
        if (is_array($val)) {
            array_trim($arr[$key]);
        } else {
            $arr[$key] = trim($arr[$key]);
        }
    }
}
/**
 * This file is part of the Froxlor project.
 * Copyright (c) 2003-2009 the SysCP Team (see authors).
 * Copyright (c) 2010 the Froxlor Team (see authors).
 *
 * For the full copyright and license information, please view the COPYING
 * file that was distributed with this source code. You can also view the
 * COPYING file online at http://files.froxlor.org/misc/COPYING.txt
 *
 * @copyright  (c) the authors
 * @author     Florian Lippert <*****@*****.**> (2003-2009)
 * @author     Froxlor team <*****@*****.**> (2010-)
 * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
 * @package    Functions
 *
 */
function storeSettingIpAddress($fieldname, $fielddata, $newfieldvalue)
{
    $returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
    if ($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'system' && isset($fielddata['varname']) && $fielddata['varname'] == 'ipaddress') {
        $mysql_access_host_array = array_map('trim', explode(',', Settings::Get('system.mysql_access_host')));
        $mysql_access_host_array[] = $newfieldvalue;
        $mysql_access_host_array = array_unique(array_trim($mysql_access_host_array));
        $mysql_access_host = implode(',', $mysql_access_host_array);
        correctMysqlUsers($mysql_access_host_array);
        Settings::Set('system.mysql_access_host', $mysql_access_host);
    }
    return $returnvalue;
}
Example #4
0
 function parse($caching = true)
 {
     $feed = new SimplePie();
     $feed->feed_url($this->uri);
     $feed->cache_location(SIMPLEPIE_CACHE_DIR);
     $feed->enable_caching($caching);
     // parse
     $parse_result = @$feed->init();
     if ($parse_result === false) {
         trigger_error("FeedParser::parse(): Failed to parse feed. uri: {$this->uri}", E_USER_NOTICE);
         return false;
     }
     $feed->handle_content_type();
     $link = $feed->get_feed_link();
     $channel = array('title' => $feed->get_feed_title(), 'link' => $link, 'uri' => $this->uri, 'last_modified' => SimplePie_Sanitize::parse_date($feed->data['last-modified']), 'description' => $feed->get_feed_description());
     // url
     $url = new Net_URL($feed->get_feed_link());
     $items = array();
     $feed_items = @$feed->get_items();
     if (is_array($feed_items)) {
         foreach ($feed_items as $item) {
             // category
             $categories = $item->get_category();
             if ($categories != '') {
                 $category = split(" ", $categories);
                 $category = array_trim($category);
             } else {
                 $category = '';
             }
             // author
             $author = '';
             if (is_array($authors = $item->get_authors())) {
                 $men = array();
                 foreach ($item->get_authors() as $man) {
                     $men[] = $man->get_name();
                 }
                 $author = join(', ', $men);
             }
             // description
             $description = $item->get_description();
             if (empty($description)) {
                 $description = '';
             }
             $items[] = array('title' => $item->get_title(), 'uri' => $item->get_permalink(), 'description' => $description, 'date' => $item->get_date('U'), 'author' => $author, 'category' => $category);
         }
     }
     $this->data = array('channel' => $channel, 'items' => $items);
     $this->parser =& $feed;
     unset($feed);
     return true;
 }
/**
 * Replaces Strings in an array, with the advantage that you
 * can select which fields should be str_replace'd
 *
 * @param mixed String or array of strings to search for
 * @param mixed String or array to replace with
 * @param array The subject array
 * @param string The fields which should be checked for, separated by spaces
 * @return array The str_replace'd array
 * @author Florian Lippert <*****@*****.**>
 */
function str_replace_array($search, $replace, $subject, $fields = '')
{
    if (is_array($subject)) {
        $fields = array_trim(explode(' ', $fields));
        foreach ($subject as $field => $value) {
            if (!is_array($fields) || empty($fields) || is_array($fields) && !empty($fields) && in_array($field, $fields)) {
                $subject[$field] = str_replace($search, $replace, $subject[$field]);
            }
        }
    } else {
        $subject = str_replace($search, $replace, $subject);
    }
    return $subject;
}
Example #6
0
function execute_document_ready($l)
{
    $document_ready_exposed = document_ready(true);
    if ($document_ready_exposed != false) {
        $document_ready_exposed = explode(' ', $document_ready_exposed);
        $document_ready_exposed = array_unique($document_ready_exposed);
        $document_ready_exposed = array_trim($document_ready_exposed);
        foreach ($document_ready_exposed as $api_function) {
            if (function_exists($api_function)) {
                $l = $api_function($l);
            }
        }
    }
    return $l;
}
/**
 * This file is part of the SysCP project.
 * Copyright (c) 2003-2009 the SysCP Team (see authors).
 *
 * For the full copyright and license information, please view the COPYING
 * file that was distributed with this source code. You can also view the
 * COPYING file online at http://files.syscp.org/misc/COPYING.txt
 *
 * @copyright  (c) the authors
 * @author     Florian Lippert <*****@*****.**>
 * @license    GPLv2 http://files.syscp.org/misc/COPYING.txt
 *
 * @version    $Id$
 */
function storeSettingMysqlAccessHost($fieldname, $fielddata, $newfieldvalue)
{
    $returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
    if ($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'system' && isset($fielddata['varname']) && $fielddata['varname'] == 'mysql_access_host') {
        $mysql_access_host_array = array_map('trim', explode(',', $newfieldvalue));
        if (in_array('127.0.0.1', $mysql_access_host_array) && !in_array('localhost', $mysql_access_host_array)) {
            $mysql_access_host_array[] = 'localhost';
        }
        if (!in_array('127.0.0.1', $mysql_access_host_array) && in_array('localhost', $mysql_access_host_array)) {
            $mysql_access_host_array[] = '127.0.0.1';
        }
        $mysql_access_host_array = array_unique(array_trim($mysql_access_host_array));
        $newfieldvalue = implode(',', $mysql_access_host_array);
        correctMysqlUsers($mysql_access_host_array);
    }
    return $returnvalue;
}
/**
 * Wrapper around htmlentities to handle arrays, with the advantage that you
 * can select which fields should be handled by htmlentities
 *
 * @param array The subject array
 * @param string The fields which should be checked for, separated by spaces
 * @param int See php documentation about this
 * @param string See php documentation about this
 * @return array The array with htmlentitie'd strings
 * @author Florian Lippert <*****@*****.**>
 */
function htmlentities_array($subject, $fields = '', $quote_style = ENT_QUOTES, $charset = 'UTF-8')
{
    if (is_array($subject)) {
        if (!is_array($fields)) {
            $fields = array_trim(explode(' ', $fields));
        }
        foreach ($subject as $field => $value) {
            if (!is_array($fields) || empty($fields) || is_array($fields) && !empty($fields) && in_array($field, $fields)) {
                /**
                 * Just call ourselve to manage multi-dimensional arrays
                 */
                $subject[$field] = htmlentities_array($subject[$field], $fields, $quote_style, $charset);
            }
        }
    } else {
        $subject = htmlentities($subject, $quote_style, $charset);
    }
    return $subject;
}
Example #9
0
/** function array_clean [arrayClean]
 *		Strips out the unnecessary bits from an array
 *		so it can be input into a database, or to just
 *		generally clean an array of fluff
 *
 * @param array data array to be cleaned
 * @param mixed csv or array of allowed keys
 * @param mixed optional csv or array of required keys
 * @return array
 */
function array_clean($array, $keys, $reqd = array())
{
    if (!is_array($array)) {
        return array();
    }
    array_trim($keys);
    if (0 == count($keys)) {
        throw new MyException(__FUNCTION__ . ': No keys given');
    }
    array_trim($reqd);
    $return = array();
    foreach ($keys as $key) {
        if (in_array($key, $reqd) && empty($array[$key])) {
            throw new MyException(__FUNCTION__ . ': Required element (' . $key . ') missing');
        }
        if (isset($array[$key])) {
            $return[$key] = $array[$key];
        }
    }
    return $return;
}
Example #10
0
/** function array_clean [arrayClean]
 *		Strips out the unnecessary bits from an array
 *		so it can be input into a database, or to just
 *		generally clean an array of fluff
 *
 * @param array $array data array to be cleaned
 * @param mixed $keys csv or array of allowed keys
 * @param mixed $required optional csv or array of required keys
 *
 * @return array
 * @throws MyException
 */
function array_clean($array, $keys, $required = array())
{
    if (!is_array($array)) {
        return array();
    }
    array_trim($keys);
    array_trim($required);
    $keys = array_unique(array_merge($keys, $required));
    if (empty($keys)) {
        return array();
    }
    $return = array();
    foreach ($keys as $key) {
        if (in_array($key, $required) && empty($array[$key])) {
            throw new MyException(__FUNCTION__ . ': Required element (' . $key . ') missing');
        }
        if (isset($array[$key])) {
            $return[$key] = $array[$key];
        }
    }
    return $return;
}
/**
 * Wrapper around stripslashes to handle arrays, with the advantage that you
 * can select which fields should be handled by htmlentities and with advantage,
 * that you can eliminate all slashes by setting complete=true
 *
 * @param array The subject array
 * @param int See php documentation about this
 * @param string See php documentation about this
 * @param string The fields which should be checked for, separated by spaces
 * @param bool Select true to use stripslashes_complete instead of stripslashes
 * @return array The array with stripslashe'd strings
 * @author Florian Lippert <*****@*****.**>
 */
function stripslashes_array($subject, $fields = '', $complete = false)
{
    if (is_array($subject)) {
        if (!is_array($fields)) {
            $fields = array_trim(explode(' ', $fields));
        }
        foreach ($subject as $field => $value) {
            if (!is_array($fields) || empty($fields) || is_array($fields) && !empty($fields) && in_array($field, $fields)) {
                /**
                 * Just call ourselve to manage multi-dimensional arrays
                 */
                $subject[$field] = stripslashes_array($subject[$field], $fields, $complete);
            }
        }
    } else {
        if ($complete == true) {
            $subject = stripslashes_complete($subject);
        } else {
            $subject = stripslashes($subject);
        }
    }
    return $subject;
}
Example #12
0
 public function update_password($data, $id)
 {
     if (array_valid($data) && is_valid_id($id)) {
         // Ensure no bogus whitespace on any of the information
         array_trim($data);
         // Let's be sure the passwords match
         $new_password = $data['magickey'];
         $match_password = $data['matchkey'];
         if ($new_password === $match_password) {
             $update_data['magickey'] = sha1($new_password);
             $this->db->where('id', $id);
             $this->db->update('user', $update_data);
             return TRUE;
         } else {
             $errors[] = 'The passwords for both fields did not match, please try again';
         }
     } else {
         $errors[] = 'No user information was provided';
     }
     if (array_valid($errors)) {
         return $errors;
     }
 }
/**
 * Wrapper around html_entity_decode to handle arrays, with the advantage that you
 * can select which fields should be handled by htmlentities and with advantage,
 * that you can eliminate all html entities by setting complete=true
 *
 * @param array The subject array
 * @param string The fields which should be checked for, separated by spaces
 * @param bool Select true to use html_entity_decode_complete instead of html_entity_decode
 * @param int See php documentation about this
 * @param string See php documentation about this
 * @return array The array with html_entity_decode'd strings
 * @author Florian Lippert <*****@*****.**>
 */
function html_entity_decode_array($subject, $fields = '', $complete = false, $quote_style = ENT_COMPAT, $charset = 'ISO-8859-1')
{
    if (is_array($subject)) {
        if (!is_array($fields)) {
            $fields = array_trim(explode(' ', $fields));
        }
        foreach ($subject as $field => $value) {
            if (!is_array($fields) || empty($fields) || is_array($fields) && !empty($fields) && in_array($field, $fields)) {
                /**
                 * Just call ourselve to manage multi-dimensional arrays
                 */
                $subject[$field] = html_entity_decode_array($subject[$field], $fields, $complete, $quote_style, $charset);
            }
        }
    } else {
        if ($complete == true) {
            $subject = html_entity_decode_complete($subject, $quote_style, $charset);
        } else {
            $subject = html_entity_decode($subject, $quote_style, $charset);
        }
    }
    return $subject;
}
Example #14
0
/**
 * @example
 * $value = [
 *     'a' => [
 *         'b' => [],
 *     ],
 *     'c' => [
 *         'd' => [
 *             'e' => 1,
 *         ],
 *     ],
 * ];
 *
 * // [
 * //     'c' => [
 * //         'd' => [
 * //             'e' => 1,
 * //         ],
 * //     ],
 * // ];
 * $value = \Owl\array_trim($value);
 */
function array_trim(array $target)
{
    $keys = array_keys($target);
    $is_array = $keys === array_keys($keys);
    $result = [];
    foreach ($target as $key => $value) {
        if (is_array($value) && $value) {
            $value = array_trim($value);
        }
        if ($value === null || $value === '' || $value === []) {
            continue;
        }
        $result[$key] = $value;
    }
    if ($is_array && $result) {
        $result = array_values($result);
    }
    return $result;
}
Example #15
0
                                <td>
                                	<input type='text' name='dfinal_dia' maxlength="2" size="2" />&nbsp;/
                                    <input type='text' name='dfinal_mes' maxlength="2" size="2" />&nbsp;/
                                    <input type='text' name='dfinal_ano' maxlength="4" size="4" />
								</td>
                            </tr>
							<tr>
                                <td colspan="2" class="bottom_row">
                                	<input type='submit' value='Pesquisar' />
                                </td>
                            </tr>
                        </table>
                        </form>
					<?php 
        } else {
            $_POST = array_trim($_POST);
            $data_inicial = implode('-', array($_POST['dinicial_ano'], $_POST['dinicial_mes'], $_POST['dinicial_dia']));
            $data_final = implode('-', array($_POST['dfinal_ano'], $_POST['dfinal_mes'], $_POST['dfinal_dia']));
            $c = new conexao();
            $c->set_charset('utf8');
            $q = "SELECT a.nome, b.* FROM usuarios AS a INNER JOIN logs AS b ON a.id = b.usuario_id WHERE horario BETWEEN '{$data_inicial}' AND '{$data_final}';";
            $r = $c->query($q);
            ?>
                    	<h2>Mostrando registros entre (<?php 
            echo $data_inicial;
            ?>
) e (<?php 
            echo $data_final;
            ?>
)</h2>
                    	<table class="content_table">
Example #16
0
 function array_trim($arr, $charlist = null)
 {
     foreach ($arr as $key => $value) {
         if (is_array($value)) {
             $result[$key] = array_trim($value, $charlist);
         } else {
             $result[$key] = trim($value, $charlist);
         }
     }
     return $result;
 }
Example #17
0
 /**
  * `
  *
  * Prints the selected categories as an <UL> tree, you might pass several
  * options for more flexibility
  *
  * @param
  *            array
  *
  * @param
  *            boolean
  *
  *
  * @version 1.0
  *
  * @since   Version 1.0
  *
  */
 public function html_tree($parent, $link = false, $active_ids = false, $active_code = false, $remove_ids = false, $removed_ids_code = false, $ul_class_name = false, $include_first = false, $content_type = false, $li_class_name = false, $add_ids = false, $orderby = false, $only_with_content = false, $visible_on_frontend = false, $depth_level_counter = 0, $max_level = false, $list_tag = false, $list_item_tag = false, $active_code_tag = false, $ul_class_deep = false, $only_ids = false)
 {
     $db_t_content = $this->tables['content'];
     $table = $db_categories = $this->tables['categories'];
     if ($parent == false) {
         $parent = 0;
         $include_first = false;
     } else {
         $parent = (int) $parent;
     }
     if (!is_array($orderby)) {
         $orderby[0] = 'position';
         $orderby[1] = 'ASC';
     }
     if (isset($remove_ids) and !is_array($remove_ids)) {
         $temp = intval($remove_ids);
         $remove_ids_q = " and id not in ({$temp}) ";
     } elseif (is_array($remove_ids) and !empty($remove_ids)) {
         $remove_ids_q = implode(',', $remove_ids);
         if ($remove_ids_q != '') {
             $remove_ids_q = " and id not in ({$remove_ids_q}) ";
         }
     } else {
         $remove_ids_q = false;
     }
     if (!empty($add_ids)) {
         $add_ids_q = implode(',', $add_ids);
         $add_ids_q = " and id in ({$add_ids_q}) ";
     } else {
         $add_ids_q = false;
     }
     if ($max_level != false and $depth_level_counter != false) {
         if (intval($depth_level_counter) >= intval($max_level)) {
             print '';
             return;
         }
     }
     if (isset($list_tag) == false or $list_tag == false) {
         $list_tag = 'ul';
     }
     if (isset($active_code_tag) == false or $active_code_tag == false) {
         $active_code_tag = '';
     }
     if (isset($list_item_tag) == false or $list_item_tag == false) {
         $list_item_tag = 'li';
     }
     if (empty($limit)) {
         $limit = array(0, 10);
     }
     $table = mw()->database_manager->real_table_name($table);
     $content_type = addslashes($content_type);
     $hard_limit = " LIMIT 300 ";
     $inf_loop_fix = "  and {$table}.id!={$table}.parent_id  ";
     //	$inf_loop_fix = "     ";
     if ($only_ids != false) {
         if (is_string($only_ids)) {
             $only_ids = explode(',', $only_ids);
         }
         $sql = "SELECT * FROM {$table} WHERE id IN (" . implode(',', $only_ids) . ") ";
         $sql = $sql . " and data_type='category'   and is_deleted=0  ";
         //   $sql = $sql . "$remove_ids_q  $add_ids_q $inf_loop_fix  ";
         $sql = $sql . " group by id order by {$orderby[0]}  {$orderby[1]}  {$hard_limit}";
     } else {
         if ($content_type == false) {
             if ($include_first == true) {
                 $sql = "SELECT * FROM {$table} WHERE id={$parent} ";
                 $sql = $sql . " and data_type='category'   and is_deleted=0  ";
                 $sql = $sql . "{$remove_ids_q}  {$add_ids_q} {$inf_loop_fix}  ";
                 $sql = $sql . " group by id order by {$orderby[0]}  {$orderby[1]}  {$hard_limit}";
             } else {
                 $sql = "SELECT * FROM {$table} WHERE parent_id={$parent} AND data_type='category' AND is_deleted=0 ";
                 $sql = $sql . "{$remove_ids_q} {$add_ids_q} {$inf_loop_fix} group by id order by {$orderby[0]}  {$orderby[1]}   {$hard_limit}";
             }
         } else {
             if ($include_first == true) {
                 $sql = "SELECT * FROM {$table} WHERE id={$parent}  AND is_deleted=0  ";
                 $sql = $sql . "{$remove_ids_q} {$add_ids_q}   {$inf_loop_fix} group by id order by {$orderby[0]}  {$orderby[1]}  {$hard_limit}";
             } else {
                 $sql = "SELECT * FROM {$table} WHERE parent_id={$parent} AND is_deleted=0 AND data_type='category' AND (categories_content_type='{$content_type}' OR categories_content_type='inherit' ) ";
                 $sql = $sql . " {$remove_ids_q}  {$add_ids_q} {$inf_loop_fix} group by id order by {$orderby[0]}  {$orderby[1]}   {$hard_limit}";
             }
         }
     }
     if (!empty($limit)) {
         $my_offset = $limit[1] - $limit[0];
         $my_limit_q = " limit  {$limit[0]} , {$my_offset}  ";
     } else {
         $my_limit_q = false;
     }
     $output = '';
     //$q = $this->app->database_manager->query($sql, $cache_id = 'html_tree_parent_cats_q_' . crc32($sql), 'categories/' . intval($parent));
     $q = $this->app->database_manager->query($sql, false);
     $result = $q;
     $only_with_content2 = $only_with_content;
     $do_not_show_next = false;
     $chosen_categories_array = array();
     if (isset($result) and is_array($result) and !empty($result)) {
         $depth_level_counter++;
         $i = 0;
         $do_not_show = false;
         if ($do_not_show == false) {
             $print1 = false;
             if (trim($list_tag) != '') {
                 if ($ul_class_name == false) {
                     $print1 = "<{$list_tag}  class='{active_class} category_tree depth-{$depth_level_counter}'>";
                 } else {
                     $cl_name = $ul_class_name;
                     if ($depth_level_counter > 1) {
                         $cl_name = $ul_class_deep;
                     }
                     $print1 = "<{$list_tag} class='{active_class} {$cl_name} depth-{$depth_level_counter}'>";
                 }
             }
             if (intval($parent) != 0 and intval($parent) == intval(CATEGORY_ID)) {
                 $print1 = str_replace('{active_class}', 'active', $print1);
             }
             $print1 = str_replace('{active_class}', '', $print1);
             print $print1;
             foreach ($result as $item) {
                 if ($only_with_content == true) {
                     $do_not_show = false;
                     $check_in_content = false;
                     $children_content = array();
                     $do_not_show = false;
                     if (!empty($children_content)) {
                         $do_not_show = false;
                     } else {
                         $do_not_show = true;
                     }
                 } else {
                     $do_not_show = false;
                 }
                 $iid = $item['id'];
                 if ($do_not_show == false) {
                     $output = $output . $item['title'];
                     if ($li_class_name == false) {
                         $output = "<{$list_item_tag} class='{active_class} category_element depth-{$depth_level_counter} item_{$iid}'   value='{$item['id']}' data-category-id='{$item['id']}' data-category-parent-id='{$item['parent_id']}' data-item-id='{$item['id']}'  data-to-table='{$item['rel_type']}'  data-to-table-id='{$item['rel_id']}'    data-categories-type='{$item['data_type']}' {active_code_tag} title='{title_slashes}'>";
                     } else {
                         $output = "<{$list_item_tag} class='{active_class} {$li_class_name}  category_element depth-{$depth_level_counter} item_{$iid}'  value='{$item['id']}' data-item-id='{$item['id']}' data-category-id='{$item['id']}'  data-to-table='{$item['rel_type']}'  data-to-table-id='{$item['rel_id']}'  data-categories-type='{$item['data_type']}'  {active_code_tag} title='{title_slashes}' >";
                     }
                 }
                 if (intval($item['id']) != 0 and intval($item['id']) == intval(CATEGORY_ID)) {
                     $output = str_replace('{active_class}', 'active', $output);
                 } else {
                     $output = str_replace('{active_class}', '', $output);
                 }
                 if ($do_not_show == false) {
                     if ($link != false) {
                         $to_print = false;
                         $empty1 = intval($depth_level_counter);
                         $empty = '';
                         for ($i1 = 0; $i1 < $empty1; $i1++) {
                             $empty = $empty . '&nbsp;&nbsp;';
                         }
                         $ext_classes = '';
                         $to_print = str_replace('{id}', $item['id'], $link);
                         if (stristr($link, '{items_count}')) {
                             $to_print = str_ireplace('{items_count}', $this->get_items_count($item['id']), $to_print);
                         }
                         $to_print = str_ireplace('{url}', $this->link($item['id']), $to_print);
                         $to_print = str_ireplace('{link}', $this->link($item['id']), $to_print);
                         $to_print = str_replace('{exteded_classes}', $ext_classes, $to_print);
                         $to_print = str_ireplace('{categories_url}', $this->link($item['id']), $to_print);
                         $to_print = str_ireplace('{nest_level}', 'depth-' . $depth_level_counter, $to_print);
                         $to_print = str_ireplace('{title}', $item['title'], $to_print);
                         $to_print = str_ireplace('{title_slashes}', addslashes($item['title']), $to_print);
                         $to_print = str_replace('{content_link_class}', '', $to_print);
                         $output = str_replace('{title_slashes}', addslashes($item['title']), $output);
                         $output = str_replace('{content_link_class}', '', $output);
                         $active_class = ' ';
                         $active_parent_class = '';
                         //if(isset($item['parent']) and intval($item['parent']) != 0){
                         if (intval($item['parent_id']) != 0 and intval($item['parent_id']) == intval(CATEGORY_ID)) {
                             $active_parent_class = 'active-parent';
                             $active_class = '';
                         } else {
                             if (intval($item['id']) != 0 and intval($item['id']) == intval(CATEGORY_ID)) {
                                 $active_parent_class = 'active-parent';
                                 $active_class = 'active';
                             } else {
                                 $active_parent_class = '';
                             }
                         }
                         $active_class = str_replace('"', ' ', $active_class);
                         $to_print = str_replace('{active_class}', $active_class, $to_print);
                         $to_print = str_replace('{active_parent_class}', $active_parent_class, $to_print);
                         $to_print = str_ireplace('{categories_content_type}', trim($item['categories_content_type']), $to_print);
                         $to_print = str_replace('{empty}', $empty, $to_print);
                         $active_found = false;
                         if (is_string($active_ids)) {
                             $active_ids = explode(',', $active_ids);
                         }
                         if (is_array($active_ids) == true) {
                             $active_ids = array_trim($active_ids);
                             foreach ($active_ids as $value_active_cat) {
                                 if ($value_active_cat != '') {
                                     $value_active_cat = intval($value_active_cat);
                                     if (intval($item['id']) == $value_active_cat) {
                                         $active_found = $value_active_cat;
                                     }
                                 }
                             }
                             if ($active_found == true) {
                                 $to_print = str_replace('{active_code}', $active_code, $to_print);
                                 $to_print = str_replace('{active_class}', $active_class, $to_print);
                                 $to_print = str_replace('{active_code_tag}', $active_code_tag, $to_print);
                                 $output = str_replace('{active_code_tag}', $active_code_tag, $output);
                             } else {
                                 $to_print = str_replace('{active_code}', '', $to_print);
                             }
                         } else {
                             $to_print = str_ireplace('{active_code}', '', $to_print);
                         }
                         $output = str_replace('{active_code_tag}', '', $output);
                         $output = str_replace('{title_slashes}', '', $output);
                         $output = str_replace('{exteded_classes}', $ext_classes, $output);
                         $to_print = str_replace('{items_count}', '', $to_print);
                         $to_print = str_replace('{active_class}', '', $to_print);
                         $to_print = str_replace('{active_code_tag}', '', $to_print);
                         if (is_array($remove_ids) == true) {
                             if (in_array($item['id'], $remove_ids)) {
                                 if ($removed_ids_code == false) {
                                     $to_print = false;
                                 } else {
                                     $to_print = str_ireplace('{removed_ids_code}', $removed_ids_code, $to_print);
                                 }
                             } else {
                                 $to_print = str_ireplace('{removed_ids_code}', '', $to_print);
                             }
                         }
                         if (strval($to_print) == '') {
                             print $output . $item['title'];
                         } else {
                             print $output . $to_print;
                         }
                     } else {
                         print $output . $item['title'];
                     }
                     $children_of_the_main_parent1 = array();
                     if (!isset($remove_ids) or !is_array($remove_ids)) {
                         $remove_ids = array();
                     }
                     $remove_ids[] = $item['id'];
                     if ($only_ids == false) {
                         $children = $this->html_tree($item['id'], $link, $active_ids, $active_code, $remove_ids, $removed_ids_code, $ul_class_name, false, $content_type, $li_class_name, $add_ids = false, $orderby, $only_with_content, $visible_on_frontend, $depth_level_counter, $max_level, $list_tag, $list_item_tag, $active_code_tag, $ul_class_deep);
                     }
                     print "</{$list_item_tag}>";
                 }
             }
             if (trim($list_tag) != '') {
                 print "</{$list_tag}>";
             }
         }
     }
 }
Example #18
0
    function index($params, $config)
    {
        $current_page = $current_page = 1;
        $post_params = $params;
        if (isset($post_params['id'])) {
            $paging_param = 'current_page' . crc32($post_params['id']);
            unset($post_params['id']);
        }
        $cat_from_url = url_param('category');
        $posts_parent_related = false;
        if (isset($params['current_page'])) {
            // $params['current_page'] = $params['current_page'];
        } elseif (isset($params['curent-page'])) {
            $params['current_page'] = $params['curent-page'];
        } elseif (isset($params['current-page'])) {
            $params['current_page'] = $params['current-page'];
        } elseif (isset($params['curent-page'])) {
            $params['current_page'] = $params['curent-page'];
        }
        if (isset($params['paging_param'])) {
            if (isset($params[$params['paging_param']])) {
                $current_page = $current_page = $params['current_page'] = $params[$params['paging_param']];
                $paging_param = $params['paging_param'];
            }
        }
        if (isset($params['current_page'])) {
            $current_page = $params['current_page'] = $params['current_page'];
        } else {
            $current_page_from_url = url_param($paging_param);
            if ($current_page_from_url != false) {
                $current_page = $current_page_from_url;
            }
        }
        if (isset($post_params['data-page-number'])) {
            $post_params['current_page'] = $post_params['data-page-number'];
            unset($post_params['data-page-number']);
        }
        if (isset($post_params['data-category-id'])) {
            $post_params['category'] = $post_params['data-category-id'];
            unset($post_params['data-category-id']);
        }
        if (isset($params['data-paging-param'])) {
            $paging_param = $params['data-paging-param'];
        }
        $show_fields = false;
        if (isset($post_params['data-show'])) {
            $show_fields = $post_params['data-show'];
        }
        if (isset($post_params['show'])) {
            $show_fields = $post_params['show'];
        }
        $set_content_type_from_opt = get_option('data-content-type', $params['id']);
        $show_fields1 = get_option('data-show', $params['id']);
        if ($show_fields1 != false and is_string($show_fields1) and trim($show_fields1) != '') {
            $show_fields = $show_fields1;
        }
        if ($show_fields != false and is_string($show_fields)) {
            $show_fields = explode(',', $show_fields);
        }
        if (isset($post_params['limit'])) {
            $post_params['limit'] = $post_params['limit'];
        }
        if (isset($post_params['data-limit'])) {
            $post_params['limit'] = $post_params['data-limit'];
        }
        if (!isset($post_params['data-limit'])) {
            $posts_limit = get_option('data-limit', $params['id']);
            if ($posts_limit != false) {
                $post_params['limit'] = $posts_limit;
            }
        }
        $posts_parent_category = $posts_parent_category_cfg = get_option('data-category-id', $params['id']);
        if ($posts_parent_category == '') {
            $posts_parent_category = false;
        }
        $set_category_for_posts = false;
        $posts_limit = get_option('data-limit', $params['id']);
        if ($posts_limit != false) {
            $post_params['data-limit'] = $post_params['limit'] = $posts_limit;
        }
        $cfg_page_id = $cfg_page_id_force = get_option('data-page-id', $params['id']);
        if ($cfg_page_id == false and isset($post_params['data-page-id'])) {
            $cfg_page_id = intval($post_params['data-page-id']);
        } else {
            if ($cfg_page_id == false and isset($post_params['content_id'])) {
                $cfg_page_id = intval($post_params['content_id']);
            } else {
                if ($cfg_page_id == false and isset($post_params['content-id'])) {
                    $cfg_page_id = intval($post_params['content-id']);
                } elseif ($cfg_page_id == false and isset($post_params['current_page'])) {
                    $cfg_page_id = 'current_page';
                }
            }
        }
        if ($posts_parent_category == false and isset($post_params['category_id'])) {
            $posts_parent_category = $post_params['category_id'];
        }
        if ($posts_parent_category == false and isset($post_params['related'])) {
            if (defined('CATEGORY_ID') and CATEGORY_ID > 0) {
                $posts_parent_category = $posts_parent_related = CATEGORY_ID;
            }
        }
        if ($posts_parent_category_cfg == 'related') {
            $posts_parent_related = true;
            $posts_parent_category = $posts_parent_related = CATEGORY_ID;
        }
        if ($posts_parent_category == false and $cfg_page_id == 'current_page') {
            if (defined('PAGE_ID') and PAGE_ID > 0) {
                $cfg_page_id = PAGE_ID;
            }
        }
        if ($posts_parent_category_cfg == false) {
            if (defined('CATEGORY_ID') and CATEGORY_ID > 0) {
                $posts_parent_category = CATEGORY_ID;
            }
        }
        if ($cfg_page_id == false and isset($post_params['related']) and $post_params['related'] != false and (!isset($post_params['parent']) or $post_params['parent'] == false)) {
            if (defined('PAGE_ID') and PAGE_ID > 0) {
                $cfg_page_id = PAGE_ID;
                $post_params['parent'] = $cfg_page_id;
            }
        }
        if (isset($post_params['most_ordered'])) {
            //
            $str0 = 'table=cart&limit=30&rel_type=content&fields=rel_id&order_by=id desc';
            $orders = db_get($str0);
            if (!empty($orders)) {
                $ids = array();
                foreach ($orders as $order) {
                    $ids[] = $order['rel_id'];
                }
                $post_params['ids'] = $ids;
            }
        }
        if (isset($post_params['recently_viewed'])) {
            if (defined("MAIN_PAGE_ID") and defined("CONTENT_ID")) {
                $str0 = 'table=stats_pageviews&limit=30&main_page_id=' . MAIN_PAGE_ID . '&page_id=[neq]' . CONTENT_ID . '&fields=page_id&order_by=id desc&no_cache=true';
                $orders = db_get($str0);
                if (!empty($orders)) {
                    $ids = array();
                    foreach ($orders as $order) {
                        $ids[] = $order['page_id'];
                    }
                    $post_params['ids'] = $ids;
                }
            }
        }
        if ($posts_parent_related == false) {
            if (intval($cfg_page_id_force) or !isset($params['global'])) {
                if ($cfg_page_id != false and intval($cfg_page_id) > 0) {
                    $sub_categories = array();
                    $page_categories = false;
                    if (intval($cfg_page_id) != 0 and $cat_from_url == false) {
                        $str0 = 'table=categories&limit=1000&data_type=category&what=categories&' . 'parent_id=0&rel_id=' . $cfg_page_id;
                        $page_categories = db_get($str0);
                        $str0 = 'table=categories&limit=1000&data_type=category&what=categories&' . 'parent_id=0&rel_id=' . $cfg_page_id;
                        $page_categories = db_get('table=categories&limit=1&data_type=category&' . 'parent_id=0&rel_id=' . $cfg_page_id);
                        if (is_array($page_categories)) {
                            foreach ($page_categories as $item_cat) {
                                $sub_categories[] = $item_cat['id'];
                                $more = get_category_children($item_cat['id']);
                                if ($more != false and is_array($more)) {
                                    foreach ($more as $item_more_subcat) {
                                        $sub_categories[] = $item_more_subcat;
                                    }
                                }
                            }
                        }
                    }
                    if ($posts_parent_category != false and intval($posts_parent_category) > 0 and $cat_from_url == false) {
                        if ($page_categories != false and is_array($page_categories) and !empty($page_categories)) {
                            // $sub_categories = array();
                            foreach ($page_categories as $item_cat) {
                                if (intval($item_cat['id']) == intval($posts_parent_category)) {
                                    $sub_categories[] = $item_cat['id'];
                                }
                            }
                        } elseif ($posts_parent_category_cfg != false) {
                            $post_params['category'] = $posts_parent_category_cfg;
                        }
                        if (is_array($sub_categories) and !empty($sub_categories) and isset($post_params['related']) and $post_params['related'] != false) {
                            $post_params['category'] = $sub_categories;
                        } elseif ($cfg_page_id != false) {
                            $post_params['parent'] = $cfg_page_id;
                        }
                    } else {
                        $post_params['parent'] = $cfg_page_id;
                        if (($cfg_page_id == PAGE_ID or $cfg_page_id == MAIN_PAGE_ID) and (!isset($post_params['category']) or $post_params['category'] == false) and $cat_from_url != false) {
                            $post_params['category'] = $cat_from_url;
                        }
                    }
                } elseif ($cat_from_url != false) {
                    $post_params['category'] = $cat_from_url;
                } elseif ($posts_parent_category != false and intval($posts_parent_category) > 0 and $cfg_page_id != false) {
                    $post_params['category'] = $posts_parent_category;
                }
            }
            if ($posts_parent_category_cfg != false and intval($posts_parent_category_cfg) > 0 and $cfg_page_id_force != false and intval($cfg_page_id_force) > 0) {
                $post_params['category'] = $posts_parent_category_cfg;
            }
        } else {
            $post_params['category'] = $posts_parent_related;
        }
        $tn_size = array('150');
        $tn = $tn_size;
        if (isset($post_params['data-thumbnail-size'])) {
            $temp = explode('x', strtolower($post_params['data-thumbnail-size']));
            if (!empty($temp)) {
                $tn_size = $temp;
            }
        } else {
            $cfg_page_item = get_option('data-thumbnail-size', $params['id']);
            if ($cfg_page_item != false) {
                $temp = explode('x', strtolower($cfg_page_item));
                if (!empty($temp)) {
                    $tn_size = $temp;
                }
            }
        }
        if (!isset($tn[0]) or $tn[0] == 150) {
            $tn[0] = 350;
        }
        if (!isset($tn[1])) {
            $tn[1] = $tn[0];
        }
        $character_limit = 120;
        $cfg_character_limit = get_option('data-character-limit', $params['id']);
        if ($cfg_character_limit != false and trim($cfg_character_limit) != '') {
            $character_limit = intval($cfg_character_limit);
        } else {
            if (isset($params['description-length'])) {
                $character_limit = intval($params['description-length']);
            }
        }
        $title_character_limit = 200;
        $cfg_character_limit1 = get_option('data-title-limit', $params['id']);
        if ($cfg_character_limit1 != false and trim($cfg_character_limit1) != '') {
            $title_character_limit = intval($cfg_character_limit1);
        } else {
            if (isset($params['title-length'])) {
                $title_character_limit = intval($params['title-length']);
            }
        }
        if ($show_fields == false) {
            //$show_fields = array('thumbnail', 'title', 'description', 'read_more');
        }
        if (is_array($show_fields)) {
            $show_fields = array_trim($show_fields);
        }
        if (isset($current_page) and intval($current_page) > 0) {
            $post_params['current_page'] = intval($current_page);
        }
        if (!isset($post_params['global'])) {
            if (!isset($post_params['content_type'])) {
                $post_params['content_type'] = 'post';
            }
        }
        if (isset($params['is_shop'])) {
            $post_params['content_type'] = 'product';
            unset($post_params['is_shop']);
        }
        if (!isset($post_params['content_type']) and !isset($post_params['global'])) {
            $post_params['content_type'] = 'post';
        }
        if (!isset($params['order_by']) and isset($params['order-by'])) {
            $params['orderby'] = $post_params['orderby'] = $params['order-by'];
        }
        if (isset($params['subtype_value'])) {
            $post_params['subtype_value'] = $params['subtype_value'];
        }
        $schema_org_item_type = false;
        $schema_org_item_type_tag = false;
        if (isset($post_params['content_type']) and $post_params['content_type'] == 'page') {
            $schema_org_item_type = 'WebPage';
        } else {
            if (isset($post_params['content_type']) and $post_params['content_type'] == 'post') {
                if (isset($post_params['subtype']) and $post_params['subtype'] != $post_params['content_type']) {
                    $schema_org_item_type = $post_params['subtype'];
                } else {
                    $schema_org_item_type = 'Article';
                }
            }
        }
        if ($schema_org_item_type != false) {
            $schema_org_item_type = ucfirst($schema_org_item_type);
            $schema_org_item_type_tag = ' itemtype="http://schema.org/' . $schema_org_item_type . '" ';
            $schema_org_item_type_tag = 'http://schema.org/' . $schema_org_item_type;
        }
        $ord_by = get_option('data-order-by', $params['id']);
        if ($ord_by != false and trim($ord_by) != '') {
            $post_params['orderby'] = $ord_by;
        }
        $date_format = get_option('date_format', 'website');
        if ($date_format == false) {
            $date_format = "Y-m-d H:i:s";
        }
        if (isset($params['title'])) {
            unset($post_params['title']);
        }
        $post_params['is_active'] = 1;
        $post_params['is_deleted'] = 0;
        if ((!isset($post_params['parent']) and !isset($post_params['category']) or isset($post_params['category']) and empty($post_params['category'])) and $cat_from_url != false and trim($cat_from_url) != '') {
            $post_params['category'] = $cat_from_url;
        }
        if (isset($params['content_type']) and $params['content_type'] == 'all') {
            unset($post_params['content_type']);
            unset($post_params['subtype']);
        }
        if (isset($params['search-parent'])) {
            $sub_content = get_content_children($params['search-parent']);
            if (!empty($sub_content)) {
                $post_params['ids'] = $sub_content;
                unset($post_params['parent']);
            }
        }
        if (isset($params['data-id'])) {
            unset($post_params['data-id']);
        }
        if ($posts_parent_related == false) {
            if (isset($post_params['category']) and is_string($post_params['category'])) {
                $sub_categories = array();
                $sub_categories[] = $post_params['category'];
                $more = get_category_children($post_params['category']);
                if ($more != false and is_array($more)) {
                    foreach ($more as $item_more_subcat) {
                        $sub_categories[] = $item_more_subcat;
                    }
                }
                //$post_params['category']
                $post_params['category'] = $sub_categories;
                //$post_params['category'] = $post_params['category'];
            } else {
                if (isset($post_params['category']) and is_array($post_params['category']) and empty($post_params['category']) and isset($post_params['related']) and $post_params['related'] != false) {
                    if (defined('CATEGORY_ID') and CATEGORY_ID > 0) {
                        $post_params['category'] = CATEGORY_ID;
                    }
                }
            }
        }
        if (defined('POST_ID') and isset($posts_parent_category) and $posts_parent_category != false or isset($post_params['related'])) {
            $post_params['exclude_ids'] = POST_ID;
        }
        if (!isset($params['order_by'])) {
            //            if(isset($post_params['content_type']) and $post_params['content_type'] == 'page'){
            //                $post_params['order_by'] = 'position asc';
            //            } else {
            //
            //            }
            $post_params['order_by'] = 'position desc';
        }
        if (isset($params['search_in_fields']) and $params['search_in_fields'] != false) {
            $post_params['search_in_fields'] = $params['search_in_fields'];
        }
        $content = get_content($post_params);
        if ($posts_parent_related != false and empty($content) and isset($post_params['category'])) {
            unset($post_params['category']);
            $content = get_content($post_params);
        }
        $data = array();
        if (!empty($content)) {
            foreach ($content as $item) {
                $iu = get_picture($item['id'], $for = 'post', $full = false);
                if ($iu != false) {
                    $item['image'] = $iu;
                } else {
                    $item['image'] = false;
                }
                if ($item['image'] != false) {
                    $item['tn_image'] = thumbnail($item['image'], $tn[0], $tn[1]);
                } else {
                    $item['tn_image'] = false;
                }
                $item['content'] = htmlspecialchars_decode($item['content']);
                if (isset($item['created_at']) and trim($item['created_at']) != '') {
                    $item['created_at'] = date($date_format, strtotime($item['created_at']));
                }
                if (isset($item['updated_at']) and trim($item['updated_at']) != '') {
                    $item['updated_at'] = date($date_format, strtotime($item['updated_at']));
                }
                $item['link'] = content_link($item['id']);
                $item['full_description'] = '';
                if (!isset($item['description']) or $item['description'] == '') {
                    if (isset($item['content']) and $item['content'] != '') {
                        $item['description'] = character_limiter(strip_tags($item['content']), $character_limit);
                        $item['full_description'] = strip_tags($item['content']);
                    } elseif (isset($item['content_body']) and $item['content_body'] != '') {
                        $item['full_description'] = strip_tags($item['content']);
                        $item['description'] = character_limiter(strip_tags($item['content_body']), $character_limit);
                    }
                } else {
                    $item['full_description'] = trim($item['description']);
                    $item['description'] = character_limiter(strip_tags($item['description']), $character_limit);
                }
                if (isset($item['title']) and $item['title'] != '') {
                    $item['full_title'] = $item['title'];
                    $item['title'] = character_limiter($item['title'], $title_character_limit);
                }
                if (isset($post_params['content_type']) and $post_params['content_type'] == 'product') {
                    $item['prices'] = get_custom_fields("field_type=price&for=content&for_id=" . $item['id']);
                } else {
                    $item['prices'] = false;
                }
                if (isset($item['prices']) and is_array($item['prices']) and !empty($item['prices'])) {
                    $vals2 = array_values($item['prices']);
                    $val1 = array_shift($vals2);
                    $item['price'] = $val1;
                } else {
                    $item['price'] = false;
                }
                if (isset($show_fields) and is_array($show_fields) and !empty($show_fields)) {
                    if (!in_array('title', $show_fields)) {
                        $item['title'] = false;
                    }
                    if (!in_array('description', $show_fields)) {
                        $item['description'] = false;
                    }
                    if (!in_array('created_at', $show_fields)) {
                        $item['created_at'] = false;
                    }
                    if (!in_array('read_more', $show_fields)) {
                        $item['read_more'] = false;
                    }
                    if (!in_array('thumbnail', $show_fields)) {
                        $item['thumbnail'] = false;
                    }
                }
                $data[] = $item;
            }
        } else {
            if (isset($params['is_shop'])) {
                print lnotif('Your products module is empty');
            } elseif (isset($params['global'])) {
                print lnotif('Your content module is empty');
            } else {
                print lnotif('Your posts module is empty');
            }
        }
        $post_params_paging = $post_params;
        $post_params_paging['page_count'] = true;
        $cfg_data_hide_paging = get_option('data-hide-paging', $params['id']);
        if ($cfg_data_hide_paging === false) {
            if (isset($post_params['hide_paging']) and trim($post_params['hide_paging']) != 'false') {
                $post_params['hide-paging'] = $post_params['hide_paging'];
                unset($post_params['hide_paging']);
            }
            if (isset($post_params['hide-paging']) and trim($post_params['hide-paging']) != 'false') {
                $cfg_data_hide_paging = 'y';
                unset($post_params['hide-paging']);
            }
        }
        if ($cfg_data_hide_paging != 'y') {
            $pages_of_posts = get_content($post_params_paging);
            $pages_count = intval($pages_of_posts);
        } else {
            $pages_count = 0;
        }
        $paging_links = false;
        if (intval($pages_count) > 1) {
            //$paging_links = mw()->content_manager->paging_links(false, $pages_count, $paging_param, $keyword_param = 'keyword');
        }
        $read_more_text = get_option('data-read-more-text', $params['id']);
        $add_cart_text = get_option('data-add-to-cart-text', $params['id']);
        if ($add_cart_text == false or $add_cart_text == "Add to cart") {
            $add_cart_text = _e("Add to cart", true);
        }
        if (!isset($params['return'])) {
            $module_template = get_option('data-template', $params['id']);
            if ($module_template == false and isset($params['template'])) {
                $module_template = $params['template'];
            }
            if ($module_template != false) {
                if (strtolower($module_template) == 'none') {
                    if (isset($params['template'])) {
                        $module_template = $params['template'];
                    }
                }
                $template_file = module_templates($config['module'], $module_template);
            } else {
                $template_file = module_templates($config['module'], 'default');
            }
            if ($template_file == false) {
                $template_file = module_templates($config['module'], 'default');
            }
            if (isset($template_file) and is_file($template_file) != false) {
                include $template_file;
                ?>
                <?php 
                if (isset($params['ajax_paging']) or isset($params['ajax-paging'])) {
                    ?>
                    <script type="text/javascript">
                        $(document).ready(function () {
                            mw.$('#<?php 
                    print $params['id'];
                    ?>
').find('a[data-page-number]').unbind('click');
                            mw.$('#<?php 
                    print $params['id'];
                    ?>
').find('a[data-page-number]').click(function (e) {
                                var pn = $(this).attr('data-page-number');
                                mw.$('#<?php 
                    print $params['id'];
                    ?>
').attr('paging_param', 'current_page');
                                mw.$('#<?php 
                    print $params['id'];
                    ?>
').attr('current_page', pn)
                                mw.reload_module('#<?php 
                    print $params['id'];
                    ?>
');
                                return false;
                            });
                        });
                    </script>
                <?php 
                }
                ?>
                <?php 
                if (isset($params['is_shop'])) {
                    ?>
                    <script type="text/javascript">
                        mw.require("shop.js");
                    </script>
                <?php 
                }
                ?>
            <?php 
            } else {
                print lnotif('No default template for ' . $config['module'] . ' is found');
            }
        }
    }
Example #19
0
 /**
  * Invoke function and return result.
  *
  * @return mixed
  */
 public function invoke()
 {
     $result = $this->fm->invoke($this->parameters);
     // Parse result if trigger is true.
     if ($this->parse) {
         if ($this->parser instanceof Closure) {
             return $this->parser->__invoke($result);
         }
         return array_trim(array_decode_guid($result));
     }
     return $result;
 }
Example #20
0
function array_trim(&$var)
{
    if (is_array($var)) {
        foreach ($var as $k => &$v) {
            array_trim($v);
        }
    } else {
        $var = trim($var);
    }
    return $var;
}
Example #21
0
 public function make_default($rel, $rel_id, $fields_csv_str)
 {
     global $_mw_made_default_fields_register;
     if (!defined('SKIP_CF_ADMIN_CHECK')) {
         define('SKIP_CF_ADMIN_CHECK', 1);
     }
     // return false;
     $id = $this->app->user_manager->is_admin();
     if ($id == false) {
         //return false;
     }
     $function_cache_id = false;
     $args = func_get_args();
     foreach ($args as $k => $v) {
         $function_cache_id = $function_cache_id . serialize($k) . serialize($v);
     }
     $function_cache_id = 'fields_' . __FUNCTION__ . crc32($function_cache_id);
     //$is_made = $this->app->option_manager->get($function_cache_id, 'make_default_custom_fields');
     $make_field = array();
     $make_field['rel_type'] = $rel;
     $make_field['rel_id'] = $rel_id;
     $is_made = $this->get_all($make_field);
     if (isset($_mw_made_default_fields_register[$function_cache_id])) {
         return;
     }
     if (is_array($is_made) and !empty($is_made)) {
         return;
     }
     $_mw_made_default_fields_register[$function_cache_id] = true;
     $table_custom_field = $this->table;
     if (isset($rel)) {
         $rel = $this->app->database_manager->escape_string($rel);
         $rel = $this->app->database_manager->assoc_table_name($rel);
         $rel_id = $this->app->database_manager->escape_string($rel_id);
         if (strstr($fields_csv_str, ',')) {
             $fields_csv_str = explode(',', $fields_csv_str);
             $fields_csv_str = array_trim($fields_csv_str);
         } else {
             $fields_csv_str = array($fields_csv_str);
         }
         $pos = 0;
         if (is_array($fields_csv_str)) {
             foreach ($fields_csv_str as $field_type) {
                 $ex = array();
                 $ex['type'] = $field_type;
                 $ex['rel_type'] = $rel;
                 $ex['rel_id'] = $rel_id;
                 $ex = $this->get_all($ex);
                 if ($ex == false or is_array($ex) == false) {
                     $make_field = array();
                     $make_field['rel_type'] = $rel;
                     $make_field['rel_id'] = $rel_id;
                     $make_field['position'] = $pos;
                     $make_field['name'] = ucfirst($field_type);
                     $make_field['value'] = '';
                     $make_field['type'] = $field_type;
                     $this->save($make_field);
                     ++$pos;
                 }
             }
             if ($pos > 0) {
                 $this->app->cache_manager->delete('custom_fields/global');
             }
         }
     }
 }
Example #22
0
 private function getAllExtensionIds()
 {
     $result = array();
     $paths = $this->getExtensionPaths();
     $cache_status = CacheSettings::caching_enabled();
     CacheSettings::enable_caching();
     $cache = get_cache_function("extensionmaster", 3600);
     foreach ($paths as $path) {
         $result += $cache->call(array($this, "searchForExtensions"), $path);
         //$result += $this->searchForExtensions($path);
     }
     if (!$cache_status) {
         CacheSettings::disable_caching();
     }
     if (defined("EXTENSIONS_WHITELIST") && EXTENSIONS_WHITELIST != "") {
         $whitelist = explode(",", EXTENSIONS_WHITELIST);
         $whitelist = array_trim($whitelist);
         $result = array_intersect($whitelist, $result);
     }
     if (BLACKLISTED_EXTENSIONS != "") {
         $parts = explode(",", BLACKLISTED_EXTENSIONS);
         $parts = array_trim($parts);
     } else {
         $parts = array();
     }
     $result = array_diff($result, array_intersect($parts, $result));
     return $result;
 }
Example #23
0
    public function Search($keywords, $url_query, $start_page = 1)
    {
        global $db;
        $jobs = array();
        $conditions = '';
        $_SESSION['keywords_array'] = array();
        if (SEARCH_METHOD == 'classic') {
            $kw1 = $kw2 = $extra_conditions = '';
            $found_city = false;
            if (strstr($keywords, ',') || strstr($keywords, ', ')) {
                $tmp = explode(',', $keywords);
                $kw1 = trim($tmp[0]);
                $kw2 = trim($tmp[1]);
                if ($kw1 == '') {
                    $kw1 = $kw2;
                    $kw2 = '';
                }
            } else {
                if (strstr($keywords, ' ') || strstr($keywords, '  ')) {
                    // filter out empty strings (can happen if there are many whitespaces between two words in the search string)
                    $tmp = array_filter(explode(' ', $keywords));
                    foreach ($tmp as $word) {
                        // try to find city based on city_id
                        $sql = 'SELECT id FROM ' . DB_PREFIX . 'cities WHERE name LIKE "%' . $word . '%"';
                        $result = $db->query($sql);
                        $row = $result->fetch_assoc();
                        if ($row['id'] != '') {
                            if ($found_city) {
                                $conditions .= ' OR';
                            }
                            $conditions .= ' city_id = ' . $row['id'];
                            $found_city = true;
                            $keywords = trim(str_replace($word, '', $keywords));
                        }
                        // try to find city based on postcode or location_details
                        $sql = 'SELECT id FROM ' . DB_PREFIX . 'jobs WHERE outside_location LIKE "%' . $word . '%"';
                        $results = $db->QueryArray($sql);
                        if ($db->affected_rows > 0) {
                            if ($found_city) {
                                $conditions .= ' OR ';
                            }
                            $conditions .= ' id IN (';
                            foreach ($results as $j) {
                                $conditions .= $j['id'] . ',';
                                $found_city = true;
                            }
                            $conditions = rtrim($conditions, ',');
                            $conditions .= ') ';
                            $keywords = trim(str_replace($word, '', $keywords));
                        }
                    }
                    if ($found_city) {
                        $conditions .= ' AND (title LIKE "%' . $keywords . '%" OR summary LIKE "%' . $keywords . '%" OR company LIKE "%' . $keywords . '%"' . ' OR description LIKE "%' . $keywords . '%")';
                    }
                }
            }
            if (!$found_city) {
                if ($kw1 != '') {
                    $conditions .= ' (title LIKE "%' . $kw1 . '%" OR summary LIKE "%' . $kw1 . '" OR company LIKE "%' . $kw1 . '%" OR description LIKE "%' . $kw1 . '%")';
                    $_SESSION['keywords_array'][] = $kw1;
                }
                if ($kw2 != '') {
                    $sql = 'SELECT id FROM ' . DB_PREFIX . 'cities WHERE name LIKE "%' . $kw2 . '%"';
                    $result = $db->query($sql);
                    $row = $result->fetch_assoc();
                    if ($row['id'] != '') {
                        $extra_conditions .= ' OR city_id = ' . $row['id'];
                    }
                    $conditions .= ' AND (outside_location LIKE "%' . $kw2 . '%" ' . $extra_conditions . ')';
                    $_SESSION['keywords_array'][] = $kw2;
                }
                if ($kw1 == '' && $kw2 == '') {
                    $sql = 'SELECT id FROM ' . DB_PREFIX . 'cities WHERE name LIKE "%' . $keywords . '%"';
                    $result = $db->query($sql);
                    $row = $result->fetch_assoc();
                    if ($row['id'] != '') {
                        $extra_conditions .= ' OR city_id = ' . $row['id'];
                    }
                    $conditions = 'title LIKE "%' . $keywords . '%" OR summary LIKE "%' . $keywords . '%" OR company LIKE "%' . $keywords . '%"' . ' OR description LIKE "%' . $keywords . '%" OR outside_location LIKE "%' . $keywords . '%"' . $extra_conditions;
                    $_SESSION['keywords_array'][] = $keywords;
                }
            }
            $sql = 'SELECT id
		               FROM ' . DB_PREFIX . 'jobs
		               WHERE is_temp = 0 AND is_active = 1 AND (' . $conditions . ')
		               ORDER BY created_on DESC';
            $result = $db->query($sql);
        } else {
            $cities = array();
            $check_cities = '';
            $keywords = str_replace(",", " ", $keywords);
            $keywords = str_replace("  ", " ", $keywords);
            $keywords = rtrim($keywords);
            $keywords_a = preg_split("/[\\s,]*\\'([^\\\"]+)\\'[\\s,]*|[\\s,]+/", $keywords, 0, PREG_SPLIT_DELIM_CAPTURE);
            function array_trim($a)
            {
                $j = 0;
                for ($i = 0; $i < count($a); $i++) {
                    if ($a[$i] != "") {
                        $b[$j++] = $a[$i];
                    }
                }
                return $b;
            }
            $keywords_r = array_trim($keywords_a);
            //Search in Cities
            for ($i = 0; $i < count($keywords_r); $i++) {
                $sql = 'SELECT id
		                     FROM ' . DB_PREFIX . 'cities
		                     WHERE name LIKE "%' . $keywords_r[$i] . '%"
		                     ORDER BY ID ASC';
                $result = $db->query($sql);
                $cities_line = '';
                while ($row = $result->fetch_assoc()) {
                    $cities_line .= $row['id'] . ' ';
                }
                $cities[$i] = $cities_line;
            }
            //Search in Jobs
            for ($i = 0; $i < count($keywords_r); $i++) {
                if ($cities[$i] != "") {
                    $cities[$i] = rtrim($cities[$i]);
                    $cities_r = explode(' ', $cities[$i]);
                    for ($a = 0; $a < count($cities_r); $a++) {
                        $check_cities .= 'OR city_id = "' . $cities_r[$a] . '" ';
                    }
                }
                $conditions .= 'AND (title LIKE "%' . $keywords_r[$i] . '%" OR summary LIKE "%' . $keywords_r[$i] . '%" OR company LIKE "%' . $keywords_r[$i] . '%" OR description LIKE "%' . $keywords_r[$i] . '%" OR outside_location LIKE "%' . $keywords_r[$i] . '%" ' . $check_cities . ' ) ';
            }
            $sql = 'SELECT id
					FROM ' . DB_PREFIX . 'jobs
					WHERE is_temp = 0 AND is_active = 1 ' . $conditions . '
					ORDER BY created_on DESC';
            $result = $db->query($sql);
        }
        $pages = '';
        $id_array = '';
        //$max_loop = SEARCH_RESULTS_PER_PAGE;
        //$max_visible_pages = SEARCH_AMOUNT_PAGES;
        $max_loop = JOBS_PER_PAGE;
        $max_visible_pages = 10;
        while ($row = $result->fetch_assoc()) {
            $id_array[] = $row['id'];
        }
        $start_count = ($start_page - 1) * $max_loop;
        $current_loop = 0;
        $total_results = count($id_array);
        $total_loop = $total_results - $start_count;
        $total_pages = ceil($total_results / $max_loop);
        if ($total_pages > 1) {
            $pagination_loop = $start_page - $max_visible_pages / 2;
            if ($pagination_loop < 1) {
                $pagination_loop = 1;
            } elseif ($pagination_loop - 1 > 0) {
                $pages .= "&nbsp;<a href='" . BASE_URL . "search/" . $url_query . "/?p=" . ($pagination_loop - 1) . "'>&laquo;</a>&nbsp;";
            }
            $pagination_top = $pagination_loop + $max_visible_pages + 1;
            while ($pagination_loop < $total_pages + 1 && $pagination_loop < $pagination_top) {
                if ($pagination_loop == $start_page) {
                    $pages .= "&nbsp;<a class='current_page' href='" . BASE_URL . "search/" . $url_query . "/?p={$pagination_loop}'>{$pagination_loop}</a>&nbsp;";
                } else {
                    $pages .= "&nbsp;<a href='" . BASE_URL . "search/" . $url_query . "/?p={$pagination_loop}'>{$pagination_loop}</a>&nbsp;";
                }
                $pagination_loop++;
            }
            if ($pagination_loop == $pagination_top) {
                $pages .= "&nbsp;<a href='" . BASE_URL . "search/" . $url_query . "/?p=" . $pagination_loop . "'>&raquo;</a>&nbsp;";
            }
        }
        if ($id_array != '') {
            while ($current_loop < $total_loop && $current_loop < $max_loop) {
                $current_job = new Job($id_array[$start_count]);
                $jobs[] = $current_job->GetInfo();
                $current_loop++;
                $start_count++;
            }
        }
        $_SESSION['search_results'] = $jobs;
        $_SESSION['search_pagination'] = $pages;
        return $jobs;
    }
Example #24
0
 /** public function admin_remove_admin
  *		Removes admin status from the given players
  *
  * @param mixed csv or array of player IDs
  * @action removes the given players admin status
  * @return void
  */
 public function admin_remove_admin($player_ids)
 {
     // make sure the user doing this is an admin
     if (!$this->is_admin) {
         throw new MyException(__METHOD__ . ': Player is not an admin');
     }
     array_trim($player_ids, 'int');
     $player_ids[] = 0;
     // make sure we have at least one entry
     if (isset($GLOBALS['_ROOT_ADMIN'])) {
         $query = "\n\t\t\t\tSELECT player_id\n\t\t\t\tFROM " . Player::PLAYER_TABLE . "\n\t\t\t\tWHERE username = '******'_ROOT_ADMIN']}'\n\t\t\t";
         $root_admin = (int) $this->_mysql->fetch_value($query);
         if (in_array($root_admin, $player_ids)) {
             unset($player_ids[array_search($root_admin, $player_ids)]);
         }
     }
     // remove the player doing the removing
     unset($player_ids[array_search($_SESSION['player_id'], $player_ids)]);
     // remove the admin doing the removing
     unset($player_ids[array_search($_SESSION['admin_id'], $player_ids)]);
     $this->_mysql->insert(self::EXTEND_TABLE, array('is_admin' => 0), " WHERE player_id IN (" . implode(',', $player_ids) . ") ");
 }
Example #25
0
<?php

$skip_types = array();
$for = 'module';
if (isset($params['for'])) {
    $for = $params['for'];
}
if (isset($params['data-skip-type'])) {
    $skip_types = explode(',', $params['data-skip-type']);
    $skip_types = array_trim($skip_types);
}
if (isset($params['content-id'])) {
    $for_id = $params['content-id'];
    $for = 'content';
} elseif (isset($params['content_id'])) {
    $for_id = $params['content_id'];
    $for = 'content';
} else {
    if (isset($params['for_id'])) {
        $for_id = $params['for_id'];
    } else {
        if (isset($params['data-id'])) {
            $for_id = $params['data-id'];
        } else {
            if (isset($params['id'])) {
                $for_id = $params['id'];
            }
        }
    }
    //$for_id =$params['id'];
    if (isset($params['rel_id'])) {
Example #26
0


            <span class="mw_editor_btn mw_editor_link" data-command="custom-link" title="<?php 
_e("Add/Edit Link");
?>
"><span class="ed-ico"></span></span>
            <span class="mw_editor_btn mw_editor_unlink" data-command="custom-unlink" title="<?php 
_e("Remove Link");
?>
"><span class="ed-ico"></span></span>


            <span class="mw_editor_btn mw_editor_remove_formatting" data-command="removeformat" title="<?php 
_e("Remove Formatting");
?>
"><span class="ed-ico"></span></span>

            <?php 
if (is_admin() and isset($_REQUEST['modules'])) {
    $mods = explode(',', $_REQUEST['modules']);
    $mods = array_trim($mods);
    if (is_array($mods)) {
        foreach ($mods as $mod) {
            print load_module($mod);
        }
    }
}
?>
        </div>
    </div>
 public function api($api_function = false, $params = false)
 {
     if (isset($_REQUEST['api_key']) and user_id() == 0) {
         api_login($_REQUEST['api_key']);
     }
     if (!defined('MW_API_CALL')) {
         define('MW_API_CALL', true);
     }
     $set_constants = true;
     $mod_class_api = false;
     $mod_class_api_called = false;
     $mod_class_api_class_exist = false;
     $caller_commander = false;
     if ($api_function == false) {
         $api_function_full = $this->app->url_manager->string();
         $api_function_full = $this->app->format->replace_once('api_html', '', $api_function_full);
         $api_function_full = $this->app->format->replace_once('api/api', 'api', $api_function_full);
         $api_function_full = $this->app->format->replace_once('api', '', $api_function_full);
         $api_function_full = trim($api_function_full, '/');
         //$api_function_full = substr($api_function_full, 4);
     } else {
         $api_function_full = $api_function;
     }
     if (isset($api_function_full) and $api_function_full != '') {
         if (ltrim($api_function_full, '/') == 'module') {
             $set_constants = false;
         }
     }
     if ($set_constants == true) {
         $this->app->content_manager->define_constants();
     }
     if (defined('TEMPLATE_DIR')) {
         $load_template_functions = TEMPLATE_DIR . 'functions.php';
         if (is_file($load_template_functions)) {
             include_once $load_template_functions;
         }
     }
     //$api_function_full = str_ireplace('api/', '', $api_function_full);
     $api_function_full = str_replace('..', '', $api_function_full);
     $api_function_full = str_replace('\\', '/', $api_function_full);
     $api_function_full = str_replace('//', '/', $api_function_full);
     $api_function_full = $this->app->database_manager->escape_string($api_function_full);
     if (is_string($api_function_full)) {
         $mod_api_class = explode('/', $api_function_full);
     } else {
         $mod_api_class = $api_function_full;
     }
     $try_class_func = array_pop($mod_api_class);
     // $try_class_func2 = array_pop($mod_api_class);
     $mod_api_class_copy = $mod_api_class;
     $try_class_func2 = array_pop($mod_api_class_copy);
     $mod_api_class2 = implode(DS, $mod_api_class_copy);
     $mod_api_class = implode(DS, $mod_api_class);
     $mod_api_class_clean = ltrim($mod_api_class, '/');
     $mod_api_class_clean = ltrim($mod_api_class_clean, '\\');
     $mod_api_class_clean_uc1 = ucfirst($mod_api_class_clean);
     $mod_api_class1 = normalize_path(modules_path() . $mod_api_class, false) . '.php';
     $mod_api_class_native = normalize_path(mw_includes_path() . $mod_api_class, false) . '.php';
     $mod_api_class_native_system = normalize_path(dirname(MW_PATH) . DS . $mod_api_class, false) . '.php';
     $mod_api_class_native_global_ns = normalize_path(mw_includes_path() . 'classes' . DS . $mod_api_class2, false) . '.php';
     $mod_api_class1_uc1 = normalize_path(modules_path() . $mod_api_class_clean_uc1, false) . '.php';
     $mod_api_class_native_uc1 = normalize_path(mw_includes_path() . $mod_api_class_clean_uc1, false) . '.php';
     $mod_api_class_native_global_ns_uc1 = normalize_path(mw_includes_path() . 'classes' . DS . $mod_api_class_clean_uc1, false) . '.php';
     $mod_api_class2 = normalize_path(modules_path() . DS . $mod_api_class_clean . DS . $mod_api_class_clean, false) . '.php';
     $mod_api_class2_uc1 = normalize_path(modules_path() . DS . $mod_api_class_clean . DS . $mod_api_class_clean, false) . '.php';
     $try_class = '\\' . str_replace('/', '\\', $mod_api_class);
     if (class_exists($try_class, false)) {
         $caller_commander = 'class_is_already_here';
         $mod_class_api_class_exist = true;
     } else {
         if (is_file($mod_api_class1)) {
             $mod_class_api = true;
             include_once $mod_api_class1;
         } elseif (is_file($mod_api_class_native_system)) {
             $mod_class_api = true;
             include_once $mod_api_class_native_system;
         } elseif (is_file($mod_api_class1_uc1)) {
             $mod_class_api = true;
             include_once $mod_api_class1_uc1;
         } elseif (is_file($mod_api_class_native_global_ns_uc1)) {
             $try_class = str_replace('/', '\\', $mod_api_class2);
             $mod_class_api = true;
             include_once $mod_api_class_native_global_ns_uc1;
         } elseif (is_file($mod_api_class_native_global_ns)) {
             $try_class = str_replace('/', '\\', $mod_api_class2);
             $mod_class_api = true;
             include_once $mod_api_class_native_global_ns;
         } elseif (is_file($mod_api_class_native_uc1)) {
             $mod_class_api = true;
             include_once $mod_api_class_native_uc1;
         } elseif (is_file($mod_api_class_native)) {
             $mod_class_api = true;
             include_once $mod_api_class_native;
         } elseif (is_file($mod_api_class2)) {
             $mod_class_api = true;
             include_once $mod_api_class2;
         } elseif (is_file($mod_api_class2_uc1)) {
             $mod_class_api = true;
             include_once $mod_api_class2_uc1;
         }
     }
     $api_exposed = '';
     // user functions
     $api_exposed .= 'user_login user_logout social_login_process';
     // content functions
     $api_exposed .= 'set_language ';
     $api_exposed .= api_expose(true);
     if (is_logged()) {
         $api_exposed .= api_expose_user(true);
     }
     if (is_admin()) {
         $api_exposed .= api_expose_admin(true);
     }
     $api_exposed = explode(' ', $api_exposed);
     $api_exposed = array_unique($api_exposed);
     $api_exposed = array_trim($api_exposed);
     $hooks = api_bind(true);
     if (is_logged()) {
         $hooks_admin = api_bind_user(true);
         if (is_array($hooks_admin)) {
             $hooks = array_merge($hooks, $hooks_admin);
         }
     }
     if (is_admin()) {
         $hooks_admin = api_bind_admin(true);
         if (is_array($hooks_admin)) {
             $hooks = array_merge($hooks, $hooks_admin);
         }
     }
     if ($api_function == false) {
         $api_function = $this->app->url_manager->segment(1);
     }
     if (!defined('MW_API_RAW')) {
         if ($mod_class_api != false) {
             $url_segs = $this->app->url_manager->segment(-1);
         }
     } else {
         if (is_array($api_function)) {
             $url_segs = $api_function;
         } else {
             $url_segs = explode('/', $api_function);
         }
     }
     if (!defined('MW_API_FUNCTION_CALL')) {
         define('MW_API_FUNCTION_CALL', $api_function);
     }
     switch ($caller_commander) {
         case 'class_is_already_here':
             if ($params != false) {
                 $data = $params;
             } elseif (!$_POST and !$_REQUEST) {
                 $data = $this->app->url_manager->params(true);
                 if (empty($data)) {
                     $data = $this->app->url_manager->segment(2);
                 }
             } else {
                 //$data = $_REQUEST;
                 $data = array_merge($_GET, $_POST);
             }
             static $loaded_classes = array();
             //$try_class_n = src_
             if (isset($loaded_classes[$try_class]) == false) {
                 $res = new $try_class($data);
                 $loaded_classes[$try_class] = $res;
             } else {
                 $res = $loaded_classes[$try_class];
                 //
             }
             if (method_exists($res, $try_class_func) or method_exists($res, $try_class_func2)) {
                 if (method_exists($res, $try_class_func2)) {
                     $try_class_func = $try_class_func2;
                 }
                 $res = $res->{$try_class_func}($data);
                 if (defined('MW_API_RAW')) {
                     $mod_class_api_called = true;
                 }
                 return $this->_api_responce($res);
             }
             break;
         default:
             $res = false;
             if (isset($hooks[$api_function_full])) {
                 $data = array_merge($_GET, $_POST);
                 $call = $hooks[$api_function_full];
                 if (!empty($call)) {
                     foreach ($call as $call_item) {
                         $res = call_user_func($call_item, $data);
                     }
                 }
                 if ($res != false) {
                     return $this->_api_responce($res);
                 }
             }
             if ($mod_class_api == true and $mod_api_class != false) {
                 $mod_api_class = str_replace('..', '', $mod_api_class);
                 $try_class = str_replace('/', '\\', $mod_api_class);
                 $try_class_full = str_replace('/', '\\', $api_function_full);
                 $try_class_full2 = str_replace('\\', '/', $api_function_full);
                 $mod_api_class_test = explode('/', $try_class_full2);
                 $try_class_func_test = array_pop($mod_api_class_test);
                 $mod_api_class_test_full = implode('/', $mod_api_class_test);
                 $mod_api_err = false;
                 if (!defined('MW_API_RAW')) {
                     if (!in_array($try_class_full, $api_exposed) and !in_array($try_class_full2, $api_exposed) and !in_array($mod_api_class_test_full, $api_exposed)) {
                         $mod_api_err = true;
                         foreach ($api_exposed as $api_exposed_value) {
                             if ($mod_api_err == true) {
                                 if ($api_exposed_value == $try_class_full) {
                                     $mod_api_err = false;
                                 } elseif (strtolower('\\' . $api_exposed_value) == strtolower($try_class_full)) {
                                     $mod_api_err = false;
                                 } elseif ($api_exposed_value == $try_class_full2) {
                                     $mod_api_err = false;
                                 } else {
                                     $convert_slashes = str_replace('\\', '/', $try_class_full);
                                     if ($convert_slashes == $api_exposed_value) {
                                         $mod_api_err = false;
                                     }
                                 }
                             }
                         }
                     } else {
                         $mod_api_err = false;
                     }
                 }
                 if ($mod_class_api and $mod_api_err == false) {
                     if (!class_exists($try_class, false)) {
                         $remove = $url_segs;
                         $last_seg = array_pop($remove);
                         $last_prev_seg = array_pop($remove);
                         $last_prev_seg2 = array_pop($remove);
                         if (class_exists($last_prev_seg, false)) {
                             $try_class = $last_prev_seg;
                         } elseif (class_exists($last_prev_seg2, false)) {
                             $try_class = $last_prev_seg2;
                         }
                     }
                     if (!class_exists($try_class, false)) {
                         $try_class_mw = ltrim($try_class, '/');
                         $try_class_mw = ltrim($try_class_mw, '\\');
                         $try_class = $try_class_mw;
                     }
                     if (class_exists($try_class, false)) {
                         if ($params != false) {
                             $data = $params;
                         } elseif (!$_POST and !$_REQUEST) {
                             $data = $this->app->url_manager->params(true);
                             if (empty($data)) {
                                 $data = $this->app->url_manager->segment(2);
                             }
                         } else {
                             $data = array_merge($_GET, $_POST);
                         }
                         $res = new $try_class($data);
                         if (method_exists($res, $try_class_func) or method_exists($res, $try_class_func2)) {
                             if (method_exists($res, $try_class_func2)) {
                                 $try_class_func = $try_class_func2;
                             }
                             $res = $res->{$try_class_func}($data);
                             $mod_class_api_called = true;
                             return $this->_api_responce($res);
                         }
                     } else {
                         mw_error('The api class ' . $try_class . '  does not exist');
                     }
                 }
             }
             break;
     }
     if ($api_function) {
     } else {
         $api_function = 'index';
     }
     if ($api_function == 'module' and $mod_class_api_called == false) {
         $this->module();
     } else {
         $err = false;
         if (!in_array($api_function, $api_exposed)) {
             $err = true;
         }
         if ($err == true) {
             foreach ($api_exposed as $api_exposed_item) {
                 if ($api_exposed_item == $api_function) {
                     $err = false;
                 }
             }
         }
         if (isset($api_function_full)) {
             foreach ($api_exposed as $api_exposed_item) {
                 if (is_string($api_exposed_item) and is_string($api_function_full)) {
                     $api_function_full = str_replace('\\', '/', $api_function_full);
                     $api_function_full = ltrim($api_function_full, '/');
                     if (strtolower($api_exposed_item) == strtolower($api_function_full)) {
                         $err = false;
                     }
                 }
             }
         }
         if ($err == false) {
             if ($mod_class_api_called == false) {
                 if (!$_POST and !$_REQUEST) {
                     //  $data = $this->app->url_manager->segment(2);
                     $data = $this->app->url_manager->params(true);
                     if (empty($data)) {
                         $data = $this->app->url_manager->segment(2);
                     }
                 } else {
                     //$data = $_REQUEST;
                     $data = array_merge($_GET, $_POST);
                 }
                 $api_function_full_2 = explode('/', $api_function_full);
                 unset($api_function_full_2[count($api_function_full_2) - 1]);
                 $api_function_full_2 = implode('/', $api_function_full_2);
                 if (function_exists($api_function)) {
                     $res = $api_function($data);
                 } elseif (class_exists($api_function, false)) {
                     //
                     $segs = $this->app->url_manager->segment();
                     $mmethod = array_pop($segs);
                     $class = new $api_function($this->app);
                     if (method_exists($class, $mmethod)) {
                         $res = $class->{$mmethod}($data);
                     }
                 } else {
                     $api_function_full_2 = str_replace(array('..', '/'), array('', '\\'), $api_function_full_2);
                     $api_function_full_2 = __NAMESPACE__ . '\\' . $api_function_full_2;
                     if (class_exists($api_function_full_2, false)) {
                         //
                         $segs = $this->app->url_manager->segment();
                         $mmethod = array_pop($segs);
                         $class = new $api_function_full_2($this->app);
                         if (method_exists($class, $mmethod)) {
                             $res = $class->{$mmethod}($data);
                         }
                     } elseif (isset($api_function_full)) {
                         $api_function_full = str_replace('\\', '/', $api_function_full);
                         $api_function_full1 = explode('/', $api_function_full);
                         $mmethod = array_pop($api_function_full1);
                         $mclass = array_pop($api_function_full1);
                         if (class_exists($mclass, false)) {
                             $class = new $mclass($this->app);
                             if (method_exists($class, $mmethod)) {
                                 $res = $class->{$mmethod}($data);
                             }
                         }
                     }
                 }
             }
             if (isset($res) and isset($hooks[$api_function]) and is_array($hooks[$api_function]) and !empty($hooks[$api_function])) {
                 foreach ($hooks[$api_function] as $hook_key => $hook_value) {
                     if ($hook_value != false and $hook_value != null) {
                         $hook_value($res);
                     }
                 }
             } else {
                 //error('The api function ' . $api_function . ' does not exist', __FILE__, __LINE__);
             }
             // print $api_function;
         } else {
             $api_function = mw()->format->clean_html($api_function);
             $api_function = mw()->format->clean_xss($api_function);
             mw_error('The api function ' . $api_function . ' is not defined in the allowed functions list');
         }
         if (isset($res)) {
             return $this->_api_responce($res);
         }
         return;
     }
 }
Example #28
0
 /**
  * HTTP Content Negotiation
  * 
  * Using the content negotiation algorithm specified in 
  * {@link http://cidr-report.org/ietf/all-ids/draft-ietf-http-v11-spec-00.txt draft-ietf-http-v11-spec-00}, 
  * will return the most appropriate variants (may be more then one that
  * works) based on the provided request headers. This function is based
  * off of {@link http://search.cpan.org/dist/libwww-perl/lib/HTTP/Negotiate.pm libwww-perl, HTTP::Negotiate, choose()}.
  *
  * Usage:
  * <code>
  *  $variants = array(
  *    array(
  *      id => 'var1',
  *      qs => 1.000,
  *      type => 'text/html',
  *      encoding => null,
  *      charset => 'iso-8859-1',
  *      language => 'en',
  *      size => 3000
  *    ),
  *    array(
  *      id => 'var2',
  *      qs => 1.000,
  *      type => 'application/xhtml+xml',
  *      encoding => null,
  *      charset => 'iso-8859-1',
  *      language => 'en',
  *      size => 3000
  *    ),
  *  );
  *  
  *  $request_headers = array(
  *    HTTP_ACCEPT => 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,{@*}*;q=0.5',
  *    HTTP_ACCEPT_LANGUAGE => 'en-us,en;q=0.5',
  *    HTTP_ACCEPT_CHARSET => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 
  *    HTTP_ACCEPT_ENCODING => 'gzip,deflate'
  *  );
  *  
  *  $results = HTTP_Negotiate::choose($variants, $request_headers);
  *  assertTrue(count($results) == 1 && $results[0]['id'] == 'var2');
  * </code>
  *
  * More information on accept headers can be found at 
  * {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html}
  *
  * @access public
  * @author Gary Court <*****@*****.**>
  * @param array $variants Array of array of strings which contain the supported parameters of each variant (supported keys: id, qs, type, encoding, charset, language, size)
  * @param array $request_headers Array of strings which contain the request header (supported keys: HTTP_ACCEPT, HTTP_ACCEPT_LANGUAGE, HTTP_ACCEPT_CHARSET, HTTP_ACCEPT_ENCODING). If null, $_SERVER is used.
  * @return array The acceptable variants (from $variants) based on the request headers. May return more then one acceptable variant (in original order) or may return null (if no acceptable variant was found). 
  * @static
  * @version 1.0
  * @todo Support for parameters in variant->type.
  */
 function choose($variants, $request_headers = null)
 {
     //check arguments
     if (!is_array($variants)) {
         return false;
     }
     if ($request_headers === null) {
         $request_headers = $_SERVER;
     } elseif (!is_array($request_headers)) {
         return false;
     }
     //parse all accept values
     $request = array();
     $request_header_keys = array_keys($request_headers);
     foreach ($request_header_keys as $request_header_key) {
         $accept_type = null;
         if (strpos($request_header_key, 'HTTP_ACCEPT_') !== false) {
             $accept_type = strtolower(substr($request_header_key, strlen('HTTP_ACCEPT_')));
         } elseif ($request_header_key == 'HTTP_ACCEPT') {
             $accept_type = 'type';
         }
         if ($accept_type) {
             $request[$accept_type] = array();
             $accept_variants = array_trim(explode(',', $request_headers[$request_header_key]));
             foreach ($accept_variants as $accept_variant) {
                 if ($accept_variant) {
                     $accept_variant_parameters = array_trim(explode(';', $accept_variant));
                     $request[$accept_type][$accept_variant_parameters[0]] = array();
                     for ($i = 1; $i < count($accept_variant_parameters); $i++) {
                         if (strpos($accept_variant_parameters[$i], '=') !== false) {
                             $accept_variant_parameter_values = array_trim(explode('=', $accept_variant_parameters[$i]));
                             $accept_variant_parameter_values[1] = convert_type($accept_variant_parameter_values[1]);
                             if ($accept_variant_parameter_values[0] == 'q') {
                                 if ($accept_variant_parameter_values[1] > 1.0) {
                                     $accept_variant_parameter_values[1] = 1.0;
                                 } elseif ($accept_variant_parameter_values[1] < 0.0) {
                                     $accept_variant_parameter_values[1] = 0.0;
                                 }
                             }
                             if ($accept_variant_parameter_values[0] == 'mxb' && $accept_variant_parameter_values[1] < 0) {
                                 $accept_variant_parameter_values[1] = 0;
                             }
                             $request[$accept_type][$accept_variant_parameters[0]][$accept_variant_parameter_values[0]] = $accept_variant_parameter_values[1];
                         }
                     }
                     if (!isset($request[$accept_type][$accept_variant_parameters[0]]['q'])) {
                         $request[$accept_type][$accept_variant_parameters[0]]['q'] = 1.0;
                     }
                 }
             }
         }
     }
     //determine if at least one variant specifies a language
     $language_variant_specified = false;
     foreach ($variants as $variant) {
         if (isset($variant['language'])) {
             $language_variant_specified = true;
             break;
         }
     }
     //determine the best variant for the request
     $results = array();
     foreach ($variants as $variant) {
         //calculate qs
         if (!isset($variant['qs']) || !is_numeric($variant['qs'])) {
             $qs = 1.0;
         } else {
             $qs = (double) convert_type($variant['qs']);
         }
         //calculate qe
         if (!isset($request['encoding'])) {
             $qe = 1.0;
         } elseif (!isset($variant['encoding']) || !count($request['encoding'])) {
             $qe = 1.0;
         } elseif (array_key_exists($variant['encoding'], $request['encoding'])) {
             $qe = (double) $request['encoding'][$variant['encoding']]['q'];
         } elseif ($variant['encoding'] == 'identity') {
             $qe = 1.0;
         } elseif (isset($request['encoding']['*'])) {
             $qe = (double) $request['encoding']['*']['q'];
         } else {
             $qe = 0.0;
         }
         // ---------
         // hack by Brian
         // changed !count(... to !isset($request['charset'])
         // ---------
         //calculate qc
         if (!isset($request['charset'])) {
             $qc = 1.0;
         } elseif (!isset($variant['charset']) || $variant['charset'] == 'US-ASCII' || !isset($request['charset'])) {
             $qc = 1.0;
         } elseif (array_key_exists($variant['charset'], $request['charset'])) {
             $qc = (double) $request['charset'][$variant['charset']]['q'];
         } elseif (isset($request['charset']['*'])) {
             $qc = (double) $request['charset']['*']['q'];
         } else {
             $qc = 0.0;
         }
         //calculate ql
         if (!isset($request['language'])) {
             $ql = 1.0;
         } elseif (!$language_variant_specified || !count($request['language'])) {
             $ql = 1.0;
         } elseif (!isset($variant['language'])) {
             $ql = 0.5;
         } elseif (array_key_exists($variant['language'], $request['language'])) {
             $ql = (double) $request['language'][$variant['language']]['q'];
         } elseif (array_key_exists(substr($variant['language'], 0, 2), $request['language'])) {
             $ql = (double) $request['language'][substr($variant['language'], 0, 2)]['q'];
         } elseif (isset($request['language']['*'])) {
             $ql = (double) $request['language']['*']['q'];
         } else {
             $ql = 0.001;
         }
         //calculate q & mxb
         $mxb = null;
         // ---------
         // hack by Brian below added (6) !(isset...
         // to prevent warnings on strict php setups
         // ---------
         if (!isset($request['type'])) {
             $q = 0.0;
         } elseif (!isset($variant['type'])) {
             $q = 0.0;
         } elseif (!count($request['type'])) {
             $q = 1.0;
         } elseif (array_key_exists($variant['type'], $request['type'])) {
             if (!isset($request['type'][$variant['type']]['q'])) {
                 $request['type'][$variant['type']]['q'] = $q;
             }
             $q = (double) $request['type'][$variant['type']]['q'];
             if (!isset($request['type'][$variant['type']]['mxb'])) {
                 $request['type'][$variant['type']]['mxb'] = $mxb;
             }
             $mxb = $request['type'][$variant['type']]['mxb'];
         } elseif (array_key_exists(strtok($variant['type'], '/') . '/*', $request['type'])) {
             if (!isset($request['type'][strtok($variant['type'], '/') . '/*']['q'])) {
                 $request['type'][strtok($variant['type'], '/') . '/*']['q'] = $q;
             }
             $q = (double) $request['type'][strtok($variant['type'], '/') . '/*']['q'];
             if (!isset($request['type'][strtok($variant['type'], '/') . '/*']['mxb'])) {
                 $request['type'][strtok($variant['type'], '/') . '/*']['mxb'] = $mxb;
             }
             $mxb = $request['type'][strtok($variant['type'], '/') . '/*']['mxb'];
         } elseif (array_key_exists('*/*', $request['type'])) {
             if (!isset($request['type']['*/*']['q'])) {
                 $request['type']['*/*']['q'] = $q;
             }
             $q = (double) $request['type']['*/*']['q'];
             if (!isset($request['type']['*/*']['mxb'])) {
                 $request['type']['*/*']['mxb'] = $mxb;
             }
             $mxb = $request['type']['*/*']['mxb'];
         } else {
             $q = 0.0;
         }
         //calculate bs
         $bs = $variant['size'];
         //calculate Q
         if ($mxb === null || $bs === null || $mxb >= $bs) {
             $Q = $qs * $qe * $qc * $ql * $q;
         } else {
             $Q = 0.0;
         }
         //keep track of the highest Q values
         $variant['Q'] = $Q;
         if (!count($results) || $variant['Q'] > $results[0]['Q']) {
             $results = array($variant);
         } elseif ($variant['Q'] == $results[0]['Q']) {
             array_push($results, $variant);
         }
     }
     //sort results (which all have same Q) by smallest filesize, ascending
     if (!function_exists('compareVariants')) {
         function compareVariants($a, $b)
         {
             if ($a['Q'] == $b['Q']) {
                 if (isset($a['size'])) {
                     if (isset($b['size'])) {
                         if ($a['size'] == $b['size']) {
                             return 0;
                         }
                         return $a['size'] < $b['size'] ? -1 : 1;
                     }
                     return -1;
                 }
                 if (isset($b['size'])) {
                     return 1;
                 }
                 return 0;
             }
             return $a['Q'] < $b['Q'] ? 1 : -1;
         }
     }
     mergesort($results, 'compareVariants');
     //return variants ordered by best choice
     return $results;
 }
Example #29
0
include "{$currDir}/config.php";
include "{$currDir}/db.php";
include "{$currDir}/ci_input.php";
include "{$currDir}/datalist.php";
include "{$currDir}/incCommon.php";
include "{$currDir}/admin/incFunctions.php";
ob_start();
/* trim $_POST, $_GET, $_REQUEST */
if (count($_POST)) {
    $_POST = array_trim($_POST);
}
if (count($_GET)) {
    $_GET = array_trim($_GET);
}
if (count($_REQUEST)) {
    $_REQUEST = array_trim($_REQUEST);
}
// include nav menu links and hook functions
@(include "{$currDir}/hooks/links-navmenu.php");
@(include "{$currDir}/hooks/__global.php");
// check sessions config
$noPathCheck = true;
$arrPath = explode(';', ini_get('session.save_path'));
$save_path = $arrPath[count($arrPath) - 1];
if (!$noPathCheck && !is_dir($save_path)) {
    ?>
		<center>
			<div class="alert alert-danger">
				Your site is not configured to support sessions correctly. Please edit your php.ini file and change the value of <i>session.save_path</i> to a valid path.
			</div>
		</center>
Example #30
0
function get_sort_script($table_id, $sort_types = '', $alt_class = 'alt', $init_sort_column = null)
{
    if (!is_array($init_sort_column) || 0 == count($init_sort_column)) {
        $init_sort_column = null;
    }
    $html = '
		<script type="text/javascript">//<![CDATA[
			$(document).ready(function( ) {';
    if (!is_null($init_sort_column)) {
        $html .= '
				var c = [';
        $sort = '';
        foreach ($init_sort_column as $col => $dir) {
            $sort .= '[' . $col . ',' . $dir . '],';
        }
        $html .= substr($sort, 0, -1) . ']
				';
    }
    $html .= '
				$("#' . $table_id . '").tablesorter({
					textExtraction: "complex",
					widgets: ["zebra"],
					widgetZebra: {css: ["","' . $alt_class . '"]},
					headers: {';
    if ('' != $sort_types) {
        array_trim($sort_types);
        $keys = array_keys($sort_types);
        $last_key = end($keys);
        foreach ($sort_types as $key => $type) {
            if ('' !== $type) {
                if ('false' != $type) {
                    $type = "'{$type}'";
                }
                $html .= '
						' . $key . ': { sorter: ' . $type . ' }';
                if ($last_key != $key) {
                    $html .= ',';
                }
            }
        }
    }
    $html .= '
					}
				});';
    if (!is_null($init_sort_column)) {
        $html .= '
				$("#' . $table_id . '").trigger("sorton",[c]);';
    }
    $html .= '
			});
		//]]></script>';
    return $html;
}