parent
d654bb558a
commit
6d32affd79
@ -1,74 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Definition of the AddManySessionToCategoryFunctions class |
||||
* @package chamilo.library |
||||
*/ |
||||
/** |
||||
* Ajax controller. Dispatch request and perform required action. |
||||
* |
||||
* |
||||
* Usage: |
||||
* |
||||
* $controller = AjaxController::instance(); |
||||
* $controller->run(); |
||||
* |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Genevas |
||||
* @license /license.txt |
||||
*/ |
||||
class AjaxController extends \Controller |
||||
{ |
||||
/** |
||||
* Returns an HTML error message for forbidden access |
||||
* @return bool|void |
||||
* @assert () === null |
||||
*/ |
||||
function forbidden() |
||||
{ |
||||
$this->response(false, get_lang('YouAreNotAuthorized')); |
||||
} |
||||
|
||||
/** |
||||
* Returns an HTML error message for unknown action |
||||
* @return bool|void |
||||
* @assert () === null |
||||
*/ |
||||
public function unknown() |
||||
{ |
||||
$this->response(false, get_lang('UnknownAction')); |
||||
} |
||||
|
||||
/** |
||||
* Action exists but implementation is missing. |
||||
* @return bool|void |
||||
* @assert () === null |
||||
*/ |
||||
public function missing() |
||||
{ |
||||
$this->response(false, get_lang('NoImplementation')); |
||||
} |
||||
|
||||
/** |
||||
* Display a standard json responce. |
||||
* |
||||
* @param bool $success |
||||
* @param string $message |
||||
* @param object $data |
||||
* @return bool|void |
||||
* @assert () === null |
||||
*/ |
||||
public function response($success = false, $message = '', $data = null) |
||||
{ |
||||
$message = trim($message); |
||||
$response = (object) array(); |
||||
$response->success = $success; |
||||
if ($message) { |
||||
$response->message = Display::return_message($message, $success ? 'normal' : 'error'); |
||||
} else { |
||||
$response->message = ''; |
||||
} |
||||
$response->data = $data; |
||||
$this->render_json($response); |
||||
} |
||||
|
||||
} |
@ -1,128 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Cache for storing data. |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class Cache |
||||
{ |
||||
|
||||
/** |
||||
* Retrieve an item from the cache if item creation date is greater than limit. |
||||
* If item does not exists or is stale returns false. |
||||
* |
||||
* @param any Identifier for the variable stored |
||||
* @param int If this limit is greater than last mod time of value, stale |
||||
* @return false|object Value kept in cache |
||||
*/ |
||||
static function get($key, $limit = 0) |
||||
{ |
||||
if (!self::has($key, $limit)) |
||||
{ |
||||
return false; |
||||
} |
||||
$path = self::path($key); |
||||
return file_get_contents($path); |
||||
} |
||||
|
||||
/** |
||||
* Returnsn true if the cache has the item and it is not staled. |
||||
* |
||||
* @param any Identifier for the variable stored |
||||
* @param int If this limit is greater than last mod time of value, stale |
||||
* @return boolean |
||||
*/ |
||||
static function has($key, $limit = 0) |
||||
{ |
||||
$path = self::path($key); |
||||
if (!is_readable($path)) |
||||
{ |
||||
return false; |
||||
} |
||||
if ($limit) |
||||
{ |
||||
$mtime = filemtime($path); |
||||
if ($mtime < $limit) |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* Put something in cache. |
||||
* |
||||
* @param any Identifier for the variable to be stored |
||||
* @param string Value to be stored |
||||
*/ |
||||
static function put($key, $value) |
||||
{ |
||||
$path = self::path($key); |
||||
file_put_contents($path, $value); |
||||
} |
||||
|
||||
/** |
||||
* Remove an item from the cache. |
||||
* |
||||
* @param any Identifier for the variable to remove |
||||
*/ |
||||
static function remove($key) |
||||
{ |
||||
$path = self::path($key); |
||||
if (is_readable($path)) |
||||
{ |
||||
unlink($path); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Clear the cache. Remove all entries. |
||||
*/ |
||||
static function clear() |
||||
{ |
||||
$dir = self::path(); |
||||
$files = scandir($dir); |
||||
$files = array_diff($files, array('.', '..')); |
||||
foreach ($files as $file) |
||||
{ |
||||
$path = $dir . $file; |
||||
unlink($path); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns the file path based on the key. |
||||
* |
||||
* @param any Identifier for the variable |
||||
* @return string Path of the file where this |
||||
* variable is/should-be stored |
||||
*/ |
||||
static function path($key = '') |
||||
{ |
||||
return Chamilo::path('archive/temp/cache/' . self::key($key)); |
||||
} |
||||
|
||||
/** |
||||
* Returns the internal string key from the external key. |
||||
* For internal use. |
||||
* |
||||
* @param any Identifier for the variable |
||||
* @return string Unique ID generated to identify the variable |
||||
*/ |
||||
static function key($item) |
||||
{ |
||||
if (is_object($item)) |
||||
{ |
||||
$f = array($item, 'get_unique_id'); |
||||
if (is_callable($f)) |
||||
{ |
||||
return call_user_func($f); |
||||
} |
||||
} |
||||
$result = (string)$item; |
||||
} |
||||
|
||||
} |
@ -1,198 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Controller |
||||
* |
||||
* |
||||
* |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Genevas |
||||
* @license see /license.txt |
||||
*/ |
||||
class Controller |
||||
{ |
||||
|
||||
const PARAM_ACTION = 'action'; |
||||
|
||||
protected $access; |
||||
|
||||
protected function __construct($access = null) |
||||
{ |
||||
$access = $access ? $access : Access::all(); |
||||
$this->access = $access; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return \Access |
||||
*/ |
||||
public function access() |
||||
{ |
||||
return $this->access; |
||||
} |
||||
|
||||
/** |
||||
* List of actions accepted by the controller. |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function get_actions() |
||||
{ |
||||
$reflector = new ReflectionClass($this); |
||||
$constants = $reflector->getConstants(); |
||||
$result = array(); |
||||
foreach ($constants as $key => $value) { |
||||
if (strpos($key, 'ACTION') !== false) { |
||||
$result[$key] = $value; |
||||
} |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* Action to perform. |
||||
* Returns the request parameter. |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function get_action() |
||||
{ |
||||
$result = Request::get(self::PARAM_ACTION); |
||||
$actions = $this->get_actions(); |
||||
$result = in_array($result, $actions) ? $result : ''; |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* Set up the environment. Set up breadcrumps, raise tracking event, etc. |
||||
*/ |
||||
protected function prolog() |
||||
{ |
||||
|
||||
} |
||||
|
||||
/** |
||||
* Whether the call is authorized or not. |
||||
* |
||||
* @return boolean |
||||
*/ |
||||
public function authorize() |
||||
{ |
||||
return $this->access()->authorize(); |
||||
} |
||||
|
||||
/** |
||||
* Returns a string containing dynamic javascript to be included in the template. |
||||
* This requires a {{javascript}} tag in a twigg template to appear. |
||||
* |
||||
* Note: |
||||
* |
||||
* A better approach to this method is to create a twigg "javascript" |
||||
* template and to include it where required. |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function javascript() |
||||
{ |
||||
return ''; |
||||
} |
||||
|
||||
// public function check_token() |
||||
// { |
||||
// return (bool) Security::check_token('get'); |
||||
// } |
||||
|
||||
/** |
||||
* Run the controller. Dispatch action and execute requested tasks. |
||||
*/ |
||||
public function run() |
||||
{ |
||||
if (!$this->authorize()) { |
||||
$this->forbidden(); |
||||
return false; |
||||
} |
||||
|
||||
$this->prolog(); |
||||
$action = $this->get_action(); |
||||
if (empty($action)) { |
||||
$this->unknown(); |
||||
return; |
||||
} |
||||
$f = array($this, $action); |
||||
if (is_callable($f)) { |
||||
call_user_func($f); |
||||
} else { |
||||
$this->missing(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Unknown action. I.e. the action has not been registered. |
||||
* Possibly missing action declaration: |
||||
* |
||||
* const ACTION_XXX = 'XXX'; |
||||
* |
||||
* @return boolean |
||||
*/ |
||||
public function unknown() |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return boolean |
||||
*/ |
||||
public function forbidden() |
||||
{ |
||||
api_not_allowed(); |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* Action exists but implementation is missing. |
||||
*/ |
||||
public function missing() |
||||
{ |
||||
echo 'No implementation'; |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* Render a template using data. Adds a few common parameters to data. |
||||
* |
||||
* @see /main/template/default/course_description/ |
||||
* @param string $template |
||||
* @param array $data |
||||
*/ |
||||
protected function render($template_name, $data) |
||||
{ |
||||
$data = (object) $data; |
||||
$data->www = \Chamilo::url(); |
||||
$data->messages = isset($data->messages) ? $data->messages : array(); |
||||
$javascript = $this->javascript(); |
||||
if ($javascript) { |
||||
$data->javascript = $javascript; |
||||
} |
||||
|
||||
$tpl = new Template(); |
||||
foreach ($data as $key => $value) { |
||||
$tpl->assign($key, $value); |
||||
} |
||||
$template = $tpl->get_template($template_name); |
||||
$content = $tpl->fetch($template); |
||||
$tpl->assign('content', $content); |
||||
$tpl->display_one_col_template(); |
||||
} |
||||
|
||||
/** |
||||
* Render data as JSON |
||||
* |
||||
* @param any $data |
||||
*/ |
||||
protected function render_json($data) |
||||
{ |
||||
Header::content_type_json(); |
||||
echo json_encode($data); |
||||
} |
||||
|
||||
} |
@ -1,145 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace Model; |
||||
|
||||
use Database; |
||||
use ResultSet; |
||||
|
||||
/** |
||||
* Description of course |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class Course |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param string $where |
||||
* @return \ResultSet |
||||
*/ |
||||
public static function query($where) |
||||
{ |
||||
$table = Database::get_main_table(TABLE_MAIN_COURSE); |
||||
$sql = "SELECT * FROM $table "; |
||||
$sql .= $where ? "WHERE $where" : ''; |
||||
$result = new ResultSet($sql); |
||||
return $result->return_type(__CLASS__); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $code |
||||
* @return \Model\Course|null |
||||
*/ |
||||
public static function get_by_code($code) |
||||
{ |
||||
$current = self::current(); |
||||
if ($current && $current->get_code() == $code) { |
||||
return $current; |
||||
} |
||||
return self::query("code = '$code'")->first(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param int $id |
||||
* @return \Model\Course|null |
||||
*/ |
||||
public static function get_by_id($id) |
||||
{ |
||||
$id = (int) $id; |
||||
$current = self::current(); |
||||
if ($current && $current->get_id() == $id) { |
||||
return $current; |
||||
} |
||||
return self::query("id = $id")->first(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return \Model\Course|null |
||||
*/ |
||||
public static function current() |
||||
{ |
||||
global $_course; |
||||
/** |
||||
* Note that $_course = -1 when not set. |
||||
*/ |
||||
if (empty($_course) || !is_array($_course)) { |
||||
return null; |
||||
} |
||||
|
||||
static $result = null; |
||||
if (empty($result)) { |
||||
$id = $_course['real_id']; |
||||
$result = self::query("id = $id")->first(); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
protected $id = 0; |
||||
protected $code = 0; |
||||
protected $directory = ''; |
||||
protected $show_score = ''; |
||||
|
||||
public function __construct($data) |
||||
{ |
||||
$data = (object) $data; |
||||
$this->id = $data->id; |
||||
$this->code = $data->code; |
||||
$this->directory = $data->directory; |
||||
$this->show_score = $data->show_score; |
||||
} |
||||
|
||||
public function get_id() |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function set_id($value) |
||||
{ |
||||
$this->id = (int) $value; |
||||
} |
||||
|
||||
public function get_code() |
||||
{ |
||||
return $this->code; |
||||
} |
||||
|
||||
public function set_code($value) |
||||
{ |
||||
$this->code = (int) $value; |
||||
} |
||||
|
||||
public function get_directory() |
||||
{ |
||||
return $this->directory; |
||||
} |
||||
|
||||
public function set_directory($value) |
||||
{ |
||||
$this->directory = (int) $value; |
||||
} |
||||
|
||||
public function get_show_score() |
||||
{ |
||||
return $this->show_score; |
||||
} |
||||
|
||||
public function set_show_score($value) |
||||
{ |
||||
$this->show_score = (int) $value; |
||||
} |
||||
|
||||
public function get_path() |
||||
{ |
||||
$dir = $this->directory; |
||||
if (empty($dir)) { |
||||
return ''; |
||||
} |
||||
return api_get_path(SYS_COURSE_PATH) . $dir . '/'; |
||||
} |
||||
|
||||
} |
@ -1,21 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Description of course_entity |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class CourseEntity extends Entity |
||||
{ |
||||
|
||||
public function __construct() |
||||
{ |
||||
$current_course = self::current_course(); |
||||
if ($current_course) { |
||||
$this->defaults('c_id', self::current_course()->get_id()); |
||||
} |
||||
$this->defaults('session_id', api_get_session_id()); |
||||
} |
||||
|
||||
} |
@ -1,17 +0,0 @@ |
||||
<?php |
||||
|
||||
/* |
||||
* To change this template, choose Tools | Templates |
||||
* and open the template in the editor. |
||||
*/ |
||||
|
||||
/** |
||||
* Description of course_entity_repository |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class CourseEntityRepository extends EntityRepository |
||||
{ |
||||
//put your code here |
||||
} |
@ -1,302 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace Model; |
||||
|
||||
use Database; |
||||
use ResultSet; |
||||
|
||||
/** |
||||
* Represent a database "document" object - i.e. a file or a folder. |
||||
* |
||||
* Note: |
||||
* |
||||
* Each database column is mapped to a property. |
||||
* |
||||
* The item_property table is available through its own property but is loaded |
||||
* alongside document data. |
||||
* |
||||
* Some db query functions exists in this class and would need to be adapted |
||||
* to Symphony once it is moved to production. Yet the object structure should |
||||
* stay. |
||||
* |
||||
* @see \Model\ItemProperty |
||||
* @see table c_document |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class Document |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param string $where |
||||
* @return \ResultSet |
||||
*/ |
||||
public static function query($where) |
||||
{ |
||||
$table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||||
$table_document = Database::get_course_table(TABLE_DOCUMENT); |
||||
$tool = TOOL_DOCUMENT; |
||||
|
||||
$sql = "SELECT doc.*, |
||||
prop.id AS property_id, |
||||
prop.tool, |
||||
prop.insert_user_id, |
||||
prop.insert_date, |
||||
prop.lastedit_date, |
||||
prop.ref, |
||||
prop.lastedit_type, |
||||
prop.lastedit_user_id, |
||||
prop.to_group_id, |
||||
prop.to_user_id, |
||||
prop.visibility, |
||||
prop.start_visible, |
||||
prop.end_visible, |
||||
prop.id_session |
||||
FROM |
||||
$table_document AS doc, |
||||
$table_item_property AS prop |
||||
WHERE |
||||
(doc.id = prop.ref AND |
||||
doc.c_id = prop.c_id AND |
||||
prop.tool = '$tool')"; |
||||
|
||||
$sql .= $where ? "AND ($where)" : ''; |
||||
$result = new ResultSet($sql); |
||||
return $result->return_type(__CLASS__); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param int|Course $c_id |
||||
* @param int $id |
||||
* @return \Model\Document |
||||
*/ |
||||
public static function get_by_id($c_id, $id) |
||||
{ |
||||
$c_id = is_object($c_id) ? $c_id->get_id() : (int) $c_id; |
||||
return self::query("doc.c_id = $c_id AND doc.id = $id")->first(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param int|Course $c_id |
||||
* @param int $id |
||||
* @return \Model\Document |
||||
*/ |
||||
public static function get_by_path($c_id, $path) |
||||
{ |
||||
$c_id = is_object($c_id) ? $c_id->get_id() : (int) $c_id; |
||||
return self::query("doc.c_id = $c_id AND doc.path = '$path'")->first(); |
||||
} |
||||
|
||||
protected $c_id = 0; |
||||
protected $id = 0; |
||||
protected $path = ''; |
||||
protected $comment = ''; |
||||
protected $title = ''; |
||||
protected $filetype = ''; |
||||
protected $size = 0; |
||||
protected $readonly = false; |
||||
protected $session_id = 0; |
||||
protected $course = null; |
||||
protected $item_property = null; |
||||
|
||||
public function __construct($data) |
||||
{ |
||||
$data = (object) $data; |
||||
$this->c_id = (int) $data->c_id; |
||||
$this->id = (int) $data->id; |
||||
$this->path = $data->path; |
||||
$this->comment = $data->comment; |
||||
$this->title = $data->title; |
||||
$this->filetype = $data->filetype; |
||||
$this->size = (int) $data->size; |
||||
$this->readonly = (bool) $data->readonly; |
||||
$this->session_id = (int) $data->session_id; |
||||
|
||||
$this->course = null; |
||||
|
||||
if (isset($data->property_id)) { |
||||
$property = (array) $data; |
||||
$property = (object) $property; |
||||
$property->id = $property->property_id; |
||||
$this->item_property = ItemProperty::create($property); |
||||
} else { |
||||
$this->item_property = null; |
||||
} |
||||
} |
||||
|
||||
public function get_c_id() |
||||
{ |
||||
return $this->c_id; |
||||
} |
||||
|
||||
public function set_c_id($value) |
||||
{ |
||||
$this->c_id = (int) $value; |
||||
$this->course = null; |
||||
$this->item_property = null; |
||||
} |
||||
|
||||
public function get_id() |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function set_id($value) |
||||
{ |
||||
$this->id = (int) $value; |
||||
$this->item_property = null; |
||||
} |
||||
|
||||
public function get_path() |
||||
{ |
||||
return $this->path; |
||||
} |
||||
|
||||
public function set_path($value) |
||||
{ |
||||
$this->path = $value; |
||||
} |
||||
|
||||
public function get_comment() |
||||
{ |
||||
return $this->comment; |
||||
} |
||||
|
||||
public function set_comment($value) |
||||
{ |
||||
$this->comment = $value; |
||||
} |
||||
|
||||
public function get_title() |
||||
{ |
||||
return $this->title; |
||||
} |
||||
|
||||
public function set_title($value) |
||||
{ |
||||
$this->title = $value; |
||||
} |
||||
|
||||
public function get_filetype() |
||||
{ |
||||
return $this->filetype; |
||||
} |
||||
|
||||
public function set_filetype($value) |
||||
{ |
||||
$this->filetype = $value; |
||||
} |
||||
|
||||
public function get_size() |
||||
{ |
||||
return $this->size; |
||||
} |
||||
|
||||
public function set_size($value) |
||||
{ |
||||
$this->size = (int) $value; |
||||
} |
||||
|
||||
public function get_readonly() |
||||
{ |
||||
return $this->readonly; |
||||
} |
||||
|
||||
public function set_readonly($value) |
||||
{ |
||||
$this->readonly = (bool) $value; |
||||
} |
||||
|
||||
public function get_session_id() |
||||
{ |
||||
return $this->session_id; |
||||
} |
||||
|
||||
public function set_session_id($value) |
||||
{ |
||||
$this->session_id = (int) $value; |
||||
} |
||||
|
||||
public function is_folder() |
||||
{ |
||||
return $this->filetype == 'folder'; |
||||
} |
||||
|
||||
public function is_file() |
||||
{ |
||||
return $this->filetype == 'file'; |
||||
} |
||||
|
||||
public function is_visible() |
||||
{ |
||||
$this->get_item_property()->get_visibility() == 1; |
||||
} |
||||
|
||||
public function is_accessible() |
||||
{ |
||||
return api_is_allowed_to_edit() || $this->is_visible(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return \Model\Course |
||||
*/ |
||||
public function get_course() |
||||
{ |
||||
if ($this->course && $this->course->get_id() == $this->c_id) { |
||||
return $this->course; |
||||
} |
||||
|
||||
$this->course = Course::get_by_id($this->c_id); |
||||
return $this->course; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return \Model\ItemProperty |
||||
*/ |
||||
public function get_item_property() |
||||
{ |
||||
if ($this->item_property && $this->item_property->get_c_id() == $this->c_id && $this->item_property->get_ref() == $this->id) { |
||||
return $this->item_property; |
||||
} |
||||
|
||||
$this->item_property = ItemProperty::get_by_ref($this->id, TOOL_DOCUMENT); |
||||
return $this->item_property; |
||||
} |
||||
|
||||
public function get_absolute_path() |
||||
{ |
||||
$course = $this->get_course(); |
||||
return $course->get_path() . 'document' . $this->path; |
||||
} |
||||
|
||||
public function __toString() |
||||
{ |
||||
return $this->get_absolute_path(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param bool $all |
||||
* @return ResultSet|array |
||||
*/ |
||||
public function get_children($all = false) |
||||
{ |
||||
if (!$this->is_folder()) { |
||||
return array(); |
||||
} |
||||
$path = $this->path; |
||||
$c_id = $this->c_id; |
||||
if ($this->all) { |
||||
$where = "doc.c_id = $c_id AND doc.path LIKE '$path/%'"; |
||||
} else { |
||||
$where = "doc.c_id = $c_id AND doc.path LIKE '$path/%' AND doc.path NOT LIKE '$path/%/%'"; |
||||
} |
||||
return self::query($where); |
||||
} |
||||
|
||||
} |
@ -1,100 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Description of Entity |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class Entity |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @return \Entity\Course |
||||
*/ |
||||
public static function current_course() |
||||
{ |
||||
static $result = false; |
||||
if ($result === false) { |
||||
$repo = \Entity\Course::repository(); |
||||
$course_id = api_get_course_int_id(); |
||||
if ($course_id) { |
||||
$result = $repo->find($course_id); |
||||
} |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return \Entity\Session |
||||
*/ |
||||
public static function current_session() |
||||
{ |
||||
static $result = false; |
||||
if ($result === false) { |
||||
$repo = \Entity\Session::repository(); |
||||
$session_id = api_get_session_id(); |
||||
$result = $repo->find($session_id); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
function __construct($data = null) |
||||
{ |
||||
if ($data) { |
||||
foreach ($this as $key => $value) { |
||||
if (isset($data->{$key})) { |
||||
$this->{$key} = $data->{$key}; |
||||
} |
||||
} |
||||
} |
||||
$this->defaults('session_id', api_get_session_id()); |
||||
} |
||||
|
||||
function __get($name) |
||||
{ |
||||
$f = array($this, "get_$name"); |
||||
return call_user_func($f); |
||||
} |
||||
|
||||
function __isset($name) |
||||
{ |
||||
$f = array($this, "get_$name"); |
||||
return is_callable($f); |
||||
} |
||||
|
||||
function __set($name, $value) |
||||
{ |
||||
$f = array($this, "set_$name"); |
||||
if (!is_callable($f)) { |
||||
return; |
||||
} |
||||
call_user_func($f, $value); |
||||
} |
||||
|
||||
function before_save() |
||||
{ |
||||
$repo = $this->repository(); |
||||
$field = $repo->get_id_field(); |
||||
if (empty($field)) { |
||||
return; |
||||
} |
||||
|
||||
$value = isset($this->{$field}) ? $this->{$field} : null; |
||||
if ($value) { |
||||
return; |
||||
} |
||||
$next_id = $repo->next_id($this); |
||||
$this->{$field} = $next_id; |
||||
} |
||||
|
||||
function defaults($name, $value) |
||||
{ |
||||
if (property_exists($this, $name) && empty($this->{$name})) { |
||||
$this->{$name} = $value; |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,83 +0,0 @@ |
||||
<?php |
||||
|
||||
use Doctrine\ORM\QueryBuilder; |
||||
|
||||
/** |
||||
* Description of repository |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class EntityRepository extends Doctrine\ORM\EntityRepository |
||||
{ |
||||
|
||||
function next_id($entity = null) |
||||
{ |
||||
$column = $this->get_id_field(); |
||||
if (empty($column)) { |
||||
return false; |
||||
} |
||||
|
||||
$metadata = $this->getClassMetadata(); |
||||
$entity_name = $metadata->name; |
||||
|
||||
if ($this->is_course_table()) { |
||||
$course = $entity ? $entity->get_c_id() : Entity::current_course(); |
||||
$course = $course ? $course : Entity::current_course(); |
||||
$c_id = is_object($course) ? $course->get_id() : $course; |
||||
if (empty($c_id)) { |
||||
return null; |
||||
} |
||||
|
||||
$query = new QueryBuilder($this->getEntityManager()); |
||||
$query = $query->select("MAX(t.id) AS m")->from($entity_name, 't')->where('t.c_id = ' . $c_id); |
||||
} else { |
||||
$query = new QueryBuilder($this->getEntityManager()); |
||||
$query = $query->select("MAX(t.$column) AS m")->from($entity_name, 't'); |
||||
} |
||||
$result = $this->getEntityManager()->createQuery($query); |
||||
$result = $result->getSingleScalarResult(); |
||||
$result += 10; //in case somebody does an insert in between |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return string|bool |
||||
*/ |
||||
function get_id_field() |
||||
{ |
||||
$metadata = $this->getClassMetadata(); |
||||
if (count($metadata->identifier) == 1) { |
||||
$field = $metadata->identifier[0]; |
||||
return $field; |
||||
} |
||||
if (count($metadata->identifier) > 2) { |
||||
return false; |
||||
} |
||||
|
||||
if (isset($metadata->identifier['id'])) { |
||||
return 'id'; |
||||
} |
||||
|
||||
if (!$this->is_course_table()) { |
||||
return false; |
||||
} |
||||
|
||||
|
||||
foreach ($metadata->identifier as $field) { |
||||
if ($field != 'c_id' && $field != 'course') { |
||||
return $field; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
function is_course_table() |
||||
{ |
||||
$metadata = $this->getClassMetadata(); |
||||
$table = $metadata->table['name']; |
||||
return strpos($table, 'c_') === 0; |
||||
} |
||||
|
||||
} |
@ -1,390 +0,0 @@ |
||||
<?php |
||||
/* This library is licensed under New BSD. See below to check its terms.*/ |
||||
/* |
||||
================================================================================ |
||||
|
||||
EvalMath - PHP Class to safely evaluate math expressions |
||||
Copyright (C) 2005 Miles Kaufmann <http://www.twmagic.com/> |
||||
|
||||
================================================================================ |
||||
|
||||
NAME |
||||
EvalMath - safely evaluate math expressions |
||||
|
||||
SYNOPSIS |
||||
<? |
||||
include('evalmath.class.php'); |
||||
$m = new EvalMath; |
||||
// basic evaluation: |
||||
$result = $m->evaluate('2+2'); |
||||
// supports: order of operation; parentheses; negation; built-in functions |
||||
$result = $m->evaluate('-8(5/2)^2*(1-sqrt(4))-8'); |
||||
// create your own variables |
||||
$m->evaluate('a = e^(ln(pi))'); |
||||
// or functions |
||||
$m->evaluate('f(x,y) = x^2 + y^2 - 2x*y + 1'); |
||||
// and then use them |
||||
$result = $m->evaluate('3*f(42,a)'); |
||||
?> |
||||
|
||||
DESCRIPTION |
||||
Use the EvalMath class when you want to evaluate mathematical expressions |
||||
from untrusted sources. You can define your own variables and functions, |
||||
which are stored in the object. Try it, it's fun! |
||||
|
||||
METHODS |
||||
$m->evalute($expr) |
||||
Evaluates the expression and returns the result. If an error occurs, |
||||
prints a warning and returns false. If $expr is a function assignment, |
||||
returns true on success. |
||||
|
||||
$m->e($expr) |
||||
A synonym for $m->evaluate(). |
||||
|
||||
$m->vars() |
||||
Returns an associative array of all user-defined variables and values. |
||||
|
||||
$m->funcs() |
||||
Returns an array of all user-defined functions. |
||||
|
||||
PARAMETERS |
||||
$m->suppress_errors |
||||
Set to true to turn off warnings when evaluating expressions |
||||
|
||||
$m->last_error |
||||
If the last evaluation failed, contains a string describing the error. |
||||
(Useful when suppress_errors is on). |
||||
|
||||
AUTHOR INFORMATION |
||||
Copyright 2005, Miles Kaufmann. |
||||
|
||||
LICENSE |
||||
Redistribution and use in source and binary forms, with or without |
||||
modification, are permitted provided that the following conditions are |
||||
met: |
||||
|
||||
1 Redistributions of source code must retain the above copyright |
||||
notice, this list of conditions and the following disclaimer. |
||||
2. Redistributions in binary form must reproduce the above copyright |
||||
notice, this list of conditions and the following disclaimer in the |
||||
documentation and/or other materials provided with the distribution. |
||||
3. The name of the author may not be used to endorse or promote |
||||
products derived from this software without specific prior written |
||||
permission. |
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||||
POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
*/ |
||||
|
||||
class EvalMath { |
||||
|
||||
var $suppress_errors = false; |
||||
var $last_error = null; |
||||
|
||||
var $v = array('e'=>2.71,'pi'=>3.14); // variables (and constants) |
||||
var $f = array(); // user-defined functions |
||||
var $vb = array('e', 'pi'); // constants |
||||
var $fb = array( // built-in functions |
||||
'sin','sinh','arcsin','asin','arcsinh','asinh', |
||||
'cos','cosh','arccos','acos','arccosh','acosh', |
||||
'tan','tanh','arctan','atan','arctanh','atanh', |
||||
'sqrt','abs','ln','log'); |
||||
|
||||
function EvalMath() { |
||||
// make the variables a little more accurate |
||||
$this->v['pi'] = pi(); |
||||
$this->v['e'] = exp(1); |
||||
} |
||||
|
||||
function e($expr) { |
||||
return $this->evaluate($expr); |
||||
} |
||||
|
||||
function evaluate($expr) { |
||||
$this->last_error = null; |
||||
$expr = trim($expr); |
||||
if (substr($expr, -1, 1) == ';') $expr = substr($expr, 0, strlen($expr)-1); // strip semicolons at the end |
||||
//=============== |
||||
// is it a variable assignment? |
||||
if (preg_match('/^\s*([a-z]\w*)\s*=\s*(.+)$/', $expr, $matches)) { |
||||
if (in_array($matches[1], $this->vb)) { // make sure we're not assigning to a constant |
||||
return $this->trigger("cannot assign to constant '$matches[1]'"); |
||||
} |
||||
if (($tmp = $this->pfx($this->nfx($matches[2]))) === false) return false; // get the result and make sure it's good |
||||
$this->v[$matches[1]] = $tmp; // if so, stick it in the variable array |
||||
return $this->v[$matches[1]]; // and return the resulting value |
||||
//=============== |
||||
// is it a function assignment? |
||||
} elseif (preg_match('/^\s*([a-z]\w*)\s*\(\s*([a-z]\w*(?:\s*,\s*[a-z]\w*)*)\s*\)\s*=\s*(.+)$/', $expr, $matches)) { |
||||
$fnn = $matches[1]; // get the function name |
||||
if (in_array($matches[1], $this->fb)) { // make sure it isn't built in |
||||
return $this->trigger("cannot redefine built-in function '$matches[1]()'"); |
||||
} |
||||
$args = explode(",", preg_replace("/\s+/", "", $matches[2])); // get the arguments |
||||
if (($stack = $this->nfx($matches[3])) === false) return false; // see if it can be converted to postfix |
||||
for ($i = 0; $i<count($stack); $i++) { // freeze the state of the non-argument variables |
||||
$token = $stack[$i]; |
||||
if (preg_match('/^[a-z]\w*$/', $token) and !in_array($token, $args)) { |
||||
if (array_key_exists($token, $this->v)) { |
||||
$stack[$i] = $this->v[$token]; |
||||
} else { |
||||
return $this->trigger("undefined variable '$token' in function definition"); |
||||
} |
||||
} |
||||
} |
||||
$this->f[$fnn] = array('args'=>$args, 'func'=>$stack); |
||||
return true; |
||||
//=============== |
||||
} else { |
||||
return $this->pfx($this->nfx($expr)); // straight up evaluation, woo |
||||
} |
||||
} |
||||
|
||||
function vars() { |
||||
$output = $this->v; |
||||
unset($output['pi']); |
||||
unset($output['e']); |
||||
return $output; |
||||
} |
||||
|
||||
function funcs() { |
||||
$output = array(); |
||||
foreach ($this->f as $fnn=>$dat) |
||||
$output[] = $fnn . '(' . implode(',', $dat['args']) . ')'; |
||||
return $output; |
||||
} |
||||
|
||||
//===================== HERE BE INTERNAL METHODS ====================\\ |
||||
|
||||
// Convert infix to postfix notation |
||||
function nfx($expr) { |
||||
|
||||
$index = 0; |
||||
$stack = new EvalMathStack; |
||||
$output = array(); // postfix form of expression, to be passed to pfx() |
||||
$expr = trim(strtolower($expr)); |
||||
|
||||
$ops = array('+', '-', '*', '/', '^', '_'); |
||||
$ops_r = array('+'=>0,'-'=>0,'*'=>0,'/'=>0,'^'=>1); // right-associative operator? |
||||
$ops_p = array('+'=>0,'-'=>0,'*'=>1,'/'=>1,'_'=>1,'^'=>2); // operator precedence |
||||
|
||||
$expecting_op = false; // we use this in syntax-checking the expression |
||||
// and determining when a - is a negation |
||||
|
||||
if (preg_match("/[^\w\s+*^\/()\.,-]/", $expr, $matches)) { // make sure the characters are all good |
||||
return $this->trigger("illegal character '{$matches[0]}'"); |
||||
} |
||||
|
||||
while(1) { // 1 Infinite Loop ;) |
||||
$op = substr($expr, $index, 1); // get the first character at the current index |
||||
// find out if we're currently at the beginning of a number/variable/function/parenthesis/operand |
||||
$ex = preg_match('/^([a-z]\w*\(?|\d+(?:\.\d*)?|\.\d+|\()/', substr($expr, $index), $match); |
||||
//=============== |
||||
if ($op == '-' and !$expecting_op) { // is it a negation instead of a minus? |
||||
$stack->push('_'); // put a negation on the stack |
||||
$index++; |
||||
} elseif ($op == '_') { // we have to explicitly deny this, because it's legal on the stack |
||||
return $this->trigger("illegal character '_'"); // but not in the input expression |
||||
//=============== |
||||
} elseif ((in_array($op, $ops) or $ex) and $expecting_op) { // are we putting an operator on the stack? |
||||
if ($ex) { // are we expecting an operator but have a number/variable/function/opening parethesis? |
||||
$op = '*'; $index--; // it's an implicit multiplication |
||||
} |
||||
// heart of the algorithm: |
||||
while($stack->count > 0 and ($o2 = $stack->last()) and in_array($o2, $ops) and ($ops_r[$op] ? $ops_p[$op] < $ops_p[$o2] : $ops_p[$op] <= $ops_p[$o2])) { |
||||
$output[] = $stack->pop(); // pop stuff off the stack into the output |
||||
} |
||||
// many thanks: http://en.wikipedia.org/wiki/Reverse_Polish_notation#The_algorithm_in_detail |
||||
$stack->push($op); // finally put OUR operator onto the stack |
||||
$index++; |
||||
$expecting_op = false; |
||||
//=============== |
||||
} elseif ($op == ')' and $expecting_op) { // ready to close a parenthesis? |
||||
while (($o2 = $stack->pop()) != '(') { // pop off the stack back to the last ( |
||||
if (is_null($o2)) return $this->trigger("unexpected ')'"); |
||||
else $output[] = $o2; |
||||
} |
||||
if (preg_match("/^([a-z]\w*)\($/", $stack->last(2), $matches)) { // did we just close a function? |
||||
$fnn = $matches[1]; // get the function name |
||||
$arg_count = $stack->pop(); // see how many arguments there were (cleverly stored on the stack, thank you) |
||||
$output[] = $stack->pop(); // pop the function and push onto the output |
||||
if (in_array($fnn, $this->fb)) { // check the argument count |
||||
if($arg_count > 1) |
||||
return $this->trigger("too many arguments ($arg_count given, 1 expected)"); |
||||
} elseif (array_key_exists($fnn, $this->f)) { |
||||
if ($arg_count != count($this->f[$fnn]['args'])) |
||||
return $this->trigger("wrong number of arguments ($arg_count given, " . count($this->f[$fnn]['args']) . " expected)"); |
||||
} else { // did we somehow push a non-function on the stack? this should never happen |
||||
return $this->trigger("internal error"); |
||||
} |
||||
} |
||||
$index++; |
||||
//=============== |
||||
} elseif ($op == ',' and $expecting_op) { // did we just finish a function argument? |
||||
while (($o2 = $stack->pop()) != '(') { |
||||
if (is_null($o2)) return $this->trigger("unexpected ','"); // oops, never had a ( |
||||
else $output[] = $o2; // pop the argument expression stuff and push onto the output |
||||
} |
||||
// make sure there was a function |
||||
if (!preg_match("/^([a-z]\w*)\($/", $stack->last(2), $matches)) |
||||
return $this->trigger("unexpected ','"); |
||||
$stack->push($stack->pop()+1); // increment the argument count |
||||
$stack->push('('); // put the ( back on, we'll need to pop back to it again |
||||
$index++; |
||||
$expecting_op = false; |
||||
//=============== |
||||
} elseif ($op == '(' and !$expecting_op) { |
||||
$stack->push('('); // that was easy |
||||
$index++; |
||||
$allow_neg = true; |
||||
//=============== |
||||
} elseif ($ex and !$expecting_op) { // do we now have a function/variable/number? |
||||
$expecting_op = true; |
||||
$val = $match[1]; |
||||
if (preg_match("/^([a-z]\w*)\($/", $val, $matches)) { // may be func, or variable w/ implicit multiplication against parentheses... |
||||
if (in_array($matches[1], $this->fb) or array_key_exists($matches[1], $this->f)) { // it's a func |
||||
$stack->push($val); |
||||
$stack->push(1); |
||||
$stack->push('('); |
||||
$expecting_op = false; |
||||
} else { // it's a var w/ implicit multiplication |
||||
$val = $matches[1]; |
||||
$output[] = $val; |
||||
} |
||||
} else { // it's a plain old var or num |
||||
$output[] = $val; |
||||
} |
||||
$index += strlen($val); |
||||
//=============== |
||||
} elseif ($op == ')') { // miscellaneous error checking |
||||
return $this->trigger("unexpected ')'"); |
||||
} elseif (in_array($op, $ops) and !$expecting_op) { |
||||
return $this->trigger("unexpected operator '$op'"); |
||||
} else { // I don't even want to know what you did to get here |
||||
return $this->trigger("an unexpected error occured"); |
||||
} |
||||
if ($index == strlen($expr)) { |
||||
if (in_array($op, $ops)) { // did we end with an operator? bad. |
||||
return $this->trigger("operator '$op' lacks operand"); |
||||
} else { |
||||
break; |
||||
} |
||||
} |
||||
while (substr($expr, $index, 1) == ' ') { // step the index past whitespace (pretty much turns whitespace |
||||
$index++; // into implicit multiplication if no operator is there) |
||||
} |
||||
|
||||
} |
||||
while (!is_null($op = $stack->pop())) { // pop everything off the stack and push onto output |
||||
if ($op == '(') return $this->trigger("expecting ')'"); // if there are (s on the stack, ()s were unbalanced |
||||
$output[] = $op; |
||||
} |
||||
return $output; |
||||
} |
||||
|
||||
// evaluate postfix notation |
||||
function pfx($tokens, $vars = array()) { |
||||
|
||||
if ($tokens == false) return false; |
||||
|
||||
$stack = new EvalMathStack; |
||||
|
||||
foreach ($tokens as $token) { // nice and easy |
||||
// if the token is a binary operator, pop two values off the stack, do the operation, and push the result back on |
||||
if (in_array($token, array('+', '-', '*', '/', '^'))) { |
||||
if (is_null($op2 = $stack->pop())) return $this->trigger("internal error"); |
||||
if (is_null($op1 = $stack->pop())) return $this->trigger("internal error"); |
||||
switch ($token) { |
||||
case '+': |
||||
$stack->push($op1+$op2); break; |
||||
case '-': |
||||
$stack->push($op1-$op2); break; |
||||
case '*': |
||||
$stack->push($op1*$op2); break; |
||||
case '/': |
||||
if ($op2 == 0) return $this->trigger("division by zero"); |
||||
$stack->push($op1/$op2); break; |
||||
case '^': |
||||
$stack->push(pow($op1, $op2)); break; |
||||
} |
||||
// if the token is a unary operator, pop one value off the stack, do the operation, and push it back on |
||||
} elseif ($token == "_") { |
||||
$stack->push(-1*$stack->pop()); |
||||
// if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on |
||||
} elseif (preg_match("/^([a-z]\w*)\($/", $token, $matches)) { // it's a function! |
||||
$fnn = $matches[1]; |
||||
if (in_array($fnn, $this->fb)) { // built-in function: |
||||
if (is_null($op1 = $stack->pop())) return $this->trigger("internal error"); |
||||
$fnn = preg_replace("/^arc/", "a", $fnn); // for the 'arc' trig synonyms |
||||
if ($fnn == 'ln') $fnn = 'log'; |
||||
eval('$stack->push(' . $fnn . '($op1));'); // perfectly safe eval() |
||||
} elseif (array_key_exists($fnn, $this->f)) { // user function |
||||
// get args |
||||
$args = array(); |
||||
for ($i = count($this->f[$fnn]['args'])-1; $i >= 0; $i--) { |
||||
if (is_null($args[$this->f[$fnn]['args'][$i]] = $stack->pop())) return $this->trigger("internal error"); |
||||
} |
||||
$stack->push($this->pfx($this->f[$fnn]['func'], $args)); // yay... recursion!!!! |
||||
} |
||||
// if the token is a number or variable, push it on the stack |
||||
} else { |
||||
if (is_numeric($token)) { |
||||
$stack->push($token); |
||||
} elseif (array_key_exists($token, $this->v)) { |
||||
$stack->push($this->v[$token]); |
||||
} elseif (array_key_exists($token, $vars)) { |
||||
$stack->push($vars[$token]); |
||||
} else { |
||||
return $this->trigger("undefined variable '$token'"); |
||||
} |
||||
} |
||||
} |
||||
// when we're out of tokens, the stack should have a single element, the final result |
||||
if ($stack->count != 1) return $this->trigger("internal error"); |
||||
return $stack->pop(); |
||||
} |
||||
|
||||
// trigger an error, but nicely, if need be |
||||
function trigger($msg) { |
||||
$this->last_error = $msg; |
||||
if (!$this->suppress_errors) trigger_error($msg, E_USER_WARNING); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
// for internal use |
||||
class EvalMathStack { |
||||
|
||||
var $stack = array(); |
||||
var $count = 0; |
||||
|
||||
function push($val) { |
||||
$this->stack[$this->count] = $val; |
||||
$this->count++; |
||||
} |
||||
|
||||
function pop() { |
||||
if ($this->count > 0) { |
||||
$this->count--; |
||||
return $this->stack[$this->count]; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
function last($n=1) { |
||||
if (isset($this->stack[$this->count-$n])) { |
||||
return $this->stack[$this->count-$n]; |
||||
} |
||||
return; |
||||
} |
||||
} |
@ -1,603 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace Model; |
||||
|
||||
use ResultSet; |
||||
use Database; |
||||
|
||||
/** |
||||
* Represent a database "item_property" object - i.e. common properties for tool |
||||
* objects: created date, modified date, etc. |
||||
* |
||||
* Note: |
||||
* |
||||
* Each database column is mapped to a property. |
||||
* |
||||
* |
||||
* Some db query functions exists in this class and would need to be adapted |
||||
* to Sympony once it is moved to production. Yet the object structure should |
||||
* stay. |
||||
* |
||||
* @see \Model\ItemProperty |
||||
* @see table c_item_property |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class ItemProperty |
||||
{ |
||||
|
||||
const VISIBILITY_INVISIBLE = 0; |
||||
const VISIBILITY_VISIBLE = 1; |
||||
const VISIBILITY_DELETED = 2; |
||||
|
||||
/** |
||||
* |
||||
* @return ItemPropertyRepository |
||||
*/ |
||||
public static function repository() |
||||
{ |
||||
return ItemPropertyRepository::instance(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $where |
||||
* @return \ResultSet |
||||
*/ |
||||
public static function query($where) |
||||
{ |
||||
return self::repository()->query($where); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param id $ref |
||||
* @param string $tool |
||||
* @return \Model\ItemProperty |
||||
*/ |
||||
public static function get_by_ref($ref, $tool) |
||||
{ |
||||
return self::repository()->get_by_ref($ref, $tool); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param array|object $data |
||||
* @return \Model\ItemProperty |
||||
*/ |
||||
static function create($data) |
||||
{ |
||||
return new self($data); |
||||
} |
||||
|
||||
protected $c_id = 0; |
||||
protected $id = 0; |
||||
protected $tool = ''; |
||||
protected $insert_user_id = 0; |
||||
protected $insert_date = 0; |
||||
protected $lastedit_date = 0; |
||||
protected $ref = ''; |
||||
protected $lastedit_type = ''; |
||||
protected $lastedit_user_id = 0; |
||||
protected $to_group_id = null; |
||||
protected $to_user_id = null; |
||||
protected $visibility = self::VISIBILITY_VISIBLE; |
||||
protected $start_visible = 0; |
||||
protected $end_visible = 0; |
||||
protected $id_session = 0; |
||||
|
||||
public function __construct($data) |
||||
{ |
||||
$data = (object) $data; |
||||
$this->c_id = (int) $data->c_id; |
||||
$this->id = (int) $data->id; |
||||
$this->tool = $data->tool; |
||||
$this->insert_user_id = (int) $data->insert_user_id; |
||||
$this->insert_date = is_numeric($data->insert_date) ? $data->insert_date : strtotime($data->insert_date); |
||||
$this->lastedit_date = is_numeric($data->lastedit_date) ? $data->lastedit_date : strtotime($data->lastedit_date); |
||||
$this->ref = (int) $data->ref; |
||||
$this->lastedit_type = $data->lastedit_type; |
||||
$this->lastedit_user_id = (int) $data->lastedit_user_id; |
||||
$this->to_group_id = (int) $data->to_group_id; |
||||
$this->to_user_id = (int) $data->to_user_id; |
||||
$this->visibility = (int) $data->visibility; |
||||
$this->start_visible = is_numeric($data->start_visible) ? $data->start_visible : strtotime($data->start_visible); |
||||
$this->end_visible = is_numeric($data->end_visible) ? $data->end_visible : strtotime($data->end_visible); |
||||
$this->id_session = $data->id_session; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_c_id() |
||||
{ |
||||
return $this->c_id; |
||||
} |
||||
|
||||
public function set_c_id($value) |
||||
{ |
||||
$this->c_id = (int) $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_id() |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function set_id($value) |
||||
{ |
||||
$this->id = (int) $value; |
||||
} |
||||
|
||||
public function get_tool() |
||||
{ |
||||
return $this->tool; |
||||
} |
||||
|
||||
public function set_tool($value) |
||||
{ |
||||
$this->tool = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_insert_user_id() |
||||
{ |
||||
return $this->insert_user_id; |
||||
} |
||||
|
||||
public function set_insert_user_id($value) |
||||
{ |
||||
$this->insert_user_id = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_insert_date() |
||||
{ |
||||
return $this->insert_date; |
||||
} |
||||
|
||||
public function set_insert_date($value) |
||||
{ |
||||
$value = is_numeric($value) ? $value : strtotime($value); |
||||
$this->insert_date = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_lastedit_date() |
||||
{ |
||||
return $this->lastedit_date; |
||||
} |
||||
|
||||
public function set_lastedit_date($value) |
||||
{ |
||||
$value = is_numeric($value) ? $value : strtotime($value); |
||||
$this->lastedit_date = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_ref() |
||||
{ |
||||
return $this->ref; |
||||
} |
||||
|
||||
public function set_ref($value) |
||||
{ |
||||
$this->ref = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function get_lastedit_type() |
||||
{ |
||||
return $this->lastedit_type; |
||||
} |
||||
|
||||
public function set_lastedit_type($value) |
||||
{ |
||||
$this->lastedit_type = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_lastedit_user_id() |
||||
{ |
||||
return $this->lastedit_user_id; |
||||
} |
||||
|
||||
public function set_lastedit_user_id($value) |
||||
{ |
||||
$this->lastedit_user_id = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_to_group_id() |
||||
{ |
||||
return $this->to_group_id; |
||||
} |
||||
|
||||
public function set_to_group_id($value) |
||||
{ |
||||
$this->to_group_id = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_to_user_id() |
||||
{ |
||||
return $this->to_user_id; |
||||
} |
||||
|
||||
public function set_to_user_id($value) |
||||
{ |
||||
$this->to_user_id = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_visibility() |
||||
{ |
||||
return $this->visibility; |
||||
} |
||||
|
||||
public function set_visibility($value) |
||||
{ |
||||
$this->visibility = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_start_visible() |
||||
{ |
||||
return $this->start_visible; |
||||
} |
||||
|
||||
public function set_start_visible($value) |
||||
{ |
||||
$value = is_numeric($value) ? $value : strtotime($value); |
||||
$this->start_visible = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_end_visible() |
||||
{ |
||||
return $this->end_visible; |
||||
} |
||||
|
||||
public function set_end_visible($value) |
||||
{ |
||||
$value = is_numeric($value) ? $value : strtotime($value); |
||||
$this->end_visible = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function get_id_session() |
||||
{ |
||||
return $this->id_session; |
||||
} |
||||
|
||||
public function set_id_session($value) |
||||
{ |
||||
$this->id_session = $value; |
||||
} |
||||
|
||||
public function mark_deleted() |
||||
{ |
||||
$this->set_visibility(self::VISIBILITY_DELETED); |
||||
|
||||
$tool = $this->get_tool(); |
||||
$lastedit_type = str_replace('_', '', ucwords($tool)) . 'Deleted'; |
||||
$this->set_lastedit_type($lastedit_type); |
||||
|
||||
$user_id = api_get_user_id(); |
||||
$this->set_insert_user_id($user_id); |
||||
} |
||||
|
||||
public function mark_visible() |
||||
{ |
||||
$this->set_visibility(self::VISIBILITY_VISIBLE); |
||||
$tool = $this->get_tool(); |
||||
|
||||
$lastedit_type = str_replace('_', '', ucwords($tool)) . 'Visible'; |
||||
$this->set_lastedit_type($lastedit_type); |
||||
|
||||
$user_id = api_get_user_id(); |
||||
$this->set_insert_user_id($user_id); |
||||
} |
||||
|
||||
public function mark_invisible() |
||||
{ |
||||
$this->set_visibility(self::VISIBILITY_INVISIBLE); |
||||
$tool = $this->get_tool(); |
||||
|
||||
$lastedit_type = str_replace('_', '', ucwords($tool)) . 'Invisible'; |
||||
$this->set_lastedit_type($lastedit_type); |
||||
|
||||
$user_id = api_get_user_id(); |
||||
$this->set_insert_user_id($user_id); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
class ItemPropertyRepository |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @return \Model\ItemPropertyRepository |
||||
*/ |
||||
public static function instance() |
||||
{ |
||||
static $result = null; |
||||
if (empty($result)) { |
||||
$result = new self(); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $where |
||||
* @return \ResultSet |
||||
*/ |
||||
public function query($where) |
||||
{ |
||||
$table = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||||
$sql = "SELECT * FROM $table "; |
||||
$sql .= $where ? "WHERE $where" : ''; |
||||
$result = new ResultSet($sql); |
||||
return $result->return_type(__CLASS__); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param id $ref |
||||
* @param string $tool |
||||
* @return \Model\ItemProperty |
||||
*/ |
||||
public function get_by_ref($ref, $tool) |
||||
{ |
||||
return $this->query("ref=$ref AND tool = '$tool'")->first(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param ItemProperty $item |
||||
*/ |
||||
function save($item) |
||||
{ |
||||
if ($this->exists($item)) { |
||||
$this->update($item); |
||||
} else { |
||||
$this->insert($item); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns true if item is not new, false otherwise. |
||||
* |
||||
* @param ItemProperty $item |
||||
* @return bool |
||||
*/ |
||||
public function exists($item) |
||||
{ |
||||
$id = $item->get_id(); |
||||
$c_id = $item->get_c_id(); |
||||
return !empty($id) && !empty($c_id); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param ItemProperty $item |
||||
* @return bool |
||||
*/ |
||||
public function insert($item) |
||||
{ |
||||
$this->defaults($item); |
||||
$user_id = api_get_user_id(); |
||||
$item->set_insert_user_id($user_id); |
||||
|
||||
$c_id = $item->get_c_id(); |
||||
$id = $item->get_id(); |
||||
$tool = Database::escape_string($item->get_tool()); |
||||
$insert_user_id = $item->get_insert_user_id(); |
||||
$insert_date = api_get_utc_datetime($item->get_insert_date()); |
||||
$lastedit_date = api_get_utc_datetime($item->get_lastedit_date()); |
||||
$ref = $item->get_ref(); |
||||
$lastedit_type = Database::escape_string($item->get_lastedit_type()); |
||||
$last_edit_user_id = $item->get_lastedit_user_id(); |
||||
|
||||
$to_group_id = $item->get_to_group_id(); |
||||
$to_group_id = empty($to_group_id) ? '0' : $to_group_id; |
||||
|
||||
$to_user_id = $item->get_to_user_id(); |
||||
$to_user_id = empty($to_user_id) ? '0' : $to_user_id; |
||||
|
||||
$visibility = $item->get_visibility(); |
||||
$visibility = $visibility ? $visibility : '0'; |
||||
|
||||
$start_visible = $item->get_start_visible(); |
||||
$start_visible = empty($start_visible) ? '0000-00-00 00:00:00' : api_get_utc_datetime($start_visible); |
||||
|
||||
$end_visible = $item->get_end_visible(); |
||||
$end_visible = empty($end_visible) ? '0000-00-00 00:00:00' : api_get_utc_datetime($end_visible); |
||||
|
||||
$session_id = $item->get_id_session(); |
||||
|
||||
$TABLE = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||||
|
||||
|
||||
$sql = "INSERT INTO $TABLE_ITEMPROPERTY ( |
||||
c_id, |
||||
tool, |
||||
insert_user_id, |
||||
insert_date, |
||||
lastedit_date, |
||||
ref, |
||||
lastedit_type, |
||||
lastedit_user_id, |
||||
to_group_id, |
||||
to_user_id, |
||||
visibility, |
||||
start_visible, |
||||
end_visible, |
||||
id_session |
||||
) VALUES ( |
||||
$c_id, |
||||
'$tool', |
||||
$insert_user_id, |
||||
'$insert_date', |
||||
'$lastedit_date', |
||||
$ref, |
||||
'$lastedit_type', |
||||
$last_edit_user_id, |
||||
$to_group_id, |
||||
$to_user_id, |
||||
$visibility, |
||||
'$start_visible', |
||||
'$end_visible', |
||||
'$session_id' |
||||
)"; |
||||
|
||||
$result = Database::query($sql); |
||||
$id = Database::insert_id(); |
||||
if ($id) { |
||||
$item->set_id($id); |
||||
} |
||||
return (bool) $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param ItemProperty $item |
||||
*/ |
||||
public function update($item) |
||||
{ |
||||
$this->defaults($item); |
||||
$user_id = api_get_user_id(); |
||||
$item->set_insert_user_id($user_id); |
||||
|
||||
$c_id = $item->get_c_id(); |
||||
$id = $item->get_id(); |
||||
//$tool = Database::escape_string($item->get_tool()); |
||||
//$insert_user_id = $item->get_insert_user_id(); |
||||
//$insert_date = api_get_utc_datetime($item->get_insert_date()); |
||||
$lastedit_date = api_get_utc_datetime($item->get_lastedit_date()); |
||||
//$ref = $item->get_ref(); |
||||
$lastedit_type = Database::escape_string($item->get_lastedit_type()); |
||||
$last_edit_user_id = $item->get_lastedit_user_id(); |
||||
|
||||
$to_group_id = $item->get_to_group_id(); |
||||
$to_group_id = empty($to_group_id) ? '0' : $to_group_id; |
||||
|
||||
$to_user_id = $item->get_to_user_id(); |
||||
$to_user_id = empty($to_user_id) ? '0' : $to_user_id; |
||||
|
||||
$visibility = $item->get_visibility(); |
||||
$visibility = $visibility ? $visibility : '0'; |
||||
|
||||
$start_visible = $item->get_start_visible(); |
||||
$start_visible = empty($start_visible) ? '0000-00-00 00:00:00' : api_get_utc_datetime($start_visible); |
||||
|
||||
$end_visible = $item->get_end_visible(); |
||||
$end_visible = empty($end_visible) ? '0000-00-00 00:00:00' : api_get_utc_datetime($end_visible); |
||||
|
||||
$session_id = $item->get_id_session(); |
||||
|
||||
|
||||
$TABLE = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||||
$sql = "UPDATE |
||||
$TABLE |
||||
SET |
||||
lastedit_date = '$lastedit_date', |
||||
lastedit_type = '$lastedit_type', |
||||
lastedit_user_id = $last_edit_user_id, |
||||
to_group_id = $to_group_id, |
||||
to_user_id = $to_user_id, |
||||
visibility = $visibility, |
||||
start_visible = '$start_visible', |
||||
end_visible = '$end_visible', |
||||
id_session = $session_id |
||||
WHERE |
||||
c_id = $c_id AND |
||||
id = $id"; |
||||
|
||||
$result = Database::query($sql); |
||||
return (bool) $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param ItemProperty $item |
||||
*/ |
||||
function defaults($item) |
||||
{ |
||||
$now = time(); |
||||
$user = api_get_user_id(); |
||||
|
||||
$value = $item->get_insert_user_id(); |
||||
if (empty($value)) { |
||||
$item->set_insert_user_id($user); |
||||
} |
||||
|
||||
$value = get_insert_date(); |
||||
if (empty($value)) { |
||||
$item->set_insert_date($now); |
||||
} |
||||
|
||||
$value = get_lastedit_date(); |
||||
if (empty($value)) { |
||||
$item->set_lastedit_date($now); |
||||
} |
||||
|
||||
$value = $item->get_lastedit_user_id(); |
||||
if (empty($value)) { |
||||
$item->set_insert_user_id($user); |
||||
} |
||||
|
||||
$value = $item->get_id_session(); |
||||
if (empty($value)) { |
||||
$value = api_get_session_id(); |
||||
$item->set_session_id($value); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,91 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Javascript utility functions. |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class Javascript |
||||
{ |
||||
|
||||
/** |
||||
* Minimify Javascript. |
||||
* |
||||
* If called with a path |
||||
* |
||||
* input: /dir/dir/file.js |
||||
* returns: /dir/dir/file.min.js |
||||
* |
||||
* Otherwise returns the actual code. |
||||
* |
||||
* @param string $arg either a path or actual code |
||||
* @return string either a path to minified content (ends with min.js) or actual code |
||||
*/ |
||||
public static function minify($arg) |
||||
{ |
||||
if (is_readable($arg)) |
||||
{ |
||||
$path = $arg; |
||||
$code = file_get_contents($path); |
||||
$code = ClosureCompiler::post($code); |
||||
|
||||
$min_path = $path; |
||||
$min_path = str_replace('.js', '', $min_path); |
||||
$min_path .= '.min.js'; |
||||
file_put_contents($min_path, $code); |
||||
return $min_path; |
||||
} |
||||
else |
||||
{ |
||||
return ClosureCompiler::post($code); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns lang object that contains the translation. |
||||
* |
||||
* Javascript::get_lang('string1', 'string2', 'string3'); |
||||
* |
||||
* returns |
||||
* |
||||
* if(typeof(lang) == "undefined") |
||||
* { |
||||
* var lang = {}; |
||||
* } |
||||
* lang.string1 = "..."; |
||||
* lang.string2 = "..."; |
||||
* lang.string3 = "... |
||||
* |
||||
* @param type $_ |
||||
* @return type |
||||
*/ |
||||
public static function get_lang($_) |
||||
{ |
||||
$result = array(); |
||||
$result[] = 'if(typeof(lang) == "undefined")'; |
||||
$result[] = '{'; |
||||
$result[] = ' var lang = {};'; |
||||
$result[] = '}'; |
||||
|
||||
$keys = func_get_args(); |
||||
foreach ($keys as $key) |
||||
{ |
||||
$value = get_lang($key); |
||||
$result[] = 'lang.' . $key . ' = "' . $value . '";'; |
||||
} |
||||
return implode("\n", $result); |
||||
} |
||||
|
||||
public static function tag($src) |
||||
{ |
||||
return '<script type="text/javascript" src="' . $src . '"></script>'; |
||||
} |
||||
|
||||
public static function tag_code($code) |
||||
{ |
||||
$new_line = "\n"; |
||||
return '<script type="text/javascript">' . $new_line . $code . $new_line . '</script>'; |
||||
} |
||||
|
||||
} |
@ -1,168 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Web page wrapper. Usage: |
||||
* |
||||
* Page::create()->title('my_title')->display($content); |
||||
* |
||||
* $page = Page::create()->title('my_title')->help('help')->content($content); |
||||
* $page->display(); |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class Page |
||||
{ |
||||
|
||||
protected $title = null; |
||||
protected $help = null; |
||||
protected $header = null; |
||||
protected $content; |
||||
protected $breadcrumbs = ''; |
||||
protected $message = null; |
||||
protected $warning = null; |
||||
protected $error = null; |
||||
|
||||
/** |
||||
* |
||||
* @return Page |
||||
*/ |
||||
static function create($title = '') |
||||
{ |
||||
return new self($title); |
||||
} |
||||
|
||||
function __construct($title = '') |
||||
{ |
||||
$this->title = $title; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param $header |
||||
* @return Page |
||||
*/ |
||||
function header($header) |
||||
{ |
||||
$this->header = $header; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $title |
||||
* @return Page |
||||
*/ |
||||
function title($title) |
||||
{ |
||||
$this->title = $title; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param array $crumbs_ |
||||
* @return Page |
||||
*/ |
||||
function breadcrumbs($crumbs) |
||||
{ |
||||
$this->breadcrumbs = $crumbs; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $help help file name |
||||
* @return Page |
||||
*/ |
||||
function help($help) |
||||
{ |
||||
$this->help = $help; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $message |
||||
* @return Page |
||||
*/ |
||||
function message($message) |
||||
{ |
||||
$this->message = $message; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $warning |
||||
* @return Page |
||||
*/ |
||||
function warning($warning) |
||||
{ |
||||
$this->warning = $warning; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $error |
||||
* @return Page |
||||
*/ |
||||
function error($error) |
||||
{ |
||||
$this->error = $error; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param object|string $content |
||||
* @return Page |
||||
*/ |
||||
function content($content) |
||||
{ |
||||
$this->content = $content; |
||||
return $this; |
||||
} |
||||
|
||||
function __toString() |
||||
{ |
||||
$this->display($this->content); |
||||
} |
||||
|
||||
function display($content = null) |
||||
{ |
||||
$this->display_header(); |
||||
$this->display_content($content); |
||||
$this->display_footer(); |
||||
} |
||||
|
||||
function display_header() |
||||
{ |
||||
global $interbreadcrumb; |
||||
$interbreadcrumb = $this->breadcrumbs; |
||||
|
||||
Display::display_header($this->title, $this->help, $this->header); |
||||
if ($message = $this->message) { |
||||
Display::display_confirmation_message($message); |
||||
} |
||||
if ($warning = $this->warning) { |
||||
Display::display_warning_message($warning); |
||||
} |
||||
if ($error = $this->error) { |
||||
Display::display_error_message($error); |
||||
} |
||||
} |
||||
|
||||
protected function display_content($content) |
||||
{ |
||||
$content = $content ? $content : $this->content; |
||||
echo $content; |
||||
} |
||||
|
||||
function display_footer() |
||||
{ |
||||
Display::display_footer(); |
||||
} |
||||
|
||||
} |
@ -1,23 +0,0 @@ |
||||
<?php |
||||
|
||||
/* |
||||
* To change this template, choose Tools | Templates |
||||
* and open the template in the editor. |
||||
*/ |
||||
|
||||
/** |
||||
* Description of response |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class Response |
||||
{ |
||||
|
||||
public static function not_found() |
||||
{ |
||||
Header::response_code(404); |
||||
exit; |
||||
} |
||||
|
||||
} |
@ -1,194 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* ResultSet |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
* @deprecated |
||||
*/ |
||||
class ResultSet implements Countable, Iterator |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param string $sql |
||||
* @return ResultSet |
||||
*/ |
||||
static function create($sql) |
||||
{ |
||||
return new self($sql); |
||||
} |
||||
|
||||
protected $sql = ''; |
||||
protected $handle = null; |
||||
protected $current = false; |
||||
protected $index = -1; |
||||
protected $count = false; |
||||
protected $limit_count = null; |
||||
protected $limit_offset = null; |
||||
protected $orderby_column = null; |
||||
protected $orderby_direction = null; |
||||
protected $return_type = null; |
||||
|
||||
function __construct($sql, $limit_count = null, $limit_offset = null, $orderby_column = null, $orderby_direction = null, $return_type = null) |
||||
{ |
||||
$this->sql = $sql; |
||||
$this->limit_count = $limit_count; |
||||
$this->limit_offset = $limit_offset; |
||||
$this->orderby_column = $orderby_column; |
||||
$this->orderby_direction = $orderby_direction; |
||||
$this->return_type = $return_type; |
||||
} |
||||
|
||||
public function sql() |
||||
{ |
||||
$sql = $this->sql; |
||||
|
||||
$column = $this->orderby_column; |
||||
$direction = $this->orderby_direction; |
||||
|
||||
$offset = $this->limit_offset; |
||||
$count = $this->limit_count; |
||||
if (is_null($column) && is_null($count) && is_null($offset)) { |
||||
return $sql; |
||||
} |
||||
|
||||
if (strpos($sql, ' ORDER ') || strpos($sql, ' LIMIT ') || strpos($sql, ' OFFSET ')) { |
||||
$sql = "SELECT * FROM ($sql) AS dat "; |
||||
} else { |
||||
$sql .= ' '; |
||||
} |
||||
|
||||
if ($column) { |
||||
$sql .= "ORDER BY $column $direction "; |
||||
} |
||||
|
||||
if ($count) { |
||||
$sql .= "LIMIT $count "; |
||||
} |
||||
if ($offset) { |
||||
$sql .= "OFFSET $offset"; |
||||
} |
||||
|
||||
return $sql; |
||||
} |
||||
|
||||
protected function handle() |
||||
{ |
||||
if (is_null($this->handle)) { |
||||
$this->handle = Database::query($this->sql()); |
||||
} |
||||
|
||||
return $this->handle; |
||||
} |
||||
|
||||
public function count() |
||||
{ |
||||
if ($this->count === false) { |
||||
$sql = $this->sql(); |
||||
$sql = "SELECT COUNT(*) AS alpha FROM ($sql) AS dat "; |
||||
$rs = Database :: query($sql); |
||||
$data = Database::fetch_array($rs); |
||||
$count = $data ? $data['alpha'] : 0; |
||||
$this->count = (int) $count; |
||||
} |
||||
return $this->count; |
||||
} |
||||
|
||||
public function first() |
||||
{ |
||||
foreach ($this as $item) { |
||||
return $item; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param int $count |
||||
* @param int $from |
||||
* @return ResultSet |
||||
*/ |
||||
public function limit($count, $from = 0) |
||||
{ |
||||
$result = clone($this); |
||||
$result->limit_offset = $from; |
||||
$result->limit_count = $count; |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param int $column |
||||
* @param int $dir |
||||
* @return ResultSet |
||||
*/ |
||||
public function orderby($column, $dir = 'ASC') |
||||
{ |
||||
$result = clone($this); |
||||
$result->orderby_column = $column; |
||||
$result->orderby_direction = $dir; |
||||
return $result; |
||||
} |
||||
|
||||
public function return_type($value) |
||||
{ |
||||
$result = clone($this); |
||||
$result->return_type = $value; |
||||
return $result; |
||||
} |
||||
|
||||
public function current() |
||||
{ |
||||
return $this->current; |
||||
} |
||||
|
||||
public function key() |
||||
{ |
||||
return $this->index; |
||||
} |
||||
|
||||
public function next() |
||||
{ |
||||
$data = Database::fetch_assoc($this->handle()); |
||||
if (!$data) { |
||||
$this->current = $this->return_type ? null : array(); |
||||
} else if (empty($this->return_type)) { |
||||
$this->current = $data; |
||||
} else if ($this->return_type == 'object') { |
||||
$this->current = (object) $data; |
||||
} else { |
||||
$this->current = new $this->return_type($data); |
||||
} |
||||
$this->index++; |
||||
return $this->current; |
||||
} |
||||
|
||||
public function rewind() |
||||
{ |
||||
$this->handle = null; |
||||
$this->current = false; |
||||
$this->index = -1; |
||||
$this->next(); |
||||
} |
||||
|
||||
public function valid() |
||||
{ |
||||
return !empty($this->current); |
||||
} |
||||
|
||||
function __clone() |
||||
{ |
||||
$this->reset(); |
||||
} |
||||
|
||||
function reset() |
||||
{ |
||||
$this->handle = null; |
||||
$this->current = false; |
||||
$this->index = -1; |
||||
$this->count = false; |
||||
} |
||||
|
||||
} |
@ -1,206 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Definition of the SessionHandlerMemcache class |
||||
* @package chamilo.library |
||||
*/ |
||||
/** |
||||
* Class SessionHandlerMemcache deals with volatile Memcache storage |
||||
* and a more persistent but less frequent database backup storage |
||||
* @todo This class might require a review to MySQL calls, depending on |
||||
* when the session variables start to be saved |
||||
*/ |
||||
class SessionHandlerMemcache |
||||
{ |
||||
public $connection; |
||||
public $connection_handler; |
||||
public $lifetime; |
||||
public $session_name; |
||||
public $memcache; |
||||
public $initSessionData; |
||||
|
||||
public function __construct() |
||||
{ |
||||
global $_configuration; |
||||
|
||||
$this->memcache = new Memcache; |
||||
if (!empty($_configuration['memcache_server'])) { |
||||
foreach ($_configuration['memcache_server'] as $serverData) { |
||||
$isServerAvailable = @fsockopen($serverData['host'], $serverData['port']); |
||||
if (!$isServerAvailable){ |
||||
continue; |
||||
} |
||||
$this->memcache->addServer($serverData['host'], $serverData['port']); |
||||
} |
||||
} |
||||
$this->lifetime = 3600; // 60 minutes |
||||
|
||||
$this->connection = array ( |
||||
'server' => $_configuration['db_host'], |
||||
'login' => $_configuration['db_user'], |
||||
'password' => $_configuration['db_password'], |
||||
'base' => $_configuration['main_database'] |
||||
); |
||||
|
||||
$this->connection_handler = false; |
||||
} |
||||
|
||||
/** |
||||
*@deprecated |
||||
* */ |
||||
public function sqlConnect() |
||||
{ |
||||
if (!$this->connection_handler) { |
||||
$this->connection_handler = @mysql_connect($this->connection['server'], $this->connection['login'], $this->connection['password'], true); |
||||
|
||||
// The system has not been designed to use special SQL modes that were introduced since MySQL 5 |
||||
@mysql_query("set session sql_mode='';", $this->connection_handler); |
||||
|
||||
@mysql_select_db($this->connection['base'], $this->connection_handler); |
||||
|
||||
// Initialization of the database connection encoding to be used. |
||||
// The internationalization library should be already initialized. |
||||
@mysql_query("SET SESSION character_set_server='utf8';", $this->connection_handler); |
||||
@mysql_query("SET SESSION collation_server='utf8_general_ci';", $this->connection_handler); |
||||
$system_encoding = api_get_system_encoding(); |
||||
if (api_is_utf8($system_encoding)) { |
||||
// See Bug #1802: For UTF-8 systems we prefer to use "SET NAMES 'utf8'" statement in order to avoid a bizarre problem with Chinese language. |
||||
@mysql_query("SET NAMES 'utf8';", $this->connection_handler); |
||||
} else { |
||||
@mysql_query("SET CHARACTER SET '" . Database::to_db_encoding($system_encoding) . "';", $this->connection_handler); |
||||
} |
||||
} |
||||
|
||||
return ($this->connection_handler) ? true : false; |
||||
} |
||||
|
||||
public function sqlClose() |
||||
{ |
||||
|
||||
if ($this->connection_handler) { |
||||
mysql_close($this->connection_handler); |
||||
$this->connection_handler = false; |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public function sqlQuery($query, $dieOnError = true) |
||||
{ |
||||
$result = mysql_query($query, $this->connection_handler); |
||||
if ($dieOnError && !$result) { |
||||
$this->sqlClose(); |
||||
return; |
||||
} |
||||
|
||||
return $result; |
||||
} |
||||
|
||||
public function open($savePath, $sessionName) |
||||
{ |
||||
$sessionID = session_id(); |
||||
if ($sessionID !== "") { |
||||
$this->initSessionData = $this->read($sessionID); |
||||
$this->session_name = $sessionName; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
public function close() |
||||
{ |
||||
$this->lifeTime = null; |
||||
$this->memcache = null; |
||||
$this->initSessionData = null; |
||||
|
||||
return $this->gc(0) ? true : false; |
||||
} |
||||
|
||||
public function read($sessionID) |
||||
{ |
||||
$data = $this->memcache->get($sessionID); |
||||
if (($data === false || empty($data)) && $this->sqlConnect()) { |
||||
$result = $this->sqlQuery("SELECT session_value FROM ".$this->connection['base'].".php_session WHERE session_id='$sessionID'"); |
||||
if (!empty($result) && $result !== false && $row = Database::fetch_row($result)) { |
||||
$data = stripslashes($row[0]); |
||||
$this->memcache->set($sessionID, $data); |
||||
} else { |
||||
$data = false; |
||||
} |
||||
} else { |
||||
$data = stripslashes($data); |
||||
} |
||||
|
||||
return $data; |
||||
} |
||||
|
||||
public function write($sessionID, $data) |
||||
{ |
||||
global $_configuration; |
||||
|
||||
$this->memcache->set($sessionID, $data); |
||||
if ($this->memcache->get('interactions-' . $sessionID) !== false) { |
||||
$interactions = $this->memcache->get('interactions-' . $sessionID); |
||||
++$interactions; |
||||
if ($_configuration['session_stored_after_n_times'] < $interactions) { |
||||
$interactions = 1; |
||||
} |
||||
$this->memcache->set('interactions-' . $sessionID, $interactions); |
||||
} else { |
||||
$this->memcache->set('interactions-' . $sessionID, 1); |
||||
} |
||||
|
||||
$interactions = $this->memcache->get('interactions-' . $sessionID); |
||||
//$this->initSessionData !== $data #avoid this validation for performance improvements |
||||
|
||||
if ($_configuration['session_stored_after_n_times'] === $interactions) { |
||||
$sessionID = mysql_real_escape_string($sessionID); |
||||
$sessionExpirationTS = ($this->lifetime + time()); |
||||
$sessionData = mysql_real_escape_string($data); |
||||
|
||||
if ($this->sqlConnect()) { |
||||
$result = $this->sqlQuery("INSERT INTO ".$this->connection['base'].".php_session( |
||||
session_id,session_name,session_time,session_start,session_value) |
||||
VALUES('$sessionID','".$this->session_name."','$sessionExpirationTS','$sessionExpirationTS','".addslashes($sessionData)."')", false); |
||||
|
||||
if (!$result) { |
||||
$this->sqlQuery("UPDATE ".$this->connection['base'].".php_session |
||||
SET session_name='".$this->session_name."',session_time='$sessionExpirationTS',session_value='".addslashes($sessionData)."' |
||||
WHERE session_id='$sessionID'"); |
||||
} |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public function destroy($sessionID) |
||||
{ |
||||
$this->memcache->delete($sessionID); |
||||
if ($this->sqlConnect()) { |
||||
$this->sqlQuery("DELETE FROM ".$this->connection['base'].".php_session WHERE session_id='$sessionID'"); |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public function gc($maxlifetime) |
||||
{ |
||||
if ($this->sqlConnect()) { |
||||
$result = $this->sqlQuery("SELECT COUNT(session_id) FROM ".$this->connection['base'].".php_session"); |
||||
list($nbr_results) = Database::fetch_row($result); |
||||
|
||||
if ($nbr_results > 5000) { |
||||
$this->sqlQuery("DELETE FROM ".$this->connection['base'].".php_session WHERE session_time<'".strtotime('-'.$this->lifetime.' minutes')."'"); |
||||
} |
||||
|
||||
$this->sqlClose(); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
} |
@ -1,487 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace Model; |
||||
|
||||
use Database; |
||||
use ResultSet; |
||||
|
||||
/** |
||||
* Represent a database "student_publication" object. |
||||
* |
||||
* Note: |
||||
* |
||||
* Each database column is mapped to a property. |
||||
* |
||||
* The item_property table is available through its own property but is loaded |
||||
* alongside document data. |
||||
* |
||||
* Some db query functions exists in this class and would need to be adapted |
||||
* to Symphony once it is moved to production. Yet the object structure should |
||||
* stay. |
||||
* |
||||
* @see \Model\ItemProperty |
||||
* @see table c_student_publication |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class StudentPublication |
||||
{ |
||||
|
||||
public static function void() |
||||
{ |
||||
static $result = null; |
||||
if ($result) { |
||||
return $result; |
||||
} |
||||
|
||||
$result = new self(); |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* @return Model\StudentPublicationRepository |
||||
*/ |
||||
public static function repository() |
||||
{ |
||||
return StudentPublicationRepository::instance(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $where |
||||
* @return \ResultSet |
||||
*/ |
||||
public static function query($where) |
||||
{ |
||||
return self::repository()->query($where); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param int|Course $c_id |
||||
* @param int $id |
||||
* @return \Model\StudentPublication |
||||
*/ |
||||
public static function get_by_id($c_id, $id) |
||||
{ |
||||
return self::repository()->get_by_id($c_id, $id); |
||||
} |
||||
|
||||
protected $c_id = 0; |
||||
protected $id = 0; |
||||
protected $url = ''; |
||||
protected $title = ''; |
||||
protected $description = ''; |
||||
protected $author = ''; |
||||
protected $active = null; |
||||
protected $accepted = false; |
||||
protected $post_group_id = 0; |
||||
protected $sent_date = 0; |
||||
protected $filetype = ''; |
||||
protected $has_properties = 0; |
||||
protected $view_properties = null; |
||||
protected $qualification = 0; |
||||
protected $date_of_qualification = 0; |
||||
protected $parent_id = 0; |
||||
protected $qualificator_id = 0; |
||||
protected $weight = 0; |
||||
protected $session_id = 0; |
||||
protected $user_id = null; |
||||
protected $allow_text_assignment = 0; |
||||
protected $contains_file = 0; |
||||
protected $course = null; |
||||
protected $item_property = null; |
||||
|
||||
public function __construct($data) |
||||
{ |
||||
$data = (object) $data; |
||||
$this->c_id = (int) $data->c_id; |
||||
$this->id = (int) $data->id; |
||||
$this->url = $data->url; |
||||
$this->title = $data->title; |
||||
$this->description = $data->description; |
||||
$this->author = $data->author; |
||||
$this->active = $data->active; |
||||
$this->accepted = $data->accepted; |
||||
$this->post_group_id = $data->post_group_id; |
||||
$this->sent_date = $data->sent_date; |
||||
$this->filetype = $data->filetype; |
||||
$this->has_properties = $data->has_properties; |
||||
$this->view_properties = $data->view_properties; |
||||
$this->qualification = $data->qualification; |
||||
$this->date_of_qualification = $data->date_of_qualification; |
||||
$this->parent_id = $data->parent_id; |
||||
$this->qualificator_id = $data->qualificator_id; |
||||
$this->weight = $data->weight; |
||||
$this->session_id = $data->session_id; |
||||
$this->user_id = $data->user_id; |
||||
$this->allow_text_assignment = $data->allow_text_assignment; |
||||
$this->contains_file = $data->contains_file; |
||||
$this->course = $data->course; |
||||
$this->item_property = $data->item_property; |
||||
|
||||
$this->course = null; |
||||
|
||||
if (isset($data->property_id)) { |
||||
$property = (array) $data; |
||||
$property = (object) $property; |
||||
$property->id = $property->property_id; |
||||
$this->item_property = ItemProperty::create($property); |
||||
} else { |
||||
$this->item_property = null; |
||||
} |
||||
} |
||||
|
||||
public function get_c_id() |
||||
{ |
||||
return $this->c_id; |
||||
} |
||||
|
||||
public function set_c_id($value) |
||||
{ |
||||
$this->c_id = $value; |
||||
} |
||||
|
||||
public function get_id() |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function set_id($value) |
||||
{ |
||||
$this->id = $value; |
||||
} |
||||
|
||||
public function get_url() |
||||
{ |
||||
return $this->url; |
||||
} |
||||
|
||||
public function set_url($value) |
||||
{ |
||||
$this->url = $value; |
||||
} |
||||
|
||||
public function get_title() |
||||
{ |
||||
return $this->title; |
||||
} |
||||
|
||||
public function set_title($value) |
||||
{ |
||||
$this->title = $value; |
||||
} |
||||
|
||||
public function get_description() |
||||
{ |
||||
return $this->description; |
||||
} |
||||
|
||||
public function set_description($value) |
||||
{ |
||||
$this->description = $value; |
||||
} |
||||
|
||||
public function get_author() |
||||
{ |
||||
return $this->author; |
||||
} |
||||
|
||||
public function set_author($value) |
||||
{ |
||||
$this->author = $value; |
||||
} |
||||
|
||||
public function get_active() |
||||
{ |
||||
return $this->active; |
||||
} |
||||
|
||||
public function set_active($value) |
||||
{ |
||||
$this->active = $value; |
||||
} |
||||
|
||||
public function get_accepted() |
||||
{ |
||||
return $this->accepted; |
||||
} |
||||
|
||||
public function set_accepted($value) |
||||
{ |
||||
$this->accepted = $value; |
||||
} |
||||
|
||||
public function get_post_group_id() |
||||
{ |
||||
return $this->post_group_id; |
||||
} |
||||
|
||||
public function set_post_group_id($value) |
||||
{ |
||||
$this->post_group_id = $value; |
||||
} |
||||
|
||||
public function get_sent_date() |
||||
{ |
||||
return $this->sent_date; |
||||
} |
||||
|
||||
public function set_sent_date($value) |
||||
{ |
||||
$this->sent_date = $value; |
||||
} |
||||
|
||||
public function get_filetype() |
||||
{ |
||||
return $this->filetype; |
||||
} |
||||
|
||||
public function set_filetype($value) |
||||
{ |
||||
$this->filetype = $value; |
||||
} |
||||
|
||||
public function get_has_properties() |
||||
{ |
||||
return $this->has_properties; |
||||
} |
||||
|
||||
public function set_has_properties($value) |
||||
{ |
||||
$this->has_properties = $value; |
||||
} |
||||
|
||||
public function get_view_properties() |
||||
{ |
||||
return $this->view_properties; |
||||
} |
||||
|
||||
public function set_view_properties($value) |
||||
{ |
||||
$this->view_properties = $value; |
||||
} |
||||
|
||||
public function get_qualification() |
||||
{ |
||||
return $this->qualification; |
||||
} |
||||
|
||||
public function set_qualification($value) |
||||
{ |
||||
$this->qualification = $value; |
||||
} |
||||
|
||||
public function get_date_of_qualification() |
||||
{ |
||||
return $this->date_of_qualification; |
||||
} |
||||
|
||||
public function set_date_of_qualification($value) |
||||
{ |
||||
$this->date_of_qualification = $value; |
||||
} |
||||
|
||||
public function get_parent_id() |
||||
{ |
||||
return $this->parent_id; |
||||
} |
||||
|
||||
public function set_parent_id($value) |
||||
{ |
||||
$this->parent_id = $value; |
||||
} |
||||
|
||||
public function get_qualificator_id() |
||||
{ |
||||
return $this->qualificator_id; |
||||
} |
||||
|
||||
public function set_qualificator_id($value) |
||||
{ |
||||
$this->qualificator_id = $value; |
||||
} |
||||
|
||||
public function get_weight() |
||||
{ |
||||
return $this->weight; |
||||
} |
||||
|
||||
public function set_weight($value) |
||||
{ |
||||
$this->weight = $value; |
||||
} |
||||
|
||||
public function get_session_id() |
||||
{ |
||||
return $this->session_id; |
||||
} |
||||
|
||||
public function set_session_id($value) |
||||
{ |
||||
$this->session_id = $value; |
||||
} |
||||
|
||||
public function get_user_id() |
||||
{ |
||||
return $this->user_id; |
||||
} |
||||
|
||||
public function set_user_id($value) |
||||
{ |
||||
$this->user_id = $value; |
||||
} |
||||
|
||||
public function get_allow_text_assignment() |
||||
{ |
||||
return $this->allow_text_assignment; |
||||
} |
||||
|
||||
public function set_allow_text_assignment($value) |
||||
{ |
||||
$this->allow_text_assignment = $value; |
||||
} |
||||
|
||||
public function get_contains_file() |
||||
{ |
||||
return $this->contains_file; |
||||
} |
||||
|
||||
public function set_contains_file($value) |
||||
{ |
||||
$this->contains_file = $value; |
||||
} |
||||
|
||||
public function is_folder() |
||||
{ |
||||
return $this->filetype == 'folder'; |
||||
} |
||||
|
||||
public function is_file() |
||||
{ |
||||
return $this->filetype == 'file'; |
||||
} |
||||
|
||||
public function is_visible() |
||||
{ |
||||
$this->get_item_property()->get_visibility() == 1; |
||||
} |
||||
|
||||
public function is_accessible($user = null) |
||||
{ |
||||
$user_id = $user ? $user : api_get_user_id(); |
||||
$result = $this->is_visible() || $this->get_user_id() == $user_id || api_is_allowed_to_edit(); |
||||
return $result; |
||||
} |
||||
|
||||
public function get_absolute_path() |
||||
{ |
||||
return api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/' . $this->get_url(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return \Model\ItemProperty |
||||
*/ |
||||
public function get_item_property() |
||||
{ |
||||
if ($this->item_property && $this->item_property->get_c_id() == $this->c_id && $this->item_property->get_ref() == $this->id) { |
||||
return $this->item_property; |
||||
} |
||||
|
||||
$this->item_property = ItemProperty::get_by_ref($this->id, TOOL_DOCUMENT); |
||||
return $this->item_property; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param bool $all |
||||
* @return ResultSet|array |
||||
*/ |
||||
public function get_children() |
||||
{ |
||||
if (!$this->is_folder()) { |
||||
return array(); |
||||
} |
||||
$id = $this->id; |
||||
$c_id = $this->c_id; |
||||
$where = "pub.c_id = $c_id AND pub.parent_id = $id"; |
||||
return self::query($where); |
||||
} |
||||
|
||||
} |
||||
|
||||
class StudentPublicationRepository |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @staticvar null $result |
||||
* @return StudentPublicationRepository |
||||
*/ |
||||
public static function instance() |
||||
{ |
||||
static $result = null; |
||||
if (empty($result)) { |
||||
$result = new self(); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $where |
||||
* @return \ResultSet |
||||
*/ |
||||
public function query($where) |
||||
{ |
||||
$table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); |
||||
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); |
||||
$tool = 'work'; |
||||
|
||||
$sql = "SELECT pub.*, |
||||
prop.id AS property_id, |
||||
prop.tool, |
||||
prop.insert_user_id, |
||||
prop.insert_date, |
||||
prop.lastedit_date, |
||||
prop.ref, |
||||
prop.lastedit_type, |
||||
prop.lastedit_user_id, |
||||
prop.to_group_id, |
||||
prop.to_user_id, |
||||
prop.visibility, |
||||
prop.start_visible, |
||||
prop.end_visible, |
||||
prop.id_session |
||||
FROM |
||||
$table AS pub, |
||||
$table_item_property AS prop |
||||
WHERE |
||||
(pub.id = prop.ref AND |
||||
pub.c_id = prop.c_id AND |
||||
prop.tool = '$tool')"; |
||||
|
||||
$sql .= $where ? "AND ($where)" : ''; |
||||
$result = new ResultSet($sql); |
||||
return $result->return_type(__CLASS__); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param int|Course $c_id |
||||
* @param int $id |
||||
* @return \Model\StudentPublication |
||||
*/ |
||||
public function get_by_id($c_id, $id) |
||||
{ |
||||
$c_id = is_object($c_id) ? $c_id->get_id() : (int) $c_id; |
||||
return $this->query("pub.c_id = $c_id AND pub.id = $id")->first(); |
||||
} |
||||
|
||||
public function update($pub) |
||||
{ |
||||
|
||||
} |
||||
|
||||
} |
@ -1,92 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Proxy for the closure compiler. Allows to minify javascript files. |
||||
* This makes use of CURL and calls the closure service. |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
* @see http://closure-compiler.appspot.com/home |
||||
* @see https://developers.google.com/closure/compiler/ |
||||
* |
||||
*/ |
||||
class ClosureCompiler |
||||
{ |
||||
|
||||
const PARAM_OUTPUT_FORMAT = 'output_format'; |
||||
const PARAM_OUTPUT_INFO = 'output_info'; |
||||
const PARAM_COMPILATION_LEVEL = 'compilation_level'; |
||||
const PARAM_JS_CODE = 'js_code'; |
||||
const LEVEL_SIMPLE = 'SIMPLE_OPTIMIZATIONS'; |
||||
const LEVEL_WHITESPACE = 'WHITESPACE_ONLY'; |
||||
const LEVEL_ADVANCED = 'ADVANCED_OPTIMIZATIONS'; |
||||
const OUTPUT_FORMAT_TEXT = 'text'; |
||||
const OUTPUT_INFO_CODE = 'compiled_code'; |
||||
|
||||
/** |
||||
* Url of the service |
||||
* |
||||
* @return string |
||||
*/ |
||||
public static function url() |
||||
{ |
||||
return 'closure-compiler.appspot.com/compile'; |
||||
} |
||||
|
||||
/** |
||||
* Post data the closure compiler service. By default it returns minimized code |
||||
* with the simple option. |
||||
* |
||||
* @param string $code Javascript code to minimify |
||||
* @param array $params parameters to pass to the service |
||||
* @return string minimified code |
||||
*/ |
||||
public static function post($code, $params = array()) |
||||
{ |
||||
if (!isset($params[self::PARAM_OUTPUT_FORMAT])) |
||||
{ |
||||
$params[self::PARAM_OUTPUT_FORMAT] = self::OUTPUT_FORMAT_TEXT; |
||||
} |
||||
if (!isset($params[self::PARAM_OUTPUT_INFO])) |
||||
{ |
||||
$params[self::PARAM_OUTPUT_INFO] = self::OUTPUT_INFO_CODE; |
||||
} |
||||
if (!isset($params[self::PARAM_COMPILATION_LEVEL])) |
||||
{ |
||||
$params[self::PARAM_JS_CODE] = $code; |
||||
} |
||||
|
||||
$params[self::PARAM_COMPILATION_LEVEL] = self::LEVEL_SIMPLE; |
||||
|
||||
$fields = array(); |
||||
foreach ($params as $key => $value) |
||||
{ |
||||
$fields[] = $key . '=' . urlencode($value); |
||||
} |
||||
$fields = implode('&', $fields); |
||||
|
||||
$headers = array("Content-type: application/x-www-form-urlencoded"); |
||||
|
||||
$url = self::url(); |
||||
|
||||
$ch = curl_init(); |
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url); |
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
||||
curl_setopt($ch, CURLOPT_POST, true); |
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); |
||||
//curl_setopt($ch, CURLOPT_HEADER, false); |
||||
//curl_setopt($ch, CURLOPT_VERBOSE, true); |
||||
|
||||
$content = curl_exec($ch); |
||||
$error = curl_error($ch); |
||||
$info = curl_getinfo($ch); |
||||
|
||||
curl_close($ch); |
||||
|
||||
return $content; |
||||
} |
||||
|
||||
} |
@ -1,92 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Description of code_utilities |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class CodeUtilities |
||||
{ |
||||
|
||||
const CLASS_PATTERN = '/(?:\s+class\s+[a-zA-Z_0-9\x7f-\xff]+\s*{)|(?:\s+class\s+[a-zA-Z_0-9\x7f-\xff]+\s*extends)|(?:\s+class\s+[a-zA-Z_0-9\x7f-\xff]+\s*implements)|(?:\s+interface\s+[a-zA-Z_0-9\x7f-\xff]+\s*{)|(?:\s+interface\s+[a-zA-Z_0-9\x7f-\xff]+\s*extends)/mi'; |
||||
const INLINE_COMMENT_PATTERN = '#//.*$#m'; |
||||
const MULTILINE_COMMENT_PATTERN = '#/\*.*?\*/#ms'; |
||||
const NAMESPACE_PATTERN = '/namespace\s*(.*);/'; |
||||
const IDENTIFIER_PATTERN = '/^[a-zA-Z_][a-zA-Z0-9_]*$/'; |
||||
|
||||
static function remove_comments($content) |
||||
{ |
||||
$content = preg_replace(self::INLINE_COMMENT_PATTERN, '', $content); |
||||
$content = preg_replace(self::MULTILINE_COMMENT_PATTERN, '', $content); |
||||
return $content; |
||||
} |
||||
|
||||
/** |
||||
* Returns the name of classes and interfaces contained in content. |
||||
* |
||||
* @param text $content |
||||
* @return array |
||||
*/ |
||||
static function get_classes($content) |
||||
{ |
||||
$result = array(); |
||||
$cls_pattern = self::CLASS_PATTERN; |
||||
|
||||
$content = self::remove_comments($content); //comments may contains class declaration we don't want to capture. |
||||
|
||||
$matches = array(); |
||||
if (preg_match_all($cls_pattern, $content, $matches)) { |
||||
$matches = reset($matches); |
||||
foreach ($matches as $match) { |
||||
$match = str_replace("\n", ' ', $match); |
||||
$match = str_replace('{', ' ', $match); |
||||
$words = explode(' ', $match); |
||||
foreach ($words as $word) { |
||||
$word = trim($word); |
||||
//we capture the interface/class name with the current pattern |
||||
if (strtolower($word) != 'class' && strtolower($word) != 'interface' && strtolower($word) != 'implements' && strtolower($word) != 'extends' && !empty($word)) { |
||||
$result[] = $word; |
||||
break; //we only take the first name as we don't want to capture the name of the interface or of the parent class name |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
static function get_namespace($content) |
||||
{ |
||||
$namespace_pattern = self::NAMESPACE_PATTERN; |
||||
if (preg_match($namespace_pattern, $content, $matches)) { |
||||
$result = end($matches); |
||||
return trim($result); |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
static function is_valid_identifier($name) |
||||
{ |
||||
$pattern = self::IDENTIFIER_PATTERN; |
||||
$r = preg_match($pattern, $name); |
||||
return $r; |
||||
} |
||||
|
||||
/** |
||||
* Make path relative to root. |
||||
* |
||||
* @param string $root |
||||
* @param string $path |
||||
* @return string |
||||
*/ |
||||
static function relative_path($root, $path) |
||||
{ |
||||
$path = realpath($path); |
||||
$root = realpath($root); |
||||
$path = str_ireplace($root, '', $path); |
||||
$path = str_ireplace('\\', '/', $path); |
||||
return $path; |
||||
} |
||||
|
||||
} |
@ -1 +0,0 @@ |
||||
Used to extract metadata from external resources : youtube, dailymotion, etc |
@ -1,56 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Process all renderers attached in order. |
||||
* |
||||
* If a renderer returns an key value that has not already been set add it |
||||
* to the result. Otherwise let the previous value unchanged. |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetAggregatedRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
protected $renderers = array(); |
||||
|
||||
public function __construct($renderers) |
||||
{ |
||||
$this->renderers = $renderers; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function renderers() |
||||
{ |
||||
return $this->renderers; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
* @return array |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
$result = array(); |
||||
$plugins = self::plugins(); |
||||
foreach ($this->renderers as $renderer) |
||||
{ |
||||
$data = $renderer->render($asset); |
||||
$data = $data ? $data : array(); |
||||
foreach ($data as $key => $value) |
||||
{ |
||||
if (!isset($result[$key]) && !empty($value)) |
||||
{ |
||||
$result[$key] = $value; |
||||
} |
||||
} |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,107 +0,0 @@ |
||||
<?php |
||||
|
||||
require_once dirname(__FILE__) . '/http_resource.class.php'; |
||||
require_once dirname(__FILE__) . '/asset_aggregated_renderer.class.php'; |
||||
|
||||
/** |
||||
* Renderer for an http resource. |
||||
* Extract meta data and snippet html view from an given url/resource. |
||||
* |
||||
* Base class. Other renderers must inherit from it. |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetRenderer |
||||
{ |
||||
|
||||
const THUMBNAIL = 'thumbnail'; |
||||
const EMBED_SNIPPET = 'embed_snippet'; |
||||
const EMBED_TYPE = 'embed_type'; |
||||
const EMBED_URL = 'embed_url'; |
||||
const WIDTH = 'width'; |
||||
const HEIGHT = 'height'; |
||||
const LANGUAGE = 'language'; |
||||
const URL = 'url'; |
||||
const TAGS = 'tags'; |
||||
const TITLE = 'title'; |
||||
const CREATED_TIME = 'created_time'; |
||||
const DURATION = 'duration'; |
||||
const DESCRIPTION = 'description'; |
||||
const ICON = 'icon'; |
||||
|
||||
static function get($url, $config = array()) |
||||
{ |
||||
if (strpos('url', 'javascript:') !== false) |
||||
{ |
||||
return array(); |
||||
} |
||||
$result = array(); |
||||
$url = trim($url); |
||||
if (empty($url)) |
||||
{ |
||||
return array(); |
||||
} |
||||
$asset = new HttpResource($url, $config); |
||||
$renderer = new AssetAggregatedRenderer(self::plugins()); |
||||
$result = $renderer->render($asset); |
||||
$result['url'] = $url; |
||||
return $result; |
||||
} |
||||
|
||||
static function plugins() |
||||
{ |
||||
static $result = array(); |
||||
if (!empty($result)) |
||||
{ |
||||
return $result; |
||||
} |
||||
|
||||
/* |
||||
* We make sure we load them from most specialized to less specialized. |
||||
* The first that provides a value for a field wins. |
||||
*/ |
||||
$protocols = array( |
||||
'oembed', |
||||
'og', |
||||
'image', |
||||
'media', |
||||
'rss', |
||||
'google_map', |
||||
'google_document', |
||||
'google_document_viewer', |
||||
'google_widget', |
||||
'mediaserver', |
||||
'scratch', |
||||
'page'); |
||||
|
||||
foreach ($protocols as $protocol) |
||||
{ |
||||
$file = "asset_{$protocol}_renderer.class.php"; |
||||
require_once dirname(__FILE__) . '/protocol/' . $file; |
||||
|
||||
$class = "asset_{$protocol}_renderer"; |
||||
$class = explode('_', $class); |
||||
$class = array_map('ucfirst', $class); |
||||
$class = implode($class); |
||||
|
||||
$result[] = new $class(); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* Renderer function. Take a http asset as input and return an array containing |
||||
* various properties: metadata, html snippet, etc. |
||||
* |
||||
* @param HttpResource $asset |
||||
* @return array |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
$result = array(); |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,662 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* An HTTP resource. In most cases an HTML document. |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class HttpResource |
||||
{ |
||||
|
||||
/** |
||||
* Fetch the content and metadata of an url. |
||||
* |
||||
* If the content type is not parsable, i.e. it is not made of text, |
||||
* only fetch the metadata and not the content. This is mostly done to |
||||
* avoid downloading big files - videos, images, etc - which is unnecessary. |
||||
* |
||||
* @param string $url the url to fetch |
||||
* @return array array containing the content and various info |
||||
*/ |
||||
static function fetch($url, $fetch_content = null) |
||||
{ |
||||
static $cache = array(); |
||||
if (isset($cache[$url])) |
||||
{ |
||||
return $cache; |
||||
} |
||||
|
||||
if (is_null($fetch_content) || $fetch_content === false) |
||||
{ |
||||
// create a new cURL resource |
||||
$ch = curl_init(); |
||||
|
||||
// set URL and other appropriate options |
||||
curl_setopt($ch, CURLOPT_URL, $url); |
||||
curl_setopt($ch, CURLOPT_HEADER, false); |
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
||||
curl_setopt($ch, CURLOPT_NOBODY, true); |
||||
|
||||
$content = curl_exec($ch); |
||||
$error = curl_error($ch); |
||||
$info = curl_getinfo($ch); |
||||
|
||||
// close cURL resource, and free up system resources |
||||
curl_close($ch); |
||||
$info['content'] = $content; |
||||
$info['error'] = $error; |
||||
|
||||
if ($fetch_content === false) |
||||
{ |
||||
return $cache[$url] = $info; |
||||
} |
||||
|
||||
if (isset($info['content_type']) && strpos($info['content_type'], 'text') === false) |
||||
{ |
||||
return $cache[$url] = $info; |
||||
} |
||||
} |
||||
|
||||
// create a new cURL resource |
||||
$ch = curl_init(); |
||||
|
||||
// set URL and other appropriate options |
||||
curl_setopt($ch, CURLOPT_URL, $url); |
||||
curl_setopt($ch, CURLOPT_HEADER, false); |
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
||||
|
||||
//curl_setopt($ch, CURLOPT_VERBOSE, true); |
||||
|
||||
$content = curl_exec($ch); |
||||
$error = curl_error($ch); |
||||
$info = curl_getinfo($ch); |
||||
|
||||
// close cURL resource, and free up system resources |
||||
curl_close($ch); |
||||
$info['content'] = $content; |
||||
$info['error'] = $error; |
||||
|
||||
return $cache[$url] = $info; |
||||
} |
||||
|
||||
static function fetch_json($url) |
||||
{ |
||||
$content = self::fetch($url, true); |
||||
$content = $content['content']; |
||||
if ($content) |
||||
{ |
||||
$result = (array) json_decode($content); |
||||
} |
||||
else |
||||
{ |
||||
$result = array(); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
protected $url; |
||||
protected $url_params = null; |
||||
protected $info = null; |
||||
protected $source = null; |
||||
protected $metadata = null; |
||||
protected $links = null; |
||||
protected $title = null; |
||||
protected $mime = null; |
||||
protected $doc = null; |
||||
protected $config = array(); |
||||
|
||||
public function __construct($url, $config = array()) |
||||
{ |
||||
$this->url = $url; |
||||
$this->config = $config; |
||||
} |
||||
|
||||
public function config($key = '', $default = null) |
||||
{ |
||||
return isset($this->config[$key]) ? $this->config[$key] : $default; |
||||
} |
||||
|
||||
/** |
||||
* Url of the resource |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function url() |
||||
{ |
||||
return $this->url; |
||||
} |
||||
|
||||
public function url_domain() |
||||
{ |
||||
$url = $this->url(); |
||||
$url = trim($url, '/'); |
||||
if (strpos($url, '//') !== false) |
||||
{ |
||||
$parts = explode('//', $url); |
||||
$url = end($parts); |
||||
} |
||||
$parts = explode('/', $url); |
||||
$result = reset($parts); |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param array|string $part |
||||
* @return boolean |
||||
*/ |
||||
public function url_match($part) |
||||
{ |
||||
$params = func_get_args(); |
||||
$params = is_array($params) ? $params : array($params); |
||||
|
||||
$url = strtolower($this->url()); |
||||
foreach ($params as $param) |
||||
{ |
||||
if (strpos($url, strtolower($param)) !== false) |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public function url_params() |
||||
{ |
||||
if (!is_null($this->url_params)) |
||||
{ |
||||
return $this->url_params; |
||||
} |
||||
|
||||
$url = $this->url(); |
||||
if (strpos($url, '?') === false) |
||||
{ |
||||
return $this->url_params = array(); |
||||
} |
||||
|
||||
$result = array(); |
||||
$params = explode('?', $url); |
||||
$params = end($params); |
||||
$params = explode('&', $params); |
||||
foreach ($params as $param) |
||||
{ |
||||
list($key, $val) = explode('=', $param); |
||||
$result[$key] = $val; |
||||
} |
||||
|
||||
return $this->url_params = $result; |
||||
} |
||||
|
||||
public function url_param($name, $default = false) |
||||
{ |
||||
$params = $this->url_params(); |
||||
return isset($params[$name]) ? $params[$name] : $default; |
||||
} |
||||
|
||||
/** |
||||
* The name of the resource. I.e. the last part of the url without the ext |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function name() |
||||
{ |
||||
$url = $this->url(); |
||||
$url = explode('/', $url); |
||||
$title = end($url); |
||||
$title = explode('.', $title); |
||||
$title = reset($title); |
||||
return $title; |
||||
} |
||||
|
||||
/** |
||||
* Extention of the url |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function ext() |
||||
{ |
||||
$url = $this->url(); |
||||
$url = explode('.', $url); |
||||
$ext = end($url); |
||||
$ext = strtolower($ext); |
||||
return $ext; |
||||
} |
||||
|
||||
/** |
||||
* Return true if the object has one of the extentions. Overloaded: |
||||
* |
||||
* $res->has_ext('pdf'); |
||||
* $res->has_ext('pdf', 'doc'); |
||||
* $res->has_ext(array('pdf', 'doc')); |
||||
* |
||||
* @param array|string $_ |
||||
* @return boolean true if the resource has one of the extentions passed |
||||
*/ |
||||
public function has_ext($_) |
||||
{ |
||||
if (is_array($_)) |
||||
{ |
||||
$params = $_; |
||||
} |
||||
else |
||||
{ |
||||
$params = func_get_args(); |
||||
$params = is_array($params) ? $params : array($params); |
||||
} |
||||
$ext = $this->ext(); |
||||
foreach ($params as $param) |
||||
{ |
||||
if (strtolower($param) == $ext) |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public function charset() |
||||
{ |
||||
$info = $this->info(); |
||||
|
||||
$content_type = isset($info['content_type']) ? $info['content_type'] : ''; |
||||
if (empty($content_type)) |
||||
{ |
||||
return null; |
||||
} |
||||
$items = explode(';', $content_type); |
||||
foreach ($items as $item) |
||||
{ |
||||
$parts = explode('=', $item); |
||||
if (count($parts) == 2 && reset($parts) == 'charset') |
||||
{ |
||||
return strtolower(end($parts)); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* The mime type of the resource or the empty string if none has been specified |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function mime() |
||||
{ |
||||
if (!is_null($this->mime)) |
||||
{ |
||||
return $this->mime; |
||||
} |
||||
$info = $this->info(); |
||||
|
||||
$content_type = isset($info['content_type']) ? $info['content_type'] : ''; |
||||
if ($content_type) |
||||
{ |
||||
$result = reset(explode(';', $content_type)); |
||||
$result = strtolower($result); |
||||
return $this->mime = $result; |
||||
} |
||||
|
||||
return $this->mime = ''; |
||||
} |
||||
|
||||
public function is_xml() |
||||
{ |
||||
$mime = $this->mime(); |
||||
if (!empty($mime)) |
||||
{ |
||||
return strpos($mime, 'xml') !== false; |
||||
} |
||||
return $this->ext() == 'xml'; |
||||
} |
||||
|
||||
public function is_image() |
||||
{ |
||||
$mime = $this->mime(); |
||||
if ($mime) |
||||
{ |
||||
return strpos($mime, 'image') !== false; |
||||
} |
||||
|
||||
$ext = $this->ext(); |
||||
$formats = array('gif', 'jpeg', 'jpg', 'jpe', 'pjpeg', 'png', 'svg', 'tiff', 'ico'); |
||||
foreach ($formats as $format) |
||||
{ |
||||
if ($format == $ext) |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public function is_video() |
||||
{ |
||||
$mime = $this->mime(); |
||||
if ($mime) |
||||
{ |
||||
return strpos($mime, 'video') !== false; |
||||
} |
||||
|
||||
$ext = $this->ext(); |
||||
$formats = array('mpeg', 'mp4', 'ogg', 'wmv', 'mkv'); |
||||
foreach ($formats as $format) |
||||
{ |
||||
if ($format == $ext) |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public function is_audio() |
||||
{ |
||||
$mime = $this->mime(); |
||||
if ($mime) |
||||
{ |
||||
return strpos($mime, 'audio') !== false; |
||||
} |
||||
|
||||
$ext = $this->ext(); |
||||
$formats = array('mp3'); |
||||
foreach ($formats as $format) |
||||
{ |
||||
if ($format == $ext) |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public function is_rss() |
||||
{ |
||||
if (!$this->is_xml()) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
$doc = $this->doc(); |
||||
$nodes = $doc->getElementsByTagName('rss'); |
||||
return $nodes->length != 0; |
||||
} |
||||
|
||||
public function is_gadget() |
||||
{ |
||||
if (!$this->is_xml()) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
$doc = $this->doc(); |
||||
$nodes = $doc->getElementsByTagName('ModulePrefs'); |
||||
return $nodes->length != 0; |
||||
} |
||||
|
||||
public function canonic_url($src) |
||||
{ |
||||
if (strpos($src, '//') === 0) |
||||
{ |
||||
$src = "http:$src"; |
||||
} |
||||
else if (strpos($src, '/') === 0) //relative url to the root |
||||
{ |
||||
$url = $this->url(); |
||||
$protocol = reset(explode('://', $url)); |
||||
$domain = end(explode('://', $url)); |
||||
$domain = reset(explode('/', $domain)); |
||||
$src = "$protocol://$domain/$src"; |
||||
} |
||||
else if (strpos($src, 'http') !== 0) //relative url to the document |
||||
{ |
||||
$url = $this->url(); |
||||
$tail = end(explode('/', $url)); |
||||
$base = str_replace($tail, '', $url); |
||||
|
||||
$src = $base . $src; |
||||
} |
||||
return $src; |
||||
} |
||||
|
||||
/** |
||||
* Content of the resource. |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function source() |
||||
{ |
||||
if (!is_null($this->source)) |
||||
{ |
||||
return $this->source; |
||||
} |
||||
$info = $this->info(); |
||||
|
||||
return $this->source = $info['content']; |
||||
} |
||||
|
||||
/** |
||||
* Array of arrays containing the page's metadata. |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function metadata() |
||||
{ |
||||
if (!is_null($this->metadata)) |
||||
{ |
||||
return $this->metadata; |
||||
} |
||||
return $this->metadata = $this->get_metadata(); |
||||
} |
||||
|
||||
public function title() |
||||
{ |
||||
if (!is_null($this->title)) |
||||
{ |
||||
return $this->title; |
||||
} |
||||
return $this->title = $this->get_title(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return DOMDocument|boolean |
||||
*/ |
||||
public function doc() |
||||
{ |
||||
if (!is_null($this->doc)) |
||||
{ |
||||
return $this->doc; |
||||
} |
||||
return $this->doc = $this->get_doc($this->source()); |
||||
} |
||||
|
||||
function get_meta($name) |
||||
{ |
||||
$metadata = $this->metadata(); |
||||
$name = strtolower($name); |
||||
foreach ($metadata as $attributes) |
||||
{ |
||||
$key = isset($attributes['name']) ? $attributes['name'] : false; |
||||
$key = $key ? strtolower($key) : $key; |
||||
if ($name == $key) |
||||
{ |
||||
return $attributes['content']; |
||||
} |
||||
$key = isset($attributes['property']) ? $attributes['property'] : false; |
||||
$key = $key ? strtolower($key) : $key; |
||||
if ($name == $key) |
||||
{ |
||||
return isset($attributes['content']) ? $attributes['content'] : false; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
function get_link($key, $value) |
||||
{ |
||||
$links = $this->links(); |
||||
$key = strtolower($key); |
||||
$value = strtolower($value); |
||||
foreach ($links as $attributes) |
||||
{ |
||||
$a = isset($attributes[$key]) ? $attributes[$key] : false; |
||||
$a = $a ? strtolower($a) : $a; |
||||
if ($a == $value) |
||||
{ |
||||
return $attributes; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
public function links() |
||||
{ |
||||
if (!is_null($this->links)) |
||||
{ |
||||
return $this->links; |
||||
} |
||||
return $this->links = $this->get_links(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $xpath dom xpath |
||||
* @return string |
||||
*/ |
||||
public function findx($query) |
||||
{ |
||||
$doc = $this->doc(); |
||||
if (empty($doc)) |
||||
{ |
||||
return array(); |
||||
} |
||||
$xpath = new DOMXpath($doc); |
||||
$nodes = $xpath->query($query); |
||||
if ($nodes->length > 0) |
||||
{ |
||||
return $doc->saveXML($nodes->item(0)); |
||||
} |
||||
else |
||||
{ |
||||
return ''; |
||||
} |
||||
} |
||||
|
||||
protected function info() |
||||
{ |
||||
if (!is_null($this->info)) |
||||
{ |
||||
return $this->info; |
||||
} |
||||
return $this->info = self::fetch($this->url()); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $source |
||||
* @return boolean|DOMDocument |
||||
*/ |
||||
protected function get_doc($source) |
||||
{ |
||||
if ($source == false) |
||||
{ |
||||
return false; |
||||
} |
||||
$source = $this->source(); |
||||
$result = new DOMDocument(); |
||||
libxml_clear_errors(); |
||||
libxml_use_internal_errors(true); |
||||
if ($this->is_xml()) |
||||
{ |
||||
$success = $result->loadXML($source); |
||||
} |
||||
else |
||||
{ |
||||
$success = $result->loadHTML($source); |
||||
} |
||||
//$e = libxml_get_errors(); |
||||
return $result ? $result : false; |
||||
} |
||||
|
||||
protected function get_metadata() |
||||
{ |
||||
$result = array(); |
||||
|
||||
$doc = $this->doc(); |
||||
if ($doc == false) |
||||
{ |
||||
return array(); |
||||
} |
||||
$metas = $doc->getElementsByTagName('meta'); |
||||
if ($metas->length == 0) |
||||
{ |
||||
return $result; |
||||
} |
||||
foreach ($metas as $meta) |
||||
{ |
||||
$values = array(); |
||||
$attributes = $meta->attributes; |
||||
$length = $attributes->length; |
||||
for ($i = 0; $i < $length; ++$i) |
||||
{ |
||||
$name = $attributes->item($i)->name; |
||||
$value = $attributes->item($i)->value; |
||||
$value = $attributes->item($i)->value; |
||||
$values[$name] = $value; |
||||
} |
||||
$result[] = $values; |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
protected function get_title() |
||||
{ |
||||
$doc = $this->doc(); |
||||
if ($doc == false) |
||||
{ |
||||
return ''; |
||||
} |
||||
$titles = $doc->getElementsByTagName('title'); |
||||
if ($titles->length == 0) |
||||
{ |
||||
return false; |
||||
} |
||||
$result = $titles->item(0)->nodeValue; |
||||
return $result; |
||||
} |
||||
|
||||
protected function get_links() |
||||
{ |
||||
$doc = $this->doc(); |
||||
if ($doc == false) |
||||
{ |
||||
return array(); |
||||
} |
||||
$result = array(); |
||||
|
||||
$metas = $doc->getElementsByTagName('link'); |
||||
if ($metas->length == 0) |
||||
{ |
||||
return $result; |
||||
} |
||||
foreach ($metas as $meta) |
||||
{ |
||||
$values = array(); |
||||
$attributes = $meta->attributes; |
||||
$length = $attributes->length; |
||||
for ($i = 0; $i < $length; ++$i) |
||||
{ |
||||
$name = $attributes->item($i)->name; |
||||
$value = $attributes->item($i)->value; |
||||
$values[$name] = $value; |
||||
} |
||||
$result[] = $values; |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,113 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Google calendar renderer. |
||||
* |
||||
* @todo: |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetGoogleCalendarRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function accept($asset) |
||||
{ |
||||
$url = $asset->url(); |
||||
$url = str_replace('http://', '', $url); |
||||
$url = str_replace('https://', '', $url); |
||||
|
||||
$domain = reset(split('/', $url)); |
||||
return strpos($domain, 'google.com/calendar') !== false; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $url |
||||
*/ |
||||
public function explode_url_parameters($url = null) |
||||
{ |
||||
if (strpos($url, '?') === false) |
||||
{ |
||||
return array(); |
||||
} |
||||
|
||||
$result = array(); |
||||
$params = explode('?', $url); |
||||
$params = end($params); |
||||
$params = explode('&', $params); |
||||
foreach ($params as $param) |
||||
{ |
||||
list($key, $val) = explode('=', $param); |
||||
$result[$key] = $val; |
||||
} |
||||
|
||||
return $result; |
||||
} |
||||
|
||||
public function implode_url_parameters($params) |
||||
{ |
||||
$result = array(); |
||||
foreach ($params as $key => $value) |
||||
{ |
||||
if ($value) |
||||
{ |
||||
$result[] = "$key=$value"; |
||||
} |
||||
} |
||||
return join('&', $result); |
||||
} |
||||
|
||||
protected function url($base = 'http:://map.google.com/', $params = array()) |
||||
{ |
||||
$head = reset(explode('?', $base)); |
||||
$items = $this->explode_url_parameters($base); |
||||
foreach ($params as $key => $value) |
||||
{ |
||||
$items[$key] = $value; |
||||
} |
||||
$tail = $this->implode_url_parameters($items); |
||||
$tail = empty($tail) ? '' : "?$tail"; |
||||
return $head . $tail; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
if (!$this->accept($asset)) |
||||
{ |
||||
return; |
||||
} |
||||
$params = array('output' => 'embed'); |
||||
|
||||
$base = $asset->url(); |
||||
$url = $this->url($base, $params); |
||||
|
||||
$title = $asset->title(); |
||||
$description = $asset->get_meta('description'); |
||||
|
||||
$keywords = $asset->get_meta('keywords'); |
||||
|
||||
$embed = <<<EOT |
||||
<iframe width="100%" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="$url"></iframe> |
||||
EOT; |
||||
|
||||
|
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::TITLE] = $title; |
||||
$result[self::THUMBNAIL] = $image_src; |
||||
$result[self::DESCRIPTION] = $description; |
||||
$result[self::TAGS] = $keywords; |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,57 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Internal group. I.e. a group from this instance of Mahara. |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetMaharaGroupRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
public static function get_group_id($ref) |
||||
{ |
||||
$ref = trim($ref); |
||||
$pattern = '#group/view.php\?id\=([0123456789]+)#'; |
||||
$matches = array(); |
||||
//mahara group's profile |
||||
if (preg_match($pattern, $ref, $matches)) |
||||
{ |
||||
return $matches[1]; |
||||
} |
||||
//group id |
||||
if ($val = intval($ref)) |
||||
{ |
||||
return $val; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
$url = $asset->url(); |
||||
$group_id = self::get_group_id($url); |
||||
if (empty($group_id)) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
$data = get_record('group', 'id', $group_id); |
||||
|
||||
$result = array(); |
||||
safe_require('blocktype', 'ple/group'); |
||||
$result[self::EMBED_SNIPPET] = PluginBlocktypeGroup::render_preview($group_id); |
||||
$result[self::THUMBNAIL] = PluginBlocktypeGroup::get_thumbnail($group_id); |
||||
$result[self::TITLE] = $data->name; |
||||
$result[self::DESCRIPTION] = $data->description; |
||||
|
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,63 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* |
||||
* Internal person. I.e. a person from this instance of Mahara. |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetMaharaPersonRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
public static function get_user_id($ref) |
||||
{ |
||||
$ref = trim($ref); |
||||
$pattern = '#user/view.php\?id\=([0123456789]+)#'; |
||||
$matches = array(); |
||||
//mahara user's profile |
||||
if (preg_match($pattern, $ref, $matches)) |
||||
{ |
||||
return $matches[1]; |
||||
} |
||||
//email |
||||
if ($user = get_record('usr', 'email', $ref)) |
||||
{ |
||||
return $user->id; |
||||
} |
||||
//user id |
||||
if ($val = intval($ref)) |
||||
{ |
||||
return $val; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
$url = $asset->url(); |
||||
$id = self::get_user_id($url); |
||||
if (empty($id)) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
$data = get_record('usr', 'id', $id); |
||||
|
||||
$result = array(); |
||||
safe_require('blocktype', 'ple/person'); |
||||
$result[self::EMBED_SNIPPET] = PluginBlocktypePerson::render_preview($id); |
||||
$result[self::THUMBNAIL] = PluginBlocktypePerson::get_thumbnail($id); |
||||
$result[self::TITLE] = $data->prefferedname ? $data->prefferedname : $data->firstname . ' ' . $data->lastname; |
||||
$result[self::DESCRIPTION] = isset($data->description) ? $data->description : ''; |
||||
|
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,46 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Wiki renderer. |
||||
* |
||||
* @see http://en.wikipedia.org/w/api.php |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetWikiRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function accept($asset) |
||||
{ |
||||
return $asset->url_match('wikipedia.org/wiki', 'mediawiki.org/wiki'); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
* |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
if (!$this->accept($asset)) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
$domain = $asset->url_domain(); |
||||
$description = $asset->findx('//div[@id="bodyContent"]/p'); |
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = $description; |
||||
$result[self::TITLE] = $title; |
||||
$result[self::DESCRIPTION] = $description; |
||||
$result[self::TAGS] = $keywords; |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,75 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Google document renderer. |
||||
* |
||||
* @see http://support.google.com/docs/bin/answer.py?hl=en&answer=86101&topic=1360911&ctx=topic |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetGoogleDocumentRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function accept($asset) |
||||
{ |
||||
$url = $asset->url(); |
||||
|
||||
return strpos($url, 'docs.google.com/document/pub') !== false; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
if (!$this->accept($asset)) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
$url = $asset->url(); |
||||
|
||||
$title = $asset->title(); |
||||
$description = $asset->get_meta('description'); |
||||
$keywords = $asset->get_meta('keywords'); |
||||
|
||||
$size = (int) $asset->config('size'); |
||||
$size = (24 <= $size && $size <= 800) ? $size : 300; |
||||
|
||||
$embed = <<<EOT |
||||
|
||||
<div style="height:{$size}px;" class="resize vertical" > |
||||
<iframe style=background-color:#ffffff;" width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="$url"></iframe> |
||||
</div> |
||||
<style type="text/css"> |
||||
div.resize.vertical { |
||||
background-color: #EEEEEE; |
||||
border-color: #EEEEEE; |
||||
border-style: solid; |
||||
border-width: 1px; |
||||
resize:vertical; |
||||
overflow: hidden; |
||||
padding-bottom:15px; |
||||
min-height:24px; |
||||
max-height:800px; |
||||
} |
||||
</style> |
||||
EOT; |
||||
|
||||
|
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::TITLE] = $title; |
||||
$result[self::DESCRIPTION] = $description; |
||||
$result[self::TAGS] = $keywords; |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,95 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Google document viewer renderer. Provide an embeded viewer for the following |
||||
* documetn types: |
||||
* |
||||
* Microsoft Word (.DOC and .DOCX) |
||||
* Microsoft Excel (.XLS and .XLSX) |
||||
* Microsoft PowerPoint (.PPT and .PPTX) |
||||
* Adobe Portable Document Format (.PDF) |
||||
* Apple Pages (.PAGES) |
||||
* Adobe Illustrator (.AI) |
||||
* Adobe Photoshop (.PSD) |
||||
* Tagged Image File Format (.TIFF) |
||||
* Autodesk AutoCad (.DXF) |
||||
* Scalable Vector Graphics (.SVG) |
||||
* PostScript (.EPS, .PS) |
||||
* TrueType (.TTF) |
||||
* XML Paper Specification (.XPS) |
||||
* Archive file types (.ZIP and .RAR) |
||||
* |
||||
* @see https://docs.google.com/viewer |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetGoogleDocumentViewerRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function accept($asset) |
||||
{ |
||||
$supported_extentions = array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'pages', 'ai', 'psd', 'tiff', 'dxf', 'svg', 'eps', 'ps', 'eps', 'ttf', 'zip', 'rar'); |
||||
return $asset->has_ext($supported_extentions); |
||||
} |
||||
|
||||
protected function url($document_url) |
||||
{ |
||||
return 'https://docs.google.com/viewer?embedded=true&url=' . urlencode($document_url); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
if (!$this->accept($asset)) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
$url = $this->url($asset->url()); |
||||
|
||||
$title = $asset->title(); |
||||
$description = $asset->get_meta('description'); |
||||
|
||||
$keywords = $asset->get_meta('keywords'); |
||||
|
||||
$size = (int) $asset->config('size'); |
||||
$size = (24 <= $size && $size <= 800) ? $size : 300; |
||||
|
||||
$embed = <<<EOT |
||||
<div style="height:{$size}px;" class="resize vertical" > |
||||
<iframe style=background-color:#ffffff;" width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="$url"></iframe> |
||||
</div> |
||||
<style type="text/css"> |
||||
div.resize.vertical { |
||||
background-color: #EEEEEE; |
||||
border-color: #EEEEEE; |
||||
border-style: solid; |
||||
border-width: 1px; |
||||
resize:vertical; |
||||
overflow: hidden; |
||||
padding-bottom:15px; |
||||
min-height:24px; |
||||
max-height:800px; |
||||
} |
||||
</style> |
||||
EOT; |
||||
|
||||
|
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::TITLE] = $title; |
||||
//$result[self::THUMBNAIL] = $image_src; |
||||
$result[self::DESCRIPTION] = $description; |
||||
$result[self::TAGS] = $keywords; |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,129 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Google map page renderer. |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetGoogleMapRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function accept($asset) |
||||
{ |
||||
$url = $asset->url(); |
||||
$url = str_replace('http://', '', $url); |
||||
$url = str_replace('https://', '', $url); |
||||
|
||||
$domain = reset(explode('/', $url)); |
||||
return strpos($domain, 'maps.google') !== false; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $url |
||||
*/ |
||||
public function explode_url_parameters($url = null) |
||||
{ |
||||
if (strpos($url, '?') === false) |
||||
{ |
||||
return array(); |
||||
} |
||||
|
||||
$result = array(); |
||||
$params = explode('?', $url); |
||||
$params = end($params); |
||||
$params = explode('&', $params); |
||||
foreach ($params as $param) |
||||
{ |
||||
list($key, $val) = explode('=', $param); |
||||
$result[$key] = $val; |
||||
} |
||||
|
||||
return $result; |
||||
} |
||||
|
||||
public function implode_url_parameters($params) |
||||
{ |
||||
$result = array(); |
||||
foreach ($params as $key => $value) |
||||
{ |
||||
if ($value) |
||||
{ |
||||
$result[] = "$key=$value"; |
||||
} |
||||
} |
||||
return join('&', $result); |
||||
} |
||||
|
||||
protected function url($base = 'http:://map.google.com/', $params = array()) |
||||
{ |
||||
$head = reset(explode('?', $base)); |
||||
$items = $this->explode_url_parameters($base); |
||||
foreach ($params as $key => $value) |
||||
{ |
||||
$items[$key] = $value; |
||||
} |
||||
$tail = $this->implode_url_parameters($items); |
||||
$tail = empty($tail) ? '' : "?$tail"; |
||||
return $head . $tail; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
if (!$this->accept($asset)) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
$params = array('output' => 'embed'); |
||||
|
||||
$base = $asset->url(); |
||||
$url = $this->url($base, $params); |
||||
|
||||
$title = $asset->title(); |
||||
$description = $asset->get_meta('description'); |
||||
|
||||
$keywords = $asset->get_meta('keywords'); |
||||
|
||||
$size = (int) $asset->config('size'); |
||||
$size = (24 <= $size && $size <= 800) ? $size : 300; |
||||
|
||||
$embed = <<<EOT |
||||
<div style="height:{$size}px;" class="resize vertical" > |
||||
<iframe style=background-color:#ffffff;" width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="$url"></iframe> |
||||
</div> |
||||
<style type="text/css"> |
||||
div.resize.vertical { |
||||
background-color: #EEEEEE; |
||||
border-color: #EEEEEE; |
||||
border-style: solid; |
||||
border-width: 1px; |
||||
resize:vertical; |
||||
overflow: hidden; |
||||
padding-bottom:15px; |
||||
min-height:24px; |
||||
max-height:800px; |
||||
} |
||||
</style> |
||||
EOT; |
||||
|
||||
|
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::TITLE] = $title; |
||||
$result[self::DESCRIPTION] = $description; |
||||
$result[self::TAGS] = $keywords; |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,90 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Google widget/gadget renderer. |
||||
* Accept the following urls: |
||||
* |
||||
* module: http://www.google.com/ig/directory?type=gadgets&url=www.google.com/ig/modules/eyes/eyes.xml |
||||
* directory entry: www.google.com/ig/modules/eyes/eyes.xml |
||||
* configured url: www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/eyes/eyes.xml&synd=open&w=320&h=121&title=__MSG_title__&lang=fr&country=ALL&border=%23ffffff%7C3px%2C1px+solid+%23999999&output=js |
||||
* |
||||
* @see http://www.google.com/ig/directory?type=gadgets&url=www.google.com/ig/modules/eyes/eyes.xml |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetGoogleWidgetRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
|
||||
if ($asset->url_match('gmodules.com/ig/') && $asset->url_param('url') != false) |
||||
{ |
||||
$url = $asset->url(); |
||||
$title = $asset->url_param('title'); |
||||
$title = ($title == '__MSG_title__') ? '' : $title; |
||||
|
||||
$embed = <<<EOT |
||||
<script src="$url"></script> |
||||
EOT; |
||||
|
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::TITLE] = $title; |
||||
return $result; |
||||
} |
||||
|
||||
if (!$asset->is_gadget()) |
||||
{ |
||||
$url = $asset->url(); |
||||
|
||||
if (!$asset->url_match('google.com/ig/directory')) |
||||
{ |
||||
return false; |
||||
} |
||||
if (!$asset->url_match('type=gadgets')) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
$url = $asset->url_param('url'); |
||||
if (empty($url)) |
||||
{ |
||||
return false; |
||||
} |
||||
$asset = new HttpResource($url); |
||||
if (!$asset->is_gadget()) |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
$url = $asset->url(); |
||||
if (strpos($url, 'http') !== 0) |
||||
{ |
||||
$url = "http://$url"; |
||||
} |
||||
$url = urlencode($url); |
||||
$title = $asset->title(); |
||||
$title = $title ? $title : $asset->name(); |
||||
|
||||
$size = (int) $asset->config('size'); |
||||
$size = (24 <= $size && $size <= 800) ? $size : 300; |
||||
|
||||
$embed = <<<EOT |
||||
<script src="//www.gmodules.com/ig/ifr?url=$url&w=$size&output=js"></script> |
||||
EOT; |
||||
|
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::TITLE] = $title; |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,44 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Process image resources. I.e. png, jpeg, etc. |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetImageRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
if (! $asset->is_image()) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
global $THEME; |
||||
$url = $asset->url(); |
||||
$title = $asset->title(); |
||||
$title = $title ? $title : $asset->name(); |
||||
|
||||
$size = (int) $asset->config('size'); |
||||
$size = (24 <= $size && $size <= 800) ? $size : 300; |
||||
|
||||
$embed = <<<EOT |
||||
<div style="text-align:center"><a href="$url"><img src="{$url}" width="$size" alt="{$title}" title="{$title}"></a></div> |
||||
EOT; |
||||
|
||||
$result = array(); |
||||
$result[self::URL] = $url; |
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::TITLE] = $title; |
||||
$result[self::THUMBNAIL] = $url; |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,65 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Media renderer. I.e. video streams that can be embeded through an embed tag. |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetMediaRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function accept($asset) |
||||
{ |
||||
if ($asset->is_video()) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
//swf mime type is application/x-shockwave-flash |
||||
return $asset->has_ext('swf'); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
if (!$this->accept($asset)) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
$url = $asset->url(); |
||||
|
||||
$title = $asset->title(); |
||||
$description = $asset->get_meta('description'); |
||||
$keywords = $asset->get_meta('keywords'); |
||||
|
||||
|
||||
$size = (int) $asset->config('size'); |
||||
$size = (24 <= $size && $size <= 800) ? $size : 300; |
||||
|
||||
$width = $size; |
||||
$height = $size *9/16; |
||||
|
||||
$embed = <<<EOT |
||||
<div style="text-align:center;"><embed style="display:inline-block;" width="{$width}px" height="{$height}px" name="plugin" src="$url" ></div> |
||||
EOT; |
||||
|
||||
|
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::TITLE] = $title; |
||||
$result[self::DESCRIPTION] = $description; |
||||
$result[self::TAGS] = $keywords; |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,65 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Media Server renderer. |
||||
* |
||||
* Note that some videos are protected. It is therefore not possible to use the |
||||
* autodiscovery feature. That is to get the web page, look at the meta data headers |
||||
* and read the oembed api call. This would only work for public content/javascript |
||||
* bookmarklet. |
||||
* |
||||
* So here we bypass the discovery service and directly call the API endpoint |
||||
* with the page url to retrieve oembed metadata - which happens to be public. |
||||
* |
||||
* @see https://mediaserver.unige.ch |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetMediaserverRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
const API_ENDPOINT = 'http://129.194.20.121/oembed/unige-oembed-provider-test.php'; |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function accept($asset) |
||||
{ |
||||
return $asset->url_match('https://mediaserver.unige.ch/play/') ||$asset->url_match('http://mediaserver.unige.ch/play/'); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
if (!$this->accept($asset)) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
$width = (int) $asset->config('size'); |
||||
$width = (24 <= $width && $width <= 800) ? $width : 300; |
||||
|
||||
$url = $asset->url(); |
||||
|
||||
$oembed = self::API_ENDPOINT . '?url=' . urlencode($url) . '&maxwidth=' . $width; |
||||
|
||||
$data = HttpResource::fetch_json($oembed); |
||||
if (empty($data)) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
$result[self::THUMBNAIL] = isset($data['thumbnail_url']) ? $data['thumbnail_url'] : ''; |
||||
$result[self::TITLE] = isset($data['title']) ? $data['title'] : ''; |
||||
$result[self::EMBED_SNIPPET] = isset($data['html']) ? $data['html'] : ''; |
||||
|
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,124 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Process html pages that support the oembed protocol. |
||||
* |
||||
* Note that here we rely on the discovery service. That is each page that contains in |
||||
* its metadata the oembed request. |
||||
* |
||||
* @see http://oembed.com/ |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
* |
||||
*/ |
||||
class AssetOembedRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
$link = $asset->get_link('type', 'application/json+oembed'); |
||||
if (empty($link)) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
$width = (int) $asset->config('size'); |
||||
$width = (24 <= $width && $width <= 800) ? $width : 300; |
||||
|
||||
$href = $link['href']; |
||||
$data = HttpResource::fetch_json("$href&maxwidth=$width"); //&maxheight=$height |
||||
if (empty($data)) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
$data['title'] = isset($data['title']) ? $data['title'] : ''; |
||||
$data['width'] = isset($data['width']) ? intval($data['width']) : ''; |
||||
$data['height'] = isset($data['height']) ? intval($data['height']) : ''; |
||||
|
||||
$type = $data['type']; |
||||
$f = array($this, "render_$type"); |
||||
if (is_callable($f)) |
||||
{ |
||||
$result = call_user_func($f, $asset, $data); |
||||
} |
||||
else |
||||
{ |
||||
$result = array(); |
||||
} |
||||
$result[self::THUMBNAIL] = isset($data['thumbnail_url']) ? $data['thumbnail_url'] : ''; |
||||
$result[self::TITLE] = isset($data['title']) ? $data['title'] : ''; |
||||
|
||||
return $result; |
||||
} |
||||
|
||||
protected function render_photo($asset, $data) |
||||
{ |
||||
if ($data['type'] != 'photo') |
||||
{ |
||||
return array(); |
||||
} |
||||
|
||||
$result = array(); |
||||
$html = isset($data['html']) ? $data['html'] : ''; |
||||
if ($html) |
||||
{ |
||||
$result[self::EMBED_SNIPPET] = '<div style="display:inline-block">' . $html . '</div>'; |
||||
return $result; |
||||
} |
||||
|
||||
$title = $data['title']; |
||||
$width = (int)$data['width']; |
||||
$height = (int)$data['height']; |
||||
// $ratio = $height / $width; |
||||
// $height = $ratio * $width; |
||||
|
||||
$url = $data['url']; |
||||
|
||||
$embed = <<<EOT |
||||
<div><a href="$url"><img src="{$url}" width="{$width}" height="{$height}" "alt="{$title}" title="{$title}"></a></div> |
||||
EOT; |
||||
|
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
return $result; |
||||
} |
||||
|
||||
protected function render_video($asset, $data) |
||||
{ |
||||
if ($data['type'] != 'video') |
||||
{ |
||||
return array(); |
||||
} |
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = '<div style="display:inline-block">' . $data['html'] . '</div>'; |
||||
return $result; |
||||
} |
||||
|
||||
protected function render_rich($asset, $data) |
||||
{ |
||||
if ($data['type'] != 'rich') |
||||
{ |
||||
return array(); |
||||
} |
||||
|
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = '<div style="display:inline-block">' . $data['html'] . '</div>'; |
||||
return $result; |
||||
} |
||||
|
||||
protected function render_link($asset, $data) |
||||
{ |
||||
if ($data['type'] != 'link') |
||||
{ |
||||
return array(); |
||||
} |
||||
return array(); |
||||
} |
||||
|
||||
} |
@ -1,201 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Process pages that support the open graph protocol |
||||
* |
||||
* @see http://ogp.me/ |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetOgRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* Renderer function. Take a http asset as input and return an array containing |
||||
* various properties: metadata, html snippet, etc. |
||||
* |
||||
* @param HttpResource $asset |
||||
* @return array |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
$type = $asset->get_meta('og:type'); |
||||
if (empty($type)) |
||||
{ |
||||
if ($video = $asset->get_meta('og:video')) |
||||
{ |
||||
$type = 'video'; |
||||
} |
||||
else if ($video = $asset->get_meta('og:image')) |
||||
{ |
||||
$type = 'default'; |
||||
} |
||||
} |
||||
if (empty($type)) |
||||
{ |
||||
return array(); |
||||
} |
||||
|
||||
$type = explode('.', $type); |
||||
$type = reset($type); |
||||
$f = array($this, "render_$type"); |
||||
if (is_callable($f)) |
||||
{ |
||||
$result = call_user_func($f, $asset); |
||||
} |
||||
else |
||||
{ |
||||
$result = $this->render_default($asset); |
||||
} |
||||
|
||||
$result[self::TITLE] = $asset->get_meta('og:title'); |
||||
$result[self::THUMBNAIL] = $asset->get_meta('og:image'); |
||||
$result[self::LANGUAGE] = $asset->get_meta('og:language'); |
||||
|
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* @param HttpResource $asset |
||||
* @return array |
||||
*/ |
||||
protected function render_video($asset) |
||||
{ |
||||
$url = $asset->get_meta('og:video'); |
||||
$url = str_replace('?autoPlay=1', '?', $url); |
||||
$url = str_replace('&autoPlay=1', '', $url); |
||||
|
||||
if (empty($url)) |
||||
{ |
||||
return array(); |
||||
} |
||||
|
||||
$type = $asset->get_meta('og:video:type'); |
||||
if ($type) |
||||
{ |
||||
$type = ' type="' . $type . '" '; |
||||
} |
||||
|
||||
$size = (int) $asset->config('size'); |
||||
$size = (24 <= $size && $size <= 800) ? $size : 300; |
||||
|
||||
$width = $asset->get_meta('og:video:width'); |
||||
$width = $width ? $width : $asset->get_meta('video_width'); |
||||
$height = $asset->get_meta('og:video:height'); |
||||
$height = $height ? $height : $asset->get_meta('video_height'); |
||||
|
||||
if ($width) |
||||
{ |
||||
$ratio = $height / $width; |
||||
$base = min($size, $width); |
||||
$width = $base; |
||||
$height = $ratio * $base; |
||||
$size = 'width="' . $width . '" height="' . $height . '"'; |
||||
} |
||||
else |
||||
{ |
||||
$size = 'width="' . $size . '"'; |
||||
} |
||||
|
||||
$embed = <<<EOT |
||||
<embed $type $size src="$url" /> |
||||
EOT; |
||||
|
||||
$result[self::EMBED_TYPE] = $type; |
||||
$result[self::EMBED_URL] = $url; |
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::TAGS] = $asset->get_meta('og:video:tag'); |
||||
$result[self::CREATED_TIME] = $asset->get_meta('og:video:release_date'); |
||||
$result[self::DURATION] = $asset->get_meta('og:duration'); |
||||
return $result; |
||||
} |
||||
|
||||
protected function render_article($asset) |
||||
{ |
||||
$result = $this->render_default($asset); |
||||
return $result; |
||||
} |
||||
|
||||
protected function render_audio($asset) |
||||
{ |
||||
$result = $this->render_default($asset); |
||||
return $result; |
||||
} |
||||
|
||||
protected function render_book($asset) |
||||
{ |
||||
$result = $this->render_default($asset); |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
* @return array |
||||
*/ |
||||
protected function render_default($asset) |
||||
{ |
||||
$url = $asset->get_meta('og:url'); |
||||
$url = htmlentities($url); |
||||
$title = $asset->get_meta('og:title'); |
||||
$image = $asset->get_meta('og:image'); |
||||
$image = htmlentities($image); |
||||
$width = $asset->get_meta('og:image:width'); |
||||
$height = $asset->get_meta('og:image:height'); |
||||
$description = $asset->get_meta('og:description'); |
||||
$description = $description ? $description : $asset->get_meta('description'); |
||||
|
||||
$size = (int) $asset->config('size'); |
||||
$size = (24 <= $size && $size <= 800) ? $size : 300; |
||||
|
||||
if ($width) |
||||
{ |
||||
$ratio = $height / $width; |
||||
$base = min($size, $width); |
||||
$width = $base; |
||||
$height = $ratio * $base; |
||||
$size = 'width="' . $width . '" height="' . $height . '"'; |
||||
} |
||||
else |
||||
{ |
||||
$size = 'width="' . $size . '"'; |
||||
} |
||||
$embed = <<<EOT |
||||
<div> |
||||
<a href="$url" style="float:left; margin-right:5px; margin-bottom:5px; display:block;"><img src="{$image}" {$size} alt="{$title}" title="{$title}"></a> |
||||
<div style="clear:both;"></div> |
||||
</div> |
||||
EOT; |
||||
|
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::DESCRIPTION] = $asset->get_meta('description'); |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* @param HttpResource $asset |
||||
* @return array |
||||
*/ |
||||
protected function render_image($asset) |
||||
{ |
||||
$size = (int) $asset->config('size'); |
||||
$size = (24 <= $size && $size <= 800) ? $size : 300; |
||||
|
||||
$title = $data['title']; |
||||
$width = $data['width']; |
||||
$height = $data['height']; |
||||
$ratio = $height / $width; |
||||
$base = min($size, $width); |
||||
$width = $base; |
||||
$height = $ratio * $base; |
||||
|
||||
$url = $data['url']; |
||||
|
||||
$embed = <<<EOT |
||||
<a href="$url"><img src="{$url}" width="{$width}" height="{$height} "alt="{$title}" title="{$title}"></a> |
||||
EOT; |
||||
} |
||||
|
||||
} |
@ -1,83 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Generic HTML page renderer. Process any html page. |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetPageRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
global $THEME; |
||||
$url = $asset->url(); |
||||
$title = $asset->title(); |
||||
$title = $title ? $title : $asset->name(); |
||||
$description = $asset->get_meta('description'); |
||||
$description = $description; |
||||
|
||||
$keywords = $asset->get_meta('keywords'); |
||||
|
||||
$image_src = $asset->get_link('rel', 'image_src'); |
||||
$image_src = $image_src ? $image_src['href'] : false; |
||||
|
||||
if (empty($image_src)) |
||||
{ |
||||
$image_src = $this->get_icon($asset); |
||||
} |
||||
|
||||
$icon = $this->get_icon($asset); |
||||
|
||||
$image_src = $asset->canonic_url($image_src); |
||||
$icon = $asset->canonic_url($icon); |
||||
|
||||
$embed = <<<EOT |
||||
<a href="$url"> |
||||
<img src="{$image_src}" alt="{$title}" title="{$title}" style="float:left; margin-right:5px; margin-bottom:5px; " > |
||||
</a> |
||||
$description |
||||
<span style="clear:both;"></span> |
||||
EOT; |
||||
|
||||
|
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::TITLE] = $title; |
||||
$result[self::THUMBNAIL] = $image_src; |
||||
$result[self::DESCRIPTION] = $description; |
||||
$result[self::ICON] = $icon; |
||||
$result[self::TAGS] = $keywords; |
||||
return $result; |
||||
} |
||||
|
||||
function get_icon($asset) |
||||
{ |
||||
|
||||
$icon = $asset->get_link('rel', 'apple-touch-icon'); |
||||
$icon = $icon ? $icon['href'] : false; |
||||
if (empty($icon)) |
||||
{ |
||||
$icon = $asset->get_link('rel', 'fluid-icon'); |
||||
$icon = $icon ? $icon['href'] : false; |
||||
} |
||||
if (empty($icon)) |
||||
{ |
||||
$icon = $asset->get_link('rel', 'shortcut icon'); |
||||
$icon = $icon ? $icon['href'] : false; |
||||
} |
||||
if (empty($icon)) |
||||
{ |
||||
$icon = $asset->get_link('rel', 'icon'); |
||||
$icon = $icon ? $icon['href'] : false; |
||||
} |
||||
return $icon; |
||||
} |
||||
|
||||
} |
@ -1,95 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Rss renderer. Display RSS thanks to Google feed control. |
||||
* |
||||
* @see http://www.google.com/uds/solutions/dynamicfeed/reference.html |
||||
* @see http://code.google.com/apis/ajax/playground/#dynamic_feed_control_-_vertical |
||||
* |
||||
* @copyright (c) 2011 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetRssRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
if (!$asset->is_rss()) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
$url = $asset->url(); |
||||
$title = $asset->title(); |
||||
$id = 'a' . md5($url); |
||||
|
||||
$embed = <<<EOT |
||||
<style type="text/css"> |
||||
.gfg-root { |
||||
border: none; |
||||
font-family: inherit; |
||||
} |
||||
</style> |
||||
<script type="text/javascript" src="http://www.google.com/jsapi"></script> |
||||
<script src="http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js" type="text/javascript"></script> |
||||
<script type="text/javascript"> |
||||
|
||||
function init() |
||||
{ |
||||
if (typeof this.has_run == 'undefined' ) |
||||
{ |
||||
this.has_run = true; |
||||
} |
||||
else |
||||
{ |
||||
return; |
||||
} |
||||
var head = document.getElementsByTagName('head')[0]; |
||||
|
||||
var element = document.createElement('link'); |
||||
element.type = 'text/css'; |
||||
element.rel = 'stylesheet'; |
||||
element.href = 'http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.css'; |
||||
head.appendChild(element); |
||||
} |
||||
|
||||
function load_$id() { |
||||
var feeds = [ |
||||
{ |
||||
title: ' ', |
||||
url: '$url' |
||||
} |
||||
]; |
||||
|
||||
var options = { |
||||
stacked : false, |
||||
horizontal : false, |
||||
title : '', |
||||
numResults : 10 |
||||
}; |
||||
|
||||
new GFdynamicFeedControl(feeds, '$id', options); |
||||
document.getElementById('content').style.width = "500px"; |
||||
} |
||||
|
||||
|
||||
init(); |
||||
google.load('feeds', '1'); |
||||
google.setOnLoadCallback(load_$id); |
||||
</script> |
||||
<div id="$id" style="min-height:271px;">Loading...</div> |
||||
EOT; |
||||
|
||||
|
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::TITLE] = $title; |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,76 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Scratch renderer. |
||||
* |
||||
* @see http://scratch.mit.edu/projects/ |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht |
||||
*/ |
||||
class AssetScratchRenderer extends AssetRenderer |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function accept($asset) |
||||
{ |
||||
return $asset->url_match('http://scratch.mit.edu/projects/'); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param HttpResource $asset |
||||
*/ |
||||
public function render($asset) |
||||
{ |
||||
if (!$this->accept($asset)) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
$matches = array(); |
||||
$pattern = "#http:\/\/scratch.mit.edu\/projects\/(\w+)/(\d*)\/?#ims"; |
||||
preg_match($pattern, $asset->url(), $matches); |
||||
|
||||
$url = $matches[0]; |
||||
$author = $matches[1]; |
||||
$project_id = $matches[2]; |
||||
|
||||
$project_url = "../../static/projects/$author/$project_id.sb"; |
||||
$image_url = "http://scratch.mit.edu/static/projects/$author/{$project_id}_med.png"; |
||||
$thumb_url = "http://scratch.mit.edu/static/projects/$author/{$project_id}_sm.png"; |
||||
|
||||
$height = 387; |
||||
$width = 482; |
||||
|
||||
if (function_exists('get_string')) |
||||
{ |
||||
$no_java = get_string('no_java', 'artefact.extresource'); |
||||
} |
||||
else |
||||
{ |
||||
$no_java = 'Java is not installed on your computer. You must install java first.'; |
||||
} |
||||
|
||||
$embed = <<<EOT |
||||
<object type="application/x-java-applet" width="$width" height="$height" style="display:block" id="ProjectApplet"> |
||||
|
||||
<param name="codebase" value="http://scratch.mit.edu/static/misc"> |
||||
<param name="archive" value="ScratchApplet.jar"> |
||||
<param name="code" value="ScratchApplet"> |
||||
<param name="project" value="$project_url"> |
||||
<pre>$no_java</pre> |
||||
<img alt="" src="$image_url"> |
||||
</object> |
||||
EOT; |
||||
$result = array(); |
||||
$result[self::EMBED_SNIPPET] = $embed; |
||||
$result[self::THUMBNAIL] = $thumb_url; |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,131 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
*/ |
||||
class Curl |
||||
{ |
||||
|
||||
protected static $default_options = array(); |
||||
|
||||
static function get_default_options($options = array()) |
||||
{ |
||||
if (empty(self::$default_options)) { |
||||
self::$default_options[CURLOPT_HEADER] = false; |
||||
self::$default_options[CURLOPT_RETURNTRANSFER] = true; |
||||
self::$default_options[CURLOPT_SSL_VERIFYPEER] = false; |
||||
} |
||||
|
||||
$result = self::$default_options; |
||||
foreach ($options as $key => $value) { |
||||
$result[$key] = $value; |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
static function set_default_option($key, $value) |
||||
{ |
||||
$options = $this->get_options(array($key => $value)); |
||||
self::$default_options = $options; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $url |
||||
* @param array $options |
||||
* @return Curl |
||||
*/ |
||||
static function get($url, $options = array()) |
||||
{ |
||||
$options[CURLOPT_HTTPGET] = true; |
||||
$result = new self($url, $options); |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $url |
||||
* @param array $fields |
||||
* @param array $options |
||||
* @return Curl |
||||
*/ |
||||
static function post($url, $fields, $options = array()) |
||||
{ |
||||
$options[CURLOPT_POST] = true; |
||||
$options[CURLOPT_POSTFIELDS] = $fields; |
||||
$result = new self($url, $options); |
||||
return $result; |
||||
} |
||||
|
||||
protected $url = ''; |
||||
protected $options = array(); |
||||
protected $content = ''; |
||||
protected $info = array(); |
||||
protected $error = ''; |
||||
protected $error_no = 0; |
||||
|
||||
function __construct($url, $options = array()) |
||||
{ |
||||
$this->url = $url; |
||||
$this->options = self::get_default_options($options); |
||||
} |
||||
|
||||
function url() |
||||
{ |
||||
return $this->url; |
||||
} |
||||
|
||||
function options() |
||||
{ |
||||
return $this->options; |
||||
} |
||||
|
||||
function execute() |
||||
{ |
||||
$ch = curl_init(); |
||||
|
||||
$options = $this->options; |
||||
$options[CURLOPT_URL] = $this->url; |
||||
curl_setopt_array($ch, $options); |
||||
|
||||
$this->content = curl_exec($ch); |
||||
$this->error = curl_error($ch); |
||||
$this->info = curl_getinfo($ch); |
||||
$this->error_no = curl_errno($ch); |
||||
|
||||
curl_close($ch); |
||||
|
||||
return $this->content; |
||||
} |
||||
|
||||
function content() |
||||
{ |
||||
return $this->content; |
||||
} |
||||
|
||||
/** |
||||
* @return array|string |
||||
*/ |
||||
function info($key = false) |
||||
{ |
||||
if ($key) { |
||||
return isset($this->info[$key]) ? $this->info[$key] : false; |
||||
} else { |
||||
return $this->info; |
||||
} |
||||
} |
||||
|
||||
function error() |
||||
{ |
||||
return $this->error; |
||||
} |
||||
|
||||
function error_no() |
||||
{ |
||||
return $this->error_no; |
||||
} |
||||
|
||||
} |
@ -1,72 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace net; |
||||
|
||||
use Curl; |
||||
|
||||
/** |
||||
* Description of channel |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
*/ |
||||
class HttpChannel |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param string $url |
||||
* @param type $modules |
||||
* @return HttpChannel |
||||
*/ |
||||
static function create($url, $modules = array()) |
||||
{ |
||||
return new self($url, $modules); |
||||
} |
||||
|
||||
protected $base_url = ''; |
||||
protected $modules = array(); |
||||
|
||||
public function __construct($base_url = '', $modules = array()) |
||||
{ |
||||
$this->base_url = $base_url; |
||||
$this->modules = $modules; |
||||
} |
||||
|
||||
function modules() |
||||
{ |
||||
return $this->modules; |
||||
} |
||||
|
||||
function get($url, $parameters) |
||||
{ |
||||
$options = $this->get_options(); |
||||
$url = $this->base_url . $url; |
||||
return Curl::get($url, $options)->execute(); |
||||
} |
||||
|
||||
function post($url, $fields) |
||||
{ |
||||
$options = $this->get_options(); |
||||
$url = $this->base_url . $url; |
||||
return Curl::post($url, $fields, $options)->execute(); |
||||
} |
||||
|
||||
protected function get_options() |
||||
{ |
||||
$result = array(); |
||||
$modules = $this->modules(); |
||||
foreach ($modules as $module) { |
||||
if (is_array($module)) { |
||||
$options = $module; |
||||
} else { |
||||
|
||||
$options = $module->get_options(); |
||||
} |
||||
$result = array_merge($result, $options); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
} |
@ -1,149 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace Portfolio; |
||||
|
||||
/** |
||||
* An artefact is any object the user can display in its portfolio. |
||||
* |
||||
* The artefact point either to a local file or to a url from which the object's content |
||||
* can be fetched. |
||||
* |
||||
* Usage |
||||
* |
||||
* $artefact = new artefact(); |
||||
* $artefact->set_path('...'); |
||||
* |
||||
* or |
||||
* |
||||
* |
||||
* $artefact = new artefact(); |
||||
* $artefact->set_url('...'); |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
*/ |
||||
class Artefact |
||||
{ |
||||
|
||||
protected $id = ''; |
||||
protected $mime_type = ''; |
||||
protected $name = ''; |
||||
protected $description = ''; |
||||
protected $path = ''; |
||||
protected $url = ''; |
||||
protected $creation_date = ''; |
||||
protected $modification_date = ''; |
||||
protected $metadata = null; |
||||
|
||||
/** |
||||
* |
||||
* @param string $file Either url or file path |
||||
*/ |
||||
public function __construct($file = '') |
||||
{ |
||||
if ($file) { |
||||
if (strpos($file, 'http') !== false) { |
||||
$this->url = $file; |
||||
} else { |
||||
$this->path = $file; |
||||
} |
||||
} |
||||
$this->id = uniqid('', true); |
||||
$this->mime_type = ''; |
||||
$time = time(); |
||||
$this->creation_date = $time; |
||||
$this->modification_date = $time; |
||||
} |
||||
|
||||
public function get_id() |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function set_id($value) |
||||
{ |
||||
$this->id = $value; |
||||
} |
||||
|
||||
public function get_name() |
||||
{ |
||||
return $this->name; |
||||
} |
||||
|
||||
public function set_name($value) |
||||
{ |
||||
$this->name = $value; |
||||
} |
||||
|
||||
public function get_mime_type() |
||||
{ |
||||
return $this->mime_type; |
||||
} |
||||
|
||||
public function set_mime_type($value) |
||||
{ |
||||
$this->mime_type = $value; |
||||
} |
||||
|
||||
public function get_description() |
||||
{ |
||||
return $this->description; |
||||
} |
||||
|
||||
public function set_description($value) |
||||
{ |
||||
$this->description = $value; |
||||
} |
||||
|
||||
public function get_path() |
||||
{ |
||||
return $this->path; |
||||
} |
||||
|
||||
public function set_path($value) |
||||
{ |
||||
$this->path = $value; |
||||
} |
||||
|
||||
public function get_url() |
||||
{ |
||||
return $this->url; |
||||
} |
||||
|
||||
public function set_url($value) |
||||
{ |
||||
$this->url = $value; |
||||
} |
||||
|
||||
public function get_creation_date() |
||||
{ |
||||
return $this->creation_date; |
||||
} |
||||
|
||||
public function set_creation_date($value) |
||||
{ |
||||
$this->creation_date = $value; |
||||
} |
||||
|
||||
public function get_modification_date() |
||||
{ |
||||
return $this->modification_date; |
||||
} |
||||
|
||||
public function set_modification_date($value) |
||||
{ |
||||
$this->modification_date = $value; |
||||
} |
||||
|
||||
public function get_metadata() |
||||
{ |
||||
return $this->metadata; |
||||
} |
||||
|
||||
public function set_metadata($value) |
||||
{ |
||||
$this->metadata = $value; |
||||
} |
||||
|
||||
} |
@ -1,35 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace Portfolio; |
||||
|
||||
use Header; |
||||
|
||||
/** |
||||
* Download file to your desktop |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
*/ |
||||
class Download extends Portfolio |
||||
{ |
||||
|
||||
function __construct() |
||||
{ |
||||
parent::__construct('download', null); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param User $user |
||||
* @param Artefact $artefact |
||||
* @return bool |
||||
*/ |
||||
function send($user, $artefact) |
||||
{ |
||||
if ($artefact->get_url()) { |
||||
Header::location($artefact->get_url()); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,59 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace Portfolio; |
||||
|
||||
use Header; |
||||
|
||||
/** |
||||
* Interface with a Mahara portfolio. |
||||
* |
||||
* This class requires that the connect mahara plugin is installed and enabled. |
||||
* |
||||
* @see https://mahara.org/ |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
*/ |
||||
class Mahara extends Portfolio |
||||
{ |
||||
|
||||
protected $url = ''; |
||||
|
||||
/** |
||||
* |
||||
* @param string $url The root url |
||||
*/ |
||||
function __construct($url) |
||||
{ |
||||
$name = md5($url); |
||||
parent::__construct($name, null); |
||||
$this->url = $url; |
||||
} |
||||
|
||||
function get_url() |
||||
{ |
||||
return $this->url; |
||||
} |
||||
|
||||
function get_title(){ |
||||
$result = parent::get_title(); |
||||
$result = $result ? $result : 'Mahara'; |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param User $user |
||||
* @param Artefact $artefact |
||||
* @return bool |
||||
*/ |
||||
function send($user, $artefact) |
||||
{ |
||||
$root = $this->get_url(); |
||||
rtrim($root, '/'); |
||||
$url = $artefact->get_url(); |
||||
$url = $root . '/artefact/connect/upload.php?url=' . urlencode($url) . '&extract=true'; |
||||
Header::location($url); |
||||
} |
||||
|
||||
} |
@ -1,106 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace Portfolio; |
||||
|
||||
/** |
||||
* Portfolio are used to display and share content. The porfolio class represents |
||||
* one (external) portfolio application and allows to share content with an it. |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
*/ |
||||
class Portfolio |
||||
{ |
||||
|
||||
public static function none() |
||||
{ |
||||
static $result = null; |
||||
if (empty($result)) { |
||||
$result = new self('empty', null); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
public static function all() |
||||
{ |
||||
|
||||
} |
||||
|
||||
protected $name; |
||||
protected $title = ''; |
||||
protected $description = ''; |
||||
protected $channel; |
||||
|
||||
function __construct($name, $channel = null) |
||||
{ |
||||
$this->name = $name; |
||||
$this->title = $name; |
||||
$this->channel = $channel; |
||||
} |
||||
|
||||
/** |
||||
* The name of the portfolio - i.e. the unique id. |
||||
* @return type |
||||
*/ |
||||
function get_name() |
||||
{ |
||||
return $this->name; |
||||
} |
||||
|
||||
/** |
||||
* Title for the end user. |
||||
* |
||||
* @return type |
||||
*/ |
||||
function get_title() |
||||
{ |
||||
return $this->title; |
||||
} |
||||
|
||||
function set_title($value) |
||||
{ |
||||
$this->title = $value; |
||||
} |
||||
|
||||
/** |
||||
* Description for the end user. |
||||
* |
||||
* @return type |
||||
*/ |
||||
function get_description() |
||||
{ |
||||
return $this->description; |
||||
} |
||||
|
||||
function set_description($value) |
||||
{ |
||||
$this->description = $value; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return HttpChannel |
||||
*/ |
||||
function channel() |
||||
{ |
||||
return $this->channel; |
||||
} |
||||
|
||||
function __toString() |
||||
{ |
||||
return $this->name; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param User $user |
||||
* @param Artefact $artefact |
||||
* @return bool |
||||
*/ |
||||
function send($user, $artefact) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
} |
@ -1,19 +0,0 @@ |
||||
<?php |
||||
|
||||
namespace Portfolio; |
||||
|
||||
/** |
||||
* A portfolio user is used to share identity between two applications. |
||||
* Not used at this point. |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
*/ |
||||
class User |
||||
{ |
||||
public $id; |
||||
public $email; |
||||
public $token; |
||||
|
||||
} |
@ -1,33 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Convert text. Used mostly to convert from one encoding to another. |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
*/ |
||||
class Converter |
||||
{ |
||||
|
||||
/** |
||||
* Identity converter. Returns the string with no transformations. |
||||
* |
||||
* @return Converter |
||||
*/ |
||||
public static function identity() |
||||
{ |
||||
static $result = null; |
||||
if(empty($result)) |
||||
{ |
||||
$result = new self(); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
|
||||
function convert($string) |
||||
{ |
||||
return $string; |
||||
} |
||||
} |
@ -1,158 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Set the system encoding to the plateform encoding. |
||||
* |
||||
* @todo: |
||||
* Note: those lines are here for ease of use only. They should be move away: |
||||
* |
||||
* 1 first autodetection should be done inside the Encoding class |
||||
* 2 this library should not call a chamilo specific function (this should |
||||
* be the other way around, chamilo calling the encoding functions) |
||||
*/ |
||||
|
||||
$plateform_encoding = api_get_system_encoding(); |
||||
Encoding::system($plateform_encoding); |
||||
|
||||
/** |
||||
* Encoding class. Handles text encoding. Usage: |
||||
* |
||||
* $encoding = Encoding::get('name'); |
||||
* $decoder = $encoding->decoder(); |
||||
* $decoder->convert('text'); |
||||
* |
||||
* The system encoding is the platform/system/default encoding. This defaults to |
||||
* UTF8 but can be changed: |
||||
* |
||||
* Encoding::system('name'); |
||||
* |
||||
* Note that Encoding returns to its name when converted to a string. As such it |
||||
* can be used in places where a string is expected: |
||||
* |
||||
* $utf8 = Encoding::Utf8(); |
||||
* echo $utf8; |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
*/ |
||||
class Encoding |
||||
{ |
||||
|
||||
private static $system = null; |
||||
|
||||
/** |
||||
* Returns encoding for $name. |
||||
* |
||||
* @param string $name |
||||
* @return Encoding |
||||
*/ |
||||
public static function get($name) |
||||
{ |
||||
if (is_object($name)) { |
||||
return $name; |
||||
} else if (Encoding::utf8()->is($name)) { |
||||
return self::utf8(); |
||||
} else { |
||||
return new self($name); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns the Utf8 encoding. |
||||
* |
||||
* @return Utf8 |
||||
*/ |
||||
public static function utf8() |
||||
{ |
||||
return Utf8::instance(); |
||||
} |
||||
|
||||
/** |
||||
* Returns/set the system/default encoding. |
||||
* |
||||
* @return Encoding |
||||
*/ |
||||
public static function system($value = null) |
||||
{ |
||||
if (is_object($value)) { |
||||
self::$system = $value; |
||||
} else if (is_string($value)) { |
||||
self::$system = self::get($value); |
||||
} |
||||
|
||||
return self::$system ? self::$system : self::utf8(); |
||||
} |
||||
|
||||
/** |
||||
* Detect encoding from an abstract. |
||||
* |
||||
* @param string $abstract |
||||
* @return Encoding |
||||
*/ |
||||
public static function detect_encoding($abstract) |
||||
{ |
||||
$encoding_name = api_detect_encoding($abstract); |
||||
return self::get($encoding_name); |
||||
} |
||||
|
||||
protected $name = ''; |
||||
|
||||
protected function __construct($name = '') |
||||
{ |
||||
$this->name = $name; |
||||
} |
||||
|
||||
/** |
||||
* The name of the encoding |
||||
* |
||||
* @return string |
||||
*/ |
||||
function name() |
||||
{ |
||||
return $this->name; |
||||
} |
||||
|
||||
/** |
||||
* The Byte Order Mark. |
||||
* |
||||
* @see http://en.wikipedia.org/wiki/Byte_order_mark |
||||
* @return string |
||||
*/ |
||||
function bom() |
||||
{ |
||||
return ''; |
||||
} |
||||
|
||||
/** |
||||
* Returns a decoder that convert encoding to another encoding. |
||||
* |
||||
* @param string|Encoder $to Encoding to convert to, defaults to system encoding |
||||
* @return Converter |
||||
*/ |
||||
public function decoder($to = null) |
||||
{ |
||||
$from = $this; |
||||
$to = $to ? $to : Encoding::system(); |
||||
return EncodingConverter::create($from, $to); |
||||
} |
||||
|
||||
/** |
||||
* Returns an encoder that convert from another encoding to this encoding. |
||||
* |
||||
* @param string|Encoder $from Encoding to convert from, defaults to system encoding. |
||||
* @return Converter |
||||
*/ |
||||
public function encoder($from = null) |
||||
{ |
||||
$from = $from ? $from : Encoding::system(); |
||||
$to = $this; |
||||
return EncodingConverter::create($from, $to); |
||||
} |
||||
|
||||
function __toString() |
||||
{ |
||||
return $this->name(); |
||||
} |
||||
|
||||
} |
@ -1,71 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Convert text from one encoding to another. Usage: |
||||
* |
||||
* $converter = EncodingConverter::create($from, $to); |
||||
* $converter->convert($text); |
||||
* |
||||
* Note that the create function will returns an identify converter if from and to |
||||
* encodings are the same. Reason why the constructor is private. |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
*/ |
||||
class EncodingConverter extends Converter |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @param string $from_encoding |
||||
* @param string $to_encoding |
||||
* |
||||
* @return EncodingConverter |
||||
*/ |
||||
public static function create($from_encoding, $to_encoding) |
||||
{ |
||||
$from_encoding = (string) $from_encoding; |
||||
$to_encoding = (string) $to_encoding; |
||||
if (strtolower($from_encoding) == strtolower($to_encoding)) { |
||||
return Converter::identity(); |
||||
} else { |
||||
return new self($from_encoding, $to_encoding); |
||||
} |
||||
} |
||||
|
||||
protected $from_encoding; |
||||
protected $to_encoding; |
||||
|
||||
protected function __construct($from_encoding, $to_encoding) |
||||
{ |
||||
$this->from_encoding = $from_encoding; |
||||
$this->to_encoding = $to_encoding; |
||||
} |
||||
|
||||
function from_encoding() |
||||
{ |
||||
return $this->from_encoding; |
||||
} |
||||
|
||||
function to_encoding() |
||||
{ |
||||
return $this->to_encoding; |
||||
} |
||||
|
||||
function convert($string) |
||||
{ |
||||
$from = $this->from_encoding; |
||||
$to = $this->to_encoding; |
||||
if ($from == $to) { |
||||
return $string; |
||||
} |
||||
return api_convert_encoding($string, $to, $from); |
||||
} |
||||
|
||||
function reset() |
||||
{ |
||||
; |
||||
} |
||||
|
||||
} |
@ -1,287 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Utf8 encoding class. Provides utility function to deal with UTF8 encoding. |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
* @author More authors, mentioned in the correpsonding fragments of this source. |
||||
*/ |
||||
class Utf8 extends Encoding |
||||
{ |
||||
|
||||
const PATTERN_NOT_VISIBLE_CHARS = '/[^[:print:]-]/'; //Visible characters and the space character |
||||
|
||||
/** |
||||
* @see http://en.wikipedia.org/wiki/Byte_order_mark |
||||
*/ |
||||
const BOM = "\xEF\xBB\xBF"; |
||||
const NAME = 'UTF-8'; |
||||
|
||||
/** |
||||
* |
||||
* @return Utf8 |
||||
*/ |
||||
public static function instance() |
||||
{ |
||||
static $result = null; |
||||
if (empty($result)) { |
||||
$result = new self(); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* Returns true if encoding is UTF8. |
||||
* |
||||
* @param string|Encoding $encoding |
||||
* @return bool |
||||
*/ |
||||
function is($encoding) |
||||
{ |
||||
$encoding = (string) $encoding; |
||||
return strtolower($encoding) == strtolower(self::NAME); |
||||
} |
||||
|
||||
protected function __construct() |
||||
{ |
||||
parent::__construct(self::NAME); |
||||
} |
||||
|
||||
function name() |
||||
{ |
||||
return self::NAME; |
||||
} |
||||
|
||||
function bom() |
||||
{ |
||||
return self::BOM; |
||||
} |
||||
|
||||
/** |
||||
* Returns the hexa decimal representation of an utf8 string. Usefull to understand |
||||
* what is going on - not printable chars, rare patterns such as e' for é, etc. |
||||
* |
||||
* @param type $text |
||||
* @return string |
||||
*/ |
||||
function to_hex($text) |
||||
{ |
||||
$result = ''; |
||||
mb_internal_encoding('utf-8'); |
||||
|
||||
for ($i = 0, $n = mb_strlen($text); $i < $n; $i++) { |
||||
$char = mb_substr($text, $i, 1); |
||||
$num = strlen($char); |
||||
for ($j = 0; $j < $num; $j++) { |
||||
$result .= sprintf('%02x', ord($char[$j])); |
||||
} |
||||
$result .= ' '; |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* Trim the BOM from an utf-8 string |
||||
* |
||||
* @param string $text |
||||
* @return string |
||||
*/ |
||||
function trim($text) |
||||
{ |
||||
$bom = self::BOM; |
||||
if (strlen($text) < strlen($bom)) { |
||||
return $text; |
||||
} |
||||
|
||||
if (substr($text, 0, 3) == $bom) { |
||||
return substr($text, 3); |
||||
} |
||||
return $text; |
||||
} |
||||
|
||||
/** |
||||
* Checks a string for UTF-8 validity. |
||||
* |
||||
* @param string $string The string to be tested. |
||||
* @return bool Returns TRUE when the tested string is valid UTF-8, FALSE othewise. |
||||
* @link http://en.wikipedia.org/wiki/UTF-8 |
||||
* @author see internationalization.lib.php |
||||
*/ |
||||
static function is_valid(&$string) |
||||
{ |
||||
|
||||
//return @mb_detect_encoding($string, 'UTF-8', true) == 'UTF-8' ? true : false; |
||||
// Ivan Tcholakov, 05-OCT-2008: I do not trust mb_detect_encoding(). I have |
||||
// found a string with a single cyrillic letter (single byte), that is |
||||
// wrongly detected as UTF-8. Possibly, there would be problems with other |
||||
// languages too. An alternative implementation will be used. |
||||
|
||||
$str = (string) $string; |
||||
$len = api_byte_count($str); |
||||
$i = 0; |
||||
while ($i < $len) { |
||||
$byte1 = ord($str[$i++]); // Here the current character begins. Its size is |
||||
// determined by the senior bits in the first byte. |
||||
|
||||
if (($byte1 & 0x80) == 0x00) { // 0xxxxxxx |
||||
// & |
||||
// 10000000 |
||||
// -------- |
||||
// 00000000 |
||||
// This is s valid character and it contains a single byte. |
||||
} elseif (($byte1 & 0xE0) == 0xC0) { // 110xxxxx 10xxxxxx |
||||
// & & |
||||
// 11100000 11000000 |
||||
// -------- -------- |
||||
// 11000000 10000000 |
||||
// The character contains two bytes. |
||||
if ($i == $len) { |
||||
return false; // Here the string ends unexpectedly. |
||||
} |
||||
|
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) |
||||
return false; // Invalid second byte, invalid string. |
||||
} |
||||
|
||||
elseif (($byte1 & 0xF0) == 0xE0) { // 1110xxxx 10xxxxxx 10xxxxxx |
||||
// & & & |
||||
// 11110000 11000000 11000000 |
||||
// -------- -------- -------- |
||||
// 11100000 10000000 10000000 |
||||
// This is a character of three bytes. |
||||
if ($i == $len) { |
||||
return false; // Unexpected end of the string. |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; // Invalid second byte. |
||||
} |
||||
if ($i == $len) { |
||||
return false; // Unexpected end of the string. |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; // Invalid third byte, invalid string. |
||||
} |
||||
} elseif (($byte1 & 0xF8) == 0xF0) { // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
||||
// & & & & |
||||
// 11111000 11000000 11000000 11000000 |
||||
// -------- -------- -------- -------- |
||||
// 11110000 10000000 10000000 10000000 |
||||
// This is a character of four bytes. |
||||
if ($i == $len) { |
||||
return false; |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; |
||||
} |
||||
if ($i == $len) { |
||||
return false; |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; |
||||
} |
||||
if ($i == $len) { |
||||
return false; |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; |
||||
} |
||||
} elseif (($byte1 & 0xFC) == 0xF8) { // 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx |
||||
// & & & & & |
||||
// 11111100 11000000 11000000 11000000 11000000 |
||||
// -------- -------- -------- -------- -------- |
||||
// 11111000 10000000 10000000 10000000 10000000 |
||||
// This is a character of five bytes. |
||||
if ($i == $len) { |
||||
return false; |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; |
||||
} |
||||
if ($i == $len) { |
||||
return false; |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; |
||||
} |
||||
if ($i == $len) { |
||||
return false; |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; |
||||
} |
||||
if ($i == $len) { |
||||
return false; |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; |
||||
} |
||||
} elseif (($byte1 & 0xFE) == 0xFC) { // 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx |
||||
// & & & & & & |
||||
// 11111110 11000000 11000000 11000000 11000000 11000000 |
||||
// -------- -------- -------- -------- -------- -------- |
||||
// 11111100 10000000 10000000 10000000 10000000 10000000 |
||||
// This is a character of six bytes. |
||||
if ($i == $len) { |
||||
return false; |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; |
||||
} |
||||
if ($i == $len) { |
||||
return false; |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; |
||||
} |
||||
if ($i == $len) { |
||||
return false; |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; |
||||
} |
||||
if ($i == $len) { |
||||
return false; |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; |
||||
} |
||||
if ($i == $len) { |
||||
return false; |
||||
} |
||||
if (!((ord($str[$i++]) & 0xC0) == 0x80)) { |
||||
return false; |
||||
} |
||||
} else { |
||||
return false; // In any other case the character is invalid. |
||||
} |
||||
// Here the current character is valid, it |
||||
// matches to some of the cases above. |
||||
// The next character is to be examinated. |
||||
} |
||||
return true; // Empty strings are valid too. |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param type $to |
||||
* @return Utf8Decoder |
||||
*/ |
||||
public function decoder($to = null) |
||||
{ |
||||
$to = $to ? $to : Encoding::system(); |
||||
return new Utf8Decoder($to); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param type $from |
||||
* @return Utf8Encoder |
||||
*/ |
||||
public function encoder($from = null) |
||||
{ |
||||
$from = $from ? $from : Encoding::system(); |
||||
return new Utf8Encoder($from); |
||||
} |
||||
|
||||
} |
@ -1,54 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Convert from Utf8 to another encoding: |
||||
* |
||||
* - remove BOM |
||||
* - change encoding |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
*/ |
||||
class Utf8Decoder extends Converter |
||||
{ |
||||
|
||||
protected $started = false; |
||||
protected $to_encoding; |
||||
protected $encoding_converter; |
||||
|
||||
function __construct($to_encoding = null) |
||||
{ |
||||
$this->to_encoding = $to_encoding ? $to_encoding : Encoding::system(); |
||||
$this->encoding_converter = EncodingConverter::create(Utf8::NAME, $this->to_encoding); |
||||
$this->reset(); |
||||
} |
||||
|
||||
function from_encoding() |
||||
{ |
||||
return Utf8::NAME; |
||||
} |
||||
|
||||
function to_encoding() |
||||
{ |
||||
return $this->to_encoding; |
||||
} |
||||
|
||||
function reset() |
||||
{ |
||||
$this->started = false; |
||||
} |
||||
|
||||
function convert($string) |
||||
{ |
||||
if (!$this->started) { |
||||
$this->started = true; |
||||
$string = Utf8::instance()->trim($string); |
||||
return $this->encoding_converter->convert($string); |
||||
} else { |
||||
return $this->encoding_converter->convert($string); |
||||
} |
||||
return $string; |
||||
} |
||||
|
||||
} |
@ -1,72 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Encode from another encoding to UTF8: |
||||
* |
||||
* - add BOM |
||||
* - change encoding |
||||
* - convert html entities if turned on |
||||
* |
||||
* Note: |
||||
* |
||||
* Convert_html_entities cannot but turned on by default. This would be bad |
||||
* for performances but more than anything else it may be perfectly valid to write |
||||
* html entities wihtout transformation - i.e. when writing html content. |
||||
* |
||||
* It may be better to move convert_html_entities to its own converter and to chain |
||||
* converters together to achieve the same result. |
||||
* |
||||
* @copyright (c) 2012 University of Geneva |
||||
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
*/ |
||||
class Utf8Encoder extends Converter |
||||
{ |
||||
|
||||
protected $started = false; |
||||
protected $from_encoding; |
||||
protected $encoding_converter; |
||||
protected $convert_html_entities = false; |
||||
|
||||
function __construct($from_encoding = null , $convert_html_entities = false) |
||||
{ |
||||
$this->from_encoding = $from_encoding ? $from_encoding : Encoding::system(); |
||||
$this->encoding_converter = EncodingConverter::create($this->from_encoding, Utf8::NAME); |
||||
$this->convert_html_entities = $convert_html_entities; |
||||
$this->reset(); |
||||
} |
||||
|
||||
function from_encoding() |
||||
{ |
||||
return $this->from_encoding; |
||||
} |
||||
|
||||
function to_encoding() |
||||
{ |
||||
return Utf8::NAME; |
||||
} |
||||
|
||||
function get_convert_html_entities() |
||||
{ |
||||
return $this->convert_html_entities; |
||||
} |
||||
|
||||
function reset() |
||||
{ |
||||
$this->started = false; |
||||
} |
||||
|
||||
function convert($string) |
||||
{ |
||||
if ($this->convert_html_entities) { |
||||
$string = html_entity_decode($string, ENT_COMPAT, Utf8::NAME); |
||||
} |
||||
$string = $this->encoding_converter->convert($string); |
||||
if (!$this->started) { |
||||
$this->started = true; |
||||
$string = Utf8::BOM . $string; |
||||
} |
||||
return $string; |
||||
} |
||||
|
||||
} |
@ -1,302 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Provides access to the $_SERVER variable. Useful to have autocompletion working. |
||||
* Access through the Request class. |
||||
* |
||||
* Example: |
||||
* |
||||
* Request :: server()-> request_uri() |
||||
* |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class RequestServer |
||||
{ |
||||
|
||||
public static function instance() |
||||
{ |
||||
static $result = null; |
||||
if (empty($result)) { |
||||
$result = new self(); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
function get($key, $default = null) |
||||
{ |
||||
return isset($_SERVER[$key]) ? $_SERVER[$key] : null; |
||||
} |
||||
|
||||
/** |
||||
* The timestamp of the start of the request. Available since PHP 5.1.0. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function request_time() |
||||
{ |
||||
return isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : null; |
||||
} |
||||
|
||||
/** |
||||
* Contents of the Host: header from the current request, if there is one. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function http_host() |
||||
{ |
||||
return isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; |
||||
} |
||||
|
||||
/** |
||||
* Contents of the User-Agent: header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page. A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586). Among other things, you can use this value with get_browser() to tailor your page's output to the capabilities of the user agent. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function http_user_agent() |
||||
{ |
||||
return isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; |
||||
} |
||||
|
||||
/** |
||||
* Contents of the Accept: header from the current request, if there is one. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function http_accept() |
||||
{ |
||||
return isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; |
||||
} |
||||
|
||||
/** |
||||
* Contents of the Accept-Language: header from the current request, if there is one. Example: 'en'. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function http_accept_language() |
||||
{ |
||||
return isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null; |
||||
} |
||||
|
||||
/** |
||||
* Contents of the Accept-Encoding: header from the current request, if there is one. Example: 'gzip'. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function http_accept_encoding() |
||||
{ |
||||
return isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : null; |
||||
} |
||||
|
||||
/** |
||||
* Contents of the Connection: header from the current request, if there is one. Example: 'Keep-Alive'. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function http_connection() |
||||
{ |
||||
return isset($_SERVER['HTTP_CONNECTION']) ? $_SERVER['HTTP_CONNECTION'] : null; |
||||
} |
||||
|
||||
function http_cookie() |
||||
{ |
||||
return isset($_SERVER['HTTP_COOKIE']) ? $_SERVER['HTTP_COOKIE'] : null; |
||||
} |
||||
|
||||
function http_cache_control() |
||||
{ |
||||
return isset($_SERVER['HTTP_CACHE_CONTROL']) ? $_SERVER['HTTP_CACHE_CONTROL'] : null; |
||||
} |
||||
|
||||
function path() |
||||
{ |
||||
return isset($_SERVER['PATH']) ? $_SERVER['PATH'] : null; |
||||
} |
||||
|
||||
function systemroot() |
||||
{ |
||||
return isset($_SERVER['SystemRoot']) ? $_SERVER['SystemRoot'] : null; |
||||
} |
||||
|
||||
function comspec() |
||||
{ |
||||
return isset($_SERVER['COMSPEC']) ? $_SERVER['COMSPEC'] : null; |
||||
} |
||||
|
||||
function pathext() |
||||
{ |
||||
return isset($_SERVER['PATHEXT']) ? $_SERVER['PATHEXT'] : null; |
||||
} |
||||
|
||||
function windir() |
||||
{ |
||||
return isset($_SERVER['WINDIR']) ? $_SERVER['WINDIR'] : null; |
||||
} |
||||
|
||||
function server_signature() |
||||
{ |
||||
return isset($_SERVER['SERVER_SIGNATURE']) ? $_SERVER['SERVER_SIGNATURE'] : null; |
||||
} |
||||
|
||||
/** |
||||
* Server identification string, given in the headers when responding to requests. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function server_software() |
||||
{ |
||||
return isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null; |
||||
} |
||||
|
||||
/** |
||||
* The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function server_name() |
||||
{ |
||||
return isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null; |
||||
} |
||||
|
||||
/** |
||||
* The IP address of the server under which the current script is executing. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function server_addr() |
||||
{ |
||||
return isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : null; |
||||
} |
||||
|
||||
function server_port() |
||||
{ |
||||
return isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : null; |
||||
} |
||||
|
||||
/** |
||||
* The IP address from which the user is viewing the current page. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function remote_addr() |
||||
{ |
||||
return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; |
||||
} |
||||
|
||||
/** |
||||
* The document root directory under which the current script is executing, as defined in the server's configuration file. |
||||
* @return string |
||||
*/ |
||||
function document_root() |
||||
{ |
||||
return isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : null; |
||||
} |
||||
|
||||
/** |
||||
* The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file. If the script is running on a virtual host, this will be the value defined for that virtual host. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function server_admin() |
||||
{ |
||||
return isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN'] : null; |
||||
} |
||||
|
||||
/** |
||||
* The absolute pathname of the currently executing script. |
||||
* |
||||
* Note: |
||||
* |
||||
* If a script is executed with the CLI, as a relative path, such as file.php or ../file.php, $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function script_filename() |
||||
{ |
||||
return isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : null; |
||||
} |
||||
|
||||
/** |
||||
* The port being used on the user's machine to communicate with the web server. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function remote_port() |
||||
{ |
||||
return isset($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : null; |
||||
} |
||||
|
||||
/** |
||||
* What revision of the CGI specification the server is using; i.e. 'CGI/1.1'. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function gateway_interface() |
||||
{ |
||||
return isset($_SERVER['GATEWAY_INTERFACE']) ? $_SERVER['GATEWAY_INTERFACE'] : null; |
||||
} |
||||
|
||||
/** |
||||
* Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0'; |
||||
* |
||||
* @return string |
||||
*/ |
||||
function server_protocol() |
||||
{ |
||||
return isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : null; |
||||
} |
||||
|
||||
/** |
||||
* Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'. |
||||
* |
||||
* Note: |
||||
* PHP script is terminated after sending headers (it means after producing any output without output buffering) if the request method was HEAD. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function request_method() |
||||
{ |
||||
return isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : null; |
||||
} |
||||
|
||||
/** |
||||
* The query string, if any, via which the page was accessed. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function query_string() |
||||
{ |
||||
return isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null; |
||||
} |
||||
|
||||
/** |
||||
* The URI which was given in order to access this page; for instance, '/index.html'. |
||||
* @return string |
||||
*/ |
||||
function request_uri() |
||||
{ |
||||
return isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null; |
||||
} |
||||
|
||||
/** |
||||
* Contains the current script's path. This is useful for pages which need to point to themselves. The __FILE__ constant contains the full path and filename of the current (i.e. included) file. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function script_name() |
||||
{ |
||||
return isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : null; |
||||
} |
||||
|
||||
/** |
||||
* The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The __FILE__ constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available. |
||||
* |
||||
* @return string |
||||
*/ |
||||
function php_self() |
||||
{ |
||||
return isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : null; |
||||
} |
||||
|
||||
} |
File diff suppressed because it is too large
Load Diff
@ -1,138 +0,0 @@ |
||||
<?php |
||||
|
||||
/* |
||||
* $Id$ |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
* This software consists of voluntary contributions made by many individuals |
||||
* and is licensed under the LGPL. For more information, see |
||||
* <http://www.doctrine-project.org>. |
||||
*/ |
||||
|
||||
namespace Tools; |
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo, |
||||
Doctrine\ORM\Mapping\AssociationMapping, |
||||
Doctrine\Common\Util\Inflector; |
||||
|
||||
/** |
||||
* Class to generate entity repository classes |
||||
* |
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL |
||||
* @link www.doctrine-project.org |
||||
* @since 2.0 |
||||
* @version $Revision$ |
||||
* @author Benjamin Eberlei <kontakt@beberlei.de> |
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> |
||||
* @author Jonathan Wage <jonwage@gmail.com> |
||||
* @author Roman Borschel <roman@code-factory.org> |
||||
*/ |
||||
class EntityRepositoryGenerator |
||||
{ |
||||
|
||||
protected static $_template = |
||||
'<?php |
||||
|
||||
namespace Entity\Repository; |
||||
use \db; |
||||
|
||||
/** |
||||
* |
||||
* @license see /license.txt |
||||
* @author autogenerated |
||||
*/ |
||||
class <className> extends <extends> |
||||
{ |
||||
|
||||
/** |
||||
* @return \Entity\Repository\<className> |
||||
*/ |
||||
public static function instance(){ |
||||
static $result = false; |
||||
if($result === false){ |
||||
$result = db::instance()->get_repository(\'\\Entity\\<entityName>\'); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param EntityManager $em The EntityManager to use. |
||||
* @param ClassMetadata $class The class descriptor. |
||||
*/ |
||||
public function __construct($em, $class){ |
||||
parent::__construct($em, $class); |
||||
} |
||||
|
||||
}'; |
||||
|
||||
public function generateEntityRepositoryClass($name) |
||||
{ |
||||
$name = Inflector::tableize($name); |
||||
$is_course_table = (strpos($name, 'c_') === 0); |
||||
if ($is_course_table) { |
||||
$name = substr($name, 2, strlen($name) - 2); |
||||
} |
||||
$name = Inflector::classify($name); |
||||
$className = $name; |
||||
//$namespace = substr($fullClassName, 0, strrpos($fullClassName, '\\')); |
||||
//$className = substr($fullClassName, strrpos($fullClassName, '\\') + 1, strlen($fullClassName)); |
||||
|
||||
$is_course_table = $metadata->is_course_table; |
||||
|
||||
|
||||
$variables = array( |
||||
'<namespace>' => $namespace, |
||||
'<className>' => $className, |
||||
'<entityName>' => str_replace('Repository', '', $className), |
||||
'<extends>' => $is_course_table ? '\CourseEntityRepository' : '\EntityRepository' |
||||
); |
||||
return str_replace(array_keys($variables), array_values($variables), self::$_template); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param type $name |
||||
* @param type $outputDirectory |
||||
*/ |
||||
public function writeEntityRepositoryClass($name, $outputDirectory) |
||||
{ |
||||
$name = explode('\\', $name); |
||||
$name = end($name); |
||||
$name = Inflector::tableize($name); |
||||
$is_course_table = (strpos($name, 'c_') === 0); |
||||
if ($is_course_table) { |
||||
$name = substr($name, 2, strlen($name) - 2); |
||||
} |
||||
$name = Inflector::classify($name) . 'Repository'; |
||||
$fullClassName = $name; |
||||
|
||||
$file_name = Inflector::tableize($name); |
||||
|
||||
$code = $this->generateEntityRepositoryClass($fullClassName); |
||||
|
||||
$path = $outputDirectory . DIRECTORY_SEPARATOR |
||||
. str_replace('\\', \DIRECTORY_SEPARATOR, $file_name) . '.class.php'; |
||||
$dir = dirname($path); |
||||
|
||||
if (!is_dir($dir)) { |
||||
mkdir($dir, 0777, true); |
||||
} |
||||
|
||||
if (!file_exists($path)) { |
||||
file_put_contents($path, $code); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,214 +0,0 @@ |
||||
<?php |
||||
|
||||
/* |
||||
* $Id$ |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
* This software consists of voluntary contributions made by many individuals |
||||
* and is licensed under the LGPL. For more information, see |
||||
* <http://www.doctrine-project.org>. |
||||
*/ |
||||
|
||||
namespace Tools; |
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo; |
||||
use Doctrine\ORM\Tools\Export\Driver\AbstractExporter; |
||||
|
||||
/** |
||||
* ClassMetadata exporter for Doctrine YAML mapping files |
||||
* |
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL |
||||
* @link www.doctrine-project.org |
||||
* @since 2.0 |
||||
* @version $Revision$ |
||||
* @author Jonathan Wage <jonwage@gmail.com> |
||||
*/ |
||||
class YamlExporter extends AbstractExporter |
||||
{ |
||||
protected $_extension = '.dcm.yml'; |
||||
|
||||
/** |
||||
* Converts a single ClassMetadata instance to the exported format |
||||
* and returns it |
||||
* |
||||
* TODO: Should this code be pulled out in to a toArray() method in ClassMetadata |
||||
* |
||||
* @param ClassMetadataInfo $metadata |
||||
* @return mixed $exported |
||||
*/ |
||||
public function exportClassMetadata(ClassMetadataInfo $metadata) |
||||
{ |
||||
$array = array(); |
||||
|
||||
if ($metadata->isMappedSuperclass) { |
||||
$array['type'] = 'mappedSuperclass'; |
||||
} else { |
||||
$array['type'] = 'entity'; |
||||
} |
||||
|
||||
$array['table'] = $metadata->table['name']; |
||||
|
||||
if (isset($metadata->table['schema'])) { |
||||
$array['schema'] = $metadata->table['schema']; |
||||
} |
||||
|
||||
$inheritanceType = $metadata->inheritanceType; |
||||
if ($inheritanceType !== ClassMetadataInfo::INHERITANCE_TYPE_NONE) { |
||||
$array['inheritanceType'] = $this->_getInheritanceTypeString($inheritanceType); |
||||
} |
||||
|
||||
if ($column = $metadata->discriminatorColumn) { |
||||
$array['discriminatorColumn'] = $column; |
||||
} |
||||
|
||||
if ($map = $metadata->discriminatorMap) { |
||||
$array['discriminatorMap'] = $map; |
||||
} |
||||
|
||||
if ($metadata->changeTrackingPolicy !== ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT) { |
||||
$array['changeTrackingPolicy'] = $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy); |
||||
} |
||||
|
||||
if (isset($metadata->table['indexes'])) { |
||||
$array['indexes'] = $metadata->table['indexes']; |
||||
} |
||||
|
||||
if ($metadata->customRepositoryClassName) { |
||||
$array['repositoryClass'] = $metadata->customRepositoryClassName; |
||||
} |
||||
|
||||
if (isset($metadata->table['uniqueConstraints'])) { |
||||
$array['uniqueConstraints'] = $metadata->table['uniqueConstraints']; |
||||
} |
||||
|
||||
$fieldMappings = $metadata->fieldMappings; |
||||
|
||||
$ids = array(); |
||||
foreach ($fieldMappings as $name => $fieldMapping) { |
||||
$fieldMapping['column'] = $fieldMapping['columnName']; |
||||
unset( |
||||
$fieldMapping['columnName'], |
||||
$fieldMapping['fieldName'] |
||||
); |
||||
|
||||
if ($fieldMapping['column'] == $name) { |
||||
unset($fieldMapping['column']); |
||||
} |
||||
|
||||
if (isset($fieldMapping['id']) && $fieldMapping['id']) { |
||||
$ids[$name] = $fieldMapping; |
||||
unset($fieldMappings[$name]); |
||||
continue; |
||||
} |
||||
|
||||
$fieldMappings[$name] = $fieldMapping; |
||||
} |
||||
|
||||
if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) { |
||||
$ids[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $this->_getIdGeneratorTypeString($metadata->generatorType); |
||||
}else{ |
||||
if(count($metadata->identifier) == 2){ |
||||
foreach($metadata->identifier as $identifier){ |
||||
if($identifier != 'c_id'){ |
||||
$ids[$identifier]['generator']['strategy'] = 'IDENTITY'; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
if ($ids) { |
||||
$array['fields'] = $ids; |
||||
} |
||||
|
||||
if ($fieldMappings) { |
||||
if ( ! isset($array['fields'])) { |
||||
$array['fields'] = array(); |
||||
} |
||||
$array['fields'] = array_merge($array['fields'], $fieldMappings); |
||||
} |
||||
|
||||
$associations = array(); |
||||
foreach ($metadata->associationMappings as $name => $associationMapping) { |
||||
$cascade = array(); |
||||
if ($associationMapping['isCascadeRemove']) { |
||||
$cascade[] = 'remove'; |
||||
} |
||||
if ($associationMapping['isCascadePersist']) { |
||||
$cascade[] = 'persist'; |
||||
} |
||||
if ($associationMapping['isCascadeRefresh']) { |
||||
$cascade[] = 'refresh'; |
||||
} |
||||
if ($associationMapping['isCascadeMerge']) { |
||||
$cascade[] = 'merge'; |
||||
} |
||||
if ($associationMapping['isCascadeDetach']) { |
||||
$cascade[] = 'detach'; |
||||
} |
||||
if (count($cascade) === 5) { |
||||
$cascade = array('all'); |
||||
} |
||||
$associationMappingArray = array( |
||||
'targetEntity' => $associationMapping['targetEntity'], |
||||
'cascade' => $cascade, |
||||
); |
||||
|
||||
if ($associationMapping['type'] & ClassMetadataInfo::TO_ONE) { |
||||
$joinColumns = $associationMapping['joinColumns']; |
||||
$newJoinColumns = array(); |
||||
foreach ($joinColumns as $joinColumn) { |
||||
$newJoinColumns[$joinColumn['name']]['referencedColumnName'] = $joinColumn['referencedColumnName']; |
||||
if (isset($joinColumn['onDelete'])) { |
||||
$newJoinColumns[$joinColumn['name']]['onDelete'] = $joinColumn['onDelete']; |
||||
} |
||||
} |
||||
$oneToOneMappingArray = array( |
||||
'mappedBy' => $associationMapping['mappedBy'], |
||||
'inversedBy' => $associationMapping['inversedBy'], |
||||
'joinColumns' => $newJoinColumns, |
||||
'orphanRemoval' => $associationMapping['orphanRemoval'], |
||||
); |
||||
|
||||
$associationMappingArray = array_merge($associationMappingArray, $oneToOneMappingArray); |
||||
$array['oneToOne'][$name] = $associationMappingArray; |
||||
} else if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) { |
||||
$oneToManyMappingArray = array( |
||||
'mappedBy' => $associationMapping['mappedBy'], |
||||
'inversedBy' => $associationMapping['inversedBy'], |
||||
'orphanRemoval' => $associationMapping['orphanRemoval'], |
||||
'orderBy' => isset($associationMapping['orderBy']) ? $associationMapping['orderBy'] : null |
||||
); |
||||
|
||||
$associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray); |
||||
$array['oneToMany'][$name] = $associationMappingArray; |
||||
} else if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_MANY) { |
||||
$manyToManyMappingArray = array( |
||||
'mappedBy' => $associationMapping['mappedBy'], |
||||
'inversedBy' => $associationMapping['inversedBy'], |
||||
'joinTable' => isset($associationMapping['joinTable']) ? $associationMapping['joinTable'] : null, |
||||
'orderBy' => isset($associationMapping['orderBy']) ? $associationMapping['orderBy'] : null |
||||
); |
||||
|
||||
$associationMappingArray = array_merge($associationMappingArray, $manyToManyMappingArray); |
||||
$array['manyToMany'][$name] = $associationMappingArray; |
||||
} |
||||
} |
||||
if (isset($metadata->lifecycleCallbacks)) { |
||||
$array['lifecycleCallbacks'] = $metadata->lifecycleCallbacks; |
||||
} |
||||
|
||||
return \Symfony\Component\Yaml\Yaml::dump(array($metadata->name => $array), 10); |
||||
} |
||||
} |
@ -1,104 +0,0 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Utility functions to manage uris/urls. |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class Uri |
||||
{ |
||||
|
||||
public static function chamilo() |
||||
{ |
||||
return 'http://chamilo.org/'; |
||||
} |
||||
|
||||
/** |
||||
* Application web root |
||||
*/ |
||||
public static function www() |
||||
{ |
||||
static $result = false; |
||||
if (empty($result)) { |
||||
$result = api_get_path(WEB_PATH); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
public static function here($params = array(), $html = true) |
||||
{ |
||||
$protocol = Request::server()->server_protocol(); |
||||
$protocol = stripos($protocol, 'https') !== false ? 'https' : 'http'; |
||||
|
||||
$host = Request::server()->server_name(); |
||||
$host = $host ? $host : Request::server()->server_addr(); |
||||
|
||||
$here = Request::server()->request_uri(); |
||||
$here = explode('?', $here); |
||||
$here = reset($here); |
||||
$here = $protocol . '://' . $host . $here; |
||||
return self::url($here, $params, $html); |
||||
} |
||||
|
||||
/** |
||||
* Returns a full url from local/absolute path and parameters. |
||||
* Append the root as required for relative urls. |
||||
* |
||||
* @param string $path |
||||
* @param array $params |
||||
* @return string |
||||
*/ |
||||
public static function url($path = '', $params = array(), $html = true) |
||||
{ |
||||
$result = $path; |
||||
if (strpos($result, 'http') !== 0) |
||||
{ |
||||
$result = ltrim($result, '/'); |
||||
$result = self::www() . $result; |
||||
} |
||||
if ($params) |
||||
{ |
||||
|
||||
$result = rtrim($result, '?'); |
||||
$result = $result . '?' . self::params($params, $html); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* Format url parameters |
||||
* |
||||
* @param array $params |
||||
* @return string |
||||
*/ |
||||
public static function params($params = array(), $html = true) |
||||
{ |
||||
$result = array(); |
||||
foreach ($params as $key => $value) |
||||
{ |
||||
$result[] = $key . '=' . urlencode($value); |
||||
} |
||||
$result = implode($html ? '&' : '&', $result); |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* Returns the course parameters. If null default to the current user parameters. |
||||
* |
||||
* @param string $course_code |
||||
* @param string|int $session_id |
||||
* @param string|int $group_id |
||||
* @return type |
||||
*/ |
||||
public static function course_params($course_code = null, $session_id = null, $group_id = null) |
||||
{ |
||||
$course_code = is_null($course_code) ? api_get_course_id() : $course_code; |
||||
$session_id = is_null($session_id) ? api_get_session_id() : $session_id; |
||||
$session_id = $session_id ? $session_id : '0'; |
||||
$group_id = is_null($group_id) ? '' : $group_id; |
||||
$group_id = $group_id ? $group_id : '0'; |
||||
return array('cidReq' => $course_code, 'id_session' => $session_id, 'gidReq' => $group_id); |
||||
} |
||||
|
||||
} |
@ -1,131 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* Wrapper around pclzip. Makes a bit easier to use compression. |
||||
* |
||||
* Usage: |
||||
* |
||||
* $zip = Zip::create('...'); |
||||
* $zip->add($file_path, $local_path); |
||||
* |
||||
* Note |
||||
* |
||||
* Pclzip do not accept method callbacks. It only accepts pure function callbacks. |
||||
* As a result the implementation is a bit more complicated than it should be. |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
/** |
||||
* Zip wrapper class |
||||
*/ |
||||
class Zip |
||||
{ |
||||
|
||||
protected static $pool = array(); |
||||
|
||||
public static function pool($hash = '') |
||||
{ |
||||
if (empty($hash)) { |
||||
return self::$pool; |
||||
} else { |
||||
return self::$pool[$hash]; |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* |
||||
* @param string $path |
||||
* @return Zip |
||||
*/ |
||||
public static function create($path) |
||||
{ |
||||
return new self($path); |
||||
} |
||||
|
||||
protected $path = ''; |
||||
protected $archive = null; |
||||
protected $entries = array(); |
||||
|
||||
public function __construct($path = '') |
||||
{ |
||||
$this->path = $path; |
||||
self::$pool[$this->get_hash()] = $this; |
||||
} |
||||
|
||||
public function get_path() |
||||
{ |
||||
return $this->path; |
||||
} |
||||
|
||||
public function get_hash() |
||||
{ |
||||
return md5($this->path); |
||||
} |
||||
|
||||
public function add($file_path, $archive_path = '', $comment = '') |
||||
{ |
||||
/** |
||||
* Remove c: when working on windows. |
||||
*/ |
||||
if (substr($file_path, 1, 1) == ':') { |
||||
$file_path = substr($file_path, 2); |
||||
} |
||||
|
||||
$entry = array( |
||||
'file_path' => $file_path, |
||||
'archive_path' => $archive_path, |
||||
'comment' => $comment |
||||
); |
||||
$this->entries[$file_path] = $entry; |
||||
|
||||
$callback_name = 'zipcallback_' . $this->get_hash(); |
||||
if (!function_exists($callback_name)) { |
||||
$callback = ''; |
||||
$callback .= 'function ' . $callback_name . '($event, &$header){'; |
||||
$callback .= '$parts = explode(\'_\', __FUNCTION__);'; |
||||
$callback .= '$hash = end($parts);'; |
||||
$callback .= 'return Zip::pool($hash)->callback($event, $header);'; |
||||
$callback .= '};'; |
||||
eval($callback); |
||||
} |
||||
|
||||
$archive = $this->archive(); |
||||
$archive->add($file_path, PCLZIP_CB_PRE_ADD, $callback_name); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return PclZip |
||||
*/ |
||||
protected function archive() |
||||
{ |
||||
if ($this->archive) { |
||||
return $this->archive; |
||||
} |
||||
if (empty($this->path)) { |
||||
return null; |
||||
} |
||||
return $this->archive = new PclZip($this->path); |
||||
} |
||||
|
||||
public function callback($event, &$header) |
||||
{ |
||||
if ($event != PCLZIP_CB_PRE_ADD) { |
||||
return 0; |
||||
} |
||||
|
||||
$path = $header['filename']; |
||||
if (!isset($this->entries[$path])) { |
||||
return 1; |
||||
} |
||||
|
||||
$entry = $this->entries[$path]; |
||||
$archive_path = $entry['archive_path']; |
||||
if (!empty($archive_path)) { |
||||
$header['stored_filename'] = $archive_path; |
||||
} |
||||
return 1; |
||||
} |
||||
|
||||
} |
@ -1,100 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* Generated by PHPUnit_SkeletonGenerator on 2012-10-01 at 14:44:10. |
||||
*/ |
||||
class UriTest extends PHPUnit_Framework_TestCase |
||||
{ |
||||
/** |
||||
* @var Uri |
||||
*/ |
||||
protected $object; |
||||
|
||||
/** |
||||
* Sets up the fixture, for example, opens a network connection. |
||||
* This method is called before a test is executed. |
||||
*/ |
||||
protected function setUp() |
||||
{ |
||||
$this->object = new Uri; |
||||
} |
||||
|
||||
/** |
||||
* Tears down the fixture, for example, closes a network connection. |
||||
* This method is called after a test is executed. |
||||
*/ |
||||
protected function tearDown() |
||||
{ |
||||
} |
||||
|
||||
/** |
||||
* @covers Uri::chamilo |
||||
* @todo Implement testChamilo(). |
||||
*/ |
||||
public function testChamilo() |
||||
{ |
||||
// Remove the following lines when you implement this test. |
||||
$this->markTestIncomplete( |
||||
'This test has not been implemented yet.' |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers Uri::www |
||||
* @todo Implement testWww(). |
||||
*/ |
||||
public function testWww() |
||||
{ |
||||
// Remove the following lines when you implement this test. |
||||
$this->markTestIncomplete( |
||||
'This test has not been implemented yet.' |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers Uri::here |
||||
* @todo Implement testHere(). |
||||
*/ |
||||
public function testHere() |
||||
{ |
||||
// Remove the following lines when you implement this test. |
||||
$this->markTestIncomplete( |
||||
'This test has not been implemented yet.' |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers Uri::url |
||||
* @todo Implement testUrl(). |
||||
*/ |
||||
public function testUrl() |
||||
{ |
||||
// Remove the following lines when you implement this test. |
||||
$this->markTestIncomplete( |
||||
'This test has not been implemented yet.' |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers Uri::params |
||||
* @todo Implement testParams(). |
||||
*/ |
||||
public function testParams() |
||||
{ |
||||
// Remove the following lines when you implement this test. |
||||
$this->markTestIncomplete( |
||||
'This test has not been implemented yet.' |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers Uri::course_params |
||||
* @todo Implement testCourse_params(). |
||||
*/ |
||||
public function testCourse_params() |
||||
{ |
||||
// Remove the following lines when you implement this test. |
||||
$this->markTestIncomplete( |
||||
'This test has not been implemented yet.' |
||||
); |
||||
} |
||||
} |
Loading…
Reference in new issue