/**
	 * Returns an object that is a child of the FTPClient class or null on failure.
	 */
	public static function initializeFTP() {
		if (self::$ftp === null && Config::get('base.ftp.enabled') == true) {
			self::$ftp = FTPClient::getObject();
			$data = Config::get('base.ftp');
			if (self::$ftp !== null && self::$ftp->setServer($data['host'], $data['port']) !== true) {
				self::$debug->addText('Could not set ftp server to ...');
				self::$ftp = null;
			}
			if (self::$ftp !== null && self::$ftp->connect() !== true) {
				self::$debug->addText('Could not connect to ftp server');
				self::$ftp->quit();
				self::$ftp = null;
			}
			if (self::$ftp !== null && self::$ftp->login($data['username'], $data['password']) !== true) {
				self::$debug->addText('Could not login on ftp server with user data ...');
				self::$ftp->quit();
				self::$ftp = null;
			}
			if (self::$ftp !== null && self::$ftp->chdir($data['directory']) !== true) {
				self::$debug->addText('Could not change directory on ftp server to ...');
				self::$ftp->quit();
				self::$ftp = null;
			}
		}
		return self::$ftp;
	}
Example #2
0
 public function DisableModule()
 {
     $database = Mysql::getConnection();
     $database->Query("UPDATE " . TABLE_PREFIX . "modules SET moduleStatus='0' WHERE moduleId='{$this->moduleId}';");
     $debug = new Debug();
     $debug->debugMessage = Lang::$langData['moduleDisabled'] . " ({$this->moduleName})";
     $debug->debugType = 0;
     $debug->StartDebug();
 }
Example #3
0
 public static function SystemStop()
 {
     $stoppedFrom = debug_backtrace();
     $stoppedFile = $stoppedFrom[0]['file'];
     $debug = new Debug();
     $debug->debugMessage = 'System has been stopped from file: ' . $stoppedFile;
     $debug->StartDebug();
     die("System has been stopped, check your debug!");
 }
Example #4
0
 public static function Install($template)
 {
     require_once ABS_PATH . '/temp/' . $template . '/install.php';
     $database = Mysql::getConnection();
     $database->Query("INSERT INTO " . TABLE_PREFIX . "templates VALUES ('', '" . $installData['templateName'] . "', '" . $installData['templateAuthor'] . "', '" . $installData['templateVersion'] . "', '0','" . $installData['templateDescription'] . "');");
     $debug = new Debug();
     $debug->debugType = 0;
     $debug->debugMessage = Lang::$langData['installTemplate'] . " (" . $template . ")";
     $debug->StartDebug();
 }
 /**
  * Send emails - Note: properties must be set before calling this function
  */
 public function doEmail()
 {
     if (!$this->body) {
         return false;
     }
     if (!$this->to) {
         $this->to = SITE_NAME . ' <' . SITE_EMAIL . '>';
     }
     if (!$this->from) {
         $this->from = SITE_NAME . ' <' . SITE_EMAIL . '>';
     }
     if (SMTP == 'true') {
         // note: this overwrites headers passed to this function:
         if (is_array($this->to)) {
             $to = $this->to['To'];
         } else {
             $to = $this->to;
         }
         $this->headers = array('From' => $this->from, 'To' => $to, 'Subject' => $this->subject);
     } else {
         // if not using SMTP and no headers passed to this function, use default
         if (!$this->headers) {
             $this->headers = "From: " . $this->from . "\r\nReply-To: " . SITE_EMAIL . "\r\nX-Priority: 3\r\n";
         }
     }
     switch ($this->type) {
         case 'log':
             require_once LIBS . 'Debug.php';
             $debug = new Debug();
             $debug->openLog('email_log', 'a+');
             $content = $this->headers . "\r\n" . $this->to . "\r\n" . $this->subject . "\r\n" . $this->body . "\r\n\r\n";
             $content .= "**************************************************************\r\n\r\n";
             $debug->writeLog('email_log', $content);
             $debug->closeLog('email_log');
             break;
         case 'screen':
             echo "Headers: " . $this->headers . "<br /><br />";
             echo "To: " . $this->to . "<br /><br />";
             echo "Subject: " . $this->subject . "<br /><br />";
             $this->body = nl2br($this->body);
             echo "Body: " . $this->body . "<br /><br />";
             break;
         case 'return':
             return array('headers' => $this->headers, 'to' => $this->to, 'subject' => $this->subject, 'body' => $this->body, 'type' => $this->type);
             break;
         default:
             if (SMTP == 'true') {
                 $this->doSmtpEmail();
             } else {
                 mail($this->to, $this->subject, $this->body, $this->headers);
             }
     }
 }
Example #6
0
 public function SaveConfig()
 {
     $filename = ABS_PATH . '/config.php';
     //if(file_exists($filename))unlink($filename);
     $configData = "<?php" . PHP_EOL . "/*" . PHP_EOL . " *\t@author: Tomáš Mičulka" . PHP_EOL . " *\t@version: 2.0" . PHP_EOL . " *\t@last_update: 6.1.2014 " . PHP_EOL . " */" . PHP_EOL . "defined('IN_INNE') or die('Acces denied!');" . PHP_EOL . "" . PHP_EOL . "//Database config" . PHP_EOL . "define('DB_HOST', '{$this->dbHost}');" . PHP_EOL . "define('DB_USER', '{$this->dbUser}');" . PHP_EOL . "define('DB_PASS', '{$this->dbPass}');" . PHP_EOL . "define('DB_NAME', '{$this->dbName}');" . PHP_EOL . "define('DB_VERSION', '{$this->dbVersion}');" . PHP_EOL . "define('TABLE_PREFIX', '{$this->tablePrefix}');" . PHP_EOL . "" . PHP_EOL . "//System config" . PHP_EOL . "define('SYS_LANG', '{$this->sysLang}');" . PHP_EOL . "define('SYS_DEBUG', '{$this->sysDebug}');" . PHP_EOL . "define('DEBUG_FILE', '{$this->sysDebugFile}');" . PHP_EOL . "define('SYS_TEMP', '{$this->webTemplate}');" . PHP_EOL . "define('ADM_VER', '{$this->sysAdmVer}');" . PHP_EOL . "define('ERROR_LEVEL', '{$this->sysErrorLevel}');" . PHP_EOL . "error_reporting({$this->sysErrorLevel});" . PHP_EOL . "define('GET_UPDATE', '{$this->update}');" . PHP_EOL . "define('USING_EXTERN', '{$this->extern}');" . PHP_EOL . "define('ABS_PATH', dirname(__FILE__));" . PHP_EOL . "" . PHP_EOL . "//Website config" . PHP_EOL . "define('WEBSITE_NAME', '{$this->webTitle}');" . PHP_EOL . "define('WEBSITE_DESCRIPTION', '{$this->webDescription}');" . PHP_EOL . "define('WEBSITE_AUTHOR', '{$this->webAuthor}');" . PHP_EOL . "define('WEBSITE_KEYWORDS', '{$this->webKeywords}');" . PHP_EOL . "define('WEBSITE_DEFAULT_PAGE', '{$this->webDefaultPage}');" . PHP_EOL . "define('WEBSITE_ADDRESS', '{$this->webAddress}');" . PHP_EOL . "";
     $file = fopen($filename, "w+");
     file_put_contents($filename, $configData);
     fclose($file);
     $debug = new Debug();
     $debug->debugType = 0;
     $debug->debugMessage = Lang::$langData["debugChangeConfig"];
     $debug->StartDebug();
 }
Example #7
0
 public function fetchPayablesList($showFilter = self::FILTER_ACTIVE, $fromDate = null, $toDate = null, $supplierId = null)
 {
     $this->db->select('ie.*, s.supplierId, s.name as supplierName, i.itemId, i.description as itemDescription, i.productCode as itemProductCode')->from('ItemExpense ie')->join('Supplier s', 'ie.supplierId=s.supplierId', 'left')->join('Item i', 'i.itemId = ie.itemId')->where('ie.isCredit = 1');
     switch ($showFilter) {
         case self::FILTER_PAID:
             $this->db->where('ie.isFullyPaid = 1');
             break;
         default:
             $this->db->where('ie.isFullyPaid = 0');
             break;
     }
     if (!empty($fromDate) && !empty($toDate)) {
         $this->db->where('DATE(ie.dateAdded) >= ', $fromDate);
         $this->db->where('DATE(ie.dateAdded) <= ', $toDate);
     } elseif (!empty($fromDate) && empty($toDate)) {
         $this->db->where('DATE(ie.dateAdded) >= ', $fromDate);
         $this->db->where('DATE(ie.dateAdded) <= ', date('Y-m-d'));
     } elseif (empty($fromDate) && !empty($toDate)) {
         $this->db->where('DATE(ie.dateAdded) <= ', $toDate);
     }
     if (!empty($supplierId)) {
         $this->db->where('ie.supplierId', $supplierId);
     }
     $query = $this->db->get();
     Debug::log($this->db->last_query());
     return $query->result_array();
 }
Example #8
0
 public function action_index()
 {
     if (!file_exists(DOCROOT . $this->sitemap_directory_base)) {
         throw new HTTP_Exception_404();
     }
     $this->site_code = ORM::factory('site', $this->request->site_id)->code;
     $this->sitemap_directory = $this->sitemap_directory_base . DIRECTORY_SEPARATOR . $this->site_code;
     $this->response->headers('Content-Type', 'text/xml')->headers('cache-control', 'max-age=0, must-revalidate, public')->headers('expires', gmdate('D, d M Y H:i:s', time()) . ' GMT');
     try {
         $dir = new DirectoryIterator(DOCROOT . $this->sitemap_directory);
         $xml = new DOMDocument('1.0', Kohana::$charset);
         $xml->formatOutput = TRUE;
         $root = $xml->createElement('sitemapindex');
         $root->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
         $xml->appendChild($root);
         foreach ($dir as $fileinfo) {
             if ($fileinfo->isDot() or $fileinfo->isDir()) {
                 continue;
             }
             $_file_path = str_replace(DOCROOT, '', $fileinfo->getPathName());
             $_file_url = $this->domain . '/' . str_replace(DIRECTORY_SEPARATOR, '/', $_file_path);
             $sitemap = $xml->createElement('sitemap');
             $root->appendChild($sitemap);
             $sitemap->appendChild(new DOMElement('loc', $_file_url));
             $_last_mod = Sitemap::date_format($fileinfo->getCTime());
             $sitemap->appendChild(new DOMElement('lastmod', $_last_mod));
         }
     } catch (Exception $e) {
         echo Debug::vars($e->getMessage());
         die;
     }
     echo $xml->saveXML();
 }
Example #9
0
 function display($resource_name = null, $cache_id = null, $compile_id = null)
 {
     if (is_null($resource_name)) {
         $resource_name = "{$_GET["m"]}/{$_GET["a"]}" . C('TPL_SUFFIX');
     } else {
         if (strstr($resource_name, "/")) {
             $resource_name = $resource_name . C('TPL_SUFFIX');
         } else {
             $resource_name = $_GET["m"] . "/" . $resource_name . C('TPL_SUFFIX');
         }
     }
     $tplpath = rtrim(C('TPL_DIR'), '/') . '/' . $resource_name;
     if (!file_exists($tplpath)) {
         if (C('DEBUG')) {
             Debug::addmsg("<font style='color:red'>当前访问的模板文件:  {$tplpath} 不存在</font>");
         } else {
             $this->error('抱歉, 访问的页面不存在!');
         }
     } else {
         if (C('DEBUG')) {
             Debug::addmsg("当前访问的模板文件: {$tplpath}");
         }
         //预定义目录
         $root = rtrim(substr(C('PRO_PATH'), strlen(rtrim($_SERVER["DOCUMENT_ROOT"], "/\\"))), '/\\');
         $resource = rtrim(dirname($_SERVER["SCRIPT_NAME"]), "/\\") . '/' . ltrim(C('APP_PATH'), './') . "/View/" . C('TPL_STYLE') . "/Resource/";
         $url = $_SERVER['SCRIPT_NAME'] . '/' . $_GET['m'];
         $this->assign('root', $root);
         $this->assign('public', $root . '/Public');
         $this->assign('res', $resource);
         $this->assign('url', $url);
         parent::display($resource_name, $cache_id, $compile_id);
     }
 }
Example #10
0
    public function query($sql, $errorLevel = E_USER_ERROR)
    {
        if (isset($_REQUEST['previewwrite']) && in_array(strtolower(substr($sql, 0, strpos($sql, ' '))), array('insert', 'update', 'delete', 'replace'))) {
            Debug::message("Will execute: {$sql}");
            return;
        }
        if (isset($_REQUEST['showqueries'])) {
            $starttime = microtime(true);
        }
        // @todo This is a very ugly hack to rewrite the update statement of SiteTree::doPublish()
        // @see SiteTree::doPublish() There is a hack for MySQL already, maybe it's worth moving this to SiteTree or that other hack to Database...
        if (preg_replace('/[\\W\\d]*/i', '', $sql) == 'UPDATESiteTree_LiveSETSortSiteTreeSortFROMSiteTreeWHERESiteTree_LiveIDSiteTreeIDANDSiteTree_LiveParentID') {
            preg_match('/\\d+/i', $sql, $matches);
            $sql = 'UPDATE "SiteTree_Live"
				SET "Sort" = (SELECT "SiteTree"."Sort" FROM "SiteTree" WHERE "SiteTree_Live"."ID" = "SiteTree"."ID")
				WHERE "ParentID" = ' . $matches[0];
        }
        @($handle = $this->dbConn->query($sql));
        if (isset($_REQUEST['showqueries'])) {
            $endtime = round(microtime(true) - $starttime, 4);
            Debug::message("\n{$sql}\n{$endtime}ms\n", false);
        }
        DB::$lastQuery = $handle;
        if (!$handle && $errorLevel) {
            $msg = $this->dbConn->errorInfo();
            $this->databaseError("Couldn't run query: {$sql} | " . $msg[2], $errorLevel);
        }
        return new SQLitePDOQuery($this, $handle);
    }
Example #11
0
/**
 * Debug::dump shortcut.
 */
function dump($var)
{
    foreach (func_get_args() as $arg) {
        Debug::dump($arg);
    }
    return $var;
}
 public static function inspect($obj, $die = true)
 {
     \Debug::dump($obj);
     if ($die) {
         die;
     }
 }
Example #13
0
 public function action_index()
 {
     // Statusモデルから結果を取得する
     $results = Model_Status::find_body_by_username('foo');
     // $resultsをダンプして確認する
     Debug::dump($results);
 }
 public function output()
 {
     // TODO: Refactor into a content-type option
     if (\Director::is_ajax()) {
         return $this->friendlyErrorMessage;
     } else {
         // TODO: Refactor this into CMS
         if (class_exists('ErrorPage')) {
             $errorFilePath = \ErrorPage::get_filepath_for_errorcode($this->statusCode, class_exists('Translatable') ? \Translatable::get_current_locale() : null);
             if (file_exists($errorFilePath)) {
                 $content = file_get_contents($errorFilePath);
                 if (!headers_sent()) {
                     header('Content-Type: text/html');
                 }
                 // $BaseURL is left dynamic in error-###.html, so that multi-domain sites don't get broken
                 return str_replace('$BaseURL', \Director::absoluteBaseURL(), $content);
             }
         }
         $renderer = \Debug::create_debug_view();
         $output = $renderer->renderHeader();
         $output .= $renderer->renderInfo("Website Error", $this->friendlyErrorMessage, $this->friendlyErrorDetail);
         if (\Email::config()->admin_email) {
             $mailto = \Email::obfuscate(\Email::config()->admin_email);
             $output .= $renderer->renderParagraph('Contact an administrator: ' . $mailto . '');
         }
         $output .= $renderer->renderFooter();
         return $output;
     }
 }
Example #15
0
 public static function save(array $file, $filename = NULL, $directory = NULL, $chmod = 0644)
 {
     if (!isset($file['tmp_name']) or !is_uploaded_file($file['tmp_name'])) {
         return FALSE;
     }
     if ($filename === NULL) {
         $filename = uniqid() . $file['name'];
     }
     if (Upload::$remove_spaces === TRUE) {
         $filename = preg_replace('/\\s+/', '_', $filename);
     }
     if ($directory === NULL) {
         $directory = Upload::$default_directory;
     }
     if (!is_dir($directory) or !is_writable(realpath($directory))) {
         throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Debug::path($directory)));
     }
     $filename = realpath($directory) . DIRECTORY_SEPARATOR . $filename;
     if (move_uploaded_file($file['tmp_name'], $filename)) {
         if ($chmod !== FALSE) {
             chmod($filename, $chmod);
         }
         return $filename;
     }
     return FALSE;
 }
Example #16
0
 /**
  *
  * @return array
  */
 public function validate_authorize_params()
 {
     $request_params = $this->_get_authorize_params();
     $validation = Validation::factory($request_params)->rule('client_id', 'not_empty')->rule('client_id', 'uuid::valid')->rule('response_type', 'not_empty')->rule('response_type', 'in_array', array(':value', OAuth2::$supported_response_types))->rule('scope', 'in_array', array(':value', OAuth2::$supported_scopes))->rule('redirect_uri', 'url');
     if (!$validation->check()) {
         throw new OAuth2_Exception_InvalidRequest("Invalid Request: " . Debug::vars($validation->errors()));
     }
     // Check we have a valid client
     $client = Model_OAuth2_Client::find_client($request_params['client_id']);
     if (!$client->loaded()) {
         throw new OAuth2_Exception_InvalidClient('Invalid client');
     }
     // Lookup the redirect_uri if none was supplied in the URL
     if (!Valid::url($request_params['redirect_uri'])) {
         $request_params['redirect_uri'] = $client->redirect_uri;
         // Is the redirect_uri still empty? Error if so..
         if (!Valid::url($request_params['redirect_uri'])) {
             throw new OAuth2_Exception_InvalidRequest('\'redirect_uri\' is required');
         }
     } else {
         if ($client->redirect_uri != $request_params['redirect_uri']) {
             throw new OAuth2_Exception_InvalidGrant('redirect_uri mismatch');
         }
     }
     // Check if this client is allowed use this response_type
     if (!in_array($request_params['response_type'], $client->allowed_response_types())) {
         throw new OAuth2_Exception_UnauthorizedClient('You are not allowed use the \':response_type\' response_type', array(':response_type' => $request_params['response_type']));
     }
     return $request_params;
 }
Example #17
0
 function getStateTaxPayable()
 {
     //Arizona is a percent of federal tax rate.
     //However after 01-Jul-10 it changed to a straight percent of gross.
     $annual_income = $this->getAnnualTaxableIncome();
     $rate = $this->getUserValue1();
     Debug::text('Raw Rate: ' . $rate, __FILE__, __LINE__, __METHOD__, 10);
     //Because of the change from a percent of federal rate to a gross rate,
     //add some checks so if an employee's amount isn't changed we default to the closest rate.
     if ($rate >= 39.5) {
         $rate = 5.1;
     } elseif ($rate >= 33.1) {
         $rate = 4.2;
     } elseif ($rate >= 26.7) {
         $rate = 3.6;
     } elseif ($rate >= 24.5) {
         $rate = 2.7;
     } elseif ($rate >= 20.3) {
         $rate = 1.8;
     } elseif ($rate >= 10.7) {
         $rate = 1.3;
     }
     Debug::text(' Adjusted Rate: ' . $rate, __FILE__, __LINE__, __METHOD__, 10);
     $retval = bcmul($annual_income, bcdiv($rate, 100));
     if ($retval < 0) {
         $retval = 0;
     }
     Debug::text('State Annual Tax Payable: ' . $retval, __FILE__, __LINE__, __METHOD__, 10);
     return $retval;
 }
Example #18
0
 /**
  * Log stacktrace + optional message to debug bar
  *
  * @param string $ps_message Optional message to prefix stacktrace with
  */
 public static function isEnabled()
 {
     if (is_null(Debug::$debugEnabled)) {
         Debug::$debugEnabled = defined('__CA_ENABLE_DEBUG_OUTPUT__') && __CA_ENABLE_DEBUG_OUTPUT__;
     }
     return Debug::$debugEnabled;
 }
Example #19
0
 /**
  * Layout Page Logic
  * @return 
  * @param $db Object
  */
 function __construct(database $db, user $user)
 {
     $this->db =& $db;
     $this->user =& $user;
     $this->sub_page = Kit::GetParam('sp', _GET, _WORD, 'view');
     $this->layoutid = Kit::GetParam('layoutid', _REQUEST, _INT);
     // If we have modify selected then we need to get some info
     if ($this->layoutid != '') {
         // get the permissions
         Debug::LogEntry('audit', 'Loading permissions for layoutid ' . $this->layoutid);
         $this->auth = $user->LayoutAuth($this->layoutid, true);
         if (!$this->auth->edit) {
             trigger_error(__("You do not have permissions to edit this layout"), E_USER_ERROR);
         }
         $this->sub_page = "edit";
         $sql = " SELECT layout, description, userid, retired, xml FROM layout ";
         $sql .= sprintf(" WHERE layoutID = %d ", $this->layoutid);
         if (!($results = $db->query($sql))) {
             trigger_error($db->error());
             trigger_error(__("Cannot retrieve the Information relating to this layout. The layout may be corrupt."), E_USER_ERROR);
         }
         if ($db->num_rows($results) == 0) {
             $this->has_permissions = false;
         }
         while ($aRow = $db->get_row($results)) {
             $this->layout = Kit::ValidateParam($aRow[0], _STRING);
             $this->description = Kit::ValidateParam($aRow[1], _STRING);
             $this->retired = Kit::ValidateParam($aRow[3], _INT);
             $this->xml = $aRow[4];
         }
     }
 }
Example #20
0
 public static function sendMail($recipients, $subject, $content)
 {
     $cfg = CfgHelper::getInstance();
     $mail = new PHPMailer();
     // recipients
     if (is_array($recipients)) {
         foreach ($recipients as $r) {
             $mail->AddAddress($r);
         }
     } else {
         if (is_string($recipients)) {
         } else {
             Debug::loge('Wrong recipients parameter ! Should be an array or a string...', 'MailHelper');
             return;
         }
     }
     // sender
     $mail->From = $cfg->getMailFromAddr();
     $mail->FromName = $cfg->getMailFromName();
     $mail->IsHTML(true);
     // Set email format to HTML
     $mail->Subject = $subject;
     $mail->Body = $content;
     if (!$mail->Send()) {
         Debug::loge('Message could not be sent. Mailer Error: ' . $mail->ErrorInfo, 'MailHelper');
     }
 }
Example #21
0
/**
 * 输出各种类型的数据,调试程序时打印数据使用。
 * @param	mixed	参数:可以是一个或多个任意变量或值
 */
function p()
{
    $args = func_get_args();
    //获取多个参数
    if (count($args) < 1) {
        Debug::addmsg("<font color='red'>必须为p()函数提供参数!");
        return;
    }
    echo '<div style="width:100%;text-align:left"><pre>';
    //多个参数循环输出
    foreach ($args as $arg) {
        if (is_array($arg)) {
            print_r($arg);
            echo '<br>';
        } else {
            if (is_string($arg)) {
                echo $arg . '<br>';
            } else {
                var_dump($arg);
                echo '<br>';
            }
        }
    }
    echo '</pre></div>';
}
Example #22
0
function updateInfo($percent, $infoText, $debug = true) {
    global $command_line;

    if ($debug) {
        Debug::message($infoText, Debug::WARNING);
    }
    $percentageText = ($percent == 1)? '100': sprintf('%2.0f', $percent * 100);
    if (isset($command_line) and $command_line) {
        if ($percent < 0) {
            $percentageText = ' * ';
        } else {
            $percentageText .= '%';
        }
        echo $percentageText, ' ', $infoText, "\n";
    } else {
        echo '<script>';
        if ($percent >= 0) {
            echo 'document.getElementById("progress-bar").style="width:' . ($percent * 100) . '%;";', "\n",
                 'document.getElementById("progress-bar").innerHTML ="' . $percentageText . '%";', "\n";
        }
        if ($percent == 1) {
            echo 'document.getElementById("progress-bar").className = "progress-bar progress-bar-striped";';
        }
        echo 'document.getElementById("progressbar-info").innerHTML="' . addslashes($infoText) . '";</script>';
    }

    // This is for the buffer achieve the minimum size in order to flush data
    //    echo str_repeat(' ', 1024 * 64);

    // Send output to browser immediately
    flush();
}
 function postInstall()
 {
     global $cache;
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     Debug::text('l: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     return TRUE;
 }
Example #24
0
 public function query($query)
 {
     if ($results = $this->_mysql->query($query) or Debug::warning($this->_mysql->error)) {
         if ($this->_mysql->affected_rows == 0) {
             //Debug::info("No Affected Rows");
         }
         if (isset($results->num_rows)) {
             $response = array();
             while ($result = $results->fetch_assoc()) {
                 //Debug::info("Returning Data");
                 $response[] = $result;
             }
             return $response;
         }
         if ($this->_mysql->affected_rows > 0) {
             if (isset($this->_mysql->insert_id)) {
                 //Debug::info("Returning Id");
                 return $this->_mysql->insert_id;
             }
         }
         return true;
     } else {
         return false;
     }
 }
 static function convert($src_unit, $dst_unit, $measurement, $exponent = 1)
 {
     $src_unit = strtolower($src_unit);
     $dst_unit = strtolower($dst_unit);
     if (!isset(self::$units[$src_unit])) {
         return FALSE;
     }
     if (!isset(self::$units[$dst_unit])) {
         return FALSE;
     }
     if ($src_unit == $dst_unit) {
         return $measurement;
     }
     //Make sure we can convert from one unit to another.
     $valid_conversion = FALSE;
     foreach (self::$valid_unit_groups as $base_unit => $valid_units) {
         if (in_array($src_unit, $valid_units) and in_array($dst_unit, $valid_units)) {
             //Valid conversion
             $valid_conversion = TRUE;
         }
     }
     if ($valid_conversion == FALSE) {
         return FALSE;
     }
     $base_measurement = pow(self::$units[$src_unit], $exponent) * $measurement;
     Debug::Text(' Base Measurement: ' . $base_measurement, __FILE__, __LINE__, __METHOD__, 10);
     if ($base_measurement != 0) {
         $retval = 1 / pow(self::$units[$dst_unit], $exponent) * $base_measurement;
         return $retval;
     }
     return FALSE;
 }
Example #26
0
 static function draw()
 {
     $page = self::urlArray(0);
     if ($page != "setupcomplete" && $page != "action" && file_exists(getSitePath() . "install/")) {
         forward("setupcomplete");
     }
     $body = $header = $nav = $footer = NULL;
     if ($page) {
         $page_handler_class = "SocialApparatus\\" . ucfirst($page) . "PageHandler";
     } else {
         $page_handler_class = "SocialApparatus\\HomePageHandler";
     }
     Vars::clear();
     if (class_exists($page_handler_class)) {
         $body = (new $page_handler_class())->view();
     } else {
         new SystemMessage("Page not found.");
         forward("home");
     }
     Vars::clear();
     $header = display("page_elements/header");
     Vars::clear();
     $nav = display("page_elements/navigation");
     Vars::clear();
     $footer = display("page_elements/footer");
     Vars::clear();
     echo $header;
     echo $nav;
     echo $body;
     echo $footer;
     Debug::clear();
     Dbase::con()->close();
     die;
 }
Example #27
0
 function index()
 {
     $test = $this->User->find('all');
     $this->smarty->assign('name', 'world');
     $this->smarty->display('test.tpl');
     Debug::b($test);
 }
Example #28
0
 public function listen()
 {
     foreach ((array) $this->bindEv as $on => $class) {
         if (!count($this->bindEv[$on])) {
             unset($this->bindEv[$on]);
             $this->change();
             continue;
         }
         $this->O->event()->bind($on, function ($ev) {
             $e = $ev['bind'][0];
             $O = clone $e->O;
             foreach ((array) $e->bindEv[$ev['bind'][1]] as $k => $action) {
                 try {
                     if (!class_exists($action['class'])) {
                         return;
                     }
                     $class = new $action['class']($O);
                     $class = $class->json();
                     $class->rpc_data = Filter::array_($action);
                     $class->rpc_method = Filter::id('method', $class->rpc_data);
                     $class->rpc_id = Filter::id('id', $class->rpc_data);
                     $class->rpc_params = Filter::array_('params', $class->rpc_data);
                     $r = json_decode($class->renderReturn(), 1);
                 } catch (\Exception $e) {
                     Debug::report($e);
                 }
                 unset($e->bindEv[$ev['bind'][1]][$k]);
                 $e->change();
             }
         }, array($this, $on));
     }
 }
 static function error($errorNumber, $message = null, $pos = null)
 {
     $GLOBALS['%s']->push("PHP::error");
     $__hx__spos = $GLOBALS['%s']->length;
     Debug::error($errorNumber, $message, $pos->fileName, $pos->lineNumber);
     $GLOBALS['%s']->pop();
 }
Example #30
0
 /**
  * Save an uploaded file to a new location. If no filename is provided,
  * the original filename will be used, with a unique prefix added.
  *
  * This method should be used after validating the $_FILES array:
  *
  *     if ($array->check())
  *     {
  *         // Upload is valid, save it
  *         Upload::save($array['file']);
  *     }
  *
  * @param   array   $file       uploaded file data
  * @param   string  $filename   new filename
  * @param   string  $directory  new directory
  * @param   integer $chmod      chmod mask
  * @return  string  on success, full path to new file
  * @return  FALSE   on failure
  */
 public static function save(array $file, $filename = NULL, $directory = NULL, $chmod = 0644)
 {
     if (!isset($file['tmp_name']) or !is_uploaded_file($file['tmp_name'])) {
         // Ignore corrupted uploads
         return FALSE;
     }
     if ($filename === NULL) {
         // Use the default filename, with a timestamp pre-pended
         $filename = uniqid() . $file['name'];
     }
     if (Upload::$remove_spaces === TRUE) {
         // Remove spaces from the filename
         $filename = preg_replace('/\\s+/u', '_', $filename);
     }
     if ($directory === NULL) {
         // Use the pre-configured upload directory
         $directory = Upload::$default_directory;
     }
     if (!is_dir($directory) or !is_writable(realpath($directory))) {
         throw new Kohana_Exception('Directory :dir must be writable', array(':dir' => Debug::path($directory)));
     }
     // Make the filename into a complete path
     $filename = realpath($directory) . DIRECTORY_SEPARATOR . $filename;
     if (move_uploaded_file($file['tmp_name'], $filename)) {
         if ($chmod !== FALSE) {
             // Set permissions on filename
             chmod($filename, $chmod);
         }
         // Return new file path
         return $filename;
     }
     return FALSE;
 }