Example #1
0
 /**
  *
  * @param Context $context
  * @param string $appName
  * @param bool $saveToUser
  */
 public function __construct($appName, $saveToUser = false)
 {
     $this->_context = Context::getInstance();
     $this->_saveToUser = $saveToUser;
     $this->_appName = $appName;
     if ($saveToUser) {
         $users = $this->_context->getUsersDatabase();
         $this->_user = $users->getUserName($saveToUser);
         if ($this->_user == null) {
             throw new NotAuthenticatedException("You have to be authenticated to access this feature");
         }
     }
     $oauthFile = new AnydatasetFilenameProcessor("_oauthclient10");
     $oauthAny = new AnyDataset($oauthFile->FullQualifiedNameAndPath());
     $itf = new IteratorFilter();
     $itf->addRelation("appname", Relation::EQUAL, $appName);
     $it = $oauthAny->getIterator($itf);
     if ($it->hasNext()) {
         $sr = $it->moveNext();
         $this->_consumer_key = $sr->getField("consumer_key");
         $this->_consumer_secret = $sr->getField("consumer_secret");
         $this->_className = $sr->getField("appclass");
         $this->_extraArgs = $sr->getFieldArray("extra_arg");
     } else {
         throw new InvalidArgumentException("Cant find OAuth AppName " . $appName);
     }
 }
Example #2
0
 /**
  *@param string $singlename
  *@return string
  *@desc Constructor
  */
 public function __construct($singlename)
 {
     if (strpos($singlename, "..") === false) {
         $this->_singlename = $singlename;
         $this->_context = Context::getInstance();
         $lang = $this->_context->Language();
         if ($lang != null) {
             $this->_languageid = strtolower($lang->getName());
         } else {
             $this->_languageid = 'en-us';
         }
         $this->_filenameLocation = ForceFilenameLocation::UseWhereExists;
     } else {
         throw new InvalidArgumentException("Invalid file name");
     }
 }
Example #3
0
 /**
  * This method is used only in the Wrappers
  * So, it can echo string directly
  *
  * @param type $buffer
  */
 public function SearchAndReplace($buffer)
 {
     $context = Context::getInstance();
     $posi = 0;
     $i = strpos($buffer, "<param-", $posi);
     while ($i !== false) {
         echo substr($buffer, $posi, $i - $posi);
         $if = strpos($buffer, "</param-", $i);
         $tamparam = $if - $i - 8;
         $var = substr($buffer, $i + 7, $tamparam);
         echo $context->get($var);
         $posi = $if + $tamparam + 9;
         $i = strpos($buffer, "<param-", $posi);
     }
     echo substr($buffer, $posi);
 }
Example #4
0
 /**
  * Set the proper Error Handler based on the Output of the page
  *
  * @param OutputData $output
  */
 public function setHandler($output)
 {
     $this->_whoops->popHandler();
     if ($output == OutputData::Json) {
         $this->_handler = new JsonResponseHandler();
     } else {
         if ($output == OutputData::Xml) {
             $this->_handler = new XmlResponseHandler();
         } else {
             $this->_handler = new PrettyPageHandler();
             if (!Context::getInstance()->getDevelopmentStatus()) {
                 $this->_handler->addResourcePath(\WhoopsResources\Resource::getPath());
             }
         }
     }
     $this->_whoops->pushHandler($this->_handler);
 }
Example #5
0
 public function Process()
 {
     /**
      * @var Context
      */
     $context = Context::getInstance();
     $name = $context->getVirtualCommand();
     if ($name == "") {
         $this->printHelp();
         // END
         exit;
     }
     require_once PHPXMLNUKEDIR . "src/Xmlnuke/Library/webservice/webservice.php";
     $className = '\\' . str_replace('.', '\\', $name);
     $rClass = new ReflectionClass($className);
     $class = $rClass->newInstance();
     if ($class instanceof \Services_Webservice) {
         $class->handle();
     } else {
         throw new InvalidArgumentException("Class '{$name}' is not a WebServices");
     }
 }
Example #6
0
 /**
  *
  * @param type $field
  * @param type $value
  * @return \ByJG\AnyDataset\Repository\SingleRow
  */
 public static function getInfoLocaleDB($field, $value)
 {
     if (self::$_localeData == null) {
         $file = new \Xmlnuke\Core\Processor\AnydatasetSetupFilenameProcessor('locale');
         self::$_localeData = new \ByJG\AnyDataset\Repository\AnyDataset($file->FullQualifiedNameAndPath());
     }
     if (!isset(self::$_localeDbCache[$field])) {
         $filter = new \ByJG\AnyDataset\Repository\IteratorFilter();
         $filter->addRelation($field, \ByJG\AnyDataset\Enum\Relation::CONTAINS, $value);
         $it = self::$_localeData->getIterator($filter);
         if ($it->hasNext()) {
             self::$_localeDbCache[$field] = $it->moveNext();
         } else {
             $sr = new \ByJG\AnyDataset\Repository\SingleRow();
             \Xmlnuke\Core\Engine\Context::getInstance()->WriteWarningMessage("The language {$value} was not found in locale.anydata.xml file");
             $sr->AddField('name', $value . ' ???');
             $sr->AddField('shortname', $value);
             self::$_localeDbCache[$field] = $sr;
         }
     }
     return self::$_localeDbCache[$field];
 }
Example #7
0
 /**
  *
  * @param Context $context
  * @param string $appName
  * @param bool $saveToUser
  */
 public function __construct($appName, $saveToUser = false)
 {
     $this->_context = Context::getInstance();
     $this->_saveToUser = $saveToUser;
     $this->_appName = $appName;
     if ($saveToUser) {
         $users = $this->_context->getUsersDatabase();
         $this->_user = $users->getUserName($saveToUser);
         if ($this->_user == null) {
             throw new NotAuthenticatedException("You need to be authenticated in order to save data into a existing user");
         }
     }
     $oauthFile = new AnydatasetFilenameProcessor("_oauthclient20");
     $oauthAny = new AnyDataset($oauthFile->FullQualifiedNameAndPath());
     $itf = new IteratorFilter();
     $itf->addRelation("appname", Relation::EQUAL, $appName);
     $it = $oauthAny->getIterator($itf);
     if ($it->hasNext()) {
         $sr = $it->moveNext();
         $this->_client_id = $sr->getField("client_id");
         $this->_client_secret = $sr->getField("client_secret");
         $this->_redirect_uri = $sr->getField("redirect_uri");
         $this->_scope = $sr->getField("scope") != "" ? $sr->getField("scope") : $this->_scope;
         $this->_window_top = $sr->getField("window_top") == "true";
         $this->_app_uri = $sr->getField("app_uri");
         $this->_className = $sr->getField("appclass");
         $this->_extraArgs = array();
         $tmpExtraArgs = $sr->getFieldArray("extra_arg");
         if (count($tmpExtraArgs) > 0) {
             foreach ($tmpExtraArgs as $value) {
                 $params = explode("=", $value);
                 $this->_extraArgs[$params[0]] = count($params) > 1 ? $params[1] : "";
             }
         }
     } else {
         throw new InvalidArgumentException("The OAuth 2.0 AppName " . $appName . " is not defined in _oauthclient20.anydata.xml file");
     }
 }
Example #8
0
 public function Process()
 {
     $context = Context::getInstance();
     /*
        You must have pass a parameter called CN.
        Example: chart.php?cn=NAME
     
        XmlNuke will Try load the class called "NAME" and execute the Method:
        getChartObject()
     */
     try {
         $cn = $context->get("cn");
         if ($cn != "") {
             $cn = '\\' . str_replace('.', '\\', $context->get("cn"));
             $chartObj = new $cn();
             $chart = $chartObj->getChartObject();
             //$chart = new \Xmlnuke\Core\Classes\ChartObject();
             $params = array();
             if ($chart->getChartType() == ChartType::Area) {
                 $params['cht'] = '1c';
             } else {
                 if ($chart->getChartType() == ChartType::Line) {
                     $params['cht'] = '1c';
                 } else {
                     if ($chart->getChartType() == ChartType::Pie && !$chart->getIs3d()) {
                         $params['cht'] = 'p';
                     } else {
                         if ($chart->getChartType() == ChartType::Pie && $chart->getIs3d()) {
                             $params['cht'] = 'p3';
                         } else {
                             if ($chart->getChartType() == ChartType::Donut) {
                                 $params['cht'] = 'p';
                             } else {
                                 if ($chart->getChartType() == ChartType::Bar) {
                                     $params['cht'] = 'bhg';
                                 } else {
                                     if ($chart->getChartType() == ChartType::Column) {
                                         $params['cht'] = 'bvg';
                                     } else {
                                         $params['cht'] = 'bvg';
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             /*
               The formula below is necessary because Google have a maximum limit of 480.000.
               This is basic rule of three
             
               R = W/H --> W = R*H
             
               Wo*Ho => (Wo*Ho)/10000
               R*H² => 30
                .
               . .
               H² = (30*Wo*Ho) / (R*((Wo*Ho)/10000))
             */
             $size = $chart->getWidth() * $chart->getHeight() / 10000;
             if ($size > 30) {
                 $ratio = $chart->getWidth() / $chart->getHeight();
                 $chart->setHeight(intval(sqrt(30 * $chart->getWidth() * $chart->getHeight() / ($ratio * $size))));
                 $chart->setWidth(intval($ratio * $chart->getHeight()));
             }
             $params['chs'] = $chart->getWidth() . 'x' . $chart->getHeight();
             $iter = $chart->getSerie();
             $params['chd'] = 't:';
             $data = array();
             foreach ($iter as $serie) {
                 if (!isset($params['chdl'])) {
                     $serieData = $serie->toArray();
                     unset($serieData['data_0']);
                     $params['chdl'] = implode('|', $serieData);
                 } else {
                     $serieData = $serie->toArray();
                     for ($i = 1; $i < count($serieData); $i++) {
                         if (!isset($data[$i])) {
                             $data[$i] = array();
                         }
                         $data[$i][] = $serieData["data_{$i}"];
                     }
                 }
             }
             foreach ($data as $itemData) {
                 $params['chd'] .= implode(',', $itemData) . "|";
             }
             $params['chd'] = substr($params['chd'], 0, strlen($params['chd']) - 1);
             $colors = array('#FFF8A3', '#A9CC8F', '#B2C8D9', '#BEA37A', '#F3AA79', '#B5B5A9', '#E6A5A4', '#F8D753', '#5C9746', '#3E75A7', '#7A653E', '#E1662A', '#74796F', '#C4384F', '#F0B400', '#1E6C0B', '#00488C', '#332600', '#D84000', '#434C43', '#B30023', '#FAE16B', '#82B16A', '#779DBF', '#907A52', '#EB8953', '#8A8D82', '#D6707B', '#F3C01C', '#3D8128', '#205F9A', '#63522B', '#DC5313', '#5D645A', '#BC1C39');
             $params['chco'] = str_replace('#', '', implode('|', $colors));
             $strParams = "";
             foreach ($params as $key => $value) {
                 $strParams .= $key . "=" . str_replace("'", "", $value) . "&";
             }
             $strParams .= 'chds=a';
             header("Content-Type: image/png");
             $imageData = file_get_contents('http://chart.apis.google.com/chart?cht=p3&chd=t:39,47,8,4,2&chs=380x180&chl=IE|Firefox|Chrome|Safari|Opera');
             echo $imageData;
         }
     } catch (Exception $ex) {
         echo "Chart Error: " . $ex->getMessage();
     }
 }
Example #9
0
 /**
  * Locate and create custom module if exists. Otherwise throw exception.
  *
  * Important:
  *   A module must reside on a folder named 'Modules'.
  *   You can call a module by \namespace\Modules\ModuleName or just \namespace\ModuleName
  *
  * @param string $modulename
  * @param object $o
  * @return IModule
  */
 public static function GetModule($modulename, $o = null)
 {
     $context = Context::getInstance();
     $basePath = "";
     $classNameAr = explode('.', $modulename);
     if (strpos($modulename, '.Modules.') === false) {
         array_splice($classNameAr, count($classNameAr) - 1, 0, array('Modules'));
     }
     $className = '\\' . implode('\\', $classNameAr);
     if (class_exists($className, true)) {
         $result = new $className();
     } else {
         throw new ModuleNotFoundException("Module \"{$modulename}\" not found");
     }
     if (!$result instanceof IModule) {
         throw new InvalidArgumentException('Class "' . $className . '" is not a IModule object');
     }
     // ----------------------------------------------------------
     // Activate the Module
     // ----------------------------------------------------------
     $xml = new XMLFilenameProcessor($modulename);
     $result->Setup($xml, $o);
     $urlSSL = "";
     $isHttps = $context->get("HTTPS") == "on" || $context->get("HTTP_X_FORWARDED_PROTO") == "https";
     $requireSSL = $result->requiresSSL();
     if ($requireSSL == SSLAccess::ForcePlain && $isHttps) {
         $urlSSL = "http://" . $context->get("HTTP_HOST") . $context->get("REQUEST_URI");
     } else {
         if ($requireSSL == SSLAccess::ForceSSL && !$isHttps) {
             $urlSSL = "https://" . $context->get("HTTP_HOST") . $context->get("REQUEST_URI");
         }
     }
     $output = $result->getOutputFormat();
     if ($output != null) {
         $context->setOutputFormat($output);
         ErrorHandler::getInstance()->setHandler($output);
     }
     if (strlen($urlSSL) > 0) {
         if ($context->get("REQUEST_METHOD") == "GET") {
             $context->redirectUrl($urlSSL);
         } else {
             echo "<html><body>";
             echo "<div style='font-family: arial; font-size: 14px; background-color: lightblue; line-height: 24px; width: 80px; text-align: center'>Switching...</div>";
             echo '<form action="' . $urlSSL . '" method="post">';
             foreach ($_POST as $key => $value) {
                 echo "<input type='hidden' name='{$key}' value='{$value}' />";
             }
             echo "<script language='JavaScript'>document.forms[0].submit()</script>";
             echo "</body></html>";
             die;
         }
     }
     if ($result->requiresAuthentication()) {
         if ($result->getAuthMode() == AuthMode::Form && !$context->IsAuthenticated()) {
             throw new NotAuthenticatedException("You need login to access this feature");
         } elseif ($result->getAuthMode() == AuthMode::HttpBasic) {
             $realm = 'Restricted area';
             if (empty($_SERVER['PHP_AUTH_USER'])) {
                 header('WWW-Authenticate: Basic realm="' . $realm . '"');
                 header('HTTP/1.0 401 Unauthorized');
                 die('You have to provide your credentials before proceed.');
             } else {
                 $usersDb = $context->getUsersDatabase();
                 $users = $usersDb->getUserName($_SERVER['PHP_AUTH_USER']);
                 if ($users == null) {
                     header('HTTP/1.1 403 Forbiden');
                     die('Wrong Credentials!');
                 }
                 $userTable = $usersDb->getUserTable();
                 // Check if Username and plain password is valid. If dont try to check if the SHA1 password is ok
                 if (!$usersDb->isValidUser($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
                     $password = $users->getField($userTable->Password);
                     if ($password != $_SERVER['PHP_AUTH_PW']) {
                         header('HTTP/1.1 403 Forbiden');
                         die('Wrong Credentials!');
                     }
                 }
                 $context->MakeLogin($users->getField($userTable->Username), $users->getField($userTable->Id));
             }
         } elseif ($result->getAuthMode() == AuthMode::HttpDigest) {
             $realm = 'Restricted area';
             if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
                 header('HTTP/1.1 401 Unauthorized');
                 header('WWW-Authenticate: Digest realm="' . $realm . '",qop="auth",nonce="' . uniqid() . '",opaque="' . md5($realm) . '"');
                 die('You have to provide your credentials before proceed.');
             }
             // analyze the PHP_AUTH_DIGEST variable
             if (!($data = self::httpDigestParse($_SERVER['PHP_AUTH_DIGEST'])) || !isset($data['username'])) {
                 die('Wrong Credentials!');
             }
             // Validate if the username and password are valid
             $usersDb = $context->getUsersDatabase();
             $users = $usersDb->getUserName($data['username']);
             if ($users == null) {
                 header('HTTP/1.1 403 Forbiden');
                 die('Wrong Credentials!');
             }
             $userTable = $usersDb->getUserTable();
             $password = $users->getField($userTable->Password);
             // generate the valid response
             $A1 = md5($data['username'] . ':' . $realm . ':' . $password);
             $A2 = md5($_SERVER['REQUEST_METHOD'] . ':' . $data['uri']);
             $valid_response = md5($A1 . ':' . $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $A2);
             if ($data['response'] != $valid_response) {
                 header('HTTP/1.1 403 Forbiden');
                 die('Wrong Credentials!');
             }
             // ok, valid username & password
             $context->MakeLogin($users->getField($userTable->Username), $users->getField($userTable->Id));
         }
         if (!$result->accessGranted()) {
             $result->processInsufficientPrivilege();
         }
     }
     return $result;
 }
Example #10
0
 /**
  *@param Context $context
  *@param XSLFilenameProcessor $file
  *@return void 
  *@desc SnippetProcessor constructor
  */
 public function __construct($file)
 {
     $this->_context = Context::getInstance();
     $this->_file = $file;
 }
Example #11
0
 /**
  *@param Context $context
  *@return void
  *@desc LanguageCollection Constructor
  */
 public function __construct()
 {
     $this->_context = Context::getInstance();
 }
Example #12
0
<?php

use Captcha\Captcha;
use Xmlnuke\Core\Engine\Context;
#############################################
# To create a XMLNuke capable PHP5 page
#
require_once "xmlnuke.inc.php";
#############################################
$context = Context::getInstance();
$cq = $context->get("xmlnuke.CAPTCHACHALLENGE") != "easy";
$c = intval($context->get("xmlnuke.CAPTCHALETTERS"));
$captcha = new Captcha($context, $cq, $c);
$captcha->show();
Example #13
0
 /**
  * @param XMLFilenameProcessor $xmlModuleName
  * @param Object $customArgs
  * @return void
  * @desc Add custom setup elements
  */
 public function Setup($xmlModuleName, $customArgs)
 {
     $this->_start = microtime(true);
     $this->_xmlModuleName = $xmlModuleName;
     $this->_context = Context::getInstance();
     $this->_cacheFile = new CacheFilenameProcessor($this->_xmlModuleName->ToString());
     $this->_action = $this->_context->get("action");
     if ($this->_action == "") {
         $this->_action = $this->_context->get("acao");
     }
     $this->CustomSetup($customArgs);
     $this->defaultXmlnukeDocument = new XmlnukeDocument();
     $this->_url = new XmlnukeManageUrl(URLTYPE::MODULE, $this->_xmlModuleName->ToString());
     $this->_moduleName = $this->_xmlModuleName->ToString();
 }
Example #14
0
 /**
  * @param string $duallistaname
  * @return string[]
  */
 public static function Parse($sortableName)
 {
     $context = Context::getInstance();
     $cols = $context->get($sortableName . "_columns");
     if ($cols == "") {
         return null;
     }
     $arCols = explode("|", $cols);
     $ret = array();
     foreach ($arCols as $col) {
         $value = $context->get($sortableName . "_" . $col);
         $ret[$col] = explode("|", $value);
     }
     return $ret;
 }
Example #15
0
 /**
  * Initialize a poll context
  * Use the method processData to process data.
  *
  * @param Context $context
  * @param string $urlProcess
  * @param string $poll
  * @param string $lang
  * @return XmlnukePoll
  */
 public function __construct($urlProcess, $poll, $lang = "")
 {
     $this->_context = Context::getInstance();
     $this->_url = $urlProcess;
     $this->_poll = $poll;
     if ($lang != "") {
         $this->_lang = $lang;
     } else {
         $this->_lang = $this->_context->Language()->getName();
     }
     $this->_processed = false;
     $this->getPollConfig();
     $this->_myWords = LanguageFactory::GetLanguageCollection(get_class());
 }
Example #16
0
 /**
  *
  * @return BaseProcessResult
  */
 protected function getProcessResult()
 {
     $context = Context::getInstance();
     $className = $context->get('xmlnuke.POST_PROCESS_RESULT');
     if (empty($className)) {
         $className = "\\Xmlnuke\\Core\\Processor\\BaseProcessResult";
     }
     $class = new $className();
     return $class;
 }