/**
  * Formata o valor
  * @param mixed $value
  * @param string $type
  * @param boolean $formatar
  * @return mixed
  */
 function formatValue($value, $type, $formatar)
 {
     switch (strtolower($type)) {
         case 'data':
         case 'dt':
         case 'date':
             $value = Date::data((string) $value);
             return $formatar ? Date::formatData($value) : $value;
             break;
         case 'timestamp':
         case 'datatime':
             $value = Date::timestamp((string) $value);
             return $formatar ? Date::formatDataTime($value) : $value;
             break;
         case 'real':
             return $formatar ? Number::real($value) : Number::float($value, 2);
         case 'hide':
             return $formatar ? null : $value;
             break;
         case 'array':
             return $formatar ? stringToArray($value) : arrayToString($value);
             break;
         default:
             return $value;
     }
 }
Beispiel #2
0
function checkNumber($n, $maxNumber)
{
    if (isMax(stringToArray($n), $maxNumber)) {
        echo "\n\nnot possible and max is {$n}\n\n";
    } else {
        $n++;
        $new = stringToArray($n);
        sort($new);
        if ($new == $compairNumber) {
            echo "\n\nThe next number is {$n}\n\n";
        } else {
            checkNumber($n, $maxNumber);
        }
    }
}
function mostOftenCharacter($string)
{
    $myArray = stringToArray($string);
    $resultArray = array();
    $k = 0;
    $counts = array_count_values($myArray);
    foreach ($myArray as $value) {
        $maxRepeat = $counts[$myArray[$k]];
        $resultArray[0] = $counts[$myArray[0]];
        if ($resultArray[0] < $counts[$myArray[$k]]) {
            $resultArray[0] = $myArray[$k];
            $resultArray[1] = $counts[$myArray[$k]];
        } else {
            $resultArray[0] = $myArray[0];
            $resultArray[1] = $counts[$myArray[0]];
        }
        $k++;
    }
    return $resultArray;
}
 function _getPage($userId, $params, $cacheSetting)
 {
     if (!$cacheSetting) {
         # MVC initalization script
         if (!defined('DS')) {
             define('DS', DIRECTORY_SEPARATOR);
         }
         require 'components' . DS . 'com_jreviews' . DS . 'jreviews' . DS . 'framework.php';
     }
     Configure::write('Libraries.disableJS', array('jquery'));
     # Populate $params array with module settings
     $eParams['page'] = 1;
     $eParams['user'] = $userId;
     $eParams['module'] = stringToArray($params->_raw);
     $eParams['module']['community'] = true;
     $eParams['module_id'] = 'plugin_myfavorites' . $userId;
     $eParams['page'] = 1;
     $eParams['data']['module'] = true;
     $eParams['data']['controller'] = 'community_listings';
     $eParams['data']['action'] = 'favorites';
     $eParams['data']['module_limit'] = $params->get('limit', 10);
     $Dispatcher = new S2Dispatcher('jreviews', true, false);
     return $Dispatcher->dispatch($eParams);
 }
Beispiel #5
0
 /**
  * Creates the custom field group array with group info and fields values and attributes
  *
  * @param array $entries Entry array must have keys for entry id and criteriaid
  */
 function getFieldsArray($elements, $type = 'listing')
 {
     $fields = array();
     $field_pairs = array();
     $element_ids = array();
     $rows = array();
     $this->criteria_ids = array();
     // Alejandro = for discussion functionality
     //build entry_ids and criteria_ids array
     switch ($type) {
         case 'listing':
             foreach ($elements as $key => $element) {
                 if (isset($element['Criteria'])) {
                     $element_ids[] = $element[inflector::camelize($type)]['listing_id'];
                     if ($element['Criteria']['criteria_id'] != '') {
                         $this->criteria_ids[] = $element['Criteria']['criteria_id'];
                     }
                 }
             }
             break;
         case 'review':
             foreach ($elements as $element) {
                 if (isset($element['Criteria'])) {
                     $element_ids[] = $element[inflector::camelize($type)]['review_id'];
                     if ($element['Criteria']['criteria_id'] != '') {
                         $this->criteria_ids[] = $element['Criteria']['criteria_id'];
                     }
                 }
             }
             break;
     }
     $this->group_ids = $this->_criteria2Groups($this->criteria_ids, $type);
     $criteria_ids = implode(',', $this->criteria_ids);
     $element_ids = implode(',', array_unique($element_ids));
     if (empty($this->group_ids)) {
         return;
     }
     $group_ids = implode(',', $this->group_ids);
     $field_type = $type == 'listing' ? 'content' : $type;
     // Get field attributes and field values
     $query = "SELECT Field.fieldid AS `Field.field_id`, Field.groupid AS `Field.group_id`, Field.name AS `Field.name`, Field.title AS `Field.title`," . "\n Field.showtitle AS `Field.showTitle`, Field.description AS `Field.description`, Field.required AS `Field.required`," . "\n Field.type AS `Field.type`, Field.location AS `Field.location`, Field.options AS `Field.params`," . "\n Field.contentview AS `Field.contentView`, Field.listview AS `Field.listView`, Field.compareview AS `Field.compareView`, Field.listsort AS `Field.listSort`," . "\n Field.search AS `Field.search`, Field.access AS `Field.access`, Field.access_view AS `Field.accessView`," . "\n Field.published As `Field.published`," . "\n `Group`.groupid AS `Group.group_id`, `Group`.title AS `Group.title`, `Group`.name AS `Group.name`, `Group`.showtitle AS `Group.showTitle`" . "\n FROM #__jreviews_fields AS Field" . "\n INNER JOIN #__jreviews_groups AS `Group` ON (`Group`.groupid = Field.groupid AND " . "\n `Group`.groupid IN ({$group_ids}) AND `Group`.type =  '{$field_type}' )" . "\n WHERE Field.location = '{$field_type}' AND Field.published = 1" . "\n ORDER BY Group.ordering, Field.ordering";
     $this->_db->setQuery($query);
     $rows = $this->_db->loadObjectList('Field.name');
     if (!$rows || empty($rows)) {
         return;
     }
     # Extract list of field names from array
     $fieldNames = array();
     $fieldNamesByType = array();
     $fieldRows = array();
     $optionFields = array('selectmultiple', 'checkboxes', 'select', 'radiobuttons');
     foreach ($rows as $key => $row) {
         $fieldNames[] = $row->{'Field.name'};
         $fieldIds[$row->{'Field.name'}] = $row->{'Field.field_id'};
         $fieldRows[$key] = (array) $row;
         if (in_array($row->{'Field.type'}, $optionFields)) {
             $query = "SELECT * FROM #__jreviews_fieldoptions" . "\n WHERE fieldid = " . $row->{'Field.field_id'} . "\n ORDER BY ordering ASC ,optionid ASC";
             $this->_db->setQuery($query);
             $this->fieldOptions[$row->{'Field.field_id'}] = $this->_db->loadObjectList('value');
         }
     }
     # Get field values from current element ids
     switch ($type) {
         case 'listing':
             # PaidListings integration
             if (Configure::read('ListingEdit') && Configure::read('PaidListings.enabled')) {
                 // Load the paid_listing_fields table instead of the jos_content table so users can see all their
                 // fields when editing a listing
                 Configure::write('ListingEdit', false);
                 $fieldValues = PaidListingFieldModel::edit($element_ids);
                 if ($fieldValues) {
                     break;
                 }
             }
             $query = "SELECT Listing.contentid AS element_id," . implode(',', $fieldNames) . "\n FROM #__jreviews_content AS Listing" . "\n WHERE Listing.contentid IN (" . $element_ids . ")";
             $this->_db->setQuery($query);
             $fieldValues = $this->_db->loadObjectList('element_id');
             break;
         case 'review':
             $query = "SELECT Review.reviewid AS element_id," . implode(',', $fieldNames) . "\n FROM #__jreviews_review_fields AS Review" . "\n WHERE Review.reviewid IN (" . $element_ids . ")";
             $this->_db->setQuery($query);
             $fieldValues = $this->_db->loadObjectList('element_id');
             break;
     }
     # Now for each option field add array of selected value,text,images
     $elementFields = array();
     if (!empty($fieldValues)) {
         foreach ($fieldValues as $fieldValue) {
             $fieldValue = (array) $fieldValue;
             foreach ($fieldValue as $key => $value) {
                 if ($key != 'element_id' && $value != '' && isset($rows[$key])) {
                     !in_array($rows[$key]->{'Field.type'}, array('textarea', 'code')) and $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
                     if ($rows[$key]->{'Field.type'} != 'date' || $rows[$key]->{'Field.type'} == 'date' && $value != NULL_DATE) {
                         $elementFields[$fieldValue['element_id']]['field_id'] = $fieldRows[$key]['Field.field_id'];
                         if (!in_array($rows[$key]->{'Field.type'}, $optionFields)) {
                             $elementFields[$fieldValue['element_id']][$key]['Field.text'][] = $value;
                             $elementFields[$fieldValue['element_id']][$key]['Field.value'][] = $value;
                             $elementFields[$fieldValue['element_id']][$key]['Field.image'][] = '';
                         } elseif (in_array($rows[$key]->{'Field.type'}, $optionFields)) {
                             $fieldOptions = $this->fieldOptions[$rows[$key]->{'Field.field_id'}];
                             $selOptions = explode('*', $value);
                             foreach ($selOptions as $selOption) {
                                 if (isset($fieldOptions[$selOption])) {
                                     $elementFields[$fieldValue['element_id']][$key]['Field.value'][] = $fieldOptions[$selOption]->value;
                                     $elementFields[$fieldValue['element_id']][$key]['Field.text'][] = $fieldOptions[$selOption]->text;
                                     $elementFields[$fieldValue['element_id']][$key]['Field.image'][] = $fieldOptions[$selOption]->image;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Reformat array so array keys match element ids
     foreach ($elementFields as $key => $elementField) {
         $element_id = $key;
         $field_id = $elementField['field_id'];
         unset($elementField['field_id']);
         $field_name = key($elementField);
         foreach ($elementField as $field_name => $field_options) {
             //FieldGroups array
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['group_id'] = $fieldRows[$field_name]['Field.group_id'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['title'] = $fieldRows[$field_name]['Group.title'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['name'] = $fieldRows[$field_name]['Group.name'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['show_title'] = $fieldRows[$field_name]['Group.showTitle'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['id'] = $field_id;
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['group_id'] = $fieldRows[$field_name]['Field.group_id'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['name'] = $fieldRows[$field_name]['Field.name'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['type'] = $fieldRows[$field_name]['Field.type'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['title'] = $fieldRows[$field_name]['Field.title'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['description'] = $fieldRows[$field_name]['Field.description'];
             // Field values
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['value'] = $field_options['Field.value'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['text'] = $field_options['Field.text'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['image'] = $field_options['Field.image'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['show_title'] = $fieldRows[$field_name]['Field.showTitle'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['location'] = $fieldRows[$field_name]['Field.location'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['contentview'] = $fieldRows[$field_name]['Field.contentView'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['listview'] = $fieldRows[$field_name]['Field.listView'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['compareview'] = $fieldRows[$field_name]['Field.compareView'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['listsort'] = $fieldRows[$field_name]['Field.listSort'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['search'] = $fieldRows[$field_name]['Field.search'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['access'] = $fieldRows[$field_name]['Field.access'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['access_view'] = $fieldRows[$field_name]['Field.accessView'];
             //FieldPairs associative array with field name as key and field value as value
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_id'] = $fieldRows[$field_name]['Field.group_id'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_show_title'] = $fieldRows[$field_name]['Group.showTitle'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_title'] = $fieldRows[$field_name]['Group.title'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_name'] = $fieldRows[$field_name]['Group.name'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['name'] = $fieldRows[$field_name]['Field.name'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['title'] = $fieldRows[$field_name]['Field.title'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['value'] = $field_options['Field.value'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['text'] = $field_options['Field.text'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['image'] = $field_options['Field.image'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['type'] = $fieldRows[$field_name]['Field.type'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['show_title'] = $fieldRows[$field_name]['Field.showTitle'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['location'] = $fieldRows[$field_name]['Field.location'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['contentview'] = $fieldRows[$field_name]['Field.contentView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['listview'] = $fieldRows[$field_name]['Field.listView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['compareview'] = $fieldRows[$field_name]['Field.compareView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['listsort'] = $fieldRows[$field_name]['Field.listSort'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['search'] = $fieldRows[$field_name]['Field.search'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['access'] = $fieldRows[$field_name]['Field.access'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['access_view'] = $fieldRows[$field_name]['Field.accessView'];
             $properties = stringToArray($fieldRows[$field_name]['Field.params']);
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties'] = array_merge($fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties'], $properties);
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties'] = array_merge($field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties'], $properties);
             //$params = explode("\n",$fieldRows[$field_name]['Field.params']);
         }
     }
     $this->custom_fields = $fields;
     $this->field_pairs = $field_pairs;
 }
Beispiel #6
0
<?php

/**
 * jReviews - Reviews Extension
 * Copyright (C) 2006 ClickFWD LLC
 * This is not free software, do not distribute it.
 * For licencing information visit http://www.reviewsforjoomla.com
 * or contact sales@reviewsforjoomla.com
**/
defined('_VALID_MOS') || defined('_JEXEC') or die('Direct Access to this location is not allowed.');
# MVC initalization script
require JPATH_SITE . DS . 'components' . DS . 'com_jreviews' . DS . 'jreviews' . DS . 'framework.php';
# Populate $params array with module settings
$module_params = isset($params->_raw) ? stringToArray($params->_raw) : $params->toArray();
$moduleParams['module'] = $module_params;
$moduleParams['module_id'] = $module->id;
$moduleParams['page'] = 1;
$moduleParams['data']['module'] = true;
$moduleParams['data']['controller'] = 'module_totals';
$moduleParams['data']['action'] = 'index';
$moduleParams['token'] = cmsFramework::formIntegrityToken($moduleParams, array('module', 'module_id', 'form', 'data'), false);
$Dispatcher = new S2Dispatcher('jreviews');
echo $Dispatcher->dispatch($moduleParams);
unset($Dispatcher);
Beispiel #7
0
    } else {
        $_GET['url'] = Sanitize::getString($_GET, 'url', 'about');
    }
    /*******************************************************************
     *                         FRONT-END ROUTING
     ******************************************************************/
} elseif ($menu_id && !isset($_POST['data']['controller']) && (!$url || !isset($route['data']['controller']) || preg_match('/^menu\\//', $route['url']['url']))) {
    // If no task is passed in the url, then this is a menu item and we read the menu parameters
    $segments = array();
    $url_param = $url;
    $url = str_replace('menu', '', $url);
    $db = cmsFramework::getDB();
    $query = "SELECT * FROM #__menu WHERE id = " . $menu_id;
    $db->setQuery($query);
    $menu = end($db->loadObjectList());
    $mparams = getCmsVersion() == CMS_JOOMLA16 ? json_decode($menu->params, true) : stringToArray($menu->params);
    if (isset($mparams['action'])) {
        $action = paramsRoute((int) $mparams['action']);
        $_REQUEST['Itemid'] = $_GET['Itemid'] = $menu->id;
        // For default - home page menu
        unset($mparams['action']);
        $menu_params['data'] = $mparams;
        $filters = array('dir' => 'dirid', 'section' => 'sectionid', 'cat' => 'catid', 'criteria' => 'criteriaid');
        foreach ($filters as $key => $key2) {
            $menu_params[$key] = Sanitize::getVar($mparams, $key2);
            is_array($menu_params[$key]) and $menu_params[$key] = implode(',', $menu_params[$key]);
        }
        //        $menu_params['url'] = 'menu';
        $menu_params['data']['component_menu'] = true;
        $menu_params['data']['controller'] = $action[0];
        $menu_params['data']['action'] = $action[1];
<?php

/**
 * jReviews - Reviews Extension
 * Copyright (C) 2006 Alejandro Schmeichler
 * This is not free software, do not distribute it.
 * For licencing information visit http://www.reviewsforjoomla.com
 * or contact sales@reviewsforjoomla.com
**/
defined('_VALID_MOS') || defined('_JEXEC') or die('Direct Access to this location is not allowed.');
# MVC initalization script
if (!defined('DS')) {
    define('DS', DIRECTORY_SEPARATOR);
}
if (defined('JPATH_SITE')) {
    $root = JPATH_SITE . DS;
} else {
    global $mainframe;
    $root = $mainframe->getCfg('absolute_path') . DS;
}
require $root . 'components' . DS . 'com_jreviews' . DS . 'jreviews' . DS . 'framework.php';
# Populate $params array with module settings
$moduleParams['module'] = stringToArray($params->_raw);
$moduleParams['module_id'] = $module->id;
$moduleParams['data']['module'] = true;
$moduleParams['data']['controller'] = 'module_geomaps';
$moduleParams['data']['action'] = 'listings';
$Dispatcher = new S2Dispatcher('jreviews', false);
echo $Dispatcher->dispatch($moduleParams);
Beispiel #9
0
$view = Sanitize::getString($_REQUEST, 'view', '');
$layout = Sanitize::getString($_REQUEST, 'layout', '');
$id = explode(':', Sanitize::getInt($_REQUEST, 'id'));
$id = $id[0];
# Plugins table
if (!defined('_PLUGIN_DIR_NAME')) {
    if (getCmsVersion() == CMS_JOOMLA15) {
        define('_PLUGIN_DIR_NAME', 'plugins');
    } else {
        define('_PLUGIN_DIR_NAME', 'mambots');
    }
}
$query = "SELECT published,params FROM #__" . _PLUGIN_DIR_NAME . " WHERE element = 'jreviews' AND folder = 'content' LIMIT 1";
$CMS->_db->setQuery($query);
$jrbot = current($CMS->_db->loadObjectList());
$params = stringToArray($jrbot->params);
$published = $jrbot->published;
if ((int) (!$published)) {
    return;
}
$frontpageOff = Sanitize::getVar($params, 'frontpage');
$blogLayoutOff = Sanitize::getVar($params, 'blog');
# Get theme, suffix and load CSS so it's not killed by the built-in cache
if (getCmsVersion() == CMS_JOOMLA10 || getCmsVersion() == CMS_MAMBO46) {
    if ($option == 'com_content' && ($task == 'category' || $task == 'section' || $blogLayoutOff && $task == 'blogsection' || $blogLayoutOff && $task == 'blogcategory') || $frontpageOff && $option == 'com_frontpage') {
        return;
    }
} elseif ($blogLayoutOff && $option == 'com_content' && ($view == 'category' || $view == 'section') && ($layout == 'blog' || $layout == 'blogfull')) {
    return;
} elseif ($frontpageOff && $view == 'frontpage') {
    return;
 function index()
 {
     $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id'));
     if (!isset($this->params['module'])) {
         $this->params['module'] = array();
     }
     // For direct calls to the controller
     $listing_type_id = Sanitize::getInt($this->params, 'listingtype', false);
     # Find the correct set of params to use
     if ($this->ajaxRequest && $listing_type_id) {
         $listingType = $this->Criteria->getCriteria(array('criteria_id' => $listing_type_id));
         if (isset($listingType['ListingType']['config']['userfavorites'])) {
             $userfavoritesParams = $listingType['ListingType']['config']['userfavorites'];
             $userfavoritesParams['criteria'] = implode(',', Sanitize::getVar($userfavoritesParams, 'criteria', array()));
             $this->params['module'] = array_merge($this->params['module'], $userfavoritesParams);
         }
     } elseif ($this->ajaxRequest && empty($this->params['module']) && $module_id) {
         $query = "SELECT params FROM #__modules WHERE id = " . $module_id;
         $this->_db->setQuery($query);
         $this->params['module'] = stringToArray($this->_db->loadResult());
     }
     # Get cached vesion
     /*        if($this->_user->id === 0) 
             {    
                 $page = $this->cached($this->here);
                 if($page) {
                     return $this->ajaxRequest ? $this->ajaxResponse($page,false) : $page;
                 } 
             }  */
     srand((double) microtime() * 1000000);
     $this->params['rand'] = rand();
     isset($this->params['module']) and $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix');
     // Read the module parameters
     $img_width = Sanitize::getInt($this->params['module'], 'img_width', 50);
     $random_mode = Sanitize::getString($this->params['module'], 'random_mode', 'Random Users');
     $favorites_mode = Sanitize::getString($this->params['module'], 'favorites_mode', 'Other users interested in {title}');
     $limit = Sanitize::getInt($this->params['module'], 'module_limit', 5);
     $total = min(50, Sanitize::getInt($this->params['module'], 'module_total', 10));
     # Get url params for current controller/action
     if (!$this->ajaxRequest) {
         $url = Sanitize::getString($_REQUEST, 'url');
         $route['url']['url'] = $url;
         $route['data'] = array();
         $route = S2Router::parse($route, true, 'jreviews');
         # Check if page is listing detail
         $detail = Sanitize::getString($route['url'], 'extension', 'com_content') == 'com_content' && isset($route['data']) && Sanitize::getString($route['data'], 'controller') == 'listings' && Sanitize::getString($route['data'], 'action') == 'detail' ? true : false;
         # Initialize variables
         $listing_id = $detail ? Sanitize::getInt($route, 'id') : Sanitize::getInt($this->params, 'id');
         $option = Sanitize::getString($this->params, 'option');
         $view = Sanitize::getString($this->params, 'view');
         $task = Sanitize::getString($this->params, 'task');
         $listing_title = '';
     } else {
         $detail = true;
         $listing_id = Sanitize::getInt($this->params, 'id');
     }
     # Article auto-detect - only for com_content
     if ($detail || 'com_content' == $option && ('article' == $view || 'view' == $task)) {
         $query = "SELECT Listing.id, Listing.title FROM #__content AS Listing WHERE Listing.id = " . $listing_id;
         $this->_db->setQuery($query);
         $listing = current($this->_db->loadObjectList());
         $listing_title = $listing->title;
     } else {
         $listing_id = null;
     }
     $profiles = $this->Community->getListingFavorites($listing_id, $this->_user->id, $this->params);
     $total = count($profiles);
     $this->set(array('profiles' => $profiles, 'listing_title' => $listing_title, 'limit' => $limit, 'total' => $total));
     $this->_completeModuleParamsArray();
     $page = $this->ajaxRequest && empty($profiles) ? '' : $this->render('modules', 'favorite_users');
     # Save cached version
     /*        if($this->_user->id ===0) {    
                 $this->cacheView('modules','userfavorites',$this->here, $page);
             }      */
     return $this->ajaxRequest ? $this->ajaxResponse($page, false) : $page;
 }
 function index()
 {
     /*        if($this->_user->id === 0) 
             {
                 $this->cacheAction = Configure::read('Cache.expires');        
             }   */
     $this->EverywhereAfterFind = true;
     // Triggers the afterFind in the Observer Model
     if (!isset($this->params['module'])) {
         $this->params['module'] = array();
     }
     // For direct calls to the controller
     $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id'));
     if (empty($this->params)) {
         $query = "SELECT params FROM #__modules WHERE id = " . $module_id;
         $this->_db->setQuery($query);
         $this->params['module'] = stringToArray($this->_db->loadResult());
     }
     $ids = $conditions = $joins = $order = array();
     # Read module parameters
     $extension = Sanitize::getString($this->params['module'], 'extension');
     $reviews_type = Sanitize::getString($this->params['module'], 'reviews_type');
     $custom_where = Sanitize::getString($this->params['module'], 'custom_where');
     $cat_id = Sanitize::getString($this->params['module'], 'category');
     $listing_id = Sanitize::getString($this->params['module'], 'listing');
     $limit = Sanitize::getInt($this->params['module'], 'module_limit', 5);
     $total = min(50, Sanitize::getInt($this->params['module'], 'module_total', 10));
     if ($extension == 'com_content') {
         $dir_id = Sanitize::getString($this->params['module'], 'dir');
         $section_id = Sanitize::getString($this->params['module'], 'section');
         $criteria_id = Sanitize::getString($this->params['module'], 'criteria');
     } else {
         $dir_id = null;
         $section_id = null;
         $criteria_id = null;
     }
     # Prevent sql injection
     $token = Sanitize::getString($this->params, 'token');
     $tokenMatch = 0 === strcmp($token, cmsFramework::formIntegrityToken($this->params, array('module', 'module_id', 'form', 'data'), false));
     isset($this->params['module']) and $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix');
     // This parameter determines the module mode
     $sort = Sanitize::getString($this->params['module'], 'reviews_order');
     if (in_array($sort, array('random'))) {
         srand((double) microtime() * 1000000);
         $this->params['rand'] = rand();
     }
     # Category auto detect
     if (Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') {
         $ids = CommonController::_discoverIDs($this);
         extract($ids);
     }
     $extension != '' and $conditions[] = "Review.mode = " . $this->quote($extension);
     # Set conditionals based on configuration parameters
     if ($extension == 'com_content') {
         $conditions = array_merge($conditions, array('Listing.state = 1', '( Listing.publish_up = "' . NULL_DATE . '" OR DATE(Listing.publish_up) <= DATE("' . _CURRENT_SERVER_TIME . '") )', '( Listing.publish_down = "' . NULL_DATE . '" OR DATE(Listing.publish_down) >= DATE("' . _CURRENT_SERVER_TIME . '") )'));
         if ($this->cmsVersion == CMS_JOOMLA15) {
             //                $conditions[] = 'Section.access <= ' . $this->Access->getAccessId();
             $conditions[] = 'Category.access <= ' . $this->Access->getAccessId();
             $conditions[] = 'Listing.access <= ' . $this->Access->getAccessId();
         } else {
             $conditions[] = 'Category.access IN (' . $this->Access->getAccessLevels() . ')';
             $conditions[] = 'Listing.access IN ( ' . $this->Access->getAccessLevels() . ')';
         }
         if (!empty($cat_id)) {
             if ($this->cmsVersion == CMS_JOOMLA15) {
                 $conditions[] = 'Listing.catid IN (' . cleanIntegerCommaList($cat_id) . ')';
             } else {
                 $this->Review->joins['ParentCategory'] = "LEFT JOIN #__categories AS ParentCategory ON Category.lft BETWEEN ParentCategory.lft AND ParentCategory.rgt";
                 $conditions[] = 'ParentCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')';
             }
         }
         empty($cat_id) and !empty($section_id) and $conditions[] = 'Listing.sectionid IN (' . cleanIntegerCommaList($section_id) . ')';
         empty($cat_id) and !empty($dir_id) and $conditions[] = 'JreviewsCategory.dirid IN (' . cleanIntegerCommaList($dir_id) . ')';
         empty($cat_id) and !empty($criteria_id) and $conditions[] = 'JreviewsCategory.criteriaid IN (' . cleanIntegerCommaList($criteria_id) . ')';
     } else {
         if (Sanitize::getInt($this->params['module'], 'cat_auto') && isset($this->Listing) && method_exists($this->Listing, 'catUrlParam')) {
             if ($cat_id = Sanitize::getInt($this->passedArgs, $this->Listing->catUrlParam())) {
                 $conditions[] = 'JreviewsCategory.id IN (' . $cat_id . ')';
             }
         } elseif ($cat_id) {
             $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')';
         }
     }
     $listing_id and $conditions[] = "Review.pid IN ( " . cleanIntegerCommaList($listing_id) . ")";
     $conditions[] = 'Review.published > 0';
     switch ($sort) {
         case 'latest':
             $order[] = $this->Review->processSorting('rdate');
             break;
         case 'helpful':
             $order[] = $this->Review->processSorting('helpful');
             break;
         case 'random':
             $order[] = 'RAND(' . $this->params['rand'] . ')';
             break;
         default:
             $order[] = $this->Review->processSorting('rdate');
             break;
     }
     switch ($reviews_type) {
         case 'all':
             break;
         case 'user':
             $conditions[] = 'Review.author = 0';
             break;
         case 'editor':
             $conditions[] = 'Review.author = 1';
             break;
     }
     # Custom WHERE
     $tokenMatch and $custom_where and $conditions[] = $custom_where;
     $queryData = array('joins' => $joins, 'conditions' => $conditions, 'order' => $order, 'limit' => $total);
     # Don't run it here because it's run in the Everywhere Observer Component
     $this->Review->runProcessRatings = false;
     // Excludes listing owner info in Everywhere component
     $this->Review->controller = 'module_reviews';
     $reviews = $this->Review->findAll($queryData);
     $count = count($reviews);
     # Send variables to view template
     $this->set(array('autodetect_ids' => $ids, 'reviews' => $reviews, 'total' => $count, 'limit' => $limit));
     $this->_completeModuleParamsArray();
     $page = $this->ajaxRequest && empty($reviews) ? '' : $this->render('modules', 'reviews');
     /*        if($this->_user->id === 0 && $this->ajaxRequest) 
             {
                 $path = $this->here;
     
                 $this->here == '/' and $path = 'home';
                 
                 $cache_fname = Inflector::slug($path) . '.php';
              
                 $now = time();
     
                 $cacheTime = is_numeric($this->cacheAction) ? $now + $this->cacheAction : strtotime($this->cacheAction, $now);
              
                 $fileHeader = '<!--cachetime:' . $cacheTime . '-->'; 
                 
                 cache('views' . DS . $cache_fname, $fileHeader . $this->ajaxResponse($page,false), $this->cacheAction);
             }*/
     return $this->ajaxRequest ? $this->ajaxResponse($page, false) : $page;
 }
Beispiel #12
0
    exit;
}
if ($fileType != 'text/plain') {
    echo 'Error: file is not a plain text';
    exit;
}
$upfile = __DIR__ . "\\upload\\" . $userFile;
if (is_uploaded_file($tmpFile)) {
    if (!move_uploaded_file($tmpFile, $upfile)) {
        echo 'File uploaded, but could not move to destination directory';
        exit;
    }
}
//call user function
$str = fileToString($upfile);
$arr = stringToArray($str);
usort($arr, "sortBySourceField");
echo "<table border=1>";
foreach ($arr as $key => $value) {
    foreach ($value as $key2 => $value2) {
        echo "<tr><td>{$key2}</td>";
        echo "<td>{$value2}</td>";
    }
}
echo "</table>";
//define user's functions
function fileToString($filePatch)
{
    $handle = fopen($filePatch, 'r');
    if (!$handle) {
        echo "Error. Can't read file";
Beispiel #13
0
 private function parseArticleList($allTitles)
 {
     if (count($allTitles) < 1) {
         $this->articleList = array();
         return;
     }
     $this->articleList = array();
     foreach ($allTitles as $aID => $row) {
         $this->articleList[$aID] = $row;
         if ($row['aCateURLName'] == '_trash') {
             $this->articleList[$aID]['aCateDispName'] = bw::$conf['l']['admin:item:TrashBin'];
         } elseif ($row['aCateURLName'] == '_page') {
             $this->articleList[$aID]['aCateDispName'] = bw::$conf['l']['page:SinglePage'];
         } else {
             $this->articleList[$aID]['aCateDispName'] = bw::$cateData[$row['aCateURLName']];
         }
         $this->articleList[$aID]['aAllTags'] = stringToArray(@explode(',', $row['aTags']), 'tagValue');
         if (isset(bw::$conf['commentOpt'])) {
             if (bw::$conf['commentOpt'] == 0 || bw::$conf['commentOpt'] == 3) {
                 // If using non-built-in comment system, give an empty string instead of 0 for the attribute aComments
                 $this->articleList[$aID]['aComments'] = '';
             }
         }
     }
 }
Beispiel #14
0
$size = count($query->result());
foreach ($query->result() as $row) {
    echo '{';
    echo '"id":"' . $row->tIndex . '", ';
    echo '"word":"' . $row->word . '", ';
    if ($row->WordNumer != '') {
        echo '"noWord":[' . stringToArray($row->WordNumer) . '], ';
    }
    if ($row->Symbol != '') {
        echo '"symbol":[' . stringToArray($row->Symbol) . '], ';
    }
    if ($row->IPASymbol != '') {
        echo '"iPASymbol":[' . stringToArray($row->IPASymbol) . '], ';
    }
    if ($row->unicode != '') {
        echo '"unicode":[' . stringToArray($row->unicode) . ']';
    }
    echo "}";
    if ($i < $size - 1) {
        echo ',';
    }
    echo "\n";
    $i++;
}
echo ']}';
function stringToArray($text)
{
    $i = 0;
    $array = explode(" ", $text);
    $string = "";
    $size = count($array);
 function index()
 {
     /*        if($this->_user->id === 0) 
             {
                 $this->cacheAction = Configure::read('Cache.expires');        
             }*/
     // Required for ajax pagination to remember module settings
     $ids = $conditions = $joins = $order = $having = array();
     $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id'));
     if (!isset($this->params['module'])) {
         $this->params['module'] = array();
     }
     // For direct calls to the controller
     # Find the correct set of params to use
     if ($this->ajaxRequest && Sanitize::getInt($this->params, 'listing_id')) {
         $this->params['module'] = array_merge($this->params['module'], $this->__processListingTypeWidgets($conditions));
     } elseif ($this->ajaxRequest && empty($this->params['module']) && $module_id) {
         $query = "SELECT params FROM #__modules WHERE id = " . $module_id;
         $this->_db->setQuery($query);
         $this->params['module'] = stringToArray($this->_db->loadResult());
     }
     if ($this->abort) {
         return $this->ajaxResponse('', false);
     }
     # Read module parameters
     $dir_id = Sanitize::getString($this->params['module'], 'dir');
     $section_id = Sanitize::getString($this->params['module'], 'section');
     $cat_id = Sanitize::getString($this->params['module'], 'category');
     $listing_id = Sanitize::getString($this->params['module'], 'listing');
     $created_by = Sanitize::getString($this->params['module'], 'owner');
     $criteria_id = Sanitize::getString($this->params['module'], 'criteria');
     $limit = Sanitize::getInt($this->params['module'], 'module_limit', 5);
     $total = min(50, Sanitize::getInt($this->params['module'], 'module_total', 10));
     $extension = Sanitize::getString($this->params['module'], 'extension');
     $extension = $extension != '' ? $extension : 'com_content';
     $sort = Sanitize::getString($this->params['module'], 'listing_order');
     if (in_array($sort, array('random', 'featuredrandom'))) {
         srand((double) microtime() * 1000000);
         $this->params['rand'] = rand();
     }
     # Prevent sql injection
     $token = Sanitize::getString($this->params, 'token');
     $tokenMatch = 0 === strcmp($token, cmsFramework::formIntegrityToken($this->params, array('module', 'module_id', 'form', 'data'), false));
     isset($this->params['module']) and $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix');
     if (isset($this->Listing)) {
         $this->Listing->_user = $this->_user;
         // This parameter determines the module mode
         $custom_order = Sanitize::getString($this->params['module'], 'custom_order');
         $custom_where = Sanitize::getString($this->params['module'], 'custom_where');
         if ($extension != 'com_content' && in_array($sort, array('topratededitor', 'featuredrandom', 'rhits'))) {
             echo "You have selected the {$sort} mode which is not supported for components other than com_content. Please read the tooltips in the module parameters for more info on allowed settings.";
             return;
         }
         # Category auto detect
         if (Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') {
             $ids = CommonController::_discoverIDs($this);
             extract($ids);
         }
         # Set conditionals based on configuration parameters
         if ($extension == 'com_content') {
             // Perform tag replacement for listing_id to allow for related listing queries
             if (Sanitize::getString($this->params, 'view') == 'article' && $custom_where != '') {
                 $curr_listing_id = Sanitize::getInt($this->params, 'id');
                 $custom_where = str_replace('{listing_id}', $curr_listing_id, $custom_where);
             }
             // Only works for core articles
             $conditions = array_merge($conditions, array('Listing.state = 1', '( Listing.publish_up = "' . NULL_DATE . '" OR DATE(Listing.publish_up) <= DATE("' . _CURRENT_SERVER_TIME . '") )', '( Listing.publish_down = "' . NULL_DATE . '" OR DATE(Listing.publish_down) >= DATE("' . _CURRENT_SERVER_TIME . '") )'));
             if ($this->cmsVersion == CMS_JOOMLA15) {
                 //                    $conditions[] = 'Section.access <= ' . $this->Access->getAccessId();
                 $conditions[] = 'Category.access <= ' . $this->Access->getAccessId();
                 $conditions[] = 'Listing.access <= ' . $this->Access->getAccessId();
             } else {
                 $conditions[] = 'Category.access IN (' . $this->Access->getAccessLevels() . ')';
                 $conditions[] = 'Listing.access IN (' . $this->Access->getAccessLevels() . ')';
             }
             // Remove unnecessary fields from model query
             $this->Listing->modelUnbind(array('Listing.fulltext AS `Listing.description`', 'Listing.metakey AS `Listing.metakey`', 'Listing.metadesc AS `Listing.metadesc`', 'User.email AS `User.email`'));
             if (!empty($cat_id)) {
                 $conditions[] = $this->cmsVersion == CMS_JOOMLA15 ? 'Listing.catid IN (' . cleanIntegerCommaList($cat_id) . ')' : 'ParentCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')';
             } else {
                 unset($this->Listing->joins['ParentCategory']);
             }
             empty($cat_id) and !empty($section_id) and $conditions[] = 'Listing.sectionid IN (' . cleanIntegerCommaList($section_id) . ')';
             empty($cat_id) and !empty($dir_id) and $conditions[] = 'JreviewsCategory.dirid IN (' . cleanIntegerCommaList($dir_id) . ')';
             empty($cat_id) and !empty($criteria_id) and $conditions[] = 'JreviewsCategory.criteriaid IN (' . cleanIntegerCommaList($criteria_id) . ')';
         } else {
             if (Sanitize::getInt($this->params['module'], 'cat_auto') && method_exists($this->Listing, 'catUrlParam')) {
                 if ($cat_id = Sanitize::getInt($this->passedArgs, $this->Listing->catUrlParam())) {
                     $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')';
                 }
             } elseif ($cat_id) {
                 $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')';
             }
         }
         $listing_id and $conditions[] = "Listing.{$this->Listing->realKey} IN (" . cleanIntegerCommaList($listing_id) . ")";
         switch ($sort) {
             case 'random':
                 $order[] = 'RAND(' . $this->params['rand'] . ')';
                 break;
             case 'featured':
                 $conditions[] = 'Field.featured = 1';
                 break;
             case 'featuredrandom':
                 $conditions[] = 'Field.featured = 1';
                 $order[] = 'RAND(' . $this->params['rand'] . ')';
                 break;
             case 'topratededitor':
                 //                    $conditions[] = 'Totals.editor_rating > 0';
                 $sort = 'editor_rating';
                 break;
                 // Editor rating sorting options dealt with in the Listing->processSorting method
         }
         # Custom WHERE
         $tokenMatch and $custom_where and $conditions[] = $custom_where;
         # Filtering options
         $having = array();
         // Listings submitted in the past x days
         $entry_period = Sanitize::getInt($this->params['module'], 'filter_listing_period');
         if ($entry_period > 0 && $this->Listing->dateKey) {
             $conditions[] = "Listing.{$this->Listing->dateKey} >= DATE_SUB('" . _CURRENT_SERVER_TIME . "', INTERVAL {$entry_period} DAY)";
         }
         // Listings with reviews submitted in past x days
         $review_period = Sanitize::getInt($this->params['module'], 'filter_review_period');
         if ($review_period > 0) {
             $conditions[] = "Review.created >= DATE_SUB(CURDATE(), INTERVAL {$review_period} DAY)";
             $joins[] = 'LEFT JOIN #__jreviews_comments AS Review ON Listing.' . $this->Listing->realKey . ' = Review.pid';
         }
         // Listings with review count higher than
         $filter_review_count = Sanitize::getInt($this->params['module'], 'filter_review_count');
         $filter_review_count > 0 and $conditions[] = "Totals.user_rating_count >= " . $filter_review_count;
         // Listings with avg rating higher than
         $filter_avg_rating = Sanitize::getFloat($this->params['module'], 'filter_avg_rating');
         $filter_avg_rating > 0 and $conditions[] = 'Totals.user_rating  >= ' . $filter_avg_rating;
         $this->Listing->group = array();
         // Exlude listings without ratings from the results
         $join_direction = in_array($sort, array('rating', 'rrating', 'topratededitor', 'reviews')) ? 'INNER' : 'LEFT';
         $this->Listing->joins['Total'] = "{$join_direction} JOIN #__jreviews_listing_totals AS Totals ON Totals.listing_id = Listing.{$this->Listing->realKey} AND Totals.extension = " . $this->quote($extension);
         # Modify query for correct ordering. Change FIELDS, ORDER BY and HAVING BY directly in Listing Model variables
         if ($tokenMatch and $custom_order) {
             $this->Listing->order[] = $custom_order;
         } elseif (empty($order) && $extension == 'com_content') {
             $this->Listing->processSorting('module', $sort);
             // Modifies Listing model order var directly
         } elseif (empty($order) && ($order = $this->__processSorting($sort))) {
             $order = array($order);
         }
         $fields = array('Totals.user_rating AS `Review.user_rating`', 'Totals.user_rating_count AS `Review.user_rating_count`', 'Totals.user_comment_count AS `Review.review_count`', 'Totals.editor_rating AS `Review.editor_rating`', 'Totals.editor_rating_count AS `Review.editor_rating_count`', 'Totals.editor_comment_count AS `Review.editor_review_count`');
         $queryData = array('fields' => !isset($this->Listing->fields['editor_rating']) ? $fields : array(), 'joins' => $joins, 'conditions' => $conditions, 'limit' => $total, 'having' => $having);
         isset($order) and !empty($order) and $queryData['order'] = $order;
         // Trigger addFields for $listing results. Checked in Everywhere model
         $this->Listing->addFields = true;
         $listings = $this->Listing->findAll($queryData);
         $count = count($listings);
     } else {
         $listings = array();
         $count = 0;
     }
     unset($this->Listing);
     # Send variables to view template
     $this->set(array('autodetect_ids' => $ids, 'subclass' => 'listing', 'listings' => $listings, 'total' => $count, 'limit' => $limit));
     $this->_completeModuleParamsArray();
     $page = $this->ajaxRequest && empty($listings) ? '' : $this->render('modules', 'listings');
     /*        if($this->_user->id === 0 && $this->ajaxRequest) 
             {
                 $path = $this->here;
     
                 $this->here == '/' and $path = 'home';
                 
                 $cache_fname = Inflector::slug($path) . '.php';
              
                 $now = time();
     
                 $cacheTime = is_numeric($this->cacheAction) ? $now + $this->cacheAction : strtotime($this->cacheAction, $now);
              
                 $fileHeader = '<!--cachetime:' . $cacheTime . '-->'; 
                 
                 cache('views' . DS . $cache_fname, $fileHeader . $this->ajaxResponse($page,false), $this->cacheAction);
             }*/
     return $this->ajaxRequest ? $this->ajaxResponse($page, false) : $page;
 }
Beispiel #16
0
 function __construct()
 {
     parent::__construct();
     # Check for cached version
     $cache_file = 'jreviews_menu_' . cmsFramework::locale() . '_' . md5(cmsFramework::getConfig('secret'));
     if ($cache = S2Cache::read($cache_file)) {
         $this->___menu_data = $cache['___menu_data'];
         return;
     }
     $menuList = array();
     switch ($this->cmsVersion) {
         case CMS_JOOMLA15:
             $select = "\n                    SELECT \n                        id,\n                        name,\n                        link AS menu_type,\n                        link,\n                        componentid,\n                        params,\n                        access,\n                        published\n                ";
             break;
         case CMS_JOOMLA16:
             $select = "\n                    SELECT \n                        id, \n                        title AS name,\n                        link AS menu_type,\n                        link,\n                        component_id AS componentid,\n                        params,\n                        access,\n                        published\n                ";
             break;
     }
     // Get all com_content category/section menus and JReviews menus
     $sql = $select . "\n            FROM #__menu\n            WHERE published = 1\n            ORDER BY link DESC\n        ";
     $this->_db->setQuery($sql);
     $menuList = $this->_db->loadObjectList();
     // Get itemid for each menu link and store it
     if (!empty($menuList)) {
         foreach ($menuList as $menu) {
             $params = stringToArray($menu->params);
             $m_name = Sanitize::getVar($params, 'sef_name') != '' ? Sanitize::getVar($params, 'sef_name') : $menu->name;
             function_exists("sefEncode") and $m_name = sefEncode($m_name);
             $m_action = Sanitize::getVar($params, 'action');
             $m_dir_id = str_replace(",", "-", Sanitize::getVar($params, 'dirid'));
             $m_cat_id = str_replace(",", "-", Sanitize::getVar($params, 'catid'));
             $m_section_id = str_replace(",", "-", Sanitize::getVar($params, 'sectionid'));
             $m_criteria_id = str_replace(",", "-", Sanitize::getVar($params, 'criteriaid'));
             // Create a variable to get Menu Name from Itemid
             $this->set('jr_itemid_' . $menu->id, $m_name);
             $this->set('jr_menu_' . $m_name, $menu->id);
             if (strpos($menu->menu_type, 'option=com_content&view=section&id=') || strpos($menu->menu_type, 'option=com_content&view=section&layout=blog&id=')) {
                 $menu->componentid = end(explode('id=', $menu->menu_type));
                 $menu->menu_type = 'content_section';
             } elseif (strpos($menu->menu_type, 'option=com_content&view=category&id=') || strpos($menu->menu_type, 'option=com_content&view=category&layout=blog&id=')) {
                 $menu->componentid = end(explode('id=', $menu->menu_type));
                 $menu->menu_type = 'content_category';
             } elseif (strpos($menu->menu_type, 'option=com_content&view=article&id=') || strpos($menu->menu_type, 'option=com_content&task=view&id=')) {
                 $menu->componentid = end(explode('id=', $menu->menu_type));
                 $menu->menu_type = 'content_item_link';
             }
             switch ($menu->menu_type) {
                 case 'content_section':
                 case 'content_blog_section':
                     if ($menu->componentid) {
                         // Only one section id
                         $this->set('core_section_menu_id_' . $menu->componentid, $menu->id);
                     } else {
                         $section_ids = explode(",", Sanitize::getVar($params, 'sectionid'));
                         $this->set('jr_manyIds_' . $menu->id, 1);
                         foreach ($section_ids as $section_id) {
                             $this->set('core_section_menu_id_' . $section_id, $menu->id);
                         }
                     }
                     break;
                 case 'content_category':
                 case 'content_blog_category':
                     if ($menu->componentid) {
                         // Only one category id
                         $this->set('core_category_menu_id_' . $menu->componentid, $menu->id);
                     } else {
                         $cat_ids = explode(",", Sanitize::getVar($params, 'categoryid'));
                         $this->set('jr_manyIds_' . $menu->id, 1);
                         foreach ($cat_ids as $cat_id) {
                             $this->set('core_category_menu_id_' . $cat_id, $menu->id);
                         }
                     }
                     break;
                 case 'content_item_link':
                     $this->set('core_content_menu_id_' . $menu->componentid, $menu->id);
                     break;
                 default:
                     if ($menu->componentid > 0 && strstr($menu->link, 'index.php?option=' . S2Paths::get('jreviews', 'S2_CMSCOMP'))) {
                         // It's a JReviews menu
                         $access = $this->cmsVersion == CMS_JOOMLA15 ? 0 : 1;
                         // Get a JReviews menu with public access to use in ajax requests
                         if ($menu->access == $access && $menu->published == 1) {
                             $this->set('jreviews_public', $menu->id);
                         }
                         $this->set('jr_menu_action_' . $m_dir_id, $m_action);
                         $this->set('menu_params_' . $menu->id, $params);
                         switch ($m_action) {
                             case '0':
                                 // Directory menu
                                 $this->set('jr_directory_menu_id_' . $m_dir_id, $menu->id);
                                 break;
                             case '1':
                                 // Section menu
                                 $this->set('jr_section_menu_id_' . $m_section_id, $menu->id);
                                 break;
                             case '2':
                                 // Category menu
                                 $this->set('jr_category_menu_id_' . $m_cat_id, $menu->id);
                                 break;
                             case '10':
                                 $this->set('jr_myreviews', $menu->id);
                                 break;
                             case '11':
                                 $m_criteria_id && $this->set('jr_advsearch_' . $m_criteria_id, $menu->id);
                                 !$m_criteria_id && $this->set('jr_advsearch', $menu->id);
                                 break;
                             case '12':
                                 $this->set('jr_mylistings', $menu->id);
                                 break;
                             case '18':
                                 $this->set('jr_reviewers', $menu->id);
                                 break;
                             default:
                                 $this->set('jr_menu_id_action_' . $m_action, $menu->id);
                                 break;
                         }
                     }
                     break;
             }
         }
         S2Cache::write($cache_file, array('___menu_data' => $this->___menu_data));
     }
     //        prx($this->___menu_data);exit;
 }
Beispiel #17
0
 function __construct()
 {
     parent::__construct();
     $menuList = array();
     switch (getCmsVersion()) {
         case CMS_JOOMLA15:
             $select = 'SELECT id,name,link AS menu_type,link,componentid,params,access,published';
             $type = "\n AND type = 'component'";
             $link = "\n AND ( \n                    link LIKE '%option=com_content&view=section%' OR\n                    link LIKE '%option=com_content&view=section&layout=blog%' OR\n                    link LIKE '%option=com_content&view=category\\%' OR\n                    link LIKE '%option=com_content&view=category&layout=blog%' OR\n                    link LIKE '%option=com_content&view=article%'                \n                )";
             break;
         case CMS_JOOMLA16:
             $select = "\n                    SELECT \n                        id, \n                        alias AS name,\n                        link AS menu_type,\n                        link,\n                        component_id AS componentid,\n                        params,\n                        access,\n                        published\n                ";
             $type = "\n AND type = 'component'";
             $link = "\n AND ( \n                    link LIKE '%option=com_content&view=section%' OR\n                    link LIKE '%option=com_content&view=section&layout=blog%' OR\n                    link LIKE '%option=com_content&view=category\\%' OR\n                    link LIKE '%option=com_content&view=category&layout=blog%' OR\n                    link LIKE '%option=com_content&view=article%'                \n                )";
             break;
     }
     // Get all com_content category/section menus and jReviews menus
     $sql = $select . "\n FROM #__menu" . "\n WHERE published = 1" . (getCmsVersion() == CMS_MAMBO46 ? "\n ORDER BY link ASC" : "\n ORDER BY link DESC");
     # Check for cached version
     $cache_prefix = 'menu_model';
     $cache_key = $sql;
     if ($cache = S2cacheRead($cache_prefix, $cache_key)) {
         $menuList = $cache;
     }
     if (empty($menuList)) {
         // Mambo4.6, as opposed to Mambo4.5, does not allow using other components Itemids so jReviews
         // Sections and category lists cannot use the section/category table or blog list menu Itemids
         $this->_db->setQuery($sql);
         $menuList = $this->_db->loadObjectList();
         # Send to cache
         S2cacheWrite($cache_prefix, $cache_key, $menuList);
     }
     // Get itemid for each menu link and store it
     if (is_array($menuList)) {
         foreach ($menuList as $menu) {
             $this->menues[$menu->id] = $menu;
             $params = stringToArray($menu->params);
             $paramsArray = explode("\n", $menu->params);
             if (Sanitize::getVar($params, 'sef_name') != '') {
                 $m_name = Sanitize::getVar($params, 'sef_name');
             } else {
                 $m_name = $menu->name;
             }
             if (function_exists("sefEncode")) {
                 $m_name = sefEncode($m_name);
             }
             $m_action = Sanitize::getVar($params, 'action');
             $m_dir_id = str_replace(",", "-", Sanitize::getVar($params, 'dirid'));
             $m_cat_id = str_replace(",", "-", Sanitize::getVar($params, 'catid'));
             $m_section_id = str_replace(",", "-", Sanitize::getVar($params, 'sectionid'));
             $m_criteria_id = str_replace(",", "-", Sanitize::getVar($params, 'criteriaid'));
             // Create a variable to get Menu Name from Itemid
             $this->set('jr_itemid_' . $menu->id, $m_name);
             $this->set('jr_menu_' . $m_name, $menu->id);
             # Fix for change in menu structure in J1.5
             if (getCmsVersion() == CMS_JOOMLA15) {
                 if (strpos($menu->menu_type, 'option=com_content&view=section&id=') || strpos($menu->menu_type, 'option=com_content&view=section&layout=blog&id=')) {
                     $menu->componentid = end(explode('id=', $menu->menu_type));
                     $menu->menu_type = 'content_section';
                 } elseif (strpos($menu->menu_type, 'option=com_content&view=category&id=') || strpos($menu->menu_type, 'option=com_content&view=category&layout=blog&id=')) {
                     $menu->componentid = end(explode('id=', $menu->menu_type));
                     $menu->menu_type = 'content_category';
                 } elseif (strpos($menu->menu_type, 'option=com_content&view=article&id=') || strpos($menu->menu_type, 'option=com_content&task=view&id=')) {
                     $menu->componentid = end(explode('id=', $menu->menu_type));
                     $menu->menu_type = 'content_item_link';
                 }
             }
             switch ($menu->menu_type) {
                 case 'content_section':
                 case 'content_blog_section':
                     if ($menu->componentid) {
                         // Only one section id
                         $this->set('core_section_menu_id_' . $menu->componentid, $menu->id);
                         //                                $this->set('jr_section_menu_id_'.$menu->componentid,$menu->id);
                     } else {
                         $section_ids = explode(",", Sanitize::getVar($params, 'sectionid'));
                         $this->set('jr_manyIds_' . $menu->id, 1);
                         foreach ($section_ids as $section_id) {
                             $this->set('core_section_menu_id_' . $section_id, $menu->id);
                             //                                    $this->set('jr_section_menu_id_'.$section_id,$menu->id);
                         }
                     }
                     break;
                 case 'content_category':
                 case 'content_blog_category':
                     if ($menu->componentid) {
                         // Only one category id
                         $this->set('core_category_menu_id_' . $menu->componentid, $menu->id);
                         //                            $this->set('jr_category_menu_id_'.$menu->componentid,$menu->id);
                     } else {
                         $cat_ids = explode(",", Sanitize::getVar($params, 'categoryid'));
                         $this->set('jr_manyIds_' . $menu->id, 1);
                         foreach ($cat_ids as $cat_id) {
                             $this->set('core_category_menu_id_' . $cat_id, $menu->id);
                             //                                    $this->set('jr_category_menu_id_'.$cat_id,$menu->id);
                         }
                     }
                     break;
                 case 'content_item_link':
                     $this->set('core_content_menu_id_' . $menu->componentid, $menu->id);
                     break;
                 default:
                     if ($menu->link == 'index.php?option=' . S2Paths::get('jreviews', 'S2_CMSCOMP')) {
                         // It's a jReviews menu
                         // Get a jReviews menu with public access to use in xajax requests
                         if ($menu->access == 0 && $menu->published == 1) {
                             $this->set('jreviews_public', $menu->id);
                         }
                         $menuParams = array();
                         foreach ($paramsArray as $parameter) {
                             $menuParams[current(explode('=', $parameter))] = end(explode('=', $parameter));
                         }
                         $this->set('jr_menu_action_' . $m_dir_id, $m_action);
                         $this->set('menu_params_' . $menu->id, $menuParams);
                         switch ($m_action) {
                             case '0':
                                 // Directory menu
                                 $this->set('jr_directory_menu_id_' . $m_dir_id, $menu->id);
                                 break;
                             case '1':
                                 // Section menu
                                 $this->set('jr_section_menu_id_' . $m_section_id, $menu->id);
                                 break;
                             case '2':
                                 // Category menu
                                 $this->set('jr_category_menu_id_' . $m_cat_id, $menu->id);
                                 break;
                             case '10':
                                 $this->set('jr_myreviews', $menu->id);
                                 break;
                             case '11':
                                 $m_criteria_id && $this->set('jr_advsearch_' . $m_criteria_id, $menu->id);
                                 !$m_criteria_id && $this->set('jr_advsearch', $menu->id);
                                 break;
                             case '12':
                                 $this->set('jr_mylistings', $menu->id);
                                 break;
                             case '18':
                                 $this->set('jr_reviewers', $menu->id);
                                 break;
                             default:
                                 $this->set('jr_menu_id_action_' . $m_action, $menu->id);
                                 break;
                         }
                     }
                     break;
             }
         }
     }
     //        prx($this->___menu_data);
 }
 function getPermissoes($inArray = false)
 {
     return $inArray ? stringToArray($this->Permissoes) : arrayToString($this->Permissoes);
 }
Beispiel #19
0
 /**
  * Creates the custom field group array with group info and fields values and attributes
  *
  * @param array $entries Entry array must have keys for entry id and criteriaid
  */
 function getFieldsArray($elements, $type = 'listing')
 {
     $fields = array();
     $field_pairs = array();
     $element_ids = array();
     $rows = array();
     $this->criteria_ids = array();
     // Alejandro = for discussion functionality
     //build entry_ids and criteria_ids array
     switch ($type) {
         case 'listing':
             foreach ($elements as $key => $element) {
                 if (isset($element['Criteria'])) {
                     $element_ids[] = $element[inflector::camelize($type)]['listing_id'];
                     if ($element['Criteria']['criteria_id'] != '') {
                         $this->criteria_ids[] = $element['Criteria']['criteria_id'];
                     }
                 }
             }
             break;
         case 'review':
             foreach ($elements as $element) {
                 if (isset($element['Criteria'])) {
                     $element_ids[] = $element[inflector::camelize($type)]['review_id'];
                     if ($element['Criteria']['criteria_id'] != '') {
                         $this->criteria_ids[] = $element['Criteria']['criteria_id'];
                     }
                 }
             }
             break;
     }
     $this->group_ids = $this->_criteria2Groups($this->criteria_ids, $type);
     $criteria_ids = implode(',', $this->criteria_ids);
     $element_ids = implode(',', array_unique($element_ids));
     if (empty($this->group_ids)) {
         return;
     }
     $group_ids = implode(',', $this->group_ids);
     $field_type = $type == 'listing' ? 'content' : $type;
     // Get field attributes and field values
     $query = "SELECT Field.fieldid AS `Field.field_id`, Field.groupid AS `Field.group_id`, Field.name AS `Field.name`, Field.title AS `Field.title`," . "\n Field.showtitle AS `Field.showTitle`, Field.description AS `Field.description`, Field.required AS `Field.required`," . "\n Field.type AS `Field.type`, Field.location AS `Field.location`, Field.options AS `Field.params`," . "\n Field.contentview AS `Field.contentView`, Field.listview AS `Field.listView`, Field.compareview AS `Field.compareView`, Field.listsort AS `Field.listSort`," . "\n Field.search AS `Field.search`, Field.access AS `Field.access`, Field.access_view AS `Field.accessView`," . "\n Field.published As `Field.published`," . "\n `Group`.groupid AS `Group.group_id`, `Group`.title AS `Group.title`, `Group`.name AS `Group.name`, `Group`.showtitle AS `Group.showTitle`" . "\n FROM #__jreviews_fields AS Field" . "\n INNER JOIN #__jreviews_groups AS `Group` ON (`Group`.groupid = Field.groupid AND " . "\n `Group`.groupid IN ({$group_ids}) AND `Group`.type =  '{$field_type}' )" . "\n WHERE Field.location = '{$field_type}' AND Field.published = 1" . "\n ORDER BY Group.ordering, Field.ordering";
     $this->_db->setQuery($query);
     $rows = $this->_db->loadObjectList('Field.name');
     if (!$rows || empty($rows)) {
         return;
     }
     # Extract list of field names from array
     $fieldNames = $optionFieldNames = $nonInputFieldNames = $fieldNamesByType = $fieldRows = array();
     $optionFields = array('selectmultiple', 'checkboxes', 'select', 'radiobuttons');
     $nonInputFields = array('banner');
     foreach ($rows as $key => $row) {
         // Exclude non-input fields, like banner, from forms
         if (!in_array($row->{'Field.type'}, $nonInputFields)) {
             $fieldNames[] = $row->{'Field.name'};
         } else {
             $row->{'Field.search'} = 0;
             $nonInputFieldNames[] = $row->{'Field.name'};
         }
         $fieldIds[$row->{'Field.name'}] = $row->{'Field.field_id'};
         $fieldRows[$key] = (array) $row;
         if (in_array($row->{'Field.type'}, $optionFields)) {
             $optionFieldNames[$row->{'Field.name'}] = $row->{'Field.field_id'};
             // Used to find the option text for each option value
         }
     }
     # Get field values from current element ids
     switch ($type) {
         case 'listing':
             # PaidListings integration
             if (Configure::read('ListingEdit') && Configure::read('PaidListings.enabled') && is_int($element_ids)) {
                 // Load the paid_listing_fields table instead of the jos_content table so users can see all their
                 // fields when editing a listing
                 Configure::write('ListingEdit', false);
                 $fieldValues = PaidListingFieldModel::edit($element_ids);
                 if ($fieldValues) {
                     break;
                 }
             }
             $query = "SELECT Listing.contentid AS element_id," . implode(',', $fieldNames) . "\n FROM #__jreviews_content AS Listing" . "\n WHERE Listing.contentid IN (" . $element_ids . ")";
             $this->_db->setQuery($query);
             $fieldValues = $this->_db->loadObjectList('element_id');
             break;
         case 'review':
             $query = "SELECT Review.reviewid AS element_id," . implode(',', $fieldNames) . "\n FROM #__jreviews_review_fields AS Review" . "\n WHERE Review.reviewid IN (" . $element_ids . ")";
             $this->_db->setQuery($query);
             $fieldValues = $this->_db->loadObjectList('element_id');
             break;
     }
     //prx($optionFieldNames);
     //prx($fieldValues);
     # Now for each option field add array of selected value,text,images
     $elementFields = array();
     $relatedListingIds = array();
     if (!empty($fieldValues)) {
         foreach ($fieldValues as $fieldValue) {
             $fieldValue = array_filter((array) $fieldValue);
             $fieldOptionValuesTemp = array_intersect_key($fieldValue, $optionFieldNames);
             foreach ($fieldOptionValuesTemp as $fname => $optionval) {
                 $values = !is_array($optionval) ? explode('*', $optionval) : $optionval;
                 foreach ($values as $optionval) {
                     if ($optionval != '') {
                         $fieldOptionValuesToSearch[] = $optionval;
                         $fieldOptionFieldIdsToSearch[$optionFieldNames[$fname]] = $optionFieldNames[$fname];
                     }
                 }
             }
         }
         if (!empty($fieldOptionValuesToSearch)) {
             $query = "\n                    SELECT \n                        * \n                    FROM \n                        #__jreviews_fieldoptions\n                    WHERE \n                        fieldid IN ( " . $this->Quote($fieldOptionFieldIdsToSearch) . ")\n                        AND\n                        value IN ( " . $this->Quote($fieldOptionValuesToSearch) . ")\n                    ORDER \n                        BY ordering ASC ,optionid ASC\n                ";
             $this->_db->setQuery($query);
             $SelectedFieldOptionsArray = $this->_db->loadObjectList('optionid');
             # Reformat array, group by field id
             $SelelectedFieldOptionsByValue = array();
             foreach ($SelectedFieldOptionsArray as $option) {
                 $SelelectedFieldOptionsByValue[$option->fieldid][$option->value] = (array) $option;
             }
         }
         //prx($nonInputFieldNames);
         $fnameArray = array_keys($rows);
         foreach ($fieldValues as $fieldValue) {
             $fieldValue = (array) $fieldValue;
             $fieldvalue = $this->sortArrayByArray($fieldValue, $fnameArray);
             foreach ($fnameArray as $key) {
                 $value = '';
                 if (isset($fieldValue[$key])) {
                     $value = $fieldValue[$key];
                 } elseif (in_array($key, $nonInputFieldNames)) {
                     $value = 'banner';
                 }
                 if ($key != 'element_id' && $value != '' && isset($rows[$key])) {
                     $properties = stringToArray($rows[$key]->{'Field.params'});
                     // Process related listing fields. Need to get listing info to build the url
                     if ($rows[$key]->{'Field.type'} == 'relatedlisting') {
                         if ($value == 0) {
                             continue;
                         }
                         $relatedListingIds[] = $value;
                     }
                     // Strip html from fields except those where it is allowed
                     if (!is_array($value) && (!in_array($rows[$key]->{'Field.type'}, array('text', 'textarea', 'code')) || in_array($rows[$key]->{'Field.type'}, array('text', 'textarea')) && Sanitize::getBool($properties, 'allow_html') == false)) {
                         $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
                     }
                     if ($rows[$key]->{'Field.type'} != 'date' || $rows[$key]->{'Field.type'} == 'date' && $value != NULL_DATE) {
                         $elementFields[$fieldValue['element_id']]['field_id'] = $fieldRows[$key]['Field.field_id'];
                         if (!in_array($rows[$key]->{'Field.type'}, $optionFields)) {
                             $elementFields[$fieldValue['element_id']][$key]['Field.text'][] = $value;
                             $elementFields[$fieldValue['element_id']][$key]['Field.value'][] = $value;
                             $elementFields[$fieldValue['element_id']][$key]['Field.image'][] = '';
                         } elseif (in_array($rows[$key]->{'Field.type'}, $optionFields)) {
                             $fieldOptions = Sanitize::getVar($SelelectedFieldOptionsByValue, $rows[$key]->{'Field.field_id'});
                             $selOptions = !is_array($value) ? explode('*', $value) : $value;
                             foreach ($selOptions as $selOption) {
                                 if ($selOption != '' && isset($fieldOptions[$selOption])) {
                                     $elementFields[$fieldValue['element_id']][$key]['Field.value'][] = $fieldOptions[$selOption]['value'];
                                     $elementFields[$fieldValue['element_id']][$key]['Field.text'][] = $fieldOptions[$selOption]['text'];
                                     $elementFields[$fieldValue['element_id']][$key]['Field.image'][] = $fieldOptions[$selOption]['image'];
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $relatedListings = $this->getRelatedListings($relatedListingIds);
     // Reformat array so array keys match element ids
     foreach ($elementFields as $key => $elementField) {
         $element_id = $key;
         $field_id = $elementField['field_id'];
         unset($elementField['field_id']);
         $field_name = key($elementField);
         foreach ($elementField as $field_name => $field_options) {
             //FieldGroups array
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['group_id'] = $fieldRows[$field_name]['Field.group_id'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['title'] = $fieldRows[$field_name]['Group.title'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['name'] = $fieldRows[$field_name]['Group.name'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Group']['show_title'] = $fieldRows[$field_name]['Group.showTitle'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['id'] = $field_id;
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['group_id'] = $fieldRows[$field_name]['Field.group_id'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['name'] = $fieldRows[$field_name]['Field.name'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['type'] = $fieldRows[$field_name]['Field.type'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['title'] = $fieldRows[$field_name]['Field.title'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['description'] = $fieldRows[$field_name]['Field.description'];
             // Field values
             //                prx($field_options);exit;
             if ($fieldRows[$field_name]['Field.type'] == 'relatedlisting') {
                 $value = isset($relatedListings[$field_options['Field.value'][0]]) ? array($relatedListings[$field_options['Field.value'][0]]['value']) : '';
                 $real_value = $field_options['Field.value'];
                 $text = isset($relatedListings[$field_options['Field.text'][0]]) ? array($relatedListings[$field_options['Field.value'][0]]['text']) : '';
                 $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['value'] = $value;
                 $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['text'] = $text;
                 $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['real_value'] = $field_options['Field.text'];
             } else {
                 $value = $field_options['Field.value'];
                 $text = $field_options['Field.text'];
                 $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['value'] = $value;
                 $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['text'] = $text;
             }
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['image'] = $field_options['Field.image'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['show_title'] = $fieldRows[$field_name]['Field.showTitle'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['location'] = $fieldRows[$field_name]['Field.location'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['contentview'] = $fieldRows[$field_name]['Field.contentView'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['listview'] = $fieldRows[$field_name]['Field.listView'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['compareview'] = $fieldRows[$field_name]['Field.compareView'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['listsort'] = $fieldRows[$field_name]['Field.listSort'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['search'] = $fieldRows[$field_name]['Field.search'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['access'] = $fieldRows[$field_name]['Field.access'];
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties']['access_view'] = $fieldRows[$field_name]['Field.accessView'];
             //FieldPairs associative array with field name as key and field value as value
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['field_id'] = $element_id;
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_id'] = $fieldRows[$field_name]['Field.group_id'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_show_title'] = $fieldRows[$field_name]['Group.showTitle'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_title'] = $fieldRows[$field_name]['Group.title'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['group_name'] = $fieldRows[$field_name]['Group.name'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['name'] = $fieldRows[$field_name]['Field.name'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['title'] = $fieldRows[$field_name]['Field.title'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['value'] = $value;
             isset($real_value) and $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['real_value'] = $real_value;
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['text'] = $text;
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['image'] = $field_options['Field.image'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['type'] = $fieldRows[$field_name]['Field.type'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['description'] = $fieldRows[$field_name]['Field.description'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['show_title'] = $fieldRows[$field_name]['Field.showTitle'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['location'] = $fieldRows[$field_name]['Field.location'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['contentview'] = $fieldRows[$field_name]['Field.contentView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['listview'] = $fieldRows[$field_name]['Field.listView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['compareview'] = $fieldRows[$field_name]['Field.compareView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['listsort'] = $fieldRows[$field_name]['Field.listSort'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['search'] = $fieldRows[$field_name]['Field.search'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['access'] = $fieldRows[$field_name]['Field.access'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['access_view'] = $fieldRows[$field_name]['Field.accessView'];
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties']['access_view'] = $fieldRows[$field_name]['Field.accessView'];
             $properties = stringToArray($fieldRows[$field_name]['Field.params']);
             $fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties'] = array_merge($fields[$element_id][$fieldRows[$field_name]['Group.name']]['Fields'][$fieldRows[$field_name]['Field.name']]['properties'], $properties);
             $field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties'] = array_merge($field_pairs[$element_id][$fieldRows[$field_name]['Field.name']]['properties'], $properties);
             //$params = explode("\n",$fieldRows[$field_name]['Field.params']);
         }
     }
     $this->custom_fields = $fields;
     $this->field_pairs = $field_pairs;
 }
 function getAdvancedOptions($type, $fieldid, $location)
 {
     $this->name = 'fields';
     $this->action = 'advanced_options';
     $fieldParams = array();
     $script = '';
     if ($fieldid) {
         $field = $this->Field->findRow(array('conditions' => array('fieldid = ' . $fieldid)));
         $fieldParams = stringToArray($field['Field']['options']);
     }
     # Preselect list/radio values based on current settings
     switch ($type) {
         case 'integer':
         case 'decimal':
             $script = "jQuery('#curr_format').val(" . Sanitize::getVar($fieldParams, 'curr_format', 1) . ");";
             break;
         case 'select':
         case 'selectmultiple':
         case 'radiobuttons':
         case 'checkboxes':
             $script = "jQuery('#options_ordering').val(" . Sanitize::getVar($fieldParams, 'option_ordering', 0) . ");";
             break;
         case 'textarea':
         case 'text':
             $script = "jQuery('#allow_html').val(" . Sanitize::getVar($fieldParams, 'allow_html', 0) . ");";
             break;
     }
     if (Sanitize::getVar($fieldParams, 'output_format') == '' && !in_array($type, array('website', 'relatedlisting'))) {
         $fieldParams['output_format'] = "{FIELDTEXT}";
     } else {
         $fieldParams['output_format'] = Sanitize::getVar($fieldParams, 'output_format');
     }
     $fieldParams['valid_regex'] = !Sanitize::getVar($fieldParams, 'valid_regex', 0) ? '' : Sanitize::getVar($fieldParams, 'valid_regex');
     $fieldParams['date_setup'] = trim(br2nl(stripslashes(Sanitize::getVar($fieldParams, 'date_setup'))));
     $paramArray = array('valid_regex', 'allow_html', 'click2searchlink', 'output_format', 'click2search', 'click2add', 'date_format', 'option_images', 'listing_type');
     $params = new stdClass();
     foreach ($paramArray as $paramKey) {
         $params->{$paramKey} = '';
     }
     foreach ($fieldParams as $paramKey => $paramValue) {
         $params->{$paramKey} = $paramValue;
     }
     $this->set(array('type' => $type, 'location' => $location, 'params' => $params, 'field_params' => $fieldParams));
     switch ($type) {
         case 'text':
         case 'textarea':
         case 'code':
             $script .= 'jQuery("#valid_regex").val("");';
             break;
         case 'email':
             $script .= 'jQuery("#valid_regex").val(".+@.*");';
             break;
         case 'website':
             $script .= 'jQuery("#valid_regex").val("^((ftp|http|https)+(:\\/\\/)+[a-z0-9_-]+\\.+[a-z0-9_-]|[a-z0-9_-]+\\.+[a-z0-9_-])");';
             break;
     }
     $output = $this->render();
     return array('page' => $output, 'type' => $type, 'location' => $location, 'demo' => (int) defined('_JREVIEWS_DEMO'), 'params' => $fieldParams, 'response' => $this->makeJS($script));
 }
 /**
  * Returns a json object of field options used to dynamicaly show and populate dependent fields
  *         
  */
 function _loadFieldData($json = true, $_data = array())
 {
     !empty($_data) and $this->data = $_data;
     $fields = $field_options = $selected_values = $group_ids = array();
     $selected_values_autocomplete = array();
     $dependent_fields = $dependent_groups = $control_fields = $fields = $responses = array();
     $location = strtolower(Sanitize::getString($this->data, 'fieldLocation', 'content'));
     $location == 'listing' and $location = 'content';
     $recursive = Sanitize::getBool($this->data, 'recursive');
     $field_names = Sanitize::getVar($this->data, 'fields');
     $control_field = $field_names = is_array($field_names) ? array_filter($field_names) : array($field_names);
     $page_setup = Sanitize::getInt($this->data, 'page_setup', false);
     $control_value = Sanitize::getVar($this->data, 'value');
     $entry_id = Sanitize::getInt($this->data, 'entry_id');
     $referrer = Sanitize::getString($this->data, 'referrer');
     $edit = (bool) $entry_id || is_array($control_value);
     // In adv. search module we make it work like edit for previously searched values which are passed as an array in $control_value
     # Access check
     # Need to pass token to validate the listing id and check user access.
     # Filter passed field names to fix those with double underscores which are checkboxes and radiobuttons
     foreach ($field_names as $key => $name) {
         if (substr_count($name, '_') > 1) {
             $tmp = explode('_', $name);
             array_pop($tmp);
             $field_names[$key] = implode('_', $tmp);
         }
     }
     $field_names = array_unique($field_names);
     /** 
      * We are in edit mode. Find selected values
      */
     if ($page_setup && $entry_id > 0) {
         # PaidListings integration
         if ($location == 'content' && Configure::read('PaidListings.enabled') && PaidPlanCategoryModel::isInPaidCategoryByListingId($entry_id)) {
             // Load the paid_listing_fields table instead of the jos_content table so users can see all their
             // fields when editing a listing
             Configure::write('ListingEdit', false);
             $curr_field_values = PaidListingFieldModel::edit($entry_id);
             if ($curr_field_values && !empty($curr_field_values)) {
                 $curr_field_values = (array) array_shift($curr_field_values);
                 $curr_field_values['contentid'] = $curr_field_values['element_id'];
                 unset($curr_field_values['element_id'], $curr_field_values['email']);
             }
         }
         if (empty($curr_field_values)) {
             $query = $location == 'content' ? "SELECT * FROM #__jreviews_content WHERE contentid = {$entry_id}" : "SELECT * FROM #__jreviews_review_fields WHERE reviewid = {$entry_id}";
             $this->_db->setQuery($query);
             $curr_field_values = array_shift($this->_db->loadAssocList());
         }
         if (!empty($curr_field_values)) {
             foreach ($curr_field_values as $key => $val) {
                 if (substr($key, 0, 3) == 'jr_') {
                     $selected_values[$key] = $val != '' ? is_array($val) ? $val : array($val) : array();
                 }
             }
         }
     } elseif (is_array($control_value)) {
         $selected_values = $control_value;
         $control_value = '';
     }
     /****************************************************************************************
      *  Control field option selected, so we find all dependent fields and groups
      *  Need to look in FieldOptions, Fields and FieldGroups
      ****************************************************************************************/
     if (!$page_setup) {
         # Find dependent FieldOptions
         $query = "\r\n                SELECT \r\n                    DISTINCT Field.name\r\n                FROM \r\n                    #__jreviews_fieldoptions AS FieldOption\r\n                LEFT JOIN\r\n                    #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid AND (\r\n                        Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n                    )\r\n                LEFT JOIN\r\n                    #__jreviews_groups AS FieldGroup ON Field.groupid = FieldGroup.groupid\r\n                WHERE\r\n                    Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n                    AND FieldOption.control_field = " . $this->quote($control_field) . " AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') . "\r\n                ORDER BY \r\n                    FieldGroup.ordering, Field.ordering \r\n            ";
         $this->_db->setQuery($query);
         $field_names = $this->_db->loadResultArray();
         # Find dependent Fields
         $query = "\r\n                SELECT \r\n                    DISTINCT Field.name\r\n                FROM \r\n                    #__jreviews_fields AS Field\r\n                LEFT JOIN\r\n                    #__jreviews_groups AS FieldGroup ON Field.groupid = FieldGroup.groupid\r\n                WHERE\r\n                    Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n                    AND Field.control_field = " . $this->quote($control_field) . " AND Field.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') . "\r\n                ORDER BY \r\n                    FieldGroup.ordering, Field.ordering \r\n            ";
         $this->_db->setQuery($query);
         $field_names = is_array($field_names) ? array_merge($field_names, $this->_db->loadResultArray()) : $this->_db->loadResultArray();
         # Find depedent Field Groups
         $query = "\r\n                SELECT DISTINCT\r\n                   FieldGroup.groupid\r\n                FROM \r\n                    #__jreviews_groups AS FieldGroup\r\n                LEFT JOIN\r\n                    #__jreviews_fields AS Field ON Field.groupid = FieldGroup.groupid\r\n                WHERE\r\n                    Field.published = 1 AND Field.location = " . $this->quote($location) . "  \r\n                    AND FieldGroup.type = " . $this->quote($location) . "\r\n                    AND FieldGroup.control_field = " . $this->quote($control_field) . "\r\n                    AND FieldGroup.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') . "\r\n                ORDER BY\r\n                    FieldGroup.ordering\r\n           ";
         $this->_db->setQuery($query);
         $group_ids = $this->_db->loadResultArray();
         !empty($field_names) and $field_names = array_unique($field_names);
         if (empty($field_names) && empty($group_ids)) {
             return json_encode(compact('control_field', 'dependent_fields', 'dependent_groups', 'data'));
         }
     }
     # Get info for all fields
     $query = "\r\n            SELECT \r\n                Field.fieldid, Field.groupid, Field.title, Field.name, Field.type, Field.options, Field.control_field, Field.control_value, FieldGroup.name AS group_name\r\n            FROM \r\n                #__jreviews_fields AS Field \r\n            LEFT JOIN\r\n                #__jreviews_groups AS FieldGroup ON Field.groupid = FieldGroup.groupid\r\n            WHERE \r\n                Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n                AND (\r\n                    " . (!empty($field_names) ? "Field.name IN (" . $this->quote($field_names) . ")" : '') . "\r\n                    " . (!empty($field_names) && !empty($group_ids) ? " OR " : '') . "\r\n                    " . (!empty($group_ids) ? "Field.groupid IN (" . $this->quote($group_ids) . ")" : '') . "\r\n                )\r\n            ORDER BY \r\n                FieldGroup.ordering, Field.ordering\r\n        ";
     $this->_db->setQuery($query);
     $curr_form_fields = $this->_db->loadAssocList('name');
     if (empty($curr_form_fields)) {
         return json_encode(compact('control_field', 'dependent_fields', 'dependent_groups', 'data'));
     }
     foreach ($curr_form_fields as $key => $curr_form_field) {
         $curr_form_fields[$key]['options'] = stringToArray($curr_form_field['options']);
     }
     /****************************************************************************************
      *  Check if fields have any dependents to avoid unnecessary ajax requests 
      *  Three tables need to be checked: fieldoptions, fields, and fieldgroups
      ****************************************************************************************/
     # FieldOptions
     $query = "\r\n            SELECT DISTINCT     \r\n                Field.name AS dependent_field, FieldOption.control_field\r\n            FROM \r\n                #__jreviews_fieldoptions AS FieldOption\r\n            LEFT JOIN\r\n                #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n            WHERE\r\n                Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n                AND FieldOption.control_field IN ( " . $this->quote($page_setup ? array_keys($curr_form_fields) : $control_field) . ")\r\n            " . (!$page_setup ? "AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') : '') . "\r\n            ORDER BY Field.ordering\r\n       ";
     $this->_db->setQuery($query);
     $controlling_and_dependent_fields = $this->_db->loadAssocList();
     # Fields
     $query = "\r\n            SELECT DISTINCT\r\n                Field.name AS dependent_field, Field.control_field\r\n            FROM \r\n                #__jreviews_fields AS Field\r\n            WHERE\r\n                Field.published = 1 AND Field.location = " . $this->quote($location) . "\r\n                AND Field.control_field IN ( " . $this->quote($page_setup ? array_keys($curr_form_fields) : $control_field) . ")\r\n            " . (!$page_setup ? "AND Field.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') : '') . "\r\n            ORDER BY Field.ordering\r\n       ";
     $this->_db->setQuery($query);
     $controlling_and_dependent_fields = is_array($controlling_and_dependent_fields) ? array_merge($controlling_and_dependent_fields, $this->_db->loadAssocList()) : $this->_db->loadAssocList();
     # Groups
     $query = "\r\n            SELECT DISTINCT\r\n               FieldGroup.name AS dependent_group, FieldGroup.control_field\r\n            FROM \r\n                #__jreviews_groups AS FieldGroup\r\n            LEFT JOIN\r\n                #__jreviews_fields AS Field ON Field.groupid = FieldGroup.groupid\r\n            WHERE\r\n                Field.published = 1 AND Field.location = " . $this->quote($location) . "  \r\n                AND FieldGroup.type = " . $this->quote($location) . "\r\n                AND FieldGroup.control_field IN ( " . $this->quote($page_setup ? array_keys($curr_form_fields) : $control_field) . ")\r\n            " . (!$page_setup ? "AND FieldGroup.control_value LIKE " . $this->quoteLike('*' . $control_value . '*') : '') . "\r\n            ORDER BY\r\n                FieldGroup.ordering\r\n       ";
     $this->_db->setQuery($query);
     $controlling_and_dependent_fields = is_array($controlling_and_dependent_fields) ? array_merge($controlling_and_dependent_fields, $this->_db->loadAssocList()) : $this->_db->loadAssocList();
     #Extract controlling and dependent fields
     foreach ($controlling_and_dependent_fields as $row) {
         isset($row['dependent_field']) and $dependent_fields[$row['dependent_field']] = $row['dependent_field'];
         if (isset($row['dependent_group'])) {
             $group_name = str_replace(' ', '', $row['dependent_group']);
             $dependent_groups[$group_name] = $group_name;
         }
         $control_fields[$row['control_field']] = $row['control_field'];
     }
     $ids_to_names = $ids_to_names_autocomplete = $ids_to_names_noautocomplete = array();
     $control_fields_array = array();
     foreach ($curr_form_fields as $curr_form_field) {
         $ordering = Sanitize::getVar($curr_form_field['options'], 'option_ordering', null);
         $fields[$curr_form_field['name']]['name'] = $curr_form_field['name'];
         $fields[$curr_form_field['name']]['type'] = $curr_form_field['type'];
         $fields[$curr_form_field['name']]['group'] = $curr_form_field['group_name'];
         $fields[$curr_form_field['name']]['autocomplete'] = Sanitize::getVar($curr_form_field['options'], in_array($referrer, array('adv_search', 'adv_search_module')) ? 'autocomplete.search' : 'autocomplete', 0);
         $fields[$curr_form_field['name']]['autocompletetype'] = Sanitize::getVar($curr_form_field['options'], 'autocomplete.option_type', 'link');
         $fields[$curr_form_field['name']]['autocompletepos'] = Sanitize::getVar($curr_form_field['options'], 'autocomplete.option_pos', 'after');
         $fields[$curr_form_field['name']]['title'] = $curr_form_field['title'];
         $entry_id and $fields[$curr_form_field['name']]['selected'] = array();
         !is_null($ordering) and $fields[$curr_form_field['name']]['order_by'] = !$ordering ? 'ordering' : 'text';
         // Add selected value for text fields
         if (isset($selected_values[$curr_form_field['name']])) {
             switch ($fields[$curr_form_field['name']]['type']) {
                 case 'date':
                     if (isset($selected_values[$curr_form_field['name']][0])) {
                         if ($selected_values[$curr_form_field['name']][0] == NULL_DATE) {
                             $fields[$curr_form_field['name']]['selected'] = array();
                         } else {
                             $fields[$curr_form_field['name']]['selected'] = array(str_replace(" 00:00:00", "", $selected_values[$curr_form_field['name']][0]));
                         }
                     }
                     break;
                 case 'relatedlisting':
                     if (isset($selected_values[$curr_form_field['name']][0]) && $selected_values[$curr_form_field['name']][0] > 0) {
                         $fields[$curr_form_field['name']]['selected'] = $selected_values[$curr_form_field['name']];
                     }
                     break;
                 case 'radiobuttons':
                 case 'select':
                 case 'checkboxes':
                 case 'selectmultiple':
                     if (!empty($selected_values[$curr_form_field['name']])) {
                         $selected_values[$curr_form_field['name']] = explode('*', ltrim(rtrim($selected_values[$curr_form_field['name']][0], '*'), '*'));
                         $fields[$curr_form_field['name']]['selected'] = $selected_values[$curr_form_field['name']];
                     }
                     break;
                 default:
                     $fields[$curr_form_field['name']]['selected'] = $selected_values[$curr_form_field['name']];
                     break;
             }
         }
         // Add control related vars
         // If field is text type, then it has no control and we check the controlBy values
         if ($fields[$curr_form_field['name']]['type'] == 'text') {
             $fields[$curr_form_field['name']]['control'] = false;
             $fields[$curr_form_field['name']]['controlled'] = $curr_form_field['control_field'] != '' && $curr_form_field['control_value'];
         } else {
             $fields[$curr_form_field['name']]['control'] = $recursive ? true : in_array($curr_form_field['name'], $control_fields);
             $fields[$curr_form_field['name']]['controlled'] = in_array($curr_form_field['name'], $dependent_fields);
         }
         if (in_array($curr_form_field['groupid'], $group_ids)) {
             $fields[$curr_form_field['name']]['controlgroup'] = true;
         }
         // Create an array of field ids to field names used below to save on additional queries.
         // The initial field option values are loaded for the fields in this array
         if (!$page_setup || !$fields[$curr_form_field['name']]['autocomplete'] || !empty($fields[$curr_form_field['name']]['selected'])) {
             if (in_array($fields[$curr_form_field['name']]['type'], array('select', 'selectmultiple'))) {
                 $ids_to_names[$curr_form_field['fieldid']] = $curr_form_field['name'];
             }
             if (!empty($fields[$curr_form_field['name']]['selected']) && $fields[$curr_form_field['name']]['autocomplete'] && in_array($fields[$curr_form_field['name']]['type'], array('select', 'selectmultiple'))) {
                 $ids_to_names_autocomplete[$curr_form_field['fieldid']] = $curr_form_field['name'];
                 $selected_values_autocomplete = array_merge($selected_values_autocomplete, $selected_values[$curr_form_field['name']]);
             } elseif (!$fields[$curr_form_field['name']]['autocomplete'] && in_array($fields[$curr_form_field['name']]['type'], array('select', 'selectmultiple'))) {
                 $ids_to_names_noautocomplete[$curr_form_field['fieldid']] = $curr_form_field['name'];
             }
         }
         $control_fields_array[] = $curr_form_field['name'];
     }
     //prx($ids_to_names);
     //prx($ids_to_names_autocomplete);
     //prx($ids_to_names_noautocomplete);
     //prx('------------------BEGIN-------------------');
     //prx($recursive);
     //prx($curr_form_fields);
     //prx($fields);
     //prx($control_fields);
     //prx('------------------END-------------------');
     /****************************************************************************************
      * Build the fields array for control and controlled fields 
      ****************************************************************************************/
     # For FieldOption-FieldOption relationships get field options ordered by a-z ASC to start building the fields array.
     if (!empty($ids_to_names)) {
         if ($edit) {
             if (!empty($ids_to_names_autocomplete)) {
                 $query = "\r\n                        SELECT \r\n                            Field.name, Field.fieldid, FieldOption.optionid, FieldOption.text, FieldOption.value, FieldOption.image, FieldOption.ordering\r\n                        FROM \r\n                            #__jreviews_fieldoptions AS FieldOption\r\n                        LEFT JOIN\r\n                            #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n                        WHERE\r\n                            Field.published = 1 AND Field.location = " . $this->quote($location) . "  \r\n                            AND " . ($page_setup ? " FieldOption.fieldid IN (" . $this->quote(array_keys($ids_to_names_autocomplete)) . ") " : '1 = 1') . " \r\n                            " . ($page_setup ? " AND FieldOption.control_field = ''" : " AND FieldOption.control_field = " . $this->quote($control_field) . " AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*')) . " \r\n                            " . (!empty($selected_values_autocomplete) ? "AND FieldOption.value IN ( " . $this->quote($selected_values_autocomplete) . ")" : '') . "\r\n                        ORDER BY \r\n                            FieldOption.fieldid, FieldOption.text\r\n                    ";
                 $this->_db->setQuery($query);
                 $field_options_ac = $this->_db->loadAssocList();
             }
             if (!empty($ids_to_names_noautocomplete)) {
                 $query = "\r\n                        SELECT \r\n                            Field.name, Field.fieldid, FieldOption.optionid, FieldOption.text, FieldOption.value, FieldOption.image, FieldOption.ordering\r\n                        FROM \r\n                            #__jreviews_fieldoptions AS FieldOption\r\n                        LEFT JOIN\r\n                            #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n                        WHERE\r\n                            Field.published = 1 AND Field.location = " . $this->quote($location) . "  \r\n                            AND " . ($page_setup ? " FieldOption.fieldid IN (" . $this->quote(array_keys($ids_to_names_noautocomplete)) . ") " : '1 = 1') . " \r\n                            " . ($page_setup ? " AND FieldOption.control_field = ''" : " AND FieldOption.control_field = " . $this->quote($control_field) . " AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*')) . " \r\n                        ORDER BY \r\n                            FieldOption.fieldid, FieldOption.text\r\n                    ";
                 $this->_db->setQuery($query);
                 $field_options_noac = $this->_db->loadAssocList();
             }
             empty($field_options_ac) and $field_options_ac = array();
             empty($field_options_noac) and $field_options_noac = array();
             $field_options = array_merge($field_options_ac, $field_options_noac);
         } else {
             $query = "\r\n                    SELECT \r\n                        Field.name, Field.fieldid, FieldOption.optionid, FieldOption.text, FieldOption.value, FieldOption.image, FieldOption.ordering\r\n                    FROM \r\n                        #__jreviews_fieldoptions AS FieldOption\r\n                    LEFT JOIN\r\n                        #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n                    WHERE\r\n                        Field.published = 1 AND Field.location = " . $this->quote($location) . "  \r\n                        AND " . ($page_setup ? " FieldOption.fieldid IN (" . $this->quote(array_keys($ids_to_names)) . ") " : '1 = 1') . " \r\n                        " . ($page_setup ? " AND FieldOption.control_field = ''" : " AND FieldOption.control_field = " . $this->quote($control_field) . " AND FieldOption.control_value LIKE " . $this->quoteLike('*' . $control_value . '*')) . " \r\n                    ORDER BY \r\n                        FieldOption.fieldid, FieldOption.text\r\n                ";
             $this->_db->setQuery($query);
             $field_options = $this->_db->loadAssocList();
         }
     }
     # For FieldOption-Field relationships get field options ordered by a-z ASC to start building the fields array.
     if (!$page_setup && !empty($ids_to_names)) {
         $query = "\r\n                SELECT \r\n                    Field.name, Field.fieldid, FieldOption.optionid, FieldOption.text, FieldOption.value, FieldOption.image, FieldOption.ordering\r\n                FROM \r\n                    #__jreviews_fieldoptions AS FieldOption\r\n                LEFT JOIN\r\n                    #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid\r\n                WHERE\r\n                    Field.published = 1 AND Field.location = " . $this->quote($location) . "  \r\n                    AND " . ($page_setup ? " FieldOption.fieldid IN (" . $this->quote(array_keys($ids_to_names)) . ") " : '1 = 1') . " \r\n                    " . ($page_setup ? " AND Field.control_field = ''" : " AND Field.control_field = " . $this->quote($control_field) . " AND Field.control_value LIKE " . $this->quoteLike('*' . $control_value . '*')) . " \r\n                ORDER BY \r\n                    FieldOption.fieldid, FieldOption.text\r\n            ";
         $this->_db->setQuery($query);
         $field_options = array_merge($field_options, $this->_db->loadAssocList());
     }
     foreach ($field_options as $field_option) {
         $field_id = $field_option['fieldid'];
         $field_name = $field_option['name'];
         unset($field_option['fieldid'], $field_option['name']);
         if (isset($ids_to_names[$field_id])) {
             $fields[$ids_to_names[$field_id]]['options'][] = $field_option;
             isset($selected_values[$field_name]) and $fields[$ids_to_names[$field_id]]['selected'] = $selected_values[$field_name];
         }
     }
     if ($page_setup) {
         $control_field = array_values($control_fields_array);
         $dependent_fields = array();
     } else {
         $control_field = $control_field;
         $dependent_fields = array_values($dependent_fields);
     }
     # Edit mode: for each control field that has a selected value find dependent field options
     foreach ($selected_values as $key => $val) {
         if (!empty($val) && $val != '' && in_array($key, $field_names)) {
             foreach ($val as $selected) {
                 $res = $this->_loadFieldData(false, array('recursive' => true, 'fields' => $key, 'value' => array_shift($val), 'fieldLocation' => $location));
                 if (is_array($res)) {
                     $responses[$res['control_field'][0]][$res['control_value']] = $res;
                     foreach ($res['fields'] as $res_fields) {
                         if (isset($selected_values[$res_fields['name']]) && !empty($res_fields['options']) && empty($fields[$res_fields['name']]['options'])) {
                             $fields[$res_fields['name']] = $res_fields;
                             $fields[$res_fields['name']]['selected'] = $selected_values[$res_fields['name']];
                         }
                     }
                 } elseif ($fields[$key]['type'] != 'text') {
                     $responses[$key][$selected] = array('location' => $location, 'control_field' => array($key), 'control_value' => $selected, 'dependent_groups' => array(), 'dependent_fields' => array(), 'fields' => array());
                 }
             }
         }
     }
     /** DEBUG **/
     //if($json) {prx(compact('page_setup','control_field','control_value','dependent_fields','dependent_groups','fields','responses'));}
     //if($json && !$page_setup) {prx(compact('page_setup','control_field','control_value','dependent_fields','dependent_groups','fields','responses'));}
     $dependent_groups = array_values($dependent_groups);
     $location = $location == 'content' ? 'Listing' : 'Review';
     return $json ? json_encode(compact('page_setup', 'edit', 'location', 'control_field', 'control_value', 'dependent_groups', 'dependent_fields', 'fields', 'responses')) : compact('location', 'control_field', 'control_value', 'dependent_groups', 'dependent_fields', 'fields');
 }
Beispiel #22
0
function hellman($a)
{
    echo shell_exec('clear');
    echo "\n                Bonjour, mon nom est Bernard, je suis la pour crypter votre message.\n\n                Vous etes Alice, et votre but est de m'envoyer une clé publique pour que je puisse chiffrer mon message ...\n\n                D'abord, vous devez créer une clé privée, celle ci doit etre une suite super-croissante :\n\n                Alice : ";
    while (true) {
        // bernard : votre private key
        $pKey = readline($a);
        $private_key = stringToArray($pKey);
        if (!super_croissance_check($private_key)) {
            echo "\n                Veuillez entrer une suite super croissante\n";
            $pKey = readline($a);
            $private_key = stringToArray($pKey);
            if (!super_croissance_check($private_key)) {
                echo "\n                Vas t'acheter des doigts !\n";
                exit;
            }
        }
        // sleep(1);
        echo "\n                Hum... c'est bien une suite supercroissante.\n";
        //  bernard :      votre mod
        echo "\n                Maintenant, un modulo :\n\n                Alice : ";
        $mod = readline($a);
        if (!is_numeric($mod)) {
            echo "\n\n                Je n'ai pas compris, 'ai besoin d'un entier pour pouvoir continuer.\n\n                Alice : \n";
            $mod = readline($a);
            if (!is_numeric($mod)) {
                echo "\n                Je n'ai toujours pas compris, pour eviter l'explosion de la terre je m'arette la.\n";
                exit;
            }
        }
        // bernard : votre $e
        echo "\n                Bien ! Maintenant un entier e.\n\n                Alice : ";
        $e = readline($a);
        if (!is_numeric($e)) {
            echo "\n\n                Je n'ai pas compris, 'ai besoin d'un entier pour pouvoir continuer\n\n                Alice : ";
            $e = readline($a);
            if (!is_numeric($e)) {
                echo "\n                Je n'ai toujours pas compris, je ... je dois vous laisser, j'ai oublié, une fourchette dans le micro-ondes\n";
                exit;
            }
        }
        //        /echo "E :: $e ::";
        //        limit > 4
        echo "\n                Et pour finir un entier bloc pour limiter les bloc messages dont la longueur doit etre supérieur à 4 et que la longueur de cl2 privée ne depasse pas celle ci\n\n                Alice : ";
        $limit = readline($a);
        if ($limit <= 4 || $limit > count($private_key)) {
            echo "\n\n                Hum pouvez vous recommencer ? la limite ne correspond pas au regles decrites tout à l'heure\n\n                Alice : ";
            $limit = readline($a);
            if (!$limit <= 4 || $limit > count($private_key)) {
                echo "\n                Hum, pouvez vous vous acheter des doigts ?\n";
                exit;
            }
        }
        echo "\n";
        sleep(2);
        $public_key = getPublicKey($private_key, $mod, $e, $limit);
        //        bernard votre message
        echo "\n\n                Tout est bon ! il ne reste plus que le message a crypter.\n\n                Bernard : ";
        $mess = readline($a);
        echo "\n";
        sleep(2);
        $message_crypted = cryptMessage($public_key[0], $mess, $limit);
        // $message_crypted = cryptMessage($public_key[0], $mess, $limit);
        $passwd = $public_key[1];
        // decrypt($private_key, $e, $mod, $message_crypted, $passwd, $limit);
        decrypt($private_key, $e, $mod, $message_crypted, $passwd, $limit);
        exit;
    }
    echo "\n";
}
Beispiel #23
0
        return 0;
    } else {
        return 1;
    }
}
if (checkIfUserAlreadyHasThisUrl($url, $userID) == 0) {
    echo "link already exists";
    break;
} else {
    $title = getPageTitle($url);
    $query = "INSERT into links (userID, url, title, timestamp) VALUES (?, ?, ?, now())";
    $params = [$userID, $url, $title];
    $lastInserted = editQuery($query, $params);
    if (strlen($tags) > 0) {
        $tagString = strtolower($tags);
        $tags = stringToArray($tagString);
        $tags = array_unique($tags);
        foreach ($tags as $tag) {
            $query = "SELECT * from tags WHERE tag = ?";
            $params = [$tag];
            $res = selectQuery($query, $params);
            if (count($res) == 0) {
                $query = "INSERT into tags (tag) VALUES (?)";
                $params = [$tag];
                editQuery($query, $params);
            }
        }
        foreach ($tags as $tag) {
            $query = "SELECT tagID from tags WHERE tag = ?";
            $params = [$tag];
            $res = selectQuery($query, $params);
 function getDias($toArray = false)
 {
     return $toArray ? stringToArray($this->Dias) : arrayToString($this->Dias);
 }