17 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
36 private $_attribute_mapping = Array(
37 'getAssetTypes' =>
'get_asset_types',
38 'trashAsset' =>
'trash_asset',
39 'getChildCount' =>
'get_general',
40 'updateMultipleLinks' =>
'update_link',
41 'removeMultipleLinks' =>
'remove_link',
42 'importAssetsFromXML' =>
'import_assets',
43 'getRoles' =>
'get_roles',
44 'executeHTMLTidy' =>
'execute_html_tidy',
45 'getGeneral' =>
'get_general',
46 'getAttributes' =>
'get_attributes',
47 'setMultipleAttributes' =>
'set_attribute',
48 'setAttribute' =>
'set_attribute',
49 'getMetadata' =>
'get_metadata',
50 'setMetadataAllFields' =>
'set_metadata',
51 'setMetadata' =>
'set_metadata',
52 'getChildren' =>
'get_children',
53 'getParents' =>
'get_parents',
54 'getPermissions' =>
'get_permissions',
55 'createAsset' =>
'create_asset',
56 'getLocksInfo' =>
'get_locks_info',
57 'acquireLock' =>
'acquire_lock',
58 'releaseLock' =>
'release_lock',
59 'createLink' =>
'create_link',
60 'removeLink' =>
'remove_link',
61 'moveLink' =>
'move_link',
62 'updateLink' =>
'update_link',
63 'getLinkId' =>
'get_link_id',
64 'getAssetTree' =>
'get_asset_tree',
65 'getKeywordsReplacements' =>
'get_keywords_replacements',
66 'setAssetStatus' =>
'set_asset_status',
67 'getWebPath' =>
'get_web_path',
68 'setWebPath' =>
'set_web_path',
69 'getWorkflowSchema' =>
'get_workflow_schema',
70 'createFileAsset' =>
'create_asset',
71 'setContentOfEditableFileAsset' =>
'set_file_content',
72 'getLineage' =>
'get_lineage',
73 'getLineageFromUrl' =>
'get_lineage_from_url',
74 'getUrlFromLineage' =>
'get_url_from_lineage',
75 'batchRequest' =>
'batch_requests',
76 'cloneAsset' =>
'clone_asset',
77 'showDifference' =>
'show_diff',
78 'setContext' =>
'set_context',
79 'restoreContext' =>
'set_context',
80 'getAlternateContext' =>
'get_context',
81 'getCurrentContext' =>
'get_context',
82 'getAllContexts' =>
'get_context',
83 'getMetadataSchema' =>
'get_metadata_schema',
90 private $_permission_mapping = Array(
91 'getGeneral' => Array(
'read_access'),
92 'getAttributes' => Array(
'read_access'),
93 'getMetadata' => Array(
'read_access'),
94 'getChildren' => Array(
'read_access'),
95 'getParents' => Array(
'read_access'),
96 'getPermissions' => Array(
'read_access'),
97 'getLocksInfo' => Array(
'read_access'),
98 'getLinkId' => Array(
'read_access'),
99 'getAssetTree' => Array(
'read_access'),
100 'getKeywordsReplacements' => Array(
'read_access'),
101 'getWebPath' => Array(
'read_access'),
102 'getWorkflowSchema' => Array(
'read_access'),
103 'showDifference' => Array(
'read_access'),
104 'setMultipleAttributes' => Array(
'write_access'),
105 'setAttribute' => Array(
'write_access'),
106 'setMetadataAllFields' => Array(
'write_access'),
107 'setMetadata' => Array(
'write_access'),
108 'createAsset' => Array(
'write_access',
'ignore_perm'),
109 'cloneAsset' => Array(
'write_access',
'ignore_perm'),
110 'createFileAsset' => Array(
'write_access',
'ignore_perm'),
111 'acquireLock' => Array(
'write_access'),
112 'releaseLock' => Array(
'write_access'),
113 'createLink' => Array(
'write_access'),
114 'removeLink' => Array(
'write_access'),
115 'moveLink' => Array(
'write_access'),
116 'updateLink' => Array(
'write_access'),
117 'setAssetStatus' => Array(
'write_access'),
118 'setWebPath' => Array(
'write_access'),
119 'setContentOfEditableFileAsset' => Array(
'write_access'),
120 'getMetadataSchema' => Array(
'write_access'),
121 'getAssetTypes' => Array(
'no_check'),
122 'trashAsset' => Array(
'no_check'),
123 'getChildCount' => Array(
'no_check'),
124 'updateMultipleLinks' => Array(
'no_check'),
125 'removeMultipleLinks' => Array(
'no_check'),
126 'importAssetsFromXML' => Array(
'no_check'),
127 'getRoles' => Array(
'no_check'),
128 'executeHTMLTidy' => Array(
'no_check'),
129 'getLineage' => Array(
'no_check'),
130 'getLineageFromUrl' => Array(
'no_check'),
131 'getUrlFromLineage' => Array(
'no_check'),
132 'batchRequest' => Array(
'no_check'),
133 'getAlternateContext' => Array(
'no_check'),
134 'getCurrentContext' => Array(
'no_check'),
135 'getAllContexts' => Array(
'no_check'),
136 'setContext' => Array(
'no_check'),
137 'restoreContext' => Array(
'no_check'),
149 $this->_ser_attrs = TRUE;
150 parent::__construct($assetid);
167 if (!parent::_createAdditional($link))
return FALSE;
170 $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($this->
id,
'attributes');
171 $key = rand(1000000000, 9999999999);
174 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($this->
id,
'attributes');
190 $links = parent::_getAllowedLinks();
191 $links[SQ_LINK_NOTICE] = Array(
'asset' => Array(
'card' =>
'M',
'exclusive' => FALSE));
207 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_asset', $this->name));
212 if (!isset($_REQUEST[
'key']) && !isset($_REQUEST[
'id']) && !isset($_REQUEST[
'type'])) {
213 header(
'Content-Type: text/javascript');
214 header(
'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
215 if ($this->
attr(
'use_enhanced_js')) {
216 require_once
'js_api_enhanced_function_list.inc';
219 require_once
'js_api_standard_function_list.inc';
226 require_once dirname(__FILE__).
'/js_api_error_handler.inc';
227 $old_error_handler = set_error_handler(
'js_api_error_handler');
230 $api_key = array_get_index($_REQUEST,
'key',
'');
231 $id = array_get_index($_REQUEST,
'id',
'');
233 if (empty($id)) $id = array_get_index($_REQUEST,
'assetid',
'');
234 $function_type = array_get_index($_REQUEST,
'type',
'');
237 $nonce_token = get_unique_token();
238 if (!isset($_POST[
'nonce_token']) || ($_POST[
'nonce_token'] !== $nonce_token)) {
240 restore_error_handler();
245 if (empty($function_type)) {
246 $this->
returnError(
'You must set a function type');
247 restore_error_handler();
251 if ($this->
attr(
'sync_context') && isset($_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_BACKEND_ALTERNATE_CONTEXT_ID'])) {
252 $current_contextid = $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_BACKEND_ALTERNATE_CONTEXT_ID'];
253 if (!isset($_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID']) ||
254 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID'] != $current_contextid) {
255 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID'] = $current_contextid;
256 $GLOBALS[
'SQ_SYSTEM']->changeContext($current_contextid);
260 if ($function_type ==
'batchRequest') {
262 if (!$this->_attribute_mapping[$function_type]) {
263 $this->
returnError(
'The '.$type.
' function must be activated');
264 restore_error_handler();
267 if (!function_exists(
'json_decode')) {
268 require_once
'Services/JSON.php';
269 $json =
new Services_JSON();
270 $functions_info = Array();
271 $request_data = $json->decode($_REQUEST[
'functions']);
274 $functions_info = json_decode($_REQUEST[
'functions'], TRUE);
277 foreach ($functions_info as $index => $info) {
278 $function_calls[$index] = $info[
'function'];
280 $batching_request = TRUE;
282 $function_calls = Array($function_type);
283 $batching_request = FALSE;
287 $check_key = $this->
attr(
'api_key');
290 if (!isset($check_key) || $check_key ==
'' || $api_key ==
'') {
291 $this->
returnError(
'You must enter an API key in order to use this asset');
292 restore_error_handler();
297 if ($check_key != $api_key) {
298 $this->
returnError(
'The API key does not match, please enter a valid key');
299 restore_error_handler();
305 $_REQUEST[
'force_simple_edit'] = $this->
attr(
'force_simple_edit');
306 $temp_server_vars = $_SERVER[
'PHP_SELF'];
308 if (isset($_SERVER[
'HTTP_REFERER']) && !empty($_SERVER[
'HTTP_REFERER'])) {
309 $referer_url = str_replace(current_protocol().
'://',
'', $_SERVER[
'HTTP_REFERER']);
311 $suffix_to_check = Array(
312 SQ_CONF_BACKEND_SUFFIX,
313 SQ_CONF_LIMBO_SUFFIX,
314 SQ_CONF_NOCACHE_SUFFIX,
315 SQ_CONF_RECACHE_SUFFIX,
316 SQ_CONF_PERFORMANCE_SUFFIX
320 foreach ($suffix_to_check as $suffix) {
321 if (strpos($_SERVER[
'HTTP_REFERER'], $suffix) !== FALSE) {
322 $referer_url = preg_replace(
'|/'.$suffix.
'(.)*|',
'', $referer_url);
326 $url_asset_object = $GLOBALS[
'SQ_SYSTEM']->am->getAssetFromURL(current_protocol(), $referer_url, TRUE, TRUE);
327 if (!is_null($url_asset_object) ) {
328 $_SERVER[
'PHP_SELF'] = str_replace(current_protocol().
'://'.$_SERVER[
'HTTP_HOST'],
'', $_SERVER[
'HTTP_REFERER']);
331 if (strpos($_SERVER[
'HTTP_REFERER'], SQ_CONF_LIMBO_SUFFIX) !== FALSE || $this->
attr(
'force_simple_edit')) {
332 $_SERVER[
'PHP_SELF'] = preg_replace(
'|/'.SQ_CONF_LIMBO_SUFFIX.
'(.)*|',
'', $_SERVER[
'PHP_SELF']);
333 $_SERVER[
'PHP_SELF'] = preg_replace(
'|/'.SQ_CONF_BACKEND_SUFFIX.
'(.)*|',
'', $_SERVER[
'PHP_SELF']);
334 $_SERVER[
'PHP_SELF'] = $_SERVER[
'PHP_SELF'].
'/';
335 $_REQUEST[
'force_simple_edit'] = TRUE;
345 $replace_these = Array (
'%26' ,
'%23' ,
'%3F' ,
'%2B');
346 $replace_with = Array (
'&' ,
'#' ,
'?' ,
'+');
348 foreach ($function_calls as $type) {
351 if ($batching_request) {
352 $args = $functions_info[$track_func][
'args'];
353 $blocking = (isset($functions_info[$track_func][
'blocking']) && $functions_info[$track_func][
'blocking']) ? TRUE : FALSE;
358 if (!isset($args[
'id'])) {
359 if (isset($args[
'asset_id'])) {
360 $args[
'id'] = $args[
'asset_id'];
361 }
else if (isset($args[
'child_id'])) {
362 $args[
'id'] = $args[
'child_id'];
363 }
else if (isset($args[
'parentID'])) {
364 $args[
'id'] = $args[
'parentID'];
365 }
else if (isset($args[
'parent_id'])) {
366 $args[
'id'] = $args[
'parent_id'];
376 if ($track_func === 0 || strpos($args[
'id'],
'%results_') === FALSE) {
381 $keyword = $args[
'id'];
382 $instructions = explode(
'_', trim($keyword,
'%'));
385 $string_to_eval =
'';
386 if (count($instructions) >= 3) {
387 for ($i = 1; $i < count($instructions); $i++) {
388 $string_to_eval .=
'[$'.
"instructions[$i]]";
390 eval(
'$id = $results'.$string_to_eval.
';');
399 foreach ($args as $index => $arg) {
400 $args[$index] = str_replace($replace_these, $replace_with, $args[$index]);
404 if ($this->
attr($this->_attribute_mapping[$type])) {
406 if ($this->_permission_mapping[$type] != Array(
'no_check')) {
408 if ((preg_match(
'/^[0-9]*:/i', $id) != FALSE) && !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($id)) {
409 $results[$track_func][
'error'] =
'Assetid supplied doesnt exist on the system';
417 $this->
returnError(
'You do not have permissions to access this asset');
418 restore_error_handler();
422 if ($this->_permission_mapping[$type] == Array(
'read_access')) {
423 $ra = $asset->readAccess();
427 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
428 $running_wfs = $wfm->getSchemas($asset->id, TRUE, TRUE);
429 if(!empty($running_wfs)) {
430 $wa = $asset->writeAccess();
432 $wa = $asset->writeAccess(
'', Array(), FALSE);
438 $func_name =
'_'.$type;
440 $results[$track_func] = $this->$func_name($args, $asset, $ra, $wa);
441 }
catch (Exception $e) {
443 $results[$track_func][
'error'] =
'Exception occured when executing JS API function "'.$type.
'()": '.$e->getMessage();
448 if (isset($results[$track_func][
'error']) && $blocking) {
449 $results[
'error'] =
'Function '.$type.
' set to blocking returned error';
454 $this->
returnError(
'The '.$type.
' function must be activated');
455 restore_error_handler();
463 if ($function_type ==
'batchRequest') {
466 $data = $results[$track_func - 1];
476 $_SERVER[
'PHP_SELF'] = $temp_server_vars;
479 restore_error_handler();
495 $am = $GLOBALS[
'SQ_SYSTEM']->am;
499 $this->
returnError(
'You must enter a valid asset id or URL');
504 if (is_numeric($id) || (preg_match(
'/^[0-9]*:/i', $id) != 0)) {
508 $valid_assetid = $am->assetExists($id);
509 }
catch (Exception $e) {
510 $this->
returnError($id.
' is not a valid asset id');
513 if (!$valid_assetid) {
514 $this->
returnError($id.
' is not a valid asset id');
518 return $am->getAsset($id);
522 if (strpos($id,
'http://') !== FALSE || strpos($id,
'https://') !== FALSE) {
526 $url_parts = parse_url($id);
527 $protocol = (isset($url_parts[
'scheme']) && !empty($url_parts[
'scheme'])) ? $url_parts[
'scheme'] :
'http';
530 $asset = $am->getAssetFromURL($protocol, strip_url($id, TRUE), TRUE, TRUE);
531 if (is_null($asset)) $this->
returnError($id.
' is not a valid URL');
556 private function _getAssetTypes($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
558 $data = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypes(TRUE, TRUE);
580 private function _trashAsset($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
582 if (isset($args[
'assetid']) && !empty($args[
'assetid'])) {
583 $assetids = explode(
'\\,', $args[
'assetid']);
586 $data[
'error'] =
'Please Enter Asset Id(s) to move to Trash';
608 private function _getChildCount($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
610 if (isset($args[
'asset_id']) && !empty($args[
'asset_id'])) {
611 $assetid = $args[
'asset_id'];
613 if ($args[
'levels'] ==
'0') {
616 $level = $args[
'levels'];
618 $children = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($assetid,
'', TRUE, NULL, NULL, NULL, TRUE, NULL, $level);
619 $data[
'child_count'] = count($children);
621 $data[
'error'] =
'Please Enter Asset Id to get the child count';
642 private function _updateMultipleLinks($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
644 $links = $data = Array();
645 $links[
'parents'] = explode(
'\\,', $args[
'parent_id']);
646 $links[
'children'] = explode(
'\\,', $args[
'child_id']);
647 $links[
'existing_link_type'] = explode(
'\\,', $args[
'existing_link_type']);
648 $links[
'existing_link_value'] = explode(
'\\,', $args[
'existing_link_value']);
649 $links[
'link_type'] = explode(
'\\,', $args[
'link_type']);
650 $links[
'link_value'] = explode(
'\\,', $args[
'link_value']);
651 $links[
'sort_order'] = explode(
'\\,', $args[
'sort_order']);
652 $links[
'lock'] = explode(
'\\,', $args[
'locked']);
654 foreach ($links as $elements) {
655 if (count($elements) != count($links[
'parents'])) {
656 $data[
'error'] =
'Please provide correct number of link elements';
662 for ($i = 0; $i < count($links[
'parents']); $i++) {
664 if($links[
'children'][$i] ==
'Undefined' || $links[
'children'][$i] ==
'' ) {
665 $data[$i][
'error'] =
'Child Id whose link is to be update was not provided';
667 }
else if ($links[
'parents'][$i] ==
'Undefined' || $links[
'parents'][$i] ==
''){
668 $data[$i][
'error'] =
'Parent Id whose link is to be update was not provided';
672 $child_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($links[
'children'][$i]);
673 if(is_null($child_asset)) {
674 $data[$i][
'error'] =
'Asset #'.$links[
'children'][$i].
' does not exist';
678 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($links[
'parents'][$i]);
679 if(is_null($parent_asset)) {
680 $data[$i][
'error'] =
'Asset #'.$links[
'parents'][$i].
' does not exist';
684 if ($child_asset->writeAccess()) {
686 $ext_link_type = defined($links[
'existing_link_type'][$i]) ? constant($links[
'existing_link_type'][$i]) : SQ_LINK_TYPE_1;
687 $ext_link_value = $links[
'existing_link_value'][$i];
688 $link_type = defined($links[
'link_type'][$i]) ? constant($links[
'link_type'][$i]) : SQ_LINK_TYPE_1;
689 $link_value = $links[
'link_value'][$i];
691 $links[
'parents'][$i] ,
692 $links[
'children'][$i] ,
697 ($links[
'sort_order'][$i] !=
'' && $links[
'sort_order'][$i] !=
'undefined') ? $links[
'sort_order'][$i] : NULL ,
698 ($links[
'lock'][$i] !=
'' && $links[
'lock'][$i] !=
'undefined') ? $links[
'lock'][$i] : TRUE
701 $data[$i] =
'Not enough permission to update link between Asset "'.$child_asset->name.
'" (#'.$child_asset->id.
') and for Asset "'.$parent_asset->name.
'" (#'.$parent_asset->id.
')';
723 private function _removeMultipleLinks($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
725 $links = $data = Array();
726 $links[
'parents'] = explode(
'\\,', $args[
'parent_id']);
727 $links[
'children'] = explode(
'\\,', $args[
'child_id']);
728 $links[
'link_type'] = explode(
'\\,', $args[
'link_type']);
729 $links[
'link_value'] = explode(
'\\,', $args[
'link_value']);
731 foreach ($links as $elements) {
732 if (count($elements) != count($links[
'parents'])) {
733 $data[
'error'] =
'Please provide correct number of link elements';
739 for ($i = 0; $i < count($links[
'parents']); $i++) {
741 if($links[
'children'][$i] ==
'Undefined' || $links[
'children'][$i] ==
'' || $links[
'children'][$i] == NULL) {
742 $data[$i][
'error'] =
'Child Id whose link is to be update was not provided';
744 }
else if ($links[
'parents'][$i] ==
'Undefined' || $links[
'parents'][$i] ==
''|| $links[
'children'][$i] == NULL){
745 $data[$i][
'error'] =
'Parent Id whose link is to be update was not provided';
749 $child_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($links[
'children'][$i]);
750 if(is_null($child_asset)) {
751 $data[$i][
'error'] =
'Asset #'.$links[
'children'][$i].
' does not exist';
755 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($links[
'parents'][$i]);
756 if(is_null($parent_asset)) {
757 $data[$i][
'error'] =
'Asset #'.$links[
'parents'][$i].
' does not exist';
761 if ($child_asset->writeAccess()) {
763 $link_value = $links[
'link_value'][$i];
764 $link_type = defined($links[
'link_type'][$i]) ? constant($links[
'link_type'][$i]) : SQ_LINK_TYPE_1;
766 $data[$i] = $this->
removeLink($parent_asset->id, $child_asset->id, $link_type, $link_value);
768 $data[$i] =
'Not enough permission to remove link between Asset "'.$child_asset->name.
'" (#'.$child_asset->id.
') and for Asset "'.$parent_asset->name.
'" (#'.$parent_asset->id.
')';
790 private function _importAssetsFromXML($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
793 $filePath = $args[
'filePath'];
794 $import_under = $args[
'id'];
797 if (file_exists($filePath) || $filePath ==
'no_file_provided') {
799 if (strtolower(substr($filePath, -3)) ==
'xml') {
801 if($GLOBALS[
'SQ_SYSTEM']->am->assetExists($import_under)) {
803 $vars[
'file_info'] = $filePath;
804 $vars[
'create_under_assetid'] = $import_under;
805 $vars[
'delete_after_import'] = FALSE;
808 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
809 $errors = $hh->freestyleHipo(
'hipo_job_import_assets_from_xml', $vars, SQ_PACKAGES_PATH.
'/import_tools/hipo_jobs');
810 if (empty($errors)) {
811 $data[
'success'] =
'Assets sucessfully imported under Asset #'.$import_under;
813 $data[
'error'] =
'Error occured while importing assets under Asset #'.$import_under;
817 $data[
'error'] =
'Assetid provided to import assets under is not valid';
820 $data[
'error'] =
'File provided is not XML';
823 $data[
'error'] =
'No File path provided OR File does not exist for the provided path';
844 private function _getRoles($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
846 $assetid = isset($args[
'id']) && $args[
'id'] !=
'' ? $args[
'id'] : NULL;
847 $roleid = isset($args[
'roleid']) && $args[
'roleid'] !=
'' ? $args[
'roleid'] : NULL;
848 $userid = isset($args[
'userid']) && $args[
'userid'] !=
'' ? $args[
'userid'] : NULL;
849 $include_assetid = isset($args[
'include_assetid']) && $args[
'include_assetid'] !=
'' ? $args[
'include_assetid'] : FALSE;
850 $include_globals = isset($args[
'include_globals']) && $args[
'include_globals'] !=
'' ? $args[
'include_globals'] : FALSE;
851 $expand_groups = isset($args[
'expand_groups']) && $args[
'expand_groups'] !=
'' ? $args[
'expand_groups'] : FALSE;
852 $inc_dependants = isset($args[
'inc_dependants']) && $args[
'inc_dependants'] !=
'' ? $args[
'inc_dependants'] : TRUE;
853 $include_parents = isset($args[
'include_parents']) && $args[
'include_parents'] !=
'' ? $args[
'include_parents'] : FALSE;
854 $type_codes = (isset($args[
'type_codes']) && $args[
'type_codes'] !=
'') ? explode(
'\\,', $args[
'type_codes']) : Array();
855 $strict_type_code = isset($args[
'strict_type_code']) && $args[
'strict_type_code'] !=
'' ? $args[
'strict_type_code'] : TRUE;
857 $data = $GLOBALS[
'SQ_SYSTEM']->am->getRole($assetid, $roleid, $userid, $include_assetid, $include_globals, $expand_groups, $inc_dependants, $include_parents, $type_codes,$strict_type_code);
859 if(empty($data)) $data[] =
'No roles data is found';
878 private function _executeHTMLTidy($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
880 $str_to_process = isset($args[
'content']) && $args[
'content'] !=
'' ? $args[
'content'] : NULL;
882 if (!is_null($str_to_process)) {
885 $ROOT_PATH = SQ_FUDGE_PATH.
'/wysiwyg/';
886 require_once SQ_FUDGE_PATH.
'/wysiwyg/plugins/html_tidy/html_tidy.inc';
889 $tidy->process($str_to_process);
891 if ($tidy->htmltidy_status ==
'pass') {
892 $data[] = $str_to_process;
894 }
else if ($tidy->htmltidy_status ==
'fail') {
895 $data[
'error'] =
'HTML Tidy failed to process the given content';
897 }
else if ($tidy->htmltidy_status ==
'wait') {
898 $data[
'error'] =
'HTML Tidy wasn\'t ready to process content. Try again';
900 }
else if ($tidy->htmltidy_status ==
'disabled') {
901 $data[
'error'] =
'HTML Tidy is disabled on the System';
905 $data[
'error'] =
'No string passes to process HTMLTidy on';
926 private function _getGeneral($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
929 $get_attributes = isset($args[
'get_attributes']) ? $args[
'get_attributes'] : FALSE;
932 $data[
'error'] =
'You do not have permissions to access this asset';
953 private function _getAttributes($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
957 $attributes = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypeAttributes($asset->type());
958 foreach ($attributes as $key => $val) {
959 if ($val[
'type'] ==
'password')
continue;
960 if ($key ==
'api_key') {
964 $data[$key] = $asset->attr($key);
968 $data[
'error'] =
'You do not have permissions to access this asset';
990 private function _setMultipleAttributes($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
992 return $this->_setAttribute($args, $asset, $read_access, $write_access);
1010 private function _setAttribute($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1012 if ($write_access) {
1013 if (isset($args[
'attr_name']) && isset($args[
'attr_val'])) {
1014 $attr_names = explode(
'\\,', $args[
'attr_name']);
1015 $attr_vals = explode(
'\\,', $args[
'attr_val']);
1022 $data =
'Attribute for Asset #'.$asset->id.
' were not set. Check Error Log for more information';
1025 $data[
'error'] =
'Please enter both the attribute name and value';
1028 $data[
'error'] =
'You do not have permissions to access this asset';
1049 private function _getMetadata($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1052 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
1053 $schema = $mm->getSchemas($asset->id, TRUE);
1054 if (!empty($schema)) {
1055 $data = $mm->getMetadataFieldValues($asset->id);
1057 $data[
'error'] =
'No Metadata Schema applied to Asset "'.$asset->name.
'(#'.$asset->id.
')"';
1060 $data[
'error'] =
'You do not have permissions to access this asset';
1082 private function _setMetadataAllFields($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1084 return $this->_setMetadata($args, $asset, $read_access, $write_access);
1102 private function _setMetadata($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1104 if ($write_access) {
1105 if (isset($args[
'field_id']) && isset($args[
'field_val'])) {
1106 require_once SQ_CORE_PACKAGE_PATH.
'/metadata/metadata_field/metadata_field.inc';
1108 $field_ids = explode(
'\\,', $args[
'field_id']);
1109 $field_vals = explode(
'\\,', $args[
'field_val']);
1111 foreach($field_vals as $index => $fieldVal) {
1112 $field_vals[$index] = $fieldVal;
1119 foreach($field_vals as $index => $fieldVal) {
1121 $to_decode = Array(
'\=',
'\;',
'\\\\');
1122 $decoded_str = Array(
'=',
';',
'\\');
1123 $value = str_replace($to_decode, $decoded_str, $value);
1124 $data[
'success'][] =
'Metadata field #'.$field_ids[$i].
' has been successfully set to "'.$value.
'" for Asset "'.$asset->name.
'" (#'.$asset->id.
')';
1129 $data[
'error'] =
'Please enter both the field id and value';
1132 $data[
'error'] =
'You do not have permissions to access this asset';
1154 private function _getChildren($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1158 if (empty($args[
'levels']) && $args[
'levels'] !=
'0') {
1159 $data[
'error'] =
'Please set a depth(levels) limit';
1163 if ($args[
'levels'] ==
'0') {
1166 $level = $args[
'levels'];
1170 $type_codes = (isset($args[
'type_codes']) && $args[
'type_codes'] !=
'') ? explode(
'\\,', $args[
'type_codes']) : Array();
1171 $link_types = (isset($args[
'link_type']) && $args[
'link_type'] !=
'') ? explode(
'\\,', $args[
'link_type']) : Array();
1172 $link_values = (isset($args[
'link_value']) && $args[
'link_value'] !=
'') ? explode(
'\\,', $args[
'link_value']) : Array() ;
1173 $get_attributes = isset($args[
'get_attributes']) ? $args[
'get_attributes'] : FALSE;
1175 $data = $this->
getChildren($asset->id, $level, $type_codes, $link_types, $link_values, $get_attributes);
1178 $data[
'error'] =
'Asset #'.$asset->id.
' has no children';
1181 $data[
'error'] =
'You do not have permissions to access this asset';
1204 private function _getParents($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1207 if ($asset->id == 1) {
1208 $data[
'error'] =
'The root asset does not have any parents';
1211 if (empty($args[
'levels']) && $args[
'levels'] !=
'0') {
1212 $data[
'error'] =
'Please set a depth(levels) limit';
1216 if ($args[
'levels'] ==
'0') {
1219 $level = $args[
'levels'];
1223 $type_codes = (isset($args[
'type_codes']) && $args[
'type_codes'] !=
'') ? explode(
'\\,', $args[
'type_codes']) : Array();
1224 $link_types = (isset($args[
'link_type']) && $args[
'link_type'] !=
'') ? explode(
'\\,', $args[
'link_type']) : Array();
1225 $link_values = (isset($args[
'link_value']) && $args[
'link_value'] !=
'') ? explode(
'\\,', $args[
'link_value']) : Array();
1226 $get_attributes = isset($args[
'get_attributes']) ? $args[
'get_attributes'] : FALSE;
1228 $data = $this->
getParents($asset->id, $level, $type_codes, $link_types, $link_values, $get_attributes);
1230 $data[
'error'] =
'You do not have permissions to access this asset';
1251 private function _getPermissions($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1254 $level = $args[
'level'];
1255 if (empty($level)) {
1256 $data[
'error'] =
'Please set a permissions level';
1259 if (!is_numeric($level)) {
1260 $data[
'error'] =
'Permissions level must be numeric';
1264 $data[
'error'] = $level.
' is not a valid permissions level';
1269 if (!$data)
return FALSE;
1273 $data[
'error'] =
'You do not have permissions to access this asset';
1294 private function _createAsset($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1296 if ($write_access || $this->
attr(
'ignore_permissions')) {
1298 if (isset($args[
'type_code']) && isset($args[
'asset_name'])) {
1299 $type_code = isset($args[
'type_code']) ? $args[
'type_code'] :
'';
1300 $asset_name = isset($args[
'asset_name']) ? $args[
'asset_name'] :
'';
1301 $link_type = isset($args[
'link_type']) ? $args[
'link_type'] : 1;
1302 $link_value = isset($args[
'link_value']) ? $args[
'link_value'] :
'';
1303 $sort_order = isset($args[
'sort_order']) ? $args[
'sort_order'] :
'';
1304 $is_dependant = isset($args[
'is_dependant']) ? $args[
'is_dependant'] : 0;
1305 $is_exclusive = isset($args[
'is_exclusive']) ? $args[
'is_exclusive'] : 0;
1306 $extra_attributes = (isset($args[
'extra_attributes']) && $args[
'extra_attributes'] ==
'1') ? TRUE : FALSE;
1309 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
1310 $data = $this->
createAsset($asset->id, $type_code, $asset_name, $link_type, $link_value, $sort_order, $is_dependant, $is_exclusive, $extra_attributes, $args);
1311 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
1313 $data[
'error'] =
'You must set the parent id, type code and asset name to create an asset';
1316 $data[
'error'] =
'You do not have permissions to create an asset';
1337 private function _getLocksInfo($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1341 $screen = $args[
'screen'];
1343 if (empty($response)) {
1344 $data[] =
'No lock are held by anyone on Asset "'.$asset->name.
'" (#'.$asset->id.
')';
1346 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
1347 foreach ($response as $screen_lock => $lock_info) {
1348 if ($screen_lock ==
'0') $screen_lock = $screen;
1349 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($lock_info[
'userid']);
1350 $expires_in = easy_time_total(($lock_info[
'expires'] - time()), TRUE);
1351 if (!$expires_in) $expires_in =
'1 second';
1352 $data[] =
'"'.$screen_lock.
'" locks are held by User "'.$user->name.
'" (#'.$lock_info[
'userid'].
') for Asset "'.$asset->name.
'" (#'.$asset->id.
'). This is due to expire in '.$expires_in;
1356 $data[
'error'] =
'You do not have permission to access this asset';
1379 private function _acquireLock($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1381 if ($write_access) {
1382 $screen = $args[
'screen'];
1383 $dependants_only = isset($args[
'dependants_only']) ? $args[
'dependants_only'] : TRUE ;
1384 $force_acquire = isset($args[
'force_acquire']) ? $args[
'force_acquire'] : FALSE;
1386 $response = $this->
acquireLocks($asset, $screen, $dependants_only, $force_acquire);
1387 if (empty($response)) {
1388 $data[] =
'"'.$screen.
'" locks are now acquired for Asset "'.$asset->name.
'" (#'.$asset->id.
')';
1393 $data[
'error'] =
'You do not have permission to access this asset';
1414 private function _releaseLock($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1416 $screen = $args[
'screen'];
1422 if ($write_access || (!empty($response) && $asset->writeAccess(
'', Array(), FALSE))) {
1423 if (empty($response)) {
1424 $data[] =
'No lock are held by anyone on Asset "'.$asset->name.
'" (#'.$asset->id.
')';
1426 $response = $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($asset->id, $screen);
1428 $data[] =
'"'.$screen.
'" locks are now released for Asset "'.$asset->name.
'" (#'.$asset->id.
')';
1430 $data[
'error'] =
'You cannot release locks on this asset';
1434 $data[
'error'] =
'You do not have permission to access this asset';
1455 private function _createLink($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1457 if ($write_access) {
1458 if (isset($args[
'parent_id'])) {
1460 $parent = $this->
setAsset($args[
'parent_id']);
1461 if (!$parent)
return FALSE;
1463 $data[
'error'] =
'A parent asset is required';
1467 $link_type = isset($args[
'link_type']) ? $args[
'link_type'] : 1;
1468 $link_value = isset($args[
'link_value']) ? $args[
'link_value'] :
'';
1469 $sort_order = isset($args[
'sort_order']) ? $args[
'sort_order'] :
'';
1470 $is_dependant = isset($args[
'is_dependant']) ? $args[
'is_dependant'] : 0;
1471 $is_exclusive = isset($args[
'is_exclusive']) ? $args[
'is_exclusive'] : 0;
1473 $data = $this->
createLink($parent->id, $asset->id, $link_type, $link_value, $sort_order, $is_dependant, $is_exclusive);
1475 $data[
'error'] =
'You do not have permission to access this asset';
1497 private function _removeLink($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1499 if ($write_access) {
1500 if (isset($args[
'parent_id'])) {
1502 $parent = $this->
setAsset($args[
'parent_id']);
1503 if (!$parent)
return FALSE;
1505 $data[
'error'] =
'A parent asset is required';
1508 $link_type = defined($args[
'link_type']) ? constant($args[
'link_type']) : SQ_LINK_TYPE_1;
1509 $link_value = $args[
'link_value'];
1512 $data = $this->
removeLink($parent->id, $asset->id, $link_type, $link_value);
1513 if (!$data)
return FALSE;
1515 $data[
'error'] =
'You do not have permission to access this asset';
1536 private function _moveLink($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1538 if ($write_access) {
1539 if (!empty($args[
'old_parent_id']) && !empty($args[
'new_parent_id'])) {
1541 $old_parent = $this->
setAsset($args[
'old_parent_id']);
1542 $new_parent = $this->
setAsset($args[
'new_parent_id']);
1543 if (is_null($old_parent) || is_null($new_parent)) {
1544 $data[
'error'] =
'Either Old Parent or the New Parent was not a valid assetid.';
1548 $data[
'error'] =
'A parent asset is required';
1552 $old_link_type = defined($args[
'old_link_type']) ? constant($args[
'old_link_type']) : SQ_LINK_TYPE_1 ;
1553 $old_link_value = $args[
'old_link_value'];
1554 $new_link_type = defined($args[
'new_link_type']) ? constant($args[
'new_link_type']) : SQ_LINK_TYPE_1 ;
1555 $new_link_value = $args[
'new_link_value'];
1556 $new_position = isset($args[
'new_position']) ? $args[
'new_position'] : -1;
1559 $data = $this->
moveLink($old_parent->id, $asset->id, $old_link_type, $old_link_value, $new_parent->id, $new_link_type, $new_link_value, $new_position);
1561 if (!$data)
return FALSE;
1563 $data[
'error'] =
'You do not have permission to access this asset';
1584 private function _updateLink($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1586 if ($write_access) {
1587 if (isset($args[
'parent_id'])) {
1589 $parent = $this->
setAsset($args[
'parent_id']);
1590 if (!$parent)
return FALSE;
1592 $data[
'error'] =
'A parent asset is required';
1596 $old_link_type = defined($args[
'existing_link_type']) ? constant($args[
'existing_link_type']) : SQ_LINK_TYPE_1 ;
1597 $old_link_value = $args[
'existing_link_value'];
1598 $new_link_type = defined($args[
'link_type']) ? constant($args[
'link_type']) : SQ_LINK_TYPE_1 ;
1599 $new_link_value = $args[
'link_value'];
1600 $sort_order = (isset($args[
'sort_order']) && $args[
'sort_order'] !=
'' ) ?$args[
'sort_order'] : NULL;
1601 $locked = (isset($args[
'locked']) && $args[
'locked'] !=
'' ) ? $args[
'locked'] : TRUE;
1604 $data = $this->
updateLink($parent->id, $asset->id, $old_link_type, $old_link_value, $new_link_type, $new_link_value, $sort_order, $locked);
1606 if (!$data)
return FALSE;
1608 $data[
'error'] =
'You do not have permission to access this asset';
1629 private function _getLinkId($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1632 if (isset($args[
'parent_id'])) {
1634 $parent = $this->
setAsset($args[
'parent_id']);
1635 if (!$parent)
return FALSE;
1637 $data[
'error'] =
'A parent asset is required';
1640 $link_type = defined($args[
'link_type']) ? constant($args[
'link_type']) : SQ_LINK_TYPE_1 ;
1641 $link_value = $args[
'link_value'];
1642 $all_info = (boolean)$args[
'all_info'];
1645 $data = $this->
getLinkId($parent->id, $asset->id, $link_type, $link_value, $all_info);
1648 $data[
'error'] =
'Parent Asset #'.$parent->id.
' and Child Asset #'.$asset->id.
' do not have a valid link for given Link Type and Link Value';
1651 $data[
'error'] =
'You do not have permissions to access this asset';
1672 private function _getAssetTree($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1676 if (empty($args[
'levels'])) {
1679 $levels = $args[
'levels'];
1682 $data = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTree($asset->id, $levels);
1684 if (empty($data)) $data[
'error'] =
'Asset #'.$asset->id.
' has no children';
1686 $data[
'error'] =
'You do not have permissions to access this asset';
1707 private function _getKeywordsReplacements($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1709 if (!isset($arg[
'keywords']) && isset($args[
'keywords_array'])) {
1712 $args[
'keywords'] = $args[
'keywords_array'];
1716 if (isset($args[
'keywords']) && !empty ($args[
'keywords']) ){
1717 $keywords = is_array($args[
'keywords']) ? $args[
'keywords'] : explode(
'\\,', $args[
'keywords']);
1720 $data[
'error'] =
'Please provide keywords to get replacement for';
1723 $data[
'error'] =
'You do not have permissions to access this asset';
1744 private function _setAssetStatus($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1746 if ($write_access) {
1747 $status = (int) $args[
'status'];
1748 $cascade = isset($args[
'cascade']) ? $args[
'cascade'] : FALSE;
1749 $workflow_stream = (isset($args[
'workflow_stream']) && ($args[
'workflow_stream'] !=
'') )? $args[
'workflow_stream'] :
'SQ_USE_DEFAULT';
1752 $desc = get_status_description($status);
1753 $current_desc = ($status != $asset->status) ? get_status_description($asset->status) : $desc;
1755 $response = $this->
setAssetStatus($asset, $status, $cascade, $current_desc, $desc, $workflow_stream);
1756 if (empty($response)) {
1758 $data[] =
'Status for Asset "'.$asset->name.
'" (#'.$asset->id.
') has been changed successfully to '.$desc;
1760 $data[] =
'Status for Asset "'.$asset->name.
'" (#'.$asset->id.
') and its non-dependant children has been changed successfully to '.$desc;
1766 $data[
'error'] =
'You do not have permissions to access this change status for this asset';
1787 private function _getWebPath($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1790 $webpaths = $asset->getWebPaths();
1791 if(!empty($webpaths)) {
1793 foreach($webpaths as $webpath) {
1794 $data[
'webpath'][$i] = $webpath;
1798 $data [
'webpath'] = Array();
1801 $data[
'error'] =
'You do not have permission to access this asset';
1823 private function _setWebPath($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1826 $webpaths = explode(
'\\,', $args[
'webpath']);
1827 if (!empty($webpaths)) {
1828 $webpaths = explode(
'\\,', $args[
'webpath']);
1829 $auto_remap = (isset($args[
'auto_remap']) && $args[
'auto_remap'] !=
'') ? $args[
'auto_remap'] : TRUE;
1830 $response = $asset->saveWebpaths($webpaths, $auto_remap);
1834 $data[] =
'Webpath for Asset "'.$asset->name.
'" (# '.$asset->id.
') had been updated sucessfully';
1836 $data[] =
'Could not update webpath for Asset "'.$asset->name.
'" (# '.$asset->id.
') ';
1839 $data[
'error'] =
'No webpaths provided';
1842 $data[
'error'] =
'You do not have permission to access this asset';
1863 private function _getWorkflowSchema($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1866 $wfm = $GLOBALS[
'SQ_SYSTEM']->getWorkflowManager();
1867 $granted = isset($args[
'granted']) && $args[
'granted'] !=
'' ? $args[
'granted'] : NULL;
1868 $running = isset($args[
'running']) && $args[
'running'] !=
'' ? $args[
'running'] : FALSE;
1869 $schemas = $wfm->getSchemas($asset->id, $granted, $running);
1871 if(empty($schemas)) {
1872 $message =
'No Workflow Schema ';
1874 $message .=
'currently running for ';
1876 if (is_null($granted)) {
1877 $message .=
'currently applied to';
1879 $message .= $granted ?
'granted on ' :
'denied on ';
1882 $data[] = $message.
'Asset "'.$asset->name.
'" (# '.$asset->id.
')';
1884 foreach ($schemas as $index => $info) {
1885 if ($running && $granted) {
1886 $data[
'running'][] = $info;
1887 }
else if (is_null($granted) && $running) {
1888 $data[
'running'][] = $index;
1890 if (is_null($granted)) {
1891 $status = $info ?
'granted' :
'denied';
1892 $data[$status][] = $index;
1894 $status = $granted ?
'granted' :
'denied';
1895 $data[$status][] = $info;
1901 $data[
'error'] =
'You do not have permission to access this asset';
1924 private function _createFileAsset($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
1926 if ($write_access || $this->
attr(
'ignore_permissions')) {
1928 if ((isset($args[
'friendly_name']) && $args[
'friendly_name'] !=
'' )) {
1929 $filename = $args[
'friendly_name'];
1930 $type_code = $args[
'type_code'];
1931 $link_type = defined($args[
'link_type']) ? constant($args[
'link_type']) : SQ_LINK_TYPE_1;
1932 $link_value = $args[
'link_value'];
1933 $valid_type_code= $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants(
'file', TRUE);
1935 if(!in_array(Array($type_code), $valid_type_code)) {
1937 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
1938 $new_asset =
new $type_code();
1940 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
1941 $file_ext = get_file_type($filename);
1946 if (strtolower($type_code) ==
'file' || strtolower($type_code) ==
'text_file') {
1948 include SQ_FUDGE_PATH.
'/standards_lists/mime_types.inc';
1949 $allowed_extensions = array_keys($standards_lists_mime_types);
1951 $allowed_extensions = $new_asset->allowed_extensions;
1954 if (!in_array($file_ext, $allowed_extensions)) {
1955 return Array(
'error' =>
'The supplied file extension "'.$file_ext.
'" is not allowed for file type "'.$type_code.
'"');
1959 $destination_file = SQ_DATA_PATH.
'/temp/'.$tmp_file_name.
'.'.$file_ext;
1961 while (file_exists($destination_file)) {
1963 $destination_file = SQ_DATA_PATH.
'/temp/'.$tmp_file_name.
'.'.$file_ext;
1967 if ($type_code !=
'image' && $type_code !=
'thumbnail') {
1968 file_put_contents($destination_file,
'');
1971 $img = imagecreate(
'10',
'10');
1972 $background_color = imagecolorallocate($img, 0, 0, 0);
1973 imagepng($img, $destination_file);
1979 'link_type' => $link_type,
1980 'value' => $link_value,
1984 $file_info = Array (
1985 'name' => $filename,
1986 'tmp_name' => $destination_file,
1987 'type' => $file_ext,
1989 'size' => filesize($destination_file),
1990 'filename' => $filename,
1991 'non_uploaded_file' => TRUE,
1995 $new_asset->_tmp[
'uploading_file'] = TRUE;
1996 if ($type_code ==
'data_source_graph') $new_asset->setAttrValue(
'title', $filename);
1998 $success = $new_asset->create($link, $file_info);
2001 $data[
'error'] =
'Error occured while creating new asset of type \''.$type_code.
'\'';
2004 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
2005 $existing = $new_asset->getExistingFile();
2007 $new_asset_edit_fns = $new_asset->getEditFns();
2008 $new_asset_edit_fns->removeOldFile($new_asset, $existing, $fv);
2009 $data[$new_asset->id] =
'New File Asset (#'.$new_asset->id.
') \''.$new_asset->name.
'\'of type_code \
''.$type_code.
'\' created successfully
';
2012 $data['error
'] = 'Passed
type code is not
File Type asset or its Descendant Type
';
2015 $data['error
'] = 'You must
set the Name of the
Asset and provide a Base 64 encoded file to upload
';
2018 $data['error
'] = 'You
do not have permissions to
create an asset
';
2023 }// end _createFileAsset
2039 private function _setContentOfEditableFileAsset($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
2041 if ($write_access) {
2042 $valid_file_type = Array('xml_file
', 'xsl_file
', 'css_file
', 'text_file
', 'js_file
');
2043 if(in_array($asset->type(), $valid_file_type)) {
2044 if($asset->writeAccess('attributes
')) {
2045 $content = urldecode($args['content
']);
2046 if($content == 'no_value_provided
') {
2047 $data[] = 'No file content provided
';
2049 require_once(SQ_INCLUDE_PATH.'/backend_outputter.inc
');
2050 $o = new Backend_Outputter();
2051 $prefix = $asset->getPrefix();
2052 $edit_fns = $asset->getEditFns();
2053 $_POST[$prefix.'_new_file
'] = urldecode($content);
2055 $success = $edit_fns->processEditFile($asset, $o, $prefix);
2057 $data['success
'] = 'Content of
Asset '.$asset->short_name.'(#
'.$asset->id.') successfully updated
';
2059 $data['error
'] = 'Error occured
while updating Content of
Asset '.$asset->short_name.'(#
'.$asset->id.')
';
2063 $data['error
'] = 'Locks are not acquired on
Asset '.$asset->short_name.'(#
'.$asset->id.'), content cannot be updated
';
2066 $data['error
'] = 'Content
for Asset of
type code \
''.$asset->type().
'\' cannot be updated
';
2069 $data['error
'] = 'You
do not have permissions to Edit
this asset
';
2074 }// end _setContentOfEditableFileAsset
2090 private function _getLineage($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
2092 // we have the url in the args, lets get it and get the asset are dealing with
2093 $url = trim(array_get_index($args, 'asset_url
', ''));
2096 'error
' => 'No URL supplied
'
2099 $significant_link_only = array_get_index($args, 'significant_link_only
', TRUE);
2101 // cant get lineage of root_folder, DUHH !
2102 if ($url == '1
') return Array();
2104 // now if we have url we have a ready made function in asset_manager.inc we can use
2105 // although we manipulate the results as it not the elements/format we want
2106 $url_bits = parse_url($url);
2107 if (!empty($url_bits['scheme
']) && !empty($url_bits['host
'])) {
2108 $asset = $GLOBALS['SQ_SYSTEM
']->am->getAssetFromURL($url_bits['scheme
'], $url_bits['host
'].$url_bits['path
']);
2109 if (is_null($asset)) {
2111 'error
' => 'URL supplied does not point to asset in Matrix
'
2114 } else if (preg_match('|^[0-9]+(?:\:.+)?|
', $url)) {
2115 if (!$GLOBALS['SQ_SYSTEM
']->am->getAssetInfo($url)) {
2117 'error
' => 'Supplied assetid #
'.$url.' does not exist
'
2120 $asset = $GLOBALS['SQ_SYSTEM
']->am->getAsset($url);
2123 'error
' => 'URL supplied is invalid
'
2127 if(!$asset->readAccess()) return Array('error
' => 'You
do not have permissions to access
this asset
');
2129 $raw_lineages = $GLOBALS['SQ_SYSTEM
']->am->getLinkLineages($asset->id, 0, NULL, Array('name
', 'type_code
'), $significant_link_only);
2130 $root_folder = $GLOBALS['SQ_SYSTEM
']->am->getSystemAsset('root_folder
');
2132 $result_lineages = Array();
2133 $linkid_done = Array();
2134 $link_types = $significant_link_only ? SQ_SC_LINK_SIGNIFICANT : SQ_SC_LINK_ALL;
2136 foreach ($raw_lineages as $index => $val) {
2138 $minorid = $asset->id;
2139 $parent_lineage_assetids = array_merge(array_reverse(array_keys($val['lineage
'])), Array($root_folder->id));
2140 foreach($parent_lineage_assetids as $majorid) {
2141 $major_asset = $GLOBALS['SQ_SYSTEM
']->am->getAsset($majorid);
2142 $minor_asset = $GLOBALS['SQ_SYSTEM
']->am->getAsset($minorid);
2144 $links = $GLOBALS['SQ_SYSTEM
']->am->getLinkByAsset($major_asset->id, $minor_asset->id, $link_types, NULL, 'major
', TRUE);
2145 foreach($links as $link) {
2146 if (!in_array($link['linkid
'], $linkid_done)) {
2147 if ($link['link_type
'] & SQ_SC_LINK_SIGNIFICANT) {
2148 $treeid_data = $GLOBALS['SQ_SYSTEM
']->am->getLinkTreeid($link['linkid
']);
2150 $treeid_data = Array($link['linkid
'] => Array(Array(FALSE)));
2152 foreach($treeid_data[$link['linkid
']] as $treeid) {
2154 $info['tree_id
'] = $treeid[0];
2155 $info['assetid
'] = $minor_asset->id;
2156 $info['name
'] = $minor_asset->name;
2157 $info['type_code
'] = $minor_asset->type();
2158 $info['link_type
'] = $link['link_type
'];
2159 $info['link_value
'] = $link['value
'];
2160 $info['linkid
'] = $link['linkid
'];
2161 $info['parent_assetid
'] = $major_asset->id;
2162 $info['parent_type_code
'] = $major_asset->type();
2166 $linkid_done[] = $link['linkid
'];
2170 // Get the link info for the next lineage, one level up, if any
2171 $GLOBALS['SQ_SYSTEM
']->am->forgetAsset($minorid);
2172 $minorid = $majorid;
2175 $result_lineages = array_merge($result_lineages, array_reverse($data));
2178 $GLOBALS['SQ_SYSTEM
']->am->forgetAsset($root_folder);
2180 return $result_lineages;
2182 }// end _getLineage()
2198 private function _getLineageFromUrl($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
2200 // we have the url in the args, lets get it and get the asset are dealing with
2201 $url = trim(array_get_index($args, 'asset_url
', ''));
2202 if (empty($url)) return Array('error
' => 'No URL supplied
');
2204 $url_bits = parse_url($url);
2206 $asset = $GLOBALS['SQ_SYSTEM
']->am->getAssetFromURL($url_bits['scheme
'], $url_bits['host
'].$url_bits['path
']);
2208 if (is_null($asset)) return Array('error
' => 'URL supplied does not point to asset in Matrix
');
2210 if(!$asset->readAccess()) return Array('error
' => 'You
do not have permissions to access
this asset
');
2213 $result_lineage = $GLOBALS['SQ_SYSTEM
']->am->getLineageFromURL($url_bits['scheme
'], $url_bits['host
'].$url_bits['path
']);
2214 if(empty($result_lineage)) return Array('error
' => 'No lineage found
');
2216 return $result_lineage;
2218 }// end _getLineageFromUrl()
2234 private function _getUrlFromLineage($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
2237 $lineage = trim(array_get_index($args, 'lineage
', ''));
2238 $root_url = trim(array_get_index($args, 'root_url
', NULL));
2239 $protocol = trim(array_get_index($args, 'protocol
', NULL));
2241 if(empty($root_url)) $root_url = NULL;
2242 if (empty($lineage)) return Array('error
' => 'No lineage supplied
');
2244 $lineage = explode('\\,
', $lineage);
2246 $current_asset_id = trim(array_pop($lineage));
2247 $current_asset = $this->setAsset($current_asset_id);
2248 If(!$current_asset) return FALSE;
2250 if(!$current_asset->readAccess()) return Array('error
' => 'You
do not have permissions to access
this asset
');
2252 $candidate_urls = $GLOBALS['SQ_SYSTEM
']->am->getURLs($current_asset_id);
2253 if(empty($candidate_urls)) return Array('error
' => 'No URL found
for current asset
');
2255 $lineage[] = $current_asset_id;
2257 $result = $GLOBALS['SQ_SYSTEM
']->am->getUrlFromLineage($lineage, $root_url, $protocol);
2259 if (empty($result)) return Array('error
' => 'No URL found
for supplied lineage
');
2263 }// end _getUrlFromLineage()
2279 private function _cloneAsset($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
2281 if ($write_access || $this->attr('ignore_permissions
')) {
2283 $new_parent = array_get_index($args, 'new_parent
', '');
2285 // check if the parent asset is provided
2286 if (empty($new_parent)) {
2287 $data['error
'] = 'No location to clone the asset was provided
';
2291 // check to see if we have write permission to the new parent
2292 if (!($new_parent_asset = $GLOBALS['SQ_SYSTEM
']->am->getAsset($new_parent, '', TRUE))) {
2293 $data['error
'] = 'Assetid
"'.$new_parent.'" provided is invalid or doesn\
't exist on system';
2297 if (!$new_parent_asset->writeAccess() && !$this->
attr(
'ignore_permissions')) {
2298 $data[
'error'] =
'You do not have write access to the Asset under which you are tying to clone';
2302 $clone_num = array_get_index($args,
'clone_num', 1);
2303 $position = array_get_index($args,
'new_position', -1);
2304 $value = array_get_index($args,
'link_value',
'');
2305 $link_type = defined($args[
'link_type']) ? constant($args[
'link_type']) : SQ_LINK_TYPE_1;
2307 if (!is_null($asset)) {
2308 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
2309 $running_vars = Array (
2311 $asset->id => Array (
2312 'number_of_clones' => 1,
2315 'to_parent_assetid' => $new_parent,
2316 'to_parent_pos' => $position,
2317 'link_type' => $link_type,
2321 $all_errors = Array();
2322 $cloned_assets = Array();
2323 for ($i = 0; $i < $clone_num; $i++) {
2325 $running_vars_copy = $running_vars;
2326 $errors = $hh->freestyleHipo(
'hipo_job_clone_assets', $running_vars_copy);
2327 if(isset($running_vars_copy[
'cloned_asset'])) {
2328 $cloned_asset_id = array_pop(array_keys($running_vars_copy[
'cloned_asset']));
2329 $cloned_asset_id =
'#'.$cloned_asset_id;
2330 $cloned_assets[] = $cloned_asset_id;
2332 $all_errors += $errors;
2334 if (empty($all_errors)) {
2335 $cloned_assets_string = implode($cloned_assets,
', ');
2336 $data[
'success'] = $asset->name.
'(#'.$asset->id.
') has been successfully cloned to '.$cloned_assets_string;
2338 $data[
'error'] = $all_errors;
2341 $data[
'error'] =
'Asset to clone was not provided';
2344 $data[
'error'] =
'You do not have permissions to create an asset';
2366 private function _showDifference($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
2368 $asset_2_id = array_get_index($args,
'assetid_2',
'');
2369 if (empty($asset_2_id)) {
2370 $data[
'error'] =
'Only one asset was provided. Need 2 assets to check the difference';
2374 if (!($asset_2 = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset_2_id,
'', TRUE))) {
2375 $data[
'error'] =
'Assetid "'.$asset_2_id.
'", provided is invalid or doesn\'t exist on system';
2379 if (($read_access) && $asset_2->readAccess()) {
2381 $paint_layout_1 = array_get_index($args,
'paint_layout_1',
'');
2382 $paint_layout_2 = array_get_index($args,
'paint_layout_2',
'');
2384 if (empty($paint_layout_1) || empty($paint_layout_2)) {
2388 $asset->printBody();
2389 $content1 = ob_get_contents();
2393 $asset_2->printBody();
2394 $content2 = ob_get_contents();
2402 foreach (Array($paint_layout_1, $paint_layout_2) as $paint_layout_assetid) {
2403 if (!$paint_layout = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($paint_layout_assetid,
'paint_layout_page',
'TRUE')) {
2404 $data[
'error'] =
'Invalid assetid (#'.$paint_layout_assetid.
') provided for Paint Layout to use';
2406 $paint_layout = NULL;
2407 if (isset($data[
'error']))
return $data;
2411 $asset->printBodyWithPaintLayout($paint_layout_1);
2412 $content1 = ob_get_contents();
2416 $asset_2->printBodyWithPaintLayout($paint_layout_2);
2417 $content2 = ob_get_contents();
2422 require_once SQ_CORE_PACKAGE_PATH.
'/designs/design_areas/design_area_body/matrix_diff_highlighter.inc';
2424 $contents = Array(&$content1, &$content2);
2425 foreach ($contents as $index => $content) {
2426 $pattern =
'/(<div)([^>]*)( id="content_div_[0-9]*")([^>]*)(>)/';
2427 $replacement =
'$1$2$4$5';
2431 $contents[$index] = preg_replace($pattern, $replacement, $contents[$index]);
2436 $contents[$index] = str_replace(
' ',
' ', $contents[$index]);
2438 $difference = $highlighter->process($content1, $content2, FALSE);
2439 $data[
'success'] = $difference;
2441 $data[
'error'] =
'You do not have permissions to read content of one or either of the assets passed in';
2463 private function _getAlternateContext($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
2465 $all_info = array_get_index($args,
'all_info', FALSE);
2467 $system_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
2468 $current_contextid = $GLOBALS[
'SQ_SYSTEM']->getAlternateContext();
2469 $context_info = Array();
2471 $currnet_context = $system_contexts[$current_contextid];
2473 $context_info[$current_contextid] = $currnet_context;
2475 $context_info[$current_contextid] = $currnet_context[
'name'];
2478 $data[
'success'] = $context_info;
2498 private function _getCurrentContext($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
2500 $all_info = array_get_index($args,
'all_info', FALSE);
2503 if ($this->
attr(
'sync_context') && isset($_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_BACKEND_ALTERNATE_CONTEXT_ID'])) {
2504 $current_contextid = $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_BACKEND_ALTERNATE_CONTEXT_ID'];
2505 if (!isset($_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID']) ||
2506 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID'] != $current_contextid) {
2507 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID'] = $current_contextid;
2509 }
else if (isset($_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID'])) {
2510 $current_contextid = $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID'];
2512 $current_contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
2515 $system_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
2516 $context_info = Array();
2518 $currnet_context = $system_contexts[$current_contextid];
2520 $context_info[$current_contextid] = $currnet_context;
2522 $context_info[$current_contextid] = $currnet_context[
'name'];
2525 $data[
'success'] = $context_info;
2545 private function _getAllContexts($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
2547 $all_info = array_get_index($args,
'all_info', FALSE);
2549 $system_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
2550 $context_info = Array();
2552 foreach ($system_contexts as $context_id => $context_data) {
2554 $context_info[$context_id] = $context_data;
2556 $context_info[$context_id] = $context_data[
'name'];
2560 $data[
'success'] = $context_info;
2580 private function _setContext($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
2582 $context_id = array_get_index($args,
'context_id', NULL);
2584 if (!is_null($context_id)) {
2585 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
2586 if (isset($all_contexts[$context_id])) {
2588 $GLOBALS[
'SQ_SYSTEM']->changeContext($context_id);
2589 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID'] = $context_id;
2590 if ($this->
attr(
'sync_context')) {
2591 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_BACKEND_ALTERNATE_CONTEXT_ID'] = $context_id;
2593 $data[
'success'] =
"Context successfully set to '$context_id'.";
2595 $data[
'error'] =
'Context Id Provided doesn\'t exist on the system.';
2598 $data[
'error'] =
'No Context Id Provided.';
2619 private function _restoreContext($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
2622 $restored_context = $GLOBALS[
'SQ_SYSTEM']->restoreContext(TRUE);
2623 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID'] = $restored_context;
2624 if ($this->
attr(
'sync_context')) {
2625 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_BACKEND_ALTERNATE_CONTEXT_ID'] = $restored_context;
2628 $data[
'success'] =
"Context successfully restored back to '$restored_context'.";
2648 private function _getMetadataSchema($args=Array(), $asset=NULL, $read_access=FALSE, $write_access=FALSE)
2650 if ($write_access) {
2651 if (!is_null($asset)) {
2652 $granted = array_get_index($args,
'granted', TRUE);
2653 $cascades = array_get_index($args,
'cascades', NULL);
2657 $data[
'error'] =
'Asset to get the Metadata Schema applied to it was not provided';
2660 $data[
'error'] =
'You do not have permissions to access this asset';
2679 if (is_null($asset))
return Array();
2682 if ($asset->id ==
'1') {
2683 $data[
'name'] =
'Root Folder';
2688 $am = $GLOBALS[
'SQ_SYSTEM']->am;
2690 $user_to_check = Array(
2691 'created_user' => Array(
2692 'id' =>
'created_userid',
2693 'default' =>
'Undefined',
2695 'updated_user' => Array(
2696 'id' =>
'updated_userid',
2697 'default' =>
'Never Updated',
2699 'published_user' => Array(
2700 'id' =>
'published_userid',
2701 'default' =>
'Never Published',
2703 'status_user' => Array(
2704 'id' =>
'status_changed_userid',
2705 'default' =>
'Never Changed',
2709 $created_user = $updated_user = $published_user = $status_user = NULL;
2710 foreach ($user_to_check as $user => $user_info) {
2711 $user_id = $user_info[
'id'];
2712 if (isset($asset->$user_id) && $asset->$user_id !=
'' && (
int)$asset->$user_id != 0 ) {
2713 if(!(${$user} = $am->getAsset($asset->$user_id,
'', TRUE))) {
2714 ${$user} =
'Unknown User';
2716 }
else if (isset($asset->$user_id) && (int)$asset->$user_id == 0) {
2717 ${$user} =
'Root User';
2719 ${$user} = $user_info[
'default'];
2723 $user = $am->getAsset($GLOBALS[
'SQ_SYSTEM']->currentUserId());
2724 $array_to_check_in = array_merge(Array($user->id), $user->getUserGroups());
2725 $effective_permission =
'';
2728 $effective_permission =
'Admin Access';
2732 if($effective_permission ===
'' ) {
2733 foreach($array_to_check_in as $user_group_id) {
2734 if ($asset->
adminAccess(
'', Array($user_group_id))) {
2735 $effective_permission =
'Admin Access';
2740 }
else if ($effective_permission !=
'Write Access' && $asset->
writeAccess(
'', Array($user_group_id), FALSE)) {
2741 $effective_permission =
'Write Access';
2747 }
else if ($effective_permission ==
'' && $asset->
readAccess(Array($user_group_id))) {
2748 $effective_permission =
'Read Access';
2757 'name' => $asset->name,
2758 'short_name' => $asset->short_name,
2760 'type_code' => $asset->
type(),
2761 'type' => str_replace(
'_',
' ', get_class($asset)),
2762 'icon_path' => $am->getAssetIconURL($asset->
type()),
2763 'data_path' => $asset->data_path,
2764 'web_path' => $asset->
getURL(),
2766 'created' => $asset->created,
2767 'created_userid' => $asset->created_userid,
2768 'created_username' => ($created_user ===
'Root User' || $created_user ===
'Undefined' || $created_user ===
'Unknown User') ? $created_user : $created_user->name,
2769 'updated' => ($updated_user ===
'Never Updated' || $updated_user ===
'Unknown User') ? $updated_user : $asset->updated,
2770 'updated_userid' => ($updated_user ===
'Never Updated' || $updated_user ===
'Unknown User') ? $updated_user : $updated_user->id,
2771 'updated_username' => ($updated_user ===
'Never Updated' || $updated_user ===
'Unknown User') ? $updated_user : $updated_user->name,
2772 'published' => ($published_user ===
'Never Published' || $published_user ===
'Unknown User') ? $published_user : $asset->published,
2773 'published_userid' => ($published_user ===
'Never Published' || $published_user ===
'Unknown User') ? $published_user : $published_user->id,
2774 'published_username' => ($published_user ===
'Never Published' || $published_user ===
'Unknown User') ? $published_user : $published_user->name,
2775 'status_changed' => ($status_user ===
'Never Changed' || $status_user ===
'Unknown User') ? $status_user : $asset->status_changed,
2776 'status_changed_userid' => ($status_user ===
'Never Changed' || $status_user ===
'Unknown User') ? $status_user : $status_user->id,
2777 'status_changed_username' => ($status_user ===
'Never Changed' || $status_user ===
'Unknown User') ? $status_user : $status_user->name,
2778 'maximum_perm_on_asset' => $effective_permission,
2781 foreach($am->getAssetTypeAttributes($asset->
type()) as $name => $type) {
2782 if(($add_more_attributes || isset($data[$name])) && $name !=
'api_key' && $type[
'type'] !=
'password') {
2783 $value = $asset->
attr($name);
2784 $data[$name] = $value;
2807 function createLink($parent, $child, $link_type, $link_value, $sort_order, $is_dependant, $is_exclusive)
2809 if (!empty($parent) && !empty($child)) {
2811 $am = $GLOBALS[
'SQ_SYSTEM']->am;
2813 $parent = $am->getAsset($parent);
2814 $child = $am->getAsset($child);
2815 $new_id = $am->createAssetLink($parent, $child, $link_type, $link_value, $sort_order, $is_dependant, $is_exclusive);
2818 if (!is_null($result))
return Array(
'error' =>
'Unable to Update Lookups on the Asset #'.$child->id.
' and its Childrens');
2821 return Array(
'error' =>
'Unable to create link');
2824 'link_id' => $new_id,
2827 $this->
returnError(
'Missing information to create link. Make sure parent id and child are provided');
2844 function removeLink($parent, $child, $link_type=NULL, $link_value=NULL)
2846 $am = $GLOBALS[
'SQ_SYSTEM']->am;
2849 $linkid = $this->
getLinkId($parent, $child, $link_type, $link_value, TRUE);
2852 $data[
'error'] =
'Parent Asset #'.$parent.
' and Child Asset #'.$child.
' do not have a valid link for given Link Type and Link Value';
2856 $parent_asset = $am->getAsset($parent);
2857 $child_asset = $am->getAsset($child);
2859 if ($linkid[
'locked']) {
2860 $data[
'error'] =
'Link #"'.$linkid[
'link_id'].
'" between Asset "'.$child_asset->name.
'" (#'.$child_asset->id.
') and Asset "'.$parent_asset->name.
'" (#'.$parent_asset->id.
') " cannot be deleted, link is locked';
2865 $am = $GLOBALS[
'SQ_SYSTEM']->am;
2867 if ($linkid[
'link_id'] !=
'') {
2868 $link = $am->getLinkById($linkid[
'link_id']);
2870 if (!empty($link)) {
2872 $am->acquireLock($link[
'majorid'],
'all');
2873 $am->acquireLock($link[
'minorid'],
'all');
2874 $parents = $am->getLinks($link[
'minorid'], SQ_SC_LINK_SIGNIFICANT,
'', TRUE,
'minor');
2878 if (count($parents) > 1 || !($link_type & SQ_SC_LINK_SIGNIFICANT)) {
2880 $result = $am->deleteAssetLink($linkid[
'link_id']);
2883 $result = $am->trashAsset($link[
'minorid'], TRUE);
2887 if (!is_null($result_from_update)) $this->
returnError(
'Unable to Update Lookups on the Asset "'.$child_asset->name.
'" (#'.$child.
') and its Childrens');
2890 $am->releaseLock($link[
'minorid'],
'all');
2891 $am->releaseLock($link[
'majorid'],
'all');
2894 $data[
'success'] =
'Link #"'.$linkid[
'link_id'].
'" between Asset "'.$child_asset->name.
'" (#'.$child_asset->id.
') and Asset "'.$parent_asset->name.
'" (#'.$parent_asset->id.
') " has been sucessfully removed';
2897 $data[
'error'] =
'Unable to delete link';
2902 $data[
'error'] =
'The link id that was provided is invalid';
2907 $data[
'error'] =
'The link id provided is empty';
2931 function moveLink($old_parent_id, $asset_id_to_move, $old_link_type=SQ_LINK_TYPE_1, $old_link_value=
'', $new_parent_id, $new_link_type=SQ_LINK_TYPE_1, $new_link_value=
'', $new_position)
2934 if (!($new_link_type & SQ_SC_LINK_SIGNIFICANT)) $new_link_type = SQ_LINK_TYPE_1;
2935 if (!($old_link_type & SQ_SC_LINK_SIGNIFICANT)) $old_link_type = SQ_LINK_TYPE_1;
2937 if (!empty($old_parent_id) && !empty($asset_id_to_move) && !empty($new_parent_id)) {
2939 $link_id = $this->
getLinkId($old_parent_id, $asset_id_to_move, $old_link_type, $old_link_value, TRUE);
2942 $data[
'error'] =
'Parent Asset #'.$old_parent_id.
' and Child Asset #'.$asset_id_to_move.
' do not have a valid link for given Link Type and Link Value';
2946 if ($link_id[
'locked']) {
2947 $this->
returnError(
'Link "'.$link_id[
'link_id'].
'" cannot be moved, link is locked');
2950 $new_link_id = $GLOBALS[
'SQ_SYSTEM']->am->moveLink($link_id[
'link_id'], $new_parent_id, $new_link_type, $new_position, $new_link_value);
2952 if (!empty($new_link_id)) {
2955 if (!is_null($result)) $this->
returnError(
'Unable to Update Lookups on the Asset #'.$asset_id_to_move.
' and its Childrens');
2957 'link_id' => $new_link_id,
2963 $this->
returnError(
'Please provide a valid current parent id, asset id to move, and new parent id');
2984 function updateLink($parent, $child, $existing_link_type=SQ_LINK_TYPE_1, $existing_link_value=
'', $link_type=SQ_LINK_TYPE_1, $link_value=
'', $sort_order, $locked=TRUE)
2986 $am = $GLOBALS[
'SQ_SYSTEM']->am;
2988 if (!empty($parent) && !empty($child)) {
2990 $link_id = $this->
getLinkId($parent, $child, $existing_link_type, $existing_link_value, TRUE);
2991 $parent_asset = $am->getAsset($parent);
2992 $child_asset = $am->getAsset($child);
2995 $data[
'error'] =
'Parent Asset #'.$parent.
' and Child Asset #'.$child.
' do not have a valid link for given Link Type and Link Value';
3002 $current_is_sig = (bool) ((
int) $link_id[
'link_type'] & SQ_SC_LINK_SIGNIFICANT);
3003 $new_is_sig = (bool) ($link_type & SQ_SC_LINK_SIGNIFICANT);
3004 if ($current_is_sig !== $new_is_sig) {
3005 if ($am->deleteAssetLink($link_id[
'link_id'], FALSE)) {
3012 $new_link_id = $am->createAssetLink($parent_asset, $child_asset, $link_type, $link_value, $sort_order, $link_id[
'is_dependant'], $link_id[
'is_exclusive'], FALSE, $lock);
3016 $new_link_id = $am->updateLink($link_id[
'link_id'], $link_type, $link_value, $sort_order, $locked);
3019 if (!empty($new_link_id)) {
3020 $response[
'success'] =
'Link #'.$link_id[
'link_id'].
' between Asset "'.$child_asset->name.
'" (#'.$child_asset->id.
') and Asset "'.$parent_asset->name.
'" (#'.$parent_asset->id.
') has been updated';
3023 $response[
'error'] =
'Unable to update Link #'.$link_id[
'link_id'].
' between Asset "'.$child_asset->name.
'" (#'.$child_asset->id.
') and Asset "'.$parent_asset->name.
'" (#'.$parent_asset->id.
')';
3027 $this->
returnError(
'Please enter a valid parent id and child id');
3045 if (!empty($id) && !empty($level)) {
3047 $am = $GLOBALS[
'SQ_SYSTEM']->am;
3051 $level = SQ_PERMISSION_READ;
3052 $level_name =
'read';
3053 }
else if ($level == 2) {
3054 $level = SQ_PERMISSION_WRITE;
3055 $level_name =
'write';
3056 }
else if ($level == 3) {
3057 $level = SQ_PERMISSION_ADMIN;
3058 $level_name =
'admin';
3061 $permissions = $am->getPermission($id, $level, NULL, FALSE, FALSE, TRUE);
3062 if (empty($permissions)) {
3063 $this->
returnError(
'There are no '.$level_name.
' permissions set for id #'.$id);
3067 foreach ($permissions as $key => $access) {
3069 $granted = ($access == 0) ?
'denied' :
'granted';
3070 $asset = $am->getAsset($key);
3072 $data[$granted][$key][
'id'] = $key;
3073 $data[$granted][$key][
'name'] = $asset->name;
3074 if (isset($asset->vars[
'username'])) {
3075 $data[$granted][$key][
'user_name'] = $asset->attr(
'username');
3077 $data[$granted][$key][
'type'] = $asset->type();
3080 if ($asset->type() ==
'user_group') {
3091 $this->
returnError(
'Asset ID or Access Level is not valid. Please provide a valid AssetID and Access Level');
3109 $am = $GLOBALS[
'SQ_SYSTEM']->am;
3111 $group_children = $am->getChildren($key,
'', TRUE, NULL, NULL, NULL, TRUE, NULL, 1);
3112 foreach ($group_children as $children => $child_id) {
3113 $child = $am->getAsset($children);
3114 $children_arr[$child->id] = Array(
3116 'name' => $child->name,
3117 'type' => $child->type(),
3118 'username' => $child->attr(
'username'),
3122 return $children_arr;
3142 function getParents($id, $level, $type_codes=Array(), $link_types=Array(), $link_values=Array(), $also_attributes=FALSE)
3145 $am = $GLOBALS[
'SQ_SYSTEM']->am;
3146 $parent_arr = Array();
3148 $parents = $am->getParents($id,
'', TRUE, NULL, NULL, TRUE, NULL, $level);
3149 foreach ($parents as $parent => $parent_type_code) {
3151 if(!empty($type_codes) && !in_array($parent_type_code, $type_codes)) {
3152 unset($childrens[$children]);
3155 $parent_asset = $am->getAsset($parent);
3158 if (!$this->
hasLink($parent, $id)) {
3159 $show[
'link_id'] = NULL;
3160 $show[
'link_type'] = NULL;
3161 $show[
'is_dependant'] = NULL;
3162 $show[
'is_exclusive'] = NULL;
3163 $show[
'sort_order'] = NULL;
3164 $show[
'link_value'] = NULL;
3165 $show[
'locked'] = NULL;
3167 $show_link = $this->
getLinkId($parent, $id, NULL, NULL, TRUE);
3169 $data[
'error'] =
'Parent Asset #'.$parent.
' and Child Asset #'.$id.
' do not have a valid link';
3174 if (!empty($link_values) && !in_array($show_link[
'value'], $link_values)) {
3175 unset($childrens[$children]);
3179 if(!empty($link_types)) {
3181 foreach($link_types as $link_type) {
3182 if(defined($link_type) && (constant($link_type) == $show_link[
'link_type'])) {
3184 }
else if (!defined($link_type)) {
3189 unset($childrens[$children]);
3194 $show[
'link_id'] = $show_link[
'link_id'];
3195 $show[
'link_type'] = $show_link[
'link_type'];
3196 $show[
'is_dependant'] = $show_link[
'is_dependant'];
3197 $show[
'is_exclusive'] = $show_link[
'is_exclusive'];
3198 $show[
'sort_order'] = $show_link[
'sort_order'];
3199 $show[
'link_value'] = $show_link[
'value'];
3200 $show[
'locked'] = $show_link[
'locked'];
3202 $parent_arr[] = array_merge($this->
getGeneralInfo($parent_asset, $also_attributes), $show);
3226 function getChildren($id, $level, $type_codes=Array(), $link_types=Array(), $link_values=Array(), $also_attributes=FALSE)
3229 $am = $GLOBALS[
'SQ_SYSTEM']->am;
3230 $children_arr =Array();
3231 if (empty($type_codes)) $type_codes =
'';
3232 foreach ($link_types as $index => $link_type) {
3233 if(defined($link_type)) $link_types[$index] = constant($link_type);
3236 $children = $am->getChildren($id, $type_codes, TRUE, NULL, NULL, NULL, TRUE, NULL, $level, TRUE, NULL, $link_types);
3238 foreach ($children as $child_id => $child_info) {
3241 if (!$this->
hasLink($id, $child_id)) {
3242 $show[
'link_id'] = NULL;
3243 $show[
'link_type'] = NULL;
3244 $show[
'is_dependant'] = NULL;
3245 $show[
'is_exclusive'] = NULL;
3246 $show[
'sort_order'] = NULL;
3247 $show[
'link_value'] = NULL;
3248 $show[
'locked'] = NULL;
3250 $show_link = $this->
getLinkId($id, $child_id, NULL, NULL, TRUE);
3253 if (!empty($link_values) && !in_array($show_link[
'value'], $link_values)) {
3254 unset($children[$child_id]);
3258 $show[
'link_id'] = $show_link[
'link_id'];
3259 $show[
'link_type'] = $show_link[
'link_type'];
3260 $show[
'is_dependant'] = $show_link[
'is_dependant'];
3261 $show[
'is_exclusive'] = $show_link[
'is_exclusive'];
3262 $show[
'sort_order'] = $show_link[
'sort_order'];
3263 $show[
'link_value'] = $show_link[
'value'];
3264 $show[
'locked'] = $show_link[
'locked'];
3267 $sub_children = $am->getLinks($child_id, SQ_SC_LINK_ALL);
3268 $sub_dependent_count = $sub_non_dependent_count = $sub_shadow_child_count = 0;
3270 foreach ($sub_children as $idx => $sub_child) {
3272 if ($sub_child[
'link_type'] == SQ_LINK_NOTICE) $sub_shadow_child_count++;
3273 else if ($sub_child[
'is_dependant']) $sub_dependent_count++;
3274 else if ($sub_child[
'is_dependant'] == 0) $sub_non_dependent_count++;
3277 $show[
'direct_dependant_children'] = $sub_dependent_count;
3278 $show[
'direct_non_dependant_children'] = $sub_non_dependent_count;
3279 $show[
'direct_notice_linked_children'] = $sub_shadow_child_count;
3281 $child = $am->getAsset($child_id);
3282 $children_arr[] = array_merge($this->
getGeneralInfo($child, $also_attributes), $show);
3286 return $children_arr;
3303 $am = $GLOBALS[
'SQ_SYSTEM']->am;
3304 $response = Array();
3307 foreach($ids as $id) {
3308 $already_in_trash = $am->assetInTrash($id, TRUE);
3309 $asset = $am->getAsset($id);
3314 foreach ($parents as $parentid => $parent_link_info) {
3315 if($parent_link_info[
'locked'] ==
'1') $locked = TRUE;
3318 if ($already_in_trash) {
3319 $response[] =
'Asset "'.$asset->name.
'" (#'.$asset->id.
') is already in the trash';
3320 }
else if ($locked && $asset->writeAccess()){
3322 foreach ($parents as $parentid => $parent_link_info) {
3323 $parent_asset = $am->getAsset($parentid);
3324 if ($parent_link_info[
'locked'] ==
'1') {
3326 $response[] =
'Link between Asset "'.$asset->name.
'" (#'.$asset->id.
') and Asset "'.$parent_asset->name.
'" (#'.$parent_asset->id.
') is locked';
3329 if($am->deleteAssetLink($parent_link_info[
'link_id'])) {
3330 $response[] =
'Successfully unlinked link between Asset "'.$asset->name.
'" (#'.$asset->id.
') and Asset "'.$parent_asset->name.
'" (#'.$parent_asset->id.
')';
3334 }
else if ($asset->writeAccess()) {
3336 $am->acquireLock($id,
'all');
3337 $result = $am->trashAsset($id, TRUE);
3339 $response[] =
'Could not move Asset "'.$asset->name.
'" (#'.$asset->id.
') to Trash';
3343 if (!is_null($result_from_update)) {
3344 $response[] =
'Asset deleted but unable to Update Lookups on the Asset "'.$asset->name.
'" (#'.$asset->id.
')';
3347 $response[] =
'Asset "'.$asset->name.
'" (#'.$asset->id.
') successfully moved to Trash';
3350 $am->releaseLock($id,
'all');
3352 $response[] =
'Not enough permision to delete Asset "'.$asset->name.
'" (#'.$asset->id.
')';
3357 $this->
returnError(
'Please provide a valid Asset ID');
3378 if (!empty($assetid) && !empty($attr_name) && !empty($attr_val)) {
3379 if (count($attr_name) != count($attr_val) ) $this->
returnError(
'Please provide Attributes and corresponding values correctly');
3381 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
3382 $am = $GLOBALS[
'SQ_SYSTEM']->am;
3385 $am->acquireLock($assetid,
'attributes');
3386 for ($i = 0; $i < count($attr_name); $i++ ) {
3387 $attributes = $am->getAssetTypeAttributes($asset->type());
3388 if ($attr_name[$i] !=
'' && array_key_exists($attr_name[$i], $attributes)) {
3390 $attr_set = $asset->setAttrValue($attr_name[$i], $attr_val[$i]);
3392 $attr_type = $attributes[$attr_name[$i]][
'type'];
3393 $data[] =
'Attribute "'.$attr_name[$i].
'"(of type "'.$attr_type.
'") could not be set to "'.$attr_val[$i].
'" for Asset "'.$asset->name.
'" (#'.$assetid.
')';
3396 }
else if (!array_key_exists($attr_name[$i], $attributes)){
3397 $data[] =
'Attribute "'.$attr_name[$i].
'" does not exist for Asset "'.$asset->name.
'" (#'.$assetid.
')';
3400 if (!$asset->saveAttributes()) {
3401 $data[] =
'Attribute "'.$attr_name[$i].
'" could not be set to "'.$attr_val[$i].
'" for Asset "'.$asset->name.
'" (#'.$assetid.
')';
3403 $data[] =
'Attribute "'.$attr_name[$i].
'" has been successfully set to "'.$attr_val[$i].
'" for Asset "'.$asset->name.
'" (#'.$assetid.
')';
3406 $am->releaseLock($assetid,
'attributes');
3407 $am->forgetAsset($asset);
3411 $this->
returnError(
'Please make sure to provide an Asset ID, Attribute Name and Attribute Value');
3429 if (!empty($assetid) && !empty($fieldid)) {
3430 if (count($fieldid) != count($new_value) ) $this->
returnError(
'Please provide Metadata fieldids and corresponding values correctly');
3435 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
3436 $am = $GLOBALS[
'SQ_SYSTEM']->am;
3438 $am->acquireLock($assetid,
'metadata');
3440 $regen_all_contexts = FALSE;
3441 for ($i = 0; $i < count($fieldid); $i++ ) {
3443 $field = $am->getAsset($fieldid[$i]);
3445 $this->
returnError(
'The Field ID provided does not belong to a metadata field');
3448 if (!$regen_all_contexts && (!$field->attr(
'is_contextable') || $field instanceof
Metadata_Field_Select)) {
3449 $regen_all_contexts = TRUE;
3452 $field_name = $field->attr(
'name');
3453 $metadata_info = Array (
3454 $fieldid[$i] => Array (
3456 'name' => $field_name,
3457 'value' => $new_value[$i],
3462 if (!$mm->setMetadata($assetid, $metadata_info)) $s_result = FALSE;
3465 $am->releaseLock($assetid,
'metadata');
3470 $this->
returnError(
'Unable to set Matadata for Asset #'.$assetid);
3475 if ($regen_all_contexts) {
3476 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
3477 foreach ($all_contexts as $contextid => $context_data) {
3478 if (!$mm->generateContentFile($assetid, FALSE, $contextid)) {
3484 if (!$mm->generateContentFile($assetid)) $g_result = FALSE;
3487 if ($s_result && $g_result) {
3490 $this->
returnError(
'Unable To Regenerate Metadata For Asset #'.$assetid);
3494 $this->
returnError(
'Please provide both AssetID and FieldID of the metadata field');
3513 function getLinkId($parent, $child, $link_type=SQ_LINK_TYPE_1, $link_value=NULL, $all_info = FALSE)
3515 if (!empty($parent) && !empty($child)) {
3516 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($parent, $child, $link_type, $link_value,
'major', TRUE);
3519 }
else if (count($link) > 1) {
3520 $this->
returnError(
'More than one link found between Parent Asset #'.$parent.
' and Child Asset #'.$child.
', please filter out with help of Link value and Link Type');
3526 $data_array[
'link_id'] = array_get_index($link,
'linkid', 0);
3530 $data_array = Array (
3531 'link_id' => isset($link[
'linkid']) ? $link[
'linkid'] :
'',
3532 'minorid' => isset($link[
'minorid']) ? $link[
'minorid'] :
'',
3533 'majorid' => $parent,
3534 'value' => isset($link[
'value']) ? $link[
'value'] :
'',
3535 'link_type' => isset($link[
'link_type']) ? $link[
'link_type'] :
'',
3536 'sort_order' => isset($link[
'sort_order']) ? $link[
'sort_order'] :
'',
3537 'is_dependant' => isset($link[
'is_dependant']) ? $link[
'is_dependant'] :
'',
3538 'is_exclusive' => isset($link[
'is_exclusive']) ? $link[
'is_exclusive'] :
'',
3539 'locked' => isset($link[
'locked']) ? $link[
'locked'] :
'',
3544 $this->
returnError(
'Please provide a parent id and child id');
3562 if (!empty($parent) && !empty($child)) {
3563 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($parent, $child);
3564 $linkid = array_get_index($link,
'linkid', 0);
3565 if (!empty($linkid)) {
3593 function createAsset($id, $type_code, $asset_name, $link_type=1, $link_value, $sort_order, $is_dependant=0, $is_exclusive=0, $extra_attributes=FALSE, $attribute_values)
3596 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
3597 $am = $GLOBALS[
'SQ_SYSTEM']->am;
3599 $pa = $am->getAsset($id);
3601 $type_code = strtolower($type_code);
3602 if (!$am->installed($type_code)) {
3603 return Array(
'error' =>
'Asset type requested to create not installed on the system');
3607 $types = $this->
attr(
'types');
3608 if (!empty($types)) {
3609 if (!isset($types[$type_code])) {
3610 return Array(
'error' =>
'Asset type requested to create is not allowed via API');
3615 $restrict = $this->
attr(
'types_restriction');
3616 if (!empty($restrict)) {
3618 return Array(
'error' =>
'Parent asset passed does not match the restricted Parents type configured');
3622 $am->includeAsset($type_code);
3624 $object_name = str_replace(
' ',
'_', ucwords(str_replace(
'_',
' ', $type_code)));
3625 $asset =
new $object_name();
3626 $asset->setAttrValue(
'name', $asset_name);
3627 $request_info[
'asset'] = $pa;
3629 $link_info = Array (
3631 'name' => $asset_name,
3632 'link_type' => $link_type,
3633 'value' => $link_value,
3634 'sort_order' => $sort_order,
3635 'is_dependant' => $is_dependant,
3636 'is_exclusive' => $is_exclusive,
3640 if ($extra_attributes && $this->
attr(
'create_attributes')) {
3642 $attributes = $am->getAssetTypeAttributes($type_code);
3643 foreach($attribute_values as $name => $value) {
3644 if (array_key_exists($name, $attributes) && $name !== $link_info[$name]) {
3646 $asset->setAttrValue($name, $value);
3651 $link_id = $asset->create($link_info);
3655 $am->acquireLock($asset->id,
'attributes');
3656 $asset->saveAttributes();
3657 $am->releaseLock($asset->id,
'attributes');
3659 'name' => $asset_name,
3661 'link_id' => $link_id,
3665 return Array(
'error' =>
'Error occured while asset creation');
3681 if (array_key_exists($parent->type(), $this->
attr(
'types_restriction'))) {
3704 if (in_array($asset->id, $root_nodes) || in_array(
'1', $root_nodes))
return TRUE;
3707 if (strpos($asset->id,
':') !== FALSE) {
3708 $matches = explode(
':', $asset->id);
3709 $test_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($matches[0]);
3711 $test_asset = $asset;
3714 $is_under = $GLOBALS[
'SQ_SYSTEM']->am->isUnderRootNodes($test_asset->id, $root_nodes);
3729 $root_nodes = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE,
'', TRUE,
'major',
'root');
3731 foreach ($root_nodes as $node) {
3732 $node_id = array_get_index($node,
'minorid', 0);
3733 if (!empty($node_id)) $nodes[] = $node_id;
3749 require_once SQ_SYSTEM_ROOT.
'/core/hipo/jobs/hipo_job_update_lookups.inc';
3750 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
3752 $vars = Array(
'assetids' => Array($assetid));
3753 $hh->freestyleHipo(
'hipo_job_update_lookups', $vars);
3769 require_once SQ_INCLUDE_PATH.
'/general.inc';
3770 $return_array = Array();
3771 $se_level_keywords = Array();
3773 foreach ($keywords as $index => $keyword) {
3774 if(!(strpos($keyword,
'%asset_') === 0 || strpos($keyword,
'%globals_') === 0) ) {
3776 $se_level_keywords[] = $keyword;
3777 unset($keywords[$index]);
3781 foreach ($keywords as $keyword) {
3782 $trimmed_keyword = trim($keyword,
'%');
3783 if (strpos($keyword,
'%globals_') === 0) {
3784 $return_array[$trimmed_keyword] = replace_global_keywords($keyword);
3785 }
else if (strpos($keyword,
'%asset_') === 0 ) {
3786 $return_array[$trimmed_keyword] = $asset->getKeywordReplacement($trimmed_keyword);
3788 if (empty($return_array[$trimmed_keyword]) || $return_array[$trimmed_keyword] ==
'%'.$trimmed_keyword.
'%') {
3789 $return_array[$trimmed_keyword] =
'Could not get replacement for keyword : '.$trimmed_keyword ;
3793 if(!empty($se_level_keywords)) {
3795 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'layout');
3798 require_once SQ_INCLUDE_PATH.
'/limbo_outputter.inc';
3801 require_once SQ_SYSTEM_ROOT.
'/core/include/asset_edit_interface.inc';
3808 foreach ($se_level_keywords as $index => $se_keyword) {
3809 $se_keyword = trim($se_keyword,
'%');
3810 $layout->layout_keywords = $layout->getLayoutKeywordsArray(Array ($se_keyword));
3812 $screen_sort_order = Array (
'0' =>
'custom',
'1' =>
'screen');
3813 $return_array[$se_keyword] = $ei->getKeywordsReplacementsForPaint($asset, $limbo_outputter, $layout, $screen_sort_order, FALSE, TRUE);
3816 $pattern =
'/(.)(%)([asset_|globals_]?[a-zA-Z0-9_:\.\^]*)(%)(.)/';
3817 $replacement =
'$1%$3%$5';
3818 $return_array[$se_keyword] = preg_replace($pattern, $replacement ,$return_array[$se_keyword]);
3819 $pattern_2 =
'/([\"|\']{0}%)([asset_|globals_]?[a-zA-Z0-9_:\.\^]*)(%[\"|\']{0})/';
3820 $replacement_2 =
'%$2%';
3821 $return_array[$se_keyword] = preg_replace($pattern_2, $replacement_2 ,$return_array[$se_keyword]);
3823 if (empty($return_array[$se_keyword])) $return_array[$se_keyword] =
'Could not get replacement for keyword : '.$se_keyword ;
3827 return $return_array;
3846 $return_array = Array();
3849 if(!in_array($screen, $GLOBALS[
'SQ_SYSTEM']->am->getLockTypes($asset->id,
'all')) && $screen !=
'all') {
3850 $return_array[] =
'"'.$screen.
'" type lock doesnt exist for Asset "'.$asset->name.
'" (#'.$asset->id.
').';
3851 return $return_array;
3858 if (empty($locks) || (!empty($locks) && $force_acquire) || (!empty($locks) && $screen ==
'all')) {
3859 $job_dir = SQ_SYSTEM_ROOT.
'/core/hipo/jobs';
3860 require_once $job_dir.
'/hipo_job_acquire_locks.inc';
3861 $init_hipo =
new Hipo_Job_Acquire_Locks();
3862 $running_vars = Array(
3863 'assetids' => Array($asset->id),
3864 'lock_type' => $screen,
3865 'forceably_acquire' => $force_acquire,
3866 'dependants_only' => $dependants_only,
3868 $init_hipo->setRunningVars($running_vars);
3869 $init_hipo->_steps = $init_hipo->getInitialStepData();
3870 if (!$init_hipo->prepare()) {
3871 $return_array[
'error'] =
'Could not initialise HIPO job';
3872 return $return_array;
3874 set_error_handler(Array(&$init_hipo,
'_errorHandler'));
3875 $init_hipo->freestyle();
3876 restore_error_handler();
3877 $return_array = $init_hipo->getErrors();
3882 if (!$GLOBALS[
'SQ_SYSTEM']->am->updateLock($asset->id, $screen)) {
3883 $return_array[
'error'] =
'Unable to update locks for Asset '.$asset->name.
'('.$asset->id.
')';
3885 $return_array[] =
'Locks for \''.$screen.
'\' screen
for Asset '.$asset->name.'(
'.$asset->id.') successfully updated
';
3889 return array_unique($return_array);
3891 }//end acquireLocks()
3904 public function getLocksInfo($assetid, $lock_types)
3906 $return_array = $GLOBALS['SQ_SYSTEM
']->am->getLockInfo($assetid, $lock_types);
3907 foreach ($return_array as $screen => $lock_info){
3908 if (empty($lock_info)){
3909 unset($return_array[$screen]);
3912 if($lock_types != 'all
' && !empty($return_array) && !(array_key_exists('attributes
', $return_array) || array_key_exists('links
', $return_array))) $return_array = Array ($return_array);
3914 return $return_array;
3916 }//end getLocksInfo()
3931 public function setAssetStatus(Asset $asset, $status, $cascade, $current_status_desc, $to_be_status_desc, $workflow_stream)
3934 $return_array = Array();
3935 //if status is being set to something we are not allowed to set then start complaining
3936 if(!(in_array($status, array_keys($asset->getAvailableStatii()))) && !($status == $asset->status && $cascade) ) {
3937 $return_array[] = '"'.$to_be_status_desc.'" is not a valid option
for the
"'.$asset->name.'" asset (#
'.$asset->id.') in its current
"'.$current_status_desc.'" state
';
3938 return $return_array;
3941 //lets prepare a hipo running vars
3942 $job_dir = SQ_SYSTEM_ROOT.'/core/hipo/jobs
';
3943 require_once $job_dir.'/hipo_job_edit_status.inc
';
3944 $init_hipo = new HIPO_Job_Edit_Status();
3945 $running_vars = Array(
3946 'assetid
' => $asset->id,
3947 'new_status
' => $status,
3948 'dependants_only
' => !$cascade,
3950 if ($workflow_stream !== 'SQ_USE_DEFAULT
') {
3951 $running_vars['workflow_stream
'] = $workflow_stream;
3954 $init_hipo->setRunningVars($running_vars);
3955 $init_hipo->_steps = $init_hipo->getInitialStepData();
3956 if (!$init_hipo->prepare()) {
3957 $return_array[] = 'Could not initialise HIPO job
';
3958 return $return_array;
3960 set_error_handler(Array(&$init_hipo, '_errorHandler
'));
3961 $init_hipo->freestyle();
3962 restore_error_handler();
3963 $return_array = $init_hipo->getErrors();
3965 return $return_array;
3967 }//end setAssetStatus()
3980 function getMetadataSchema($asset, $granted, $cascades)
3982 $return_array = Array();
3984 if (is_null($granted)) {
3988 $mm = $GLOBALS['SQ_SYSTEM
']->getMetadataManager();
3989 $schemas = $mm->getSchemas($asset->id, $granted, $cascades);
3990 if (!empty($schemas)) {
3991 foreach($schemas as $schema_id) {
3992 $return_array[$schema_id] = Array();
3993 $field_children = $GLOBALS['SQ_SYSTEM
']->am->getChildren($schema_id, 'metadata_field
', FALSE);
3994 foreach($field_children as $field_id => $field_type) {
3995 $return_array[$schema_id][$field_id] = $GLOBALS['SQ_SYSTEM
']->am->getAllAttributeValues($field_id, $field_type[0]['type_code
']);
3999 $return_array['error
'] = 'Asset #
'.$asset->id.' does not has any Metadata Schema
'.($granted ? 'applied
' : 'denied
') .' to it
';
4002 return $return_array;
4004 }//end getMetadataSchema()
4014 function returnError($error)
4017 trigger_error($error, E_USER_WARNING);
4019 // Send error as JSON so they are not confused why the function quit
4020 $data['error
'] = $error;
4022 // Send our data as JSON
4024 $this->returnJSON($data);
4027 }//end returnError()
4037 function returnJSON($data, $type='')
4039 // Are we allowed to send JSON? OR return JSON when the function is a 'get' OR on error which will be empty type
4040 if ($this->attr('allow_json
') || (!empty($type) && (strpos($type, 'get') === 0))) {
4041 // Send our data as JSON
4042 if (!empty($data)) {
4043 if (!function_exists('json_encode
')) {
4044 require_once 'Services/JSON.php
';
4045 $json = new Services_JSON();
4046 $output = $json->encode($data);
4047 if (Services_JSON::isError($output)) {
4048 $this->returnError($output);
4051 // all ISO characters have to be converted to UTF8 encoding
4052 if(SQ_CONF_DEFAULT_CHARACTER_SET == 'iso-8859-1
')
4053 $data = $this->array_utf8_encode_recursive($data);
4054 $output = json_encode($data);
4055 if (function_exists('json_last_error
') && (json_last_error() != JSON_ERROR_NONE)) {
4056 switch (json_last_error()) {
4057 case JSON_ERROR_DEPTH:
4058 $error = 'Maximum stack depth exceeded
';
4060 case JSON_ERROR_STATE_MISMATCH:
4061 $error = 'Underflow or the modes mismatch
';
4063 case JSON_ERROR_CTRL_CHAR:
4064 $error = 'Unexpected control character found
';
4066 case JSON_ERROR_SYNTAX:
4067 $error = 'Syntax error, malformed JSON
';
4069 case JSON_ERROR_UTF8:
4070 $error = 'Malformed UTF-8 characters, possibly incorrectly encoded
';
4073 $error = 'Unknown error
';
4076 $this->returnError($error);
4081 $output = preg_replace('/(%){1}(globals_[snippet|asset][_A-Za-z0-9\-:]*)(%){1}/
','%$2%
', $output);
4082 $GLOBALS['SQ_SYSTEM
']->setGlobalDefine('SQ_REPLACE_MYSOURCE_LEVEL_KEYWORDS
', FALSE);
4101 function getRandomFilename($file_name)
4103 $hash_file_name = hash('md5
', $file_name.time());
4104 $rand_position = rand(0, strlen($hash_file_name)-6);
4105 $tmp_file_name = substr($hash_file_name, $rand_position, 6);
4107 return $tmp_file_name;
4109 }//end getRandomFileName()
4120 function object2Array($obj)
4123 if (is_object($obj)) {
4124 foreach ($obj as $key => $value) {
4125 if (is_object($value)) {
4126 $array[$key] = $this->object2Array($value);
4128 $array[$key] = $value;
4137 }// end object2Array
4148 function array_utf8_encode_recursive($dat)
4150 if (is_string($dat)) {
4151 return utf8_encode($dat);
4154 if (is_object($dat)) {
4155 $ovs= get_object_vars($dat);
4157 foreach ($ovs as $k =>$v) {
4158 $new->$k= $this->array_utf8_encode_recursive($new->$k);
4163 if (!is_array($dat)) return $dat;
4165 foreach($dat as $i=>$d) {
4166 $ret[$i] = $this->array_utf8_encode_recursive($d);
4171 }//end array_utf8_encode_recursive