id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
34,500 | jon48/webtrees-lib | src/Webtrees/Module/Sosa/Model/SosaProvider.php | SosaProvider.getSosaListAtGeneration | public function getSosaListAtGeneration($gen){
if(!$this->is_setup) return array();
if(!$this->sosa_list_by_gen)
$this->sosa_list_by_gen = array();
if($gen){
if(!isset($this->sosa_list_by_gen[$gen])){
$this->sosa_list_by_gen[$gen] = Database::prepare(
'SELECT majs_sosa AS sosa, majs_i_id AS indi'.
' FROM `##maj_sosa`'.
' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
' AND majs_gen = :gen'.
' ORDER BY majs_sosa ASC')
->execute(array(
'tree_id' => $this->tree->getTreeId(),
'user_id' => $this->user->getUserId(),
'gen' => $gen
))
->fetchAssoc();
}
return $this->sosa_list_by_gen[$gen];
}
return array();
} | php | public function getSosaListAtGeneration($gen){
if(!$this->is_setup) return array();
if(!$this->sosa_list_by_gen)
$this->sosa_list_by_gen = array();
if($gen){
if(!isset($this->sosa_list_by_gen[$gen])){
$this->sosa_list_by_gen[$gen] = Database::prepare(
'SELECT majs_sosa AS sosa, majs_i_id AS indi'.
' FROM `##maj_sosa`'.
' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
' AND majs_gen = :gen'.
' ORDER BY majs_sosa ASC')
->execute(array(
'tree_id' => $this->tree->getTreeId(),
'user_id' => $this->user->getUserId(),
'gen' => $gen
))
->fetchAssoc();
}
return $this->sosa_list_by_gen[$gen];
}
return array();
} | [
"public",
"function",
"getSosaListAtGeneration",
"(",
"$",
"gen",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_setup",
")",
"return",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"sosa_list_by_gen",
")",
"$",
"this",
"->",
"sosa_list_by_gen",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"gen",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"sosa_list_by_gen",
"[",
"$",
"gen",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sosa_list_by_gen",
"[",
"$",
"gen",
"]",
"=",
"Database",
"::",
"prepare",
"(",
"'SELECT majs_sosa AS sosa, majs_i_id AS indi'",
".",
"' FROM `##maj_sosa`'",
".",
"' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'",
".",
"' AND majs_gen = :gen'",
".",
"' ORDER BY majs_sosa ASC'",
")",
"->",
"execute",
"(",
"array",
"(",
"'tree_id'",
"=>",
"$",
"this",
"->",
"tree",
"->",
"getTreeId",
"(",
")",
",",
"'user_id'",
"=>",
"$",
"this",
"->",
"user",
"->",
"getUserId",
"(",
")",
",",
"'gen'",
"=>",
"$",
"gen",
")",
")",
"->",
"fetchAssoc",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sosa_list_by_gen",
"[",
"$",
"gen",
"]",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals.
@param number $gen Generation
@return array Array of Sosa individuals | [
"Get",
"an",
"associative",
"array",
"of",
"Sosa",
"individuals",
"in",
"generation",
"G",
".",
"Keys",
"are",
"Sosa",
"numbers",
"values",
"individuals",
"."
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaProvider.php#L283-L306 |
34,501 | jon48/webtrees-lib | src/Webtrees/Module/Sosa/Model/SosaProvider.php | SosaProvider.getFamilySosaListAtGeneration | public function getFamilySosaListAtGeneration($gen){
if(!$this->is_setup) return array();
if(!$this->sosa_fam_list_by_gen)
$this->sosa_fam_list_by_gen = array();
if($gen){
if(!isset($this->sosa_fam_list_by_gen[$gen])){
$this->sosa_fam_list_by_gen[$gen] = Database::prepare(
'SELECT s1.majs_sosa AS sosa, f_id AS fam'.
' FROM `##families`'.
' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'.
' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'.
' WHERE s1.majs_sosa + 1 = s2.majs_sosa'.
' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'.
' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'.
' AND s1.majs_gen = :gen'.
' ORDER BY s1.majs_sosa ASC'
)
->execute(array(
'tree_id' => $this->tree->getTreeId(),
'user_id' => $this->user->getUserId(),
'gen' => $gen
))
->fetchAssoc();
}
return $this->sosa_fam_list_by_gen[$gen];
}
return array();
} | php | public function getFamilySosaListAtGeneration($gen){
if(!$this->is_setup) return array();
if(!$this->sosa_fam_list_by_gen)
$this->sosa_fam_list_by_gen = array();
if($gen){
if(!isset($this->sosa_fam_list_by_gen[$gen])){
$this->sosa_fam_list_by_gen[$gen] = Database::prepare(
'SELECT s1.majs_sosa AS sosa, f_id AS fam'.
' FROM `##families`'.
' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'.
' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'.
' WHERE s1.majs_sosa + 1 = s2.majs_sosa'.
' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'.
' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'.
' AND s1.majs_gen = :gen'.
' ORDER BY s1.majs_sosa ASC'
)
->execute(array(
'tree_id' => $this->tree->getTreeId(),
'user_id' => $this->user->getUserId(),
'gen' => $gen
))
->fetchAssoc();
}
return $this->sosa_fam_list_by_gen[$gen];
}
return array();
} | [
"public",
"function",
"getFamilySosaListAtGeneration",
"(",
"$",
"gen",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_setup",
")",
"return",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"sosa_fam_list_by_gen",
")",
"$",
"this",
"->",
"sosa_fam_list_by_gen",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"gen",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"sosa_fam_list_by_gen",
"[",
"$",
"gen",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sosa_fam_list_by_gen",
"[",
"$",
"gen",
"]",
"=",
"Database",
"::",
"prepare",
"(",
"'SELECT s1.majs_sosa AS sosa, f_id AS fam'",
".",
"' FROM `##families`'",
".",
"' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'",
".",
"' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'",
".",
"' WHERE s1.majs_sosa + 1 = s2.majs_sosa'",
".",
"' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'",
".",
"' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'",
".",
"' AND s1.majs_gen = :gen'",
".",
"' ORDER BY s1.majs_sosa ASC'",
")",
"->",
"execute",
"(",
"array",
"(",
"'tree_id'",
"=>",
"$",
"this",
"->",
"tree",
"->",
"getTreeId",
"(",
")",
",",
"'user_id'",
"=>",
"$",
"this",
"->",
"user",
"->",
"getUserId",
"(",
")",
",",
"'gen'",
"=>",
"$",
"gen",
")",
")",
"->",
"fetchAssoc",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sosa_fam_list_by_gen",
"[",
"$",
"gen",
"]",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families.
@param number $gen Generation
@return array Array of Sosa families | [
"Get",
"an",
"associative",
"array",
"of",
"Sosa",
"families",
"in",
"generation",
"G",
".",
"Keys",
"are",
"Sosa",
"numbers",
"for",
"the",
"husband",
"values",
"families",
"."
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaProvider.php#L314-L342 |
34,502 | jon48/webtrees-lib | src/Webtrees/Module/Sosa/Model/SosaProvider.php | SosaProvider.getMissingSosaListAtGeneration | public function getMissingSosaListAtGeneration($gen){
if(!$this->is_setup) return array();
if($gen){
return $this->sosa_list_by_gen[$gen] = Database::prepare(
'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'.
' FROM `##maj_sosa` schild'.
' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'.
' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'.
' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'.
' AND schild.majs_gen = :gen'.
' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'.
' ORDER BY schild.majs_sosa ASC')
->execute(array(
'tree_id' => $this->tree->getTreeId(),
'user_id' => $this->user->getUserId(),
'gen' => $gen - 1
))->fetchAll(\PDO::FETCH_ASSOC);
}
return array();
} | php | public function getMissingSosaListAtGeneration($gen){
if(!$this->is_setup) return array();
if($gen){
return $this->sosa_list_by_gen[$gen] = Database::prepare(
'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'.
' FROM `##maj_sosa` schild'.
' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'.
' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'.
' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'.
' AND schild.majs_gen = :gen'.
' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'.
' ORDER BY schild.majs_sosa ASC')
->execute(array(
'tree_id' => $this->tree->getTreeId(),
'user_id' => $this->user->getUserId(),
'gen' => $gen - 1
))->fetchAll(\PDO::FETCH_ASSOC);
}
return array();
} | [
"public",
"function",
"getMissingSosaListAtGeneration",
"(",
"$",
"gen",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_setup",
")",
"return",
"array",
"(",
")",
";",
"if",
"(",
"$",
"gen",
")",
"{",
"return",
"$",
"this",
"->",
"sosa_list_by_gen",
"[",
"$",
"gen",
"]",
"=",
"Database",
"::",
"prepare",
"(",
"'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'",
".",
"' FROM `##maj_sosa` schild'",
".",
"' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'",
".",
"' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'",
".",
"' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'",
".",
"' AND schild.majs_gen = :gen'",
".",
"' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'",
".",
"' ORDER BY schild.majs_sosa ASC'",
")",
"->",
"execute",
"(",
"array",
"(",
"'tree_id'",
"=>",
"$",
"this",
"->",
"tree",
"->",
"getTreeId",
"(",
")",
",",
"'user_id'",
"=>",
"$",
"this",
"->",
"user",
"->",
"getUserId",
"(",
")",
",",
"'gen'",
"=>",
"$",
"gen",
"-",
"1",
")",
")",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals.
@param number $gen Generation
@return array Array of Sosa individuals | [
"Get",
"an",
"associative",
"array",
"of",
"Sosa",
"individuals",
"in",
"generation",
"G",
"who",
"are",
"missing",
"parents",
".",
"Keys",
"are",
"Sosa",
"numbers",
"values",
"individuals",
"."
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaProvider.php#L350-L369 |
34,503 | jon48/webtrees-lib | src/Webtrees/Module/Sosa/Model/SosaProvider.php | SosaProvider.getTotalIndividuals | public function getTotalIndividuals() {
if(!$this->is_setup) return 0;
return Database::prepare(
'SELECT COUNT(*) FROM `##individuals`' .
' WHERE i_file = :tree_id')
->execute(array('tree_id' => $this->tree->getTreeId()))
->fetchOne() ?: 0;
} | php | public function getTotalIndividuals() {
if(!$this->is_setup) return 0;
return Database::prepare(
'SELECT COUNT(*) FROM `##individuals`' .
' WHERE i_file = :tree_id')
->execute(array('tree_id' => $this->tree->getTreeId()))
->fetchOne() ?: 0;
} | [
"public",
"function",
"getTotalIndividuals",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_setup",
")",
"return",
"0",
";",
"return",
"Database",
"::",
"prepare",
"(",
"'SELECT COUNT(*) FROM `##individuals`'",
".",
"' WHERE i_file = :tree_id'",
")",
"->",
"execute",
"(",
"array",
"(",
"'tree_id'",
"=>",
"$",
"this",
"->",
"tree",
"->",
"getTreeId",
"(",
")",
")",
")",
"->",
"fetchOne",
"(",
")",
"?",
":",
"0",
";",
"}"
] | How many individuals exist in the tree.
@return int | [
"How",
"many",
"individuals",
"exist",
"in",
"the",
"tree",
"."
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaProvider.php#L414-L421 |
34,504 | jon48/webtrees-lib | src/Webtrees/Module/Sosa/Model/SosaProvider.php | SosaProvider.getSosaCount | public function getSosaCount(){
if(!$this->is_setup) return 0;
return Database::prepare(
'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' .
' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
->execute(array(
'tree_id' => $this->tree->getTreeId(),
'user_id' => $this->user->getUserId()
))->fetchOne() ?: 0;
} | php | public function getSosaCount(){
if(!$this->is_setup) return 0;
return Database::prepare(
'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' .
' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
->execute(array(
'tree_id' => $this->tree->getTreeId(),
'user_id' => $this->user->getUserId()
))->fetchOne() ?: 0;
} | [
"public",
"function",
"getSosaCount",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_setup",
")",
"return",
"0",
";",
"return",
"Database",
"::",
"prepare",
"(",
"'SELECT COUNT(majs_sosa) FROM `##maj_sosa`'",
".",
"' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'",
")",
"->",
"execute",
"(",
"array",
"(",
"'tree_id'",
"=>",
"$",
"this",
"->",
"tree",
"->",
"getTreeId",
"(",
")",
",",
"'user_id'",
"=>",
"$",
"this",
"->",
"user",
"->",
"getUserId",
"(",
")",
")",
")",
"->",
"fetchOne",
"(",
")",
"?",
":",
"0",
";",
"}"
] | Get the total Sosa count for all generations
@return number Number of Sosas | [
"Get",
"the",
"total",
"Sosa",
"count",
"for",
"all",
"generations"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaProvider.php#L428-L437 |
34,505 | jon48/webtrees-lib | src/Webtrees/Module/Sosa/Model/SosaProvider.php | SosaProvider.getDifferentSosaCountUpToGeneration | public function getDifferentSosaCountUpToGeneration($gen){
if(!$this->is_setup) return 0;
return Database::prepare(
'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
' AND majs_gen <= :gen')
->execute(array(
'tree_id' => $this->tree->getTreeId(),
'user_id' => $this->user->getUserId(),
'gen' => $gen
))->fetchOne() ?: 0;
} | php | public function getDifferentSosaCountUpToGeneration($gen){
if(!$this->is_setup) return 0;
return Database::prepare(
'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
' AND majs_gen <= :gen')
->execute(array(
'tree_id' => $this->tree->getTreeId(),
'user_id' => $this->user->getUserId(),
'gen' => $gen
))->fetchOne() ?: 0;
} | [
"public",
"function",
"getDifferentSosaCountUpToGeneration",
"(",
"$",
"gen",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_setup",
")",
"return",
"0",
";",
"return",
"Database",
"::",
"prepare",
"(",
"'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`'",
".",
"' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'",
".",
"' AND majs_gen <= :gen'",
")",
"->",
"execute",
"(",
"array",
"(",
"'tree_id'",
"=>",
"$",
"this",
"->",
"tree",
"->",
"getTreeId",
"(",
")",
",",
"'user_id'",
"=>",
"$",
"this",
"->",
"user",
"->",
"getUserId",
"(",
")",
",",
"'gen'",
"=>",
"$",
"gen",
")",
")",
"->",
"fetchOne",
"(",
")",
"?",
":",
"0",
";",
"}"
] | Get the number of distinct Sosa individual up to a specific generation.
@param number $gen Generation
@return number Number of distinct Sosa individuals up to generation | [
"Get",
"the",
"number",
"of",
"distinct",
"Sosa",
"individual",
"up",
"to",
"a",
"specific",
"generation",
"."
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaProvider.php#L499-L510 |
34,506 | jon48/webtrees-lib | src/Webtrees/Module/Sosa/Model/SosaProvider.php | SosaProvider.getMeanGenerationTime | public function getMeanGenerationTime(){
if(!$this->is_setup) return;
if(!$this->statistics_tab){
$this->getStatisticsByGeneration();
}
//Linear regression on x=generation and y=birthdate
$sum_xy = 0;
$sum_x=0;
$sum_y=0;
$sum_x2=0;
$n=count($this->statistics_tab);
foreach($this->statistics_tab as $gen=>$stats){
$sum_xy+=$gen*$stats['avgBirth'];
$sum_x+=$gen;
$sum_y+=$stats['avgBirth'];
$sum_x2+=$gen*$gen;
}
$denom=($n*$sum_x2)-($sum_x*$sum_x);
if($denom!=0){
return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom);
}
return null;
} | php | public function getMeanGenerationTime(){
if(!$this->is_setup) return;
if(!$this->statistics_tab){
$this->getStatisticsByGeneration();
}
//Linear regression on x=generation and y=birthdate
$sum_xy = 0;
$sum_x=0;
$sum_y=0;
$sum_x2=0;
$n=count($this->statistics_tab);
foreach($this->statistics_tab as $gen=>$stats){
$sum_xy+=$gen*$stats['avgBirth'];
$sum_x+=$gen;
$sum_y+=$stats['avgBirth'];
$sum_x2+=$gen*$gen;
}
$denom=($n*$sum_x2)-($sum_x*$sum_x);
if($denom!=0){
return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom);
}
return null;
} | [
"public",
"function",
"getMeanGenerationTime",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_setup",
")",
"return",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"statistics_tab",
")",
"{",
"$",
"this",
"->",
"getStatisticsByGeneration",
"(",
")",
";",
"}",
"//Linear regression on x=generation and y=birthdate",
"$",
"sum_xy",
"=",
"0",
";",
"$",
"sum_x",
"=",
"0",
";",
"$",
"sum_y",
"=",
"0",
";",
"$",
"sum_x2",
"=",
"0",
";",
"$",
"n",
"=",
"count",
"(",
"$",
"this",
"->",
"statistics_tab",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"statistics_tab",
"as",
"$",
"gen",
"=>",
"$",
"stats",
")",
"{",
"$",
"sum_xy",
"+=",
"$",
"gen",
"*",
"$",
"stats",
"[",
"'avgBirth'",
"]",
";",
"$",
"sum_x",
"+=",
"$",
"gen",
";",
"$",
"sum_y",
"+=",
"$",
"stats",
"[",
"'avgBirth'",
"]",
";",
"$",
"sum_x2",
"+=",
"$",
"gen",
"*",
"$",
"gen",
";",
"}",
"$",
"denom",
"=",
"(",
"$",
"n",
"*",
"$",
"sum_x2",
")",
"-",
"(",
"$",
"sum_x",
"*",
"$",
"sum_x",
")",
";",
"if",
"(",
"$",
"denom",
"!=",
"0",
")",
"{",
"return",
"-",
"(",
"(",
"$",
"n",
"*",
"$",
"sum_xy",
")",
"-",
"(",
"$",
"sum_x",
"*",
"$",
"sum_y",
")",
")",
"/",
"(",
"$",
"denom",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get the mean generation time, based on a linear regression of birth years and generations
@return number|NULL Mean generation time | [
"Get",
"the",
"mean",
"generation",
"time",
"based",
"on",
"a",
"linear",
"regression",
"of",
"birth",
"years",
"and",
"generations"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaProvider.php#L542-L564 |
34,507 | jon48/webtrees-lib | src/Webtrees/Module/Sosa/Model/SosaProvider.php | SosaProvider.getAncestorDispersionForGen | public function getAncestorDispersionForGen($gen) {
if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query
return Database::prepare(
'SELECT branches, count(i_id)'.
' FROM ('.
' SELECT i_id,'.
' CASE'.
' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'.
' ELSE -1'. // We put all ancestors shared between some branches in the same bucket
' END branches'.
' FROM ('.
' SELECT DISTINCT majs_i_id i_id,'.
' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'.
' FROM `##maj_sosa`'.
' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'.
' AND majs_gen >= :gen'.
' ) indistat'.
' GROUP BY i_id'.
') grouped'.
' GROUP BY branches')
->execute(array(
'tree_id' => $this->tree->getTreeId(),
'user_id' => $this->user->getUserId(),
'gen' => $gen
))->fetchAssoc() ?: array();
} | php | public function getAncestorDispersionForGen($gen) {
if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query
return Database::prepare(
'SELECT branches, count(i_id)'.
' FROM ('.
' SELECT i_id,'.
' CASE'.
' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'.
' ELSE -1'. // We put all ancestors shared between some branches in the same bucket
' END branches'.
' FROM ('.
' SELECT DISTINCT majs_i_id i_id,'.
' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'.
' FROM `##maj_sosa`'.
' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'.
' AND majs_gen >= :gen'.
' ) indistat'.
' GROUP BY i_id'.
') grouped'.
' GROUP BY branches')
->execute(array(
'tree_id' => $this->tree->getTreeId(),
'user_id' => $this->user->getUserId(),
'gen' => $gen
))->fetchAssoc() ?: array();
} | [
"public",
"function",
"getAncestorDispersionForGen",
"(",
"$",
"gen",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_setup",
"||",
"$",
"gen",
">",
"11",
")",
"return",
"array",
"(",
")",
";",
"// Going further than 11 gen will be out of range in the query",
"return",
"Database",
"::",
"prepare",
"(",
"'SELECT branches, count(i_id)'",
".",
"' FROM ('",
".",
"' SELECT i_id,'",
".",
"' CASE'",
".",
"' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'",
".",
"' ELSE -1'",
".",
"// We put all ancestors shared between some branches in the same bucket",
"' END branches'",
".",
"' FROM ('",
".",
"' SELECT DISTINCT majs_i_id i_id,'",
".",
"' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'",
".",
"' FROM `##maj_sosa`'",
".",
"' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'",
".",
"' AND majs_gen >= :gen'",
".",
"' ) indistat'",
".",
"' GROUP BY i_id'",
".",
"') grouped'",
".",
"' GROUP BY branches'",
")",
"->",
"execute",
"(",
"array",
"(",
"'tree_id'",
"=>",
"$",
"this",
"->",
"tree",
"->",
"getTreeId",
"(",
")",
",",
"'user_id'",
"=>",
"$",
"this",
"->",
"user",
"->",
"getUserId",
"(",
")",
",",
"'gen'",
"=>",
"$",
"gen",
")",
")",
"->",
"fetchAssoc",
"(",
")",
"?",
":",
"array",
"(",
")",
";",
"}"
] | Return a computed array of statistics about the dispersion of ancestors across the ancestors
at a specified generation.
This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL
Format:
- key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found,
-1 is used for shared ancestors
For instance base2(0100) = base10(4) represent the maternal grand father
- values: number of ancestors exclusively in the ancestors of the ancestor in key
For instance a result at generation 3 could be :
array ( -1 => 12 -> 12 ancestors are shared by the grand-parents
base10(1) => 32 -> 32 ancestors are exclusive to the paternal grand-father
base10(2) => 25 -> 25 ancestors are exclusive to the paternal grand-mother
base10(4) => 12 -> 12 ancestors are exclusive to the maternal grand-father
base10(8) => 30 -> 30 ancestors are exclusive to the maternal grand-mother
)
@param int $gen Reference generation
@return array | [
"Return",
"a",
"computed",
"array",
"of",
"statistics",
"about",
"the",
"dispersion",
"of",
"ancestors",
"across",
"the",
"ancestors",
"at",
"a",
"specified",
"generation",
".",
"This",
"statistics",
"cannot",
"be",
"used",
"for",
"generations",
"above",
"11",
"as",
"it",
"would",
"cause",
"a",
"out",
"of",
"range",
"in",
"MySQL"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaProvider.php#L588-L613 |
34,508 | voslartomas/WebCMS2 | Entity/Entity.php | Entity.toArray | public function toArray($notEmptyValues = false)
{
$props = $this->getReflection()->getProperties();
if ($this->getReflection()->getParentClass()) {
$temp = $this->getReflection()->getParentClass()->getProperties();
$props = array_merge($props, $temp);
}
if (strpos($this->getReflection()->getName(), '__CG__') !== FALSE) {
$props = $this->getReflection()->getParentClass()->getProperties();
}
$array = array();
foreach ($props as $prop) {
$getter = 'get'.ucfirst($prop->getName());
if (method_exists($this, $getter)) {
$empty = $this->$getter();
$empty = is_null($empty) || empty($empty);
if (!is_object($this->$getter())) {
if (($notEmptyValues && !$empty) || !$empty) {
$array[$prop->getName()] = $this->$getter();
}
} elseif (is_object($this->$getter())) {
if (method_exists($this->$getter(), 'getId')) {
$array[$prop->getName()] = $this->$getter()->getId();
} elseif ($this->$getter() instanceof \DateTime) {
$array[$prop->getName()] = $this->$getter()->format('d.m.Y');
} elseif ($this->$getter() instanceof \Doctrine\Common\Collections\Collection) {
$tmp = array();
foreach ($this->$getter() as $item) {
$tmp[] = $item->getId();
}
$array[$prop->getName()] = $tmp;
}
}
}
}
return $array;
} | php | public function toArray($notEmptyValues = false)
{
$props = $this->getReflection()->getProperties();
if ($this->getReflection()->getParentClass()) {
$temp = $this->getReflection()->getParentClass()->getProperties();
$props = array_merge($props, $temp);
}
if (strpos($this->getReflection()->getName(), '__CG__') !== FALSE) {
$props = $this->getReflection()->getParentClass()->getProperties();
}
$array = array();
foreach ($props as $prop) {
$getter = 'get'.ucfirst($prop->getName());
if (method_exists($this, $getter)) {
$empty = $this->$getter();
$empty = is_null($empty) || empty($empty);
if (!is_object($this->$getter())) {
if (($notEmptyValues && !$empty) || !$empty) {
$array[$prop->getName()] = $this->$getter();
}
} elseif (is_object($this->$getter())) {
if (method_exists($this->$getter(), 'getId')) {
$array[$prop->getName()] = $this->$getter()->getId();
} elseif ($this->$getter() instanceof \DateTime) {
$array[$prop->getName()] = $this->$getter()->format('d.m.Y');
} elseif ($this->$getter() instanceof \Doctrine\Common\Collections\Collection) {
$tmp = array();
foreach ($this->$getter() as $item) {
$tmp[] = $item->getId();
}
$array[$prop->getName()] = $tmp;
}
}
}
}
return $array;
} | [
"public",
"function",
"toArray",
"(",
"$",
"notEmptyValues",
"=",
"false",
")",
"{",
"$",
"props",
"=",
"$",
"this",
"->",
"getReflection",
"(",
")",
"->",
"getProperties",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getReflection",
"(",
")",
"->",
"getParentClass",
"(",
")",
")",
"{",
"$",
"temp",
"=",
"$",
"this",
"->",
"getReflection",
"(",
")",
"->",
"getParentClass",
"(",
")",
"->",
"getProperties",
"(",
")",
";",
"$",
"props",
"=",
"array_merge",
"(",
"$",
"props",
",",
"$",
"temp",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"getReflection",
"(",
")",
"->",
"getName",
"(",
")",
",",
"'__CG__'",
")",
"!==",
"FALSE",
")",
"{",
"$",
"props",
"=",
"$",
"this",
"->",
"getReflection",
"(",
")",
"->",
"getParentClass",
"(",
")",
"->",
"getProperties",
"(",
")",
";",
"}",
"$",
"array",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"props",
"as",
"$",
"prop",
")",
"{",
"$",
"getter",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"prop",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"getter",
")",
")",
"{",
"$",
"empty",
"=",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
";",
"$",
"empty",
"=",
"is_null",
"(",
"$",
"empty",
")",
"||",
"empty",
"(",
"$",
"empty",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
")",
")",
"{",
"if",
"(",
"(",
"$",
"notEmptyValues",
"&&",
"!",
"$",
"empty",
")",
"||",
"!",
"$",
"empty",
")",
"{",
"$",
"array",
"[",
"$",
"prop",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
";",
"}",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
")",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
",",
"'getId'",
")",
")",
"{",
"$",
"array",
"[",
"$",
"prop",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
"->",
"getId",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"array",
"[",
"$",
"prop",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
"->",
"format",
"(",
"'d.m.Y'",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
"instanceof",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Collections",
"\\",
"Collection",
")",
"{",
"$",
"tmp",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
"as",
"$",
"item",
")",
"{",
"$",
"tmp",
"[",
"]",
"=",
"$",
"item",
"->",
"getId",
"(",
")",
";",
"}",
"$",
"array",
"[",
"$",
"prop",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"tmp",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] | Converts object into array.
@return Array | [
"Converts",
"object",
"into",
"array",
"."
] | b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf | https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/Entity/Entity.php#L35-L77 |
34,509 | GrupaZero/cms | src/Gzero/Cms/Http/Controllers/Api/ContentController.php | ContentController.show | public function show($id)
{
$content = $this->repository->getById($id);
if (!$content) {
return $this->errorNotFound();
}
$this->authorize('read', $content);
return new ContentResource($content);
} | php | public function show($id)
{
$content = $this->repository->getById($id);
if (!$content) {
return $this->errorNotFound();
}
$this->authorize('read', $content);
return new ContentResource($content);
} | [
"public",
"function",
"show",
"(",
"$",
"id",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"repository",
"->",
"getById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"content",
")",
"{",
"return",
"$",
"this",
"->",
"errorNotFound",
"(",
")",
";",
"}",
"$",
"this",
"->",
"authorize",
"(",
"'read'",
",",
"$",
"content",
")",
";",
"return",
"new",
"ContentResource",
"(",
"$",
"content",
")",
";",
"}"
] | Display a specified content.
@SWG\Get(
path="/contents/{id}",
tags={"content"},
summary="Returns a specific content by id",
description="Returns a specific content by id",
produces={"application/json"},
security={{"AdminAccess": {}}},
@SWG\Parameter(
name="id",
in="path",
description="Id of content that needs to be returned.",
required=true,
type="integer"
),
@SWG\Response(
response=200,
description="Successful operation",
@SWG\Schema(type="object", ref="#/definitions/Content"),
),
@SWG\Response(response=404, description="Content not found")
)
@param int $id content Id
@return ContentResource | [
"Display",
"a",
"specified",
"content",
"."
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Http/Controllers/Api/ContentController.php#L271-L281 |
34,510 | alexislefebvre/AsyncTweetsBundle | src/Entity/TweetRepository.php | TweetRepository.removeOrphanMedias | private function removeOrphanMedias(Media $media)
{
if (count($media->getTweets()) == 0) {
$this->_em->remove($media);
}
} | php | private function removeOrphanMedias(Media $media)
{
if (count($media->getTweets()) == 0) {
$this->_em->remove($media);
}
} | [
"private",
"function",
"removeOrphanMedias",
"(",
"Media",
"$",
"media",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"media",
"->",
"getTweets",
"(",
")",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"_em",
"->",
"remove",
"(",
"$",
"media",
")",
";",
"}",
"}"
] | Remove Media not associated to any Tweet.
@param Media $media | [
"Remove",
"Media",
"not",
"associated",
"to",
"any",
"Tweet",
"."
] | 76266fae7de978963e05dadb14c81f8398bb00a6 | https://github.com/alexislefebvre/AsyncTweetsBundle/blob/76266fae7de978963e05dadb14c81f8398bb00a6/src/Entity/TweetRepository.php#L181-L186 |
34,511 | alexislefebvre/AsyncTweetsBundle | src/Entity/TweetRepository.php | TweetRepository.removeTweet | protected function removeTweet($tweet)
{
$count = 0;
foreach ($tweet->getMedias() as $media) {
$tweet->removeMedia($media);
$this->removeOrphanMedias($media);
}
// Don't count tweets that were only retweeted
if ($tweet->isInTimeline()) {
$count = 1;
}
$this->_em->remove($tweet);
return $count;
} | php | protected function removeTweet($tweet)
{
$count = 0;
foreach ($tweet->getMedias() as $media) {
$tweet->removeMedia($media);
$this->removeOrphanMedias($media);
}
// Don't count tweets that were only retweeted
if ($tweet->isInTimeline()) {
$count = 1;
}
$this->_em->remove($tweet);
return $count;
} | [
"protected",
"function",
"removeTweet",
"(",
"$",
"tweet",
")",
"{",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"tweet",
"->",
"getMedias",
"(",
")",
"as",
"$",
"media",
")",
"{",
"$",
"tweet",
"->",
"removeMedia",
"(",
"$",
"media",
")",
";",
"$",
"this",
"->",
"removeOrphanMedias",
"(",
"$",
"media",
")",
";",
"}",
"// Don't count tweets that were only retweeted",
"if",
"(",
"$",
"tweet",
"->",
"isInTimeline",
"(",
")",
")",
"{",
"$",
"count",
"=",
"1",
";",
"}",
"$",
"this",
"->",
"_em",
"->",
"remove",
"(",
"$",
"tweet",
")",
";",
"return",
"$",
"count",
";",
"}"
] | Remove the tweet and return 1 is the deleted tweet is not a
retweet.
@param Tweet $tweet
@return int | [
"Remove",
"the",
"tweet",
"and",
"return",
"1",
"is",
"the",
"deleted",
"tweet",
"is",
"not",
"a",
"retweet",
"."
] | 76266fae7de978963e05dadb14c81f8398bb00a6 | https://github.com/alexislefebvre/AsyncTweetsBundle/blob/76266fae7de978963e05dadb14c81f8398bb00a6/src/Entity/TweetRepository.php#L196-L213 |
34,512 | voslartomas/WebCMS2 | AdminModule/presenters/UpdatePresenter.php | UpdatePresenter.renderLog | public function renderLog()
{
$this->reloadContent();
$this->template->installLog = $this->getLog('../log/install.log');
$this->template->installErrorLog = $this->getLog('../log/install-error.log');
$this->template->updateLog = $this->getLog('../log/auto-update.log');
$this->template->errorLog = $this->getLog('../log/error.log');
} | php | public function renderLog()
{
$this->reloadContent();
$this->template->installLog = $this->getLog('../log/install.log');
$this->template->installErrorLog = $this->getLog('../log/install-error.log');
$this->template->updateLog = $this->getLog('../log/auto-update.log');
$this->template->errorLog = $this->getLog('../log/error.log');
} | [
"public",
"function",
"renderLog",
"(",
")",
"{",
"$",
"this",
"->",
"reloadContent",
"(",
")",
";",
"$",
"this",
"->",
"template",
"->",
"installLog",
"=",
"$",
"this",
"->",
"getLog",
"(",
"'../log/install.log'",
")",
";",
"$",
"this",
"->",
"template",
"->",
"installErrorLog",
"=",
"$",
"this",
"->",
"getLog",
"(",
"'../log/install-error.log'",
")",
";",
"$",
"this",
"->",
"template",
"->",
"updateLog",
"=",
"$",
"this",
"->",
"getLog",
"(",
"'../log/auto-update.log'",
")",
";",
"$",
"this",
"->",
"template",
"->",
"errorLog",
"=",
"$",
"this",
"->",
"getLog",
"(",
"'../log/error.log'",
")",
";",
"}"
] | render log tab | [
"render",
"log",
"tab"
] | b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf | https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/AdminModule/presenters/UpdatePresenter.php#L347-L355 |
34,513 | kadet1090/KeyLighter | Language/Perl.php | Perl.setupRules | public function setupRules()
{
$identifier = '\w+';
$number = '[+-]?(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?';
$this->rules->addMany([
'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], [
'context' => ['!keyword', '!comment', '!string', '!language', '!number'],
]),
'comment' => new Rule(new CommentMatcher(['#'])),
'keyword' => new Rule(new WordMatcher([
'case', 'continue', 'do', 'else', 'elsif', 'for', 'foreach',
'if', 'last', 'my', 'next', 'our', 'redo', 'reset', 'then',
'unless', 'until', 'while', 'use', 'print', 'new', 'BEGIN',
'sub', 'CHECK', 'INIT', 'END', 'return', 'exit'
])),
'operator.escape' => new Rule(new RegexMatcher('/(\\\.)/'), [
'context' => ['string']
]),
'string.nowdoc' => new Rule(
new RegexMatcher('/<<\s*\'(\w+)\';(?P<string>.*?)\R\1/sm', [
'string' => Token::NAME,
0 => 'keyword.nowdoc'
]), ['context' => ['!comment']]
),
'language.shell' => new Rule(new SubStringMatcher('`'), [
'context' => ['!operator.escape', '!comment', '!string', '!keyword.nowdoc'],
'factory' => new TokenFactory(ContextualToken::class),
]),
'variable.scalar' => new Rule(new RegexMatcher("/(\\\$$identifier)/")),
'variable.array' => new Rule(new RegexMatcher("/(\\@$identifier)/")),
'variable.hash' => new Rule(new RegexMatcher("/(\\%$identifier)/")),
'variable.property' => new Rule(new RegexMatcher("/\\\$$identifier{($identifier)}/")),
// Stupidly named var? Perl one, for sure.
'variable.special' => new Rule(new RegexMatcher('/([$@%][^\s\w]+[\w]*)/')),
'operator' => [
new Rule(new RegexMatcher('/(-[rwxoRWXOezsfdlpSbctugkTBMAC])/')),
new Rule(new WordMatcher([
'not', 'and', 'or', 'xor', 'goto', 'last', 'next', 'redo', 'dump',
'eq', 'ne', 'cmp', 'not', 'and', 'or', 'xor'
], ['atomic' => true])),
],
'call' => new Rule(new RegexMatcher('/([a-z]\w+)(?:\s*\(|\s+[$%@"\'`{])/i')),
'number' => [
new Rule(new RegexMatcher("/(\\b|\"|')$number\\1/", [
0 => Token::NAME
]), ['priority' => 5]),
],
'string.regex' => [
new OpenRule(new RegexMatcher('#~\s*[ms]?(/).*?/#m'), [
'context' => Validator::everywhere()
]),
new OpenRule(new RegexMatcher('#~\s*(s/).*?/#m')),
new Rule(new RegexMatcher('#(?=\/.*?(/[gimuy]{0,5}))#m'), [
'priority' => 1,
'factory' => new TokenFactory(ContextualToken::class),
'context' => ['!operator.escape', 'string.regex']
])
],
'symbol.iterator' => [
new Rule(new RegexMatcher('#(<\w+>)#s'))
]
]);
} | php | public function setupRules()
{
$identifier = '\w+';
$number = '[+-]?(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?';
$this->rules->addMany([
'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"'], [
'context' => ['!keyword', '!comment', '!string', '!language', '!number'],
]),
'comment' => new Rule(new CommentMatcher(['#'])),
'keyword' => new Rule(new WordMatcher([
'case', 'continue', 'do', 'else', 'elsif', 'for', 'foreach',
'if', 'last', 'my', 'next', 'our', 'redo', 'reset', 'then',
'unless', 'until', 'while', 'use', 'print', 'new', 'BEGIN',
'sub', 'CHECK', 'INIT', 'END', 'return', 'exit'
])),
'operator.escape' => new Rule(new RegexMatcher('/(\\\.)/'), [
'context' => ['string']
]),
'string.nowdoc' => new Rule(
new RegexMatcher('/<<\s*\'(\w+)\';(?P<string>.*?)\R\1/sm', [
'string' => Token::NAME,
0 => 'keyword.nowdoc'
]), ['context' => ['!comment']]
),
'language.shell' => new Rule(new SubStringMatcher('`'), [
'context' => ['!operator.escape', '!comment', '!string', '!keyword.nowdoc'],
'factory' => new TokenFactory(ContextualToken::class),
]),
'variable.scalar' => new Rule(new RegexMatcher("/(\\\$$identifier)/")),
'variable.array' => new Rule(new RegexMatcher("/(\\@$identifier)/")),
'variable.hash' => new Rule(new RegexMatcher("/(\\%$identifier)/")),
'variable.property' => new Rule(new RegexMatcher("/\\\$$identifier{($identifier)}/")),
// Stupidly named var? Perl one, for sure.
'variable.special' => new Rule(new RegexMatcher('/([$@%][^\s\w]+[\w]*)/')),
'operator' => [
new Rule(new RegexMatcher('/(-[rwxoRWXOezsfdlpSbctugkTBMAC])/')),
new Rule(new WordMatcher([
'not', 'and', 'or', 'xor', 'goto', 'last', 'next', 'redo', 'dump',
'eq', 'ne', 'cmp', 'not', 'and', 'or', 'xor'
], ['atomic' => true])),
],
'call' => new Rule(new RegexMatcher('/([a-z]\w+)(?:\s*\(|\s+[$%@"\'`{])/i')),
'number' => [
new Rule(new RegexMatcher("/(\\b|\"|')$number\\1/", [
0 => Token::NAME
]), ['priority' => 5]),
],
'string.regex' => [
new OpenRule(new RegexMatcher('#~\s*[ms]?(/).*?/#m'), [
'context' => Validator::everywhere()
]),
new OpenRule(new RegexMatcher('#~\s*(s/).*?/#m')),
new Rule(new RegexMatcher('#(?=\/.*?(/[gimuy]{0,5}))#m'), [
'priority' => 1,
'factory' => new TokenFactory(ContextualToken::class),
'context' => ['!operator.escape', 'string.regex']
])
],
'symbol.iterator' => [
new Rule(new RegexMatcher('#(<\w+>)#s'))
]
]);
} | [
"public",
"function",
"setupRules",
"(",
")",
"{",
"$",
"identifier",
"=",
"'\\w+'",
";",
"$",
"number",
"=",
"'[+-]?(?=\\d|\\.\\d)\\d*(\\.\\d*)?([Ee]([+-]?\\d+))?'",
";",
"$",
"this",
"->",
"rules",
"->",
"addMany",
"(",
"[",
"'string'",
"=>",
"CommonFeatures",
"::",
"strings",
"(",
"[",
"'single'",
"=>",
"'\\''",
",",
"'double'",
"=>",
"'\"'",
"]",
",",
"[",
"'context'",
"=>",
"[",
"'!keyword'",
",",
"'!comment'",
",",
"'!string'",
",",
"'!language'",
",",
"'!number'",
"]",
",",
"]",
")",
",",
"'comment'",
"=>",
"new",
"Rule",
"(",
"new",
"CommentMatcher",
"(",
"[",
"'#'",
"]",
")",
")",
",",
"'keyword'",
"=>",
"new",
"Rule",
"(",
"new",
"WordMatcher",
"(",
"[",
"'case'",
",",
"'continue'",
",",
"'do'",
",",
"'else'",
",",
"'elsif'",
",",
"'for'",
",",
"'foreach'",
",",
"'if'",
",",
"'last'",
",",
"'my'",
",",
"'next'",
",",
"'our'",
",",
"'redo'",
",",
"'reset'",
",",
"'then'",
",",
"'unless'",
",",
"'until'",
",",
"'while'",
",",
"'use'",
",",
"'print'",
",",
"'new'",
",",
"'BEGIN'",
",",
"'sub'",
",",
"'CHECK'",
",",
"'INIT'",
",",
"'END'",
",",
"'return'",
",",
"'exit'",
"]",
")",
")",
",",
"'operator.escape'",
"=>",
"new",
"Rule",
"(",
"new",
"RegexMatcher",
"(",
"'/(\\\\\\.)/'",
")",
",",
"[",
"'context'",
"=>",
"[",
"'string'",
"]",
"]",
")",
",",
"'string.nowdoc'",
"=>",
"new",
"Rule",
"(",
"new",
"RegexMatcher",
"(",
"'/<<\\s*\\'(\\w+)\\';(?P<string>.*?)\\R\\1/sm'",
",",
"[",
"'string'",
"=>",
"Token",
"::",
"NAME",
",",
"0",
"=>",
"'keyword.nowdoc'",
"]",
")",
",",
"[",
"'context'",
"=>",
"[",
"'!comment'",
"]",
"]",
")",
",",
"'language.shell'",
"=>",
"new",
"Rule",
"(",
"new",
"SubStringMatcher",
"(",
"'`'",
")",
",",
"[",
"'context'",
"=>",
"[",
"'!operator.escape'",
",",
"'!comment'",
",",
"'!string'",
",",
"'!keyword.nowdoc'",
"]",
",",
"'factory'",
"=>",
"new",
"TokenFactory",
"(",
"ContextualToken",
"::",
"class",
")",
",",
"]",
")",
",",
"'variable.scalar'",
"=>",
"new",
"Rule",
"(",
"new",
"RegexMatcher",
"(",
"\"/(\\\\\\$$identifier)/\"",
")",
")",
",",
"'variable.array'",
"=>",
"new",
"Rule",
"(",
"new",
"RegexMatcher",
"(",
"\"/(\\\\@$identifier)/\"",
")",
")",
",",
"'variable.hash'",
"=>",
"new",
"Rule",
"(",
"new",
"RegexMatcher",
"(",
"\"/(\\\\%$identifier)/\"",
")",
")",
",",
"'variable.property'",
"=>",
"new",
"Rule",
"(",
"new",
"RegexMatcher",
"(",
"\"/\\\\\\$$identifier{($identifier)}/\"",
")",
")",
",",
"// Stupidly named var? Perl one, for sure.",
"'variable.special'",
"=>",
"new",
"Rule",
"(",
"new",
"RegexMatcher",
"(",
"'/([$@%][^\\s\\w]+[\\w]*)/'",
")",
")",
",",
"'operator'",
"=>",
"[",
"new",
"Rule",
"(",
"new",
"RegexMatcher",
"(",
"'/(-[rwxoRWXOezsfdlpSbctugkTBMAC])/'",
")",
")",
",",
"new",
"Rule",
"(",
"new",
"WordMatcher",
"(",
"[",
"'not'",
",",
"'and'",
",",
"'or'",
",",
"'xor'",
",",
"'goto'",
",",
"'last'",
",",
"'next'",
",",
"'redo'",
",",
"'dump'",
",",
"'eq'",
",",
"'ne'",
",",
"'cmp'",
",",
"'not'",
",",
"'and'",
",",
"'or'",
",",
"'xor'",
"]",
",",
"[",
"'atomic'",
"=>",
"true",
"]",
")",
")",
",",
"]",
",",
"'call'",
"=>",
"new",
"Rule",
"(",
"new",
"RegexMatcher",
"(",
"'/([a-z]\\w+)(?:\\s*\\(|\\s+[$%@\"\\'`{])/i'",
")",
")",
",",
"'number'",
"=>",
"[",
"new",
"Rule",
"(",
"new",
"RegexMatcher",
"(",
"\"/(\\\\b|\\\"|')$number\\\\1/\"",
",",
"[",
"0",
"=>",
"Token",
"::",
"NAME",
"]",
")",
",",
"[",
"'priority'",
"=>",
"5",
"]",
")",
",",
"]",
",",
"'string.regex'",
"=>",
"[",
"new",
"OpenRule",
"(",
"new",
"RegexMatcher",
"(",
"'#~\\s*[ms]?(/).*?/#m'",
")",
",",
"[",
"'context'",
"=>",
"Validator",
"::",
"everywhere",
"(",
")",
"]",
")",
",",
"new",
"OpenRule",
"(",
"new",
"RegexMatcher",
"(",
"'#~\\s*(s/).*?/#m'",
")",
")",
",",
"new",
"Rule",
"(",
"new",
"RegexMatcher",
"(",
"'#(?=\\/.*?(/[gimuy]{0,5}))#m'",
")",
",",
"[",
"'priority'",
"=>",
"1",
",",
"'factory'",
"=>",
"new",
"TokenFactory",
"(",
"ContextualToken",
"::",
"class",
")",
",",
"'context'",
"=>",
"[",
"'!operator.escape'",
",",
"'string.regex'",
"]",
"]",
")",
"]",
",",
"'symbol.iterator'",
"=>",
"[",
"new",
"Rule",
"(",
"new",
"RegexMatcher",
"(",
"'#(<\\w+>)#s'",
")",
")",
"]",
"]",
")",
";",
"}"
] | Tokenization rules definition | [
"Tokenization",
"rules",
"definition"
] | 6aac402b7fe0170edf3c5afbae652009951068af | https://github.com/kadet1090/KeyLighter/blob/6aac402b7fe0170edf3c5afbae652009951068af/Language/Perl.php#L38-L115 |
34,514 | GrupaZero/cms | src/Gzero/Cms/Http/Controllers/Api/BlockController.php | BlockController.show | public function show($id)
{
$block = $this->repository->getById($id);
if (!$block) {
return $this->errorNotFound();
}
$this->authorize('read', $block);
return new BlockResource($block);
} | php | public function show($id)
{
$block = $this->repository->getById($id);
if (!$block) {
return $this->errorNotFound();
}
$this->authorize('read', $block);
return new BlockResource($block);
} | [
"public",
"function",
"show",
"(",
"$",
"id",
")",
"{",
"$",
"block",
"=",
"$",
"this",
"->",
"repository",
"->",
"getById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"block",
")",
"{",
"return",
"$",
"this",
"->",
"errorNotFound",
"(",
")",
";",
"}",
"$",
"this",
"->",
"authorize",
"(",
"'read'",
",",
"$",
"block",
")",
";",
"return",
"new",
"BlockResource",
"(",
"$",
"block",
")",
";",
"}"
] | Display a specified block.
@SWG\Get(
path="/blocks/{id}",
tags={"blocks"},
summary="Returns a specific block by id",
description="Returns a specific block by id",
produces={"application/json"},
security={{"AdminAccess": {}}},
@SWG\Parameter(
name="id",
in="path",
description="Id of block that needs to be returned.",
required=true,
type="integer"
),
@SWG\Response(
response=200,
description="Successful operation",
@SWG\Schema(type="object", ref="#/definitions/Block"),
),
@SWG\Response(response=404, description="Block not found")
)
@param int $id content Id
@return BlockResource | [
"Display",
"a",
"specified",
"block",
"."
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Http/Controllers/Api/BlockController.php#L199-L209 |
34,515 | GrupaZero/cms | database/migrations/2015_11_26_115322_create_block.php | CreateBlock.seedBlockTypes | private function seedBlockTypes()
{
BlockType::firstOrCreate(['name' => 'basic', 'handler' => Gzero\Cms\Handlers\Block\Basic::class]);
BlockType::firstOrCreate(['name' => 'menu', 'handler' => Gzero\Cms\Handlers\Block\Menu::class]);
BlockType::firstOrCreate(['name' => 'slider', 'handler' => Gzero\Cms\Handlers\Block\Slider::class]);
} | php | private function seedBlockTypes()
{
BlockType::firstOrCreate(['name' => 'basic', 'handler' => Gzero\Cms\Handlers\Block\Basic::class]);
BlockType::firstOrCreate(['name' => 'menu', 'handler' => Gzero\Cms\Handlers\Block\Menu::class]);
BlockType::firstOrCreate(['name' => 'slider', 'handler' => Gzero\Cms\Handlers\Block\Slider::class]);
} | [
"private",
"function",
"seedBlockTypes",
"(",
")",
"{",
"BlockType",
"::",
"firstOrCreate",
"(",
"[",
"'name'",
"=>",
"'basic'",
",",
"'handler'",
"=>",
"Gzero",
"\\",
"Cms",
"\\",
"Handlers",
"\\",
"Block",
"\\",
"Basic",
"::",
"class",
"]",
")",
";",
"BlockType",
"::",
"firstOrCreate",
"(",
"[",
"'name'",
"=>",
"'menu'",
",",
"'handler'",
"=>",
"Gzero",
"\\",
"Cms",
"\\",
"Handlers",
"\\",
"Block",
"\\",
"Menu",
"::",
"class",
"]",
")",
";",
"BlockType",
"::",
"firstOrCreate",
"(",
"[",
"'name'",
"=>",
"'slider'",
",",
"'handler'",
"=>",
"Gzero",
"\\",
"Cms",
"\\",
"Handlers",
"\\",
"Block",
"\\",
"Slider",
"::",
"class",
"]",
")",
";",
"}"
] | Seed block types
@return void | [
"Seed",
"block",
"types"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/database/migrations/2015_11_26_115322_create_block.php#L86-L91 |
34,516 | voslartomas/WebCMS2 | FrontendModule/presenters/BasePresenter.php | BasePresenter.getStructures | private function getStructures($direct = true, $rootClass = 'nav navbar-nav', $dropDown = false, $rootId = '')
{
$repo = $this->em->getRepository('WebCMS\Entity\Page');
$structs = $repo->findBy(array(
'language' => $this->language,
'parent' => NULL,
));
$structures = array();
foreach ($structs as $s) {
$structures[$s->getTitle()] = $this->getStructure($this, $s, $repo, $direct, $rootClass, $dropDown, true, null, '', null, $rootId);
}
return $structures;
} | php | private function getStructures($direct = true, $rootClass = 'nav navbar-nav', $dropDown = false, $rootId = '')
{
$repo = $this->em->getRepository('WebCMS\Entity\Page');
$structs = $repo->findBy(array(
'language' => $this->language,
'parent' => NULL,
));
$structures = array();
foreach ($structs as $s) {
$structures[$s->getTitle()] = $this->getStructure($this, $s, $repo, $direct, $rootClass, $dropDown, true, null, '', null, $rootId);
}
return $structures;
} | [
"private",
"function",
"getStructures",
"(",
"$",
"direct",
"=",
"true",
",",
"$",
"rootClass",
"=",
"'nav navbar-nav'",
",",
"$",
"dropDown",
"=",
"false",
",",
"$",
"rootId",
"=",
"''",
")",
"{",
"$",
"repo",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"'WebCMS\\Entity\\Page'",
")",
";",
"$",
"structs",
"=",
"$",
"repo",
"->",
"findBy",
"(",
"array",
"(",
"'language'",
"=>",
"$",
"this",
"->",
"language",
",",
"'parent'",
"=>",
"NULL",
",",
")",
")",
";",
"$",
"structures",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"structs",
"as",
"$",
"s",
")",
"{",
"$",
"structures",
"[",
"$",
"s",
"->",
"getTitle",
"(",
")",
"]",
"=",
"$",
"this",
"->",
"getStructure",
"(",
"$",
"this",
",",
"$",
"s",
",",
"$",
"repo",
",",
"$",
"direct",
",",
"$",
"rootClass",
",",
"$",
"dropDown",
",",
"true",
",",
"null",
",",
"''",
",",
"null",
",",
"$",
"rootId",
")",
";",
"}",
"return",
"$",
"structures",
";",
"}"
] | Load all system structures.
@return type | [
"Load",
"all",
"system",
"structures",
"."
] | b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf | https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/FrontendModule/presenters/BasePresenter.php#L435-L450 |
34,517 | voslartomas/WebCMS2 | FrontendModule/presenters/BasePresenter.php | BasePresenter.formatTemplateFiles | public function formatTemplateFiles()
{
$name = $this->getName();
$path = explode(':', $name);
if (isset($path[2])) {
$module = $path[1];
$presenter = $path[2];
} else {
$module = $path[0];
$presenter = $path[1];
}
$dir = dirname($this->getReflection()->getFileName());
$dir = is_dir("$dir/templates") ? $dir : dirname($dir);
$appPath = APP_DIR."/templates/".lcfirst($module)."-module/$presenter/$this->view.latte";
return array(
$appPath,
"$dir/templates/$presenter/$this->view.latte",
"$dir/templates/$presenter.$this->view.latte",
"$dir/templates/$presenter/$this->view.phtml",
"$dir/templates/$presenter.$this->view.phtml",
);
} | php | public function formatTemplateFiles()
{
$name = $this->getName();
$path = explode(':', $name);
if (isset($path[2])) {
$module = $path[1];
$presenter = $path[2];
} else {
$module = $path[0];
$presenter = $path[1];
}
$dir = dirname($this->getReflection()->getFileName());
$dir = is_dir("$dir/templates") ? $dir : dirname($dir);
$appPath = APP_DIR."/templates/".lcfirst($module)."-module/$presenter/$this->view.latte";
return array(
$appPath,
"$dir/templates/$presenter/$this->view.latte",
"$dir/templates/$presenter.$this->view.latte",
"$dir/templates/$presenter/$this->view.phtml",
"$dir/templates/$presenter.$this->view.phtml",
);
} | [
"public",
"function",
"formatTemplateFiles",
"(",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"$",
"path",
"=",
"explode",
"(",
"':'",
",",
"$",
"name",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"path",
"[",
"2",
"]",
")",
")",
"{",
"$",
"module",
"=",
"$",
"path",
"[",
"1",
"]",
";",
"$",
"presenter",
"=",
"$",
"path",
"[",
"2",
"]",
";",
"}",
"else",
"{",
"$",
"module",
"=",
"$",
"path",
"[",
"0",
"]",
";",
"$",
"presenter",
"=",
"$",
"path",
"[",
"1",
"]",
";",
"}",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"this",
"->",
"getReflection",
"(",
")",
"->",
"getFileName",
"(",
")",
")",
";",
"$",
"dir",
"=",
"is_dir",
"(",
"\"$dir/templates\"",
")",
"?",
"$",
"dir",
":",
"dirname",
"(",
"$",
"dir",
")",
";",
"$",
"appPath",
"=",
"APP_DIR",
".",
"\"/templates/\"",
".",
"lcfirst",
"(",
"$",
"module",
")",
".",
"\"-module/$presenter/$this->view.latte\"",
";",
"return",
"array",
"(",
"$",
"appPath",
",",
"\"$dir/templates/$presenter/$this->view.latte\"",
",",
"\"$dir/templates/$presenter.$this->view.latte\"",
",",
"\"$dir/templates/$presenter/$this->view.phtml\"",
",",
"\"$dir/templates/$presenter.$this->view.phtml\"",
",",
")",
";",
"}"
] | Formats view template file names.
@return array | [
"Formats",
"view",
"template",
"file",
"names",
"."
] | b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf | https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/FrontendModule/presenters/BasePresenter.php#L643-L669 |
34,518 | CanalTP/NmmPortalBundle | Services/NavitiaTokenManager.php | NavitiaTokenManager.call | private function call($url, $method = 'GET')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
//Timeout in 5s
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->timeout);
$response = curl_exec($ch);
$errorMsg = curl_error($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
$response = json_decode($response);
if (isset($response->error)) {
$errorMsg .= '(' . $response->error . ')';
}
throw new \Exception($httpCode . ' : ' . $errorMsg);
}
if ($response === false) {
return false;
}
return $response;
} | php | private function call($url, $method = 'GET')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
//Timeout in 5s
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->timeout);
$response = curl_exec($ch);
$errorMsg = curl_error($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
$response = json_decode($response);
if (isset($response->error)) {
$errorMsg .= '(' . $response->error . ')';
}
throw new \Exception($httpCode . ' : ' . $errorMsg);
}
if ($response === false) {
return false;
}
return $response;
} | [
"private",
"function",
"call",
"(",
"$",
"url",
",",
"$",
"method",
"=",
"'GET'",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_NOSIGNAL",
",",
"1",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"method",
")",
";",
"//Timeout in 5s",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_TIMEOUT_MS",
",",
"$",
"this",
"->",
"timeout",
")",
";",
"$",
"response",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"$",
"errorMsg",
"=",
"curl_error",
"(",
"$",
"ch",
")",
";",
"$",
"httpCode",
"=",
"curl_getinfo",
"(",
"$",
"ch",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"if",
"(",
"$",
"httpCode",
"!==",
"200",
")",
"{",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"response",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"response",
"->",
"error",
")",
")",
"{",
"$",
"errorMsg",
".=",
"'('",
".",
"$",
"response",
"->",
"error",
".",
"')'",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"httpCode",
".",
"' : '",
".",
"$",
"errorMsg",
")",
";",
"}",
"if",
"(",
"$",
"response",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Make calls to WS
@param string $url
@param string $method
@return boolean if no result or string if succes
@throws \Exception if navitia call fail | [
"Make",
"calls",
"to",
"WS"
] | b1ad026a33897984206ea1691ad9e25db5854efb | https://github.com/CanalTP/NmmPortalBundle/blob/b1ad026a33897984206ea1691ad9e25db5854efb/Services/NavitiaTokenManager.php#L40-L67 |
34,519 | CanalTP/NmmPortalBundle | Services/NavitiaTokenManager.php | NavitiaTokenManager.getInstancesIdsFromExternalsCoveragesIds | private function getInstancesIdsFromExternalsCoveragesIds(\Traversable $perimeters)
{
$userPerimeterNavitiaIds = array();
$instances = $this->getInstances();
foreach ($perimeters as $perimeter) {
$userPerimeterNavitiaId = array_search($perimeter->getExternalCoverageId(), $instances);
if ($userPerimeterNavitiaId) {
$userPerimeterNavitiaIds[] = array_search($perimeter->getExternalCoverageId(), $instances);
} else {
throw new NotFoundHttpException("Coverage not found: " . $perimeter->getExternalCoverageId() . " in tyr api (" . $this->tyrUrl . ") ");
}
}
return $userPerimeterNavitiaIds;
} | php | private function getInstancesIdsFromExternalsCoveragesIds(\Traversable $perimeters)
{
$userPerimeterNavitiaIds = array();
$instances = $this->getInstances();
foreach ($perimeters as $perimeter) {
$userPerimeterNavitiaId = array_search($perimeter->getExternalCoverageId(), $instances);
if ($userPerimeterNavitiaId) {
$userPerimeterNavitiaIds[] = array_search($perimeter->getExternalCoverageId(), $instances);
} else {
throw new NotFoundHttpException("Coverage not found: " . $perimeter->getExternalCoverageId() . " in tyr api (" . $this->tyrUrl . ") ");
}
}
return $userPerimeterNavitiaIds;
} | [
"private",
"function",
"getInstancesIdsFromExternalsCoveragesIds",
"(",
"\\",
"Traversable",
"$",
"perimeters",
")",
"{",
"$",
"userPerimeterNavitiaIds",
"=",
"array",
"(",
")",
";",
"$",
"instances",
"=",
"$",
"this",
"->",
"getInstances",
"(",
")",
";",
"foreach",
"(",
"$",
"perimeters",
"as",
"$",
"perimeter",
")",
"{",
"$",
"userPerimeterNavitiaId",
"=",
"array_search",
"(",
"$",
"perimeter",
"->",
"getExternalCoverageId",
"(",
")",
",",
"$",
"instances",
")",
";",
"if",
"(",
"$",
"userPerimeterNavitiaId",
")",
"{",
"$",
"userPerimeterNavitiaIds",
"[",
"]",
"=",
"array_search",
"(",
"$",
"perimeter",
"->",
"getExternalCoverageId",
"(",
")",
",",
"$",
"instances",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"\"Coverage not found: \"",
".",
"$",
"perimeter",
"->",
"getExternalCoverageId",
"(",
")",
".",
"\" in tyr api (\"",
".",
"$",
"this",
"->",
"tyrUrl",
".",
"\") \"",
")",
";",
"}",
"}",
"return",
"$",
"userPerimeterNavitiaIds",
";",
"}"
] | From perimeters names, find navitia instances ids for add permissions
@param array $coverages | [
"From",
"perimeters",
"names",
"find",
"navitia",
"instances",
"ids",
"for",
"add",
"permissions"
] | b1ad026a33897984206ea1691ad9e25db5854efb | https://github.com/CanalTP/NmmPortalBundle/blob/b1ad026a33897984206ea1691ad9e25db5854efb/Services/NavitiaTokenManager.php#L211-L225 |
34,520 | CanalTP/NmmPortalBundle | Services/NavitiaTokenManager.php | NavitiaTokenManager.getNavitiaApiAllId | private function getNavitiaApiAllId()
{
$response = $this->call($this->tyrUrl . '/' . $this->version . '/api/');
$apis = json_decode($response);
foreach ($apis as $api) {
if ($api->name == 'ALL') {
return $api;
}
}
} | php | private function getNavitiaApiAllId()
{
$response = $this->call($this->tyrUrl . '/' . $this->version . '/api/');
$apis = json_decode($response);
foreach ($apis as $api) {
if ($api->name == 'ALL') {
return $api;
}
}
} | [
"private",
"function",
"getNavitiaApiAllId",
"(",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"call",
"(",
"$",
"this",
"->",
"tyrUrl",
".",
"'/'",
".",
"$",
"this",
"->",
"version",
".",
"'/api/'",
")",
";",
"$",
"apis",
"=",
"json_decode",
"(",
"$",
"response",
")",
";",
"foreach",
"(",
"$",
"apis",
"as",
"$",
"api",
")",
"{",
"if",
"(",
"$",
"api",
"->",
"name",
"==",
"'ALL'",
")",
"{",
"return",
"$",
"api",
";",
"}",
"}",
"}"
] | Return meta api 'ALL' id
@return type | [
"Return",
"meta",
"api",
"ALL",
"id"
] | b1ad026a33897984206ea1691ad9e25db5854efb | https://github.com/CanalTP/NmmPortalBundle/blob/b1ad026a33897984206ea1691ad9e25db5854efb/Services/NavitiaTokenManager.php#L232-L242 |
34,521 | CanalTP/NmmPortalBundle | Services/NavitiaTokenManager.php | NavitiaTokenManager.createAuthorization | private function createAuthorization($userId, $instanceId)
{
$apiAll = $this->getNavitiaApiAllId();
$this->call($this->tyrUrl . '/' . $this->version . '/users/' . $userId . '/authorizations/?api_id=' . $apiAll->id . '&instance_id=' . $instanceId, 'POST');
return true;
} | php | private function createAuthorization($userId, $instanceId)
{
$apiAll = $this->getNavitiaApiAllId();
$this->call($this->tyrUrl . '/' . $this->version . '/users/' . $userId . '/authorizations/?api_id=' . $apiAll->id . '&instance_id=' . $instanceId, 'POST');
return true;
} | [
"private",
"function",
"createAuthorization",
"(",
"$",
"userId",
",",
"$",
"instanceId",
")",
"{",
"$",
"apiAll",
"=",
"$",
"this",
"->",
"getNavitiaApiAllId",
"(",
")",
";",
"$",
"this",
"->",
"call",
"(",
"$",
"this",
"->",
"tyrUrl",
".",
"'/'",
".",
"$",
"this",
"->",
"version",
".",
"'/users/'",
".",
"$",
"userId",
".",
"'/authorizations/?api_id='",
".",
"$",
"apiAll",
"->",
"id",
".",
"'&instance_id='",
".",
"$",
"instanceId",
",",
"'POST'",
")",
";",
"return",
"true",
";",
"}"
] | Add permissions to navitia user
@param int $userId
@param int $instanceId
@return boolean | [
"Add",
"permissions",
"to",
"navitia",
"user"
] | b1ad026a33897984206ea1691ad9e25db5854efb | https://github.com/CanalTP/NmmPortalBundle/blob/b1ad026a33897984206ea1691ad9e25db5854efb/Services/NavitiaTokenManager.php#L251-L257 |
34,522 | nails/module-cdn | cdn/controllers/Crop.php | Crop.resize | private function resize(
$filePath,
$phpCropMethod
) {
// Set some PHPThumb options
$_options = [];
$_options['resizeUp'] = true;
$_options['jpegQuality'] = 80;
// --------------------------------------------------------------------------
/**
* Perform the resize
* Turn errors off, if something bad happens we want to
* output the serveBadSrc image and log the issue.
*/
$oldErrorReporting = error_reporting();
error_reporting(0);
$width = $this->width * $this->retinaMultiplier;
$height = $this->height * $this->retinaMultiplier;
$ext = strtoupper(substr($this->extension, 1));
if ($ext === 'JPEG') {
$ext = 'jpg';
}
try {
/**
* Catch any output, don't want anything going to the browser unless
* we're sure it's ok
*/
ob_start();
$PHPThumb = new \PHPThumb\GD($filePath, $_options);
// Prepare the parameters and call the method
$aParams = [
$width,
$height,
$this->cropQuadrant,
];
call_user_func_array([$PHPThumb, $phpCropMethod], $aParams);
// Save cache version
$PHPThumb->save($this->cdnCacheDir . $this->cdnCacheFile, $ext);
// Flush the buffer
ob_end_clean();
} catch (Exception $e) {
// Log the error
Factory::service('Logger')->line('CDN: ' . $phpCropMethod . ': ' . $e->getMessage());
// Switch error reporting back how it was
error_reporting($oldErrorReporting);
// Flush the buffer
ob_end_clean();
// Bad SRC
$this->serveBadSrc([
'width' => $width,
'height' => $height,
]);
}
$this->serveFromCache($this->cdnCacheFile, false);
// Switch error reporting back how it was
error_reporting($oldErrorReporting);
} | php | private function resize(
$filePath,
$phpCropMethod
) {
// Set some PHPThumb options
$_options = [];
$_options['resizeUp'] = true;
$_options['jpegQuality'] = 80;
// --------------------------------------------------------------------------
/**
* Perform the resize
* Turn errors off, if something bad happens we want to
* output the serveBadSrc image and log the issue.
*/
$oldErrorReporting = error_reporting();
error_reporting(0);
$width = $this->width * $this->retinaMultiplier;
$height = $this->height * $this->retinaMultiplier;
$ext = strtoupper(substr($this->extension, 1));
if ($ext === 'JPEG') {
$ext = 'jpg';
}
try {
/**
* Catch any output, don't want anything going to the browser unless
* we're sure it's ok
*/
ob_start();
$PHPThumb = new \PHPThumb\GD($filePath, $_options);
// Prepare the parameters and call the method
$aParams = [
$width,
$height,
$this->cropQuadrant,
];
call_user_func_array([$PHPThumb, $phpCropMethod], $aParams);
// Save cache version
$PHPThumb->save($this->cdnCacheDir . $this->cdnCacheFile, $ext);
// Flush the buffer
ob_end_clean();
} catch (Exception $e) {
// Log the error
Factory::service('Logger')->line('CDN: ' . $phpCropMethod . ': ' . $e->getMessage());
// Switch error reporting back how it was
error_reporting($oldErrorReporting);
// Flush the buffer
ob_end_clean();
// Bad SRC
$this->serveBadSrc([
'width' => $width,
'height' => $height,
]);
}
$this->serveFromCache($this->cdnCacheFile, false);
// Switch error reporting back how it was
error_reporting($oldErrorReporting);
} | [
"private",
"function",
"resize",
"(",
"$",
"filePath",
",",
"$",
"phpCropMethod",
")",
"{",
"// Set some PHPThumb options",
"$",
"_options",
"=",
"[",
"]",
";",
"$",
"_options",
"[",
"'resizeUp'",
"]",
"=",
"true",
";",
"$",
"_options",
"[",
"'jpegQuality'",
"]",
"=",
"80",
";",
"// --------------------------------------------------------------------------",
"/**\n * Perform the resize\n * Turn errors off, if something bad happens we want to\n * output the serveBadSrc image and log the issue.\n */",
"$",
"oldErrorReporting",
"=",
"error_reporting",
"(",
")",
";",
"error_reporting",
"(",
"0",
")",
";",
"$",
"width",
"=",
"$",
"this",
"->",
"width",
"*",
"$",
"this",
"->",
"retinaMultiplier",
";",
"$",
"height",
"=",
"$",
"this",
"->",
"height",
"*",
"$",
"this",
"->",
"retinaMultiplier",
";",
"$",
"ext",
"=",
"strtoupper",
"(",
"substr",
"(",
"$",
"this",
"->",
"extension",
",",
"1",
")",
")",
";",
"if",
"(",
"$",
"ext",
"===",
"'JPEG'",
")",
"{",
"$",
"ext",
"=",
"'jpg'",
";",
"}",
"try",
"{",
"/**\n * Catch any output, don't want anything going to the browser unless\n * we're sure it's ok\n */",
"ob_start",
"(",
")",
";",
"$",
"PHPThumb",
"=",
"new",
"\\",
"PHPThumb",
"\\",
"GD",
"(",
"$",
"filePath",
",",
"$",
"_options",
")",
";",
"// Prepare the parameters and call the method",
"$",
"aParams",
"=",
"[",
"$",
"width",
",",
"$",
"height",
",",
"$",
"this",
"->",
"cropQuadrant",
",",
"]",
";",
"call_user_func_array",
"(",
"[",
"$",
"PHPThumb",
",",
"$",
"phpCropMethod",
"]",
",",
"$",
"aParams",
")",
";",
"// Save cache version",
"$",
"PHPThumb",
"->",
"save",
"(",
"$",
"this",
"->",
"cdnCacheDir",
".",
"$",
"this",
"->",
"cdnCacheFile",
",",
"$",
"ext",
")",
";",
"// Flush the buffer",
"ob_end_clean",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// Log the error",
"Factory",
"::",
"service",
"(",
"'Logger'",
")",
"->",
"line",
"(",
"'CDN: '",
".",
"$",
"phpCropMethod",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"// Switch error reporting back how it was",
"error_reporting",
"(",
"$",
"oldErrorReporting",
")",
";",
"// Flush the buffer",
"ob_end_clean",
"(",
")",
";",
"// Bad SRC",
"$",
"this",
"->",
"serveBadSrc",
"(",
"[",
"'width'",
"=>",
"$",
"width",
",",
"'height'",
"=>",
"$",
"height",
",",
"]",
")",
";",
"}",
"$",
"this",
"->",
"serveFromCache",
"(",
"$",
"this",
"->",
"cdnCacheFile",
",",
"false",
")",
";",
"// Switch error reporting back how it was",
"error_reporting",
"(",
"$",
"oldErrorReporting",
")",
";",
"}"
] | Resize a static image
@param string $filePath The file to resize
@param string $phpCropMethod The PHPThumb method to use for resizing
@return void | [
"Resize",
"a",
"static",
"image"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/cdn/controllers/Crop.php#L281-L357 |
34,523 | nails/module-cdn | cdn/controllers/Crop.php | Crop.resizeAnimated | private function resizeAnimated(
$filePath,
$phpCropMethod
) {
$hash = md5(microtime(true) . uniqid()) . uniqid();
$frames = [];
$cacheFiles = [];
$durations = [];
$gfe = new GifFrameExtractor\GifFrameExtractor();
$gc = new GifCreator\GifCreator();
$width = $this->width * $this->retinaMultiplier;
$height = $this->height * $this->retinaMultiplier;
// --------------------------------------------------------------------------
// Extract all the frames, resize them and save to the cache
$gfe->extract($filePath);
$i = 0;
foreach ($gfe->getFrames() as $frame) {
// Define the filename
$filename = $hash . '-' . $i . '.gif';
$tempFilename = $hash . '-' . $i . '-original.gif';
$i++;
// Set these for recompiling
$frames[] = $this->cdnCacheDir . $filename;
$cacheFiles[] = $this->cdnCacheDir . $tempFilename;
$durations[] = $frame['duration'];
// --------------------------------------------------------------------------
// Set some PHPThumb options
$options = [
'resizeUp' => true,
];
// --------------------------------------------------------------------------
// Perform the resize; first save the original frame to disk
imagegif($frame['image'], $this->cdnCacheDir . $tempFilename);
$PHPThumb = new \PHPThumb\GD($this->cdnCacheDir . $tempFilename, $options);
// Prepare the parameters and call the method
$aParams = [
$width,
$height,
$this->cropQuadrant,
];
call_user_func_array([$PHPThumb, $phpCropMethod], $aParams);
// --------------------------------------------------------------------------
// Save cache version
$PHPThumb->save($this->cdnCacheDir . $filename, strtoupper(substr($this->extension, 1)));
}
/**
* Recompile the re-sized images back into an animated gif and save to the cache
*
* @todo: We assume the gif loops infinitely but we should really check.
* Issue made on the library's GitHub asking for this feature.
* View here: https://github.com/Sybio/GifFrameExtractor/issues/3
*/
$gc->create($frames, $durations, 0);
$data = $gc->getGif();
// --------------------------------------------------------------------------
// Output to browser
header('Content-Type: image/gif', true);
echo $data;
// --------------------------------------------------------------------------
// Save to cache
Factory::helper('file');
write_file($this->cdnCacheDir . $this->cdnCacheFile, $data);
// --------------------------------------------------------------------------
// Remove cache frames
foreach ($frames as $frame) {
if (file_exists($frame)) {
unlink($frame);
}
}
foreach ($cacheFiles as $frame) {
if (file_exists($frame)) {
unlink($frame);
}
}
// --------------------------------------------------------------------------
/**
* Kill script, th, th, that's all folks.
* Stop the output class from hijacking our headers and
* setting an incorrect Content-Type
*/
exit(0);
} | php | private function resizeAnimated(
$filePath,
$phpCropMethod
) {
$hash = md5(microtime(true) . uniqid()) . uniqid();
$frames = [];
$cacheFiles = [];
$durations = [];
$gfe = new GifFrameExtractor\GifFrameExtractor();
$gc = new GifCreator\GifCreator();
$width = $this->width * $this->retinaMultiplier;
$height = $this->height * $this->retinaMultiplier;
// --------------------------------------------------------------------------
// Extract all the frames, resize them and save to the cache
$gfe->extract($filePath);
$i = 0;
foreach ($gfe->getFrames() as $frame) {
// Define the filename
$filename = $hash . '-' . $i . '.gif';
$tempFilename = $hash . '-' . $i . '-original.gif';
$i++;
// Set these for recompiling
$frames[] = $this->cdnCacheDir . $filename;
$cacheFiles[] = $this->cdnCacheDir . $tempFilename;
$durations[] = $frame['duration'];
// --------------------------------------------------------------------------
// Set some PHPThumb options
$options = [
'resizeUp' => true,
];
// --------------------------------------------------------------------------
// Perform the resize; first save the original frame to disk
imagegif($frame['image'], $this->cdnCacheDir . $tempFilename);
$PHPThumb = new \PHPThumb\GD($this->cdnCacheDir . $tempFilename, $options);
// Prepare the parameters and call the method
$aParams = [
$width,
$height,
$this->cropQuadrant,
];
call_user_func_array([$PHPThumb, $phpCropMethod], $aParams);
// --------------------------------------------------------------------------
// Save cache version
$PHPThumb->save($this->cdnCacheDir . $filename, strtoupper(substr($this->extension, 1)));
}
/**
* Recompile the re-sized images back into an animated gif and save to the cache
*
* @todo: We assume the gif loops infinitely but we should really check.
* Issue made on the library's GitHub asking for this feature.
* View here: https://github.com/Sybio/GifFrameExtractor/issues/3
*/
$gc->create($frames, $durations, 0);
$data = $gc->getGif();
// --------------------------------------------------------------------------
// Output to browser
header('Content-Type: image/gif', true);
echo $data;
// --------------------------------------------------------------------------
// Save to cache
Factory::helper('file');
write_file($this->cdnCacheDir . $this->cdnCacheFile, $data);
// --------------------------------------------------------------------------
// Remove cache frames
foreach ($frames as $frame) {
if (file_exists($frame)) {
unlink($frame);
}
}
foreach ($cacheFiles as $frame) {
if (file_exists($frame)) {
unlink($frame);
}
}
// --------------------------------------------------------------------------
/**
* Kill script, th, th, that's all folks.
* Stop the output class from hijacking our headers and
* setting an incorrect Content-Type
*/
exit(0);
} | [
"private",
"function",
"resizeAnimated",
"(",
"$",
"filePath",
",",
"$",
"phpCropMethod",
")",
"{",
"$",
"hash",
"=",
"md5",
"(",
"microtime",
"(",
"true",
")",
".",
"uniqid",
"(",
")",
")",
".",
"uniqid",
"(",
")",
";",
"$",
"frames",
"=",
"[",
"]",
";",
"$",
"cacheFiles",
"=",
"[",
"]",
";",
"$",
"durations",
"=",
"[",
"]",
";",
"$",
"gfe",
"=",
"new",
"GifFrameExtractor",
"\\",
"GifFrameExtractor",
"(",
")",
";",
"$",
"gc",
"=",
"new",
"GifCreator",
"\\",
"GifCreator",
"(",
")",
";",
"$",
"width",
"=",
"$",
"this",
"->",
"width",
"*",
"$",
"this",
"->",
"retinaMultiplier",
";",
"$",
"height",
"=",
"$",
"this",
"->",
"height",
"*",
"$",
"this",
"->",
"retinaMultiplier",
";",
"// --------------------------------------------------------------------------",
"// Extract all the frames, resize them and save to the cache",
"$",
"gfe",
"->",
"extract",
"(",
"$",
"filePath",
")",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"gfe",
"->",
"getFrames",
"(",
")",
"as",
"$",
"frame",
")",
"{",
"// Define the filename",
"$",
"filename",
"=",
"$",
"hash",
".",
"'-'",
".",
"$",
"i",
".",
"'.gif'",
";",
"$",
"tempFilename",
"=",
"$",
"hash",
".",
"'-'",
".",
"$",
"i",
".",
"'-original.gif'",
";",
"$",
"i",
"++",
";",
"// Set these for recompiling",
"$",
"frames",
"[",
"]",
"=",
"$",
"this",
"->",
"cdnCacheDir",
".",
"$",
"filename",
";",
"$",
"cacheFiles",
"[",
"]",
"=",
"$",
"this",
"->",
"cdnCacheDir",
".",
"$",
"tempFilename",
";",
"$",
"durations",
"[",
"]",
"=",
"$",
"frame",
"[",
"'duration'",
"]",
";",
"// --------------------------------------------------------------------------",
"// Set some PHPThumb options",
"$",
"options",
"=",
"[",
"'resizeUp'",
"=>",
"true",
",",
"]",
";",
"// --------------------------------------------------------------------------",
"// Perform the resize; first save the original frame to disk",
"imagegif",
"(",
"$",
"frame",
"[",
"'image'",
"]",
",",
"$",
"this",
"->",
"cdnCacheDir",
".",
"$",
"tempFilename",
")",
";",
"$",
"PHPThumb",
"=",
"new",
"\\",
"PHPThumb",
"\\",
"GD",
"(",
"$",
"this",
"->",
"cdnCacheDir",
".",
"$",
"tempFilename",
",",
"$",
"options",
")",
";",
"// Prepare the parameters and call the method",
"$",
"aParams",
"=",
"[",
"$",
"width",
",",
"$",
"height",
",",
"$",
"this",
"->",
"cropQuadrant",
",",
"]",
";",
"call_user_func_array",
"(",
"[",
"$",
"PHPThumb",
",",
"$",
"phpCropMethod",
"]",
",",
"$",
"aParams",
")",
";",
"// --------------------------------------------------------------------------",
"// Save cache version",
"$",
"PHPThumb",
"->",
"save",
"(",
"$",
"this",
"->",
"cdnCacheDir",
".",
"$",
"filename",
",",
"strtoupper",
"(",
"substr",
"(",
"$",
"this",
"->",
"extension",
",",
"1",
")",
")",
")",
";",
"}",
"/**\n * Recompile the re-sized images back into an animated gif and save to the cache\n *\n * @todo: We assume the gif loops infinitely but we should really check.\n * Issue made on the library's GitHub asking for this feature.\n * View here: https://github.com/Sybio/GifFrameExtractor/issues/3\n */",
"$",
"gc",
"->",
"create",
"(",
"$",
"frames",
",",
"$",
"durations",
",",
"0",
")",
";",
"$",
"data",
"=",
"$",
"gc",
"->",
"getGif",
"(",
")",
";",
"// --------------------------------------------------------------------------",
"// Output to browser",
"header",
"(",
"'Content-Type: image/gif'",
",",
"true",
")",
";",
"echo",
"$",
"data",
";",
"// --------------------------------------------------------------------------",
"// Save to cache",
"Factory",
"::",
"helper",
"(",
"'file'",
")",
";",
"write_file",
"(",
"$",
"this",
"->",
"cdnCacheDir",
".",
"$",
"this",
"->",
"cdnCacheFile",
",",
"$",
"data",
")",
";",
"// --------------------------------------------------------------------------",
"// Remove cache frames",
"foreach",
"(",
"$",
"frames",
"as",
"$",
"frame",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"frame",
")",
")",
"{",
"unlink",
"(",
"$",
"frame",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"cacheFiles",
"as",
"$",
"frame",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"frame",
")",
")",
"{",
"unlink",
"(",
"$",
"frame",
")",
";",
"}",
"}",
"// --------------------------------------------------------------------------",
"/**\n * Kill script, th, th, that's all folks.\n * Stop the output class from hijacking our headers and\n * setting an incorrect Content-Type\n */",
"exit",
"(",
"0",
")",
";",
"}"
] | Resize an animated image
@param string $filePath The file to resize
@param string $phpCropMethod The PHPThumb method to use for resizing
@return void | [
"Resize",
"an",
"animated",
"image"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/cdn/controllers/Crop.php#L369-L476 |
34,524 | jon48/webtrees-lib | src/Webtrees/Module/PatronymicLineage/Model/LineageNode.php | LineageNode.addFamily | public function addFamily(Family $fams) {
if($fams && !isset($this->linked_fams[$fams])) {
$this->linked_fams[$fams] = array();
}
} | php | public function addFamily(Family $fams) {
if($fams && !isset($this->linked_fams[$fams])) {
$this->linked_fams[$fams] = array();
}
} | [
"public",
"function",
"addFamily",
"(",
"Family",
"$",
"fams",
")",
"{",
"if",
"(",
"$",
"fams",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"linked_fams",
"[",
"$",
"fams",
"]",
")",
")",
"{",
"$",
"this",
"->",
"linked_fams",
"[",
"$",
"fams",
"]",
"=",
"array",
"(",
")",
";",
"}",
"}"
] | Add a spouse family to the node
@param Fisharebest\Webtrees\Family $fams | [
"Add",
"a",
"spouse",
"family",
"to",
"the",
"node"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/PatronymicLineage/Model/LineageNode.php#L59-L63 |
34,525 | jon48/webtrees-lib | src/Webtrees/Module/PatronymicLineage/Model/LineageNode.php | LineageNode.addChild | public function addChild(Family $fams, LineageNode $child = null) {
if($fams) {
$this->addFamily($fams);
$tmp = $this->linked_fams[$fams];
$tmp[] = $child;
$this->linked_fams[$fams] = $tmp;
}
} | php | public function addChild(Family $fams, LineageNode $child = null) {
if($fams) {
$this->addFamily($fams);
$tmp = $this->linked_fams[$fams];
$tmp[] = $child;
$this->linked_fams[$fams] = $tmp;
}
} | [
"public",
"function",
"addChild",
"(",
"Family",
"$",
"fams",
",",
"LineageNode",
"$",
"child",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"fams",
")",
"{",
"$",
"this",
"->",
"addFamily",
"(",
"$",
"fams",
")",
";",
"$",
"tmp",
"=",
"$",
"this",
"->",
"linked_fams",
"[",
"$",
"fams",
"]",
";",
"$",
"tmp",
"[",
"]",
"=",
"$",
"child",
";",
"$",
"this",
"->",
"linked_fams",
"[",
"$",
"fams",
"]",
"=",
"$",
"tmp",
";",
"}",
"}"
] | Add a child LineageNode to the node
@param Fisharebest\Webtrees\Family $fams
@param LineageNode $child | [
"Add",
"a",
"child",
"LineageNode",
"to",
"the",
"node"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/PatronymicLineage/Model/LineageNode.php#L71-L78 |
34,526 | GrupaZero/cms | src/Gzero/Cms/ServiceProvider.php | ServiceProvider.registerViewComposers | protected function registerViewComposers()
{
view()->composer(
'gzero-cms::contents._disqus',
function ($view) {
$data = [];
$user = auth()->user();
if ($user && !$user->isGuest()) {
$data = [
"id" => $user["id"],
"username" => $user->getPresenter()->displayName(),
"email" => $user["email"],
//"avatar" => $user["avatar"],
];
}
$message = base64_encode(json_encode($data));
$timestamp = time();
$hmac = $this->dsqHmacSha1($message . ' ' . $timestamp, config('gzero-cms.disqus.api_secret'));
$view->with('remoteAuthS3', "$message $hmac $timestamp");
}
);
} | php | protected function registerViewComposers()
{
view()->composer(
'gzero-cms::contents._disqus',
function ($view) {
$data = [];
$user = auth()->user();
if ($user && !$user->isGuest()) {
$data = [
"id" => $user["id"],
"username" => $user->getPresenter()->displayName(),
"email" => $user["email"],
//"avatar" => $user["avatar"],
];
}
$message = base64_encode(json_encode($data));
$timestamp = time();
$hmac = $this->dsqHmacSha1($message . ' ' . $timestamp, config('gzero-cms.disqus.api_secret'));
$view->with('remoteAuthS3', "$message $hmac $timestamp");
}
);
} | [
"protected",
"function",
"registerViewComposers",
"(",
")",
"{",
"view",
"(",
")",
"->",
"composer",
"(",
"'gzero-cms::contents._disqus'",
",",
"function",
"(",
"$",
"view",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"user",
"=",
"auth",
"(",
")",
"->",
"user",
"(",
")",
";",
"if",
"(",
"$",
"user",
"&&",
"!",
"$",
"user",
"->",
"isGuest",
"(",
")",
")",
"{",
"$",
"data",
"=",
"[",
"\"id\"",
"=>",
"$",
"user",
"[",
"\"id\"",
"]",
",",
"\"username\"",
"=>",
"$",
"user",
"->",
"getPresenter",
"(",
")",
"->",
"displayName",
"(",
")",
",",
"\"email\"",
"=>",
"$",
"user",
"[",
"\"email\"",
"]",
",",
"//\"avatar\" => $user[\"avatar\"],",
"]",
";",
"}",
"$",
"message",
"=",
"base64_encode",
"(",
"json_encode",
"(",
"$",
"data",
")",
")",
";",
"$",
"timestamp",
"=",
"time",
"(",
")",
";",
"$",
"hmac",
"=",
"$",
"this",
"->",
"dsqHmacSha1",
"(",
"$",
"message",
".",
"' '",
".",
"$",
"timestamp",
",",
"config",
"(",
"'gzero-cms.disqus.api_secret'",
")",
")",
";",
"$",
"view",
"->",
"with",
"(",
"'remoteAuthS3'",
",",
"\"$message $hmac $timestamp\"",
")",
";",
"}",
")",
";",
"}"
] | It registers view composers
@return void | [
"It",
"registers",
"view",
"composers"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/ServiceProvider.php#L183-L205 |
34,527 | GrupaZero/cms | src/Gzero/Cms/ServiceProvider.php | ServiceProvider.registerListeners | protected function registerListeners()
{
Event::listen(RouteMatched::class, BlockLoad::class);
Event::listen(GzeroRouteMatched::class, BlockLoad::class);
Event::listen('block.*', BlockCacheClear::class);
} | php | protected function registerListeners()
{
Event::listen(RouteMatched::class, BlockLoad::class);
Event::listen(GzeroRouteMatched::class, BlockLoad::class);
Event::listen('block.*', BlockCacheClear::class);
} | [
"protected",
"function",
"registerListeners",
"(",
")",
"{",
"Event",
"::",
"listen",
"(",
"RouteMatched",
"::",
"class",
",",
"BlockLoad",
"::",
"class",
")",
";",
"Event",
"::",
"listen",
"(",
"GzeroRouteMatched",
"::",
"class",
",",
"BlockLoad",
"::",
"class",
")",
";",
"Event",
"::",
"listen",
"(",
"'block.*'",
",",
"BlockCacheClear",
"::",
"class",
")",
";",
"}"
] | It registers event listeners
@return void | [
"It",
"registers",
"event",
"listeners"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/ServiceProvider.php#L270-L275 |
34,528 | voslartomas/WebCMS2 | AdminModule/model/Authenticator.php | Authenticator.authenticate | public function authenticate(array $credentials)
{
list($username, $password) = $credentials;
$user = $this->users->findOneBy(array('username' => $username));
if (!$user) {
throw new NS\AuthenticationException("User not found.", self::IDENTITY_NOT_FOUND);
}
if ($user->password !== $this->calculateHash($password)) {
throw new NS\AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
}
$permissions = array();
foreach ($user->getRole()->getPermissions() as $key => $per) {
$permissions[$per->getResource()] = $per->getRead();
}
return new NS\Identity($user->id, $user->getRole()->getName(), array(
'username' => $user->username,
'email' => $user->email,
'permissions' => $permissions,
));
} | php | public function authenticate(array $credentials)
{
list($username, $password) = $credentials;
$user = $this->users->findOneBy(array('username' => $username));
if (!$user) {
throw new NS\AuthenticationException("User not found.", self::IDENTITY_NOT_FOUND);
}
if ($user->password !== $this->calculateHash($password)) {
throw new NS\AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
}
$permissions = array();
foreach ($user->getRole()->getPermissions() as $key => $per) {
$permissions[$per->getResource()] = $per->getRead();
}
return new NS\Identity($user->id, $user->getRole()->getName(), array(
'username' => $user->username,
'email' => $user->email,
'permissions' => $permissions,
));
} | [
"public",
"function",
"authenticate",
"(",
"array",
"$",
"credentials",
")",
"{",
"list",
"(",
"$",
"username",
",",
"$",
"password",
")",
"=",
"$",
"credentials",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"users",
"->",
"findOneBy",
"(",
"array",
"(",
"'username'",
"=>",
"$",
"username",
")",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"throw",
"new",
"NS",
"\\",
"AuthenticationException",
"(",
"\"User not found.\"",
",",
"self",
"::",
"IDENTITY_NOT_FOUND",
")",
";",
"}",
"if",
"(",
"$",
"user",
"->",
"password",
"!==",
"$",
"this",
"->",
"calculateHash",
"(",
"$",
"password",
")",
")",
"{",
"throw",
"new",
"NS",
"\\",
"AuthenticationException",
"(",
"\"Invalid password.\"",
",",
"self",
"::",
"INVALID_CREDENTIAL",
")",
";",
"}",
"$",
"permissions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"user",
"->",
"getRole",
"(",
")",
"->",
"getPermissions",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"per",
")",
"{",
"$",
"permissions",
"[",
"$",
"per",
"->",
"getResource",
"(",
")",
"]",
"=",
"$",
"per",
"->",
"getRead",
"(",
")",
";",
"}",
"return",
"new",
"NS",
"\\",
"Identity",
"(",
"$",
"user",
"->",
"id",
",",
"$",
"user",
"->",
"getRole",
"(",
")",
"->",
"getName",
"(",
")",
",",
"array",
"(",
"'username'",
"=>",
"$",
"user",
"->",
"username",
",",
"'email'",
"=>",
"$",
"user",
"->",
"email",
",",
"'permissions'",
"=>",
"$",
"permissions",
",",
")",
")",
";",
"}"
] | Performs an authentication
@param array
@return Nette\Security\Identity
@throws Nette\Security\AuthenticationException | [
"Performs",
"an",
"authentication"
] | b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf | https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/AdminModule/model/Authenticator.php#L29-L52 |
34,529 | jon48/webtrees-lib | src/Webtrees/Functions/FunctionsPrintLists.php | FunctionsPrintLists.sortableNames | public static function sortableNames(Individual $individual) {
$names = $individual->getAllNames();
$primary = $individual->getPrimaryName();
list($surn, $givn) = explode(',', $names[$primary]['sort']);
$givn = str_replace('@P.N.', 'AAAA', $givn);
$surn = str_replace('@N.N.', 'AAAA', $surn);
return array(
$surn . 'AAAA' . $givn,
$givn . 'AAAA' . $surn,
);
} | php | public static function sortableNames(Individual $individual) {
$names = $individual->getAllNames();
$primary = $individual->getPrimaryName();
list($surn, $givn) = explode(',', $names[$primary]['sort']);
$givn = str_replace('@P.N.', 'AAAA', $givn);
$surn = str_replace('@N.N.', 'AAAA', $surn);
return array(
$surn . 'AAAA' . $givn,
$givn . 'AAAA' . $surn,
);
} | [
"public",
"static",
"function",
"sortableNames",
"(",
"Individual",
"$",
"individual",
")",
"{",
"$",
"names",
"=",
"$",
"individual",
"->",
"getAllNames",
"(",
")",
";",
"$",
"primary",
"=",
"$",
"individual",
"->",
"getPrimaryName",
"(",
")",
";",
"list",
"(",
"$",
"surn",
",",
"$",
"givn",
")",
"=",
"explode",
"(",
"','",
",",
"$",
"names",
"[",
"$",
"primary",
"]",
"[",
"'sort'",
"]",
")",
";",
"$",
"givn",
"=",
"str_replace",
"(",
"'@P.N.'",
",",
"'AAAA'",
",",
"$",
"givn",
")",
";",
"$",
"surn",
"=",
"str_replace",
"(",
"'@N.N.'",
",",
"'AAAA'",
",",
"$",
"surn",
")",
";",
"return",
"array",
"(",
"$",
"surn",
".",
"'AAAA'",
".",
"$",
"givn",
",",
"$",
"givn",
".",
"'AAAA'",
".",
"$",
"surn",
",",
")",
";",
"}"
] | Copy of core function, which is not public.
@param Individual $individual
@return string[]
@see \Fisharebest\Webtrees\Functions\FunctionsPrintLists | [
"Copy",
"of",
"core",
"function",
"which",
"is",
"not",
"public",
"."
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Functions/FunctionsPrintLists.php#L28-L41 |
34,530 | GrupaZero/cms | src/Gzero/Cms/Jobs/UpdateContent.php | UpdateContent.handleThumb | protected function handleThumb()
{
if ($this->thumbId !== $this->content->thumb_id) {
if ($this->thumbId === null) {
return $this->content->thumb()->dissociate();
}
$thumb = File::find($this->thumbId);
if (empty($thumb)) {
throw new InvalidArgumentException('Thumbnail file does not exist');
}
return $this->content->thumb()->associate($thumb);
}
} | php | protected function handleThumb()
{
if ($this->thumbId !== $this->content->thumb_id) {
if ($this->thumbId === null) {
return $this->content->thumb()->dissociate();
}
$thumb = File::find($this->thumbId);
if (empty($thumb)) {
throw new InvalidArgumentException('Thumbnail file does not exist');
}
return $this->content->thumb()->associate($thumb);
}
} | [
"protected",
"function",
"handleThumb",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"thumbId",
"!==",
"$",
"this",
"->",
"content",
"->",
"thumb_id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"thumbId",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"content",
"->",
"thumb",
"(",
")",
"->",
"dissociate",
"(",
")",
";",
"}",
"$",
"thumb",
"=",
"File",
"::",
"find",
"(",
"$",
"this",
"->",
"thumbId",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"thumb",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Thumbnail file does not exist'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"content",
"->",
"thumb",
"(",
")",
"->",
"associate",
"(",
"$",
"thumb",
")",
";",
"}",
"}"
] | It handles thumb relation
@throws InvalidArgumentException
@return \Illuminate\Database\Eloquent\Model | [
"It",
"handles",
"thumb",
"relation"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Jobs/UpdateContent.php#L97-L110 |
34,531 | nails/module-cdn | src/Api/Controller/Manager.php | Manager.getUrl | public function getUrl()
{
if (!userHasPermission('admin:cdn:manager:object:browse')) {
$oHttpCodes = Factory::service('HttpCodes');
throw new ApiException(
'You do not have permission to access this resource',
$oHttpCodes::STATUS_UNAUTHORIZED
);
}
$oInput = Factory::service('Input');
return Factory::factory('ApiResponse', 'nails/module-api')
->setData(site_url(
'admin/cdn/manager?' .
http_build_query([
'bucket' => $oInput->get('bucket'),
'callback' => $oInput->get('callback'),
])
));
} | php | public function getUrl()
{
if (!userHasPermission('admin:cdn:manager:object:browse')) {
$oHttpCodes = Factory::service('HttpCodes');
throw new ApiException(
'You do not have permission to access this resource',
$oHttpCodes::STATUS_UNAUTHORIZED
);
}
$oInput = Factory::service('Input');
return Factory::factory('ApiResponse', 'nails/module-api')
->setData(site_url(
'admin/cdn/manager?' .
http_build_query([
'bucket' => $oInput->get('bucket'),
'callback' => $oInput->get('callback'),
])
));
} | [
"public",
"function",
"getUrl",
"(",
")",
"{",
"if",
"(",
"!",
"userHasPermission",
"(",
"'admin:cdn:manager:object:browse'",
")",
")",
"{",
"$",
"oHttpCodes",
"=",
"Factory",
"::",
"service",
"(",
"'HttpCodes'",
")",
";",
"throw",
"new",
"ApiException",
"(",
"'You do not have permission to access this resource'",
",",
"$",
"oHttpCodes",
"::",
"STATUS_UNAUTHORIZED",
")",
";",
"}",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"return",
"Factory",
"::",
"factory",
"(",
"'ApiResponse'",
",",
"'nails/module-api'",
")",
"->",
"setData",
"(",
"site_url",
"(",
"'admin/cdn/manager?'",
".",
"http_build_query",
"(",
"[",
"'bucket'",
"=>",
"$",
"oInput",
"->",
"get",
"(",
"'bucket'",
")",
",",
"'callback'",
"=>",
"$",
"oInput",
"->",
"get",
"(",
"'callback'",
")",
",",
"]",
")",
")",
")",
";",
"}"
] | Returns the URL for a manager
@return array | [
"Returns",
"the",
"URL",
"for",
"a",
"manager"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Api/Controller/Manager.php#L33-L53 |
34,532 | jon48/webtrees-lib | src/Webtrees/Module/Sosa/Model/SosaCalculator.php | SosaCalculator.computeAll | public function computeAll() {
$root_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');
$indi = Individual::getInstance($root_id, $this->tree);
if($indi){
$this->sosa_provider->deleteAll();
$this->addNode($indi, 1);
$this->flushTmpSosaTable(true);
return true;
}
return false;
} | php | public function computeAll() {
$root_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');
$indi = Individual::getInstance($root_id, $this->tree);
if($indi){
$this->sosa_provider->deleteAll();
$this->addNode($indi, 1);
$this->flushTmpSosaTable(true);
return true;
}
return false;
} | [
"public",
"function",
"computeAll",
"(",
")",
"{",
"$",
"root_id",
"=",
"$",
"this",
"->",
"tree",
"->",
"getUserPreference",
"(",
"$",
"this",
"->",
"user",
",",
"'MAJ_SOSA_ROOT_ID'",
")",
";",
"$",
"indi",
"=",
"Individual",
"::",
"getInstance",
"(",
"$",
"root_id",
",",
"$",
"this",
"->",
"tree",
")",
";",
"if",
"(",
"$",
"indi",
")",
"{",
"$",
"this",
"->",
"sosa_provider",
"->",
"deleteAll",
"(",
")",
";",
"$",
"this",
"->",
"addNode",
"(",
"$",
"indi",
",",
"1",
")",
";",
"$",
"this",
"->",
"flushTmpSosaTable",
"(",
"true",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Compute all Sosa ancestors from the user's root individual.
@return bool Result of the computation | [
"Compute",
"all",
"Sosa",
"ancestors",
"from",
"the",
"user",
"s",
"root",
"individual",
"."
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaCalculator.php#L68-L78 |
34,533 | jon48/webtrees-lib | src/Webtrees/Module/Sosa/Model/SosaCalculator.php | SosaCalculator.computeFromIndividual | public function computeFromIndividual(Individual $indi) {
$dindi = new \MyArtJaub\Webtrees\Individual($indi);
$current_sosas = $dindi->getSosaNumbers();
foreach($current_sosas as $current_sosa => $gen) {
$this->sosa_provider->deleteAncestors($current_sosa);
$this->addNode($indi, $current_sosa);
}
$this->flushTmpSosaTable(true);
return true;
} | php | public function computeFromIndividual(Individual $indi) {
$dindi = new \MyArtJaub\Webtrees\Individual($indi);
$current_sosas = $dindi->getSosaNumbers();
foreach($current_sosas as $current_sosa => $gen) {
$this->sosa_provider->deleteAncestors($current_sosa);
$this->addNode($indi, $current_sosa);
}
$this->flushTmpSosaTable(true);
return true;
} | [
"public",
"function",
"computeFromIndividual",
"(",
"Individual",
"$",
"indi",
")",
"{",
"$",
"dindi",
"=",
"new",
"\\",
"MyArtJaub",
"\\",
"Webtrees",
"\\",
"Individual",
"(",
"$",
"indi",
")",
";",
"$",
"current_sosas",
"=",
"$",
"dindi",
"->",
"getSosaNumbers",
"(",
")",
";",
"foreach",
"(",
"$",
"current_sosas",
"as",
"$",
"current_sosa",
"=>",
"$",
"gen",
")",
"{",
"$",
"this",
"->",
"sosa_provider",
"->",
"deleteAncestors",
"(",
"$",
"current_sosa",
")",
";",
"$",
"this",
"->",
"addNode",
"(",
"$",
"indi",
",",
"$",
"current_sosa",
")",
";",
"}",
"$",
"this",
"->",
"flushTmpSosaTable",
"(",
"true",
")",
";",
"return",
"true",
";",
"}"
] | Compute all Sosa Ancestors from a specified Individual
@param Individual $indi
@return bool Result of the computation | [
"Compute",
"all",
"Sosa",
"Ancestors",
"from",
"a",
"specified",
"Individual"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaCalculator.php#L85-L94 |
34,534 | jon48/webtrees-lib | src/Webtrees/Module/Sosa/Model/SosaCalculator.php | SosaCalculator.addNode | protected function addNode(Individual $indi, $sosa) {
$birth_year = $indi->getEstimatedBirthDate()->gregorianYear();
$death_year = $indi->getEstimatedDeathDate()->gregorianYear();
$this->tmp_sosa_table[] = array(
'indi' => $indi->getXref(),
'sosa' => $sosa,
'birth_year' => $birth_year,
'death_year' => $death_year
);
$this->flushTmpSosaTable();
if($fam = $indi->getPrimaryChildFamily()) {
if($husb = $fam->getHusband()) $this->addNode($husb, 2 * $sosa);
if($wife = $fam->getWife()) $this->addNode($wife, 2 * $sosa + 1);
}
} | php | protected function addNode(Individual $indi, $sosa) {
$birth_year = $indi->getEstimatedBirthDate()->gregorianYear();
$death_year = $indi->getEstimatedDeathDate()->gregorianYear();
$this->tmp_sosa_table[] = array(
'indi' => $indi->getXref(),
'sosa' => $sosa,
'birth_year' => $birth_year,
'death_year' => $death_year
);
$this->flushTmpSosaTable();
if($fam = $indi->getPrimaryChildFamily()) {
if($husb = $fam->getHusband()) $this->addNode($husb, 2 * $sosa);
if($wife = $fam->getWife()) $this->addNode($wife, 2 * $sosa + 1);
}
} | [
"protected",
"function",
"addNode",
"(",
"Individual",
"$",
"indi",
",",
"$",
"sosa",
")",
"{",
"$",
"birth_year",
"=",
"$",
"indi",
"->",
"getEstimatedBirthDate",
"(",
")",
"->",
"gregorianYear",
"(",
")",
";",
"$",
"death_year",
"=",
"$",
"indi",
"->",
"getEstimatedDeathDate",
"(",
")",
"->",
"gregorianYear",
"(",
")",
";",
"$",
"this",
"->",
"tmp_sosa_table",
"[",
"]",
"=",
"array",
"(",
"'indi'",
"=>",
"$",
"indi",
"->",
"getXref",
"(",
")",
",",
"'sosa'",
"=>",
"$",
"sosa",
",",
"'birth_year'",
"=>",
"$",
"birth_year",
",",
"'death_year'",
"=>",
"$",
"death_year",
")",
";",
"$",
"this",
"->",
"flushTmpSosaTable",
"(",
")",
";",
"if",
"(",
"$",
"fam",
"=",
"$",
"indi",
"->",
"getPrimaryChildFamily",
"(",
")",
")",
"{",
"if",
"(",
"$",
"husb",
"=",
"$",
"fam",
"->",
"getHusband",
"(",
")",
")",
"$",
"this",
"->",
"addNode",
"(",
"$",
"husb",
",",
"2",
"*",
"$",
"sosa",
")",
";",
"if",
"(",
"$",
"wife",
"=",
"$",
"fam",
"->",
"getWife",
"(",
")",
")",
"$",
"this",
"->",
"addNode",
"(",
"$",
"wife",
",",
"2",
"*",
"$",
"sosa",
"+",
"1",
")",
";",
"}",
"}"
] | Recursive method to add individual to the Sosa table, and flush it regularly
@param Individual $indi Individual to add
@param int $sosa Individual's sosa | [
"Recursive",
"method",
"to",
"add",
"individual",
"to",
"the",
"Sosa",
"table",
"and",
"flush",
"it",
"regularly"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaCalculator.php#L101-L118 |
34,535 | jon48/webtrees-lib | src/Webtrees/Module/Sosa/Model/SosaCalculator.php | SosaCalculator.flushTmpSosaTable | protected function flushTmpSosaTable($force = false) {
if( count($this->tmp_sosa_table)> 0 &&
($force || count($this->tmp_sosa_table) >= self::TMP_SOSA_TABLE_LIMIT)){
$this->sosa_provider->insertOrUpdate($this->tmp_sosa_table);
$this->tmp_sosa_table = array();
}
} | php | protected function flushTmpSosaTable($force = false) {
if( count($this->tmp_sosa_table)> 0 &&
($force || count($this->tmp_sosa_table) >= self::TMP_SOSA_TABLE_LIMIT)){
$this->sosa_provider->insertOrUpdate($this->tmp_sosa_table);
$this->tmp_sosa_table = array();
}
} | [
"protected",
"function",
"flushTmpSosaTable",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"tmp_sosa_table",
")",
">",
"0",
"&&",
"(",
"$",
"force",
"||",
"count",
"(",
"$",
"this",
"->",
"tmp_sosa_table",
")",
">=",
"self",
"::",
"TMP_SOSA_TABLE_LIMIT",
")",
")",
"{",
"$",
"this",
"->",
"sosa_provider",
"->",
"insertOrUpdate",
"(",
"$",
"this",
"->",
"tmp_sosa_table",
")",
";",
"$",
"this",
"->",
"tmp_sosa_table",
"=",
"array",
"(",
")",
";",
"}",
"}"
] | Write sosas in the table, if the number of items is superior to the limit, or if forced.
@param bool $force Should the flush be forced | [
"Write",
"sosas",
"in",
"the",
"table",
"if",
"the",
"number",
"of",
"items",
"is",
"superior",
"to",
"the",
"limit",
"or",
"if",
"forced",
"."
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/Sosa/Model/SosaCalculator.php#L125-L131 |
34,536 | c4studio/chronos | src/Chronos/Content/app/Console/Kernel.php | Kernel.schedule | protected function schedule(Schedule $schedule)
{
parent::schedule($schedule);
// Activate scheduled posts
$schedule->call(function() {
$content = Content::where('status_scheduled', '<=', Carbon::now())->get();
foreach ($content as $item) {
$item->status = 1;
$item->status_scheduled = null;
$item->save();
}
})->everyMinute();
} | php | protected function schedule(Schedule $schedule)
{
parent::schedule($schedule);
// Activate scheduled posts
$schedule->call(function() {
$content = Content::where('status_scheduled', '<=', Carbon::now())->get();
foreach ($content as $item) {
$item->status = 1;
$item->status_scheduled = null;
$item->save();
}
})->everyMinute();
} | [
"protected",
"function",
"schedule",
"(",
"Schedule",
"$",
"schedule",
")",
"{",
"parent",
"::",
"schedule",
"(",
"$",
"schedule",
")",
";",
"// Activate scheduled posts",
"$",
"schedule",
"->",
"call",
"(",
"function",
"(",
")",
"{",
"$",
"content",
"=",
"Content",
"::",
"where",
"(",
"'status_scheduled'",
",",
"'<='",
",",
"Carbon",
"::",
"now",
"(",
")",
")",
"->",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"content",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"->",
"status",
"=",
"1",
";",
"$",
"item",
"->",
"status_scheduled",
"=",
"null",
";",
"$",
"item",
"->",
"save",
"(",
")",
";",
"}",
"}",
")",
"->",
"everyMinute",
"(",
")",
";",
"}"
] | Define the package's command schedule.
@param \Illuminate\Console\Scheduling\Schedule $schedule
@return void | [
"Define",
"the",
"package",
"s",
"command",
"schedule",
"."
] | df7f3a9794afaade3bee8f6be1223c98e4936cb2 | https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Console/Kernel.php#L18-L32 |
34,537 | jon48/webtrees-lib | src/Webtrees/Module/AdminTasks/Model/TaskProvider.php | TaskProvider.loadTask | protected function loadTask($task_name) {
try {
if (file_exists($this->root_path . $task_name .'.php')) {
$task = include $this->root_path . $task_name .'.php';
if($task instanceof AbstractTask) {
$task->setProvider($this);
return $task;
}
}
}
catch(\Exception $ex) { }
return null;
} | php | protected function loadTask($task_name) {
try {
if (file_exists($this->root_path . $task_name .'.php')) {
$task = include $this->root_path . $task_name .'.php';
if($task instanceof AbstractTask) {
$task->setProvider($this);
return $task;
}
}
}
catch(\Exception $ex) { }
return null;
} | [
"protected",
"function",
"loadTask",
"(",
"$",
"task_name",
")",
"{",
"try",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"root_path",
".",
"$",
"task_name",
".",
"'.php'",
")",
")",
"{",
"$",
"task",
"=",
"include",
"$",
"this",
"->",
"root_path",
".",
"$",
"task_name",
".",
"'.php'",
";",
"if",
"(",
"$",
"task",
"instanceof",
"AbstractTask",
")",
"{",
"$",
"task",
"->",
"setProvider",
"(",
"$",
"this",
")",
";",
"return",
"$",
"task",
";",
"}",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"}",
"return",
"null",
";",
"}"
] | Load a task object from a file.
@param string $task_name Name of the task to load. | [
"Load",
"a",
"task",
"object",
"from",
"a",
"file",
"."
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Module/AdminTasks/Model/TaskProvider.php#L43-L56 |
34,538 | Rareloop/primer-core | src/Primer/Renderable/RenderList.php | RenderList.add | public function add($pattern)
{
if (is_array($pattern)) {
$this->items += $pattern;
} else {
$this->items[] = $pattern;
}
} | php | public function add($pattern)
{
if (is_array($pattern)) {
$this->items += $pattern;
} else {
$this->items[] = $pattern;
}
} | [
"public",
"function",
"add",
"(",
"$",
"pattern",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"pattern",
")",
")",
"{",
"$",
"this",
"->",
"items",
"+=",
"$",
"pattern",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"items",
"[",
"]",
"=",
"$",
"pattern",
";",
"}",
"}"
] | Add items to the list of items to render
@param [Pattern|Group] $pattern | [
"Add",
"items",
"to",
"the",
"list",
"of",
"items",
"to",
"render"
] | fe098d6794a4add368f97672397dc93d223a1786 | https://github.com/Rareloop/primer-core/blob/fe098d6794a4add368f97672397dc93d223a1786/src/Primer/Renderable/RenderList.php#L30-L37 |
34,539 | Rareloop/primer-core | src/Primer/Renderable/RenderList.php | RenderList.render | public function render($showChrome = true)
{
$html = "";
foreach ($this->items as $item) {
$html .= $item->render($showChrome);
}
return $html;
} | php | public function render($showChrome = true)
{
$html = "";
foreach ($this->items as $item) {
$html .= $item->render($showChrome);
}
return $html;
} | [
"public",
"function",
"render",
"(",
"$",
"showChrome",
"=",
"true",
")",
"{",
"$",
"html",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"html",
".=",
"$",
"item",
"->",
"render",
"(",
"$",
"showChrome",
")",
";",
"}",
"return",
"$",
"html",
";",
"}"
] | Render the list of items
@param boolean $showChrome [description]
@return [type] [description] | [
"Render",
"the",
"list",
"of",
"items"
] | fe098d6794a4add368f97672397dc93d223a1786 | https://github.com/Rareloop/primer-core/blob/fe098d6794a4add368f97672397dc93d223a1786/src/Primer/Renderable/RenderList.php#L45-L54 |
34,540 | jon48/webtrees-lib | src/Webtrees/GedcomRecord.php | GedcomRecord.formatFirstMajorFact | public function formatFirstMajorFact($facts, $style) {
foreach ($this->gedcomrecord->getFacts($facts) as $fact) {
// Only display if it has a date or place (or both)
if (($fact->getDate() || $fact->getPlace()) && $fact->canShow()) {
switch ($style) {
case 10:
return '<i>'.$fact->getLabel().' '. \MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactDateShort($fact) .' '. \MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactPlaceShort($fact, '%1') .'</i>';
default:
return $this->gedcomrecord->formatFirstMajorFact($facts, $style);
}
}
}
return '';
} | php | public function formatFirstMajorFact($facts, $style) {
foreach ($this->gedcomrecord->getFacts($facts) as $fact) {
// Only display if it has a date or place (or both)
if (($fact->getDate() || $fact->getPlace()) && $fact->canShow()) {
switch ($style) {
case 10:
return '<i>'.$fact->getLabel().' '. \MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactDateShort($fact) .' '. \MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactPlaceShort($fact, '%1') .'</i>';
default:
return $this->gedcomrecord->formatFirstMajorFact($facts, $style);
}
}
}
return '';
} | [
"public",
"function",
"formatFirstMajorFact",
"(",
"$",
"facts",
",",
"$",
"style",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"gedcomrecord",
"->",
"getFacts",
"(",
"$",
"facts",
")",
"as",
"$",
"fact",
")",
"{",
"// Only display if it has a date or place (or both)",
"if",
"(",
"(",
"$",
"fact",
"->",
"getDate",
"(",
")",
"||",
"$",
"fact",
"->",
"getPlace",
"(",
")",
")",
"&&",
"$",
"fact",
"->",
"canShow",
"(",
")",
")",
"{",
"switch",
"(",
"$",
"style",
")",
"{",
"case",
"10",
":",
"return",
"'<i>'",
".",
"$",
"fact",
"->",
"getLabel",
"(",
")",
".",
"' '",
".",
"\\",
"MyArtJaub",
"\\",
"Webtrees",
"\\",
"Functions",
"\\",
"FunctionsPrint",
"::",
"formatFactDateShort",
"(",
"$",
"fact",
")",
".",
"' '",
".",
"\\",
"MyArtJaub",
"\\",
"Webtrees",
"\\",
"Functions",
"\\",
"FunctionsPrint",
"::",
"formatFactPlaceShort",
"(",
"$",
"fact",
",",
"'%1'",
")",
".",
"'</i>'",
";",
"default",
":",
"return",
"$",
"this",
"->",
"gedcomrecord",
"->",
"formatFirstMajorFact",
"(",
"$",
"facts",
",",
"$",
"style",
")",
";",
"}",
"}",
"}",
"return",
"''",
";",
"}"
] | Add additional options to the core formatFirstMajorFact function.
If no option is suitable, it will try returning the core function.
Option 10 : display <i>factLabel shortFactDate shortFactPlace</i>
@uses \MyArtJaub\Webtrees\Functions\FunctionsPrint
@param string $facts List of facts to find information from
@param int $style Style to apply to the information. Number >= 10 should be used in this function, lower number will return the core function.
@return string Formatted fact description | [
"Add",
"additional",
"options",
"to",
"the",
"core",
"formatFirstMajorFact",
"function",
".",
"If",
"no",
"option",
"is",
"suitable",
"it",
"will",
"try",
"returning",
"the",
"core",
"function",
"."
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/GedcomRecord.php#L67-L80 |
34,541 | jon48/webtrees-lib | src/Webtrees/GedcomRecord.php | GedcomRecord.canDisplayIsSourced | public function canDisplayIsSourced($access_level = null){
if(!$this->gedcomrecord->canShow($access_level)) return false;
if($access_level === null )
$access_level = \Fisharebest\Webtrees\Auth::accessLevel($this->gedcomrecord->getTree());
$global_facts = Globals::getGlobalFacts();
if (isset($global_facts['SOUR'])) {
return $global_facts['SOUR'] >= $access_level;
}
return true;
} | php | public function canDisplayIsSourced($access_level = null){
if(!$this->gedcomrecord->canShow($access_level)) return false;
if($access_level === null )
$access_level = \Fisharebest\Webtrees\Auth::accessLevel($this->gedcomrecord->getTree());
$global_facts = Globals::getGlobalFacts();
if (isset($global_facts['SOUR'])) {
return $global_facts['SOUR'] >= $access_level;
}
return true;
} | [
"public",
"function",
"canDisplayIsSourced",
"(",
"$",
"access_level",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"gedcomrecord",
"->",
"canShow",
"(",
"$",
"access_level",
")",
")",
"return",
"false",
";",
"if",
"(",
"$",
"access_level",
"===",
"null",
")",
"$",
"access_level",
"=",
"\\",
"Fisharebest",
"\\",
"Webtrees",
"\\",
"Auth",
"::",
"accessLevel",
"(",
"$",
"this",
"->",
"gedcomrecord",
"->",
"getTree",
"(",
")",
")",
";",
"$",
"global_facts",
"=",
"Globals",
"::",
"getGlobalFacts",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"global_facts",
"[",
"'SOUR'",
"]",
")",
")",
"{",
"return",
"$",
"global_facts",
"[",
"'SOUR'",
"]",
">=",
"$",
"access_level",
";",
"}",
"return",
"true",
";",
"}"
] | Check if the IsSourced information can be displayed
@param int $access_level
@return boolean | [
"Check",
"if",
"the",
"IsSourced",
"information",
"can",
"be",
"displayed"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/GedcomRecord.php#L88-L99 |
34,542 | jon48/webtrees-lib | src/Webtrees/GedcomRecord.php | GedcomRecord.isFactSourced | public function isFactSourced($eventslist){
if(empty($eventslist)) return 0;
$isSourced=0;
$facts = $this->gedcomrecord->getFacts($eventslist);
foreach($facts as $fact){
if($isSourced < Fact::MAX_IS_SOURCED_LEVEL){
$dfact = new Fact($fact);
$tmpIsSourced = $dfact->isSourced();
if($tmpIsSourced != 0) {
if($isSourced==0) {
$isSourced = $tmpIsSourced;
}
else{
$isSourced = max($isSourced, $tmpIsSourced);
}
}
}
}
return $isSourced;
} | php | public function isFactSourced($eventslist){
if(empty($eventslist)) return 0;
$isSourced=0;
$facts = $this->gedcomrecord->getFacts($eventslist);
foreach($facts as $fact){
if($isSourced < Fact::MAX_IS_SOURCED_LEVEL){
$dfact = new Fact($fact);
$tmpIsSourced = $dfact->isSourced();
if($tmpIsSourced != 0) {
if($isSourced==0) {
$isSourced = $tmpIsSourced;
}
else{
$isSourced = max($isSourced, $tmpIsSourced);
}
}
}
}
return $isSourced;
} | [
"public",
"function",
"isFactSourced",
"(",
"$",
"eventslist",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"eventslist",
")",
")",
"return",
"0",
";",
"$",
"isSourced",
"=",
"0",
";",
"$",
"facts",
"=",
"$",
"this",
"->",
"gedcomrecord",
"->",
"getFacts",
"(",
"$",
"eventslist",
")",
";",
"foreach",
"(",
"$",
"facts",
"as",
"$",
"fact",
")",
"{",
"if",
"(",
"$",
"isSourced",
"<",
"Fact",
"::",
"MAX_IS_SOURCED_LEVEL",
")",
"{",
"$",
"dfact",
"=",
"new",
"Fact",
"(",
"$",
"fact",
")",
";",
"$",
"tmpIsSourced",
"=",
"$",
"dfact",
"->",
"isSourced",
"(",
")",
";",
"if",
"(",
"$",
"tmpIsSourced",
"!=",
"0",
")",
"{",
"if",
"(",
"$",
"isSourced",
"==",
"0",
")",
"{",
"$",
"isSourced",
"=",
"$",
"tmpIsSourced",
";",
"}",
"else",
"{",
"$",
"isSourced",
"=",
"max",
"(",
"$",
"isSourced",
",",
"$",
"tmpIsSourced",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"isSourced",
";",
"}"
] | Check is an event associated to this record is sourced
@param string $eventslist
@return int Level of sources | [
"Check",
"is",
"an",
"event",
"associated",
"to",
"this",
"record",
"is",
"sourced"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/GedcomRecord.php#L129-L148 |
34,543 | CanalTP/NmmPortalBundle | Services/Navitia.php | Navitia.setToken | public function setToken($token)
{
$config = $this->navitia_component->getConfiguration();
$config['token'] = $token;
$this->navitia_component->setConfiguration($config);
} | php | public function setToken($token)
{
$config = $this->navitia_component->getConfiguration();
$config['token'] = $token;
$this->navitia_component->setConfiguration($config);
} | [
"public",
"function",
"setToken",
"(",
"$",
"token",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"navitia_component",
"->",
"getConfiguration",
"(",
")",
";",
"$",
"config",
"[",
"'token'",
"]",
"=",
"$",
"token",
";",
"$",
"this",
"->",
"navitia_component",
"->",
"setConfiguration",
"(",
"$",
"config",
")",
";",
"}"
] | Set token.
@param string $token | [
"Set",
"token",
"."
] | b1ad026a33897984206ea1691ad9e25db5854efb | https://github.com/CanalTP/NmmPortalBundle/blob/b1ad026a33897984206ea1691ad9e25db5854efb/Services/Navitia.php#L19-L24 |
34,544 | CanalTP/NmmPortalBundle | Services/Navitia.php | Navitia.getStopPoints | public function getStopPoints($coverageId, $networkId, $lineId, $routeId)
{
$pathFilter = 'networks/'.$networkId.'/lines/'.$lineId.'/routes/'.$routeId;
$query = array(
'api' => 'coverage',
'parameters' => array(
'region' => $coverageId,
'action' => 'route_schedules',
'path_filter' => $pathFilter,
'parameters' => '?depth=0',
),
);
return $this->navitia_component->call($query);
} | php | public function getStopPoints($coverageId, $networkId, $lineId, $routeId)
{
$pathFilter = 'networks/'.$networkId.'/lines/'.$lineId.'/routes/'.$routeId;
$query = array(
'api' => 'coverage',
'parameters' => array(
'region' => $coverageId,
'action' => 'route_schedules',
'path_filter' => $pathFilter,
'parameters' => '?depth=0',
),
);
return $this->navitia_component->call($query);
} | [
"public",
"function",
"getStopPoints",
"(",
"$",
"coverageId",
",",
"$",
"networkId",
",",
"$",
"lineId",
",",
"$",
"routeId",
")",
"{",
"$",
"pathFilter",
"=",
"'networks/'",
".",
"$",
"networkId",
".",
"'/lines/'",
".",
"$",
"lineId",
".",
"'/routes/'",
".",
"$",
"routeId",
";",
"$",
"query",
"=",
"array",
"(",
"'api'",
"=>",
"'coverage'",
",",
"'parameters'",
"=>",
"array",
"(",
"'region'",
"=>",
"$",
"coverageId",
",",
"'action'",
"=>",
"'route_schedules'",
",",
"'path_filter'",
"=>",
"$",
"pathFilter",
",",
"'parameters'",
"=>",
"'?depth=0'",
",",
")",
",",
")",
";",
"return",
"$",
"this",
"->",
"navitia_component",
"->",
"call",
"(",
"$",
"query",
")",
";",
"}"
] | Retourne les stop points.
@param string $coverageId
@param string $networkId
@param string $lineId
@param string $routeId
@return array | [
"Retourne",
"les",
"stop",
"points",
"."
] | b1ad026a33897984206ea1691ad9e25db5854efb | https://github.com/CanalTP/NmmPortalBundle/blob/b1ad026a33897984206ea1691ad9e25db5854efb/Services/Navitia.php#L161-L176 |
34,545 | CanalTP/NmmPortalBundle | Services/Navitia.php | Navitia.getRoute | public function getRoute($coverageId, $routeId, $depth = 1)
{
$query = array(
'api' => 'coverage',
'parameters' => array(
'region' => $coverageId,
'path_filter' => 'routes/'.$routeId,
'parameters' => '?depth='.$depth
)
);
return $this->navitia_component->call($query);
} | php | public function getRoute($coverageId, $routeId, $depth = 1)
{
$query = array(
'api' => 'coverage',
'parameters' => array(
'region' => $coverageId,
'path_filter' => 'routes/'.$routeId,
'parameters' => '?depth='.$depth
)
);
return $this->navitia_component->call($query);
} | [
"public",
"function",
"getRoute",
"(",
"$",
"coverageId",
",",
"$",
"routeId",
",",
"$",
"depth",
"=",
"1",
")",
"{",
"$",
"query",
"=",
"array",
"(",
"'api'",
"=>",
"'coverage'",
",",
"'parameters'",
"=>",
"array",
"(",
"'region'",
"=>",
"$",
"coverageId",
",",
"'path_filter'",
"=>",
"'routes/'",
".",
"$",
"routeId",
",",
"'parameters'",
"=>",
"'?depth='",
".",
"$",
"depth",
")",
")",
";",
"return",
"$",
"this",
"->",
"navitia_component",
"->",
"call",
"(",
"$",
"query",
")",
";",
"}"
] | Returns Basic Route data with corresponding line data.
@param string $coverageId
@param string $routeId
@param int $depth
@return stdClass | [
"Returns",
"Basic",
"Route",
"data",
"with",
"corresponding",
"line",
"data",
"."
] | b1ad026a33897984206ea1691ad9e25db5854efb | https://github.com/CanalTP/NmmPortalBundle/blob/b1ad026a33897984206ea1691ad9e25db5854efb/Services/Navitia.php#L234-L246 |
34,546 | GrupaZero/cms | src/Gzero/Cms/Models/Content.php | Content.getPath | public function getPath($languageCode)
{
$route = $this->routes()->newQuery()
->where('language_code', $languageCode)
->first();
if (empty($route->path)) {
throw new DomainException("There is no route in '$languageCode' language for content: $this->id");
}
return $route->path;
} | php | public function getPath($languageCode)
{
$route = $this->routes()->newQuery()
->where('language_code', $languageCode)
->first();
if (empty($route->path)) {
throw new DomainException("There is no route in '$languageCode' language for content: $this->id");
}
return $route->path;
} | [
"public",
"function",
"getPath",
"(",
"$",
"languageCode",
")",
"{",
"$",
"route",
"=",
"$",
"this",
"->",
"routes",
"(",
")",
"->",
"newQuery",
"(",
")",
"->",
"where",
"(",
"'language_code'",
",",
"$",
"languageCode",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"route",
"->",
"path",
")",
")",
"{",
"throw",
"new",
"DomainException",
"(",
"\"There is no route in '$languageCode' language for content: $this->id\"",
")",
";",
"}",
"return",
"$",
"route",
"->",
"path",
";",
"}"
] | Get Content url in specified language.
@param string $languageCode Lang code
@throws DomainException
@return string | [
"Get",
"Content",
"url",
"in",
"specified",
"language",
"."
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Content.php#L174-L183 |
34,547 | GrupaZero/cms | src/Gzero/Cms/Models/Content.php | Content.canBeShown | public function canBeShown()
{
if ($this->published_at === null) {
return false;
}
return Carbon::parse($this->published_at)->lte(Carbon::now());
} | php | public function canBeShown()
{
if ($this->published_at === null) {
return false;
}
return Carbon::parse($this->published_at)->lte(Carbon::now());
} | [
"public",
"function",
"canBeShown",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"published_at",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"return",
"Carbon",
"::",
"parse",
"(",
"$",
"this",
"->",
"published_at",
")",
"->",
"lte",
"(",
"Carbon",
"::",
"now",
"(",
")",
")",
";",
"}"
] | Return true if content can be shown on frontend
@TODO What about active url?
@return bool | [
"Return",
"true",
"if",
"content",
"can",
"be",
"shown",
"on",
"frontend"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Content.php#L216-L223 |
34,548 | GrupaZero/cms | src/Gzero/Cms/Models/Content.php | Content.findDescendantsWithTrashed | public function findDescendantsWithTrashed()
{
return static::withTrashed()->where($this->getTreeColumn('path'), 'LIKE', $this->{$this->getTreeColumn('path')} . '%')
->orderBy($this->getTreeColumn('level'), 'ASC');
} | php | public function findDescendantsWithTrashed()
{
return static::withTrashed()->where($this->getTreeColumn('path'), 'LIKE', $this->{$this->getTreeColumn('path')} . '%')
->orderBy($this->getTreeColumn('level'), 'ASC');
} | [
"public",
"function",
"findDescendantsWithTrashed",
"(",
")",
"{",
"return",
"static",
"::",
"withTrashed",
"(",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"getTreeColumn",
"(",
"'path'",
")",
",",
"'LIKE'",
",",
"$",
"this",
"->",
"{",
"$",
"this",
"->",
"getTreeColumn",
"(",
"'path'",
")",
"}",
".",
"'%'",
")",
"->",
"orderBy",
"(",
"$",
"this",
"->",
"getTreeColumn",
"(",
"'level'",
")",
",",
"'ASC'",
")",
";",
"}"
] | Find all trashed descendants for specific node with this node as root
@return \Illuminate\Database\Eloquent\Builder | [
"Find",
"all",
"trashed",
"descendants",
"for",
"specific",
"node",
"with",
"this",
"node",
"as",
"root"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Content.php#L242-L246 |
34,549 | GrupaZero/cms | src/Gzero/Cms/Models/Content.php | Content.handle | public function handle(Language $language): Response
{
// We need to unify response with repository format
$this->load(ContentReadRepository::$loadRelations);
return $this->getHandler()->handle($this, $language);
} | php | public function handle(Language $language): Response
{
// We need to unify response with repository format
$this->load(ContentReadRepository::$loadRelations);
return $this->getHandler()->handle($this, $language);
} | [
"public",
"function",
"handle",
"(",
"Language",
"$",
"language",
")",
":",
"Response",
"{",
"// We need to unify response with repository format",
"$",
"this",
"->",
"load",
"(",
"ContentReadRepository",
"::",
"$",
"loadRelations",
")",
";",
"return",
"$",
"this",
"->",
"getHandler",
"(",
")",
"->",
"handle",
"(",
"$",
"this",
",",
"$",
"language",
")",
";",
"}"
] | Handle content rendering by type
@param Language $language Language
@return Response | [
"Handle",
"content",
"rendering",
"by",
"type"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Content.php#L255-L260 |
34,550 | GrupaZero/cms | src/Gzero/Cms/Models/Content.php | Content.createRoute | public function createRoute(ContentTranslation $translation, bool $isActive = false)
{
$path = Route::buildUniquePath($this->getSlug($translation), $translation->language_code);
$route = Route::firstOrNew(
[
'language_code' => $translation->language_code,
'path' => $path,
],
['is_active' => $isActive]
);
$this->routes()->save($route);
return $this;
} | php | public function createRoute(ContentTranslation $translation, bool $isActive = false)
{
$path = Route::buildUniquePath($this->getSlug($translation), $translation->language_code);
$route = Route::firstOrNew(
[
'language_code' => $translation->language_code,
'path' => $path,
],
['is_active' => $isActive]
);
$this->routes()->save($route);
return $this;
} | [
"public",
"function",
"createRoute",
"(",
"ContentTranslation",
"$",
"translation",
",",
"bool",
"$",
"isActive",
"=",
"false",
")",
"{",
"$",
"path",
"=",
"Route",
"::",
"buildUniquePath",
"(",
"$",
"this",
"->",
"getSlug",
"(",
"$",
"translation",
")",
",",
"$",
"translation",
"->",
"language_code",
")",
";",
"$",
"route",
"=",
"Route",
"::",
"firstOrNew",
"(",
"[",
"'language_code'",
"=>",
"$",
"translation",
"->",
"language_code",
",",
"'path'",
"=>",
"$",
"path",
",",
"]",
",",
"[",
"'is_active'",
"=>",
"$",
"isActive",
"]",
")",
";",
"$",
"this",
"->",
"routes",
"(",
")",
"->",
"save",
"(",
"$",
"route",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Creates route with unique path based on content translation title, and tree hierarchy
@param ContentTranslation $translation Translation
@param bool $isActive Is active trigger
@return $this | [
"Creates",
"route",
"with",
"unique",
"path",
"based",
"on",
"content",
"translation",
"title",
"and",
"tree",
"hierarchy"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Content.php#L280-L295 |
34,551 | GrupaZero/cms | src/Gzero/Cms/Models/Content.php | Content.disableActiveTranslations | public function disableActiveTranslations($languageCode)
{
return $this->translations()
->where('content_id', $this->id)
->where('language_code', $languageCode)
->update(['is_active' => false]);
} | php | public function disableActiveTranslations($languageCode)
{
return $this->translations()
->where('content_id', $this->id)
->where('language_code', $languageCode)
->update(['is_active' => false]);
} | [
"public",
"function",
"disableActiveTranslations",
"(",
"$",
"languageCode",
")",
"{",
"return",
"$",
"this",
"->",
"translations",
"(",
")",
"->",
"where",
"(",
"'content_id'",
",",
"$",
"this",
"->",
"id",
")",
"->",
"where",
"(",
"'language_code'",
",",
"$",
"languageCode",
")",
"->",
"update",
"(",
"[",
"'is_active'",
"=>",
"false",
"]",
")",
";",
"}"
] | Function sets all content translations in provided language code as inactive
@param string $languageCode language code
@return mixed | [
"Function",
"sets",
"all",
"content",
"translations",
"in",
"provided",
"language",
"code",
"as",
"inactive"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Content.php#L304-L310 |
34,552 | GrupaZero/cms | src/Gzero/Cms/Models/Content.php | Content.getSlug | protected function getSlug(ContentTranslation $translation)
{
$path = str_slug($translation->title);
if ($this->parent_id) {
$path = $this->parent->getPath($translation->language_code) . '/' . $path;
}
return $path;
} | php | protected function getSlug(ContentTranslation $translation)
{
$path = str_slug($translation->title);
if ($this->parent_id) {
$path = $this->parent->getPath($translation->language_code) . '/' . $path;
}
return $path;
} | [
"protected",
"function",
"getSlug",
"(",
"ContentTranslation",
"$",
"translation",
")",
"{",
"$",
"path",
"=",
"str_slug",
"(",
"$",
"translation",
"->",
"title",
")",
";",
"if",
"(",
"$",
"this",
"->",
"parent_id",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"parent",
"->",
"getPath",
"(",
"$",
"translation",
"->",
"language_code",
")",
".",
"'/'",
".",
"$",
"path",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Returns content slug from translation title with parent slug
@param ContentTranslation $translation Content translation
@return string an unique route path address in specified language | [
"Returns",
"content",
"slug",
"from",
"translation",
"title",
"with",
"parent",
"slug"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Content.php#L337-L346 |
34,553 | GrupaZero/cms | src/Gzero/Cms/Models/Content.php | Content.getHandler | protected function getHandler()
{
$handler = resolve($this->type->handler);
if (!$handler instanceof ContentTypeHandler) {
throw new DomainException("Type: $this->type can't be handled");
}
return $handler;
} | php | protected function getHandler()
{
$handler = resolve($this->type->handler);
if (!$handler instanceof ContentTypeHandler) {
throw new DomainException("Type: $this->type can't be handled");
}
return $handler;
} | [
"protected",
"function",
"getHandler",
"(",
")",
"{",
"$",
"handler",
"=",
"resolve",
"(",
"$",
"this",
"->",
"type",
"->",
"handler",
")",
";",
"if",
"(",
"!",
"$",
"handler",
"instanceof",
"ContentTypeHandler",
")",
"{",
"throw",
"new",
"DomainException",
"(",
"\"Type: $this->type can't be handled\"",
")",
";",
"}",
"return",
"$",
"handler",
";",
"}"
] | Dynamically resolve content handler
@throws DomainException
@return ContentTypeHandler | [
"Dynamically",
"resolve",
"content",
"handler"
] | a7956966d2edec54fc99ebb61eeb2f01704aa2c2 | https://github.com/GrupaZero/cms/blob/a7956966d2edec54fc99ebb61eeb2f01704aa2c2/src/Gzero/Cms/Models/Content.php#L355-L362 |
34,554 | nails/module-cdn | cdn/controllers/Placeholder.php | Placeholder.index | public function index()
{
/**
* Check the request headers; avoid hitting the disk at all if possible.
* If the Etag matches then send a Not-Modified header and terminate
* execution.
*/
if ($this->serveNotModified($this->cdnCacheFile)) {
return;
}
// --------------------------------------------------------------------------
/**
* The browser does not have a local cache (or it's out of date) check the
* cache directory to see if this image has been processed already; serve
* it up if it has.
*/
if (file_exists($this->cdnCacheDir . $this->cdnCacheFile)) {
$this->serveFromCache($this->cdnCacheFile);
} else {
// Cache object does not exist, create a new one and cache it
$width = $this->width * $this->retinaMultiplier;
$height = $this->height * $this->retinaMultiplier;
$border = $this->border * $this->retinaMultiplier;
// Get and create the placeholder graphic
$tile = imagecreatefrompng($this->tile);
// --------------------------------------------------------------------------
// Create the container
$img = imagecreatetruecolor($width, $height);
// --------------------------------------------------------------------------
// Tile the placeholder
imagesettile($img, $tile);
imagefilledrectangle($img, 0, 0, $width, $height, IMG_COLOR_TILED);
// --------------------------------------------------------------------------
// Draw a border
$borderColor = imagecolorallocate($img, 190, 190, 190);
for ($i = 0; $i < $border; $i++) {
// Left
imageline($img, 0 + $i, 0, 0 + $i, $height, $borderColor);
// Top
imageline($img, 0, 0 + $i, $width, 0 + $i, $borderColor);
// Bottom
imageline($img, 0, $height - 1 - $i, $width, $height - 1 - $i, $borderColor);
// Right
imageline($img, $width - 1 - $i, 0, $width - 1 - $i, $height, $borderColor);
}
// --------------------------------------------------------------------------
// Set the appropriate cache headers
$this->setCacheHeaders(time(), $this->cdnCacheFile, false);
// --------------------------------------------------------------------------
// Output to browser
header('Content-Type: image/png', true);
imagepng($img);
// --------------------------------------------------------------------------
// Save local version, make sure cache is writable
imagepng($img, $this->cdnCacheDir . $this->cdnCacheFile);
// --------------------------------------------------------------------------
// Destroy the images to free up resource
imagedestroy($tile);
imagedestroy($img);
}
// --------------------------------------------------------------------------
// Kill script, th, th, that's all folks.
// Stop the output class from hijacking our headers and
// setting an incorrect Content-Type
exit(0);
} | php | public function index()
{
/**
* Check the request headers; avoid hitting the disk at all if possible.
* If the Etag matches then send a Not-Modified header and terminate
* execution.
*/
if ($this->serveNotModified($this->cdnCacheFile)) {
return;
}
// --------------------------------------------------------------------------
/**
* The browser does not have a local cache (or it's out of date) check the
* cache directory to see if this image has been processed already; serve
* it up if it has.
*/
if (file_exists($this->cdnCacheDir . $this->cdnCacheFile)) {
$this->serveFromCache($this->cdnCacheFile);
} else {
// Cache object does not exist, create a new one and cache it
$width = $this->width * $this->retinaMultiplier;
$height = $this->height * $this->retinaMultiplier;
$border = $this->border * $this->retinaMultiplier;
// Get and create the placeholder graphic
$tile = imagecreatefrompng($this->tile);
// --------------------------------------------------------------------------
// Create the container
$img = imagecreatetruecolor($width, $height);
// --------------------------------------------------------------------------
// Tile the placeholder
imagesettile($img, $tile);
imagefilledrectangle($img, 0, 0, $width, $height, IMG_COLOR_TILED);
// --------------------------------------------------------------------------
// Draw a border
$borderColor = imagecolorallocate($img, 190, 190, 190);
for ($i = 0; $i < $border; $i++) {
// Left
imageline($img, 0 + $i, 0, 0 + $i, $height, $borderColor);
// Top
imageline($img, 0, 0 + $i, $width, 0 + $i, $borderColor);
// Bottom
imageline($img, 0, $height - 1 - $i, $width, $height - 1 - $i, $borderColor);
// Right
imageline($img, $width - 1 - $i, 0, $width - 1 - $i, $height, $borderColor);
}
// --------------------------------------------------------------------------
// Set the appropriate cache headers
$this->setCacheHeaders(time(), $this->cdnCacheFile, false);
// --------------------------------------------------------------------------
// Output to browser
header('Content-Type: image/png', true);
imagepng($img);
// --------------------------------------------------------------------------
// Save local version, make sure cache is writable
imagepng($img, $this->cdnCacheDir . $this->cdnCacheFile);
// --------------------------------------------------------------------------
// Destroy the images to free up resource
imagedestroy($tile);
imagedestroy($img);
}
// --------------------------------------------------------------------------
// Kill script, th, th, that's all folks.
// Stop the output class from hijacking our headers and
// setting an incorrect Content-Type
exit(0);
} | [
"public",
"function",
"index",
"(",
")",
"{",
"/**\n * Check the request headers; avoid hitting the disk at all if possible.\n * If the Etag matches then send a Not-Modified header and terminate\n * execution.\n */",
"if",
"(",
"$",
"this",
"->",
"serveNotModified",
"(",
"$",
"this",
"->",
"cdnCacheFile",
")",
")",
"{",
"return",
";",
"}",
"// --------------------------------------------------------------------------",
"/**\n * The browser does not have a local cache (or it's out of date) check the\n * cache directory to see if this image has been processed already; serve\n * it up if it has.\n */",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"cdnCacheDir",
".",
"$",
"this",
"->",
"cdnCacheFile",
")",
")",
"{",
"$",
"this",
"->",
"serveFromCache",
"(",
"$",
"this",
"->",
"cdnCacheFile",
")",
";",
"}",
"else",
"{",
"// Cache object does not exist, create a new one and cache it",
"$",
"width",
"=",
"$",
"this",
"->",
"width",
"*",
"$",
"this",
"->",
"retinaMultiplier",
";",
"$",
"height",
"=",
"$",
"this",
"->",
"height",
"*",
"$",
"this",
"->",
"retinaMultiplier",
";",
"$",
"border",
"=",
"$",
"this",
"->",
"border",
"*",
"$",
"this",
"->",
"retinaMultiplier",
";",
"// Get and create the placeholder graphic",
"$",
"tile",
"=",
"imagecreatefrompng",
"(",
"$",
"this",
"->",
"tile",
")",
";",
"// --------------------------------------------------------------------------",
"// Create the container",
"$",
"img",
"=",
"imagecreatetruecolor",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"// --------------------------------------------------------------------------",
"// Tile the placeholder",
"imagesettile",
"(",
"$",
"img",
",",
"$",
"tile",
")",
";",
"imagefilledrectangle",
"(",
"$",
"img",
",",
"0",
",",
"0",
",",
"$",
"width",
",",
"$",
"height",
",",
"IMG_COLOR_TILED",
")",
";",
"// --------------------------------------------------------------------------",
"// Draw a border",
"$",
"borderColor",
"=",
"imagecolorallocate",
"(",
"$",
"img",
",",
"190",
",",
"190",
",",
"190",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"border",
";",
"$",
"i",
"++",
")",
"{",
"// Left",
"imageline",
"(",
"$",
"img",
",",
"0",
"+",
"$",
"i",
",",
"0",
",",
"0",
"+",
"$",
"i",
",",
"$",
"height",
",",
"$",
"borderColor",
")",
";",
"// Top",
"imageline",
"(",
"$",
"img",
",",
"0",
",",
"0",
"+",
"$",
"i",
",",
"$",
"width",
",",
"0",
"+",
"$",
"i",
",",
"$",
"borderColor",
")",
";",
"// Bottom",
"imageline",
"(",
"$",
"img",
",",
"0",
",",
"$",
"height",
"-",
"1",
"-",
"$",
"i",
",",
"$",
"width",
",",
"$",
"height",
"-",
"1",
"-",
"$",
"i",
",",
"$",
"borderColor",
")",
";",
"// Right",
"imageline",
"(",
"$",
"img",
",",
"$",
"width",
"-",
"1",
"-",
"$",
"i",
",",
"0",
",",
"$",
"width",
"-",
"1",
"-",
"$",
"i",
",",
"$",
"height",
",",
"$",
"borderColor",
")",
";",
"}",
"// --------------------------------------------------------------------------",
"// Set the appropriate cache headers",
"$",
"this",
"->",
"setCacheHeaders",
"(",
"time",
"(",
")",
",",
"$",
"this",
"->",
"cdnCacheFile",
",",
"false",
")",
";",
"// --------------------------------------------------------------------------",
"// Output to browser",
"header",
"(",
"'Content-Type: image/png'",
",",
"true",
")",
";",
"imagepng",
"(",
"$",
"img",
")",
";",
"// --------------------------------------------------------------------------",
"// Save local version, make sure cache is writable",
"imagepng",
"(",
"$",
"img",
",",
"$",
"this",
"->",
"cdnCacheDir",
".",
"$",
"this",
"->",
"cdnCacheFile",
")",
";",
"// --------------------------------------------------------------------------",
"// Destroy the images to free up resource",
"imagedestroy",
"(",
"$",
"tile",
")",
";",
"imagedestroy",
"(",
"$",
"img",
")",
";",
"}",
"// --------------------------------------------------------------------------",
"// Kill script, th, th, that's all folks.",
"// Stop the output class from hijacking our headers and",
"// setting an incorrect Content-Type",
"exit",
"(",
"0",
")",
";",
"}"
] | Render a placeholder
@return void | [
"Render",
"a",
"placeholder"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/cdn/controllers/Placeholder.php#L97-L194 |
34,555 | c4studio/chronos | src/Chronos/Content/app/Models/Content.php | Content.__isset | public function __isset($key)
{
if (isset($this->custom_attributes[$key]))
return true;
return ! is_null($this->getAttribute($key));
} | php | public function __isset($key)
{
if (isset($this->custom_attributes[$key]))
return true;
return ! is_null($this->getAttribute($key));
} | [
"public",
"function",
"__isset",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"custom_attributes",
"[",
"$",
"key",
"]",
")",
")",
"return",
"true",
";",
"return",
"!",
"is_null",
"(",
"$",
"this",
"->",
"getAttribute",
"(",
"$",
"key",
")",
")",
";",
"}"
] | Determine if a dynamic attribute or relation exists on the model.
@param string $key
@return bool | [
"Determine",
"if",
"a",
"dynamic",
"attribute",
"or",
"relation",
"exists",
"on",
"the",
"model",
"."
] | df7f3a9794afaade3bee8f6be1223c98e4936cb2 | https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/Content.php#L73-L79 |
34,556 | c4studio/chronos | src/Chronos/Content/app/Models/Content.php | Content.getAllFieldsetsAttribute | public function getAllFieldsetsAttribute()
{
$fieldsets = [];
$all_fieldsets = [];
if ($this->type->fieldsets)
$all_fieldsets = $this->type->fieldsets;
if ($this->fieldsets)
$all_fieldsets = $all_fieldsets->merge($this->fieldsets);
if ($all_fieldsets) {
foreach ($all_fieldsets as $fieldset) {
$fieldset_orig = clone $fieldset;
$fieldset_repetitions = [$fieldset_orig];
foreach ($fieldset->fields as $field) {
$field_orig = clone $field;
$field_repetitions = [$field_orig];
$field_values = [];
$values = ContentFieldData::query()->where('content_id', $this->id)->where('field_id', $field->id)->get();
if ($values) {
foreach ($values as $valueData) {
if (@unserialize($valueData->value) !== false || $valueData->value == 'b:0;')
$valueData->value = unserialize($valueData->value);
if (!isset($fieldset_repetitions[$valueData->fieldset_repetition_key]))
$fieldset_repetitions[$valueData->fieldset_repetition_key] = clone $fieldset_orig;
if (!isset($field_repetitions[$valueData->field_repetition_key]))
$field_repetitions[$valueData->field_repetition_key] = clone $field_orig;
$field_values[$valueData->fieldset_repetition_key][$valueData->field_repetition_key] = $valueData->value;
}
}
$field->value = $field_values;
$field->repetitions = $field_repetitions;
}
$fieldset->repetitions = $fieldset_repetitions;
$fieldsets[] = $fieldset;
}
}
return $fieldsets;
} | php | public function getAllFieldsetsAttribute()
{
$fieldsets = [];
$all_fieldsets = [];
if ($this->type->fieldsets)
$all_fieldsets = $this->type->fieldsets;
if ($this->fieldsets)
$all_fieldsets = $all_fieldsets->merge($this->fieldsets);
if ($all_fieldsets) {
foreach ($all_fieldsets as $fieldset) {
$fieldset_orig = clone $fieldset;
$fieldset_repetitions = [$fieldset_orig];
foreach ($fieldset->fields as $field) {
$field_orig = clone $field;
$field_repetitions = [$field_orig];
$field_values = [];
$values = ContentFieldData::query()->where('content_id', $this->id)->where('field_id', $field->id)->get();
if ($values) {
foreach ($values as $valueData) {
if (@unserialize($valueData->value) !== false || $valueData->value == 'b:0;')
$valueData->value = unserialize($valueData->value);
if (!isset($fieldset_repetitions[$valueData->fieldset_repetition_key]))
$fieldset_repetitions[$valueData->fieldset_repetition_key] = clone $fieldset_orig;
if (!isset($field_repetitions[$valueData->field_repetition_key]))
$field_repetitions[$valueData->field_repetition_key] = clone $field_orig;
$field_values[$valueData->fieldset_repetition_key][$valueData->field_repetition_key] = $valueData->value;
}
}
$field->value = $field_values;
$field->repetitions = $field_repetitions;
}
$fieldset->repetitions = $fieldset_repetitions;
$fieldsets[] = $fieldset;
}
}
return $fieldsets;
} | [
"public",
"function",
"getAllFieldsetsAttribute",
"(",
")",
"{",
"$",
"fieldsets",
"=",
"[",
"]",
";",
"$",
"all_fieldsets",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"type",
"->",
"fieldsets",
")",
"$",
"all_fieldsets",
"=",
"$",
"this",
"->",
"type",
"->",
"fieldsets",
";",
"if",
"(",
"$",
"this",
"->",
"fieldsets",
")",
"$",
"all_fieldsets",
"=",
"$",
"all_fieldsets",
"->",
"merge",
"(",
"$",
"this",
"->",
"fieldsets",
")",
";",
"if",
"(",
"$",
"all_fieldsets",
")",
"{",
"foreach",
"(",
"$",
"all_fieldsets",
"as",
"$",
"fieldset",
")",
"{",
"$",
"fieldset_orig",
"=",
"clone",
"$",
"fieldset",
";",
"$",
"fieldset_repetitions",
"=",
"[",
"$",
"fieldset_orig",
"]",
";",
"foreach",
"(",
"$",
"fieldset",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"field_orig",
"=",
"clone",
"$",
"field",
";",
"$",
"field_repetitions",
"=",
"[",
"$",
"field_orig",
"]",
";",
"$",
"field_values",
"=",
"[",
"]",
";",
"$",
"values",
"=",
"ContentFieldData",
"::",
"query",
"(",
")",
"->",
"where",
"(",
"'content_id'",
",",
"$",
"this",
"->",
"id",
")",
"->",
"where",
"(",
"'field_id'",
",",
"$",
"field",
"->",
"id",
")",
"->",
"get",
"(",
")",
";",
"if",
"(",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"valueData",
")",
"{",
"if",
"(",
"@",
"unserialize",
"(",
"$",
"valueData",
"->",
"value",
")",
"!==",
"false",
"||",
"$",
"valueData",
"->",
"value",
"==",
"'b:0;'",
")",
"$",
"valueData",
"->",
"value",
"=",
"unserialize",
"(",
"$",
"valueData",
"->",
"value",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"fieldset_repetitions",
"[",
"$",
"valueData",
"->",
"fieldset_repetition_key",
"]",
")",
")",
"$",
"fieldset_repetitions",
"[",
"$",
"valueData",
"->",
"fieldset_repetition_key",
"]",
"=",
"clone",
"$",
"fieldset_orig",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"field_repetitions",
"[",
"$",
"valueData",
"->",
"field_repetition_key",
"]",
")",
")",
"$",
"field_repetitions",
"[",
"$",
"valueData",
"->",
"field_repetition_key",
"]",
"=",
"clone",
"$",
"field_orig",
";",
"$",
"field_values",
"[",
"$",
"valueData",
"->",
"fieldset_repetition_key",
"]",
"[",
"$",
"valueData",
"->",
"field_repetition_key",
"]",
"=",
"$",
"valueData",
"->",
"value",
";",
"}",
"}",
"$",
"field",
"->",
"value",
"=",
"$",
"field_values",
";",
"$",
"field",
"->",
"repetitions",
"=",
"$",
"field_repetitions",
";",
"}",
"$",
"fieldset",
"->",
"repetitions",
"=",
"$",
"fieldset_repetitions",
";",
"$",
"fieldsets",
"[",
"]",
"=",
"$",
"fieldset",
";",
"}",
"}",
"return",
"$",
"fieldsets",
";",
"}"
] | Add fieldsets to model.
This is where the magic happens. Basically this function iterates over each fieldset and field,
and if there is a value saved it adds it to the field's JSON object. If there are multiple values, repetitions
are added, which can be read on the frontend. | [
"Add",
"fieldsets",
"to",
"model",
"."
] | df7f3a9794afaade3bee8f6be1223c98e4936cb2 | https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/Content.php#L178-L224 |
34,557 | c4studio/chronos | src/Chronos/Content/app/Models/Content.php | Content.getEndpointsAttribute | public function getEndpointsAttribute()
{
$id = $this->attributes['id'];
$type = $this->attributes['type_id'];
$endpoints['index'] = route('api.content', ['type' => $type]);
$endpoints['destroy'] = route('api.content.destroy', ['type' => $type, 'content' => $id]);
if (settings('is_multilanguage') && ContentType::find($type)->translatable)
$endpoints['translate'] = route('api.content.translate', ['type' => $type, 'content' => $id]);
return $endpoints;
} | php | public function getEndpointsAttribute()
{
$id = $this->attributes['id'];
$type = $this->attributes['type_id'];
$endpoints['index'] = route('api.content', ['type' => $type]);
$endpoints['destroy'] = route('api.content.destroy', ['type' => $type, 'content' => $id]);
if (settings('is_multilanguage') && ContentType::find($type)->translatable)
$endpoints['translate'] = route('api.content.translate', ['type' => $type, 'content' => $id]);
return $endpoints;
} | [
"public",
"function",
"getEndpointsAttribute",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"attributes",
"[",
"'id'",
"]",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"attributes",
"[",
"'type_id'",
"]",
";",
"$",
"endpoints",
"[",
"'index'",
"]",
"=",
"route",
"(",
"'api.content'",
",",
"[",
"'type'",
"=>",
"$",
"type",
"]",
")",
";",
"$",
"endpoints",
"[",
"'destroy'",
"]",
"=",
"route",
"(",
"'api.content.destroy'",
",",
"[",
"'type'",
"=>",
"$",
"type",
",",
"'content'",
"=>",
"$",
"id",
"]",
")",
";",
"if",
"(",
"settings",
"(",
"'is_multilanguage'",
")",
"&&",
"ContentType",
"::",
"find",
"(",
"$",
"type",
")",
"->",
"translatable",
")",
"$",
"endpoints",
"[",
"'translate'",
"]",
"=",
"route",
"(",
"'api.content.translate'",
",",
"[",
"'type'",
"=>",
"$",
"type",
",",
"'content'",
"=>",
"$",
"id",
"]",
")",
";",
"return",
"$",
"endpoints",
";",
"}"
] | Add endpoints to model. | [
"Add",
"endpoints",
"to",
"model",
"."
] | df7f3a9794afaade3bee8f6be1223c98e4936cb2 | https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/Content.php#L229-L240 |
34,558 | c4studio/chronos | src/Chronos/Content/app/Models/Content.php | Content.getPathAttribute | public function getPathAttribute()
{
// add type
$path = $this->type->path;
// add parents
$crumbs = $this->crumbs;
$crumbs_path = '';
while ($crumbs) {
$crumbs_path = '/' . $crumbs->slug . $crumbs_path;
$crumbs = $crumbs->crumbs;
}
$path .= $crumbs_path;
// add slug
$path .= '/' . $this->slug;
return $path;
} | php | public function getPathAttribute()
{
// add type
$path = $this->type->path;
// add parents
$crumbs = $this->crumbs;
$crumbs_path = '';
while ($crumbs) {
$crumbs_path = '/' . $crumbs->slug . $crumbs_path;
$crumbs = $crumbs->crumbs;
}
$path .= $crumbs_path;
// add slug
$path .= '/' . $this->slug;
return $path;
} | [
"public",
"function",
"getPathAttribute",
"(",
")",
"{",
"// add type",
"$",
"path",
"=",
"$",
"this",
"->",
"type",
"->",
"path",
";",
"// add parents",
"$",
"crumbs",
"=",
"$",
"this",
"->",
"crumbs",
";",
"$",
"crumbs_path",
"=",
"''",
";",
"while",
"(",
"$",
"crumbs",
")",
"{",
"$",
"crumbs_path",
"=",
"'/'",
".",
"$",
"crumbs",
"->",
"slug",
".",
"$",
"crumbs_path",
";",
"$",
"crumbs",
"=",
"$",
"crumbs",
"->",
"crumbs",
";",
"}",
"$",
"path",
".=",
"$",
"crumbs_path",
";",
"// add slug",
"$",
"path",
".=",
"'/'",
".",
"$",
"this",
"->",
"slug",
";",
"return",
"$",
"path",
";",
"}"
] | Get path for item. | [
"Get",
"path",
"for",
"item",
"."
] | df7f3a9794afaade3bee8f6be1223c98e4936cb2 | https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/Content.php#L253-L271 |
34,559 | c4studio/chronos | src/Chronos/Content/app/Models/Content.php | Content.setTitleAttribute | public function setTitleAttribute($value) {
$this->attributes['title'] = $value;
if (!$this->slug) {
$slug = str_transliterate($value);
$slugCount = self::whereRaw('slug REGEXP "^' . $slug . '(-[0-9]*)?$"')->count();
if ($slugCount > 0)
$slug = $slug . '-' . $slugCount;
$this->attributes['slug'] = $slug;
}
} | php | public function setTitleAttribute($value) {
$this->attributes['title'] = $value;
if (!$this->slug) {
$slug = str_transliterate($value);
$slugCount = self::whereRaw('slug REGEXP "^' . $slug . '(-[0-9]*)?$"')->count();
if ($slugCount > 0)
$slug = $slug . '-' . $slugCount;
$this->attributes['slug'] = $slug;
}
} | [
"public",
"function",
"setTitleAttribute",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"'title'",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"slug",
")",
"{",
"$",
"slug",
"=",
"str_transliterate",
"(",
"$",
"value",
")",
";",
"$",
"slugCount",
"=",
"self",
"::",
"whereRaw",
"(",
"'slug REGEXP \"^'",
".",
"$",
"slug",
".",
"'(-[0-9]*)?$\"'",
")",
"->",
"count",
"(",
")",
";",
"if",
"(",
"$",
"slugCount",
">",
"0",
")",
"$",
"slug",
"=",
"$",
"slug",
".",
"'-'",
".",
"$",
"slugCount",
";",
"$",
"this",
"->",
"attributes",
"[",
"'slug'",
"]",
"=",
"$",
"slug",
";",
"}",
"}"
] | Set slug by transliterating.
@param $value | [
"Set",
"slug",
"by",
"transliterating",
"."
] | df7f3a9794afaade3bee8f6be1223c98e4936cb2 | https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/Content.php#L307-L318 |
34,560 | pckg/database | src/Pckg/Database/Entity.php | Entity.cache | public function cache($time, $type = 'app', $key = null)
{
return new Cached($this, $time, $type, $key);
} | php | public function cache($time, $type = 'app', $key = null)
{
return new Cached($this, $time, $type, $key);
} | [
"public",
"function",
"cache",
"(",
"$",
"time",
",",
"$",
"type",
"=",
"'app'",
",",
"$",
"key",
"=",
"null",
")",
"{",
"return",
"new",
"Cached",
"(",
"$",
"this",
",",
"$",
"time",
",",
"$",
"type",
",",
"$",
"key",
")",
";",
"}"
] | Wraps entity into proxy instance which takes care of handling cached requests.
@param $time
@param string $type
@return Cached|Entity | [
"Wraps",
"entity",
"into",
"proxy",
"instance",
"which",
"takes",
"care",
"of",
"handling",
"cached",
"requests",
"."
] | 99b26b4cb2bacc2bbbb83b7341a209c1cf0100d3 | https://github.com/pckg/database/blob/99b26b4cb2bacc2bbbb83b7341a209c1cf0100d3/src/Pckg/Database/Entity.php#L526-L529 |
34,561 | CESNET/perun-simplesamlphp-module | lib/Auth/Process/PerunGroups.php | PerunGroups.mapGroupName | protected function mapGroupName($request, $groupName)
{
if (isset($request["SPMetadata"]["groupMapping"]) &&
isset($request["SPMetadata"]["groupMapping"][$groupName])) {
Logger::debug(
"Mapping $groupName to " . $request["SPMetadata"]["groupMapping"][$groupName] .
" for SP " . $request["SPMetadata"]["entityid"]
);
return $request["SPMetadata"]["groupMapping"][$groupName];
} elseif (isset($request["SPMetadata"][self::GROUPNAMEPREFIX_ATTR])) {
Logger::debug(
"GroupNamePrefix overridden by a SP " . $request["SPMetadata"]["entityid"] .
" to " . $request["SPMetadata"][self::GROUPNAMEPREFIX_ATTR]
);
return $request["SPMetadata"][self::GROUPNAMEPREFIX_ATTR] . $groupName;
} else {
# No mapping defined, so just put groupNamePrefix in front of the group
Logger::debug(
"No mapping found for group $groupName for SP " . $request["SPMetadata"]["entityid"]
);
return $this->groupNamePrefix . $groupName;
}
} | php | protected function mapGroupName($request, $groupName)
{
if (isset($request["SPMetadata"]["groupMapping"]) &&
isset($request["SPMetadata"]["groupMapping"][$groupName])) {
Logger::debug(
"Mapping $groupName to " . $request["SPMetadata"]["groupMapping"][$groupName] .
" for SP " . $request["SPMetadata"]["entityid"]
);
return $request["SPMetadata"]["groupMapping"][$groupName];
} elseif (isset($request["SPMetadata"][self::GROUPNAMEPREFIX_ATTR])) {
Logger::debug(
"GroupNamePrefix overridden by a SP " . $request["SPMetadata"]["entityid"] .
" to " . $request["SPMetadata"][self::GROUPNAMEPREFIX_ATTR]
);
return $request["SPMetadata"][self::GROUPNAMEPREFIX_ATTR] . $groupName;
} else {
# No mapping defined, so just put groupNamePrefix in front of the group
Logger::debug(
"No mapping found for group $groupName for SP " . $request["SPMetadata"]["entityid"]
);
return $this->groupNamePrefix . $groupName;
}
} | [
"protected",
"function",
"mapGroupName",
"(",
"$",
"request",
",",
"$",
"groupName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"request",
"[",
"\"SPMetadata\"",
"]",
"[",
"\"groupMapping\"",
"]",
")",
"&&",
"isset",
"(",
"$",
"request",
"[",
"\"SPMetadata\"",
"]",
"[",
"\"groupMapping\"",
"]",
"[",
"$",
"groupName",
"]",
")",
")",
"{",
"Logger",
"::",
"debug",
"(",
"\"Mapping $groupName to \"",
".",
"$",
"request",
"[",
"\"SPMetadata\"",
"]",
"[",
"\"groupMapping\"",
"]",
"[",
"$",
"groupName",
"]",
".",
"\" for SP \"",
".",
"$",
"request",
"[",
"\"SPMetadata\"",
"]",
"[",
"\"entityid\"",
"]",
")",
";",
"return",
"$",
"request",
"[",
"\"SPMetadata\"",
"]",
"[",
"\"groupMapping\"",
"]",
"[",
"$",
"groupName",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"request",
"[",
"\"SPMetadata\"",
"]",
"[",
"self",
"::",
"GROUPNAMEPREFIX_ATTR",
"]",
")",
")",
"{",
"Logger",
"::",
"debug",
"(",
"\"GroupNamePrefix overridden by a SP \"",
".",
"$",
"request",
"[",
"\"SPMetadata\"",
"]",
"[",
"\"entityid\"",
"]",
".",
"\" to \"",
".",
"$",
"request",
"[",
"\"SPMetadata\"",
"]",
"[",
"self",
"::",
"GROUPNAMEPREFIX_ATTR",
"]",
")",
";",
"return",
"$",
"request",
"[",
"\"SPMetadata\"",
"]",
"[",
"self",
"::",
"GROUPNAMEPREFIX_ATTR",
"]",
".",
"$",
"groupName",
";",
"}",
"else",
"{",
"# No mapping defined, so just put groupNamePrefix in front of the group",
"Logger",
"::",
"debug",
"(",
"\"No mapping found for group $groupName for SP \"",
".",
"$",
"request",
"[",
"\"SPMetadata\"",
"]",
"[",
"\"entityid\"",
"]",
")",
";",
"return",
"$",
"this",
"->",
"groupNamePrefix",
".",
"$",
"groupName",
";",
"}",
"}"
] | This method translates given name of group based on associative array 'groupMapping' in SP metadata.
@param $request
@param string $groupName
@return string translated group name | [
"This",
"method",
"translates",
"given",
"name",
"of",
"group",
"based",
"on",
"associative",
"array",
"groupMapping",
"in",
"SP",
"metadata",
"."
] | f1d686f06472053a7cdb31f2b2776f9714779ee1 | https://github.com/CESNET/perun-simplesamlphp-module/blob/f1d686f06472053a7cdb31f2b2776f9714779ee1/lib/Auth/Process/PerunGroups.php#L113-L135 |
34,562 | jon48/webtrees-lib | src/Webtrees/Controller/IndividualController.php | IndividualController.printHeaderExtensions | public function printHeaderExtensions(){
$hook_extend_indi_header_left = new mw\Hook\Hook('hExtendIndiHeaderLeft');
$hook_extend_indi_header_right = new mw\Hook\Hook('hExtendIndiHeaderRight');
$hook_extend_indi_header_left = $hook_extend_indi_header_left->execute($this->ctrl_individual);
$hook_extend_indi_header_right = $hook_extend_indi_header_right->execute($this->ctrl_individual);
echo '<div id="indi_perso_header">',
'<div id="indi_perso_header_left">';
foreach ($hook_extend_indi_header_left as $div) {
if(count($div)==2){
echo '<div id="', $div[0], '" class="indi_perso_header_left_div">',
$div[1], '</div>';
}
}
echo '</div>',
'<div id="indi_perso_header_right">';
foreach ($hook_extend_indi_header_right as $div) {
if(count($div)==2){
echo '<div id="', $div[0], '" class="indi_perso_header_right_div">',
$div[1], '</div>';
}
}
echo '</div>',
'</div>';
} | php | public function printHeaderExtensions(){
$hook_extend_indi_header_left = new mw\Hook\Hook('hExtendIndiHeaderLeft');
$hook_extend_indi_header_right = new mw\Hook\Hook('hExtendIndiHeaderRight');
$hook_extend_indi_header_left = $hook_extend_indi_header_left->execute($this->ctrl_individual);
$hook_extend_indi_header_right = $hook_extend_indi_header_right->execute($this->ctrl_individual);
echo '<div id="indi_perso_header">',
'<div id="indi_perso_header_left">';
foreach ($hook_extend_indi_header_left as $div) {
if(count($div)==2){
echo '<div id="', $div[0], '" class="indi_perso_header_left_div">',
$div[1], '</div>';
}
}
echo '</div>',
'<div id="indi_perso_header_right">';
foreach ($hook_extend_indi_header_right as $div) {
if(count($div)==2){
echo '<div id="', $div[0], '" class="indi_perso_header_right_div">',
$div[1], '</div>';
}
}
echo '</div>',
'</div>';
} | [
"public",
"function",
"printHeaderExtensions",
"(",
")",
"{",
"$",
"hook_extend_indi_header_left",
"=",
"new",
"mw",
"\\",
"Hook",
"\\",
"Hook",
"(",
"'hExtendIndiHeaderLeft'",
")",
";",
"$",
"hook_extend_indi_header_right",
"=",
"new",
"mw",
"\\",
"Hook",
"\\",
"Hook",
"(",
"'hExtendIndiHeaderRight'",
")",
";",
"$",
"hook_extend_indi_header_left",
"=",
"$",
"hook_extend_indi_header_left",
"->",
"execute",
"(",
"$",
"this",
"->",
"ctrl_individual",
")",
";",
"$",
"hook_extend_indi_header_right",
"=",
"$",
"hook_extend_indi_header_right",
"->",
"execute",
"(",
"$",
"this",
"->",
"ctrl_individual",
")",
";",
"echo",
"'<div id=\"indi_perso_header\">'",
",",
"'<div id=\"indi_perso_header_left\">'",
";",
"foreach",
"(",
"$",
"hook_extend_indi_header_left",
"as",
"$",
"div",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"div",
")",
"==",
"2",
")",
"{",
"echo",
"'<div id=\"'",
",",
"$",
"div",
"[",
"0",
"]",
",",
"'\" class=\"indi_perso_header_left_div\">'",
",",
"$",
"div",
"[",
"1",
"]",
",",
"'</div>'",
";",
"}",
"}",
"echo",
"'</div>'",
",",
"'<div id=\"indi_perso_header_right\">'",
";",
"foreach",
"(",
"$",
"hook_extend_indi_header_right",
"as",
"$",
"div",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"div",
")",
"==",
"2",
")",
"{",
"echo",
"'<div id=\"'",
",",
"$",
"div",
"[",
"0",
"]",
",",
"'\" class=\"indi_perso_header_right_div\">'",
",",
"$",
"div",
"[",
"1",
"]",
",",
"'</div>'",
";",
"}",
"}",
"echo",
"'</div>'",
",",
"'</div>'",
";",
"}"
] | Print individual header extensions.
Use hooks hExtendIndiHeaderLeft and hExtendIndiHeaderRight
@uses \MyArtJaub\Webtrees\Hook\Hook | [
"Print",
"individual",
"header",
"extensions",
".",
"Use",
"hooks",
"hExtendIndiHeaderLeft",
"and",
"hExtendIndiHeaderRight"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Controller/IndividualController.php#L46-L70 |
34,563 | jon48/webtrees-lib | src/Webtrees/Controller/IndividualController.php | IndividualController.printHeaderExtraIcons | public function printHeaderExtraIcons(){
$hook_extend_indi_header_icons = new Hook('hExtendIndiHeaderIcons');
$hook_extend_indi_header_icons = $hook_extend_indi_header_icons->execute($this->ctrl_individual);
echo '<span id="indi_perso_icons"> ',
implode(' ', $hook_extend_indi_header_icons),
'</span>';
} | php | public function printHeaderExtraIcons(){
$hook_extend_indi_header_icons = new Hook('hExtendIndiHeaderIcons');
$hook_extend_indi_header_icons = $hook_extend_indi_header_icons->execute($this->ctrl_individual);
echo '<span id="indi_perso_icons"> ',
implode(' ', $hook_extend_indi_header_icons),
'</span>';
} | [
"public",
"function",
"printHeaderExtraIcons",
"(",
")",
"{",
"$",
"hook_extend_indi_header_icons",
"=",
"new",
"Hook",
"(",
"'hExtendIndiHeaderIcons'",
")",
";",
"$",
"hook_extend_indi_header_icons",
"=",
"$",
"hook_extend_indi_header_icons",
"->",
"execute",
"(",
"$",
"this",
"->",
"ctrl_individual",
")",
";",
"echo",
"'<span id=\"indi_perso_icons\"> '",
",",
"implode",
"(",
"' '",
",",
"$",
"hook_extend_indi_header_icons",
")",
",",
"'</span>'",
";",
"}"
] | Print individual header extra icons.
Use hook hExtendIndiHeaderIcons
@uses \MyArtJaub\Webtrees\Hook\Hook | [
"Print",
"individual",
"header",
"extra",
"icons",
".",
"Use",
"hook",
"hExtendIndiHeaderIcons"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Controller/IndividualController.php#L78-L85 |
34,564 | jon48/webtrees-lib | src/Webtrees/Cache.php | Cache.init | protected function init() {
if(Apc::isAvailable()) {
$driver = new Apc();
} else {
if (!is_dir(WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache')) {
// We may not have permission - especially during setup, before we instruct
// the user to "chmod 777 /data"
@mkdir(WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache');
}
if (is_dir(WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache')) {
$driver = new FileSystem(array('path' => WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache'));
} else {
// No cache available, let's just use a basic one :-(
$driver = new Ephemeral();
}
}
$this->cache = new \Stash\Pool($driver);
$this->is_init = true;
} | php | protected function init() {
if(Apc::isAvailable()) {
$driver = new Apc();
} else {
if (!is_dir(WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache')) {
// We may not have permission - especially during setup, before we instruct
// the user to "chmod 777 /data"
@mkdir(WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache');
}
if (is_dir(WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache')) {
$driver = new FileSystem(array('path' => WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache'));
} else {
// No cache available, let's just use a basic one :-(
$driver = new Ephemeral();
}
}
$this->cache = new \Stash\Pool($driver);
$this->is_init = true;
} | [
"protected",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"Apc",
"::",
"isAvailable",
"(",
")",
")",
"{",
"$",
"driver",
"=",
"new",
"Apc",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"WT_DATA_DIR",
".",
"DIRECTORY_SEPARATOR",
".",
"'cache'",
")",
")",
"{",
"// We may not have permission - especially during setup, before we instruct",
"// the user to \"chmod 777 /data\"",
"@",
"mkdir",
"(",
"WT_DATA_DIR",
".",
"DIRECTORY_SEPARATOR",
".",
"'cache'",
")",
";",
"}",
"if",
"(",
"is_dir",
"(",
"WT_DATA_DIR",
".",
"DIRECTORY_SEPARATOR",
".",
"'cache'",
")",
")",
"{",
"$",
"driver",
"=",
"new",
"FileSystem",
"(",
"array",
"(",
"'path'",
"=>",
"WT_DATA_DIR",
".",
"DIRECTORY_SEPARATOR",
".",
"'cache'",
")",
")",
";",
"}",
"else",
"{",
"// No cache available, let's just use a basic one :-(",
"$",
"driver",
"=",
"new",
"Ephemeral",
"(",
")",
";",
"}",
"}",
"$",
"this",
"->",
"cache",
"=",
"new",
"\\",
"Stash",
"\\",
"Pool",
"(",
"$",
"driver",
")",
";",
"$",
"this",
"->",
"is_init",
"=",
"true",
";",
"}"
] | Initialise the Cache class | [
"Initialise",
"the",
"Cache",
"class"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Cache.php#L61-L80 |
34,565 | jon48/webtrees-lib | src/Webtrees/Cache.php | Cache.getKeyName | protected function getKeyName($value, AbstractModule $mod = null){
$this->checkInit();
$mod_name = 'myartjaub';
if($mod !== null) $mod_name = $mod->getName();
return $mod_name.'_'.$value;
} | php | protected function getKeyName($value, AbstractModule $mod = null){
$this->checkInit();
$mod_name = 'myartjaub';
if($mod !== null) $mod_name = $mod->getName();
return $mod_name.'_'.$value;
} | [
"protected",
"function",
"getKeyName",
"(",
"$",
"value",
",",
"AbstractModule",
"$",
"mod",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"checkInit",
"(",
")",
";",
"$",
"mod_name",
"=",
"'myartjaub'",
";",
"if",
"(",
"$",
"mod",
"!==",
"null",
")",
"$",
"mod_name",
"=",
"$",
"mod",
"->",
"getName",
"(",
")",
";",
"return",
"$",
"mod_name",
".",
"'_'",
".",
"$",
"value",
";",
"}"
] | Returns the name of the cached key, based on the value name and the calling module
@param string $value Value name
@param AbstractModule $mod Calling module
@return string Cached key name | [
"Returns",
"the",
"name",
"of",
"the",
"cached",
"key",
"based",
"on",
"the",
"value",
"name",
"and",
"the",
"calling",
"module"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Cache.php#L97-L102 |
34,566 | jon48/webtrees-lib | src/Webtrees/Cache.php | Cache.getI | public function getI($value, AbstractModule $mod = null){
$this->checkInit();
return $this->cache->getItem($this->getKeyName($value, $mod));
} | php | public function getI($value, AbstractModule $mod = null){
$this->checkInit();
return $this->cache->getItem($this->getKeyName($value, $mod));
} | [
"public",
"function",
"getI",
"(",
"$",
"value",
",",
"AbstractModule",
"$",
"mod",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"checkInit",
"(",
")",
";",
"return",
"$",
"this",
"->",
"cache",
"->",
"getItem",
"(",
"$",
"this",
"->",
"getKeyName",
"(",
"$",
"value",
",",
"$",
"mod",
")",
")",
";",
"}"
] | Returns the cached value, if exists
@param string $value Value name
@param AbstractModule $mod Calling module
@return \Psr\Cache\CacheItemInterface | [
"Returns",
"the",
"cached",
"value",
"if",
"exists"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Cache.php#L111-L114 |
34,567 | jon48/webtrees-lib | src/Webtrees/Cache.php | Cache.saveI | public function saveI($value, $data, AbstractModule $mod = null){
$this->checkInit();
$item = $value;
if(!($value instanceof CacheItemInterface)) {
$item = new \Stash\Item();
$item->setKey($this->getKeyName($value, $mod));
}
$item->set($data);
$this->cache->save($item);
} | php | public function saveI($value, $data, AbstractModule $mod = null){
$this->checkInit();
$item = $value;
if(!($value instanceof CacheItemInterface)) {
$item = new \Stash\Item();
$item->setKey($this->getKeyName($value, $mod));
}
$item->set($data);
$this->cache->save($item);
} | [
"public",
"function",
"saveI",
"(",
"$",
"value",
",",
"$",
"data",
",",
"AbstractModule",
"$",
"mod",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"checkInit",
"(",
")",
";",
"$",
"item",
"=",
"$",
"value",
";",
"if",
"(",
"!",
"(",
"$",
"value",
"instanceof",
"CacheItemInterface",
")",
")",
"{",
"$",
"item",
"=",
"new",
"\\",
"Stash",
"\\",
"Item",
"(",
")",
";",
"$",
"item",
"->",
"setKey",
"(",
"$",
"this",
"->",
"getKeyName",
"(",
"$",
"value",
",",
"$",
"mod",
")",
")",
";",
"}",
"$",
"item",
"->",
"set",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"$",
"item",
")",
";",
"}"
] | Cache a value to the specified key
@param string|\Psr\Cache\CacheItemInterface $value Value name
@param mixed $data Value
@param AbstractModule $mod Calling module | [
"Cache",
"a",
"value",
"to",
"the",
"specified",
"key"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Cache.php#L134-L144 |
34,568 | jon48/webtrees-lib | src/Webtrees/Cache.php | Cache.deleteI | public function deleteI($value, AbstractModule $mod = null){
$this->checkInit();
return $this->cache->deleteItem($this->getKeyName($value, $mod));
} | php | public function deleteI($value, AbstractModule $mod = null){
$this->checkInit();
return $this->cache->deleteItem($this->getKeyName($value, $mod));
} | [
"public",
"function",
"deleteI",
"(",
"$",
"value",
",",
"AbstractModule",
"$",
"mod",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"checkInit",
"(",
")",
";",
"return",
"$",
"this",
"->",
"cache",
"->",
"deleteItem",
"(",
"$",
"this",
"->",
"getKeyName",
"(",
"$",
"value",
",",
"$",
"mod",
")",
")",
";",
"}"
] | Delete the value associated to the specified key
@param string $value Value name
@param AbstractModule $mod Calling module
@return bool Deletion successful? | [
"Delete",
"the",
"value",
"associated",
"to",
"the",
"specified",
"key"
] | e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7 | https://github.com/jon48/webtrees-lib/blob/e8097cdfcdbb3c9e885e7e06fe7683ed39267bb7/src/Webtrees/Cache.php#L164-L167 |
34,569 | c4studio/chronos | src/Chronos/Content/ContentServiceProvider.php | ContentServiceProvider.registerKernels | public function registerKernels()
{
if (class_exists('Chronos\Content\Console\Kernel')) {
$this->app->singleton('chronos.content.console.kernel', function($app) {
$dispatcher = $app->make(Dispatcher::class);
return new Kernel($app, $dispatcher);
});
$this->app->make('chronos.content.console.kernel');
}
} | php | public function registerKernels()
{
if (class_exists('Chronos\Content\Console\Kernel')) {
$this->app->singleton('chronos.content.console.kernel', function($app) {
$dispatcher = $app->make(Dispatcher::class);
return new Kernel($app, $dispatcher);
});
$this->app->make('chronos.content.console.kernel');
}
} | [
"public",
"function",
"registerKernels",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'Chronos\\Content\\Console\\Kernel'",
")",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'chronos.content.console.kernel'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"dispatcher",
"=",
"$",
"app",
"->",
"make",
"(",
"Dispatcher",
"::",
"class",
")",
";",
"return",
"new",
"Kernel",
"(",
"$",
"app",
",",
"$",
"dispatcher",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'chronos.content.console.kernel'",
")",
";",
"}",
"}"
] | Registers package kernels | [
"Registers",
"package",
"kernels"
] | df7f3a9794afaade3bee8f6be1223c98e4936cb2 | https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/ContentServiceProvider.php#L83-L93 |
34,570 | c4studio/chronos | src/Chronos/Content/ContentServiceProvider.php | ContentServiceProvider.updateMenu | protected function updateMenu()
{
$menu = \Menu::get('ChronosMenu');
// Content tab
$content_menu = $menu->add(trans('chronos.content::menu.Content'), null)
->prepend('<span class="icon c4icon-pencil-3"></span>')
->data('order', 100)->data('permissions', ['view_content_types', 'view_media']);
if (class_exists('Chronos\Content\Models\ContentType') && Schema::hasTable('content_types')) {
$types = \Chronos\Content\Models\ContentType::orderBy('name')->get();
if ($types) {
foreach ($types as $k => $type) {
$content_menu->add($type->name, ['route' => ['chronos.content', 'type' => $type->id]])
->data('order', 100 + $k * 5)->data('permissions', ['view_content_type_' . $type->id]);
}
}
}
$content_menu->add(trans('chronos.content::menu.Media'), ['route' => 'chronos.content.media'])
->data('order', 800)->data('permissions', ['view_media']);
$content_menu->add(trans('chronos.content::menu.Content types'), ['route' => 'chronos.content.types'])
->data('order', 900)->data('permissions', ['view_content_types']);
// Settings tab
if (class_exists('Chronos\Scaffolding\Models\Setting') && \Schema::hasTable('settings') && settings('is_multilanguage')) {
$settings_menu = $menu->get(camel_case(trans('chronos.scaffolding::menu.Settings')));
$settings_permissions = $settings_menu->permissions;
$settings_permissions[] = 'edit_languages';
$settings_menu->data('permissions', $settings_permissions);
$settings_menu->add(trans('chronos.content::menu.Languages'), ['route' => 'chronos.settings.languages'])
->data('order', 920)->data('permissions', ['edit_languages']);
}
} | php | protected function updateMenu()
{
$menu = \Menu::get('ChronosMenu');
// Content tab
$content_menu = $menu->add(trans('chronos.content::menu.Content'), null)
->prepend('<span class="icon c4icon-pencil-3"></span>')
->data('order', 100)->data('permissions', ['view_content_types', 'view_media']);
if (class_exists('Chronos\Content\Models\ContentType') && Schema::hasTable('content_types')) {
$types = \Chronos\Content\Models\ContentType::orderBy('name')->get();
if ($types) {
foreach ($types as $k => $type) {
$content_menu->add($type->name, ['route' => ['chronos.content', 'type' => $type->id]])
->data('order', 100 + $k * 5)->data('permissions', ['view_content_type_' . $type->id]);
}
}
}
$content_menu->add(trans('chronos.content::menu.Media'), ['route' => 'chronos.content.media'])
->data('order', 800)->data('permissions', ['view_media']);
$content_menu->add(trans('chronos.content::menu.Content types'), ['route' => 'chronos.content.types'])
->data('order', 900)->data('permissions', ['view_content_types']);
// Settings tab
if (class_exists('Chronos\Scaffolding\Models\Setting') && \Schema::hasTable('settings') && settings('is_multilanguage')) {
$settings_menu = $menu->get(camel_case(trans('chronos.scaffolding::menu.Settings')));
$settings_permissions = $settings_menu->permissions;
$settings_permissions[] = 'edit_languages';
$settings_menu->data('permissions', $settings_permissions);
$settings_menu->add(trans('chronos.content::menu.Languages'), ['route' => 'chronos.settings.languages'])
->data('order', 920)->data('permissions', ['edit_languages']);
}
} | [
"protected",
"function",
"updateMenu",
"(",
")",
"{",
"$",
"menu",
"=",
"\\",
"Menu",
"::",
"get",
"(",
"'ChronosMenu'",
")",
";",
"// Content tab",
"$",
"content_menu",
"=",
"$",
"menu",
"->",
"add",
"(",
"trans",
"(",
"'chronos.content::menu.Content'",
")",
",",
"null",
")",
"->",
"prepend",
"(",
"'<span class=\"icon c4icon-pencil-3\"></span>'",
")",
"->",
"data",
"(",
"'order'",
",",
"100",
")",
"->",
"data",
"(",
"'permissions'",
",",
"[",
"'view_content_types'",
",",
"'view_media'",
"]",
")",
";",
"if",
"(",
"class_exists",
"(",
"'Chronos\\Content\\Models\\ContentType'",
")",
"&&",
"Schema",
"::",
"hasTable",
"(",
"'content_types'",
")",
")",
"{",
"$",
"types",
"=",
"\\",
"Chronos",
"\\",
"Content",
"\\",
"Models",
"\\",
"ContentType",
"::",
"orderBy",
"(",
"'name'",
")",
"->",
"get",
"(",
")",
";",
"if",
"(",
"$",
"types",
")",
"{",
"foreach",
"(",
"$",
"types",
"as",
"$",
"k",
"=>",
"$",
"type",
")",
"{",
"$",
"content_menu",
"->",
"add",
"(",
"$",
"type",
"->",
"name",
",",
"[",
"'route'",
"=>",
"[",
"'chronos.content'",
",",
"'type'",
"=>",
"$",
"type",
"->",
"id",
"]",
"]",
")",
"->",
"data",
"(",
"'order'",
",",
"100",
"+",
"$",
"k",
"*",
"5",
")",
"->",
"data",
"(",
"'permissions'",
",",
"[",
"'view_content_type_'",
".",
"$",
"type",
"->",
"id",
"]",
")",
";",
"}",
"}",
"}",
"$",
"content_menu",
"->",
"add",
"(",
"trans",
"(",
"'chronos.content::menu.Media'",
")",
",",
"[",
"'route'",
"=>",
"'chronos.content.media'",
"]",
")",
"->",
"data",
"(",
"'order'",
",",
"800",
")",
"->",
"data",
"(",
"'permissions'",
",",
"[",
"'view_media'",
"]",
")",
";",
"$",
"content_menu",
"->",
"add",
"(",
"trans",
"(",
"'chronos.content::menu.Content types'",
")",
",",
"[",
"'route'",
"=>",
"'chronos.content.types'",
"]",
")",
"->",
"data",
"(",
"'order'",
",",
"900",
")",
"->",
"data",
"(",
"'permissions'",
",",
"[",
"'view_content_types'",
"]",
")",
";",
"// Settings tab",
"if",
"(",
"class_exists",
"(",
"'Chronos\\Scaffolding\\Models\\Setting'",
")",
"&&",
"\\",
"Schema",
"::",
"hasTable",
"(",
"'settings'",
")",
"&&",
"settings",
"(",
"'is_multilanguage'",
")",
")",
"{",
"$",
"settings_menu",
"=",
"$",
"menu",
"->",
"get",
"(",
"camel_case",
"(",
"trans",
"(",
"'chronos.scaffolding::menu.Settings'",
")",
")",
")",
";",
"$",
"settings_permissions",
"=",
"$",
"settings_menu",
"->",
"permissions",
";",
"$",
"settings_permissions",
"[",
"]",
"=",
"'edit_languages'",
";",
"$",
"settings_menu",
"->",
"data",
"(",
"'permissions'",
",",
"$",
"settings_permissions",
")",
";",
"$",
"settings_menu",
"->",
"add",
"(",
"trans",
"(",
"'chronos.content::menu.Languages'",
")",
",",
"[",
"'route'",
"=>",
"'chronos.settings.languages'",
"]",
")",
"->",
"data",
"(",
"'order'",
",",
"920",
")",
"->",
"data",
"(",
"'permissions'",
",",
"[",
"'edit_languages'",
"]",
")",
";",
"}",
"}"
] | Updates menu. | [
"Updates",
"menu",
"."
] | df7f3a9794afaade3bee8f6be1223c98e4936cb2 | https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/ContentServiceProvider.php#L99-L131 |
34,571 | voslartomas/WebCMS2 | AdminModule/presenters/FilesystemPresenter.php | FilesystemPresenter.getMaxUploadFileSize | public function getMaxUploadFileSize()
{
static $max_size = -1;
if ($max_size < 0) {
// Start with post_max_size.
$max_size = $this->parseFileSize(ini_get('post_max_size'));
// If upload_max_size is less, then reduce. Except if upload_max_size is
// zero, which indicates no limit.
$upload_max = $this->parseFileSize(ini_get('upload_max_filesize'));
if ($upload_max > 0 && $upload_max < $max_size) {
$max_size = $upload_max;
}
}
return $max_size;
} | php | public function getMaxUploadFileSize()
{
static $max_size = -1;
if ($max_size < 0) {
// Start with post_max_size.
$max_size = $this->parseFileSize(ini_get('post_max_size'));
// If upload_max_size is less, then reduce. Except if upload_max_size is
// zero, which indicates no limit.
$upload_max = $this->parseFileSize(ini_get('upload_max_filesize'));
if ($upload_max > 0 && $upload_max < $max_size) {
$max_size = $upload_max;
}
}
return $max_size;
} | [
"public",
"function",
"getMaxUploadFileSize",
"(",
")",
"{",
"static",
"$",
"max_size",
"=",
"-",
"1",
";",
"if",
"(",
"$",
"max_size",
"<",
"0",
")",
"{",
"// Start with post_max_size.",
"$",
"max_size",
"=",
"$",
"this",
"->",
"parseFileSize",
"(",
"ini_get",
"(",
"'post_max_size'",
")",
")",
";",
"// If upload_max_size is less, then reduce. Except if upload_max_size is",
"// zero, which indicates no limit.",
"$",
"upload_max",
"=",
"$",
"this",
"->",
"parseFileSize",
"(",
"ini_get",
"(",
"'upload_max_filesize'",
")",
")",
";",
"if",
"(",
"$",
"upload_max",
">",
"0",
"&&",
"$",
"upload_max",
"<",
"$",
"max_size",
")",
"{",
"$",
"max_size",
"=",
"$",
"upload_max",
";",
"}",
"}",
"return",
"$",
"max_size",
";",
"}"
] | Get the maximal file upload size from the environment variables.
@author Taken from the Drupal.org project
@license GPL 2
@return int | [
"Get",
"the",
"maximal",
"file",
"upload",
"size",
"from",
"the",
"environment",
"variables",
"."
] | b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf | https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/AdminModule/presenters/FilesystemPresenter.php#L226-L243 |
34,572 | voslartomas/WebCMS2 | AdminModule/presenters/FilesystemPresenter.php | FilesystemPresenter.parseFileSize | public function parseFileSize($size)
{
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size.
$size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size.
if ($unit) {
// Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.
return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
} else {
return round($size);
}
} | php | public function parseFileSize($size)
{
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size.
$size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size.
if ($unit) {
// Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.
return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
} else {
return round($size);
}
} | [
"public",
"function",
"parseFileSize",
"(",
"$",
"size",
")",
"{",
"$",
"unit",
"=",
"preg_replace",
"(",
"'/[^bkmgtpezy]/i'",
",",
"''",
",",
"$",
"size",
")",
";",
"// Remove the non-unit characters from the size.",
"$",
"size",
"=",
"preg_replace",
"(",
"'/[^0-9\\.]/'",
",",
"''",
",",
"$",
"size",
")",
";",
"// Remove the non-numeric characters from the size.",
"if",
"(",
"$",
"unit",
")",
"{",
"// Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.",
"return",
"round",
"(",
"$",
"size",
"*",
"pow",
"(",
"1024",
",",
"stripos",
"(",
"'bkmgtpezy'",
",",
"$",
"unit",
"[",
"0",
"]",
")",
")",
")",
";",
"}",
"else",
"{",
"return",
"round",
"(",
"$",
"size",
")",
";",
"}",
"}"
] | Parse file size.
@author Taken from the Drupal.org project
@license GPL 2
@return int | [
"Parse",
"file",
"size",
"."
] | b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf | https://github.com/voslartomas/WebCMS2/blob/b39ea4b2fd30e87ff5e4fa81441cefa308e51fbf/AdminModule/presenters/FilesystemPresenter.php#L252-L262 |
34,573 | nails/module-cdn | src/Api/Controller/Bucket.php | Bucket.getList | public function getList()
{
if (!userHasPermission('admin:cdn:manager:object:browse')) {
throw new ApiException(
'You do not have permission to access this resource',
$oHttpCodes::STATUS_UNAUTHORIZED
);
}
$oInput = Factory::service('Input');
$oObjectModel = Factory::model('Object', 'nails/module-cdn');
$iBucketId = (int) $oInput->get('bucket_id') ?: null;
$iPage = (int) $oInput->get('page') ?: 1;
if (empty($iBucketId)) {
throw new ApiException(
'`bucket_id` is a required field',
$oHttpCodes::STATUS_BAD_REQUEST
);
}
$aObjects = $oObjectModel->getAll(
$iPage,
static::CONFIG_OBJECTS_PER_PAGE,
['where' => [['bucket_id', $iBucketId]]]
);
return Factory::factory('ApiResponse', 'nails/module-api')
->setData(array_map(
function ($oObj) {
$oObj->url->preview = $oObj->is_img ? cdnCrop($oObj->id, 400, 400) : null;
return $oObj;
},
$aObjects
))
->setMeta([
'page' => $iPage,
'per_page' => static::CONFIG_OBJECTS_PER_PAGE,
]);
} | php | public function getList()
{
if (!userHasPermission('admin:cdn:manager:object:browse')) {
throw new ApiException(
'You do not have permission to access this resource',
$oHttpCodes::STATUS_UNAUTHORIZED
);
}
$oInput = Factory::service('Input');
$oObjectModel = Factory::model('Object', 'nails/module-cdn');
$iBucketId = (int) $oInput->get('bucket_id') ?: null;
$iPage = (int) $oInput->get('page') ?: 1;
if (empty($iBucketId)) {
throw new ApiException(
'`bucket_id` is a required field',
$oHttpCodes::STATUS_BAD_REQUEST
);
}
$aObjects = $oObjectModel->getAll(
$iPage,
static::CONFIG_OBJECTS_PER_PAGE,
['where' => [['bucket_id', $iBucketId]]]
);
return Factory::factory('ApiResponse', 'nails/module-api')
->setData(array_map(
function ($oObj) {
$oObj->url->preview = $oObj->is_img ? cdnCrop($oObj->id, 400, 400) : null;
return $oObj;
},
$aObjects
))
->setMeta([
'page' => $iPage,
'per_page' => static::CONFIG_OBJECTS_PER_PAGE,
]);
} | [
"public",
"function",
"getList",
"(",
")",
"{",
"if",
"(",
"!",
"userHasPermission",
"(",
"'admin:cdn:manager:object:browse'",
")",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"'You do not have permission to access this resource'",
",",
"$",
"oHttpCodes",
"::",
"STATUS_UNAUTHORIZED",
")",
";",
"}",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"$",
"oObjectModel",
"=",
"Factory",
"::",
"model",
"(",
"'Object'",
",",
"'nails/module-cdn'",
")",
";",
"$",
"iBucketId",
"=",
"(",
"int",
")",
"$",
"oInput",
"->",
"get",
"(",
"'bucket_id'",
")",
"?",
":",
"null",
";",
"$",
"iPage",
"=",
"(",
"int",
")",
"$",
"oInput",
"->",
"get",
"(",
"'page'",
")",
"?",
":",
"1",
";",
"if",
"(",
"empty",
"(",
"$",
"iBucketId",
")",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"'`bucket_id` is a required field'",
",",
"$",
"oHttpCodes",
"::",
"STATUS_BAD_REQUEST",
")",
";",
"}",
"$",
"aObjects",
"=",
"$",
"oObjectModel",
"->",
"getAll",
"(",
"$",
"iPage",
",",
"static",
"::",
"CONFIG_OBJECTS_PER_PAGE",
",",
"[",
"'where'",
"=>",
"[",
"[",
"'bucket_id'",
",",
"$",
"iBucketId",
"]",
"]",
"]",
")",
";",
"return",
"Factory",
"::",
"factory",
"(",
"'ApiResponse'",
",",
"'nails/module-api'",
")",
"->",
"setData",
"(",
"array_map",
"(",
"function",
"(",
"$",
"oObj",
")",
"{",
"$",
"oObj",
"->",
"url",
"->",
"preview",
"=",
"$",
"oObj",
"->",
"is_img",
"?",
"cdnCrop",
"(",
"$",
"oObj",
"->",
"id",
",",
"400",
",",
"400",
")",
":",
"null",
";",
"return",
"$",
"oObj",
";",
"}",
",",
"$",
"aObjects",
")",
")",
"->",
"setMeta",
"(",
"[",
"'page'",
"=>",
"$",
"iPage",
",",
"'per_page'",
"=>",
"static",
"::",
"CONFIG_OBJECTS_PER_PAGE",
",",
"]",
")",
";",
"}"
] | Returns a paginated list of a bucket's contents
@return array | [
"Returns",
"a",
"paginated",
"list",
"of",
"a",
"bucket",
"s",
"contents"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Api/Controller/Bucket.php#L38-L77 |
34,574 | nails/module-cdn | src/Api/Controller/Bucket.php | Bucket.postIndex | public function postIndex()
{
$oInput = Factory::service('Input');
$oHttpCodes = Factory::service('HttpCodes');
if (!userHasPermission('admin:cdn:manager:bucket:create')) {
throw new ApiException(
'You do not have permission to create this resource',
$oHttpCodes::STATUS_UNAUTHORIZED
);
}
// @todo (Pablo - 2018-08-16) - Remove once CrudController validates properly itself
if (!$oInput->post('label')) {
throw new ApiException(
'`label` is a required field',
$oHttpCodes::STATUS_UNAUTHORIZED
);
}
return parent::postIndex();
} | php | public function postIndex()
{
$oInput = Factory::service('Input');
$oHttpCodes = Factory::service('HttpCodes');
if (!userHasPermission('admin:cdn:manager:bucket:create')) {
throw new ApiException(
'You do not have permission to create this resource',
$oHttpCodes::STATUS_UNAUTHORIZED
);
}
// @todo (Pablo - 2018-08-16) - Remove once CrudController validates properly itself
if (!$oInput->post('label')) {
throw new ApiException(
'`label` is a required field',
$oHttpCodes::STATUS_UNAUTHORIZED
);
}
return parent::postIndex();
} | [
"public",
"function",
"postIndex",
"(",
")",
"{",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"$",
"oHttpCodes",
"=",
"Factory",
"::",
"service",
"(",
"'HttpCodes'",
")",
";",
"if",
"(",
"!",
"userHasPermission",
"(",
"'admin:cdn:manager:bucket:create'",
")",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"'You do not have permission to create this resource'",
",",
"$",
"oHttpCodes",
"::",
"STATUS_UNAUTHORIZED",
")",
";",
"}",
"// @todo (Pablo - 2018-08-16) - Remove once CrudController validates properly itself",
"if",
"(",
"!",
"$",
"oInput",
"->",
"post",
"(",
"'label'",
")",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"'`label` is a required field'",
",",
"$",
"oHttpCodes",
"::",
"STATUS_UNAUTHORIZED",
")",
";",
"}",
"return",
"parent",
"::",
"postIndex",
"(",
")",
";",
"}"
] | Overridden to check user permissions before creating buckets
@return array | [
"Overridden",
"to",
"check",
"user",
"permissions",
"before",
"creating",
"buckets"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Api/Controller/Bucket.php#L86-L107 |
34,575 | c4studio/chronos | src/Chronos/Content/app/Models/Media.php | Media.getAltAttribute | public function getAltAttribute()
{
$data = unserialize($this->attributes['data']);
return $data === false ? null : (isset($data['alt']) ? $data['alt'] : null);
} | php | public function getAltAttribute()
{
$data = unserialize($this->attributes['data']);
return $data === false ? null : (isset($data['alt']) ? $data['alt'] : null);
} | [
"public",
"function",
"getAltAttribute",
"(",
")",
"{",
"$",
"data",
"=",
"unserialize",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'data'",
"]",
")",
";",
"return",
"$",
"data",
"===",
"false",
"?",
"null",
":",
"(",
"isset",
"(",
"$",
"data",
"[",
"'alt'",
"]",
")",
"?",
"$",
"data",
"[",
"'alt'",
"]",
":",
"null",
")",
";",
"}"
] | Add alt tag to model. | [
"Add",
"alt",
"tag",
"to",
"model",
"."
] | df7f3a9794afaade3bee8f6be1223c98e4936cb2 | https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/Media.php#L45-L50 |
34,576 | c4studio/chronos | src/Chronos/Content/app/Models/Media.php | Media.getStylesAttribute | public function getStylesAttribute()
{
if (!$this->isImage)
return null;
$styles = [];
foreach ($this->image_styles as $style)
$styles[$style->style->name] = $style->file;
return $styles;
} | php | public function getStylesAttribute()
{
if (!$this->isImage)
return null;
$styles = [];
foreach ($this->image_styles as $style)
$styles[$style->style->name] = $style->file;
return $styles;
} | [
"public",
"function",
"getStylesAttribute",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isImage",
")",
"return",
"null",
";",
"$",
"styles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"image_styles",
"as",
"$",
"style",
")",
"$",
"styles",
"[",
"$",
"style",
"->",
"style",
"->",
"name",
"]",
"=",
"$",
"style",
"->",
"file",
";",
"return",
"$",
"styles",
";",
"}"
] | Add styles to model. | [
"Add",
"styles",
"to",
"model",
"."
] | df7f3a9794afaade3bee8f6be1223c98e4936cb2 | https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/Media.php#L90-L100 |
34,577 | c4studio/chronos | src/Chronos/Content/app/Models/Media.php | Media.getTitleAttribute | public function getTitleAttribute()
{
$data = unserialize($this->attributes['data']);
return $data === false ? null : (isset($data['title']) ? $data['title'] : null);
} | php | public function getTitleAttribute()
{
$data = unserialize($this->attributes['data']);
return $data === false ? null : (isset($data['title']) ? $data['title'] : null);
} | [
"public",
"function",
"getTitleAttribute",
"(",
")",
"{",
"$",
"data",
"=",
"unserialize",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'data'",
"]",
")",
";",
"return",
"$",
"data",
"===",
"false",
"?",
"null",
":",
"(",
"isset",
"(",
"$",
"data",
"[",
"'title'",
"]",
")",
"?",
"$",
"data",
"[",
"'title'",
"]",
":",
"null",
")",
";",
"}"
] | Add title tag to model. | [
"Add",
"title",
"tag",
"to",
"model",
"."
] | df7f3a9794afaade3bee8f6be1223c98e4936cb2 | https://github.com/c4studio/chronos/blob/df7f3a9794afaade3bee8f6be1223c98e4936cb2/src/Chronos/Content/app/Models/Media.php#L122-L127 |
34,578 | nails/module-cdn | src/Controller/Base.php | Base.serveFromCache | protected function serveFromCache($file, $hit = true, $setCacheHeaders = true)
{
/**
* Cache object exists, set the appropriate headers and return the
* contents of the file.
**/
$aStats = stat($this->cdnCacheDir . $file);
// Set cache headers
if ($setCacheHeaders) {
$this->setCacheHeaders($aStats['mtime'], $file, $hit);
}
// Work out content type
$oCdn = Factory::service('Cdn', 'nails/module-cdn');
$sMime = $oCdn->getMimeFromFile($this->cdnCacheDir . $file);
header('Content-Type: ' . $sMime, true);
header('Content-Length: ' . $aStats['size']);
// --------------------------------------------------------------------------
// Send the contents of the file to the browser
Factory::helper('file');
readFileChunked($this->cdnCacheDir . $file);
/**
* Kill script, th, th, that's all folks.
* Stop the output class from hijacking our headers and
* setting an incorrect Content-Type
**/
exit(0);
} | php | protected function serveFromCache($file, $hit = true, $setCacheHeaders = true)
{
/**
* Cache object exists, set the appropriate headers and return the
* contents of the file.
**/
$aStats = stat($this->cdnCacheDir . $file);
// Set cache headers
if ($setCacheHeaders) {
$this->setCacheHeaders($aStats['mtime'], $file, $hit);
}
// Work out content type
$oCdn = Factory::service('Cdn', 'nails/module-cdn');
$sMime = $oCdn->getMimeFromFile($this->cdnCacheDir . $file);
header('Content-Type: ' . $sMime, true);
header('Content-Length: ' . $aStats['size']);
// --------------------------------------------------------------------------
// Send the contents of the file to the browser
Factory::helper('file');
readFileChunked($this->cdnCacheDir . $file);
/**
* Kill script, th, th, that's all folks.
* Stop the output class from hijacking our headers and
* setting an incorrect Content-Type
**/
exit(0);
} | [
"protected",
"function",
"serveFromCache",
"(",
"$",
"file",
",",
"$",
"hit",
"=",
"true",
",",
"$",
"setCacheHeaders",
"=",
"true",
")",
"{",
"/**\n * Cache object exists, set the appropriate headers and return the\n * contents of the file.\n **/",
"$",
"aStats",
"=",
"stat",
"(",
"$",
"this",
"->",
"cdnCacheDir",
".",
"$",
"file",
")",
";",
"// Set cache headers",
"if",
"(",
"$",
"setCacheHeaders",
")",
"{",
"$",
"this",
"->",
"setCacheHeaders",
"(",
"$",
"aStats",
"[",
"'mtime'",
"]",
",",
"$",
"file",
",",
"$",
"hit",
")",
";",
"}",
"// Work out content type",
"$",
"oCdn",
"=",
"Factory",
"::",
"service",
"(",
"'Cdn'",
",",
"'nails/module-cdn'",
")",
";",
"$",
"sMime",
"=",
"$",
"oCdn",
"->",
"getMimeFromFile",
"(",
"$",
"this",
"->",
"cdnCacheDir",
".",
"$",
"file",
")",
";",
"header",
"(",
"'Content-Type: '",
".",
"$",
"sMime",
",",
"true",
")",
";",
"header",
"(",
"'Content-Length: '",
".",
"$",
"aStats",
"[",
"'size'",
"]",
")",
";",
"// --------------------------------------------------------------------------",
"// Send the contents of the file to the browser",
"Factory",
"::",
"helper",
"(",
"'file'",
")",
";",
"readFileChunked",
"(",
"$",
"this",
"->",
"cdnCacheDir",
".",
"$",
"file",
")",
";",
"/**\n * Kill script, th, th, that's all folks.\n * Stop the output class from hijacking our headers and\n * setting an incorrect Content-Type\n **/",
"exit",
"(",
"0",
")",
";",
"}"
] | Serve a file from the app's cache
@param string $file The file to serve
@param boolean $hit Whether or not the request was a cache hit or not
@param boolean $setCacheHeaders Whether tos et the cache headers or not
@return void | [
"Serve",
"a",
"file",
"from",
"the",
"app",
"s",
"cache"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Controller/Base.php#L94-L128 |
34,579 | nails/module-cdn | src/Controller/Base.php | Base.setCacheHeaders | protected function setCacheHeaders($lastModified, $file, $hit)
{
// Set some flags
$this->cdnCacheHeadersSet = true;
$this->cdnCacheHeadersLastModified = $lastModified;
$this->cdnCacheHeadersExpires = time() + $this->cdnCacheHeadersMaxAge;
$this->cdnCacheHeadersFile = $file;
$this->cdnCacheHeadersHit = $hit ? 'HIT' : 'MISS';
// --------------------------------------------------------------------------
header('Cache-Control: max-age=' . $this->cdnCacheHeadersMaxAge . ', must-revalidate', true);
header('Last-Modified: ' . date('r', $this->cdnCacheHeadersLastModified), true);
header('Expires: ' . date('r', $this->cdnCacheHeadersExpires), true);
header('ETag: "' . md5($this->cdnCacheHeadersFile) . '"', true);
header('X-CDN-CACHE: ' . $this->cdnCacheHeadersHit, true);
} | php | protected function setCacheHeaders($lastModified, $file, $hit)
{
// Set some flags
$this->cdnCacheHeadersSet = true;
$this->cdnCacheHeadersLastModified = $lastModified;
$this->cdnCacheHeadersExpires = time() + $this->cdnCacheHeadersMaxAge;
$this->cdnCacheHeadersFile = $file;
$this->cdnCacheHeadersHit = $hit ? 'HIT' : 'MISS';
// --------------------------------------------------------------------------
header('Cache-Control: max-age=' . $this->cdnCacheHeadersMaxAge . ', must-revalidate', true);
header('Last-Modified: ' . date('r', $this->cdnCacheHeadersLastModified), true);
header('Expires: ' . date('r', $this->cdnCacheHeadersExpires), true);
header('ETag: "' . md5($this->cdnCacheHeadersFile) . '"', true);
header('X-CDN-CACHE: ' . $this->cdnCacheHeadersHit, true);
} | [
"protected",
"function",
"setCacheHeaders",
"(",
"$",
"lastModified",
",",
"$",
"file",
",",
"$",
"hit",
")",
"{",
"// Set some flags",
"$",
"this",
"->",
"cdnCacheHeadersSet",
"=",
"true",
";",
"$",
"this",
"->",
"cdnCacheHeadersLastModified",
"=",
"$",
"lastModified",
";",
"$",
"this",
"->",
"cdnCacheHeadersExpires",
"=",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"cdnCacheHeadersMaxAge",
";",
"$",
"this",
"->",
"cdnCacheHeadersFile",
"=",
"$",
"file",
";",
"$",
"this",
"->",
"cdnCacheHeadersHit",
"=",
"$",
"hit",
"?",
"'HIT'",
":",
"'MISS'",
";",
"// --------------------------------------------------------------------------",
"header",
"(",
"'Cache-Control: max-age='",
".",
"$",
"this",
"->",
"cdnCacheHeadersMaxAge",
".",
"', must-revalidate'",
",",
"true",
")",
";",
"header",
"(",
"'Last-Modified: '",
".",
"date",
"(",
"'r'",
",",
"$",
"this",
"->",
"cdnCacheHeadersLastModified",
")",
",",
"true",
")",
";",
"header",
"(",
"'Expires: '",
".",
"date",
"(",
"'r'",
",",
"$",
"this",
"->",
"cdnCacheHeadersExpires",
")",
",",
"true",
")",
";",
"header",
"(",
"'ETag: \"'",
".",
"md5",
"(",
"$",
"this",
"->",
"cdnCacheHeadersFile",
")",
".",
"'\"'",
",",
"true",
")",
";",
"header",
"(",
"'X-CDN-CACHE: '",
".",
"$",
"this",
"->",
"cdnCacheHeadersHit",
",",
"true",
")",
";",
"}"
] | Set the cache headers of an object
@param string $lastModified The last modified date of the file
@param string $file The file we're serving
@param boolean $hit Whether or not the request was a cache hit or not | [
"Set",
"the",
"cache",
"headers",
"of",
"an",
"object"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Controller/Base.php#L139-L155 |
34,580 | nails/module-cdn | src/Controller/Base.php | Base.unsetCacheHeaders | protected function unsetCacheHeaders()
{
if (empty($this->cdnCacheHeadersSet)) {
return false;
}
// --------------------------------------------------------------------------
// Remove previously set headers
header_remove('Cache-Control');
header_remove('Last-Modified');
header_remove('Expires');
header_remove('ETag');
header_remove('X-CDN-CACHE');
// --------------------------------------------------------------------------
// Set new "do not cache" headers
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT', true);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT', true);
header('Cache-Control: no-store, no-cache, must-revalidate', true);
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache', true);
header('X-CDN-CACHE: MISS', true);
return true;
} | php | protected function unsetCacheHeaders()
{
if (empty($this->cdnCacheHeadersSet)) {
return false;
}
// --------------------------------------------------------------------------
// Remove previously set headers
header_remove('Cache-Control');
header_remove('Last-Modified');
header_remove('Expires');
header_remove('ETag');
header_remove('X-CDN-CACHE');
// --------------------------------------------------------------------------
// Set new "do not cache" headers
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT', true);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT', true);
header('Cache-Control: no-store, no-cache, must-revalidate', true);
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache', true);
header('X-CDN-CACHE: MISS', true);
return true;
} | [
"protected",
"function",
"unsetCacheHeaders",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"cdnCacheHeadersSet",
")",
")",
"{",
"return",
"false",
";",
"}",
"// --------------------------------------------------------------------------",
"// Remove previously set headers",
"header_remove",
"(",
"'Cache-Control'",
")",
";",
"header_remove",
"(",
"'Last-Modified'",
")",
";",
"header_remove",
"(",
"'Expires'",
")",
";",
"header_remove",
"(",
"'ETag'",
")",
";",
"header_remove",
"(",
"'X-CDN-CACHE'",
")",
";",
"// --------------------------------------------------------------------------",
"// Set new \"do not cache\" headers",
"header",
"(",
"'Expires: Mon, 26 Jul 1997 05:00:00 GMT'",
",",
"true",
")",
";",
"header",
"(",
"'Last-Modified: '",
".",
"gmdate",
"(",
"'D, d M Y H:i:s'",
")",
".",
"' GMT'",
",",
"true",
")",
";",
"header",
"(",
"'Cache-Control: no-store, no-cache, must-revalidate'",
",",
"true",
")",
";",
"header",
"(",
"'Cache-Control: post-check=0, pre-check=0'",
",",
"false",
")",
";",
"header",
"(",
"'Pragma: no-cache'",
",",
"true",
")",
";",
"header",
"(",
"'X-CDN-CACHE: MISS'",
",",
"true",
")",
";",
"return",
"true",
";",
"}"
] | Unset the cache headers of an object
@return boolean | [
"Unset",
"the",
"cache",
"headers",
"of",
"an",
"object"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Controller/Base.php#L163-L189 |
34,581 | nails/module-cdn | src/Controller/Base.php | Base.serveNotModified | protected function serveNotModified($file)
{
$oInput = Factory::service('Input');
if (function_exists('apache_request_headers')) {
$headers = apache_request_headers();
} elseif ($oInput->server('HTTP_IF_NONE_MATCH')) {
$headers = [];
$headers['If-None-Match'] = $oInput->server('HTTP_IF_NONE_MATCH');
} elseif (isset($_SERVER)) {
/**
* Can we work the headers out for ourself?
* Credit: http://www.php.net/manual/en/function.apache-request-headers.php#70810
**/
$headers = [];
$rxHttp = '/\AHTTP_/';
foreach ($_SERVER as $key => $val) {
if (preg_match($rxHttp, $key)) {
$arhKey = preg_replace($rxHttp, '', $key);
$rxMatches = explode('_', $arhKey);
/**
* Do some nasty string manipulations to restore the original letter case
* this should work in most cases
**/
if (count($rxMatches) > 0 && strlen($arhKey) > 2) {
foreach ($rxMatches as $ak_key => $akVal) {
$rxMatches[$ak_key] = ucfirst($akVal);
}
$arhKey = implode('-', $rxMatches);
}
$headers[$arhKey] = $val;
}
}
} else {
// Give up.
return false;
}
if (isset($headers['If-None-Match']) && $headers['If-None-Match'] == '"' . md5($file) . '"') {
header($oInput->server('SERVER_PROTOCOL') . ' 304 Not Modified', true, 304);
return true;
}
// --------------------------------------------------------------------------
return false;
} | php | protected function serveNotModified($file)
{
$oInput = Factory::service('Input');
if (function_exists('apache_request_headers')) {
$headers = apache_request_headers();
} elseif ($oInput->server('HTTP_IF_NONE_MATCH')) {
$headers = [];
$headers['If-None-Match'] = $oInput->server('HTTP_IF_NONE_MATCH');
} elseif (isset($_SERVER)) {
/**
* Can we work the headers out for ourself?
* Credit: http://www.php.net/manual/en/function.apache-request-headers.php#70810
**/
$headers = [];
$rxHttp = '/\AHTTP_/';
foreach ($_SERVER as $key => $val) {
if (preg_match($rxHttp, $key)) {
$arhKey = preg_replace($rxHttp, '', $key);
$rxMatches = explode('_', $arhKey);
/**
* Do some nasty string manipulations to restore the original letter case
* this should work in most cases
**/
if (count($rxMatches) > 0 && strlen($arhKey) > 2) {
foreach ($rxMatches as $ak_key => $akVal) {
$rxMatches[$ak_key] = ucfirst($akVal);
}
$arhKey = implode('-', $rxMatches);
}
$headers[$arhKey] = $val;
}
}
} else {
// Give up.
return false;
}
if (isset($headers['If-None-Match']) && $headers['If-None-Match'] == '"' . md5($file) . '"') {
header($oInput->server('SERVER_PROTOCOL') . ' 304 Not Modified', true, 304);
return true;
}
// --------------------------------------------------------------------------
return false;
} | [
"protected",
"function",
"serveNotModified",
"(",
"$",
"file",
")",
"{",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"if",
"(",
"function_exists",
"(",
"'apache_request_headers'",
")",
")",
"{",
"$",
"headers",
"=",
"apache_request_headers",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"oInput",
"->",
"server",
"(",
"'HTTP_IF_NONE_MATCH'",
")",
")",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"$",
"headers",
"[",
"'If-None-Match'",
"]",
"=",
"$",
"oInput",
"->",
"server",
"(",
"'HTTP_IF_NONE_MATCH'",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"_SERVER",
")",
")",
"{",
"/**\n * Can we work the headers out for ourself?\n * Credit: http://www.php.net/manual/en/function.apache-request-headers.php#70810\n **/",
"$",
"headers",
"=",
"[",
"]",
";",
"$",
"rxHttp",
"=",
"'/\\AHTTP_/'",
";",
"foreach",
"(",
"$",
"_SERVER",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"rxHttp",
",",
"$",
"key",
")",
")",
"{",
"$",
"arhKey",
"=",
"preg_replace",
"(",
"$",
"rxHttp",
",",
"''",
",",
"$",
"key",
")",
";",
"$",
"rxMatches",
"=",
"explode",
"(",
"'_'",
",",
"$",
"arhKey",
")",
";",
"/**\n * Do some nasty string manipulations to restore the original letter case\n * this should work in most cases\n **/",
"if",
"(",
"count",
"(",
"$",
"rxMatches",
")",
">",
"0",
"&&",
"strlen",
"(",
"$",
"arhKey",
")",
">",
"2",
")",
"{",
"foreach",
"(",
"$",
"rxMatches",
"as",
"$",
"ak_key",
"=>",
"$",
"akVal",
")",
"{",
"$",
"rxMatches",
"[",
"$",
"ak_key",
"]",
"=",
"ucfirst",
"(",
"$",
"akVal",
")",
";",
"}",
"$",
"arhKey",
"=",
"implode",
"(",
"'-'",
",",
"$",
"rxMatches",
")",
";",
"}",
"$",
"headers",
"[",
"$",
"arhKey",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"}",
"else",
"{",
"// Give up.",
"return",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"headers",
"[",
"'If-None-Match'",
"]",
")",
"&&",
"$",
"headers",
"[",
"'If-None-Match'",
"]",
"==",
"'\"'",
".",
"md5",
"(",
"$",
"file",
")",
".",
"'\"'",
")",
"{",
"header",
"(",
"$",
"oInput",
"->",
"server",
"(",
"'SERVER_PROTOCOL'",
")",
".",
"' 304 Not Modified'",
",",
"true",
",",
"304",
")",
";",
"return",
"true",
";",
"}",
"// --------------------------------------------------------------------------",
"return",
"false",
";",
"}"
] | Serve the "304 Not Modified" headers for an object
@param string $file The file we're sending the headers for
@return boolean | [
"Serve",
"the",
"304",
"Not",
"Modified",
"headers",
"for",
"an",
"object"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Controller/Base.php#L200-L258 |
34,582 | nails/module-cdn | src/Controller/Base.php | Base.serveBadSrc | protected function serveBadSrc(array $params)
{
$width = isset($params['width']) ? $params['width'] : 100;
$height = isset($params['height']) ? $params['height'] : 100;
$sError = isset($params['error']) ? $params['error'] : '';
// Make sure this doesn't get cached
$this->unsetCacheHeaders();
// --------------------------------------------------------------------------
// Create the icon
if ($this->isRetina) {
$icon = @imagecreatefrompng($this->cdnRoot . '_resources/img/fail@2x.png');
} else {
$icon = @imagecreatefrompng($this->cdnRoot . '_resources/img/fail.png');
}
$iconW = imagesx($icon);
$iconH = imagesy($icon);
// --------------------------------------------------------------------------
// Create the background
$bg = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($bg, 255, 255, 255);
imagefill($bg, 0, 0, $white);
// --------------------------------------------------------------------------
// Merge the two
$centerX = ($width / 2) - ($iconW / 2);
$centerY = ($height / 2) - ($iconH / 2);
imagecopymerge($bg, $icon, $centerX, $centerY, 0, 0, $iconW, $iconH, 100);
// --------------------------------------------------------------------------
// Write the error on the bottom
if (!empty($sError)) {
$textcolor = imagecolorallocate($bg, 0, 0, 0);
imagestring($bg, 1, 5, $height - 15, 'ERROR: ' . $sError, $textcolor);
}
// --------------------------------------------------------------------------
// Output to browser
$oInput = Factory::service('Input');
header('Content-Type: image/png', true);
header($oInput->server('SERVER_PROTOCOL') . ' 400 Bad Request', true, 400);
imagepng($bg);
// --------------------------------------------------------------------------
// Destroy the images
imagedestroy($icon);
imagedestroy($bg);
// --------------------------------------------------------------------------
/**
* Kill script, th, th, that's all folks.
* Stop the output class from hijacking our headers and
* setting an incorrect Content-Type
**/
exit(0);
} | php | protected function serveBadSrc(array $params)
{
$width = isset($params['width']) ? $params['width'] : 100;
$height = isset($params['height']) ? $params['height'] : 100;
$sError = isset($params['error']) ? $params['error'] : '';
// Make sure this doesn't get cached
$this->unsetCacheHeaders();
// --------------------------------------------------------------------------
// Create the icon
if ($this->isRetina) {
$icon = @imagecreatefrompng($this->cdnRoot . '_resources/img/fail@2x.png');
} else {
$icon = @imagecreatefrompng($this->cdnRoot . '_resources/img/fail.png');
}
$iconW = imagesx($icon);
$iconH = imagesy($icon);
// --------------------------------------------------------------------------
// Create the background
$bg = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($bg, 255, 255, 255);
imagefill($bg, 0, 0, $white);
// --------------------------------------------------------------------------
// Merge the two
$centerX = ($width / 2) - ($iconW / 2);
$centerY = ($height / 2) - ($iconH / 2);
imagecopymerge($bg, $icon, $centerX, $centerY, 0, 0, $iconW, $iconH, 100);
// --------------------------------------------------------------------------
// Write the error on the bottom
if (!empty($sError)) {
$textcolor = imagecolorallocate($bg, 0, 0, 0);
imagestring($bg, 1, 5, $height - 15, 'ERROR: ' . $sError, $textcolor);
}
// --------------------------------------------------------------------------
// Output to browser
$oInput = Factory::service('Input');
header('Content-Type: image/png', true);
header($oInput->server('SERVER_PROTOCOL') . ' 400 Bad Request', true, 400);
imagepng($bg);
// --------------------------------------------------------------------------
// Destroy the images
imagedestroy($icon);
imagedestroy($bg);
// --------------------------------------------------------------------------
/**
* Kill script, th, th, that's all folks.
* Stop the output class from hijacking our headers and
* setting an incorrect Content-Type
**/
exit(0);
} | [
"protected",
"function",
"serveBadSrc",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"width",
"=",
"isset",
"(",
"$",
"params",
"[",
"'width'",
"]",
")",
"?",
"$",
"params",
"[",
"'width'",
"]",
":",
"100",
";",
"$",
"height",
"=",
"isset",
"(",
"$",
"params",
"[",
"'height'",
"]",
")",
"?",
"$",
"params",
"[",
"'height'",
"]",
":",
"100",
";",
"$",
"sError",
"=",
"isset",
"(",
"$",
"params",
"[",
"'error'",
"]",
")",
"?",
"$",
"params",
"[",
"'error'",
"]",
":",
"''",
";",
"// Make sure this doesn't get cached",
"$",
"this",
"->",
"unsetCacheHeaders",
"(",
")",
";",
"// --------------------------------------------------------------------------",
"// Create the icon",
"if",
"(",
"$",
"this",
"->",
"isRetina",
")",
"{",
"$",
"icon",
"=",
"@",
"imagecreatefrompng",
"(",
"$",
"this",
"->",
"cdnRoot",
".",
"'_resources/img/fail@2x.png'",
")",
";",
"}",
"else",
"{",
"$",
"icon",
"=",
"@",
"imagecreatefrompng",
"(",
"$",
"this",
"->",
"cdnRoot",
".",
"'_resources/img/fail.png'",
")",
";",
"}",
"$",
"iconW",
"=",
"imagesx",
"(",
"$",
"icon",
")",
";",
"$",
"iconH",
"=",
"imagesy",
"(",
"$",
"icon",
")",
";",
"// --------------------------------------------------------------------------",
"// Create the background",
"$",
"bg",
"=",
"imagecreatetruecolor",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"$",
"white",
"=",
"imagecolorallocate",
"(",
"$",
"bg",
",",
"255",
",",
"255",
",",
"255",
")",
";",
"imagefill",
"(",
"$",
"bg",
",",
"0",
",",
"0",
",",
"$",
"white",
")",
";",
"// --------------------------------------------------------------------------",
"// Merge the two",
"$",
"centerX",
"=",
"(",
"$",
"width",
"/",
"2",
")",
"-",
"(",
"$",
"iconW",
"/",
"2",
")",
";",
"$",
"centerY",
"=",
"(",
"$",
"height",
"/",
"2",
")",
"-",
"(",
"$",
"iconH",
"/",
"2",
")",
";",
"imagecopymerge",
"(",
"$",
"bg",
",",
"$",
"icon",
",",
"$",
"centerX",
",",
"$",
"centerY",
",",
"0",
",",
"0",
",",
"$",
"iconW",
",",
"$",
"iconH",
",",
"100",
")",
";",
"// --------------------------------------------------------------------------",
"// Write the error on the bottom",
"if",
"(",
"!",
"empty",
"(",
"$",
"sError",
")",
")",
"{",
"$",
"textcolor",
"=",
"imagecolorallocate",
"(",
"$",
"bg",
",",
"0",
",",
"0",
",",
"0",
")",
";",
"imagestring",
"(",
"$",
"bg",
",",
"1",
",",
"5",
",",
"$",
"height",
"-",
"15",
",",
"'ERROR: '",
".",
"$",
"sError",
",",
"$",
"textcolor",
")",
";",
"}",
"// --------------------------------------------------------------------------",
"// Output to browser",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"header",
"(",
"'Content-Type: image/png'",
",",
"true",
")",
";",
"header",
"(",
"$",
"oInput",
"->",
"server",
"(",
"'SERVER_PROTOCOL'",
")",
".",
"' 400 Bad Request'",
",",
"true",
",",
"400",
")",
";",
"imagepng",
"(",
"$",
"bg",
")",
";",
"// --------------------------------------------------------------------------",
"// Destroy the images",
"imagedestroy",
"(",
"$",
"icon",
")",
";",
"imagedestroy",
"(",
"$",
"bg",
")",
";",
"// --------------------------------------------------------------------------",
"/**\n * Kill script, th, th, that's all folks.\n * Stop the output class from hijacking our headers and\n * setting an incorrect Content-Type\n **/",
"exit",
"(",
"0",
")",
";",
"}"
] | Serve up the "fail whale" graphic
@return void | [
"Serve",
"up",
"the",
"fail",
"whale",
"graphic"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Controller/Base.php#L266-L331 |
34,583 | nails/module-cdn | src/Controller/Base.php | Base.checkDimensions | protected function checkDimensions($iWidth, $iHeight)
{
$oCdn = Factory::service('Cdn', 'nails/module-cdn');
if (!$oCdn->isPermittedDimension($iWidth, $iHeight)) {
if (Environment::not(Environment::ENV_PROD)) {
throw new PermittedDimensionException(
'Transformation of image to ' . $iWidth . 'x' . $iHeight . ' is not permitted'
);
} else {
show404();
}
}
} | php | protected function checkDimensions($iWidth, $iHeight)
{
$oCdn = Factory::service('Cdn', 'nails/module-cdn');
if (!$oCdn->isPermittedDimension($iWidth, $iHeight)) {
if (Environment::not(Environment::ENV_PROD)) {
throw new PermittedDimensionException(
'Transformation of image to ' . $iWidth . 'x' . $iHeight . ' is not permitted'
);
} else {
show404();
}
}
} | [
"protected",
"function",
"checkDimensions",
"(",
"$",
"iWidth",
",",
"$",
"iHeight",
")",
"{",
"$",
"oCdn",
"=",
"Factory",
"::",
"service",
"(",
"'Cdn'",
",",
"'nails/module-cdn'",
")",
";",
"if",
"(",
"!",
"$",
"oCdn",
"->",
"isPermittedDimension",
"(",
"$",
"iWidth",
",",
"$",
"iHeight",
")",
")",
"{",
"if",
"(",
"Environment",
"::",
"not",
"(",
"Environment",
"::",
"ENV_PROD",
")",
")",
"{",
"throw",
"new",
"PermittedDimensionException",
"(",
"'Transformation of image to '",
".",
"$",
"iWidth",
".",
"'x'",
".",
"$",
"iHeight",
".",
"' is not permitted'",
")",
";",
"}",
"else",
"{",
"show404",
"(",
")",
";",
"}",
"}",
"}"
] | Determines if the requested dimensions can be satisfied, throws an exception
on non-production environments
@param $iWidth
@param $iHeight
@throws PermittedDimensionException | [
"Determines",
"if",
"the",
"requested",
"dimensions",
"can",
"be",
"satisfied",
"throws",
"an",
"exception",
"on",
"non",
"-",
"production",
"environments"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Controller/Base.php#L344-L356 |
34,584 | nails/module-cdn | src/Service/Cdn.php | Cdn.callDriver | protected function callDriver($sMethod, $aArguments = [], $sDriver = null)
{
// Work out which driver we need to use
if (empty($sDriver)) {
$oDriver = $this->oEnabledDriver;
} elseif (array_key_exists($sDriver, $this->aDrivers)) {
$oDriver = $this->aDrivers[$sDriver];
} else {
throw new DriverException('"' . $sDriver . '" is not a valid CDN driver.');
}
$oStorageDriver = Factory::service('StorageDriver', 'nails/module-cdn');
$oInstance = $oStorageDriver->getInstance($oDriver->slug);
if (empty($oInstance)) {
throw new DriverException('Failed to load CDN driver instance.');
}
return call_user_func_array([$oInstance, $sMethod], $aArguments);
} | php | protected function callDriver($sMethod, $aArguments = [], $sDriver = null)
{
// Work out which driver we need to use
if (empty($sDriver)) {
$oDriver = $this->oEnabledDriver;
} elseif (array_key_exists($sDriver, $this->aDrivers)) {
$oDriver = $this->aDrivers[$sDriver];
} else {
throw new DriverException('"' . $sDriver . '" is not a valid CDN driver.');
}
$oStorageDriver = Factory::service('StorageDriver', 'nails/module-cdn');
$oInstance = $oStorageDriver->getInstance($oDriver->slug);
if (empty($oInstance)) {
throw new DriverException('Failed to load CDN driver instance.');
}
return call_user_func_array([$oInstance, $sMethod], $aArguments);
} | [
"protected",
"function",
"callDriver",
"(",
"$",
"sMethod",
",",
"$",
"aArguments",
"=",
"[",
"]",
",",
"$",
"sDriver",
"=",
"null",
")",
"{",
"// Work out which driver we need to use",
"if",
"(",
"empty",
"(",
"$",
"sDriver",
")",
")",
"{",
"$",
"oDriver",
"=",
"$",
"this",
"->",
"oEnabledDriver",
";",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"$",
"sDriver",
",",
"$",
"this",
"->",
"aDrivers",
")",
")",
"{",
"$",
"oDriver",
"=",
"$",
"this",
"->",
"aDrivers",
"[",
"$",
"sDriver",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"DriverException",
"(",
"'\"'",
".",
"$",
"sDriver",
".",
"'\" is not a valid CDN driver.'",
")",
";",
"}",
"$",
"oStorageDriver",
"=",
"Factory",
"::",
"service",
"(",
"'StorageDriver'",
",",
"'nails/module-cdn'",
")",
";",
"$",
"oInstance",
"=",
"$",
"oStorageDriver",
"->",
"getInstance",
"(",
"$",
"oDriver",
"->",
"slug",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oInstance",
")",
")",
"{",
"throw",
"new",
"DriverException",
"(",
"'Failed to load CDN driver instance.'",
")",
";",
"}",
"return",
"call_user_func_array",
"(",
"[",
"$",
"oInstance",
",",
"$",
"sMethod",
"]",
",",
"$",
"aArguments",
")",
";",
"}"
] | Routes calls to the driver
@param string $sMethod The method to call
@param array $aArguments an array of arguments to pass to the driver
@param string $sDriver If specified, which driver to call
@return mixed
@throws DriverException | [
"Routes",
"calls",
"to",
"the",
"driver"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L228-L247 |
34,585 | nails/module-cdn | src/Service/Cdn.php | Cdn.unsetCacheObject | protected function unsetCacheObject($object, $clearCacheDir = true)
{
$objectId = isset($object->id) ? $object->id : '';
$objectFilename = isset($object->file->name->disk) ? $object->file->name->disk : '';
$bucketId = isset($object->bucket->id) ? $object->bucket->id : '';
$bucketSlug = isset($object->bucket->slug) ? $object->bucket->slug : '';
// --------------------------------------------------------------------------
$this->unsetCache('object-' . $objectId);
$this->unsetCache('object-' . $objectFilename);
$this->unsetCache('object-' . $objectFilename . '-' . $bucketId);
$this->unsetCache('object-' . $objectFilename . '-' . $bucketSlug);
// --------------------------------------------------------------------------
// Clear out any cache files
if ($clearCacheDir) {
// Create a handler for the directory
$pattern = '#^' . $bucketSlug . '-' . substr($objectFilename, 0, strrpos($objectFilename, '.')) . '#';
$fh = @opendir(static::CACHE_PATH);
if ($fh !== false) {
// Open directory and walk through the file names
while ($file = readdir($fh)) {
// If file isn't this directory or its parent, add it to the results
if ($file != '.' && $file != '..') {
// Check with regex that the file format is what we're expecting and not something else
if (preg_match($pattern, $file) && file_exists(static::CACHE_PATH . $file)) {
unlink(static::CACHE_PATH . $file);
}
}
}
}
}
} | php | protected function unsetCacheObject($object, $clearCacheDir = true)
{
$objectId = isset($object->id) ? $object->id : '';
$objectFilename = isset($object->file->name->disk) ? $object->file->name->disk : '';
$bucketId = isset($object->bucket->id) ? $object->bucket->id : '';
$bucketSlug = isset($object->bucket->slug) ? $object->bucket->slug : '';
// --------------------------------------------------------------------------
$this->unsetCache('object-' . $objectId);
$this->unsetCache('object-' . $objectFilename);
$this->unsetCache('object-' . $objectFilename . '-' . $bucketId);
$this->unsetCache('object-' . $objectFilename . '-' . $bucketSlug);
// --------------------------------------------------------------------------
// Clear out any cache files
if ($clearCacheDir) {
// Create a handler for the directory
$pattern = '#^' . $bucketSlug . '-' . substr($objectFilename, 0, strrpos($objectFilename, '.')) . '#';
$fh = @opendir(static::CACHE_PATH);
if ($fh !== false) {
// Open directory and walk through the file names
while ($file = readdir($fh)) {
// If file isn't this directory or its parent, add it to the results
if ($file != '.' && $file != '..') {
// Check with regex that the file format is what we're expecting and not something else
if (preg_match($pattern, $file) && file_exists(static::CACHE_PATH . $file)) {
unlink(static::CACHE_PATH . $file);
}
}
}
}
}
} | [
"protected",
"function",
"unsetCacheObject",
"(",
"$",
"object",
",",
"$",
"clearCacheDir",
"=",
"true",
")",
"{",
"$",
"objectId",
"=",
"isset",
"(",
"$",
"object",
"->",
"id",
")",
"?",
"$",
"object",
"->",
"id",
":",
"''",
";",
"$",
"objectFilename",
"=",
"isset",
"(",
"$",
"object",
"->",
"file",
"->",
"name",
"->",
"disk",
")",
"?",
"$",
"object",
"->",
"file",
"->",
"name",
"->",
"disk",
":",
"''",
";",
"$",
"bucketId",
"=",
"isset",
"(",
"$",
"object",
"->",
"bucket",
"->",
"id",
")",
"?",
"$",
"object",
"->",
"bucket",
"->",
"id",
":",
"''",
";",
"$",
"bucketSlug",
"=",
"isset",
"(",
"$",
"object",
"->",
"bucket",
"->",
"slug",
")",
"?",
"$",
"object",
"->",
"bucket",
"->",
"slug",
":",
"''",
";",
"// --------------------------------------------------------------------------",
"$",
"this",
"->",
"unsetCache",
"(",
"'object-'",
".",
"$",
"objectId",
")",
";",
"$",
"this",
"->",
"unsetCache",
"(",
"'object-'",
".",
"$",
"objectFilename",
")",
";",
"$",
"this",
"->",
"unsetCache",
"(",
"'object-'",
".",
"$",
"objectFilename",
".",
"'-'",
".",
"$",
"bucketId",
")",
";",
"$",
"this",
"->",
"unsetCache",
"(",
"'object-'",
".",
"$",
"objectFilename",
".",
"'-'",
".",
"$",
"bucketSlug",
")",
";",
"// --------------------------------------------------------------------------",
"// Clear out any cache files",
"if",
"(",
"$",
"clearCacheDir",
")",
"{",
"// Create a handler for the directory",
"$",
"pattern",
"=",
"'#^'",
".",
"$",
"bucketSlug",
".",
"'-'",
".",
"substr",
"(",
"$",
"objectFilename",
",",
"0",
",",
"strrpos",
"(",
"$",
"objectFilename",
",",
"'.'",
")",
")",
".",
"'#'",
";",
"$",
"fh",
"=",
"@",
"opendir",
"(",
"static",
"::",
"CACHE_PATH",
")",
";",
"if",
"(",
"$",
"fh",
"!==",
"false",
")",
"{",
"// Open directory and walk through the file names",
"while",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"fh",
")",
")",
"{",
"// If file isn't this directory or its parent, add it to the results",
"if",
"(",
"$",
"file",
"!=",
"'.'",
"&&",
"$",
"file",
"!=",
"'..'",
")",
"{",
"// Check with regex that the file format is what we're expecting and not something else",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"file",
")",
"&&",
"file_exists",
"(",
"static",
"::",
"CACHE_PATH",
".",
"$",
"file",
")",
")",
"{",
"unlink",
"(",
"static",
"::",
"CACHE_PATH",
".",
"$",
"file",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}"
] | Unset an object from the cache in one fell swoop
@param \stdClass $object The object to remove from the cache
@param bool $clearCacheDir Whether to clear the cache directory or not | [
"Unset",
"an",
"object",
"from",
"the",
"cache",
"in",
"one",
"fell",
"swoop"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L257-L296 |
34,586 | nails/module-cdn | src/Service/Cdn.php | Cdn.getObjects | public function getObjects($page = null, $perPage = null, $data = [])
{
$oDb = Factory::service('Database');
$oDb->select('o.id, o.filename, o.filename_display, o.serves, o.downloads, o.thumbs, o.scales, o.driver, o.md5_hash');
$oDb->Select('o.created, o.created_by, o.modified, o.modified_by');
$oDb->select('o.mime, o.filesize, o.img_width, o.img_height, o.img_orientation, o.is_animated');
$oDb->select('b.id bucket_id, b.label bucket_label, b.slug bucket_slug');
$oDb->join(NAILS_DB_PREFIX . 'cdn_bucket b', 'b.id = o.bucket_id', 'LEFT');
// --------------------------------------------------------------------------
// Apply common items; pass $data
$this->getCountCommonObjects($data);
// --------------------------------------------------------------------------
// Facilitate pagination
if (!is_null($page)) {
/**
* Adjust the page variable, reduce by one so that the offset is calculated
* correctly. Make sure we don't go into negative numbers
*/
$page--;
$page = $page < 0 ? 0 : $page;
// Work out what the offset should be
$perPage = is_null($perPage) ? 50 : (int) $perPage;
$offset = $page * $perPage;
$oDb->limit($perPage, $offset);
}
// --------------------------------------------------------------------------
$objects = $oDb->get(NAILS_DB_PREFIX . 'cdn_object o')->result();
$numObjects = count($objects);
for ($i = 0; $i < $numObjects; $i++) {
$this->formatObject($objects[$i]);
}
return $objects;
} | php | public function getObjects($page = null, $perPage = null, $data = [])
{
$oDb = Factory::service('Database');
$oDb->select('o.id, o.filename, o.filename_display, o.serves, o.downloads, o.thumbs, o.scales, o.driver, o.md5_hash');
$oDb->Select('o.created, o.created_by, o.modified, o.modified_by');
$oDb->select('o.mime, o.filesize, o.img_width, o.img_height, o.img_orientation, o.is_animated');
$oDb->select('b.id bucket_id, b.label bucket_label, b.slug bucket_slug');
$oDb->join(NAILS_DB_PREFIX . 'cdn_bucket b', 'b.id = o.bucket_id', 'LEFT');
// --------------------------------------------------------------------------
// Apply common items; pass $data
$this->getCountCommonObjects($data);
// --------------------------------------------------------------------------
// Facilitate pagination
if (!is_null($page)) {
/**
* Adjust the page variable, reduce by one so that the offset is calculated
* correctly. Make sure we don't go into negative numbers
*/
$page--;
$page = $page < 0 ? 0 : $page;
// Work out what the offset should be
$perPage = is_null($perPage) ? 50 : (int) $perPage;
$offset = $page * $perPage;
$oDb->limit($perPage, $offset);
}
// --------------------------------------------------------------------------
$objects = $oDb->get(NAILS_DB_PREFIX . 'cdn_object o')->result();
$numObjects = count($objects);
for ($i = 0; $i < $numObjects; $i++) {
$this->formatObject($objects[$i]);
}
return $objects;
} | [
"public",
"function",
"getObjects",
"(",
"$",
"page",
"=",
"null",
",",
"$",
"perPage",
"=",
"null",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"select",
"(",
"'o.id, o.filename, o.filename_display, o.serves, o.downloads, o.thumbs, o.scales, o.driver, o.md5_hash'",
")",
";",
"$",
"oDb",
"->",
"Select",
"(",
"'o.created, o.created_by, o.modified, o.modified_by'",
")",
";",
"$",
"oDb",
"->",
"select",
"(",
"'o.mime, o.filesize, o.img_width, o.img_height, o.img_orientation, o.is_animated'",
")",
";",
"$",
"oDb",
"->",
"select",
"(",
"'b.id bucket_id, b.label bucket_label, b.slug bucket_slug'",
")",
";",
"$",
"oDb",
"->",
"join",
"(",
"NAILS_DB_PREFIX",
".",
"'cdn_bucket b'",
",",
"'b.id = o.bucket_id'",
",",
"'LEFT'",
")",
";",
"// --------------------------------------------------------------------------",
"// Apply common items; pass $data",
"$",
"this",
"->",
"getCountCommonObjects",
"(",
"$",
"data",
")",
";",
"// --------------------------------------------------------------------------",
"// Facilitate pagination",
"if",
"(",
"!",
"is_null",
"(",
"$",
"page",
")",
")",
"{",
"/**\n * Adjust the page variable, reduce by one so that the offset is calculated\n * correctly. Make sure we don't go into negative numbers\n */",
"$",
"page",
"--",
";",
"$",
"page",
"=",
"$",
"page",
"<",
"0",
"?",
"0",
":",
"$",
"page",
";",
"// Work out what the offset should be",
"$",
"perPage",
"=",
"is_null",
"(",
"$",
"perPage",
")",
"?",
"50",
":",
"(",
"int",
")",
"$",
"perPage",
";",
"$",
"offset",
"=",
"$",
"page",
"*",
"$",
"perPage",
";",
"$",
"oDb",
"->",
"limit",
"(",
"$",
"perPage",
",",
"$",
"offset",
")",
";",
"}",
"// --------------------------------------------------------------------------",
"$",
"objects",
"=",
"$",
"oDb",
"->",
"get",
"(",
"NAILS_DB_PREFIX",
".",
"'cdn_object o'",
")",
"->",
"result",
"(",
")",
";",
"$",
"numObjects",
"=",
"count",
"(",
"$",
"objects",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"numObjects",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"formatObject",
"(",
"$",
"objects",
"[",
"$",
"i",
"]",
")",
";",
"}",
"return",
"$",
"objects",
";",
"}"
] | Returns an array of objects
@param integer $page The page to return
@param integer $perPage The number of items to return per page
@param array $data An array of data to pass to getCountCommonBuckets()
@return array | [
"Returns",
"an",
"array",
"of",
"objects"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L337-L382 |
34,587 | nails/module-cdn | src/Service/Cdn.php | Cdn.getCountCommonObjects | public function getCountCommonObjects($aData = [])
{
if (!empty($aData['keywords'])) {
if (empty($aData['or_like'])) {
$aData['or_like'] = [];
}
$aData['or_like'][] = [
'column' => 'o.filename_display',
'value' => $aData['keywords'],
];
}
$this->getCountCommon($aData);
} | php | public function getCountCommonObjects($aData = [])
{
if (!empty($aData['keywords'])) {
if (empty($aData['or_like'])) {
$aData['or_like'] = [];
}
$aData['or_like'][] = [
'column' => 'o.filename_display',
'value' => $aData['keywords'],
];
}
$this->getCountCommon($aData);
} | [
"public",
"function",
"getCountCommonObjects",
"(",
"$",
"aData",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"aData",
"[",
"'keywords'",
"]",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"aData",
"[",
"'or_like'",
"]",
")",
")",
"{",
"$",
"aData",
"[",
"'or_like'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"aData",
"[",
"'or_like'",
"]",
"[",
"]",
"=",
"[",
"'column'",
"=>",
"'o.filename_display'",
",",
"'value'",
"=>",
"$",
"aData",
"[",
"'keywords'",
"]",
",",
"]",
";",
"}",
"$",
"this",
"->",
"getCountCommon",
"(",
"$",
"aData",
")",
";",
"}"
] | Adds the ability to search by keyword
@param array $aData Data to pass to parent::getCountCommon | [
"Adds",
"the",
"ability",
"to",
"search",
"by",
"keyword"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L391-L404 |
34,588 | nails/module-cdn | src/Service/Cdn.php | Cdn.getObject | public function getObject($objectIdSlug, $bucketIdSlug = '', $data = [])
{
// Check the cache
$cacheKey = 'object-' . $objectIdSlug;
$cacheKey .= $bucketIdSlug ? '-' . $bucketIdSlug : '';
$cache = $this->getCache($cacheKey);
if ($cache) {
return $cache;
}
// --------------------------------------------------------------------------
if (!isset($data['where'])) {
$data['where'] = [];
}
if (is_numeric($objectIdSlug)) {
$data['where'][] = ['o.id', $objectIdSlug];
} else {
$data['where'][] = ['o.filename', $objectIdSlug];
if (!empty($bucketIdSlug)) {
if (is_numeric($bucketIdSlug)) {
$data['where'][] = ['b.id', $bucketIdSlug];
} else {
$data['where'][] = ['b.slug', $bucketIdSlug];
}
}
}
$objects = $this->getObjects(null, null, $data);
if (empty($objects)) {
return false;
}
// --------------------------------------------------------------------------
// Cache the object
$this->setCache($cacheKey, $objects[0]);
// --------------------------------------------------------------------------
return $objects[0];
} | php | public function getObject($objectIdSlug, $bucketIdSlug = '', $data = [])
{
// Check the cache
$cacheKey = 'object-' . $objectIdSlug;
$cacheKey .= $bucketIdSlug ? '-' . $bucketIdSlug : '';
$cache = $this->getCache($cacheKey);
if ($cache) {
return $cache;
}
// --------------------------------------------------------------------------
if (!isset($data['where'])) {
$data['where'] = [];
}
if (is_numeric($objectIdSlug)) {
$data['where'][] = ['o.id', $objectIdSlug];
} else {
$data['where'][] = ['o.filename', $objectIdSlug];
if (!empty($bucketIdSlug)) {
if (is_numeric($bucketIdSlug)) {
$data['where'][] = ['b.id', $bucketIdSlug];
} else {
$data['where'][] = ['b.slug', $bucketIdSlug];
}
}
}
$objects = $this->getObjects(null, null, $data);
if (empty($objects)) {
return false;
}
// --------------------------------------------------------------------------
// Cache the object
$this->setCache($cacheKey, $objects[0]);
// --------------------------------------------------------------------------
return $objects[0];
} | [
"public",
"function",
"getObject",
"(",
"$",
"objectIdSlug",
",",
"$",
"bucketIdSlug",
"=",
"''",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"// Check the cache",
"$",
"cacheKey",
"=",
"'object-'",
".",
"$",
"objectIdSlug",
";",
"$",
"cacheKey",
".=",
"$",
"bucketIdSlug",
"?",
"'-'",
".",
"$",
"bucketIdSlug",
":",
"''",
";",
"$",
"cache",
"=",
"$",
"this",
"->",
"getCache",
"(",
"$",
"cacheKey",
")",
";",
"if",
"(",
"$",
"cache",
")",
"{",
"return",
"$",
"cache",
";",
"}",
"// --------------------------------------------------------------------------",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'where'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'where'",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"objectIdSlug",
")",
")",
"{",
"$",
"data",
"[",
"'where'",
"]",
"[",
"]",
"=",
"[",
"'o.id'",
",",
"$",
"objectIdSlug",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"'where'",
"]",
"[",
"]",
"=",
"[",
"'o.filename'",
",",
"$",
"objectIdSlug",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"bucketIdSlug",
")",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"bucketIdSlug",
")",
")",
"{",
"$",
"data",
"[",
"'where'",
"]",
"[",
"]",
"=",
"[",
"'b.id'",
",",
"$",
"bucketIdSlug",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"'where'",
"]",
"[",
"]",
"=",
"[",
"'b.slug'",
",",
"$",
"bucketIdSlug",
"]",
";",
"}",
"}",
"}",
"$",
"objects",
"=",
"$",
"this",
"->",
"getObjects",
"(",
"null",
",",
"null",
",",
"$",
"data",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"objects",
")",
")",
"{",
"return",
"false",
";",
"}",
"// --------------------------------------------------------------------------",
"// Cache the object",
"$",
"this",
"->",
"setCache",
"(",
"$",
"cacheKey",
",",
"$",
"objects",
"[",
"0",
"]",
")",
";",
"// --------------------------------------------------------------------------",
"return",
"$",
"objects",
"[",
"0",
"]",
";",
"}"
] | Returns a single object
@param mixed $objectIdSlug The object's ID or filename
@param string $bucketIdSlug The bucket's ID or slug
@param array $data Data to pass to getCountCommon()()
@return mixed stdClass on success, false on failure | [
"Returns",
"a",
"single",
"object"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L497-L541 |
34,589 | nails/module-cdn | src/Service/Cdn.php | Cdn.getObjectFromTrash | public function getObjectFromTrash($object, $bucket = '', $data = [])
{
$oDb = Factory::service('Database');
if (is_numeric($object)) {
// Check the cache
$cacheKey = 'object-trash-' . $object;
$cache = $this->getCache($cacheKey);
if ($cache) {
return $cache;
}
// --------------------------------------------------------------------------
$oDb->where('o.id', $object);
} else {
// Check the cache
$cacheKey = 'object-trash-' . $object;
$cacheKey .= !empty($bucket) ? '-' . $bucket : '';
$cache = $this->getCache($cacheKey);
if ($cache) {
return $cache;
}
// --------------------------------------------------------------------------
$oDb->where('o.filename', $object);
if (!empty($bucket)) {
if (is_numeric($bucket)) {
$oDb->where('b.id', $bucket);
} else {
$oDb->where('b.slug', $bucket);
}
}
}
$objects = $this->getObjectsFromTrash(null, null, $data);
if (empty($objects)) {
return false;
}
// --------------------------------------------------------------------------
// Cache the object
$this->setCache($cacheKey, $objects[0]);
// --------------------------------------------------------------------------
return $objects[0];
} | php | public function getObjectFromTrash($object, $bucket = '', $data = [])
{
$oDb = Factory::service('Database');
if (is_numeric($object)) {
// Check the cache
$cacheKey = 'object-trash-' . $object;
$cache = $this->getCache($cacheKey);
if ($cache) {
return $cache;
}
// --------------------------------------------------------------------------
$oDb->where('o.id', $object);
} else {
// Check the cache
$cacheKey = 'object-trash-' . $object;
$cacheKey .= !empty($bucket) ? '-' . $bucket : '';
$cache = $this->getCache($cacheKey);
if ($cache) {
return $cache;
}
// --------------------------------------------------------------------------
$oDb->where('o.filename', $object);
if (!empty($bucket)) {
if (is_numeric($bucket)) {
$oDb->where('b.id', $bucket);
} else {
$oDb->where('b.slug', $bucket);
}
}
}
$objects = $this->getObjectsFromTrash(null, null, $data);
if (empty($objects)) {
return false;
}
// --------------------------------------------------------------------------
// Cache the object
$this->setCache($cacheKey, $objects[0]);
// --------------------------------------------------------------------------
return $objects[0];
} | [
"public",
"function",
"getObjectFromTrash",
"(",
"$",
"object",
",",
"$",
"bucket",
"=",
"''",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"object",
")",
")",
"{",
"// Check the cache",
"$",
"cacheKey",
"=",
"'object-trash-'",
".",
"$",
"object",
";",
"$",
"cache",
"=",
"$",
"this",
"->",
"getCache",
"(",
"$",
"cacheKey",
")",
";",
"if",
"(",
"$",
"cache",
")",
"{",
"return",
"$",
"cache",
";",
"}",
"// --------------------------------------------------------------------------",
"$",
"oDb",
"->",
"where",
"(",
"'o.id'",
",",
"$",
"object",
")",
";",
"}",
"else",
"{",
"// Check the cache",
"$",
"cacheKey",
"=",
"'object-trash-'",
".",
"$",
"object",
";",
"$",
"cacheKey",
".=",
"!",
"empty",
"(",
"$",
"bucket",
")",
"?",
"'-'",
".",
"$",
"bucket",
":",
"''",
";",
"$",
"cache",
"=",
"$",
"this",
"->",
"getCache",
"(",
"$",
"cacheKey",
")",
";",
"if",
"(",
"$",
"cache",
")",
"{",
"return",
"$",
"cache",
";",
"}",
"// --------------------------------------------------------------------------",
"$",
"oDb",
"->",
"where",
"(",
"'o.filename'",
",",
"$",
"object",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"bucket",
")",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"bucket",
")",
")",
"{",
"$",
"oDb",
"->",
"where",
"(",
"'b.id'",
",",
"$",
"bucket",
")",
";",
"}",
"else",
"{",
"$",
"oDb",
"->",
"where",
"(",
"'b.slug'",
",",
"$",
"bucket",
")",
";",
"}",
"}",
"}",
"$",
"objects",
"=",
"$",
"this",
"->",
"getObjectsFromTrash",
"(",
"null",
",",
"null",
",",
"$",
"data",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"objects",
")",
")",
"{",
"return",
"false",
";",
"}",
"// --------------------------------------------------------------------------",
"// Cache the object",
"$",
"this",
"->",
"setCache",
"(",
"$",
"cacheKey",
",",
"$",
"objects",
"[",
"0",
"]",
")",
";",
"// --------------------------------------------------------------------------",
"return",
"$",
"objects",
"[",
"0",
"]",
";",
"}"
] | Returns a single object from the trash
@param mixed $object The object's ID or filename
@param string $bucket The bucket's ID or slug
@param array $data Data to pass to getCountCommon()
@return mixed stdClass on success, false on failure | [
"Returns",
"a",
"single",
"object",
"from",
"the",
"trash"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L554-L610 |
34,590 | nails/module-cdn | src/Service/Cdn.php | Cdn.getObjectsForUser | public function getObjectsForUser($userId, $page = null, $perPage = null, $data = [])
{
$oDb = Factory::service('Database');
$oDb->where('o.created_by', $userId);
return $this->getObjects($page, $perPage, $data);
} | php | public function getObjectsForUser($userId, $page = null, $perPage = null, $data = [])
{
$oDb = Factory::service('Database');
$oDb->where('o.created_by', $userId);
return $this->getObjects($page, $perPage, $data);
} | [
"public",
"function",
"getObjectsForUser",
"(",
"$",
"userId",
",",
"$",
"page",
"=",
"null",
",",
"$",
"perPage",
"=",
"null",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"where",
"(",
"'o.created_by'",
",",
"$",
"userId",
")",
";",
"return",
"$",
"this",
"->",
"getObjects",
"(",
"$",
"page",
",",
"$",
"perPage",
",",
"$",
"data",
")",
";",
"}"
] | Returns objects created by a user
@param int $userId The user's ID
@param int $page The page of results to return
@param int $perPage The number of results per page
@param array $data Data to pass to getCountCommon()
@return array | [
"Returns",
"objects",
"created",
"by",
"a",
"user"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L656-L661 |
34,591 | nails/module-cdn | src/Service/Cdn.php | Cdn.getUploadError | static function getUploadError($iErrorNumber)
{
// Upload was aborted, I wonder why?
switch ($iErrorNumber) {
case UPLOAD_ERR_INI_SIZE:
$iMaxFileSize = function_exists('ini_get') ? ini_get('upload_max_filesize') : null;
if (!is_null($iMaxFileSize)) {
$iMaxFileSize = static::returnBytes($iMaxFileSize);
$iMaxFileSize = static::formatBytes($iMaxFileSize);
$sError = sprintf(
'The file exceeds the maximum size accepted by this server (which is %s).',
$iMaxFileSize
);
} else {
$sError = 'The file exceeds the maximum size accepted by this server.';
}
break;
case UPLOAD_ERR_FORM_SIZE:
$sError = 'The file exceeds the maximum size accepted by this server.';
break;
case UPLOAD_ERR_PARTIAL:
$sError = 'The file was only partially uploaded.';
break;
case UPLOAD_ERR_NO_FILE:
$sError = 'No file was uploaded.';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$sError = 'This server cannot accept uploads at this time.';
break;
case UPLOAD_ERR_CANT_WRITE:
$sError = 'Failed to write uploaded file to disk, you can try again.';
break;
case UPLOAD_ERR_EXTENSION:
$sError = 'The file failed to upload due to a server configuration.';
break;
default:
$sError = 'The file failed to upload.';
break;
}
return $sError;
} | php | static function getUploadError($iErrorNumber)
{
// Upload was aborted, I wonder why?
switch ($iErrorNumber) {
case UPLOAD_ERR_INI_SIZE:
$iMaxFileSize = function_exists('ini_get') ? ini_get('upload_max_filesize') : null;
if (!is_null($iMaxFileSize)) {
$iMaxFileSize = static::returnBytes($iMaxFileSize);
$iMaxFileSize = static::formatBytes($iMaxFileSize);
$sError = sprintf(
'The file exceeds the maximum size accepted by this server (which is %s).',
$iMaxFileSize
);
} else {
$sError = 'The file exceeds the maximum size accepted by this server.';
}
break;
case UPLOAD_ERR_FORM_SIZE:
$sError = 'The file exceeds the maximum size accepted by this server.';
break;
case UPLOAD_ERR_PARTIAL:
$sError = 'The file was only partially uploaded.';
break;
case UPLOAD_ERR_NO_FILE:
$sError = 'No file was uploaded.';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$sError = 'This server cannot accept uploads at this time.';
break;
case UPLOAD_ERR_CANT_WRITE:
$sError = 'Failed to write uploaded file to disk, you can try again.';
break;
case UPLOAD_ERR_EXTENSION:
$sError = 'The file failed to upload due to a server configuration.';
break;
default:
$sError = 'The file failed to upload.';
break;
}
return $sError;
} | [
"static",
"function",
"getUploadError",
"(",
"$",
"iErrorNumber",
")",
"{",
"// Upload was aborted, I wonder why?",
"switch",
"(",
"$",
"iErrorNumber",
")",
"{",
"case",
"UPLOAD_ERR_INI_SIZE",
":",
"$",
"iMaxFileSize",
"=",
"function_exists",
"(",
"'ini_get'",
")",
"?",
"ini_get",
"(",
"'upload_max_filesize'",
")",
":",
"null",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"iMaxFileSize",
")",
")",
"{",
"$",
"iMaxFileSize",
"=",
"static",
"::",
"returnBytes",
"(",
"$",
"iMaxFileSize",
")",
";",
"$",
"iMaxFileSize",
"=",
"static",
"::",
"formatBytes",
"(",
"$",
"iMaxFileSize",
")",
";",
"$",
"sError",
"=",
"sprintf",
"(",
"'The file exceeds the maximum size accepted by this server (which is %s).'",
",",
"$",
"iMaxFileSize",
")",
";",
"}",
"else",
"{",
"$",
"sError",
"=",
"'The file exceeds the maximum size accepted by this server.'",
";",
"}",
"break",
";",
"case",
"UPLOAD_ERR_FORM_SIZE",
":",
"$",
"sError",
"=",
"'The file exceeds the maximum size accepted by this server.'",
";",
"break",
";",
"case",
"UPLOAD_ERR_PARTIAL",
":",
"$",
"sError",
"=",
"'The file was only partially uploaded.'",
";",
"break",
";",
"case",
"UPLOAD_ERR_NO_FILE",
":",
"$",
"sError",
"=",
"'No file was uploaded.'",
";",
"break",
";",
"case",
"UPLOAD_ERR_NO_TMP_DIR",
":",
"$",
"sError",
"=",
"'This server cannot accept uploads at this time.'",
";",
"break",
";",
"case",
"UPLOAD_ERR_CANT_WRITE",
":",
"$",
"sError",
"=",
"'Failed to write uploaded file to disk, you can try again.'",
";",
"break",
";",
"case",
"UPLOAD_ERR_EXTENSION",
":",
"$",
"sError",
"=",
"'The file failed to upload due to a server configuration.'",
";",
"break",
";",
"default",
":",
"$",
"sError",
"=",
"'The file failed to upload.'",
";",
"break",
";",
"}",
"return",
"$",
"sError",
";",
"}"
] | Returns a string representation of an upload error number
@param integer $iErrorNumber The error number
@return string | [
"Returns",
"a",
"string",
"representation",
"of",
"an",
"upload",
"error",
"number"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1105-L1158 |
34,592 | nails/module-cdn | src/Service/Cdn.php | Cdn.objectDelete | public function objectDelete($iObjectId)
{
$oDb = Factory::service('Database');
try {
$object = $this->getObject($iObjectId);
if (empty($object)) {
throw new CdnException('Not a valid object');
}
// --------------------------------------------------------------------------
$aObjectData = [
'id' => $object->id,
'bucket_id' => $object->bucket->id,
'filename' => $object->file->name->disk,
'filename_display' => $object->file->name->human,
'mime' => $object->file->mime,
'filesize' => $object->file->size->bytes,
'img_width' => $object->img_width,
'img_height' => $object->img_height,
'img_orientation' => $object->img_orientation,
'is_animated' => $object->is_animated,
'serves' => $object->serves,
'downloads' => $object->downloads,
'thumbs' => $object->thumbs,
'scales' => $object->scales,
'driver' => $object->driver,
'created' => $object->created,
'created_by' => $object->created_by,
'modified' => $object->modified,
'modified_by' => $object->modified_by,
];
$oDb->set($aObjectData);
$oDb->set('trashed', 'NOW()', false);
if (isLoggedIn()) {
$oDb->set('trashed_by', activeUser('id'));
}
// Start transaction
$oDb->trans_begin();
// Create trash object
if (!$oDb->insert(NAILS_DB_PREFIX . 'cdn_object_trash')) {
throw new CdnException('Failed to create the trash object.');
}
// Remove original object
$oDb->where('id', $object->id);
if (!$oDb->delete(NAILS_DB_PREFIX . 'cdn_object')) {
throw new CdnException('Failed to remove original object.');
}
$oDb->trans_commit();
// Clear caches
$this->unsetCacheObject($object);
return true;
} catch (\Exception $e) {
$oDb->trans_rollback();
$this->setError($e->getMessage());
return false;
}
} | php | public function objectDelete($iObjectId)
{
$oDb = Factory::service('Database');
try {
$object = $this->getObject($iObjectId);
if (empty($object)) {
throw new CdnException('Not a valid object');
}
// --------------------------------------------------------------------------
$aObjectData = [
'id' => $object->id,
'bucket_id' => $object->bucket->id,
'filename' => $object->file->name->disk,
'filename_display' => $object->file->name->human,
'mime' => $object->file->mime,
'filesize' => $object->file->size->bytes,
'img_width' => $object->img_width,
'img_height' => $object->img_height,
'img_orientation' => $object->img_orientation,
'is_animated' => $object->is_animated,
'serves' => $object->serves,
'downloads' => $object->downloads,
'thumbs' => $object->thumbs,
'scales' => $object->scales,
'driver' => $object->driver,
'created' => $object->created,
'created_by' => $object->created_by,
'modified' => $object->modified,
'modified_by' => $object->modified_by,
];
$oDb->set($aObjectData);
$oDb->set('trashed', 'NOW()', false);
if (isLoggedIn()) {
$oDb->set('trashed_by', activeUser('id'));
}
// Start transaction
$oDb->trans_begin();
// Create trash object
if (!$oDb->insert(NAILS_DB_PREFIX . 'cdn_object_trash')) {
throw new CdnException('Failed to create the trash object.');
}
// Remove original object
$oDb->where('id', $object->id);
if (!$oDb->delete(NAILS_DB_PREFIX . 'cdn_object')) {
throw new CdnException('Failed to remove original object.');
}
$oDb->trans_commit();
// Clear caches
$this->unsetCacheObject($object);
return true;
} catch (\Exception $e) {
$oDb->trans_rollback();
$this->setError($e->getMessage());
return false;
}
} | [
"public",
"function",
"objectDelete",
"(",
"$",
"iObjectId",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"try",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"getObject",
"(",
"$",
"iObjectId",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"object",
")",
")",
"{",
"throw",
"new",
"CdnException",
"(",
"'Not a valid object'",
")",
";",
"}",
"// --------------------------------------------------------------------------",
"$",
"aObjectData",
"=",
"[",
"'id'",
"=>",
"$",
"object",
"->",
"id",
",",
"'bucket_id'",
"=>",
"$",
"object",
"->",
"bucket",
"->",
"id",
",",
"'filename'",
"=>",
"$",
"object",
"->",
"file",
"->",
"name",
"->",
"disk",
",",
"'filename_display'",
"=>",
"$",
"object",
"->",
"file",
"->",
"name",
"->",
"human",
",",
"'mime'",
"=>",
"$",
"object",
"->",
"file",
"->",
"mime",
",",
"'filesize'",
"=>",
"$",
"object",
"->",
"file",
"->",
"size",
"->",
"bytes",
",",
"'img_width'",
"=>",
"$",
"object",
"->",
"img_width",
",",
"'img_height'",
"=>",
"$",
"object",
"->",
"img_height",
",",
"'img_orientation'",
"=>",
"$",
"object",
"->",
"img_orientation",
",",
"'is_animated'",
"=>",
"$",
"object",
"->",
"is_animated",
",",
"'serves'",
"=>",
"$",
"object",
"->",
"serves",
",",
"'downloads'",
"=>",
"$",
"object",
"->",
"downloads",
",",
"'thumbs'",
"=>",
"$",
"object",
"->",
"thumbs",
",",
"'scales'",
"=>",
"$",
"object",
"->",
"scales",
",",
"'driver'",
"=>",
"$",
"object",
"->",
"driver",
",",
"'created'",
"=>",
"$",
"object",
"->",
"created",
",",
"'created_by'",
"=>",
"$",
"object",
"->",
"created_by",
",",
"'modified'",
"=>",
"$",
"object",
"->",
"modified",
",",
"'modified_by'",
"=>",
"$",
"object",
"->",
"modified_by",
",",
"]",
";",
"$",
"oDb",
"->",
"set",
"(",
"$",
"aObjectData",
")",
";",
"$",
"oDb",
"->",
"set",
"(",
"'trashed'",
",",
"'NOW()'",
",",
"false",
")",
";",
"if",
"(",
"isLoggedIn",
"(",
")",
")",
"{",
"$",
"oDb",
"->",
"set",
"(",
"'trashed_by'",
",",
"activeUser",
"(",
"'id'",
")",
")",
";",
"}",
"// Start transaction",
"$",
"oDb",
"->",
"trans_begin",
"(",
")",
";",
"// Create trash object",
"if",
"(",
"!",
"$",
"oDb",
"->",
"insert",
"(",
"NAILS_DB_PREFIX",
".",
"'cdn_object_trash'",
")",
")",
"{",
"throw",
"new",
"CdnException",
"(",
"'Failed to create the trash object.'",
")",
";",
"}",
"// Remove original object",
"$",
"oDb",
"->",
"where",
"(",
"'id'",
",",
"$",
"object",
"->",
"id",
")",
";",
"if",
"(",
"!",
"$",
"oDb",
"->",
"delete",
"(",
"NAILS_DB_PREFIX",
".",
"'cdn_object'",
")",
")",
"{",
"throw",
"new",
"CdnException",
"(",
"'Failed to remove original object.'",
")",
";",
"}",
"$",
"oDb",
"->",
"trans_commit",
"(",
")",
";",
"// Clear caches",
"$",
"this",
"->",
"unsetCacheObject",
"(",
"$",
"object",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"oDb",
"->",
"trans_rollback",
"(",
")",
";",
"$",
"this",
"->",
"setError",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Deletes an object
@param int $iObjectId The object's ID or filename
@return boolean | [
"Deletes",
"an",
"object"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1169-L1239 |
34,593 | nails/module-cdn | src/Service/Cdn.php | Cdn.objectRestore | public function objectRestore($iObjectId)
{
$oDb = Factory::service('Database');
try {
$oObject = $this->getObjectFromTrash($iObjectId);
if (empty($oObject)) {
throw new CdnException('Not a valid object');
}
// --------------------------------------------------------------------------
$aObjectData = [
'id' => $oObject->id,
'bucket_id' => $oObject->bucket->id,
'filename' => $oObject->file->name->disk,
'filename_display' => $oObject->file->name->human,
'mime' => $oObject->file->mime,
'filesize' => $oObject->file->size->bytes,
'img_width' => $oObject->img_width,
'img_height' => $oObject->img_height,
'img_orientation' => $oObject->img_orientation,
'is_animated' => $oObject->is_animated,
'serves' => $oObject->serves,
'downloads' => $oObject->downloads,
'thumbs' => $oObject->thumbs,
'scales' => $oObject->scales,
'driver' => $oObject->driver,
'created' => $oObject->created,
'created_by' => $oObject->created_by,
];
if (isLoggedIn()) {
$aObjectData['modified_by'] = activeUser('id');
}
$oDb->set($aObjectData);
$oDb->set('modified', 'NOW()', false);
// Start transaction
$oDb->trans_begin();
// Restore object
if (!$oDb->insert(NAILS_DB_PREFIX . 'cdn_object')) {
throw new CdnException('Failed to restore original object.');
}
// Remove trash object
$oDb->where('id', $oObject->id);
if (!$oDb->delete(NAILS_DB_PREFIX . 'cdn_object_trash')) {
throw new CdnException('Failed to remove the trash object.');
}
$oDb->trans_commit();
return true;
} catch (\Exception $e) {
$oDb->trans_rollback();
$this->setError($e->getMessage());
return false;
}
} | php | public function objectRestore($iObjectId)
{
$oDb = Factory::service('Database');
try {
$oObject = $this->getObjectFromTrash($iObjectId);
if (empty($oObject)) {
throw new CdnException('Not a valid object');
}
// --------------------------------------------------------------------------
$aObjectData = [
'id' => $oObject->id,
'bucket_id' => $oObject->bucket->id,
'filename' => $oObject->file->name->disk,
'filename_display' => $oObject->file->name->human,
'mime' => $oObject->file->mime,
'filesize' => $oObject->file->size->bytes,
'img_width' => $oObject->img_width,
'img_height' => $oObject->img_height,
'img_orientation' => $oObject->img_orientation,
'is_animated' => $oObject->is_animated,
'serves' => $oObject->serves,
'downloads' => $oObject->downloads,
'thumbs' => $oObject->thumbs,
'scales' => $oObject->scales,
'driver' => $oObject->driver,
'created' => $oObject->created,
'created_by' => $oObject->created_by,
];
if (isLoggedIn()) {
$aObjectData['modified_by'] = activeUser('id');
}
$oDb->set($aObjectData);
$oDb->set('modified', 'NOW()', false);
// Start transaction
$oDb->trans_begin();
// Restore object
if (!$oDb->insert(NAILS_DB_PREFIX . 'cdn_object')) {
throw new CdnException('Failed to restore original object.');
}
// Remove trash object
$oDb->where('id', $oObject->id);
if (!$oDb->delete(NAILS_DB_PREFIX . 'cdn_object_trash')) {
throw new CdnException('Failed to remove the trash object.');
}
$oDb->trans_commit();
return true;
} catch (\Exception $e) {
$oDb->trans_rollback();
$this->setError($e->getMessage());
return false;
}
} | [
"public",
"function",
"objectRestore",
"(",
"$",
"iObjectId",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"try",
"{",
"$",
"oObject",
"=",
"$",
"this",
"->",
"getObjectFromTrash",
"(",
"$",
"iObjectId",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oObject",
")",
")",
"{",
"throw",
"new",
"CdnException",
"(",
"'Not a valid object'",
")",
";",
"}",
"// --------------------------------------------------------------------------",
"$",
"aObjectData",
"=",
"[",
"'id'",
"=>",
"$",
"oObject",
"->",
"id",
",",
"'bucket_id'",
"=>",
"$",
"oObject",
"->",
"bucket",
"->",
"id",
",",
"'filename'",
"=>",
"$",
"oObject",
"->",
"file",
"->",
"name",
"->",
"disk",
",",
"'filename_display'",
"=>",
"$",
"oObject",
"->",
"file",
"->",
"name",
"->",
"human",
",",
"'mime'",
"=>",
"$",
"oObject",
"->",
"file",
"->",
"mime",
",",
"'filesize'",
"=>",
"$",
"oObject",
"->",
"file",
"->",
"size",
"->",
"bytes",
",",
"'img_width'",
"=>",
"$",
"oObject",
"->",
"img_width",
",",
"'img_height'",
"=>",
"$",
"oObject",
"->",
"img_height",
",",
"'img_orientation'",
"=>",
"$",
"oObject",
"->",
"img_orientation",
",",
"'is_animated'",
"=>",
"$",
"oObject",
"->",
"is_animated",
",",
"'serves'",
"=>",
"$",
"oObject",
"->",
"serves",
",",
"'downloads'",
"=>",
"$",
"oObject",
"->",
"downloads",
",",
"'thumbs'",
"=>",
"$",
"oObject",
"->",
"thumbs",
",",
"'scales'",
"=>",
"$",
"oObject",
"->",
"scales",
",",
"'driver'",
"=>",
"$",
"oObject",
"->",
"driver",
",",
"'created'",
"=>",
"$",
"oObject",
"->",
"created",
",",
"'created_by'",
"=>",
"$",
"oObject",
"->",
"created_by",
",",
"]",
";",
"if",
"(",
"isLoggedIn",
"(",
")",
")",
"{",
"$",
"aObjectData",
"[",
"'modified_by'",
"]",
"=",
"activeUser",
"(",
"'id'",
")",
";",
"}",
"$",
"oDb",
"->",
"set",
"(",
"$",
"aObjectData",
")",
";",
"$",
"oDb",
"->",
"set",
"(",
"'modified'",
",",
"'NOW()'",
",",
"false",
")",
";",
"// Start transaction",
"$",
"oDb",
"->",
"trans_begin",
"(",
")",
";",
"// Restore object",
"if",
"(",
"!",
"$",
"oDb",
"->",
"insert",
"(",
"NAILS_DB_PREFIX",
".",
"'cdn_object'",
")",
")",
"{",
"throw",
"new",
"CdnException",
"(",
"'Failed to restore original object.'",
")",
";",
"}",
"// Remove trash object",
"$",
"oDb",
"->",
"where",
"(",
"'id'",
",",
"$",
"oObject",
"->",
"id",
")",
";",
"if",
"(",
"!",
"$",
"oDb",
"->",
"delete",
"(",
"NAILS_DB_PREFIX",
".",
"'cdn_object_trash'",
")",
")",
"{",
"throw",
"new",
"CdnException",
"(",
"'Failed to remove the trash object.'",
")",
";",
"}",
"$",
"oDb",
"->",
"trans_commit",
"(",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"oDb",
"->",
"trans_rollback",
"(",
")",
";",
"$",
"this",
"->",
"setError",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Restore an object from the trash
@param mixed $iObjectId The object's ID or filename
@return boolean | [
"Restore",
"an",
"object",
"from",
"the",
"trash"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1250-L1313 |
34,594 | nails/module-cdn | src/Service/Cdn.php | Cdn.objectReplace | public function objectReplace($object, $bucket, $replaceWith, $options = [], $bIsStream = false)
{
// Firstly, attempt the upload
$upload = $this->objectCreate($replaceWith, $bucket, $options, $bIsStream);
if ($upload) {
$oObj = $this->getObject($object);
if ($oObj) {
$this->objectDelete($oObj->id);
}
return $upload;
} else {
return false;
}
} | php | public function objectReplace($object, $bucket, $replaceWith, $options = [], $bIsStream = false)
{
// Firstly, attempt the upload
$upload = $this->objectCreate($replaceWith, $bucket, $options, $bIsStream);
if ($upload) {
$oObj = $this->getObject($object);
if ($oObj) {
$this->objectDelete($oObj->id);
}
return $upload;
} else {
return false;
}
} | [
"public",
"function",
"objectReplace",
"(",
"$",
"object",
",",
"$",
"bucket",
",",
"$",
"replaceWith",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"bIsStream",
"=",
"false",
")",
"{",
"// Firstly, attempt the upload",
"$",
"upload",
"=",
"$",
"this",
"->",
"objectCreate",
"(",
"$",
"replaceWith",
",",
"$",
"bucket",
",",
"$",
"options",
",",
"$",
"bIsStream",
")",
";",
"if",
"(",
"$",
"upload",
")",
"{",
"$",
"oObj",
"=",
"$",
"this",
"->",
"getObject",
"(",
"$",
"object",
")",
";",
"if",
"(",
"$",
"oObj",
")",
"{",
"$",
"this",
"->",
"objectDelete",
"(",
"$",
"oObj",
"->",
"id",
")",
";",
"}",
"return",
"$",
"upload",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Uploads an object and, if successful, removes the old object. Note that a new Object ID is created.
@param mixed $object The existing object's ID or filename
@param mixed $bucket The bucket's ID or slug
@param mixed $replaceWith The replacement: $_FILE key, path or data stream
@param array $options An array of options to apply to the upload
@param boolean $bIsStream Whether the replacement object is a data stream or not
@return mixed stdClass on success, false on failure | [
"Uploads",
"an",
"object",
"and",
"if",
"successful",
"removes",
"the",
"old",
"object",
".",
"Note",
"that",
"a",
"new",
"Object",
"ID",
"is",
"created",
"."
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1428-L1446 |
34,595 | nails/module-cdn | src/Service/Cdn.php | Cdn.objectIncrementCount | public function objectIncrementCount($action, $object, $bucket = null)
{
/** @var \CI_Db $oDb */
$oDb = Factory::service('Database');
switch (strtoupper($action)) {
case 'SERVE':
$oDb->set('o.serves', 'o.serves+1', false);
break;
case 'DOWNLOAD':
$oDb->set('o.downloads', 'o.downloads+1', false);
break;
case 'THUMB':
case 'CROP':
$oDb->set('o.thumbs', 'o.thumbs+1', false);
break;
case 'SCALE':
$oDb->set('o.scales', 'o.scales+1', false);
break;
}
if (is_numeric($object)) {
$oDb->where('o.id', $object);
} else {
$oDb->where('o.filename', $object);
}
if ($bucket && is_numeric($bucket)) {
$oDb->where('o.bucket_id', $bucket);
return $oDb->update(NAILS_DB_PREFIX . 'cdn_object o');
} elseif ($bucket) {
$oDb->where('b.slug', $bucket);
$oDb->join(NAILS_DB_PREFIX . 'cdn_bucket b', 'b.id = o.bucket_id');
return $oDb->update(NAILS_DB_PREFIX . 'cdn_object o');
} else {
return $oDb->update(NAILS_DB_PREFIX . 'cdn_object o');
}
} | php | public function objectIncrementCount($action, $object, $bucket = null)
{
/** @var \CI_Db $oDb */
$oDb = Factory::service('Database');
switch (strtoupper($action)) {
case 'SERVE':
$oDb->set('o.serves', 'o.serves+1', false);
break;
case 'DOWNLOAD':
$oDb->set('o.downloads', 'o.downloads+1', false);
break;
case 'THUMB':
case 'CROP':
$oDb->set('o.thumbs', 'o.thumbs+1', false);
break;
case 'SCALE':
$oDb->set('o.scales', 'o.scales+1', false);
break;
}
if (is_numeric($object)) {
$oDb->where('o.id', $object);
} else {
$oDb->where('o.filename', $object);
}
if ($bucket && is_numeric($bucket)) {
$oDb->where('o.bucket_id', $bucket);
return $oDb->update(NAILS_DB_PREFIX . 'cdn_object o');
} elseif ($bucket) {
$oDb->where('b.slug', $bucket);
$oDb->join(NAILS_DB_PREFIX . 'cdn_bucket b', 'b.id = o.bucket_id');
return $oDb->update(NAILS_DB_PREFIX . 'cdn_object o');
} else {
return $oDb->update(NAILS_DB_PREFIX . 'cdn_object o');
}
} | [
"public",
"function",
"objectIncrementCount",
"(",
"$",
"action",
",",
"$",
"object",
",",
"$",
"bucket",
"=",
"null",
")",
"{",
"/** @var \\CI_Db $oDb */",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"switch",
"(",
"strtoupper",
"(",
"$",
"action",
")",
")",
"{",
"case",
"'SERVE'",
":",
"$",
"oDb",
"->",
"set",
"(",
"'o.serves'",
",",
"'o.serves+1'",
",",
"false",
")",
";",
"break",
";",
"case",
"'DOWNLOAD'",
":",
"$",
"oDb",
"->",
"set",
"(",
"'o.downloads'",
",",
"'o.downloads+1'",
",",
"false",
")",
";",
"break",
";",
"case",
"'THUMB'",
":",
"case",
"'CROP'",
":",
"$",
"oDb",
"->",
"set",
"(",
"'o.thumbs'",
",",
"'o.thumbs+1'",
",",
"false",
")",
";",
"break",
";",
"case",
"'SCALE'",
":",
"$",
"oDb",
"->",
"set",
"(",
"'o.scales'",
",",
"'o.scales+1'",
",",
"false",
")",
";",
"break",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"object",
")",
")",
"{",
"$",
"oDb",
"->",
"where",
"(",
"'o.id'",
",",
"$",
"object",
")",
";",
"}",
"else",
"{",
"$",
"oDb",
"->",
"where",
"(",
"'o.filename'",
",",
"$",
"object",
")",
";",
"}",
"if",
"(",
"$",
"bucket",
"&&",
"is_numeric",
"(",
"$",
"bucket",
")",
")",
"{",
"$",
"oDb",
"->",
"where",
"(",
"'o.bucket_id'",
",",
"$",
"bucket",
")",
";",
"return",
"$",
"oDb",
"->",
"update",
"(",
"NAILS_DB_PREFIX",
".",
"'cdn_object o'",
")",
";",
"}",
"elseif",
"(",
"$",
"bucket",
")",
"{",
"$",
"oDb",
"->",
"where",
"(",
"'b.slug'",
",",
"$",
"bucket",
")",
";",
"$",
"oDb",
"->",
"join",
"(",
"NAILS_DB_PREFIX",
".",
"'cdn_bucket b'",
",",
"'b.id = o.bucket_id'",
")",
";",
"return",
"$",
"oDb",
"->",
"update",
"(",
"NAILS_DB_PREFIX",
".",
"'cdn_object o'",
")",
";",
"}",
"else",
"{",
"return",
"$",
"oDb",
"->",
"update",
"(",
"NAILS_DB_PREFIX",
".",
"'cdn_object o'",
")",
";",
"}",
"}"
] | Increments the stats of on object
@param string $action The stat to increment
@param mixed $object The object's ID or filename
@param mixed $bucket The bucket's ID or slug
@return boolean | [
"Increments",
"the",
"stats",
"of",
"on",
"object"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1459-L1499 |
34,596 | nails/module-cdn | src/Service/Cdn.php | Cdn.objectLocalPath | public function objectLocalPath($iId, $bIsTrash = false)
{
try {
$oObj = $bIsTrash ? $this->getObjectFromTrash($iId) : $this->getObject($iId);
if (!$oObj) {
throw new CdnException('Invalid Object ID');
}
$sLocalPath = $this->callDriver(
'objectLocalPath',
[
$oObj->bucket->slug,
$oObj->file->name->disk,
],
$oObj->driver
);
if (!$sLocalPath) {
throw new CdnException($this->callDriver('lastError'));
}
return $sLocalPath;
} catch (\Exception $e) {
$this->setError($e->getMessage());
return false;
}
} | php | public function objectLocalPath($iId, $bIsTrash = false)
{
try {
$oObj = $bIsTrash ? $this->getObjectFromTrash($iId) : $this->getObject($iId);
if (!$oObj) {
throw new CdnException('Invalid Object ID');
}
$sLocalPath = $this->callDriver(
'objectLocalPath',
[
$oObj->bucket->slug,
$oObj->file->name->disk,
],
$oObj->driver
);
if (!$sLocalPath) {
throw new CdnException($this->callDriver('lastError'));
}
return $sLocalPath;
} catch (\Exception $e) {
$this->setError($e->getMessage());
return false;
}
} | [
"public",
"function",
"objectLocalPath",
"(",
"$",
"iId",
",",
"$",
"bIsTrash",
"=",
"false",
")",
"{",
"try",
"{",
"$",
"oObj",
"=",
"$",
"bIsTrash",
"?",
"$",
"this",
"->",
"getObjectFromTrash",
"(",
"$",
"iId",
")",
":",
"$",
"this",
"->",
"getObject",
"(",
"$",
"iId",
")",
";",
"if",
"(",
"!",
"$",
"oObj",
")",
"{",
"throw",
"new",
"CdnException",
"(",
"'Invalid Object ID'",
")",
";",
"}",
"$",
"sLocalPath",
"=",
"$",
"this",
"->",
"callDriver",
"(",
"'objectLocalPath'",
",",
"[",
"$",
"oObj",
"->",
"bucket",
"->",
"slug",
",",
"$",
"oObj",
"->",
"file",
"->",
"name",
"->",
"disk",
",",
"]",
",",
"$",
"oObj",
"->",
"driver",
")",
";",
"if",
"(",
"!",
"$",
"sLocalPath",
")",
"{",
"throw",
"new",
"CdnException",
"(",
"$",
"this",
"->",
"callDriver",
"(",
"'lastError'",
")",
")",
";",
"}",
"return",
"$",
"sLocalPath",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Returns a local path for an object ID
@param int $iId The object's ID
@param boolean $bIsTrash Whether to look in the trash or not
@return mixed | [
"Returns",
"a",
"local",
"path",
"for",
"an",
"object",
"ID"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1511-L1539 |
34,597 | nails/module-cdn | src/Service/Cdn.php | Cdn.createObject | protected function createObject($oData, $bReturnObject = false)
{
$aData = [
'bucket_id' => $oData->bucket->id,
'filename' => $oData->filename,
'filename_display' => $oData->name,
'mime' => $oData->mime,
'filesize' => $oData->filesize,
'md5_hash' => $oData->md5_hash,
'driver' => $this->oEnabledDriver->slug,
];
// --------------------------------------------------------------------------
if (isset($oData->img->width) && isset($oData->img->height) && isset($oData->img->orientation)) {
$aData['img_width'] = $oData->img->width;
$aData['img_height'] = $oData->img->height;
$aData['img_orientation'] = $oData->img->orientation;
}
// --------------------------------------------------------------------------
// Check whether file is animated gif
if ($oData->mime == 'image/gif') {
if (isset($oData->img->is_animated)) {
$aData['is_animated'] = $oData->img->is_animated;
} else {
$aData['is_animated'] = false;
}
}
// --------------------------------------------------------------------------
$oObjectModel = Factory::model('Object', 'nails/module-cdn');
$iObjectId = $oObjectModel->create($aData);
if ($iObjectId) {
return $bReturnObject ? $this->getObject($iObjectId) : $iObjectId;
} else {
return false;
}
} | php | protected function createObject($oData, $bReturnObject = false)
{
$aData = [
'bucket_id' => $oData->bucket->id,
'filename' => $oData->filename,
'filename_display' => $oData->name,
'mime' => $oData->mime,
'filesize' => $oData->filesize,
'md5_hash' => $oData->md5_hash,
'driver' => $this->oEnabledDriver->slug,
];
// --------------------------------------------------------------------------
if (isset($oData->img->width) && isset($oData->img->height) && isset($oData->img->orientation)) {
$aData['img_width'] = $oData->img->width;
$aData['img_height'] = $oData->img->height;
$aData['img_orientation'] = $oData->img->orientation;
}
// --------------------------------------------------------------------------
// Check whether file is animated gif
if ($oData->mime == 'image/gif') {
if (isset($oData->img->is_animated)) {
$aData['is_animated'] = $oData->img->is_animated;
} else {
$aData['is_animated'] = false;
}
}
// --------------------------------------------------------------------------
$oObjectModel = Factory::model('Object', 'nails/module-cdn');
$iObjectId = $oObjectModel->create($aData);
if ($iObjectId) {
return $bReturnObject ? $this->getObject($iObjectId) : $iObjectId;
} else {
return false;
}
} | [
"protected",
"function",
"createObject",
"(",
"$",
"oData",
",",
"$",
"bReturnObject",
"=",
"false",
")",
"{",
"$",
"aData",
"=",
"[",
"'bucket_id'",
"=>",
"$",
"oData",
"->",
"bucket",
"->",
"id",
",",
"'filename'",
"=>",
"$",
"oData",
"->",
"filename",
",",
"'filename_display'",
"=>",
"$",
"oData",
"->",
"name",
",",
"'mime'",
"=>",
"$",
"oData",
"->",
"mime",
",",
"'filesize'",
"=>",
"$",
"oData",
"->",
"filesize",
",",
"'md5_hash'",
"=>",
"$",
"oData",
"->",
"md5_hash",
",",
"'driver'",
"=>",
"$",
"this",
"->",
"oEnabledDriver",
"->",
"slug",
",",
"]",
";",
"// --------------------------------------------------------------------------",
"if",
"(",
"isset",
"(",
"$",
"oData",
"->",
"img",
"->",
"width",
")",
"&&",
"isset",
"(",
"$",
"oData",
"->",
"img",
"->",
"height",
")",
"&&",
"isset",
"(",
"$",
"oData",
"->",
"img",
"->",
"orientation",
")",
")",
"{",
"$",
"aData",
"[",
"'img_width'",
"]",
"=",
"$",
"oData",
"->",
"img",
"->",
"width",
";",
"$",
"aData",
"[",
"'img_height'",
"]",
"=",
"$",
"oData",
"->",
"img",
"->",
"height",
";",
"$",
"aData",
"[",
"'img_orientation'",
"]",
"=",
"$",
"oData",
"->",
"img",
"->",
"orientation",
";",
"}",
"// --------------------------------------------------------------------------",
"// Check whether file is animated gif",
"if",
"(",
"$",
"oData",
"->",
"mime",
"==",
"'image/gif'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"oData",
"->",
"img",
"->",
"is_animated",
")",
")",
"{",
"$",
"aData",
"[",
"'is_animated'",
"]",
"=",
"$",
"oData",
"->",
"img",
"->",
"is_animated",
";",
"}",
"else",
"{",
"$",
"aData",
"[",
"'is_animated'",
"]",
"=",
"false",
";",
"}",
"}",
"// --------------------------------------------------------------------------",
"$",
"oObjectModel",
"=",
"Factory",
"::",
"model",
"(",
"'Object'",
",",
"'nails/module-cdn'",
")",
";",
"$",
"iObjectId",
"=",
"$",
"oObjectModel",
"->",
"create",
"(",
"$",
"aData",
")",
";",
"if",
"(",
"$",
"iObjectId",
")",
"{",
"return",
"$",
"bReturnObject",
"?",
"$",
"this",
"->",
"getObject",
"(",
"$",
"iObjectId",
")",
":",
"$",
"iObjectId",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Creates a new object record in the DB; called from various other methods
@param \stdClass $oData The data to create the object with
@param boolean $bReturnObject Whether to return the object, or just it's ID
@return mixed | [
"Creates",
"a",
"new",
"object",
"record",
"in",
"the",
"DB",
";",
"called",
"from",
"various",
"other",
"methods"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1551-L1592 |
34,598 | nails/module-cdn | src/Service/Cdn.php | Cdn.formatObject | protected function formatObject(&$oObj)
{
$oObj->id = (int) $oObj->id;
$oObj->img_width = (int) $oObj->img_width;
$oObj->img_height = (int) $oObj->img_height;
$oObj->is_animated = (bool) $oObj->is_animated;
$oObj->serves = (int) $oObj->serves;
$oObj->downloads = (int) $oObj->downloads;
$oObj->thumbs = (int) $oObj->thumbs;
$oObj->scales = (int) $oObj->scales;
$oObj->modified_by = (int) $oObj->modified_by ?: null;
// --------------------------------------------------------------------------
$sFileNameDisk = $oObj->filename;
$sFileNameHuman = $oObj->filename_display;
$iFileSize = (int) $oObj->filesize;
$oObj->file = (object) [
'name' => (object) [
'disk' => $sFileNameDisk,
'human' => $sFileNameHuman,
],
'mime' => $oObj->mime,
'ext' => strtolower(pathinfo($sFileNameDisk, PATHINFO_EXTENSION)),
'size' => (object) [
'bytes' => $iFileSize,
'kilobytes' => round($iFileSize / self::BYTE_MULTIPLIER_KB, self::FILE_SIZE_PRECISION),
'megabytes' => round($iFileSize / self::BYTE_MULTIPLIER_MB, self::FILE_SIZE_PRECISION),
'gigabytes' => round($iFileSize / self::BYTE_MULTIPLIER_GB, self::FILE_SIZE_PRECISION),
'human' => static::formatBytes($iFileSize),
],
'hash' => (object) [
'md5' => $oObj->md5_hash,
],
];
unset($oObj->filename);
unset($oObj->filename_display);
unset($oObj->mime);
unset($oObj->filesize);
// --------------------------------------------------------------------------
$oObj->bucket = (object) [
'id' => (int) $oObj->bucket_id,
'label' => $oObj->bucket_label,
'slug' => $oObj->bucket_slug,
];
unset($oObj->bucket_id);
unset($oObj->bucket_label);
unset($oObj->bucket_slug);
// --------------------------------------------------------------------------
// Quick flag for detecting images
$oObj->is_img = false;
switch ($oObj->file->mime) {
case 'image/jpg':
case 'image/jpeg':
case 'image/gif':
case 'image/png':
$oObj->is_img = true;
break;
}
} | php | protected function formatObject(&$oObj)
{
$oObj->id = (int) $oObj->id;
$oObj->img_width = (int) $oObj->img_width;
$oObj->img_height = (int) $oObj->img_height;
$oObj->is_animated = (bool) $oObj->is_animated;
$oObj->serves = (int) $oObj->serves;
$oObj->downloads = (int) $oObj->downloads;
$oObj->thumbs = (int) $oObj->thumbs;
$oObj->scales = (int) $oObj->scales;
$oObj->modified_by = (int) $oObj->modified_by ?: null;
// --------------------------------------------------------------------------
$sFileNameDisk = $oObj->filename;
$sFileNameHuman = $oObj->filename_display;
$iFileSize = (int) $oObj->filesize;
$oObj->file = (object) [
'name' => (object) [
'disk' => $sFileNameDisk,
'human' => $sFileNameHuman,
],
'mime' => $oObj->mime,
'ext' => strtolower(pathinfo($sFileNameDisk, PATHINFO_EXTENSION)),
'size' => (object) [
'bytes' => $iFileSize,
'kilobytes' => round($iFileSize / self::BYTE_MULTIPLIER_KB, self::FILE_SIZE_PRECISION),
'megabytes' => round($iFileSize / self::BYTE_MULTIPLIER_MB, self::FILE_SIZE_PRECISION),
'gigabytes' => round($iFileSize / self::BYTE_MULTIPLIER_GB, self::FILE_SIZE_PRECISION),
'human' => static::formatBytes($iFileSize),
],
'hash' => (object) [
'md5' => $oObj->md5_hash,
],
];
unset($oObj->filename);
unset($oObj->filename_display);
unset($oObj->mime);
unset($oObj->filesize);
// --------------------------------------------------------------------------
$oObj->bucket = (object) [
'id' => (int) $oObj->bucket_id,
'label' => $oObj->bucket_label,
'slug' => $oObj->bucket_slug,
];
unset($oObj->bucket_id);
unset($oObj->bucket_label);
unset($oObj->bucket_slug);
// --------------------------------------------------------------------------
// Quick flag for detecting images
$oObj->is_img = false;
switch ($oObj->file->mime) {
case 'image/jpg':
case 'image/jpeg':
case 'image/gif':
case 'image/png':
$oObj->is_img = true;
break;
}
} | [
"protected",
"function",
"formatObject",
"(",
"&",
"$",
"oObj",
")",
"{",
"$",
"oObj",
"->",
"id",
"=",
"(",
"int",
")",
"$",
"oObj",
"->",
"id",
";",
"$",
"oObj",
"->",
"img_width",
"=",
"(",
"int",
")",
"$",
"oObj",
"->",
"img_width",
";",
"$",
"oObj",
"->",
"img_height",
"=",
"(",
"int",
")",
"$",
"oObj",
"->",
"img_height",
";",
"$",
"oObj",
"->",
"is_animated",
"=",
"(",
"bool",
")",
"$",
"oObj",
"->",
"is_animated",
";",
"$",
"oObj",
"->",
"serves",
"=",
"(",
"int",
")",
"$",
"oObj",
"->",
"serves",
";",
"$",
"oObj",
"->",
"downloads",
"=",
"(",
"int",
")",
"$",
"oObj",
"->",
"downloads",
";",
"$",
"oObj",
"->",
"thumbs",
"=",
"(",
"int",
")",
"$",
"oObj",
"->",
"thumbs",
";",
"$",
"oObj",
"->",
"scales",
"=",
"(",
"int",
")",
"$",
"oObj",
"->",
"scales",
";",
"$",
"oObj",
"->",
"modified_by",
"=",
"(",
"int",
")",
"$",
"oObj",
"->",
"modified_by",
"?",
":",
"null",
";",
"// --------------------------------------------------------------------------",
"$",
"sFileNameDisk",
"=",
"$",
"oObj",
"->",
"filename",
";",
"$",
"sFileNameHuman",
"=",
"$",
"oObj",
"->",
"filename_display",
";",
"$",
"iFileSize",
"=",
"(",
"int",
")",
"$",
"oObj",
"->",
"filesize",
";",
"$",
"oObj",
"->",
"file",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"(",
"object",
")",
"[",
"'disk'",
"=>",
"$",
"sFileNameDisk",
",",
"'human'",
"=>",
"$",
"sFileNameHuman",
",",
"]",
",",
"'mime'",
"=>",
"$",
"oObj",
"->",
"mime",
",",
"'ext'",
"=>",
"strtolower",
"(",
"pathinfo",
"(",
"$",
"sFileNameDisk",
",",
"PATHINFO_EXTENSION",
")",
")",
",",
"'size'",
"=>",
"(",
"object",
")",
"[",
"'bytes'",
"=>",
"$",
"iFileSize",
",",
"'kilobytes'",
"=>",
"round",
"(",
"$",
"iFileSize",
"/",
"self",
"::",
"BYTE_MULTIPLIER_KB",
",",
"self",
"::",
"FILE_SIZE_PRECISION",
")",
",",
"'megabytes'",
"=>",
"round",
"(",
"$",
"iFileSize",
"/",
"self",
"::",
"BYTE_MULTIPLIER_MB",
",",
"self",
"::",
"FILE_SIZE_PRECISION",
")",
",",
"'gigabytes'",
"=>",
"round",
"(",
"$",
"iFileSize",
"/",
"self",
"::",
"BYTE_MULTIPLIER_GB",
",",
"self",
"::",
"FILE_SIZE_PRECISION",
")",
",",
"'human'",
"=>",
"static",
"::",
"formatBytes",
"(",
"$",
"iFileSize",
")",
",",
"]",
",",
"'hash'",
"=>",
"(",
"object",
")",
"[",
"'md5'",
"=>",
"$",
"oObj",
"->",
"md5_hash",
",",
"]",
",",
"]",
";",
"unset",
"(",
"$",
"oObj",
"->",
"filename",
")",
";",
"unset",
"(",
"$",
"oObj",
"->",
"filename_display",
")",
";",
"unset",
"(",
"$",
"oObj",
"->",
"mime",
")",
";",
"unset",
"(",
"$",
"oObj",
"->",
"filesize",
")",
";",
"// --------------------------------------------------------------------------",
"$",
"oObj",
"->",
"bucket",
"=",
"(",
"object",
")",
"[",
"'id'",
"=>",
"(",
"int",
")",
"$",
"oObj",
"->",
"bucket_id",
",",
"'label'",
"=>",
"$",
"oObj",
"->",
"bucket_label",
",",
"'slug'",
"=>",
"$",
"oObj",
"->",
"bucket_slug",
",",
"]",
";",
"unset",
"(",
"$",
"oObj",
"->",
"bucket_id",
")",
";",
"unset",
"(",
"$",
"oObj",
"->",
"bucket_label",
")",
";",
"unset",
"(",
"$",
"oObj",
"->",
"bucket_slug",
")",
";",
"// --------------------------------------------------------------------------",
"// Quick flag for detecting images",
"$",
"oObj",
"->",
"is_img",
"=",
"false",
";",
"switch",
"(",
"$",
"oObj",
"->",
"file",
"->",
"mime",
")",
"{",
"case",
"'image/jpg'",
":",
"case",
"'image/jpeg'",
":",
"case",
"'image/gif'",
":",
"case",
"'image/png'",
":",
"$",
"oObj",
"->",
"is_img",
"=",
"true",
";",
"break",
";",
"}",
"}"
] | Formats an object object
@param object $oObj The object to format
@return void | [
"Formats",
"an",
"object",
"object"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1603-L1670 |
34,599 | nails/module-cdn | src/Service/Cdn.php | Cdn.getBuckets | public function getBuckets($page = null, $perPage = null, $data = [])
{
$oDb = Factory::service('Database');
$oDb->select('b.id,b.slug,b.label,b.allowed_types,b.max_size,b.created,b.created_by');
$oDb->select('b.modified,b.modified_by');
// Apply common items; pass $data
$this->getCountCommonBuckets($data);
// --------------------------------------------------------------------------
// Facilitate pagination
if (!is_null($page)) {
/**
* Adjust the page variable, reduce by one so that the offset is calculated
* correctly. Make sure we don't go into negative numbers
*/
$page--;
$page = $page < 0 ? 0 : $page;
// Work out what the offset should be
$perPage = is_null($perPage) ? 50 : (int) $perPage;
$offset = $page * $perPage;
$oDb->limit($perPage, $offset);
}
// --------------------------------------------------------------------------
$buckets = $oDb->get(NAILS_DB_PREFIX . 'cdn_bucket b')->result();
$numBuckets = count($buckets);
for ($i = 0; $i < $numBuckets; $i++) {
// Format the object, make it pretty
$this->formatBucket($buckets[$i]);
}
return $buckets;
} | php | public function getBuckets($page = null, $perPage = null, $data = [])
{
$oDb = Factory::service('Database');
$oDb->select('b.id,b.slug,b.label,b.allowed_types,b.max_size,b.created,b.created_by');
$oDb->select('b.modified,b.modified_by');
// Apply common items; pass $data
$this->getCountCommonBuckets($data);
// --------------------------------------------------------------------------
// Facilitate pagination
if (!is_null($page)) {
/**
* Adjust the page variable, reduce by one so that the offset is calculated
* correctly. Make sure we don't go into negative numbers
*/
$page--;
$page = $page < 0 ? 0 : $page;
// Work out what the offset should be
$perPage = is_null($perPage) ? 50 : (int) $perPage;
$offset = $page * $perPage;
$oDb->limit($perPage, $offset);
}
// --------------------------------------------------------------------------
$buckets = $oDb->get(NAILS_DB_PREFIX . 'cdn_bucket b')->result();
$numBuckets = count($buckets);
for ($i = 0; $i < $numBuckets; $i++) {
// Format the object, make it pretty
$this->formatBucket($buckets[$i]);
}
return $buckets;
} | [
"public",
"function",
"getBuckets",
"(",
"$",
"page",
"=",
"null",
",",
"$",
"perPage",
"=",
"null",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"select",
"(",
"'b.id,b.slug,b.label,b.allowed_types,b.max_size,b.created,b.created_by'",
")",
";",
"$",
"oDb",
"->",
"select",
"(",
"'b.modified,b.modified_by'",
")",
";",
"// Apply common items; pass $data",
"$",
"this",
"->",
"getCountCommonBuckets",
"(",
"$",
"data",
")",
";",
"// --------------------------------------------------------------------------",
"// Facilitate pagination",
"if",
"(",
"!",
"is_null",
"(",
"$",
"page",
")",
")",
"{",
"/**\n * Adjust the page variable, reduce by one so that the offset is calculated\n * correctly. Make sure we don't go into negative numbers\n */",
"$",
"page",
"--",
";",
"$",
"page",
"=",
"$",
"page",
"<",
"0",
"?",
"0",
":",
"$",
"page",
";",
"// Work out what the offset should be",
"$",
"perPage",
"=",
"is_null",
"(",
"$",
"perPage",
")",
"?",
"50",
":",
"(",
"int",
")",
"$",
"perPage",
";",
"$",
"offset",
"=",
"$",
"page",
"*",
"$",
"perPage",
";",
"$",
"oDb",
"->",
"limit",
"(",
"$",
"perPage",
",",
"$",
"offset",
")",
";",
"}",
"// --------------------------------------------------------------------------",
"$",
"buckets",
"=",
"$",
"oDb",
"->",
"get",
"(",
"NAILS_DB_PREFIX",
".",
"'cdn_bucket b'",
")",
"->",
"result",
"(",
")",
";",
"$",
"numBuckets",
"=",
"count",
"(",
"$",
"buckets",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"numBuckets",
";",
"$",
"i",
"++",
")",
"{",
"// Format the object, make it pretty",
"$",
"this",
"->",
"formatBucket",
"(",
"$",
"buckets",
"[",
"$",
"i",
"]",
")",
";",
"}",
"return",
"$",
"buckets",
";",
"}"
] | Returns an array of buckets
@param integer $page The page to return
@param integer $perPage The number of items to return per page
@param array $data An array of data to pass to getCountCommonBuckets()
@return array | [
"Returns",
"an",
"array",
"of",
"buckets"
] | 1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef | https://github.com/nails/module-cdn/blob/1c2ff1cbdf2aa6a7162f92c8fdbcde87c506e1ef/src/Service/Cdn.php#L1685-L1726 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.