Large diffs are not rendered by default.

@@ -265,7 +265,7 @@ public function checkoutItem()
*/
public function createVersion()
{
if ($this->parameters->def('version_management', 1) == 1) {
if ($this->parameters->get('version_management', 1) == 1) {
} else {
return true;
}
@@ -277,7 +277,7 @@ public function createVersion()

/** versions deleted with delete **/
if ($this->get('task') == 'delete'
&& $this->parameters->def('retain_versions_after_delete', 1) == 0
&& $this->parameters->get('retain_versions_after_delete', 1) == 0
) {
return true;
}
@@ -314,7 +314,7 @@ public function createVersion()
*/
public function maintainVersionCount()
{
if ($this->parameters->def('version_management', 1) == 1) {
if ($this->parameters->get('version_management', 1) == 1) {
} else {
return true;
}
@@ -326,12 +326,12 @@ public function maintainVersionCount()

/** versions deleted with delete **/
if ($this->get('task') == 'delete'
&& $this->parameters->def('retain_versions_after_delete', 1) == 0
&& $this->parameters->get('retain_versions_after_delete', 1) == 0
) {
$maintainVersions = 0;
} else {
/** retrieve versions desired **/
$maintainVersions = $this->parameters->def('maintain_version_count', 5);
$maintainVersions = $this->parameters->get('maintain_version_count', 5);
}

/** delete extra versions **/

Large diffs are not rendered by default.

@@ -72,7 +72,7 @@ class MolajoDisplayModel extends MolajoModel
* @var array
* @since 1.0
*/
protected $tableFieldList = array();
protected $table_fields = array();

/**
* Model Object for Molajo configuration DELETE
@@ -165,7 +165,7 @@ public function populateStateMultiple()
/** selected filters **/
//for ($i = 1; $i < 10000; $i++) {

// $filterName = $this->parameters->def($this->filterFieldName . $i);
// $filterName = $this->parameters->get($this->filterFieldName . $i);

/** end of filter processing **/
// if ($filterName == null) {
@@ -218,7 +218,7 @@ public function populateStateMultiple()
} else {
$searchValue = $value;
}
if (in_array($searchValue, $this->tableFieldList)) {
if (in_array($searchValue, $this->table_fields)) {
$ordering = $value;
} else {
$ordering = 'a.title';
@@ -230,7 +230,7 @@ public function populateStateMultiple()

$this->setState('list.ordering', $value);

if (in_array($value, $this->tableFieldList)) {
if (in_array($value, $this->table_fields)) {
$ordering = $value;
} else {
$ordering = 'a.title';
@@ -339,9 +339,9 @@ public function getData()
{
$names = $this->getModel()->getProperties();

$this->tableFieldList = array();
$this->table_fields = array();
foreach ($names as $name => $value) {
$this->tableFieldList[] = $name;
$this->table_fields[] = $name;
}

/** create query **/
@@ -573,7 +573,7 @@ function getListQuery()
$nameArray = array();

/** load all available columns into select list **/
foreach ($this->tableFieldList as $name) {
foreach ($this->table_fields as $name) {
$this->setQueryInformation($name, false);
}

@@ -749,7 +749,7 @@ protected function getStoreId($id = '')
$id = ':' . $this->getState('filter.search');

// for ($i = 1; $i < 1000; $i++) {
// $temp = $this->parameters->def($this->filterFieldName . $i);
// $temp = $this->parameters->get($this->filterFieldName . $i);
// $filterName = substr($temp, 0, stripos($temp, ';'));
// $filterDataType = substr($temp, stripos($temp, ';') + 1, 1);
// if ($filterName == null) {
@@ -920,7 +920,7 @@ public function getOptionList($name1, $name2, $showKey = false, $showKeyFirst =

for ($i = 1; $i < 1000; $i++) {

$filterName = $this->parameters->def($this->filterFieldName . $i);
$filterName = $this->parameters->get($this->filterFieldName . $i);

/** end of filter processing **/
if ($filterName == null) {
@@ -1143,7 +1143,7 @@ private function saveSelective()

for ($i = 1; $i < 1000; $i++) {

$name = $this->parameters->def($this->filterFieldName . $i);
$name = $this->parameters->get($this->filterFieldName . $i);

/** end of filter processing **/
if ($name == null) {
@@ -1164,7 +1164,7 @@ private function saveSelective()

/** filter by known field names and append into query object **/
foreach ($nameArray as $name) {
if ((in_array($name, $this->tableFieldList)) || $name == 'search') {
if ((in_array($name, $this->table_fields)) || $name == 'search') {
$this->setQueryInformation($name, false);
}
}
@@ -28,7 +28,7 @@ class MolajoUsersModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__users';
$this->table_name = '#__users';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoActionTypesModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__action_types';
$this->table_name = '#__action_types';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoApplicationExtensionInstancesModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__application_extension_instances';
$this->table_name = '#__application_extension_instances';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoApplicationsModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__applications';
$this->table_name = '#__applications';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoAssetActivityModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__asset_activity';
$this->table_name = '#__asset_activity';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoAssetCategoriesModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__asset_categories';
$this->table_name = '#__asset_categories';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoAssetTypesModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__asset_types';
$this->table_name = '#__asset_types';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoAssetsModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__assets';
$this->table_name = '#__assets';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoContentModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__content';
$this->table_name = '#__content';
$this->primary_key = 'id';

return parent::__construct($id);

This file was deleted.

@@ -40,7 +40,7 @@ public function __construct($id = null)
*/
public function getData()
{
$this->data = array();
$this->query_results = array();

/** type: javascript_links */
$list = Molajo::Responder()->getScriptLinks(1);
@@ -55,7 +55,7 @@ public function getData()
$row->async = $item['async'];
$row->priority = $item['priority'];

$this->data[] = $row;
$this->query_results[] = $row;
}

/** type: javascript_declarations */
@@ -68,9 +68,9 @@ public function getData()
$row->mimetype = $item['mimetype'];
$row->content = $item['content'];

$this->data[] = $row;
$this->query_results[] = $row;
}

return $this->data;
return $this->query_results;
}
}
@@ -16,7 +16,7 @@
* @subpackage Model
* @since 1.0
*/
class MolajoDisplayModel extends MolajoCrudModel
class MolajoDisplayModel extends MolajoLoadModel
{
/**
* _setQuery
@@ -95,16 +95,17 @@ protected function _setQuery()
* From
*/
$this->query->from(
$this->db->qn($this->table)
$this->db->qn($this->table_name)
. ' as '
. $this->db->qn($this->primary_prefix)
);

if (isset($parameterArray['disable_view_access_check'])
&& $parameterArray['disable_view_access_check'] == 0
) {
MolajoAccessService::setQueryViewAccess(
Services::Access()->setQueryViewAccess(
$this->query,
$this->db,
array('join_to_prefix' => $this->primary_prefix,
'join_to_primary_key' => $this->primary_key,
'asset_prefix' => $this->primary_prefix . '_assets',
@@ -231,16 +232,16 @@ public function runQuery()
*
* Method to append additional data elements, as needed
*
* @param array $this->data
* @param array $this->query_results
*
* @return array
* @since 1.0
*/
protected function _getAdditionalData()
{
$rowCount = 1;
if (count($this->data) == 0) {
return $this->data;
if (count($this->query_results) == 0) {
return $this->query_results;
}

/**
@@ -273,7 +274,7 @@ protected function _getAdditionalData()
/**
* Loop through query results
*/
foreach ($this->data as $item) {
foreach ($this->query_results as $item) {
$keep = true;

if (count($methodArray) > 0) {
@@ -306,12 +307,12 @@ protected function _getAdditionalData()

/** remove items so marked **/
if ($keep === true) {
$item->rowCount = $rowCount++;
$item->row_count = $rowCount++;
} else {
unset($item);
}
}
return $this->data;
return $this->query_results;
}

/**
@@ -27,7 +27,7 @@ class MolajoExtensionInstancesModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__extension_instances';
$this->table_name = '#__extension_instances';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoExtensionSitesModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__extension_sites';
$this->table_name = '#__extension_sites';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoExtensionsModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__extensions';
$this->table_name = '#__extensions';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -46,10 +46,10 @@ public function getOptions()
$options[] = MolajoHTML::_('select.option', MOLAJO_STATUS_PUBLISHED, Services::Language()->_('MOLAJO_OPTION_STATUS_PUBLISHED'));
$options[] = MolajoHTML::_('select.option', MOLAJO_STATUS_UNPUBLISHED, Services::Language()->_('MOLAJO_OPTION_STATUS_UNPUBLISHED'));
$options[] = MolajoHTML::_('select.option', MOLAJO_STATUS_TRASHED, Services::Language()->_('MOLAJO_OPTION_STATUS_TRASHED'));
if ($this->parameters->def('state_spam', '0') == 1) {
if ($this->parameters->get('state_spam', '0') == 1) {
$options[] = MolajoHTML::_('select.option', MOLAJO_STATUS_SPAMMED, Services::Language()->_('MOLAJO_OPTION_STATUS_SPAMMED'));
}
if ($this->parameters->def('version_management', '1') == 1) {
if ($this->parameters->get('version_management', '1') == 1) {
$options[] = MolajoHTML::_('select.option', MOLAJO_STATUS_VERSION, Services::Language()->_('MOLAJO_OPTION_STATUS_VERSION'));
}
$options[] = MolajoHTML::_('select.option', '*', Services::Language()->_('MOLAJO_OPTION_ALL'));
@@ -27,7 +27,7 @@ class MolajoGroupPermissionsModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__group_permissions';
$this->table_name = '#__group_permissions';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoGroupViewGroupsModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__group_view_groups';
$this->table_name = '#__group_view_groups';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -40,7 +40,7 @@ public function __construct($id = null)
*/
public function getData()
{
$this->data = array();
$this->query_results = array();

$row = new stdClass();
$row->type = 'base';
@@ -58,7 +58,7 @@ public function getData()
$row->base = Molajo::Request()->get('url_base');
$row->last_modified = Molajo::Request()->get('source_last_modified');
$row->favicon = Molajo::Request()->get('theme_favicon');
$this->data[] = $row;
$this->query_results[] = $row;

/** type: links */
$list = Molajo::Responder()->getHeadLinks();
@@ -71,7 +71,7 @@ public function getData()
$row->relation = $item['relation'];
$row->relation_type = $item['relation_type'];
$row->attributes = $item['attributes'];
$this->data[] = $row;
$this->query_results[] = $row;
}
}

@@ -86,7 +86,7 @@ public function getData()
$row->media = $item['media'];
$row->attributes = $item['attributes'];
$row->priority = $item['priority'];
$this->data[] = $row;
$this->query_results[] = $row;
}
}

@@ -97,7 +97,7 @@ public function getData()
$row->type = 'stylesheet_declarations';
$row->mimetype = $item['mimetype'];
$row->content = $item['content'];
$this->data[] = $row;
$this->query_results[] = $row;
}

/** type: javascript_links */
@@ -110,7 +110,7 @@ public function getData()
$row->defer = 0;
$row->async = $item['async'];
$row->priority = $item['priority'];
$this->data[] = $row;
$this->query_results[] = $row;
}

/** type: javascript_declarations */
@@ -120,9 +120,9 @@ public function getData()
$row->type = 'javascript_declarations';
$row->mimetype = $item['mimetype'];
$row->content = $item['content'];
$this->data[] = $row;
$this->query_results[] = $row;
}

return $this->data;
return $this->query_results;
}
}

Large diffs are not rendered by default.

@@ -0,0 +1,127 @@
<?php
/**
* @package Molajo
* @subpackage Model
* @copyright Copyright (C) 2012 Amy Stephen. All rights reserved.
* @license GNU General Public License Version 2, or later http://www.gnu.org/licenses/gpl.html
*/
defined('MOLAJO') or die;

/**
* Load
*
* @package Molajo
* @subpackage Model
* @since 1.0
*/
class MolajoLoadModel extends MolajoItemModel
{
/**
* load
*
* Method to load a specific item from a specific model.
* Creates and runs the database query, allows for additional data,
* and returns integrated data as the item requested
*
* @return object
* @since 1.0
*/
public function load()
{
$this->_setLoadQuery();

$this->_runLoadQuery();
if (empty($this->query_results)) {
return false;
}

$this->_getLoadAdditionalData();

return $this->query_results;
}

/**
* _setLoadQuery
*
* Retrieve all elements of the specific table for a specific item
*
* @return object
* @since 1.0
*/
protected function _setLoadQuery()
{
$this->query = $this->db->getQuery(true);

$this->query->select(' * ');
$this->query->from($this->db->qn($this->table_name));
$this->query->where($this->primary_key
. ' = '
. $this->db->q($this->id));

$this->db->setQuery($this->query->__toString());
}

/**
* _runLoadQuery
*
* Execute query and returns an associative array of data elements
*
* @return array
* @since 1.0
*/
protected function _runLoadQuery()
{
$this->query_results = $this->db->loadAssoc();

if (empty($this->query_results)) {
return false;
}

if (key_exists('custom_fields', $this->query_results)
&& is_array($this->query_results['custom_fields'])
) {
$registry = new Registry();
$registry->loadString($this->query_results['custom_fields']);
$this->query_results['custom_fields'] = (string)$registry;
}

if (key_exists('parameters', $this->query_results)
&& is_array($this->query_results['parameters'])
) {
$registry = new Registry();
$registry->loadString($this->query_results['parameters']);
$this->query_results['parameters'] = (string)$registry;
}

if (key_exists('metadata', $this->query_results)
&& is_array($this->query_results['metadata'])
) {
$registry = new Registry();
$registry->loadString($this->query_results['metadata']);
$this->query_results['metadata'] = (string)$registry;
}

if ($this->db->getErrorNum()) {
$e = new MolajoException($this->db->getErrorMsg());
$this->setError($e);
return false;
}

return $this->query_results;
}

/**
* _getAdditionalData
*
* Method to append additional data elements needed to the standard
* array of elements provided by the data source
*
* @return array
* @since 1.0
*/
protected function _getLoadAdditionalData()
{
return $this->query_results;
}
}

@@ -40,7 +40,7 @@ public function __construct($id = null)
*/
public function getData()
{
$this->data = array();
$this->query_results = array();

$messages = Services::Message()->get();
if (count($messages) == 0) {
@@ -55,9 +55,9 @@ public function getData()
$row->debug_location = $message['debug_location'];
$row->debug_object = $message['debug_object'];

$this->data[] = $row;
$this->query_results[] = $row;
}

return $this->data;
return $this->query_results;
}
}

Large diffs are not rendered by default.

@@ -45,8 +45,8 @@ public function __construct($id = null)
public function getData()
{
/** input for events is stored in the task request object */
$this->data = Molajo::Request()->get('query_rowset');
return $this->data;
$this->query_results = Molajo::Request()->get('query_rowset');
return $this->query_results;
}

/**
@@ -14,7 +14,7 @@
* @subpackage Model
* @since 1.0
*/
class MolajoSessionsModel extends MolajoCrudModel
class MolajoSessionsModel extends MolajoLoadModel
{
/**
* __construct
@@ -27,7 +27,7 @@ class MolajoSessionsModel extends MolajoCrudModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__sessions';
$this->table_name = '#__sessions';
$this->primary_key = 'session_id';

parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoSiteApplicationsModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__site_applications';
$this->table_name = '#__site_applications';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoSiteExtensionInstancesModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__site_extension_instances';
$this->table_name = '#__site_extension_instances';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoSitesModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__sites';
$this->table_name = '#__sites';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoUserActivityModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__user_activity';
$this->table_name = '#__user_activity';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoUserApplicationsModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__user_applications';
$this->table_name = '#__user_applications';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoUserGroupsModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__user_groups';
$this->table_name = '#__user_groups';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoUserViewGroupsModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__user_view_groups';
$this->table_name = '#__user_view_groups';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -13,7 +13,6 @@
* @package Molajo
* @subpackage Model
* @since 1.0
* @link
*/
class MolajoUsersModel extends MolajoDisplayModel
{
@@ -28,7 +27,7 @@ class MolajoUsersModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__users';
$this->table_name = '#__users';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -40,8 +39,6 @@ public function __construct($id = null)
* Method to append additional data elements needed to the standard
* array of elements provided by the data source
*
* @param array $this->data
*
* @return array
* @since 1.0
*/
@@ -50,10 +47,11 @@ protected function _getLoadAdditionalData()
parent::_getLoadAdditionalData();

/** concatenate name */
$this->data['name'] = $this->data['first_name'] . ' ' . $this->data['last_name'];
$this->query_results['name'] = $this->query_results['first_name'] . ' ' . $this->query_results['last_name'];

/** retrieve applications for which the user is authorized to login */
$m = new MolajoUserApplicationsModel ();

$m->query->select($this->db->qn('application_id'));
$m->query->where($this->db->qn('user_id') . ' = ' . (int)$this->id);

@@ -63,41 +61,45 @@ protected function _getLoadAdditionalData()
foreach ($applications as $application) {
$x[] = $application;
}
$this->data['applications'] = $x;
$this->query_results['applications'] = $x;

/** retrieve groups to which the user belongs */
$m = new MolajoUserGroupsModel ();

$m->query->select($this->db->qn('group_id'));
$m->query->where($this->db->qn('user_id') . ' = ' . (int)$this->id);

$groups = $m->loadObjectList();

$x = array();
foreach ($groups as $group) {
$x[] = $group->group_id;
}
$this->data['groups'] = $x;
$this->query_results['groups'] = $x;

/** retrieve system groups to which the user belongs */
$this->data['public'] = 1;
$this->data['guest'] = 0;
$this->data['registered'] = 1;
if (in_array(5, $this->data['groups'])) {
$this->data['administrator'] = 1;
$this->query_results['public'] = 1;
$this->query_results['guest'] = 0;
$this->query_results['registered'] = 1;
if (in_array(MOLAJO_SYSTEM_GROUP_ADMINISTRATOR, $this->query_results['groups'])) {
$this->query_results['administrator'] = 1;
}

/** retrieve view access groups to which the user belongs */
$m = new MolajoUserViewGroupsModel ();

$m->query->select($this->db->qn('view_group_id'));
$m->query->where($this->db->qn('user_id') . ' = ' . (int)$this->id);

$vgroups = $m->runQuery();

$x = array();
foreach ($vgroups as $vgroup) {
$x[] = $vgroup->view_group_id;
}
$this->data['view_groups'] = $x;
$this->query_results['view_groups'] = $x;

/** return array of primary query and additional data elements */
return $this->data;
return $this->query_results;
}
}
@@ -27,7 +27,7 @@ class MolajoViewGroupPermissionsModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__view_group_permissions';
$this->table_name = '#__view_group_permissions';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -27,7 +27,7 @@ class MolajoViewGroupsModel extends MolajoDisplayModel
public function __construct($id = null)
{
$this->name = get_class($this);
$this->table = '#__view_groups';
$this->table_name = '#__view_groups';
$this->primary_key = 'id';

return parent::__construct($id);
@@ -525,7 +525,6 @@ protected function _getExtensionDefaults()
$this->get('extension_parameters', '')
)
);

}

/** wrap */
@@ -540,8 +539,8 @@ protected function _getExtensionDefaults()
$this->get('extension_parameters', '')
)
);

}

return true;
}

@@ -749,15 +748,15 @@ protected function _invokeMVC()
$task = (string)$this->get('task', 'display');
$this->set('task', $task);

$this->_verifyMVC(false);
if ($this->get('status_found') === false) {
return $this->get('status_found');
if (Services::Configuration()->get('debug', 0) == 1) {
debug(' ');
debug('MolajoRenderer::_invokeMVC');
debug('Controller: '.$cc.' Task: '.$task.' Model: '.$model.' ');
debug('Extension: '.$this->get('extension_instance_name').' ID: '.$this->get('id').'');
debug('Template: '.$this->get('template_view_path').'');
debug('Wrap: '.$this->get('wrap_view_path').'');
}
/**
echo '<pre>';
var_dump($this->task_request);
echo '</pre>';
*/

/** instantiate controller */
$controller = new $cc($this->task_request, $this->parameters);

@@ -877,46 +876,6 @@ protected function _setController()
return 'MolajoController';
}

/**
* _verifyMVC
*
* @return bool
*/
protected function _verifyMVC($display = false)
{
$test1 = class_exists($this->get('controller'));
$test2 = method_exists($this->get('controller'), $this->get('task'));
$test3 = class_exists($this->get('controller'));
if ($this->get('template_view_id', 0) == 0) {
$test4 = 0;
} else {
$test4 = 1;
}
if ($this->get('wrap_view_id', 0) == 0) {
$test5 = 0;
} else {
$test5 = 1;
}

if (($test1 + $test2 + $test3 + $test4 + $test5) < 5) {
$this->set('status_found', false);
}

if (($this->get('status_found') === false)
|| $display === true
) {
echo 'Error Count: ' . (5 - ($test1 + $test2 + $test3 + $test4 + $test5)) . '<br />';
echo 'Controller ' . $this->get('controller') . '<br />';
echo 'Model ' . $this->get('model') . '<br />';
echo 'Task ' . $this->get('task') . '<br />';
echo 'Template View ' . $this->get('template_view_id') . '<br />';
echo 'Wrap View ' . $this->get('wrap_view_id') . '<br />';
echo '<pre>';
var_dump($this->task_request);
echo '</pre>';
}
}

/**
* _postMVCProcessing
* @return bool
@@ -33,9 +33,11 @@ protected function _getExtension()
$results = parent::_getExtension();

if ($results === false) {
echo 'remove from MolajoModuleRenderer when .
dev is done. Module not found: '.
$this->get('extension_instance_name').'<br />';
if (Services::Configuration()->get('debug', 0) == 1) {
debug(' ');
debug('MolajoModuleRenderer::_getExtension');
debug('Module not found: '.$this->get('extension_instance_name'));
}
return false;
}

Large diffs are not rendered by default.

@@ -90,6 +90,11 @@ public function get($key, $default = null)
*/
public function set($key, $value = null)
{
if ($value == null) {
debug(' ');
debug('MolajoServices::set');
debug('Service failed to start: '.$key);
}
$this->service_connection->set($key, $value);
}

@@ -116,9 +121,11 @@ public function initiateServices()
foreach ($services->service as $s) {
$serviceName = (string)$s->name;
$connection = $this->_connectService($s);
//echo 'Name '.$serviceName.'<br />';
//var_dump($connection);
//echo '<br />';
/**
echo 'SERVICE: '.$serviceName.'<br />';
var_dump($connection);
echo '<br />';
*/
$this->set($serviceName, $connection);
}

@@ -53,12 +53,15 @@ public static function get($asset_id = 0, $query_request = null)
' = b.' . $m->db->qn('id'));

if ((int)$asset_id == 0) {

$m->query->where('(a.' . $m->db->qn('sef_request') .
' = ' . $m->db->q($query_request) .
' OR a.' . $m->db->qn('request') . ' = ' .
$m->db->q($query_request) . ')'
);

} else {

$m->query->where('a.' . $m->db->qn('id') . ' = ' .
(int)$asset_id
);
@@ -46,8 +46,9 @@ static public function get($id, $content_table)
);

/** Assets Join and View Access Check */
MolajoAccessService::setQueryViewAccess(
Services::Access()->setQueryViewAccess(
$m->query,
$m->db,
array('join_to_prefix' => 'a',
'join_to_primary_key' => 'id',
'asset_prefix' => 'b_assets',
@@ -85,9 +85,9 @@ public static function get($asset_type_id = 0, $extension = null)
);

/** Assets Join and View Access Check */
Services::Access()
->setQueryViewAccess(
Services::Access()->setQueryViewAccess(
$m->query,
$m->db,
array('join_to_prefix' => 'a',
'join_to_primary_key' => 'id',
'asset_prefix' => 'b_assets',
@@ -14,7 +14,7 @@
* @subpackage Helper
* @since 1.0
*/
class MolajoLanguageHelper
abstract class MolajoLanguageHelper
{
/**
* getLanguage
@@ -24,7 +24,7 @@ class MolajoLanguageHelper
* @return string locale or null if not found
* @since 1.0
*/
public function getDefault()
static public function getDefault()
{
/** Installed Languages */
$languages = LanguageHelper::getLanguages(
@@ -80,7 +80,7 @@ public function getDefault()
* @return array
* @since 1.0
*/
public static function createLanguageList($path = null)
static public function createLanguageList($path = null)
{
if (MOLAJO_APPLICATION_ID == 0) {
$path = MOLAJO_EXTENSIONS_COMPONENTS . '/' . 'installer';
@@ -124,7 +124,7 @@ public static function createLanguageList($path = null)
* @return object
* @since 1.0
*/
public function getLanguages($path = MOLAJO_EXTENSIONS_LANGUAGES)
static public function getLanguages($path = MOLAJO_EXTENSIONS_LANGUAGES)
{
if ($path == MOLAJO_EXTENSIONS_LANGUAGES) {
return LanguageHelper::getLanguagesCore();
@@ -159,7 +159,7 @@ public function getLanguages($path = MOLAJO_EXTENSIONS_LANGUAGES)
* @return array
* @since 1.0
*/
public function getLanguagesCore()
static public function getLanguagesCore()
{
$subfolders = JFolder::folders(MOLAJO_EXTENSIONS_LANGUAGES);
$languages = array();
@@ -185,7 +185,7 @@ public function getLanguagesCore()
* @return array array
* @since 1.0
*/
public function getMetadata($file)
static public function getMetadata($file)
{
$xml = simplexml_load_file($file);
if ($xml) {
@@ -55,9 +55,9 @@ public static function get($menu_item_id)
$m->query->where('a.' . $m->db->qn('id') . ' = ' . (int)$menu_item_id);

/** Assets Join and View Access Check */
Services::Access()
->setQueryViewAccess(
Services::Access()->setQueryViewAccess(
$m->query,
$m->db,
array('join_to_prefix' => 'a',
'join_to_primary_key' => 'id',
'asset_prefix' => 'a_assets',
@@ -89,9 +89,9 @@ public static function get($menu_item_id)
' OR b.stop_publishing_datetime >= ' . $m->db->q($m->now) . ')'
);

Services::Access()
->setQueryViewAccess(
Services::Access()->setQueryViewAccess(
$m->query,
$m->db,
array('join_to_prefix' => 'b',
'join_to_primary_key' => 'id',
'asset_prefix' => 'b_assets',
@@ -510,10 +510,13 @@ public function getList($field)

$m = new $model();

$m->query->select($m->db->qn('a') . '.' . $m->db->qn($key) . ' as ' . $m->db->qn('key'));
$m->query->select($m->db->qn('a') . '.' . $m->db->qn($value) . ' as ' . $m->db->qn('value'));
$m->query->select($m->db->qn('a') . '.' . $m->db->qn($key)
. ' as ' . $m->db->qn('key'));
$m->query->select($m->db->qn('a') . '.' . $m->db->qn($value)
. ' as ' . $m->db->qn('value'));

$m->query->from($m->db->qn(trim($m->table)) . ' as ' . $m->db->qn('a'));
$m->query->from($m->db->qn(trim($m->table_name))
. ' as ' . $m->db->qn('a'));

if ((int)$assettypes == '0') {
} else {
@@ -529,8 +532,9 @@ public function getList($field)
}

if ((int)$viewaccess == 1) {
MolajoAccessService::setQueryViewAccess(
$m->query,
Services::Access()->setQueryViewAccess(
$this->query,
$this->db,
array('join_to_prefix' => 'a',
'join_to_primary_key' => 'id',
'asset_prefix' => 'a_assets',
@@ -627,13 +631,8 @@ public function validateToList($name)
* @return boolean True if checked out to user
* @since 1.0
*/
public function validateCheckedOut($model)
public function validateCheckedOut($model, $query, $db)
{
$db = Services::DB();
$query = $db->getQuery(true);
$now = Services::Date()->getDate()->toSql();
$nullDate = $db->getNullDate();

$query->select('a.' . $db->qn('view_group_id'));
$query->select('a.' . $db->qn('asset'));
}
@@ -82,11 +82,12 @@

/** Models */
$load->requireClassFile(MOLAJO_APPLICATIONS_MVC . '/models/model.php', 'MolajoModel');
$load->requireClassFile(MOLAJO_APPLICATIONS_MVC . '/models/crud.php', 'MolajoCrudModel');
$load->requireClassFile(MOLAJO_APPLICATIONS_MVC . '/models/item.php', 'MolajoItemModel');
$load->requireClassFile(MOLAJO_APPLICATIONS_MVC . '/models/load.php', 'MolajoLoadModel');
$load->requireClassFile(MOLAJO_APPLICATIONS_MVC . '/models/display.php', 'MolajoDisplayModel');
$files = JFolder::files(MOLAJO_APPLICATIONS_MVC . '/models', '\.php$', false, false);
foreach ($files as $file) {
if ($file == 'model.php' || $file == 'display.php') {
if ($file == 'model.php' || $file == 'item.php' || $file == 'load.php' || $file == 'display.php') {
} else {
$load->requireClassFile(MOLAJO_APPLICATIONS_MVC . '/models/' . $file, 'Molajo' . ucfirst(substr($file, 0, strpos($file, '.'))).'Model');
}
@@ -38,3 +38,9 @@
}
}

/**
* Debug
*/
$load->requireClassFile(PLATFORM_MOLAJO . '/debug/PhpConsole.php', 'PhpConsole');
PhpConsole::start(true, true, PLATFORM_MOLAJO . '/debug');

@@ -23,11 +23,6 @@
<name>Configuration</name>
<serviceClass>MolajoConfigurationService</serviceClass>
</service>

<service>
<name>Access</name>
<serviceClass>MolajoAccessService</serviceClass>
</service>
<service>
<name>User</name>
<serviceClass>MolajoUserService</serviceClass>
@@ -39,6 +34,10 @@
<connect>
</connect>
</service>
<service>
<name>Access</name>
<serviceClass>MolajoAccessService</serviceClass>
</service>
<service>
<name>Image</name>
<serviceClass>MolajoImageService</serviceClass>
@@ -60,12 +59,11 @@
<serviceClass>MolajoSecurityService</serviceClass>
</service>
<service>
<name>URL</name>
<name>Url</name>
<serviceClass>MolajoURLService</serviceClass>
</service>
<service>
<name>Text</name>
<serviceClass>MolajoTextService</serviceClass>
</service>

</services>
@@ -4,11 +4,11 @@
<task name="archive" action="publish" controller="updatelist"/>
<task name="cancel" action="none" controller="update"/>
<task name="checkin" action="administer" controller="updatelist"/>
<task name="copy" action="create" controller="updatelist"/>
<task name="create" action="create" controller="update"/>
<task name="copy" action="view" controller="updatelist"/>
<task name="create" action="view" controller="update"/>
<task name="delete" action="delete" controller="updatelist"/>
<task name="display" action="view" controller="display"/>
<task name="edit" action="edit" controller="display"/>
<task name="edit" action="view" controller="display"/>
<task name="feature" action="publish" controller="updatelist"/>
<task name="login" action="login" controller="login"/>
<task name="logout" action="logout" controller="login"/>
@@ -18,25 +18,26 @@
*/
class MolajoAccessService
{

/**
* $task_to_action
* $action_to_action_id
*
* Task to ACL Action list
* ACL Action literal to database pk
*
* @var Registry
* @since 1.0
*/
public $task_to_action;
protected $action_to_action_id;

/**
* $action_to_action_id
* $task_to_action
*
* ACL Action literal to database pk
* Task to ACL Action list
*
* @var Registry
* @since 1.0
*/
public $action_to_action_id;
protected $task_to_action;

/**
* $action_to_controller
@@ -46,7 +47,7 @@ class MolajoAccessService
* @var Registry
* @since 1.0
*/
public $action_to_controller;
protected $action_to_controller;

/**
* Static instance
@@ -101,6 +102,7 @@ protected function _initialize()
if (count($tasks) == 0) {
return;
}

$this->task_to_action = new Registry();
$this->action_to_controller = new Registry();

@@ -122,7 +124,9 @@ protected function _initialize()

/** retrieve database keys for actions */
$m = new MolajoActionTypesModel();

$actionsList = $m->getData();

foreach ($actionsList as $actionDefinition) {
$this->action_to_action_id
->set(
@@ -134,6 +138,23 @@ protected function _initialize()
return;
}

/**
* getTaskController
*
* Using the Task, retrieve the Controller
*
* @param $task
*
* @return string
* @since 1.0
*/
public function getTaskController ($task)
{
$action = $this->task_to_action->get($task);
$controller = $this->action_to_controller->get($action);
return $controller;
}

/**
* authoriseTaskList
*
@@ -146,20 +167,16 @@ protected function _initialize()
public function authoriseTaskList($tasklist = array(), $asset_id = 0)
{
if (count($tasklist) == 0) {
return;
return false;
}
if ($asset_id == 0) {
return;
return false;
}

$taskPermissions = array();
foreach ($tasklist as $task) {
$taskPermissions[$task] =
Services::Access()
->authoriseTask(
$task,
$asset_id
);
Services::Access()->authoriseTask($task, $asset_id);
}
return $taskPermissions;
}
@@ -176,23 +193,28 @@ public function authoriseTaskList($tasklist = array(), $asset_id = 0)
public function authoriseTask($task, $asset_id)
{
if ($task == 'login') {
return Services::Access()
->authoriseTask('login', $asset_id);
return Services::Access()->authoriseLogin('login', $asset_id);
}

/** Retrieve ACL Action for this Task */
$action = $this->task_to_action->get($task);
$action_id = (int) $this->action_to_action_id->get($action);

if (trim($action) == '' || (int) $action_id == 0 || trim($action) == '') {
echo 'Task: ' . $task . ' Action: ' . $action . ' Action ID: '. $action_id . ' (Message in Access)' . '<br />';
if (Services::Configuration()->get('debug', 0) == 1) {
debug(' ');
debug('MolajoAccessService::authoriseTask');
debug('Task: ' . $task . ' Action: ' . $action . ' Action ID: '. $action_id);
}
}

//todo: amy fill database with real actions

/** check for permission */
$action_id = 3;

$m = new MolajoGroupPermissionsModel();

$m->query->where($m->db->qn('asset_id') . ' = ' . (int)$asset_id);
$m->query->where($m->db->qn('action_id') . ' = ' . (int)$action_id);
$m->query->where($m->db->qn('group_id')
@@ -226,6 +248,7 @@ public function authoriseLogin($user_id)
}

$m = new MolajoUserApplicationsModel();

$m->query->where('application_id = ' . (int)MOLAJO_APPLICATION_ID);
$m->query->where('user_id = ' . (int)$user_id);

@@ -243,18 +266,18 @@ public function authoriseLogin($user_id)
*
* Append criteria needed to implement view access for Query
*
* @param string $query
* @param string $parameters
* @param array $query
* $param array $db
* @param Registry $parameters
*
* @return boolean
* @since 1.0
*/
public function setQueryViewAccess(
$query = array(),
$db = array(),
$parameters = array())
{
$db = Services::DB();

if ($parameters['select'] === true) {
$query->select(
$db->qn($parameters['asset_prefix']) .
@@ -48,6 +48,14 @@ class MolajoSecurityService
*/
protected $token;

/**
* Filter
*
* @var array
* @since 1.0
*/
protected $filter;

/**
* @var array A list of the default whitelist tags.
* @since 1.5
@@ -96,6 +104,7 @@ public static function getInstance()
public function __construct()
{
$this->session = Services::Session();
$this->filter = FilterInput::getInstance();
}

/**
@@ -217,6 +226,213 @@ function encodeLinkText($option_Text)
return htmlentities($option_Text, ENT_QUOTES, 'UTF-8');
}

/**
* filter
*
* Filter input, default value, edit
*
* @param string $field_name Value of input field
* @param string $field_value Value of input field
* @param string $datatype Datatype of input field
* @param int $null 0 or 1 - is null allowed
* @param string $default Default value, optional
*
* @return mixed
* @since 1.0
*/
public function filter($field_name,
$field_value = null,
$datatype = 'char',
$null = 1,
$default = null)
{
if ($datatype == 'int') {
return $this->filter_int(
$field_name, $field_value, $null, $default
);

} else if ($datatype == 'date') {
return $this->filter_date(
$field_name, $field_value, $null, $default
);

} else if ($datatype == 'text') {
return $this->filter_html(
$field_name, $field_value, $null, $default
);

} else {
return $this->filter_char(
$field_name, $field_value, $null, $default
);
}
}

/**
* filter_int
*
* @param string $field_name Value of input field
* @param string $field_value Value of input field
* @param int $null 0 or 1 - is null allowed
* @param string $default Default value, optional
*
* @return string
* @since 1.0
*/
public function filter_int($field_name,
$field_value = null,
$null = 1,
$default = null)
{
if ($default == null) {
} else if ($field_value == null) {
$field_value = $default;
}

if ($field_value == null) {
} else {
$test = (int)$field_value;
if ($test == $field_value) {
return $test;
}
}

if ($field_value == null
&& $null == 0
) {
throw new Exception('FILTER_VALUE_REQUIRED');
}

return $field_value;
}


/**
* filter_date
*
* @param string $field_name Value of input field
* @param string $field_value Value of input field
* @param int $null 0 or 1 - is null allowed
* @param string $default Default value, optional
*
* @return string
* @since 1.0
*/
public function filter_date($field_name,
$field_value = null,
$null = 1,
$default = null)
{
if ($default == null) {
} else if ($field_value == null
|| $field_value == ''
|| $field_value == 0 ) {
$field_value = $default;
}

if ($field_value == null
|| $field_value == '0000-00-00 00:00:00') {
} else {
$dd = substr($field_value, 8, 2);
$mm = substr($field_value, 5, 2);
$ccyy = substr($field_value, 0, 4);

if (checkdate((int) $mm, (int) $dd, (int) $ccyy)) {
} else {
throw new Exception('FILTER_INVALID_VALUE');
}
$test = $ccyy . '-' . $mm . '-' . $dd;

if ($test == $field_value) {
return $test;
} else {
throw new Exception('FILTER_INVALID_VALUE');
}
}

if ($field_value == null
&& $null == 0
) {
throw new Exception('FILTER_VALUE_REQUIRED');
}

return $field_value;
}

/**
* filter_html
*
* @param string $field_name Value of input field
* @param string $field_value Value of input field
* @param int $null 0 or 1 - is null allowed
* @param string $default Default value, optional
*
* @return mixed
* @since 1.0
*/
public function filter_html($field_name,
$field_value = null,
$null = 1,
$default = null)
{
if ($default == null) {
} else if ($field_value == null) {
$field_value = $default;
}

if ($field_value == null) {
} else {
$field_value = $this->filter->clean($field_value, 'HTML');
}

if ($field_value == null
&& $null == 0
) {
throw new Exception('FILTER_VALUE_REQUIRED');
}

return $field_value;
}

/**
* filter_char
*
* @param string $field_name Value of input field
* @param string $field_value Value of input field
* @param int $null 0 or 1 - is null allowed
* @param string $default Default value, optional
*
* @return mixed
* @since 1.0
*/
public function filter_char($field_name,
$field_value = null,
$null = 1,
$default = null)
{
if ($default == null) {
} else if ($field_value == null) {
if ($default == 'space') {
$field_value = ' ';
} else {
$field_value = $default;
}
}

if ($field_value == null) {
} else {
$field_value = $this->filter->clean($field_value, 'STRING');
}

if ($field_value == null
&& $null == 0
) {
throw new Exception('FILTER_VALUE_REQUIRED');
}

return $field_value;
}

/**
* Applies the content text filters as per settings for current user group
*
@@ -227,10 +443,6 @@ public function filterText($text)
{
return true;

/** filter parameters **/
$molajoSystemPlugin =& MolajoPluginService::getPlugin('system', 'molajo');
$systemParameters = new JParameter($molajoSystemPlugin->parameters);

$acl = new MolajoACL ();
$userGroups = $acl->getList('usergroups');

@@ -332,11 +544,11 @@ public function filterText($text)
1 // blacklist attributes
);
}
// White lists take third precedence.
// White lists take third precedence.
else if ($whiteList) {
$filter = FilterInput::getInstance($whiteListTags, $whiteListAttributes, 0, 0, 0); // turn off xss auto clean
}
// No HTML takes last place.
// No HTML takes last place.
else {
$filter = FilterInput::getInstance();
}
@@ -347,22 +559,6 @@ public function filterText($text)
return $text;
}

public static function filterURL($text)
{
}

public static function filterEmail($text)
{
}

public static function filterFile($text)
{
}

public static function filterIPAddress($text)
{
}

/**
* escapeHTML
*
@@ -386,7 +582,7 @@ static public function escapeHTML($htmlText)
*/
static public function escapeInteger($integer)
{
return (int) $integer;
return (int)$integer;
}

/**
@@ -34,7 +34,7 @@ class MolajoUrlService
* @var object
* @since 1.0
*/
public static $input;
public $input;

/**
* getInstance
@@ -74,17 +74,14 @@ public function __construct()
*/
public function _getInput()
{
if (class_exists('JInput')) {
$this->input = new JInput;
}
$this->input = new JInput;

// Get the full request URI.
$uri = clone JURI::getInstance();
$results = $uri->get('_vars');
foreach ($results as $key => $value) {
$this->input->set($key, $value);
}

}

/**
@@ -132,3 +132,5 @@ CONTENT_VALUES_STICKIED="Stickied must be 0 or 1."
CONTENT_VALUES_PROTECTED="Protected must be 0 or 1."
ACTION_TYPES_VALUES_TITLE_REQUIRED="Title is required."
ACTION_TYPES_VALUES_PROTECTED="Protected must be 0 or 1."
FILTER_VALUE_REQUIRED="Value required, but not provided, for field: "
FILTER_INVALID_VALUE="Invalid value provided for field: "
@@ -71,7 +71,7 @@ protected function _cloak(&$text, &$parameters)
return true;
}

$mode = $this->parameters->def('mode', 1);
$mode = $this->parameters->get('mode', 1);

// any@email.address.com
$searchEmail = '([\w\.\-]+\@(?:[a-z0-9\.\-]+\.)+(?:[a-z0-9\-]{2,4}))';
@@ -6,7 +6,7 @@
* @license GNU General Public License Version 2, or later http://www.gnu.org/licenses/gpl.html
*/
defined('MOLAJO') or die; ?>
<tr class="row<?php echo $i % 2; ?>">
<tr class="row<?php echo $this->row->row_count % 2; ?>">
<?php
$count = 0;
foreach ($columnArray as $column) {
@@ -88,7 +88,7 @@ public static function copy($src, $dest, $path = null, $use_streams = false)

// Check src path
if (!is_readable($src)) {
JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_JFILE_FIND_COPY', $src));
JError::raiseWarning(21, Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_JFILE_FIND_COPY', $src));

return false;
}
@@ -97,7 +97,7 @@ public static function copy($src, $dest, $path = null, $use_streams = false)
$stream = JFactory::getStream();

if (!$stream->copy($src, $dest)) {
JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_JFILE_STREAMS', $src, $dest, $stream->getError()));
JError::raiseWarning(21, Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_JFILE_STREAMS', $src, $dest, $stream->getError()));

return false;
}
@@ -199,7 +199,7 @@ public static function delete($file)
else
{
$filename = basename($file);
JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('JLIB_FILESYSTEM_DELETE_FAILED', $filename));
JError::raiseWarning('SOME_ERROR_CODE', Services::Language()->sprintf('JLIB_FILESYSTEM_DELETE_FAILED', $filename));

return false;
}
@@ -237,7 +237,7 @@ public static function move($src, $dest, $path = '', $use_streams = false)
$stream = JFactory::getStream();

if (!$stream->move($src, $dest)) {
JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_JFILE_MOVE_STREAMS', $stream->getError()));
JError::raiseWarning(21, Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_JFILE_MOVE_STREAMS', $stream->getError()));

return false;
}
@@ -301,7 +301,7 @@ public static function read($filename, $incpath = false, $amount = 0, $chunksize
}

if (false === $fh = fopen($filename, 'rb', $incpath)) {
JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_READ_UNABLE_TO_OPEN_FILE', $filename));
JError::raiseWarning(21, Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_READ_UNABLE_TO_OPEN_FILE', $filename));

return false;
}
@@ -365,7 +365,7 @@ public static function write($file, &$buffer, $use_streams = false)
$stream->set('chunksize', (1024 * 1024 * 1024));

if (!$stream->writeFile($file, $buffer)) {
JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_WRITE_STREAMS', $file, $stream->getError()));
JError::raiseWarning(21, Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_WRITE_STREAMS', $file, $stream->getError()));
return false;
}

@@ -424,7 +424,7 @@ public static function upload($src, $dest, $use_streams = false)
$stream = JFactory::getStream();

if (!$stream->upload($src, $dest)) {
JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_UPLOAD', $stream->getError()));
JError::raiseWarning(21, Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_UPLOAD', $stream->getError()));
return false;
}

@@ -278,7 +278,7 @@ public static function delete($path)

// Is this really a folder?
if (!is_dir($path)) {
JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path));
JError::raiseWarning(21, Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path));
return false;
}

@@ -331,7 +331,7 @@ public static function delete($path)
}
else
{
JError::raiseWarning('SOME_ERROR_CODE', JText::sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_DELETE', $path));
JError::raiseWarning('SOME_ERROR_CODE', Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_DELETE', $path));
$ret = false;
}
return $ret;
@@ -369,7 +369,7 @@ public static function move($src, $dest, $path = '', $use_streams = false)
if ($use_streams) {
$stream = JFactory::getStream();
if (!$stream->move($src, $dest)) {
return JText::sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_RENAME', $stream->getError());
return Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_RENAME', $stream->getError());
}
$ret = true;
}
@@ -437,7 +437,7 @@ public static function files($path, $filter = '.', $recurse = false, $full = fal

// Is the path a folder?
if (!is_dir($path)) {
JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER_FILES', $path));
JError::raiseWarning(21, Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER_FILES', $path));
return false;
}

@@ -480,7 +480,7 @@ public static function folders($path, $filter = '.', $recurse = false, $full = f

// Is the path a folder?
if (!is_dir($path)) {
JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER_FOLDER', $path));
JError::raiseWarning(21, Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER_FOLDER', $path));
return false;
}

@@ -1138,13 +1138,13 @@ function copy($src, $dest, $context = null, $use_prefix = true, $relative = fals
else
{
@fclose($reader); // close the reader off
$php_errormsg = JText::sprintf('JLIB_FILESYSTEM_ERROR_STREAMS_FAILED_TO_OPEN_WRITER', $this->getError());
$php_errormsg = Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_STREAMS_FAILED_TO_OPEN_WRITER', $this->getError());
}
}
else
{
if (!$php_errormsg) {
$php_errormsg = JText::sprintf('JLIB_FILESYSTEM_ERROR_STREAMS_FAILED_TO_OPEN_READER', $this->getError());
$php_errormsg = Services::Language()->sprintf('JLIB_FILESYSTEM_ERROR_STREAMS_FAILED_TO_OPEN_READER', $this->getError());
}
}
}
@@ -0,0 +1,316 @@
<?php

/**
*
* @see http://code.google.com/p/php-console
* @author Barbushin Sergey http://linkedin.com/in/barbushin
* @version 1.1
*
* @desc Sending messages to Google Chrome console
*
* You need to install Google Chrome extension:
* https://chrome.google.com/extensions/detail/nfhmhhlpfleoednkpnnnkolmclajemef
*
* All class properties and methods are static because it's required to let
* them work on script shutdown when FATAL error occurs.
*
*/
class PhpConsole {

public static $ignoreRepeatedEvents = false;
public static $callOldErrorHandler = true;
public static $callOldExceptionsHandler = true;

/**
* @var PhpConsole
*/
protected static $instance;

protected $handledMessagesHashes = array();
protected $sourceBasePath;

protected function __construct($handleErrors, $handleExceptions, $sourceBasePath) {
if($handleErrors) {
$this->initErrorsHandler();
}
if($handleExceptions) {
$this->initExceptionsHandler();
}
if($sourceBasePath) {
$this->sourceBasePath = realpath($sourceBasePath);
}
$this->initClient();
}

public static function start($handleErrors = true, $handleExceptions = true, $sourceBasePath = null) {
if(!self::$instance) {
self::$instance = new PhpConsole($handleErrors, $handleExceptions, $sourceBasePath);
}
}

protected function handle(PhpConsoleEvent $event) {
if(self::$ignoreRepeatedEvents) {
$eventHash = md5($event->message . $event->file . $event->line);
if(in_array($eventHash, $this->handledMessagesHashes)) {
return;
}
else {
$this->handledMessagesHashes[] = $eventHash;
}
}
$this->sendEventToClient($event);
}

public function __destruct() {
self::flushMessagesBuffer();
}

/***************************************************************
CLIENT
**************************************************************/

const clientProtocolCookie = 'phpcslc';
const serverProtocolCookie = 'phpcsls';
const serverProtocol = 4;
const messagesCookiePrefix = 'phpcsl_';
const cookiesLimit = 50;
const cookieSizeLimit = 4000;
const messageLengthLimit = 2500;

protected static $isEnabledOnClient;
protected static $isDisabled;
protected static $messagesBuffer = array();
protected static $bufferLength = 0;
protected static $messagesSent = 0;
protected static $cookiesSent = 0;
protected static $index = 0;

protected function initClient() {
if(self::$isEnabledOnClient === null) {
self::setEnabledOnServer();
self::$isEnabledOnClient = self::isEnabledOnClient();
if(self::$isEnabledOnClient) {
ob_start();
}
}
}

protected static function isEnabledOnClient() {
return isset($_COOKIE[self::clientProtocolCookie]) && $_COOKIE[self::clientProtocolCookie] == self::serverProtocol;
}

protected static function setEnabledOnServer() {
if(!isset($_COOKIE[self::serverProtocolCookie]) || $_COOKIE[self::serverProtocolCookie] != self::serverProtocol) {
self::setCookie(self::serverProtocolCookie, self::serverProtocol);
}
}

protected function sendEventToClient(PhpConsoleEvent $event) {
if(!self::$isEnabledOnClient || self::$isDisabled) {
return;
}
$message = array();
$message['type'] = strpos($event->tags, 'error,') === 0 ? 'error' : 'debug';
$message['subject'] = $event->type;
$message['text'] = substr($event->message, 0, self::messageLengthLimit);

if($event->file) {
$message['source'] = ($this->sourceBasePath ? preg_replace('!^' . preg_quote($this->sourceBasePath, '!') . '!', '', $event->file) : $event->file) . ($event->line ? ':' . $event->line : '');
}
if($event->trace) {
$traceArray = $this->convertTraceToArray($event->trace, $event->file, $event->line);
if($traceArray) {
$message['trace'] = $traceArray;
}
}

self::pushMessageToBuffer($message);

if(strpos($event->tags, ',fatal')) {
self::flushMessagesBuffer();
}
}

protected function convertTraceToArray($traceData, $eventFile = null, $eventLine = null) {
$trace = array();
foreach($traceData as $call) {
if((isset($call['class']) && $call['class'] == __CLASS__) || (!$trace && isset($call['file']) && $call['file'] == $eventFile && $call['line'] == $eventLine)) {
$trace = array();
continue;
}
$args = array();
if(isset($call['args'])) {
foreach($call['args'] as $arg) {
if(is_object($arg)) {
$args[] = get_class($arg);
}
elseif(is_array($arg)) {
$args[] = 'Array';
}
else {
$arg = var_export($arg, 1);
$args[] = strlen($arg) > 12 ? substr($arg, 0, 8) . '...\'' : $arg;
}
}
}
if(isset($call['file']) && $this->sourceBasePath) {
$call['file'] = preg_replace('!^' . preg_quote($this->sourceBasePath, '!') . '!', '', $call['file']);
}
$trace[] = (isset($call['file']) ? ($call['file'] . ':' . $call['line']) : '[internal call]') . ' - ' . (isset($call['class']) ? $call['class'] . $call['type'] : '') . $call['function'] . '(' . implode(', ', $args) . ')';
}
$trace = array_reverse($trace);
foreach($trace as $i => &$call) {
$call = '#' . ($i + 1) . ' ' . $call;
}
return $trace;
}

protected static function pushMessageToBuffer($message) {
$encodedMessageLength = strlen(rawurlencode(json_encode($message)));
if(self::$bufferLength + $encodedMessageLength > self::cookieSizeLimit) {
self::flushMessagesBuffer();
}
self::$messagesBuffer[] = $message;
self::$bufferLength += $encodedMessageLength;
}

protected static function getNextIndex() {
return substr(number_format(microtime(1), 3, '', ''), -6) + self::$index++;
}

public static function flushMessagesBuffer() {
if(self::$messagesBuffer) {
self::sendMessages(self::$messagesBuffer);
self::$bufferLength = 0;
self::$messagesSent += count(self::$messagesBuffer);
self::$messagesBuffer = array();
self::$cookiesSent++;
if(self::$cookiesSent == self::cookiesLimit) {
self::$isDisabled = true;
$message = array('type' => 'error', 'subject' => 'PHP CONSOLE', 'text' => 'MESSAGES LIMIT EXCEEDED BECAUSE OF COOKIES STORAGE LIMIT. TOTAL MESSAGES SENT: ' . self::$messagesSent, 'source' => __FILE__, 'notify' => 3);
self::sendMessages(array($message));
}
}
}

protected static function setCookie($name, $value) {
if(headers_sent($file, $line)) {
throw new Exception('setcookie() failed because haders are sent (' . $file . ':' . $line . '). Try to use ob_start()');
}
setcookie($name, $value, null, '/');
}

protected static function sendMessages($messages) {
self::setCookie(self::messagesCookiePrefix . self::getNextIndex(), json_encode($messages));
}

/***************************************************************
ERRORS
**************************************************************/

protected $codesTags = array(E_ERROR => 'fatal', E_WARNING => 'warning', E_PARSE => 'fatal', E_NOTICE => 'notice', E_CORE_ERROR => 'fatal', E_CORE_WARNING => 'warning', E_COMPILE_ERROR => 'fatal', E_COMPILE_WARNING => 'warning', E_USER_ERROR => 'fatal', E_USER_WARNING => 'warning', E_USER_NOTICE => 'notice', E_STRICT => 'warning');
protected $codesNames = array(E_ERROR => 'E_ERROR', E_WARNING => 'E_WARNING', E_PARSE => 'E_PARSE', E_NOTICE => 'E_NOTICE', E_CORE_ERROR => 'E_CORE_ERROR', E_CORE_WARNING => 'E_CORE_WARNING', E_COMPILE_ERROR => 'E_COMPILE_ERROR', E_COMPILE_WARNING => 'E_COMPILE_WARNING', E_USER_ERROR => 'E_USER_ERROR', E_USER_WARNING => 'E_USER_WARNING', E_USER_NOTICE => 'E_USER_NOTICE', E_STRICT => 'E_STRICT');
protected $notCompitableCodes = array('E_RECOVERABLE_ERROR' => 'warning', 'E_DEPRECATED' => 'warning');
protected $oldErrorHandler;

protected function initErrorsHandler() {
ini_set('display_errors', false);
ini_set('html_errors', false);
ini_set('ignore_repeated_errors', self::$ignoreRepeatedEvents);
ini_set('ignore_repeated_source', self::$ignoreRepeatedEvents);

foreach($this->notCompitableCodes as $code => $tag) {
if(defined($code)) {
$this->codesTags[constant($code)] = $tag;
$this->codesNames[constant($code)] = $code;
}
}

$this->oldErrorHandler = set_error_handler(array($this, 'handleError'));
register_shutdown_function(array($this, 'checkFatalError'));
}

public function checkFatalError() {
$error = error_get_last();
if($error) {
$this->handleError($error['type'], $error['message'], $error['file'], $error['line']);
}
}

public function handleError($code = null, $message = null, $file = null, $line = null) {
if(error_reporting() == 0) { // if error has been supressed with an @
return;
}
if(!$code) {
$code = E_USER_ERROR;
}

$event = new PhpConsoleEvent();
$event->tags = 'error,' . (isset($this->codesTags[$code]) ? $this->codesTags[$code] : 'warning');
$event->message = $message;
$event->type = isset($this->codesNames[$code]) ? $this->codesNames[$code] : $code;
$event->file = $file;
$event->line = $line;
$event->trace = debug_backtrace();

$this->handle($event);

if(self::$callOldErrorHandler && $this->oldErrorHandler) {
call_user_func_array($this->oldErrorHandler, array($code, $message, $file, $line));
}
}

/***************************************************************
EXCEPTIONS
**************************************************************/

protected $oldExceptionsHandler;

protected function initExceptionsHandler() {
$this->oldExceptionsHandler = set_exception_handler(array($this, 'handleException'));
}

public function handleException(Exception $exception) {
$event = new PhpConsoleEvent();
$event->message = $exception->getMessage();
$event->tags = 'error,fatal,exception,' . get_class($exception);
$event->type = get_class($exception);
$event->file = $exception->getFile();
$event->line = $exception->getLine();
$event->trace = $exception->getTrace();

$this->handle($event);

// TODO: check if need to throw
if(self::$callOldExceptionsHandler && $this->oldExceptionsHandler) {
call_user_func($this->oldExceptionsHandler, $exception);
}
}

/***************************************************************
DEBUG
**************************************************************/

public static function debug($message, $tags = 'debug') {
if(self::$instance) {
$event = new PhpConsoleEvent();
$event->message = $message;
$event->tags = $tags;
$event->type = $tags;
self::$instance->handle($event);
}
}
}

class PhpConsoleEvent {
public $message;
public $type;
public $tags;
public $trace;
public $file;
public $line;
}

function debug($message, $tags = 'debug') {
PhpConsole::debug($message, $tags);
}
@@ -0,0 +1,13 @@
Release 1.1

Fixed: error in PHP < 5.3 syntax error, unexpected T_STATIC in PhpConsole.php on line 249
Fixed: PhpConsole::convertTraceToString for calls without arguments
Added: basePath stripping

Release 1.0

* Debug: Handle all exceptions and errors (even fatal)
* Added: Handle all exceptions and errors (even fatal)
* Added: Ignore repeated events when PhpConsole::$ignoreRepeatedEvents
* Added: Call previouse errors handler when PhpConsole::$callOldErrorHandler
* Added: Call previous exceptions handler when PhpConsole::$callOldExceptionsHandler
@@ -0,0 +1,24 @@
<?php

require_once('PhpConsole.php');
PhpConsole::start(true, true, dirname(__FILE__));

// test

debug('debug message');
debug('SELECT * FROM users', 'db');

class TestErrorBacktrace {
function __construct() {
$this->yeah(12, array());
}
function yeah() {
self::oops('some string', new stdClass());
}
static function oops() {
file_get_contents('oops.txt');
throw new Exception('Exception with call backtrace');
}
}

new TestErrorBacktrace();
@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.


This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.

0. Additional Definitions.

As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.

"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.

An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.

A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".

The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.

The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.

1. Exception to Section 3 of the GNU GPL.

You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.

2. Conveying Modified Versions.

If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:

a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or

b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.

3. Object Code Incorporating Material from Library Header Files.

The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:

a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the object code with a copy of the GNU GPL and this license
document.

4. Combined Works.

You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:

a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.

c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.

d) Do one of the following:

0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.

1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.

e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)

5. Combined Libraries.

You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:

a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.

b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.

6. Revised Versions of the GNU Lesser General Public License.

The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.

If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
@@ -0,0 +1,16 @@
Extra lightweight errors/exceptions/debugs handler for Google Chrome extension PHP Console

SVN/trunk:
http://lagger.googlecode.com/svn/trunk/PhpConsole

Project site:
http://code.google.com/p/php-console

Project updates by RSS:
http://code.google.com/feeds/p/php-console/updates/basic

Contact to developer (freelancer, looking for interesting web-projects):
http://linkedin.com/in/barbushin

PHP Console development donation:
http://web-grant.com/donation/php-console
@@ -60,6 +60,18 @@
$db = Services::Connect('jdb');

<?php
/*
* Debugging: Send message to Chrome Console
*
* To use, must use Chrome and install:
* https://chrome.google.com/webstore/detail/nfhmhhlpfleoednkpnnnkolmclajemef
*
*/

if (Services::Configuration()->get('debug', 0) == 1) {
debug('stuff goes here'.$includingVariables);
}

/*
* Application Configuration Object
*