function loadPackages()
  {
    include_once(LIMB_DIR . '/core/util/ini_support.inc.php');

    $toolkit =& Limb :: toolkit();
    $ini =& $toolkit->getINI('packages.ini');
    $this->_packages = array();

    $groups = $ini->getAll();

    $packages = $ini->getOption('packages');

    if (!count($packages))
      return throw_error(new LimbException('no packages in package.ini!'));

    foreach($packages as $package_path)
    {
      $package_data = array();

      include($package_path . '/setup.php');

      $this->_definePackageConstant($PACKAGE_NAME, $package_path);

      $package_data['path'] = $package_path;
      $package_data['name'] = $PACKAGE_NAME;

      $this->_packages[] = $package_data;
    }
  }
  function getClassId($object)
  {
    $toolkit =& Limb :: toolkit();
    $db_table =& $toolkit->createDBTable('SysClass');

    $class_name = $object->__class_name;

    $rs =& $db_table->select(array('name' => $class_name));

    $count = $rs->getTotalRowCount();

    if ($count == 1)
    {
      $rs->rewind();
      $record = $rs->current();
      return $record->get('id');
    }
    elseif($count > 1)
    {
      return throw_error(new LimbException('there are more than 1 type found',
        array('name' => $class_name)));
    }

    $insert_data['name'] = $class_name;

    return $db_table->insert($insert_data);
  }
Exemplo n.º 3
0
 public function run($sql, $data = array())
 {
     try {
         $statement = $this->PDO->prepare($sql);
         if (count($data)) {
             foreach ($data as $key => $value) {
                 if (is_int($value)) {
                     $statement->bindValue(":" . $key, $value, PDO::PARAM_INT);
                 } else {
                     if (is_bool($value)) {
                         $statement->bindValue(":" . $key, $value, PDO::PARAM_BOOL);
                     } else {
                         if (is_null($value)) {
                             $statement->bindValue(":" . $key, $value, PDO::PARAM_NULL);
                         } else {
                             if (is_string($value)) {
                                 $statement->bindValue(":" . $key, $value);
                             }
                         }
                     }
                 }
             }
         }
         $statement->execute();
         return $statement;
     } catch (PDOException $e) {
         throw_error("Query Error: " . $e->getMessage());
     }
 }
 function resize($max_size)
 {
     $image_library =& $this->_getImageLibrary();
     $media_manager =& $this->_getMediaManager();
     $media_file_id = $this->getMediaFileId();
     $input_file = $media_manager->getMediaFilePath($media_file_id);
     $output_file = $this->_generateTempFile();
     $input_file_type = $image_library->getImageType($this->getMimeType());
     $output_file_type = $image_library->fallBackToAnySupportedType($input_file_type);
     $image_library->setInputFile($input_file);
     $image_library->setInputType($input_file_type);
     $image_library->setOutputFile($output_file);
     $image_library->setOutputType($output_file_type);
     $image_library->resize(array('max_dimension' => $max_size));
     //ugly!!!
     $image_library->commit();
     if (catch_error('LimbException', $e)) {
         if (file_exists($output_file)) {
             $this->_unlinkTempFile($output_file);
         }
         return throw_error($e);
     }
     $this->_updateDimensionsUsingFile($output_file);
     $media_file_id = $media_manager->store($output_file);
     $this->setMediaFileId($media_file_id);
     $this->_unlinkTempFile($output_file);
 }
  function create($library = 'gd', $dir = '')
  {
    if(defined('IMAGE_LIBRARY'))
      $library = IMAGE_LIBRARY;

    $image_class_name = 'image_' . $library;

    if(isset($GLOBALS['global_' . $image_class_name]))
      $obj =& $GLOBALS['global_' . $image_class_name];
    else
      $obj = null;

    if(get_class($obj) != $image_class_name)
    {
      $dir = ($dir == '') ? LIMB_DIR . '/core/image/' : $dir;

      if(!file_exists($dir . $image_class_name . '.class.php'))
          return throw_error(new FileNotFoundException('image library not found', $dir . $image_class_name . '.class.php'));

      include_once($dir . $image_class_name . '.class.php');

      $obj = new $image_class_name();
      $GLOBALS['global_' . $image_class_name] =& $obj;
    }

    return $obj;
  }
  function run(&$filter_chain, &$request, &$response)
  {
    $toolkit =& Limb :: toolkit();

    $action_resolver =& $toolkit->getRequestResolver('action');
    $service_resolver =& $toolkit->getRequestResolver('service');

    if(!is_object($service_resolver) || !is_object($action_resolver))
      return throw_error(new LimbException('request resolvers not set'));

    $service =& $service_resolver->resolve($request);
    if(!$action =& $action_resolver->resolve($request))
    {
      $toolkit->setService($service);
    }
    elseif($service->actionExists($action))
    {
      $service->setCurrentAction($action);
      $toolkit->setService($service);
    }
    else
    {
      $service404 = new Service('404');
      $toolkit->setService($service404);
    }

    $filter_chain->next();
  }
 function preParse()
 {
     if (!isset($this->attributes['name'])) {
         return throw_error(new WactException('missing required attribute', array('tag' => $this->tag, 'attribute' => 'name', 'file' => $this->source_file, 'line' => $this->starting_line_no)));
     }
     $this->const = $this->attributes['name'];
     return PARSER_REQUIRE_PARSING;
 }
function & getFileResolver($resolver_name)
{
  global $LIMB_FILE_RESOLVERS;
  if(isset($LIMB_FILE_RESOLVERS[$resolver_name]))
    return $LIMB_FILE_RESOLVERS[$resolver_name];
  else
    return throw_error(new LimbException('unknown file resolver',
      array('resolver' => $resolver_name)));
}
  function resolve($class_path, $params = array())
  {
    if(file_exists(LIMB_DIR . '/core/actions/' . $class_path . '.class.php'))
      $full_path = LIMB_DIR . '/core/actions/' . $class_path . '.class.php';
    else
      return throw_error(new FileNotFoundException('action not found', $class_path));

    return $full_path;
  }
Exemplo n.º 10
0
/**
 * Created by PhpStorm.
 * User: Asus
 * Date: 5/30/2015
 * Time: 9:57 AM
 */
function getCurrentDateTime()
{
    global $timezone;
    try {
        $now = new DateTime("now", new DateTimeZone($timezone['timezone']));
    } catch (Exception $e) {
        throw_error($e->getMessage());
    }
    return $now->format("Y-m-d H:i:s");
}
Exemplo n.º 11
0
function get_slow_page_data()
{
    global $xhprofModelObject;
    global $game_cfg;
    $result = $xhprofModelObject->generic_execute_get_query_detail('get_slow_page_data', array("slow_page_table" => $game_cfg["slow_page_table"]));
    if (!$result) {
        throw_error("Internal plumping error, slow db could not be owned (mined)");
    }
    return $result;
}
 function _applyAccessPolicy($object, $action)
 {
     $access_policy = new AccessPolicy();
     $access_policy->applyAccessTemplates($object, $action);
     if (catch_error('LimbException', $e)) {
         MessageBox::writeNotice("Access template of " . get_class($object) . " for action '{$action}' not defined!!!");
     } elseif (catch_error('LimbException', $e)) {
         return throw_error($e);
     }
 }
Exemplo n.º 13
0
  function load()
  {
    if(!file_exists($this->file_path))
      return throw_error(new FileNotFoundException('ini file not found', $this->file_path));

    if ($this->use_cache)
      $this->_loadCache();
    else
      $this->_parse($this->file_path);
  }
 function preParse()
 {
     if (!isset($this->attributes['tab_id'])) {
         return throw_error(new WactException('missing required attribute', array('tag' => $this->tag, 'attribute' => 'id', 'file' => $this->source_file, 'line' => $this->starting_line_no)));
     }
     if (!in_array($this->attributes['tab_id'], $this->parent->parent->tabs)) {
         return throw_error(new WactException('invalid attribute value', array('tag' => $this->tag, 'attribute' => 'tab_id', 'description' => 'tab_id not declared in <tab_item:label> tag', 'file' => $this->source_file, 'line' => $this->starting_line_no)));
     }
     return PARSER_REQUIRE_PARSING;
 }
  function resolve($file_name, $params = array())
  {
    if (file_exists(LIMB_DIR . '/tests/settings/' . $file_name))
      $dir = LIMB_DIR . '/tests/settings/';
    elseif (file_exists(LIMB_DIR . '/settings/' . $file_name))
      $dir = LIMB_DIR . '/settings/';
    else
      return throw_error(new FileNotFoundException('ini file not found', $file_name));

    return $dir . $file_name;
  }
 function _updateObjectOperation()
 {
     $this->object->set('files_data', $_FILES[$this->name]);
     $this->object->updateVariations();
     if (catch_error('SQLException', $e)) {
         return throw_error($e);
     } elseif (catch_error('LimbException', $e)) {
         MessageBox::writeNotice('Some variations were not resized');
     } elseif (catch_error('LimbException', $e)) {
         return throw_error($e);
     }
 }
Exemplo n.º 17
0
  function & _getIni()
  {
    if(is_object($this->ini))
      return $this->ini;

    $toolkit =& Limb :: toolkit();
    $this->ini =& $toolkit->getIni($this->name . '.service.ini', 'service');

    if(!is_object($this->ini))
      return throw_error(new LimbException($this->name . '.service.ini not found'));//FIX

    return $this->ini;
  }
  function fallBackToAnySupportedType($type)
  {
    if ($this->isTypeCreateSupported($type))
      return $type;

    if ($this->isTypeCreateSupported('PNG'))
      return 'PNG';

    if ($this->isTypeCreateSupported('JPEG'))
      return 'JPEG';

    return throw_error(new LimbException('no file type supported'));
  }
  function resolve($file_name, $params = array())
  {
    if(!isset($params[0]))
      $locale_id = DEFAULT_CONTENT_LOCALE_ID;
    else
      $locale_id = $params[0];

    if(file_exists(LIMB_DIR . '/tests/i18n/' . $file_name . '_' . $locale_id . '.ini'))
      $dir = LIMB_DIR . '/tests/i18n/';
    else
      return throw_error(new FileNotFoundException('strings file not found', $file_name, array('locale_id' => $locale_id)));

    return $dir . $file_name . '_' . $locale_id . '.ini';
  }
 function store($disk_file_path)
 {
     if (!file_exists($disk_file_path)) {
         return throw_error(new FileNotFoundException('file not found', $disk_file_path));
     }
     srand(time());
     $media_id = md5(uniqid(rand()));
     Fs::mkdir(MEDIA_DIR);
     $media_file = $this->getMediaFilePath($media_id);
     if (!copy($disk_file_path, $media_file)) {
         return throw_error(new IOException('copy failed', array('dst' => $media_file, 'src' => $disk_file_path)));
     }
     return $media_id;
 }
  function _performStateCommand($state)
  {
    if (!isset($this->states[$state]))
    {
      return throw_error(new LimbException('illegal state',
                            array('state_name' => $state)));
    }

    $method = 'perform' .  $state;
    $result = $this->factory->$method();

    $this->state_history[] = array($state => $result);

    return $result;
  }
 function _validPerform(&$request, &$response)
 {
     $params = array();
     $params['identifier'] = $this->dataspace->get('identifier');
     $params['parent_path'] = $this->dataspace->get('parent_path');
     $params['class'] = $this->dataspace->get('class_name');
     $params['title'] = $this->dataspace->get('title');
     $toolkit =& Limb::toolkit();
     $object =& $toolkit->createSiteObject($params['Class']);
     $datasource =& $toolkit->getDatasource('SingleObjectDatasource');
     $datasource->setPath($params['parent_path']);
     $is_root = false;
     if (!($parent_data = $datasource->fetch())) {
         if ($params['parent_path'] == '/') {
             $is_root = true;
         } else {
             MessageBox::writeNotice('parent wasn\'t retrieved by path ' . $params['parent_path']);
             $request->setStatus(Request::STATUS_FAILURE);
             return;
         }
     }
     if (!$is_root) {
         $params['parent_node_id'] = $parent_data['node_id'];
     } else {
         $params['parent_node_id'] = 0;
     }
     $object->merge($params);
     $object->create($is_root);
     if (catch_error($e, 'LimbException')) {
         MessageBox::writeNotice('object wasn\'t registered!');
         $request->setStatus(Request::STATUS_FAILURE);
         return;
     } elseif (catch_error($e, 'LimbException')) {
         return throw_error($e);
     }
     if (!$is_root) {
         $parent_object =& $toolkit->createSiteObject($parent_data['ClassName']);
         $parent_object->merge($parent_data);
         $controller =& $parent_object->getController();
         $action = $controller->determineAction();
         $access_policy = new AccessPolicy();
         $access_policy->saveNewObjectAccess($object, $parent_object, $action);
     }
     $request->setStatus(Request::STATUS_FORM_SUBMITTED);
     if ($request->hasAttribute('popup')) {
         $response->write(closePopupResponse($request));
     }
 }
  function insert(&$object)
  {
    if (!$object->get('oid'))
      return throw_error(new LimbException('oid is not set'));

    if (!$object->get('id'))
      return throw_error(new LimbException('node id is not set'));

    $toolkit =& Limb :: toolkit();
    $db_table =& $toolkit->createDBTable('SysObject2Node');

    $row = array('oid' => $object->get('oid'),
                 'node_id' => $object->get('id'));

    $db_table->insert($row);
  }
  function resolve($file_path, $params = array())
  {
    $packages = $this->_getPackages();

    foreach($packages as $package)
    {
      if (!isset($package['path']))
        continue;

      $resolved_file_path = $package['path'] . $file_path;
      if (file_exists($resolved_file_path))
        return $resolved_file_path;
    }

    return throw_error(new FileNotFoundException('file not found in packages', $file_path));
  }
Exemplo n.º 25
0
  function write($log_file_data, $string)
  {
    $log_dir = $log_file_data[0];
    $log_name = $log_file_data[1];
    $file_name = $log_dir . $log_name;

    if (!is_dir($log_dir))
      Fs :: mkdir($log_dir, 0775, true);

    $oldumask = umask(0);
    $file_existed = file_exists($file_name);
    $log_file = fopen($file_name, 'a');

    if ($log_file)
    {
      $time = gmstrftime("%b %d %Y %H:%M:%S", time());

      $notice = '[ ' . $time . " ]\n";

      $toolkit =& Limb :: toolkit();
      $user =& $toolkit->getUser();

      if(($user_id = $user->getId()) != DEFAULT_USER_ID)
        $notice .= '[ ' . $user_id . ' ] [ '  . $user->getLogin() . ' ] [ ' . $user->get('email', '') . ' ] ';

      $notice .= '[' . Sys::clientIp() . '] [' . (isset($_SERVER['REQUEST_URI']) ?  $_SERVER['REQUEST_URI'] : '') . "]\n" . $string . "\n\n";

      fwrite($log_file, $notice);
      fclose($log_file );
      if (!$file_existed)
        chmod($file_name, 0664);

      umask($oldumask);
      $result = true;
    }
    else
    {
      umask($oldumask);
      return throw_error(new IOException("Cannot open log file '$file_name' for writing\n" .
                         "The web server must be allowed to modify the file.\n" .
                         "File logging for '$file_name' is disabled."));
    }

    return $result;
  }
  function process()
  {
    $ds =& $this->_createDAO();
    $datasource =& $ds->fetchRecord();

    foreach($this->targets as $target)
    {
      if($target_component =& $this->parent->findChild($target))
      {
        $target_component->registerDataSource($datasource);
      }
      else
      {
        return throw_error(new WactException('target component not found',
                                array('target' => $target)));
      }
    }
  }
 function _updateObjectOperation()
 {
     if (isset($_FILES[$this->name]['tmp_name']['file'])) {
         if ($_FILES[$this->name]['size']['file'] > ini_get('upload_max_filesize') * 1024 * 1024) {
             return throw_error(new LimbException('uploaded file size exceeds limit'));
         }
         $toolkit =& Limb::toolkit();
         $request =& $toolkit->getRequest();
         $datasource =& $toolkit->getDatasource('RequestedObjectDatasource');
         $datasource->setRequest($request);
         $object_data = $datasource->fetch();
         $this->object->set('media_id', $object_data['media_id']);
         $this->object->set('tmp_file_path', $_FILES[$this->name]['tmp_name']['file']);
         $this->object->set('file_name', $_FILES[$this->name]['name']['file']);
         $this->object->set('mime_type', $_FILES[$this->name]['type']['file']);
     }
     parent::_updateObjectOperation();
 }
  function perform()
  {
    $toolkit =& Limb :: toolkit();

    if(!$view =& $toolkit->getView())
      return throw_error(new LimbException('view is null'));

    ob_start();

    $view->display();

    $response =& $toolkit->getResponse();
    $response->write(ob_get_contents());

    if(ob_get_level())
      ob_end_clean();

    return LIMB_STATUS_OK;
  }
  function insert(&$object)
  {
    if (!$object->get('oid'))
      return throw_error(new LimbException('oid is not set'));

    $toolkit =& Limb :: toolkit();
    $service_db_table =& $toolkit->createDBTable('SysService');

    $service_id = $this->_getServiceId($object);

    $db_table =& $toolkit->createDBTable('SysObject2Service');

    $row = array('oid' => $object->get('oid'),
                 'service_id' => $service_id,
                 'title' => $object->get('title'),
                 );

    $db_table->insert($row);
  }
  function process()
  {
    $dataset =& $this->getDataset();

    if($navigator =& $this->_getNavigatorComponent())
      $dataset->paginate($navigator);

    foreach($this->targets as $target)
    {
      if($target_component =& $this->parent->findChild($target))
      {
        $target_component->registerDataSet($dataset);
      }
      else
      {
        return throw_error(new WactException('target component not found',
                                array('target' => $target)));
      }
    }
  }