Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Code Inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Oct 21, 2015
1 parent 6b7566e commit 2c6b444
Show file tree
Hide file tree
Showing 25 changed files with 153 additions and 104 deletions.
4 changes: 1 addition & 3 deletions core/src/core/classes/class.AJXP_Cache.php
Expand Up @@ -27,8 +27,6 @@
*/
class AJXP_Cache
{
private static $instance;

protected $cacheDir;
protected $cacheId;
protected $masterFile;
Expand All @@ -39,7 +37,7 @@ class AJXP_Cache
* Create an AJXP_Cache instance
* @param string $pluginId
* @param string $filepath
* @param Function $dataCallback A function to generate the data cache. If no callback provided, will simply use the content of the master item as the cache data
* @param callable $dataCallback A function to generate the data cache. If no callback provided, will simply use the content of the master item as the cache data
* @param string $idComputerCallback A function to generate the ID of the cache. If not provided, will generate a random hash
* @return AJXP_Cache
*/
Expand Down
9 changes: 7 additions & 2 deletions core/src/core/classes/class.AJXP_Controller.php
Expand Up @@ -344,6 +344,7 @@ public static function runCommandInBackground($cmd, $logFile)
file_put_contents($tmpBat, $cmd);
pclose(popen('start /b "CLI" "'.$tmpBat.'"', 'r'));
}
return null;
} else {
$process = new UnixProcess($cmd, (AJXP_SERVER_DEBUG?$logFile:null));
AJXP_Logger::debug("Starting process and sending output dev null");
Expand All @@ -361,7 +362,7 @@ public static function runCommandInBackground($cmd, $logFile)
* @param array $httpVars
* @param array $fileVars
* @param bool $multiple
* @return DOMElement|bool
* @return DOMElement|bool|DOMElement[]
*/
private static function getCallbackNode($xPath, $actionNode, $query ,$actionName, $httpVars, $fileVars, $multiple = true)
{
Expand All @@ -387,7 +388,7 @@ private static function getCallbackNode($xPath, $actionNode, $query ,$actionName
* Check in the callback node if an applyCondition XML attribute exists, and eval its content.
* The content must set an $apply boolean as result
* @static
* @param DOMElement $callback
* @param DOMElement|DOMNode $callback
* @param string $actionName
* @param array $httpVars
* @param array $fileVars
Expand Down Expand Up @@ -441,6 +442,7 @@ private static function applyCallback($callback, &$actionName, &$httpVars, &$fil
} else {
throw new AJXP_Exception("Cannot find method $methodName for plugin $plugId!");
}
return null;
}

/**
Expand Down Expand Up @@ -471,6 +473,9 @@ public static function applyHook($hookName, $args, $forceNonDefer = false)
$callbacks = $xPath->query("hooks/serverCallback[@hookName='$hookName']");
if(!$callbacks->length) return ;
self::$hooksCache[$hookName] = array();
/**
* @var $callback DOMElement
*/
foreach ($callbacks as $callback) {
$defer = ($callback->getAttribute("defer") === "true");
$applyCondition = $callback->getAttribute("applyCondition");
Expand Down
4 changes: 2 additions & 2 deletions core/src/core/classes/class.AJXP_JSPacker.php
Expand Up @@ -31,10 +31,10 @@ class AJXP_JSPacker
* Static function for packing all js and css into big files
* Auto detect /js/*_list.txt files and /css/*_list.txt files and pack them.
*/
public function pack()
public static function pack()
{
// Make sure that the gui.* plugin is loaded
$plug = AJXP_PluginsService::getInstance()->getPluginsByType("gui");
AJXP_PluginsService::getInstance()->getPluginsByType("gui");

$sList = glob(CLIENT_RESOURCES_FOLDER."/js/*_list.txt");
foreach ($sList as $list) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/core/classes/class.AJXP_Node.php
Expand Up @@ -533,7 +533,7 @@ public function __get($varName)
* Magic setter for metadata
* @param $metaName
* @param $metaValue
* @return
* @return void
*/
public function __set($metaName, $metaValue)
{
Expand Down
5 changes: 3 additions & 2 deletions core/src/core/classes/class.AJXP_Plugin.php
Expand Up @@ -210,7 +210,7 @@ public function isEnabled()

/**
* Main function for loading all the nodes under registry_contributions.
* @return void
* @param bool $dry
*/
protected function loadRegistryContributions($dry = false)
{
Expand Down Expand Up @@ -265,7 +265,7 @@ protected function loadRegistryContributions($dry = false)
* @param string $xmlFile Path to the file from the base install path
* @param array $include XPath query for XML Nodes to include
* @param array $exclude XPath query for XML Nodes to exclude from the included ones.
* @return
* @param bool $dry Dry-run of the inclusion
*/
protected function initXmlContributionFile($xmlFile, $include=array("*"), $exclude=array(), $dry = false)
{
Expand Down Expand Up @@ -310,6 +310,7 @@ protected function initXmlContributionFile($xmlFile, $include=array("*"), $exclu
}
if(!count($selected)) return;
$originalRegContrib = $this->xPath->query("registry_contributions")->item(0);
$localRegParent = null;
foreach ($selected as $parentNodeName => $data) {
$node = $data["parent"]->cloneNode(false);
//$newNode = $originalRegContrib->ownerDocument->importNode($node, false);
Expand Down
21 changes: 16 additions & 5 deletions core/src/core/classes/class.AJXP_PluginsService.php
Expand Up @@ -216,6 +216,9 @@ public function softLoad($pluginId, $pluginOptions)
// Try to get from cache
list($type, $name) = explode(".", $pluginId);
if(!empty($this->registry) && isSet($this->registry[$type][$name])) {
/**
* @var AJXP_Plugin $plugin
*/
$plugin = $this->registry[$type][$name];
$plugin->init($pluginOptions);
return clone $plugin;
Expand Down Expand Up @@ -243,6 +246,9 @@ private function instanciatePluginClass($plugin)
$filename = AJXP_INSTALL_PATH."/".$definition["filename"];
$className = $definition["classname"];
if (is_file($filename)) {
/**
* @var AJXP_Plugin $newPlugin
*/
require_once($filename);
$newPlugin = new $className($plugin->getId(), $plugin->getBaseDir());
$newPlugin->loadManifest();
Expand All @@ -252,10 +258,10 @@ private function instanciatePluginClass($plugin)
return $plugin;
}
}

/**
* Check that a plugin dependencies are loaded, disable it otherwise.
* @param $arrayToSort
* @return
* @param AJXP_Plugin[] $arrayToSort
*/
private function checkDependencies(&$arrayToSort)
{
Expand Down Expand Up @@ -306,7 +312,6 @@ public static function sortByDependencyIds($pluginIdA, $pluginIdB)

public function getOrderByDependency($plugins, $withStatus = true)
{
$orders = array();
$keys = array();
$unkowns = array();
if ($withStatus) {
Expand Down Expand Up @@ -397,6 +402,9 @@ public function removePluginById($pluginId)
*/
public function initActivePlugins()
{
/**
* @var AJXP_Plugin $pObject
*/
$detected = $this->getDetectedPlugins();
$toActivate = array();
foreach ($detected as $pType => $pObjects) {
Expand Down Expand Up @@ -631,11 +639,12 @@ public static function getXmlRegistry($extendedVersion = true)
}
return $self->xmlRegistry;
}

/**
* Replace the current xml registry
* @static
* @param $registry
* @return void
* @param bool $extendedVersion
*/
public static function updateXmlRegistry($registry, $extendedVersion = true)
{
Expand Down Expand Up @@ -677,6 +686,8 @@ public function patchPluginWithMixin(&$plugin, &$manifestDoc, $mixinName)
* @param string $query
* @param string $stringOrNodeFormat
* @param boolean $limitToActivePlugins Whether to search only in active plugins or in all plugins
* @param bool $limitToEnabledPlugins
* @param bool $loadExternalFiles
* @return DOMNode[]
*/
public static function searchAllManifests($query, $stringOrNodeFormat = "string", $limitToActivePlugins = false, $limitToEnabledPlugins = false, $loadExternalFiles = false)
Expand Down Expand Up @@ -756,11 +767,11 @@ protected function mergeNodes(&$original, $parentName, $uuidAttr, $childrenNodes
}
}
}

/**
* Utilitary function
* @param $new
* @param $old
* @return
*/
protected function mergeChildByTagName($new, &$old)
{
Expand Down
1 change: 1 addition & 0 deletions core/src/core/classes/class.AJXP_ProgressBarCLI.php
Expand Up @@ -154,6 +154,7 @@ public function ago($time) {
$remain=$remain%3600;
$mins=intval($remain/60);
$secs=$remain%60;
$timestring = "-";

if ($secs>=0) $timestring = "0m".$secs."s";
if ($mins>0) $timestring = $mins."m".$secs."s";
Expand Down
2 changes: 1 addition & 1 deletion core/src/core/classes/class.AJXP_Role.php
Expand Up @@ -491,7 +491,7 @@ public function array_merge_recursive2($array1, $array2)
if (!is_array($arrays[$i])) {
// also array_merge_recursive returns nothing in this case
trigger_error('Argument #' . ($i+1) . ' is not an array - trying to merge array with scalar! Returning null!', E_USER_WARNING);
return;
return null;
}
}

Expand Down
59 changes: 20 additions & 39 deletions core/src/core/classes/class.AJXP_Utils.php
Expand Up @@ -77,7 +77,7 @@ public static function natksort(&$array)
*/
public static function natkrsort(&$array)
{
natksort($array);
AJXP_Utils::natksort($array);
$array = array_reverse($array, TRUE);
return true;
}
Expand Down Expand Up @@ -610,6 +610,7 @@ public static function getImageMimeType($fileName)
} else if (preg_match("/\.gif$/i", $fileName)) {
return "image/gif";
}
return "";
}
/**
* Headers to send when streaming
Expand Down Expand Up @@ -1047,7 +1048,9 @@ public function prettyPrintJSON($json)
public static function extractConfStringsFromManifests()
{
$plugins = AJXP_PluginsService::getInstance()->getDetectedPlugins();
$plug = new AJXP_Plugin("", "");
/**
* @var AJXP_Plugin $plug
*/
foreach ($plugins as $pType => $plugs) {
foreach ($plugs as $plug) {
$lib = $plug->getManifestRawContent("//i18n", "nodes");
Expand Down Expand Up @@ -1110,7 +1113,6 @@ public static function updateAllI18nLibraries($createLanguage = "")
* @param $baseDir
* @param bool $detectLanguages
* @param string $createLanguage
* @return
*/
public static function updateI18nFiles($baseDir, $detectLanguages = true, $createLanguage = "")
{
Expand All @@ -1128,6 +1130,7 @@ public static function updateI18nFiles($baseDir, $detectLanguages = true, $creat
$filenames = glob($baseDir . "/*.php");
}

$mess = array();
include($baseDir . "/en.php");
$reference = $mess;

Expand All @@ -1141,11 +1144,11 @@ public static function updateI18nFiles($baseDir, $detectLanguages = true, $creat
* @static
* @param $filename
* @param $reference
* @return
*/
public static function updateI18nFromRef($filename, $reference)
{
if (!is_file($filename)) return;
$mess = array();
include($filename);
$missing = array();
foreach ($reference as $messKey => $message) {
Expand Down Expand Up @@ -1253,6 +1256,7 @@ public static function runTests(&$outputArray, &$testedParams)
}
// PREPARE REPOSITORY LISTS
$repoList = array();
$REPOSITORIES = array();
require_once("../classes/class.ConfService.php");
require_once("../classes/class.Repository.php");
include(AJXP_CONF_PATH . "/bootstrap_repositories.php");
Expand Down Expand Up @@ -1330,6 +1334,7 @@ public static function isStream($path)
*
* @param String $filePath Full path to the file
* @param Boolean $skipCheck do not test for file existence before opening
* @param string $format
* @return Array
*/
public static function loadSerialFile($filePath, $skipCheck = false, $format="ser")
Expand Down Expand Up @@ -1359,11 +1364,15 @@ public static function loadSerialFile($filePath, $skipCheck = false, $format="se
* @param Array|Object $value The value to store
* @param Boolean $createDir Whether to create the parent folder or not, if it does not exist.
* @param bool $silent Silently write the file, are throw an exception on problem.
* @param string $format
* @param string $format "ser" or "json"
* @param bool $jsonPrettyPrint If json, use pretty printing
* @throws Exception
*/
public static function saveSerialFile($filePath, $value, $createDir = true, $silent = false, $format="ser", $jsonPrettyPrint = false)
{
if(!in_array($format, array("ser", "json"))){
throw new Exception("Unsupported serialization format: ".$format);
}
$filePath = AJXP_VarsFilter::filter($filePath);
if ($createDir && !is_dir(dirname($filePath))) {
@mkdir(dirname($filePath), 0755, true);
Expand All @@ -1375,8 +1384,9 @@ public static function saveSerialFile($filePath, $value, $createDir = true, $sil
}
try {
$fp = fopen($filePath, "w");
if($format == "ser") $content = serialize($value);
else if ($format == "json") {
if($format == "ser") {
$content = serialize($value);
} else {
$content = json_encode($value);
if($jsonPrettyPrint) $content = self::prettyPrintJSON($content);
}
Expand All @@ -1395,8 +1405,6 @@ public static function saveSerialFile($filePath, $value, $createDir = true, $sil
*/
public static function userAgentIsMobile()
{
$isMobile = false;

$op = strtolower($_SERVER['HTTP_X_OPERAMINI_PHONE'] OR "");
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$ac = strtolower($_SERVER['HTTP_ACCEPT']);
Expand Down Expand Up @@ -1445,34 +1453,6 @@ public static function userAgentIsMobile()
|| strpos($ua, 'vodafone/') !== false
|| strpos($ua, 'wap1.') !== false
|| strpos($ua, 'wap2.') !== false;
/*
$isBot = false;
$ip = $_SERVER['REMOTE_ADDR'];
$isBot = $ip == '66.249.65.39'
|| strpos($ua, 'googlebot') !== false
|| strpos($ua, 'mediapartners') !== false
|| strpos($ua, 'yahooysmcm') !== false
|| strpos($ua, 'baiduspider') !== false
|| strpos($ua, 'msnbot') !== false
|| strpos($ua, 'slurp') !== false
|| strpos($ua, 'ask') !== false
|| strpos($ua, 'teoma') !== false
|| strpos($ua, 'spider') !== false
|| strpos($ua, 'heritrix') !== false
|| strpos($ua, 'attentio') !== false
|| strpos($ua, 'twiceler') !== false
|| strpos($ua, 'irlbot') !== false
|| strpos($ua, 'fast crawler') !== false
|| strpos($ua, 'fastmobilecrawl') !== false
|| strpos($ua, 'jumpbot') !== false
|| strpos($ua, 'googlebot-mobile') !== false
|| strpos($ua, 'yahooseeker') !== false
|| strpos($ua, 'motionbot') !== false
|| strpos($ua, 'mediobot') !== false
|| strpos($ua, 'chtml generic') !== false
|| strpos($ua, 'nokia6230i/. fast crawler') !== false;
*/
return $isMobile;
}
/**
Expand Down Expand Up @@ -1756,6 +1736,7 @@ public static function parseStandardFormParameters(&$repDef, &$options, $userId
}
// DO SOMETHING WITH REPLICATED PARAMETERS?
if (count($switchesGroups)) {
$gValues = array();
foreach ($switchesGroups as $fieldName => $groupName) {
if (isSet($options[$fieldName])) {
$gValues = array();
Expand Down Expand Up @@ -2082,11 +2063,11 @@ public static function regexpToLdap($regexp)
}
return $left.$regexp.$right;
}

/**
* Hide file or folder for Windows OS
* @static
* @param $path
* @return void
* @param $file
*/
public static function winSetHidden($file)
{
Expand Down

0 comments on commit 2c6b444

Please sign in to comment.